Search in sources :

Example 6 with CustomPropertyFunction

use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.

the class AbstractDefaultFunctionService method getPropertyFunctions.

@Override
public Collection<? extends PropertyFunctionDefinition> getPropertyFunctions(String categoryId) {
    Collection<? extends PropertyFunctionDefinition> functions = super.getPropertyFunctions(categoryId);
    Alignment al = getCurrentAlignment();
    if (al != null) {
        List<PropertyFunctionDefinition> cfs = new ArrayList<>();
        for (CustomPropertyFunction cf : al.getAllCustomPropertyFunctions().values()) {
            PropertyFunctionDefinition descriptor = cf.getDescriptor();
            if (Objects.equal(categoryId, descriptor.getCategoryId())) {
                cfs.add(new AlignmentFunctionDescriptor(descriptor));
            }
        }
        cfs.addAll(functions);
        functions = cfs;
    }
    return functions;
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ArrayList(java.util.ArrayList) PropertyFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)

Example 7 with CustomPropertyFunction

use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.

the class AbstractBaseAlignmentLoader method processBaseAlignments.

/**
 * Creates and adds cells and modifiers of the base alignments to the main
 * alignment.
 *
 * @param alignment the alignment to add base alignments to
 * @param sourceTypes the source types to use for resolving definition
 *            references
 * @param targetTypes the target types to use for resolving definition
 *            references
 * @param prefixMapping gets filled with a mapping from local to global
 *            prefixes
 * @param alignmentToInfo gets filled with a mapping from base alignment
 *            representations to prefixes and URIs
 * @param reporter the I/O reporter to report any errors to, may be
 *            <code>null</code>
 * @throws IOException if one of the base alignments does not have cell ids
 */
private void processBaseAlignments(MutableAlignment alignment, TypeIndex sourceTypes, TypeIndex targetTypes, Map<A, Map<String, String>> prefixMapping, Map<A, AlignmentInfo> alignmentToInfo, IOReporter reporter) throws IOException {
    for (Entry<A, AlignmentInfo> base : alignmentToInfo.entrySet()) {
        Collection<C> baseCells = getCells(base.getKey());
        boolean hasIds = true;
        for (C baseCell : baseCells) if (Strings.isNullOrEmpty(getCellId(baseCell))) {
            hasIds = false;
            break;
        }
        if (!hasIds) {
            throw new IOException("At least one base alignment (" + base.getValue().uri.absoluteURI + ") has no cell ids. Please load and save it to generate them.");
        }
    }
    for (Entry<A, AlignmentInfo> base : alignmentToInfo.entrySet()) {
        if (alignment.getBaseAlignments().containsValue(base.getValue().uri.usedURI)) {
            // base alignment already present
            // can currently happen with base alignments included in base
            // alignments
            reporter.warn(new IOMessageImpl("Base alignment at " + base.getValue().uri.usedURI + " has already been added", null));
        } else {
            Collection<CustomPropertyFunction> baseFunctions = getPropertyFunctions(base.getKey(), sourceTypes, targetTypes);
            Collection<C> baseCells = getCells(base.getKey());
            Collection<BaseAlignmentCell> createdBaseCells = new ArrayList<BaseAlignmentCell>(baseCells.size());
            List<MutableCell> createdCells = new ArrayList<>(baseCells.size());
            for (C baseCell : baseCells) {
                // add cells of base alignments
                MutableCell cell = createCell(baseCell, sourceTypes, targetTypes, reporter);
                if (cell != null) {
                    createdCells.add(cell);
                }
            }
            // Migrate UnmigratedCells
            migrateCells(createdCells, reporter);
            for (MutableCell cell : createdCells) {
                createdBaseCells.add(new BaseAlignmentCell(cell, base.getValue().uri.usedURI, base.getValue().prefix));
            }
            alignment.addBaseAlignment(base.getValue().prefix, base.getValue().uri.usedURI, createdBaseCells, baseFunctions);
        }
    }
    // add modifiers of base alignments
    for (Entry<A, AlignmentInfo> base : alignmentToInfo.entrySet()) applyModifiers(alignment, getModifiers(base.getKey()), prefixMapping.get(base.getKey()), base.getValue().prefix, true, reporter);
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)

Example 8 with CustomPropertyFunction

use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.

the class AbstractDefaultFunctionService method getCustomPropertyFunction.

private PropertyFunctionDefinition getCustomPropertyFunction(String id) {
    Alignment al = getCurrentAlignment();
    if (al != null) {
        String localId = id;
        if (localId.startsWith(PREFIX_ALIGNMENT_FUNCTION)) {
            localId = localId.substring(PREFIX_ALIGNMENT_FUNCTION.length());
        }
        CustomPropertyFunction cf = al.getAllCustomPropertyFunctions().get(localId);
        if (cf != null) {
            return new AlignmentFunctionDescriptor(cf.getDescriptor());
        }
    }
    return null;
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)

Example 9 with CustomPropertyFunction

use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.

the class AbstractDefaultTransformationFunctionService method getPropertyTransformations.

@Override
public List<PropertyTransformationFactory> getPropertyTransformations(String functionId) {
    List<PropertyTransformationFactory> functions = super.getPropertyTransformations(functionId);
    Alignment al = getCurrentAlignment();
    if (al != null) {
        List<PropertyTransformationFactory> cfs = new ArrayList<>(functions);
        String localId = functionId;
        if (localId.startsWith(PREFIX_ALIGNMENT_FUNCTION)) {
            localId = localId.substring(PREFIX_ALIGNMENT_FUNCTION.length());
        }
        CustomPropertyFunction cf = al.getAllCustomPropertyFunctions().get(localId);
        if (cf != null) {
            cfs.add(new CustomPropertyFunctionFactory(cf));
        }
        functions = cfs;
    }
    return functions;
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ArrayList(java.util.ArrayList) PropertyTransformationFactory(eu.esdihumboldt.hale.common.align.extension.transformation.PropertyTransformationFactory) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)

Example 10 with CustomPropertyFunction

use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.

the class JaxbToAlignment method getPropertyFunctions.

@Override
protected Collection<CustomPropertyFunction> getPropertyFunctions(AlignmentType source, TypeIndex sourceTypes, TypeIndex targetTypes) {
    LoadAlignmentContextImpl context = new LoadAlignmentContextImpl();
    context.setSourceTypes(sourceTypes);
    context.setTargetTypes(targetTypes);
    Collection<CustomPropertyFunction> result = new ArrayList<>();
    List<CustomFunctionType> functions = source.getCustomFunction();
    if (functions != null) {
        for (CustomFunctionType function : functions) {
            Element elem = function.getAny();
            if (elem != null) {
                CustomPropertyFunction cf = HaleIO.getComplexValue(elem, CustomPropertyFunction.class, context);
                if (cf != null) {
                    result.add(cf);
                }
            }
        }
    }
    return result;
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction) CustomFunctionType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CustomFunctionType)

Aggregations

CustomPropertyFunction (eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)10 ArrayList (java.util.ArrayList)7 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)4 DefaultCustomPropertyFunction (eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction)3 PropertyFunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)2 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)2 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)2 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)2 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)2 IContributionItem (org.eclipse.jface.action.IContributionItem)2 PropertyTransformationFactory (eu.esdihumboldt.hale.common.align.extension.transformation.PropertyTransformationFactory)1 CustomFunctionType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CustomFunctionType)1 ModifiableCell (eu.esdihumboldt.hale.common.align.model.ModifiableCell)1 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1