Search in sources :

Example 6 with ProjectFileInfo

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

use of eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo 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)

Aggregations

ProjectFileInfo (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo)7 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)4 URI (java.net.URI)4 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)3 IOException (java.io.IOException)3 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)2 Value (eu.esdihumboldt.hale.common.core.io.Value)2 ProjectFile (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile)2 ComplexPropertyType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType)2 ExportConfigurationType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ExportConfigurationType)2 IOConfigurationType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.IOConfigurationType)2 PropertyType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.PropertyType)2 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)2 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)2 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)2 File (java.io.File)2 OutputStream (java.io.OutputStream)2 ZipEntry (java.util.zip.ZipEntry)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 AlignmentReader (eu.esdihumboldt.hale.common.align.io.AlignmentReader)1