It's all about the answers!

Ask a question

How to prevent the users to add invalid approvers?


Joseph Simon Arokiaraj (21414845) | asked Dec 14 '11, 10:52 a.m.
Hi All,

In our project we have many roles like (Analyst, SC manager, Project manager, Developers, etc ..)

Lets take a workitem "Task" and I need to permit the endusers to add only the members of Project Managers as approvers in the approval tab.

I can enforce the pre condition to permit approvals only Project Mangers, but how to prevent the enduser to add a incorrect approver?

Is that possible?

Cheers,
Jose

8 answers



permanent link
Eduardo Bello (4401922) | answered Dec 20 '11, 1:57 p.m.
I never tried to change any dialog. I think attribute Validators or Providers may be easier to implement, but I also never tried it.

You can easily make an IOperationAdvisor like this:



public class CheckApproverAdvisor extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
IApprovals approvals = workItem.getApprovals();
if (approvals!=null) {
IProcessServerService processServerService = getService(IProcessServerService.class);
List<IApproval> apprList = approvals.getContents();
for (IApproval appr : apprList) {
if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {
IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");
collector.addInfo(info);
break;
}
}
}
}
}
}

private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {
try {
IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);
for (IRole role : contributorRoles) {
if (role.getId().equals("project_manager")) {
return true;
}
}
return false;
} catch (TeamRepositoryException e) {
return false;
}
}
}



I didn't test it, but I think it would be something like that.

permanent link
Parker Dunton (4064) | answered Dec 14 '11, 1:11 p.m.
JAZZ DEVELOPER
Hi Jose,

I don't believe you can prevent users from adding an incorrect approver in the first place, the dialog will let you choose from any users in the repository. But as you said, this is something you can do with a precondition.

Parker
Jazz Foundation | Process team

permanent link
Joseph Simon Arokiaraj (21414845) | answered Dec 15 '11, 12:42 p.m.
Hi Parker,

Thanks for your reply.

Could you please update me if you find any sample customized precondition examples?

Cheers,
Jose

Hi Jose,

I don't believe you can prevent users from adding an incorrect approver in the first place, the dialog will let you choose from any users in the repository. But as you said, this is something you can do with a precondition.

Parker
Jazz Foundation | Process team

permanent link
Parker Dunton (4064) | answered Dec 15 '11, 6:49 p.m.
JAZZ DEVELOPER
Hi Jose,

