Adding attachements/links to the work item programmatically.
7 answers
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
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?
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?
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
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?
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 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?
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.
Thanks,
Ralph
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
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);
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>
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>