Search in sources :

Example 6 with AttachedBinary

use of com.enonic.xp.node.AttachedBinary in project xp by enonic.

the class XmlNodeSerializerTest method doCreateNode.

private Node doCreateNode(final Instant instant) {
    final PropertyTree propertyTree = new PropertyTree();
    propertyTree.addString("myString", "myStringValue");
    propertyTree.addString("myString", "myStringValue2");
    propertyTree.addString("myEmptyString", "");
    propertyTree.addBoolean("myBoolean", true);
    propertyTree.addDouble("myDouble", 123.1);
    propertyTree.addLong("myLong", 111L);
    propertyTree.addXml("myXml", "<car><color>Arctic Grey<color><car>");
    propertyTree.addString("myHtmlEncoded", "<p><a href=\"/naringsliv/tema/forsikrings-og-pensjonspakker\" data-event=\"{&quot;event_category&quot;: &quot;button&quot;, &quot;event_action&quot;: &quot;click&quot;,&quot;event_label&quot;: &quot;se-php&quot;}\">Se pakkene her</a></p>");
    propertyTree.addGeoPoint("myGeoPoint", GeoPoint.from("8,4"));
    // Date & Time
    propertyTree.addInstant("myInstant", instant);
    propertyTree.addLocalTime("myLocalTime", LocalTime.of(21, 42, 0));
    propertyTree.addLocalDate("myLocalDate", LocalDate.of(2014, 11, 28));
    propertyTree.addLocalDateTime("myLocalDateTime", LocalDateTime.of(2014, 11, 28, 21, 0, 0, 0));
    // Links and ref
    propertyTree.addReference("myRef", Reference.from("abcd"));
    propertyTree.addLink("myLink", Link.from("/root/parent/child"));
    // Binary refs
    propertyTree.addBinaryReference("myBinaryRef1", BinaryReference.from("image.jpg"));
    propertyTree.addBinaryReference("myBinaryRef2", BinaryReference.from("image2.jpg"));
    // Property-set
    final PropertySet mySubset = propertyTree.addSet("mySet");
    mySubset.setString("myString", "myStringValue");
    mySubset.setBoolean("myBoolean", true);
    // Property-set in set
    final PropertySet mySubSubset = mySubset.addSet("mySet");
    mySubSubset.setString("myString", "myStringValue");
    mySubSubset.setBoolean("myBoolean", true);
    // Null values
    propertyTree.addString("myString", null);
    propertyTree.addBoolean("myBoolean", null);
    propertyTree.addDouble("myDouble", null);
    propertyTree.addLong("myLong", null);
    propertyTree.addXml("myXml", null);
    propertyTree.addGeoPoint("myGeoPoint", null);
    propertyTree.addInstant("myInstant", null);
    propertyTree.addLocalTime("myLocalTime", null);
    propertyTree.addLocalDate("myLocalDate", null);
    propertyTree.addLocalDateTime("myLocalDateTime", null);
    propertyTree.addReference("myRef", null);
    propertyTree.addLink("myLink", null);
    propertyTree.addBinaryReference("myBinaryRef2", null);
    propertyTree.addSet("nullSet", null);
    // Index configs
    final IndexConfig indexConfig = IndexConfig.create().enabled(true).fulltext(true).nGram(true).decideByType(false).includeInAllText(true).addIndexValueProcessor(IndexValueProcessors.HTML_STRIPPER).addLanguage("en").build();
    final PatternIndexConfigDocument.Builder indexConfigDocumentBuilder = PatternIndexConfigDocument.create();
    indexConfigDocumentBuilder.analyzer("no");
    indexConfigDocumentBuilder.add("mydata", indexConfig);
    indexConfigDocumentBuilder.addAllTextConfigLanguage("en");
    // Permissions
    final Permission createPermission = Permission.CREATE;
    final Permission publishPermission = Permission.PUBLISH;
    final PrincipalKey systemPrincipalKey = PrincipalKey.from("role:system.admin");
    final PrincipalKey cmsPrincipalKey = PrincipalKey.from("role:cms.admin");
    final AccessControlEntry systemAccessControlEntry = AccessControlEntry.create().principal(systemPrincipalKey).allowAll().build();
    final AccessControlEntry cmsAccessControlEntry = AccessControlEntry.create().principal(cmsPrincipalKey).allow(createPermission).deny(publishPermission).build();
    final AccessControlList accessControlList = AccessControlList.of(systemAccessControlEntry, cmsAccessControlEntry);
    return Node.create().id(NodeId.from("abc")).name(NodeName.from("my-node-name")).parentPath(NodePath.ROOT).childOrder(ChildOrder.manualOrder()).nodeType(NodeType.from("content")).data(propertyTree).indexConfigDocument(indexConfigDocumentBuilder.build()).permissions(accessControlList).inheritPermissions(false).attachedBinaries(AttachedBinaries.create().add(new AttachedBinary(BinaryReference.from("image.jpg"), "a")).add(new AttachedBinary(BinaryReference.from("image2.jpg"), "b")).build()).build();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IndexConfig(com.enonic.xp.index.IndexConfig) PropertyTree(com.enonic.xp.data.PropertyTree) Permission(com.enonic.xp.security.acl.Permission) PropertySet(com.enonic.xp.data.PropertySet) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) PrincipalKey(com.enonic.xp.security.PrincipalKey) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 7 with AttachedBinary

