Search in sources :

Example 1 with NodeAlreadyExistAtPathException

use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.

the class MoveContentCommand method execute.

MoveContentsResult execute() {
    params.validate();
    try {
        final MoveContentsResult movedContents = doExecute();
        this.nodeService.refresh(RefreshMode.ALL);
        return movedContents;
    } catch (MoveNodeException e) {
        throw new MoveContentException(e.getMessage(), ContentPath.from(e.getPath().toString()));
    } catch (NodeAlreadyExistAtPathException e) {
        throw new ContentAlreadyExistsException(ContentPath.from(e.getNode().toString()), e.getRepositoryId(), e.getBranch());
    } catch (NodeAccessException e) {
        throw new ContentAccessException(e);
    }
}
Also used : MoveNodeException(com.enonic.xp.node.MoveNodeException) NodeAccessException(com.enonic.xp.node.NodeAccessException) MoveContentException(com.enonic.xp.content.MoveContentException) MoveContentsResult(com.enonic.xp.content.MoveContentsResult) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) ContentAccessException(com.enonic.xp.content.ContentAccessException)

Example 2 with NodeAlreadyExistAtPathException

use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.

the class CheckNodeExistsCommand method execute.

public boolean execute() {
    final InternalContext context = InternalContext.create(ContextAccessor.current()).searchPreference(Mode.ACCURACY.equals(mode) ? SearchPreference.PRIMARY : SearchPreference.LOCAL).build();
    if (Mode.ACCURACY.equals(mode)) {
        RefreshCommand.create().indexServiceInternal(this.indexServiceInternal).refreshMode(RefreshMode.STORAGE).build().execute();
    }
    final NodeId found = nodeStorageService.getIdForPath(nodePath, context);
    if (found != null && throwIfExists) {
        throw new NodeAlreadyExistAtPathException(nodePath, context.getRepositoryId(), context.getBranch());
    }
    return found != null;
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeId(com.enonic.xp.node.NodeId) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException)

Example 3 with NodeAlreadyExistAtPathException

use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.

the class SecurityServiceImpl method doCreateUser.

private User doCreateUser(final CreateUserParams createUser) {
    final User user = User.create().key(createUser.getKey()).login(createUser.getLogin()).email(createUser.getEmail()).displayName(createUser.getDisplayName()).modifiedTime(Instant.now(clock)).build();
    final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(user);
    try {
        final Node node = callWithContext(() -> {
            final Node createdNode = nodeService.create(createNodeParams);
            this.nodeService.refresh(RefreshMode.SEARCH);
            return createdNode;
        });
        if (createUser.getPassword() != null) {
            return setPassword(user.getKey(), createUser.getPassword());
        }
        return PrincipalNodeTranslator.userFromNode(node);
    } catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
        throw new PrincipalAlreadyExistsException(createUser.getKey());
    }
}
Also used : User(com.enonic.xp.security.User) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 4 with NodeAlreadyExistAtPathException

use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.

the class SecurityServiceImpl method createGroup.

@Override
public Group createGroup(final CreateGroupParams createGroup) {
    final Group group = Group.create().key(createGroup.getKey()).displayName(createGroup.getDisplayName()).modifiedTime(Instant.now(clock)).description(createGroup.getDescription()).build();
    final CreateNodeParams createGroupParams = PrincipalNodeTranslator.toCreateNodeParams(group);
    try {
        final Node node = callWithContext(() -> {
            final Node createdNode = this.nodeService.create(createGroupParams);
            this.nodeService.refresh(RefreshMode.SEARCH);
            return createdNode;
        });
        return PrincipalNodeTranslator.groupFromNode(node);
    } catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
        throw new PrincipalAlreadyExistsException(createGroup.getKey());
    }
}
Also used : Group(com.enonic.xp.security.Group) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 5 with NodeAlreadyExistAtPathException

use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.

the class SecurityServiceImpl method createRole.

@Override
public Role createRole(final CreateRoleParams createRole) {
    final Role role = Role.create().key(createRole.getKey()).displayName(createRole.getDisplayName()).modifiedTime(Instant.now(clock)).description(createRole.getDescription()).build();
    final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(role);
    try {
        final Node node = callWithContext(() -> {
            final Node createdNode = this.nodeService.create(createNodeParams);
            this.nodeService.refresh(RefreshMode.SEARCH);
            return createdNode;
        });
        return PrincipalNodeTranslator.roleFromNode(node);
    } catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
        throw new PrincipalAlreadyExistsException(createRole.getKey());
    }
}
Also used : Role(com.enonic.xp.security.Role) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Aggregations

NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)12 Node (com.enonic.xp.node.Node)9 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)8 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)4 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)3 PrincipalAlreadyExistsException (com.enonic.xp.security.PrincipalAlreadyExistsException)3 ContentAccessException (com.enonic.xp.content.ContentAccessException)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 IssueAlreadyExistsException (com.enonic.xp.issue.IssueAlreadyExistsException)2 NodeAccessException (com.enonic.xp.node.NodeAccessException)2 Test (org.junit.jupiter.api.Test)2 Branch (com.enonic.xp.branch.Branch)1 Content (com.enonic.xp.content.Content)1 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 CreateContentTranslatorParams (com.enonic.xp.content.CreateContentTranslatorParams)1 MoveContentException (com.enonic.xp.content.MoveContentException)1 MoveContentsResult (com.enonic.xp.content.MoveContentsResult)1 IssueName (com.enonic.xp.issue.IssueName)1 ApplyNodePermissionsParams (com.enonic.xp.node.ApplyNodePermissionsParams)1 MoveNodeException (com.enonic.xp.node.MoveNodeException)1