03-16-2009 06:39 AM
package org.alfresco.sample;
import org.alfresco.webservice.action.Action;
import org.alfresco.webservice.action.Rule;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLCreate;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.ParentReference;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.Utils;
import org.alfresco.webservice.util.WebServiceFactory;
/**
* Testing WebServiceFactory.getActionService().saveRules()
*/
public class SaveActionWebServiceClient {
final static Store WORKSPACESTORE_SPACESSTORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
public static void main(String[] args) throws Exception {
// Start the session
AuthenticationUtils.startSession("admin", "admin");
try {
// Add a folder to save the rule to:
ParentReference refCompanyHome = new ParentReference(WORKSPACESTORE_SPACESSTORE, null, "/app:company_home", Constants.ASSOC_CONTAINS, Constants
.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "testings"));
NamedValue[] properties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, "testing rule") };
CMLCreate create = new CMLCreate("1", refCompanyHome, null, null, null, Constants.TYPE_FOLDER, properties);
CML cml = new CML();
cml.setCreate(new CMLCreate[] { create });
UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml);
String pathTestings = results[0].getDestination().getPath();
Reference refTestings = results[0].getDestination();
NamedValue propAssocName = Utils.createNamedValue("assoc-name", "{" + Constants.NAMESPACE_CONTENT_MODEL + "}copy");
NamedValue propDestinationFolder = Utils.createNamedValue("destination-folder", pathTestings);
NamedValue propAssocType = Utils.createNamedValue("assoc-type", "{" + Constants.NAMESPACE_CONTENT_MODEL + "}contains");
NamedValue propConvertCommand = Utils.createNamedValue("convert-command", "-thumbnail 100x100");
NamedValue propMimeType = Utils.createNamedValue("mime-type", "image/jpeg");
NamedValue[] actionParameters = new NamedValue[] { propAssocName, propDestinationFolder, propAssocType, propConvertCommand, propMimeType };
Action action = new Action();
action.setId("1");
action.setActionName("transform-bilag");
action.setTitle("Thumbnailtransformer");
action.setParameters(actionParameters);
Rule rule = new Rule();
rule.setRuleTypes(new String[] { "inbound" });
rule.setTitle("ThumbnailRule");
rule.setDescription("Make thumbnail of incoming jpgs");
rule.setExecuteAsynchronously(false);
rule.setAction(action);
rule.setOwningReference(refTestings);
rule.setRuleReference(refTestings);
Rule[] rules = new Rule[] { rule };
WebServiceFactory.getActionService().saveRules(refTestings, rules);
} catch (Throwable e) {
System.out.println(e.toString());
} finally {
// End the session
AuthenticationUtils.endSession();
System.exit(0);
}
}
}
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Date: Mon, 16 Mar 2009 10:13:12 GMT
Connection: close
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server.generalException</faultcode><faultstring></faultstring><detail><ns1:ActionFault xmlns:ns1="http://www.alfresco.org/ws/service/action/1.0"><ns1:errorCode>0</ns1:errorCode><ns1:message>Invalid store ref: Does not contain :// /app:company_home</ns1:message></ns1:ActionFault><ns2:exceptionName xmlns:ns2="http://xml.apache.org/axis/">org.alfresco.repo.webservice.action.ActionFault</ns2:exceptionName><ns3:stackTrace xmlns:ns3="http://xml.apache.org/axis/">
at org.alfresco.repo.webservice.action.ActionWebService.saveRules(ActionWebService.java:1041)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
</ns3:stackTrace><ns4:hostname xmlns:ns4="http://xml.apache.org/axis/">PC-087</ns4:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
05-18-2009 11:33 PM
Node folder = ContentHandler.createNodeByPath("/app:company_home/cm:test");
String idTo = ContentHandler.createNodeByPath("/app:company_home").getReference().getUuid();
NamedValue propDestinationFolder = Utils.createNamedValue("destination-folder", "workspace://SpacesStore/"+idTo);
NamedValue propAssocType = Utils.createNamedValue("assoc-type", "{" + Constants.NAMESPACE_CONTENT_MODEL + "}contains");
NamedValue propAssocName = Utils.createNamedValue("assoc-name", "{" + Constants.NAMESPACE_CONTENT_MODEL + "}move");
Action newAction = new Action();
newAction.setActionName("move");
newAction.setParameters(new NamedValue[]{propDestinationFolder, propAssocName, propAssocType});
// Create the action condition
Condition condition = new Condition();
condition.setConditionName("no-condition");
// Create the composite action
Action action = new Action();
action.setActionName("composite-action");
action.setActions(new Action[]{newAction});
action.setConditions(new Condition[]{condition});
// Create the rule
Rule newRule = new Rule();
newRule.setRuleTypes(new String[]{"inbound"});
newRule.setTitle("This rule adds the classificable aspect");
newRule.setDescription("This is the description of the rule");
newRule.setAction(action);
newRule.setOwningReference(folder.getReference());
WebServiceFactory.getActionService().saveRules(folder.getReference(), new Rule[]{newRule});
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.