use of com.emc.storageos.db.client.model.uimodels.ApprovalRequest in project coprhd-controller by CoprHD.
the class ApprovalRequestTest method testPersistObject.
@Test
public void testPersistObject() throws Exception {
_logger.info("Starting persist ApprovalRequest test");
ApprovalRequest model = new ApprovalRequest();
model.setLabel("foo");
model.setApprovalStatus(ApprovalStatus.APPROVED.name());
model.setApprovedBy("billy");
Date d = new Date();
model.setDateActioned(d);
model.setMessage("my message");
URI orderId = URIUtil.createId(Order.class);
model.setOrderId(orderId);
model.setTenant(DEFAULT_TENANT);
save(model);
model = findById(model.getId());
Assert.assertNotNull(model);
Assert.assertEquals("foo", model.getLabel());
Assert.assertEquals(ApprovalStatus.APPROVED.name(), model.getApprovalStatus());
Assert.assertEquals("billy", model.getApprovedBy());
Assert.assertEquals(d, model.getDateActioned());
Assert.assertEquals("my message", model.getMessage());
Assert.assertEquals(orderId, model.getOrderId());
Assert.assertEquals(DEFAULT_TENANT, model.getTenant());
}
use of com.emc.storageos.db.client.model.uimodels.ApprovalRequest in project coprhd-controller by CoprHD.
the class ApprovalRequestTest method testMultiTenant.
@Test
public void testMultiTenant() throws Exception {
_logger.info("Starting multi tenant ApprovalRequest test");
ModelClient modelClient = getModelClient();
ApprovalRequest ar1 = create("t1", "foo1", ApprovalStatus.PENDING);
modelClient.save(ar1);
ApprovalRequest ar2 = create("t1", "bar2", ApprovalStatus.REJECTED);
modelClient.save(ar2);
ApprovalRequest ar3 = create("t2", "foo3", ApprovalStatus.REJECTED);
modelClient.save(ar3);
ApprovalRequest ar4 = create("t2", "bar4", ApprovalStatus.REJECTED);
modelClient.save(ar4);
ApprovalRequest ar5 = create("t2", "foo5", ApprovalStatus.APPROVED);
modelClient.save(ar5);
ApprovalRequest ar6 = create("t3", "bar6", ApprovalStatus.PENDING);
modelClient.save(ar6);
List<ApprovalRequest> approvalRequests = modelClient.approvalRequests().findAll("t1");
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(2, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findAll("t2");
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(3, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findAll("t3");
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(1, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByLabel("t1", "foo");
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(1, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByLabel("t1", "ba");
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(1, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByLabel("t1", "ab");
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(0, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByLabel("t2", "ba");
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(1, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByLabel("t2", "fo");
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(2, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByLabel("t3", "ba");
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(1, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByLabel("t3", "foo");
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(0, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByApprovalStatus("t1", ApprovalStatus.PENDING);
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(1, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByApprovalStatus("t1", ApprovalStatus.APPROVED);
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(0, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByApprovalStatus("t1", ApprovalStatus.REJECTED);
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(1, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByApprovalStatus("t2", ApprovalStatus.PENDING);
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(0, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByApprovalStatus("t2", ApprovalStatus.APPROVED);
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(1, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByApprovalStatus("t2", ApprovalStatus.REJECTED);
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(2, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByApprovalStatus("t3", ApprovalStatus.PENDING);
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(1, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByApprovalStatus("t3", ApprovalStatus.APPROVED);
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(0, approvalRequests.size());
approvalRequests = modelClient.approvalRequests().findByApprovalStatus("t3", ApprovalStatus.REJECTED);
Assert.assertNotNull(approvalRequests);
Assert.assertEquals(0, approvalRequests.size());
}
use of com.emc.storageos.db.client.model.uimodels.ApprovalRequest in project coprhd-controller by CoprHD.
the class ApprovalRequestTest method create.
private static ApprovalRequest create(String tenant, String label, ApprovalStatus status) {
ApprovalRequest model = new ApprovalRequest();
model.setLabel(label);
model.setApprovalStatus(status.name());
model.setApprovedBy("billy");
Date d = new Date();
model.setDateActioned(d);
model.setMessage("my message");
URI orderId = URIUtil.createId(Order.class);
model.setOrderId(orderId);
model.setTenant(tenant);
return model;
}
use of com.emc.storageos.db.client.model.uimodels.ApprovalRequest in project coprhd-controller by CoprHD.
the class ApprovalService method updateApproval.
/**
* Update approval
*
* @param param Approval update parameters
* @param id the URN the approval
* @prereq none
* @brief Update Approval
* @return No data returned in response body
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_APPROVER })
public ApprovalRestRep updateApproval(@PathParam("id") URI id, ApprovalUpdateParam param) {
ApprovalRequest approval = getApprovalById(id, true);
StorageOSUser user = getUserFromContext();
verifyAuthorizedInTenantOrg(uri(approval.getTenant()), user);
Order order = orderManager.getOrderById(approval.getOrderId());
if (order.getSubmittedByUserId().equals(user.getUserName()) && param.getApprovalStatus().equals(ApprovalStatus.APPROVED.toString())) {
throw APIException.badRequests.updateApprovalBySameUser(user.getUserName());
}
validateParam(param, approval);
updateObject(approval, param);
approvalManager.updateApproval(approval, user);
if (approval.getOrderId() != null) {
if (order != null) {
orderManager.processOrder(order);
}
}
auditOpSuccess(OperationTypeEnum.UPDATE_APPROVAL, approval.auditParameters());
approval = approvalManager.getApprovalById(approval.getId());
return map(approval);
}
use of com.emc.storageos.db.client.model.uimodels.ApprovalRequest in project coprhd-controller by CoprHD.
the class ApprovalService method getApprovalById.
private ApprovalRequest getApprovalById(URI id, boolean checkInactive) {
ApprovalRequest approval = approvalManager.getApprovalById(id);
ArgValidator.checkEntity(approval, id, isIdEmbeddedInURL(id), checkInactive);
return approval;
}
Aggregations