Search in sources :

Example 26 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class ServiceInstances method configurationRecipeLookup.

private Response configurationRecipeLookup(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri) throws ApiException {
    String serviceInstanceId;
    Boolean aLaCarte = null;
    String apiVersion = version.substring(1);
    ServiceInstancesRequest sir;
    sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
    String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri);
    InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope);
    if (sir.getRequestDetails().getRequestParameters() != null) {
        aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
    }
    requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq);
    requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
    String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
    requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, instanceName);
    ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
    RequestReferences referencesResponse = new RequestReferences();
    referencesResponse.setRequestId(requestId);
    serviceResponse.setRequestReferences(referencesResponse);
    String orchestrationUri = env.getProperty(CommonConstants.ALACARTE_ORCHESTRATION);
    String timeOut = env.getProperty(CommonConstants.ALACARTE_RECIPE_TIMEOUT);
    if (StringUtils.isBlank(orchestrationUri) || StringUtils.isBlank(timeOut)) {
        String error = StringUtils.isBlank(orchestrationUri) ? "ALaCarte Orchestration URI not found in properties" : "ALaCarte Recipe Timeout not found in properties";
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        ValidateException validateException = new ValidateException.Builder(error, HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
        requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
        throw validateException;
    }
    serviceInstanceId = "";
    String configurationId = "";
    String pnfCorrelationId = "";
    if (sir.getServiceInstanceId() != null) {
        serviceInstanceId = sir.getServiceInstanceId();
    }
    if (sir.getConfigurationId() != null) {
        configurationId = sir.getConfigurationId();
    }
    pnfCorrelationId = getPnfCorrelationId(sir);
    try {
        infraActiveRequestsClient.save(currentActiveReq);
    } catch (Exception e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
    }
    if (!requestScope.equalsIgnoreCase(ModelType.service.name())) {
        aLaCarte = true;
    } else if (aLaCarte == null) {
        aLaCarte = false;
    }
    RequestClientParameter requestClientParameter = null;
    try {
        requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(Integer.parseInt(timeOut)).setRequestAction(action.toString()).setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfCorrelationId).setConfigurationId(configurationId).setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, sir, aLaCarte, action)).setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).build();
    } catch (IOException e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
    }
    return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, orchestrationUri, requestScope);
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) BpmnRequestBuilder(org.onap.so.apihandlerinfra.infra.rest.BpmnRequestBuilder) IOException(java.io.IOException) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestDbFailureException(org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException) IOException(java.io.IOException) CloudConfigurationNotFoundException(org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException) ValidationException(org.onap.so.exceptions.ValidationException) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences)

Example 27 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class ServiceInstances method serviceInstances.

