Java Code Examples for org.alfresco.service.cmr.repository.NodeRef#getId()
The following examples show how to use
org.alfresco.service.cmr.repository.NodeRef#getId() .
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: DeletedNodesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Node getDeletedNode(String originalId, Parameters parameters, boolean fullnode, Map<String, UserInfo> mapUserInfo) { //First check the node is valid and has been archived. NodeRef validatedNodeRef = nodes.validateNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, originalId); //Now get the Node NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, validatedNodeRef.getId()); NodeRef archivedNodeRef = nodeArchiveService.getArchivedNode(nodeRef); Node foundNode = null; if (fullnode) { foundNode = nodes.getFolderOrDocumentFullInfo(archivedNodeRef, null, null, parameters, mapUserInfo); } else { foundNode = nodes.getFolderOrDocument(archivedNodeRef, null, null, parameters.getInclude(), mapUserInfo); } if (foundNode != null) mapArchiveInfo(foundNode,null); return foundNode; }
Example 2
Source File: UUIDSupport.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public void setUuids(String[] uuids) { this.uuids = new String[uuids.length]; for(int i = 0; i < uuids.length; i++) { if(NodeRef.isNodeRef(uuids[i])) { NodeRef ref = new NodeRef(uuids[i]); this.uuids[i] = ref.getId(); } else { this.uuids[i] = uuids[i]; } } }
Example 3
Source File: ThumbnailServiceTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private void getWait(NodeRef node, String thumbnailName) throws Exception { String url = "/api/node/" + node.getStoreRef().getProtocol() + "/" + node.getStoreRef().getIdentifier() + "/" + node.getId() + "/content/thumbnails/" + thumbnailName; int retries = 50; int tries = 0; while (true) { if (tries >= retries) { fail("Thumbnail never gets created " + thumbnailName); } Response response = sendRequest(new GetRequest(url), 0); if (response.getStatus() == 200) { break; } else if (response.getStatus() == 500) { System.out.println("Error during getWait: " + response.getContentAsString()); fail("A 500 status was found whilst waiting for the thumbnail to be processed"); } else { Thread.sleep(100); } tries++; } }
Example 4
Source File: SitesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public SiteInfo validateSite(NodeRef guid) { SiteInfo siteInfo = null; if(guid == null) { throw new InvalidArgumentException("guid is null"); } nodes.validateNode(guid); QName type = nodeService.getType(guid); boolean isSiteNodeRef = dictionaryService.isSubClass(type, SiteModel.TYPE_SITE); if(isSiteNodeRef) { siteInfo = siteService.getSite(guid); if(siteInfo == null) { // not a site throw new InvalidArgumentException(guid.getId() + " is not a site"); } } else { // site does not exist throw new EntityNotFoundException(guid.getId()); } return siteInfo; }
Example 5
Source File: DbNodeServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class) public Serializable getProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException { Long nodeId = getNodePairNotNull(nodeRef).getFirst(); // Spoof referencable properties if (qname.equals(ContentModel.PROP_STORE_PROTOCOL)) { return nodeRef.getStoreRef().getProtocol(); } else if (qname.equals(ContentModel.PROP_STORE_IDENTIFIER)) { return nodeRef.getStoreRef().getIdentifier(); } else if (qname.equals(ContentModel.PROP_NODE_UUID)) { return nodeRef.getId(); } else if (qname.equals(ContentModel.PROP_NODE_DBID)) { return nodeId; } Serializable property = nodeDAO.getNodeProperty(nodeId, qname); // check if we need to provide a spoofed name if (property == null && qname.equals(ContentModel.PROP_NAME)) { return nodeRef.getId(); } // done return property; }
Example 6
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 for the current user. */ public void testRestoreDeletedItemsAsNonAdminUser() throws Exception { AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE); String restoreUrl = getArchiveUrl(user2_DeletedTestNode.getStoreRef()) + "/" + user2_DeletedTestNode.getId(); String jsonString = new JSONStringer().object().key("restoreLocation").value("").endObject().toString(); // User_One has the nodeRef of the node deleted by User_Two. User_One is // not an Admin, so he must not be allowed to restore a node which he doesn’t own. Response rsp = sendRequest(new PutRequest(restoreUrl, jsonString, "application/json"), 403); assertEquals(403, rsp.getStatus()); // Now User_One gets his own archived node and tries to restore it JSONObject jsonRsp = getArchivedNodes(); JSONObject dataObj = (JSONObject) jsonRsp.get(DATA); JSONArray deletedNodesArray = (JSONArray) dataObj.get(AbstractArchivedNodeWebScript.DELETED_NODES); // User_One deleted only 1 node and he doesn't have permission to see other users' archived data. assertEquals("Unexpectedly found more than 1 item in the archive store.", 1, deletedNodesArray.length()); JSONObject archivedNode = (JSONObject) deletedNodesArray.get(0); // So we have identified a specific Node in the archive that we want to restore. String nodeRefString = archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF); assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString)); NodeRef nodeRef = new NodeRef(nodeRefString); // This is its current StoreRef i.e. archive://SpacesStore restoreUrl = getArchiveUrl(nodeRef.getStoreRef()) + "/" + nodeRef.getId(); int archivedNodesCountBeforeRestore = getArchivedNodesCount(); // Send the PUT REST call. jsonString = new JSONStringer().object().key("restoreLocation").value("").endObject().toString(); rsp = sendRequest(new PutRequest(restoreUrl, jsonString, "application/json"), 200); assertEquals("Expected archive to shrink by one", archivedNodesCountBeforeRestore - 1, getArchivedNodesCount()); }
Example 7
Source File: NodesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * @deprecated note: currently required for backwards compat' (Favourites API) */ @Override public Document getDocument(NodeRef nodeRef) { Type type = getType(nodeRef); if ((type != null) && type.equals(Type.DOCUMENT)) { Map<QName, Serializable> properties = nodeService.getProperties(nodeRef); Document doc = new Document(nodeRef, getParentNodeRef(nodeRef), properties, null, sr); doc.setVersionLabel((String) properties.get(ContentModel.PROP_VERSION_LABEL)); ContentData cd = (ContentData) properties.get(ContentModel.PROP_CONTENT); if (cd != null) { doc.setSizeInBytes(BigInteger.valueOf(cd.getSize())); doc.setMimeType((cd.getMimetype())); } setCommonProps(doc, nodeRef, properties); return doc; } else { throw new InvalidArgumentException("Node is not a file: "+nodeRef.getId()); } }
Example 8
Source File: FavouritesServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private boolean removeFavouriteNode(String userName, Type type, NodeRef nodeRef) { boolean exists = false; Map<PersonFavouriteKey, PersonFavourite> personFavourites = getFavouriteNodes(userName, type); PersonFavouriteKey personFavouriteKey = new PersonFavouriteKey(userName, null, type, nodeRef); PersonFavourite personFavourite = personFavourites.remove(personFavouriteKey); exists = personFavourite != null; updateFavouriteNodes(userName, type, personFavourites); QName nodeClass = nodeService.getType(nodeRef); final String finalRef = nodeRef.getId(); final QName nodeType = nodeClass; eventPublisher.publishEvent(new EventPreparator(){ @Override public Event prepareEvent(String user, String networkId, String transactionId) { return new ActivityEvent("favorite.removed", transactionId, networkId, user, finalRef, null, nodeType==null?null:nodeType.toString(), Client.asType(ClientType.script), null, null, null, 0l, null); } }); OnRemoveFavouritePolicy policy = onRemoveFavouriteDelegate.get(nodeRef, nodeClass); policy.onRemoveFavourite(userName, nodeRef); return exists; }
Example 9
Source File: MultiTServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public NodeRef getBaseName(NodeRef nodeRef, boolean forceForNonTenant) { if (nodeRef == null) { return null; } return new NodeRef(nodeRef.getStoreRef().getProtocol(), getBaseName(nodeRef.getStoreRef().getIdentifier(), forceForNonTenant), nodeRef.getId()); }
Example 10
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 11
Source File: UUIDSupport.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * @param uuid the uud to set */ public void setUuid(String uuid) { if(NodeRef.isNodeRef(uuid)) { NodeRef ref = new NodeRef(uuid); this.uuid = ref.getId(); } else { this.uuid = uuid; } }
Example 12
Source File: DBQuery.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public static String getUUID(String source) { // Ignore version label for now String ref; String versionLabel = null; String[] split = source.split(";"); if(split.length == 1) { ref = source; } else { if(split[1].equalsIgnoreCase("PWC")) { throw new UnsupportedOperationException("Query for PWC is not supported"); } ref = split[0]; versionLabel = split[1]; } if (NodeRef.isNodeRef(ref)) { NodeRef nodeRef = new NodeRef(ref); return nodeRef.getId(); } else { return ref; } }
Example 13
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 14
Source File: NodesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Node updateContent(String fileNodeId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters) { if (contentInfo.getMimeType().toLowerCase().startsWith("multipart")) { throw new UnsupportedMediaTypeException("Cannot update using "+contentInfo.getMimeType()); } final NodeRef nodeRef = validateNode(fileNodeId); if (! nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false)) { throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef.getId()); } Boolean versionMajor = null; String str = parameters.getParameter(PARAM_VERSION_MAJOR); if (str != null) { versionMajor = Boolean.valueOf(str); } String versionComment = parameters.getParameter(PARAM_VERSION_COMMENT); String fileName = parameters.getParameter(PARAM_NAME); if (fileName != null) { // optionally rename, before updating the content nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, fileName); } else { fileName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); } return updateExistingFile(null, nodeRef, fileName, contentInfo, stream, parameters, versionMajor, versionComment); }
Example 15
Source File: NodesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
public NodeRef validateOrLookupNode(String nodeId, String path) { NodeRef parentNodeRef; if ((nodeId == null) || (nodeId.isEmpty())) { throw new InvalidArgumentException("Missing nodeId"); } if (nodeId.equals(PATH_ROOT)) { parentNodeRef = repositoryHelper.getCompanyHome(); } else if (nodeId.equals(PATH_SHARED)) { parentNodeRef = repositoryHelper.getSharedHome(); } else if (nodeId.equals(PATH_MY)) { NodeRef person = repositoryHelper.getPerson(); if (person == null) { throw new InvalidArgumentException("Unexpected - cannot use: " + PATH_MY); } parentNodeRef = repositoryHelper.getUserHome(person); if (parentNodeRef == null) { throw new EntityNotFoundException(nodeId); } } else { parentNodeRef = validateNode(nodeId); } if (path != null) { // check that parent is a folder before resolving relative path if (! nodeMatches(parentNodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), null, false)) { throw new InvalidArgumentException("NodeId of folder is expected: "+parentNodeRef.getId()); } // resolve path relative to current nodeId parentNodeRef = resolveNodeByPath(parentNodeRef, path, true); } return parentNodeRef; }
Example 16
Source File: ThumbnailServiceTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private String getThumbnailsURL(NodeRef nodeRef) { return "/api/node/" + nodeRef.getStoreRef().getProtocol() + "/" + nodeRef.getStoreRef().getIdentifier() + "/" + nodeRef.getId() + "/content/thumbnails"; }
Example 17
Source File: TestCMIS.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * 1) Creating a file with currency symbols in the name, title and description (MNT-15044) * 2) Get the document with correct chars in the properties. * @throws Exception */ @Test public void testGetXmlWithCorrectCurrencySymbols() throws Exception { final TestNetwork network1 = getTestFixture().getRandomNetwork(); String username = "user" + System.currentTimeMillis(); PersonInfo personInfo = new PersonInfo(username, username, username, "password", null, null, null, null, null, null, null); TestPerson person1 = network1.createUser(personInfo); String person1Id = person1.getId(); final String siteName = "site" + System.currentTimeMillis(); NodeRef fileNode = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() { @Override public NodeRef doWork() throws Exception { SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); final TestSite site = network1.createSite(siteInfo); NodeRef resNode = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Euro \u20AC Pound \u00A3 Franc \u20A3.txt", "Euro \u20AC Pound \u00A3 Franc \u20A3 File", "\u20A3 \u00A3 \u20A3", "\u20A3 \u00A3 \u20A3"); return resNode; } }, person1Id, network1.getId()); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id)); CmisSession atomCmisSession10 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName()); String objectId = fileNode.getId(); Document doc = (Document)atomCmisSession10.getObject(objectId); String name = (String)doc.getProperty(PropertyIds.NAME).getFirstValue(); String title = (String)doc.getProperty("cm:title").getFirstValue(); String description = (String)doc.getProperty("cm:description").getFirstValue(); assertEquals("Euro \u20AC Pound \u00A3 Franc \u20A3.txt", name); assertEquals("Euro \u20AC Pound \u00A3 Franc \u20A3 File", title); assertEquals("\u20A3 \u00A3 \u20A3", description); }
Example 18
Source File: ZeroStringifier.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public String stringifyRepositoryLocation(RepositoryNodeRef repositoryNodeRef) throws ReferenceEncodingException { NodeRef nodeRef = repositoryNodeRef.getNodeRef(); return NODE_CODE + DELIMITER + nodeRef.getId(); }
Example 19
Source File: NodesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
protected FileInfo moveOrCopyImpl(NodeRef nodeRef, NodeRef parentNodeRef, String name, boolean isCopy) { String targetParentId = parentNodeRef.getId(); try { if (isCopy) { // copy FileInfo newFileInfo = fileFolderService.copy(nodeRef, parentNodeRef, name); if (newFileInfo.getNodeRef().equals(nodeRef)) { // copy did not happen - eg. same parent folder and name (name can be null or same) throw new FileExistsException(nodeRef, ""); } return newFileInfo; } else { // move if ((! nodeRef.equals(parentNodeRef)) && isSpecialNode(nodeRef, getNodeType(nodeRef))) { throw new PermissionDeniedException("Cannot move: "+nodeRef.getId()); } // updating "parentId" means moving primary parent ! // note: in the future (as and when we support secondary parent/child assocs) we may also // wish to select which parent to "move from" (in case where the node resides in multiple locations) return fileFolderService.move(nodeRef, parentNodeRef, name); } } catch (InvalidNodeRefException inre) { throw new EntityNotFoundException(targetParentId); } catch (FileNotFoundException fnfe) { // convert checked exception throw new EntityNotFoundException(targetParentId); } catch (FileExistsException fee) { // duplicate - name clash throw new ConstraintViolatedException("Name already exists in target parent: "+name); } catch (FileFolderServiceImpl.InvalidTypeException ite) { throw new InvalidArgumentException("Invalid type of target parent: "+targetParentId); } }
Example 20
Source File: VersionUtil.java From alfresco-repository with GNU Lesser General Public License v3.0 | 2 votes |
/** * Convert the incomming node ref (with the version store protocol specified) * to the internal representation with the workspace protocol. * * @param nodeRef the incomming verison protocol node reference * @return the internal version node reference */ public static NodeRef convertNodeRef(NodeRef nodeRef) { return new NodeRef(convertStoreRef(nodeRef.getStoreRef()), nodeRef.getId()); }