Search in sources :

Example 1 with PropertyBuilder

use of org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder in project jackrabbit-oak by apache.

the class BlobMigrator method migrateMultiProperty.

private PropertyState migrateMultiProperty(PropertyState propertyState) throws IOException {
    Iterable<Blob> oldBlobs = propertyState.getValue(Type.BINARIES);
    List<Blob> newBlobs = new ArrayList<Blob>();
    PropertyBuilder<Blob> builder = new PropertyBuilder<Blob>(Type.BINARY);
    builder.assignFrom(propertyState);
    boolean blobUpdated = false;
    for (Blob oldBlob : oldBlobs) {
        String blobId = getIdentity(oldBlob);
        if (blobStore.isMigrated(blobId)) {
            newBlobs.add(new BlobStoreBlob(blobStore, blobId));
        } else {
            String newBlobId = blobStore.writeBlob(oldBlob.getNewStream());
            Blob newBlob = new BlobStoreBlob(blobStore, newBlobId);
            newBlobs.add(newBlob);
            blobUpdated = true;
        }
    }
    if (blobUpdated) {
        builder.setValues(newBlobs);
        return builder.getPropertyState();
    } else {
        return null;
    }
}
Also used : BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) Blob(org.apache.jackrabbit.oak.api.Blob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) ArrayList(java.util.ArrayList) PropertyBuilder(org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder)

Example 2 with PropertyBuilder

use of org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder in project jackrabbit-oak by apache.

the class BlobMigrator method migrateProperty.

private PropertyState migrateProperty(PropertyState propertyState) throws IOException {
    Blob oldBlob = propertyState.getValue(Type.BINARY);
    String blobId = getIdentity(oldBlob);
    if (blobStore.isMigrated(blobId)) {
        return null;
    }
    String newBlobId = blobStore.writeBlob(oldBlob.getNewStream());
    Blob newBlob = new BlobStoreBlob(blobStore, newBlobId);
    PropertyBuilder<Blob> builder = new PropertyBuilder<Blob>(Type.BINARY);
    builder.assignFrom(propertyState);
    builder.setValue(newBlob);
    return builder.getPropertyState();
}
Also used : BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) Blob(org.apache.jackrabbit.oak.api.Blob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) PropertyBuilder(org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder)

Example 3 with PropertyBuilder

use of org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder in project jackrabbit-oak by apache.

the class SelectorImpl method currentOakProperty.

private PropertyValue currentOakProperty(String oakPropertyName, Integer propertyType) {
    boolean asterisk = oakPropertyName.indexOf('*') >= 0;
    if (asterisk) {
        Tree t = currentTree();
        if (t != null) {
            LOG.trace("currentOakProperty() - '*' case. looking for '{}' in '{}'", oakPropertyName, t.getPath());
        }
        ArrayList<PropertyValue> list = new ArrayList<PropertyValue>();
        readOakProperties(list, t, oakPropertyName, propertyType);
        if (list.size() == 0) {
            return null;
        } else if (list.size() == 1) {
            return list.get(0);
        }
        Type<?> type = list.get(0).getType();
        for (int i = 1; i < list.size(); i++) {
            Type<?> t2 = list.get(i).getType();
            if (t2 != type) {
                // types don't match
                type = Type.STRING;
                break;
            }
        }
        if (type == Type.STRING) {
            ArrayList<String> strings = new ArrayList<String>();
            for (PropertyValue p : list) {
                Iterables.addAll(strings, p.getValue(Type.STRINGS));
            }
            return PropertyValues.newString(strings);
        }
        Type<?> baseType = type.isArray() ? type.getBaseType() : type;
        @SuppressWarnings("unchecked") PropertyBuilder<Object> builder = (PropertyBuilder<Object>) PropertyBuilder.array(baseType);
        builder.setName("");
        for (PropertyValue v : list) {
            if (type.isArray()) {
                for (Object value : (Iterable<?>) v.getValue(type)) {
                    builder.addValue(value);
                }
            } else {
                builder.addValue(v.getValue(type));
            }
        }
        PropertyState s = builder.getPropertyState();
        return PropertyValues.create(s);
    }
    boolean relative = oakPropertyName.indexOf('/') >= 0;
    Tree t = currentTree();
    if (relative) {
        for (String p : PathUtils.elements(PathUtils.getParentPath(oakPropertyName))) {
            if (t == null) {
                return null;
            }
            if (p.equals("..")) {
                t = t.isRoot() ? null : t.getParent();
            } else if (p.equals(".")) {
            // same node
            } else {
                t = t.getChild(p);
            }
        }
        oakPropertyName = PathUtils.getName(oakPropertyName);
    }
    return currentOakProperty(t, oakPropertyName, propertyType);
}
Also used : ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyBuilder(org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder)

Example 4 with PropertyBuilder

use of org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder in project jackrabbit-oak by apache.

the class AccessControlManagerImpl method createAclTree.

/**
     * @param oakPath the Oak path as specified with the ac mgr call.
     * @param tree    the access controlled node.
     * @return the new acl tree.
     * @throws AccessDeniedException In case the new acl tree is not accessible.
     */
@Nonnull
private Tree createAclTree(@Nullable String oakPath, @Nonnull Tree tree) throws AccessDeniedException {
    if (!Util.isAccessControlled(oakPath, tree, ntMgr)) {
        PropertyState mixins = tree.getProperty(JcrConstants.JCR_MIXINTYPES);
        String mixinName = Util.getMixinName(oakPath);
        if (mixins == null) {
            tree.setProperty(JcrConstants.JCR_MIXINTYPES, Collections.singleton(mixinName), Type.NAMES);
        } else {
            PropertyBuilder pb = PropertyBuilder.copy(Type.NAME, mixins);
            pb.addValue(mixinName);
            tree.setProperty(pb.getPropertyState());
        }
    }
    String aclName = Util.getAclName(oakPath);
    return TreeUtil.addChild(tree, aclName, NT_REP_ACL);
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState) PropertyBuilder(org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder) Nonnull(javax.annotation.Nonnull)

Aggregations

PropertyBuilder (org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder)4 ArrayList (java.util.ArrayList)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 BlobStoreBlob (org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Nonnull (javax.annotation.Nonnull)1 PropertyValue (org.apache.jackrabbit.oak.api.PropertyValue)1 Tree (org.apache.jackrabbit.oak.api.Tree)1