Search in sources :

Example 26 with ValidateException

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

the class CloudResourcesOrchestration method mapInfraActiveRequestToRequest.

private Request mapInfraActiveRequestToRequest(InfraActiveRequests iar) throws ApiException {
    Request request = new Request();
    request.setRequestId(iar.getRequestId());
    request.setRequestScope(iar.getRequestScope());
    request.setRequestType(iar.getRequestAction());
    InstanceReferences ir = new InstanceReferences();
    if (iar.getOperationalEnvId() != null)
        ir.setOperationalEnvironmentId(iar.getOperationalEnvId());
    if (iar.getOperationalEnvName() != null)
        ir.setOperationalEnvName(iar.getOperationalEnvName());
    if (iar.getRequestorId() != null)
        ir.setRequestorId(iar.getRequestorId());
    request.setInstanceReferences(ir);
    String requestBody = iar.getRequestBody();
    RequestDetails requestDetails = null;
    if (requestBody != null) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            requestDetails = mapper.readValue(requestBody, RequestDetails.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;
        }
    }
    request.setRequestDetails(requestDetails);
    String startTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getStartTime()) + " GMT";
    request.setStartTime(startTimeStamp);
    RequestStatus status = new RequestStatus();
    if (iar.getStatusMessage() != null) {
        status.setStatusMessage(iar.getStatusMessage());
    }
    if (iar.getEndTime() != null) {
        String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getEndTime()) + " GMT";
        status.setTimeStamp(endTimeStamp);
    }
    if (iar.getRequestStatus() != null) {
        status.setRequestState(iar.getRequestStatus());
    }
    if (iar.getProgress() != null) {
        status.setPercentProgress(iar.getProgress().toString());
    }
    request.setRequestStatus(status);
    return request;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) InstanceReferences(org.onap.so.apihandlerinfra.tenantisolationbeans.InstanceReferences) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.apihandlerinfra.tenantisolationbeans.Request) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) RequestDetails(org.onap.so.apihandlerinfra.tenantisolationbeans.RequestDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestStatus(org.onap.so.apihandlerinfra.tenantisolationbeans.RequestStatus)

Example 27 with ValidateException

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

the class CloudResourcesOrchestration method getOperationEnvironmentStatusFilter.

@GET
@Path("/{version:[vV][1]}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Get status of an Operational Environment based on filter criteria", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response getOperationEnvironmentStatusFilter(@Context UriInfo ui, @PathParam("version") String version) throws ApiException {
    MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
    List<String> requestIdKey = queryParams.get("requestId");
    String apiVersion = version.substring(1);
    if (queryParams.size() == 1 && requestIdKey != null) {
        String requestId = requestIdKey.get(0);
        CloudOrchestrationResponse cloudOrchestrationGetResponse = new CloudOrchestrationResponse();
        InfraActiveRequests requestDB;
        try {
            requestDB = requestDbClient.getInfraActiveRequestbyRequestId(requestId);
        } catch (Exception e) {
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build();
            ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
        if (requestDB == null) {
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.BusinessProcessError).build();
            ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " is not found in DB", HttpStatus.SC_NO_CONTENT, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
        Request request = mapInfraActiveRequestToRequest(requestDB);
        cloudOrchestrationGetResponse.setRequest(request);
        return builder.buildResponse(HttpStatus.SC_OK, requestId, cloudOrchestrationGetResponse, apiVersion);
    } else {
        TenantIsolationRequest tenantIsolationRequest = new TenantIsolationRequest();
        List<InfraActiveRequests> activeRequests;
        CloudOrchestrationRequestList orchestrationList;
        Map<String, String> orchestrationMap;
        try {
            orchestrationMap = tenantIsolationRequest.getOrchestrationFilters(queryParams);
        } catch (ValidationException ex) {
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
            ValidateException validateException = new ValidateException.Builder(ex.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
        activeRequests = requestDbClient.getCloudOrchestrationFiltersFromInfraActive(orchestrationMap);
        orchestrationList = new CloudOrchestrationRequestList();
        List<CloudOrchestrationResponse> requestLists = new ArrayList<>();
        for (InfraActiveRequests infraActive : activeRequests) {
            Request request = mapInfraActiveRequestToRequest(infraActive);
            CloudOrchestrationResponse requestList = new CloudOrchestrationResponse();
            requestList.setRequest(request);
            requestLists.add(requestList);
        }
        orchestrationList.setRequestList(requestLists);
        return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationList, apiVersion);
    }
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ValidationException(org.onap.so.exceptions.ValidationException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.apihandlerinfra.tenantisolationbeans.Request) ArrayList(java.util.ArrayList) CloudOrchestrationResponse(org.onap.so.apihandlerinfra.tenantisolationbeans.CloudOrchestrationResponse) 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) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) CloudOrchestrationRequestList(org.onap.so.apihandlerinfra.tenantisolationbeans.CloudOrchestrationRequestList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Example 28 with ValidateException

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

the class ModelDistributionRequest method buildServiceErrorResponse.

private Response buildServiceErrorResponse(int httpResponseCode, MsoException exceptionType, String text, String messageId, List<String> variables) throws ApiException {
    RequestError re = new RequestError();
    ServiceException se = new ServiceException();
    se.setMessageId(messageId);
    se.setText(text);
    if (variables != null) {
        for (String variable : variables) {
            se.getVariables().add(variable);
        }
    }
    re.setServiceException(se);
    String requestErrorStr;
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(Include.NON_DEFAULT);
        requestErrorStr = mapper.writeValueAsString(re);
    } catch (JsonProcessingException e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.DataError).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;
    }
    return Response.status(httpResponseCode).entity(requestErrorStr).build();
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestError(org.onap.so.serviceinstancebeans.RequestError) ServiceException(org.onap.so.serviceinstancebeans.ServiceException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 29 with ValidateException

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

the class DeactivateVnfOperationalEnvironment method execute.

public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
    String operationalEnvironmentId = request.getOperationalEnvironmentId();
    OperationalEnvironment aaiOpEnv = getAAIOperationalEnvironment(operationalEnvironmentId);
    if (aaiOpEnv != null) {
        String operationalEnvironmentStatus = aaiOpEnv.getOperationalEnvironmentStatus();
        if (StringUtils.isBlank(operationalEnvironmentStatus)) {
            String error = "OperationalEnvironmentStatus is null on OperationalEnvironmentId: " + operationalEnvironmentId;
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
            throw new ValidateException.Builder(error, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
        }
        if (operationalEnvironmentStatus.equalsIgnoreCase("ACTIVE")) {
            aaiOpEnv.setOperationalEnvironmentStatus("INACTIVE");
            aaiHelper.updateAaiOperationalEnvironment(operationalEnvironmentId, aaiOpEnv);
        } else if (!operationalEnvironmentStatus.equalsIgnoreCase("INACTIVE")) {
            String error = "Invalid OperationalEnvironmentStatus on OperationalEnvironmentId: " + operationalEnvironmentId;
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
            ValidateException validateException = new ValidateException.Builder(error, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
            requestDb.updateInfraFailureCompletion(error, requestId, operationalEnvironmentId);
            throw validateException;
        }
        requestDb.updateInfraSuccessCompletion("SUCCESSFULLY Deactivated OperationalEnvironment", requestId, operationalEnvironmentId);
    }
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) OperationalEnvironment(org.onap.aai.domain.yang.OperationalEnvironment)

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