Search in sources :

Example 61 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class DefaultProjectWriter method updateRelativeResourcePaths.

private void updateRelativeResourcePaths(Iterable<IOConfiguration> resources, URI previousTarget, URI newTarget) {
    // if the previous target is null, there cannot be relative paths
    if (previousTarget == null)
        return;
    for (IOConfiguration resource : resources) {
        Map<String, Value> providerConfig = resource.getProviderConfiguration();
        URI pathUri = URI.create(providerConfig.get(ImportProvider.PARAM_SOURCE).as(String.class));
        // update relative URIs
        if (!pathUri.isAbsolute()) {
            // resolve the resource's URI
            pathUri = previousTarget.resolve(pathUri);
            // try to get a relative path from the new project to the
            // resource
            URI relative = IOUtils.getRelativePath(pathUri, newTarget);
            providerConfig.put(ImportProvider.PARAM_SOURCE, Value.of(relative.toString()));
        }
    }
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) Value(eu.esdihumboldt.hale.common.core.io.Value) URI(java.net.URI)

Example 62 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class JaxbToProject method toIOConfiguration.

/**
 * Convert a JAXB representation to an {@link IOConfiguration}.
 *
 * @param config the JAXB representation
 * @return the I/O configuration
 */
public static IOConfiguration toIOConfiguration(IOConfigurationType config) {
    if (config == null) {
        return null;
    }
    IOConfiguration result = new IOConfiguration();
    result.setActionId(config.getActionId());
    result.setProviderId(config.getProviderId());
    for (JAXBElement<?> setting : config.getAbstractSetting()) {
        Object value = setting.getValue();
        if (value instanceof PropertyType) {
            addProperty(result.getProviderConfiguration(), (PropertyType) value);
        } else if (value instanceof ComplexPropertyType) {
            addProperty(result.getProviderConfiguration(), (ComplexPropertyType) value);
        }
    }
    // cache
    ValueType cache = config.getCache();
    if (cache != null) {
        Value value = Value.NULL;
        if (cache.getAny() != null) {
            value = new ElementValue(cache.getAny(), null);
        } else if (cache.getValue() != null) {
            value = Value.of(cache.getValue());
        }
        result.setCache(value);
    }
    return result;
}
Also used : ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ValueType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ValueType) ElementValue(eu.esdihumboldt.hale.common.core.io.impl.ElementValue) Value(eu.esdihumboldt.hale.common.core.io.Value) PropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.PropertyType) ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType) ElementValue(eu.esdihumboldt.hale.common.core.io.impl.ElementValue)

Example 63 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class LocationUpdater method updateProject.

/**
 * Update locations in the given project.
 *
 * @param keepRelative whether to keep working relative URIs as is or make
 *            them absolute
 */
