Examples of NodeBuilder


Examples of org.apache.jackrabbit.oak.spi.state.NodeBuilder

     */
    private NodeBuilder createVersion(@Nonnull NodeBuilder vHistory,
                                      @Nonnull NodeBuilder versionable)
            throws IllegalArgumentException, CommitFailedException {
        List<String> predecessors;
        NodeBuilder version;
        boolean isRootVersion;
        if (!vHistory.hasChildNode(JCR_ROOTVERSION)) {
            // create root version
            isRootVersion = true;
            predecessors = Collections.emptyList();
            version = vHistory.child(JCR_ROOTVERSION);
        } else {
            isRootVersion = false;
            checkState(versionable.hasProperty(JCR_PREDECESSORS));
            PropertyState state = versionable.getProperty(JCR_PREDECESSORS);
            predecessors = ImmutableList.copyOf(state.getValue(Type.REFERENCES));
            version = vHistory.child(calculateVersion(vHistory, versionable));
        }
        String versionUUID = IdentifierManager.generateUUID();
        version.setProperty(JCR_UUID, versionUUID, Type.STRING);
        version.setProperty(JCR_PRIMARYTYPE, NT_VERSION, Type.NAME);
        version.setProperty(JCR_CREATED, ISO8601.format(Calendar.getInstance()), Type.DATE);
        version.setProperty(JCR_PREDECESSORS, predecessors, Type.REFERENCES);
        version.setProperty(JCR_SUCCESSORS, Collections.<String>emptyList(), Type.REFERENCES);

        // update successors of versions identified by predecessors
        for (String id : predecessors) {
            String name = PathUtils.getName(getIdentifierManager().getPath(id));
            NodeBuilder predecessor = vHistory.getChildNode(name);
            PropertyState state = predecessor.getProperty(JCR_SUCCESSORS);
            if (state == null) {
                throw new IllegalStateException("Missing " + JCR_SUCCESSORS +
                        " property on " + predecessor);
            }
            Set<String> refs = Sets.newHashSet(state.getValue(Type.REFERENCES));
            refs.add(versionUUID);
            predecessor.setProperty(JCR_SUCCESSORS, refs, Type.REFERENCES);
        }

        // jcr:frozenNode of created version
        VersionableState versionableState = VersionableState.fromVersion(
                version, vHistory, versionable, this, ntMgr);

Examples of org.apache.jackrabbit.oak.spi.state.NodeBuilder

            }
            return newVersionName;
        } else {
            // best is root version
            checkState(history.hasChildNode(JCR_ROOTVERSION));
            NodeBuilder v = history.getChildNode(JCR_ROOTVERSION);
            return String.valueOf(v.getProperty(JCR_SUCCESSORS).count() + 1) + ".0";
        }
    }

Examples of org.apache.jackrabbit.oak.spi.state.NodeBuilder

        if (group.hasChildNode(UserConstants.REP_MEMBERS)) {
            group.getChildNode(UserConstants.REP_MEMBERS).remove();
        }

        PropertyBuilder<String> prop = null;
        NodeBuilder refList = null;
        NodeBuilder node = group;

        int count = 0;
        int numNodes = 0;
        for (String ref: members) {
            if (prop == null) {
                prop = PropertyBuilder.array(Type.WEAKREFERENCE, UserConstants.REP_MEMBERS);
            }
            prop.addValue(ref);
            count++;
            if (count > membershipSizeThreshold) {
                node.setProperty(prop.getPropertyState());
                prop = null;
                if (refList == null) {
                    // create intermediate structure
                    refList = group.child(UserConstants.REP_MEMBERS_LIST);
                    refList.setProperty(JcrConstants.JCR_PRIMARYTYPE, UserConstants.NT_REP_MEMBER_REFERENCES_LIST, NAME);
                }
                node = refList.child(String.valueOf(numNodes++));
                node.setProperty(JcrConstants.JCR_PRIMARYTYPE, UserConstants.NT_REP_MEMBER_REFERENCES, NAME);
            }
        }
        if (prop != null) {
            node.setProperty(prop.getPropertyState());
        }
    }

Examples of org.apache.jackrabbit.oak.spi.state.NodeBuilder

     * @throws CommitFailedException if there is no version history at the
     * given path.
     */
    private NodeBuilder getVersionLabelsFor(String historyRelPath)
            throws CommitFailedException {
        NodeBuilder history = resolve(versionStorageNode, historyRelPath);
        if (!history.exists()) {
            throw new CommitFailedException(CommitFailedException.VERSION,
                    VersionExceptionCode.UNEXPECTED_REPOSITORY_EXCEPTION.ordinal(),
                    "Version history does not exist: " + PathUtils.concat(
                            VERSION_STORE_PATH, historyRelPath));
        }
        return history.child(JCR_VERSIONLABELS);
    }

