Examples of PropertyFactory


Examples of org.modeshape.jcr.value.PropertyFactory

            }

            // Restore the back references ...
            if (!referrersByNodeKey.isEmpty()) {
                for (Map.Entry<NodeKey, ReferrerCounts> entry : referrersByNodeKey.entrySet()) {
                    PropertyFactory propFactory = context.getPropertyFactory();
                    MutableCachedNode referred = cache.mutable(entry.getKey());
                    ReferrerCounts counts = entry.getValue();
                    if (referred != null && counts != null) {
                        // Add in the strong and weak referrers (that are outside the import scope) that used to be in the node
                        // before it was replaced ...
                        for (NodeKey key : counts.getStrongReferrers()) {
                            int count = counts.countStrongReferencesFrom(key);
                            for (int i = 0; i != count; ++i) {
                                Property prop = propFactory.create(nameFor(key.toString() + i));
                                referred.addReferrer(cache, prop, key, ReferenceType.STRONG);
                            }
                        }
                        for (NodeKey key : counts.getWeakReferrers()) {
                            int count = counts.countWeakReferencesFrom(key);
                            for (int i = 0; i != count; ++i) {
                                Property prop = propFactory.create(nameFor(key.toString() + i));
                                referred.addReferrer(cache, prop, key, ReferenceType.WEAK);
                            }
                        }
                    }
                }
View Full Code Here

Examples of org.modeshape.jcr.value.PropertyFactory

            }
        }
    }

    private void storeProjection( Projection projection ) {
        PropertyFactory propertyFactory = repository.context().getPropertyFactory();

        // we need to store the projection mappings so that we don't loose that information
        SessionCache systemSession = repository.createSystemSession(repository.context(), false);
        NodeKey systemNodeKey = getSystemNode(systemSession).getKey();
        MutableCachedNode systemNode = systemSession.mutable(systemNodeKey);
        ChildReference federationNodeRef = systemNode.getChildReferences(systemSession).getChild(ModeShapeLexicon.FEDERATION);

        if (federationNodeRef == null) {
            // there isn't a federation node present, so we need to add it
            try {
                Property primaryType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.FEDERATION);
                systemNode.createChild(systemSession, systemNodeKey.withId("mode:federation"), ModeShapeLexicon.FEDERATION,
                                       primaryType);
                systemSession.save();
                federationNodeRef = systemNode.getChildReferences(systemSession).getChild(ModeShapeLexicon.FEDERATION);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        NodeKey federationNodeKey = federationNodeRef.getKey();
        MutableCachedNode federationNode = systemSession.mutable(federationNodeKey);

        Property primaryType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.PROJECTION);
        Property externalNodeKeyProp = propertyFactory.create(ModeShapeLexicon.EXTERNAL_NODE_KEY, projection.getExternalNodeKey());

        Property projectedNodeKeyProp = propertyFactory.create(ModeShapeLexicon.PROJECTED_NODE_KEY,
                                                               projection.getProjectedNodeKey());
        Property alias = propertyFactory.create(ModeShapeLexicon.PROJECTION_ALIAS, projection.getAlias());
        federationNode.createChild(systemSession, federationNodeKey.withRandomId(), ModeShapeLexicon.PROJECTION, primaryType,
                                   externalNodeKeyProp, projectedNodeKeyProp, alias);

        systemSession.save();
    }
View Full Code Here