public void updateProject(boolean keepRelative) {
    if (project == null || getOldLocation() == null || getNewLocation() == null)
        return;
    IOConfiguration saveconfig = project.getSaveConfiguration();
    // actually cannot be null here because then old location would be null
    if (saveconfig == null)
        return;
    if (!getOldLocation().equals(getNewLocation()) || !keepRelative) {
        // update save configuration
        saveconfig.getProviderConfiguration().put(ExportProvider.PARAM_TARGET, Value.of(getNewLocation().toString()));
        // update I/O configurations
        List<IOConfiguration> configuration = project.getResources();
        for (IOConfiguration providerconf : configuration) {
            final Map<String, Value> conf = providerconf.getProviderConfiguration();
            final URI uri = URI.create(conf.get(ImportProvider.PARAM_SOURCE).as(String.class));
            URI resolved = findLocation(uri, true, true, keepRelative);
            if (resolved != null)
                conf.put(ImportProvider.PARAM_SOURCE, Value.of(resolved.toString()));
        }
        // update project file infos
        for (ProjectFileInfo fileInfo : project.getProjectFiles()) {
            URI location = fileInfo.getLocation();
            /*
				 * Project files should always be next to the project file.
				 * 
				 * Fallback wouldn't have an effect here because as it is used
				 * currently in the project service, project files are already
				 * loaded in the DefaultProjectReader.
				 */
            URI resolved = findLocation(location, false, false, keepRelative);
            if (resolved != null)
                fileInfo.setLocation(resolved);
        }
    }
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ProjectFileInfo(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo) Value(eu.esdihumboldt.hale.common.core.io.Value) URI(java.net.URI)

Example 64 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class ClassificationMappingUtil method getClassificationLookup.

/**
 * Get the classification lookup table from the transformation parameters.
 *
 * @param parameters the transformation parameters
 * @param serviceProvider service provider in case a lookup table has to be
 *            retrieved through a service
 * @return the classification lookup table
 */
public static LookupTable getClassificationLookup(Multimap<String, ? extends Value> parameters, ServiceProvider serviceProvider) {
    try {
        if (!(parameters.get(PARAMETER_LOOKUPTABLE).isEmpty())) {
            Collection<? extends Value> tmpMap = parameters.get(PARAMETER_LOOKUPTABLE);
            return tmpMap.iterator().next().as(LookupTable.class);
        }
        if (!(parameters.get(PARAMETER_LOOKUPTABLE_ID).isEmpty())) {
            LookupService lookupServiceImpl = serviceProvider.getService(LookupService.class);
            Collection<? extends Value> tmpMap = parameters.get(PARAMETER_LOOKUPTABLE_ID);
            LookupTableInfo lookupTableInfo = lookupServiceImpl.getTable(tmpMap.iterator().next().as(String.class));
            return lookupTableInfo.getTable();
        }
    } catch (NullPointerException e) {
        log.error("Service provider not accessible for retrieving lookup table", e);
    }
    // For reason of compatibility we need the following code
    // lookup table in strangely encoded string parameter
    Collection<? extends Value> mappings = parameters.get(PARAMETER_CLASSIFICATIONS);
    try {
        Map<Value, Value> lookupMap = new HashMap<Value, Value>();
        for (Value mapping : mappings) {
            String[] parts = mapping.as(String.class).split(" ");
            if (parts.length > 0) {
                Value target = Value.of(URLDecoder.decode(parts[0], "UTF-8"));
                for (int i = 1; i < parts.length; i++) {
                    lookupMap.put(Value.of(URLDecoder.decode(parts[i], "UTF-8")), target);
                }
            }
        }
        return new LookupTableImpl(lookupMap);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("Failed to decode classification mapping.");
    }
}
Also used : HashMap(java.util.HashMap) LookupTableInfo(eu.esdihumboldt.hale.common.lookup.LookupTableInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LookupService(eu.esdihumboldt.hale.common.lookup.LookupService) Value(eu.esdihumboldt.hale.common.core.io.Value) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)

Example 65 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class ClassificationMappingExplanation method getExplanation.

@Override
public String getExplanation(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();
        for (Value targetValue : revLookup.keySet()) {
            mappingString.append(quoteValue(targetValue.as(String.class), false));
            mappingString.append(' ');
            mappingString.append(getMessage("oneOf", locale));
            mappingString.append(' ');
            int i = 1;
            for (Value sourceValue : revLookup.get(targetValue)) {
                if (i != 1) {
                    mappingString.append(", ");
                }
                mappingString.append(quoteValue(sourceValue.as(String.class), false));
                i++;
            }
            mappingString.append(".\n");
        }
        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), false);
        }
        return MessageFormat.format(getMessage("main", locale), formatEntity(target, false, true, locale), formatEntity(source, false, true, locale), mappingString.toString(), notClassifiedResult);
    }
    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)

Aggregations

Value (eu.esdihumboldt.hale.common.core.io.Value)81 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)12 LookupTable (eu.esdihumboldt.hale.common.lookup.LookupTable)12 HashMap (java.util.HashMap)12 ValueProperties (eu.esdihumboldt.hale.common.core.io.ValueProperties)11 LookupTableImpl (eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)11 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)10 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 ArrayList (java.util.ArrayList)9 URI (java.net.URI)8 Test (org.junit.Test)6 StyledString (org.eclipse.jface.viewers.StyledString)5 Composite (org.eclipse.swt.widgets.Composite)5 DefaultCustomPropertyFunction (eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction)4 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)4 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)4 IOException (java.io.IOException)4 Locale (java.util.Locale)4