cancel
Showing results for 
Search instead for 
Did you mean: 

How to add custom metadata during execution?

jtorres
Champ in-the-making
Champ in-the-making
Hi people:

I've seen the process to add custom metadata to a file using Web Services: I simply add it to the contentModel.xml, start the Alfresco server and then this metadata is already available to add to a file.

My question if is I can do a "warm add", this is, with the server runing and with no need to modify contentModel.xml I'd like to have the posibility that the user creates a new metadata from a web interface using Web Services.

Thanks for your help.
4 REPLIES 4

nimind
Champ in-the-making
Champ in-the-making
i am interested too. answers?

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

It is possible to add a model to the repo at run time, but it is currently unsupported.

Here is a quick example of how it can be done …


       // Load a custom model using the cm:dictionaryModel type
        CMLCreate create = new CMLCreate();
        create.setId("id1");
        create.setType(Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "dictionaryModel"));

        ParentReference parentReference = new ParentReference(new Store(Constants.WORKSPACE_STORE, "SpacesStore"), null, "/app:company_home", Constants.ASSOC_CONTAINS, Constants.ASSOC_CONTAINS);                   
       
        create.setParent(parentReference);
        create.setProperty(new NamedValue[] {
                        new NamedValue(
                                Constants.PROP_NAME,
                                false,
                                "testModel.xml",
                                null),
                        new NamedValue(
                                Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "modelActive"),
                                false,
                                "true",
                                null)});
       
        CML cml = new CML();
        cml.setCreate(new CMLCreate[]{create});
        UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml);
        Reference model = results[0].getDestination();
       
        // Now add the content to the model
        InputStream viewStream = getClass().getClassLoader().getResourceAsStream("org/alfresco/webservice/test/resources/propertymodel.xml");
        byte[] bytes = ContentUtils.convertToByteArray(viewStream);
        this.contentService.write(model, Constants.PROP_CONTENT, bytes, new ContentFormat(Constants.MIMETYPE_XML, "UTF-8"));

This model will now be included in the dictionary.  It will also be picked up when the repo is re-started so this need only be done once.

Hope this helps,
Roy

christophes
Champ in-the-making
Champ in-the-making
It is possible to add a model to the repo at run time, but it is currently unsupported.

Does this option is supported in the V2.0 of Alfresco?

If yes, how can we implement that.

Thank you in advance.

Christophe.

rwetherall
Confirmed Champ
Confirmed Champ
The method to add a model at runtime is implemented in version 2.0, but is not a supported feature.

I'm not sure when this capability will be expanded to be a supported feature.

Cheers,
Roy