use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class ProjectCasDoctorPanel method actionRepair.
private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
casStorageService.disableCache();
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)) {
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
JCas initialCas;
if (documentService.existsInitialCas(sd)) {
initialCas = documentService.readInitialCas(sd, false);
} else {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "Created initial CAS for [" + sd.getName() + "]"));
initialCas = documentService.createInitialCas(sd, false);
}
casDoctor.repair(project, initialCas.getCas(), messageSet.messages);
CasPersistenceUtils.writeSerializedCas(initialCas, documentService.getCasFile(sd, INITIAL_CAS_PSEUDO_USER));
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
if (documentService.existsAnnotationCas(ad)) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
JCas userCas = documentService.readAnnotationCas(ad, false);
casDoctor.repair(project, userCas.getCas(), messageSet.messages);
CasPersistenceUtils.writeSerializedCas(userCas, documentService.getCasFile(ad.getDocument(), ad.getUser()));
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
}
}
aTarget.add(this);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class ProjectCasDoctorPanel method actionCheck.
private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
casStorageService.disableCache();
CasDoctor casDoctor = new CasDoctor();
casDoctor.setApplicationContext(ApplicationContextProvider.getApplicationContext());
casDoctor.setFatalChecks(false);
casDoctor.setCheckClasses(CasDoctor.scanChecks());
Project project = getModelObject();
formModel.messageSets = new ArrayList<>();
for (SourceDocument sd : documentService.listSourceDocuments(project)) {
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
JCas initialCas;
try {
if (documentService.existsInitialCas(sd)) {
initialCas = documentService.readInitialCas(sd, false);
} else {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "No initial CAS for [" + sd.getName() + "]"));
initialCas = documentService.createInitialCas(sd, false);
}
casDoctor.analyze(project, initialCas.getCas(), messageSet.messages);
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error reading initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error reading initial CAS for [" + sd.getName() + "]", e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
if (documentService.existsAnnotationCas(ad)) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
JCas userCas = documentService.readAnnotationCas(ad, false);
casDoctor.analyze(project, userCas.getCas(), messageSet.messages);
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
}
}
aTarget.add(this);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class ImportDocumentsPanel method actionImport.
private void actionImport(AjaxRequestTarget aTarget, Form<Void> aForm) {
aTarget.addChildren(getPage(), IFeedback.class);
List<FileUpload> uploadedFiles = fileUpload.getFileUploads();
Project project = projectModel.getObject();
if (isEmpty(uploadedFiles)) {
error("No document is selected to upload, please select a document first");
return;
}
if (isNull(project.getId())) {
error("Project not yet created, please save project details!");
return;
}
for (FileUpload documentToUpload : uploadedFiles) {
String fileName = documentToUpload.getClientFileName();
if (documentService.existsSourceDocument(project, fileName)) {
error("Document " + fileName + " already uploaded ! Delete " + "the document if you want to upload again");
continue;
}
try {
SourceDocument document = new SourceDocument();
document.setName(fileName);
document.setProject(project);
document.setFormat(importExportService.getReadableFormatId(format.getObject()));
try (InputStream is = documentToUpload.getInputStream()) {
documentService.uploadSourceDocument(is, document);
}
info("File [" + fileName + "] has been imported successfully!");
} catch (Exception e) {
error("Error while uploading document " + fileName + ": " + ExceptionUtils.getRootCauseMessage(e));
LOG.error(fileName + ": " + e.getMessage(), e);
}
}
WicketUtil.refreshPage(aTarget, getPage());
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class MonitoringPage method getOverallProjectProgress.
private Map<String, Integer> getOverallProjectProgress() {
Map<String, Integer> overallProjectProgress = new LinkedHashMap<>();
String username = SecurityContextHolder.getContext().getAuthentication().getName();
User user = userRepository.get(username);
for (Project project : projectService.listProjects()) {
if (SecurityUtil.isCurator(project, projectService, user) || SecurityUtil.isProjectAdmin(project, projectService, user)) {
int annoFinished = documentService.listFinishedAnnotationDocuments(project).size();
int allAnno = documentService.numberOfExpectedAnnotationDocuments(project);
int progress = (int) Math.round((double) (annoFinished * 100) / (allAnno));
overallProjectProgress.put(project.getName(), progress);
}
}
return overallProjectProgress;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class TagSetImportPanel method actionImport.
private void actionImport(AjaxRequestTarget aTarget, Form<Preferences> aForm) {
List<FileUpload> uploadedFiles = fileUpload.getFileUploads();
Project project = selectedProject.getObject();
if (isEmpty(uploadedFiles)) {
error("Please choose file with tagset before uploading");
return;
} else if (isNull(project.getId())) {
error("Project not yet created, please save project details!");
return;
}
if (aForm.getModelObject().format.equals(ExportedTagSetConstant.JSON_FORMAT)) {
for (FileUpload tagFile : uploadedFiles) {
InputStream tagInputStream;
try {
tagInputStream = tagFile.getInputStream();
if (aForm.getModelObject().overwrite) {
JsonImportUtil.importTagSetFromJsonWithOverwrite(project, tagInputStream, annotationService);
} else {
JsonImportUtil.importTagSetFromJson(project, tagInputStream, annotationService);
}
} catch (IOException e) {
error("Error Importing TagSet " + ExceptionUtils.getRootCauseMessage(e));
}
}
} else if (aForm.getModelObject().format.equals(ExportedTagSetConstant.TAB_FORMAT)) {
for (FileUpload tagFile : uploadedFiles) {
InputStream tagInputStream;
try {
tagInputStream = tagFile.getInputStream();
String text = IOUtils.toString(tagInputStream, "UTF-8");
Map<String, String> tabbedTagsetFromFile = ImportUtil.getTagSetFromFile(text);
Set<String> listOfTagsFromFile = tabbedTagsetFromFile.keySet();
int i = 0;
String tagSetName = "";
String tagSetDescription = "";
String tagsetLanguage = "";
de.tudarmstadt.ukp.clarin.webanno.model.TagSet tagSet = null;
for (String key : listOfTagsFromFile) {
// description
if (i == 0) {
tagSetName = key;
tagSetDescription = tabbedTagsetFromFile.get(key);
} else // the second key is the tagset language
if (i == 1) {
tagsetLanguage = key;
// exist
if (annotationService.existsTagSet(tagSetName, project)) {
// If overwrite is enabled
if (aForm.getModelObject().overwrite) {
tagSet = annotationService.getTagSet(tagSetName, project);
annotationService.removeAllTags(tagSet);
} else {
tagSet = new TagSet();
tagSet.setName(JsonImportUtil.copyTagSetName(annotationService, tagSetName, project));
}
} else {
tagSet = new TagSet();
tagSet.setName(tagSetName);
}
tagSet.setDescription(tagSetDescription.replace("\\n", "\n"));
tagSet.setLanguage(tagsetLanguage);
tagSet.setProject(project);
annotationService.createTagSet(tagSet);
} else // otherwise it is a tag entry, add the tag
// to the tagset
{
Tag tag = new Tag();
tag.setDescription(tabbedTagsetFromFile.get(key).replace("\\n", "\n"));
tag.setName(key);
tag.setTagSet(tagSet);
annotationService.createTag(tag);
}
i++;
}
} catch (Exception e) {
error("Error importing tag set: " + ExceptionUtils.getRootCauseMessage(e));
LOG.error("Error importing tag set", e);
}
}
}
try {
onImportComplete(aTarget);
} catch (Exception e) {
error("Error importing tag set: " + ExceptionUtils.getRootCauseMessage(e));
LOG.error("Error importing tag set", e);
}
}
Aggregations