Search in sources :

Example 51 with Entity

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;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) Value(eu.esdihumboldt.hale.common.core.io.Value)

Example 52 with Entity

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;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity)

Example 53 with Entity

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;
}
Also used : List(java.util.List) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Locale(java.util.Locale) Map(java.util.Map) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) Entity(eu.esdihumboldt.hale.common.align.model.Entity) FormattedStringFunction(eu.esdihumboldt.hale.common.align.model.functions.FormattedStringFunction) AbstractCellExplanation(eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation) Collectors(java.util.stream.Collectors) CellUtil(eu.esdihumboldt.hale.common.align.model.CellUtil) MessageFormat(java.text.MessageFormat) Entity(eu.esdihumboldt.hale.common.align.model.Entity)

Example 54 with Entity

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;
}
Also used : List(java.util.List) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MergeFunction(eu.esdihumboldt.hale.common.align.model.functions.MergeFunction) Locale(java.util.Locale) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) Entity(eu.esdihumboldt.hale.common.align.model.Entity) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) AbstractCellExplanation(eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation) Collectors(java.util.stream.Collectors) CellUtil(eu.esdihumboldt.hale.common.align.model.CellUtil) MessageFormat(java.text.MessageFormat) Entity(eu.esdihumboldt.hale.common.align.model.Entity) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue)

Example 55 with Entity

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;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Pair(eu.esdihumboldt.util.Pair)

Aggregations

Entity (eu.esdihumboldt.hale.common.align.model.Entity)64 Cell (eu.esdihumboldt.hale.common.align.model.Cell)25 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)21 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)14 ArrayList (java.util.ArrayList)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)9 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)9 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)9 List (java.util.List)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)8 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)6 HashSet (java.util.HashSet)6 Locale (java.util.Locale)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)5 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)4 CellUtil (eu.esdihumboldt.hale.common.align.model.CellUtil)4 CellLog (eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog)4 AbstractCellExplanation (eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation)4