use of de.tudarmstadt.ukp.clarin.webanno.diag.repairs.Repair in project webanno by webanno.
the class CasDoctor method scanRepairs.
public static List<Class<? extends Repair>> scanRepairs() {
long start = currentTimeMillis();
Reflections reflections = new Reflections(Repair.class.getPackage().getName());
List<Class<? extends Repair>> repairs = reflections.getSubTypesOf(Repair.class).stream().filter(c -> !Modifier.isAbstract(c.getModifiers())).sorted(Comparator.comparing(Class::getName)).collect(Collectors.toList());
LOG.info("Found {} repairs in {}ms", repairs.size(), currentTimeMillis() - start);
return repairs;
}
use of de.tudarmstadt.ukp.clarin.webanno.diag.repairs.Repair in project webanno by webanno.
the class CasDoctor method repair.
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
// If there are no active repairs, don't do anything
if (repairClasses.isEmpty()) {
return;
}
// APPLY REPAIRS
long tStart = System.currentTimeMillis();
for (Class<? extends Repair> repairClass : repairClasses) {
try {
long tStartTask = System.currentTimeMillis();
Repair repair = repairClass.newInstance();
if (context != null) {
context.getAutowireCapableBeanFactory().autowireBean(repair);
}
LOG.info("CasDoctor repair [" + repairClass.getSimpleName() + "] running...");
repair.repair(aProject, aCas, aMessages);
LOG.info("CasDoctor repair [" + repairClass.getSimpleName() + "] completed in " + (System.currentTimeMillis() - tStartTask) + "ms");
} catch (Exception e) {
// aMessages.add(new LogMessage(this, LogLevel.ERROR, "Cannot perform repair [%s]:
// %s",
// repairClass.getSimpleName(), ExceptionUtils.getRootCauseMessage(e)));
LOG.error("Cannot perform repair [" + repairClass.getSimpleName() + "]", e);
throw new IllegalStateException("Repair attempt failed - ask system administrator " + "for details.");
}
}
LOG.info("CasDoctor completed all repairs in " + (System.currentTimeMillis() - tStart) + "ms");
// POST-CONDITION: CAS must be consistent
// Ensure that the repairs actually fixed the CAS
analyze(aProject, aCas, aMessages, true);
}
use of de.tudarmstadt.ukp.clarin.webanno.diag.repairs.Repair in project webanno by webanno.
the class ProjectCasDoctorPanel method actionRepair.
private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
CasDoctor casDoctor = new CasDoctor();
casDoctor.setApplicationContext(ApplicationContextProvider.getApplicationContext());
casDoctor.setFatalChecks(false);
casDoctor.setRepairClasses(formModel.repairs);
Project project = getModelObject();
formModel.messageSets = new ArrayList<>();
for (SourceDocument sd : documentService.listSourceDocuments(project)) {
// Repair INITIAL CAS
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
try {
casStorageService.forceActionOnCas(sd, INITIAL_CAS_PSEUDO_USER, (doc, user) -> createOrReadInitialCasWithoutSaving(doc, messageSet), //
(cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error repairing initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error repairing initial CAS for [{}]", sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
// Repair CORRECTION_USER CAS if necessary
if (PROJECT_TYPE_CORRECTION.equals(project.getMode())) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + CORRECTION_USER + "]");
try {
casStorageService.forceActionOnCas(sd, CORRECTION_USER, (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), //
(cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
} catch (FileNotFoundException e) {
// If there is no CAS for the correction user, then correction has not started
// yet. This is not a problem, so we can ignore it. (REC: I wonder if this
// assumption is correct in curation mode...)
messageSet.messages.add(LogMessage.info(getClass(), "Correction seems to have not yet started."));
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations for [" + CORRECTION_USER + "] for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error checking annotations for [{}] for [{}]", CORRECTION_USER, sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
// Repair CURATION_USER CAS
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + CURATION_USER + "]");
try {
casStorageService.forceActionOnCas(sd, CURATION_USER, (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), //
(cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
} catch (FileNotFoundException e) {
if (asList(CURATION_IN_PROGRESS, CURATION_FINISHED).contains(sd.getState())) {
messageSet.messages.add(LogMessage.error(getClass(), "Curation CAS missing."));
} else {
// If there is no CAS for the curation user, then curation has not started
// yet. This is not a problem, so we can ignore it.
messageSet.messages.add(LogMessage.info(getClass(), "Curation has not started."));
}
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations for [" + CURATION_USER + "] for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error checking annotations for [{}] for [{}]", CURATION_USER, sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
// Repair regular annotator CASes
for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
if (documentService.existsAnnotationCas(ad)) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
try {
casStorageService.forceActionOnCas(sd, ad.getUser(), (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), //
(cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error repairing annotations of user [" + ad.getUser() + "] for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error repairing annotations of user [{}] for [{}]", ad.getUser(), sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
}
}
aTarget.add(this);
}
Aggregations