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
}
}
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));
}
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;
}
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));
}
}
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));
}
Aggregations