2011년 11월 20일 일요일

Client API - 상태그룹 쿼리


repo.login(monitor);

IProcessClientService processClient = (IProcessClientService)repo.getClientLibrary(IProcessClientService.class);
URI uri = URI.create(prjAreaName.replaceAll(" ", "%20"));
IProjectArea prjArea = (IProjectArea)processClient.findProcessArea(uri, null, null);
IProjectAreaHandle prjAreaHandle = (IProjectAreaHandle)prjArea.getItemHandle();

IContributorManager contributorManager = repo.contributorManager();
IContributor kdyoung = contributorManager.fetchContributorByUserId(userId, null);
System.out.println(kdyoung.getEmailAddress());

IQueryClient queryClient = (IQueryClient) repo.getClientLibrary(IQueryClient.class);
IAuditableClient auditableClient = (IAuditableClient) repo.getClientLibrary(IAuditableClient.class);
IQueryableAttributeFactory attFactory = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);



IQueryableAttribute typeAttribute = attFactory.findAttribute(prjAreaHandle, IWorkItem.TYPE_PROPERTY, auditableClient, null);
Expression typeExpression = new AttributeExpression(typeAttribute, AttributeOperation.EQUALS, workItemTypeID);
IQueryableAttribute projectAreaAttribute = attFactory.findAttribute(prjAreaHandle, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, null);
AttributeExpression projectAreaExpression = new AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS, prjAreaHandle);
Term term1 = new Term(Operator.AND);
term1.add(typeExpression);
term1.add(projectAreaExpression);

IQueryableAttribute ownerAttribute = attFactory.findAttribute(prjAreaHandle, IWorkItem.OWNER_PROPERTY, auditableClient, null);
Expression ownerExpression = new AttributeExpression(ownerAttribute, AttributeOperation.EQUALS, kdyoung);
IQueryableAttribute stateAttribute = attFactory.findAttribute(prjAreaHandle, IWorkItem.STATE_PROPERTY, auditableClient, null);
//AttributeExpression stateExpression = new AttributeExpression(stateAttribute, AttributeOperation.EQUALS, prjAreaHandle);
Expression openStates = new VariableAttributeExpression(stateAttribute, AttributeOperation.EQUALS, new StatusVariable(IWorkflowInfo.OPEN_STATES));
Term term2 = new Term(Operator.AND);
term2.add(ownerExpression);
term2.add(openStates);

Term term = new Term(Operator.AND);
term.add(term1);
term.add(term2);

IQueryResult<IResolvedResult<IWorkItem>> queryResult = queryClient.getResolvedExpressionResults(prjAreaHandle, term, IWorkItem.FULL_PROFILE);
System.out.println("# of Query Results: " + queryResult.getResultSize(monitor).getTotal());

List<IWorkItem> matchingWorkItems = new ArrayList<IWorkItem>(queryResult.getResultSize(monitor).getTotalAvailable());
while (queryResult.hasNext(monitor)) {
matchingWorkItems.add(queryResult.next(monitor).getItem());
}

for (IWorkItem workItem : matchingWorkItems) {
System.out.println(workItem.getId() + " - " + workItem.getHTMLSummary().getPlainText());
IContributorHandle ich = workItem.getModifiedBy();
IContributor ic = auditableClient.resolveAuditable(ich, ItemProfile.CONTRIBUTOR_DEFAULT, monitor);
System.out.println(ic.getName());
}

TeamPlatform.shutdown();

댓글 없음:

댓글 쓰기