use of de.tudarmstadt.ukp.clarin.webanno.model.Project 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());
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class AnnotationPage method getProjectFromParameters.
private Project getProjectFromParameters(StringValue projectParam) {
Project project = null;
if (projectParam != null && !projectParam.isEmpty()) {
long projectId = projectParam.toLong();
project = projectService.getProject(projectId);
}
return project;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class AutomationPage method getAllowedProjects.
private IModel<List<DecoratedObject<Project>>> getAllowedProjects() {
return LambdaModel.of(() -> {
User user = userRepository.getCurrentUser();
List<DecoratedObject<Project>> allowedProject = new ArrayList<>();
for (Project project : projectService.listProjects()) {
if (SecurityUtil.isAnnotator(project, projectService, user) && WebAnnoConst.PROJECT_TYPE_AUTOMATION.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 CopyAnnotationTest method setup.
@Before
public void setup() {
project = new Project();
tokenLayer = new AnnotationLayer(Token.class.getName(), "Token", SPAN_TYPE, null, true);
tokenPosFeature = new AnnotationFeature();
tokenPosFeature.setName("pos");
tokenPosFeature.setEnabled(true);
tokenPosFeature.setType(POS.class.getName());
tokenPosFeature.setUiName("pos");
tokenPosFeature.setLayer(tokenLayer);
tokenPosFeature.setProject(project);
tokenPosFeature.setVisible(true);
posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, project, true);
posLayer.setAttachType(tokenLayer);
posLayer.setAttachFeature(tokenPosFeature);
posFeature = new AnnotationFeature();
posFeature.setName("PosValue");
posFeature.setEnabled(true);
posFeature.setType(CAS.TYPE_NAME_STRING);
posFeature.setUiName("PosValue");
posFeature.setLayer(posLayer);
posFeature.setProject(project);
posFeature.setVisible(true);
slotLayer = new AnnotationLayer(DiffUtils.HOST_TYPE, DiffUtils.HOST_TYPE, SPAN_TYPE, project, false);
slotFeature = new AnnotationFeature();
slotFeature.setName("links");
slotFeature.setEnabled(true);
slotFeature.setType(Token.class.getName());
slotFeature.setLinkMode(LinkMode.WITH_ROLE);
slotFeature.setUiName("f1");
slotFeature.setLayer(slotLayer);
slotFeature.setProject(project);
slotFeature.setVisible(true);
stringFeature = new AnnotationFeature();
stringFeature.setName("f1");
stringFeature.setEnabled(true);
stringFeature.setType(CAS.TYPE_NAME_STRING);
stringFeature.setUiName("f1");
stringFeature.setLayer(slotLayer);
stringFeature.setProject(project);
stringFeature.setVisible(true);
annotationSchemaService = new MockUp<AnnotationSchemaService>() {
@Mock
List<AnnotationFeature> listAnnotationFeature(AnnotationLayer type) {
if (type.getName().equals(POS.class.getName())) {
return asList(posFeature);
}
if (type.getName().equals(DiffUtils.HOST_TYPE)) {
return asList(slotFeature, stringFeature);
}
throw new IllegalStateException("Unknown layer type: " + type.getName());
}
@Mock
TypeAdapter getAdapter(AnnotationLayer aLayer) {
return AnnotationSchemaServiceImpl.getAdapter(annotationSchemaService, featureSupportRegistry, null, aLayer);
}
}.getMockInstance();
featureSupportRegistry = new FeatureSupportRegistryImpl(asList(new PrimitiveUimaFeatureSupport(), new SlotFeatureSupport()));
featureSupportRegistry.init();
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class ProjectImportPanel method actionImport.
private void actionImport(AjaxRequestTarget aTarget, Form<Preferences> aForm) {
List<FileUpload> exportedProjects = fileUpload.getFileUploads();
boolean aGenerateUsers = preferences.getObject().generateUsers;
// import multiple projects!
Project importedProject = null;
for (FileUpload exportedProject : exportedProjects) {
try {
// Workaround for WICKET-6425
File tempFile = File.createTempFile("webanno-training", null);
try (InputStream is = new BufferedInputStream(exportedProject.getInputStream());
OutputStream os = new FileOutputStream(tempFile)) {
if (!ZipUtils.isZipStream(is)) {
throw new IOException("Invalid ZIP file");
}
IOUtils.copyLarge(is, os);
if (!ImportUtil.isZipValidWebanno(tempFile)) {
throw new IOException("ZIP file is not a WebAnno project archive");
}
importedProject = importService.importProject(tempFile, aGenerateUsers);
} finally {
tempFile.delete();
}
} catch (Exception e) {
aTarget.addChildren(getPage(), IFeedback.class);
error("Error importing project: " + ExceptionUtils.getRootCauseMessage(e));
LOG.error("Error importing project", e);
}
}
if (importedProject != null) {
selectedModel.setObject(importedProject);
aTarget.add(getPage());
}
}
Aggregations