It's all about the answers!

Ask a question

Adding attachements/links to the work item programmatically.


Dashrath Kale (1542523) | 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
Ralph Schoon (59.7k23643) | 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&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?

permanent link
Dashrath Kale (1542523) | 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&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?

permanent link
Susan Hanson (1.6k2186193) | 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&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?

permanent link
Ralph Schoon (59.7k23643) | 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&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?

permanent link
Ralph Schoon (59.7k23643) | 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(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

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 {
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);



permanent link
Sachin Nairy (5111119) | 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>

Your answer


Register or to post your answer.