use of de.catma.repository.git.managers.JGitRepoManager 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.managers.JGitRepoManager 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.managers.JGitRepoManager in project catma by forTEXT.
the class GitTagsetHandlerTest method open.
@Test
public void open() throws Exception {
// TODO: don't hardcode anything in assertions (tagset name, tag definition UUID...)
try (JGitRepoManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
HashMap<String, Object> getJsonLdWebAnnotationResult = JsonLdWebAnnotationTest.getJsonLdWebAnnotation(jGitRepoManager, this.gitLabServerManager, this.catmaUser);
String projectId = (String) getJsonLdWebAnnotationResult.get("projectUuid");
String tagsetId = (String) getJsonLdWebAnnotationResult.get("tagsetDefinitionUuid");
String tagDefinitionId = (String) getJsonLdWebAnnotationResult.get("tagDefinitionUuid");
this.projectsToDeleteOnTearDown.add(projectId);
GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
TagsetDefinition loadedTagsetDefinition = gitTagsetHandler.open(projectId, tagsetId);
assertEquals(tagsetId, loadedTagsetDefinition.getUuid());
assertEquals("Test Tagset", loadedTagsetDefinition.getName());
assertNotNull(loadedTagsetDefinition.getRevisionHash());
assertFalse(loadedTagsetDefinition.isEmpty());
TagDefinition loadedTagDefinition = loadedTagsetDefinition.getTagDefinition(tagDefinitionId);
assertNotNull(loadedTagDefinition);
assertEquals(tagDefinitionId, loadedTagDefinition.getUuid());
assertEquals("TAG_DEF", loadedTagDefinition.getName());
assertEquals("", loadedTagDefinition.getParentUuid());
}
}
use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.
the class GitProjectHandlerTest method createSourceDocument.
// @Test
// public void delete() throws Exception {
// try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(CATMAPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
// this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
//
// GitProjectManager gitProjectHandler = new GitProjectManager(
// CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(),
// UserIdentification.userToMap(this.catmaUser.getIdentifier()));
//
//
// String projectId = gitProjectHandler.create(
// "Test CATMA Project", "This is a test CATMA project"
// );
// // we don't add the projectId to this.projectsToDeleteOnTearDown as this is the delete test
//
// assertNotNull(projectId);
// assert projectId.startsWith("CATMA_");
//
// // the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls
// // return
// assertFalse(jGitRepoManager.isAttached());
//
// String expectedRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
//
// File expectedRootRepositoryPath = new File(
// jGitRepoManager.getRepositoryBasePath(), expectedRootRepositoryName
// );
//
// assert expectedRootRepositoryPath.exists();
// assert expectedRootRepositoryPath.isDirectory();
//
// gitProjectHandler.delete(projectId);
//
// assertFalse(expectedRootRepositoryPath.exists());
//
// // the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls
// // return
// assertFalse(jGitRepoManager.isAttached());
// }
// }
//
// @Test
// public void createTagset() throws Exception {
// try (JGitRepoManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(CATMAPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
// this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
//
// GitProjectManager gitProjectManager = new GitProjectManager(
// CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(),
// UserIdentification.userToMap(this.catmaUser.getIdentifier()));
//
//
// String projectId = gitProjectManager.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());
//
// GitProjectHandler gitProjectHandler = new GitProjectHandler(null, projectId, jGitRepoManager, gitLabServerManager);
//
// String tagsetId = gitProjectHandler.createTagset(
//
// null,
// "Test Tagset",
// null
// );
//
// assertNotNull(tagsetId);
//
// // the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls return
// assertFalse(jGitRepoManager.isAttached());
//
// jGitRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
// Status status = jGitRepoManager.getGitApi().status().call();
// Set<String> added = status.getAdded();
//
// assert status.hasUncommittedChanges();
// assert added.contains(".gitmodules");
// assert added.contains(String.format("%s/%s", GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME, tagsetId));
// }
// }
//
// @Test
// public void createMarkupCollection() throws Exception {
// try (JGitRepoManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(CATMAPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
// this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
//
// GitProjectManager gitProjectManager = new GitProjectManager(
// CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(),
// UserIdentification.userToMap(this.catmaUser.getIdentifier()));
//
//
// String projectId = gitProjectManager.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());
//
// GitProjectHandler gitProjectHandler = new GitProjectHandler(null, projectId, jGitRepoManager, gitLabServerManager);
//
// String markupCollectionId = gitProjectHandler.createMarkupCollection(
// null,
// "Test Markup Collection",
// null,
// "fakeSourceDocumentId",
// "fakeSourceDocumentVersion"
// );
//
// assertNotNull(markupCollectionId);
//
// // the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls return
// assertFalse(jGitRepoManager.isAttached());
//
// jGitRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
// Status status = jGitRepoManager.getGitApi().status().call();
// Set<String> added = status.getAdded();
//
// assert status.hasUncommittedChanges();
// assert added.contains(".gitmodules");
// assert added.contains(
// String.format(
// "%s/%s", GitProjectHandler.MARKUP_COLLECTION_SUBMODULES_DIRECTORY_NAME, markupCollectionId
// )
// );
// }
// }
@Test
public void createSourceDocument() throws Exception {
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);
Map<String, List<TermInfo>> terms = new TermExtractor(IOUtils.toString(convertedSourceDocumentStream, techInfoSet.getCharset()), new ArrayList<>(), new ArrayList<>(), indexInfoSet.getLocale()).getTerms();
// need to re-instantiate the stream, otherwise an empty file will be written later on (FileInputStream does not support `reset`)
convertedSourceDocumentStream = new FileInputStream(convertedSourceDocument);
String sourceDocumentUuid = new IDGenerator().generateDocumentId();
// GraphWorktreeProject.TOKENIZED_FILE_EXTENSION
String tokenizedSourceDocumentFileName = sourceDocumentUuid + "." + "json";
try (JGitRepoManager 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
// the JGitRepoManager instance should always be in a detached state after GitProjectManager calls return
assertFalse(jGitRepoManager.isAttached());
GitProjectHandler gitProjectHandler = new GitProjectHandler(gitlabManagerRestricted.getUser(), projectId, jGitRepoManager, gitlabManagerRestricted);
// would usually happen when the project is opened via GraphWorktreeProject
gitProjectHandler.loadRolesPerResource();
String revisionHash = gitProjectHandler.createSourceDocument(sourceDocumentUuid, originalSourceDocumentStream, originalSourceDocument.getName(), convertedSourceDocumentStream, convertedSourceDocument.getName(), terms, tokenizedSourceDocumentFileName, sourceDocumentInfo);
assertNotNull(revisionHash);
// the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls return
assertFalse(jGitRepoManager.isAttached());
jGitRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
Status status = jGitRepoManager.getGitApi().status().call();
assert status.isClean();
assertFalse(status.hasUncommittedChanges());
Iterable<RevCommit> commits = jGitRepoManager.getGitApi().log().all().call();
@SuppressWarnings("unchecked") List<RevCommit> commitsList = IteratorUtils.toList(commits.iterator());
assertEquals(1, commitsList.size());
// TODO: it would be good to check that the revision hash of the commit matches, however GitProjectHandler currently returns the revision hash
// from the source document repo itself rather than from the root repo
assertEquals(gitlabManagerRestricted.getUser().getIdentifier(), commitsList.get(0).getCommitterIdent().getName());
assertEquals(gitlabManagerRestricted.getUser().getEmail(), commitsList.get(0).getCommitterIdent().getEmailAddress());
assert commitsList.get(0).getFullMessage().contains(String.format("Added Document %s with ID", contentInfoSet.getTitle()));
// TODO: add assertions for actual paths changed (see commented above - would need to be modified for already committed changes)
}
}
use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.
the class GitSourceDocumentHandlerTest method update.
// // how to test for exceptions: https://stackoverflow.com/a/31826781
// @Rule
// public ExpectedException thrown = ExpectedException.none();
//
// @Test
// public void delete() throws Exception {
// try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
// GitSourceDocumentHandler gitSourceDocumentHandler = new GitSourceDocumentHandler(
// jGitRepoManager, this.gitLabServerManager
// );
//
// thrown.expect(IOException.class);
// thrown.expectMessage("Not implemented");
// gitSourceDocumentHandler.delete("fakeProjectId", "fakeSourceDocumentId");
// }
// }
//
// @Test
// public void open() throws Exception {
// try (JGitRepoManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
// this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
//
// HashMap<String, Object> getJsonLdWebAnnotationResult = JsonLdWebAnnotationTest.getJsonLdWebAnnotation(
// jGitRepoManager, this.gitLabServerManager, this.catmaUser
// );
//
// String projectId = (String)getJsonLdWebAnnotationResult.get("projectUuid");
// String sourceDocumentId = (String)getJsonLdWebAnnotationResult.get("sourceDocumentUuid");
//
// this.projectsToDeleteOnTearDown.add(projectId);
//
// GitSourceDocumentHandler gitSourceDocumentHandler = new GitSourceDocumentHandler(
// jGitRepoManager, this.gitLabServerManager
// );
//
// SourceDocument loadedSourceDocument = gitSourceDocumentHandler.open(projectId, sourceDocumentId);
//
// assertNotNull(loadedSourceDocument);
// assertEquals(
// "William Faulkner",
// loadedSourceDocument.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet()
// .getAuthor()
// );
// assertEquals(
// "A Rose for Emily",
// loadedSourceDocument.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet()
// .getTitle()
// );
// assertNotNull(loadedSourceDocument.getRevisionHash());
// }
// }
@Test
public void update() throws Exception {
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);
Map<String, List<TermInfo>> terms = new TermExtractor(IOUtils.toString(convertedSourceDocumentStream, techInfoSet.getCharset()), new ArrayList<>(), new ArrayList<>(), indexInfoSet.getLocale()).getTerms();
// need to re-instantiate the stream, otherwise an empty file will be written later on (FileInputStream does not support `reset`)
convertedSourceDocumentStream = new FileInputStream(convertedSourceDocument);
String sourceDocumentUuid = new IDGenerator().generateDocumentId();
// GraphWorktreeProject.TOKENIZED_FILE_EXTENSION
String tokenizedSourceDocumentFileName = sourceDocumentUuid + "." + "json";
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
// the JGitRepoManager instance should always be in a detached state after GitProjectManager calls return
assertFalse(jGitRepoManager.isAttached());
GitSourceDocumentHandler gitSourceDocumentHandler = new GitSourceDocumentHandler(jGitRepoManager, gitlabManagerRestricted, new UsernamePasswordCredentialsProvider("oauth2", gitlabManagerRestricted.getPassword()));
String revisionHash = gitSourceDocumentHandler.create(projectId, sourceDocumentUuid, originalSourceDocumentStream, originalSourceDocument.getName(), convertedSourceDocumentStream, convertedSourceDocument.getName(), terms, tokenizedSourceDocumentFileName, sourceDocumentInfo);
assertNotNull(revisionHash);
// the JGitRepoManager instance should always be in a detached state after GitSourceDocumentHandler calls return
assertFalse(jGitRepoManager.isAttached());
// TODO: factor out a function that does all of the above
jGitRepoManager.open(projectId, sourceDocumentUuid);
jGitRepoManager.push(new UsernamePasswordCredentialsProvider("oauth2", gitlabManagerRestricted.getPassword()));
String remoteUri = jGitRepoManager.getRemoteUrl(null);
jGitRepoManager.detach();
// open the project root repository
jGitRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
// create the submodule
File targetSubmodulePath = Paths.get(jGitRepoManager.getRepositoryWorkTree().getAbsolutePath(), SOURCE_DOCUMENT_SUBMODULES_DIRECTORY_NAME, sourceDocumentUuid).toFile();
// submodule files and the changed .gitmodules file are automatically staged
jGitRepoManager.addSubmodule(targetSubmodulePath, remoteUri, new UsernamePasswordCredentialsProvider("oauth2", gitlabManagerRestricted.getPassword()));
jGitRepoManager.detach();
SourceDocument sourceDocument = gitSourceDocumentHandler.open(projectId, sourceDocumentUuid);
sourceDocument.getSourceContentHandler().getSourceDocumentInfo().setContentInfoSet(new ContentInfoSet("William Faulkner (updated)", "Test description (new)", "Test publisher (new)", "A Rose for Emily (updated)"));
String sourceDocumentRevision = gitSourceDocumentHandler.update(projectId, sourceDocument);
assertNotNull(sourceDocumentRevision);
String expectedSerializedSourceDocumentInfo = "" + "{\n" + " \"gitContentInfoSet\": {\n" + " \"author\": \"William Faulkner (updated)\",\n" + " \"description\": \"Test description (new)\",\n" + " \"publisher\": \"Test publisher (new)\",\n" + " \"title\": \"A Rose for Emily (updated)\"\n" + " },\n" + " \"gitIndexInfoSet\": {\n" + " \"locale\": \"en\",\n" + " \"unseparableCharacterSequences\": [],\n" + " \"userDefinedSeparatingCharacters\": []\n" + " },\n" + " \"gitTechInfoSet\": {\n" + " \"charset\": \"UTF-8\",\n" + " \"checksum\": 705211438,\n" + " \"fileName\": null,\n" + " \"fileOSType\": \"DOS\",\n" + " \"fileType\": \"TEXT\",\n" + " \"mimeType\": \"text/plain\",\n" + " \"uri\": null\n" + " }\n" + "}";
assertEquals(expectedSerializedSourceDocumentInfo, FileUtils.readFileToString(new File(targetSubmodulePath, "header.json"), StandardCharsets.UTF_8));
}
}
Aggregations