use of com.enonic.xp.node.EditableNode in project xp by enonic.
the class ModifyNodeExecutorTest method update_child_order.
@Test
public void update_child_order() throws Exception {
final Node originalNode = Node.create().name("myNode").childOrder(ChildOrder.manualOrder()).parentPath(NodePath.ROOT).build();
final EditableNode editableNode = new EditableNode(originalNode);
final PropertyTree updateScript = new PropertyTree();
updateScript.setString("_childOrder", ChildOrder.reverseManualOrder().toString());
ModifyNodeExecutor.create().editableNode(editableNode).propertyTree(updateScript).build().execute();
assertEquals(ChildOrder.reverseManualOrder(), editableNode.childOrder);
}
use of com.enonic.xp.node.EditableNode in project xp by enonic.
the class ModifyNodeHandlerTest method testExample.
@Test
public void testExample() {
final PropertyTree data = new PropertyTree();
data.setString("notChanged", "originalValue");
data.setString("myString", "originalValue");
data.setString("toBeRemoved", "removeThis");
final PropertySet mySet = data.addSet("mySet");
mySet.setGeoPoint("myGeoPoint", new GeoPoint(30, -30));
final Node node = Node.create().id(NodeId.from("abc")).parentPath(NodePath.ROOT).data(data).name("myNode").build();
mockGetNode(node);
mockUpdateNode(node);
runScript("/lib/xp/examples/node/modify.js");
Mockito.verify(this.nodeService).update(updateCaptor.capture());
assertEquals(updateCaptor.getValue().getId(), NodeId.from("abc"));
final EditableNode editedNode = getEditedNode(node);
assertEquals("modified", editedNode.data.getString("myString"));
assertEquals("originalValue", editedNode.data.getString("notChanged"));
assertEquals(new GeoPoint(0, 0), editedNode.data.getGeoPoint("mySet.myGeoPoint"));
final Iterable<String> myArray = editedNode.data.getStrings("myArray");
assertNotNull(myArray);
final ArrayList<String> myArrayValues = Lists.newArrayList(myArray);
assertEquals(3, myArrayValues.size());
assertTrue(myArrayValues.containsAll(List.of("modified1", "modified2", "modified3")));
final AccessControlList permissions = editedNode.permissions;
assertTrue(permissions.getEntry(PrincipalKey.from("role:newRole")).isAllowed(Permission.MODIFY));
assertTrue(permissions.getEntry(PrincipalKey.from("user:system:newUser")).isAllowed(Permission.CREATE));
final IndexConfigDocument indexConfigDocument = editedNode.indexConfigDocument;
assertFalse(indexConfigDocument.getConfigForPath(PropertyPath.from("displayName")).isEnabled());
assertTrue(indexConfigDocument.getConfigForPath(PropertyPath.from("whatever")).isFulltext());
}
use of com.enonic.xp.node.EditableNode in project xp by enonic.
the class ModifyNodeHandlerTest method keep_original_value_types_when_not_touched.
@Test
public void keep_original_value_types_when_not_touched() {
final PropertyTree data = new PropertyTree();
data.setString("myString", "originalValue");
data.setString("untouchedString", "originalValue");
data.setBoolean("untouchedBoolean", true);
data.setDouble("untouchedDouble", 2.0);
data.setLong("untouchedLong", 2L);
data.setLink("untouchedLink", Link.from("myLink"));
data.setInstant("untouchedInstant", Instant.parse("2017-01-02T10:00:00Z"));
data.setBinaryReference("untouchedBinaryRef", BinaryReference.from("abcd"));
data.setGeoPoint("untouchedGeoPoint", GeoPoint.from("30,-30"));
data.setLocalDate("untouchedLocalDate", LocalDate.parse("2017-03-24"));
data.setReference("untouchedReference", Reference.from("myReference"));
final Node node = Node.create().id(NodeId.from("abc")).parentPath(NodePath.ROOT).data(data).name("myNode").build();
mockGetNode(node);
mockUpdateNode(node);
runScript("/lib/xp/examples/node/modify-keep-types.js");
Mockito.verify(this.nodeService).update(updateCaptor.capture());
assertEquals(updateCaptor.getValue().getId(), NodeId.from("abc"));
final EditableNode editedNode = getEditedNode(node);
assertEquals("modifiedValue", editedNode.data.getString("myString"));
// Validate that properties not changed keeps original type
assertTrue(editedNode.data.getProperty("untouchedString").getType().equals(ValueTypes.STRING));
assertTrue(editedNode.data.getProperty("untouchedBoolean").getType().equals(ValueTypes.BOOLEAN));
assertTrue(editedNode.data.getProperty("untouchedDouble").getType().equals(ValueTypes.DOUBLE));
assertTrue(editedNode.data.getProperty("untouchedLong").getType().equals(ValueTypes.LONG));
assertTrue(editedNode.data.getProperty("untouchedLink").getType().equals(ValueTypes.LINK));
assertTrue(editedNode.data.getProperty("untouchedInstant").getType().equals(ValueTypes.DATE_TIME));
assertTrue(editedNode.data.getProperty("untouchedGeoPoint").getType().equals(ValueTypes.GEO_POINT));
assertTrue(editedNode.data.getProperty("untouchedLocalDate").getType().equals(ValueTypes.LOCAL_DATE));
assertTrue(editedNode.data.getProperty("untouchedReference").getType().equals(ValueTypes.REFERENCE));
assertTrue(editedNode.data.getProperty("untouchedBinaryRef").getType().equals(ValueTypes.BINARY_REFERENCE));
}
use of com.enonic.xp.node.EditableNode in project xp by enonic.
the class UpdateNodeCommand method doExecute.
private Node doExecute() {
final Node persistedNode = getPersistedNode();
requireContextUserPermissionOrAdmin(Permission.MODIFY, persistedNode);
final EditableNode editableNode = new EditableNode(persistedNode);
params.getEditor().edit(editableNode);
if (editableNode.inheritPermissions != persistedNode.inheritsPermissions() || !persistedNode.getPermissions().equals(editableNode.permissions)) {
requireContextUserPermissionOrAdmin(Permission.WRITE_PERMISSIONS, persistedNode);
}
final AttachedBinaries updatedBinaries = UpdatedAttachedBinariesResolver.create().editableNode(editableNode).persistedNode(persistedNode).binaryAttachments(this.params.getBinaryAttachments()).binaryService(this.binaryService).build().resolve();
final Node editedNode = editableNode.build();
if (editedNode.equals(persistedNode) && updatedBinaries.equals(persistedNode.getAttachedBinaries())) {
return persistedNode;
}
final Node updatedNode = createUpdatedNode(Node.create(editedNode).timestamp(Instant.now(CLOCK)).attachedBinaries(updatedBinaries).build());
if (!this.params.isDryRun()) {
StoreNodeCommand.create(this).node(updatedNode).build().execute();
}
return updatedNode;
}
use of com.enonic.xp.node.EditableNode in project xp by enonic.
the class UpdateLastRunCommandTest method testCreateJob.
@Test
public void testCreateJob() throws Exception {
final TaskId lastTaskId = TaskId.from("task-id");
final Instant lastRun = Instant.parse("2021-02-25T10:44:33.170079900Z");
final Node node = mockNode();
when(nodeService.update(isA(UpdateNodeParams.class))).thenReturn(node);
UpdateLastRunCommand.create().name(ScheduledJobName.from("job")).lastTaskId(lastTaskId).lastRun(lastRun).nodeService(nodeService).build().execute();
verify(nodeService).update(captor.capture());
final EditableNode editableNode = new EditableNode(node);
captor.getValue().getEditor().edit(editableNode);
assertEquals(lastRun, editableNode.data.getProperty(ScheduledJobPropertyNames.LAST_RUN).getInstant());
assertEquals(lastTaskId.toString(), editableNode.data.getProperty(ScheduledJobPropertyNames.LAST_TASK_ID).getString());
}
Aggregations