use of org.finra.gatekeeper.controllers.wrappers.CompletedAccessRequestWrapper in project Gatekeeper by FINRAOS.
the class AccessRequestService method getCompletedRequests.
public List<CompletedAccessRequestWrapper> getCompletedRequests() {
// We can use the variables stored on the activiti requests to build out our request history.
List<HistoricVariableInstance> taskVars = historyService.createHistoricVariableInstanceQuery().list();
Map<String, Map<String, Object>> historicData = new HashMap<>();
List<CompletedAccessRequestWrapper> results = new ArrayList<>();
taskVars.forEach(taskVar -> {
String key = taskVar.getVariableName();
Object value = taskVar.getValue();
if (historicData.containsKey(taskVar.getProcessInstanceId())) {
historicData.get(taskVar.getProcessInstanceId()).put(taskVar.getVariableName(), taskVar.getValue());
} else {
Map<String, Object> data = new HashMap<>();
data.put("created", taskVar.getCreateTime());
data.put(taskVar.getVariableName(), taskVar.getValue());
historicData.put(taskVar.getProcessInstanceId(), data);
}
if (key.equals("requestStatus")) {
historicData.get(taskVar.getProcessInstanceId()).put("updated", taskVar.getLastUpdatedTime());
}
});
for (String k : historicData.keySet()) {
Map<String, Object> varMap = historicData.get(k);
RequestStatus status = (RequestStatus) varMap.get("requestStatus") != null ? (RequestStatus) varMap.get("requestStatus") : RequestStatus.APPROVAL_PENDING;
AccessRequest request = (AccessRequest) varMap.get("accessRequest");
Date created = (Date) varMap.get("created");
Date updated = (Date) varMap.get("updated");
CompletedAccessRequestWrapper wrapper = new CompletedAccessRequestWrapper(request).setUpdated(updated).setAttempts((Integer) varMap.get("attempts")).setStatus(status);
wrapper.setCreated(created);
results.add(wrapper);
}
return (List<CompletedAccessRequestWrapper>) filterResults(results);
}
use of org.finra.gatekeeper.controllers.wrappers.CompletedAccessRequestWrapper in project Gatekeeper by FINRAOS.
the class AccessRequestServiceTest method testGetCompletedRequestsAdmin.
/**
* Test for checking that, when the user is APPROVER, they should be able to see
* any completed request. Even ones that they do not own.
*/
@Test
public void testGetCompletedRequestsAdmin() {
when(gatekeeperRoleService.getRole()).thenReturn(GatekeeperRdsRole.APPROVER);
List<CompletedAccessRequestWrapper> completedRequests = accessRequestService.getCompletedRequests();
Assert.assertTrue(completedRequests.size() == 2);
CompletedAccessRequestWrapper nonOwnerRequest = completedRequests.get(0);
Assert.assertEquals(nonOwnerRequest.getUserCount(), new Integer(0));
Assert.assertEquals(nonOwnerRequest.getInstanceCount(), new Integer(1));
Assert.assertEquals(nonOwnerRequest.getCreated().toString(), new Date(45002).toString());
Assert.assertEquals(nonOwnerRequest.getUpdated().toString(), new Date(45003).toString());
CompletedAccessRequestWrapper ownerRequest = completedRequests.get(1);
Assert.assertEquals(ownerRequest.getUserCount(), new Integer(1));
Assert.assertEquals(ownerRequest.getInstanceCount(), new Integer(1));
Assert.assertEquals(ownerRequest.getCreated().toString(), new Date(45000).toString());
Assert.assertEquals(ownerRequest.getUpdated().toString(), new Date(45002).toString());
}
use of org.finra.gatekeeper.controllers.wrappers.CompletedAccessRequestWrapper in project Gatekeeper by FINRAOS.
the class AccessRequestServiceTest method testGetCompletedRequests.
/**
* Test for checking that, when the user is DEV, they should be able to see
* only the requests that are active and were requested by themselves
*/
@Test
public void testGetCompletedRequests() {
when(gatekeeperRoleService.getUserProfile().getName()).thenReturn("owner");
when(gatekeeperRoleService.getRole()).thenReturn(GatekeeperRdsRole.DEV);
List<CompletedAccessRequestWrapper> completedRequests = accessRequestService.getCompletedRequests();
Assert.assertTrue(completedRequests.size() == 1);
CompletedAccessRequestWrapper ownerRequest = completedRequests.get(0);
Assert.assertEquals(ownerRequest.getUserCount(), new Integer(1));
Assert.assertEquals(ownerRequest.getInstanceCount(), new Integer(1));
Assert.assertEquals(ownerRequest.getAttempts(), new Integer(1));
Assert.assertEquals(ownerRequest.getCreated().toString(), new Date(45000).toString());
Assert.assertEquals(ownerRequest.getUpdated().toString(), new Date(45002).toString());
when(gatekeeperRoleService.getUserProfile().getName()).thenReturn("non-owner");
when(gatekeeperRoleService.getRole()).thenReturn(GatekeeperRdsRole.DEV);
completedRequests = accessRequestService.getCompletedRequests();
Assert.assertEquals(completedRequests.size(), 1);
CompletedAccessRequestWrapper nonOwnerRequest = completedRequests.get(0);
Assert.assertEquals(nonOwnerRequest.getUserCount(), new Integer(0));
Assert.assertEquals(nonOwnerRequest.getInstanceCount(), new Integer(1));
Assert.assertEquals(nonOwnerRequest.getAttempts(), new Integer(2));
Assert.assertEquals(nonOwnerRequest.getCreated().toString(), new Date(45002).toString());
Assert.assertEquals(nonOwnerRequest.getUpdated().toString(), new Date(45003).toString());
}
use of org.finra.gatekeeper.controllers.wrappers.CompletedAccessRequestWrapper in project Gatekeeper by FINRAOS.
the class AccessRequestServiceTests method testGetCompletedRequestsAdmin.
/**
* Test for checking that, when the user is APPROVER, they should be able to see
* any completed request. Even ones that they do not own.
*/
@Test
public void testGetCompletedRequestsAdmin() {
when(gatekeeperLdapService.getRole()).thenReturn(GatekeeperRole.APPROVER);
List<CompletedAccessRequestWrapper> completedRequests = accessRequestService.getCompletedRequests();
Assert.assertTrue(completedRequests.size() == 2);
CompletedAccessRequestWrapper nonOwnerRequest = completedRequests.get(0);
Assert.assertEquals(nonOwnerRequest.getUserCount(), new Integer(0));
Assert.assertEquals(nonOwnerRequest.getInstanceCount(), new Integer(1));
Assert.assertEquals(nonOwnerRequest.getCreated().toString(), new Date(45002).toString());
Assert.assertEquals(nonOwnerRequest.getUpdated().toString(), new Date(45003).toString());
CompletedAccessRequestWrapper ownerRequest = completedRequests.get(1);
Assert.assertEquals(ownerRequest.getUserCount(), new Integer(1));
Assert.assertEquals(ownerRequest.getInstanceCount(), new Integer(1));
Assert.assertEquals(ownerRequest.getCreated().toString(), new Date(45000).toString());
Assert.assertEquals(ownerRequest.getUpdated().toString(), new Date(45002).toString());
}
use of org.finra.gatekeeper.controllers.wrappers.CompletedAccessRequestWrapper in project Gatekeeper by FINRAOS.
the class AccessRequestServiceTests method testGetCompletedRequests.
/**
* Test for checking that, when the user is DEV, they should be able to see
* only the requests that are active and were requested by themselves
*/
@Test
public void testGetCompletedRequests() {
when(gatekeeperLdapService.getUserProfile().getName()).thenReturn("owner");
when(gatekeeperLdapService.getRole()).thenReturn(GatekeeperRole.DEV);
List<CompletedAccessRequestWrapper> completedRequests = accessRequestService.getCompletedRequests();
Assert.assertTrue(completedRequests.size() == 1);
CompletedAccessRequestWrapper ownerRequest = completedRequests.get(0);
Assert.assertEquals(ownerRequest.getUserCount(), new Integer(1));
Assert.assertEquals(ownerRequest.getInstanceCount(), new Integer(1));
Assert.assertEquals(ownerRequest.getAttempts(), new Integer(1));
Assert.assertEquals(ownerRequest.getCreated().toString(), new Date(45000).toString());
Assert.assertEquals(ownerRequest.getUpdated().toString(), new Date(45002).toString());
when(gatekeeperLdapService.getUserProfile().getName()).thenReturn("non-owner");
completedRequests = accessRequestService.getCompletedRequests();
Assert.assertEquals(completedRequests.size(), 1);
CompletedAccessRequestWrapper nonOwnerRequest = completedRequests.get(0);
Assert.assertEquals(nonOwnerRequest.getUserCount(), new Integer(0));
Assert.assertEquals(nonOwnerRequest.getInstanceCount(), new Integer(1));
Assert.assertEquals(nonOwnerRequest.getAttempts(), new Integer(2));
Assert.assertEquals(nonOwnerRequest.getCreated().toString(), new Date(45002).toString());
Assert.assertEquals(nonOwnerRequest.getUpdated().toString(), new Date(45003).toString());
}
Aggregations