Search in sources :

Example 1 with RequestStatus

use of org.onap.so.apihandlerinfra.tenantisolationbeans.RequestStatus 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)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)1 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)1 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)1 InstanceReferences (org.onap.so.apihandlerinfra.tenantisolationbeans.InstanceReferences)1 Request (org.onap.so.apihandlerinfra.tenantisolationbeans.Request)1 RequestDetails (org.onap.so.apihandlerinfra.tenantisolationbeans.RequestDetails)1 RequestStatus (org.onap.so.apihandlerinfra.tenantisolationbeans.RequestStatus)1