Search in sources :

Example 21 with ValidationException

use of org.onap.so.exceptions.ValidationException in project so by onap.

the class OrchestrationRequests method getOrchestrationRequest.

@GET
@Path("/{version:[vV][4-8]}")
@Operation(description = "Find Orchestrated Requests for a URI Information", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response getOrchestrationRequest(@Context UriInfo ui, @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest, @QueryParam(value = "format") String format) throws ApiException {
    MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
    List<InfraActiveRequests> activeRequests;
    GetOrchestrationListResponse orchestrationList;
    Map<String, List<String>> orchestrationMap;
    String apiVersion = version.substring(1);
    try {
        orchestrationMap = msoRequest.getOrchestrationFilters(queryParams);
        if (orchestrationMap.isEmpty()) {
            throw new ValidationException("At least one filter query param must be specified");
        }
    } catch (ValidationException ex) {
        logger.error("Exception occurred", ex);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.DataError).build();
        ValidateException validateException = new ValidateException.Builder(ex.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
    activeRequests = requestsDbClient.getOrchestrationFiltersFromInfraActive(orchestrationMap);
    orchestrationList = new GetOrchestrationListResponse();
    List<RequestList> requestLists = new ArrayList<>();
    for (InfraActiveRequests infraActive : activeRequests) {
        RequestList requestList = new RequestList();
        Request request = mapInfraActiveRequestToRequest(infraActive, includeCloudRequest, format, version);
        if (isRequestProcessingDataRequired(format)) {
            List<RequestProcessingData> requestProcessingData = requestsDbClient.getExternalRequestProcessingDataBySoRequestId(infraActive.getRequestId());
            if (null != requestProcessingData && !requestProcessingData.isEmpty()) {
                request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData));
            }
        }
        requestList.setRequest(request);
        requestLists.add(requestList);
    }
    orchestrationList.setRequestList(requestLists);
    return builder.buildResponse(HttpStatus.SC_OK, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), orchestrationList, apiVersion);
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) GetOrchestrationListResponse(org.onap.so.serviceinstancebeans.GetOrchestrationListResponse) ValidationException(org.onap.so.exceptions.ValidationException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) ArrayList(java.util.ArrayList) Request(org.onap.so.serviceinstancebeans.Request) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) List(java.util.List) ArrayList(java.util.ArrayList) RequestList(org.onap.so.serviceinstancebeans.RequestList) RequestList(org.onap.so.serviceinstancebeans.RequestList) 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 22 with ValidationException

use of org.onap.so.exceptions.ValidationException 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 23 with ValidationException

use of org.onap.so.exceptions.ValidationException in project so by onap.

the class JsonUtils method jsonSchemaValidation.

/**
 * Validates the JSON document against a schema file.
 *
 * @param jsonStr String containing the JSON doc
 * @param jsonSchemaPath full path to a valid JSON schema file
 */
public static String jsonSchemaValidation(String jsonStr, String jsonSchemaPath) throws ValidationException {
    try {
        logger.debug("JSON document to be validated: {}", jsonStr);
        JsonNode document = JsonLoader.fromString(jsonStr);
        JsonNode schema = JsonLoader.fromPath(jsonSchemaPath);
        JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
        JsonValidator validator = factory.getValidator();
        ProcessingReport report = validator.validate(schema, document);
        logger.debug("JSON schema validation report: {}", report);
        return report.toString();
    } catch (IOException e) {
        logger.debug("IOException performing JSON schema validation on document:", e);
        throw new ValidationException(e.getMessage());
    } catch (ProcessingException e) {
        logger.debug("ProcessingException performing JSON schema validation on document:", e);
        throw new ValidationException(e.getMessage());
    }
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) ValidationException(org.onap.so.exceptions.ValidationException) JsonSchemaFactory(com.github.fge.jsonschema.main.JsonSchemaFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonValidator(com.github.fge.jsonschema.main.JsonValidator) IOException(java.io.IOException) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException)

Example 24 with ValidationException

use of org.onap.so.exceptions.ValidationException in project so by onap.

the class InstanceIdMapValidation method validate.

