It's all about the answers!

Ask a question

What is the replacement for IAuditableCommon.getPeer()


Kirk Woods (8158) | asked May 08 '12, 12:55 p.m.
IAuditableCommon.getPeer() is marked as deprecated. GetPeer() is used in many of the advisors in the SDK. For example from the AllChildrenClosedPrecondition code:
	private boolean isResolved(IAuditableCommon auditableCommon, IWorkItem workItem) {

if (workItem != null) {
IWorkItemCommon workItemCommon= auditableCommon.getPeer(IWorkItemCommon.class);
Identifier<IState> state= workItem.getState2();
if (state != null) {
try {
IWorkflowInfo workflowInfo= workItemCommon.findWorkflowInfo(workItem, null);
if (workflowInfo.stateGroupContains(IWorkflowInfo.CLOSED_STATES, state))
return true;
} catch (TeamRepositoryException e) {
return false;
}
}
}
return false;
}

The javadoc for getPeer() says
Deprecated. see ICommonServiceContext.getService(Class), AbstractService.getService(Class), ITeamRepository.getClientLibrary(Class)
but there are no examples on the usage to get the IWorkItemCommon object.

3 answers



permanent link
Ralph Schoon (58.7k23642) | answered May 09 '12, 3:25 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Kirk,

in an precondition or follow up action or other server extension you should extend AbstractService an you can use this.getService(Serviceclass.class) to retireve the service. Honestly i have seen and created a bunch of extensions and I never stumbled upon getPeer().

In the Plain Java Client Library you use ITeamRepository.getClientLibrary(Class) to get client libraries.

This is what the @see indicates, I think.

permanent link
Kirk Woods (8158) | answered May 09 '12, 12:44 p.m.
Thanks Ralph! As usual the documentation is typically for those who already know the information and just need a reminder. I like examples so I put together a "template" advisor that includes the retrieval of IWorkItemCommon using AbstractService. I hope others find this useful.
package advisor.example;


import org.eclipse.core.runtime.IProgressMonitor;

import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfoCollector;
import com.ibm.team.process.common.advice.runtime.IOperationAdvisor;
import com.ibm.team.repository.common.IAuditable;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.AbstractService;
import com.ibm.team.workitem.common.IAuditableCommon;
import com.ibm.team.workitem.common.ISaveParameter;
import com.ibm.team.workitem.common.IWorkItemCommon;
import com.ibm.team.workitem.common.model.IWorkItem;

public class TemplateAdvisor extends AbstractService implements IOperationAdvisor {

public static final String ID = "advisor.example.templateAdvisor";
private IWorkItemCommon workItemCommon;

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration,
IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;

IAuditable auditable = saveParameter.getNewState();
if (auditable instanceof IWorkItem) {
IAuditableCommon auditableCommon = saveParameter.getSaveOperationParameter().getAuditableCommon();
workItemCommon = this.getService(IWorkItemCommon.class);
// TODO: Implement the rest of the advisor.
}
}
}

}

permanent link
Ralph Schoon (58.7k23642) | answered May 09 '12, 1:24 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Kirk,

Right, thanks for the example.

You can do
IAudibleCommon common = (IAuditableCommon) getService(IAuditableCommon.class);


because you extend AbstreactService.


In Clinets/PlainJava you use ITeamrepository.getClientLibrary(). You can use getOrigin() form many objects to get to the ITeamrepository.

Hope that helps. It cost me weeks to find that out....

Your answer


Register or to post your answer.