summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java86
1 files changed, 39 insertions, 47 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
index 24cbb3e3a4..d3640a71a7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,13 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.CommonImportManager.ElementTypeEnum;
import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
@@ -41,11 +44,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Component;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
@Component("groupTypeImportManager")
public class GroupTypeImportManager {
@@ -55,7 +53,8 @@ public class GroupTypeImportManager {
private final ToscaOperationFacade toscaOperationFacade;
private final CommonImportManager commonImportManager;
- public GroupTypeImportManager(GroupTypeOperation groupTypeOperation, ComponentsUtils componentsUtils, ToscaOperationFacade toscaOperationFacade, CommonImportManager commonImportManager) {
+ public GroupTypeImportManager(GroupTypeOperation groupTypeOperation, ComponentsUtils componentsUtils, ToscaOperationFacade toscaOperationFacade,
+ CommonImportManager commonImportManager) {
this.groupTypeOperation = groupTypeOperation;
this.componentsUtils = componentsUtils;
this.toscaOperationFacade = toscaOperationFacade;
@@ -70,22 +69,23 @@ public class GroupTypeImportManager {
return commonImportManager.createElementTypesFromYml(groupTypesYml, this::createGroupType);
}
- private Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> upsertGroupTypesByDao(List<GroupTypeDefinition> groupTypesToCreate) {
- return commonImportManager.createElementTypesByDao(groupTypesToCreate, this::validateGroupType, groupType -> new ImmutablePair<>(ElementTypeEnum.GROUP_TYPE, groupType.getType()),
- groupTypeOperation::getLatestGroupTypeByType, groupTypeOperation::addGroupType, this::updateGroupType);
+ private Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> upsertGroupTypesByDao(
+ List<GroupTypeDefinition> groupTypesToCreate) {
+ return commonImportManager.createElementTypesByDao(groupTypesToCreate, this::validateGroupType,
+ groupType -> new ImmutablePair<>(ElementTypeEnum.GROUP_TYPE, groupType.getType()), groupTypeOperation::getLatestGroupTypeByType,
+ groupTypeOperation::addGroupType, this::updateGroupType);
}
private Either<GroupTypeDefinition, StorageOperationStatus> updateGroupType(GroupTypeDefinition newGroupType, GroupTypeDefinition oldGroupType) {
Either<GroupTypeDefinition, StorageOperationStatus> validationRes = groupTypeOperation.validateUpdateProperties(newGroupType);
if (validationRes.isRight()) {
- log.error("#updateGroupType - One or all properties of group type {} not valid. status is {}", newGroupType, validationRes.right().value());
+ log.error("#updateGroupType - One or all properties of group type {} not valid. status is {}", newGroupType,
+ validationRes.right().value());
return validationRes;
}
-
if (TypeCompareUtils.isGroupTypesEquals(newGroupType, oldGroupType)) {
return TypeCompareUtils.typeAlreadyExists();
}
-
return groupTypeOperation.updateGroupType(newGroupType, oldGroupType);
}
@@ -98,7 +98,8 @@ public class GroupTypeImportManager {
} else {
for (String member : groupType.getMembers()) {
// Verify that such Resource exist
- Either<org.openecomp.sdc.be.model.Resource, StorageOperationStatus> eitherMemberExist = toscaOperationFacade.getLatestByToscaResourceName(member);
+ Either<org.openecomp.sdc.be.model.Resource, StorageOperationStatus> eitherMemberExist = toscaOperationFacade
+ .getLatestByToscaResourceName(member);
if (eitherMemberExist.isRight()) {
StorageOperationStatus operationStatus = eitherMemberExist.right().value();
log.debug("Error when fetching parent resource {}, error: {}", member, operationStatus);
@@ -108,16 +109,13 @@ public class GroupTypeImportManager {
break;
}
}
-
}
}
return result;
}
private GroupTypeDefinition createGroupType(String groupTypeName, Map<String, Object> toscaJson) {
-
GroupTypeDefinition groupType = new GroupTypeDefinition();
-
if (toscaJson != null) {
// Description
commonImportManager.setField(toscaJson, TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName(), groupType::setDescription);
@@ -132,11 +130,8 @@ public class GroupTypeImportManager {
groupType.setCapabilities(capabilities);
// Members
commonImportManager.setField(toscaJson, TypeUtils.ToscaTagNamesEnum.MEMBERS.getElementName(), groupType::setMembers);
-
groupType.setType(groupTypeName);
-
groupType.setHighestVersion(true);
-
groupType.setVersion(TypeUtils.getFirstCertifiedVersionVersion());
}
return groupType;
@@ -148,41 +143,24 @@ public class GroupTypeImportManager {
*/
private Map<String, CapabilityDefinition> createCapabilities(Map<String, Object> toscaJson) {
CapabilityTypeToscaJsonHolder capabilityTypeToscaJsonHolder = new CapabilityTypeToscaJsonHolder();
- commonImportManager.setField(toscaJson, TypeUtils.ToscaTagNamesEnum.CAPABILITIES.getElementName(), capabilityTypeToscaJsonHolder::setCapabilityTypeToscaJson);
+ commonImportManager.setField(toscaJson, TypeUtils.ToscaTagNamesEnum.CAPABILITIES.getElementName(),
+ capabilityTypeToscaJsonHolder::setCapabilityTypeToscaJson);
Map<String, CapabilityDefinition> capabilities;
if (capabilityTypeToscaJsonHolder.isEmpty()) {
capabilities = Collections.emptyMap();
- }
- else {
- capabilities = commonImportManager.createElementTypesMapFromToscaJsonMap(this::createCapability, capabilityTypeToscaJsonHolder.getCapabilityTypeToscaJson());
+ } else {
+ capabilities = commonImportManager
+ .createElementTypesMapFromToscaJsonMap(this::createCapability, capabilityTypeToscaJsonHolder.getCapabilityTypeToscaJson());
}
return capabilities;
}
-
- private class CapabilityTypeToscaJsonHolder {
- private Map<String, Object> capabilityTypeToscaJson;
-
- public Map<String, Object> getCapabilityTypeToscaJson() {
- return capabilityTypeToscaJson;
- }
-
- public boolean isEmpty() {
- return capabilityTypeToscaJson == null;
- }
- public void setCapabilityTypeToscaJson(Map<String, Object> capabilityTypeToscaJson) {
- this.capabilityTypeToscaJson = capabilityTypeToscaJson;
- }
- }
-
private CapabilityDefinition createCapability(String capabilityName, Map<String, Object> toscaJson) {
CapabilityDefinition capability = new CapabilityDefinition();
-
capability.setName(capabilityName);
commonImportManager.setField(toscaJson, ToscaTagNamesEnum.TYPE.getElementName(), capability::setType);
// Properties
CommonImportManager.setProperties(toscaJson, pl -> capability.setProperties(map(pl)));
-
return capability;
}
@@ -191,9 +169,23 @@ public class GroupTypeImportManager {
* @return
*/
private List<ComponentInstanceProperty> map(List<PropertyDefinition> pl) {
- return pl.stream()
- .map(ComponentInstanceProperty::new)
- .collect(Collectors.toList());
+ return pl.stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
}
+ private class CapabilityTypeToscaJsonHolder {
+
+ private Map<String, Object> capabilityTypeToscaJson;
+
+ public Map<String, Object> getCapabilityTypeToscaJson() {
+ return capabilityTypeToscaJson;
+ }
+
+ public void setCapabilityTypeToscaJson(Map<String, Object> capabilityTypeToscaJson) {
+ this.capabilityTypeToscaJson = capabilityTypeToscaJson;
+ }
+
+ public boolean isEmpty() {
+ return capabilityTypeToscaJson == null;
+ }
+ }
}