summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-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()