Java Code Examples for org.alfresco.service.cmr.repository.NodeService#getChildByName()
The following examples show how to use
org.alfresco.service.cmr.repository.NodeService#getChildByName() .
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: AbstractForumEmailMessageHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Adds topic node into Alfresco repository * * @param parentNode Parent node * @param name Topic name * @return Reference to created node */ protected NodeRef addTopicNode(NodeRef parentNode, String name) { String workingName = encodeSubject(name); NodeService nodeService = getNodeService(); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1); properties.put(ContentModel.PROP_NAME, workingName); NodeRef topicNode = nodeService.getChildByName(parentNode, ContentModel.ASSOC_CONTAINS, workingName); if (topicNode == null) { ChildAssociationRef association = nodeService.createNode( parentNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, workingName), ForumModel.TYPE_TOPIC, properties); topicNode = association.getChildRef(); } // Add necessary aspects properties.clear(); properties.put(ApplicationModel.PROP_ICON, "topic"); getNodeService().addAspect(topicNode, ApplicationModel.ASPECT_UIFACETS, properties); return topicNode; }
Example 2
Source File: ReplicationRestApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); ApplicationContext appContext = getServer().getApplicationContext(); nodeService = (NodeService)appContext.getBean("NodeService"); replicationService = (ReplicationService)appContext.getBean("ReplicationService"); actionTrackingService = (ActionTrackingService)appContext.getBean("actionTrackingService"); repositoryHelper = (Repository)appContext.getBean("repositoryHelper"); transactionService = (TransactionService)appContext.getBean("transactionService"); MutableAuthenticationService authenticationService = (MutableAuthenticationService)appContext.getBean("AuthenticationService"); PersonService personService = (PersonService)appContext.getBean("PersonService"); personManager = new TestPersonManager(authenticationService, personService, nodeService); UserTransaction txn = transactionService.getUserTransaction(); txn.begin(); personManager.createPerson(USER_NORMAL); // Ensure we start with no replication definitions // (eg another test left them behind) AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); for(ReplicationDefinition rd : replicationService.loadReplicationDefinitions()) { replicationService.deleteReplicationDefinition(rd); } txn.commit(); // Grab a reference to the data dictionary dataDictionary = nodeService.getChildByName( repositoryHelper.getCompanyHome(), ContentModel.ASSOC_CONTAINS, "Data Dictionary" ); AuthenticationUtil.clearCurrentSecurityContext(); }
Example 3
Source File: AbstractEmailMessageHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Add new node into Alfresco repository with specified parameters. Node content isn't added. * * @param nodeService Alfresco Node Service * @param parent Parent node * @param name Name of the new node * @param overwrite if true then overwrite an existing node with the same name. if false the name is changed to make it unique. * @param assocType Association type that should be set between parent node and the new one. * @return Reference to created node */ protected NodeRef addContentNode(NodeService nodeService, NodeRef parent, String name, QName assocType, boolean overwrite) { String workingName = encodeSubject(name); // Need to work out a new safe name. String baseName = FilenameUtils.getBaseName(workingName); String extension = FilenameUtils.getExtension(workingName); if(logger.isDebugEnabled()) { logger.debug("addContentNode name:" + workingName); } for(int counter = 1; counter < 10000; counter++) { QName safeQName = QName.createQNameWithValidLocalName(NamespaceService.CONTENT_MODEL_1_0_URI, workingName); NodeRef childNodeRef = nodeService.getChildByName(parent, ContentModel.ASSOC_CONTAINS, workingName); if (childNodeRef != null) { if(overwrite) { if(logger.isDebugEnabled()) { logger.debug("overwriting existing node :" + workingName); } // Node already exists // The node is present already. Make sure the name case is correct nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, baseName); return childNodeRef; } // Node already exists and not overwrite String postFix = "(" + counter + ")"; if(baseName.length() + extension.length() + postFix.length() > QName.MAX_LENGTH ) { // Need to truncate base name workingName = baseName.substring(0, QName.MAX_LENGTH - postFix.length() - extension.length() -1) + postFix; } else { workingName = baseName + postFix ; } if(extension.length() > 0) { workingName = workingName + "." + extension; } } else { // Here if child node ref does not already exist if(logger.isDebugEnabled()) { logger.debug("child node ref does not already exist :" + workingName); } Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(); contentProps.put(ContentModel.PROP_NAME, workingName); ChildAssociationRef associationRef = nodeService.createNode( parent, assocType, safeQName, ContentModel.TYPE_CONTENT, contentProps); childNodeRef = associationRef.getChildRef(); return childNodeRef; } } throw new AlfrescoRuntimeException("Unable to add new file"); }
Example 4
Source File: AbstractForumEmailMessageHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Posts content * * @param nodeRef Reference to node * @param message Mail parser * @return Returns the new post node */ protected NodeRef addPostNode(NodeRef nodeRef, EmailMessage message) { NodeService nodeService = getNodeService(); Date now = new Date(); String nodeName = "posted-" + new SimpleDateFormat("dd-MM-yyyy-hh-mm-ss").format(now) + ".html"; PropertyMap properties = new PropertyMap(3); properties.put(ContentModel.PROP_NAME, nodeName); NodeRef postNodeRef = nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, nodeName); if (postNodeRef == null) { ChildAssociationRef childAssoc = nodeService.createNode( nodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), ForumModel.TYPE_POST, properties); postNodeRef = childAssoc.getChildRef(); } // Add necessary aspects properties.clear(); properties.put(ContentModel.PROP_TITLE, nodeName); nodeService.addAspect(postNodeRef, ContentModel.ASPECT_TITLED, properties); properties.clear(); properties.put(ApplicationModel.PROP_EDITINLINE, true); nodeService.addAspect(postNodeRef, ApplicationModel.ASPECT_INLINEEDITABLE, properties); // Write content if (message.getBody() != null) { writeContent( postNodeRef, message.getBody().getContent(), message.getBody().getContentType(), message.getBody().getEncoding()); } else { writeContent(postNodeRef, "<The message was empty>", MimetypeMap.MIMETYPE_TEXT_PLAIN); } addEmailedAspect(postNodeRef, message); // Done return postNodeRef; }
Example 5
Source File: RunningActionRestApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") @Override protected void setUp() throws Exception { super.setUp(); ApplicationContext appContext = getServer().getApplicationContext(); nodeService = (NodeService)appContext.getBean("NodeService"); replicationService = (ReplicationService)appContext.getBean("ReplicationService"); actionTrackingService = (ActionTrackingService)appContext.getBean("actionTrackingService"); repositoryHelper = (Repository)appContext.getBean("repositoryHelper"); transactionService = (TransactionService)appContext.getBean("transactionService"); executingActionsCache = (SimpleCache<String, ExecutionDetails>)appContext.getBean("executingActionsCache"); MutableAuthenticationService authenticationService = (MutableAuthenticationService)appContext.getBean("AuthenticationService"); PersonService personService = (PersonService)appContext.getBean("PersonService"); personManager = new TestPersonManager(authenticationService, personService, nodeService); UserTransaction txn = transactionService.getUserTransaction(); txn.begin(); personManager.createPerson(USER_NORMAL); // Ensure we start with no replication definitions // (eg another test left them behind) AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); for(ReplicationDefinition rd : replicationService.loadReplicationDefinitions()) { replicationService.deleteReplicationDefinition(rd); } txn.commit(); // Grab a reference to the data dictionary dataDictionary = nodeService.getChildByName( repositoryHelper.getCompanyHome(), ContentModel.ASSOC_CONTAINS, "Data Dictionary" ); AuthenticationUtil.clearCurrentSecurityContext(); }