Search in sources :

Example 1 with NodeVersionKey

use of org.alfresco.repo.domain.node.NodeVersionKey in project alfresco-repository by Alfresco.

the class NodeDAOImpl method selectNodeAspects.

@Override
protected Map<NodeVersionKey, Set<QName>> selectNodeAspects(Set<Long> nodeIds) {
    if (nodeIds.size() == 0) {
        return Collections.emptyMap();
    }
    NodeAspectsEntity aspects = new NodeAspectsEntity();
    aspects.setNodeIds(new ArrayList<Long>(nodeIds));
    List<NodeAspectsEntity> rows = template.selectList(SELECT_NODE_ASPECTS, aspects);
    Map<NodeVersionKey, Set<QName>> results = new HashMap<NodeVersionKey, Set<QName>>(rows.size() * 2);
    for (NodeAspectsEntity nodeAspectsEntity : rows) {
        Long nodeId = nodeAspectsEntity.getNodeId();
        Long nodeVersion = nodeAspectsEntity.getNodeVersion();
        NodeVersionKey nodeVersionKey = new NodeVersionKey(nodeId, nodeVersion);
        if (results.containsKey(nodeVersionKey)) {
            throw new IllegalStateException("Found existing key while querying for node aspects: " + nodeIds);
        }
        Set<Long> aspectIds = new HashSet<Long>(nodeAspectsEntity.getAspectQNameIds());
        Set<QName> aspectQNames = qnameDAO.convertIdsToQNames(aspectIds);
        results.put(nodeVersionKey, aspectQNames);
    }
    return results;
}
Also used : NodeAspectsEntity(org.alfresco.repo.domain.node.NodeAspectsEntity) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) NodeVersionKey(org.alfresco.repo.domain.node.NodeVersionKey) HashSet(java.util.HashSet)

Example 2 with NodeVersionKey

use of org.alfresco.repo.domain.node.NodeVersionKey in project alfresco-repository by Alfresco.

the class NodeDAOImpl method makePersistentPropertiesMap.

/**
 * Pull out the key-value pairs from the rows
 */
private Map<NodeVersionKey, Map<NodePropertyKey, NodePropertyValue>> makePersistentPropertiesMap(List<NodePropertyEntity> rows) {
    Map<NodeVersionKey, Map<NodePropertyKey, NodePropertyValue>> results = new HashMap<NodeVersionKey, Map<NodePropertyKey, NodePropertyValue>>(3);
    for (NodePropertyEntity row : rows) {
        Long nodeId = row.getNodeId();
        Long nodeVersion = row.getNodeVersion();
        if (nodeId == null || nodeVersion == null) {
            throw new RuntimeException("Expect results with a Node and Version: " + row);
        }
        NodeVersionKey nodeTxnKey = new NodeVersionKey(nodeId, nodeVersion);
        Map<NodePropertyKey, NodePropertyValue> props = results.get(nodeTxnKey);
        if (props == null) {
            props = new HashMap<NodePropertyKey, NodePropertyValue>(17);
            results.put(nodeTxnKey, props);
        }
        props.put(row.getKey(), row.getValue());
    }
    // Done
    return results;
}
Also used : AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NodeVersionKey(org.alfresco.repo.domain.node.NodeVersionKey) HashMap(java.util.HashMap) NodePropertyKey(org.alfresco.repo.domain.node.NodePropertyKey) NodePropertyValue(org.alfresco.repo.domain.node.NodePropertyValue) NodePropertyEntity(org.alfresco.repo.domain.node.NodePropertyEntity) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with NodeVersionKey

use of org.alfresco.repo.domain.node.NodeVersionKey in project alfresco-repository by Alfresco.

the class NodeServiceTest method testCaches_ImmutableNodeCaches.

/**
 * Check that simple node property modifications advance the node caches correctly
 */
