<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sheila&#039;s Blog &#187; web service</title>
	<atom:link href="http://sheilapollard.com/tag/web-service/feed/" rel="self" type="application/rss+xml" />
	<link>http://sheilapollard.com</link>
	<description>Software Development</description>
	<lastBuildDate>Wed, 24 Mar 2010 17:19:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Alfresco Part Three &#8211; Create a new workspace using a web service call</title>
		<link>http://sheilapollard.com/2009/03/19/alfresco-part-three-create-a-new-workspace-using-a-web-service-call/?utm_campaign=feed&utm_medium=feed&utm_source=blog</link>
		<comments>http://sheilapollard.com/2009/03/19/alfresco-part-three-create-a-new-workspace-using-a-web-service-call/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 17:15:34 +0000</pubDate>
		<dc:creator>Sheila</dc:creator>
				<category><![CDATA[alfresco]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://sheilapollard.wordpress.com/?p=114</guid>
		<description><![CDATA[How to access create a new workspace in Alfresco using a web service API.]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://sheilapollard.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3NoZWlsYXBvbGxhcmQud29yZHByZXNzLmNvbS8yMDA5LzAzLzE2L2FsZnJlc2NvLXBhcnQtb25lLXVzaW5nLWFsZnJlc2NvLWZvci1kb2N1bWVudC1tYW5hZ2VtZW50Lw==">Part One</a> we covered the default installation of Alfresco and in <a href="http://sheilapollard.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3NoZWlsYXBvbGxhcmQud29yZHByZXNzLmNvbS8yMDA5LzAzLzE4L2FsZnJlc2NvLXBhcnQtdHdvLWRlcGxveWluZy1hbGZyZXNjby1vbi1qYm9zcy8=">Part Two</a> we covered a JBoss installation.  Now we&#8217;re going to look at how you would handle linking up your own web application with Alfresco web client.</p>
<p>The structure of the Alfresco repository is similar to that of nested folders or nodes.  You start with a root folder and then add sub folders that can contain content or more folders.  In Alfresco these folders are called spaces.  Each space or piece of content has its own node reference.</p>
<p>In our scenario you have a standalone web application and want to be able to link to Alfresco&#8217;s Web Client from it.  Alfresco will then handle all the content management functionality.  You have objects in your web application for which you want a corresponding workspace in Alfresco to contain any content for that object.  The functionality you need to add to your web application is:</p>
<p>1. When an object is created, create a corresponding workspace for that object in Alfresoc and retrieve the node reference for that workspace.<br />
2. Store the objects and matching node references (you will need to do this yourself).<br />
3. Select an object in your web application, get the node reference for the workspace in Alfresco, and open a new tab/window to view/update that workspace in Alfresco.<br />
4. You also want to bypass the Alfresco login page / authentication in all these scenarios so the user doesn&#8217;t have to enter login details.</p>
<p>At a minimum you will need the following jars in your web application:</p>
<blockquote><p>alfresco-web-service-client.jar<br />
axis-1.4.jar<br />
commons-discovery-0.2.jar<br />
wsdl4j-1.6.2.jar<br />
(jaxrpc.jar should already be available in a jboss application)<br />
commons-logging-1.1.jar<br />
wss4j.jar<br />
opensaml-1.0.1.jar<br />
xmlsec-1.4.1.jar</p></blockquote>
<p>Depending on the jar files already included in your application you may need to add some more jars.</p>
<p>We&#8217;ll start with authenticating a web service call that will create a new space.  To use a web service api you need to authenticate your session.</p>
<p>Authentication for web service API:</p>
<blockquote><p>// Start the session<br />
AuthenticationUtils.startSession(&#8220;admin&#8221;, &#8220;admin&#8221;);</p>
<p>try {<br />
	// Make your web service call in here<br />
}<br />
catch (Throwable e) {<br />
	System.out.println(e.toString());<br />
	e.printStackTrace();<br />
}<br />
finally {<br />
	// End the session<br />
        AuthenticationUtils.endSession();<br />
}
</p></blockquote>
<p>To create a workspace called &#8220;child&#8221; in the &#8220;parent&#8221; workspace using a web service call:</p>
<blockquote><p>// The default workspace store is SpacesStore<br />
Store storeRefence = new Store(Constants.WORKSPACE_STORE, &#8220;SpacesStore&#8221;);</p>
<p>// We want to create a new folder or workspace called child in the parent folder under company home<br />
// Create parent reference to the parent space in company home<br />
ParentReference parentReference = new ParentReference(storeReference, null, &#8220;/app:company_home/cm:parent&#8221;,<br />
        Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, &#8220;sample_folder&#8221;));</p>
<p>// Create the child folder<br />
NamedValue[] properties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, &#8220;Child Folder&#8221;) };<br />
CMLCreate create = new CMLCreate(&#8220;1&#8243;, parentReference, null, null, null, Constants.TYPE_FOLDER, properties);<br />
CML cml = new CML();<br />
cml.setCreate(new CMLCreate[] { create });<br />
UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml);</p>
<p>// From the result of the web service call we want to retrieve the node reference for the child folder so we can access it later<br />
String childReference = results[0].getDestination().getUuid();<br />
System.out.println(&#8220;Created a new workspace, node is: &#8221; + childReference);</p></blockquote>
<p>In Part Four we will handle generating a url to access the space we have just created and bypassing the login page when accessing the url.</p>
<br /><a href="http://sheilapollard.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3NoZWlsYXBvbGxhcmQud29yZHByZXNzLmNvbS8/cD0xMTQjY29tbWVudHM=" title=\"Comments on &quot;Alfresco Part Three &#8211; Create a new workspace using a web service call&quot;\"><img src="http://sheilapollard.com/wp-content/plugins/feed-comments-number/image.php?114" alt="Comments" /></a> <img src="http://sheilapollard.com/wp-content/plugins/feed-statistics.php?view=1&post_id=114" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://sheilapollard.com/2009/03/19/alfresco-part-three-create-a-new-workspace-using-a-web-service-call/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
