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

Adding attachements/links to the work item programmatically.

Hi


I need to add the attachment and link to the workitem using RTC Java API's in the Links section. I tried to find the API for this but have not got any thing which can help me.

Please let me know,if anyone has any idea about this?

0 votes



7 answers

Permanent link
Hi, I am

Working on that myself right now. Here is what I found searching this forum:

http://jazz.net/forums/viewtopic.php?t=2944&highlight=parent+child
http://jazz.net/forums/viewtopic.php?t=14733&highlight=parent+child
https://jazz.net/wiki/bin/view/Main/ProgrammaticLinkCreation

Sorry have not had time to code yet.

Ralph

Hi


I need to add the attachment and link to the workitem using RTC Java API's in the Links section. I tried to find the API for this but have not got any thing which can help me.

Please let me know,if anyone has any idea about this?

0 votes


Permanent link
Hi, I am

Working on that myself right now. Here is what I found searching this forum:

http://jazz.net/forums/viewtopic.php?t=2944&highlight=parent+child
http://jazz.net/forums/viewtopic.php?t=14733&highlight=parent+child
https://jazz.net/wiki/bin/view/Main/ProgrammaticLinkCreation

Sorry have not had time to code yet.

Ralph


Hi

Thanks for the response.

Actually I need to create and add the attachment to the workitem and not a work item references from parent to child or child to parent.

If you have any information on this , could you please share that.


Hi


I need to add the attachment and link to the workitem using RTC Java API's in the Links section. I tried to find the API for this but have not got any thing which can help me.

Please let me know,if anyone has any idea about this?

0 votes


Permanent link
I haven't done this specifically for an attachment, but perhaps something like:

IURIReference ref = ReferenceFactory.INSTANCE.createReferenceFromURI(file.getURI()); workingCopy.getReferences().add(WorkItemEndPoints.ATTACHMENT);

where file is the file instance?

Susan

Hi, I am

Working on that myself right now. Here is what I found searching this forum:

http://jazz.net/forums/viewtopic.php?t=2944&highlight=parent+child
http://jazz.net/forums/viewtopic.php?t=14733&highlight=parent+child
https://jazz.net/wiki/bin/view/Main/ProgrammaticLinkCreation

Sorry have not had time to code yet.

Ralph


Hi

Thanks for the response.

Actually I need to create and add the attachment to the workitem and not a work item references from parent to child or child to parent.

If you have any information on this , could you please share that.


Hi


I need to add the attachment and link to the workitem using RTC Java API's in the Links section. I tried to find the API for this but have not got any thing which can help me.

Please let me know,if anyone has any idea about this?

0 votes


Permanent link
Hi Susan,

I am still stalled on this one.

Of course it is possible to link to a URL like File://.......

But for a real attachment, I figure the file needs to be uploaded and attached to a work item. I have not found the API for uploading yet. I think that is the key.

Ralph

I haven't done this specifically for an attachment, but perhaps something like:

IURIReference ref = ReferenceFactory.INSTANCE.createReferenceFromURI(file.getURI()); workingCopy.getReferences().add(WorkItemEndPoints.ATTACHMENT);

where file is the file instance?

Susan

Hi, I am

Working on that myself right now. Here is what I found searching this forum:

http://jazz.net/forums/viewtopic.php?t=2944&highlight=parent+child
http://jazz.net/forums/viewtopic.php?t=14733&highlight=parent+child
https://jazz.net/wiki/bin/view/Main/ProgrammaticLinkCreation

Sorry have not had time to code yet.

Ralph


Hi

Thanks for the response.

Actually I need to create and add the attachment to the workitem and not a work item references from parent to child or child to parent.

If you have any information on this , could you please share that.


Hi


I need to add the attachment and link to the workitem using RTC Java API's in the Links section. I tried to find the API for this but have not got any thing which can help me.

Please let me know,if anyone has any idea about this?

0 votes


Permanent link
Hi,

I searched the SDK for WorkItemEndPoints.ATTACHMENT and was able to find the code below. I haven't tested it but it is probably a good starter anyway.



private void addJazzAttachment(File attachmentFile, IWorkItemReferences workItemReferences)
throws TeamRepositoryException
{
try {

FileInputStream fis = new FileInputStream(attachmentFile);
try {
IAttachment newAttachment =
workItemClient().createAttachment(fProjectArea,
attachmentFile.getName(),
"",
"text",
"UTF-8",
fis,
null);

newAttachment = (IAttachment) newAttachment.getWorkingCopy();
newAttachment = workItemClient().saveAttachment(newAttachment, null);
IItemReference reference = WorkItemLinkTypes.createAttachmentReference(newAttachment);
workItemReferences.add(WorkItemEndPoints.ATTACHMENT, reference);
}
finally {
if (fis != null) {
fis.close();
if (attachmentFile != null) {
attachmentFile.delete();
}
}
}
}
catch (Exception e) {
e.printStackTrace();
throw new TeamRepositoryException(e);
}
}


Thanks,

Ralph

0 votes


Permanent link
That was a great starter. Here's what ended up working for me -




try {
IAttachment newAttachment = service.createAttachment(projectArea, attachmentFile.getName(), "", "text", "UTF-8", fis, null);
newAttachment = (IAttachment) newAttachment.getWorkingCopy();
newAttachment = service.saveAttachment(newAttachment, monitor);
linkAttachment(newAttachment, wc.getWorkItem());


.......



private static void linkAttachment(IAttachment source, IWorkItem target){
try{
ILinkManager linkManager= (ILinkManager) repo.getClientLibrary(ILinkManager.class);
IItemReference sourceRef= IReferenceFactory.INSTANCE.createReferenceToItem(source.getItemHandle());
IItemReference targetRef= IReferenceFactory.INSTANCE.createReferenceToItem(target.getItemHandle());
ILink link= ILinkFactory.INSTANCE.createLink(WorkItemLinkTypes.ATTACHMENT, sourceRef, targetRef);


linkManager.saveLink(link, monitor);


0 votes


Permanent link
Dear Ralph,
i created one custom link type, i want add automatically parent & chilled relationship when custom links are added,
do you have any suggestion on this.
My link is as below:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="com.ibm.team.repository.common.linkTypes">
      <linkType
             id="com.ibm.team.workitem.linktype.ncbcr"
             constrained="false"
             internal="false">
          <target>
             <endpoint
                   displayName="Project"
                   id="project"
                   multiplicity="0..n">
                <itemReferenceType
                      itemTypeName="WorkItem"
                      packageURI="com.ibm.team.workitem"/>
             </endpoint>
          </target>
          <source>
             <endpoint
                   displayName="Change Request"
                   id="changerequest"
                   multiplicity="0..1">
                <itemReferenceType
                      itemTypeName="WorkItem"
                      packageURI="com.ibm.team.workitem"/>
             </endpoint>
          </source>
       </linkType>
   </extension>

</plugin>

0 votes

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

Question asked: Dec 20 '10, 6:22 a.m.

Question was seen: 9,883 times

Last updated: Jul 17 '12, 6:26 p.m.

Confirmation Cancel Confirm