use of com.enonic.xp.node.AttachedBinary in project xp by enonic.

the class UpdatedAttachedBinariesResolver method processExistingBinaries.

private void processExistingBinaries(final Map<BinaryReference, AttachedBinary> resolved, final Set<BinaryReference> referencesInEditedNode, final Set<BinaryReference> referencesInPersistedNode) {
    final Set<BinaryReference> unchangedReferences = Sets.intersection(referencesInPersistedNode, referencesInEditedNode);
    final AttachedBinaries attachedBinaries = persistedNode.getAttachedBinaries();
    for (final BinaryReference unchangedReference : unchangedReferences) {
        final AttachedBinary existingAttachedBinary = attachedBinaries.getByBinaryReference(unchangedReference);
        if (existingAttachedBinary != null) {
            resolved.put(unchangedReference, existingAttachedBinary);
        }
    }
}
Also used : BinaryReference(com.enonic.xp.util.BinaryReference) AttachedBinaries(com.enonic.xp.node.AttachedBinaries) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 8 with AttachedBinary

use of com.enonic.xp.node.AttachedBinary in project xp by enonic.

the class CreateNodeCommand method storeAndAttachBinaries.

private AttachedBinaries storeAndAttachBinaries() {
    final PropertyTree data = params.getData();
    final AttachedBinaries.Builder builder = AttachedBinaries.create();
    final ImmutableList<Property> binaryReferences = data.getProperties(ValueTypes.BINARY_REFERENCE);
    for (final Property binaryRef : binaryReferences) {
        final BinaryAttachment binaryAttachment = this.params.getBinaryAttachments().get(binaryRef.getBinaryReference());
        if (binaryAttachment == null) {
            throw new NodeBinaryReferenceException("No binary with reference " + binaryRef + " attached in createNodeParams");
        }
        final RepositoryId repositoryId = ContextAccessor.current().getRepositoryId();
        final AttachedBinary attachedBinary = this.binaryService.store(repositoryId, binaryAttachment);
        builder.add(attachedBinary);
    }
    return builder.build();
}
Also used : NodeBinaryReferenceException(com.enonic.xp.node.NodeBinaryReferenceException) PropertyTree(com.enonic.xp.data.PropertyTree) AttachedBinaries(com.enonic.xp.node.AttachedBinaries) Property(com.enonic.xp.data.Property) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) RepositoryId(com.enonic.xp.repository.RepositoryId) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 9 with AttachedBinary

use of com.enonic.xp.node.AttachedBinary in project xp by enonic.

the class AbstractGetBinaryCommand method getByBinaryReference.

ByteSource getByBinaryReference(final Node node) {
    final AttachedBinaries attachedBinaries = node.getAttachedBinaries();
    if (attachedBinaries == null) {
        return null;
    }
    final AttachedBinary attachedBinary = attachedBinaries.getByBinaryReference(this.binaryReference);
    if (attachedBinary == null) {
        return null;
    }
    return doGetByteSource(attachedBinary);
}
Also used : AttachedBinaries(com.enonic.xp.node.AttachedBinaries) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 10 with AttachedBinary

use of com.enonic.xp.node.AttachedBinary in project xp by enonic.

the class AbstractGetBinaryCommand method getByPropertyPath.

ByteSource getByPropertyPath(final Node node) {
    final BinaryReference binaryReference = node.data().getBinaryReference(this.propertyPath);
    if (binaryReference == null) {
        return null;
    }
    final AttachedBinary attachedBinary = node.getAttachedBinaries().getByBinaryReference(binaryReference);
    return doGetByteSource(attachedBinary);
}
Also used : BinaryReference(com.enonic.xp.util.BinaryReference) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Aggregations

AttachedBinary (com.enonic.xp.node.AttachedBinary)16 BinaryReference (com.enonic.xp.util.BinaryReference)7 PropertyTree (com.enonic.xp.data.PropertyTree)6 Node (com.enonic.xp.node.Node)4 Test (org.junit.jupiter.api.Test)4 AttachedBinaries (com.enonic.xp.node.AttachedBinaries)3 RepositoryId (com.enonic.xp.repository.RepositoryId)3 ByteSource (com.google.common.io.ByteSource)3 IndexConfig (com.enonic.xp.index.IndexConfig)2 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)2 BranchDumpEntry (com.enonic.xp.repo.impl.dump.model.BranchDumpEntry)2 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 AccessControlEntry (com.enonic.xp.security.acl.AccessControlEntry)2 AccessControlList (com.enonic.xp.security.acl.AccessControlList)2 Application (com.enonic.xp.app.Application)1 BlobKey (com.enonic.xp.blob.BlobKey)1 BlobRecord (com.enonic.xp.blob.BlobRecord)1 Segment (com.enonic.xp.blob.Segment)1 Property (com.enonic.xp.data.Property)1 PropertySet (com.enonic.xp.data.PropertySet)1