Search in sources :

Example 1 with Version

use of de.catma.tag.Version in project catma by forTEXT.

the class TeiTagLibraryDeserializer method deserialize.

private void deserialize() throws ParseException {
    Nodes tagsetDefinitionElements = teiDocument.getTagsetDefinitionElements();
    for (int i = 0; i < tagsetDefinitionElements.size(); i++) {
        TeiElement tagsetDefinitionElement = (TeiElement) tagsetDefinitionElements.get(i);
        String nValue = tagsetDefinitionElement.getAttributeValue(Attribute.n);
        int dividerPos = nValue.lastIndexOf(' ');
        String tagsetName = nValue.substring(0, dividerPos);
        // version gets ignored, versioning is done via git or not at all!
        // String versionString = nValue.substring(dividerPos+1);
        TagsetDefinition tagsetDefinition = new TagsetDefinition(tagsetDefinitionElement.getID(), tagsetName, new Version());
        tagManager.addTagsetDefinition(tagsetDefinition);
        addTagDefinitions(tagsetDefinition, tagsetDefinitionElement.getChildElements(TeiElementName.fsDecl));
    }
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) Version(de.catma.tag.Version) Nodes(nu.xom.Nodes)

Example 2 with Version

use of de.catma.tag.Version in project catma by forTEXT.

the class GitTagsetHandlerTest method createTagDefinitionWithParent.

@Test
public void createTagDefinitionWithParent() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        // create a project
        GitProjectManager gitProjectManager = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
        String projectId = gitProjectManager.create("Test CATMA Project for Tagset", "This is a test CATMA project");
        this.projectsToDeleteOnTearDown.add(projectId);
        GitProjectHandler gitProjectHandler = new GitProjectHandler(null, projectId, jGitRepoManager, gitLabServerManager);
        // create a tagset
        String tagsetId = gitProjectHandler.createTagset(null, "Test Tagset", null);
        // we don't add the tagsetId to this.tagsetReposToDeleteOnTearDown as deletion of the project will take
        // care of that for us
        // create a TagDefinition object that has a (fake) parent
        String tagDefinitionId = this.idGenerator.generate();
        String parentTagDefinitionId = this.idGenerator.generate();
        Version tagDefinitionVersion = new Version();
        TagDefinition tagDefinition = new TagDefinition(null, tagDefinitionId, "FakeTagDefinitionName", tagDefinitionVersion, null, parentTagDefinitionId);
        // call createTagDefinition
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
        String returnedTagDefinitionId = gitTagsetHandler.createOrUpdateTagDefinition(projectId, tagsetId, tagDefinition);
        assertNotNull(returnedTagDefinitionId);
        assert returnedTagDefinitionId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitTagsetHandler calls return
        assertFalse(jGitRepoManager.isAttached());
        assertEquals(tagDefinitionId, returnedTagDefinitionId);
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        File expectedTagDefinitionPath = Paths.get(jGitRepoManager.getRepositoryBasePath().toString(), projectRootRepositoryName, GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME, tagsetId, parentTagDefinitionId, tagDefinition.getUuid()).toFile();
        assert expectedTagDefinitionPath.exists() : "Directory does not exist";
        assert expectedTagDefinitionPath.isDirectory() : "Path is not a directory";
        assert Arrays.asList(expectedTagDefinitionPath.list()).contains("propertydefs.json");
        GitTagDefinition expectedGitTagDefinition = new GitTagDefinition(tagDefinition);
        String actualSerializedGitTagDefinition = FileUtils.readFileToString(new File(expectedTagDefinitionPath, "propertydefs.json"), StandardCharsets.UTF_8);
        GitTagDefinition actualGitTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(actualSerializedGitTagDefinition, GitTagDefinition.class);
        assertEquals(expectedGitTagDefinition.getTagsetDefinitionUuid(), actualGitTagDefinition.getTagsetDefinitionUuid());
        assertEquals(expectedGitTagDefinition.getParentUuid(), actualGitTagDefinition.getParentUuid());
        assertEquals(expectedGitTagDefinition.getUuid(), actualGitTagDefinition.getUuid());
        assertEquals(expectedGitTagDefinition.getName(), actualGitTagDefinition.getName());
    // TODO: assert tag definition
    }
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) Version(de.catma.tag.Version) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) File(java.io.File) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test) JsonLdWebAnnotationTest(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)

