cancel
Showing results for 
Search instead for 
Did you mean: 

Any Examples of assigning metadata via the Java API?

fraser_crichton
Champ in-the-making
Champ in-the-making
Hi,

I'm looking for some examples of uploading a file into the Alfresco Repository  and then assigning Dublin Core metadata to it.

I've had a look at SimpleExampleWithContent which shows how to upload a file but not how to assign metadata to it.

In the Data Dictionary guide it says -

"The Alfresco public APIs provide support for managing custom Content Types and Aspects. For example, the Java API provides a Node Service which allows the creation of content of any Content Type, the setting and getting of Property values and the application of Content Aspects.

Types, Aspects, Properties and Associations are referred to by their name as defined in the model. "

and under the Node Service there are methods for getting and setting aspects and properties - which I'm guessing is how you'd set the metadata??

Any help would be much appreciated.

Cheers,

Fraser
2 REPLIES 2

fraser_crichton
Champ in-the-making
Champ in-the-making
Answering my own question here, I'm guessing I use the JCR API and specifically this -

Node companyHome = rootNode.getNode("app:company_home");
Node encyclopedia = companyHome.addNode("wiki:encyclopedia", "cm:folder");


Node page1 = encyclopedia.addNode("wiki:entry", "wikiSmiley Tongueage");
page1.setProperty("cm:title", "rose");
page1.setProperty("cm:content", "A rose is a flowering shrub.");
page1.setProperty("wiki:category", new String[] {"flower", "plant", "rose"});


Node page2 = encyclopedia.addNode("wiki:entry", "wikiSmiley Tongueage");
page2.setProperty("cm:title", "Shakespeare");
page2.setProperty("cm:content", "A famous poet who likes roses.");
page2.setProperty("wiki:category", new String[] {"poet"});


session.save();


I'm also guessing I'll have to configure the use of Dublin Core before I can set specific DC properties, perhaps?

If someone could confirm any of this it would be nice, even to hear I'm barking up the wrong tree entirely would be useful.

davidc
Star Contributor
Star Contributor
Hi Fraser,

Yes, you can use the JCR api.  The set of permitted property names is defined by the node type and aspect definitions.  So, if you want Dublin Core properties, add the dublin core aspect to the node and call setProperty for each DC property.  The name of the property is made up of namespace:localname (e.g. cm:title).  You can read up on type and aspect definitions at http://www.alfresco.org/mediawiki/index.php/Data_Dictionary_Guide.

There are also other api's (http://www.alfresco.org/mediawiki/index.php/Alfresco_Content_Management_Java_API)
- Alfresco service java API
- Alfresco web service API

They all follow the same pattern where an equivalent setProperty method is provided which takes the property name (as namespace:localname) and value.