Depending on how you want things to work, this is something you could do with the pre-canned preconditions that come with RTC. Depending on what version of RTC you are using (I'm looking at 3.0.1 as I type this) you can put a precondition on Team Configuration > Operation Behavior > Source Control > Deliver (server) called Require Work Item Approval. This will prevent deliveries, but will not prevent the work item from being saved.

Parker
Jazz Foundation | Process team

permanent link
Joseph Simon Arokiaraj (21414845) | answered Dec 20 '11, 11:56 a.m.
Hi Parker,

Thanks a lot.

Is there is any way to customize the dialog, so that the users can select the members only from "Project Manager" role?

Cheers,
Simon

Hi Jose,

Depending on how you want things to work, this is something you could do with the pre-canned preconditions that come with RTC. Depending on what version of RTC you are using (I'm looking at 3.0.1 as I type this) you can put a precondition on Team Configuration > Operation Behavior > Source Control > Deliver (server) called Require Work Item Approval. This will prevent deliveries, but will not prevent the work item from being saved.

Parker
Jazz Foundation | Process team

permanent link
Joseph Simon Arokiaraj (21414845) | answered Dec 21 '11, 6:10 a.m.
Hi Edwardo,

Good Morning.

I have created a plugin project and tried to use your code.It has unresolved methods.

Source code:
CheckApprovers.java

package checkapprovers;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.apt.api.common.process.IProcessArea;
import com.ibm.team.apt.api.common.workitem.IWorkItem;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.IRole;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfo;

importcom.ibm.team.process.common.advice.IAdvisorInfoCollector;

import com.ibm.team.process.common.advice.runtime.IOperationAdvisor;

import com.ibm.team.process.service.IProcessServerService;

import com.ibm.team.repository.common.IAuditable;

import com.ibm.team.repository.common.IContributorHandle;

import com.ibm.team.repository.common.TeamRepositoryException;

import com.ibm.team.repository.service.AbstractService;

import com.ibm.team.workitem.common.ISaveParameter;

import com.ibm.team.workitem.common.model.IApproval;

import com.ibm.team.workitem.common.model.IApprovals;


public class CheckApprovers extends AbstractService implements IOperationAdvisor {


public void run(AdvisableOperation operation,

IProcessConfigurationElement advisorConfiguration,

IAdvisorInfoCollector collector, IProgressMonitor monitor)

throws TeamRepositoryException {

Object data = operation.getOperationData();

// The action is save

if (data instanceof ISaveParameter) {

ISaveParameter saveParameter = (ISaveParameter) data;

IAuditable auditable = saveParameter.getNewState();

// WorkItem Object

if (auditable instanceof IWorkItem) {

IWorkItem workItem = (IWorkItem) auditable;

IApprovals approvals = workItem.getApprovals();

if (approvals!=null) {

IProcessServerService processServerService = getService(IProcessServerService.class);

List<IApproval> apprList = approvals.getContents();

for (IApproval appr : apprList) {

if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {

IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");

collector.addInfo(info);

break;

}

}

}

}


}

}



private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {

try {

IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);

for (IRole role : contributorRoles) {

if (role.getId().equals("project_manager")) {

return true;

}

}

return false;

} catch (TeamRepositoryException e) {

return false;

}

}

}

##############################################################

Unresolved Methods:

IApprovals approvals = workItem.getApprovals();

Any idea on this? Do I need to include any more libraries?

Waiting for your reply.

Cheers,

jose





I never tried to change any dialog. I think attribute Validators or Providers may be easier to implement, but I also never tried it.

You can easily make an IOperationAdvisor like this:



public class CheckApproverAdvisor extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
IApprovals approvals = workItem.getApprovals();
if (approvals!=null) {
IProcessServerService processServerService = getService(IProcessServerService.class);
List<IApproval> apprList = approvals.getContents();
for (IApproval appr : apprList) {
if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {
IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");
collector.addInfo(info);
break;
}
}
}
}
}
}

private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {
try {
IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);
for (IRole role : contributorRoles) {
if (role.getId().equals("project_manager")) {
return true;
}
}
return false;
} catch (TeamRepositoryException e) {
return false;
}
}
}



I didn't test it, but I think it would be something like that.

permanent link
Joseph Simon Arokiaraj (21414845) | answered Dec 21 '11, 7:16 a.m.
Hi Edwardo,

I changed "com.ibm.team.apt.api.common.workitem.IWorkItem;" to "com.ibm.team.workitem.common.model.IWorkItem;" and workItem.getApprovals(); method get resolved.

Now only one method is not resolving.

IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);

Source code:
CheckApprovers.java

package checkapprovers;

import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;

import com.ibm.team.apt.api.common.process.IProcessArea;
//import com.ibm.team.apt.api.common.workitem.IWorkItem;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.IRole;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfo;
import com.ibm.team.process.common.advice.IAdvisorInfoCollector;
import com.ibm.team.process.common.advice.runtime.IOperationAdvisor;
import com.ibm.team.process.service.IProcessServerService;
import com.ibm.team.repository.common.IAuditable;
import com.ibm.team.repository.common.IContributorHandle;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.AbstractService;
import com.ibm.team.workitem.common.ISaveParameter;
import com.ibm.team.workitem.common.model.IApproval;
import com.ibm.team.workitem.common.model.IApprovals;

public class CheckApprovers extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
IApprovals approvals = workItem.getApprovals();
if (approvals!=null) {
IProcessServerService processServerService = getService(IProcessServerService.class);
List<IApproval> apprList = approvals.getContents();
for (IApproval appr : apprList) {
if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {
IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");
collector.addInfo(info);
break;
}
}
}
}
}
}

private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {
try {
IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);
for (IRole role : contributorRoles) {
if (role.getId().equals("project_manager")) {
return true;
}
}
return false;
} catch (TeamRepositoryException e) {
return false;
}
}
}



