how to get streams by project area using OSLC API/programatically
3 answers
. get a handle to project area
This is how I get all streams in a given project area using plain Java API:
IProjectArea projectArea = ...;
String repositoryURI = "https://myserver.jazz.com:9443/jts";
ITeamRepository teamRepository = TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);
IWorkspaceManager workspaceManager = (IWorkspaceManager) teamRepository.getClientLibrary(IWorkspaceManager.class);
List<IWorkspace> streams = new ArrayList<IWorkspace>();
IWorkspaceSearchCriteria workspaceSearchCriteria = IWorkspaceSearchCriteria.FACTORY.newInstance();
workspaceSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
try {
List<IWorkspaceHandle> workspaceHandles = workspaceManager.findWorkspaces(workspaceSearchCriteria, Integer.MAX_VALUE, null);
for (IWorkspaceHandle workspaceHandle : workspaceHandles) {
IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandle, null);
IProcessAreaHandle wsProcessAreaHandle = workspaceConnection.getProcessArea(null);
if (wsProcessAreaHandle != null) {
String wsProcessAreaHandleUUID = wsProcessAreaHandle.getItemId().getUuidValue();
if (wsProcessAreaHandleUUID.equals(projectArea.getItemId().getUuidValue())) {
IWorkspace stream = (IWorkspace) teamRepository.itemManager().fetchCompleteItem(workspaceHandle, IItemManager.DEFAULT, null);
streams.add(stream);
}
}
}
} catch (TeamRepositoryException e) {
e.printStackTrace();
}
public static final String CONFIGUTATION_MANAGEMENT_DOMAIN = "http://open-services.net/ns/config#"; public static final String CONFIGUTATION_MANAGEMENT_PREFIX = "oslc_config";
public static final String CONFIGURATION = CONFIGUTATION_MANAGEMENT_DOMAIN + "Configuration";
public static final String JAZZ_PROCESS_MANAGMENT_DOMAIN = "http://jazz.net/ns/process#";
@OslcNamespace(CONFIGUTATION_MANAGEMENT_DOMAIN)
@OslcResourceShape(title = "Stream Resource Shape", describes = CONFIGURATION)
public class Configuration extends AbstractResource {
private String title;
private URI serviceProvider;
private URI projectArea;
private URI baselines;
private URI component;
private final Set<URI> rdfTypes = new TreeSet<URI>();
public Configuration() {
super();
}
public Configuration(final URI about) {
super(about);
}
public void addRdfType(final URI rdfType)
{
this.rdfTypes.add(rdfType);
}
@OslcDescription("Title (reference: Dublin Core) or often a single line summary of the resource represented as rich text in XHTML content.")
@OslcOccurs(Occurs.ExactlyOne)
@OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "title")
@OslcTitle("Title")
@OslcValueType(ValueType.XMLLiteral)
public String getTitle()
{
return title;
}
@OslcDescription("The scope of a resource is a URI for the resource's OSLC Service Provider.")
@OslcPropertyDefinition(OslcConstants.OSLC_CORE_NAMESPACE + "serviceProvider")
@OslcRange(OslcConstants.TYPE_SERVICE_PROVIDER)
@OslcTitle("Service Provider")
public URI getServiceProvider()
{
return serviceProvider;
}
@OslcDescription("The scope of a resource is a URI for the resource's baselines.")
@OslcPropertyDefinition(CONFIGUTATION_MANAGEMENT_DOMAIN + "baselines")
@OslcTitle("Baselines")
public URI getBaselines()
{
return this.baselines;
}
@OslcDescription("The scope of a resource is a URI for the resource's baselines.")
@OslcPropertyDefinition(CONFIGUTATION_MANAGEMENT_DOMAIN + "component")
@OslcTitle("Component")
public URI getComponent()
{
return this.component;
}
@OslcDescription("The scope of a resource is a URI for the resource's project area.")
@OslcPropertyDefinition(JAZZ_PROCESS_MANAGMENT_DOMAIN + "projectArea")
@OslcTitle("Project Area")
public URI getProjectArea()
{
return this.projectArea;
}
@OslcDescription("The resource type URIs.")
@OslcName("type")
@OslcPropertyDefinition(OslcConstants.RDF_NAMESPACE + "type")
@OslcTitle("Types")
public URI[] getRdfTypes()
{
return rdfTypes.toArray(new URI[rdfTypes.size()]);
}
public void setTitle(final String title)
{
this.title = title;
}
public void setServiceProvider(final URI serviceProvider)
{
this.serviceProvider = serviceProvider;
}
public void setBaselines(final URI baselines)
{
this.baselines = baselines;
}
public void setComponent(final URI component)
{
this.component = component;
}
public void setProjectArea(final URI projectArea)
{
this.projectArea = projectArea;
}
public void setRdfTypes(final URI[] rdfTypes)
{
this.rdfTypes.clear();
if (rdfTypes != null)
{
this.rdfTypes.addAll(Arrays.asList(rdfTypes));
}
}
}