cancel
Showing results for 
Search instead for 
Did you mean: 

Added aspect OK but value not showing in UI

richardgunderse
Champ in-the-making
Champ in-the-making
Hi

I've got a custom aspect containing one property ('popularity'). In the UI I can see 'Popularity' on the properties page of a document I added. The value is blank.

My Java then tries to populate this value which I do with the following code

1) Get the reference to the document (docId is the filename e.g. Ford.html)

   public Reference getDocument(String docId) throws ServiceException, RemoteException, RepositoryFault, Exception {

      RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
      String queryString = "@cm\\:name:\"" + docId + "\"";
      Query query = new Query(Constants.QUERY_LANG_LUCENE, queryString);
      QueryResult queryResult = repositoryService.query(STORE, query, false);

      // Display the results
      ResultSet resultSet = queryResult.getResultSet();
      ResultSetRow[] rows = resultSet.getRows();
      Reference reference = null;
      if (rows == null) {
         System.out.println("No query results found.");
      }
      else if(rows.length > 1) {
         throw new Exception("Too many results");
      } else {
         System.out.println("Results from query:");
         outputResultSet(rows);

         // Get the id of the first result
         ResultSetRowNode node = rows[0].getNode();
         String documentId = node.getId();
         
         reference = new Reference(STORE, documentId, null);

      }
      return reference;
   }

2) Now I have the document, add the aspect values


   private void addAspect(Reference reference) {

      // Setting a property
      NamedValue[] specificationProps = new NamedValue[1];
      specificationProps[0] = Utils.createNamedValue("popularity", "Very Popular");      
      String aspectString = Constants.createQNameString("mycompany.cars", "myAspect");
      CMLAddAspect addAspect = new CMLAddAspect(aspectString, specificationProps, new Predicate(new Reference[] { reference }, null, null), "1");

      CML cml = new CML();
      cml.setAddAspect(new CMLAddAspect[] { addAspect });
      UpdateResult[] results = null;
      try {
         results = WebServiceFactory.getRepositoryService().update(cml);
         System.out.println("Aspect Added");
      } catch (RepositoryFault e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (RemoteException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      
   }

The code runs OK (no exceptions anyhow) but back in the UI, my 'popularity' value is still blank, whereas I was expecting it to say 'Very Popular'.

Just a thought: am I adding the aspect to the right thing??

Please help - thanks
2 REPLIES 2

richardgunderse
Champ in-the-making
Champ in-the-making
After I add my aspect, even though nothing appears on the Properties screen , if I do a search for my document again, and loop through the columns that come back, I do actually see my property value. It's stored under things like:

row 0: {}inxight.cars_x003a_myAspect_x003a_popularity = Quite Popular #7
row 0: {}inxight.cars_x003a_popularity = Quite Popular #4
row 0: {}ix_x003a_popularity = Quite Popular #5
row 0: {ix}popularity = Quite Popular #2
row 0: {inxight.cars}popularity = Quite Popular #8
row 0: {}popularity = Quite Popular #3

So my value is being stored somewhere but obviously not where the web interface is looking.

My name space is configured as follows

    <namespaces>
        <namespace uri="inxight.cars" prefix="ix"/>
    </namespaces>

And my Aspect is defined like this

    <aspects>
       <aspect name="ix:myAspect">
          <title>My Aspect</title>
          <properties>
             <property name="ix:popularity">
                <type>d:text</type>
                <mandatory>true</mandatory>
             </property>
          </properties>
       </aspect>
    </aspects>


I think there is some mismatch between how I set the property in the aspect, and the name that the UI is using to look it up.

Would be very grateful for any advice

richardgunderse
Champ in-the-making
Champ in-the-making
I found it! In case it helps anyone else, here is what I had to do.

Basically, I was using variations of my own namespace, but for the properties, you seem to have to prefix it with the standard Alfresco one.

Note the namespace I am now using (http://www.alfresco.org/model/content/1.0) below

      // Setting a property
      NamedValue[] props = new NamedValue[1];
      props[0] = Utils.createNamedValue("{http://www.alfresco.org/model/content/1.0}popularity", "Quite Popular #9");      
      String aspectString = Constants.createQNameString("inxight.cars", "myAspect");
      //CMLAddAspect addAspect = new CMLAddAspect(aspectString, specificationProps, new Predicate(new Reference[] { reference }, null, null), "1");
      CMLAddAspect addAspect = new CMLAddAspect();
      addAspect.setProperty(props);
      addAspect.setAspect(aspectString);
      addAspect.setWhere(new Predicate(new Reference[] {reference}, STORE, null));
   
      
      CML cml = new CML();
      cml.setAddAspect(new CMLAddAspect[] { addAspect });
      UpdateResult[] results = null;
      try {
         results = WebServiceFactory.getRepositoryService().update(cml);
         System.out.println("Aspect Added");
      } catch (RepositoryFault e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (RemoteException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

Now when I look at my document properties through the user interface, it has a value ('Quite popular #9').

If the shops weren't closed and I didn't have man-flu, I'd be getting a drink to celebrate….