Cheers,
Jose





Hi Edwardo,

Good Morning.

I have created a plugin project and tried to use your code.It has unresolved methods.

Source code:
CheckApprovers.java

package checkapprovers;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.apt.api.common.process.IProcessArea;
import com.ibm.team.apt.api.common.workitem.IWorkItem;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.IRole;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfo;

importcom.ibm.team.process.common.advice.IAdvisorInfoCollector;

import com.ibm.team.process.common.advice.runtime.IOperationAdvisor;

import com.ibm.team.process.service.IProcessServerService;

import com.ibm.team.repository.common.IAuditable;

import com.ibm.team.repository.common.IContributorHandle;

import com.ibm.team.repository.common.TeamRepositoryException;

import com.ibm.team.repository.service.AbstractService;

import com.ibm.team.workitem.common.ISaveParameter;

import com.ibm.team.workitem.common.model.IApproval;

import com.ibm.team.workitem.common.model.IApprovals;


public class CheckApprovers extends AbstractService implements IOperationAdvisor {


public void run(AdvisableOperation operation,

IProcessConfigurationElement advisorConfiguration,

IAdvisorInfoCollector collector, IProgressMonitor monitor)

throws TeamRepositoryException {

Object data = operation.getOperationData();

// The action is save

if (data instanceof ISaveParameter) {

ISaveParameter saveParameter = (ISaveParameter) data;

IAuditable auditable = saveParameter.getNewState();

// WorkItem Object

if (auditable instanceof IWorkItem) {

IWorkItem workItem = (IWorkItem) auditable;

IApprovals approvals = workItem.getApprovals();

if (approvals!=null) {

IProcessServerService processServerService = getService(IProcessServerService.class);

List<IApproval> apprList = approvals.getContents();

for (IApproval appr : apprList) {

if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {

IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");

collector.addInfo(info);

break;

}

}

}

}


}

}



private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {

try {

IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);

for (IRole role : contributorRoles) {

if (role.getId().equals("project_manager")) {

return true;

}

}

return false;

} catch (TeamRepositoryException e) {

return false;

}

}

}

##############################################################

Unresolved Methods:

IApprovals approvals = workItem.getApprovals();

Any idea on this? Do I need to include any more libraries?

Waiting for your reply.

Cheers,

jose





I never tried to change any dialog. I think attribute Validators or Providers may be easier to implement, but I also never tried it.

You can easily make an IOperationAdvisor like this:



public class CheckApproverAdvisor extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
IApprovals approvals = workItem.getApprovals();
if (approvals!=null) {
IProcessServerService processServerService = getService(IProcessServerService.class);
List<IApproval> apprList = approvals.getContents();
for (IApproval appr : apprList) {
if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {
IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");
collector.addInfo(info);
break;
}
}
}
}
}
}

private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {
try {
IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);
for (IRole role : contributorRoles) {
if (role.getId().equals("project_manager")) {
return true;
}
}
return false;
} catch (TeamRepositoryException e) {
return false;
}
}
}



I didn't test it, but I think it would be something like that.

permanent link
Jia Jia Li (8058157192) | answered Apr 24 '12, 9:37 a.m.
Hi, for the following demo code, which operation should I extend?
Save Work Item? or others?
Thanks!
I never tried to change any dialog. I think attribute Validators or Providers may be easier to implement, but I also never tried it.

You can easily make an IOperationAdvisor like this:



public class CheckApproverAdvisor extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
IApprovals approvals = workItem.getApprovals();
if (approvals!=null) {
IProcessServerService processServerService = getService(IProcessServerService.class);
List<IApproval> apprList = approvals.getContents();
for (IApproval appr : apprList) {
if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {
IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");
collector.addInfo(info);
break;
}
}
}
}
}
}

private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {
try {
IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);
for (IRole role : contributorRoles) {
if (role.getId().equals("project_manager")) {
return true;
}
}
return false;
} catch (TeamRepositoryException e) {
return false;
}
}
}



I didn't test it, but I think it would be something like that.

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.