Search in sources :

Example 6 with Status

use of org.alfresco.service.cmr.repository.NodeRef.Status in project alfresco-repository by Alfresco.

the class DbNodeServiceImpl method getNodeStatus.

@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public Status getNodeStatus(NodeRef nodeRef) {
    ParameterCheck.mandatory("nodeRef", nodeRef);
    NodeRef.Status status = nodeDAO.getNodeRefStatus(nodeRef);
    return status;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Status(org.alfresco.service.cmr.repository.NodeRef.Status) Extend(org.alfresco.traitextender.Extend)

Example 7 with Status

use of org.alfresco.service.cmr.repository.NodeRef.Status in project alfresco-repository by Alfresco.

the class NodeServiceTest method testArchiveAndRestore.

/**
 * Tests archive and restore of simple hierarchy, checking that references and IDs are
 * used correctly.
 */
@Test
public void testArchiveAndRestore() {
    // First create a node structure (a very simple one) and record the references and IDs
    final NodeRef[] liveNodeRefs = new NodeRef[10];
    final NodeRef[] archivedNodeRefs = new NodeRef[10];
    final NodeRef workspaceRootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    final NodeRef archiveRootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE);
    buildNodeHierarchy(workspaceRootNodeRef, liveNodeRefs);
    // Get the node status details
    Long txnIdCreate = null;
    for (int i = 0; i < liveNodeRefs.length; i++) {
        StoreRef archivedStoreRef = archiveRootNodeRef.getStoreRef();
        archivedNodeRefs[i] = new NodeRef(archivedStoreRef, liveNodeRefs[i].getId());
        Status liveStatus = nodeService.getNodeStatus(liveNodeRefs[i]);
        Status archivedStatus = nodeService.getNodeStatus(archivedNodeRefs[i]);
        // Check that live node statuses are correct
        assertNotNull("'Live' node " + i + " status does not exist.", liveStatus);
        assertFalse("'Live' node " + i + " should be node be deleted", liveStatus.isDeleted());
        assertNull("'Archived' node " + i + " should not (yet) exist.", archivedStatus);
        // Nodes in the hierarchy must be in the same txn
        if (txnIdCreate == null) {
            txnIdCreate = liveStatus.getDbTxnId();
        } else {
            // Make sure that the DB Txn ID is the same
            assertEquals("DB TXN ID should have been the same for the hierarchy. ", txnIdCreate, liveStatus.getDbTxnId());
        }
    }
    // Archive the top-level node
    nodeService.deleteNode(liveNodeRefs[0]);
    // Recheck the nodes and make sure that all the 'live' nodes are deleted
    Long txnIdDelete = null;
    for (int i = 0; i < liveNodeRefs.length; i++) {
        Status liveStatus = nodeService.getNodeStatus(liveNodeRefs[i]);
        Status archivedStatus = nodeService.getNodeStatus(archivedNodeRefs[i]);
        // Check that the ghosted nodes are marked as deleted and the archived nodes are not
        assertNotNull("'Live' node " + i + " status does not exist.", liveStatus);
        assertTrue("'Live' node " + i + " should be deleted (ghost entries)", liveStatus.isDeleted());
        assertNotNull("'Archived' node " + i + " does not exist.", archivedStatus);
        assertFalse("'Archived' node " + i + " should be undeleted", archivedStatus.isDeleted());
        // Check that both old (ghosted deletes) and new nodes are in the same txn
        if (txnIdDelete == null) {
            txnIdDelete = liveStatus.getDbTxnId();
        } else {
            // Make sure that the DB Txn ID is the same
            assertEquals("DB TXN ID should have been the same for the deleted (ghost) nodes. ", txnIdDelete, liveStatus.getDbTxnId());
        }
        assertEquals("DB TXN ID should be the same for deletes across the hierarchy", txnIdDelete, archivedStatus.getDbTxnId());
    }
    // Restore the top-level node
    nodeService.restoreNode(archivedNodeRefs[0], workspaceRootNodeRef, null, null);
    // Recheck the nodes and make sure that all the 'archived' nodes are deleted and the 'live' nodes are back
    Long txnIdRestore = null;
    for (int i = 0; i < liveNodeRefs.length; i++) {
        Status liveStatus = nodeService.getNodeStatus(liveNodeRefs[i]);
        StoreRef archivedStoreRef = archiveRootNodeRef.getStoreRef();
        archivedNodeRefs[i] = new NodeRef(archivedStoreRef, liveNodeRefs[i].getId());
        Status archivedStatus = nodeService.getNodeStatus(archivedNodeRefs[i]);
        // Check that the ghosted nodes are marked as deleted and the archived nodes are not
        assertNotNull("'Live' node " + i + " status does not exist.", liveStatus);
        assertFalse("'Live' node " + i + " should not be deleted", liveStatus.isDeleted());
        assertNotNull("'Archived' node " + i + " does not exist.", archivedStatus);
        assertTrue("'Archived' node " + i + " should be deleted (ghost entry)", archivedStatus.isDeleted());
        // Check that both old (ghosted deletes) and new nodes are in the same txn
        if (txnIdRestore == null) {
            txnIdRestore = liveStatus.getDbTxnId();
        } else {
            // Make sure that the DB Txn ID is the same
            assertEquals("DB TXN ID should have been the same for the restored nodes. ", txnIdRestore, liveStatus.getDbTxnId());
        }
        assertEquals("DB TXN ID should be the same for the ex-archived (now-ghost) nodes. ", txnIdRestore, archivedStatus.getDbTxnId());
    }
}
Also used : Status(org.alfresco.service.cmr.repository.NodeRef.Status) NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) CannedQueryDAOTest(org.alfresco.repo.domain.query.CannedQueryDAOTest) Test(org.junit.Test)