Example 3 with Version

use of de.catma.tag.Version in project catma by forTEXT.

the class V3TeiDocumentConverter method addStandardTagset.

private TeiElement addStandardTagset(TeiElement encodingDesc, String standardTagsetID) {
    /* 
		 	<fsdDecl xml:id="CATMA_STANDARD_TAGSET" n="Standard Tagset 1">
				<!-- base tag -->
				<fsDecl xml:id="CATMA_BASE_TAG" n="1" type="CATMA_BASE_TAG">
					<fsDescr>CATMA Base Tag</fsDescr>
					<fDecl name="catma_displaycolor"
						optional="false">
						<vRange>
							<numeric value="-16777216" max="-1"/>
						</vRange>
					</fDecl>
				</fsDecl>
			</fsdDecl>
		 */
    Version baseVersion = new Version(LEGACY_VERSION_BASE_DATE.getTime());
    TeiElement fsdDecl = addTagsetDefinition(// there is no standard tagset in V3, so we create new "standard tagsets" with identical names
    standardTagsetID, "Standard Tagset " + baseVersion, encodingDesc);
    return fsdDecl;
}
Also used : Version(de.catma.tag.Version)

Example 4 with Version

use of de.catma.tag.Version in project catma by forTEXT.

the class JsonLdWebAnnotationTest method getJsonLdWebAnnotation.

/**
 * @return a HashMap<String, Object> with these keys:
 *         'jsonLdWebAnnotation' - for the JsonLdWebAnnotation object
 *         'projectUuid'
 *         --- following additional keys which are to be used when formatting EXPECTED_SERIALIZED_ANNOTATION ---:
 *         projectRootRepositoryName, tagsetDefinitionUuid, tagDefinitionUuid, userPropertyDefinitionUuid,
 *         systemPropertyDefinitionUuid, userMarkupCollectionUuid, tagInstanceUuid, sourceDocumentUuid
 */
