As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
ProjectName src/main/java/ MainClass.java src/ main/ java/ resources/ core/ cma-core-context.xml pom.xml
import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Vector; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.namespace.QName; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.rivetlogic.core.cma.api.SearchService; import com.rivetlogic.core.cma.api.SecurityService; import com.rivetlogic.core.cma.exception.AuthenticationFailure; import com.rivetlogic.core.cma.exception.AuthorityExistsException; import com.rivetlogic.core.cma.exception.CmaRuntimeException; import com.rivetlogic.core.cma.exception.InvalidTicketException; import com.rivetlogic.core.cma.impl.AuthenticationServiceImpl; import com.rivetlogic.core.cma.impl.ContentServiceImpl; import com.rivetlogic.core.cma.impl.PeopleServiceImpl; import com.rivetlogic.core.cma.impl.SearchServiceImpl; import com.rivetlogic.core.cma.repo.Node; import com.rivetlogic.core.cma.repo.SortDefinition; import com.rivetlogic.core.cma.repo.Ticket; /** * * @author Praveen C Elineni * @Rivet * */ public class mainClass { private static final String APPLICATION_CONTEXT = "classpath*:core/cma-core-context.xml"; public static void main(String[] args) { ConfigurableApplicationContext configurationApplicationContext = null; AuthenticationServiceImpl authenticationService = null; SearchServiceImpl searchService = null; ContentServiceImpl contentService = null; PeopleServiceImpl peopleService = null; Ticket ticket = null; QName name = QName.createQName("{http://www.alfresco.org/model/content/1.0}name"); QName created = QName.createQName("{http://www.alfresco.org/model/content/1.0}created"); List<QName> properties = new Vector<QName>(); properties.add(name); properties.add(created); List<String> requiredPermissions = new ArrayList<String>(4); requiredPermissions.add(SecurityService.READ_CONTENT); requiredPermissions.add(SecurityService.WRITE_CONTENT); requiredPermissions.add(SecurityService.WRITE_PROPERTIES); requiredPermissions.add(SecurityService.DELETE); QName nodeTypeQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}content"); String spacesStore = "workspace://SpacesStore"; String repositoryUri = "http://localhost:8080/alfresco/service"; String password = "admin"; String userid= "admin"; String fileName = "/tmp/rivetlogic.txt"; String data; // variables for user / group creation String groupName = "RivetGroup"; String userName = "rivet"; String passwd = "rivet"; String firstName = "Rivet"; String lastName = "Logic"; QName firstNameQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}firstName"); QName lastNameQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}lastName"); Map<QName, Serializable> props = null; props = new HashMap<QName, Serializable>(4); // homeFolder value must be a nodeRef props.put(firstNameQName, firstName); props.put(lastNameQName, lastName); configurationApplicationContext = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT); authenticationService = (AuthenticationServiceImpl) configurationApplicationContext.getBean("authenticationService"); searchService = (SearchServiceImpl) configurationApplicationContext.getBean("searchService"); contentService = (ContentServiceImpl) configurationApplicationContext.getBean("contentService"); peopleService = (PeopleServiceImpl) configurationApplicationContext.getBean("peopleService"); List<SortDefinition> sortDefinitions = new Vector<SortDefinition>(); sortDefinitions.add(new SortDefinition(SortDefinition.SortType.FIELD, "@{http://www.alfresco.org/model/content/1.0}name", false)); try { // Validate userid and password ticket = authenticationService.authenticate(repositoryUri, userid, password.toCharArray()); /* old search - deprecated in new release * * List<Node> nodes = searchService.query(ticket, new StoreRef(spacesStore), * SearchService.QueryLanguage.lucene, "@cm\\:name:\"javaapi\"", true, true, true, true, true, 1, 100, sortDefinitions); * */ // search for file with name "rivetlogic" List<Node> nodes = searchService.query(ticket, new StoreRef(spacesStore), SearchService.QueryLanguage.lucene, "@cm\\:name:\"rivetlogic\"", properties, true, true, true, true, requiredPermissions, 100, sortDefinitions); if (nodes != null) { // file found for (Node node: nodes) { System.out.println("node: " + node); NodeRef nodeRef = node.getNodeRef(); // get data from user System.out.println("Enter content to put in the file: "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); data = br.readLine(); br.close(); // write content to the file InputStream input = new ByteArrayInputStream(data.getBytes("UTF-8")); contentService.writeContentFromStream(ticket, nodeRef, nodeTypeQName, input); input.close(); System.out.println("Data has been written into the file /CompanyHome/rivetlogic.txt"); // open file and read data and dump it into fileName file. - "/tmp/javaapi.txt" FileOutputStream output = new FileOutputStream(fileName); contentService.readContentIntoStream(ticket, nodeRef, nodeTypeQName, output); output.close(); System.out.println("Reading data from the file"); // dump data on screen InputStream file = new FileInputStream(fileName); br = new BufferedReader(new InputStreamReader(file)); String str; System.out.println("Content of file (/CompanyHome/rivetlogic.txt) is: "); while ((str = br.readLine()) != null) { System.out.println(str); } br.close(); file.close(); } } // create user group in alfresco System.out.println("Creating the group called RivetGroup"); NodeRef userGroup = peopleService.createGroup(ticket, groupName); System.out.println("Creating the user called Rivet Logic"); NodeRef userRef = peopleService.createPerson(ticket, userName, passwd.toCharArray(), props); // add user to the group created System.out.println("Adding RivetLogic to RivetGroup"); peopleService.addAuthority(ticket, userGroup, userRef); // logout - invalidate ticket System.out.println("logging out. invalidating session."); authenticationService.invalidateTicket(ticket); } catch (AuthenticationFailure e) { e.printStackTrace(); } catch (InvalidTicketException e) { e.printStackTrace(); } catch (CmaRuntimeException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (AuthorityExistsException e) { e.printStackTrace(); } } }
<?xml version="1.0" encoding="UTF-8"?><project> <modelVersion>4.0.0</modelVersion> <groupId>com.rivetlogic</groupId> <artifactId>raar-demo</artifactId> <packaging>jar</packaging> <name>RAAR Demo</name> <version>0.0.1</version> <url>http://www.rivetlogic.com</url> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>Rivet Logic</id> <url>http://mvn.rivetlogic.com/artifactory/repo</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.rivetlogic</groupId> <artifactId>cma-api</artifactId> <version>1.7.1</version> </dependency> <dependency> <groupId>com.rivetlogic</groupId> <artifactId>cma-impl</artifactId> <version>1.7.1</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.0.2</version> </dependency> </dependencies> </project>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!– /* * Copyright (C) 2008 Rivet Logic Corporation. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ –> <beans> <bean id="cmaUnmarshaller" class="com.rivetlogic.core.cma.mapping.impl.CmaCastorUnmarshaller" /> <bean id="cmaMappingService" class="com.rivetlogic.core.cma.mapping.impl.CmaMappingServiceImpl" init-method="init"> <property name="mappingFile"><value>castor/mapping/mappingservice.mapping.xml</value></property> <property name="mappingConfiguration"><value>castor/mapping/mappingservice.configuration.xml</value></property> <property name="cmaUnmarshaller" ref="cmaUnmarshaller" /> </bean> <bean id="restExecuter" class="com.rivetlogic.core.cma.rest.impl.RestExecuterImpl" init-method="init"> <property name="cmaUnmarshaller" ref="cmaUnmarshaller" /> </bean> <bean id="actionService" class="com.rivetlogic.core.cma.impl.ActionServiceImpl"> <property name="serviceUri"><value>/cma/actionservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="authenticationService" class="com.rivetlogic.core.cma.impl.AuthenticationServiceImpl"> <property name="serviceUri"><value>/cma/authenticationservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="classificationService" class="com.rivetlogic.core.cma.impl.ClassificationServiceImpl"> <property name="serviceUri"><value>/cma/classificationservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="contentService" class="com.rivetlogic.core.cma.impl.ContentServiceImpl"> <property name="serviceUri"><value>/cma/contentservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="dictionaryService" class="com.rivetlogic.core.cma.impl.DictionaryServiceImpl"> <property name="serviceUri"><value>/cma/dictionaryservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="nodeService" class="com.rivetlogic.core.cma.impl.NodeServiceImpl"> <property name="serviceUri"><value>/cma/nodeservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="libraryService" class="com.rivetlogic.core.cma.impl.LibraryServiceImpl"> <property name="serviceUri"><value>/cma/libraryservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="mimetypeService" class="com.rivetlogic.core.cma.impl.MimetypeServiceImpl"> <property name="serviceUri"><value>/cma/mimetypeservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="peopleService" class="com.rivetlogic.core.cma.impl.PeopleServiceImpl"> <property name="serviceUri"><value>/cma/peopleservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="searchService" class="com.rivetlogic.core.cma.impl.SearchServiceImpl"> <property name="serviceUri"><value>/cma/searchservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="securityService" class="com.rivetlogic.core.cma.impl.SecurityServiceImpl"> <property name="serviceUri"><value>/cma/securityservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="transformationService" class="com.rivetlogic.core.cma.impl.TransformationServiceImpl"> <property name="serviceUri"><value>/cma/transformationservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="versionService" class="com.rivetlogic.core.cma.impl.VersionServiceImpl"> <property name="serviceUri"><value>/cma/versionservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> <bean id="workflowService" class="com.rivetlogic.core.cma.impl.WorkflowServiceImpl"> <property name="serviceUri"><value>/cma/workflowservice</value></property> <property name="restExecuter" ref="restExecuter" /> <property name="cmaMappingService" ref="cmaMappingService" /> </bean> </beans>
authenticationService.authenticate(repositoryUri, userid, password.toCharArray());
peopleService.createPerson(ticket, userName, passwd.toCharArray(), props);
peopleService.createGroup(ticket, groupName);
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cmaMappingService' defined in URL [file:/D:/Satyam.com/Satyam.com/WEB-INF/classes/satyam/cma-core-context.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastException: com.rivetlogic.core.cma.alfresco.webscripts.mapping.CmaMapping Caused by: java.lang.ClassCastException: com.rivetlogic.core.cma.alfresco.webscripts.mapping.CmaMapping at com.rivetlogic.core.cma.mapping.impl.CmaMappingServiceImpl.init(CmaMappingServiceImpl.java:113) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1160) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1122) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1085) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:273) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:68) at org.satyam.common.CmaCreation.main(CmaCreation.java:90)
Caused by: java.lang.ClassCastException: com.rivetlogic.core.cma.alfresco.webscripts.mapping.CmaMapping
public static final List<QName> QUERY_PROPERTIES = new Vector<QName>(6, 1) { private static final long serialVersionUID = 5649490531607878780L; { add(ContentModel.PROP_NAME); add(ContentModel.PROP_CREATOR); add(ContentModel.PROP_CREATED); add(ContentModel.PROP_MODIFIED); add(ContentModel.PROP_CONTENT); add(ContentModel.PROP_AUTHOR); } };
/** * Produces a Lucene query that would get all content and folder nodes, except system folders, within the supplied path * non-recursively. */ public static final String FORMAT_QUERY = "+PATH:\"%s/*\" +(TYPE:\"" + ContentModel.TYPE_FOLDER + "\" OR TYPE:\"" + ContentModel.TYPE_CONTENT + "\") -TYPE:\"" + ContentModel.TYPE_SYSTEM_FOLDER + "\"";
String queryStr = String.format(FORMAT_QUERY, "/app:company_home/cm:My Folder");
/** * Return a maximum of 100 nodes inside the given folder path */ List<Node> results = searchService.query(ticket, new StoreRef("workspace://SpacesStore"), SearchService.QueryLanguage.lucene, queryStr, new Vector<QName>(QUERY_PROPERTIES), false, false, false, false, null, 100, null);
Guido, The sample demo file for RAAr is available here:http://docs.rivetlogic.com/projects/cma/1.7.1/samples/raar-sample-1.ziphttp://docs.rivetlogic.com/projects/cma/1.7.1/samples/raar-sample-1.tar.gz- Praveen C Elineni
Hey all, thanks in advance for the help. I'm writing a file movement utility using the RAAR 1.5 api and Alf 2.1. I'm noticing that when a node is copied in the same folder, the paths of the two nodes remain identical. How does one change the path of the new node once it's created?
Also, is there a way to copy a node and specify the new name?
NodeRef rename(Ticket ticket, NodeRef nodeRef, String newName)
How do you change the password for the users programatically?
// create the node to represent the Person NodeRef newPerson = this.personService.createPerson(props); // ensure the user can access their own Person object this.permissionService.setPermission(newPerson, authority, permissionService.getAllPermission(), true); // create the ACEGI Authentication instance for the new user this.authenticationService.createAuthentication(authority, password.toCharArray());