It's all about the answers!

Ask a question

How to save attachments of workitem to disk


Marcel Porz (632) | asked Jun 03 '09, 5:03 a.m.
Hi!

I have the following code:


// Query the Jazz repository for list of workitems
auditableClient = (IAuditableClient) teamRepository
.getClientLibrary(IAuditableClient.class);
IQueryClient queryClient = (IQueryClient) teamRepository
.getClientLibrary(IQueryClient.class);

IQueryableAttribute attribute = QueryableAttributes.getFactory(
IWorkItem.ITEM_TYPE).findAttribute(projectArea,
IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, null);
Expression expression = new AttributeExpression(attribute,
AttributeOperation.EQUALS, projectArea);
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient
.getResolvedExpressionResults(projectArea, expression,
IWorkItem.FULL_PROFILE);

while (results.hasNext(null)) {

IResolvedResult<IWorkItem> resolved = results.next(null);

...

// Getting existing attachments...

IWorkItemWorkingCopyManager workingCopyManager = workItemClient.getWorkItemWorkingCopyManager();
IWorkItemHandle foundWorkItem = workItemClient.findWorkItemById(resolved.getItem().getId(), IWorkItem.FULL_PROFILE, null);
workingCopyManager.connect(foundWorkItem, IWorkItem.FULL_PROFILE, null);
WorkItemWorkingCopy workingCopy = workingCopyManager.getWorkingCopy(foundWorkItem);

IWorkItemReferences references = workingCopy.getReferences();
List<IReference> attachments = references
.getReferences(WorkItemEndPoints.ATTACHMENT);


for (IReference reference : attachments) {

IItemReference attachmentReference = (IItemReference) reference;
IAttachmentHandle attachmentHandle = (IAttachmentHandle) attachmentReference
.resolve();

}
}


...and 2 questions:

1. Why do I have to use a working copy of the workitem although I already have a reference to the workitem in my iteration?
2. How can I save the attachments to disk?

Thanks in advance!
Marcel.

One answer



permanent link
Patrick Streule (4.9k21) | answered Jun 03 '09, 5:55 a.m.
JAZZ DEVELOPER
1. Why do I have to use a working copy of the workitem although I
already have a reference to the workitem in my iteration?

You don't necessarily have to use a working copy, you could also use

IWorkItemReferences resolveWorkItemReferences(IWorkItemHandle workItem,
IProgressMonitor monitor)

To get the work item references.


2. How can I save the attachments to disk?

IAttachment attachment=...;
IContentManager cm= repository.contentManager();
cm.retrieveContent(attachment.getContent(), outputStream);

--
Regards,
Patrick
Jazz Work Item Team

Your answer


Register or to post your answer.