Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Read custom Attributes of DNG Artifact using OSLC

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

0 votes



One answer

Permanent link
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.

0 votes

Comments

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

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 log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Feb 24 '19, 12:52 a.m.

Question was seen: 2,318 times

Last updated: Feb 27 '19, 2:18 a.m.

Confirmation Cancel Confirm