summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-05-08 18:45:14 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-27 06:40:43 +0000
commit9373e4f17236dc7496cd7dcfbbd159675e839e55 (patch)
tree1d20df6e554a9e73ac116fffa5ab50ffebc6c204 /catalog-be/src/main
parent66a5398f95f8c60a41ffa81f46ccee95beb34822 (diff)
Add ArtifactsBusinessLogic::fetchLatestComponentMetadata
Signed-off-by: Francis Toth <francis.toth@yoppworks.com> Change-Id: Ibb8621a91551a2e4ffcac1145f85ed7983063d02 Issue-ID: SDC-2812
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java90
1 files changed, 47 insertions, 43 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index c56517c0af..17f8bdef48 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -3958,13 +3958,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
- Either<ComponentMetadataData, StorageOperationStatus> getComponentRes =
- toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
- if (getComponentRes.isRight()) {
- StorageOperationStatus status = getComponentRes.right().value();
- log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status, componentType), componentUuid);
- }
+ Either<ComponentMetadataData, ActionStatus> getComponentRes =
+ fetchLatestComponentMetadataOrThrow(componentType, componentUuid);
ComponentMetadataDataDefinition componentMetadataDataDefinition = getComponentRes.left().value().getMetadataDataDefinition();
componentId = componentMetadataDataDefinition.getUniqueId();
@@ -4007,12 +4002,9 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String userId = request.getHeader(Constants.USER_ID_HEADER);
ImmutablePair<Component, ComponentInstance> componentRiPair = null;
- Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
- if (getComponentRes.isRight()) {
- StorageOperationStatus status = getComponentRes.right().value();
- log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status, componentType), resourceInstanceName);
- }
+
+ Either<ComponentMetadataData, ActionStatus> getComponentRes =
+ fetchLatestComponentMetadataOrThrow(componentType, componentUuid, resourceInstanceName);
if (!getComponentRes.left()
.value()
.getMetadataDataDefinition()
@@ -4062,12 +4054,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
- Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
- if (getComponentRes.isRight()) {
- StorageOperationStatus status = getComponentRes.right().value();
- log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
- }
+ Either<ComponentMetadataData, ActionStatus> getComponentRes =
+ fetchLatestComponentMetadataOrThrow(componentType, componentUuid);
componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName();
@@ -4119,12 +4107,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String userId = request.getHeader(Constants.USER_ID_HEADER);
ImmutablePair<Component, ComponentInstance> componentRiPair = null;
- Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
- if (getComponentRes.isRight()) {
- StorageOperationStatus status = getComponentRes.right().value();
- log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
- }
+ Either<ComponentMetadataData, ActionStatus> getComponentRes =
+ fetchLatestComponentMetadataOrThrow(componentType, componentUuid);
if (!getComponentRes.left()
.value()
.getMetadataDataDefinition()
@@ -4229,11 +4213,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
ArtifactDefinition existingArtifactInfo = null;
String interfaceName = null;
- Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
- if (getComponentRes.isRight()) {
- StorageOperationStatus status = getComponentRes.right().value();
- log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ Either<ComponentMetadataData, ActionStatus> getComponentRes =
+ fetchLatestComponentMetadata(componentType, componentUuid).right().map(as -> {
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(as));
+ return as;
+ });
+
+ if(getComponentRes.isRight()) {
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(getComponentRes.right().value()));
}
if (errorWrapper.isEmpty()) {
@@ -4309,6 +4296,32 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return updateArtifactResult;
}
+
+ private Either<ComponentMetadataData, ActionStatus> fetchLatestComponentMetadataOrThrow(
+ ComponentTypeEnum componentType, String componentUuid
+ ) {
+ return fetchLatestComponentMetadataOrThrow(componentType, componentUuid, componentUuid);
+ }
+
+ private Either<ComponentMetadataData, ActionStatus> fetchLatestComponentMetadataOrThrow(
+ ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName
+ ) {
+ return fetchLatestComponentMetadata(componentType, componentUuid).right().map(as -> {
+ throw new ByActionStatusComponentException(as, resourceInstanceName);
+ });
+ }
+
+ private Either<ComponentMetadataData, ActionStatus> fetchLatestComponentMetadata(
+ ComponentTypeEnum componentType, String componentUuid
+ ) {
+ return toscaOperationFacade
+ .getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true)
+ .right().map(sos -> {
+ log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, sos);
+ return componentsUtils.convertFromStorageResponse(sos, componentType);
+ });
+ }
+
private Either<String, ResponseFormat> fetchInterfaceName(String componentId, String interfaceUUID) {
Either<Component, StorageOperationStatus> componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(componentId);
if (componentStorageOperationStatusEither.isRight()) {
@@ -4347,12 +4360,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
- Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
- if (getComponentRes.isRight()) {
- StorageOperationStatus status = getComponentRes.right().value();
- log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status, componentType), componentUuid);
- }
+ Either<ComponentMetadataData, ActionStatus> getComponentRes =
+ fetchLatestComponentMetadataOrThrow(componentType, componentUuid);
componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName();
if (!getComponentRes.left()
@@ -4395,13 +4404,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
ImmutablePair<Component, ComponentInstance> componentRiPair = null;
- Either<ComponentMetadataData, StorageOperationStatus> getComponentRes =
- toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
- if (getComponentRes.isRight()) {
- StorageOperationStatus status = getComponentRes.right().value();
- log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
- }
+ Either<ComponentMetadataData, ActionStatus> getComponentRes =
+ fetchLatestComponentMetadataOrThrow(componentType, componentUuid);
if (!getComponentRes.left()
.value()
.getMetadataDataDefinition()