Search in sources :

Example 1 with CustomPropertyFunction

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

the class EditCustomFunctionContribution method fill.

@Override
public void fill(Menu menu, int index) {
    AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
    Collection<CustomPropertyFunction> functions = alignmentService.getAlignment().getCustomPropertyFunctions().values();
    for (CustomPropertyFunction function : functions) {
        if (function instanceof DefaultCustomPropertyFunction) {
            // XXX currently only these functions editable
            DefaultCustomPropertyFunction cf = (DefaultCustomPropertyFunction) function;
            EditWizardAction action = new EditWizardAction(cf, alignmentService);
            IContributionItem item = new ActionContributionItem(action);
            item.fill(menu, index++);
        }
    }
// TODO add base alignment functions (disabled, with separator)?
}
Also used : DefaultCustomPropertyFunction(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) IContributionItem(org.eclipse.jface.action.IContributionItem) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction) DefaultCustomPropertyFunction(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction)

Example 2 with CustomPropertyFunction

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

the class RemoveCustomFunctionContribution method fill.

@Override
public void fill(Menu menu, int index) {
    AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
    Collection<CustomPropertyFunction> functions = alignmentService.getAlignment().getCustomPropertyFunctions().values();
    for (CustomPropertyFunction function : functions) {
        if (function instanceof DefaultCustomPropertyFunction) {
            // XXX currently only these functions editable
            DefaultCustomPropertyFunction cf = (DefaultCustomPropertyFunction) function;
            RemoveCustomFunctionAction action = new RemoveCustomFunctionAction(cf, alignmentService);
            IContributionItem item = new ActionContributionItem(action);
            item.fill(menu, index++);
        }
    }
// TODO add base alignment functions (disabled, with separator)?
}
Also used : DefaultCustomPropertyFunction(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) IContributionItem(org.eclipse.jface.action.IContributionItem) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction) DefaultCustomPropertyFunction(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction)

Example 3 with CustomPropertyFunction

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

the class AlignmentServiceImpl method addOrUpdateAlignment.

/**
 * @see AlignmentService#addOrUpdateAlignment(MutableAlignment)
 */
@Override
public void addOrUpdateAlignment(MutableAlignment alignment) {
    Collection<Cell> added = new ArrayList<Cell>();
    /*
		 * XXX Updates for disables not supported
		 * 
		 * One problem is, that base alignments shouldn't be added twice, so if
		 * the given alignment contains a base alignment that is also contained
		 * in the current alignment it won't be added.
		 * 
		 * Now what about cells in the given alignment, that reference those
		 * base alignments (-> disabled for)? They need to be changed to the
		 * base alignment cells of the current alignment.
		 * 
		 * Those cells can be obtained by replacing the prefix part of the cell
		 * and using getCell(String).
		 * 
		 * XXX Addition of base alignments not supported
		 * 
		 * Here the problem is, that it is not enough to gather the base
		 * alignment cells and change their prefix to a new one, since the base
		 * cell could be another base alignment cell, which would need to
		 * change, too. They would have to be added in order. An option would be
		 * to load them with the base alignment loading mechanism, which would
		 * result in a loss of additional disables.
		 * 
		 * XXX Changes of conflicting base alignment cells not handled
		 */
    // if (!alignment.getBaseAlignments().isEmpty()) {
    // _log.warn("Adding alignments currently does not support merging of base alignments. Import base alignments independently.");
    // }
    boolean addedBaseCells = false;
    // add cells
    synchronized (this) {
        for (Cell cell : alignment.getCells()) {
            if (cell instanceof MutableCell) {
                this.alignment.addCell((MutableCell) cell);
                added.add(cell);
            } else if (!(cell instanceof BaseAlignmentCell)) {
                throw new IllegalStateException("The given alignment contained a cell which is neither mutable nor from a base alignment.");
            } else {
                addedBaseCells = true;
            }
        }
    }
    synchronized (this) {
        // XXX this needs merging, see above
        boolean first = true;
        for (Entry<String, URI> baseAlignment : alignment.getBaseAlignments().entrySet()) {
            Collection<CustomPropertyFunction> baseFunctions;
            if (first) {
                // XXX hack - insert all base functions with the first base
                // alignment
                baseFunctions = alignment.getBasePropertyFunctions().values();
            } else {
                // base functions should only be added once
                baseFunctions = Collections.<CustomPropertyFunction>emptyList();
            }
            this.alignment.addBaseAlignment(baseAlignment.getKey(), baseAlignment.getValue(), // 
            alignment.getBaseAlignmentCells(baseAlignment.getValue()), baseFunctions);
        }
    }
    // add custom functions
    boolean addedFunctions = false;
    synchronized (this) {
        for (CustomPropertyFunction cf : alignment.getCustomPropertyFunctions().values()) {
            this.alignment.addCustomPropertyFunction(cf);
            addedFunctions = true;
        }
    }
    if (addedBaseCells || (!added.isEmpty() && addedFunctions)) {
        // only emit one combined event (not to trigger multiple
        // transformations)
        notifyAlignmentChanged();
    } else {
        if (!added.isEmpty()) {
            notifyCellsAdded(added);
        }
        if (addedFunctions) {
            notifyCustomFunctionsChanged();
        }
    }
}
Also used : BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) ArrayList(java.util.ArrayList) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ModifiableCell(eu.esdihumboldt.hale.common.align.model.ModifiableCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) URI(java.net.URI) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)

