2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
23 import fj.data.Either;
24 import jersey.repackaged.com.google.common.collect.Sets;
25 import org.openecomp.sdc.be.model.PropertyDefinition;
26 import org.openecomp.sdc.be.model.Resource;
27 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import java.util.List;
32 import java.util.Optional;
35 public class NormativesMigration extends ComponentMigration<Resource> {
37 private static Logger LOGGER = LoggerFactory.getLogger(NormativesMigration.class);
38 private static final String JCP_VERSION_PROPERTY = "jcp-version";
39 private static final Set<String> e2eMalformedVfcs = Sets.newHashSet("59da26b4-edd0-4412-a2e6-d6711f376340");
41 @javax.annotation.Resource(name = "normatives-resolver")
42 private NormativesResolver normativesResolver;
44 @javax.annotation.Resource(name = "resource-version-migration")
45 private VersionMigration<Resource> versionMigration;
48 public String description() {
49 return "migration of node types";
53 Either<List<Resource>, ?> getElementsToMigrate() {
54 return normativesResolver.getAllNodeTypeNormatives();
58 boolean save(Resource element) {
59 if (e2eMalformedVfcs.contains(element.getUniqueId())) {
60 replaceJcpVersionPropertyTypeToVersion(element);
62 return super.save(element);
65 private void replaceJcpVersionPropertyTypeToVersion(Resource element) {
66 getJcpIntegerProperty(element).ifPresent(propertyDefinition -> {
67 LOGGER.info("resource {} with id {}: found property jcp-version with type 'integer', changing type to 'version'", element.getName(), element.getUniqueId());
68 propertyDefinition.setType(ToscaPropertyType.VERSION.getType());
72 private Optional<PropertyDefinition> getJcpIntegerProperty(Resource element) {
73 if (element.getProperties() == null) return Optional.empty();
74 return element.getProperties().stream()
75 .filter(prop -> prop.getName().equals(JCP_VERSION_PROPERTY))
76 .filter(prop -> prop.getType().equals(ToscaPropertyType.INTEGER.getType()))
82 boolean doPostMigrateOperation(List<Resource> elements) {
83 LOGGER.info("migrating node types versions");
84 return versionMigration.buildComponentsVersionChain(elements);