cancel
Showing results for 
Search instead for 
Did you mean: 

error getting aspects for content

targa2000
Champ in-the-making
Champ in-the-making
get reference to content, added custom aspect, then error when tried to retrieve aspects,

           var hmiFile = space.childByNamePath(nameOfFile);         

          // attach metadata to content        
          hmiFile.addAspect("atd:hyperwaveMeta",props);
         
          var fileAspects = hmiFile.aspects;  //error

error message:

java.lang.IllegalArgumentException(workspace://SpacesStore/bd07eb03-d448-48ba-ad13-ce9b56fd3db7#184)

in debugger aspects not defined for hmiFile.  What am I doing wrong?
6 REPLIES 6

targa2000
Champ in-the-making
Champ in-the-making
the aspect appears to be added correctly.  It just appears to be difficult to programatically access the aspects.

mikeh
Star Contributor
Star Contributor
Try this instead if you just want a list of the aspects on the node:
   var index,
      current = [],
      currentSet = node.aspectsSet.toArray();
  
   for (index in currentSet)
   {
      current.push(currentSet[index].toString());
   }

Thanks,
Mike

danw
Champ in-the-making
Champ in-the-making
So say a custom Aspect is the first entry in the currentSet.. how would one list all of the properties defined in that Aspect?  Also how would you pull the values of those properties out for a given node?

fbousson
Champ in-the-making
Champ in-the-making
I've had to write a custom javascript root object with a special method to list all the properties.


Create a class that extends from BaseScopableProcessorExtension and wire it in.

Here is the method I coded to retrieve the all the properties defined for an aspect.
Just check all the returned values (property names)on the node. if it's null, it means it's not filled in.

    /**
     * Retrieves all the properties defined on an aspect.
     *
     * @param anAspect
     * @return a list of propertiesnames.
     */
    public List<String> retrievePropertiesForAspect(String anAspect) {

        QName aspectQname = QName.createQName(anAspect);
        AspectDefinition aspectDefinition = getDictionaryService().getAspect(aspectQname);
        Map<QName, PropertyDefinition> props = aspectDefinition.getProperties();
        Set<QName> keys = props.keySet();

        List<String> propertyQNames = new ArrayList<String>();

        for (QName q : keys) {
            propertyQNames.add(q.toString());
        }


        return propertyQNames;
    }


And I'm also having a problem with accessing aspects on a node in javascript.

In FreeMarker i could just say myNode.aspects to list the aspect.
I get a nasty exception when i do the same in javascript. What gives?

fbousson
Champ in-the-making
Champ in-the-making
and the wiring;


  <bean id="myCustomScriptSupport" parent="baseJavaScriptExtension" class="be.ordina.myCustomScriptSupport">
    <property name="extensionName">
      <value>myCustomScriptSupport</value>
    </property>
  </bean>

you can now access the method using myCustomScriptSupport.*method*(*value*) in your javascript

targa2000
Champ in-the-making
Champ in-the-making
can check for a single aspect:

var tof = node.hasAspect("sm:someAspect");