Search in sources :

Example 36 with Value

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

the class ProjectToJaxb method toIOConfigurationType.

/**
 * Converts an I/O configuration to its JAXB representation.
 *
 * @param config the I/O configuration
 * @return the JAXB representation
 */
public static IOConfigurationType toIOConfigurationType(IOConfiguration config) {
    if (config == null) {
        return null;
    }
    IOConfigurationType result = new IOConfigurationType();
    result.setActionId(config.getActionId());
    result.setProviderId(config.getProviderId());
    for (Entry<String, Value> setting : config.getProviderConfiguration().entrySet()) {
        Object property = createProperty(setting.getKey(), setting.getValue());
        if (property instanceof PropertyType) {
            result.getAbstractSetting().add(of.createSetting((PropertyType) property));
        } else if (property instanceof ComplexPropertyType) {
            result.getAbstractSetting().add(of.createComplexSetting((ComplexPropertyType) property));
        }
    }
    // cache
    Value cache = config.getCache();
    if (cache != null && cache.getValue() != null) {
        ValueType value = new ValueType();
        if (cache.isRepresentedAsDOM()) {
            value.setAny(cache.getDOMRepresentation());
        } else {
            value.setValue(cache.getStringRepresentation());
        }
        result.setCache(value);
    }
    return result;
}
Also used : IOConfigurationType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.IOConfigurationType) ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType) ValueType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ValueType) 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)

Example 37 with Value

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

the class LocationUpdater method updateIOConfiguration.

/**
 * Updates the source location of the given configuration.
 *
 * @param configuration the configuration to update
 * @param keepRelative whether to keep working relative URI as is or make it
 *            absolute
 */
public void updateIOConfiguration(IOConfiguration configuration, boolean keepRelative) {
    final Map<String, Value> conf = configuration.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()));
}
Also used : Value(eu.esdihumboldt.hale.common.core.io.Value) URI(java.net.URI)

Example 38 with Value

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

the class Message method applyFromValue.

/**
 * Apply from a given {@link Value}, if the value represents a
 * {@link Message}.
 *
 * @param value the value to interpret as {@link Message}
 * @return this for chaining
 */
@Nullable
public Message applyFromValue(Value value) {
    ValueProperties props = value.as(ValueProperties.class);
    if (props != null) {
        String text = props.get("text").as(String.class);
        if (text != null && !text.isEmpty()) {
            // 
            setText(text).setAuthor(// 
            props.getSafe("author").as(String.class)).setFormat(// 
            props.getSafe("format").as(String.class)).setCategory(// 
            props.getSafe("category").as(String.class)).setDismissed(// 
            props.getSafe("dismissed").as(Boolean.class, false)).setCustomPayload(props.get("payload"));
            ValueList tags = props.getSafe("tags").as(ValueList.class);
            this.tags.clear();
            if (tags != null) {
                for (Value tag : tags) {
                    String tagString = tag.as(String.class);
                    if (tagString != null) {
                        addTag(tagString);
                    }
                }
            }
            ValueList comments = props.getSafe("comments").as(ValueList.class);
            this.comments.clear();
            if (comments != null) {
                for (Value commentVal : comments) {
                    Optional<Comment> comment = Comment.fromValue(commentVal);
                    comment.ifPresent(c -> addComment(c));
                }
            }
        }
    }
    return this;
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) Value(eu.esdihumboldt.hale.common.core.io.Value) Nullable(javax.annotation.Nullable)

Example 39 with Value

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

the class HaleConnectTarget method updateConfiguration.

@Override
public boolean updateConfiguration(HaleConnectProjectWriter provider) {
    provider.setParameter(HaleConnectProjectWriter.ENABLE_VERSIONING, Value.of(enableVersioning.getSelection()));
    provider.setParameter(HaleConnectProjectWriter.SHARING_PUBLIC, Value.of(publicAccess.getSelection()));
    Value ownerValue = Value.of(ownerUser.getSelection() ? OwnerType.USER.getJsonValue() : OwnerType.ORGANISATION.getJsonValue());
    provider.setParameter(HaleConnectProjectWriter.OWNER_TYPE, ownerValue);
    provider.setParameter(ArchiveProjectWriter.EXLUDE_DATA_FILES, Value.of(excludeData.getSelection()));
    provider.setParameter(ArchiveProjectWriter.INCLUDE_WEB_RESOURCES, Value.of(includeWebResources.getSelection()));
    provider.setParameter(ArchiveProjectWriter.EXCLUDE_CACHED_RESOURCES, Value.of(excludeCachedResources.getSelection()));
    provider.setTarget(new LocatableOutputSupplier<OutputStream>() {

        @Override
        public OutputStream getOutput() throws IOException {
            return null;
        }

        @Override
        public URI getLocation() {
            if (createNewProject) {
                // create a new hale connect transformation project
                return null;
            } else if (targetProject != null) {
                return HaleConnectUrnBuilder.buildProjectUrn(targetProject.getOwner(), targetProject.getProjectId());
            } else {
                throw new IllegalStateException("No target project selected.");
            }
        }
    });
    return true;
}
Also used : OutputStream(java.io.OutputStream) Value(eu.esdihumboldt.hale.common.core.io.Value) IOException(java.io.IOException) URI(java.net.URI)

Example 40 with Value

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

the class InterpolationSettingPage method updateConfiguration.

@Override
public boolean updateConfiguration(IOProvider provider) {
    // set interpolation algorithm
    Value alg = null;
    ISelection sel = algorithms.getSelection();
    if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
        Object selected = ((IStructuredSelection) sel).getFirstElement();
        if (selected instanceof InterpolationAlgorithmFactory) {
            String id = ((InterpolationAlgorithmFactory) selected).getIdentifier();
            alg = Value.of(id);
        }
    }
    provider.setParameter(InterpolationHelper.PARAMETER_INTERPOLATION_ALGORITHM, alg);
    // set maximum positional error
    provider.setParameter(InterpolationHelper.PARAMETER_MAX_POSITION_ERROR, Value.of(error.getText()));
    // set move to grid flag
    provider.setParameter(GridInterpolation.PARAMETER_MOVE_ALL_TO_GRID, Value.of(moveToGrid.getSelection()));
    return true;
}
Also used : Value(eu.esdihumboldt.hale.common.core.io.Value) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InterpolationAlgorithmFactory(eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)

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