Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Search WorkItems based on the value of the Custom Attribute.

Hi

I need to retrieve the WorkItems of a particular Project Area based on the value of custom attribute which will be entered by the user as a search key work. I developing a web application to search the work items based on the value of the custom attribute. At this point I am able to retrieve the all the work items of type defect from a particular Project area.
Now I am struck at returning the work items with the custom attribute value as entered by the user from the web application. Please try to guide me to reach my goal.

Thank you.
Sujith

0 votes



20 answers

Permanent link
This is the error which I got when I debugged the Application remotely

com.ibm.team.repository.common.transport.HostUnknownException: CRJAZ1368E The following URL cannot be reached: https://*******************************/ccm/versionCompatibility?clientVersion=4.0.4. The network stated that the URL is invalid. Error details: java.nio.channels.UnresolvedAddressException.         at com.ibm.team.repository.transport.client.ClientHttpUtil.executePrimitiveRequest(ClientHttpUtil.java:1310)         at com.ibm.team.repository.transport.client.ClientHttpUtil.executeHttpMethod(ClientHttpUtil.java:362)         at com.ibm.team.repository.transport.client.ClientHttpUtil.executeHttpMethod(ClientHttpUtil.java:321)         at com.ibm.team.repository.transport.client.ClientHttpUtil.executeHttpMethod(ClientHttpUtil.java:219)         at com.ibm.team.repository.transport.client.ClientHttpUtil.executeHttpMethod(ClientHttpUtil.java:228)         at com.ibm.team.repository.transport.client.RestClientConnectionBase.executeMethod(RestClientConnectionBase.java:315)         at com.ibm.team.repository.transport.client.RestClientConnectionBase.doMethod(RestClientConnectionBase.java:181)         at com.ibm.team.repository.transport.client.RestClientConnectionBase.doGet(RestClientConnectionBase.java:122)         at com.ibm.team.repository.transport.client.TeamRawRestServiceClient$RawRestClientConnection.doGet(TeamRawRestServiceClient.java:96)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         at java.lang.reflect.Method.invoke(Method.java:601)         at com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invokeServiceCall(ServiceInterfaceProxy.java:164)         at com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invoke(ServiceInterfaceProxy.java:88)         at com.ibm.team.repository.client.internal.RawRestServiceClientProxy$RestClientConnectionProxy.invoke(RawRestServiceClientProxy.java:121)         at $Proxy28.doGet(Unknown Source)         at com.ibm.team.repository.client.internal.TeamRepository.fetchClientVersionJSONObject(TeamRepository.java:1624)         at com.ibm.team.repository.client.internal.TeamRepository.access$0(TeamRepository.java:1621)         at com.ibm.team.repository.client.internal.TeamRepository$5.run(TeamRepository.java:1692)         at com.ibm.team.repository.client.internal.TeamRepository$5.run(TeamRepository.java:1)         at com.ibm.team.repository.client.internal.TeamRepository$3.run(TeamRepository.java:1287)         at com.ibm.team.repository.common.transport.CancelableCaller.call(CancelableCaller.java:79)         at com.ibm.team.repository.client.internal.TeamRepository.callCancelableService(TeamRepository.java:1280)         at com.ibm.team.repository.client.internal.TeamRepository.checkServerVersionMatches(TeamRepository.java:1695)         at com.ibm.team.repository.client.internal.TeamRepository.internalLogin(TeamRepository.java:1471)         at com.ibm.team.repository.client.internal.TeamRepository.login(TeamRepository.java:641)         at com.ibm.pureradnetezza.services.RTCPlainJavaConnection.getTeamRepositoryConnection(RTCPlainJavaConnection.java:57)         at com.ibm.pureradnetezza.controller.HomePageController.search(HomePageController.java:49)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         at java.lang.reflect.Method.invoke(Method.java:601)         at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)         at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)         at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)         at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)         at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)         at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)         at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)         at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)         at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)         at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)         at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)         at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)         at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)         at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)         at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)         at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)         at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)         at java.lang.Thread.run(Thread.java:722) Caused by: java.nio.channels.UnresolvedAddressException         at sun.nio.ch.Net.checkAddress(Net.java:85)         at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:597)         at com.ibm.team.repository.transport.client.InterruptableSocketFactory.doConnect(InterruptableSocketFactory.java:142)         at com.ibm.team.repository.transport.client.InterruptableSocketFactory.createSocket(InterruptableSocketFactory.java:69)         at com.ibm.team.repository.transport.client.SecureInterruptableSocketFactory.createSocket(SecureInterruptableSocketFactory.java:300)         at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)         at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)         at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)         at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)         at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)         at com.ibm.team.repository.transport.client.ClientHttpUtil.executePrimitiveRequest(ClientHttpUtil.java:1275)         ... 64 more

