Java Code Examples for org.alfresco.service.cmr.repository.NodeRef#getStoreRef()
The following examples show how to use
org.alfresco.service.cmr.repository.NodeRef#getStoreRef() .
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: NodeDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected NodeEntity selectNodeByNodeRef(NodeRef nodeRef) { StoreEntity store = new StoreEntity(); StoreRef storeRef = nodeRef.getStoreRef(); store.setProtocol(storeRef.getProtocol()); store.setIdentifier(storeRef.getIdentifier()); NodeEntity node = new NodeEntity(); // Store node.setStore(store); // UUID String uuid = nodeRef.getId(); if (uuid.length() > 36) { return null; // Avoid query failure if someone passes in a made-up UUID. // Originally for DB2 which has been EOLed, but might now be used by other databases. } node.setUuid(uuid); return template.selectOne(SELECT_NODE_BY_NODEREF, node); }
Example 2
Source File: NodeArchiveServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public NodeRef getArchivedNode(NodeRef originalNodeRef) { StoreRef orginalStoreRef = originalNodeRef.getStoreRef(); NodeRef archiveRootNodeRef = nodeService.getStoreArchiveNode(orginalStoreRef); // create the likely location of the archived node NodeRef archivedNodeRef = new NodeRef( archiveRootNodeRef.getStoreRef(), originalNodeRef.getId()); return archivedNodeRef; }
Example 3
Source File: NodeLocatorWebScriptTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private String makeUrl(NodeRef node, String locatorName) { StoreRef storeRef = node.getStoreRef(); StringBuilder url = new StringBuilder("/api/"); url.append(storeRef.getProtocol()).append("/") .append(storeRef.getIdentifier()).append("/") .append(node.getId()).append("/") .append("nodelocator").append("/") .append(locatorName); return url.toString(); }
Example 4
Source File: NodeArchiveServiceRestApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * This test method restores some deleted nodes from the archive store. */ public void testRestoreDeletedItems() throws Exception { AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); JSONObject archivedNodesJson = getArchivedNodes(); JSONObject dataJsonObj = archivedNodesJson.getJSONObject("data"); JSONArray archivedNodesArray = dataJsonObj.getJSONArray(AbstractArchivedNodeWebScript.DELETED_NODES); int archivedNodesLength = archivedNodesArray.length(); assertTrue("Insufficient archived nodes for test to run.", archivedNodesLength > 1); // Take a specific archived node and restore it. JSONObject firstArchivedNode = archivedNodesArray.getJSONObject(0); // So we have identified a specific Node in the archive that we want to restore. String nodeRefString = firstArchivedNode.getString(AbstractArchivedNodeWebScript.NODEREF); assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString)); NodeRef nodeRef = new NodeRef(nodeRefString); // This is not the StoreRef where the node originally lived e.g. workspace://SpacesStore // This is its current StoreRef i.e. archive://SpacesStore final StoreRef currentStoreRef = nodeRef.getStoreRef(); String restoreUrl = getArchiveUrl(currentStoreRef) + "/" + nodeRef.getId(); int archivedNodesCountBeforeRestore = getArchivedNodesCount(); // Send the PUT REST call. String jsonString = new JSONStringer().object() .key("restoreLocation").value("") .endObject() .toString(); Response rsp = sendRequest(new PutRequest(restoreUrl, jsonString, "application/json"), 200); assertEquals("Expected archive to shrink by one", archivedNodesCountBeforeRestore - 1, getArchivedNodesCount()); }
Example 5
Source File: UserUsageTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private void restore(NodeRef origfolderOrContentRef) { NodeRef archiveRootNode = nodeService.getStoreArchiveNode(this.rootNodeRef.getStoreRef()); NodeRef archiveNodeRef = new NodeRef(archiveRootNode.getStoreRef(), origfolderOrContentRef.getId()); nodeService.restoreNode(archiveNodeRef, null, null, null); }
Example 6
Source File: Location.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Construct * * @param nodeRef NodeRef */ public Location(NodeRef nodeRef) { ParameterCheck.mandatory("Node Ref", nodeRef); this.storeRef = nodeRef.getStoreRef(); this.nodeRef = nodeRef; }
Example 7
Source File: MessageServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
protected NodeRef getNode(NodeRef rootNodeRef, String path) { RepositoryLocation repositoryLocation = new RepositoryLocation(rootNodeRef.getStoreRef(), path, RepositoryLocation.LANGUAGE_PATH); String[] pathElements = repositoryLocation.getPathElements(); NodeRef nodeRef = rootNodeRef; if (pathElements.length > 0) { nodeRef = resolveQNamePath(rootNodeRef, pathElements); } return nodeRef; }
Example 8
Source File: MultiTServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public NodeRef getRootNode(NodeService nodeService, SearchService searchService, NamespaceService namespaceService, String rootPath, NodeRef rootNodeRef) { ParameterCheck.mandatory("NodeService", nodeService); ParameterCheck.mandatory("SearchService", searchService); ParameterCheck.mandatory("NamespaceService", namespaceService); ParameterCheck.mandatory("RootPath", rootPath); ParameterCheck.mandatory("RootNodeRef", rootNodeRef); // String username = AuthenticationUtil.getFullyAuthenticatedUser(); StoreRef storeRef = rootNodeRef.getStoreRef(); AuthenticationUtil.RunAsWork<NodeRef> action = new GetRootNode(nodeService, searchService, namespaceService, rootPath, rootNodeRef, storeRef); return getBaseName(AuthenticationUtil.runAs(action, AuthenticationUtil.getSystemUserName())); }
Example 9
Source File: NodeProtocol.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Reference propagateNodeRefMutations(NodeRef mutatedNodeRef, Reference reference) { StoreRef storeRef = mutatedNodeRef.getStoreRef(); String storeId = storeRef.getIdentifier(); String protocol = storeRef.getProtocol(); if (Version2Model.STORE_ID.equals(storeId) || VersionModel.STORE_ID.equals(storeId) || VersionBaseModel.STORE_PROTOCOL.equals(protocol)) { Resource resource = reference.getResource(); if (resource instanceof RepositoryResource) { RepositoryResource repositoryResource = (RepositoryResource) resource; RepositoryLocation location = repositoryResource.getLocation(); if (location instanceof RepositoryNodeRef) { RepositoryNodeRef repositoryNodeRef = (RepositoryNodeRef) location; NodeRef nodeRef = repositoryNodeRef.getNodeRef(); NodeRef nodeRefPropagation = new NodeRef(mutatedNodeRef.getStoreRef(), nodeRef.getId()); Resource resourcePropagation = new RepositoryResource(new RepositoryNodeRef(nodeRefPropagation)); return new Reference(reference.getEncoding(), reference.getProtocol(), resourcePropagation, reference.getParameters()); } } } // default branch return reference; }
Example 10
Source File: NodeRefRadixHasher.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Pair<String, String> hash(NodeRef nodeRef) { String uuid = nodeRef.getId(); if (uuid.length() != 36) { throw new RuntimeException("Invalid noderf id length " + uuid); } String bigInt16String = uuid.replaceAll("-", ""); if (bigInt16String.length() != 32) { throw new RuntimeException("Invalid noderf id format " + uuid); } BigInteger bigIntId = new BigInteger(bigInt16String, 16); StoreRef storeRef = nodeRef.getStoreRef(); String storeProtocolHash = storeProtocolStore.hash(storeRef.getProtocol()); String storeIdHash = storeIdStore.hash(storeRef.getIdentifier()); if (storeProtocolHash == null || storeIdHash == null) { throw new RuntimeException("Missing hash for " + storeRef); } String storeHash = storeProtocolHash + storeIdHash; return new Pair<String, String>(storeHash, bigIntId.toString(radix)); }
Example 11
Source File: PlainStringifier.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public String stringifyRepositoryLocation(RepositoryNodeRef repositoryNodeRef) throws ReferenceEncodingException { NodeRef nodeRef = repositoryNodeRef.getNodeRef(); StoreRef storeRef = nodeRef.getStoreRef(); return NODE + DELIMITER + storeRef.getProtocol() + DELIMITER + storeRef.getIdentifier() + DELIMITER + nodeRef.getId(); }
Example 12
Source File: VersionServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private Version getLatestVersion(NodeRef nodeRef) { Version version = null; StoreRef storeRef = nodeRef.getStoreRef(); NodeRef versionHistoryNodeRef = getVersionHistoryNodeRef(nodeRef); if (versionHistoryNodeRef != null) { List<ChildAssociationRef> versionsAssoc = this.dbNodeService.getChildAssocs(versionHistoryNodeRef, RegexQNamePattern.MATCH_ALL, VersionModel.CHILD_QNAME_VERSIONS); for (ChildAssociationRef versionAssoc : versionsAssoc) { NodeRef versionNodeRef = versionAssoc.getChildRef(); List<AssociationRef> predecessors = this.dbNodeService.getSourceAssocs(versionNodeRef, VersionModel.ASSOC_SUCCESSOR); if (predecessors.size() == 0) { String storeProtocol = (String)this.dbNodeService.getProperty( versionNodeRef, QName.createQName(NAMESPACE_URI, VersionModel.PROP_FROZEN_NODE_STORE_PROTOCOL)); String storeId = (String)this.dbNodeService.getProperty( versionNodeRef, QName.createQName(NAMESPACE_URI, VersionModel.PROP_FROZEN_NODE_STORE_ID)); StoreRef versionStoreRef = new StoreRef(storeProtocol, storeId); if (storeRef.equals(versionStoreRef) == true) { version = getVersion(versionNodeRef); } } } } return version; }
Example 13
Source File: VersionServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get the head version given a node reference * * @param nodeRef the node reference * @return the 'head' version */ private Version getHeadVersion(NodeRef nodeRef) { Version version = null; StoreRef storeRef = nodeRef.getStoreRef(); NodeRef versionHistoryNodeRef = getVersionHistoryNodeRef(nodeRef); if (versionHistoryNodeRef != null) { List<ChildAssociationRef> versionsAssoc = this.dbNodeService.getChildAssocs(versionHistoryNodeRef, RegexQNamePattern.MATCH_ALL, VersionModel.CHILD_QNAME_VERSIONS); for (ChildAssociationRef versionAssoc : versionsAssoc) { NodeRef versionNodeRef = versionAssoc.getChildRef(); List<AssociationRef> successors = this.dbNodeService.getTargetAssocs(versionNodeRef, VersionModel.ASSOC_SUCCESSOR); if (successors.size() == 0) { String storeProtocol = (String)this.dbNodeService.getProperty( versionNodeRef, QName.createQName(NAMESPACE_URI, VersionModel.PROP_FROZEN_NODE_STORE_PROTOCOL)); String storeId = (String)this.dbNodeService.getProperty( versionNodeRef, QName.createQName(NAMESPACE_URI, VersionModel.PROP_FROZEN_NODE_STORE_ID)); StoreRef versionStoreRef = new StoreRef(storeProtocol, storeId); if (storeRef.equals(versionStoreRef) == true) { version = getVersion(versionNodeRef); } } } } return version; }
Example 14
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 15
Source File: DbNodeServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * {@inheritDoc} */ @Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class) public ChildAssociationRef createNode( NodeRef parentRef, QName assocTypeQName, QName assocQName, QName nodeTypeQName, Map<QName, Serializable> properties) { // The node(s) involved may not be pending deletion checkPendingDelete(parentRef); ParameterCheck.mandatory("parentRef", parentRef); ParameterCheck.mandatory("assocTypeQName", assocTypeQName); ParameterCheck.mandatory("assocQName", assocQName); ParameterCheck.mandatory("nodeTypeQName", nodeTypeQName); if(assocQName.getLocalName().length() > QName.MAX_LENGTH) { throw new IllegalArgumentException("Localname is too long. Length of " + assocQName.getLocalName().length() + " exceeds the maximum of " + QName.MAX_LENGTH); } // Get the parent node Pair<Long, NodeRef> parentNodePair = getNodePairNotNull(parentRef); StoreRef parentStoreRef = parentRef.getStoreRef(); // null property map is allowed if (properties == null) { properties = Collections.emptyMap(); } // get an ID for the node String newUuid = generateGuid(properties); // Invoke policy behaviour invokeBeforeCreateNode(parentRef, assocTypeQName, assocQName, nodeTypeQName); // check the node type TypeDefinition nodeTypeDef = dictionaryService.getType(nodeTypeQName); if (nodeTypeDef == null) { throw new InvalidTypeException(nodeTypeQName); } // Ensure child uniqueness String newName = extractNameProperty(properties); // Get the thread's locale Locale locale = I18NUtil.getLocale(); // create the node instance ChildAssocEntity assoc = nodeDAO.newNode( parentNodePair.getFirst(), assocTypeQName, assocQName, parentStoreRef, newUuid, nodeTypeQName, locale, newName, properties); ChildAssociationRef childAssocRef = assoc.getRef(qnameDAO); Pair<Long, NodeRef> childNodePair = assoc.getChildNode().getNodePair(); addAspectsAndProperties( childNodePair, nodeTypeQName, null, Collections.<QName>emptySet(), Collections.<QName, Serializable>emptyMap(), Collections.<QName>emptySet(), properties, true, false); Map<QName, Serializable> propertiesAfter = nodeDAO.getNodeProperties(childNodePair.getFirst()); // Propagate timestamps propagateTimeStamps(childAssocRef); // Invoke policy behaviour invokeOnCreateNode(childAssocRef); invokeOnCreateChildAssociation(childAssocRef, true); Map<QName, Serializable> propertiesBefore = PropertyMap.EMPTY_MAP; invokeOnUpdateProperties( childAssocRef.getChildRef(), propertiesBefore, propertiesAfter); // Ensure that the parent node has the required aspects addAspectsAndPropertiesAssoc(parentNodePair, assocTypeQName, null, null, null, null, false); // done return childAssocRef; }
Example 16
Source File: RuleServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") private void executePendingRuleImpl(PendingRuleData pendingRule) { Set<ExecutedRuleData> executedRules = (Set<ExecutedRuleData>) AlfrescoTransactionSupport.getResource(KEY_RULES_EXECUTED); NodeRef actionedUponNodeRef = pendingRule.getActionedUponNodeRef(); Rule rule = pendingRule.getRule(); boolean isSystemUser = false; if (!(AuthenticationUtil.isRunAsUserTheSystemUser()) && (rule.getAction()!=null) && (rule.getAction() instanceof ActionImpl)) { isSystemUser = AuthenticationUtil.SYSTEM_USER_NAME.equals(((ActionImpl) rule.getAction()).getRunAsUser()); } NodeRef ruleNodeRef = rule.getNodeRef(); if (!ruleNodeRef.getStoreRef().equals(actionedUponNodeRef.getStoreRef()) && !nodeService.exists(ruleNodeRef)) { NodeRef newRuleNodeRef = new NodeRef(actionedUponNodeRef.getStoreRef(), ruleNodeRef.getId()); if (nodeService.exists(newRuleNodeRef)) { ruleNodeRef = newRuleNodeRef; } } final NodeRef finalRuleNodeRef = ruleNodeRef; // update all associations and actions rule = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Rule>() { public Rule doWork() throws Exception { return getRule(finalRuleNodeRef); } }, AuthenticationUtil.getSystemUserName()); if (executedRules == null || canExecuteRule(executedRules, actionedUponNodeRef, rule) == true) { if (isSystemUser) { final Rule fRule = rule; final NodeRef fActionedUponNodeRef = actionedUponNodeRef; final Set<ExecutedRuleData> fExecutedRules = executedRules; AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>() { public Void doWork() throws Exception { executeRule(fRule, fActionedUponNodeRef, fExecutedRules); return null; } }, AuthenticationUtil.getSystemUserName()); } else { executeRule(rule, actionedUponNodeRef, executedRules); } } }
Example 17
Source File: CheckOutCheckInServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void testDeleteAndRestore() { authenticationComponent.setSystemUserAsCurrentUser(); StoreRef spacesStoreRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE; NodeRef spacesRootNodeRef = nodeService.getRootNode(spacesStoreRef); NodeRef archiveRootNodeRef = nodeService.getStoreArchiveNode(spacesStoreRef); permissionService.setPermission(spacesRootNodeRef, userName, PermissionService.ALL_PERMISSIONS, true); authenticationComponent.setCurrentUser(userName); // create folder and some content within the the folder NodeRef folderRef = createFolder(spacesRootNodeRef, "testDeleteAndRestore-folder-"+System.currentTimeMillis()); NodeRef contentRef = createContent("testDeleteAndRestore-content", folderRef); String initialText = "initial text"; ContentWriter contentWriter = contentService.getWriter(contentRef, ContentModel.PROP_CONTENT, true); contentWriter.setMimetype("text/plain"); contentWriter.setEncoding("UTF-8"); contentWriter.putContent(initialText); assertFalse(nodeService.hasAspect(contentRef, ContentModel.ASPECT_CHECKED_OUT)); // checkout content node NodeRef workingCopyRef = cociService.checkout(contentRef, folderRef, ContentModel.ASSOC_CHILDREN, QName.createQName("workingCopy")); assertNotNull(workingCopyRef); assertTrue(nodeService.hasAspect(workingCopyRef, ContentModel.ASPECT_WORKING_COPY)); assertTrue(nodeService.hasAspect(workingCopyRef, ContentModel.ASPECT_COPIEDFROM)); assertTrue(nodeService.hasAspect(contentRef, ContentModel.ASPECT_CHECKED_OUT)); String updatedText = "updated text"; contentWriter = contentService.getWriter(workingCopyRef, ContentModel.PROP_CONTENT, true); contentWriter.setMimetype("text/plain"); contentWriter.setEncoding("UTF-8"); contentWriter.putContent(updatedText); assertTrue(nodeService.exists(folderRef)); assertTrue(nodeService.exists(contentRef)); assertTrue(nodeService.exists(workingCopyRef)); // delete folder nodeService.deleteNode(folderRef); assertFalse(nodeService.exists(folderRef)); assertFalse(nodeService.exists(contentRef)); assertFalse(nodeService.exists(workingCopyRef)); // restore folder NodeRef archiveNodeRef = new NodeRef(archiveRootNodeRef.getStoreRef(), folderRef.getId()); nodeService.restoreNode(archiveNodeRef, null, null, null); assertTrue(nodeService.exists(folderRef)); assertTrue(nodeService.exists(contentRef)); assertTrue(nodeService.exists(workingCopyRef)); assertTrue(nodeService.hasAspect(workingCopyRef, ContentModel.ASPECT_WORKING_COPY)); assertTrue(nodeService.hasAspect(workingCopyRef, ContentModel.ASPECT_COPIEDFROM)); assertTrue(nodeService.hasAspect(contentRef, ContentModel.ASPECT_CHECKED_OUT)); assertEquals(initialText, contentService.getReader(contentRef, ContentModel.PROP_CONTENT).getContentString()); assertEquals(updatedText, contentService.getReader(workingCopyRef, ContentModel.PROP_CONTENT).getContentString()); // belts-and-braces - also show that we can move a folder with checked-out item NodeRef folderRef2 = createFolder(spacesRootNodeRef, "testDeleteAndRestore-folder2-"+System.currentTimeMillis()); nodeService.moveNode(folderRef, folderRef2, ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS); // checkin content node (working copy) cociService.checkin(workingCopyRef, null); assertFalse(nodeService.exists(workingCopyRef)); assertEquals(updatedText, contentService.getReader(contentRef, ContentModel.PROP_CONTENT).getContentString()); }