It's all about the answers!

Ask a question

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


Felipe Barreno (112) | asked Nov 08 '19, 4:36 a.m.

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.

Be the first one to answer this question!


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.