use of org.onap.so.exceptions.ValidationException in project so by onap.
the class ApplyUpdatedConfigValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
RequestParameters requestParameters = info.getSir().getRequestDetails().getRequestParameters();
RequestInfo requestInfo = info.getSir().getRequestDetails().getRequestInfo();
if (requestInfo == null) {
throw new ValidationException("requestInfo");
} else if (empty(requestInfo.getRequestorId())) {
throw new ValidationException("requestorId");
} else if (empty(requestInfo.getSource())) {
throw new ValidationException("source");
}
if (requestParameters == null) {
throw new ValidationException("requestParameters");
}
return info;
}
use of org.onap.so.exceptions.ValidationException in project so by onap.
the class ConfigurationParametersValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
ServiceInstancesRequest sir = info.getSir();
List<Map<String, String>> configParams = sir.getRequestDetails().getConfigurationParameters();
String requestScope = info.getRequestScope();
Actions action = info.getAction();
if (configParams.isEmpty() && requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut) {
throw new ValidationException("configuration parameters");
}
return info;
}
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;
}
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());
}
}
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);
}
Aggregations