It's all about the answers!

Ask a question

Read custom Attributes of DNG Artifact using OSLC


Vaibhav S (106354) | asked Feb 24 '19, 12:52 a.m.

Hi, 


How can I read custom Attributes of DNG Artifacts using OSLC (eg Status2).

I tried using requirement.getExtendedProperties() but couldn’t get the desired result. 

Please let me know.

Thanks
Vaibhav

One answer



permanent link
Matthias Buettgen (23612332) | answered Feb 25 '19, 5:05 a.m.
I assume you're using Eclipse Lyo.

The extended Properties in a Lyo Object are originized in a Map. To get the value of a custom attribute, you new to know the URI defined in the Artifact Attributes. 

The you can simply fetch with the following statement


requirement.getExtendedProperties().get(new QName("http://your.namespace/definition","attributeName"));
    

Please notice, that's highly recommended to set the URI value for a custom attribute, otherwise DNG set's this value on it's own and this results in a DNG specific namespace and the custom attribute's unique identifier.


Comments
Vaibhav S commented Feb 26 '19, 9:12 p.m.

Hi Matthias,


Thanks for the response.

This approach has a constraint of knowing the Attribute Name and using in code.

My code wont have that information. Any work around for this where without using Attribute Name we can get the list of all Custom Attributes in any give Artifact.

Please let me know if there is an alternate approach to do so.

Objective: Get all the Custom Attributes and their values for any given Artifact; the names of Attributes being unknown to user's code.

With Thanks
Vaibhav


Matthias Buettgen commented Feb 27 '19, 2:18 a.m.
In Lyo all custom attraibutes can be found in the extended properties java.util.Map. So you simply need to assign them to a variable.

Map<QName, Object> custom = requirement.getExtendedProperties();

Please notice that you will also find DNG specific attributes or links like folder and access control which are not covered by the OSLC standard in the extended properties. They can usually identified by their namespace. So once you know them you can assume all others are custom attibutes.

If you are additionally interested in the labels you can fetch the resource shape of the artifact and search in the resource shape for the attribute defintions by using the keys for each unknown key value pair of the previously created Map.

You can get the resource shape by using this code.

ResourceShape shape = client.getResource(requirement.getInstanceShape().toString()).getEntity(ResourceShape.class);


Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.