Examples of org.apache.jackrabbit.oak.spi.state.NodeBuilder

    }

    @Nonnull
    @Override
    public NodeState processCommit(final NodeState before, NodeState after) throws CommitFailedException {
        NodeBuilder rootBuilder = after.builder();
        NodeBuilder vsRoot = rootBuilder.child(NodeTypeConstants.JCR_SYSTEM).child(NodeTypeConstants.JCR_VERSIONSTORAGE);
        ReadWriteVersionManager vMgr = new ReadWriteVersionManager(vsRoot, rootBuilder);
        List<CommitFailedException> exceptions = new ArrayList<CommitFailedException>();
        after.compareAgainstBaseState(before,
                new Diff(vMgr, new Node(rootBuilder), exceptions));
        if (!exceptions.isEmpty()) {

Examples of org.apache.jackrabbit.oak.spi.state.NodeBuilder

                    before, new Diff(versionManager, node, exceptions));
        }

        private boolean setVersionablePath(PropertyState after) {
            if (JcrConstants.JCR_VERSIONHISTORY.equals(after.getName()) && nodeAfter.isVersionable(versionManager)) {
                NodeBuilder vhBuilder;
                try {
                    vhBuilder = versionManager.getOrCreateVersionHistory(nodeAfter.builder);
                } catch (CommitFailedException e) {
                    exceptions.add(e);
                    // stop further comparison
                    return false;
                }

                if (!vhBuilder.hasProperty(JcrConstants.JCR_MIXINTYPES)) {
                    vhBuilder.setProperty(
                            JcrConstants.JCR_MIXINTYPES,
                            ImmutableSet.of(MIX_REP_VERSIONABLE_PATHS),
                            Type.NAMES);
                }

                String versionablePath = nodeAfter.path;
                vhBuilder.setProperty(workspaceName, versionablePath, Type.PATH);
            }
            return true;
        }

Examples of org.apache.jackrabbit.oak.spi.state.NodeBuilder

            insert(index, key, path);
        }
    }

    private static void remove(NodeBuilder index, String key, String value) {
        NodeBuilder builder = index.getChildNode(key);
        if (builder.exists()) {
            // there could be (temporarily) multiple entries
            // we need to remove the right one
            PropertyState s = builder.getProperty("entry");
            if (s.count() == 1) {
                builder.remove();
            } else {
                ArrayList<String> list = new ArrayList<String>();
                for (int i = 0; i < s.count(); i++) {
                    String r = s.getValue(Type.STRING, i);
                    if (!r.equals(value)) {
                        list.add(r);
                    }
                }
                PropertyState s2 = MultiStringPropertyState.stringProperty("entry", list);
                builder.setProperty(s2);
            }
        }
    }

Examples of org.apache.jackrabbit.oak.spi.state.NodeBuilder

            }
        }
    }

    private static void insert(NodeBuilder index, String key, String value) {
        NodeBuilder k = index.child(key);
        ArrayList<String> list = new ArrayList<String>();
        list.add(value);
        if (k.hasProperty("entry")) {
            // duplicate key (to detect duplicate entries)
            // this is just set temporarily,
            // while trying to add a duplicate entry
            PropertyState s = k.getProperty("entry");
            for (int i = 0; i < s.count(); i++) {
                String r = s.getValue(Type.STRING, i);
                list.add(r);
            }
        }
        PropertyState s2 = MultiStringPropertyState.stringProperty("entry", list);
        k.setProperty(s2);
    }

Examples of org.apache.jackrabbit.oak.spi.state.NodeBuilder

    @Override
    public NodeBuilder select(@Nonnull NodeBuilder history)
            throws RepositoryException {
        long latestDate = Long.MIN_VALUE;
        NodeBuilder latestVersion = null;
        for (String name: history.getChildNodeNames()) {
            // OAK-1192 skip hidden child nodes
            if (name.charAt(0) == ':') {
                continue;
            }
            NodeBuilder v = history.getChildNode(name);
            if (name.equals(JcrConstants.JCR_ROOTVERSION)
                    || name.equals(JcrConstants.JCR_VERSIONLABELS)) {
                // ignore root version and labels node
                continue;
            }
            long c = ISO8601.parse(v.getProperty(JcrConstants.JCR_CREATED).getValue(Type.DATE)).getTimeInMillis();
            if (c > latestDate && c <= timestamp) {
                latestDate = c;
                latestVersion = v;
            }
        }

Examples of org.apache.jackrabbit.oak.spi.state.NodeBuilder

        }

        private void update(Set<String> principalNames) {
            for (String principalName: entries.keySet()) {
                principalNames.add(principalName);
                NodeBuilder principalRoot = permissionRoot.child(principalName);
                if (!principalRoot.hasProperty(JCR_PRIMARYTYPE)) {
                    principalRoot.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME);
                }
                NodeBuilder parent = principalRoot.child(nodeName);
                if (!parent.hasProperty(JCR_PRIMARYTYPE)) {
                    parent.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME);
                }

                // check if current parent already has the correct path
                if (parent.hasProperty(REP_ACCESS_CONTROLLED_PATH)) {
                    if (!PermissionUtil.checkACLPath(parent, accessControlledPath)) {
                        // hash collision, find a new child
                        NodeBuilder child = null;
                        int idx = 0;
                        for (String childName : parent.getChildNodeNames()) {
                            if (childName.charAt(0) != 'c') {
                                continue;
                            }
                            child = parent.getChildNode(childName);
                            if (PermissionUtil.checkACLPath(child, accessControlledPath)) {
                                break;
                            }
                            child = null;
                            idx++;
                        }
                        while (child == null) {
                            String name = 'c' + String.valueOf(idx++);
                            child = parent.getChildNode(name);
                            if (child.exists()) {
                                child = null;
                            } else {
                                child = parent.child(name);
                                child.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME);
                            }
                        }
                        parent = child;
                        parent.setProperty(REP_ACCESS_CONTROLLED_PATH, accessControlledPath);
                    }
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.