Search in sources :

Example 6 with ApprovalRequest

use of com.emc.storageos.db.client.model.uimodels.ApprovalRequest in project coprhd-controller by CoprHD.

the class ApprovalService method getOtherSearchResults.

/**
 * parameter: 'orderId' The id of the order to search for approvals
 * parameter: 'approvalStatus' The status for the approval.
 * parameter: 'tenantId' The id of the tenant (if not the current tenant)
 *
 * @return Return a list of matching approvals or an empty list if no match was found.
 */
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    StorageOSUser user = getUserFromContext();
    String tenantId = user.getTenantId();
    if (parameters.containsKey(SearchConstants.TENANT_ID_PARAM)) {
        tenantId = parameters.get(SearchConstants.TENANT_ID_PARAM).get(0);
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), user);
    if (!parameters.containsKey(SearchConstants.ORDER_ID_PARAM) && !parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
        throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), SearchConstants.ORDER_ID_PARAM + " or " + SearchConstants.APPROVAL_STATUS_PARAM);
    }
    if (parameters.containsKey(SearchConstants.ORDER_ID_PARAM) && parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
        throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), SearchConstants.ORDER_ID_PARAM, SearchConstants.APPROVAL_STATUS_PARAM);
    }
    List<ApprovalRequest> approvals = Lists.newArrayList();
    if (parameters.containsKey(SearchConstants.ORDER_ID_PARAM)) {
        String orderId = parameters.get(SearchConstants.ORDER_ID_PARAM).get(0);
        ArgValidator.checkFieldNotEmpty(orderId, SearchConstants.ORDER_ID_PARAM);
        approvals = approvalManager.findApprovalsByOrderId(uri(orderId));
    } else if (parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
        String approvalStatus = parameters.get(SearchConstants.APPROVAL_STATUS_PARAM).get(0);
        ArgValidator.checkFieldNotEmpty(approvalStatus, SearchConstants.APPROVAL_STATUS_PARAM);
        approvals = approvalManager.findApprovalsByStatus(uri(tenantId), ApprovalStatus.valueOf(approvalStatus));
    }
    ResRepFilter<SearchResultResourceRep> resRepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
    List<SearchResultResourceRep> searchResultResourceReps = Lists.newArrayList();
    for (ApprovalRequest approval : approvals) {
        RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), approval.getId()));
        SearchResultResourceRep searchResultResourceRep = new SearchResultResourceRep();
        searchResultResourceRep.setId(approval.getId());
        searchResultResourceRep.setLink(selfLink);
        if (authorized || resRepFilter.isAccessible(searchResultResourceRep)) {
            searchResultResourceReps.add(searchResultResourceRep);
        }
    }
    SearchResults result = new SearchResults();
    result.setResource(searchResultResourceReps);
    return result;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ApprovalRequest(com.emc.storageos.db.client.model.uimodels.ApprovalRequest) RestLinkRep(com.emc.storageos.model.RestLinkRep) ResRepFilter(com.emc.storageos.api.service.impl.response.ResRepFilter) SearchResults(com.emc.storageos.model.search.SearchResults)

Example 7 with ApprovalRequest

use of com.emc.storageos.db.client.model.uimodels.ApprovalRequest in project coprhd-controller by CoprHD.

the class ApprovalService method getApprovals.

/**
 * Gets the list of approvals
 *
 * @param tenantId the URN of a tenant
 * @brief List Approvals
 * @return a list of approvals
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ApprovalList getApprovals(@DefaultValue("") @QueryParam(SearchConstants.TENANT_ID_PARAM) String tenantId) throws DatabaseException {
    StorageOSUser user = getUserFromContext();
    if (StringUtils.isBlank(tenantId)) {
        tenantId = user.getTenantId();
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), getUserFromContext());
    List<ApprovalRequest> approvals = approvalManager.getApprovals(uri(tenantId));
    ApprovalList approvalList = new ApprovalList();
    for (ApprovalRequest approval : approvals) {
        NamedRelatedResourceRep approvalRestRep = toNamedRelatedResource(ResourceTypeEnum.APPROVAL, approval.getId(), approval.getLabel());
        approvalList.getApprovals().add(approvalRestRep);
    }
    return approvalList;
}
Also used : ApprovalList(com.emc.vipr.model.catalog.ApprovalList) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ApprovalRequest(com.emc.storageos.db.client.model.uimodels.ApprovalRequest) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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