0 votes

Comments

I assume you have fixed your server access network problem

Not yet...I dono why its throwing Invalid url while its working fine from my local machine :(

cause that tomcat server doesn't use the same DNS server probably.

if you putty to the tomcat server can you ping that URL? u need to, but can't


Permanent link
Sam, how do we have to get the  user selected Severity value which is a Drop Down in RTC Web. because when I do workitem.getSeverity() its give me the literal.L1 .

0 votes

Comments

see my sample query code again,  to map the literal to text strings.

starting with
// this will throw exception if not enumeration
                            IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>) workItemCommon
                                    .resolveEnumeration(ia, monitor);

Can I use the below link for getting the selected literal value.

http://rsjazz.wordpress.com/2012/08/20/manipulationg-work-item-enumeration-values/

sure.. same stuff as mine.  nicer routines


Permanent link
Below is the code which I m trying to get the severity value, But its giving an assertion failed error. Where am i going wrong Sam

public static List<IWorkItem> 
getDefectWorkItems(IQueryResult<IResolvedResult<IWorkItem>> 
results,SysoutProgressMonitor monitor,ITeamRepository repo, String 
searchKey) throws TeamRepositoryException{
        List<IWorkItem> defectWorkitems=new ArrayList<IWorkItem>();
        List customAttributes=null;
        while(results.hasNext(monitor)){
            IResolvedResult<IWorkItem> result = results.next(monitor);
            IWorkItem workItem = (IWorkItem) result.getItem();
            customAttributes=workItem.getCustomAttributes();
            for (Iterator iterator = customAttributes .iterator(); iterator.hasNext();) {
                IAttributeHandle iAttributeHandle = (IAttributeHandle) iterator.next();
                IAttribute iAttribute = (IAttribute) repo
                        .itemManager().fetchCompleteItem(
                                iAttributeHandle, IItemManager.DEFAULT ,monitor);
                if (workItem.hasAttribute(iAttribute)) {
                    if(iAttribute.getDisplayName().equals("Appliance Serial Number")){
                        Object value = workItem.getValue(iAttribute);
                        RTCPlainJavaConnection.getLiteralbyID(workItem, iAttribute,  repo);                        System.out.println(iAttribute.getDisplayName()+" : "+String.valueOf(value)+" - "+" RTC Number : "+workItem.getId()+" Severity : "+workItem.getSeverity().getStringIdentifier()+" Summary : "+workItem.getHTMLSummary()); 
            }
                }
            }
            defectWorkitems.add(workItem);
        }
        System.out.println("Total Defect WorkItems:" + defectWorkitems.size());
        return defectWorkitems;
    }
    @SuppressWarnings("rawtypes")
   
 private static ILiteral getLiteralbyID(IWorkItem 
workItem,IAttributeHandle iAttribute, ITeamRepository repo) throws 
TeamRepositoryException {
        IWorkItemClient workItemClient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
        IEnumeration enumeration = workItemClient.resolveEnumeration(iAttribute, null);
        List literals = enumeration.getEnumerationLiterals();
        for (Iterator iterator = literals.iterator(); iterator.hasNext();) {
            ILiteral iLiteral = (ILiteral) iterator.next();
            if (iLiteral.getIdentifier2().getStringIdentifier().equals(workItem.getSeverity().getStringIdentifier())) {
                return iLiteral;
            }
        }
        return null;
    }

0 votes

Comments

probably this

        IEnumeration enumeration = workItemClient.resolveEnumeration(iAttribute, null)

note that there are different enum types.. and the process of reading them is different.. my dump workitems code handles all three.  enum, enumlist and enumlist (prior to V4)


Permanent link
And Sam, for now I need to just display 5 attributes like ID of the WorkItem, Summary, Description, Severity and Progress. So is it better to have a seperate pojo class names WorkItem and 5 variable which stores this above attribute values and return the arraylist of class workitem which can be sent to the JSP and then display. As of now I m rite away sending the IWorkItem ArrayList returned by the last method to the JSP.

0 votes

Comments

