Search in sources :

Example 1 with OrderCount

use of com.emc.vipr.model.catalog.OrderCount in project coprhd-controller by CoprHD.

the class OrderService method getOrderCount.

/**
 * @brief Get number of orders under given tenants within a time range
 * @param startTimeStr start time
 * @param endTimeStr   end time
 * @return  number of orders within the time range of each tenant
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("/count")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public OrderCount getOrderCount(@DefaultValue("") @QueryParam(SearchConstants.START_TIME_PARAM) String startTimeStr, @DefaultValue("") @QueryParam(SearchConstants.END_TIME_PARAM) String endTimeStr, @DefaultValue("") @QueryParam(SearchConstants.TENANT_IDS_PARAM) String tenantIDs) throws DatabaseException {
    StorageOSUser user = getUserFromContext();
    log.info("user={}", user.getName());
    long startTimeInMS = getTime(startTimeStr, 0);
    long endTimeInMS = getTime(endTimeStr, System.currentTimeMillis());
    if (startTimeInMS > endTimeInMS) {
        throw APIException.badRequests.endTimeBeforeStartTime(startTimeStr, endTimeStr);
    }
    List<URI> tids = toIDs(SearchConstants.TENANT_IDS_PARAM, tenantIDs);
    Map<String, Long> countMap = orderManager.getOrderCount(tids, startTimeInMS, endTimeInMS);
    OrderCount resp = new OrderCount(countMap);
    return resp;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) OrderCount(com.emc.vipr.model.catalog.OrderCount) URIUtil.asString(com.emc.storageos.db.client.URIUtil.asString) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with OrderCount

use of com.emc.vipr.model.catalog.OrderCount in project coprhd-controller by CoprHD.

the class OrderService method getUserOrderCount.

/**
 * Gets the number of orders within a time range for current user
 *
 * @brief Get number of orders created by current user
 * @param startTimeStr
 * @param endTimeStr
 * @return  number of orders
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("/my-order-count")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OrderCount getUserOrderCount(@DefaultValue("") @QueryParam(SearchConstants.START_TIME_PARAM) String startTimeStr, @DefaultValue("") @QueryParam(SearchConstants.END_TIME_PARAM) String endTimeStr) throws DatabaseException {
    StorageOSUser user = getUserFromContext();
    log.info("user={}", user.getName());
    long startTimeInMS = getTime(startTimeStr, 0);
    long endTimeInMS = getTime(endTimeStr, System.currentTimeMillis());
    if (startTimeInMS > endTimeInMS) {
        throw APIException.badRequests.endTimeBeforeStartTime(startTimeStr, endTimeStr);
    }
    log.info("start={} end={}", startTimeInMS, endTimeInMS);
    long count = orderManager.getOrderCount(user, startTimeInMS, endTimeInMS);
    log.info("count={}", count);
    OrderCount resp = new OrderCount();
    resp.put(user.getName(), count);
    return resp;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) OrderCount(com.emc.vipr.model.catalog.OrderCount) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)2 OrderCount (com.emc.vipr.model.catalog.OrderCount)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 URIUtil.asString (com.emc.storageos.db.client.URIUtil.asString)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 URI (java.net.URI)1