@SuppressWarnings("unchecked")
@Test
public void testCaches_ImmutableNodeCaches() throws Exception {
    final NodeRef[] nodeRefs = new NodeRef[2];
    final NodeRef workspaceRootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    buildNodeHierarchy(workspaceRootNodeRef, nodeRefs);
    final NodeRef nodeRef = nodeRefs[1];
    // Get the current node cache key
    Long nodeId = (Long) findCacheValue(nodesCache, nodeRef);
    assertNotNull("Node not found in cache", nodeId);
    Node nodeOne = (Node) findCacheValue(nodesCache, nodeId);
    assertNotNull("Node not found in cache", nodeOne);
    NodeVersionKey nodeKeyOne = nodeOne.getNodeVersionKey();
    // Get the node cached values
    Map<QName, Serializable> nodePropsOne = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyOne);
    Set<QName> nodeAspectsOne = (Set<QName>) findCacheValue(aspectsCache, nodeKeyOne);
    // Check the values
    assertEquals("The node version is incorrect", Long.valueOf(1L), nodeKeyOne.getVersion());
    assertNotNull("No cache entry for properties", nodePropsOne);
    assertNotNull("No cache entry for aspects", nodeAspectsOne);
    assertEquals("Property count incorrect", 1, nodePropsOne.size());
    assertNotNull("Expected a cm:name property", nodePropsOne.get(ContentModel.PROP_NAME));
    assertEquals("Aspect count incorrect", 1, nodeAspectsOne.size());
    assertTrue("Expected a cm:auditable aspect", nodeAspectsOne.contains(ContentModel.ASPECT_AUDITABLE));
    // Add a property
    nodeService.setProperty(nodeRef, PROP_RESIDUAL, GUID.generate());
    // Get the values for the previous version
    Map<QName, Serializable> nodePropsOneCheck = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyOne);
    Set<QName> nodeAspectsOneCheck = (Set<QName>) findCacheValue(aspectsCache, nodeKeyOne);
    assertTrue("Previous cache entries must be left alone", nodePropsOneCheck.equals(nodePropsOne));
    assertTrue("Previous cache entries must be left alone", nodeAspectsOneCheck.equals(nodeAspectsOne));
    // Get the current node cache key
    Node nodeTwo = (Node) findCacheValue(nodesCache, nodeId);
    assertNotNull("Node not found in cache", nodeTwo);
    NodeVersionKey nodeKeyTwo = nodeTwo.getNodeVersionKey();
    // Get the node cached values
    Map<QName, Serializable> nodePropsTwo = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyTwo);
    Set<QName> nodeAspectsTwo = (Set<QName>) findCacheValue(aspectsCache, nodeKeyTwo);
    // Check the values
    assertEquals("The node version is incorrect", Long.valueOf(2L), nodeKeyTwo.getVersion());
    assertNotNull("No cache entry for properties", nodePropsTwo);
    assertNotNull("No cache entry for aspects", nodeAspectsTwo);
    assertFalse("Properties must have moved on", nodePropsTwo.equals(nodePropsOne));
    assertEquals("Property count incorrect", 2, nodePropsTwo.size());
    assertNotNull("Expected a cm:name property", nodePropsTwo.get(ContentModel.PROP_NAME));
    assertNotNull("Expected a residual property", nodePropsTwo.get(PROP_RESIDUAL));
    assertTrue("Aspects must be carried", nodeAspectsTwo.equals(nodeAspectsOne));
    // Remove a property
    nodeService.removeProperty(nodeRef, PROP_RESIDUAL);
    // Get the values for the previous version
    Map<QName, Serializable> nodePropsTwoCheck = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyTwo);
    Set<QName> nodeAspectsTwoCheck = (Set<QName>) findCacheValue(aspectsCache, nodeKeyTwo);
    assertTrue("Previous cache entries must be left alone", nodePropsTwoCheck.equals(nodePropsTwo));
    assertTrue("Previous cache entries must be left alone", nodeAspectsTwoCheck.equals(nodeAspectsTwo));
    // Get the current node cache key
    Node nodeThree = (Node) findCacheValue(nodesCache, nodeId);
    assertNotNull("Node not found in cache", nodeThree);
    NodeVersionKey nodeKeyThree = nodeThree.getNodeVersionKey();
    // Get the node cached values
    Map<QName, Serializable> nodePropsThree = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyThree);
    Set<QName> nodeAspectsThree = (Set<QName>) findCacheValue(aspectsCache, nodeKeyThree);
    // Check the values
    assertEquals("The node version is incorrect", Long.valueOf(3L), nodeKeyThree.getVersion());
    assertNotNull("No cache entry for properties", nodePropsThree);
    assertNotNull("No cache entry for aspects", nodeAspectsThree);
    assertFalse("Properties must have moved on", nodePropsThree.equals(nodePropsTwo));
    assertEquals("Property count incorrect", 1, nodePropsThree.size());
    assertNotNull("Expected a cm:name property", nodePropsThree.get(ContentModel.PROP_NAME));
    assertNull("Expected no residual property", nodePropsThree.get(PROP_RESIDUAL));
    assertTrue("Aspects must be carried", nodeAspectsThree.equals(nodeAspectsTwo));
    // Add an aspect
    nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
    // Get the values for the previous version
    Map<QName, Serializable> nodePropsThreeCheck = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyThree);
    Set<QName> nodeAspectsThreeCheck = (Set<QName>) findCacheValue(aspectsCache, nodeKeyThree);
    assertTrue("Previous cache entries must be left alone", nodePropsThreeCheck.equals(nodePropsThree));
    assertTrue("Previous cache entries must be left alone", nodeAspectsThreeCheck.equals(nodeAspectsThree));
    // Get the current node cache key
    Node nodeFour = (Node) findCacheValue(nodesCache, nodeId);
    assertNotNull("Node not found in cache", nodeFour);
    NodeVersionKey nodeKeyFour = nodeFour.getNodeVersionKey();
    // Get the node cached values
    Map<QName, Serializable> nodePropsFour = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyFour);
    Set<QName> nodeAspectsFour = (Set<QName>) findCacheValue(aspectsCache, nodeKeyFour);
    // Check the values
    assertEquals("The node version is incorrect", Long.valueOf(4L), nodeKeyFour.getVersion());
    assertNotNull("No cache entry for properties", nodePropsFour);
    assertNotNull("No cache entry for aspects", nodeAspectsFour);
    assertTrue("Properties must be carried", nodePropsFour.equals(nodePropsThree));
    assertFalse("Aspects must have moved on", nodeAspectsFour.equals(nodeAspectsThree));
    assertTrue("Expected cm:titled aspect", nodeAspectsFour.contains(ContentModel.ASPECT_TITLED));
    // Remove an aspect
    nodeService.removeAspect(nodeRef, ContentModel.ASPECT_TITLED);
    // Get the values for the previous version
    Map<QName, Serializable> nodePropsFourCheck = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyFour);
    Set<QName> nodeAspectsFourCheck = (Set<QName>) findCacheValue(aspectsCache, nodeKeyFour);
    assertTrue("Previous cache entries must be left alone", nodePropsFourCheck.equals(nodePropsFour));
    assertTrue("Previous cache entries must be left alone", nodeAspectsFourCheck.equals(nodeAspectsFour));
    // Get the current node cache key
    Node nodeFive = (Node) findCacheValue(nodesCache, nodeId);
    assertNotNull("Node not found in cache", nodeFive);
    NodeVersionKey nodeKeyFive = nodeFive.getNodeVersionKey();
    // Get the node cached values
    Map<QName, Serializable> nodePropsFive = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyFive);
    Set<QName> nodeAspectsFive = (Set<QName>) findCacheValue(aspectsCache, nodeKeyFive);
    // Check the values
    assertEquals("The node version is incorrect", Long.valueOf(5L), nodeKeyFive.getVersion());
    assertNotNull("No cache entry for properties", nodePropsFive);
    assertNotNull("No cache entry for aspects", nodeAspectsFive);
    assertTrue("Properties must be carried", nodePropsFive.equals(nodePropsFour));
    assertFalse("Aspects must have moved on", nodeAspectsFive.equals(nodeAspectsFour));
    assertFalse("Expected no cm:titled aspect ", nodeAspectsFive.contains(ContentModel.ASPECT_TITLED));
    // Add an aspect, some properties and secondary association
    RetryingTransactionCallback<Void> nodeSixWork = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            Map<QName, Serializable> props = new HashMap<QName, Serializable>();
            props.put(ContentModel.PROP_TITLE, "some title");
            nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, props);
            nodeService.setProperty(nodeRef, ContentModel.PROP_DESCRIPTION, "Some description");
            // QName.createQName(TEST_PREFIX, "secondary"));
            return null;
        }
    };
    txnService.getRetryingTransactionHelper().doInTransaction(nodeSixWork);
    // Get the values for the previous version
    Map<QName, Serializable> nodePropsFiveCheck = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyFive);
    Set<QName> nodeAspectsFiveCheck = (Set<QName>) findCacheValue(aspectsCache, nodeKeyFive);
    assertTrue("Previous cache entries must be left alone", nodePropsFiveCheck.equals(nodePropsFive));
    assertTrue("Previous cache entries must be left alone", nodeAspectsFiveCheck.equals(nodeAspectsFive));
    // Get the current node cache key
    Node nodeSix = (Node) findCacheValue(nodesCache, nodeId);
    assertNotNull("Node not found in cache", nodeSix);
    NodeVersionKey nodeKeySix = nodeSix.getNodeVersionKey();
    // Get the node cached values
    Map<QName, Serializable> nodePropsSix = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeySix);
    Set<QName> nodeAspectsSix = (Set<QName>) findCacheValue(aspectsCache, nodeKeySix);
    // Check the values
    assertEquals("The node version is incorrect", Long.valueOf(6L), nodeKeySix.getVersion());
    assertNotNull("No cache entry for properties", nodePropsSix);
    assertNotNull("No cache entry for aspects", nodeAspectsSix);
    assertFalse("Properties must have moved on", nodePropsSix.equals(nodePropsFive));
    assertEquals("Property count incorrect", 3, nodePropsSix.size());
    assertNotNull("Expected a cm:name property", nodePropsSix.get(ContentModel.PROP_NAME));
    assertNotNull("Expected a cm:title property", nodePropsSix.get(ContentModel.PROP_TITLE));
    assertNotNull("Expected a cm:description property", nodePropsSix.get(ContentModel.PROP_DESCRIPTION));
    assertFalse("Aspects must have moved on", nodeAspectsSix.equals(nodeAspectsFive));
    assertTrue("Expected cm:titled aspect ", nodeAspectsSix.contains(ContentModel.ASPECT_TITLED));
    // Remove an aspect, some properties and a secondary association
    RetryingTransactionCallback<Void> nodeSevenWork = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            nodeService.removeAspect(nodeRef, ContentModel.ASPECT_TITLED);
            nodeService.removeChild(workspaceRootNodeRef, nodeRef);
            return null;
        }
    };
    txnService.getRetryingTransactionHelper().doInTransaction(nodeSevenWork);
    // Get the values for the previous version
    Map<QName, Serializable> nodePropsSixCheck = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeySix);
    Set<QName> nodeAspectsSixCheck = (Set<QName>) findCacheValue(aspectsCache, nodeKeySix);
    assertTrue("Previous cache entries must be left alone", nodePropsSixCheck.equals(nodePropsSix));
    assertTrue("Previous cache entries must be left alone", nodeAspectsSixCheck.equals(nodeAspectsSix));
    // Get the current node cache key
    Node nodeSeven = (Node) findCacheValue(nodesCache, nodeId);
    assertNotNull("Node not found in cache", nodeSeven);
    NodeVersionKey nodeKeySeven = nodeSeven.getNodeVersionKey();
    // Get the node cached values
    Map<QName, Serializable> nodePropsSeven = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeySeven);
    Set<QName> nodeAspectsSeven = (Set<QName>) findCacheValue(aspectsCache, nodeKeySeven);
    // Check the values
    assertEquals("The node version is incorrect", Long.valueOf(7L), nodeKeySeven.getVersion());
    assertNotNull("No cache entry for properties", nodePropsSeven);
    assertNotNull("No cache entry for aspects", nodeAspectsSeven);
    assertFalse("Properties must have moved on", nodePropsSeven.equals(nodePropsSix));
    assertEquals("Property count incorrect", 1, nodePropsSeven.size());
    assertNotNull("Expected a cm:name property", nodePropsSeven.get(ContentModel.PROP_NAME));
    assertFalse("Aspects must have moved on", nodeAspectsSeven.equals(nodeAspectsSix));
    assertFalse("Expected no cm:titled aspect ", nodeAspectsSeven.contains(ContentModel.ASPECT_TITLED));
    // Modify cm:auditable
    RetryingTransactionCallback<Void> nodeEightWork = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            BehaviourFilter behaviourFilter = (BehaviourFilter) APP_CONTEXT_INIT.getApplicationContext().getBean("policyBehaviourFilter");
            // Disable behaviour for txn
            behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
            nodeService.setProperty(nodeRef, ContentModel.PROP_MODIFIER, "Fred");
            return null;
        }
    };
    txnService.getRetryingTransactionHelper().doInTransaction(nodeEightWork);
    // Get the values for the previous version
    Map<QName, Serializable> nodePropsSevenCheck = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeySeven);
    Set<QName> nodeAspectsSevenCheck = (Set<QName>) findCacheValue(aspectsCache, nodeKeySeven);
    assertTrue("Previous cache entries must be left alone", nodePropsSevenCheck.equals(nodePropsSeven));
    assertTrue("Previous cache entries must be left alone", nodeAspectsSevenCheck.equals(nodeAspectsSeven));
    // Get the current node cache key
    Node nodeEight = (Node) findCacheValue(nodesCache, nodeId);
    assertNotNull("Node not found in cache", nodeEight);
    NodeVersionKey nodeKeyEight = nodeEight.getNodeVersionKey();
    // Get the node cached values
    Map<QName, Serializable> nodePropsEight = (Map<QName, Serializable>) findCacheValue(propsCache, nodeKeyEight);
    Set<QName> nodeAspectsEight = (Set<QName>) findCacheValue(aspectsCache, nodeKeyEight);
    // Check the values
    assertEquals("The node version is incorrect", Long.valueOf(8L), nodeKeyEight.getVersion());
    assertNotNull("No cache entry for properties", nodePropsEight);
    assertNotNull("No cache entry for aspects", nodeAspectsEight);
    assertEquals("Expected change to cm:modifier", "Fred", nodeEight.getAuditableProperties().getAuditModifier());
    assertTrue("Properties must be carried", nodePropsEight.equals(nodePropsSeven));
    assertTrue("Aspects be carried", nodeAspectsEight.equals(nodeAspectsSeven));
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) VisitedNode(org.alfresco.repo.node.db.NodeHierarchyWalker.VisitedNode) Node(org.alfresco.repo.domain.node.Node) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeVersionKey(org.alfresco.repo.domain.node.NodeVersionKey) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) BehaviourFilter(org.alfresco.repo.policy.BehaviourFilter) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) PropertyMap(org.alfresco.util.PropertyMap) CannedQueryDAOTest(org.alfresco.repo.domain.query.CannedQueryDAOTest) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)3 NodeVersionKey (org.alfresco.repo.domain.node.NodeVersionKey)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 QName (org.alfresco.service.namespace.QName)2 Serializable (java.io.Serializable)1 SortedSet (java.util.SortedSet)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 MimetypeMap (org.alfresco.repo.content.MimetypeMap)1 Node (org.alfresco.repo.domain.node.Node)1 NodeAspectsEntity (org.alfresco.repo.domain.node.NodeAspectsEntity)1 NodePropertyEntity (org.alfresco.repo.domain.node.NodePropertyEntity)1 NodePropertyKey (org.alfresco.repo.domain.node.NodePropertyKey)1 NodePropertyValue (org.alfresco.repo.domain.node.NodePropertyValue)1 CannedQueryDAOTest (org.alfresco.repo.domain.query.CannedQueryDAOTest)1 VisitedNode (org.alfresco.repo.node.db.NodeHierarchyWalker.VisitedNode)1 BehaviourFilter (org.alfresco.repo.policy.BehaviourFilter)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1