use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class AnnotationPage 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 (isAnnotator(project, projectService, user) && WebAnnoConst.PROJECT_TYPE_ANNOTATION.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 WebhookServiceTest method test.
@Test
public void test() {
Webhook hook = new Webhook();
hook.setUrl("http://localhost:" + port + "/test/subscribe");
hook.setTopics(asList(PROJECT_STATE, ANNOTATION_STATE, DOCUMENT_STATE));
hook.setEnabled(true);
webhooksConfiguration.setGlobalHooks(asList(hook));
Project project = new Project();
project.setState(ProjectState.NEW);
project.setId(1l);
SourceDocument doc = new SourceDocument();
doc.setProject(project);
doc.setId(2l);
doc.setState(SourceDocumentState.ANNOTATION_IN_PROGRESS);
AnnotationDocument ann = new AnnotationDocument();
ann.setProject(project);
ann.setId(3l);
ann.setDocument(doc);
ann.setState(AnnotationDocumentState.FINISHED);
applicationEventPublisher.publishEvent(new ProjectStateChangedEvent(this, project, ProjectState.CURATION_FINISHED));
applicationEventPublisher.publishEvent(new DocumentStateChangedEvent(this, doc, SourceDocumentState.NEW));
applicationEventPublisher.publishEvent(new AnnotationStateChangeEvent(this, ann, AnnotationDocumentState.IN_PROGRESS));
assertEquals(1, testService.projectStateChangeMsgs.size());
assertEquals(1, testService.docStateChangeMsgs.size());
assertEquals(1, testService.annStateChangeMsgs.size());
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class MiraAutomationServiceImpl method removeTrainingDocument.
@Override
@Transactional
public void removeTrainingDocument(TrainingDocument aDocument) throws IOException {
entityManager.remove(aDocument);
String path = dir.getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aDocument.getProject().getId() + TRAIN + aDocument.getId();
// remove from file both source and related annotation file
if (new File(path).exists()) {
FileUtils.forceDelete(new File(path));
}
try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aDocument.getProject().getId()))) {
Project project = aDocument.getProject();
log.info("Removed source document [{}]({}) from project [{}]({})", aDocument.getName(), aDocument.getId(), project.getName(), project.getId());
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class MiraAutomationServiceImpl method uploadTrainingDocument.
@Override
@Transactional
public void uploadTrainingDocument(File aFile, TrainingDocument aDocument) throws IOException {
// Check if the file has a valid format / can be converted without error
JCas cas = null;
try {
if (aDocument.getFormat().equals(WebAnnoConst.TAB_SEP)) {
if (!isTabSepFileFormatCorrect(aFile)) {
throw new IOException("This TAB-SEP file is not in correct format. It should have two columns separated by TAB!");
}
} else {
cas = importExportService.importCasFromFile(aFile, aDocument.getProject(), aDocument.getFormat());
automationCasStorageService.analyzeAndRepair(aDocument, cas.getCas());
}
} catch (IOException e) {
removeTrainingDocument(aDocument);
throw e;
} catch (Exception e) {
removeTrainingDocument(aDocument);
throw new IOException(e.getMessage(), e);
}
// Copy the original file into the repository
File targetFile = getTrainingDocumentFile(aDocument);
FileUtils.forceMkdir(targetFile.getParentFile());
FileUtils.copyFile(aFile, targetFile);
// Copy the initial conversion of the file into the repository
if (cas != null) {
CasPersistenceUtils.writeSerializedCas(cas, getCasFile(aDocument));
}
try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aDocument.getProject().getId()))) {
Project project = aDocument.getProject();
log.info("Imported training document [{}]({}) to project [{}]({})", aDocument.getName(), aDocument.getId(), project.getName(), project.getId());
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class FixAttachFeature330 method doMigration.
private void doMigration() {
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setName("migrationRoot");
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = null;
try {
status = txManager.getTransaction(def);
for (Project project : projectService.listProjects()) {
try {
AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), project);
// Set attach-feature of Dependency layer to Token.pos if necessary
fix(project, Dependency.class, RELATION_TYPE, tokenLayer, "pos");
// Set attach-feature of POS layer to Token.pos if necessary
fix(project, POS.class, SPAN_TYPE, tokenLayer, "pos");
// Set attach-feature of Lemma layer to Token.lemma if necessary
fix(project, Lemma.class, SPAN_TYPE, tokenLayer, "lemma");
// Set attach-feature of MorphologicalFeatures layer to Token.morph if necessary
fix(project, MorphologicalFeatures.class, SPAN_TYPE, tokenLayer, "morph");
} catch (NoResultException e) {
// This only happens if a project is not fully set up. Every project
// should have a Token layer. However, it is not the responsibility of this
// migration to enforce this, so we just ignore it.
log.warn("Project {} does not seem to include a Token layer!", project);
}
}
txManager.commit(status);
} finally {
if (status != null && !status.isCompleted()) {
txManager.rollback(status);
}
}
}
Aggregations