I don't think there is a 'better' answer.  I personally try to NOT use extra custom objects, only because the maintenance of the code and concepts..


Permanent link
Sam, i am getting the same Error as before

    IWorkItemCommon workItemCommon = (IWorkItemCommon) repo.getClientLibrary(IWorkItemCommon.class);
        IEnumeration enumeration = workItemCommon.resolveEnumeration(iAttribute, monitor); #Assertion Error
        IAuditableClient auditableClient = (IAuditableClient) repo.getClientLibrary(IAuditableClient.class);
        if (enumeration != null)
        {
            String[] iaval = iAttribute.getValue(auditableClient, workItem,
                    monitor).toString().split(":");
            if (iaval.length > 1 && iaval[1] != null)
            {
                List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
                for (ILiteral literal : enumerationLiterals)
                {
                    if (literal.getIdentifier2().getStringIdentifier().equalsIgnoreCase(iaval[1]))
                    {
                        System.out.println("\t\t\t\t --> attribute id="+ iAttribute.getIdentifier()
                                + ", type"+ "="+ iAttribute.getAttributeType()+ " literal="+ literal.getIdentifier2().getStringIdentifier()+ " literal name="+ literal.getName());
                        break;
                    }
                }
            }
        }

0 votes

Comments

yes, as expected.. note that the title of the original link topics is Assertion Failed.

https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes

note that the actual handling happens IN the Exception handler for one type


Permanent link
Can you please tell me from where does the enumeration code starting and where will it end in your example. Because I m confused and I m
iterating not through all the attributes  but just the custom attributes
(used: .getCustomAttributes)


List<iworkitem> defectWorkitems=new ArrayList<iworkitem>();
        List customAttributes=null;
        while(results.hasNext(monitor)){
            IResolvedResult<iworkitem> result = results.next(monitor);
            IWorkItem workItem = (IWorkItem) result.getItem();
            customAttributes=workItem.getCustomAttributes();
            for (Iterator iterator = customAttributes .iterator(); iterator.hasNext();) {
                IAttributeHandle iAttributeHandle = (IAttributeHandle) iterator.next();
                IAttribute iAttribute = (IAttribute) repo
                        .itemManager().fetchCompleteItem(
                                iAttributeHandle, IItemManager.DEFAULT ,monitor);
                if (workItem.hasAttribute(iAttribute)) {
                    if(iAttribute.getDisplayName().equals("Appliance Serial Number")){
                        Object value = workItem.getValue(iAttribute);
                        RTCPlainJavaConnection.getLiteralbyID(workItem, iAttribute,  repo);                        System.out.println(iAttribute.getDisplayName()+" : "+String.valueOf(value)+" - "+" RTC Number : "+workItem.getId()+" Severity : "+workItem.getSeverity().getStringIdentifier()+" Summary : "+workItem.getHTMLSummary()); 
            }
                }
            }
            defectWorkitems.add(workItem);
        }

0 votes


Permanent link
starts here
                        else if (ia.getAttributeType().toString()
                                .startsWith("enumerationList"))
                        {
                        ...
                        }
                        else
                        {
                            // this will throw exception if not enumeration
                            IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>) workItemCommon
                                    .resolveEnumeration(ia, monitor);
                         .....
                        }
                   }
                   catch(Exception ex)
                   {
                    and finishes here for the V3 enum list
                   }

0 votes

Comments

What is the XML string that you are passing to the method printAttributes
And I just need the attribute value of internalSeverity so can I use .findAttribute variable ??

in the pre-4.x RTC, the EnumerationList type info was stored in a special format in the process XML. there is no other way to tell.

I am confused, cause you shouldn't need any of this EnumeratonList stuff..

Sorry Sam, I couldn't reply back on that day. But I m now able to get the value of the enumeration chosen  by the user. Thanks a lot.

no problem. always my pleasure to help.

Hi Sam, I need a small information. I m not able to find the ID of an element which is found in the web interface. Its rite beside the summary element on top right corner. Its a combo-box with options like progress, resolved and so on. How can I find the ID of that enumeration element.

that is the status field with iD = com.ibm.team.workitem.attribute.state

its another field with different rules for mapping the text to the internal data

Identifier<IState> stateid = workitem.getState2()

System.out.println(" workitem state="+stateId.getStringIdentifier());

