Advanced vp search

Hello VP-Team,

we are working on a plugin for the VP Suite, that basicly extends the search functionality.
Therefore we’re iterating over all model elements, filtering them by one or more of the following criteria:

  • Search for Model Elements with specific comments (we named that “Model Status”)
  • Search for Model Elements with a specific stereotype
  • Search for Model Elements (Classes only) without Attributes
  • Search for Model Elements (Classes only) without Relationships
  • Search for Model Elements (Classes only) with Attributes that have no type
  • Search for Model Elements (Classes only) with Attributes that are no Model Elements
  • Search for Model Elements without Documentation

While implementing, we encountered two problems:

  1. We were not able to implement the first two search criteria. We tried to get access to a model element’s properties (e.g. stereotypes, comments) like this:

(IModelElement)object.getModelPropertyByName(“stereotypes”).getValue();

but this failed.

Our first question: How can we gain access to a model element’s properties correctly?

  1. We implemented all the other search criteria, but due to missing documentation of VP’s open api, we were not able to determine whether they work the way we intended.

We would kindly ask you to have a look on our code, respectively following java classes and give a feedback on whether we use the open api methods the way we intended so

that the search works correct and results are complete.

  • com.myvp.plugin.filter.ClassAttributesWithoutModelType.java
  • com.myvp.plugin.filter.ClassAttributesWithoutType.java
  • com.myvp.plugin.filter.ClassWithoutAttributeProperty.java
  • com.myvp.plugin.filter.ClassWithoutRelationshipProperty.java
  • com.myvp.plugin.filter.ObjWithoutDocumentationProperty.java

We’d appreciate any help.
Kind regards,
charon
vp-search.rar

Hi Charon,

Thanks for your post and details. For 1), “stereotypes” property is a model collection property, getValue() will return IModelElement[]. You can cast the property to IModelCollectionProperty, and then call IModelCollectionProperty.getValueAsModelArray():IModelElement[]

For 2):
== Search for Model Elements (Classes only) with Attributes that have no type ==
ClassAttributesWithoutType
if (attr.getType() == null) { <— here, better check does it return a empty String value, I am not sure vp-uml’s inline editing/open spec will set Null/Empty string to type.
return Boolean.TRUE;
}

== Search for Model Elements (Classes only) with Attributes that are no Model Elements ==
ClassAttributesWithoutModelType
only check this should be ok, don’t need get all models from project can check by name:
IAttribute attr = …; // you have get from iterator
IModelElement typeModel = attr.getTypeAsModel();
if (typeModel != null && ! (typeModel instanceof IDataType)) { // PS: I am not sure your purpose, but I think DataType is not a class you created in project, so, DataType not be considered as ModelType.
return false;
}

The other methods are okay. :slight_smile:

BTW, for documentation of OpenAPI, please visit:
http://www.visual-paradigm.com/documentation/pluginapi.jsp?format=html

Best regards,
Lilian Wong