diff options
author | MichaelMorris <michael.morris@est.tech> | 2022-02-27 08:48:31 +0000 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2022-02-28 19:23:12 +0000 |
commit | 7f07f514eacacfb54d851201c49b24acd9b5e343 (patch) | |
tree | 52131ea73a467c4a9d4bdac55a2ac22aec2c37ee /catalog-be/src/main/java/org | |
parent | 5eec3c5ec841aaca0a64e10028197a47ed2acbc6 (diff) |
Fix error when no derived_from type
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-3889
Change-Id: I1f272a658137a79a545ec90e9256267e8ef7325e
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 8c97a04a74..77d17ca76a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -3748,9 +3748,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (newResource.getResourceType().isAtomicType() && !newResource.getName().equals("Root") && newResource.getResourceType() != ResourceTypeEnum.CVFC) { ResourceTypeEnum updatedResourceType = newResource.getResourceType(); - Component derivedFromResource = getParentComponent(newResource); - if (derivedFromResource.getComponentType() == ComponentTypeEnum.RESOURCE) { - Resource parentResource = (Resource) derivedFromResource; + Optional<Component> derivedFromResourceOptional = getParentComponent(newResource); + if (derivedFromResourceOptional.isPresent() && derivedFromResourceOptional.get().getComponentType() == ComponentTypeEnum.RESOURCE) { + Resource parentResource = (Resource) derivedFromResourceOptional.get(); if (!(parentResource.isAbstract() && (ResourceTypeEnum.VFC == parentResource.getResourceType() || ResourceTypeEnum.ABSTRACT == parentResource.getResourceType())) && parentResource.getResourceType() != updatedResourceType && oldResource.getResourceType() != updatedResourceType) { @@ -3765,7 +3765,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } - private Component getParentComponent(Resource newResource) { + private Optional<Component> getParentComponent(Resource newResource) { + if (newResource.getDerivedFrom() == null) { + return Optional.empty(); + } String toscaResourceNameDerivedFrom = newResource.getDerivedFrom().get(0); Either<Component, StorageOperationStatus> latestByToscaResourceName = toscaOperationFacade .getLatestByToscaResourceName(toscaResourceNameDerivedFrom, newResource.getModel()); @@ -3775,7 +3778,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.debug("#mergeOldResourceMetadataWithNew - derived from resource {} not found", toscaResourceNameDerivedFrom); throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NOT_FOUND, toscaResourceNameDerivedFrom); } - return latestByToscaResourceName.left().value(); + return Optional.of(latestByToscaResourceName.left().value()); } private Resource prepareResourceForUpdate(Resource oldResource, Resource newResource, User user, boolean inTransaction, boolean needLock) { |