Search in sources :

Example 1 with ComplexPropertyType

use of eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType in project hale by halestudio.

the class ProjectToJaxb method convert.

/**
 * Convert the given project to the corresponding JAXB type.
 *
 * @param project the project to convert
 * @return the converted project
 */
public static ProjectType convert(Project project) {
    ProjectType result = new ProjectType();
    result.setAuthor(project.getAuthor());
    result.setCreated(toXMLCalendar(project.getCreated()));
    result.setDescription(project.getDescription());
    result.setModified(toXMLCalendar(project.getModified()));
    result.setName(project.getName());
    result.setSaveConfig(toIOConfigurationType(project.getSaveConfiguration()));
    if (project.getHaleVersion() != null) {
        result.setVersion(project.getHaleVersion().toString());
    }
    // resources
    for (IOConfiguration resource : project.getResources()) {
        result.getResource().add(toIOConfigurationType(resource));
    }
    // export configs
    for (Entry<String, IOConfiguration> confEntry : project.getExportConfigurations().entrySet()) {
        IOConfigurationType conf = toIOConfigurationType(confEntry.getValue());
        ExportConfigurationType exportConf = new ExportConfigurationType();
        exportConf.setConfiguration(conf);
        exportConf.setName(confEntry.getKey());
        result.getExportConfig().add(exportConf);
    }
    // project files
    for (ProjectFileInfo file : project.getProjectFiles()) {
        result.getFile().add(toProjectFileType(file));
    }
    // properties
    for (Entry<String, Value> property : project.getProperties().entrySet()) {
        Object p = createProperty(property.getKey(), property.getValue());
        if (p instanceof PropertyType) {
            result.getAbstractProperty().add(of.createProperty((PropertyType) p));
        } else if (p instanceof ComplexPropertyType) {
            result.getAbstractProperty().add(of.createComplexProperty((ComplexPropertyType) p));
        }
    }
    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) ExportConfigurationType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ExportConfigurationType) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ProjectType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectType) ProjectFileInfo(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo) 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 2 with ComplexPropertyType

use of eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType 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 3 with ComplexPropertyType

use of eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType in project hale by halestudio.

the class JaxbToProject method convert.

/**
 * Convert the given project.
 *
 * @param project the project to convert
 * @return the project model object
 */
public static Project convert(ProjectType project) {
    Project result = new Project();
    result.setAuthor(project.getAuthor());
    result.setCreated(toDate(project.getCreated()));
    result.setDescription(project.getDescription());
    result.setHaleVersion(toVersion(project.getVersion()));
    result.setModified(toDate(project.getModified()));
    result.setName(project.getName());
    result.setSaveConfiguration(toIOConfiguration(project.getSaveConfig()));
    for (IOConfigurationType resource : project.getResource()) {
        result.getResources().add(toIOConfiguration(resource));
    }
    for (ExportConfigurationType exportConfig : project.getExportConfig()) {
        String name = exportConfig.getName();
        if (name != null && !name.isEmpty()) {
            result.getExportConfigurations().put(name, toIOConfiguration(exportConfig.getConfiguration()));
        }
    }
    for (ProjectFileType file : project.getFile()) {
        result.getProjectFiles().add(new ProjectFileInfo(file.getName(), URI.create(file.getLocation())));
    }
    for (JAXBElement<?> property : project.getAbstractProperty()) {
        Object value = property.getValue();
        if (value instanceof PropertyType) {
            addProperty(result.getProperties(), (PropertyType) value);
        } else if (value instanceof ComplexPropertyType) {
            addProperty(result.getProperties(), (ComplexPropertyType) value);
        }
    }
    return result;
}
Also used : IOConfigurationType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.IOConfigurationType) Project(eu.esdihumboldt.hale.common.core.io.project.model.Project) ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType) ExportConfigurationType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ExportConfigurationType) ProjectFileType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectFileType) ProjectFileInfo(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo) 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 4 with ComplexPropertyType

use of eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType 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 5 with ComplexPropertyType

use of eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType in project hale by halestudio.

the class ProjectToJaxb method createProperty.

private static Object createProperty(String name, Value value) {
    if (value == null) {
        // null value
        PropertyType result = new PropertyType();
        result.setName(name);
        return result;
    } else if (value.isRepresentedAsDOM()) {
        // complex value or element
        ComplexPropertyType result = new ComplexPropertyType();
        result.setName(name);
        result.setAny(value.getDOMRepresentation());
        return result;
    } else {
        // string property value
        PropertyType result = new PropertyType();
        result.setName(name);
        result.setValue(value.getStringRepresentation());
        return result;
    }
}
Also used : ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType) PropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.PropertyType) ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType)

Aggregations

ComplexPropertyType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType)5 PropertyType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.PropertyType)5 Value (eu.esdihumboldt.hale.common.core.io.Value)3 IOConfigurationType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.IOConfigurationType)3 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)2 ProjectFileInfo (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo)2 ExportConfigurationType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ExportConfigurationType)2 ValueType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ValueType)2 ElementValue (eu.esdihumboldt.hale.common.core.io.impl.ElementValue)1 Project (eu.esdihumboldt.hale.common.core.io.project.model.Project)1 ProjectFileType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectFileType)1 ProjectType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectType)1