use of eu.esdihumboldt.hale.common.core.report.Message in project hale by halestudio.
the class ReportWriter method write.
/**
* Writes all {@link Report}s to a {@link File}.
*
* @param file target file
* @param reports reports to be saved
* @param append if the reports should be appended to the file instead of
* overwriting it
*
* @return true on success
*
* @throws IOException if IO fails
*/
public static boolean write(File file, Collection<Report<?>> reports, boolean append) throws IOException {
// check if the file exists
if (!file.exists()) {
// and create the file
if (!file.createNewFile()) {
_log.error("Logfile could not be created!");
return false;
}
// make it writable
file.setWritable(true);
}
// check if it's writable
if (!file.canWrite()) {
_log.error("Report could not be saved. No write permission!");
return false;
}
// create PrintStream
PrintStream p = new PrintStream(new BufferedOutputStream(new FileOutputStream(file, append)));
try {
// get an instance of ReportFactory
ReportFactory rf = ReportFactory.getInstance();
MessageFactory mf = MessageFactory.getInstance();
// iterate through all reports
for (Report<?> r : reports) {
// write them to the file
p.print(rf.asString(r));
for (Message m : r.getErrors()) {
p.println("!ERROR");
p.print(mf.asString(m));
}
for (Message m : r.getWarnings()) {
p.println("!WARN");
p.print(mf.asString(m));
}
for (Message m : r.getInfos()) {
p.println("!INFO");
p.print(mf.asString(m));
}
}
// new line at end of file to allow appending
p.println();
p.flush();
} finally {
// close stream
p.close();
}
return true;
}
use of eu.esdihumboldt.hale.common.core.report.Message 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.report.Message in project hale by halestudio.
the class DefinitionInstanceLabelProvider method getToolTipText.
/**
* @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
*/
@Override
public String getToolTipText(Object element) {
if (element instanceof EntityDefinition) {
InstanceValidationReport report = validator.validate(instance);
Collection<InstanceValidationMessage> warnings = report.getWarnings();
if (warnings.isEmpty())
return null;
StringBuilder toolTip = new StringBuilder();
for (Message m : warnings) toolTip.append(m.getFormattedMessage()).append('\n');
return toolTip.substring(0, toolTip.length() - 1);
} else
return null;
}
use of eu.esdihumboldt.hale.common.core.report.Message in project hale by halestudio.
the class DefaultReportDetailsPage method setInput.
@Override
public void setInput(Collection<? extends Message> messages, MessageType type) {
this.messageType = type;
if (more > 0) {
Collection<Message> messageList = new ArrayList<>(messages);
String message;
switch(messageType) {
case Error:
message = MessageFormat.format("{0} more errors that are not listed", more);
break;
case Warning:
message = MessageFormat.format("{0} more warnings that are not listed", more);
break;
case Information:
default:
message = MessageFormat.format("{0} more messages that are not listed", more);
}
messageList.add(new MessageImpl(message, null));
treeViewer.setInput(messageList);
} else {
treeViewer.setInput(messages);
}
}
Aggregations