Search in sources :

Example 1 with IOConfigurationResource

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

the class TemplateProject method onSuccess.

@Override
protected void onSuccess(Void context, String projectId, File projectFile, Project project, ReportFile reportFile) {
    super.onSuccess(context, projectId, projectFile, project, reportFile);
    // update locations in project file
    LocationUpdater updater = new LocationUpdater(project, projectFile.toURI());
    updater.updateProject(false);
    resources.clear();
    List<Path> invalidSources = new ArrayList<>();
    Path projectFolder = getProjectFolder().toPath();
    // validate resources
    for (IOConfiguration config : project.getResources()) {
        Resource resource = new IOConfigurationResource(config, getProjectFile().toURI());
        // check if file URIs are valid and inside project folder
        URI source = resource.getSource();
        if (source != null) {
            Path path = null;
            if (source.getScheme() == null) {
                // is a relative URI
                path = projectFile.toPath().resolve(source.toString()).normalize();
            } else if ("file".equals(source.getScheme())) {
                // is a file URI
                path = Paths.get(source).normalize();
            }
            if (path != null) {
                if (!path.startsWith(projectFolder) || !Files.exists(path)) {
                    // invalid source
                    invalidSources.add(path);
                }
            }
        }
        resources.put(resource.getActionId(), resource);
    }
    valid = invalidSources.isEmpty();
    if (!valid) {
        StringBuilder builder = new StringBuilder("Files referenced by the project could not be found: ");
        for (int i = 0; i < invalidSources.size(); i++) {
            if (i > 0)
                builder.append(", ");
            Path path = invalidSources.get(i);
            builder.append(path.getFileName().toString());
        }
        notValidMessage = builder.toString();
    } else {
        notValidMessage = "";
    }
    // additionally, try to find out cell count
    definedRelations = 0;
    // check if default alignment file exists
    try {
        File defAlignmentFile = new File(URI.create(projectFile.toURI().toASCIIString() + "." + AlignmentIO.PROJECT_FILE_ALIGNMENT));
        if (defAlignmentFile.exists()) {
            try (InputStream in = new BufferedInputStream(new FileInputStream(defAlignmentFile))) {
                /*
					 * Try loading the file with JAXB - only supports 2.6+
					 * projects.
					 */
                AlignmentType alignment = JaxbToAlignment.load(in, null);
                // XXX ignoring base alignments
                int count = 0;
                for (Object element : alignment.getCellOrModifier()) {
                    if (element instanceof CellType) {
                        count++;
                    }
                }
                definedRelations = count;
            } catch (Exception e) {
            // ignore
            }
        }
    } catch (Exception e) {
    // ignore
    }
}
Also used : Path(java.nio.file.Path) LocationUpdater(eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource) URI(java.net.URI) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) AlignmentType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType) BufferedInputStream(java.io.BufferedInputStream) CellType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType) ReportFile(eu.esdihumboldt.hale.common.headless.report.ReportFile) File(java.io.File)

Example 2 with IOConfigurationResource

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

the class ProjectServiceImpl method executeAndRemember.

@Override
public void executeAndRemember(IOConfiguration conf) {
    executeConfiguration(conf);
    synchronized (this) {
        main.getResources().add(conf);
    }
    setChanged();
    notifyResourceAdded(conf.getActionId(), new IOConfigurationResource(conf, projectLocation));
}
Also used : IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)

Example 3 with IOConfigurationResource

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

the class ProjectServiceImpl method removeResources.

@Override
public List<? extends Resource> removeResources(String actionId) {
    Builder<Resource> removedBuilder = ImmutableList.builder();
    synchronized (this) {
        Iterator<IOConfiguration> iter = main.getResources().iterator();
        while (iter.hasNext()) {
            IOConfiguration conf = iter.next();
            if (conf.getActionId().equals(actionId)) {
                iter.remove();
                removedBuilder.add(new IOConfigurationResource(conf, projectLocation));
            }
        }
    }
    setChanged();
    List<Resource> removedResources = removedBuilder.build();
    notifyResourcesRemoved(actionId, removedResources);
    return removedResources;
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)

Example 4 with IOConfigurationResource

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

the class ProjectServiceImpl method removeResource.

@Override
public void removeResource(String resourceId) {
    Resource removedResource = null;
    synchronized (this) {
        Iterator<IOConfiguration> iter = main.getResources().iterator();
        while (iter.hasNext()) {
            IOConfiguration conf = iter.next();
            Value idValue = conf.getProviderConfiguration().get(ImportProvider.PARAM_RESOURCE_ID);
            if (idValue != null) {
                String id = idValue.as(String.class);
                if (resourceId.equals(id)) {
                    // match found, remove
                    iter.remove();
                    removedResource = new IOConfigurationResource(conf, projectLocation);
                    break;
                }
            }
        }
    }
    if (removedResource != null) {
        setChanged();
        notifyResourcesRemoved(removedResource.getActionId(), Collections.singletonList(removedResource));
    }
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) Value(eu.esdihumboldt.hale.common.core.io.Value) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)

Example 5 with IOConfigurationResource

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

the class ProjectServiceImpl method rememberIO.

/**
 * @see ProjectService#rememberIO(String, String, IOProvider)
 */
@Override
public void rememberIO(String actionId, String providerId, IOProvider provider) {
    // populate an IOConfiguration from the given data
    IOConfiguration conf = new IOConfiguration();
    conf.setActionId(actionId);
    conf.setProviderId(providerId);
    provider.storeConfiguration(conf.getProviderConfiguration());
    if (provider instanceof CachingImportProvider) {
        conf.setCache(((CachingImportProvider) provider).getCache());
    }
    // add configuration to project
    synchronized (this) {
        main.getResources().add(conf);
    }
    setChanged();
    notifyResourceAdded(actionId, new IOConfigurationResource(conf, projectLocation));
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) CachingImportProvider(eu.esdihumboldt.hale.common.core.io.CachingImportProvider) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)

Aggregations

IOConfigurationResource (eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)5 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)4 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)3 AlignmentType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType)1 CellType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType)1 CachingImportProvider (eu.esdihumboldt.hale.common.core.io.CachingImportProvider)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 LocationUpdater (eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater)1 ReportFile (eu.esdihumboldt.hale.common.headless.report.ReportFile)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1