use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class DocumentServiceImpl method listAnnotatableDocuments.
@Override
public Map<SourceDocument, AnnotationDocument> listAnnotatableDocuments(Project aProject, User aUser) {
// First get the source documents
List<SourceDocument> sourceDocuments = entityManager.createQuery("FROM SourceDocument " + "WHERE project = (:project)", SourceDocument.class).setParameter("project", aProject).getResultList();
// Next we get all the annotation document records. We can use these to filter out
// documents which are IGNOREed for given users.
List<AnnotationDocument> annotationDocuments = entityManager.createQuery("FROM AnnotationDocument " + "WHERE user = (:username) AND project = (:project)", AnnotationDocument.class).setParameter("username", aUser.getUsername()).setParameter("project", aProject).getResultList();
// First we add all the source documents
Map<SourceDocument, AnnotationDocument> map = new TreeMap<>(SourceDocument.NAME_COMPARATOR);
for (SourceDocument doc : sourceDocuments) {
map.put(doc, null);
}
// documents
for (AnnotationDocument adoc : annotationDocuments) {
switch(adoc.getState()) {
case IGNORE:
map.remove(adoc.getDocument());
break;
default:
map.put(adoc.getDocument(), adoc);
break;
}
}
return map;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class DocumentServiceImpl method existFinishedDocument.
/**
* Return true if there exist at least one annotation document FINISHED for annotation for this
* {@link SourceDocument}
*
* @param aSourceDocument
* the source document.
* @param aProject
* the project.
* @return if a finished document exists.
*/
@Override
public boolean existFinishedDocument(SourceDocument aSourceDocument, Project aProject) {
List<de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument> annotationDocuments = listAnnotationDocuments(aSourceDocument);
boolean finishedAnnotationDocumentExist = false;
for (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument annotationDocument : annotationDocuments) {
if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
finishedAnnotationDocumentExist = true;
break;
}
}
return finishedAnnotationDocumentExist;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class DocumentServiceImpl method resetAnnotationCas.
@Override
public void resetAnnotationCas(SourceDocument aDocument, User aUser) throws UIMAException, IOException {
AnnotationDocument adoc = getAnnotationDocument(aDocument, aUser);
JCas jcas = createOrReadInitialCas(aDocument);
writeAnnotationCas(jcas, aDocument, aUser, false);
applicationEventPublisher.publishEvent(new AfterDocumentResetEvent(this, adoc, jcas));
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class DocumentServiceImpl method readAnnotationCas.
@Override
@Transactional
@Deprecated
public JCas readAnnotationCas(SourceDocument aDocument, User aUser) throws IOException {
// Check if there is an annotation document entry in the database. If there is none,
// create one.
AnnotationDocument annotationDocument = createOrGetAnnotationDocument(aDocument, aUser);
// Change the state of the source document to in progress
transitionSourceDocumentState(aDocument, NEW_TO_ANNOTATION_IN_PROGRESS);
return readAnnotationCas(annotationDocument);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class AnnotationPage method handleParameters.
private void handleParameters(AjaxRequestTarget aTarget, StringValue aProjectParameter, StringValue aDocumentParameter, StringValue aFocusParameter, boolean aLockIfPreset) {
// Get current project from parameters
Project project = null;
try {
project = getProjectFromParameters(aProjectParameter);
} catch (NoResultException e) {
error("Project [" + aProjectParameter + "] does not exist");
return;
}
// Get current document from parameters
SourceDocument document = null;
if (project != null) {
try {
document = getDocumentFromParameters(project, aDocumentParameter);
} catch (NoResultException e) {
error("Document [" + aDocumentParameter + "] does not exist in project [" + project.getId() + "]");
}
}
// Get current focus unit from parameters
int focus = 0;
if (aFocusParameter != null) {
focus = aFocusParameter.toInt(0);
}
// there is also a document change.
if (document != null && document.equals(getModelObject().getDocument()) && focus == getModelObject().getFocusUnitIndex()) {
return;
}
// Check access to project
if (project != null && !isAnnotator(project, projectService, getModelObject().getUser())) {
error("You have no permission to access project [" + project.getId() + "]");
return;
}
// Check if document is locked for the user
if (project != null && document != null && documentService.existsAnnotationDocument(document, getModelObject().getUser())) {
AnnotationDocument adoc = documentService.getAnnotationDocument(document, getModelObject().getUser());
if (AnnotationDocumentState.IGNORE.equals(adoc.getState())) {
error("Document [" + document.getId() + "] in project [" + project.getId() + "] is locked for user [" + getModelObject().getUser().getUsername() + "]");
return;
}
}
// i.e. not only in the case that it was a URL fragment parameter.
if (project != null) {
getModelObject().setProject(project);
if (aLockIfPreset) {
getModelObject().setProjectLocked(true);
}
}
if (document != null) {
// or a change of focus (or both)
if (!document.equals(getModelObject().getDocument())) {
getModelObject().setDocument(document, getListOfDocs());
actionLoadDocument(aTarget, focus);
} else {
try {
getModelObject().moveToUnit(getEditorCas(), focus);
actionRefreshDocument(aTarget);
} catch (Exception e) {
aTarget.addChildren(getPage(), IFeedback.class);
LOG.info("Error reading CAS " + e.getMessage());
error("Error reading CAS " + e.getMessage());
}
}
}
}
Aggregations