Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Lyo » Query RTC repository for "metadata" such as project areas, work item types, and attributes
Query RTC repository for "metadata" such as project areas, work item types, and attributes [message #1708285] Tue, 15 September 2015 07:48 Go to next message
Geoff Alexander is currently offline Geoff AlexanderFriend
Messages: 21
Registered: November 2013
Junior Member
I'm looking to use Lyo/OSLC4J to create and link RTC work items. In support to creating and linking RTC work items, I first need to obtain a list of project area names in a given RTC repository. Then given a particular project area name, I need to obtain a list of work item types (display name and ID) defined in the project area. And finally, for a given work item type, I need to obtain a list of the work item type's attributes (again display name and ID).

I've been able to get list of the project area names by logging into the RTC server as follows:
   public static OslcRtcConnectionData jazzRtcLogin( String repositoryUrl,
         String repositoryUserId, String repositoryPassword )
         throws OslcErrorException
   {
      try
      {
         JazzRootServicesHelper helper = new JazzRootServicesHelper(
               repositoryUrl, OSLCConstants.OSLC_CM_V2 );
         JazzFormAuthClient client = helper.initFormClient( repositoryUserId,
               repositoryPassword );
         int result = client.formLogin();
         if (result != HttpStatus.SC_OK)
         {
            String details = (result == -1)
                  ? "JazzFormAuthClient.formLogin() returned -1" : HttpStatus
                        .getStatusText( result );
            String message = MessageFormat.format( LOGIN_ERROR_MESSAGE,
                  new Object[] { repositoryUrl, repositoryUserId, details } );
            throw new OslcErrorException( message );
         }
         return new OslcRtcConnectionData( client, helper );
      }
      catch (OslcClientApplicationException e)
      {
         String message = MessageFormat.format( LOGIN_ERROR_MESSAGE,
               new Object[] { repositoryUrl, repositoryUserId,
                     getExceptionDetails( e ) } );
         throw new OslcErrorException( message, e );
      }
   }


and then getting the project area names as follows:
   public static String[] getProjectAreaNames(
         OslcRtcConnectionData oslcRtcConnectionData )
         throws OslcErrorException
   {
      JazzFormAuthClient client = oslcRtcConnectionData.getClient();
      JazzRootServicesHelper helper = oslcRtcConnectionData.getHelper();
      try
      {
         String catalogUrl = helper.getCatalogUrl();
         ServiceProviderCatalog catalog = getResource( client, catalogUrl,
               ServiceProviderCatalog.class );
         ServiceProvider[] serviceProviders = catalog.getServiceProviders();
         String[] projectAreaNames = new String[serviceProviders.length];
         for (int i = 0; i < serviceProviders.length; ++i)
         {
            projectAreaNames[i] = serviceProviders[i].getTitle();
         }
         return projectAreaNames;
      }
      catch (Exception e)
      {
         String message = MessageFormat.format(
               GET_PROJECT_AREAS_ERROR_MESSAGE,
               new Object[] { client.getUrl(), getExceptionDetails( e ) } );
         throw new OslcErrorException( message, e );
      }
   }


where the getResource method is
   private static <T> T getResource( OslcClient client, String resourceUrl,
         Class<T> cls )
         throws IOException, OAuthException, OslcErrorException,
         URISyntaxException
   {
      ClientResponse response = client.getResource( resourceUrl,
            OslcMediaType.APPLICATION_RDF_XML );
      if (response.getStatusCode() != HttpStatus.SC_OK)
      {
         String message = MessageFormat.format(
               GET_RESOURCE_ERROR_MESSAGE,
               new Object[] { cls.getName(), resourceUrl,
                     Integer.toString( response.getStatusCode() ),
                     response.getMessage() } );
         response.consumeContent();
         throw new OslcErrorException( message );
      }
      return response.getEntity( cls );
   }


Is this proper way to get the list of project area names? Or is there a better approach?

I'm now trying to figure out how to the list of work item types for a given project area. The jazz.net forum topic, What is XML parameter for OSLC queries? says that https://SERVER:PORT/jazz/oslc/types/PROJECTID/ can be used to list all work item types for a project. The problem I have is that the ServiceProvider objects returned by ServiceProvider[] serviceProviders = catalog.getServiceProviders(); are only partially populated; in particular, serviceProvider.getIdentifier() returns null. Also, even if I had the project area identifier, I don't know how to use LYO/OSLC4J get the results of https://SERVER:PORT/jazz/oslc/types/PROJECTID/.

Any assistance would be greatly appreciated.
Re: Query RTC repository for "metadata" such as project areas, work item types, and attrib [message #1708459 is a reply to message #1708285] Wed, 16 September 2015 18:15 Go to previous messageGo to next message
Geoff Alexander is currently offline Geoff AlexanderFriend
Messages: 21
Registered: November 2013
Junior Member
I believe I've found a way to use Lyo/OSLC4J to obtain the list of work item types defined in a given project area using client.lookupCreationFactoryResource( serviceProviderUrl, OSLCConstants.OSLC_CM_V2, OSLCConstants.CM_CHANGE_REQUEST_TYPE ).getResourceShapes():
   public static WorkItemTypesData getWorkItemTypes( String projectAreaName,
         OslcRtcConnectionData oslcRtcConnectionData )
         throws OslcErrorException
   {
      JazzFormAuthClient client = oslcRtcConnectionData.getClient();
      JazzRootServicesHelper helper = oslcRtcConnectionData.getHelper();
      try
      {
         String catalogUrl = helper.getCatalogUrl();
         ServiceProviderCatalog catalog = getResource( client, catalogUrl,
               ServiceProviderCatalog.class );
         ServiceProvider[] serviceProviders = catalog.getServiceProviders();
         URI[] workItemTypeUrls = null;
         for (int i = 0; i < serviceProviders.length; ++i)
         {
            if (serviceProviders[i].getTitle().equals( projectAreaName ))
            {
               String serviceProviderUrl = serviceProviders[i].getAbout()
                     .toString();
               workItemTypeUrls = client.lookupCreationFactoryResource(
                     serviceProviderUrl, OSLCConstants.OSLC_CM_V2,
                     OSLCConstants.CM_CHANGE_REQUEST_TYPE )
                     .getResourceShapes();
              break;
            }
         }
         if (workItemTypeUrls == null)
         {
            String message = MessageFormat.format(
                  PROJECT_AREA_NOT_FOUND_ERROR_MESSAGE, new Object[] {
                        projectAreaName, client.getUrl() } );
            throw new OslcErrorException( message );
         }
         String[] displayNames = new String[workItemTypeUrls.length];
         String[] ids = new String[workItemTypeUrls.length];
         for (int i = 0; i < workItemTypeUrls.length; ++i)
         {
            ResourceShape workItemType = getResource( client,
                  workItemTypeUrls[i].toString(), ResourceShape.class );
            displayNames[i] = workItemType.getTitle();
            ids[i] = workItemType.getAbout().toString();
         }
         return new WorkItemTypesData( displayNames, ids );
      }
      catch (Exception e)
      {
         String message = MessageFormat.format(
               GET_PROJECT_AREAS_ERROR_MESSAGE,
               new Object[] { client.getUrl(), getExceptionDetails( e ) } );
         throw new OslcErrorException( message, e );
      }
   }

However I've encountered a problem with this. Instead of returning all work item types defined in the project area, client.lookupCreationFactoryResource( serviceProviderUrl, OSLCConstants.OSLC_CM_V2, OSLCConstants.CM_CHANGE_REQUEST_TYPE ).getResourceShapes() returns either a single random work item type or no work item type at all. Since client.lookupCreationFactoryResource( serviceProviderUrl, OSLCConstants.OSLC_CM_V2, OSLCConstants.CM_CHANGE_REQUEST_TYPE ).getResourceShapes() has random behavior, I'm thinking that this is a Lyo/OSLC4J defect. Can one of the Lyo Developer confirm this? If this is indeed a Lyo defect, how to I obtain a fix or a workaround?

I'm using the latest Lyo/OSLC4J download, Lyo/OSLC4J 2.1.

[Updated on: Wed, 16 September 2015 18:24]

Report message to a moderator

Re: Query RTC repository for "metadata" such as project areas, work item types, and attrib [message #1708463 is a reply to message #1708459] Wed, 16 September 2015 19:03 Go to previous messageGo to next message
Jim Ruehlin is currently offline Jim RuehlinFriend
Messages: 73
Registered: July 2009
Member
Have you stepped through JazzFormAuthClient and OslcClient? Those look like Jazz classes that are retrieving the service provider catalog list. If the values in those classes are not correct, then they'll be incorrect when you assign them to ServiceProviderCatalog catalog.
Re: Query RTC repository for "metadata" such as project areas, work item types, and attrib [message #1708464 is a reply to message #1708463] Wed, 16 September 2015 19:27 Go to previous messageGo to next message
Geoff Alexander is currently offline Geoff AlexanderFriend
Messages: 21
Registered: November 2013
Junior Member
Jim, thanks for getting back to me. JazzFormAuthClient and OslcClient are Lyo/OSLC4J client classes located in the org.eclipse.lyo.client.oslc.jazz and org.eclipse.lyo.client.oslc packages respectively. Since I'm using the downloaded Lyo/OSLC4J JAR files, I don't have source code for these classes and thus can't step thru the code.
Re: Query RTC repository for "metadata" such as project areas, work item types, and attrib [message #1708474 is a reply to message #1708464] Wed, 16 September 2015 21:59 Go to previous messageGo to next message
Jim Ruehlin is currently offline Jim RuehlinFriend
Messages: 73
Registered: July 2009
Member
Oops, didn't have the projects loaded in my workspace when I did my search so I made a quick assumption. In any case, I didn't see any issues with the code when I eyeballed it. The code hasn't been changed in a while and there are no similar bugs reported against this area (doesn't mean you haven't come across something though). But it's hard to guess what's going on in your runtime environment. I suggest you download the code and try setting some breakpoints to see how the server provider array is getting populated. If the problem doesn't start to show itself, ping me and we can do some screen sharing of your environment to figure out what's going on.

You can go here for instructions for importing and compiling the clients.java and samples.client projects (that's where the OSLC and Jazz classes are).

- Jim
Re: Query RTC repository for "metadata" such as project areas, work item types, and attrib [message #1709164 is a reply to message #1708474] Thu, 24 September 2015 14:45 Go to previous messageGo to next message
Geoff Alexander is currently offline Geoff AlexanderFriend
Messages: 21
Registered: November 2013
Junior Member
Jim, thanks for the information on building the latest Lyo/OSLC4J.

I traced OslcClient.lookupCreationFactoryResource and found that instead of creating a single CreationFactory instance and adding all work item type URIs to the CreationFactory instance's resourceShapes, OslcClient.lookupCreationFactoryResource instead creates multiple CreationFactory instances via the JenaModelHelper.fromResource method, adding a single work item type URI to some but not all of the CreationFactory instances via a recursive call to the the JenaModelHelper.fromResource method. And finally, OslcClient.lookupCreationFactoryResource returns the first CreationFactory instance created, which contains either a single work item type URI or no work item type URI. This doesn't seem correct to me.

I have attached a sample test program that logs information illustrating the problem.

[Updated on: Thu, 24 September 2015 15:02]

Report message to a moderator

Re: Query RTC repository for "metadata" such as project areas, work item types, and attrib [message #1710573 is a reply to message #1709164] Wed, 07 October 2015 15:53 Go to previous messageGo to next message
Jim Ruehlin is currently offline Jim RuehlinFriend
Messages: 73
Registered: July 2009
Member
I'm not seeing the recursive calls to JenaModelHelper in OslcClient.lookupCreationFactoryResource. It's iterating through the creation factories until it finds the oslcResourceType you want and returns that factory. It will return the first factory of that type that it finds if you don't specify an oslcUsage, otherwise it will return that oslcUsage creation factory.

If it can't find the factory you're looking for, it will return the default (if it exists), or the first factory in the domain (if it exists). This might be why you're seeing different results for different calls.

In any case, it only returns the creation factory for the OSLC resource (and optionally usage) that you specifically request. It looks like you need to iterate through the list of resources you want and specifically request each one.

Just in case we're not looking at the same version of the code, this is what I'm seeing for Oslc.ClientlookupCreationFactory:
public CreationFactory lookupCreationFactoryResource(final String serviceProviderUrl, final String oslcDomain, final String oslcResourceType, final String oslcUsage)
throws IOException, OAuthException, URISyntaxException, ResourceNotFoundException
{
CreationFactory defaultCreationFactory = null;
CreationFactory firstCreationFactory = null;

ClientResponse response = getResource(serviceProviderUrl,OSLCConstants.CT_RDF);
ServiceProvider serviceProvider = response.getEntity(ServiceProvider.class);

if (serviceProvider != null) {
for (Service service:serviceProvider.getServices()) {
URI domain = service.getDomain();
if (domain != null && domain.toString().equals(oslcDomain)) {
CreationFactory [] creationFactories = service.getCreationFactories();
if (creationFactories != null && creationFactories.length > 0) {
firstCreationFactory = creationFactories[0];
for (CreationFactory creationFactory:creationFactories) {
for (URI resourceType:creationFactory.getResourceTypes()) {

//return as soon as domain + resource type are matched
if (resourceType.toString() != null && resourceType.toString().equals(oslcResourceType)) {
//...but check oslc:usage if requested
if (oslcUsage != null) {
for (URI factoryUsage : creationFactory.getUsages()) {
if (oslcUsage.equals(factoryUsage.toString())) {
return creationFactory;
}
}
} else {
return creationFactory;
}
}
}
//Check if this is the default factory
for (URI usage:creationFactory.getUsages()) {
if (usage.toString() != null && usage.toString().equals(OSLCConstants.USAGE_DEFAULT_URI)) {
defaultCreationFactory = creationFactory;
}
}
}
}
}
}
}

//If we reached this point, there was no resource type match
if (defaultCreationFactory != null) {
//return default, if present
return defaultCreationFactory;
} else if (firstCreationFactory != null && firstCreationFactory.getResourceTypes().length ==0) {
//return the first for the domain, if present
return firstCreationFactory;
}

throw new ResourceNotFoundException(serviceProviderUrl, "CreationFactory");
}

Re: Query RTC repository for "metadata" such as project areas, work item types, and attrib [message #1710597 is a reply to message #1710573] Wed, 07 October 2015 19:16 Go to previous messageGo to next message
Geoff Alexander is currently offline Geoff AlexanderFriend
Messages: 21
Registered: November 2013
Junior Member
Jim, the problem isn't in the lookupCreationFactoryResource(final String serviceProviderUrl, final String oslcDomain, final String oslcResourceType, final String oslcUsage) method. I expect this method to return a single CreationFactory. Rather, the problem is in the following code from the fromResource(final Map<Class<?>, Map<String, Method>> classPropertyDefinitionsToSetMethods, final Class<?> beanClass, final Object bean, final Resource resource, Map<String,Object> visitedResources, HashSet<String> rdfTypes) method which creates a new a new parameter class instance and then recursively calls itself:

else
    {
							
        final Object nestedBean = setMethodComponentParameterClass.newInstance();

        fromResource(classPropertyDefinitionsToSetMethods,
                     setMethodComponentParameterClass,
                     nestedBean,
                     nestedResource,
                     visitedResources,
                     rdfTypes);

        parameter = nestedBean;
    }


The problem code is called multiple times with CreattionFactory as the parameter class thus creating multiple CreationFactory instances. Only one of these CreationFactory instances is returned; the the other simply get destroyed. Something seems wrong with this.

I wonder this "recursion" problem is because the response to the RTC service provider request, for example https://<host>:<port>/ccm/oslc/contexts/_pyf14FrmEeWs66yN_e1diA/workitems/services.xml, contains nested <oslc:creationFactory> elements.

...
<oslc:creationFactory>
  <oslc:CreationFactory>
    <dcterms:title rdf:parseType="Literal">Location for creation of Task change requests </dcterms:title>
    <oslc:usage rdf:resource="http://open-services.net/ns/cm#task"/>
    <oslc:usage rdf:resource="http://open-services.net/ns/cm#requirementsChangeRequest"/>
    <oslc:resourceType rdf:resource="http://open-services.net/ns/cm#ChangeRequest"/>
    <oslc:resourceType rdf:resource="https://sport6.rtp.raleigh.ibm.com:9463/ccm/oslc/types/_pyf14FrmEeWs66yN_e1diA/task"/>
    <oslc:resourceShape rdf:resource="https://sport6.rtp.raleigh.ibm.com:9463/ccm/oslc/context/_pyf14FrmEeWs66yN_e1diA/shapes/workitems/task"/>
    <oslc:creation rdf:resource="https://sport6.rtp.raleigh.ibm.com:9463/ccm/oslc/contexts/_pyf14FrmEeWs66yN_e1diA/workitems/task"/>
  </oslc:CreationFactory>
</oslc:creationFactory>
<oslc:creationFactory>
  <oslc:CreationFactory>
    <dcterms:title rdf:parseType="Literal">Location for creation of Story change requests </dcterms:title>
    <oslc:usage rdf:resource="http://open-services.net/ns/cm#planItem"/>
    <oslc:resourceType rdf:resource="http://open-services.net/ns/cm#ChangeRequest"/>
    <oslc:resourceType rdf:resource="https://sport6.rtp.raleigh.ibm.com:9463/ccm/oslc/types/_pyf14FrmEeWs66yN_e1diA/com.ibm.team.apt.workItemType.story"/>
    <oslc:resourceShape rdf:resource="https://sport6.rtp.raleigh.ibm.com:9463/ccm/oslc/context/_pyf14FrmEeWs66yN_e1diA/shapes/workitems/com.ibm.team.apt.workItemType.story"/>
    <oslc:creation rdf:resource="https://sport6.rtp.raleigh.ibm.com:9463/ccm/oslc/contexts/_pyf14FrmEeWs66yN_e1diA/workitems/com.ibm.team.apt.workItemType.story"/>
  </oslc:CreationFactory>
</oslc:creationFactory>
...

[Updated on: Wed, 07 October 2015 19:17]

Report message to a moderator

Re: Query RTC repository for "metadata" such as project areas, work item types, and attrib [message #1710706 is a reply to message #1710597] Thu, 08 October 2015 14:31 Go to previous messageGo to next message
Geoff Alexander is currently offline Geoff AlexanderFriend
Messages: 21
Registered: November 2013
Junior Member
I think I now understand the source of my confusion. Rather that returning an OSLC response with a single creation factory element containing multiple resource shape elements, RTC is returning multiple creation factory elements each containing either zero or one resource shape element. So while the underlying code in the JenaModelHelper.fromResource method is creating a CreationFactory instance for each creation factory element in the RTC response, the OslcClient.lookupCreationFactory method only returns one of the CreationFactory instances.

Since according to OSLC Core Specification Version 2.0, an oslc:service element can contain zero-or-many oslc:creationFactory elements, it seems strange that the OslcClient.lookupCreationFactory only returns a single CreationFactory.

Is there a way using Lyo/OSLC4J to return all creation factories for a specified service or at least some way to iterate thru the service's creation factories? I looked at the methods in both the JazzFormAuthClient and OslcClient classes, but didn't find anything that looks to do what I want.
Re: Query RTC repository for "metadata" such as project areas, work item types, and attrib [message #1710847 is a reply to message #1710706] Fri, 09 October 2015 17:01 Go to previous message
Jim Ruehlin is currently offline Jim RuehlinFriend
Messages: 73
Registered: July 2009
Member
An OSLC creation factory can support zero or more resource types. There should be a factory URL for each resource type. So you should probably iterate through the resource types (and OSLC usage if necessary) and get the creation factory for each one of those by calling OslcClient.lookupCreationFactory().
Previous Topic:DOORSOauthSample [DWA 9.5.2]
Next Topic:Error making POST call to DOORS[9.6] .
Goto Forum:
  


Current Time: Sun Sep 23 18:12:20 GMT 2018

Powered by FUDForum. Page generated in 0.05095 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top