to locate the possible values.
        IAuditableClient auditableClient = (IAuditableClient) teamRepository
                .getClientLibrary(IAuditableClient.class);
        WorkflowManager wfm = new WorkflowManager(auditableClient);                              
                // get the workflow this workitem is in, so we can get the labels of the states
                IWorkflowInfo x =wfm.getWorkflowInfo(workItem, null);

Thanks a tom Sam. It worked !!

showing 5 of 7 show 2 more comments

Permanent link
Hi Sam, hope you are doing great. Do you have any idea on why I am getting the below error in the console and how can I rectify it.
ERROR: com.ibm.team.workitem.common - Value set provider not found: com.ibm.sport.rtc.common.ComponentBrowseValueSetUtils

0 votes

Comments

a valueset provider is either another class/jar file or a javascript application.

this one looks like a class.

I have not seen any doc or forum topics on how a plainjava application (like yours and most of mine) needs to be configured to be able to launch those providers.

So can I find the jar to avoid this error getting printed in the console or is there any other way to avoid it.

I do not know how to solve this problem.

Hi Sam,

I have a problem here. I need to pull all the defect WorkItems into an arraylist and then I have to perform a fuzzy search on the searched number. So When I am trying to get all the workitems into an arraylist with a large WorkItem profile. Its taking a very long time. And if I try to get small profile I am getting errors as there is no severity field included. So what can I do to get all the WorkItems into the arraylist in a low time.

Thanks,
Sujith G

you can make a custom profile.. and then pull them from each page of the query into the array.. I was able to process over 8,000 workitems in less than 12 seconds this way...  just takes memory

Oh that's great. Can you guide me on how to create a custom profile. Are there any Sample Code blocks that I can refer to get an Idea. Because I need to pull Custom Attribute, Severity Literal and State of a work Item.

see my comment in this topic.. page 1, search for

edited Aug 26, 9:08 a.m.

Sam I tried it as below but its taking long time as before

ItemProfile loadProfile = IWorkItem.SMALL_PROFILE.createExtension(
                Arrays.asList(new String[] {IWorkItem.SUMMARY_PROPERTY,IWorkItem.SEVERITY_PROPERTY,IWorkItem.DESCRIPTION_PROPERTY,IWorkItem.CUSTOM_ATTRIBUTES_PROPERTY,IWorkItem.STATE_PROPERTY}));
       

ItemProfile forworkitem = ItemProfile.createProfile(IWorkItem,
new String[] {IWorkItem.SUMMARY_PROPERTY,IWorkItem.SEVERITY_PROPERTY,
IWorkItem.DESCRIPTION_PROPERTY,IWorkItem.CUSTOM_ATTRIBUTES_PROPERTY,IWorkItem.STATE_PROPERTY}
);
like other variables, you only have to create this profile object once.

see next comment

then after you do this, you get the workitems first..
        IQueryResult<IResult> results = queryClient.getQueryResults(queryToRun);
        ((IQueryResult<IResult>) results).setLimit(Integer.MAX_VALUE);
        while (results.hasNext(null))
        {
            IResult result = results.next(null);
            IWorkItem workItem = (IWorkItem) auditableClient.resolveAuditable(
                    (IAuditableHandle) result.getItem(),
                    IWorkItem.FULL_PROFILE, null);
        }

I have tried the same as you told me in the above but had got the below error. So tried the way as I told you in my earlier comment.

"Exception Caught : java.lang.IllegalStateException: Attempting to get unset feature: ProjectArea"

Yup I rectified the above error by adding the projectArea Property. But still its talking a very long time to get 1600 workItems into the local ArrayList :/

showing 5 of 12 show 7 more comments

Permanent link
 Here is my code Sam. Can you please have a look and tell me whats going wrong

