use of de.catma.tag.TagManager in project catma by forTEXT.
the class ImportIntrinsicMarkupStep method enter.
@Override
public void enter(boolean back) {
if (back) {
return;
}
contentPanel.setEnabled(false);
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
@SuppressWarnings("unchecked") final ArrayList<UploadFile> files = new ArrayList<UploadFile>(((Collection<UploadFile>) wizardContext.get(DocumentWizard.WizardContextKey.UPLOAD_FILE_LIST)).stream().filter(uploadFile -> uploadFile.getMimetype().equals(FileType.XML2.getMimeType())).collect(Collectors.toList()));
final TagManager tagmanager = new TagManager(new TagLibrary());
BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) UI.getCurrent();
backgroundServiceProvider.submit("inspecting-intrinsic-markup", new DefaultProgressCallable<List<UploadFile>>() {
@Override
public List<UploadFile> call() throws Exception {
IDGenerator idGenerator = new IDGenerator();
for (UploadFile uploadFile : files) {
XML2ContentHandler contentHandler = new XML2ContentHandler();
SourceDocument doc = new SourceDocument(uploadFile.getUuid(), contentHandler);
SourceDocumentInfo documentInfo = new SourceDocumentInfo();
TechInfoSet techInfoSet = new TechInfoSet();
techInfoSet.setURI(uploadFile.getTempFilename());
documentInfo.setTechInfoSet(techInfoSet);
contentHandler.setSourceDocumentInfo(documentInfo);
XmlMarkupCollectionSerializationHandler handler = new XmlMarkupCollectionSerializationHandler(tagmanager, contentHandler, project.getUser().getIdentifier());
try (FileInputStream fis = new FileInputStream(new File(uploadFile.getTempFilename()))) {
AnnotationCollection collection = handler.deserialize(doc, idGenerator.generateCollectionId(), fis);
uploadFile.setIntrinsicMarkupCollection(collection);
}
}
return files;
}
}, new ExecutionListener<List<UploadFile>>() {
@Override
public void done(List<UploadFile> result) {
contentPanel.setEnabled(true);
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
fileList.clear();
fileList.addAll(result);
fileDataProvider.refreshAll();
tagsetImportList.clear();
String defaultIntrinsicXMLElmentsName = "Default Intrinsic XML Elements";
for (TagsetDefinition tagset : tagmanager.getTagLibrary()) {
if (!tagset.isEmpty()) {
TagsetDefinition targetTagset = project.getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid());
boolean inProject = false;
if (targetTagset == null) {
targetTagset = tagset;
} else {
inProject = true;
}
String namespace = tagset.getName() == null ? "none" : tagset.getName();
if (tagset.getName() == null) {
tagset.setName(defaultIntrinsicXMLElmentsName);
}
TagsetImport tagsetImport = new TagsetImport(namespace, tagset, targetTagset, inProject ? TagsetImportState.WILL_BE_MERGED : TagsetImportState.WILL_BE_CREATED);
tagsetImportList.add(tagsetImport);
}
}
tagsetDataProvider.refreshAll();
wizardContext.put(DocumentWizard.WizardContextKey.TAGSET_IMPORT_LIST, tagsetImportList);
if (stepChangeListener != null) {
stepChangeListener.stepChanged(ImportIntrinsicMarkupStep.this);
}
}
@Override
public void error(Throwable t) {
Logger.getLogger(ImportIntrinsicMarkupStep.class.getName()).log(Level.SEVERE, "Error inspecting files", t);
String errorMsg = t.getMessage();
if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
errorMsg = "";
}
Notification.show("Error", String.format("Error inspecting the contents! " + "\n The underlying error message was:\n%1$s", errorMsg), Type.ERROR_MESSAGE);
}
});
}
use of de.catma.tag.TagManager in project catma by forTEXT.
the class TagsetXMLExportStreamSource method getStream.
@Override
public InputStream getStream() {
final UI ui = UI.getCurrent();
Set<TagsetDefinition> tagsets = tagsetsSupplier.get();
Project project = projectSupplier.get();
if (tagsets != null && !tagsets.isEmpty()) {
TeiDocumentFactory teiDocumentFactory = new TeiDocumentFactory();
try {
final TeiDocument teiDocument = teiDocumentFactory.createEmptyDocument(null);
final TeiTagLibrarySerializer teiTagSerializer = new TeiTagLibrarySerializer(teiDocument);
final TagManager tagManager = new TagManager(new TagLibrary());
tagsets.forEach(tagset -> tagManager.addTagsetDefinition(tagset));
final ContentInfoSet contentInfoSet = new ContentInfoSet(project.getUser().toString(), project.getDescription(), project.getUser().toString(), project.getName());
teiDocument.getTeiHeader().setValues(contentInfoSet);
teiTagSerializer.serialize(tagManager.getTagLibrary());
File tempFile = File.createTempFile(new IDGenerator().generate() + "_TagLibrary_Export", "xml");
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
teiDocument.printXmlDocument(fos);
}
return new FileInputStream(tempFile);
} catch (Exception e) {
((ErrorHandler) ui).showAndLogError("Error exporting Tagsets to XML!", e);
}
}
return null;
}
use of de.catma.tag.TagManager in project catma by forTEXT.
the class GraphWorktreeProject method loadTagLibrary.
@Override
public List<TagsetDefinitionImportStatus> loadTagLibrary(InputStream inputStream) throws IOException {
TeiSerializationHandlerFactory factory = new TeiSerializationHandlerFactory();
factory.setTagManager(new TagManager(new TagLibrary()));
TagLibrarySerializationHandler tagLibrarySerializationHandler = factory.getTagLibrarySerializationHandler();
TagLibrary importedLibrary = tagLibrarySerializationHandler.deserialize(null, inputStream);
List<String> resourceIds = gitProjectHandler.getResourceIds();
List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = new ArrayList<>();
for (TagsetDefinition tagset : importedLibrary) {
boolean inProjectHistory = resourceIds.contains(tagset.getUuid());
boolean current = inProjectHistory && (getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid()) != null);
tagsetDefinitionImportStatusList.add(new TagsetDefinitionImportStatus(tagset, inProjectHistory, current));
}
return tagsetDefinitionImportStatusList;
}
use of de.catma.tag.TagManager in project catma by forTEXT.
the class GraphWorktreeProject method loadAnnotationCollection.
public Pair<AnnotationCollection, List<TagsetDefinitionImportStatus>> loadAnnotationCollection(InputStream inputStream, SourceDocument document) throws IOException {
TagManager tagManager = new TagManager(new TagLibrary());
TeiTagLibrarySerializationHandler tagLibrarySerializationHandler = new TeiTagLibrarySerializationHandler(tagManager);
TagLibrary importedLibrary = tagLibrarySerializationHandler.deserialize(null, inputStream);
List<String> resourceIds = gitProjectHandler.getResourceIds();
List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = new ArrayList<>();
for (TagsetDefinition tagset : importedLibrary) {
boolean inProjectHistory = resourceIds.contains(tagset.getUuid());
boolean current = inProjectHistory && (getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid()) != null);
tagsetDefinitionImportStatusList.add(new TagsetDefinitionImportStatus(tagset, inProjectHistory, current));
}
String collectionId = idGenerator.generate();
TeiUserMarkupCollectionDeserializer deserializer = new TeiUserMarkupCollectionDeserializer(tagLibrarySerializationHandler.getTeiDocument(), tagManager.getTagLibrary(), collectionId);
AnnotationCollection annotationCollection = new AnnotationCollection(collectionId, tagLibrarySerializationHandler.getTeiDocument().getContentInfoSet(), tagManager.getTagLibrary(), deserializer.getTagReferences(), document.getUuid(), document.getRevisionHash());
return new Pair<>(annotationCollection, tagsetDefinitionImportStatusList);
}
use of de.catma.tag.TagManager in project catma by forTEXT.
the class GraphWorktreeProject method synchronizeWithRemote.
@Override
public void synchronizeWithRemote(OpenProjectListener openProjectListener) throws Exception {
if (hasUncommittedChanges()) {
throw new IllegalStateException("There are uncommitted changes that need to be committed first!");
}
for (TagsetDefinition tagset : getTagsets()) {
gitProjectHandler.synchronizeTagsetWithRemote(tagset.getUuid());
}
for (SourceDocument document : getSourceDocuments()) {
gitProjectHandler.synchronizeSourceDocumentWithRemote(document.getUuid());
for (AnnotationCollectionReference collectionReference : document.getUserMarkupCollectionRefs()) {
gitProjectHandler.synchronizeCollectionWithRemote(collectionReference.getId());
}
}
gitProjectHandler.synchronizeWithRemote();
if (gitProjectHandler.hasConflicts()) {
gitProjectHandler.initAndUpdateSubmodules();
openProjectListener.conflictResolutionNeeded(new GitConflictedProject(projectReference, gitProjectHandler, documentId -> getSourceDocumentURI(documentId)));
} else {
boolean forceGraphReload = gitProjectHandler.loadRolesPerResource();
gitProjectHandler.initAndUpdateSubmodules();
gitProjectHandler.removeStaleSubmoduleDirectories();
gitProjectHandler.ensureDevBranches();
rootRevisionHash = gitProjectHandler.getRootRevisionHash();
ProgressListener progressListener = new ProgressListener() {
@Override
public void setProgress(String value, Object... args) {
openProjectListener.progress(value, args);
}
};
graphProjectHandler.ensureProjectRevisionIsLoaded(new ExecutionListener<TagManager>() {
@Override
public void error(Throwable t) {
openProjectListener.failure(t);
}
@Override
public void done(TagManager result) {
tagManager.load(result.getTagLibrary());
openProjectListener.ready(GraphWorktreeProject.this);
}
}, progressListener, rootRevisionHash, tagManager, () -> gitProjectHandler.getTagsets(), () -> gitProjectHandler.getDocuments(), (tagLibrary) -> gitProjectHandler.getCollections(tagLibrary, progressListener), forceGraphReload, backgroundService);
}
}
Aggregations