X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fcomponents%2Fimpl%2FResourceImportManager.java;h=1e2cea5c640bb68022fe4e95bbdcd676610e158d;hb=adb7f7496af6e71e1cced44ee2f7485c9917a806;hp=4e6628c8dde72a631709783385e22dcb3ad96ff2;hpb=a8d3e1b8c759c21227690a425552a245da883e97;p=sdc.git diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index 4e6628c8dd..1e2cea5c64 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -19,17 +19,29 @@ * Modifications copyright (c) 2019 Nokia * ================================================================================ */ - package org.openecomp.sdc.be.components.impl; -import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.QUOTE; import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataType; import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataTypeDefinitionWithName; -import static org.openecomp.sdc.be.utils.TypeUtils.setField; import fj.data.Either; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; -import java.util.LinkedHashMap; +import java.util.Comparator; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import javax.servlet.ServletContext; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -49,13 +61,15 @@ import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; @@ -64,11 +78,13 @@ import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.AttributeDefinition; import org.openecomp.sdc.be.model.CapabilityDefinition; -import org.openecomp.sdc.be.model.ComponentInstanceAttribute; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.DefaultUploadResourceInfo; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.NodeTypesMetadataList; +import org.openecomp.sdc.be.model.NullNodeTypeMetadata; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.RequirementDefinition; import org.openecomp.sdc.be.model.Resource; @@ -77,6 +93,8 @@ import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter; +import org.openecomp.sdc.be.model.mapper.NodeTypeMetadataMapper; import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation; @@ -84,74 +102,50 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo; -import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil; import org.openecomp.sdc.be.utils.TypeUtils; import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; +import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.util.ThreadLocalsHolder; import org.openecomp.sdc.common.util.ValidationUtils; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import org.springframework.web.context.WebApplicationContext; import org.yaml.snakeyaml.Yaml; -import javax.servlet.ServletContext; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.function.Function; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -@Component("resourceImportManager") +@org.springframework.stereotype.Component("resourceImportManager") public class ResourceImportManager { + static final Pattern PROPERTY_NAME_PATTERN_IGNORE_LENGTH = Pattern.compile("['\\w\\s\\-\\.\\:]+"); private static final Logger log = Logger.getLogger(ResourceImportManager.class); - - static final Pattern PROPERTY_NAME_PATTERN_IGNORE_LENGTH = Pattern.compile("[\\w\\-\\_\\d\\:]+"); - private static final String IMPLEMENTATION = "implementation"; - private static final String INPUTS = "inputs"; - private static final String TYPE = "type"; - private static final String DESCRIPTION = "description"; - private static final String REQUIRED = "required"; - private static final String DEFAULT = "default"; - private static final String STATUS = "status"; - + private final InterfaceDefinitionHandler interfaceDefinitionHandler; + private final ComponentsUtils componentsUtils; + private final CapabilityTypeOperation capabilityTypeOperation; + private final JanusGraphDao janusGraphDao; private ServletContext servletContext; - private AuditingManager auditingManager; private ResourceBusinessLogic resourceBusinessLogic; - public ServiceBusinessLogic getServiceBusinessLogic() { - return serviceBusinessLogic; - } - - public void setServiceBusinessLogic(ServiceBusinessLogic serviceBusinessLogic) { - this.serviceBusinessLogic = serviceBusinessLogic; - } - @Autowired private ServiceBusinessLogic serviceBusinessLogic; - private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic; - private IGraphLockOperation graphLockOperation; private ToscaOperationFacade toscaOperationFacade; - - private final ComponentsUtils componentsUtils; - private final CapabilityTypeOperation capabilityTypeOperation; - private ResponseFormatManager responseFormatManager; @Autowired - public ResourceImportManager(ComponentsUtils componentsUtils, CapabilityTypeOperation capabilityTypeOperation) { + public ResourceImportManager(final ComponentsUtils componentsUtils, final CapabilityTypeOperation capabilityTypeOperation, + final InterfaceDefinitionHandler interfaceDefinitionHandler, final JanusGraphDao janusGraphDao) { this.componentsUtils = componentsUtils; this.capabilityTypeOperation = capabilityTypeOperation; + this.interfaceDefinitionHandler = interfaceDefinitionHandler; + this.janusGraphDao = janusGraphDao; + } + + public ServiceBusinessLogic getServiceBusinessLogic() { + return serviceBusinessLogic; + } + + public void setServiceBusinessLogic(ServiceBusinessLogic serviceBusinessLogic) { + this.serviceBusinessLogic = serviceBusinessLogic; } @Autowired @@ -159,77 +153,88 @@ public class ResourceImportManager { this.toscaOperationFacade = toscaOperationFacade; } - public ImmutablePair importNormativeResource(String resourceYml, - UploadResourceInfo resourceMetaData, - User creator, boolean createNewVersion, - boolean needLock) { - + public ImmutablePair importNormativeResource(final String resourceYml, final UploadResourceInfo resourceMetaData, + final User creator, final boolean createNewVersion, final boolean needLock, + final boolean isInTransaction) { LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(); lifecycleChangeInfo.setUserRemarks("certification on import"); - Function validator = resource -> resourceBusinessLogic - .validatePropertiesDefaultValues(resource); - - return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, - createNewVersion, needLock, null, null, false, null, null, false); + Function validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource); + return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, isInTransaction, createNewVersion, + needLock, null, null, false, null, null, false); } - public ImmutablePair importNormativeResourceFromCsar(String resourceYml, - UploadResourceInfo resourceMetaData, - User creator, boolean createNewVersion, - boolean needLock) { - - LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(); - lifecycleChangeInfo.setUserRemarks("certification on import"); - Function validator = resource -> resourceBusinessLogic - .validatePropertiesDefaultValues(resource); + public void importAllNormativeResource(final String resourcesYaml, final NodeTypesMetadataList nodeTypesMetadataList, final User user, + final boolean createNewVersion, final boolean needLock) { + final Map nodeTypesYamlMap; + try { + nodeTypesYamlMap = new Yaml().load(resourcesYaml); + } catch (final Exception e) { + log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, ResourceImportManager.class.getName(), "Could not parse node types YAML", e); + throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TYPES_YAML); + } + if (!nodeTypesYamlMap.containsKey(ToscaTagNamesEnum.NODE_TYPES.getElementName())) { + return; + } + final Map nodeTypesMap = (Map) nodeTypesYamlMap.get(ToscaTagNamesEnum.NODE_TYPES.getElementName()); + importAllNormativeResource(nodeTypesMap, nodeTypesMetadataList, user, "", createNewVersion,needLock); + } - return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, - createNewVersion, needLock, null, null, false, null, null, false); + public void importAllNormativeResource(final Map nodeTypesMap, final NodeTypesMetadataList nodeTypesMetadataList, + final User user, String model, final boolean createNewVersion, final boolean needLock) { + try { + nodeTypesMetadataList.getNodeMetadataList().forEach(nodeTypeMetadata -> { + final String nodeTypeToscaName = nodeTypeMetadata.getToscaName(); + final Map nodeTypeMap = (Map) nodeTypesMap.get(nodeTypeToscaName); + if (nodeTypeMap == null) { + log.warn(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, ResourceImportManager.class.getName(), + "Could not find given node type '{}'. The node will not be created.", nodeTypeToscaName); + } else { + final Map>> nodeTypeDefinitionMap = + Map.of(ToscaTagNamesEnum.NODE_TYPES.getElementName(), + Map.of(nodeTypeToscaName, nodeTypeMap) + ); + final String nodeTypeYaml = new Yaml().dump(nodeTypeDefinitionMap); + UploadResourceInfo uploadResourceInfo = NodeTypeMetadataMapper.mapTo(nodeTypeMetadata); + if (uploadResourceInfo instanceof DefaultUploadResourceInfo) { + uploadResourceInfo.setModel(model); + uploadResourceInfo.setContactId(user.getUserId()); + } + importNormativeResource(nodeTypeYaml, uploadResourceInfo, user, createNewVersion, needLock, true); + } + }); + janusGraphDao.commit(); + } catch (final Exception e) { + janusGraphDao.rollback(); + throw e; + } } - public ImmutablePair importCertifiedResource(String resourceYml, - UploadResourceInfo resourceMetaData, - User creator, + public ImmutablePair importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, Function validationFunction, - LifecycleChangeInfoWithAction lifecycleChangeInfo, - boolean isInTransaction, + LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock, Map> nodeTypeArtifactsToHandle, List nodeTypesNewCreatedArtifacts, - boolean forceCertificationAllowed, - CsarInfo csarInfo, String nodeName, + boolean forceCertificationAllowed, CsarInfo csarInfo, String nodeName, boolean isNested) { Resource resource = new Resource(); ImmutablePair responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED); Either, ResponseFormat> response = Either.left(responsePair); - String latestCertifiedResourceId = null; try { boolean shouldBeCertified = nodeTypeArtifactsToHandle == null || nodeTypeArtifactsToHandle.isEmpty(); setConstantMetaData(resource, shouldBeCertified); - setMetaDataFromJson(resourceMetaData, resource); - + setResourceMetaData(resource, resourceYml, resourceMetaData); populateResourceFromYaml(resourceYml, resource); - - Boolean isValidResource = validationFunction.apply(resource); - if (!createNewVersion) { - Either latestByName = toscaOperationFacade - .getLatestByName(resource.getName()); - if (latestByName.isLeft()) { - throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, - resource.getName()); - } - } + validationFunction.apply(resource); + resource.getComponentMetadataDefinition().getMetadataDataDefinition().setNormative(resourceMetaData.isNormative()); + checkResourceExists(createNewVersion, csarInfo, resource); resource = resourceBusinessLogic - .createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock, csarInfo, nodeName, - isNested).left; + .createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock, csarInfo, nodeName, isNested).left; Resource changeStateResponse; - if (nodeTypeArtifactsToHandle != null && !nodeTypeArtifactsToHandle.isEmpty()) { - Either, ResponseFormat> handleNodeTypeArtifactsRes = - resourceBusinessLogic - .handleNodeTypeArtifacts(resource, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, - creator, isInTransaction, false); + Either, ResponseFormat> handleNodeTypeArtifactsRes = resourceBusinessLogic + .handleNodeTypeArtifacts(resource, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, creator, isInTransaction, false); if (handleNodeTypeArtifactsRes.isRight()) { //TODO: should be used more correct action throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); @@ -237,10 +242,8 @@ public class ResourceImportManager { } latestCertifiedResourceId = getLatestCertifiedResourceId(resource); changeStateResponse = resourceBusinessLogic - .propagateStateToCertified(creator, resource, lifecycleChangeInfo, isInTransaction, needLock, - forceCertificationAllowed); - responsePair = new ImmutablePair<>(changeStateResponse, response.left() - .value().right); + .propagateStateToCertified(creator, resource, lifecycleChangeInfo, isInTransaction, needLock, forceCertificationAllowed); + responsePair = new ImmutablePair<>(changeStateResponse, response.left().value().right); } catch (RuntimeException e) { handleImportResourceException(resourceMetaData, creator, true, e); } finally { @@ -249,19 +252,48 @@ public class ResourceImportManager { graphLockOperation.unlockComponent(latestCertifiedResourceId, NodeTypeEnum.Resource); } } - return responsePair; } - private ResponseFormat getResponseFormatFromComponentException(RuntimeException e) { - if (e instanceof ComponentException) { - return ((ComponentException) e).getResponseFormat() == null ? - componentsUtils - .getResponseFormat(((ComponentException) e).getActionStatus(), ((ComponentException) e).getParams()) - : - ((ComponentException) e).getResponseFormat(); + private void checkResourceExists(final boolean isCreate, final CsarInfo csarInfo, final Resource resource) { + if (isCreate) { + checkResourceExistsOnCreate(resource, csarInfo); + } else { + checkResourceExistsOnUpdate(resource); } - return null; + } + + private void checkResourceExistsOnCreate(final Resource resource, final CsarInfo csarInfo) { + if (isCsarPresent(csarInfo)) { + return; + } + final Either resourceEither = + toscaOperationFacade.getComponentByNameAndVendorRelease(resource.getComponentType(), resource.getName(), + resource.getVendorRelease(), JsonParseFlagEnum.ParseAll, resource.getModel()); + if (resourceEither.isLeft() && toscaOperationFacade.isNodeAssociatedToModel(resource.getModel(), resource)) { + if (resource.getModel() == null) { + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS, + resource.getName(), resource.getVendorRelease()); + } + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS_IN_MODEL, + resource.getName(), resource.getVendorRelease(), resource.getModel()); + } + } + + private void checkResourceExistsOnUpdate(final Resource resource) { + final String model = resource.getModel(); + final Either latestByName = toscaOperationFacade.getLatestByName(resource.getName(), model); + if (latestByName.isLeft() && toscaOperationFacade.isNodeAssociatedToModel(model, resource)) { + if (model == null) { + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, + resource.getResourceType().name(), resource.getName()); + } + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_MODEL_ALREADY_EXIST, resource.getName(), model); + } + } + + private boolean isCsarPresent(final CsarInfo csarInfo) { + return csarInfo != null && StringUtils.isNotEmpty(csarInfo.getCsarUUID()); } private String getLatestCertifiedResourceId(Resource resource) { @@ -290,286 +322,192 @@ public class ResourceImportManager { resource.setIcon(resourceMetaData.getResourceIconPath()); resource.setResourceVendorModelNumber(resourceMetaData.getResourceVendorModelNumber()); resource.setResourceType(ResourceTypeEnum.valueOf(resourceMetaData.getResourceType())); + resource.setTenant(resourceMetaData.getTenant()); if (resourceMetaData.getVendorName() != null) { resource.setVendorName(resourceMetaData.getVendorName()); } if (resourceMetaData.getVendorRelease() != null) { resource.setVendorRelease(resourceMetaData.getVendorRelease()); } + if (resourceMetaData.getModel() != null) { + resource.setModel(resourceMetaData.getModel()); + } } } - public ImmutablePair importUserDefinedResource(String resourceYml, - UploadResourceInfo resourceMetaData, - User creator, boolean isInTransaction) { - + public ImmutablePair importUserDefinedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, + boolean isInTransaction) { Resource resource = new Resource(); ImmutablePair responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED); - try { setMetaDataFromJson(resourceMetaData, resource); - populateResourceFromYaml(resourceYml, resource); - - // currently import VF isn't supported. In future will be supported - // import VF only with CSAR file!! + // currently import VF isn't supported. In future will be supported import VF only with CSAR file!! if (ResourceTypeEnum.VF == resource.getResourceType()) { log.debug("Now import VF isn't supported. It will be supported in future with CSAR file only"); throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION); } - resourceBusinessLogic.validateDerivedFromNotEmpty(creator, resource, AuditingActionEnum.CREATE_RESOURCE); - Boolean validatePropertiesTypes = resourceBusinessLogic.validatePropertiesDefaultValues(resource); - - responsePair = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, - false, isInTransaction, true, null, null, false); - + resourceBusinessLogic.validatePropertiesDefaultValues(resource); + responsePair = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, false, isInTransaction, true, null, null, false); } catch (RuntimeException e) { handleImportResourceException(resourceMetaData, creator, false, e); } return responsePair; - } - private void populateResourceFromYaml(String resourceYml, Resource resource) { - @SuppressWarnings("unchecked") - Object ymlObj = new Yaml().load(resourceYml); + private void populateResourceFromYaml(final String resourceYml, Resource resource) { + @SuppressWarnings("unchecked") Object ymlObj = new Yaml().load(resourceYml); if (ymlObj instanceof Map) { - Map toscaJsonAll = (Map) ymlObj; + final Either existingResource = getExistingResource(resource); + final Map toscaJsonAll = (Map) ymlObj; Map toscaJson = toscaJsonAll; - - // Checks if exist and builds the node_types map - if (toscaJsonAll.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName()) - && resource.getResourceType() != ResourceTypeEnum.CVFC) { + if (toscaJsonAll.containsKey(ToscaTagNamesEnum.NODE_TYPES.getElementName()) && resource.getResourceType() != ResourceTypeEnum.CVFC) { toscaJson = new HashMap<>(); - toscaJson.put(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName(), - toscaJsonAll.get(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName())); + toscaJson.put(ToscaTagNamesEnum.NODE_TYPES.getElementName(), toscaJsonAll.get(ToscaTagNamesEnum.NODE_TYPES.getElementName())); } final List foundElements = new ArrayList<>(); - final Either, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements(toscaJsonAll, - ToscaTagNamesEnum.DATA_TYPES.getElementName(), ToscaElementTypeEnum.MAP, foundElements); + final Either, ResultStatusEnum> toscaElements = ImportUtils + .findToscaElements(toscaJsonAll, ToscaTagNamesEnum.DATA_TYPES.getElementName(), ToscaElementTypeEnum.MAP, foundElements); if (toscaElements.isLeft()) { final Map toscaAttributes = (Map) foundElements.get(0); if (MapUtils.isNotEmpty(toscaAttributes)) { - resource.setDataTypes(extractDataTypeFromJson(resourceBusinessLogic, toscaAttributes)); + resource.setDataTypes(extractDataTypeFromJson(resourceBusinessLogic, toscaAttributes, resource.getModel())); } } - // Derived From - Resource parentResource = setDerivedFrom(toscaJson, resource); + final Resource parentResource = setDerivedFrom(toscaJson, resource); if (StringUtils.isEmpty(resource.getToscaResourceName())) { setToscaResourceName(toscaJson, resource); } - setAttributes(toscaJson, resource); setCapabilities(toscaJson, resource, parentResource); - setProperties(toscaJson, resource); + setProperties(toscaJson, resource, existingResource); + setAttributes(toscaJson, resource); setRequirements(toscaJson, resource, parentResource); - setInterfaceLifecycle(toscaJson, resource); + setInterfaceLifecycle(toscaJson, resource, existingResource); } else { throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); } - - } - - private void setToscaResourceName(Map toscaJson, Resource resource) { - Either, ResultStatusEnum> toscaElement = ImportUtils - .findFirstToscaMapElement(toscaJson, TypeUtils.ToscaTagNamesEnum.NODE_TYPES); - if (toscaElement.isLeft() || toscaElement.left().value().size() == 1) { - String toscaResourceName = toscaElement.left().value().keySet().iterator().next(); - resource.setToscaResourceName(toscaResourceName); - } } - private void setInterfaceLifecycle(Map toscaJson, Resource resource) { - Either, ResultStatusEnum> toscaInterfaces = ImportUtils - .findFirstToscaMapElement(toscaJson, TypeUtils.ToscaTagNamesEnum.INTERFACES); - if (toscaInterfaces.isLeft()) { - Map jsonInterfaces = toscaInterfaces.left().value(); - Map moduleInterfaces = new HashMap<>(); - Iterator> interfacesNameValue = jsonInterfaces.entrySet().iterator(); - while (interfacesNameValue.hasNext()) { - Entry interfaceNameValue = interfacesNameValue.next(); - Either eitherInterface = createModuleInterface(interfaceNameValue - .getValue(), resource); - if (eitherInterface.isRight()) { - log.info("error when creating interface:{}, for resource:{}", interfaceNameValue.getKey(), - resource.getName()); - } else { - moduleInterfaces.put(interfaceNameValue.getKey(), eitherInterface.left().value()); + private Either getExistingResource(final Resource resource) { + final Either, JanusGraphOperationStatus> byCriteria = janusGraphDao.getByCriteria( + getVertexTypeEnum(resource.getResourceType()), propertiesToMatch(resource), propertiesToNotMatch(), + JsonParseFlagEnum.ParseAll, resource.getModel(), false); + if (byCriteria.isLeft() && CollectionUtils.isNotEmpty(byCriteria.left().value())) { + final List graphVertexList = byCriteria.left().value(); + if (graphVertexList.size() == 1) { + return toscaOperationFacade.getToscaElement(graphVertexList.get(0).getUniqueId()); + } else { + final Optional vertex = graphVertexList.stream() + .max(Comparator.comparing(graphVertex -> (String) graphVertex.getMetadataProperties().get(GraphPropertyEnum.VERSION))); + if (vertex.isPresent()) { + return toscaOperationFacade.getToscaElement(vertex.get().getUniqueId()); } - - } - if (moduleInterfaces.size() > 0) { - resource.setInterfaces(moduleInterfaces); } } + return Either.right(StorageOperationStatus.NOT_FOUND); } - private Either createModuleInterface(Object interfaceJson, - Resource resource) { - final InterfaceDefinition interf = new InterfaceDefinition(); - Either result = Either.left(interf); + private VertexTypeEnum getVertexTypeEnum(final ResourceTypeEnum resourceType) { + return ModelConverter.isAtomicComponent(resourceType) ? VertexTypeEnum.NODE_TYPE : VertexTypeEnum.TOPOLOGY_TEMPLATE; + } - try { - if (interfaceJson instanceof String) { - final String requirementJsonString = (String) interfaceJson; - interf.setType(requirementJsonString); - } else if (interfaceJson instanceof Map && ResourceTypeEnum.VFC.equals(resource.getResourceType())) { - final Map requirementJsonMap = (Map) interfaceJson; - final Map operations = new HashMap<>(); - - for (final Entry entry : requirementJsonMap.entrySet()) { - if (entryIsInterfaceType(entry)) { - final String type = (String) requirementJsonMap - .get(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName()); - interf.setType(type); - interf.setUniqueId(type.toLowerCase()); - } else if (entryContainsImplementationForAKnownOperation(entry, interf.getType())) { - - final OperationDataDefinition operation = new OperationDataDefinition(); - operation.setName(entry.getKey()); - - final Map entryValue = (Map) entry.getValue(); - if (entryValue.containsKey(IMPLEMENTATION)) { - operation.setImplementation(handleOperationImplementation(entry)); - } - if (entryValue.containsKey(INPUTS)) { - final Map interfaceInputs = (Map) entryValue - .get(ToscaTagNamesEnum.INPUTS.getElementName()); - operation.setInputs(handleInterfaceInput(interfaceInputs)); - } - operations.put(entry.getKey(), operation); - } - } - if (!operations.isEmpty()) { - interf.setOperations(operations); - } - } else { - result = Either.right(ResultStatusEnum.GENERAL_ERROR); - } + private Map propertiesToMatch(final Resource resource) { + final Map graphProperties = new EnumMap<>(GraphPropertyEnum.class); + graphProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normaliseComponentName(resource.getName())); + graphProperties.put(GraphPropertyEnum.COMPONENT_TYPE, resource.getComponentType().name()); + graphProperties.put(GraphPropertyEnum.RESOURCE_TYPE, resource.getResourceType().name()); + graphProperties.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); + return graphProperties; + } - } catch (Exception e) { - BeEcompErrorManager.getInstance().logBeSystemError("Import Resource- create interface"); - log.debug("error when creating interface, message:{}", e.getMessage(), e); - result = Either.right(ResultStatusEnum.GENERAL_ERROR); - } + private Map propertiesToNotMatch() { + final Map graphProperties = new EnumMap<>(GraphPropertyEnum.class); + graphProperties.put(GraphPropertyEnum.IS_DELETED, true); + graphProperties.put(GraphPropertyEnum.IS_ARCHIVED, true); + return graphProperties; + } - return result; + private void setToscaResourceName(Map toscaJson, Resource resource) { + resource.setToscaResourceName(getToscaResourceName(toscaJson)); } - private ArtifactDataDefinition handleOperationImplementation(final Entry entry) { - final ArtifactDataDefinition implementation = new ArtifactDataDefinition(); - final String artifactName = ((Map) entry.getValue()).get(IMPLEMENTATION); - if (OperationArtifactUtil.artifactNameIsALiteralValue(artifactName)) { - implementation.setArtifactName(artifactName); - } else { - implementation.setArtifactName(QUOTE + artifactName + QUOTE); + private String getToscaResourceName(Map toscaJson) { + Either, ResultStatusEnum> toscaElement = ImportUtils + .findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.NODE_TYPES); + if (toscaElement.isLeft() && toscaElement.left().value().size() == 1) { + String toscaResourceName = toscaElement.left().value().keySet().iterator().next(); + return toscaResourceName; } - return implementation; + return null; } - private ListDataDefinition handleInterfaceInput( - final Map interfaceInputs) { - final ListDataDefinition inputs = new ListDataDefinition<>(); - for (final Entry interfaceInput : interfaceInputs.entrySet()) { - final OperationInputDefinition operationInput = new OperationInputDefinition(); - operationInput.setName(interfaceInput.getKey()); - if (interfaceInput.getValue() instanceof Map) { - final LinkedHashMap inputPropertyValue = - (LinkedHashMap) interfaceInput.getValue(); - log.info("createModuleInterface: i interfaceInput.getKey() {}, {} , {} ", - interfaceInput.getKey(), inputPropertyValue.keySet(), - inputPropertyValue.values()); - if (inputPropertyValue.get(TYPE) != null) { - operationInput.setType(inputPropertyValue.get(TYPE).toString()); - } - if (inputPropertyValue.get(DESCRIPTION) != null) { - operationInput.setDescription(inputPropertyValue.get(DESCRIPTION).toString()); - } - if (inputPropertyValue.get(REQUIRED) != null) { - operationInput.setRequired( - Boolean.getBoolean(inputPropertyValue.get(REQUIRED).toString())); - } - if (inputPropertyValue.get(DEFAULT) != null) { - operationInput.setToscaDefaultValue(inputPropertyValue.get(DEFAULT).toString()); - } - if (inputPropertyValue.get(STATUS) != null) { - operationInput.setStatus(inputPropertyValue.get(STATUS).toString()); + private void setInterfaceLifecycle(Map toscaJson, Resource resource, Either existingResource) { + final Either, ResultStatusEnum> toscaInterfaces = ImportUtils + .findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.INTERFACES); + final Map moduleInterfaces = new HashMap<>(); + final Map map; + if (toscaInterfaces.isLeft()) { + map = toscaInterfaces.left().value(); + for (final Entry interfaceNameValue : map.entrySet()) { + final Either eitherInterface = createModuleInterface(interfaceNameValue.getValue(), + resource.getModel()); + if (eitherInterface.isRight()) { + log.info("error when creating interface:{}, for resource:{}", interfaceNameValue.getKey(), resource.getName()); + } else { + final InterfaceDefinition interfaceDefinition = eitherInterface.left().value(); + moduleInterfaces.put(interfaceDefinition.getType(), interfaceDefinition); } - - } else if (interfaceInput.getValue() instanceof String) { - final String value = (String) interfaceInput.getValue(); - operationInput.setDefaultValue(value); - operationInput.setToscaDefaultValue(value); - operationInput.setValue(value); } - inputs.getListToscaDataDefinition().add(operationInput); - inputs.add(operationInput); + } else { + map = Collections.emptyMap(); } - return inputs; - } - - private boolean entryIsInterfaceType(final Entry entry) { - if(entry.getKey().equals(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName())) { - if (entry.getValue() instanceof String) { - return true; + if (existingResource.isLeft()) { + final Map userCreatedInterfaceDefinitions = + existingResource.left().value().getInterfaces().entrySet().stream() + .filter(i -> i.getValue().isUserCreated()) + .filter(i -> !map.containsKey(i.getValue().getType())) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + if (MapUtils.isNotEmpty(userCreatedInterfaceDefinitions)) { + moduleInterfaces.putAll(userCreatedInterfaceDefinitions); } - throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML); } - return false; - } - private boolean entryContainsImplementationForAKnownOperation(final Entry entry, - final String interfaceType) { - if (entry.getValue() instanceof Map && ((Map)entry.getValue()).containsKey(IMPLEMENTATION)) { - if (isAKnownOperation(interfaceType, entry.getKey())){ - return true; - } - throw new ByActionStatusComponentException(ActionStatus.INTERFACE_OPERATION_NOT_FOUND); + if (MapUtils.isNotEmpty(moduleInterfaces)) { + resource.setInterfaces(moduleInterfaces); } - return false; } - private boolean isAKnownOperation(String interfaceType, String operation) { - Either, ResponseFormat> interfaceLifecycleTypes = interfaceOperationBusinessLogic - .getAllInterfaceLifecycleTypes(); - if (interfaceLifecycleTypes.isRight() || interfaceLifecycleTypes.left().value() == null) { - return false; - } - - for (Entry interfaceLifecycleType : interfaceLifecycleTypes.left().value() - .entrySet()) { - if (interfaceTypeAndOperationMatches(interfaceLifecycleType, interfaceType, operation)) { - return true; + private Either createModuleInterface(final Object interfaceJson, final String model) { + try { + if (interfaceJson instanceof String) { + final InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); + interfaceDefinition.setType((String) interfaceJson); + return Either.left(interfaceDefinition); } - } - return false; - } - - private boolean interfaceTypeAndOperationMatches(Entry interfaceLifecycleType, - String interfaceType, String operation) { - if (interfaceLifecycleType.getKey().equalsIgnoreCase(interfaceType) - && interfaceLifecycleType.getValue().getOperations() != null) { - for (String interfaceLifecycleTypeOperation : interfaceLifecycleType.getValue().getOperations().keySet()) { - if (interfaceLifecycleTypeOperation != null && interfaceLifecycleTypeOperation - .equalsIgnoreCase(operation)) { - return true; - } + if (interfaceJson instanceof Map) { + final Map interfaceJsonMap = (Map) interfaceJson; + final InterfaceDefinition interfaceDefinition = interfaceDefinitionHandler.create(interfaceJsonMap, model); + return Either.left(interfaceDefinition); } + return Either.right(ResultStatusEnum.GENERAL_ERROR); + } catch (final Exception e) { + BeEcompErrorManager.getInstance().logBeSystemError("Import Resource- create interface"); + log.debug("error when creating interface, message:{}", e.getMessage(), e); + return Either.right(ResultStatusEnum.GENERAL_ERROR); } - return false; } private void setRequirements(Map toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null Either, ResultStatusEnum> toscaRequirements = ImportUtils - .findFirstToscaListElement(toscaJson, TypeUtils.ToscaTagNamesEnum.REQUIREMENTS); + .findFirstToscaListElement(toscaJson, ToscaTagNamesEnum.REQUIREMENTS); if (toscaRequirements.isLeft()) { List jsonRequirements = toscaRequirements.left().value(); Map> moduleRequirements = new HashMap<>(); // Checking for name duplication Set reqNames = new HashSet<>(); - // Getting flattened list of capabilities of parent node - cap name - // to cap type + // Getting flattened list of capabilities of parent node - cap name to cap type Map reqName2TypeMap = getReqName2Type(parentResource); for (Object jsonRequirementObj : jsonRequirements) { // Requirement @@ -577,15 +515,11 @@ public class ResourceImportManager { String requirementName = requirementJsonWrapper.keySet().iterator().next(); String reqNameLowerCase = requirementName.toLowerCase(); if (reqNames.contains(reqNameLowerCase)) { - log.debug( - "More than one requirement with same name {} (case-insensitive) in imported TOSCA file is invalid", - reqNameLowerCase); - throw new ByActionStatusComponentException(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, - "requirement", reqNameLowerCase); + log.debug("More than one requirement with same name {} (case-insensitive) in imported TOSCA file is invalid", reqNameLowerCase); + throw new ByActionStatusComponentException(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "requirement", reqNameLowerCase); } reqNames.add(reqNameLowerCase); - RequirementDefinition requirementDef = createRequirementFromImportFile(requirementJsonWrapper - .get(requirementName)); + RequirementDefinition requirementDef = createRequirementFromImportFile(requirementJsonWrapper.get(requirementName)); requirementDef.setName(requirementName); if (moduleRequirements.containsKey(requirementDef.getCapability())) { moduleRequirements.get(requirementDef.getCapability()).add(requirementDef); @@ -594,51 +528,39 @@ public class ResourceImportManager { list.add(requirementDef); moduleRequirements.put(requirementDef.getCapability(), list); } - // Validating against req/cap of "derived from" node - Boolean validateVsParentCap = validateCapNameVsDerived(reqName2TypeMap, requirementDef - .getCapability(), requirementDef.getName()); + Boolean validateVsParentCap = validateCapNameVsDerived(reqName2TypeMap, requirementDef.getCapability(), requirementDef.getName()); if (!validateVsParentCap) { String parentResourceName = parentResource != null ? parentResource.getName() : ""; - log.debug("Requirement with name {} already exists in parent {}", requirementDef.getName(), - parentResourceName); - throw new ByActionStatusComponentException(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, - "requirement", requirementDef - .getName() - .toLowerCase(), parentResourceName); + log.debug("Requirement with name {} already exists in parent {}", requirementDef.getName(), parentResourceName); + throw new ByActionStatusComponentException(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "requirement", + requirementDef.getName().toLowerCase(), parentResourceName); } } if (moduleRequirements.size() > 0) { resource.setRequirements(moduleRequirements); } - } } private RequirementDefinition createRequirementFromImportFile(Object requirementJson) { RequirementDefinition requirement = new RequirementDefinition(); - if (requirementJson instanceof String) { String requirementJsonString = (String) requirementJson; requirement.setCapability(requirementJsonString); } else if (requirementJson instanceof Map) { Map requirementJsonMap = (Map) requirementJson; - if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.CAPABILITY.getElementName())) { - requirement.setCapability( - (String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.CAPABILITY.getElementName())); + if (requirementJsonMap.containsKey(ToscaTagNamesEnum.CAPABILITY.getElementName())) { + requirement.setCapability((String) requirementJsonMap.get(ToscaTagNamesEnum.CAPABILITY.getElementName())); } - - if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.NODE.getElementName())) { - requirement.setNode((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.NODE.getElementName())); + if (requirementJsonMap.containsKey(ToscaTagNamesEnum.NODE.getElementName())) { + requirement.setNode((String) requirementJsonMap.get(ToscaTagNamesEnum.NODE.getElementName())); } - - if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.RELATIONSHIP.getElementName())) { - requirement.setRelationship( - (String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.RELATIONSHIP.getElementName())); + if (requirementJsonMap.containsKey(ToscaTagNamesEnum.RELATIONSHIP.getElementName())) { + requirement.setRelationship((String) requirementJsonMap.get(ToscaTagNamesEnum.RELATIONSHIP.getElementName())); } - if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) { - List occurrencesList = (List) requirementJsonMap - .get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName()); + if (requirementJsonMap.containsKey(ToscaTagNamesEnum.OCCURRENCES.getElementName())) { + List occurrencesList = (List) requirementJsonMap.get(ToscaTagNamesEnum.OCCURRENCES.getElementName()); validateOccurrences(occurrencesList); requirement.setMinOccurrences(occurrencesList.get(0).toString()); requirement.setMaxOccurrences(occurrencesList.get(1).toString()); @@ -649,70 +571,98 @@ public class ResourceImportManager { return requirement; } - private void setProperties(Map toscaJson, Resource resource) { - Map reducedToscaJson = new HashMap<>(toscaJson); + private void setProperties(final Map toscaJson, final Resource resource, + final Either existingResource) { + final Map reducedToscaJson = new HashMap<>(toscaJson); ImportUtils.removeElementFromJsonMap(reducedToscaJson, "capabilities"); - Either, ResultStatusEnum> properties = ImportUtils - .getProperties(reducedToscaJson); + final Either, ResultStatusEnum> properties = ImportUtils.getProperties(reducedToscaJson); if (properties.isLeft()) { - List propertiesList = new ArrayList<>(); - Map value = properties.left().value(); - if (value != null) { - for (Entry entry : value.entrySet()) { - String name = entry.getKey(); - if (!PROPERTY_NAME_PATTERN_IGNORE_LENGTH.matcher(name).matches()) { - log.debug("The property with invalid name {} occured upon import resource {}. ", name, - resource.getName()); - throw new ByActionStatusComponentException(componentsUtils - .convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, - JsonPresentationFields.PROPERTY)); + final Map propertyDefinitionMap = properties.left().value(); + if (MapUtils.isNotEmpty(propertyDefinitionMap)) { + final List propertiesList = new ArrayList<>(); + for (final Entry entry : propertyDefinitionMap.entrySet()) { + addPropertyToList(resource.getName(), propertiesList, entry); + } + if (existingResource.isLeft()) { + if ( CollectionUtils.isNotEmpty(existingResource.left().value().getProperties())) { + final List userCreatedResourceProperties = + existingResource.left().value().getProperties().stream() + .filter(PropertyDataDefinition::isUserCreated) + .filter(propertyDefinition -> !propertyDefinitionMap.containsKey(propertyDefinition.getName())) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(userCreatedResourceProperties)) { + propertiesList.addAll(userCreatedResourceProperties); + } } - PropertyDefinition propertyDefinition = entry.getValue(); - propertyDefinition.setName(name); - propertiesList.add(propertyDefinition); } + + resource.setProperties(propertiesList); } - resource.setProperties(propertiesList); } else if (properties.right().value() != ResultStatusEnum.ELEMENT_NOT_FOUND) { - throw new ByActionStatusComponentException(componentsUtils.convertFromResultStatusEnum(properties - .right() - .value(), JsonPresentationFields.PROPERTY)); + throw new ByActionStatusComponentException( + componentsUtils.convertFromResultStatusEnum(properties.right().value(), JsonPresentationFields.PROPERTY)); } } - private ResultStatusEnum setAttributes(Map toscaJson, Resource resource) { - ResultStatusEnum result = ResultStatusEnum.OK; - Either, ResultStatusEnum> attributes = ImportUtils - .getAttributes(toscaJson); - if (attributes.isLeft()) { - List attributeList = new ArrayList<>(); - Map value = attributes.left().value(); - if (value != null) { - for (Entry entry : value.entrySet()) { - String name = entry.getKey(); - AttributeDataDefinition attributeDef = entry.getValue(); - attributeDef.setName(name); - attributeList.add(attributeDef); - } + private void addPropertyToList(final String resourceName, + final List propertiesList, + final Entry entry) { + final String propertyName = entry.getKey(); + if (!PROPERTY_NAME_PATTERN_IGNORE_LENGTH.matcher(propertyName).matches()) { + log.debug("The property with invalid name {} occured upon import resource {}. ", propertyName, resourceName); + throw new ByActionStatusComponentException( + componentsUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, JsonPresentationFields.PROPERTY)); + } + final PropertyDefinition propertyDefinition = entry.getValue(); + propertyDefinition.setName(propertyName); + propertiesList.add(propertyDefinition); + } + + private void setAttributes(final Map originalToscaJsonMap, final Resource resource) { + final Map toscaJsonMap = new HashMap<>(originalToscaJsonMap); + ImportUtils.removeElementFromJsonMap(toscaJsonMap, "capabilities"); + final Either, ResultStatusEnum> getAttributeEither = ImportUtils.getAttributes(toscaJsonMap); + if (getAttributeEither.isRight()) { + final ResultStatusEnum resultStatus = getAttributeEither.right().value(); + if (resultStatus == ResultStatusEnum.ELEMENT_NOT_FOUND) { + return; } - resource.setAttributes(attributeList); - } else { - result = attributes.right().value(); + throw new ByActionStatusComponentException(componentsUtils.convertFromResultStatusEnum(resultStatus, JsonPresentationFields.ATTRIBUTES)); + } + final List attributeDefinitionList = new ArrayList<>(); + final Map attributeMap = getAttributeEither.left().value(); + if (MapUtils.isEmpty(attributeMap)) { + return; + } + for (final Entry entry : attributeMap.entrySet()) { + final String name = entry.getKey(); + if (!PROPERTY_NAME_PATTERN_IGNORE_LENGTH.matcher(name).matches()) { + log.debug("Detected attribute with invalid name '{}' during resource '{}' import. ", name, resource.getName()); + throw new ByActionStatusComponentException( + componentsUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_ATTRIBUTE_NAME, JsonPresentationFields.ATTRIBUTES)); + } + final AttributeDefinition attributeDefinition = entry.getValue(); + attributeDefinition.setName(name); + if (attributeDefinition.getEntry_schema() != null && attributeDefinition.getEntry_schema().getType() != null) { + attributeDefinition.setSchema(new SchemaDefinition()); + attributeDefinition.getSchema().setProperty(new PropertyDataDefinition()); + attributeDefinition.getSchema().getProperty().setType(entry.getValue().getEntry_schema().getType()); + } + attributeDefinitionList.add(attributeDefinition); } - return result; + resource.setAttributes(attributeDefinitionList); } private Resource setDerivedFrom(Map toscaJson, Resource resource) { Either toscaDerivedFromElement = ImportUtils - .findFirstToscaStringElement(toscaJson, TypeUtils.ToscaTagNamesEnum.DERIVED_FROM); + .findFirstToscaStringElement(toscaJson, ToscaTagNamesEnum.DERIVED_FROM); Resource derivedFromResource = null; if (toscaDerivedFromElement.isLeft()) { String derivedFrom = toscaDerivedFromElement.left().value(); log.debug("Derived from TOSCA name is {}", derivedFrom); resource.setDerivedFrom(Arrays.asList(new String[]{derivedFrom})); - Either latestByToscaResourceName = toscaOperationFacade - .getLatestByToscaResourceName(derivedFrom); - + Either latestByToscaResourceName = toscaOperationFacade.getLatestByToscaResourceName(derivedFrom, + resource.getModel()); if (latestByToscaResourceName.isRight()) { StorageOperationStatus operationStatus = latestByToscaResourceName.right().value(); if (operationStatus == StorageOperationStatus.NOT_FOUND) { @@ -720,8 +670,7 @@ public class ResourceImportManager { } log.debug("Error when fetching parent resource {}, error: {}", derivedFrom, operationStatus); ActionStatus convertFromStorageResponse = componentsUtils.convertFromStorageResponse(operationStatus); - BeEcompErrorManager.getInstance() - .logBeComponentMissingError("Import TOSCA YAML", "resource", derivedFrom); + BeEcompErrorManager.getInstance().logBeComponentMissingError("Import TOSCA YAML", "resource", derivedFrom); throw new ByActionStatusComponentException(convertFromStorageResponse, derivedFrom); } derivedFromResource = latestByToscaResourceName.left().value(); @@ -732,31 +681,26 @@ public class ResourceImportManager { private void setCapabilities(Map toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null Either, ResultStatusEnum> toscaCapabilities = ImportUtils - .findFirstToscaMapElement(toscaJson, TypeUtils.ToscaTagNamesEnum.CAPABILITIES); + .findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.CAPABILITIES); if (toscaCapabilities.isLeft()) { Map jsonCapabilities = toscaCapabilities.left().value(); Map> moduleCapabilities = new HashMap<>(); Iterator> capabilitiesNameValue = jsonCapabilities.entrySet().iterator(); Set capNames = new HashSet<>(); // Getting flattened list of capabilities of parent node - cap name + // to cap type Map capName2TypeMap = getCapName2Type(parentResource); while (capabilitiesNameValue.hasNext()) { Entry capabilityNameValue = capabilitiesNameValue.next(); - // Validating that no req/cap duplicates exist in imported YAML String capNameLowerCase = capabilityNameValue.getKey().toLowerCase(); if (capNames.contains(capNameLowerCase)) { - log.debug( - "More than one capability with same name {} (case-insensitive) in imported TOSCA file is invalid", - capNameLowerCase); - throw new ByActionStatusComponentException(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "capability", - capNameLowerCase); + log.debug("More than one capability with same name {} (case-insensitive) in imported TOSCA file is invalid", capNameLowerCase); + throw new ByActionStatusComponentException(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "capability", capNameLowerCase); } capNames.add(capNameLowerCase); - - CapabilityDefinition capabilityDef = createCapabilityFromImportFile(capabilityNameValue - .getValue()); + CapabilityDefinition capabilityDef = createCapabilityFromImportFile(capabilityNameValue.getValue()); capabilityDef.setName(capabilityNameValue.getKey()); if (moduleCapabilities.containsKey(capabilityDef.getType())) { moduleCapabilities.get(capabilityDef.getType()).add(capabilityDef); @@ -765,22 +709,18 @@ public class ResourceImportManager { list.add(capabilityDef); moduleCapabilities.put(capabilityDef.getType(), list); } - // Validating against req/cap of "derived from" node - Boolean validateVsParentCap = validateCapNameVsDerived(capName2TypeMap, capabilityDef - .getType(), capabilityDef.getName()); - + Boolean validateVsParentCap = validateCapNameVsDerived(capName2TypeMap, capabilityDef.getType(), capabilityDef.getName()); if (!validateVsParentCap) { // Here parentResource is for sure not null, so it's + // null-safe + // Check added to avoid sonar warning String parentResourceName = parentResource != null ? parentResource.getName() : ""; - log.debug("Capability with name {} already exists in parent {}", capabilityDef.getName(), - parentResourceName); - throw new ByActionStatusComponentException(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, - "capability", capabilityDef - .getName() - .toLowerCase(), parentResourceName); + log.debug("Capability with name {} already exists in parent {}", capabilityDef.getName(), parentResourceName); + throw new ByActionStatusComponentException(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "capability", + capabilityDef.getName().toLowerCase(), parentResourceName); } } if (moduleCapabilities.size() > 0) { @@ -799,12 +739,11 @@ public class ResourceImportManager { String nameLowerCase = capDefinition.getName().toLowerCase(); if (capName2type.get(nameLowerCase) != null) { String parentResourceName = parentResource.getName(); - log.debug("Resource with name {} has more than one capability with name {}, ignoring case", - parentResourceName, nameLowerCase); - BeEcompErrorManager.getInstance() - .logInternalDataError("Import resource", "Parent resource " + parentResourceName - + " of imported resource has one or more capabilities with name " + nameLowerCase, - ErrorSeverity.ERROR); + log.debug("Resource with name {} has more than one capability with name {}, ignoring case", parentResourceName, + nameLowerCase); + BeEcompErrorManager.getInstance().logInternalDataError("Import resource", + "Parent resource " + parentResourceName + " of imported resource has one or more capabilities with name " + + nameLowerCase, ErrorSeverity.ERROR); throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); } capName2type.put(nameLowerCase, capDefinition.getType()); @@ -825,12 +764,11 @@ public class ResourceImportManager { String nameLowerCase = reqDefinition.getName().toLowerCase(); if (reqName2type.get(nameLowerCase) != null) { String parentResourceName = parentResource.getName(); - log.debug("Resource with name {} has more than one requirement with name {}, ignoring case", - parentResourceName, nameLowerCase); - BeEcompErrorManager.getInstance() - .logInternalDataError("Import resource", "Parent resource " + parentResourceName - + " of imported resource has one or more requirements with name " + nameLowerCase, - ErrorSeverity.ERROR); + log.debug("Resource with name {} has more than one requirement with name {}, ignoring case", parentResourceName, + nameLowerCase); + BeEcompErrorManager.getInstance().logInternalDataError("Import resource", + "Parent resource " + parentResourceName + " of imported resource has one or more requirements with name " + + nameLowerCase, ErrorSeverity.ERROR); throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); } reqName2type.put(nameLowerCase, reqDefinition.getCapability()); @@ -841,26 +779,21 @@ public class ResourceImportManager { return reqName2type; } - private Boolean validateCapNameVsDerived(Map parentCapName2Type, String childCapabilityType, - String reqCapName) { + private Boolean validateCapNameVsDerived(Map parentCapName2Type, String childCapabilityType, String reqCapName) { String capNameLowerCase = reqCapName.toLowerCase(); log.trace("Validating capability {} vs parent resource", capNameLowerCase); String parentCapType = parentCapName2Type.get(capNameLowerCase); if (parentCapType != null) { if (childCapabilityType.equals(parentCapType)) { - log.debug( - "Capability with name {} is of same type {} for imported resource and its parent - this is OK", - capNameLowerCase, childCapabilityType); + log.debug("Capability with name {} is of same type {} for imported resource and its parent - this is OK", capNameLowerCase, + childCapabilityType); return true; } Either capabilityTypeDerivedFrom = capabilityTypeOperation .isCapabilityTypeDerivedFrom(childCapabilityType, parentCapType); if (capabilityTypeDerivedFrom.isRight()) { log.debug("Couldn't check whether imported resource capability derives from its parent's capability"); - throw new ByActionStatusComponentException( - componentsUtils.convertFromStorageResponse(capabilityTypeDerivedFrom - .right() - .value())); + throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(capabilityTypeDerivedFrom.right().value())); } return capabilityTypeDerivedFrom.left().value(); } @@ -868,76 +801,56 @@ public class ResourceImportManager { } private CapabilityDefinition createCapabilityFromImportFile(Object capabilityJson) { - CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); - if (capabilityJson instanceof String) { String capabilityJsonString = (String) capabilityJson; capabilityDefinition.setType(capabilityJsonString); } else if (capabilityJson instanceof Map) { Map capabilityJsonMap = (Map) capabilityJson; // Type - if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName())) { - capabilityDefinition - .setType((String) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName())); + if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) { + capabilityDefinition.setType((String) capabilityJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName())); } // ValidSourceTypes - if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName())) { - capabilityDefinition.setValidSourceTypes( - (List) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES - .getElementName())); + if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName())) { + capabilityDefinition + .setValidSourceTypes((List) capabilityJsonMap.get(ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName())); } // ValidSourceTypes - if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName())) { - capabilityDefinition.setDescription( - (String) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName())); + if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.DESCRIPTION.getElementName())) { + capabilityDefinition.setDescription((String) capabilityJsonMap.get(ToscaTagNamesEnum.DESCRIPTION.getElementName())); } - if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) { - List occurrencesList = (List) capabilityJsonMap - .get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName()); + if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.OCCURRENCES.getElementName())) { + List occurrencesList = (List) capabilityJsonMap.get(ToscaTagNamesEnum.OCCURRENCES.getElementName()); validateOccurrences(occurrencesList); capabilityDefinition.setMinOccurrences(occurrencesList.get(0).toString()); capabilityDefinition.setMaxOccurrences(occurrencesList.get(1).toString()); } - if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.PROPERTIES.getElementName())) { - - Either, ResultStatusEnum> propertiesRes = ImportUtils - .getProperties(capabilityJsonMap); + if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.PROPERTIES.getElementName())) { + Either, ResultStatusEnum> propertiesRes = ImportUtils.getProperties(capabilityJsonMap); if (propertiesRes.isRight()) { throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND); } else { - propertiesRes.left() - .value() - .entrySet() - .stream() - .forEach(e -> e.getValue().setName(e.getKey().toLowerCase())); - List capabilityProperties = propertiesRes.left() - .value() - .values() - .stream() - .map(p -> new ComponentInstanceProperty(p, p - .getDefaultValue(), null)) - .collect(Collectors.toList()); + propertiesRes.left().value().entrySet().stream().forEach(e -> e.getValue().setName(e.getKey().toLowerCase())); + List capabilityProperties = propertiesRes.left().value().values().stream() + .map(p -> new ComponentInstanceProperty(p, p.getDefaultValue(), null)).collect(Collectors.toList()); capabilityDefinition.setProperties(capabilityProperties); } } - } else if (!(capabilityJson instanceof List)) { throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML); } return capabilityDefinition; } - private void handleImportResourceException(UploadResourceInfo resourceMetaData, User user, boolean isNormative, - RuntimeException e) { + private void handleImportResourceException(UploadResourceInfo resourceMetaData, User user, boolean isNormative, RuntimeException e) { ResponseFormat responseFormat; ComponentException newException; if (e instanceof ComponentException) { ComponentException componentException = (ComponentException) e; responseFormat = componentException.getResponseFormat(); if (responseFormat == null) { - responseFormat = getResponseFormatManager() - .getResponseFormat(componentException.getActionStatus(), componentException.getParams()); + responseFormat = getResponseFormatManager().getResponseFormat(componentException.getActionStatus(), componentException.getParams()); } newException = componentException; } else { @@ -951,8 +864,7 @@ public class ResourceImportManager { throw newException; } - private void auditErrorImport(UploadResourceInfo resourceMetaData, User user, ResponseFormat errorResponseWrapper, - boolean isNormative) { + private void auditErrorImport(UploadResourceInfo resourceMetaData, User user, ResponseFormat errorResponseWrapper, boolean isNormative) { String version, lifeCycleState; if (isNormative) { version = TypeUtils.getFirstCertifiedVersionVersion(); @@ -960,85 +872,69 @@ public class ResourceImportManager { } else { version = ""; lifeCycleState = LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name(); - } - String message = ""; if (errorResponseWrapper.getMessageId() != null) { message = errorResponseWrapper.getMessageId() + ": "; } message += errorResponseWrapper.getFormattedMessage(); - AuditEventFactory factory = new AuditImportResourceAdminEventFactory( - CommonAuditData.newBuilder() - .status(errorResponseWrapper.getStatus()) - .description(message) - .requestId(ThreadLocalsHolder.getUuid()) - .build(), - new ResourceCommonInfo(resourceMetaData.getName(), ComponentTypeEnum.RESOURCE.getValue()), - ResourceVersionInfo.newBuilder() - .state(lifeCycleState) - .version(version) - .build(), - ResourceVersionInfo.newBuilder() - .state("") - .version("") - .build(), - "", user, ""); + CommonAuditData.newBuilder().status(errorResponseWrapper.getStatus()).description(message).requestId(ThreadLocalsHolder.getUuid()) + .build(), new ResourceCommonInfo(resourceMetaData.getName(), ComponentTypeEnum.RESOURCE.getValue()), + ResourceVersionInfo.newBuilder().state(lifeCycleState).version(version).build(), + ResourceVersionInfo.newBuilder().state("").version("").build(), "", user, ""); getAuditingManager().auditEvent(factory); + } + private void setResourceMetaData(Resource resource, String resourceYml, UploadResourceInfo resourceMetaData) { + Map ymlObj = new Yaml().load(resourceYml); + String toscaName = getToscaResourceName(ymlObj); + final Either latestByToscaName = toscaOperationFacade + .getLatestByToscaResourceName(toscaName, resourceMetaData.getModel()); + if (latestByToscaName.isLeft() && resourceMetaData instanceof DefaultUploadResourceInfo) { + setMetaDataFromLatestResource(resource, latestByToscaName.left().value()); + } else { + setMetaDataFromJson(resourceMetaData, resource); + } } private void setMetaDataFromJson(final UploadResourceInfo resourceMetaData, final Resource resource) { this.populateResourceMetadata(resourceMetaData, resource); resource.setCreatorUserId(resourceMetaData.getContactId()); - final String payloadData = resourceMetaData.getPayloadData(); if (payloadData != null) { resource.setToscaVersion(getToscaVersion(payloadData)); - resource.setAttributes(getAttributes(payloadData)); } - final List categories = resourceMetaData.getCategories(); calculateResourceIsAbstract(resource, categories); } - private List getAttributes(final String payloadData) { - final Map mappedToscaTemplate = decodePayload(payloadData); - - final List attributeDataDefinitionList = new ArrayList<>(); - - final Either, ResultStatusEnum> firstToscaMapElement = ImportUtils - .findFirstToscaMapElement(mappedToscaTemplate, ToscaTagNamesEnum.ATTRIBUTES); - if (firstToscaMapElement.isRight()) { - return attributeDataDefinitionList; - } - final Map attributes = firstToscaMapElement.left().value(); - - final Iterator> propertiesNameValue = attributes.entrySet().iterator(); - while (propertiesNameValue.hasNext()) { - final Entry attributeNameValue = propertiesNameValue.next(); - final Object value = attributeNameValue.getValue(); - final String key = attributeNameValue.getKey(); - if (value instanceof Map) { - - final Map attributeMap = (Map) value; - - final AttributeDefinition attributeDefinition = new AttributeDefinition(); - attributeDefinition.setName(key); - - setField(attributeMap, ToscaTagNamesEnum.DESCRIPTION, attributeDefinition::setDescription); - setField(attributeMap, ToscaTagNamesEnum.TYPE, attributeDefinition::setType); - setField(attributeMap, ToscaTagNamesEnum.STATUS, attributeDefinition::setStatus); - setField(attributeMap, ToscaTagNamesEnum.ENTRY_SCHEMA, attributeDefinition::setEntry_schema); - attributeDataDefinitionList.add(attributeDefinition); - } else { - final AttributeDefinition attributeDefinition = new AttributeDefinition(); - attributeDefinition.setName(key); - attributeDataDefinitionList.add(attributeDefinition); + private void setMetaDataFromLatestResource(Resource resource, Resource latestResource) { + if (resource != null && latestResource != null) { + resource.setCreatorUserId(latestResource.getContactId()); + resource.setDescription(latestResource.getDescription()); + resource.setTags(latestResource.getTags()); + resource.setCategories(latestResource.getCategories()); + resource.setContactId(latestResource.getContactId()); + resource.setName(latestResource.getName()); + resource.setIcon(latestResource.getIcon()); + resource.setResourceVendorModelNumber(latestResource.getResourceVendorModelNumber()); + resource.setResourceType(latestResource.getResourceType()); + if (latestResource.getVendorName() != null) { + resource.setVendorName(latestResource.getVendorName()); + } + if (latestResource.getVendorRelease() != null) { + resource.setVendorRelease(latestResource.getVendorRelease()); + } + if (latestResource.getModel() != null) { + resource.setModel(latestResource.getModel()); } + if (latestResource.getToscaVersion() != null) { + resource.setToscaVersion(latestResource.getToscaVersion()); + } + final List categories = latestResource.getCategories(); + calculateResourceIsAbstract(resource, categories); } - return attributeDataDefinitionList; } private Map decodePayload(final String payloadData) { @@ -1048,8 +944,8 @@ public class ResourceImportManager { private String getToscaVersion(final String payloadData) { final Map mappedToscaTemplate = decodePayload(payloadData); - final Either findFirstToscaStringElement = - ImportUtils.findFirstToscaStringElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION); + final Either findFirstToscaStringElement = ImportUtils + .findFirstToscaStringElement(mappedToscaTemplate, ToscaTagNamesEnum.TOSCA_VERSION); if (findFirstToscaStringElement.isLeft()) { return findFirstToscaStringElement.left().value(); } else { @@ -1057,23 +953,11 @@ public class ResourceImportManager { } } - private Map getDataTypes(final String payloadData) { - final Map mappedToscaTemplate = decodePayload(payloadData); - final Either, ResultStatusEnum> findFirstToscaStringElement = - ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, ToscaTagNamesEnum.DATA_TYPES); - if (findFirstToscaStringElement.isLeft()) { - return findFirstToscaStringElement.left().value(); - } else { - return Collections.EMPTY_MAP; - } - } - private void calculateResourceIsAbstract(Resource resource, List categories) { if (categories != null && !categories.isEmpty()) { CategoryDefinition categoryDef = categories.get(0); resource.setAbstract(false); - if (categoryDef != null && categoryDef.getName() != null && categoryDef.getName() - .equals(Constants.ABSTRACT_CATEGORY_NAME)) { + if (categoryDef != null && categoryDef.getName() != null && categoryDef.getName().equals(Constants.ABSTRACT_CATEGORY_NAME)) { SubCategoryDefinition subCategoryDef = categoryDef.getSubcategories().get(0); if (subCategoryDef != null && subCategoryDef.getName().equals(Constants.ABSTRACT_SUBCATEGORY)) { resource.setAbstract(true); @@ -1097,16 +981,13 @@ public class ResourceImportManager { resource.setHighestVersion(ImportUtils.Constants.NORMATIVE_TYPE_HIGHEST_VERSION); resource.setVendorName(ImportUtils.Constants.VENDOR_NAME); resource.setVendorRelease(ImportUtils.Constants.VENDOR_RELEASE); - } private void validateOccurrences(List occurrensesList) { - if (!ValidationUtils.validateListNotEmpty(occurrensesList)) { log.debug("Occurrenses list empty"); throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES); } - if (occurrensesList.size() < 2) { log.debug("Occurrenses list size not 2"); throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES); @@ -1125,7 +1006,6 @@ public class ResourceImportManager { log.debug("Invalid occurrenses format.low_bound occurrense negative {}", minOccurrences); throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES); } - if (maxObj instanceof String) { if (!"UNBOUNDED".equals(maxObj)) { log.debug("Invalid occurrenses format. Max occurrence is {}", maxObj); @@ -1138,10 +1018,8 @@ public class ResourceImportManager { log.debug("Invalid occurrenses format. Max occurrence is {}", maxObj); throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES); } - - if (maxOccurrences <= 0 || maxOccurrences < minOccurrences) { - log.debug("Invalid occurrenses format. min occurrence is {}, Max occurrence is {}", minOccurrences, - maxOccurrences); + if (maxOccurrences < 0 || maxOccurrences < minOccurrences) { + log.debug("Invalid occurrenses format. min occurrence is {}, Max occurrence is {}", minOccurrences, maxOccurrences); throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES); } } @@ -1170,10 +1048,19 @@ public class ResourceImportManager { return servletContext; } + public void setServletContext(ServletContext servletContext) { + this.servletContext = servletContext; + } + public AuditingManager getAuditingManager() { return auditingManager; } + @Autowired + public void setAuditingManager(AuditingManager auditingManager) { + this.auditingManager = auditingManager; + } + public ResponseFormatManager getResponseFormatManager() { return responseFormatManager; } @@ -1191,11 +1078,6 @@ public class ResourceImportManager { this.resourceBusinessLogic = resourceBusinessLogic; } - @Autowired - public void setInterfaceOperationBusinessLogic(InterfaceOperationBusinessLogic interfaceOperationBusinessLogic) { - this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic; - } - public IGraphLockOperation getGraphLockOperation() { return graphLockOperation; } @@ -1205,31 +1087,21 @@ public class ResourceImportManager { this.graphLockOperation = graphLockOperation; } - public void setServletContext(ServletContext servletContext) { - this.servletContext = servletContext; - } - - @Autowired - public void setAuditingManager(AuditingManager auditingManager) { - this.auditingManager = auditingManager; - } - private List extractDataTypeFromJson(final ResourceBusinessLogic resourceBusinessLogic, - final Map foundElements) { + final Map foundElements, + final String model) { final List dataTypeDefinitionList = new ArrayList<>(); if (MapUtils.isNotEmpty(foundElements)) { final Either, JanusGraphOperationStatus> dataTypeCacheAll = - resourceBusinessLogic.dataTypeCache.getAll(); + resourceBusinessLogic.applicationDataTypeCache.getAll(model); if (dataTypeCacheAll.isLeft()) { for (final Entry attributeNameValue : foundElements.entrySet()) { final Object value = attributeNameValue.getValue(); if (value instanceof Map) { - final DataTypeDefinition dataTypeDefinition = - createDataTypeDefinitionWithName(attributeNameValue); - final DataTypeDefinition dataTypeDefinitionParent = - dataTypeCacheAll.left().value().get(dataTypeDefinition.getDerivedFromName()); + final DataTypeDefinition dataTypeDefinition = createDataTypeDefinitionWithName(attributeNameValue); + final DataTypeDefinition dataTypeDefinitionParent = dataTypeCacheAll.left().value() + .get(dataTypeDefinition.getDerivedFromName()); dataTypeDefinition.setDerivedFrom(dataTypeDefinitionParent); - dataTypeDefinitionList.add(dataTypeDefinition); } else { dataTypeDefinitionList.add(createDataType(String.valueOf(value)));