public static void checkHref(final String href, final String parameterName) throws OwsExceptionReport { if (!href.startsWith("http") && !href.startsWith("urn")) { throw new InvalidParameterValueException().at(parameterName).withMessage( "The reference (href) has an invalid style!"); } }
private static OwsExceptionReport duplicateOutput(OwsCode id) { return new InvalidParameterValueException().at(OUTPUT).withMessage("Duplicate output definition for output %s", id); }
/** * Check if the requested resultType is valid * * @param resultType * Requested resultType * @throws CodedException * If the requested resultType is not valid */ private void checkRequestedResultType(String resultType) throws CodedException { if (!getValidResultTypes().contains(resultType)) { throw new InvalidParameterValueException().at("resultType").withMessage( "The requested resultType '%s' is not valid for the responseFormat '%s'", resultType, InspireOMSOConstants.NS_OMSO_30); } }
/** * Check if the requested resultType is valid * * @param resultType * Requested resultType * @throws CodedException * If the requested resultType is not valid */ private void checkRequestedResultType(String resultType) throws CodedException { if (!getValidResultTypes().contains(resultType)) { throw new InvalidParameterValueException().at("resultType").withMessage( "The requested resultType '%s' is not valid for the responseFormat '%s'", resultType, InspireOMSOConstants.NS_OMSO_30); } }
public static URI checkParameterSingleURI(String values, String name) throws OwsExceptionReport { String value = checkParameterSingleValue(values, name); try { return new URI(value); } catch (URISyntaxException e) { throw new InvalidParameterValueException().at(name).causedBy(e) .withMessage("Cannot parse provided value '%s' to URI", value); } }
/** * Check if the observation contains more than one sampling geometry * definitions. * * @param request * Request * * @throws CodedException * If more than one sampling geometry is defined */ private void checkParameterForSpatialFilteringProfile(InsertObservationRequest request) throws OwsExceptionReport { for (OmObservation observation : request.getObservations()) { if (observation.isSetParameter()) { long count = observation.getParameter().stream() .map(NamedValue::getName) .map(ReferenceType::getHref) .filter(Sos2Constants.HREF_PARAMETER_SPATIAL_FILTERING_PROFILE::equals) .count(); if (count > 1) { throw new InvalidParameterValueException().at("om:parameter").withMessage( "The observation contains more than one ({}) sampling geometry definitions!", count); } } } }
private static OwsExceptionReport invalidInput(ProcessData input, String messageDetail) { String id = input.getId().getValue(); return new InvalidParameterValueException().at(INPUT).withMessage(VALUE_INVALID, id, INPUT, messageDetail); }
private static OwsExceptionReport invalidOutput(OutputDefinition output, String messageDetail) { String id = output.getId().getValue(); return new InvalidParameterValueException().at(OUTPUT).withMessage(VALUE_INVALID, id, OUTPUT, messageDetail); }
} else { throw new InvalidParameterValueException() .at(GetCapabilitiesParams.Section) .withMessage("The requested section '%s' does not exist or is not supported!", section);
private void validateCardinalities(List<ProcessData> inputs, ProcessDescription description) throws OwsExceptionReport { CompositeOwsException exception = new CompositeOwsException(); InputOccurenceCollector collector = new InputOccurenceCollector(); Map<Chain<OwsCode>, BigInteger> cardinalities = inputs.stream().collect(MoreCollectors.toCardinalities( ProcessData::getId, ProcessData::isGroup, x -> x.asGroup().stream())); Map<Chain<OwsCode>, InputOccurence> occurences = description.getInputDescriptions().stream().map(input -> input .visit(collector)).collect(HashMap::new, Map::putAll, Map::putAll); // check the cardinalities of existing inputs // ignore if there is no cardinality, as this // will be catched by another method cardinalities.forEach((chain, cardinality) -> Optional.ofNullable(occurences.get(chain)).filter(occurence -> !occurence.isInBounds(cardinality)).ifPresent( occurence -> exception.add(new InvalidParameterValueException().at(INPUT).withMessage( "The input %s has an invalid cardinality of %s; should be in %s.", chain.toString(), cardinality, occurence)))); // check for missing inputs occurences.forEach((chain, occurence) -> { if (occurence.isRequired() && !cardinalities.containsKey(chain)) { exception.add(new MissingParameterValueException().at(INPUT).withMessage("The input %s is required", chain.toString())); } }); exception.throwIfNotEmpty(); }
/** * Checks the requested procedureDescriptionFormat with the datasource * procedureDescriptionFormat. * * @param identifier * * @param identifier * the procedure identifier * @param requestedFormat * requested procedureDescriptionFormat * * @throws OwsExceptionReport * If procedureDescriptionFormats are invalid */ private boolean checkOutputFormatWithDescriptionFormat(String identifier, String requestedFormat) throws OwsExceptionReport { if (existsGenerator(requestedFormat)) { return true; } throw new InvalidParameterValueException().at(SosConstants.DescribeSensorParams.procedure) .withMessage("The value of the output format is wrong and has to be %s for procedure %s", requestedFormat, identifier) .setStatus(HTTPStatus.BAD_REQUEST); }
private void checkParentChildProcedures(SosProcedureDescription<?> procedureDescription, String assignedIdentifier) throws CodedException { if (procedureDescription.isSetChildProcedures()) { for (AbstractSensorML child : procedureDescription.getChildProcedures()) { if (child.getIdentifier().equalsIgnoreCase(assignedIdentifier)) { throw new InvalidParameterValueException().at("childProcdureIdentifier").withMessage( "The procedure with the identifier '%s' is linked to itself as child procedure !", procedureDescription.getIdentifier()); } } } if (procedureDescription.isSetParentProcedure()) { if (procedureDescription.getParentProcedure().getHref().equals(assignedIdentifier)) { throw new InvalidParameterValueException().at("parentProcdureIdentifier").withMessage( "The procedure with the identifier '%s' is linked to itself as parent procedure !", procedureDescription.getIdentifier()); } } }
private void checkProcedureAndOfferingCombination(InsertSensorRequest request) throws OwsExceptionReport { for (SosOffering offering : request.getAssignedOfferings()) { if (!offering.isParentOffering() && getCache().getPublishedOfferings().contains(offering.getIdentifier())) { throw new InvalidParameterValueException().at(Sos2Constants.InsertSensorParams.offeringIdentifier) .withMessage( "The offering with the identifier '%s' still exists in this service and it is not allowed to insert more than one procedure to an offering!", offering.getIdentifier()); } } }
private void checkObservationType(InsertResultTemplateRequest request) throws OwsExceptionReport { OmObservationConstellation observationConstellation = request.getObservationTemplate(); if (observationConstellation.isSetObservationType()) { // TODO check why setting SweArray_Observation as type //observationConstellation.setObservationType(OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION); // check if observation type is supported checkObservationType(observationConstellation.getObservationType(), Sos2Constants.InsertResultTemplateParams.observationType.name()); } Set<String> validObservationTypesForOffering = new HashSet<>(0); for (String offering : observationConstellation.getOfferings()) { validObservationTypesForOffering.addAll(getCache() .getAllowedObservationTypesForOffering(offering)); } // check if observation type is valid for offering if (!validObservationTypesForOffering.contains(observationConstellation.getObservationType())) { throw new InvalidParameterValueException().at(Sos2Constants.InsertResultTemplateParams.observationType) .withMessage("The requested observation type is not valid for the offering!"); } }
private void checkFeatureMembers(List<AbstractFeature> featureMembers) throws OwsExceptionReport { for (AbstractFeature abstractFeature : featureMembers) { if (!abstractFeature.isSetIdentifier()) { abstractFeature.setIdentifier(JavaHelper.generateID(abstractFeature.toString())); } if (getCache().hasFeatureOfInterest(abstractFeature.getIdentifier())) { throw new InvalidParameterValueException() .at("featureMember.identifier") .withMessage( "The featureOfInterest with identifier '%s' still exists!", abstractFeature.getIdentifier()); } } }
throw new InvalidParameterValueException().at(SosConstants.DescribeSensorParams.procedure) .withMessage("The value of the output format is wrong and has to be %s for procedure %s", descriptionFormat, identifier)
private void checkObservationType(InsertResultTemplateRequest request) throws OwsExceptionReport { OmObservationConstellation observationConstellation = request.getObservationTemplate(); if (observationConstellation.isSetObservationType()) { // TODO check why setting SweArray_Observation as type //observationConstellation.setObservationType(OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION); // check if observation type is supported checkObservationType(observationConstellation.getObservationType(), Sos2Constants.InsertResultTemplateParams.observationType.name()); } Set<String> validObservationTypesForOffering = new HashSet<>(0); for (String offering : observationConstellation.getOfferings()) { validObservationTypesForOffering.addAll(getCache() .getAllowedObservationTypesForOffering(offering)); } // check if observation type is valid for offering if (!validObservationTypesForOffering.contains(observationConstellation.getObservationType())) { throw new InvalidParameterValueException().at(Sos2Constants.InsertResultTemplateParams.observationType) .withMessage("The requested observation type is not valid for the offering!"); } }
private void checkFeatureMembers(List<AbstractFeature> featureMembers) throws OwsExceptionReport { for (AbstractFeature abstractFeature : featureMembers) { if (!abstractFeature.isSetIdentifier()) { abstractFeature.setIdentifier(JavaHelper.generateID(abstractFeature.toString())); } if (getCache().hasFeatureOfInterest(abstractFeature.getIdentifier())) { throw new InvalidParameterValueException() .at("featureMember.identifier") .withMessage( "The featureOfInterest with identifier '%s' still exists!", abstractFeature.getIdentifier()); } } }
/** * method checks whether this SOS supports the single requested version * * @param request * the request * * * @throws OwsExceptionReport * * if this SOS does not support the requested versions */ protected void checkSingleVersionParameter(OwsServiceRequest request) throws OwsExceptionReport { // if version is incorrect, throw exception if (request.getVersion() == null) { throw new MissingVersionParameterException(); } if ( !this.serviceOperatorRepository.isVersionSupported(request.getService(), request.getVersion())) { throw new InvalidParameterValueException().at(OWSConstants.RequestParams.version).withMessage( "The parameter '%s' does not contain version(s) supported by this Service: '%s'!", OWSConstants.RequestParams.version.name(), Joiner.on(", ").join(this.serviceOperatorRepository.getSupportedVersions(request.getService()))); } }
private void validate(ExecuteRequest request, ProcessDescription description) throws OwsExceptionReport { CompositeOwsException exception = new CompositeOwsException(); if (request.getResponseMode() == ResponseMode.RAW && (request.getOutputs().size() > 1 || (request.getOutputs() .isEmpty() && description.getOutputs().size() > 1))) { exception.add(new InvalidParameterValueException().at("responseMode").withMessage( "The value 'raw' of the parameter 'responseMode' is invalid. Single output is required.")); } try { validateInputs(request.getInputs(), description); } catch (OwsExceptionReport ex) { exception.add(ex); } try { validateOutputs(request.getOutputs(), description); } catch (OwsExceptionReport ex) { exception.add(ex); } try { validateCardinalities(request.getInputs(), description); } catch (OwsExceptionReport ex) { exception.add(ex); } exception.throwIfNotEmpty(); }