public Response serviceInstances(String requestJSON, Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri, HashMap<String, String> queryParams) throws ApiException {
    String serviceInstanceId;
    Boolean aLaCarte = null;
    ServiceInstancesRequest sir;
    String apiVersion = version.substring(1);
    sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
    action = handleReplaceInstance(action, sir);
    String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri);
    try {
        requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action);
    } catch (ApiException e) {
        msoRequest.createErrorRequestRecord(Status.FAILED, requestId, e.getMessage(), action, requestScope, requestJSON, requestHandlerUtils.getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).orElse(null), sir);
        throw e;
    }
    InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope);
    if (sir.getRequestDetails().getRequestParameters() != null) {
        aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
    }
    requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq);
    if ((action == Action.replaceInstance || action == Action.replaceInstanceRetainAssignments) && (requestScope.equals(ModelType.vnf.toString()) || requestScope.equals(ModelType.vfModule.toString())) && sir.getRequestDetails().getCloudConfiguration() == null) {
        CloudConfiguration cloudConfiguration = getCloudConfigurationOnReplace(requestScope, instanceIdMap, currentActiveReq);
        sir.getRequestDetails().setCloudConfiguration(cloudConfiguration);
        setCloudConfigurationCurrentActiveRequest(cloudConfiguration, currentActiveReq);
    }
    requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
    String instanceName = null;
    if (sir.getRequestDetails().getRequestInfo() != null) {
        instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
    }
    boolean alaCarteFlag = msoRequest.getAlacarteFlag(sir);
    String vnfType = msoRequest.getVnfType(sir, requestScope);
    String networkType = msoRequest.getNetworkType(sir, requestScope);
    String sdcServiceModelVersion = msoRequest.getSDCServiceModelVersion(sir);
    String vfModuleType = msoRequest.getVfModuleType(sir, requestScope);
    if (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && vnfType != null) {
        currentActiveReq.setVnfType(vnfType);
    } else if (requestScope.equalsIgnoreCase(ModelType.network.name()) && networkType != null) {
        currentActiveReq.setNetworkType(networkType);
    }
    requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, instanceName);
    ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
    RequestReferences referencesResponse = new RequestReferences();
    referencesResponse.setRequestId(requestId);
    serviceResponse.setRequestReferences(referencesResponse);
    RecipeLookupResult recipeLookupResult = requestHandlerUtils.getServiceInstanceOrchestrationURI(sir, action, alaCarteFlag, currentActiveReq);
    String serviceInstanceType = requestHandlerUtils.getServiceType(requestScope, sir, alaCarteFlag);
    ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
    ModelType modelType = requestHandlerUtils.getModelType(action, modelInfo);
    Boolean isBaseVfModule = false;
    if (modelType.equals(ModelType.vfModule)) {
        isBaseVfModule = requestHandlerUtils.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion, currentActiveReq);
    }
    serviceInstanceId = requestHandlerUtils.setServiceInstanceId(requestScope, sir);
    String vnfId = "";
    String vfModuleId = "";
    String volumeGroupId = "";
    String networkId = "";
    String pnfCorrelationId = "";
    String instanceGroupId = null;
    if (sir.getVnfInstanceId() != null) {
        vnfId = sir.getVnfInstanceId();
    }
    if (sir.getVfModuleInstanceId() != null) {
        vfModuleId = sir.getVfModuleInstanceId();
    }
    if (sir.getVolumeGroupInstanceId() != null) {
        volumeGroupId = sir.getVolumeGroupInstanceId();
    }
    if (sir.getNetworkInstanceId() != null) {
        networkId = sir.getNetworkInstanceId();
    }
    if (sir.getInstanceGroupId() != null) {
        instanceGroupId = sir.getInstanceGroupId();
    }
    pnfCorrelationId = getPnfCorrelationId(sir);
    try {
        infraActiveRequestsClient.save(currentActiveReq);
    } catch (Exception e) {
        logger.error("Exception occurred", e);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
    }
    if (!requestScope.equalsIgnoreCase(ModelType.service.name()) && action != Action.recreateInstance && !requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
        aLaCarte = true;
    } else if (aLaCarte == null) {
        aLaCarte = false;
    }
    RequestClientParameter requestClientParameter;
    try {
        requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()).setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfCorrelationId).setVnfId(vnfId).setVfModuleId(vfModuleId).setVolumeGroupId(volumeGroupId).setNetworkId(networkId).setServiceType(serviceInstanceType).setVnfType(vnfType).setVfModuleType(vfModuleType).setNetworkType(networkType).setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, sir, aLaCarte, action)).setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(instanceGroupId).build();
    } catch (IOException e) {
        logger.error("Exception occurred", e);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
    }
    return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope);
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) BpmnRequestBuilder(org.onap.so.apihandlerinfra.infra.rest.BpmnRequestBuilder) IOException(java.io.IOException) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestDbFailureException(org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException) IOException(java.io.IOException) CloudConfigurationNotFoundException(org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException) ValidationException(org.onap.so.exceptions.ValidationException) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) ModelType(org.onap.so.serviceinstancebeans.ModelType) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException)

Example 28 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class ServiceInstances method deleteInstanceGroups.

