10-03-2008 08:48 AM
10-06-2008 11:14 PM
10-07-2008 06:43 AM
10-07-2008 11:24 AM
10-22-2008 12:29 PM
10-24-2008 01:26 AM
10-27-2008 06:55 PM
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);
10-28-2008 03:28 AM
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)
10-28-2008 10:07 AM
Caused by: java.lang.ClassCastException: com.rivetlogic.core.cma.alfresco.webscripts.mapping.CmaMapping
10-29-2008 08:05 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.