use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class ArchiveProjectReader method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
// copy resources to a temporary directory
tempDir = Files.createTempDir();
IOUtils.extract(tempDir, getSource().getInput());
// create the project file via XMLProjectReader
File baseFile = new File(tempDir, "project.halex");
ProjectReader reader;
if (!baseFile.exists()) {
// look for project file
log.debug("Default project file not found, looking for other candidates.");
String candidate = ProjectIO.findProjectFile(tempDir);
if (candidate != null) {
log.info(MessageFormat.format("Loading {0} as project file from archive", candidate));
baseFile = new File(tempDir, candidate);
}
reader = HaleIO.findIOProvider(ProjectReader.class, new FileIOSupplier(baseFile), candidate);
if (reader == null) {
reporter.error(new IOMessageImpl("Could not find reader for project file " + candidate, null));
reporter.setSuccess(false);
return reporter;
}
} else {
// default project file
reader = new XMLProjectReader();
}
LocatableInputSupplier<InputStream> tempSource = new FileIOSupplier(baseFile);
// save old save configuration
LocatableInputSupplier<? extends InputStream> oldSource = getSource();
setSource(tempSource);
reader.setSource(tempSource);
reader.setProjectFiles(getProjectFiles());
IOReport report = reader.execute(progress);
Project readProject = reader.getProject();
if (readProject != null) {
/*
* Because the original source is only available here, update the
* project's resource paths here.
*
* The only drawback is that the UILocationUpdater cannot be used.
*/
LocationUpdater updater = new LocationUpdater(readProject, tempSource.getLocation());
// update resources
// resources are made absolute (else they can't be found afterwards)
updater.updateProject(false);
}
// set the real source
setSource(oldSource);
// set the read project
setProjectChecked(readProject, reporter);
return report;
}
use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class MsAccessDataReaderTestSuit method readSchema.
/**
* Reads a schema from a MsAccess database file.
*
* @param sourceFile the file of the source database.
* @return the schema
* @throws Exception any exception thrown by {@link MsAccessSchemaReader}
*/
public Schema readSchema(File sourceFile) throws Exception {
MsAccessSchemaReader schemaReader = new MsAccessSchemaReader();
schemaReader.setSource(new FileIOSupplier(sourceFile));
schemaReader.setParameter(JDBCSchemaReader.PARAM_USER, Value.of(USER_NAME));
schemaReader.setParameter(JDBCSchemaReader.PARAM_PASSWORD, Value.of(PASSWORD));
IOReport report = schemaReader.execute(new LogProgressIndicator());
assertTrue(report.isSuccess());
return schemaReader.getSchema();
}
use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class SpatiaLiteInstanceWriter method loadConfiguration.
@Override
public void loadConfiguration(Map<String, Value> configuration) {
super.loadConfiguration(configuration);
Value target = configuration.get(PARAM_TARGET);
if (target != null && !target.isEmpty()) {
File file = new File(URI.create(target.as(String.class)));
setTarget(new FileIOSupplier(file));
}
}
use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class ProjectHandler method onSuccess.
@Override
protected void onSuccess(EnvironmentManager context, String projectId, File projectFile, Project project, ReportFile reportFile) {
super.onSuccess(context, projectId, projectFile, project, reportFile);
if (isEnabled()) {
// load transformation environment if not yet done
if (transformationEnvironment == null) {
try {
transformationEnvironment = new ProjectTransformationEnvironment(projectId, new FileIOSupplier(projectFile), reportFile);
// check alignment
if (transformationEnvironment.getAlignment() == null) {
throw new IllegalStateException("Alignment missing or failed to load");
}
if (transformationEnvironment.getAlignment().getActiveTypeCells().isEmpty()) {
throw new IllegalStateException("Alignment contains no active type relations");
}
} catch (Exception e) {
log.error("Could not load transformation environment for project " + projectId, e);
status = Status.BROKEN;
transformationEnvironment = null;
context.removeEnvironment(projectId);
// log the exception as report
Reporter<Message> report = new DefaultReporter<Message>("Load project transformation environment", ProjectIO.ACTION_LOAD_PROJECT, Message.class, false);
report.error(new MessageImpl(e.getMessage(), e));
reportFile.publishReport(report);
}
} else {
// XXX somehow check if project was changed?
}
if (transformationEnvironment != null) {
context.addEnvironment(transformationEnvironment);
status = Status.ACTIVE;
}
} else {
// clear transformation environment
status = Status.INACTIVE;
transformationEnvironment = null;
context.removeEnvironment(projectId);
}
}
use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class UploadAndTransForm method onSubmit.
/**
* @see Form#onSubmit()
*/
@Override
protected void onSubmit() {
List<FileUpload> uploads = file.getFileUploads();
if (uploads == null || uploads.isEmpty()) {
error("Please specify files to transform.");
return;
}
final TransformationWorkspace workspace = new TransformationWorkspace();
List<InstanceReader> readers = Lists.transform(uploads, new Function<FileUpload, InstanceReader>() {
private int count;
@Override
public InstanceReader apply(@Nullable final FileUpload input) {
/*
* Copy uploaded file to source folder, because the
* input stream retrieved from the FileUpload is
* automatically closed with the end of the request.
*/
File file = new File(workspace.getSourceFolder(), (count++) + "_" + input.getClientFileName());
try {
input.writeTo(file);
} catch (IOException e) {
throw new IllegalStateException("Unable to read uploaded source file", e);
}
InstanceReader reader = null;
try {
LocatableInputSupplier<? extends InputStream> in = new FileIOSupplier(file);
reader = HaleIO.findIOProvider(InstanceReader.class, in, input.getClientFileName());
if (reader != null) {
reader.setSource(in);
}
} catch (Exception e) {
throw new IllegalStateException("Unable to read uploaded source file", e);
}
if (reader == null) {
throw new IllegalStateException("Could not find I/O provider for source file.");
}
return reader;
}
});
try {
workspace.transform(projectId, readers, target.getConfig());
setResponsePage(StatusPage.class, new PageParameters().add(StatusPage.PARAMETER_WORKSPACE, workspace.getId()));
} catch (Exception e) {
log.error("Error launching transformation process", e);
error("Error launching transformation process");
workspace.delete();
}
}
Aggregations