use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class RenameNodeCommandTest method rename_then_create_with_same_name.
@Test
public void rename_then_create_with_same_name() throws Exception {
final CreateNodeParams createNodeNamedMyNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
final Node createdNode = createNode(createNodeNamedMyNodeParams);
RenameNodeCommand.create().params(RenameNodeParams.create().nodeId(createdNode.id()).nodeName(NodeName.from("my-node-edited")).build()).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
createNode(createNodeNamedMyNodeParams);
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class NodeVersionServiceImplTest method getVersions.
@Test
public void getVersions() throws Exception {
final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
final PropertyTree data = new PropertyTree();
data.addString("myName", "myValue");
final CreateNodeParams createNodeParams2 = CreateNodeParams.create().name("my-node2").parent(NodePath.ROOT).data(data).build();
final Node createdNode = createNode(createNodeParams);
final Node createdNode2 = createNode(createNodeParams2);
final NodeVersions nodeVersions = nodeDao.get(NodeVersionKeys.from(getNodeVersionKey(createdNode), getNodeVersionKey(createdNode2)), createInternalContext());
assertEquals(2, nodeVersions.getSize());
assertEquals(createdNode.id(), nodeVersions.get(0).getId());
assertEquals(createdNode.data(), nodeVersions.get(0).getData());
assertEquals(createdNode2.id(), nodeVersions.get(1).getId());
assertEquals(createdNode2.data(), nodeVersions.get(1).getData());
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class AbstractNodeTest method createNode.
protected Node createNode(final CreateNodeParams createNodeParams, final boolean refresh) {
final CreateNodeParams.Builder createParamsWithAnalyzer = CreateNodeParams.create(createNodeParams);
if (createNodeParams.getIndexConfigDocument() == null) {
createParamsWithAnalyzer.indexConfigDocument(PatternIndexConfigDocument.create().analyzer(ContentConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER).build());
}
final Node createdNode = CreateNodeCommand.create().indexServiceInternal(this.indexServiceInternal).binaryService(this.binaryService).storageService(this.storageService).searchService(this.searchService).params(createParamsWithAnalyzer.build()).build().execute();
if (refresh) {
refresh();
}
return createdNode;
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class PrincipalNodeTranslator method toCreateNodeParams.
public static CreateNodeParams toCreateNodeParams(final Principal principal) {
Preconditions.checkNotNull(principal);
final CreateNodeParams.Builder builder = CreateNodeParams.create().name(PrincipalKeyNodeTranslator.toNodeName(principal.getKey()).toString()).parent(principal.getKey().toPath().getParentPath()).setNodeId(NodeId.from(principal.getKey().toString().toLowerCase())).inheritPermissions(true).indexConfigDocument(PrincipalIndexConfigFactory.create());
final PropertyTree data = new PropertyTree();
data.setString(PrincipalPropertyNames.DISPLAY_NAME_KEY, principal.getDisplayName());
data.setString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY, principal.getKey().getType().toString());
if (!principal.getKey().isRole()) {
data.setString(PrincipalPropertyNames.ID_PROVIDER_KEY, principal.getKey().getIdProviderKey().toString());
}
switch(principal.getKey().getType()) {
case USER:
populateUserData(data.getRoot(), (User) principal);
break;
case ROLE:
populateRoleData(data.getRoot(), (Role) principal);
break;
case GROUP:
populateGroupData(data.getRoot(), (Group) principal);
break;
}
builder.data(data);
return builder.build();
}
use of com.enonic.xp.node.CreateNodeParams 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());
}
}
Aggregations