use of com.enonic.xp.node.NodePath in project xp by enonic.
the class BranchServiceImplTest method path_fetched_from_cache_after_stored.
@Test
public void path_fetched_from_cache_after_stored() throws Exception {
final InternalContext context = InternalContext.create().branch(Branch.from("myBranch")).repositoryId(RepositoryId.from("my-repo")).build();
final NodePath path = NodePath.create(NodePath.ROOT, "fisk").build();
Mockito.when(this.storageDao.store(Mockito.isA(StoreRequest.class))).thenReturn("123_myBranch");
this.branchService.store(NodeBranchEntry.create().nodeId(NodeId.from("123")).nodePath(path).nodeState(NodeState.DEFAULT).nodeVersionId(NodeVersionId.from("nodeVersionId")).nodeVersionKey(NodeVersionKey.from("nodeBlobKey", "indexConfigBlobKey", "accessControlBlobKey")).timestamp(Instant.now()).build(), context);
Mockito.when(this.storageDao.getById(Mockito.isA(GetByIdRequest.class))).thenReturn(GetResult.create().id("123_myBranch").resultFieldValues(ReturnValues.create().add(BranchIndexPath.PATH.getPath(), "/fisk").add(BranchIndexPath.STATE.getPath(), "default").add(BranchIndexPath.VERSION_ID.getPath(), "nodeVersionId").add(BranchIndexPath.NODE_BLOB_KEY.getPath(), "nodeBlobKey").add(BranchIndexPath.INDEX_CONFIG_BLOB_KEY.getPath(), "indexConfigBlobKey").add(BranchIndexPath.ACCESS_CONTROL_BLOB_KEY.getPath(), "accessControlBlobKey").add(BranchIndexPath.NODE_ID.getPath(), "123").add(BranchIndexPath.TIMESTAMP.getPath(), Instant.now().toString()).build()).build());
Mockito.when(this.searchDao.search(Mockito.isA(SearchRequest.class))).thenReturn(SearchResult.create().build());
final NodeBranchEntry fetchEntry = this.branchService.get(path, context);
assertNotNull(fetchEntry);
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class SecurityServiceImpl method getIdProvider.
@Override
public IdProvider getIdProvider(final IdProviderKey idProviderKey) {
final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(idProviderKey);
final Node node = callWithContext(() -> this.nodeService.getByPath(idProviderNodePath));
return node == null ? null : IdProviderNodeTranslator.fromNode(node);
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class SecurityServiceImpl method getIdProviderPermissions.
@Override
public IdProviderAccessControlList getIdProviderPermissions(final IdProviderKey idProviderKey) {
final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(idProviderKey);
final NodePath usersNodePath = IdProviderNodeTranslator.toIdProviderUsersNodePath(idProviderKey);
final NodePath groupsNodePath = IdProviderNodeTranslator.toIdProviderGroupsNodePath(idProviderKey);
final Node idProviderNode = callWithContext(() -> this.nodeService.getByPath(idProviderNodePath));
final Node usersNode = callWithContext(() -> this.nodeService.getByPath(usersNodePath));
final Node groupsNode = callWithContext(() -> this.nodeService.getByPath(groupsNodePath));
return IdProviderNodeTranslator.idProviderPermissionsFromNode(idProviderNode, usersNode, groupsNode);
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class SecurityServiceImpl method updateIdProvider.
@Override
public IdProvider updateIdProvider(final UpdateIdProviderParams updateIdProviderParams) {
return callWithContext(() -> {
final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(updateIdProviderParams.getKey());
final Node node = this.nodeService.getByPath(idProviderNodePath);
if (node == null) {
return null;
}
final IdProvider existingIdProvider = IdProviderNodeTranslator.fromNode(node);
final IdProvider idProviderToUpdate = updateIdProviderParams.update(existingIdProvider);
final UpdateNodeParams updateNodeParams = IdProviderNodeTranslator.toUpdateNodeParams(idProviderToUpdate, node.id());
final Node idProviderNode = nodeService.update(updateNodeParams);
if (updateIdProviderParams.getIdProviderPermissions() != null) {
final Node usersNode = nodeService.getByPath(IdProviderNodeTranslator.toIdProviderUsersNodePath(updateIdProviderParams.getKey()));
final Node groupsNode = nodeService.getByPath(IdProviderNodeTranslator.toIdProviderGroupsNodePath(updateIdProviderParams.getKey()));
final IdProviderAccessControlList permissions = updateIdProviderParams.getIdProviderPermissions();
AccessControlList idProviderNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToIdProviderNodePermissions(permissions);
AccessControlList usersNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToUsersNodePermissions(permissions);
AccessControlList groupsNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToGroupsNodePermissions(permissions);
final Node rootNode = nodeService.getRoot();
idProviderNodePermissions = mergeWithRootPermissions(idProviderNodePermissions, rootNode.getPermissions());
usersNodePermissions = mergeWithRootPermissions(usersNodePermissions, rootNode.getPermissions());
groupsNodePermissions = mergeWithRootPermissions(groupsNodePermissions, rootNode.getPermissions());
setNodePermissions(idProviderNode.id(), idProviderNodePermissions);
setNodePermissions(usersNode.id(), usersNodePermissions);
setNodePermissions(groupsNode.id(), groupsNodePermissions);
final ApplyNodePermissionsParams applyPermissions = ApplyNodePermissionsParams.create().nodeId(idProviderNode.id()).overwriteChildPermissions(false).build();
nodeService.applyPermissions(applyPermissions);
}
this.nodeService.refresh(RefreshMode.SEARCH);
return IdProviderNodeTranslator.fromNode(idProviderNode);
});
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class SecurityServiceImpl method removeRelationships.
private void removeRelationships(final IdProviderKey from) {
callWithContext(() -> {
final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(from);
final Node node = this.nodeService.getByPath(idProviderNodePath);
final UpdateNodeParams updateNodeParams = IdProviderNodeTranslator.removeAllRelationshipsToUpdateNodeParams(node);
nodeService.update(updateNodeParams);
this.nodeService.refresh(RefreshMode.SEARCH);
return null;
});
}
Aggregations