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

How to use createAttachment to upload attachments on server using RTC Java API

 Hi,

I was trying to upload attachments on RTC server using Java API (SDK).The following is the code I am using. After I executed it, I didn't get the result I wanted. Is there any problem with my code or is there any other way to implement it?
Thanks for the help.


public class GenerateReportAdvistor extends AbstractService implements
IOperationAdvisor {

public void run(AdvisableOperation operation,
IProcessConfigurationElement advisorConfiguration,
IAdvisorInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {

Object data = operation.getOperationData();
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = ((ISaveParameter) data).getNewState();
if (auditable instanceof IWorkItem) {
IWorkItem oldWorkItem = (IWorkItem) saveParameter.getOldState();
IWorkItem newWorkItem = (IWorkItem) auditable;
Identifier<IState> newState = newWorkItem.getState2();
IWorkItemServer service = getService(IWorkItemServer.class);
IRepositoryItemService repositoryItemService=getService(IRepositoryItemService.class);
ICombinedWorkflowInfos combinedWorkflowinfos = service.findCombinedWorkflowInfos(newWorkItem.getProjectArea(), monitor);
if(oldWorkItem!=null){
 try {
File attachmentFile = new File("C:\temp\test.doc");
FileInputStream fis = new FileInputStream(attachmentFile);
IAttachment newAttachment =service.createAttachment(projectArea, monitor);
newAttachment.setName("TestName");
IContent content= service.getAuditableCommon().storeContent(IContent.CONTENT_TYPE_UNKNOWN, IContent.ENCODING_UTF_8, fis, attachmentFile.length(), monitor);
newAttachment.setContent(content);
newAttachment=service.saveAttachment(newAttachment, monitor);
IItemReference reference = WorkItemLinkTypes.createAttachmentReference(newAttachment);
IWorkItemReferences sourceReferences= service.resolveWorkItemReferences(newWorkItem, monitor);
sourceReferences.add(WorkItemEndPoints.ATTACHMENT, reference);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}
}

0 votes


Be the first one to answer this question!

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
× 10,938

Question asked: Oct 10 '19, 6:49 a.m.

Question was seen: 743 times

Last updated: Oct 10 '19, 6:49 a.m.

Confirmation Cancel Confirm