public static HashMap<String, Object> getJsonLdWebAnnotation(JGitRepoManager jGitRepoManager, IRemoteGitServerManager gitLabServerManager, de.catma.user.User catmaUser) throws Exception {
    try (JGitRepoManager localJGitRepoManager = jGitRepoManager) {
        // caller should do the following:
        // this.directoriesToDeleteOnTearDown.add(localJGitRepoManager.getRepositoryBasePath());
        // create project
        GitProjectManager gitProjectManager = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(catmaUser.getIdentifier()));
        String projectId = gitProjectManager.create("Test CATMA Project", "This is a test CATMA project");
        // caller should do the following:
        // this.projectsToDeleteOnTearDown.add(projectId);
        GitProjectHandler gitProjectHandler = new GitProjectHandler(null, projectId, jGitRepoManager, gitLabServerManager);
        // add new tagset to project
        String tagsetId = gitProjectHandler.createTagset(null, "Test Tagset", null);
        // add new source document to project
        File originalSourceDocument = new File("testdocs/rose_for_emily.pdf");
        File convertedSourceDocument = new File("testdocs/rose_for_emily.txt");
        FileInputStream originalSourceDocumentStream = new FileInputStream(originalSourceDocument);
        FileInputStream convertedSourceDocumentStream = new FileInputStream(convertedSourceDocument);
        IndexInfoSet indexInfoSet = new IndexInfoSet();
        indexInfoSet.setLocale(Locale.ENGLISH);
        ContentInfoSet contentInfoSet = new ContentInfoSet("William Faulkner", "", "", "A Rose for Emily");
        TechInfoSet techInfoSet = new TechInfoSet(FileType.TEXT, StandardCharsets.UTF_8, FileOSType.DOS, 705211438L);
        SourceDocumentInfo sourceDocumentInfo = new SourceDocumentInfo(indexInfoSet, contentInfoSet, techInfoSet);
        String sourceDocumentId = gitProjectHandler.createSourceDocument(null, originalSourceDocumentStream, originalSourceDocument.getName(), convertedSourceDocumentStream, convertedSourceDocument.getName(), null, null, sourceDocumentInfo);
        // add new markup collection to project
        String markupCollectionId = gitProjectHandler.createMarkupCollection(null, "Test Markup Collection", null, sourceDocumentId, "fakeSourceDocumentVersion");
        // commit the changes to the project root repo (addition of tagset, source document and markup collection
        // submodules)
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        localJGitRepoManager.open(projectId, projectRootRepositoryName);
        localJGitRepoManager.commit(String.format("Adding new tagset %s, source document %s and markup collection %s", tagsetId, sourceDocumentId, markupCollectionId), "Test Committer", "testcommitter@catma.de");
        // can't call open on an attached instance
        localJGitRepoManager.detach();
        // construct TagDefinition object
        IDGenerator idGenerator = new IDGenerator();
        List<String> systemPropertyPossibleValues = Arrays.asList("SYSPROP_VAL_1", "SYSPROP_VAL_2");
        PropertyDefinition systemPropertyDefinition = new PropertyDefinition(PropertyDefinition.SystemPropertyName.catma_displaycolor.toString(), systemPropertyPossibleValues);
        List<String> userPropertyPossibleValues = Arrays.asList("UPROP_VAL_1", "UPROP_VAL_2");
        PropertyDefinition userPropertyDefinition = new PropertyDefinition("UPROP_DEF", userPropertyPossibleValues);
        String tagDefinitionUuid = idGenerator.generate();
        TagDefinition tagDefinition = new TagDefinition(null, tagDefinitionUuid, "TAG_DEF", new Version(), null, null, tagsetId);
        tagDefinition.addSystemPropertyDefinition(systemPropertyDefinition);
        tagDefinition.addUserDefinedPropertyDefinition(userPropertyDefinition);
        // call createTagDefinition
        // NB: in this case we know that the tagset submodule is on the master branch tip, ie: not in a detached
        // head state, so it's safe to make changes to the submodule and commit them
        // TODO: createTagDefinition should probably do some validation and fail fast if the tagset submodule is in
        // a detached head state - in that case the submodule would need to be updated first
        // see the "Updating a submodule in-place in the container" scenario at
        // https://medium.com/@porteneuve/mastering-git-submodules-34c65e940407
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(localJGitRepoManager, gitLabServerManager);
        String returnedTagDefinitionId = gitTagsetHandler.createOrUpdateTagDefinition(projectId, tagsetId, tagDefinition);
        assertNotNull(returnedTagDefinitionId);
        assert returnedTagDefinitionId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitTagsetHandler calls return
        assertFalse(localJGitRepoManager.isAttached());
        assertEquals(tagDefinitionUuid, returnedTagDefinitionId);
        // commit and push submodule changes (creation of tag definition)
        // TODO: add methods to JGitRepoManager to do this
        localJGitRepoManager.open(projectId, projectRootRepositoryName);
        Repository projectRootRepository = localJGitRepoManager.getGitApi().getRepository();
        String tagsetSubmodulePath = String.format("%s/%s", GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME, tagsetId);
        Repository tagsetSubmoduleRepository = SubmoduleWalk.getSubmoduleRepository(projectRootRepository, tagsetSubmodulePath);
        Git submoduleGit = new Git(tagsetSubmoduleRepository);
        submoduleGit.add().addFilepattern(tagDefinitionUuid).call();
        submoduleGit.commit().setMessage(String.format("Adding tag definition %s", tagDefinitionUuid)).setCommitter("Test Committer", "testcommitter@catma.de").call();
        submoduleGit.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitLabServerManager.getUsername(), gitLabServerManager.getPassword())).call();
        tagsetSubmoduleRepository.close();
        submoduleGit.close();
        // commit and push project root repo changes (update of tagset submodule)
        localJGitRepoManager.getGitApi().add().addFilepattern(tagsetSubmodulePath).call();
        localJGitRepoManager.commit(String.format("Updating tagset %s", tagsetId), "Test Committer", "testcommitter@catma.de");
        // construct TagInstance object
        Property systemProperty = new Property(systemPropertyDefinition, Collections.singleton("SYSPROP_VAL_1"));
        Property userProperty = new Property(userPropertyDefinition, Collections.singleton("UPROP_VAL_2"));
        String tagInstanceUuid = idGenerator.generate();
        TagInstance tagInstance = new TagInstance(tagInstanceUuid, tagDefinition);
        tagInstance.addSystemProperty(systemProperty);
        tagInstance.addUserDefinedProperty(userProperty);
        // construct JsonLdWebAnnotation object
        String sourceDocumentUri = String.format("http://catma.de/gitlab/%s/%s/%s", projectRootRepositoryName, GitProjectHandler.SOURCE_DOCUMENT_SUBMODULES_DIRECTORY_NAME, sourceDocumentId);
        Range range1 = new Range(12, 18);
        Range range2 = new Range(41, 47);
        List<TagReference> tagReferences = new ArrayList<>(Arrays.asList(new TagReference(tagInstance, sourceDocumentUri, range1, markupCollectionId), new TagReference(tagInstance, sourceDocumentUri, range2, markupCollectionId)));
        JsonLdWebAnnotation jsonLdWebAnnotation = new JsonLdWebAnnotation("http://catma.de/gitlab", projectId, tagReferences);
        HashMap<String, Object> returnValue = new HashMap<>();
        returnValue.put("jsonLdWebAnnotation", jsonLdWebAnnotation);
        returnValue.put("projectRootRepositoryName", projectRootRepositoryName);
        returnValue.put("projectUuid", projectId);
        returnValue.put("tagsetDefinitionUuid", tagsetId);
        returnValue.put("tagDefinitionUuid", tagDefinitionUuid);
        returnValue.put("userMarkupCollectionUuid", markupCollectionId);
        returnValue.put("tagInstanceUuid", tagInstanceUuid);
        returnValue.put("sourceDocumentUuid", sourceDocumentId);
        return returnValue;
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) SourceDocumentInfo(de.catma.document.source.SourceDocumentInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GitProjectManager(de.catma.repository.git.GitProjectManager) ContentInfoSet(de.catma.document.source.ContentInfoSet) IndexInfoSet(de.catma.document.source.IndexInfoSet) Version(de.catma.tag.Version) TechInfoSet(de.catma.document.source.TechInfoSet) Property(de.catma.tag.Property) GitTagsetHandler(de.catma.repository.git.GitTagsetHandler) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) Range(de.catma.document.Range) PropertyDefinition(de.catma.tag.PropertyDefinition) FileInputStream(java.io.FileInputStream) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) TagInstance(de.catma.tag.TagInstance) GitProjectHandler(de.catma.repository.git.GitProjectHandler) TagReference(de.catma.document.standoffmarkup.usermarkup.TagReference) File(java.io.File) IDGenerator(de.catma.util.IDGenerator)