/**
 * This method deletes the Instance Groups.
 *
 * This method will check whether the request is not duplicate in requestdb. if its not then will save as a new
 * request. And will send a POST request to BEPL client to delete the Insatnce Groups.
 *
 * @param action
 * @param instanceIdMap
 * @param version
 * @param requestId
 * @param requestUri
 * @param requestContext
 * @return
 * @throws ApiException
 */
public Response deleteInstanceGroups(Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri, ContainerRequestContext requestContext) throws ApiException {
    String instanceGroupId = instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID);
    Boolean aLaCarte = true;
    String apiVersion = version.substring(1);
    ServiceInstancesRequest sir = new ServiceInstancesRequest();
    sir.setInstanceGroupId(instanceGroupId);
    String requestScope = ModelType.instanceGroup.toString();
    InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, null, requestScope);
    requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
    try {
        requestHandlerUtils.validateHeaders(requestContext);
    } catch (ValidationException e) {
        logger.error("Exception occurred", e);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
        requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
        throw validateException;
    }
    requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, null);
    ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
    RequestReferences referencesResponse = new RequestReferences();
    referencesResponse.setRequestId(requestId);
    serviceResponse.setRequestReferences(referencesResponse);
    Boolean isBaseVfModule = false;
    RecipeLookupResult recipeLookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 180);
    try {
        infraActiveRequestsClient.save(currentActiveReq);
    } catch (Exception e) {
        logger.error("Exception occurred", e);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
    }
    RequestClientParameter requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()).setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(instanceGroupId).build();
    return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope);
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ValidationException(org.onap.so.exceptions.ValidationException) BpmnRequestBuilder(org.onap.so.apihandlerinfra.infra.rest.BpmnRequestBuilder) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestDbFailureException(org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException) IOException(java.io.IOException) CloudConfigurationNotFoundException(org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException) ValidationException(org.onap.so.exceptions.ValidationException) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences)

Example 29 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class TasksHandler method getTaskInfo.

// Makes a GET call to Camunda to get variables for this task
private TaskList getTaskInfo(String taskId) throws ApiException {
    TaskList taskList;
    String getRequestUrl = UriBuilder.fromUri(requestUrl).path(taskId).path("variables").build().toString();
    ResponseEntity<String> getResponse;
    getResponse = camundaClient.get(getRequestUrl);
    responseHandler.acceptedResponse(getResponse);
    String respBody = getResponse.getBody();
    if (respBody != null) {
        taskList = buildTaskList(taskId, respBody);
    } else {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.AvailabilityError).build();
        throw new BPMNFailureException.Builder(String.valueOf(HttpStatus.SC_BAD_GATEWAY), HttpStatus.SC_BAD_GATEWAY, ErrorNumbers.SVC_NO_SERVER_RESOURCES).errorInfo(errorLoggerInfo).build();
    }
    return taskList;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) TaskList(org.onap.so.apihandlerinfra.tasksbeans.TaskList) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 30 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class TasksHandler method queryFilters.

