Search in sources :

Example 1 with Reference

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());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) BinaryReference(com.enonic.xp.util.BinaryReference) Reference(com.enonic.xp.util.Reference) Instant(java.time.Instant) BinaryReference(com.enonic.xp.util.BinaryReference) LocalDate(java.time.LocalDate) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Date(java.util.Date) LocalDate(java.time.LocalDate) GeoPoint(com.enonic.xp.util.GeoPoint) Link(com.enonic.xp.util.Link)

Example 2 with Reference

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();
}
Also used : Reference(com.enonic.xp.util.Reference) PageUrlParams(com.enonic.xp.portal.url.PageUrlParams) Property(com.enonic.xp.data.Property)

Example 3 with Reference

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);
}
Also used : Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) NodeId(com.enonic.xp.node.NodeId) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 4 with Reference

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"));
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) DumpUpgradeStepResult(com.enonic.xp.dump.DumpUpgradeStepResult) Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) Collection(java.util.Collection) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) Test(org.junit.jupiter.api.Test)

Example 5 with Reference

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());
}
Also used : IndexDocument(com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument) Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) IndexValueString(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValueString) IndexItems(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItems) IndexValue(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValue) Test(org.junit.jupiter.api.Test)

Aggregations

Reference (com.enonic.xp.util.Reference)12 PropertyTree (com.enonic.xp.data.PropertyTree)7 Test (org.junit.jupiter.api.Test)5 PropertySet (com.enonic.xp.data.PropertySet)4 Node (com.enonic.xp.node.Node)4 BinaryReference (com.enonic.xp.util.BinaryReference)3 Property (com.enonic.xp.data.Property)2 Content (com.enonic.xp.content.Content)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ValueTypes (com.enonic.xp.data.ValueTypes)1 DumpUpgradeStepResult (com.enonic.xp.dump.DumpUpgradeStepResult)1 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)1 PublishRequestItem (com.enonic.xp.issue.PublishRequestItem)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 DuplicateNodeParams (com.enonic.xp.node.DuplicateNodeParams)1 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)1 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1