It's all about the answers!

Ask a question

Adding attachements/links to the work item programmatically.


Dashrath Kale (1542723) | asked Dec 20 '10, 6:22 a.m.
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?

7 answers



permanent link
Sachin Nairy (5111220) | answered Jul 17 '12, 6:26 p.m.
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>


permanent link
Megan Katysovas (7665) | answered Apr 20 '11, 4:22 p.m.
That was a great starter. Here's what ended up working for me -




try &#123;
IAttachment newAttachment = service.createAttachment&#40;projectArea, attachmentFile.getName&#40;&#41;, &quot;&quot;, &quot;text&quot;, &quot;UTF-8&quot;, fis, null&#41;;
newAttachment = &#40;IAttachment&#41; newAttachment.getWorkingCopy&#40;&#41;;
newAttachment = service.saveAttachment&#40;newAttachment, monitor&#41;;
linkAttachment&#40;newAttachment, wc.getWorkItem&#40;&#41;&#41;;


.......



private static void linkAttachment&#40;IAttachment source, IWorkItem target&#41;&#123;
try&#123;
ILinkManager linkManager= &#40;ILinkManager&#41; repo.getClientLibrary&#40;ILinkManager.class&#41;;
IItemReference sourceRef= IReferenceFactory.INSTANCE.createReferenceToItem&#40;source.getItemHandle&#40;&#41;&#41;;
IItemReference targetRef= IReferenceFactory.INSTANCE.createReferenceToItem&#40;target.getItemHandle&#40;&#41;&#41;;
ILink link= ILinkFactory.INSTANCE.createLink&#40;WorkItemLinkTypes.ATTACHMENT, sourceRef, targetRef&#41;;


linkManager.saveLink&#40;link, monitor&#41;;



permanent link
Ralph Schoon (63.1k33646) | answered Feb 04 '11, 5:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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&#40;File attachmentFile, IWorkItemReferences workItemReferences&#41;
throws TeamRepositoryException
&#123;
try &#123;

FileInputStream fis = new FileInputStream&#40;attachmentFile&#41;;
try &#123;
IAttachment newAttachment =
workItemClient&#40;&#41;.createAttachment&#40;fProjectArea,
attachmentFile.getName&#40;&#41;,
&quot;&quot;,
&quot;text&quot;,
&quot;UTF-8&quot;,
fis,
null&#41;;

newAttachment = &#40;IAttachment&#41; newAttachment.getWorkingCopy&#40;&#41;;
newAttachment = workItemClient&#40;&#41;.saveAttachment&#40;newAttachment, null&#41;;
IItemReference reference = WorkItemLinkTypes.createAttachmentReference&#40;newAttachment&#41;;
workItemReferences.add&#40;WorkItemEndPoints.ATTACHMENT, reference&#41;;
&#125;
finally &#123;
if &#40;fis != null&#41; &#123;
fis.close&#40;&#41;;
if &#40;attachmentFile != null&#41; &#123;
attachmentFile.delete&#40;&#41;;
&#125;
&#125;
&#125;
&#125;
catch &#40;Exception e&#41; &#123;
e.printStackTrace&#40;&#41;;
throw new TeamRepositoryException&#40;e&#41;;
&#125;
&#125;


Thanks,

Ralph

permanent link
Ralph Schoon (63.1k33646) | answered Feb 04 '11, 1:13 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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&amp;highlight=parent+child
http://jazz.net/forums/viewtopic.php?t=14733&amp;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?

permanent link
Susan Hanson (1.6k2201194) | answered Feb 03 '11, 3:41 p.m.
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&amp;highlight=parent+child
http://jazz.net/forums/viewtopic.php?t=14733&amp;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?

permanent link
Dashrath Kale (1542723) | answered Feb 02 '11, 2:15 a.m.
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&amp;highlight=parent+child
http://jazz.net/forums/viewtopic.php?t=14733&amp;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?

permanent link
Ralph Schoon (63.1k33646) | answered Feb 01 '11, 12:18 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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&amp;highlight=parent+child
http://jazz.net/forums/viewtopic.php?t=14733&amp;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?

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.