It's all about the answers!

Ask a question

AssertionFailedException problem with getting the values of attributes


0
1
Robert Siara (821014) | asked Nov 23 '12, 4:34 p.m.
edited Nov 23 '12, 6:56 p.m.
I have a problem with getting the values of attributes ​​(built in and custom).

I use this code to get the built-in attributes and their values.

List<IAttributeHandle> builtInAttributeHandles = service.findBuiltInAttributes(projectArea, monitor);
IFetchResult builtIn = repository.itemManager().fetchCompleteItemsPermissionAware(builtInAttributeHandles,IItemManager.REFRESH, monitor);
for (Iterator it = builtIn.getRetrievedItems().iterator(); it.hasNext();) {
com.ibm.team.workitem.common.model.IAttributeHandle handle = (IAttributeHandle) it.next();
com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT,new NullProgressMonitor());
System.out.println("  Built In Attribute: "+ attribute.getDisplayName());
System.out.println(" Type: " + attribute.getAttributeType());
try {
     System.out.println("  Value "+ resolved.getItem().getValue(attribute));
    } catch (AssertionFailedException e) {
     System.out.println(e.toString());
     }
 }

But i always get AssertionFailedException ( i know that i need use different method for enumeration but even for other atributtes i get this exception)



This code I use for enumeration (borrowed from this forum)
 System.out.println(" type"+"="+attribute.getAttributeType());
 System.out.println(" value"+"="+item.getValue(attribute));
 IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemClient.resolveEnumeration(attribute, null);
 IAuditableClient iac = (IAuditableClient) repository.getClientLibrary(IAuditableClient.class);
 if(enumeration!=null){
 IAuditableClient auditableClient = (IAuditableClient )repository.getClientLibrary(IAuditableClient.class);
 String[] iaval = attribute.getValue(auditableClient, item, null).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("attribute name="+attribute.getIdentifier() +", type"+"="+attribute.getAttributeType()+" literal="+literal.getIdentifier2().getStringIdentifier()+" literal name="+literal.getName());                                       
  break;
 }
 }
 }
 }

I will be very grateful for help

edit:
Also i have problem with format code in this post, I do not know that anyone will want to read it :/

Accepted answer


14 other answers



permanent link
Robert Siara (821014) | answered Nov 26 '12, 8:54 a.m.
edited Nov 26 '12, 8:55 a.m.
I use Your function only for custom atributtes , therefore, this condition does not help.
Please look at my code.


permanent link
sam detweiler (12.5k6195201) | answered Nov 26 '12, 8:39 a.m.
thanks for the fix for the deprecated call.

my printAttributes can handle just custom if you add a check for

if (workItem.hasAttribute(ia))  && !ia.isBuiltin())

I have not used the getCustomAttributes() method cause I choose to loop thru all



permanent link
Robert Siara (821014) | answered Nov 26 '12, 8:10 a.m.
edited Nov 26 '12, 9:08 a.m.
I tried to use your function "static void printAttributes()" in my code , but for this line, the compiler returns:
 "The method getPeer(Class<IWorkItemCommon>) from the type IAuditableCommon is deprecated
"
so i tried replace this line to "IWorkItemCommon workItemCommon = (IWorkItemCommon) repository.getClientLibrary(IWorkItemCommon.class);"
but for both solutions i dont get any result:

In addition, I send my code:

public class mRTC2 {

    static String repository_address = "xxxxx";
    static String userId = "xxxx";
    static String password = "xxxx";
    static String projectAreaName = "xxxxxx";

