use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class ClassificationMappingExplanation method getExplanationAsHtml.
@Override
public String getExplanationAsHtml(Cell cell, ServiceProvider provider, Locale locale) {
Entity target = CellUtil.getFirstEntity(cell.getTarget());
Entity source = CellUtil.getFirstEntity(cell.getSource());
LookupTable lookup = ClassificationMappingUtil.getClassificationLookup(cell.getTransformationParameters(), provider);
ListMultimap<Value, Value> revLookup = lookup.reverse();
String notClassifiedAction = CellUtil.getFirstParameter(cell, PARAMETER_NOT_CLASSIFIED_ACTION).as(String.class);
if (target != null && source != null) {
StringBuilder mappingString = new StringBuilder();
mappingString.append("<table border=\"1\"><tr><th>");
mappingString.append(getMessage("captionSource", locale));
mappingString.append("</th><th>");
mappingString.append(getMessage("captionTarget", locale));
mappingString.append("</th></tr>");
for (Value targetValue : revLookup.keySet()) {
mappingString.append("<tr><td>");
int i = 1;
for (Value sourceValue : revLookup.get(targetValue)) {
if (i != 1) {
mappingString.append(", ");
}
mappingString.append(quoteText(sourceValue.as(String.class), true));
i++;
}
mappingString.append("</td><td>");
mappingString.append(quoteText(targetValue.as(String.class), true));
mappingString.append("</td></tr>");
}
mappingString.append("</table>");
String notClassifiedResult = "null";
if (USE_SOURCE_ACTION.equals(notClassifiedAction))
notClassifiedResult = getMessage("useSource", locale);
else if (notClassifiedAction != null && notClassifiedAction.startsWith(USE_FIXED_VALUE_ACTION_PREFIX))
notClassifiedResult = quoteText(notClassifiedAction.substring(notClassifiedAction.indexOf(':') + 1), true);
return MessageFormat.format(getMessage("main", locale), formatEntity(target, true, true, locale), formatEntity(source, true, true, locale), mappingString.toString(), notClassifiedResult).replaceAll("\n", "<br />");
}
return null;
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class CreateExplanation method getExplanation.
@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
Entity target = CellUtil.getFirstEntity(cell.getTarget());
int number = CellUtil.getOptionalParameter(cell, PARAM_NUMBER, Value.of(1)).as(Integer.class);
String instancesString;
if (number == 1) {
instancesString = getMessage("one", locale);
} else {
instancesString = MessageFormat.format(getMessage("many", locale), number);
}
if (target != null)
return MessageFormat.format(getMessage("main", locale), instancesString, formatEntity(target, html, true, locale));
return null;
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class FormattedStringExplanation method getExplanation.
@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
Entity target = CellUtil.getFirstEntity(cell.getTarget());
String pattern = CellUtil.getFirstParameter(cell, PARAMETER_PATTERN).as(String.class);
List<? extends Entity> sources = null;
if (cell.getSource() != null) {
sources = cell.getSource().get(ENTITY_VARIABLE);
}
if (target != null && pattern != null) {
if (html)
pattern = "<pre>" + pattern + "</pre>";
String explanation = MessageFormat.format(getMessage("main", locale), formatEntity(target, html, true, locale), pattern);
if (html)
explanation = explanation.replaceAll("\n", "<br />");
if (sources != null && html) {
Map<String, String> varToProperty = sources.stream().collect(Collectors.toMap(entity -> {
return '{' + getEntityNameWithoutCondition(entity) + '}';
}, entity -> {
return formatEntity(entity, true, false, locale);
}));
explanation += buildReplacementTable(varToProperty, locale);
}
return explanation;
}
return null;
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class MergeExplanation method getExplanation.
@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
Entity source = CellUtil.getFirstEntity(cell.getSource());
Entity target = CellUtil.getFirstEntity(cell.getTarget());
List<ParameterValue> properties = (cell.getTransformationParameters() == null) ? (null) : (cell.getTransformationParameters().get(PARAMETER_PROPERTY));
if (source != null && target != null) {
if (properties != null && !properties.isEmpty()) {
List<String> props = properties.stream().map(prop -> quoteText(prop.as(String.class), html)).collect(Collectors.toList());
String propertiesString = enumerateJoin(props, locale);
return MessageFormat.format(getMessage("main", locale), formatEntity(source, html, true, locale), formatEntity(target, html, true, locale), propertiesString);
} else {
return MessageFormat.format(getMessage("all", locale), formatEntity(source, html, true, locale), formatEntity(target, html, true, locale));
}
}
return null;
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class CellNodeValidator method visit.
/**
* @see AbstractTargetToSourceVisitor#visit(CellNode)
*/
@Override
public boolean visit(CellNode node) {
// evaluate if for the cell all needed inputs are set
Cell cell = node.getCell();
// collect source and target nodes per entity name
ListMultimap<String, Pair<SourceNode, Entity>> sources = ArrayListMultimap.create();
if (cell.getSource() != null) {
for (Entry<String, ? extends Entity> sourceEntry : cell.getSource().entries()) {
String name = sourceEntry.getKey();
Entity entity = sourceEntry.getValue();
SourceNode sourceNode = findSourceNode(node, entity);
if (sourceNode != null) {
if (sourceNode.isDefined()) {
sources.put(name, new Pair<SourceNode, Entity>(sourceNode, entity));
}
} else {
log.error("Source node for entity not found.");
}
}
}
ListMultimap<String, Pair<TargetNode, Entity>> targets = ArrayListMultimap.create();
for (Entry<String, ? extends Entity> targetEntry : cell.getTarget().entries()) {
String name = targetEntry.getKey();
Entity entity = targetEntry.getValue();
TargetNode targetNode = findTargetNode(node, entity);
if (targetNode != null) {
targets.put(name, new Pair<TargetNode, Entity>(targetNode, entity));
} else {
log.error("Target node for entity not found.");
}
}
boolean valid = validate(node, sources, targets);
if (valid) {
processValid(cell, sources, targets);
}
node.setValid(valid);
// don't visit source nodes
return false;
}
Aggregations