diff options
author | 2021-05-18 20:57:07 +0100 | |
---|---|---|
committer | 2021-07-05 14:36:03 +0000 | |
commit | 6047cd212696f5260d1296ce1fc3449dadb6005d (patch) | |
tree | 06812f8814816ade1442ca0393a91f09655f4fd1 /catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java | |
parent | b835031b83230c36649c6e77787867a465e0ac47 (diff) |
Support for associating node types to models
Issue-ID: SDC-3597
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Change-Id: Icd0066240b78ba98d8f0efab66d11756f18cb251
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java | 46 |
1 files changed, 33 insertions, 13 deletions
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 b1841e55d8..77d8f897e7 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 @@ -171,19 +171,7 @@ public class ResourceImportManager { setMetaDataFromJson(resourceMetaData, resource); populateResourceFromYaml(resourceYml, resource); validationFunction.apply(resource); - if (!createNewVersion) { - Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resource.getName()); - if (latestByName.isLeft()) { - throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource.getName()); - } - } else if (!isCsarPresent(csarInfo)) { - final Either<Resource, StorageOperationStatus> component = toscaOperationFacade - .getComponentByNameAndVendorRelease(resource.getComponentType(), resource.getName(), resource.getVendorRelease(), - JsonParseFlagEnum.ParseAll); - if (component.isLeft()) { - throw new ByActionStatusComponentException(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, resource.getName()); - } - } + checkResourceExistsBeforeCreate(createNewVersion, csarInfo, resource); resource = resourceBusinessLogic .createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock, csarInfo, nodeName, isNested).left; Resource changeStateResponse; @@ -210,6 +198,35 @@ public class ResourceImportManager { return responsePair; } + private void checkResourceExistsBeforeCreate(final boolean createNewVersion, final CsarInfo csarInfo, final Resource resource) { + final String resourceName = resource.getName(); + final String model = resource.getModel(); + final Either<Resource, StorageOperationStatus> latestByToscaName = toscaOperationFacade + .getLatestByToscaResourceNameAndModel(resourceName, model); + if (latestByToscaName.isLeft()) { + final Resource foundResource = latestByToscaName.left().value(); + validateComponentWithModelExist(resourceName, model, foundResource); + if (!createNewVersion) { + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resourceName); + } + if (!isCsarPresent(csarInfo)) { + final Either<Resource, StorageOperationStatus> component = toscaOperationFacade + .getComponentByNameAndVendorRelease(resource.getComponentType(), resource.getName(), resource.getVendorRelease(), + JsonParseFlagEnum.ParseAll); + if (component.isLeft()) { + validateComponentWithModelExist(resourceName, model, foundResource); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, resource.getName()); + } + } + } + } + + private void validateComponentWithModelExist(final String resourceName, final String model, final Resource foundResource) { + if (model != null && toscaOperationFacade.isNodeAssociatedToModel(model, foundResource).isPresent()) { + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_MODEL_ALREADY_EXIST, resourceName, model); + } + } + private boolean isCsarPresent(final CsarInfo csarInfo) { return csarInfo != null && StringUtils.isNotEmpty(csarInfo.getCsarUUID()); } @@ -246,6 +263,9 @@ public class ResourceImportManager { if (resourceMetaData.getVendorRelease() != null) { resource.setVendorRelease(resourceMetaData.getVendorRelease()); } + if (resourceMetaData.getModel() != null) { + resource.setModel(resourceMetaData.getModel()); + } } } |