use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class ImportGuidelinesPanel method actionImport.
private void actionImport(AjaxRequestTarget aTarget, Form<Void> aForm) {
List<FileUpload> uploadedFiles = fileUpload.getFileUploads();
Project project = projectModel.getObject();
if (isNull(project.getId())) {
aTarget.addChildren(getPage(), IFeedback.class);
error("Project not yet created, please save project details!");
return;
}
if (isEmpty(uploadedFiles)) {
aTarget.addChildren(getPage(), IFeedback.class);
error("No document is selected to upload, please select a document first");
return;
}
for (FileUpload guidelineFile : uploadedFiles) {
try {
// Workaround for WICKET-6425
File tempFile = File.createTempFile("webanno-guidelines", null);
try (InputStream is = guidelineFile.getInputStream();
OutputStream os = new FileOutputStream(tempFile)) {
IOUtils.copyLarge(is, os);
String fileName = guidelineFile.getClientFileName();
projectRepository.createGuideline(project, tempFile, fileName);
} finally {
tempFile.delete();
}
} catch (Exception e) {
error("Unable to write guideline file " + ExceptionUtils.getRootCauseMessage(e));
}
}
WicketUtil.refreshPage(aTarget, getPage());
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class CurationPage method getAllowedProjects.
private IModel<List<DecoratedObject<Project>>> getAllowedProjects() {
return new LoadableDetachableModel<List<DecoratedObject<Project>>>() {
private static final long serialVersionUID = -2518743298741342852L;
@Override
protected List<DecoratedObject<Project>> load() {
User user = userRepository.get(SecurityContextHolder.getContext().getAuthentication().getName());
List<DecoratedObject<Project>> allowedProject = new ArrayList<>();
List<Project> projectsWithFinishedAnnos = projectService.listProjectsWithFinishedAnnos();
for (Project project : projectService.listProjects()) {
if (SecurityUtil.isCurator(project, projectService, user)) {
DecoratedObject<Project> dp = DecoratedObject.of(project);
if (projectsWithFinishedAnnos.contains(project)) {
dp.setColor("green");
} else {
dp.setColor("red");
}
allowedProject.add(dp);
}
}
return allowedProject;
}
};
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class ProjectDetailPanel method actionSave.
private void actionSave(AjaxRequestTarget aTarget, Form<Project> aForm) {
aTarget.add(getPage());
// aTarget.add(((ApplicationPageBase) getPage()).getPageContent());
// aTarget.addChildren(getPage(), IFeedback.class);
Project project = aForm.getModelObject();
if (isNull(project.getId())) {
try {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
projectService.createProject(project);
projectService.createProjectPermission(new ProjectPermission(project, username, PermissionLevel.ADMIN));
projectService.createProjectPermission(new ProjectPermission(project, username, PermissionLevel.CURATOR));
projectService.createProjectPermission(new ProjectPermission(project, username, PermissionLevel.USER));
annotationService.initializeProject(project);
} catch (IOException e) {
error("Project repository path not found " + ":" + ExceptionUtils.getRootCauseMessage(e));
LOG.error("Project repository path not found " + ":" + ExceptionUtils.getRootCauseMessage(e));
}
} else {
projectService.updateProject(project);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class CorrectionPage method getAllowedProjects.
private IModel<List<DecoratedObject<Project>>> getAllowedProjects() {
return new LoadableDetachableModel<List<DecoratedObject<Project>>>() {
private static final long serialVersionUID = -2518743298741342852L;
@Override
protected List<DecoratedObject<Project>> load() {
User user = userRepository.get(SecurityContextHolder.getContext().getAuthentication().getName());
List<DecoratedObject<Project>> allowedProject = new ArrayList<>();
for (Project project : projectService.listProjects()) {
if (SecurityUtil.isAnnotator(project, projectService, user) && WebAnnoConst.PROJECT_TYPE_CORRECTION.equals(project.getMode())) {
allowedProject.add(DecoratedObject.of(project));
}
}
return allowedProject;
}
};
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class AgreementPage method getJCases.
/**
* Get the finished CASes used to compute agreement.
*/
private Map<String, List<JCas>> getJCases() {
// Avoid reloading the CASes when switching features.
if (cachedCASes != null) {
return cachedCASes;
}
Project project = projectSelectionForm.getModelObject().project;
List<User> users = projectService.listProjectUsersWithPermissions(project, PermissionLevel.USER);
List<SourceDocument> sourceDocuments = documentService.listSourceDocuments(project);
cachedCASes = new LinkedHashMap<>();
for (User user : users) {
List<JCas> cases = new ArrayList<>();
for (SourceDocument document : sourceDocuments) {
JCas jCas = null;
// Load the CAS if there is a finished one.
if (documentService.existsAnnotationDocument(document, user)) {
AnnotationDocument annotationDocument = documentService.getAnnotationDocument(document, user);
if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
try {
jCas = documentService.readAnnotationCas(annotationDocument);
annotationService.upgradeCas(jCas.getCas(), annotationDocument);
// REC: I think there is no need to write the CASes here. We would not
// want to interfere with currently active annotator users
// Set the CAS name in the DocumentMetaData so that we can pick it
// up in the Diff position for the purpose of debugging / transparency.
DocumentMetaData documentMetadata = DocumentMetaData.get(jCas);
documentMetadata.setDocumentId(annotationDocument.getDocument().getName());
documentMetadata.setCollectionId(annotationDocument.getProject().getName());
} catch (Exception e) {
LOG.error("Unable to load data", e);
error("Unable to load data: " + ExceptionUtils.getRootCauseMessage(e));
}
}
}
// The next line can enter null values into the list if a user didn't work on this
// source document yet.
cases.add(jCas);
}
cachedCASes.put(user.getUsername(), cases);
}
return cachedCASes;
}
Aggregations