use of de.catma.repository.git.interfaces.ILocalGitRepositoryManager in project catma by forTEXT.
the class GitMarkupCollectionHandlerTest method create.
@Test
public void create() throws Exception {
try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
GitProjectManager gitProjectHandler = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
String projectId = gitProjectHandler.create("Test CATMA Project", "This is a test CATMA project");
this.projectsToDeleteOnTearDown.add(projectId);
// the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls
// return
assertFalse(jGitRepoManager.isAttached());
GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(jGitRepoManager, this.gitLabServerManager);
String markupCollectionId = gitMarkupCollectionHandler.create(projectId, null, "Test Markup Collection", null, "fakeSourceDocumentId", "fakeSourceDocumentVersion");
// we don't add the markupCollectionId to this.markupCollectionReposToDeleteOnTearDown as deletion of the
// project will take care of that for us
assertNotNull(markupCollectionId);
assert markupCollectionId.startsWith("CATMA_");
// the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler
// calls return
assertFalse(jGitRepoManager.isAttached());
File expectedRepoPath = new File(jGitRepoManager.getRepositoryBasePath(), GitMarkupCollectionHandler.getMarkupCollectionRepositoryName(markupCollectionId));
assert expectedRepoPath.exists();
assert expectedRepoPath.isDirectory();
assert Arrays.asList(expectedRepoPath.list()).contains("header.json");
String expectedSerializedHeader = "" + "{\n" + "\t\"author\":null,\n" + "\t\"description\":null,\n" + "\t\"name\":\"Test Markup Collection\",\n" + "\t\"publisher\":null,\n" + "\t\"sourceDocumentId\":\"fakeSourceDocumentId\",\n" + "\t\"sourceDocumentVersion\":\"fakeSourceDocumentVersion\",\n" + "\t\"tagsets\":{}\n" + "}";
assertEquals(expectedSerializedHeader.replaceAll("[\n\t]", ""), FileUtils.readFileToString(new File(expectedRepoPath, "header.json"), StandardCharsets.UTF_8));
}
}
use of de.catma.repository.git.interfaces.ILocalGitRepositoryManager in project catma by forTEXT.
the class GitProjectHandlerTest method create.
@Test
public void create() throws Exception {
try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(), gitlabManagerRestricted.getUser())) {
directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
BackgroundService mockBackgroundService = mock(BackgroundService.class);
EventBus mockEventBus = mock(EventBus.class);
GitProjectManager gitProjectManager = new GitProjectManager(CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(), gitlabManagerRestricted, // noop deletion handler
(projectId) -> {
}, mockBackgroundService, mockEventBus);
String projectId = gitProjectManager.create("Test CATMA Project", "This is a test CATMA project");
// we don't add the projectId to projectsToDeleteOnTearDown as deletion of the user will take care of that for us
assertNotNull(projectId);
assert projectId.startsWith("CATMA_");
// the JGitRepoManager instance should always be in a detached state after GitProjectManager calls return
assertFalse(jGitRepoManager.isAttached());
String expectedRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
File expectedRootRepositoryPath = Paths.get(jGitRepoManager.getRepositoryBasePath().getPath(), projectId, expectedRootRepositoryName).toFile();
assert expectedRootRepositoryPath.exists();
assert expectedRootRepositoryPath.isDirectory();
}
}
use of de.catma.repository.git.interfaces.ILocalGitRepositoryManager in project catma by forTEXT.
the class GitTagsetHandlerTest method delete.
@Test
public void delete() throws Exception {
try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
thrown.expect(IOException.class);
thrown.expectMessage("Not implemented");
gitTagsetHandler.delete("fakeProjectId", "fakeTagsetId");
}
}
use of de.catma.repository.git.interfaces.ILocalGitRepositoryManager 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
}
}
use of de.catma.repository.git.interfaces.ILocalGitRepositoryManager in project catma by forTEXT.
the class GitMarkupCollectionHandler method getCollection.
public AnnotationCollection getCollection(String projectId, String collectionId, TagLibrary tagLibrary, ProgressListener progressListener, boolean hasWritePermission, Function<String, Boolean> hasTagsetIdReadPermissionGetter) throws Exception {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
localGitRepoManager.open(projectId, projectRootRepositoryName);
String markupCollectionSubmoduleRelDir = GitProjectHandler.ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME + "/" + collectionId;
File markupCollectionSubmoduleAbsPath = new File(localGitRepoManager.getRepositoryWorkTree().toString(), markupCollectionSubmoduleRelDir);
String markupCollectionRevisionHash = localGitRepoManager.getSubmoduleHeadRevisionHash(markupCollectionSubmoduleRelDir);
// can't call open on an attached instance
localGitRepoManager.detach();
File markupCollectionHeaderFile = new File(markupCollectionSubmoduleAbsPath, HEADER_FILE_NAME);
String serializedMarkupCollectionHeaderFile = FileUtils.readFileToString(markupCollectionHeaderFile, StandardCharsets.UTF_8);
GitMarkupCollectionHeader markupCollectionHeader = new SerializationHelper<GitMarkupCollectionHeader>().deserialize(serializedMarkupCollectionHeaderFile, GitMarkupCollectionHeader.class);
ContentInfoSet contentInfoSet = new ContentInfoSet(markupCollectionHeader.getAuthor(), markupCollectionHeader.getDescription(), markupCollectionHeader.getPublisher(), markupCollectionHeader.getName());
AtomicInteger counter = new AtomicInteger();
ArrayList<TagReference> tagReferences = this.openTagReferences(projectId, collectionId, contentInfoSet.getTitle(), markupCollectionSubmoduleAbsPath, progressListener, counter);
// handle orphan Annotations
ArrayListMultimap<TagInstance, TagReference> tagInstances = ArrayListMultimap.create();
Set<String> orphanAnnotationIds = new HashSet<>();
Iterator<TagReference> tagReferenceIterator = tagReferences.iterator();
while (tagReferenceIterator.hasNext()) {
TagReference tagReference = tagReferenceIterator.next();
if (!orphanAnnotationIds.contains(tagReference.getTagInstanceId())) {
String tagsetId = tagReference.getTagInstance().getTagsetId();
boolean readPermission = hasTagsetIdReadPermissionGetter.apply(tagsetId);
TagsetDefinition tagset = tagLibrary.getTagsetDefinition(tagsetId);
String tagId = tagReference.getTagDefinitionId();
if (readPermission && (tagset == null || tagset.isDeleted(tagId))) {
// Tag/Tagset has been deleted, we remove the stale Annotation as well
orphanAnnotationIds.add(tagReference.getTagInstanceId());
tagReferenceIterator.remove();
} else {
// other orphan Annotations get ignored upon indexing
// until the corresponding Tag or its "deletion" info come along
tagInstances.put(tagReference.getTagInstance(), tagReference);
}
}
}
if (hasWritePermission) {
removeTagInstances(projectId, collectionId, orphanAnnotationIds);
}
// handle orphan Properties
if (hasWritePermission) {
for (TagInstance tagInstance : tagInstances.keySet()) {
TagsetDefinition tagset = tagLibrary.getTagsetDefinition(tagInstance.getTagsetId());
if (tagset != null) {
Collection<Property> properties = tagInstance.getUserDefinedProperties();
for (Property property : new HashSet<>(properties)) {
// deleted property?
if (tagset.isDeleted(property.getPropertyDefinitionId())) {
// yes, we remove the stale property
tagInstance.removeUserDefinedProperty(property.getPropertyDefinitionId());
// and save the change
JsonLdWebAnnotation annotation = new JsonLdWebAnnotation(CATMAPropertyKey.GitLabServerUrl.getValue(), projectId, tagInstances.get(tagInstance), tagLibrary);
createTagInstance(projectId, collectionId, annotation);
}
}
}
}
}
AnnotationCollection userMarkupCollection = new AnnotationCollection(collectionId, contentInfoSet, tagLibrary, tagReferences, markupCollectionHeader.getSourceDocumentId(), markupCollectionHeader.getSourceDocumentVersion());
userMarkupCollection.setRevisionHash(markupCollectionRevisionHash);
return userMarkupCollection;
}
}
Aggregations