Search in sources :

Example 21 with Value

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

the class IOReferenceContent method getIOProviderContent.

/**
 * @param providerId The id of the provider
 * @return The in input stream or null, if the given provider does not
 *         exist.
 * @throws Exception - if an error occurs
 */
private InputStream getIOProviderContent(String providerId) throws Exception {
    final String id = providerId;
    // try to get I/O provider
    IOProviderDescriptor providerDescriptor = HaleIO.findIOProviderFactory(IOProvider.class, null, providerId);
    if (providerDescriptor == null) {
        log.warn("I/O provider " + id + " does not exist.");
        return null;
    }
    final IOProviderDescriptor descriptor = providerDescriptor;
    return getContentFromTemplate(providerId, TEMPLATE_PROVIDER, new Callable<VelocityContext>() {

        @Override
        public VelocityContext call() throws Exception {
            VelocityContext context = new VelocityContext();
            // I/O provider descriptor
            context.put("descriptor", descriptor);
            // I/O provider type
            String type = (ImportProvider.class.isAssignableFrom(descriptor.getProviderType())) ? ("reader") : ("writer");
            context.put("providerType", type);
            // collect all optional parameter
            Collection<IOProviderParameter> parameter = new ArrayList<IOProviderParameter>();
            Map<String, String> example = new HashMap<String, String>();
            Map<String, String> defaults = new HashMap<String, String>();
            for (IOProviderParameter param : descriptor.getProviderParameter()) {
                parameter.add(param);
                // get example use of parameter
                if (param.getValueDescriptor() != null) {
                    // store sample value
                    Value sample = param.getValueDescriptor().getSampleData();
                    String displayValue = toDisplayValue(sample);
                    if (displayValue != null) {
                        example.put(param.getName(), displayValue);
                    }
                    // store default value
                    Value defaultValue = param.getValueDescriptor().getDefaultValue();
                    displayValue = toDisplayValue(defaultValue);
                    if (displayValue != null) {
                        defaults.put(param.getName(), displayValue);
                    }
                }
            }
            context.put("parameter", parameter);
            context.put("example", example);
            context.put("defaults", defaults);
            return context;
        }
    });
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) VelocityContext(org.apache.velocity.VelocityContext) ImportProvider(eu.esdihumboldt.hale.common.core.io.ImportProvider) TransformerException(javax.xml.transform.TransformerException) IOProviderParameter(eu.esdihumboldt.hale.common.core.parameter.IOProviderParameter) Value(eu.esdihumboldt.hale.common.core.io.Value) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with Value

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

the class LookupTableTypeTest method testComplexLookupJsonGroovy.

/**
 * Test if a lookup table containing only complex values is the same when
 * converted to JSON and back again.
 */
@Test
public void testComplexLookupJsonGroovy() {
    Map<Value, Value> values2 = createComplexLookup();
    LookupTable org2 = new LookupTableImpl(values2);
    // converter
    LookupTableType ltt = new LookupTableType();
    // convert to Json
    Object json = ltt.toJson(org2);
    System.out.println(new JsonBuilder(json).toString());
    // convert back
    LookupTable conv = ltt.fromJson(json, null);
    checkTable(conv, values2);
}
Also used : JsonBuilder(groovy.json.JsonBuilder) Value(eu.esdihumboldt.hale.common.core.io.Value) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl) Test(org.junit.Test)

Example 23 with Value

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

the class LookupTableTypeTest method createComplexLookup.

private Map<Value, Value> createComplexLookup() {
    // simple internal table
    Map<Value, Value> values = new HashMap<Value, Value>();
    values.put(Value.of("a"), Value.of("1"));
    values.put(Value.of("b"), Value.of("1"));
    LookupTable org = new LookupTableImpl(values);
    // external table
    Map<Value, Value> values2 = new HashMap<Value, Value>();
    values2.put(Value.of("sub"), Value.complex(org));
    values2.put(Value.of("c"), Value.of("2"));
    return values2;
}
Also used : HashMap(java.util.HashMap) Value(eu.esdihumboldt.hale.common.core.io.Value) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)

Example 24 with Value

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

the class CodeListAssocationFactory method restore.

@Override
public CodeListAssociation restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
    // is it a simple value? (single String code list reference)
    String single = value.as(String.class);
    if (single != null) {
        return new CodeListAssociation(Collections.singleton(single));
    }
    // is it a value list? (multiple String code list references)
    ValueList list = value.as(ValueList.class);
    if (list != null) {
        List<String> refList = list.stream().map(val -> val.as(String.class)).filter(val -> val != null).collect(Collectors.toList());
        return new CodeListAssociation(refList);
    }
    // fall-back
    return new CodeListAssociation();
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) List(java.util.List) ClassResolver(eu.esdihumboldt.hale.common.schema.model.constraint.factory.ClassResolver) TypeResolver(eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeResolver) CodeListAssociation(eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation) StreamSupport(java.util.stream.StreamSupport) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) TypeReferenceBuilder(eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeReferenceBuilder) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Value(eu.esdihumboldt.hale.common.core.io.Value) ValueConstraintFactory(eu.esdihumboldt.hale.common.schema.model.constraint.factory.ValueConstraintFactory) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) CodeListAssociation(eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation)

Example 25 with Value

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

the class ReferenceFactory method restore.

@Override
public Reference restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
    ValueProperties props = value.as(ValueProperties.class);
    Reference ref = new Reference(props.get(P_IS_REF).as(Boolean.class, false));
    Value types = props.get(P_TYPES);
    if (types.isComplex()) {
        ValueList list = types.as(ValueList.class);
        if (list != null) {
            for (Value entry : list) {
                Optional<TypeDefinition> type = typeIndex.resolve(entry);
                if (type.isPresent()) {
                    ref.addReferencedType(type.get());
                } else {
                    throw new IllegalStateException("Could not resolve type definition for index " + entry);
                }
            }
        }
    }
    return ref;
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) Reference(eu.esdihumboldt.hale.common.schema.model.constraint.property.Reference) Value(eu.esdihumboldt.hale.common.core.io.Value) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

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