use of org.eclipse.winery.model.tosca.kvproperties.PropertyDefinitionKV in project winery by eclipse.
the class ConsistencyChecker method checkPropertiesValidation.
public static void checkPropertiesValidation(ConsistencyErrorLogger errorLogger, ConsistencyCheckerConfiguration configuration, DefinitionsChildId id) {
if (id instanceof EntityTemplateId) {
TEntityTemplate entityTemplate = (TEntityTemplate) configuration.getRepository().getDefinitions(id).getElement();
if (Objects.isNull(entityTemplate.getType())) {
// no printing necessary; type consistency is checked at other places
return;
}
final TEntityType entityType = configuration.getRepository().getTypeForTemplate(entityTemplate);
final WinerysPropertiesDefinition winerysPropertiesDefinition = entityType.getWinerysPropertiesDefinition();
final TEntityType.PropertiesDefinition propertiesDefinition = entityType.getPropertiesDefinition();
if ((winerysPropertiesDefinition != null) || (propertiesDefinition != null)) {
final TEntityTemplate.Properties properties = entityTemplate.getProperties();
if (properties == null) {
printAndAddError(errorLogger, configuration.getVerbosity(), id, "Properties required, but no properties defined");
return;
}
if (winerysPropertiesDefinition != null) {
Map<String, String> kvProperties = entityTemplate.getProperties().getKVProperties();
if (kvProperties.isEmpty()) {
printAndAddError(errorLogger, configuration.getVerbosity(), id, "Properties required, but no properties set (any case)");
return;
}
for (PropertyDefinitionKV propertyDefinitionKV : winerysPropertiesDefinition.getPropertyDefinitionKVList().getPropertyDefinitionKVs()) {
String key = propertyDefinitionKV.getKey();
if (kvProperties.get(key) == null) {
printAndAddError(errorLogger, configuration.getVerbosity(), id, "Property " + key + " required, but not set.");
} else {
// remove the key from the map to enable checking below whether a property is defined which not requried by the property definition
kvProperties.remove(key);
}
}
// If any key is left, this is a key not defined at the schema
for (Object o : kvProperties.keySet()) {
printAndAddError(errorLogger, configuration.getVerbosity(), id, "Property " + o + " set, but not defined at schema.");
}
} else if (propertiesDefinition != null) {
@Nullable final Object any = properties.getAny();
if (any == null) {
printAndAddError(errorLogger, configuration.getVerbosity(), id, "Properties required, but no properties defined (any case)");
return;
}
@Nullable final QName element = propertiesDefinition.getElement();
if (element != null) {
final Map<String, RepositoryFileReference> mapFromLocalNameToXSD = configuration.getRepository().getXsdImportManager().getMapFromLocalNameToXSD(new Namespace(element.getNamespaceURI(), false), false);
final RepositoryFileReference repositoryFileReference = mapFromLocalNameToXSD.get(element.getLocalPart());
if (repositoryFileReference == null) {
printAndAddError(errorLogger, configuration.getVerbosity(), id, "No Xml Schema definition found for " + element);
return;
}
validate(errorLogger, repositoryFileReference, any, configuration, id);
}
}
}
}
}
Aggregations