use of com.enonic.xp.branch.Branch in project xp by enonic.
the class RepositoryServiceImpl method doCreateBranch.
private Repository doCreateBranch(final CreateBranchParams createBranchParams, final RepositoryId repositoryId, Repository previousRepository) {
// If the repository entry does not exist, throws an exception
previousRepository = previousRepository == null ? repositoryEntryService.getRepositoryEntry(repositoryId) : previousRepository;
if (previousRepository == null) {
throw new RepositoryNotFoundException(repositoryId);
}
// If the branch already exists, throws an exception
final Branch newBranch = createBranchParams.getBranch();
if (previousRepository.getBranches().contains(newBranch)) {
throw new BranchAlreadyExistException(newBranch);
}
// If the root node does not exist, creates it
if (getRootNode(previousRepository.getId(), newBranch) == null) {
pushRootNode(previousRepository, newBranch);
RefreshCommand.create().indexServiceInternal(this.indexServiceInternal).refreshMode(RefreshMode.ALL).build().execute();
}
// Updates the repository entry
return repositoryEntryService.addBranchToRepositoryEntry(repositoryId, newBranch);
}
use of com.enonic.xp.branch.Branch in project xp by enonic.
the class VersionTableVacuumCommand method findVersionsInBranches.
private BRANCH_CHECK_RESULT findVersionsInBranches(final Repository repository, final NodeVersionMetadata versionMetadata) {
final NodeId nodeId = versionMetadata.getNodeId();
final NodeVersionId versionId = versionMetadata.getNodeVersionId();
boolean nodeFound = false;
for (final Branch branch : repository.getBranches()) {
try {
final Node node = ContextBuilder.from(ContextAccessor.current()).branch(branch).repositoryId(repository.getId()).build().callWith(() -> this.nodeService.getById(nodeId));
if (versionId.equals(node.getNodeVersionId())) {
return BRANCH_CHECK_RESULT.SAME_VERSION_FOUND;
}
nodeFound = true;
} catch (NodeNotFoundException e) {
// Ignore
}
}
return nodeFound ? BRANCH_CHECK_RESULT.OTHER_VERSION_FOUND : BRANCH_CHECK_RESULT.NO_VERSION_FOUND;
}
use of com.enonic.xp.branch.Branch in project xp by enonic.
the class DumpServiceImplTest method active_versions_in_versions_list.
@Test
public void active_versions_in_versions_list() throws Exception {
final Node node = createNode(NodePath.ROOT, "myNode");
this.nodeService.push(NodeIds.from(node.id()), WS_OTHER);
updateNode(node);
refresh();
NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
refresh();
final GetActiveNodeVersionsResult activeVersions = this.nodeService.getActiveVersions(GetActiveNodeVersionsParams.create().branches(Branches.from(WS_DEFAULT, WS_OTHER)).nodeId(node.id()).build());
final ImmutableMap<Branch, NodeVersionMetadata> activeVersionsMap = activeVersions.getNodeVersions();
final NodeVersionQueryResult versionsAfterLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
activeVersionsMap.values().forEach(key -> assertTrue(versionsAfterLoad.getNodeVersionsMetadata().getAllVersionIds().contains(key.getNodeVersionId())));
}
use of com.enonic.xp.branch.Branch in project xp by enonic.
the class DumpServiceImplTest method active_versions_after_load.
@Test
public void active_versions_after_load() throws Exception {
final Node node = createNode(NodePath.ROOT, "myNode");
this.nodeService.push(NodeIds.from(node.id()), WS_OTHER);
updateNode(node);
refresh();
NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
refresh();
final GetActiveNodeVersionsResult activeVersions = this.nodeService.getActiveVersions(GetActiveNodeVersionsParams.create().branches(Branches.from(WS_DEFAULT, WS_OTHER)).nodeId(node.id()).build());
final Node defaultBranchNode = ctxDefault().callWith(() -> this.nodeService.getById(node.id()));
final Node otherBranchNode = ctxOther().callWith(() -> this.nodeService.getById(node.id()));
final ImmutableMap<Branch, NodeVersionMetadata> activeVersionsMap = activeVersions.getNodeVersions();
assertEquals(2, activeVersionsMap.size());
assertEquals(defaultBranchNode.getNodeVersionId(), activeVersionsMap.get(WS_DEFAULT).getNodeVersionId());
assertEquals(otherBranchNode.getNodeVersionId(), activeVersionsMap.get(WS_OTHER).getNodeVersionId());
}
use of com.enonic.xp.branch.Branch in project xp by enonic.
the class BranchAclEntryTest method not_equals.
@Test
public void not_equals() throws Exception {
final Branch branch = Branch.from("fisk");
final BranchAclEntry entry1 = new BranchAclEntry(branch, PrincipalKeys.from(PrincipalKey.ofRole("fisk")));
final BranchAclEntry entry2 = new BranchAclEntry(branch, PrincipalKeys.from(PrincipalKey.ofRole("ost")));
assertNotEquals(entry1, entry2);
}
Aggregations