Example 8 with Status

use of org.alfresco.service.cmr.repository.NodeRef.Status in project alfresco-repository by Alfresco.

the class NodeServiceTest method testCascadeUpdate.

@Test
public void testCascadeUpdate() {
    NodeRef nodeRef1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()), ContentModel.TYPE_CONTAINER).getChildRef();
    assertFalse(nodeService.getAspects(nodeRef1).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    Map<QName, Serializable> aspectProps = new HashMap<QName, Serializable>();
    ArrayList<NodeRef> cats = new ArrayList<NodeRef>();
    cats.add(nodeRef1);
    aspectProps.put(ContentModel.PROP_CATEGORIES, cats);
    nodeService.addAspect(nodeRef1, ContentModel.ASPECT_GEN_CLASSIFIABLE, aspectProps);
    assertTrue(nodeService.getAspects(nodeRef1).contains(ContentModel.ASPECT_GEN_CLASSIFIABLE));
    assertFalse(nodeService.getAspects(nodeRef1).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    NodeRef nodeRef2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()), ContentModel.TYPE_CONTAINER).getChildRef();
    NodeRef nodeRef3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()), ContentModel.TYPE_CONTAINER).getChildRef();
    NodeRef nodeRef4 = nodeService.createNode(nodeRef2, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()), ContentModel.TYPE_CONTAINER).getChildRef();
    assertFalse(nodeService.getAspects(nodeRef2).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    assertFalse(nodeService.getAspects(nodeRef3).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    assertFalse(nodeService.getAspects(nodeRef4).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    nodeService.moveNode(nodeRef4, nodeRef3, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()));
    assertFalse(nodeService.getAspects(nodeRef2).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    assertFalse(nodeService.getAspects(nodeRef3).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    assertTrue(nodeService.getAspects(nodeRef4).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    Status status = nodeService.getNodeStatus(nodeRef4);
    Long lastCascadeTx = (Long) nodeService.getProperty(nodeRef4, ContentModel.PROP_CASCADE_TX);
    assertTrue(status.getDbTxnId().equals(lastCascadeTx));
    assertTrue(nodeService.getProperty(nodeRef4, ContentModel.PROP_CASCADE_CRC) != null);
    Long crcIn3 = (Long) nodeService.getProperty(nodeRef4, ContentModel.PROP_CASCADE_CRC);
    nodeService.moveNode(nodeRef4, nodeRef2, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()));
    Long crcIn2 = (Long) nodeService.getProperty(nodeRef4, ContentModel.PROP_CASCADE_CRC);
    assertFalse(crcIn2.equals(crcIn3));
    NodeRef nodeRef5 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "5"), ContentModel.TYPE_CONTAINER).getChildRef();
    NodeRef nodeRef6 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "6"), ContentModel.TYPE_CONTAINER).getChildRef();
    NodeRef nodeRef7 = nodeService.createNode(nodeRef5, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "7"), ContentModel.TYPE_CONTAINER).getChildRef();
    NodeRef nodeRef8 = nodeService.createNode(nodeRef5, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "8"), ContentModel.TYPE_CONTAINER).getChildRef();
    assertFalse(nodeService.getAspects(nodeRef5).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    assertFalse(nodeService.getAspects(nodeRef6).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    assertFalse(nodeService.getAspects(nodeRef7).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    assertFalse(nodeService.getAspects(nodeRef8).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    nodeService.addChild(nodeRef6, nodeRef7, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()));
    assertFalse(nodeService.getAspects(nodeRef5).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    assertFalse(nodeService.getAspects(nodeRef6).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    assertTrue(nodeService.getAspects(nodeRef7).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    assertFalse(nodeService.getAspects(nodeRef8).contains(ContentModel.ASPECT_CASCADE_UPDATE));
    Long doubleLinkCRC = (Long) nodeService.getProperty(nodeRef7, ContentModel.PROP_CASCADE_CRC);
    assertNotNull(doubleLinkCRC);
    nodeService.removeChild(nodeRef6, nodeRef7);
    Long singleLinkCRC = (Long) nodeService.getProperty(nodeRef7, ContentModel.PROP_CASCADE_CRC);
    assertFalse(doubleLinkCRC.equals(singleLinkCRC));
    nodeService.addChild(nodeRef6, nodeRef7, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()));
    Long doubleLinkCRC2 = (Long) nodeService.getProperty(nodeRef7, ContentModel.PROP_CASCADE_CRC);
    assertFalse(singleLinkCRC.equals(doubleLinkCRC2));
    nodeService.removeChild(nodeRef6, nodeRef7);
    Long singleLinkCRC2 = (Long) nodeService.getProperty(nodeRef7, ContentModel.PROP_CASCADE_CRC);
    assertFalse(doubleLinkCRC2.equals(singleLinkCRC2));
}
Also used : Status(org.alfresco.service.cmr.repository.NodeRef.Status) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) CannedQueryDAOTest(org.alfresco.repo.domain.query.CannedQueryDAOTest) Test(org.junit.Test)

Aggregations

Status (org.alfresco.service.cmr.repository.NodeRef.Status)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 QName (org.alfresco.service.namespace.QName)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)2 CannedQueryDAOTest (org.alfresco.repo.domain.query.CannedQueryDAOTest)2 Test (org.junit.Test)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 CRC32 (java.util.zip.CRC32)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 ChildAssocRefQueryCallback (org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback)1 Visibility (org.alfresco.repo.model.filefolder.HiddenAspect.Visibility)1 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)1