Examples of org.modeshape.jcr.value.PropertyFactory

            DateTimeFactory dates = context.getValueFactories().getDateFactory();
            DateTime now = dates.create();
            DateTime newExpiration = dates.create(now, RepositoryConfiguration.LOCK_EXTENSION_INTERVAL_IN_MILLIS);

            PropertyFactory propertyFactory = context.getPropertyFactory();
            SessionCache systemSession = repository.createSystemSession(context, false);
            SystemContent systemContent = new SystemContent(systemSession);

            Map<String, List<NodeKey>> lockedNodesByWorkspaceName = new HashMap<>();
            // Iterate over the locks ...
            MutableCachedNode locksNode = systemContent.mutableLocksNode();
            for (ChildReference ref : locksNode.getChildReferences(systemSession)) {
                NodeKey lockKey = ref.getKey();
                CachedNode lockNode = systemSession.getNode(lockKey);
                if (lockNode == null) {
                    //it may happen that another thread has performed a session.logout which means the lock might have been removed
                    continue;
                }
                ModeShapeLock lock = new ModeShapeLock(lockNode, systemSession);
                NodeKey lockedNodeKey = lock.getLockedNodeKey();
                if (lock.isSessionScoped() && activeSessionIds.contains(lock.getLockingSessionId())) {
                    //for active session locks belonging to the sessions of this process, we want to extend the expiration date
                    //so that other processes in a cluster can tell that this lock is still active
                    MutableCachedNode mutableLockNode = systemSession.mutable(lockKey);
                    Property prop = propertyFactory.create(ModeShapeLexicon.EXPIRATION_DATE, newExpiration);
                    mutableLockNode.setProperty(systemSession, prop);
                    //reflect the change in the expiry date in the internal map
                    this.locksByNodeKey.replace(lockedNodeKey, lock.withExpiryTime(newExpiration));

                    continue;
View Full Code Here

Examples of org.modeshape.jcr.value.PropertyFactory

            // Update the persistent node ...
            SessionCache lockingSession = session.spawnSessionCache(false);
            MutableCachedNode lockedNode = lockingSession.mutable(nodeKey);

            PropertyFactory propertyFactory = session.propertyFactory();
            lockedNode.setProperty(lockingSession, propertyFactory.create(JcrLexicon.LOCK_OWNER, owner));
            lockedNode.setProperty(lockingSession, propertyFactory.create(JcrLexicon.LOCK_IS_DEEP, isDeep));
            lockedNode.lock(isSessionScoped);

            // Now save both sessions. This will fail with a LockFailureException if the locking failed ...
            lockingSession.save(systemSession, null);
        } catch (LockFailureException e) {
View Full Code Here

Examples of org.modeshape.jcr.value.PropertyFactory

                            // Read-read the entry that we just put, so we can populate it with the same code that edits it ...
                            entry = documentStore().localStore().get(systemMetadataKeyStr);
                        }
                    }
                    EditableDocument doc = documentStore().localStore().edit(systemMetadataKeyStr, true);
                    PropertyFactory propFactory = context().getPropertyFactory();
                    translator.setProperty(doc, propFactory.create(name("workspaces"), workspaceNames), null, null);
                    translator.setProperty(doc, propFactory.create(name("accessControl"), accessControlEnabled), null, null);

                    return null;
                }
            });
        } catch (RuntimeException re) {
View Full Code Here

Examples of org.modeshape.jcr.value.PropertyFactory

            NodeKey historyKey = version.getParentKey(systemSession);

            // Update the node's 'mix:versionable' properties, using a new session ...
            SessionCache versionSession = session.spawnSessionCache(false);
            MutableCachedNode versionableNode = versionSession.mutable(versionedKey);
            PropertyFactory props = propertyFactory();
            ReferenceFactory refFactory = session.referenceFactory();
            Reference historyRef = refFactory.create(historyKey, true);
            Reference baseVersionRef = refFactory.create(version.getKey(), true);
            versionableNode.setProperty(versionSession, props.create(JcrLexicon.VERSION_HISTORY, historyRef));
            versionableNode.setProperty(versionSession, props.create(JcrLexicon.BASE_VERSION, baseVersionRef));
            versionableNode.setProperty(versionSession, props.create(JcrLexicon.IS_CHECKED_OUT, Boolean.FALSE));
            // The 'jcr:predecessors' set to an empty array, per Section 15.2 in JSR-283
            versionableNode.setProperty(versionSession, props.create(JcrLexicon.PREDECESSORS, new Object[] {}));

            // Now process the children of the versionable node, and add them under the frozen node ...
            MutableCachedNode frozenNode = frozen.get();
            for (ChildReference childRef : cachedNode.getChildReferences(versionSession)) {
                AbstractJcrNode child = session.node(childRef.getKey(), null, versionedKey);
View Full Code Here

Examples of org.modeshape.jcr.value.PropertyFactory

                // results in COPY behavior "regardless of the OPV values of the sub-items".
                // We can achieve this by making the onParentVersionAction always COPY for the
                // recursive call ...
                forceCopy = true;

                PropertyFactory factory = propertyFactory();
                List<Property> props = new LinkedList<Property>();

                if (node.isShared()) {
                    // This is a shared node, so we should store a proxy to the shareable node ...
                    props.add(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FROZEN_NODE));
                    props.add(factory.create(JcrLexicon.FROZEN_PRIMARY_TYPE, ModeShapeLexicon.SHARE));
                    props.add(factory.create(JcrLexicon.FROZEN_UUID, node.getIdentifier()));
                    props.add(factory.create(JcrLexicon.UUID, key));
                    parentInVersionHistory.createChild(versionHistoryCache, key, node.name(), props);

                    // The proxies to shareable nodes never have children (nor versionable properties), so we're done ...
                    return;
                }

                // But the copy needs to be a 'nt:frozenNode', so that it doesn't compete with the actual node
                // (outside of version history) ...
                Name primaryTypeName = node.getPrimaryTypeName();
                Set<Name> mixinTypeNames = node.getMixinTypeNames();
                props.add(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FROZEN_NODE));
                props.add(factory.create(JcrLexicon.FROZEN_PRIMARY_TYPE, primaryTypeName));
                props.add(factory.create(JcrLexicon.FROZEN_MIXIN_TYPES, mixinTypeNames));
                props.add(factory.create(JcrLexicon.FROZEN_UUID, node.getIdentifier()));
                props.add(factory.create(JcrLexicon.UUID, key));
                addVersionedPropertiesFor(node, forceCopy, props);
                MutableCachedNode newCopy = parentInVersionHistory.createChild(versionHistoryCache, key, node.name(), props);

                // Now process the children of the versionable node ...
                NodeKey parentKey = node.key();