Example 5 with Version

use of de.catma.tag.Version in project catma by forTEXT.

the class GitTagsetHandlerTest method createTagDefinitionWithoutParent.

@Test
public void createTagDefinitionWithoutParent() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        // create a project
        GitProjectManager gitProjectManager = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
        String projectId = gitProjectManager.create("Test CATMA Project for Tagset", "This is a test CATMA project");
        this.projectsToDeleteOnTearDown.add(projectId);
        GitProjectHandler gitProjectHandler = new GitProjectHandler(null, projectId, jGitRepoManager, gitLabServerManager);
        // create a tagset
        String tagsetId = gitProjectHandler.createTagset(null, "Test Tagset", null);
        // we don't add the tagsetId to this.tagsetReposToDeleteOnTearDown as deletion of the project will take
        // care of that for us
        // create a TagDefinition object
        String tagDefinitionId = this.idGenerator.generate();
        Version tagDefinitionVersion = new Version();
        TagDefinition tagDefinition = new TagDefinition(null, tagDefinitionId, "FakeTagDefinitionName", tagDefinitionVersion, null, null);
        PropertyDefinition propertyDefinition = new PropertyDefinition("Weather", Arrays.asList("Good", "Bad", "Toto, I've a feeling we're not in Kansas anymore."));
        tagDefinition.addUserDefinedPropertyDefinition(propertyDefinition);
        // call createTagDefinition
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
        String returnedTagDefinitionId = gitTagsetHandler.createOrUpdateTagDefinition(projectId, tagsetId, tagDefinition);
        assertNotNull(returnedTagDefinitionId);
        assert returnedTagDefinitionId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitTagsetHandler calls return
        assertFalse(jGitRepoManager.isAttached());
        assertEquals(tagDefinitionId, returnedTagDefinitionId);
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        File expectedTagDefinitionPath = Paths.get(jGitRepoManager.getRepositoryBasePath().toString(), projectRootRepositoryName, GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME, tagsetId, tagDefinition.getUuid()).toFile();
        assert expectedTagDefinitionPath.exists() : "Directory does not exist";
        assert expectedTagDefinitionPath.isDirectory() : "Path is not a directory";
        assert Arrays.asList(expectedTagDefinitionPath.list()).contains("propertydefs.json");
        GitTagDefinition expectedGitTagDefinition = new GitTagDefinition(tagDefinition);
        String actualSerializedGitTagDefinition = FileUtils.readFileToString(new File(expectedTagDefinitionPath, "propertydefs.json"), StandardCharsets.UTF_8);
        GitTagDefinition actualGitTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(actualSerializedGitTagDefinition, GitTagDefinition.class);
        assertEquals(expectedGitTagDefinition.getTagsetDefinitionUuid(), actualGitTagDefinition.getTagsetDefinitionUuid());
        assertEquals(expectedGitTagDefinition.getParentUuid(), actualGitTagDefinition.getParentUuid());
        assertEquals(expectedGitTagDefinition.getUuid(), actualGitTagDefinition.getUuid());
        assertEquals(expectedGitTagDefinition.getName(), actualGitTagDefinition.getName());
    // TODO: assert tag definition and properties
    }
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) Version(de.catma.tag.Version) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) PropertyDefinition(de.catma.tag.PropertyDefinition) File(java.io.File) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test) JsonLdWebAnnotationTest(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)

Aggregations

Version (de.catma.tag.Version)13 TagsetDefinition (de.catma.tag.TagsetDefinition)8 IDGenerator (de.catma.util.IDGenerator)7 SingleTextInputDialog (de.catma.ui.dialog.SingleTextInputDialog)5 JGitRepoManager (de.catma.repository.git.managers.JGitRepoManager)3 PropertyDefinition (de.catma.tag.PropertyDefinition)3 TagDefinition (de.catma.tag.TagDefinition)3 File (java.io.File)3 ContentInfoSet (de.catma.document.source.ContentInfoSet)2 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)2 GitLabServerManagerTest (de.catma.repository.git.managers.GitLabServerManagerTest)2 GitTagDefinition (de.catma.repository.git.serialization.model_wrappers.GitTagDefinition)2 JsonLdWebAnnotationTest (de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Range (de.catma.document.Range)1 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)1 IndexInfoSet (de.catma.document.source.IndexInfoSet)1 SourceDocument (de.catma.document.source.SourceDocument)1 SourceDocumentInfo (de.catma.document.source.SourceDocumentInfo)1