    public static void main(String[] args) throws TeamRepositoryException {

        System.out.println("Main runned");
        TeamPlatform.startup();
        ITeamRepository repository = TeamPlatform.getTeamRepositoryService()
                .getTeamRepository(repository_address);

        repository.registerLoginHandler(new ITeamRepository.ILoginHandler() {
            public ILoginInfo challenge(ITeamRepository repository) {
                return new ILoginInfo() {
                    public String getUserId() {
                        return userId;
                    }

                    public String getPassword() {
                        return password;
                    }
                };
            }
        });

        // IProgressMonitor monitor = new SysoutProgressMonitor();
        IProgressMonitor monitor = null;
        try {
            repository.login(null);
        } catch (TeamRepositoryException e) {
            e.printStackTrace();
        }
        if (repository.getState() == 1) {
            System.out.println("CONNECTED to: " + repository_address);
        }

        // --------------
        IWorkItemClient service = (IWorkItemClient) repository
                .getClientLibrary(IWorkItemClient.class);
        IQueryClient queryClient = (IQueryClient) repository
                .getClientLibrary(IQueryClient.class);
        IProcessClientService processClient = (IProcessClientService) repository
                .getClientLibrary(IProcessClientService.class);
        URI uri = URI.create(projectAreaName.replaceAll(" ", "%20"));
        IProjectArea projectArea = (IProjectArea) processClient
                .findProcessArea(uri, null, null);
        IAuditableClient iac = (IAuditableClient) repository.getClientLibrary(IAuditableClient.class);
       
        // getting workitems
        Term term = new Term(Operator.AND);
        IQueryResult<IResolvedResult<IWorkItem>> result = queryClient
                .getResolvedExpressionResults(projectArea, term,
                        IWorkItem.FULL_PROFILE);

        for (int k = 0; result.hasNext(null); k++) {
            System.out.println("WORKITEM------------------------------------------------");

            IResolvedResult<IWorkItem> resolved = result.next(null);
            //Custom attributes
            WorkItem wi = new WorkItem();
            if (!resolved.getItem().getCustomAttributes().isEmpty()) {
                for (int i = 0; i < resolved.getItem().getCustomAttributes()
                        .size(); i++) {
                    com.ibm.team.workitem.common.model.IAttributeHandle handle = resolved
                            .getItem().getCustomAttributes().get(i);
                    com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository
                            .itemManager().fetchCompleteItem(handle,
                                    IItemManager.DEFAULT,
                                    new NullProgressMonitor()); //
                    System.out.println("The attribute id: "
                            + attribute.getIdentifier());
                    System.out.println("The attribute name: "
                            + attribute.getDisplayName());
                    System.out.println("The value of the custom attribute: "
                            + resolved.getItem().getValue(attribute));
                            printAttributes(resolved.getItem(), repository, iac, projectArea, monitor);
                    try {
                       
                    } catch (Exception e) {
                        System.out.println("ASSERTION FAILED!!!!");
                    }
                }
            }
            //Builtin attributtes
           
            List<IAttributeHandle> builtInAttributeHandles = service
                    .findBuiltInAttributes(projectArea, monitor);
            IFetchResult builtIn = repository.itemManager()
                    .fetchCompleteItemsPermissionAware(builtInAttributeHandles,
                            IItemManager.REFRESH, monitor);
           
            for (Iterator it = builtIn.getRetrievedItems().iterator(); it
                    .hasNext();) {
                com.ibm.team.workitem.common.model.IAttributeHandle handle = (IAttributeHandle) it
                        .next();
                com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository
                        .itemManager()
                        .fetchCompleteItem(handle, IItemManager.DEFAULT,
                                new NullProgressMonitor());
                System.out.println("  Built In Attribute: "
                        + attribute.getDisplayName());
                System.out.println(" Type: " + attribute.getAttributeType());
                try {
                    // wi.getAttributeValue(attribute, resolved.getItem());
                    System.out.println("  Value "
                            + resolved.getItem().getValue(attribute));

                } catch (AssertionFailedException e) {
                    System.out.println(e.toString());
                }
            }
           
        }
       
       
    }

