use of de.catma.repository.git.serialization.models.GitTagsetHeader in project catma by forTEXT.
the class GitTagsetHandlerTest 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 for Tagset", "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());
GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
String name = "Test Tagset";
String description = "Test Tagset Description";
String tagsetId = gitTagsetHandler.create(projectId, null, name, description);
// we don't add the tagsetId to this.tagsetReposToDeleteOnTearDown as deletion of the
// project will take care of that for us
assertNotNull(tagsetId);
assert tagsetId.startsWith("CATMA_");
File expectedRepoPath = new File(jGitRepoManager.getRepositoryBasePath(), GitTagsetHandler.getTagsetRepositoryName(tagsetId));
assert expectedRepoPath.exists();
assert expectedRepoPath.isDirectory();
assert Arrays.asList(expectedRepoPath.list()).contains("header.json");
GitTagsetHeader expectedHeader = new GitTagsetHeader(name, description);
String serialized = FileUtils.readFileToString(new File(expectedRepoPath, "header.json"), StandardCharsets.UTF_8);
GitTagsetHeader actualHeader = new SerializationHelper<GitTagsetHeader>().deserialize(serialized, GitTagsetHeader.class);
assertEquals(expectedHeader.getName(), actualHeader.getName());
assertEquals(expectedHeader.getDescription(), actualHeader.getDescription());
}
}
use of de.catma.repository.git.serialization.models.GitTagsetHeader in project catma by forTEXT.
the class GitTagsetHandler method removeTagDefinition.
public String removeTagDefinition(String projectId, TagDefinition tagDefinition) throws IOException {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
String tagsetGitRepositoryName = projectRootRepositoryName + "/" + GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME + "/" + tagDefinition.getTagsetDefinitionUuid();
localGitRepoManager.open(projectId, tagsetGitRepositoryName);
// write header.json with deletion journal
File tagsetHeaderFile = new File(localGitRepoManager.getRepositoryWorkTree(), HEADER_FILE_NAME);
String serializedTagsetHeader = FileUtils.readFileToString(tagsetHeaderFile, StandardCharsets.UTF_8);
GitTagsetHeader gitTagsetHeader = new SerializationHelper<GitTagsetHeader>().deserialize(serializedTagsetHeader, GitTagsetHeader.class);
serializedTagsetHeader = new SerializationHelper<GitTagsetHeader>().serialize(gitTagsetHeader);
gitTagsetHeader.getDeletedDefinitions().add(tagDefinition.getUuid());
serializedTagsetHeader = new SerializationHelper<GitTagsetHeader>().serialize(gitTagsetHeader);
localGitRepoManager.add(tagsetHeaderFile, serializedTagsetHeader.getBytes(StandardCharsets.UTF_8));
String targetTagDefinitionsFolderRelativePath = (StringUtils.isEmpty(tagDefinition.getParentUuid()) ? "" : (tagDefinition.getParentUuid() + "/")) + tagDefinition.getUuid();
File targetTagDefinitionsFolderAbsolutePath = Paths.get(localGitRepoManager.getRepositoryWorkTree().toString(), targetTagDefinitionsFolderRelativePath).toFile();
String tagsetRevision = localGitRepoManager.removeAndCommit(targetTagDefinitionsFolderAbsolutePath, // delete empty parent tag directory
!StringUtils.isEmpty(tagDefinition.getParentUuid()), String.format("Removing Tag %1$s with ID %2$s", tagDefinition.getName(), tagDefinition.getUuid()), remoteGitServerManager.getUsername(), remoteGitServerManager.getEmail());
return tagsetRevision;
}
}
use of de.catma.repository.git.serialization.models.GitTagsetHeader in project catma by forTEXT.
the class GitTagsetHandler method getContentInfoSet.
public ContentInfoSet getContentInfoSet(String projectId, String tagsetId) throws IOException {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
localGitRepoManager.open(projectId, projectRootRepositoryName);
String tagsetSubmoduleName = String.format("%s/%s", GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME, tagsetId);
File tagsetHeaderFile = new File(localGitRepoManager.getRepositoryWorkTree(), tagsetSubmoduleName + "/" + HEADER_FILE_NAME);
String serialized = FileUtils.readFileToString(tagsetHeaderFile, StandardCharsets.UTF_8);
GitTagsetHeader gitTagsetHeader = new SerializationHelper<GitTagsetHeader>().deserialize(serialized, GitTagsetHeader.class);
ContentInfoSet contentInfoSet = new ContentInfoSet();
contentInfoSet.setTitle(gitTagsetHeader.getName());
return contentInfoSet;
}
}
use of de.catma.repository.git.serialization.models.GitTagsetHeader in project catma by forTEXT.
the class GitTagsetHandler method resolveTagsetHeaderConflict.
private GitTagsetHeader resolveTagsetHeaderConflict(String serializedTagsetHeaderFile, StageState stageState) {
if (stageState.equals(StageState.BOTH_MODIFIED)) {
String masterVersion = serializedTagsetHeaderFile.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q=======\\E(\\r\\n|\\r|\\n|.)*?\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
String devVersion = serializedTagsetHeaderFile.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n|.)*?\\Q=======\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
GitTagsetHeader masterTagsetHeader = new SerializationHelper<GitTagsetHeader>().deserialize(masterVersion, GitTagsetHeader.class);
GitTagsetHeader devTagsetHeader = new SerializationHelper<GitTagsetHeader>().deserialize(devVersion, GitTagsetHeader.class);
String name = masterTagsetHeader.getName() == null ? "" : masterTagsetHeader.getName().trim();
String devName = devTagsetHeader.getName() == null ? "" : devTagsetHeader.getName().trim();
if (!name.equalsIgnoreCase(devName) && devName.length() > 0) {
name = String.format("%s %s", name, devName);
}
String description = masterTagsetHeader.getDescription() == null ? "" : masterTagsetHeader.getDescription().trim();
String devDescription = devTagsetHeader.getDescription() == null ? "" : devTagsetHeader.getDescription().trim();
if (!description.equalsIgnoreCase(devDescription) && devDescription.length() > 0) {
description = String.format("%s %s", description, devDescription);
}
TreeSet<String> deletedDefinitions = new TreeSet<>();
deletedDefinitions.addAll(masterTagsetHeader.getDeletedDefinitions());
deletedDefinitions.addAll(devTagsetHeader.getDeletedDefinitions());
return new GitTagsetHeader(name, description, deletedDefinitions);
} else {
return new SerializationHelper<GitTagsetHeader>().deserialize(serializedTagsetHeaderFile, GitTagsetHeader.class);
}
}
use of de.catma.repository.git.serialization.models.GitTagsetHeader in project catma by forTEXT.
the class GitTagsetHandler method create.
/**
* Creates a new tagset.
* <p>
* NB: You probably don't want to call this method directly (it doesn't create the submodule in the project root
* repo). Instead call the <code>createTagset</code> method of the {@link GitProjectManager} class.
*
* @param projectId the ID of the project within which the tagset must be created
* @param tagsetId the ID of the tagset to create. If none is provided, a new ID will be generated.
* @param name the name of the new tagset
* @param description the description of the new tagset
* @return the new revisionhash
* @throws IOException if an error occurs while creating the tagset
*/
public String create(String projectId, String tagsetId, String name, String description) throws IOException {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
// create the remote tagset repository
CreateRepositoryResponse createRepositoryResponse = this.remoteGitServerManager.createRepository(tagsetId, tagsetId, projectId);
// clone the repository locally
localGitRepoManager.clone(projectId, createRepositoryResponse.repositoryHttpUrl, // destination path is created by the repo manager
null, credentialsProvider);
// write header.json into the local repo
File targetHeaderFile = new File(localGitRepoManager.getRepositoryWorkTree(), HEADER_FILE_NAME);
GitTagsetHeader header = new GitTagsetHeader(name, description, new TreeSet<>());
String serializedHeader = new SerializationHelper<GitTagsetHeader>().serialize(header);
String revisionHash = localGitRepoManager.addAndCommit(targetHeaderFile, serializedHeader.getBytes(StandardCharsets.UTF_8), String.format("Added Tagset %1$s with ID %2$s", name, tagsetId), remoteGitServerManager.getUsername(), remoteGitServerManager.getEmail());
return revisionHash;
}
}
Aggregations