How to get a custom attribute enumerated value using OSLC Java API in DNG

I have a custom attribute enumerated value. This attribute contains two labels called True and False with two values 1 and 0, respectively.
I think, the problem is that the client’s response and subsequent treatment to take the entity as a requirement class does not return the correct structure of this requirement. But i´m mot sure.

My code is:

private static boolean getAttributeLinks(String url, JazzRootServicesHelper helper, JazzFormAuthClient client, String projectArea) {
 boolean isValid = false;

 try {

  /* Get the URL of the OSLC QualityManagement catalog */
  String catalogUrl = helper.getCatalogUrl();

  /* Find the OSLC Service Provider for the project area we want to work with */
  String serviceProviderUrl = client.lookupServiceProviderUrl(catalogUrl, projectArea);

  //STEP 6: Get the Query Capabilities URL so that we can run some OSLC queries
  String queryCapability = client.lookupQueryCapability(serviceProviderUrl,
   OSLCConstants.OSLC_RM_V2,
   OSLCConstants.RM_REQUIREMENT_TYPE);

  //Get Feature Requirement Type URL
  ResourceShape featureInstanceShape = RmUtil.lookupRequirementsInstanceShapes(
   serviceProviderUrl, OSLCConstants.OSLC_RM_V2,
   OSLCConstants.RM_REQUIREMENT_TYPE, client, "Requirement");

  // We need to use Resource shapes to properly handle date attributes,
  // so they aren't interpreted as dateTime.
  // The following 4 lines will enable the logic to properly handle date attributes
  List < ResourceShape > shapes = new ArrayList < ResourceShape > ();
  shapes.add(featureInstanceShape);
  OSLC4JUtils.setShapes(shapes);
  OSLC4JUtils.setInferTypeFromShape("true");

  ClientResponse getResponse = client.getResource(url, OslcMediaType.APPLICATION_RDF_XML);
  Requirement requirement = getResponse.getEntity(Requirement.class);
  // Display attributes based on the Resource shape
  Map < QName, Object > requestExtProperties = requirement.getExtendedProperties();

  for (QName qname: requestExtProperties.keySet()) {
   Property attr = featureInstanceShape.getProperty(new URI(qname.getNamespaceURI() + qname.getLocalPart()));
   String name = null;
   if (attr != null) {
    name = attr.getTitle();

    if (name != null) {
     if (name.equals("CUSTOM_ATTR")) {

      if (requirement.getExtendedProperties().get(qname).toString().equals("True"))
       return true;
     }
    }
   }
  }

 } catch (Exception e) {
  logger.log(Level.SEVERE, e.getMessage(), e);
 }

 return isValid;

}

This code works fine if CUSTOM_ATTR is boolen type, but it do not work whether it´s enumerated value attribute.

Any suggestions on how to get the value from this enumerated attribute?

Thanks in advance.

1 Like

Hello Felipe and welcome!

I don’t have hands-on experience with DNG’s OSLC interface, unfortunately. But I think it’s not the first time the handling of enums came up w.r.t. to their handling in IBM products with OSLC 1 and OSLC 2 I/Fs. Let me CC @jamsden for help.

Cheers,
Andrew

Heads up @fbarreno, Nick replied with a clue on Slack, you can freely join via this link:

image

Thank you very much for the answer!

If I previously set the URI value associated with each of the attribute tags listed. Later
I can make a comparison of the URI that returns the attribute listed and I could already know the value of the
attribute listed. This seems to be going well.
My next question is: How can I change this value to the attribute?

Thanks in advance.