View Full Code Here

Examples of org.modeshape.jcr.value.PropertyFactory

        // Create a session that we'll used to change the node ...
        SessionCache versionSession = session.spawnSessionCache(false);
        MutableCachedNode versionable = versionSession.mutable(node.key());
        NodeKey baseVersionKey = node.getBaseVersion().key();
        PropertyFactory props = propertyFactory();
        Reference baseVersionRef = session.referenceFactory().create(baseVersionKey, true);
        versionable.setProperty(versionSession, props.create(JcrLexicon.PREDECESSORS, new Object[] {baseVersionRef}));
        versionable.setProperty(versionSession, props.create(JcrLexicon.IS_CHECKED_OUT, Boolean.TRUE));
        versionSession.save();
    }
View Full Code Here

Examples of org.modeshape.jcr.value.PropertyFactory

        AbstractJcrNode existingNode = null;
        AbstractJcrNode nodeToCheckLock;

        JcrVersionNode jcrVersion = (JcrVersionNode)version;
        SessionCache cache = session.cache();
        PropertyFactory propFactory = session.propertyFactory();

        try {
            existingNode = parentNode.childNode(path.getLastSegment(), null);
            nodeToCheckLock = existingNode;

            // These checks only make sense if there is an existing node
            JcrVersionHistoryNode versionHistory = existingNode.getVersionHistory();
            if (!versionHistory.isSame(jcrVersion.getParent())) {
                throw new VersionException(JcrI18n.invalidVersion.text(version.getPath(), versionHistory.getPath()));
            }

            if (!versionHistory.isSame(existingNode.getVersionHistory())) {
                throw new VersionException(JcrI18n.invalidVersion.text(version.getPath(), existingNode.getVersionHistory()
                                                                                                      .getPath()));
            }

            if (jcrVersion.isSame(versionHistory.getRootVersion())) {
                throw new VersionException(JcrI18n.cannotRestoreRootVersion.text(existingNode.getPath()));
            }

        } catch (PathNotFoundException pnfe) {
            // This is allowable, but the node needs to be checked out
            if (!parentNode.isCheckedOut()) {
                String parentPath = path.getString(session.context().getNamespaceRegistry());
                throw new VersionException(JcrI18n.nodeIsCheckedIn.text(parentPath));
            }

            AbstractJcrNode sourceNode = session.workspace().getVersionManager().frozenNodeFor(version);
            Name primaryTypeName = session.nameFactory().create(sourceNode.getProperty(JcrLexicon.FROZEN_PRIMARY_TYPE)
                                                                          .property()
                                                                          .getFirstValue());
            AbstractJcrProperty uuidProp = sourceNode.getProperty(JcrLexicon.FROZEN_UUID);
            String frozenUuidString = session.stringFactory().create(uuidProp.property().getFirstValue());
            NodeKey desiredKey = parentNode.key().withId(frozenUuidString);
            Name name = path.getLastSegment().getName();

            if (ModeShapeLexicon.SHARE.equals(primaryTypeName)) {
                // Need to link to the existing node with the identifier ...
                parentNode.mutable().linkChild(cache, desiredKey, name);
                existingNode = session.node(desiredKey, (Type)null, parentNode.key());
            } else {
                // Otherwise recreate/restore the new child ...
                Property primaryType = propFactory.create(JcrLexicon.PRIMARY_TYPE, primaryTypeName);
                MutableCachedNode newChild = parentNode.mutable().createChild(cache, desiredKey, name, primaryType);
                existingNode = session.node(newChild, (Type)null, parentNode.key());
            }
            nodeToCheckLock = parentNode;
        }
