use of com.enonic.xp.data.Value in project xp by enonic.
the class FindNodesByQueryCommandTest method query_instant_different_field_name_case.
@Test
public void query_instant_different_field_name_case() throws Exception {
final Instant BASE_INSTANT = Instant.parse("2000-01-01T00:00:00.00Z");
final PropertyTree data13 = new PropertyTree();
data13.addInstant("myProperty", BASE_INSTANT.plus(10, ChronoUnit.DAYS));
final PropertyTree data2 = new PropertyTree();
data2.addInstant("myProperty", BASE_INSTANT.plus(20, ChronoUnit.DAYS));
final Node node1 = createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).data(data13).build());
final Node node2 = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).data(data2).build());
final Node node3 = createNode(CreateNodeParams.create().name("child-node").parent(node1.path()).data(data13).build());
final Value from = ValueFactory.newDateTime(BASE_INSTANT);
final Value to = ValueFactory.newDateTime(BASE_INSTANT.plus(15, ChronoUnit.DAYS));
final QueryExpr queryExpr = QueryExpr.from(CompareExpr.eq(FieldExpr.from("MYProperty"), ValueExpr.instant(BASE_INSTANT.plus(10, ChronoUnit.DAYS).toString())));
final NodeQuery query = NodeQuery.create().query(queryExpr).addPostFilter(RangeFilter.create().fieldName("MYProperty").from(from).to(to).build()).build();
final FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(2, result.getNodeIds().getSize());
assertTrue(result.getNodeIds().contains(node1.id()));
assertTrue(result.getNodeIds().contains(node3.id()));
assertFalse(result.getNodeIds().contains(node2.id()));
}
use of com.enonic.xp.data.Value in project xp by enonic.
the class FormDefaultValuesProcessorImpl method processFormItems.
private void processFormItems(final Iterable<FormItem> formItems, final PropertySet dataSet) {
StreamSupport.stream(formItems.spliterator(), false).forEach(formItem -> {
if (formItem.getType() == INPUT) {
Input input = formItem.toInput();
if (input.getDefaultValue() != null) {
try {
final Value defaultValue = InputTypes.BUILTIN.resolve(input.getInputType()).createDefaultValue(input);
final PropertyPath propertyPath = PropertyPath.from(input.getName());
if (defaultValue != null && dataSet.getProperty(propertyPath) == null) {
if (input.getOccurrences().getMinimum() > 0) {
for (int i = 0; i < input.getOccurrences().getMinimum(); i++) {
dataSet.setProperty(input.getName(), i, defaultValue);
}
} else {
dataSet.setProperty(input.getName(), defaultValue);
}
}
} catch (IllegalArgumentException ex) {
LOG.warn("Invalid default value for " + input.getInputType() + " input type with name '" + input.getName() + "': '" + input.getDefaultValue().getRootValue() + "'" + (ex.getMessage() == null ? "" : " - " + ex.getMessage()));
}
}
} else if (formItem.getType() == FORM_ITEM_SET) {
processFormItems(formItem.getName(), formItem.toFormItemSet().getFormItems(), dataSet, formItem.toFormItemSet().getOccurrences().getMinimum());
} else if (formItem.getType() == LAYOUT && formItem.toLayout() instanceof FieldSet) {
processFormItems((FieldSet) formItem.toLayout(), dataSet);
} else if (formItem.getType() == FORM_OPTION_SET_OPTION) {
FormOptionSetOption option = formItem.toFormOptionSetOption();
if (option.isDefaultOption()) {
dataSet.setProperty("_selected", ValueFactory.newString(formItem.getName()));
if (dataSet.getProperty(formItem.getName()) == null) {
Property property = dataSet.setProperty(formItem.getName(), ValueFactory.newPropertySet(new PropertySet()));
processFormItems(option.getFormItems(), property.getSet());
}
}
} else if (formItem.getType() == FORM_OPTION_SET) {
processFormItems(formItem.getName(), formItem.toFormOptionSet().getFormItems(), dataSet, formItem.toFormOptionSet().getOccurrences().getMinimum());
}
});
}
Aggregations