Search in sources :

Example 56 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class HtmlStripperTest method cornerCases.

@Test
void cornerCases() {
    Value valueToProcess = ValueFactory.newString("<span>Test</span> <a about=\">\" href=\"#\">valid html</a>");
    assertEquals(ValueFactory.newString("Test valid html"), this.htmlStripper.process(valueToProcess));
    valueToProcess = ValueFactory.newString("Hey<p>I&apos;m so <b>happy</b>!</p>");
    assertEquals(ValueFactory.newString("Hey I'm so happy!"), this.htmlStripper.process(valueToProcess));
}
Also used : Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Example 57 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class NodeVersionJsonDumpSerializerTest method serialize_deserialize.

@Test
public void serialize_deserialize() throws Exception {
    PropertyTree nodeData = new PropertyTree();
    nodeData.setDouble("a.b.c", 2.0);
    nodeData.setLocalDate("b", LocalDate.of(2013, 1, 2));
    nodeData.setString("c", "runar");
    nodeData.setLocalDateTime("d", LocalDateTime.of(2013, 1, 2, 3, 4, 5, 0));
    nodeData.setBinaryReference("e", BinaryReference.from("myImage1"));
    nodeData.setBinaryReference("f", BinaryReference.from("myImage2"));
    final AccessControlEntry entry1 = AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allow(Permission.READ).deny(Permission.DELETE).build();
    final AccessControlEntry entry2 = AccessControlEntry.create().principal(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).allow(Permission.MODIFY).deny(Permission.PUBLISH).build();
    AccessControlList acl = AccessControlList.create().add(entry1).add(entry2).build();
    IndexValueProcessor indexValueProcessor = new IndexValueProcessor() {

        @Override
        public Value process(final Value value) {
            return value;
        }

        @Override
        public String getName() {
            return "indexValueProcessor";
        }
    };
    IndexConfig indexConfig = IndexConfig.create().enabled(true).fulltext(true).nGram(true).decideByType(false).includeInAllText(true).path(true).addIndexValueProcessor(indexValueProcessor).addIndexValueProcessor(indexValueProcessor).build();
    NodeVersion nodeVersion = NodeVersion.create().id(NodeId.from("myId")).indexConfigDocument(PatternIndexConfigDocument.create().analyzer("myAnalyzer").defaultConfig(IndexConfig.MINIMAL).add("myPath", indexConfig).build()).data(nodeData).childOrder(ChildOrder.create().add(FieldOrderExpr.create(IndexPath.from("modifiedTime"), OrderExpr.Direction.ASC)).add(FieldOrderExpr.create(IndexPath.from("displayName"), OrderExpr.Direction.DESC)).build()).permissions(acl).nodeType(NodeType.from("myNodeType")).attachedBinaries(AttachedBinaries.create().add(new AttachedBinary(BinaryReference.from("myImage1"), "a")).add(new AttachedBinary(BinaryReference.from("myImage2"), "b")).build()).build();
    final String expectedNodeStr = readJson("serialized-node.json");
    final String expectedIndexConfigStr = readJson("serialized-index.json");
    final String expectedAccessControlStr = readJson("serialized-access.json");
    final String serializedNode = new String(this.serializer.toNodeString(nodeVersion), StandardCharsets.UTF_8);
    final String serializedIndexConfig = new String(this.serializer.toIndexConfigDocumentString(nodeVersion), StandardCharsets.UTF_8);
    final String serializedAccessControl = new String(this.serializer.toAccessControlString(nodeVersion), StandardCharsets.UTF_8);
    assertEquals(expectedNodeStr, serializedNode);
    assertEquals(expectedIndexConfigStr, serializedIndexConfig);
    assertEquals(expectedAccessControlStr, serializedAccessControl);
    final NodeVersion deSerializedNode = this.serializer.toNodeVersion(expectedNodeStr.getBytes(StandardCharsets.UTF_8), expectedIndexConfigStr.getBytes(StandardCharsets.UTF_8), expectedAccessControlStr.getBytes(StandardCharsets.UTF_8));
    assertEquals(nodeVersion, deSerializedNode);
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeVersion(com.enonic.xp.node.NodeVersion) IndexConfig(com.enonic.xp.index.IndexConfig) PropertyTree(com.enonic.xp.data.PropertyTree) Value(com.enonic.xp.data.Value) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) IndexValueProcessor(com.enonic.xp.index.IndexValueProcessor) AttachedBinary(com.enonic.xp.node.AttachedBinary) Test(org.junit.jupiter.api.Test)

Example 58 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class DateTimeType method createDefaultValue.

@Override
public Value createDefaultValue(final Input input) {
    final String defaultValue = input.getDefaultValue().getRootValue();
    if (defaultValue != null) {
        final boolean withTimezone = useTimeZone(input.getInputTypeConfig());
        Value value = withTimezone ? parseDateTime(defaultValue) : parseLocalDateTime(defaultValue);
        if (value != null) {
            return value;
        }
        final RelativeTime result = RelativeTimeParser.parse(defaultValue);
        if (result != null) {
            final Instant instant = Instant.now().plus(result.getTime());
            final Period period = result.getDate();
            final ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault()).plusYears(period.getYears()).plusMonths(period.getMonths()).plusDays(period.getDays()).withNano(0);
            return withTimezone ? ValueFactory.newDateTime(zonedDateTime.toInstant()) : ValueFactory.newLocalDateTime(zonedDateTime.toLocalDateTime());
        } else {
            throw new IllegalArgumentException("Invalid DateTime format: " + defaultValue);
        }
    }
    return super.createDefaultValue(input);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Value(com.enonic.xp.data.Value) Period(java.time.Period)

Example 59 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class TextLineTypeTest method testCreateDefaultValue.

@Test
public void testCreateDefaultValue() {
    final Input input = getDefaultInputBuilder(InputTypeName.TEXT_LINE, "testString").build();
    final Value value = this.type.createDefaultValue(input);
    assertNotNull(value);
    assertEquals("testString", value.toString());
}
Also used : Input(com.enonic.xp.form.Input) Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Example 60 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class TextLineTypeTest method testCreateProperty.

@Test
public void testCreateProperty() {
    final InputTypeConfig config = InputTypeConfig.create().build();
    final Value value = this.type.createValue(ValueFactory.newString("test"), config);
    assertNotNull(value);
    assertSame(ValueTypes.STRING, value.getType());
    final Value value2 = this.type.createValue("test", config);
    assertNotNull(value2);
    assertSame(ValueTypes.STRING, value2.getType());
}
Also used : Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Aggregations

Value (com.enonic.xp.data.Value)62 Test (org.junit.jupiter.api.Test)48 Input (com.enonic.xp.form.Input)24 Property (com.enonic.xp.data.Property)4 PropertySet (com.enonic.xp.data.PropertySet)4 PropertyTree (com.enonic.xp.data.PropertyTree)3 InputType (com.enonic.xp.inputtype.InputType)2 Instant (java.time.Instant)2 PropertyPath (com.enonic.xp.data.PropertyPath)1 FieldSet (com.enonic.xp.form.FieldSet)1 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)1 IndexConfig (com.enonic.xp.index.IndexConfig)1 IndexValueProcessor (com.enonic.xp.index.IndexValueProcessor)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 Node (com.enonic.xp.node.Node)1 NodePath (com.enonic.xp.node.NodePath)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)1