@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
    Map<String, String> instanceIdMap = info.getInstanceIdMap();
    ServiceInstancesRequest sir = info.getSir();
    if (instanceIdMap != null) {
        if (instanceIdMap.get(Service_InstanceId) != null) {
            if (!UUIDChecker.isValidUUID(instanceIdMap.get(Service_InstanceId))) {
                throw new ValidationException(Service_InstanceId);
            }
            sir.setServiceInstanceId(instanceIdMap.get(Service_InstanceId));
        }
        if (instanceIdMap.get(Vnf_InstanceId) != null) {
            if (!UUIDChecker.isValidUUID(instanceIdMap.get(Vnf_InstanceId))) {
                throw new ValidationException(Vnf_InstanceId);
            }
            sir.setVnfInstanceId(instanceIdMap.get(Vnf_InstanceId));
        }
        if (instanceIdMap.get(vfModule_InstanceId) != null) {
            if (!UUIDChecker.isValidUUID(instanceIdMap.get(vfModule_InstanceId))) {
                throw new ValidationException(vfModule_InstanceId);
            }
            sir.setVfModuleInstanceId(instanceIdMap.get(vfModule_InstanceId));
        }
        if (instanceIdMap.get(volume_Group_InstanceId) != null) {
            if (!UUIDChecker.isValidUUID(instanceIdMap.get(volume_Group_InstanceId))) {
                throw new ValidationException(volume_Group_InstanceId);
            }
            sir.setVolumeGroupInstanceId(instanceIdMap.get(volume_Group_InstanceId));
        }
        if (instanceIdMap.get(Network_Instance_Id) != null) {
            if (!UUIDChecker.isValidUUID(instanceIdMap.get(Network_Instance_Id))) {
                throw new ValidationException(Network_Instance_Id);
            }
            sir.setNetworkInstanceId(instanceIdMap.get(Network_Instance_Id));
        }
        if (instanceIdMap.get(Configuration_Instance_Id) != null) {
            if (!UUIDChecker.isValidUUID(instanceIdMap.get(Configuration_Instance_Id))) {
                throw new ValidationException(Configuration_Instance_Id);
            }
            sir.setConfigurationId(instanceIdMap.get(Configuration_Instance_Id));
        }
        if (instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null) {
            if (!UUIDChecker.isValidUUID(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID))) {
                throw new ValidationException(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, true);
            }
            sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID));
        }
        if (instanceIdMap.get(PNF_NAME) != null) {
            sir.setPnfName(instanceIdMap.get(PNF_NAME));
        }
    }
    return info;
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest)

Example 25 with ValidationException

use of org.onap.so.exceptions.ValidationException in project so by onap.

the class ProjectOwningEntityValidation method validate.

@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
    int reqVersion = info.getReqVersion();
    Project project;
    OwningEntity owningEntity;
    String requestScope = info.getRequestScope();
    Actions action = info.getAction();
    project = info.getSir().getRequestDetails().getProject();
    owningEntity = info.getSir().getRequestDetails().getOwningEntity();
    if (reqVersion >= 5 && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.createInstance || action == Action.assignInstance) {
        if (reqVersion > 5 && owningEntity == null) {
            throw new ValidationException("owningEntity");
        }
        if (owningEntity != null && empty(owningEntity.getOwningEntityId())) {
            throw new ValidationException("owningEntityId");
        }
        if (project != null && empty(project.getProjectName())) {
            throw new ValidationException("projectName");
        }
    }
    info.setProject(project);
    info.setOE(owningEntity);
    return info;
}
Also used : Project(org.onap.so.serviceinstancebeans.Project) ValidationException(org.onap.so.exceptions.ValidationException) Actions(org.onap.so.apihandlerinfra.Actions) OwningEntity(org.onap.so.serviceinstancebeans.OwningEntity)

Aggregations

ValidationException (org.onap.so.exceptions.ValidationException)35 Actions (org.onap.so.apihandlerinfra.Actions)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)9 IOException (java.io.IOException)8 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)8 HashMap (java.util.HashMap)6 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)6 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)6 Operation (io.swagger.v3.oas.annotations.Operation)5 Transactional (javax.transaction.Transactional)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)5 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 Consumes (javax.ws.rs.Consumes)4 Test (org.junit.Test)4 BaseTest (org.onap.so.apihandlerinfra.BaseTest)4 RequestInfo (org.onap.so.serviceinstancebeans.RequestInfo)4