use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException in project so by onap.
the class AaiResourceIdValidator method validateVnfResourceIdInAAI.
protected String validateVnfResourceIdInAAI(String generatedResourceId, String instanceName, RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
Optional<GenericVnf> vnf = bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName);
if (vnf.isPresent()) {
if (vnf.get().getModelCustomizationId().equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
return vnf.get().getVnfId();
} else {
throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, instanceName, vnf.get().getModelCustomizationId()));
}
}
GenericVnfs vnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(instanceName);
if (vnfs != null) {
throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, vnfs.getGenericVnf().get(0).getVnfId()));
}
return generatedResourceId;
}
use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException in project so by onap.
the class AaiResourceIdValidator method validateServiceResourceIdInAAI.
protected String validateServiceResourceIdInAAI(String generatedResourceId, String instanceName, RequestDetails reqDetails) throws DuplicateNameException {
String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId();
String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType();
if (instanceName != null) {
Optional<ServiceInstance> serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, instanceName);
if (serviceInstanceAAI.isPresent()) {
if (serviceInstanceAAI.get().getModelVersionId().equalsIgnoreCase(reqDetails.getModelInfo().getModelVersionId())) {
return serviceInstanceAAI.get().getServiceInstanceId();
} else {
throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_VERSION_ID, instanceName, reqDetails.getModelInfo().getModelVersionId()));
}
} else {
ServiceInstances aaiServiceInstances = bbInputSetupUtils.getAAIServiceInstancesGloballyByName(instanceName);
if (aaiServiceInstances != null) {
if (aaiServiceInstances.getServiceInstance() != null && !aaiServiceInstances.getServiceInstance().isEmpty()) {
if (aaiServiceInstances.getServiceInstance().size() > 1) {
throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_MULTIPLE, instanceName));
} else {
ServiceInstance si = aaiServiceInstances.getServiceInstance().stream().findFirst().get();
Map<String, String> keys = bbInputSetupUtils.getURIKeysFromServiceInstance(si.getServiceInstanceId());
throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_COMBINATION, instanceName, keys.get(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId), keys.get(AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType), si.getModelVersionId()));
}
}
}
}
}
return generatedResourceId;
}
use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException in project so by onap.
the class WorkflowActionTest method selectExecutionListDuplicateNameExceptionTest.
@Test
public void selectExecutionListDuplicateNameExceptionTest() throws Exception {
String gAction = "createInstance";
String bpmnRequest = readBpmnRequestFromFile(MACRO_ASSIGN_JSON);
initExecution(gAction, bpmnRequest, true);
execution.setVariable("requestUri", "v6/serviceInstances");
doThrow(new DuplicateNameException("serviceInstance with name (instanceName) and different version id (3c40d244-808e-42ca-b09a-256d83d19d0a) already exists. The name must be unique.")).when(aaiResourceIdValidator).validateResourceIdInAAI(anyString(), eq(WorkflowType.SERVICE), eq("test"), any(RequestDetails.class), any(WorkflowResourceIds.class));
SPY_workflowAction.selectExecutionList(execution);
assertEquals(execution.getVariable("WorkflowActionErrorMessage"), "Exception while setting execution list. serviceInstance with name (instanceName) and different version id (3c40d244-808e-42ca-b09a-256d83d19d0a) already exists. The name must be unique.");
// verify default values are present in failure case
assertEquals(true, execution.getVariable("isTopLevelFlow"));
assertEquals(false, execution.getVariable("sentSyncResponse"));
}
Aggregations