use of eu.esdihumboldt.hale.common.align.extension.function.ParameterDefinition in project hale by halestudio.
the class MarkdownCellExplanation method addEntityBindings.
private void addEntityBindings(Map<String, Object> binding, Set<? extends ParameterDefinition> definitions, ListMultimap<String, ? extends Entity> entities, String defaultName, boolean html, Locale locale) {
if (!definitions.isEmpty()) {
if (definitions.size() == 1) {
// single entity
ParameterDefinition def = definitions.iterator().next();
// _defaultName always maps to single entity
addEntityBindingValue(defaultName, def, entities.get(def.getName()), html, binding, locale);
// in addition also the name if it is present
String name = def.getName();
if (name != null) {
addEntityBindingValue(name, def, entities.get(name), html, binding, locale);
}
} else {
for (ParameterDefinition def : definitions) {
// add each entity based on its name, the default name is
// used for the null entity
String name = def.getName();
if (name != null) {
addEntityBindingValue(name, def, entities.get(name), html, binding, locale);
} else {
// null entity -> default name
addEntityBindingValue(defaultName, def, entities.get(name), html, binding, locale);
}
}
}
}
}
use of eu.esdihumboldt.hale.common.align.extension.function.ParameterDefinition in project hale by halestudio.
the class CellNodeValidator method validate.
/**
* Validate a cell node.
*
* @param node the cell node
* @param sources the named source entities and nodes
* @param targets the named target entities and nodes
* @return if the cell node is valid for execution
*/
protected boolean validate(CellNode node, ListMultimap<String, Pair<SourceNode, Entity>> sources, ListMultimap<String, Pair<TargetNode, Entity>> targets) {
String functionId = node.getCell().getTransformationIdentifier();
FunctionDefinition<?> function = serviceProvider.getService(FunctionService.class).getFunction(functionId);
if (function != null) {
// check source node occurrence for mandatory source entities
for (ParameterDefinition sourceParam : function.getSource()) {
int min = sourceParam.getMinOccurrence();
if (sources.get(sourceParam.getName()).size() < min) {
return false;
}
}
return true;
} else {
reporter.error(new TransformationMessageImpl(node.getCell(), "Invalid cell - function not found: " + functionId, null));
}
return false;
}
use of eu.esdihumboldt.hale.common.align.extension.function.ParameterDefinition in project hale by halestudio.
the class SchemaSelectionFunctionMatcher method checkCount.
/**
* Checks if the given entity count is compatible with the given set of
* entity definitions
*
* @param count the entity count
* @param entities the entity definitions
* @param isTarget if the entities are target entities
* @return if then entity count is compatible with the definitions
*/
protected boolean checkCount(int count, Set<? extends ParameterDefinition> entities, boolean isTarget) {
int min = 0;
int max = 0;
for (ParameterDefinition param : entities) {
min += param.getMinOccurrence();
if (max != AbstractParameter.UNBOUNDED) {
int pMax = param.getMaxOccurrence();
if (pMax == AbstractParameter.UNBOUNDED) {
max = pMax;
} else {
max += pMax;
}
}
}
// check minimum
if (count < min) {
return false;
}
if (max == 0 && !isTarget) {
// allow augmentations
return true;
}
// check maximum
if (max != AbstractParameter.UNBOUNDED && count > max) {
return false;
}
return true;
}
Aggregations