use of de.ii.xtraplatform.codelists.domain.Codelist in project ldproxy by interactive-instruments.
the class FeaturesFormatHtml method onStartup.
@Override
public ValidationResult onStartup(OgcApi api, MODE apiValidation) {
// no additional operational checks for now, only validation; we can stop, if no validation is requested
if (apiValidation == MODE.NONE)
return ValidationResult.of();
ImmutableValidationResult.Builder builder = ImmutableValidationResult.builder().mode(apiValidation);
Map<String, FeatureSchema> featureSchemas = providers.getFeatureSchemas(api.getData());
// get HTML configurations to process
Map<String, FeaturesHtmlConfiguration> htmlConfigurationMap = api.getData().getCollections().entrySet().stream().map(entry -> {
final FeatureTypeConfigurationOgcApi collectionData = entry.getValue();
final FeaturesHtmlConfiguration config = collectionData.getExtension(FeaturesHtmlConfiguration.class).orElse(null);
if (Objects.isNull(config))
return null;
return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), config);
}).filter(Objects::nonNull).collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
Map<String, Collection<String>> keyMap = htmlConfigurationMap.entrySet().stream().map(entry -> new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), entry.getValue().getTransformations().keySet())).collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
for (Map.Entry<String, Collection<String>> stringCollectionEntry : featuresCoreValidator.getInvalidPropertyKeys(keyMap, featureSchemas).entrySet()) {
for (String property : stringCollectionEntry.getValue()) {
builder.addStrictErrors(MessageFormat.format("A transformation for property ''{0}'' in collection ''{1}'' is invalid, because the property was not found in the provider schema.", property, stringCollectionEntry.getKey()));
}
}
Set<String> codelists = entityRegistry.getEntitiesForType(Codelist.class).stream().map(Codelist::getId).collect(Collectors.toUnmodifiableSet());
for (Map.Entry<String, FeaturesHtmlConfiguration> entry : htmlConfigurationMap.entrySet()) {
String collectionId = entry.getKey();
for (Map.Entry<String, List<PropertyTransformation>> entry2 : entry.getValue().getTransformations().entrySet()) {
String property = entry2.getKey();
for (PropertyTransformation transformation : entry2.getValue()) {
builder = transformation.validate(builder, collectionId, property, codelists);
}
}
}
return builder.build();
}
use of de.ii.xtraplatform.codelists.domain.Codelist in project ldproxy by interactive-instruments.
the class FeaturesFormatGeoJson method onStartup.
@Override
public ValidationResult onStartup(OgcApi api, MODE apiValidation) {
// no additional operational checks for now, only validation; we can stop, if no validation is requested
if (apiValidation == MODE.NONE)
return ValidationResult.of();
ImmutableValidationResult.Builder builder = ImmutableValidationResult.builder().mode(apiValidation);
Map<String, FeatureSchema> featureSchemas = providers.getFeatureSchemas(api.getData());
// get GeoJSON configurations to process
Map<String, GeoJsonConfiguration> geoJsonConfigurationMap = api.getData().getCollections().entrySet().stream().map(entry -> {
final FeatureTypeConfigurationOgcApi collectionData = entry.getValue();
final GeoJsonConfiguration config = collectionData.getExtension(GeoJsonConfiguration.class).orElse(null);
if (Objects.isNull(config))
return null;
return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), config);
}).filter(Objects::nonNull).collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
for (Map.Entry<String, GeoJsonConfiguration> entry : geoJsonConfigurationMap.entrySet()) {
String collectionId = entry.getKey();
GeoJsonConfiguration config = entry.getValue();
if (config.getNestedObjectStrategy() == GeoJsonConfiguration.NESTED_OBJECTS.FLATTEN && config.getMultiplicityStrategy() != GeoJsonConfiguration.MULTIPLICITY.SUFFIX) {
builder.addStrictErrors(MessageFormat.format("The GeoJSON Nested Object Strategy ''FLATTEN'' in collection ''{0}'' cannot be combined with the Multiplicity Strategy ''{1}''.", collectionId, config.getMultiplicityStrategy()));
} else if (config.getNestedObjectStrategy() == GeoJsonConfiguration.NESTED_OBJECTS.NEST && config.getMultiplicityStrategy() != GeoJsonConfiguration.MULTIPLICITY.ARRAY) {
builder.addStrictErrors(MessageFormat.format("The GeoJSON Nested Object Strategy ''FLATTEN'' in collection ''{0}'' cannot be combined with the Multiplicity Strategy ''{1}''.", collectionId, config.getMultiplicityStrategy()));
}
List<String> separators = ImmutableList.of(".", "_", ":", "/");
if (!separators.contains(config.getSeparator())) {
builder.addStrictErrors(MessageFormat.format("The separator ''{0}'' in collection ''{1}'' is invalid, it must be one of {2}.", config.getSeparator(), collectionId, separators));
}
}
Map<String, Collection<String>> keyMap = geoJsonConfigurationMap.entrySet().stream().map(entry -> new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), entry.getValue().getTransformations().keySet())).collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
for (Map.Entry<String, Collection<String>> stringCollectionEntry : featuresCoreValidator.getInvalidPropertyKeys(keyMap, featureSchemas).entrySet()) {
for (String property : stringCollectionEntry.getValue()) {
builder.addStrictErrors(MessageFormat.format("A transformation for property ''{0}'' in collection ''{1}'' is invalid, because the property was not found in the provider schema.", property, stringCollectionEntry.getKey()));
}
}
Set<String> codelists = entityRegistry.getEntitiesForType(Codelist.class).stream().map(Codelist::getId).collect(Collectors.toUnmodifiableSet());
for (Map.Entry<String, GeoJsonConfiguration> entry : geoJsonConfigurationMap.entrySet()) {
String collectionId = entry.getKey();
for (Map.Entry<String, List<PropertyTransformation>> entry2 : entry.getValue().getTransformations().entrySet()) {
String property = entry2.getKey();
for (PropertyTransformation transformation : entry2.getValue()) {
builder = transformation.validate(builder, collectionId, property, codelists);
}
}
}
return builder.build();
}
use of de.ii.xtraplatform.codelists.domain.Codelist in project ldproxy by interactive-instruments.
the class EndpointFeatures method onStartup.
@Override
public ValidationResult onStartup(OgcApi api, MODE apiValidation) {
ValidationResult result = super.onStartup(api, apiValidation);
// no additional operational checks for now, only validation; we can stop, if no validation is requested
if (apiValidation == MODE.NONE)
return result;
ImmutableValidationResult.Builder builder = ImmutableValidationResult.builder().from(result).mode(apiValidation);
Map<String, FeatureSchema> featureSchemas = providers.getFeatureSchemas(api.getData());
List<String> invalidCollections = featuresCoreValidator.getCollectionsWithoutType(api.getData(), featureSchemas);
for (String invalidCollection : invalidCollections) {
builder.addStrictErrors(MessageFormat.format("The Collection ''{0}'' is invalid, because its feature type was not found in the provider schema.", invalidCollection));
}
// get Features Core configurations to process
Map<String, FeaturesCoreConfiguration> coreConfigs = api.getData().getCollections().entrySet().stream().map(entry -> {
final FeatureTypeConfigurationOgcApi collectionData = entry.getValue();
final FeaturesCoreConfiguration config = collectionData.getExtension(FeaturesCoreConfiguration.class).orElse(null);
if (Objects.isNull(config))
return null;
return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), config);
}).filter(Objects::nonNull).collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
Map<String, Collection<String>> transformationKeys = coreConfigs.entrySet().stream().map(entry -> new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), entry.getValue().getTransformations().keySet())).collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
for (Map.Entry<String, Collection<String>> stringCollectionEntry : featuresCoreValidator.getInvalidPropertyKeys(transformationKeys, featureSchemas).entrySet()) {
for (String property : stringCollectionEntry.getValue()) {
builder.addStrictErrors(MessageFormat.format("A transformation for property ''{0}'' in collection ''{1}'' is invalid, because the property was not found in the provider schema.", property, stringCollectionEntry.getKey()));
}
}
transformationKeys = coreConfigs.entrySet().stream().map(entry -> new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), entry.getValue().getQueryables().orElse(FeaturesCollectionQueryables.of()).getAll())).collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
for (Map.Entry<String, Collection<String>> stringCollectionEntry : featuresCoreValidator.getInvalidPropertyKeys(transformationKeys, featureSchemas).entrySet()) {
for (String property : stringCollectionEntry.getValue()) {
builder.addStrictErrors(MessageFormat.format("A queryable ''{0}'' in collection ''{1}'' is invalid, because the property was not found in the provider schema.", property, stringCollectionEntry.getKey()));
}
}
for (Map.Entry<String, FeaturesCoreConfiguration> entry : coreConfigs.entrySet()) {
String collectionId = entry.getKey();
FeaturesCoreConfiguration config = entry.getValue();
if (config.getMinimumPageSize() < 1) {
builder.addStrictErrors(MessageFormat.format("The minimum page size ''{0}'' in collection ''{1}'' is invalid, it must be a positive integer.", config.getMinimumPageSize(), collectionId));
}
if (config.getMinimumPageSize() > config.getMaximumPageSize()) {
builder.addStrictErrors(MessageFormat.format("The minimum page size ''{0}'' in collection ''{1}'' is invalid, it cannot be greater than the maximum page size ''{2}''.", config.getMinimumPageSize(), collectionId, config.getMaximumPageSize()));
}
if (config.getMinimumPageSize() > config.getDefaultPageSize()) {
builder.addStrictErrors(MessageFormat.format("The minimum page size ''{0}'' in collection ''{1}'' is invalid, it cannot be greater than the default page size ''{2}''.", config.getMinimumPageSize(), collectionId, config.getDefaultPageSize()));
}
if (config.getMaximumPageSize() < config.getDefaultPageSize()) {
builder.addStrictErrors(MessageFormat.format("The maxmimum page size ''{0}'' in collection ''{1}'' is invalid, it must be at least the default page size ''{2}''.", config.getMaximumPageSize(), collectionId, config.getDefaultPageSize()));
}
}
Set<String> codelists = entityRegistry.getEntitiesForType(Codelist.class).stream().map(Codelist::getId).collect(Collectors.toUnmodifiableSet());
for (Map.Entry<String, FeaturesCoreConfiguration> entry : coreConfigs.entrySet()) {
String collectionId = entry.getKey();
for (Map.Entry<String, List<PropertyTransformation>> entry2 : entry.getValue().getTransformations().entrySet()) {
String property = entry2.getKey();
for (PropertyTransformation transformation : entry2.getValue()) {
builder = transformation.validate(builder, collectionId, property, codelists);
}
}
}
return builder.build();
}
Aggregations