IQueryCommon queryCommon = (IQueryCommon) repo.getClientLibrary(IQueryCommon.class);
        IQueryDescriptor descriptor = queryCommon.createQuery(iProjectArea, "MyQuery", "MyQuery", typeinProjectArea);
        ItemProfile loadProfile = ItemProfile.createProfile(IWorkItem.ITEM_TYPE,new String[] {IWorkItem.SUMMARY_PROPERTY,IWorkItem.SEVERITY_PROPERTY,
                IWorkItem.DESCRIPTION_PROPERTY,IWorkItem.CUSTOM_ATTRIBUTES_PROPERTY,IWorkItem.STATE_PROPERTY,IWorkItem.PROJECT_AREA_PROPERTY}
                );
        return resultsResolvedByExpression(repo, iProjectArea, descriptor, loadProfile,monitor);
    }
    //Get the result set for the above compound query and store it in Resolved Result List.
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static List<RTCWorkItemAttributesBean> resultsResolvedByExpression(
            ITeamRepository teamRepository, IProjectArea projectArea,
            IQueryDescriptor query, ItemProfile profile , SysoutProgressMonitor monitor)
                    throws TeamRepositoryException {
        IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
        IQueryClient queryClient = workItemClient.getQueryClient();
        IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedQueryResults(query, profile);
        results.setLimit(Integer.MAX_VALUE);
        System.out.println("The WorkItems of "+projectArea.getName()+" Project Area:");
        return getDefectWorkItems(results,monitor,teamRepository, projectArea);
    }
    //Get the Work Item from the Resolved Result List and get all the Custom Attributes of that Work Item and return the ArrayList with the WorkItems
    public static List<RTCWorkItemAttributesBean> getDefectWorkItems(IQueryResult<IResolvedResult<IWorkItem>> results,SysoutProgressMonitor monitor,ITeamRepository repo, IProjectArea projectArea) throws TeamRepositoryException{
        RTCWorkItemListBean rtcWorkItemListBean=new RTCWorkItemListBean();
        while(results.hasNext(monitor)){
            IResolvedResult<IWorkItem> result = results.next(monitor);
            IWorkItem workItem = (IWorkItem) result.getItem();
            getAllWorkItemAttributes(workItem, monitor, repo, projectArea, rtcWorkItemListBean.getWorkItemList());
        }
        System.out.println("Total Defect WorkItems:" + rtcWorkItemListBean.getWorkItemList().size());
        return rtcWorkItemListBean.getWorkItemList();
    }
    //Iterate through all the WorkItems in a Specific WorkArea to find the Severity Literals.
   public static void getAllWorkItemAttributes(IWorkItem workItem,SysoutProgressMonitor monitor,ITeamRepository repo, IProjectArea projectArea, List<RTCWorkItemAttributesBean> workItemAttributes) throws TeamRepositoryException{
        try{
            IWorkItemCommon workItemCommon = (IWorkItemCommon) repo.getClientLibrary(IWorkItemCommon.class);
            RTCWorkItemAttributesBean rtcWorkItemAttributes=new RTCWorkItemAttributesBean();
            for (IAttribute iAttribute : workItemCommon.findAttributes(projectArea,monitor)){
                if(workItem.hasAttribute(iAttribute)){
                    if(iAttribute.getDisplayName().equals("Severity")){
                        Object value = workItem.getValue(iAttribute);
                        if (value instanceof Identifier) {
                            Identifier literalID = (Identifier) value;
                            ILiteral literal = getLiteralbyID(literalID, iAttribute ,repo, monitor);
                            String displayValue = literal.getName();
                            rtcWorkItemAttributes.setWorkItemID(workItem.getId());
                            rtcWorkItemAttributes.setWorkItemSummary(String.valueOf(workItem.getHTMLSummary()));
                            rtcWorkItemAttributes.setWorkItemDescription(String.valueOf(workItem.getHTMLDescription()));
                            rtcWorkItemAttributes.setWorkItemSeverity(displayValue);
                            rtcWorkItemAttributes.setWorkItemState(getWorkItemState(repo, workItem, monitor));
                            rtcWorkItemAttributes.setApplianceSerialNumber(getWorkItemApplianceNumber(repo, projectArea, workItem, monitor));
                        }
                    }
                }
            }
            workItemAttributes.add(rtcWorkItemAttributes);
        }catch(Exception ex){
            System.out.println("Exception Caught : "+ex.toString());
        }
    }
    //Find the Literal by passing the LiteralID 
    public static ILiteral getLiteralbyID(Identifier findLliteralID, IAttributeHandle iAttribute, ITeamRepository repo, SysoutProgressMonitor monitor) throws TeamRepositoryException {
        try{
            IWorkItemClient workItemClient = (IWorkItemClient)repo.getClientLibrary(IWorkItemClient.class);
            IEnumeration enumeration = workItemClient.resolveEnumeration(iAttribute, monitor);
            List literals = enumeration.getEnumerationLiterals();
            for (Iterator iterator = literals.iterator(); iterator.hasNext();) {
                ILiteral iLiteral = (ILiteral) iterator.next();
                if (iLiteral.getIdentifier2().equals(findLliteralID)) {
                    return iLiteral;
                }
            }
        }catch(Exception ex){
            System.out.println("Exception Caught : "+ex.toString());
        }
        return null;
    }
    //Get WorkItem Status from the WorkItem State ID 
    public static String getWorkItemState(ITeamRepository repo, IWorkItem iWorkItem, SysoutProgressMonitor monitor) throws TeamRepositoryException{
        IAuditableClient auditableClient = (IAuditableClient) repo.getClientLibrary(IAuditableClient.class);
        WorkflowManager workflowManager = new WorkflowManager(auditableClient);
IWorkflowInfo workflowInfo  =workflowManager.getWorkflowInfo(iWorkItem, monitor);
        return workflowInfo.getStateName(iWorkItem.getState2());
    }
    public static String getWorkItemApplianceNumber(ITeamRepository repo, IProjectArea iProjectArea ,IWorkItem iWorkItem, SysoutProgressMonitor monitor) throws TeamRepositoryException{
        IWorkItemClient workItemClient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
        IAttribute someAttribute= workItemClient.findAttribute(iProjectArea, "**********************", monitor);
        Object value = "";
        if(iWorkItem.hasAttribute(someAttribute)){
            value=iWorkItem.getValue(someAttribute);
        }
        return String.valueOf(value);
    }
}

