use of de.catma.repository.git.serialization.model_wrappers.GitTagDefinition 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.serialization.model_wrappers.GitTagDefinition in project catma by forTEXT.
the class GitTagsetHandler method createOrUpdateTagDefinition.
public void createOrUpdateTagDefinition(String projectId, String tagsetId, TagDefinition tagDefinition) throws IOException {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
String targetPropertyDefinitionsFileRelativePath = (StringUtils.isEmpty(tagDefinition.getParentUuid()) ? "" : (tagDefinition.getParentUuid() + "/")) + tagDefinition.getUuid() + "/propertydefs.json";
String tagsetGitRepositoryName = projectRootRepositoryName + "/" + GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME + "/" + tagsetId;
localGitRepoManager.open(projectId, tagsetGitRepositoryName);
File targetPropertyDefinitionsFileAbsolutePath = Paths.get(localGitRepoManager.getRepositoryWorkTree().toString(), targetPropertyDefinitionsFileRelativePath).toFile();
GitTagDefinition gitTagDefinition = new GitTagDefinition(tagDefinition);
String serializedGitTagDefinition = new SerializationHelper<GitTagDefinition>().serialize(gitTagDefinition);
localGitRepoManager.add(targetPropertyDefinitionsFileAbsolutePath.getAbsoluteFile(), serializedGitTagDefinition.getBytes(StandardCharsets.UTF_8));
}
}
use of de.catma.repository.git.serialization.model_wrappers.GitTagDefinition in project catma by forTEXT.
the class GitTagsetHandler method removePropertyDefinition.
public String removePropertyDefinition(String projectId, TagsetDefinition tagsetDefinition, TagDefinition tagDefinition, PropertyDefinition propertyDefinition) throws IOException {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
String tagsetGitRepositoryName = projectRootRepositoryName + "/" + GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME + "/" + tagsetDefinition.getUuid();
localGitRepoManager.open(projectId, tagsetGitRepositoryName);
// write header.json with deletion journal
File targetHeaderFile = new File(localGitRepoManager.getRepositoryWorkTree(), HEADER_FILE_NAME);
GitTagsetHeader header = new GitTagsetHeader(tagsetDefinition.getName(), // TODO: description
"", new TreeSet<>(tagsetDefinition.getDeletedDefinitions()));
String serializedHeader = new SerializationHelper<GitTagsetHeader>().serialize(header);
localGitRepoManager.add(targetHeaderFile, serializedHeader.getBytes(StandardCharsets.UTF_8));
String targetPropertyDefinitionsFileRelativePath = (StringUtils.isEmpty(tagDefinition.getParentUuid()) ? "" : (tagDefinition.getParentUuid() + "/")) + tagDefinition.getUuid() + "/propertydefs.json";
File targetPropertyDefinitionsFileAbsolutePath = Paths.get(localGitRepoManager.getRepositoryWorkTree().toString(), targetPropertyDefinitionsFileRelativePath).toFile();
GitTagDefinition gitTagDefinition = new GitTagDefinition(tagDefinition);
String serializedGitTagDefinition = new SerializationHelper<GitTagDefinition>().serialize(gitTagDefinition);
String tagsetRevision = localGitRepoManager.addAndCommit(targetPropertyDefinitionsFileAbsolutePath, serializedGitTagDefinition.getBytes(StandardCharsets.UTF_8), String.format("Removed Property Definition %1$s with ID %2$s from Tag %3$s with ID %4$s", propertyDefinition.getName(), propertyDefinition.getUuid(), tagDefinition.getName(), tagDefinition.getUuid()), remoteGitServerManager.getUsername(), remoteGitServerManager.getEmail());
return tagsetRevision;
}
}
use of de.catma.repository.git.serialization.model_wrappers.GitTagDefinition in project catma by forTEXT.
the class GitTagsetHandler method getBothModifiedTagConflict.
private TagConflict getBothModifiedTagConflict(String projectId, String tagsetId, String serializedConflictingTag) throws Exception {
String masterVersion = serializedConflictingTag.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q=======\\E(\\r\\n|\\r|\\n|.)*?\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
String devVersion = serializedConflictingTag.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n|.)*?\\Q=======\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
GitTagDefinition gitMasterTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(masterVersion, GitTagDefinition.class);
TagDefinition masterTagDefinition = gitMasterTagDefinition.getTagDefinition();
GitTagDefinition gitDevTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(devVersion, GitTagDefinition.class);
TagDefinition devTagDefinition = gitDevTagDefinition.getTagDefinition();
TagConflict tagConflict = new TagConflict(masterTagDefinition, devTagDefinition);
return tagConflict;
}
use of de.catma.repository.git.serialization.model_wrappers.GitTagDefinition 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
}
}
Aggregations