Java Code Examples for org.alfresco.service.cmr.version.Version#getFrozenStateNodeRef()
The following examples show how to use
org.alfresco.service.cmr.version.Version#getFrozenStateNodeRef() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VersionServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testAR807() { QName prop = QName.createQName("http://www.alfresco.org/test/versionstorebasetest/1.0", "intProp"); ChildAssociationRef childAssociation = nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("http://www.alfresco.org/test/versionstorebasetest/1.0", "integerTest"), TEST_TYPE_QNAME); NodeRef newNode = childAssociation.getChildRef(); nodeService.setProperty(newNode, prop, 1); Object editionCode = nodeService.getProperty(newNode, prop); assertEquals(editionCode.getClass(), Integer.class); Map<String, Serializable> versionProps = new HashMap<String, Serializable>(1); versionProps.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR); Version version = versionService.createVersion(newNode, versionProps); NodeRef versionNodeRef = version.getFrozenStateNodeRef(); assertNotNull(versionNodeRef); Object editionCodeArchive = nodeService.getProperty(versionNodeRef, prop); assertEquals(editionCodeArchive.getClass(), Integer.class); }
Example 2
Source File: NodeServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test getParentAssocs */ @Test public void testGetParentAssocs() { // Create a new versionable node NodeRef versionableNode = createNewVersionableNode(); // Create a new version Version version = createVersion(versionableNode, this.versionProperties); NodeRef nodeRef = version.getFrozenStateNodeRef(); List<ChildAssociationRef> results = this.versionStoreNodeService.getParentAssocs(nodeRef); assertNotNull(results); assertEquals(1, results.size()); ChildAssociationRef childAssoc = results.get(0); assertEquals(nodeRef, childAssoc.getChildRef()); NodeRef versionStoreRoot = this.dbNodeService.getRootNode(this.versionService.getVersionStoreReference()); assertEquals(versionStoreRoot, childAssoc.getParentRef()); }
Example 3
Source File: NodeServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test getPrimaryParent */ @Test public void testGetPrimaryParent() { // Create a new versionable node NodeRef versionableNode = createNewVersionableNode(); // Create a new version Version version = createVersion(versionableNode, this.versionProperties); NodeRef nodeRef = version.getFrozenStateNodeRef(); ChildAssociationRef childAssoc = this.versionStoreNodeService.getPrimaryParent(nodeRef); assertNotNull(childAssoc); assertEquals(nodeRef, childAssoc.getChildRef()); NodeRef versionStoreRoot = this.dbNodeService.getRootNode(this.versionService.getVersionStoreReference()); assertEquals(versionStoreRoot, childAssoc.getParentRef()); }
Example 4
Source File: EditionServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** {@inheritDoc} */ public Map<QName, Serializable> getVersionedMetadatas(Version version) { NodeRef frozenNodeRef = version.getFrozenStateNodeRef(); if (frozenNodeRef.getStoreRef().getIdentifier().equals("lightWeightVersionStore")) { // The data stored belonged to the old version store Map<String, Serializable> versionProps = version.getVersionProperties(); } if(ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(nodeService.getType(frozenNodeRef))) { // for the mlContainer, the properties are set as a version properties Map<String, Serializable> properties = version.getVersionProperties(); // The returned map of this method need a QName type key, not a String. Map<QName, Serializable> convertedProperties = new HashMap<QName, Serializable>(properties.size()); // perform the convertion for(Map.Entry<String, Serializable> entry : properties.entrySet()) { convertedProperties.put( QName.createQName(entry.getKey()), entry.getValue()); } return convertedProperties; } else { // for any other type of node, the properties are set as versioned metadata return versionNodeService.getProperties(frozenNodeRef); } }
Example 5
Source File: CMISNodeInfoImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public NodeRef getLatestVersionNodeRef(boolean major) { if (!major) { return getLatestNonMajorVersionNodeRef(); } VersionHistory versionHistory = getVersionHistory(); // if there is no history, return the current version if (versionHistory == null) { // there are no versions return getLatestNonMajorVersionNodeRef(); } // find the latest major version for (Version version : versionHistory.getAllVersions()) { if (version.getVersionType() == VersionType.MAJOR) { return version.getFrozenStateNodeRef(); } } throw new CmisObjectNotFoundException("There is no major version!"); }
Example 6
Source File: ContentServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Test getReader */ @Test public void testGetReader() { // Create a new versionable node NodeRef versionableNode = createNewVersionableNode(); // Create a new version Version version = createVersion(versionableNode, this.versionProperties); NodeRef versionNodeRef = version.getFrozenStateNodeRef(); // Get the content reader for the frozen node ContentReader contentReader = this.contentService.getReader(versionNodeRef, ContentModel.PROP_CONTENT); assertNotNull(contentReader); assertEquals(TEST_CONTENT, contentReader.getContentString()); // Now update the content and verison again ContentWriter contentWriter = this.contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, true); assertNotNull(contentWriter); contentWriter.putContent(UPDATED_CONTENT); Version version2 = createVersion(versionableNode, this.versionProperties); NodeRef version2NodeRef = version2.getFrozenStateNodeRef(); // Get the content reader for the new verisoned content ContentReader contentReader2 = this.contentService.getReader(version2NodeRef, ContentModel.PROP_CONTENT); assertNotNull(contentReader2); assertEquals(UPDATED_CONTENT, contentReader2.getContentString()); }
Example 7
Source File: VersionServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Test retrieving the current version for a node with multiple versions */ @Test public void testGetCurrentVersion() { NodeRef versionableNode = createNewVersionableNode(); createVersion(versionableNode); createVersion(versionableNode); createVersion(versionableNode); VersionHistory vh = this.versionService.getVersionHistory(versionableNode); Version version = vh.getRootVersion(); // Get current version from live node NodeRef node = version.getVersionedNodeRef(); Version currentVersion = versionService.getCurrentVersion(node); assertNotNull("Failed to retrieve the current version from the head", currentVersion); try { // Get current version from the version node (frozen state version node) - not allowed (MNT-15447) node = version.getFrozenStateNodeRef(); currentVersion = versionService.getCurrentVersion(node); fail("Getting the current version is only allowed on live nodes, not on version nodes."); } catch (IllegalArgumentException ex) { // expected } }
Example 8
Source File: VersionServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Check permissions for the frozen node if the store protocol is swapped from "version" to "workspace" * MNT-6877 */ @Test public void testHasPermissionSwappedProtocol() { AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); if(!authenticationDAO.userExists(USER_NAME_A)) { authenticationService.createAuthentication(USER_NAME_A, PWD_A.toCharArray()); } permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.READ, true); permissionService.setInheritParentPermissions(rootNodeRef, true); // Create a new versionable node NodeRef versionableNode = createNewVersionableNode(); // Create a new version Version version = createVersion(versionableNode, versionProperties); NodeRef versionNodeRef = version.getFrozenStateNodeRef(); // Swap the protocol NodeRef versionNodeRefSwapped = new NodeRef(StoreRef.PROTOCOL_WORKSPACE, versionNodeRef.getStoreRef().getIdentifier(), versionNodeRef.getId()); // Check permission for admin assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(versionNodeRefSwapped, PermissionService.READ)); // Check permission for user AuthenticationUtil.setFullyAuthenticatedUser(USER_NAME_A); assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(versionNodeRefSwapped, PermissionService.READ)); // Remove permissions for user permissionService.setInheritParentPermissions(versionableNode, false); // Check permission for user AuthenticationUtil.setFullyAuthenticatedUser(USER_NAME_A); assertEquals(AccessStatus.DENIED, permissionService.hasPermission(versionNodeRefSwapped, PermissionService.READ)); }
Example 9
Source File: NodeVersionsRelation.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@WebApiDescription(title = "Download version content", description = "Download version content") @BinaryProperties({ "content" }) @Override public BinaryResource readProperty(String nodeId, String versionId, Parameters parameters) { Version v = findVersion(nodeId, versionId); if (v != null) { NodeRef versionNodeRef = v.getFrozenStateNodeRef(); return nodes.getContent(versionNodeRef, parameters, true); // TODO should we record version downloads ? } throw new EntityNotFoundException(nodeId+"-"+versionId); }
Example 10
Source File: DiscussableAspect.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void afterVersionRevert(NodeRef nodeRef, Version version) { NodeRef versionNodeRef = version.getFrozenStateNodeRef(); if (!this.nodeService.hasAspect(versionNodeRef, ForumModel.ASPECT_DISCUSSABLE)) { return; } // Get the discussion assoc references from the version store List<ChildAssociationRef> childAssocRefs = this.nodeService.getChildAssocs(VersionUtil.convertNodeRef(versionNodeRef), ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL); for (ChildAssociationRef childAssocRef : childAssocRefs) { // Get the child reference NodeRef childRef = childAssocRef.getChildRef(); NodeRef referencedNode = (NodeRef) this.dbNodeService.getProperty(childRef, ContentModel.PROP_REFERENCE); if (referencedNode != null && this.nodeService.exists(referencedNode) == false) { StoreRef orginalStoreRef = referencedNode.getStoreRef(); NodeRef archiveRootNodeRef = this.nodeService.getStoreArchiveNode(orginalStoreRef); if (archiveRootNodeRef == null) { // Store doesn't support archiving continue; } NodeRef archivedNodeRef = new NodeRef(archiveRootNodeRef.getStoreRef(), referencedNode.getId()); if (!this.nodeService.exists(archivedNodeRef) || !nodeService.hasAspect(archivedNodeRef, ContentModel.ASPECT_ARCHIVED)) { // Node doesn't support archiving or it was deleted within parent node. continue; } NodeRef existingChild = this.nodeService.getChildByName(nodeRef, childAssocRef.getTypeQName(), this.nodeService .getProperty(archivedNodeRef, ContentModel.PROP_NAME).toString()); if (existingChild != null) { this.nodeService.deleteNode(existingChild); } this.nodeService.restoreNode(archivedNodeRef, null, null, null); } } }
Example 11
Source File: BaseVersionStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Checkd the validity of a new version * * @param beforeVersionTime the time snap shot before the version was created * @param newVersion the new version * @param versionableNode the versioned node */ protected void checkVersion(long beforeVersionTime, String expectedVersionLabel, Version newVersion, NodeRef versionableNode) { assertNotNull(newVersion); // Check the version label assertEquals( "The expected version label was not used.", expectedVersionLabel, newVersion.getVersionLabel()); // Check the created date long afterVersionTime = System.currentTimeMillis(); long createdDate = newVersion.getFrozenModifiedDate().getTime(); if (createdDate < beforeVersionTime || createdDate > afterVersionTime) { fail("The created date of the version is incorrect."); } // Check the creator assertEquals(AuthenticationUtil.getAdminUserName(), newVersion.getFrozenModifier()); // Check the metadata properties of the version Map<String, Serializable> props = newVersion.getVersionProperties(); assertNotNull("The version properties collection should not be null.", props); if (versionProperties != null) { // TODO sort this out - need to check for the reserved properties too //assertEquals(versionProperties.size(), props.size()); for (String key : versionProperties.keySet()) { assertEquals( versionProperties.get(key), newVersion.getVersionProperty(key)); } } // Check that the node reference is correct NodeRef nodeRef = newVersion.getFrozenStateNodeRef(); assertNotNull(nodeRef); // Switch VersionStore depending on configured impl if (versionService.getVersionStoreReference().getIdentifier().equals(Version2Model.STORE_ID)) { // V2 version store (eg. workspace://version2Store) assertEquals( Version2Model.STORE_ID, nodeRef.getStoreRef().getIdentifier()); assertEquals( Version2Model.STORE_PROTOCOL, nodeRef.getStoreRef().getProtocol()); assertNotNull(nodeRef.getId()); } else if (versionService.getVersionStoreReference().getIdentifier().equals(VersionModel.STORE_ID)) { // Deprecated V1 version store (eg. workspace://lightWeightVersionStore) assertEquals( VersionModel.STORE_ID, nodeRef.getStoreRef().getIdentifier()); assertEquals( VersionModel.STORE_PROTOCOL, nodeRef.getStoreRef().getProtocol()); assertNotNull(nodeRef.getId()); } }
Example 12
Source File: CheckOutCheckInServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test checkIn */ @Test public void testCheckIn() { NodeRef workingCopy = checkout(); // Test standard check-in Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(); versionProperties.put(Version.PROP_DESCRIPTION, "This is a test version"); cociService.checkin(workingCopy, versionProperties); // Test check-in with content NodeRef workingCopy3 = checkout(); nodeService.setProperty(workingCopy3, PROP_NAME_QNAME, TEST_VALUE_2); nodeService.setProperty(workingCopy3, PROP2_QNAME, TEST_VALUE_3); ContentWriter tempWriter = this.contentService.getWriter(workingCopy3, ContentModel.PROP_CONTENT, false); assertNotNull(tempWriter); tempWriter.putContent(CONTENT_2); String contentUrl = tempWriter.getContentUrl(); Map<String, Serializable> versionProperties3 = new HashMap<String, Serializable>(); versionProperties3.put(Version.PROP_DESCRIPTION, "description"); versionProperties3.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR); NodeRef origNodeRef = cociService.checkin(workingCopy3, versionProperties3, contentUrl, true); assertNotNull(origNodeRef); // Check the checked in content ContentReader contentReader = this.contentService.getReader(origNodeRef, ContentModel.PROP_CONTENT); assertNotNull(contentReader); assertEquals(CONTENT_2, contentReader.getContentString()); // Check that the version history is correct Version version = this.versionService.getCurrentVersion(origNodeRef); assertNotNull(version); assertEquals("description", version.getDescription()); assertEquals(VersionType.MAJOR, version.getVersionType()); NodeRef versionNodeRef = version.getFrozenStateNodeRef(); assertNotNull(versionNodeRef); // Check the verioned content ContentReader versionContentReader = this.contentService.getReader(versionNodeRef, ContentModel.PROP_CONTENT); assertNotNull(versionContentReader); assertEquals(CONTENT_2, versionContentReader.getContentString()); // Check that the name is not updated during the check-in assertEquals(TEST_VALUE_2, nodeService.getProperty(versionNodeRef, PROP_NAME_QNAME)); assertEquals(TEST_VALUE_2, nodeService.getProperty(origNodeRef, PROP_NAME_QNAME)); // Check that the other properties are updated during the check-in assertEquals(TEST_VALUE_3, nodeService.getProperty(versionNodeRef, PROP2_QNAME)); assertEquals(TEST_VALUE_3, nodeService.getProperty(origNodeRef, PROP2_QNAME)); // Cancel the check out after is has been left checked out cociService.cancelCheckout(workingCopy3); // Test keep checked out flag NodeRef workingCopy2 = checkout(); Map<String, Serializable> versionProperties2 = new HashMap<String, Serializable>(); versionProperties2.put(Version.PROP_DESCRIPTION, "Another version test"); this.cociService.checkin(workingCopy2, versionProperties2, null, true); this.cociService.checkin(workingCopy2, new HashMap<String, Serializable>(), null, true); }
Example 13
Source File: CheckOutCheckInServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void testCheckInVersionedNode_MNT_8789() { String versionDescription = "This is a test version"; // Create a node as the "A" user NodeRef nodeA = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<NodeRef>() { @Override public NodeRef doWork() throws Exception { return transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() { public NodeRef execute() throws Exception { AuthenticationUtil.setFullyAuthenticatedUser(userName); NodeRef a = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}NodeForA"), ContentModel.TYPE_CONTENT ).getChildRef(); nodeService.addAspect(a, ContentModel.ASPECT_AUDITABLE, null); nodeService.addAspect(a, ContentModel.ASPECT_VERSIONABLE, null); return a; } } ); } }, this.userName); // Check that it's owned and modified by test user assertEquals(this.userName, nodeService.getProperty(nodeA, ContentModel.PROP_CREATOR)); assertEquals(this.userName, nodeService.getProperty(nodeA, ContentModel.PROP_MODIFIER)); assertEquals(true, nodeService.hasAspect(nodeA, ContentModel.ASPECT_VERSIONABLE)); // Checkout and check in by admin AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); NodeRef workingCopy = cociService.checkout(nodeA); Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(); versionProperties.put(Version.PROP_DESCRIPTION, versionDescription); cociService.checkin(workingCopy, versionProperties); // Ensure it's still owned by test user assertEquals(this.userName, nodeService.getProperty(nodeA, ContentModel.PROP_CREATOR)); // Modified by admin, but as nothing changed, test user will be put into version assertEquals(this.userName, nodeService.getProperty(nodeA, ContentModel.PROP_MODIFIER)); assertEquals(true, nodeService.hasAspect(nodeA, ContentModel.ASPECT_VERSIONABLE)); // Save the modified date Serializable modifiedDate = nodeService.getProperty(nodeA, ContentModel.PROP_MODIFIED); // Now check the version Version version = this.versionService.getCurrentVersion(nodeA); assertNotNull(version); assertEquals(versionDescription, version.getDescription()); // Admin checked in the node, but as the working copy was not modified, the modifier should not change assertEquals(this.userName, version.getFrozenModifier()); // The date should NOT have changed, as nothing was changed in the working copy assertEquals(true, version.getFrozenModifiedDate().equals(modifiedDate)); NodeRef versionNodeRef = version.getFrozenStateNodeRef(); assertNotNull(versionNodeRef); nodeService.deleteNode(nodeA); AuthenticationUtil.setFullyAuthenticatedUser(this.userName); }
Example 14
Source File: VersionServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 3 votes |
/** * Check read permission for the frozen node */ @Test public void testHasPermission() { AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); if(!authenticationDAO.userExists(USER_NAME_A)) { authenticationService.createAuthentication(USER_NAME_A, PWD_A.toCharArray()); } permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.READ, true); permissionService.setInheritParentPermissions(rootNodeRef, true); // Create a new versionable node NodeRef versionableNode = createNewVersionableNode(); // Create a new version Version version = createVersion(versionableNode, versionProperties); NodeRef versionNodeRef = version.getFrozenStateNodeRef(); assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(versionNodeRef, PermissionService.READ)); AuthenticationUtil.setFullyAuthenticatedUser(USER_NAME_A); assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(versionNodeRef, PermissionService.READ)); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); permissionService.setInheritParentPermissions(versionableNode, false); assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(versionNodeRef, PermissionService.READ)); AuthenticationUtil.setFullyAuthenticatedUser(USER_NAME_A); assertEquals(AccessStatus.DENIED, permissionService.hasPermission(versionNodeRef, PermissionService.READ)); }