use of com.enonic.xp.util.Reference in project xp by enonic.
the class ScriptValueTranslator method handleValue.
private void handleValue(final PropertySet parent, final String name, final Object value) {
if (value instanceof Instant) {
parent.addInstant(name, (Instant) value);
} else if (value instanceof GeoPoint) {
parent.addGeoPoint(name, (GeoPoint) value);
} else if (value instanceof Double) {
parent.addDouble(name, (Double) value);
} else if (value instanceof Float) {
parent.addDouble(name, ((Float) value).doubleValue());
} else if (value instanceof Integer) {
parent.addLong(name, ((Integer) value).longValue());
} else if (value instanceof Byte) {
parent.addLong(name, ((Byte) value).longValue());
} else if (value instanceof Long) {
parent.addLong(name, ((Long) value));
} else if (value instanceof Number) {
parent.addDouble(name, ((Number) value).doubleValue());
} else if (value instanceof Boolean) {
parent.addBoolean(name, (Boolean) value);
} else if (value instanceof LocalDateTime) {
parent.addLocalDateTime(name, (LocalDateTime) value);
} else if (value instanceof LocalDate) {
parent.addLocalDate(name, (LocalDate) value);
} else if (value instanceof LocalTime) {
parent.addLocalTime(name, (LocalTime) value);
} else if (value instanceof Date) {
parent.addInstant(name, ((Date) value).toInstant());
} else if (value instanceof Reference) {
parent.addReference(name, (Reference) value);
} else if (value instanceof BinaryReference) {
parent.addBinaryReference(name, (BinaryReference) value);
} else if (value instanceof Link) {
parent.addLink(name, (Link) value);
} else if (value instanceof BinaryAttachment) {
final BinaryAttachment binaryAttachment = (BinaryAttachment) value;
parent.addBinaryReference(name, binaryAttachment.getReference());
if (includeBinaryAttachments) {
this.binaryAttachmentsBuilder.add(new BinaryAttachment(binaryAttachment.getReference(), binaryAttachment.getByteSource()));
}
} else {
parent.addString(name, value.toString());
}
}
use of com.enonic.xp.util.Reference in project xp by enonic.
the class PageHandlerWorker method renderShortcut.
private PortalResponse renderShortcut(final Content content) {
final Property shortcut = content.getData().getProperty(SHORTCUT_TARGET_PROPERTY);
final Reference target = shortcut == null ? null : shortcut.getReference();
if (target == null || target.getNodeId() == null) {
throw WebException.notFound("Missing shortcut target");
}
final PageUrlParams pageUrlParams = new PageUrlParams().id(target.toString()).portalRequest(this.request);
final Multimap<String, String> params = pageUrlParams.getParams();
params.putAll(this.request.getParams());
params.putAll(getShortcutParameters(content));
final String targetUrl = this.portalUrlService.pageUrl(pageUrlParams);
return PortalResponse.create().status(HttpStatus.TEMPORARY_REDIRECT).header("Location", targetUrl).build();
}
use of com.enonic.xp.util.Reference in project xp by enonic.
the class InputValidatorTest method validate_correct_input_types.
@Test
public void validate_correct_input_types() {
// Creates a property set
final PropertySet propertySet = new PropertySet();
propertySet.addString("setString", "ost");
propertySet.addDouble("setDouble", 123d);
// Creates the correct data to validate
final PropertyTree data = new PropertyTree();
data.addString("textLine", "textLine");
data.addString("color", "#12345");
data.addString("comboBox", "value2");
data.addBoolean("checkbox", true);
data.addString("phone", "+4797773223");
data.addString("tag", "myTag");
data.addReference("contentSelector", new Reference(new NodeId()));
data.addString("contentTypeFilter", "article");
data.addString("siteConfigurator", "my config here");
data.addDouble("double", 1.1d);
data.addLong("long", 12345678910L);
data.addStrings("stringArray", "a", "b", "c");
data.addLocalDateTime("localDateTime", LocalDateTime.parse("2015-01-14T10:00:00"));
data.addInstant("dateTime", DateTimeFormatter.ISO_DATE_TIME.parse("2015-01-15T10:15:00+02:00", Instant::from));
data.addLocalDate("date", LocalDate.parse("2015-01-15"));
data.addLocalTime("time", LocalTime.parse("10:00:32.123"));
data.addGeoPoint("geoPoint", GeoPoint.from("-45,34"));
data.addString("htmlArea", "<stuff>staff</stuff>");
// Validates the correct data
inputValidator.validate(data);
}
use of com.enonic.xp.util.Reference in project xp by enonic.
the class HtmlAreaNodeDataUpgraderTest method testUpgrade.
@Test
public void testUpgrade() throws IOException {
final PropertyTree data = new PropertyTree();
data.setString("data.htmlarea", readTestResource("htmlarea-source.xml"));
final NodeVersion nodeVersion = NodeVersion.create().nodeType(ContentConstants.CONTENT_NODE_COLLECTION).data(data).build();
final PatternIndexConfigDocument indexConfigDocument = createIndexConfigDocument();
final DumpUpgradeStepResult.Builder result = DumpUpgradeStepResult.create();
final boolean upgraded = htmlAreaNodeDataUpgrader.upgrade(nodeVersion, indexConfigDocument, result);
assertTrue(upgraded);
final PropertyTree upgradedData = nodeVersion.getData();
final Collection<Reference> upgradedProcessedReferences = (Collection<Reference>) upgradedData.getReferences("processedReferences");
assertEquals(5, upgradedProcessedReferences.size());
final List<Reference> expectedReferences = Arrays.stream(new String[] { "e1f57280-d672-4cd8-b674-98e26e5b69ae", "be1ca151-cf61-4a54-9ea4-c8d01ce83e0e", "81b1e3cd-575f-4565-a618-3c85d56224f6", "43d54e23-d8ce-4058-befb-777abe1a0d9f", "32169e70-49e1-444c-a6ac-d38f22438134" }).map(Reference::from).collect(Collectors.toList());
assertTrue(expectedReferences.containsAll(upgradedProcessedReferences));
assertEquals(readTestResource("htmlarea-expected.xml"), upgradedData.getString("data.htmlarea"));
}
use of com.enonic.xp.util.Reference in project xp by enonic.
the class NodeStoreDocumentFactoryTest method references.
@Test
public void references() throws Exception {
final PropertyTree data = new PropertyTree();
data.addReference("myRef", new Reference(NodeId.from("otherNode")));
final Node node = Node.create().id(NodeId.from("myNodeId")).parentPath(NodePath.ROOT).name("myNode").data(data).build();
final Collection<IndexDocument> indexDocuments = NodeStoreDocumentFactory.createBuilder().node(node).branch(Branch.from("myBranch")).repositoryId(RepositoryId.from("my-repo")).build().create();
assertEquals(1, indexDocuments.size());
final IndexDocument indexDocument = indexDocuments.iterator().next();
final IndexItems indexItems = indexDocument.getIndexItems();
final Collection<IndexValue> referenceValues = indexItems.get(NodeIndexPath.REFERENCE.getPath());
assertEquals(1, referenceValues.size());
final IndexValue next = referenceValues.iterator().next();
assertTrue(next instanceof IndexValueString);
final IndexValueString referenceValue = (IndexValueString) next;
assertEquals("otherNode", referenceValue.getValue());
}
Aggregations