From cafd0137bce8c5f5344a2b8d249904503e0c1af3 Mon Sep 17 00:00:00 2001 From: biniek Date: Thu, 5 Apr 2018 11:09:10 +0200 Subject: Added creating WorkflowException in pnf-pnp Change-Id: I3cd5932913e58983c85e63c84c5136d04b0489e8 Issue-ID: SO-506 Signed-off-by: biniek --- .../delegate/CheckAaiForCorrelationIdDelegate.java | 12 ++++------- .../pnf/delegate/ExecutionVariableNames.java | 3 +++ .../pnf/implementation/AaiResponse.java | 23 ++++++++++------------ .../CheckAaiForCorrelationIdImplementation.java | 13 ++++++------ 4 files changed, 23 insertions(+), 28 deletions(-) (limited to 'bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso') diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java index f4483f5923..417bb4668e 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java @@ -28,6 +28,7 @@ import java.io.IOException; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil; import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiConnection; import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiResponse; import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.CheckAaiForCorrelationIdImplementation; @@ -58,21 +59,16 @@ public class CheckAaiForCorrelationIdDelegate implements JavaDelegate { public void execute(DelegateExecution execution) throws Exception { String correlationId = (String) execution.getVariable(CORRELATION_ID); if (correlationId == null) { - //todo: fix Execution -> DelegateExecution in ALL groovy scripts -// new ExceptionUtil().buildAndThrowWorkflowException(execution, 500, CORRELATION_ID + " is not set"); - throw new BpmnError("MSOWorkflowException"); + new ExceptionUtil().buildAndThrowWorkflowException(execution, 500, CORRELATION_ID + " is not set"); } try { AaiResponse aaiResponse = implementation.check(correlationId, aaiConnection); execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, aaiResponse.getContainsInfoAboutPnf()); - aaiResponse.getContainsInfoAboutIp().ifPresent( - isIp -> execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, isIp) - ); + execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, aaiResponse.getContainsInfoAboutIp()); } catch (IOException e) { - //todo: log this - throw new BpmnError("MSOWorkflowException"); + new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, e.getMessage()); } } } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java index 6b49908a0f..0d64f2c8b7 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java @@ -23,6 +23,9 @@ package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; @SuppressWarnings("ALL") public class ExecutionVariableNames { + private ExecutionVariableNames() { + } + public final static String CORRELATION_ID = "correlationId"; public final static String AAI_CONTAINS_INFO_ABOUT_PNF = "aaiContainsInfoAboutPnf"; public final static String AAI_CONTAINS_INFO_ABOUT_IP = "aaiContainsInfoAboutIp"; diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java index bbb7adc143..5fb7a43e00 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java @@ -24,28 +24,25 @@ import java.util.Optional; import javax.annotation.Nullable; import javax.validation.constraints.NotNull; -public class AaiResponse { +public enum AaiResponse { + NO_ENTRY(false, false), + ENTRY_NO_IP(true, false), + ENTRY_WITH_IP(true, true); - private Boolean containsInfoAboutPnf; - private Boolean containsInfoAboutIp; - private String ipAddress; + private boolean containsInfoAboutPnf; + private boolean containsInfoAboutIp; - public AaiResponse(@NotNull Boolean containsInfoAboutPnf, @Nullable Boolean containsInfoAboutIp, - @Nullable String ipAddress) { + AaiResponse(boolean containsInfoAboutPnf, boolean containsInfoAboutIp) { this.containsInfoAboutPnf = containsInfoAboutPnf; this.containsInfoAboutIp = containsInfoAboutIp; - this.ipAddress = ipAddress; } - public Boolean getContainsInfoAboutPnf() { + public boolean getContainsInfoAboutPnf() { return containsInfoAboutPnf; } - public Optional getContainsInfoAboutIp() { - return Optional.ofNullable(containsInfoAboutIp); + public boolean getContainsInfoAboutIp() { + return containsInfoAboutIp; } - public Optional getIpAddress() { - return Optional.ofNullable(ipAddress); - } } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java index 353a3bd5d3..b982a693da 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java @@ -29,15 +29,14 @@ public class CheckAaiForCorrelationIdImplementation { public AaiResponse check(String correlationId, AaiConnection aaiConnection) throws IOException { Optional pnf = aaiConnection.getEntryFor(correlationId); if (!pnf.isPresent()) { - return new AaiResponse(false, null, null); + return AaiResponse.NO_ENTRY; } - Optional ip = extractIp(pnf.get()); - return ip.map( - s -> new AaiResponse(true, true, s) - ).orElseGet( - () -> new AaiResponse(true, false, null) - ); + if(extractIp(pnf.get()).isPresent()) { + return AaiResponse.ENTRY_WITH_IP; + } else { + return AaiResponse.ENTRY_NO_IP; + } } private Optional extractIp(Pnf pnf) { -- cgit 1.2.3-korg