Search in sources :

Example 1 with ValidateException

use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.

the class ModelDistributionRequest method updateModelDistributionStatus.

@PATCH
@Path("/{version:[vV][1]}/distributions/{distributionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Update model distribution status", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response updateModelDistributionStatus(String requestJSON, @PathParam("version") String version, @PathParam("distributionId") String distributionId) throws ApiException {
    Distribution distributionRequest;
    try {
        ObjectMapper mapper = new ObjectMapper();
        distributionRequest = mapper.readValue(requestJSON, Distribution.class);
    } catch (IOException e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
        ValidateException validateException = 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();
        throw validateException;
    }
    try {
        parse(distributionRequest);
    } catch (ValidationException e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
        ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
    CloudOrchestrationRequest cor = new CloudOrchestrationRequest();
    cor.setDistribution(distributionRequest);
    cor.setDistributionId(distributionId);
    TenantIsolationRunnable runnable = tenantIsolationRunnable.get();
    runnable.run(Action.distributionStatus, null, cor, null);
    return Response.ok().build();
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ValidationException(org.onap.so.exceptions.ValidationException) Distribution(org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) PATCH(javax.ws.rs.PATCH) Transactional(javax.transaction.Transactional)

Example 2 with ValidateException

use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.

the class ResponseHandler method getCamundaResponse.

public CamundaResponse getCamundaResponse(ResponseEntity<String> camundaResponse) throws ValidateException {
    String responseBody = camundaResponse.getBody();
    CamundaResponse response = null;
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    try {
        response = mapper.readValue(responseBody, CamundaResponse.class);
    } catch (IOException | NullPointerException e) {
        logger.error("Cannot parse Camunda Response: ", e);
        throw new ValidateException.Builder("Cannot parse Camunda ResponseBody. BPMN HTTP status: " + camundaResponse.getStatusCodeValue(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).build();
    }
    return response;
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with ValidateException

use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.

the class OrchestrationRequests method getOrchestrationRequest.

@GET
@Path("/{version:[vV][4-8]}/{requestId}")
@Operation(description = "Find Orchestrated Requests for a given requestId", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response getOrchestrationRequest(@PathParam("requestId") String requestId, @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest, @QueryParam(value = "format") String format) throws ApiException {
    GetOrchestrationResponse orchestrationResponse = new GetOrchestrationResponse();
    InfraActiveRequests infraActiveRequest = null;
    List<org.onap.so.db.request.beans.RequestProcessingData> requestProcessingData = null;
    if (!UUIDChecker.isValidUUID(requestId)) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError).errorSource(Constants.MODIFIED_BY_APIHANDLER).build();
        throw new ValidateException.Builder("Request Id " + requestId + " is not a valid UUID", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
    }
    infraActiveRequest = infraActiveRequestLookup(requestId);
    if (isRequestProcessingDataRequired(format)) {
        try {
            requestProcessingData = requestsDbClient.getExternalRequestProcessingDataBySoRequestId(requestId);
        } catch (Exception e) {
            logger.error("Exception occurred while communicating with RequestDb during requestProcessingData lookup ", e);
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build();
            ValidateException validateException = new ValidateException.Builder("Exception occurred while communicating with RequestDb during requestProcessingData lookup", HttpStatus.SC_NOT_FOUND, ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB).cause(e).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
    }
    Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest, format, version);
    if (null != requestProcessingData && !requestProcessingData.isEmpty()) {
        request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData));
    }
    request.setRequestId(requestId);
    orchestrationResponse.setRequest(request);
    return builder.buildResponse(HttpStatus.SC_OK, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), orchestrationResponse, version);
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.serviceinstancebeans.Request) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException) GetOrchestrationResponse(org.onap.so.serviceinstancebeans.GetOrchestrationResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Example 4 with ValidateException

use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.

the class OrchestrationRequests method mapInfraActiveRequestToRequest.

protected Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest, String format, String version) throws ApiException {
    String requestBody = iar.getRequestBody();
    Request request = new Request();
    ObjectMapper mapper = new ObjectMapper();
    request.setRequestId(iar.getRequestId());
    request.setRequestScope(iar.getRequestScope());
    request.setRequestType(iar.getRequestAction());
    String originalRequestId = iar.getOriginalRequestId();
    if (originalRequestId != null) {
        request.setOriginalRequestId(originalRequestId);
    }
    if (!version.matches("v[1-7]")) {
        String workflowName = iar.getWorkflowName();
        if (workflowName == null) {
            workflowName = iar.getRequestAction();
        }
        request.setWorkflowName(workflowName);
        String operationName = iar.getOperationName();
        if (operationName != null) {
            request.setOperationName(operationName);
        }
    }
    InstanceReferences ir = new InstanceReferences();
    if (iar.getNetworkId() != null)
        ir.setNetworkInstanceId(iar.getNetworkId());
    if (iar.getNetworkName() != null)
        ir.setNetworkInstanceName(iar.getNetworkName());
    if (iar.getServiceInstanceId() != null)
        ir.setServiceInstanceId(iar.getServiceInstanceId());
    if (iar.getServiceInstanceName() != null)
        ir.setServiceInstanceName(iar.getServiceInstanceName());
    if (iar.getVfModuleId() != null)
        ir.setVfModuleInstanceId(iar.getVfModuleId());
    if (iar.getVfModuleName() != null)
        ir.setVfModuleInstanceName(iar.getVfModuleName());
    if (iar.getVnfId() != null)
        ir.setVnfInstanceId(iar.getVnfId());
    if (iar.getVnfName() != null)
        ir.setVnfInstanceName(iar.getVnfName());
    if (iar.getVolumeGroupId() != null)
        ir.setVolumeGroupInstanceId(iar.getVolumeGroupId());
    if (iar.getVolumeGroupName() != null)
        ir.setVolumeGroupInstanceName(iar.getVolumeGroupName());
    if (iar.getInstanceGroupId() != null)
        ir.setInstanceGroupId(iar.getInstanceGroupId());
    if (iar.getInstanceGroupName() != null)
        ir.setInstanceGroupName(iar.getInstanceGroupName());
    request.setInstanceReferences(ir);
    RequestDetails requestDetails = null;
    if (StringUtils.isNotBlank(requestBody)) {
        try {
            if (requestBody.contains("\"requestDetails\":")) {
                ServiceInstancesRequest sir = mapper.readValue(requestBody, ServiceInstancesRequest.class);
                requestDetails = sir.getRequestDetails();
            } else {
                requestDetails = mapper.readValue(requestBody, RequestDetails.class);
            }
            if (requestDetails.getRequestInfo() != null && iar.getProductFamilyName() != null) {
                requestDetails.getRequestInfo().setProductFamilyName(iar.getProductFamilyName());
            }
            if (requestDetails.getCloudConfiguration() != null && iar.getTenantName() != null) {
                requestDetails.getCloudConfiguration().setTenantName(iar.getTenantName());
            }
        } catch (IOException e) {
            logger.error("Exception occurred", e);
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
            ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON object failed : ", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
    }
    request.setRequestDetails(requestDetails);
    if (iar.getStartTime() != null) {
        String startTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getStartTime()) + " GMT";
        request.setStartTime(startTimeStamp);
    }
    if (iar.getEndTime() != null) {
        String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getEndTime()) + " GMT";
        request.setFinishTime(endTimeStamp);
    }
    RequestStatus status = new RequestStatus();
    if (iar.getModifyTime() != null) {
        String timeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getModifyTime()) + " GMT";
        status.setTimeStamp(timeStamp);
    }
    status.setRequestState(mapRequestStatusToRequest(iar, format));
    if (iar.getProgress() != null) {
        status.setPercentProgress(iar.getProgress().intValue());
    }
    if (iar.getCloudApiRequests() != null && !iar.getCloudApiRequests().isEmpty() && includeCloudRequest) {
        iar.getCloudApiRequests().stream().forEach(cloudRequest -> {
            try {
                request.getCloudRequestData().add(new CloudRequestData(mapper.readValue(cloudRequest.getRequestBody(), Object.class), cloudRequest.getCloudIdentifier()));
            } catch (Exception e) {
                logger.error("Error reading Cloud Request", e);
            }
        });
    }
    mapRequestStatusAndExtSysErrSrcToRequest(iar, status, format, version);
    request.setRequestStatus(status);
    return request;
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.serviceinstancebeans.Request) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) IOException(java.io.IOException) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) InstanceReferences(org.onap.so.serviceinstancebeans.InstanceReferences) CloudRequestData(org.onap.so.serviceinstancebeans.CloudRequestData) SimpleDateFormat(java.text.SimpleDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestStatus(org.onap.so.serviceinstancebeans.RequestStatus)

Example 5 with ValidateException

use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.

the class RequestHandlerUtils method getRequestId.

@Override
public String getRequestId(ContainerRequestContext requestContext) throws ValidateException {
    String requestId = null;
    if (requestContext.getProperty("requestId") != null) {
        requestId = requestContext.getProperty("requestId").toString();
    }
    if (UUIDChecker.isValidUUID(requestId)) {
        return requestId;
    } else {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        ValidateException validateException = new ValidateException.Builder("Request Id " + requestId + " is not a valid UUID", HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder)

Aggregations

ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)29 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)25 IOException (java.io.IOException)16 ValidationException (org.onap.so.exceptions.ValidationException)14 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)11 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)11 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 Operation (io.swagger.v3.oas.annotations.Operation)8 Transactional (javax.transaction.Transactional)8 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)7 Consumes (javax.ws.rs.Consumes)6 POST (javax.ws.rs.POST)4 GET (javax.ws.rs.GET)3 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)3 RequestDbFailureException (org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 SimpleDateFormat (java.text.SimpleDateFormat)2