@Path("/{version:[vV]1}")
@GET
@Operation(description = "Finds Manual Tasks", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response queryFilters(@QueryParam("taskId") String taskId, @QueryParam("originalRequestId") String originalRequestId, @QueryParam("subscriptionServiceType") String subscriptionServiceType, @QueryParam("nfRole") String nfRole, @QueryParam("buildingBlockName") String buildingBlockName, @QueryParam("originalRequestDate") String originalRequestDate, @QueryParam("originalRequestorId") String originalRequestorId, @PathParam("version") String version) throws ApiException {
    String apiVersion = version.substring(1);
    // Prepare the query string to /task interface
    TaskVariables tv = new TaskVariables();
    List<TaskVariableValue> tvvList = new ArrayList<>();
    if (originalRequestId != null) {
        TaskVariableValue tvv = new TaskVariableValue();
        tvv.setName("originalRequestId");
        tvv.setValue(originalRequestId);
        tvv.setOperator("eq");
        tvvList.add(tvv);
    }
    if (subscriptionServiceType != null) {
        TaskVariableValue tvv = new TaskVariableValue();
        tvv.setName("subscriptionServiceType");
        tvv.setValue(subscriptionServiceType);
        tvv.setOperator("eq");
        tvvList.add(tvv);
    }
    if (nfRole != null) {
        TaskVariableValue tvv = new TaskVariableValue();
        tvv.setName("nfRole");
        tvv.setValue(nfRole);
        tvv.setOperator("eq");
        tvvList.add(tvv);
    }
    if (buildingBlockName != null) {
        TaskVariableValue tvv = new TaskVariableValue();
        tvv.setName("buildingBlockName");
        tvv.setValue(buildingBlockName);
        tvv.setOperator("eq");
        tvvList.add(tvv);
    }
    if (originalRequestDate != null) {
        TaskVariableValue tvv = new TaskVariableValue();
        tvv.setName("originalRequestDate");
        tvv.setValue(originalRequestDate);
        tvv.setOperator("eq");
        tvvList.add(tvv);
    }
    if (originalRequestorId != null) {
        TaskVariableValue tvv = new TaskVariableValue();
        tvv.setName("originalRequestorId");
        tvv.setValue(originalRequestorId);
        tvv.setOperator("eq");
        tvvList.add(tvv);
    }
    tv.setTaskVariables(tvvList);
    ResponseEntity<String> response = null;
    String camundaJsonReq = null;
    try {
        ObjectMapper mapper = new ObjectMapper();
        camundaJsonReq = mapper.writeValueAsString(tv);
    } catch (JsonProcessingException e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
        throw new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
    }
    response = camundaClient.post(camundaJsonReq, requestUrl);
    TasksGetResponse trr = new TasksGetResponse();
    List<TaskList> taskList = new ArrayList<>();
    int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue());
    String respBody = response.getBody();
    responseHandler.acceptedOrNoContentResponse(response);
    if (null != respBody) {
        JSONArray data = new JSONArray(respBody);
        for (int i = 0; i < data.length(); i++) {
            JSONObject taskEntry = data.getJSONObject(i);
            String id = taskEntry.getString("id");
            if (taskId != null && !taskId.equals(id)) {
                continue;
            }
            // Get variables info for each task ID
            TaskList taskListEntry = null;
            taskListEntry = getTaskInfo(id);
            taskList.add(taskListEntry);
        }
        trr.setTaskList(taskList);
    } else {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.BusinessProcessError).build();
        throw new BPMNFailureException.Builder(String.valueOf(bpelStatus), bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
    }
    String jsonResponse = null;
    try {
        ObjectMapper mapper = new ObjectMapper();
        jsonResponse = mapper.writeValueAsString(trr);
    } catch (JsonProcessingException e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
        throw new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
    }
    return builder.buildResponse(HttpStatus.SC_ACCEPTED, "", jsonResponse, apiVersion);
}
Also used : TasksGetResponse(org.onap.so.apihandlerinfra.tasksbeans.TasksGetResponse) TaskVariableValue(org.onap.so.apihandlerinfra.tasksbeans.TaskVariableValue) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) UriBuilder(javax.ws.rs.core.UriBuilder) TaskList(org.onap.so.apihandlerinfra.tasksbeans.TaskList) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) TaskVariables(org.onap.so.apihandlerinfra.tasksbeans.TaskVariables) JSONObject(org.json.JSONObject) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Aggregations

ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)42 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)34 IOException (java.io.IOException)22 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)20 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)19 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)18 ValidationException (org.onap.so.exceptions.ValidationException)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)10 RequestDbFailureException (org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException)10 Operation (io.swagger.v3.oas.annotations.Operation)9 Transactional (javax.transaction.Transactional)9 Path (javax.ws.rs.Path)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 Produces (javax.ws.rs.Produces)8 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)8 Consumes (javax.ws.rs.Consumes)6 Response (javax.ws.rs.core.Response)6 BPMNFailureException (org.onap.so.apihandlerinfra.exceptions.BPMNFailureException)6 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)5