View Full Code Here

Examples of org.modeshape.jcr.value.PropertyFactory

        if (!this.getMixinTypes(cache).contains(ModeShapeLexicon.ACCESS_CONTROLLABLE)) {
            addMixin(cache, ModeShapeLexicon.ACCESS_CONTROLLABLE);
        }
        ChildReference aclNodeRef = getChildReferences(cache).getChild(ModeShapeLexicon.ACCESS_LIST_NODE_NAME);
        MutableCachedNode aclNode = null;
        PropertyFactory propertyFactory = cache.getContext().getPropertyFactory();
        ChildReferences permissionsReferences = null;
        if (aclNodeRef != null) {
            aclNode = cache.mutable(aclNodeRef.getKey());
            permissionsReferences = aclNode.getChildReferences(cache);
            //there was a previous ACL node present so iterate it and remove all permissions which are not found in the map
            for (ChildReference permissionRef : permissionsReferences) {
                CachedNode permissionNode = cache.getNode(permissionRef);
                String principalName = permissionNode.getProperty(ModeShapeLexicon.PERMISSION_PRINCIPAL_NAME, cache)
                                                     .getFirstValue().toString();
                if (!privilegesByPrincipalName.containsKey(principalName)) {
                    permissionChanges().principalRemoved(principalName);
                    NodeKey permissionNodeKey = permissionNode.getKey();
                    aclNode.removeChild(cache, permissionNodeKey);
                    cache.destroy(permissionNodeKey);
                }
            }
        } else {
            org.modeshape.jcr.value.Property primaryType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE,
                                                                                  ModeShapeLexicon.ACCESS_LIST_NODE_TYPE);
            aclNode = this.createChild(cache, null, ModeShapeLexicon.ACCESS_LIST_NODE_NAME, primaryType);
            permissionsReferences = ImmutableChildReferences.EmptyChildReferences.INSTANCE;
        }

        //go through the new map of permissions and update/create the internal nodes
        NameFactory nameFactory = cache.getContext().getValueFactories().getNameFactory();

        for (String principal : privilegesByPrincipalName.keySet()) {
            Name principalName = nameFactory.create(principal);
            ChildReference permissionRef = permissionsReferences.getChild(principalName);
            if (permissionRef == null) {
                //this is a new principal
                permissionChanges().principalAdded(principal);
                org.modeshape.jcr.value.Property primaryType = propertyFactory.create(
                        JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.PERMISSION);
                Property principalProp = propertyFactory.create(ModeShapeLexicon.PERMISSION_PRINCIPAL_NAME,
                                                                    principal);
                Property privileges = propertyFactory.create(ModeShapeLexicon.PERMISSION_PRIVILEGES_NAME,
                                                             privilegesByPrincipalName.get(principal));
                aclNode.createChild(cache, null, principalName, primaryType, principalProp, privileges);
            } else {
                //there already is a child node for this principal, so we just need to update its privileges
                MutableCachedNode permissionNode = cache.mutable(permissionRef.getKey());
                Property privileges = propertyFactory.create(ModeShapeLexicon.PERMISSION_PRIVILEGES_NAME,
                                                             privilegesByPrincipalName.get(principal));
                permissionNode.setProperty(cache, privileges);
            }
        }
        return permissionChanges();
View Full Code Here
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.