Example 4 with CustomPropertyFunction

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

the class PreferencesGroovyService method getScriptHash.

/**
 * Calculates the current alignments script hash.
 *
 * @return the current alignments script hash
 */
private synchronized String getScriptHash() {
    if (scriptHash == null) {
        List<String> scripts = new ArrayList<>();
        // get all Groovy scripts
        for (Cell cell : alignmentService.getAlignment().getCells()) {
            ListMultimap<String, ParameterValue> parameters = cell.getTransformationParameters();
            if (parameters == null)
                continue;
            // Groovy transformations
            if (cell.getTransformationIdentifier().contains("groovy")) {
                List<ParameterValue> val = parameters.get(GroovyConstants.PARAMETER_SCRIPT);
                if (!val.isEmpty()) {
                    String script = getScriptString(val.get(0));
                    if (script != null) {
                        scripts.add(script);
                    }
                }
            }
            // GroovyScript function parameters
            for (ParameterValue value : parameters.values()) {
                if (GroovyScript.GROOVY_SCRIPT_ID.equals(value.getType())) {
                    String script = getScriptString(value);
                    if (script != null) {
                        scripts.add(script);
                    }
                }
            }
        }
        // Groovy scripts of custom property functions
        for (CustomPropertyFunction customFunction : alignmentService.getAlignment().getAllCustomPropertyFunctions().values()) {
            if (customFunction instanceof DefaultCustomPropertyFunction) {
                DefaultCustomPropertyFunction cf = (DefaultCustomPropertyFunction) customFunction;
                if (CustomPropertyFunctionType.GROOVY.equals(cf.getFunctionType())) {
                    Value functionDef = cf.getFunctionDefinition();
                    if (functionDef != null && !functionDef.isEmpty()) {
                        String script = getScriptString(functionDef);
                        if (script != null) {
                            scripts.add(script);
                        }
                    }
                }
            }
        }
        // order scripts (for consistent hash)
        Collections.sort(scripts);
        // modify the script in a undetectable way
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            for (String script : scripts) md.update(script.getBytes("UTF-8"));
            byte[] hash = md.digest();
            StringBuilder sb = new StringBuilder(2 * hash.length);
            for (byte b : hash) {
                sb.append(String.format("%02x", b & 0xff));
            }
            scriptHash = sb.toString();
        // Both exceptions cannot happen in a valid Java platform.
        // Anyways, if they happen, execution should stop here!
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("No MD5 MessageDigest!");
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException("No UTF-8 Charset!");
        }
    }
    return scriptHash;
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DefaultCustomPropertyFunction(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction) Value(eu.esdihumboldt.hale.common.core.io.Value) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) MessageDigest(java.security.MessageDigest) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCustomPropertyFunction(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)

Example 5 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() {
    Collection<? extends PropertyFunctionDefinition> functions = super.getPropertyFunctions();
    Alignment al = getCurrentAlignment();
    if (al != null) {
        List<PropertyFunctionDefinition> cfs = new ArrayList<>();
        for (CustomPropertyFunction cf : al.getAllCustomPropertyFunctions().values()) {
            cfs.add(new AlignmentFunctionDescriptor(cf.getDescriptor()));
        }
        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)

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