cancel
Showing results for 
Search instead for 
Did you mean: 

How to update the properties of a aspect on an existing docu

mightycoco
Champ in-the-making
Champ in-the-making
Hi,

I can upload a document and add a custom aspect without issues.
Now i try to download the aspect information of a node, update the values and re-apply the aspect to the existing document. This throws an SoapException without further details…


at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)\r\n   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Objec…

Here is the code I use to update the the aspect on the existing document. Categories is a internal list i use to store the aspect / attribute informations…


            RepositoryWebService.CML cml = new RepositoryWebService.CML();
            cml.addAspect = new RepositoryWebService.CMLAddAspect[Categories.Count];

            foreach (Category category in Categories) {
                RepositoryWebService.CMLAddAspect aspect = new RepositoryWebService.CMLAddAspect();
                RepositoryWebService.NamedValue[] aspectProps = new RepositoryWebService.NamedValue[category.Count];

               foreach (CategoryAttribute attribute in category)
                {
                    aspectProps[attribtCount] = CreateProperty(attribute.InternalKey, attribute.Value.ToString());
                    attribtCount++;
                }

                aspect.aspect = category.InternalName; // like "{http:/…/…}name"
                aspect.property = aspectProps;
                aspect.where = null;
                aspect.where_id = RepositoryID; // the ID of the document, having the category <<<< correct?
                cml.addAspect[aspectCount] = aspect;
                aspectCount++;

                Repository.update(cml); <<<<<<< this throws the exception, of course.
            }

Did I do anything wrong? Do i need to remove the aspect from the document, before i can add a new one?
I'm using the AddAspect property of the CLM object, which might not be the right one, as i don't want to add it (it's already there) but only want to update it's values with the given attributes.

Thanks in advance for any hints,
coco
6 REPLIES 6

kbonnet
Champ in-the-making
Champ in-the-making
Hi,

Since i'm not a java developer, just a generic answer.

If the aspect is already present, you cant add it another time. You just have to change the properties that come from the aspect.

Does that help?

Koen

mightycoco
Champ in-the-making
Champ in-the-making
Hi Koen,

Thanks for the additional info. At least, I'm on the right track using AddAspect…

The code is a C# snipped - but looks pretty the same, though.

I came as far as i get no more exceptions, when adding the aspect a second time. However, the changed value of the property isn't applied.

The funny thing is, that the versioning aspect is setting the 'modified' property to the time, when i did the web service request - something must had happen - but still: the values in the custom aspect aren't updated… Somehow i'm running out of ideas…

thanks in advance,
-coco

kbonnet
Champ in-the-making
Champ in-the-making
I think you should try to:
- check if the aspect is already applied
  - if not, add it
  - if so, do nothing
- change the properties
- save the object

Are you aware of the last point, that if you change properties, you need to save the object? At least that's needed via the ECMA/Javascript API. Probably the same via your API.

Koen

mightycoco
Champ in-the-making
Champ in-the-making
Hello Koen,

thanks again.

afaik, there is no specific 'save' precedure for objects in the web services api.

im doing
- fetching the proerties of a node via Repository.get(predicate);
- going through the namedValues of node.properties
- changing the value of a property in my custom aspect
- writing the data back via Repository.update(cml)

the code is pretty straight forward…
Maybe the problem is the id of the aspect - i'm using "1" as if you would add a new aspect. As I understood, this is a internal value and should always be "1" - but I'm not sure…

CMLAddAspect aspect = new RepositoryWebService.CMLAddAspect();
aspect.aspect = "{http://mydomain.com/model/content/1.0}myAspect";
aspect.property = properties; // my changed set of properties
aspect.where = predicate; // points to the document, the aspect is attached to
aspect.where_id = "1";

cml.addAspect = new RepositoryWebService.CMLAddAspect[] { aspect };
Repository.update(cml);

kbonnet
Champ in-the-making
Champ in-the-making
I never worked with C# and the web service before. May be you're helped with examples? The current Kofax Release script is written in VB (not sure if its VB6 or C#. This release script is also capable of adding aspects and setting properties. You can download it from the Alfresco Forge.

Hope that helps!

Koen

mightycoco
Champ in-the-making
Champ in-the-making
Koen, thank you!

the Kofax Release Script is written in C#. It's a bit of a mess, but I found the isssue:
I was using CMLAddAspect - to update an aspect you need to use CMLUpdate of course.  Smiley Surprisedops:
Sometimes you don't need a developer to help out, but only a second insight ;o)

pepkac…

thanks,
coco