Search in sources :

Example 1 with ApprovalRequest

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());
}
Also used : ApprovalRequest(com.emc.storageos.db.client.model.uimodels.ApprovalRequest) URI(java.net.URI) Date(java.util.Date) BaseModelTest(com.emc.sa.model.BaseModelTest) Test(org.junit.Test)

Example 2 with ApprovalRequest

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());
}
Also used : ModelClient(com.emc.sa.model.dao.ModelClient) ApprovalRequest(com.emc.storageos.db.client.model.uimodels.ApprovalRequest) BaseModelTest(com.emc.sa.model.BaseModelTest) Test(org.junit.Test)

Example 3 with ApprovalRequest

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;
}
Also used : ApprovalRequest(com.emc.storageos.db.client.model.uimodels.ApprovalRequest) URI(java.net.URI) Date(java.util.Date)

Example 4 with ApprovalRequest

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);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ApprovalRequest(com.emc.storageos.db.client.model.uimodels.ApprovalRequest) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with ApprovalRequest

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;
}
Also used : ApprovalRequest(com.emc.storageos.db.client.model.uimodels.ApprovalRequest)

Aggregations

ApprovalRequest (com.emc.storageos.db.client.model.uimodels.ApprovalRequest)7 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)3 BaseModelTest (com.emc.sa.model.BaseModelTest)2 URI (java.net.URI)2 Date (java.util.Date)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Test (org.junit.Test)2 ModelClient (com.emc.sa.model.dao.ModelClient)1 ResRepFilter (com.emc.storageos.api.service.impl.response.ResRepFilter)1 Order (com.emc.storageos.db.client.model.uimodels.Order)1 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)1 RestLinkRep (com.emc.storageos.model.RestLinkRep)1 SearchResultResourceRep (com.emc.storageos.model.search.SearchResultResourceRep)1 SearchResults (com.emc.storageos.model.search.SearchResults)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 ApprovalList (com.emc.vipr.model.catalog.ApprovalList)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1