use of com.enonic.xp.node.CreateNodeParams 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());
}
}
use of com.enonic.xp.node.CreateNodeParams 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());
}
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class UserNodeTranslatorTest method toCreateNode.
@Test
public void toCreateNode() throws Exception {
final User user = User.create().displayName("displayname").email("rmy@enonic.com").login("login").authenticationHash("password").key(PrincipalKey.ofUser(IdProviderKey.system(), "rmy")).modifiedTime(Instant.now(clock)).build();
final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(user);
assertEquals("rmy", createNodeParams.getName());
final PropertyTree rootDataSet = createNodeParams.getData();
assertEquals(IdProviderKey.system().toString(), rootDataSet.getString(PrincipalPropertyNames.ID_PROVIDER_KEY));
assertEquals(PrincipalType.USER.toString(), rootDataSet.getString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY));
assertEquals("displayname", rootDataSet.getString(PrincipalPropertyNames.DISPLAY_NAME_KEY));
assertNotNull(rootDataSet);
assertEquals(7, rootDataSet.getTotalSize());
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class ContentImportValidator method ensureValid.
@Override
public CreateNodeParams ensureValid(final CreateNodeParams original) {
final CreateNodeParams.Builder builder = CreateNodeParams.create(original);
final PropertyTree updatedData = original.getData();
validateChildOrder(original, builder);
builder.data(updatedData);
return builder.build();
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class DuplicateNodeCommand method execute.
public DuplicateNodeResult execute() {
final Node existingNode = doGetById(params.getNodeId());
if (existingNode == null) {
throw new NodeNotFoundException("Cannot duplicate node with id [" + params.getNodeId() + "]");
}
if (existingNode.isRoot()) {
throw new OperationNotPermittedException("Not allowed to duplicate root-node");
}
final CreateNodeParams.Builder createNodeParams = CreateNodeParams.from(existingNode);
attachBinaries(existingNode, createNodeParams);
Node duplicatedNode = null;
String newNodeName = existingNode.name().toString();
do {
try {
newNodeName = DuplicateValueResolver.name(newNodeName);
final CreateNodeParams processedParams = executeProcessors(createNodeParams.name(newNodeName).build());
duplicatedNode = CreateNodeCommand.create(this).params(processedParams).binaryService(binaryService).build().execute();
} catch (NodeAlreadyExistAtPathException e) {
// try again with other name
LOG.debug(String.format("[%s] node with [%s] parent already exist.", newNodeName, existingNode.parentPath().toString()), e);
}
} while (duplicatedNode == null);
result.node(duplicatedNode);
nodeDuplicated(1);
final NodeReferenceUpdatesHolder.Builder builder = NodeReferenceUpdatesHolder.create().add(existingNode.id(), duplicatedNode.id());
if (params.getIncludeChildren()) {
storeChildNodes(existingNode, duplicatedNode, builder);
}
final NodeReferenceUpdatesHolder nodesToBeUpdated = builder.build();
RefreshCommand.create().refreshMode(RefreshMode.SEARCH).indexServiceInternal(this.indexServiceInternal).build().execute();
updateNodeReferences(duplicatedNode, nodesToBeUpdated);
updateChildReferences(duplicatedNode, nodesToBeUpdated);
return result.build();
}
Aggregations