    static void printAttributes(IWorkItem workItem,ITeamRepository repository,
            IAuditableClient auditableClient, IProjectArea projectArea,
            org.eclipse.core.runtime.IProgressMonitor monitor) {
       
        IWorkItemCommon workItemCommon = (IWorkItemCommon) repository.getClientLibrary(IWorkItemCommon.class);
       
        try {
            for (IAttribute ia : workItemCommon.findAttributes(projectArea,
                    monitor)) {

                if (workItem.hasAttribute(ia)) {
                    System.out.println("\t\t\tprocessing for variable="
                            + ia.getDisplayName() + " attrib type="
                            + ia.getAttributeType() + " kind="
                            + ia.getFullTextKind());
                    try {
                        // this will throw exception if not enumeration
                        IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>) workItemCommon
                                .resolveEnumeration(ia, monitor);
                        if (enumeration != null) {
                            String[] iaval = ia
                                    .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 name="
                                                        + ia.getIdentifier()
                                                        + ", type"
                                                        + "="
                                                        + ia.getAttributeType()
                                                        + " literal="
                                                        + literal
                                                                .getIdentifier2()
                                                                .getStringIdentifier()
                                                        + " literal name="
                                                        + literal.getName());
                                        break;
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        System.out.println("\t\t\t\tattribute name="
                                + ia.getIdentifier()
                                + ", type"
                                + "="
                                + ia.getAttributeType()
                                + " value="
                                + ia.getValue(auditableClient, workItem,
                                        monitor));
                    }
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            System.out.println("outer Exception=" + e.toString());
        }
    }

}// Main END


And this is snippet of result for custom atributtes:
WORKITEM------------------------------------------------
The attribute id: com.ibm.team.apt.attribute.planitem.priority._pm7NmRYUEd6L1tNIGdz5qQ
The attribute name: Ranking (w odniesieniu do null)
The value of the custom attribute: priority.literal.l01 O0000:
WORKITEM------------------------------------------------
The attribute id: com.ibm.team.apt.attribute.planitem.priority._pm7NmRYUEd6L1tNIGdz5qQ
The attribute name: Ranking (w odniesieniu do null)
The value of the custom attribute: priority.literal.l01 O0000;
WORKITEM------------------------------------------------
The attribute id: com.ibm.team.apt.attribute.planitem.priority._pm7NmRYUEd6L1tNIGdz5qQ
The attribute name: Ranking (w odniesieniu do null)
The value of the custom attribute: priority.literal.l01 O0000;
WORKITEM------------------------------------------------
The attribute id: com.ibm.team.apt.attribute.planitem.priority._pm7NmRYUEd6L1tNIGdz5qQ
The attribute name: Ranking (w odniesieniu do null)
The value of the custom attribute: priority.literal.l01 O0000=
WORKITEM------------------------------------------------
The attribute id: com.ibm.team.apt.attribute.planitem.priority._pm7NmRYUEd6L1tNIGdz5qQ
The attribute name: Ranking (w odniesieniu do null)
The value of the custom attribute: priority.literal.l01 O0000>
WORKITEM------------------------------------------------
The attribute id: com.ibm.team.apt.attribute.acceptance
The attribute name: Acceptance Test
The value of the custom attribute:
The attribute id: com.ibm.team.apt.attribute.complexity
The attribute name: Story Points
The value of the custom attribute: com.ibm.team.workitem.common.model.ILiteral:20
WORKITEM------------------------------------------------
The attribute id: com.ibm.team.apt.attribute.acceptance
The attribute name: Acceptance Test
The value of the custom attribute:
The attribute id: com.ibm.team.apt.attribute.complexity
The attribute name: Story Points
The value of the custom attribute: com.ibm.team.workitem.common.model.ILiteral:20

result when i run also code for builtIn attributes:

WORKITEM------------------------------------------------
The attribute id: com.ibm.team.apt.attribute.planitem.priority._pm7NmRYUEd6L1tNIGdz5qQ
The attribute name: Ranking (w odniesieniu do Priorytet)
The value of the custom attribute: priority.literal.l3 O00001
  Built In Attribute: Archived
 Type: boolean
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Filed Against
 Type: category
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Restricted Access
 Type: uuid
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Corrected Estimate
 Type: duration
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Creation Date
 Type: timestamp
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Created By
 Type: contributor
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Custom Attributes
 Type: customAttribute
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Description
 Type: html
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Due Date
 Type: timestamp
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Estimate
 Type: duration
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Found In
 Type: deliverable
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Id
 Type: integer
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Approval Descriptors
 Type: approvalDescriptors
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Approvals
 Type: approvals
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Comments
 Type: comments
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Priority
 Type: priority
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Resolution
 Type: smallString
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Sequence Value
 Type: smallString
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Severity
 Type: severity
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Status
 Type: smallString
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: State Transitions
 Type: stateTransitions
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Subscribed By
 Type: subscriptions
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Tags
 Type: tags
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Modified Date
 Type: timestamp
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Modified By
 Type: contributor
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Owned By
 Type: contributor
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Project Area
 Type: projectArea
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Resolution Date
 Type: timestamp
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Resolved By
 Type: contributor
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Start Date
 Type: timestamp
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Summary
 Type: mediumHtml
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Planned For
 Type: interval
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Time Spent
 Type: duration
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
  Built In Attribute: Type
 Type: type
org.eclipse.core.runtime.AssertionFailedException: assertion failed:


I have a problem with getting the values ​​displayed on the RTC webservice, what is wrong? or what I forget?


permanent link
Robert Siara (821014) | answered Nov 24 '12, 4:52 a.m.
this code don't resolve My problem with AssertionFailedException.

permanent link
sam detweiler (12.5k6195201) | answered Nov 23 '12, 8:12 p.m.
see my code in the third post here https://jazz.net/forum/questions/76276/how-to-get-the-value-selected-by-user-from-a-drop-down-list

I don't care if the attribute is builtin or not

Your answer


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