Search in sources :

Example 6 with ValidationException

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

the class TenantIsolationRequest method parseOrchestration.

void parseOrchestration(CloudOrchestrationRequest cor) throws ValidationException {
    this.cor = cor;
    try {
        ObjectMapper mapper = new ObjectMapper();
        requestJSON = mapper.writeValueAsString(cor.getRequestDetails());
    } catch (JsonProcessingException e) {
        throw new ValidationException("Parse CloudOrchestrationRequest to JSON string", e);
    }
    if (cor.getRequestDetails() == null) {
        throw new ValidationException("requestDetails", true);
    }
    this.requestInfo = cor.getRequestDetails().getRequestInfo();
    if (this.requestInfo == null) {
        throw new ValidationException("requestInfo", true);
    }
    if (empty(requestInfo.getSource())) {
        throw new ValidationException("source", true);
    }
    if (empty(requestInfo.getRequestorId())) {
        throw new ValidationException("requestorId", true);
    }
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with ValidationException

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

the class TenantIsolationRequest method getOrchestrationFilters.

public Map<String, String> getOrchestrationFilters(MultivaluedMap<String, String> queryParams) throws ValidationException {
    String queryParam = null;
    Map<String, String> orchestrationFilterParams = new HashMap<>();
    for (Entry<String, List<String>> entry : queryParams.entrySet()) {
        queryParam = entry.getKey();
        try {
            for (String value : entry.getValue()) {
                if (StringUtils.isBlank(value)) {
                    throw (new Exception(queryParam + " value"));
                }
                orchestrationFilterParams.put(queryParam, value);
            }
        } catch (Exception e) {
            logger.error("Exception in getOrchestrationFilters", e);
            throw new ValidationException(e.getMessage(), true);
        }
    }
    return orchestrationFilterParams;
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) HashMap(java.util.HashMap) RelatedInstanceList(org.onap.so.apihandlerinfra.tenantisolationbeans.RelatedInstanceList) List(java.util.List) ServiceModelList(org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ValidationException(org.onap.so.exceptions.ValidationException)

Example 8 with ValidationException

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

the class TenantIsolationRequest method requestInfoValidation.

private void requestInfoValidation(Action action, RequestInfo requestInfo) throws ValidationException {
    if (Action.create.equals(action) && empty(requestInfo.getInstanceName())) {
        throw new ValidationException("instanceName", true);
    }
    if (!empty(requestInfo.getInstanceName()) && !requestInfo.getInstanceName().matches(Constants.VALID_INSTANCE_NAME_FORMAT)) {
        throw new ValidationException("instanceName format", true);
    }
    if (empty(requestInfo.getSource())) {
        throw new ValidationException("source", true);
    }
    if (empty(requestInfo.getRequestorId())) {
        throw new ValidationException("requestorId", true);
    }
    ResourceType resourceType = requestInfo.getResourceType();
    if (resourceType == null) {
        throw new ValidationException("resourceType", true);
    }
    this.requestScope = resourceType.name();
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) ResourceType(org.onap.so.apihandlerinfra.tenantisolationbeans.ResourceType)

Example 9 with ValidationException

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

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

the class ModelInfoValidation method validate.

@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
    ModelInfo modelInfo = info.getSir().getRequestDetails().getModelInfo();
    RequestParameters requestParameters = info.getReqParameters();
    String requestScope = info.getRequestScope();
    Actions action = info.getAction();
    int reqVersion = info.getReqVersion();
    Boolean aLaCarteFlag = info.getALaCarteFlag();
    if (!requestScope.equals(ModelType.instanceGroup.toString())) {
        if (!empty(modelInfo.getModelNameVersionId())) {
            modelInfo.setModelVersionId(modelInfo.getModelNameVersionId());
        }
        // modelCustomizationId is required when usePreLoad is false for v4 and higher for VF Module Create
        if (requestParameters != null && reqVersion >= 4 && requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.createInstance && !requestParameters.isUsePreload()) {
            if (!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId())) {
                throw new ValidationException("modelCustomizationId");
            }
        }
        // modelCustomizationId is required for v5 and higher for VF Module Replace
        if (requestParameters != null && reqVersion > 4 && requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.replaceInstance) {
            if (!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId())) {
                throw new ValidationException("modelCustomizationId");
            }
        }
        // modelCustomizationId or modelCustomizationName are required for VNF Replace
        if (requestParameters != null && reqVersion > 4 && requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.replaceInstance || action == Action.recreateInstance) {
            if (!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId()) && modelInfo.getModelCustomizationName() == null) {
                throw new ValidationException("modelCustomizationId or modelCustomizationName");
            }
        }
        // create and updates except for network (except v4)
        if (empty(modelInfo.getModelInvariantId()) && ((reqVersion > 2 && (aLaCarteFlag != null && !aLaCarteFlag) && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.deleteInstance) || !(reqVersion < 4 && requestScope.equalsIgnoreCase(ModelType.network.name())) && (action == Action.createInstance || action == Action.updateInstance || action == Action.enablePort || action == Action.disablePort || action == Action.addRelationships || action == Action.removeRelationships || (requestScope.equalsIgnoreCase(ModelType.configuration.name()) && (action == Action.activateInstance || action == Action.deactivateInstance))))) {
            throw new ValidationException("modelInvariantId");
        }
        if (empty(modelInfo.getModelInvariantId()) && (requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut)) {
            throw new ValidationException("modelInvariantId");
        }
        if (empty(modelInfo.getModelInvariantId()) && (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.recreateInstance)) {
            throw new ValidationException("modelInvariantId", true);
        }
        if (!empty(modelInfo.getModelInvariantId()) && !UUIDChecker.isValidUUID(modelInfo.getModelInvariantId())) {
            throw new ValidationException("modelInvariantId format");
        }
        if (reqVersion >= 4 && !(requestScope.equalsIgnoreCase(ModelType.configuration.name())) && empty(modelInfo.getModelName()) && (action == Action.createInstance || action == Action.updateInstance || action == Action.addRelationships || action == Action.removeRelationships || action == Action.recreateInstance || ((action == Action.deleteInstance || action == Action.scaleOut) && (requestScope.equalsIgnoreCase(ModelType.vfModule.name()))))) {
            throw new ValidationException("modelName", true);
        }
        if (empty(modelInfo.getModelVersion()) && !(requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (!(reqVersion < 4 && requestScope.equalsIgnoreCase(ModelType.network.name())) && (action == Action.createInstance || action == Action.updateInstance || action == Action.addRelationships || action == Action.removeRelationships || action == Action.scaleOut))) {
            throw new ValidationException("modelVersion");
        }
        if (empty(modelInfo.getModelVersion()) && (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.recreateInstance)) {
            throw new ValidationException("modelVersion", true);
        }
        // is required for serviceInstance delete macro when aLaCarte=false in v4
        if (reqVersion >= 4 && empty(modelInfo.getModelVersionId()) && (((aLaCarteFlag != null && !aLaCarteFlag) && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.deleteInstance) || (action == Action.createInstance || action == Action.updateInstance || action == Action.enablePort || action == Action.disablePort || action == Action.addRelationships || action == Action.removeRelationships || (requestScope.equalsIgnoreCase(ModelType.configuration.name()) && (action == Action.activateInstance || action == Action.deactivateInstance))))) {
            throw new ValidationException("modelVersionId");
        }
        if (empty(modelInfo.getModelVersionId()) && (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.recreateInstance)) {
            throw new ValidationException("modelVersionId", true);
        }
        if (empty(modelInfo.getModelVersionId()) && (requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut)) {
            throw new ValidationException("modelVersionId");
        }
        if (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action != Action.deleteInstance && empty(modelInfo.getModelCustomizationName())) {
            if (!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId())) {
                throw new ValidationException("modelCustomizationId or modelCustomizationName");
            }
        }
        if (reqVersion >= 4 && (!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId())) && (requestScope.equalsIgnoreCase(ModelType.network.name()) || requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (action == Action.updateInstance || action == Action.createInstance)) {
            throw new ValidationException("modelCustomizationId");
        }
        if (empty(modelInfo.getModelCustomizationId()) && requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut && !(requestParameters.getTestApi() == TestApi.VNF_API.name() && requestParameters.isUsePreload() == true)) {
            throw new ValidationException("modelCustomizationId");
        }
    } else {
        if (empty(modelInfo.getModelVersionId()) && action == Action.createInstance) {
            throw new ValidationException("modelVersionId", true);
        }
    }
    return info;
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) ValidationException(org.onap.so.exceptions.ValidationException) Actions(org.onap.so.apihandlerinfra.Actions) RequestParameters(org.onap.so.serviceinstancebeans.RequestParameters)

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