How to set parent link when creating a work item java client
2 answers
Hi,
please see: https://jazz.net/forums/viewtopic.php?p=5489
There are several ways how to do it, important is the link type in WorkItemLinkTypes
The code below seems to work also.
please see: https://jazz.net/forums/viewtopic.php?p=5489
There are several ways how to do it, important is the link type in WorkItemLinkTypes
The code below seems to work also.
ILinkManager linkManager= (ILinkManager)teamRepository.getClientLibrary(ILinkManager.class);
IItemReference source=IReferenceFactory.INSTANCE.createReferenceToItem(handle);
IItemReference target=IReferenceFactory.INSTANCE.createReferenceToItem(opposite);
ILink link=ILinkFactory.INSTANCE.createLink(WorkItemLinkTypes.BLOCKS_WORK_ITEM, source, target);
linkManager.saveLink(link, monitor);
Hi,
Thanks for your response. I have found the solution.Check my code below.
public class WorkItemInitialization extends AbstractWorkItemOperation {
private String fSummary;
private ICategoryHandle fCategory;
private IAttribute iattribute;
IWorkItem iparent;
IWorkItemHandle target;
public WorkItemInitialization(String summary, ICategoryHandle category, IWorkItem parent, IWorkItemHandle parent2, IAttribute ia,IWorkItemClient workItemClient) {
super("Initializing Work Item");
fSummary = summary;
fCategory = category;
iattribute = ia;
iparent = parent;
target = parent2;
this.workItemClient = workItemClient;
}
protected void execute(WorkItemWorkingCopy workingCopy,IProgressMonitor monitor) throws TeamRepositoryException {
IWorkItem workItem = workingCopy.getWorkItem();
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary));
java.util.Date date= new java.util.Date();
String str_date="08-05-2012";
DateFormat formatter ;
Date date1 = null ;
formatter = new SimpleDateFormat("dd-M-yy");
try {
date1 = (Date)formatter.parse(str_date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java.sql.Timestamp timeStampDate = new Timestamp(date1.getTime());
System.out.println("Today is " +timeStampDate);
workItem.setCategory(fCategory);
workItem.setDueDate(timeStampDate);
IAttribute attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.Planned_Start_Date", monitor);
if (attr != null) {
workItem.setValue(attr,timeStampDate);
}
attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.Planned_Target_Date", monitor);
if (attr != null) {
workItem.setValue(attr,timeStampDate);
}
attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.parent_dev", monitor);
System.out.println("------------------------------");
System.out.println(attr);
System.out.println("------------------------------");
if (attr != null) {
workItem.setValue(attr,iparent );
}
setParent(workingCopy,iparent);
}
private void setParent(WorkItemWorkingCopy wc, IWorkItem parent) {
IEndPointDescriptor referenceType= WorkItemEndPoints.PARENT_WORK_ITEM;
IReference reference= WorkItemLinkTypes.createWorkItemReference(parent);
wc.getReferences().add(referenceType, reference);
}
}
Thanks
Glory
Thanks for your response. I have found the solution.Check my code below.
public class WorkItemInitialization extends AbstractWorkItemOperation {
private String fSummary;
private ICategoryHandle fCategory;
private IAttribute iattribute;
IWorkItem iparent;
IWorkItemHandle target;
public WorkItemInitialization(String summary, ICategoryHandle category, IWorkItem parent, IWorkItemHandle parent2, IAttribute ia,IWorkItemClient workItemClient) {
super("Initializing Work Item");
fSummary = summary;
fCategory = category;
iattribute = ia;
iparent = parent;
target = parent2;
this.workItemClient = workItemClient;
}
protected void execute(WorkItemWorkingCopy workingCopy,IProgressMonitor monitor) throws TeamRepositoryException {
IWorkItem workItem = workingCopy.getWorkItem();
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary));
java.util.Date date= new java.util.Date();
String str_date="08-05-2012";
DateFormat formatter ;
Date date1 = null ;
formatter = new SimpleDateFormat("dd-M-yy");
try {
date1 = (Date)formatter.parse(str_date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java.sql.Timestamp timeStampDate = new Timestamp(date1.getTime());
System.out.println("Today is " +timeStampDate);
workItem.setCategory(fCategory);
workItem.setDueDate(timeStampDate);
IAttribute attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.Planned_Start_Date", monitor);
if (attr != null) {
workItem.setValue(attr,timeStampDate);
}
attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.Planned_Target_Date", monitor);
if (attr != null) {
workItem.setValue(attr,timeStampDate);
}
attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.parent_dev", monitor);
System.out.println("------------------------------");
System.out.println(attr);
System.out.println("------------------------------");
if (attr != null) {
workItem.setValue(attr,iparent );
}
setParent(workingCopy,iparent);
}
private void setParent(WorkItemWorkingCopy wc, IWorkItem parent) {
IEndPointDescriptor referenceType= WorkItemEndPoints.PARENT_WORK_ITEM;
IReference reference= WorkItemLinkTypes.createWorkItemReference(parent);
wc.getReferences().add(referenceType, reference);
}
}
Thanks
Glory