0 votes

Comments

Hi Sam,

I am just trying to pull 1450 recording doing a custom profile as above but still it taking a considerable amount of time which is an inefficient task in a Web based application. Am I doing something wrong in the above code which is making the retrieval very slow.

Thanks
Sujith G

Okay Will do that.

Okay, Will do that

Thanks
Sujith G


Permanent link
Hi Sam,

Now the fetch time is reduced but only problem is When I am using custom profile I am getting the value of a custom Attribute as Null

ItemProfile loadProfile = ItemProfile.createProfile(IWorkItem.ITEM_TYPE,new String[] {IWorkItem.SUMMARY_PROPERTY,IWorkItem.CUSTOM_ATTRIBUTES_PROPERTY}
                );
Appliance Number Method:
public static String getWorkItemApplianceNumber(IProjectArea iProjectArea ,IWorkItem iWorkItem, SysoutProgressMonitor monitor,IWorkItemClient workItemClient) throws TeamRepositoryException{
        IAttribute someAttribute= workItemClient.findAttribute(iProjectArea, "sdi.workitem.attribute.ApplianceNumber", monitor);
        Object value = "";
        if(iWorkItem.hasAttribute(someAttribute)){
            value=iWorkItem.getValue(someAttribute);
        }
        return String.valueOf(value);
    }

0 votes

Comments

well, custom attributes are project are wide, not necessarily in every workitem tho.,

where are u getting the null value?

did u check to see if someAttribute was not null?



 I dont think the someAttribute is coming null because when I did syso(someAttr) I got some thing like below
(identifier: sdi.workitem.attribute.ApplianceID, attributeType: smallString, displayName: Appliance Serial Number, builtIn: false, internal: false, fullTextKind: _meta, readOnly: false, archived: false)
I am getting null when I trying to print the ApplianceID value i.e String.valueOf(value);

Only Using WorkItem profile as Full_Profile or Large_Profile I am able to get the Appliance ID. Instead If I use Small_Profile,Medium_Profile or a Custom Profile I am getting the value as Null :(

got it.. this is because FULL gives you EVERYTHING (without using a name)
and small and medium only give you NAMED things (large & full are the same)

you would have to use a custom profile AND add your attributes ID to the list

ItemProfile loadProfile = ItemProfile.createProfile(IWorkItem.ITEM_TYPE,new String[] {IWorkItem.SUMMARY_PROPERTY,IWorkItem.SEVERITY_PROPERTY,
                IWorkItem.DESCRIPTION_PROPERTY,IWorkItem.CUSTOM_ATTRIBUTES_PROPERTY,IWorkItem.STATE_PROPERTY,IWorkItem.PROJECT_AREA_PROPERTY,sdi.workitem.attribute.ApplianceNumber}


 

1 vote

Wonderful Sam, You are Awesome :)
It worked, Now I get it Small Medium will only get Named Stuff where as Default, Large, Full get all the things present for the workItem.

1–15 items
page 2of 1 pagesof 2 pages

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 11,074
× 369
× 170

Question asked: Aug 25 '14, 4:04 p.m.

Question was seen: 19,291 times

Last updated: Oct 01 '14, 10:03 a.m.

Related questions
Confirmation Cancel Confirm