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 03:48  |
Eclipse User |
|
|
|
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 14:15   |
Eclipse User |
|
|
|
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 14:24] by 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 11:53   |
Eclipse User |
|
|
|
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 15:16   |
Eclipse User |
|
|
|
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 15:17] by Moderator
|
|
| | |
Goto Forum:
Current Time: Sun Mar 16 00:13:31 EDT 2025
Powered by FUDForum. Page generated in 0.06659 seconds
|