aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org
diff options
context:
space:
mode:
authorChris André <chris.andre@yoppworks.com>2020-04-23 22:24:36 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-24 07:04:43 +0000
commitd426d3a68f0cd5313cc7d543f74af97580e59493 (patch)
tree1528ff52c1248238f61191596a1b4d9c5b2be021 /catalog-model/src/main/java/org
parent0a65c2fe97240e892c8c65af2c9e6048aa350857 (diff)
Work around potential NullPointerExceptions in ToscaElementLifecycleOperation
- Rewrite of `checkinToscaELement` - Extracted methods from `checkinToscaELement` Issue-ID: SDC-2964 Signed-off-by: Chris Andre <chris.andre@yoppworks.com> Change-Id: I99d2c5aaa73b955ef5aa60eeb7644bb47ac12bd6
Diffstat (limited to 'catalog-model/src/main/java/org')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementLifecycleOperation.java70
1 files changed, 44 insertions, 26 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementLifecycleOperation.java
index 6ae99aeb1a..273d5001f6 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementLifecycleOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementLifecycleOperation.java
@@ -38,7 +38,6 @@ import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.dao.jsongraph.utils.IdBuilderUtils;
import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils;
-import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.datatypes.elements.*;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
@@ -85,34 +84,53 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
* @param ownerId
* @return
*/
- public Either<ToscaElement, StorageOperationStatus> checkinToscaELement(LifecycleStateEnum currState, String toscaElementId, String modifierId, String ownerId) {
- Either<GraphVertex, StorageOperationStatus> updateResult = null;
- Either<ToscaElement, StorageOperationStatus> result = null;
- Map<String, GraphVertex> vertices = null;
- ToscaElementOperation operation;
+ public Either<ToscaElement, StorageOperationStatus> checkinToscaELement(LifecycleStateEnum currState,
+ String toscaElementId, String modifierId, String ownerId) {
try {
- Either<Map<String, GraphVertex>, JanusGraphOperationStatus> getVerticesRes = janusGraphDao
- .getVerticesByUniqueIdAndParseFlag(prepareParametersToGetVerticesForCheckin(toscaElementId, modifierId, ownerId));
- if (getVerticesRes.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_GET_VERTICES, toscaElementId);
- updateResult = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getVerticesRes.right().value()));
- } else {
- vertices = getVerticesRes.left().value();
- updateResult = checkinToscaELement(currState, vertices.get(toscaElementId), vertices.get(ownerId), vertices.get(modifierId), LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- }
- if (updateResult.isLeft()) {
- operation = getToscaElementOperation(vertices.get(toscaElementId).getLabel());
- result = operation.getToscaElement(updateResult.left().value().getUniqueId());
- if (result.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated tosca element {}. Status is {}", toscaElementId, result.right().value());
- }
- } else {
- result = Either.right(updateResult.right().value());
- }
+ return janusGraphDao
+ .getVerticesByUniqueIdAndParseFlag(
+ prepareParametersToGetVerticesForCheckin(toscaElementId, modifierId, ownerId))
+ .right().map(status -> handleFailureToPrepareParameters(status, toscaElementId))
+ .left().bind(
+ verticesMap ->
+ checkinToscaELement(
+ currState,
+ verticesMap.get(toscaElementId),
+ verticesMap.get(ownerId),
+ verticesMap.get(modifierId),
+ LifecycleStateEnum.NOT_CERTIFIED_CHECKIN
+ ).left().bind(checkinResult -> {
+ //We retrieve the operation
+ ToscaElementOperation operation =
+ getToscaElementOperation(verticesMap.get(toscaElementId).getLabel());
+
+ //We retrieve the ToscaElement from the operation
+ return getToscaElementFromOperation(operation, checkinResult.getUniqueId(), toscaElementId);
+ })
+ );
} catch (Exception e) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Exception occured during checkin of tosca element {}. {} ", toscaElementId, e.getMessage());
+ CommonUtility.addRecordToLog(
+ log, LogLevelEnum.DEBUG, "Exception occurred during checkin of tosca element {}. {} ", toscaElementId,
+ e.getMessage());
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
}
- return result;
+ }
+
+ static StorageOperationStatus handleFailureToPrepareParameters(final JanusGraphOperationStatus status, final String toscaElementId) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_GET_VERTICES, toscaElementId);
+ return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status);
+ }
+
+ static Either<ToscaElement, StorageOperationStatus> getToscaElementFromOperation(final ToscaElementOperation operation,
+ final String uniqueId, final String toscaElementId) {
+ return operation.getToscaElement(uniqueId)
+ .right().map(status -> {
+ //We log a potential error we got while retrieving the ToscaElement
+ CommonUtility
+ .addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated tosca element {}. Status is {}",
+ toscaElementId, status);
+ return status;
+ });
}
/**