Java Code Examples for org.alfresco.service.cmr.repository.NodeService#exists()
The following examples show how to use
org.alfresco.service.cmr.repository.NodeService#exists() .
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: AlfrescoImapFolder.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Determine if it is a complex move operation, which consists of a create superseded by a delete. * * @param sourceNodeRef NodeRef * @return boolean */ @SuppressWarnings("deprecation") private boolean isMoveOperation(NodeRef sourceNodeRef) { if (sourceNodeRef != null) { NodeService nodeService = serviceRegistry.getNodeService(); if (nodeService.exists(sourceNodeRef)) { FileFolderService fileFolderService = serviceRegistry.getFileFolderService(); FileInfo node = fileFolderService.getFileInfo(sourceNodeRef); if (node != null) { if (fileFolderService.isHidden(sourceNodeRef)) { return true; } } } } return false; }
Example 2
Source File: NodeStoreInspector.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Dumps the contents of a store to a string. * * @param nodeService the node service * @param storeRef the store reference * @return string containing textual representation of the contents of the store */ public static String dumpNodeStore(NodeService nodeService, StoreRef storeRef) { StringBuilder builder = new StringBuilder(); if (nodeService.exists(storeRef) == true) { NodeRef rootNode = nodeService.getRootNode(storeRef); builder.append(outputNode(0, nodeService, rootNode)); } else { builder. append("The store "). append(storeRef.toString()). append(" does not exist."); } return builder.toString(); }
Example 3
Source File: NodeStoreInspector.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Dumps the contents of a node * * @param nodeService NodeService * @param nodeRef NodeRef * @return String */ public static String dumpNode(NodeService nodeService, NodeRef nodeRef) { StringBuilder builder = new StringBuilder(); if (nodeService.exists(nodeRef) == true) { builder.append(outputNode(0, nodeService, nodeRef)); } else { builder. append("The node "). append(nodeRef.toString()). append(" does not exist."); } return builder.toString(); }
Example 4
Source File: StandardRenditionLocationResolverImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * This method creates a {@link RenditionLocation} object from the specified destination node. * This is formed from the specified destination NodeRef, its cm:name and its primary parent. * * @param destination NodeRef * @return RenditionLocationImpl * @throws RenditionServiceException if the destination node does not exist. */ private RenditionLocationImpl createNodeLocation(NodeRef destination) { NodeService nodeService = serviceRegistry.getNodeService(); if(nodeService.exists(destination)==false) throw new RenditionServiceException("The rendition destination node does not exist! NodeRef: "+destination); NodeRef parentRef = nodeService.getPrimaryParent(destination).getParentRef(); String destinationCmName = (String) nodeService.getProperty(destination, ContentModel.PROP_NAME); RenditionLocationImpl location = new RenditionLocationImpl(parentRef, destination, destinationCmName); return location; }
Example 5
Source File: NodeUtils.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public static Filter<NodeRef> exists(final NodeService nodeService) { return new Filter<NodeRef>() { public Boolean apply(NodeRef value) { return nodeService.exists(value); } }; }
Example 6
Source File: RoutingContentServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void setUp() throws Exception { ctx = ApplicationContextHelper.getApplicationContext(); transactionService = (TransactionService) ctx.getBean("TransactionService"); nodeService = (NodeService) ctx.getBean("NodeService"); contentService = (ContentService) ctx.getBean(ServiceRegistry.CONTENT_SERVICE.getLocalName()); copyService = (CopyService) ctx.getBean("CopyService"); this.policyComponent = (PolicyComponent) ctx.getBean("policyComponent"); this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); // authenticate this.authenticationComponent.setSystemUserAsCurrentUser(); // start the transaction txn = getUserTransaction(); txn.begin(); // create a store and get the root node StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName()); if (!nodeService.exists(storeRef)) { storeRef = nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier()); } rootNodeRef = nodeService.getRootNode(storeRef); ChildAssociationRef assocRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, GUID.generate()), ContentModel.TYPE_CONTENT); contentNodeRef = assocRef.getChildRef(); ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); writer.setEncoding("UTF-16"); writer.setLocale(Locale.CHINESE); writer.setMimetype("text/plain"); writer.putContent("sample content"); }
Example 7
Source File: BaseSearchResultsMap.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Perform a SearchService query with the given Lucene search string */ protected List<TemplateNode> query(String search) { List<TemplateNode> nodes = null; HashSet<NodeRef> nodeRefs = new HashSet<NodeRef>(); // check if a full Lucene search string has been supplied or extracted from XML if (search != null && search.length() != 0) { // perform the search against the repo ResultSet results = null; try { results = this.services.getSearchService().query(this.parent.getNodeRef().getStoreRef(), SearchService.LANGUAGE_LUCENE, search); if (results.length() != 0) { NodeService nodeService = this.services.getNodeService(); nodes = new ArrayList<TemplateNode>(results.length()); for (ResultSetRow row : results) { NodeRef nodeRef = row.getNodeRef(); if (!nodeRefs.contains(nodeRef) && (nodeService.exists(nodeRef))) { nodes.add(new TemplateNode(nodeRef, services, this.parent.getImageResolver())); nodeRefs.add(nodeRef); } } } } catch (Throwable err) { throw new AlfrescoRuntimeException("Failed to execute search: " + search, err); } finally { if (results != null) { results.close(); } } } return nodes != null ? nodes : (List) Collections.emptyList(); }
Example 8
Source File: NodeUtils.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public static boolean exists(NodeRef node, NodeService nodeService) { return node != null && nodeService.exists(node); }
Example 9
Source File: ScriptActionExecuter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) */ protected void executeImpl(Action action, NodeRef actionedUponNodeRef) { NodeService nodeService = this.serviceRegistry.getNodeService(); if (nodeService.exists(actionedUponNodeRef)) { NodeRef scriptRef = (NodeRef)action.getParameterValue(PARAM_SCRIPTREF); NodeRef spaceRef = this.serviceRegistry.getRuleService().getOwningNodeRef(action); if (spaceRef == null) { // the actionedUponNodeRef may actually be a space if (this.serviceRegistry.getDictionaryService().isSubClass( nodeService.getType(actionedUponNodeRef), ContentModel.TYPE_FOLDER)) { spaceRef = actionedUponNodeRef; } else { spaceRef = nodeService.getPrimaryParent(actionedUponNodeRef).getParentRef(); } } if (this.scriptLocation != null || (scriptRef != null && nodeService.exists(scriptRef) == true)) { // get the references we need to build the default scripting data-model String userName = this.serviceRegistry.getAuthenticationService().getCurrentUserName(); NodeRef personRef = this.personService.getPerson(userName); NodeRef homeSpaceRef = (NodeRef)nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER); // the default scripting model provides access to well known objects and searching // facilities - it also provides basic create/update/delete/copy/move services Map<String, Object> model = this.serviceRegistry.getScriptService().buildDefaultModel( personRef, getCompanyHome(), homeSpaceRef, scriptRef, actionedUponNodeRef, spaceRef); // Add the action to the default model ScriptAction scriptAction = new ScriptAction(this.serviceRegistry, action, this.actionDefinition); model.put("action", scriptAction); model.put("webApplicationContextUrl", UrlUtil.getAlfrescoUrl(sysAdminParams)); Object result = null; if (this.scriptLocation == null) { // execute the script against the default model result = this.serviceRegistry.getScriptService().executeScript( scriptRef, ContentModel.PROP_CONTENT, model); } else { // execute the script at the specified script location result = this.serviceRegistry.getScriptService().executeScript(this.scriptLocation, model); } // Set the result if (result != null) { action.setParameterValue(PARAM_RESULT, (Serializable)result); } } } }
Example 10
Source File: XmlMetadataExtracterTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Tests metadata extraction using an action with an EAGER MetadataExtracter for XML. */ public void testLifecycleOfXmlMetadataExtraction() throws Exception { NodeService nodeService = serviceRegistry.getNodeService(); ContentService contentService = serviceRegistry.getContentService(); ActionExecuter executer = (ActionExecuter) ctx.getBean("extract-metadata"); Action action = new ActionImpl(null, GUID.generate(), SetPropertyValueActionExecuter.NAME, null); StoreRef storeRef = new StoreRef("test", getName()); NodeRef rootNodeRef = null; if (nodeService.exists(storeRef)) { rootNodeRef = nodeService.getRootNode(storeRef); } else { nodeService.createStore("test", getName()); rootNodeRef = nodeService.getRootNode(storeRef); } // Set up some properties PropertyMap properties = new PropertyMap(); properties.put(ContentModel.PROP_TITLE, "My title"); properties.put(ContentModel.PROP_DESCRIPTION, "My description"); NodeRef contentNodeRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getName()), ContentModel.TYPE_CONTENT, properties).getChildRef(); // Add some content ContentReader alfrescoModelReader = getReader(FILE_ALFRESCO_MODEL); assertTrue(alfrescoModelReader.exists()); ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); writer.setEncoding("UTF-8"); writer.setMimetype(MimetypeMap.MIMETYPE_XML); writer.putContent(alfrescoModelReader); // Execute the action executer.execute(action, contentNodeRef); // Check the node's properties. The EAGER overwrite policy should have replaced the required // properties. String checkTitle = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_TITLE); String checkDescription = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_DESCRIPTION); assertEquals("fm:forummodel", checkTitle); assertEquals("Forum Model", checkDescription); }
Example 11
Source File: ArchivedNodeState.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
public static ArchivedNodeState create(NodeRef archivedNode, ServiceRegistry serviceRegistry) { ArchivedNodeState result = new ArchivedNodeState(); NodeService nodeService = serviceRegistry.getNodeService(); Map<QName, Serializable> properties = nodeService.getProperties(archivedNode); result.archivedNodeRef = archivedNode; result.archivedBy = (String) properties.get(ContentModel.PROP_ARCHIVED_BY); result.archivedDate = (Date) properties.get(ContentModel.PROP_ARCHIVED_DATE); result.name = (String) properties.get(ContentModel.PROP_NAME); result.title = (String) properties.get(ContentModel.PROP_TITLE); result.description = (String) properties.get(ContentModel.PROP_DESCRIPTION); QName type = nodeService.getType(archivedNode); result.isContentType = (type.equals(ContentModel.TYPE_CONTENT) || serviceRegistry.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT)); result.nodeType = type.toPrefixString(serviceRegistry.getNamespaceService()); PersonService personService = serviceRegistry.getPersonService(); if (result.archivedBy != null && personService.personExists(result.archivedBy)) { NodeRef personNodeRef = personService.getPerson(result.archivedBy, false); Map<QName, Serializable> personProps = nodeService.getProperties(personNodeRef); result.firstName = (String) personProps.get(ContentModel.PROP_FIRSTNAME); result.lastName = (String) personProps.get(ContentModel.PROP_LASTNAME); } ChildAssociationRef originalParentAssoc = (ChildAssociationRef) properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC); if (serviceRegistry.getPermissionService().hasPermission(originalParentAssoc.getParentRef(), PermissionService.READ).equals(AccessStatus.ALLOWED) && nodeService.exists(originalParentAssoc.getParentRef())) { result.displayPath = PathUtil.getDisplayPath(nodeService.getPath(originalParentAssoc.getParentRef()), true); } else { result.displayPath = ""; } return result; }
Example 12
Source File: WebDAVServlet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * @param storeValue String * @param rootPath String * @param context WebApplicationContext * @param nodeService NodeService * @param searchService SearchService * @param namespaceService NamespaceService * @param tenantService TenantService * @param m_transactionService TransactionService */ private void initializeRootNode(String storeValue, String rootPath, WebApplicationContext context, NodeService nodeService, SearchService searchService, NamespaceService namespaceService, TenantService tenantService, TransactionService m_transactionService) { // Use the system user as the authenticated context for the filesystem initialization AuthenticationContext authComponent = (AuthenticationContext) context.getBean("authenticationContext"); authComponent.setSystemUserAsCurrentUser(); // Wrap the initialization in a transaction UserTransaction tx = m_transactionService.getUserTransaction(true); try { // Start the transaction if (tx != null) tx.begin(); StoreRef storeRef = new StoreRef(storeValue); if (nodeService.exists(storeRef) == false) { throw new RuntimeException("No store for path: " + storeRef); } NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef); List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false); if (nodeRefs.size() > 1) { throw new RuntimeException("Multiple possible children for : \n" + " path: " + rootPath + "\n" + " results: " + nodeRefs); } else if (nodeRefs.size() == 0) { throw new RuntimeException("Node is not found for : \n" + " root path: " + rootPath); } defaultRootNode = nodeRefs.get(0); // Commit the transaction if (tx != null) tx.commit(); } catch (Exception ex) { logger.error(ex); } finally { // Clear the current system user authComponent.clearCurrentSecurityContext(); } }
Example 13
Source File: ScriptCounterSignService.java From CounterSign with GNU Affero General Public License v3.0 | 4 votes |
/** * Gets all of the recorded signature workflow events for this node, both for * active and completed workflows * * @param nodeRef */ public List<Map<String, Object>> getSignatureWorkflowHistory(String nodeRef) { NodeService ns = serviceRegistry.getNodeService(); WorkflowService wfs = serviceRegistry.getWorkflowService(); List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); NodeRef node = new NodeRef(nodeRef); WorkflowModelBuilder modelBuilder = new WorkflowModelBuilder(serviceRegistry.getNamespaceService(), serviceRegistry.getNodeService(), serviceRegistry.getAuthenticationService(), serviceRegistry.getPersonService(), serviceRegistry.getWorkflowService(), serviceRegistry.getDictionaryService()); if(ns.exists(node)) { List<WorkflowInstance> active = wfs.getWorkflowsForContent(node, true); List<WorkflowInstance> inactive = wfs.getWorkflowsForContent(node, false); // merge the lists ArrayList<WorkflowInstance> all = new ArrayList<WorkflowInstance>(active.size() + inactive.size()); all.addAll(active); all.addAll(inactive); // we only need instances of the known CounterSign workflow types for(WorkflowInstance instance : all) { // if the instance definition name is in the list, get its tasks // and add them to the task list if(counterSignWorkflowIds.contains(instance.getDefinition().getName())) { results.add(modelBuilder.buildDetailed(instance, true)); } } } else { throw new AlfrescoRuntimeException("Node " + nodeRef + " does not exist"); } return results; }
Example 14
Source File: ScriptCounterSignService.java From CounterSign with GNU Affero General Public License v3.0 | 4 votes |
/** * Validates a single signature, passed in as a nodeRef String * * @param nodeRef * @return {signatureValid:[validity],hashValid:[validity]} */ public JSONObject validateSignature(String nodeRef) { // get the node, make sure it exists NodeService ns = serviceRegistry.getNodeService(); ContentService cs = serviceRegistry.getContentService(); NodeRef sigNode = new NodeRef(nodeRef); boolean signatureValid = false; boolean hashValid = false; if(ns.exists(sigNode)) { try { // get the doc has from the time of the sig and the sig itself String docHash = String.valueOf(ns.getProperty(sigNode, CounterSignSignatureModel.PROP_DOCHASH)); ContentReader sigReader = cs.getReader(sigNode, ContentModel.PROP_CONTENT); InputStream sigStream = sigReader.getContentInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int read = 0; while ((read = sigStream.read(buffer, 0, buffer.length)) != -1) { baos.write(buffer, 0, read); } baos.flush(); // get the signing user's public key String person = String.valueOf(ns.getProperty(sigNode, CounterSignSignatureModel.PROP_EXTERNALSIGNER)); SignatureProvider prov = signatureProviderFactory.getSignatureProvider(person); // validate the sig using the public key signatureValid = prov.validateSignature(baos.toByteArray(), docHash.getBytes()); // get the document associated with this sig, and compute the hash NodeRef signedDoc = ns.getParentAssocs(sigNode).get(0).getParentRef(); ContentReader docReader = cs.getReader(signedDoc, ContentModel.PROP_CONTENT); String contentHash = new String(prov.computeHash(docReader.getContentInputStream())); if(docHash.equals(contentHash)) { hashValid = true; } else { signatureValid = false; } } catch(IOException ioex) { throw new AlfrescoRuntimeException("IOException reading signature: " + ioex.getMessage()); } } else { throw new AlfrescoRuntimeException("Node: " + nodeRef + " does not exist"); } // create the JSONObject to return JSONObject valid = new JSONObject(); valid.put(signatureValidName, signatureValid); valid.put(hashValidName, hashValid); return valid; }
Example 15
Source File: ContentSignatureActionExecuter.java From CounterSign with GNU Affero General Public License v3.0 | 4 votes |
@Override protected void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) { NodeService nodeService = serviceRegistry.getNodeService(); ContentService contentService = serviceRegistry.getContentService(); byte[] sigBytes; if (nodeService.exists(actionedUponNodeRef) == false) { return; } String location = (String)ruleAction.getParameterValue(PARAM_LOCATION); String geolocation = (String)ruleAction.getParameterValue(PARAM_GEOLOCATION); String reason = (String)ruleAction.getParameterValue(PARAM_REASON); String keyPassword = (String)ruleAction.getParameterValue(PARAM_KEY_PASSWORD); // get a hash of the document InputStream contentStream = contentService. getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT).getContentInputStream(); try { // get the user's private key String user = AuthenticationUtil.getRunAsUser(); SignatureProvider signatureProvider = signatureProviderFactory.getSignatureProvider(user); KeyStore keystore = signatureProvider.getUserKeyStore(keyPassword); PrivateKey key = (PrivateKey)keystore.getKey(alias, keyPassword.toCharArray()); // compute the document hash byte[] hash = signatureProvider.computeHash(contentStream); // sign the hash sigBytes = signatureProvider.signHash(hash, keyPassword); // create a "signature" node and associate it with the signed doc NodeRef sig = addSignatureNodeAssociation(actionedUponNodeRef, location, reason, "none", new java.util.Date(), geolocation, -1, "none"); // save the signature ContentWriter writer = contentService.getWriter(sig, ContentModel.PROP_CONTENT, true); writer.putContent(new ByteArrayInputStream(sigBytes)); // also save the expected hash in the signature nodeService.setProperty(sig, CounterSignSignatureModel.PROP_DOCHASH, new String(hash)); } catch(UnrecoverableKeyException uke) { throw new AlfrescoRuntimeException(uke.getMessage()); } catch (KeyStoreException kse) { throw new AlfrescoRuntimeException(kse.getMessage()); } catch (NoSuchAlgorithmException nsae) { throw new AlfrescoRuntimeException(nsae.getMessage()); } catch (Exception e) { throw new AlfrescoRuntimeException(e.getMessage()); } }