Example usage for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST

List of usage examples for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST.

Prototype

int SC_BAD_REQUEST

To view the source code for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST.

Click Source Link

Document

<tt>400 Bad Request</tt> (HTTP/1.1 - RFC 2616)

Usage

From source file:org.wso2.carbon.device.mgt.jaxrs.api.DashboardImpl.java

@GET
@Path("feature-non-compliant-device-counts-by-groups")
public Response getFeatureNonCompliantDeviceCountsByGroups(
        @QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
        @QueryParam(PLATFORM) String platform, @QueryParam(OWNERSHIP) String ownership) {
    // getting gadget data service
    GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();

    // constructing filter set
    BasicFilterSet filterSet = new BasicFilterSet();
    filterSet.setPlatform(platform);// w  ww  .  j  a v a2 s.c  o m
    filterSet.setOwnership(ownership);

    // creating feature-non-compliant-device-Counts-by-platforms Data Wrapper
    List<DeviceCountByGroup> featureNonCompliantDeviceCountsByPlatforms;
    try {
        featureNonCompliantDeviceCountsByPlatforms = gadgetDataService
                .getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet);
    } catch (InvalidFeatureCodeValueException e) {
        log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                + "invalid (query) parameter value. This was while trying to execute relevant data service "
                + "function @ Dashboard API layer to retrieve a filtered set of feature "
                + "non-compliant device counts by platforms.", e);
        return Response.status(HttpStatus.SC_BAD_REQUEST)
                .entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
    } catch (DataAccessLayerException e) {
        log.error("An internal error occurred while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve a filtered set of feature non-compliant "
                + "device counts by platforms.", e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ERROR_IN_RETRIEVING_REQUESTED_DATA)
                .build();
    }

    DashboardGadgetDataWrapper dashboardGadgetDataWrapper1 = new DashboardGadgetDataWrapper();
    dashboardGadgetDataWrapper1.setContext("Feature-non-compliant-device-counts-by-platforms");
    dashboardGadgetDataWrapper1.setGroupingAttribute(PLATFORM);
    dashboardGadgetDataWrapper1.setData(featureNonCompliantDeviceCountsByPlatforms);

    // creating feature-non-compliant-device-Counts-by-ownership-types Data Wrapper
    List<DeviceCountByGroup> featureNonCompliantDeviceCountsByOwnerships;
    try {
        featureNonCompliantDeviceCountsByOwnerships = gadgetDataService
                .getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet);
    } catch (InvalidFeatureCodeValueException e) {
        log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                + "invalid (query) parameter value. This was while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve a filtered set of feature "
                + "non-compliant device counts by ownerships.", e);
        return Response.status(HttpStatus.SC_BAD_REQUEST)
                .entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
    } catch (DataAccessLayerException e) {
        log.error("An internal error occurred while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve a filtered set of feature non-compliant "
                + "device counts by ownerships.", e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ERROR_IN_RETRIEVING_REQUESTED_DATA)
                .build();
    }

    DashboardGadgetDataWrapper dashboardGadgetDataWrapper2 = new DashboardGadgetDataWrapper();
    dashboardGadgetDataWrapper2.setContext("Feature-non-compliant-device-counts-by-ownerships");
    dashboardGadgetDataWrapper2.setGroupingAttribute(OWNERSHIP);
    dashboardGadgetDataWrapper2.setData(featureNonCompliantDeviceCountsByOwnerships);

    List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
    responsePayload.add(dashboardGadgetDataWrapper1);
    responsePayload.add(dashboardGadgetDataWrapper2);

    return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}

From source file:org.wso2.carbon.device.mgt.jaxrs.api.DashboardImpl.java

@GET
@Path("filtered-device-count-over-total")
public Response getFilteredDeviceCountOverTotal(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
        @QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
        @QueryParam(PLATFORM) String platform, @QueryParam(OWNERSHIP) String ownership) {

    // getting gadget data service
    GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();

    // constructing filter set
    ExtendedFilterSet filterSet = new ExtendedFilterSet();
    filterSet.setConnectivityStatus(connectivityStatus);
    filterSet.setPotentialVulnerability(potentialVulnerability);
    filterSet.setPlatform(platform);/*from  www  .  j a v  a  2  s. com*/
    filterSet.setOwnership(ownership);

    // creating filteredDeviceCount Data Wrapper
    DeviceCountByGroup filteredDeviceCount;
    try {
        filteredDeviceCount = gadgetDataService.getDeviceCount(filterSet);
    } catch (InvalidPotentialVulnerabilityValueException e) {
        log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                + "invalid (query) parameter value. This was while trying to execute relevant data service "
                + "function @ Dashboard API layer to retrieve a filtered device count over the total.", e);
        return Response.status(HttpStatus.SC_BAD_REQUEST)
                .entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
    } catch (DataAccessLayerException e) {
        log.error("An internal error occurred while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve a filtered device count over the total.", e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ERROR_IN_RETRIEVING_REQUESTED_DATA)
                .build();
    }

    // creating TotalDeviceCount Data Wrapper
    DeviceCountByGroup totalDeviceCount;
    try {
        totalDeviceCount = gadgetDataService.getTotalDeviceCount();
    } catch (DataAccessLayerException e) {
        log.error("An internal error occurred while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve the total device count over filtered.", e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ERROR_IN_RETRIEVING_REQUESTED_DATA)
                .build();
    }

    List<Object> filteredDeviceCountOverTotalDataWrapper = new ArrayList<>();
    filteredDeviceCountOverTotalDataWrapper.add(filteredDeviceCount);
    filteredDeviceCountOverTotalDataWrapper.add(totalDeviceCount);

    DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
    dashboardGadgetDataWrapper.setContext("Filtered-device-count-over-total");
    dashboardGadgetDataWrapper.setGroupingAttribute(null);
    dashboardGadgetDataWrapper.setData(filteredDeviceCountOverTotalDataWrapper);

    List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
    responsePayload.add(dashboardGadgetDataWrapper);

    return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}

From source file:org.wso2.carbon.device.mgt.jaxrs.api.DashboardImpl.java

@GET
@Path("feature-non-compliant-device-count-over-total")
public Response getFeatureNonCompliantDeviceCountOverTotal(
        @QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
        @QueryParam(PLATFORM) String platform, @QueryParam(OWNERSHIP) String ownership) {

    // getting gadget data service
    GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();

    // constructing filter set
    BasicFilterSet filterSet = new BasicFilterSet();
    filterSet.setPlatform(platform);/*from  www. j av  a 2 s  .  c  o m*/
    filterSet.setOwnership(ownership);

    // creating featureNonCompliantDeviceCount Data Wrapper
    DeviceCountByGroup featureNonCompliantDeviceCount;
    try {
        featureNonCompliantDeviceCount = gadgetDataService
                .getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet);
    } catch (InvalidFeatureCodeValueException e) {
        log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                + "invalid (query) parameter value. This was while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve a feature non-compliant device count over the total.", e);
        return Response.status(HttpStatus.SC_BAD_REQUEST)
                .entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
    } catch (DataAccessLayerException e) {
        log.error("An internal error occurred while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve a feature non-compliant device count over the total.", e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ERROR_IN_RETRIEVING_REQUESTED_DATA)
                .build();
    }

    // creating TotalDeviceCount Data Wrapper
    DeviceCountByGroup totalDeviceCount;
    try {
        totalDeviceCount = gadgetDataService.getTotalDeviceCount();
    } catch (DataAccessLayerException e) {
        log.error("An internal error occurred while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve the total device count over filtered feature non-compliant.",
                e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ERROR_IN_RETRIEVING_REQUESTED_DATA)
                .build();
    }

    List<Object> featureNonCompliantDeviceCountOverTotalDataWrapper = new ArrayList<>();
    featureNonCompliantDeviceCountOverTotalDataWrapper.add(featureNonCompliantDeviceCount);
    featureNonCompliantDeviceCountOverTotalDataWrapper.add(totalDeviceCount);

    DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
    dashboardGadgetDataWrapper.setContext("Feature-non-compliant-device-count-over-total");
    dashboardGadgetDataWrapper.setGroupingAttribute(null);
    dashboardGadgetDataWrapper.setData(featureNonCompliantDeviceCountOverTotalDataWrapper);

    List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
    responsePayload.add(dashboardGadgetDataWrapper);

    return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}

From source file:org.wso2.carbon.device.mgt.jaxrs.api.DashboardImpl.java

@GET
@Path("devices-with-details")
public Response getDevicesWithDetails(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
        @QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
        @QueryParam(PLATFORM) String platform, @QueryParam(OWNERSHIP) String ownership,
        @QueryParam(PAGINATION_ENABLED) String paginationEnabled, @QueryParam(START_INDEX) int startIndex,
        @QueryParam(RESULT_COUNT) int resultCount) {

    if (paginationEnabled == null) {

        log.error("Bad request on retrieving a filtered set of devices with details @ "
                + "Dashboard API layer. " + REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
        return Response.status(HttpStatus.SC_BAD_REQUEST).entity(REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED)
                .build();// w w w.  j  ava  2  s  .  c  o m

    } else if (FLAG_TRUE.equals(paginationEnabled)) {

        // getting gadget data service
        GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();

        // constructing filter set
        ExtendedFilterSet filterSet = new ExtendedFilterSet();
        filterSet.setConnectivityStatus(connectivityStatus);
        filterSet.setPotentialVulnerability(potentialVulnerability);
        filterSet.setPlatform(platform);
        filterSet.setOwnership(ownership);

        PaginationResult paginationResult;
        try {
            paginationResult = gadgetDataService.getDevicesWithDetails(filterSet, startIndex, resultCount);
        } catch (InvalidPotentialVulnerabilityValueException e) {
            log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                    + "invalid (query) parameter value. This was while trying to execute relevant data service "
                    + "function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
            return Response.status(HttpStatus.SC_BAD_REQUEST)
                    .entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
        } catch (InvalidStartIndexValueException e) {
            log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                    + "invalid (query) parameter value. This was while trying to execute relevant data service "
                    + "function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
            return Response.status(HttpStatus.SC_BAD_REQUEST).entity(INVALID_QUERY_PARAM_VALUE_START_INDEX)
                    .build();
        } catch (InvalidResultCountValueException e) {
            log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                    + "invalid (query) parameter value. This was while trying to execute relevant data service "
                    + "function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
            return Response.status(HttpStatus.SC_BAD_REQUEST).entity(INVALID_QUERY_PARAM_VALUE_RESULT_COUNT)
                    .build();
        } catch (DataAccessLayerException e) {
            log.error("An internal error occurred while trying to execute relevant data service function "
                    + "@ Dashboard API layer to retrieve a filtered set of devices with details.", e);
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
                    .entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
        }

        DashboardPaginationGadgetDataWrapper dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper();
        dashboardPaginationGadgetDataWrapper.setContext("Filtered-and-paginated-devices-with-details");
        dashboardPaginationGadgetDataWrapper.setGroupingAttribute(null);
        dashboardPaginationGadgetDataWrapper.setData(paginationResult.getData());
        dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());

        List<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
        responsePayload.add(dashboardPaginationGadgetDataWrapper);

        return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();

    } else if (FLAG_FALSE.equals(paginationEnabled)) {

        // getting gadget data service
        GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();

        // constructing filter set
        ExtendedFilterSet filterSet = new ExtendedFilterSet();
        filterSet.setConnectivityStatus(connectivityStatus);
        filterSet.setPotentialVulnerability(potentialVulnerability);
        filterSet.setPlatform(platform);
        filterSet.setOwnership(ownership);

        List<DeviceWithDetails> devicesWithDetails;
        try {
            devicesWithDetails = gadgetDataService.getDevicesWithDetails(filterSet);
        } catch (InvalidPotentialVulnerabilityValueException e) {
            log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                    + "invalid (query) parameter value. This was while trying to execute relevant data service "
                    + "function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
            return Response.status(HttpStatus.SC_BAD_REQUEST)
                    .entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
        } catch (DataAccessLayerException e) {
            log.error("An internal error occurred while trying to execute relevant data service function "
                    + "@ Dashboard API layer to retrieve a filtered set of devices with details.", e);
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
                    .entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
        }

        DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
        dashboardGadgetDataWrapper.setContext("Filtered-devices-with-details");
        dashboardGadgetDataWrapper.setGroupingAttribute(null);
        dashboardGadgetDataWrapper.setData(devicesWithDetails);

        List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
        responsePayload.add(dashboardGadgetDataWrapper);

        return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();

    } else {

        log.error("Bad request on retrieving a filtered set of devices with details @ "
                + "Dashboard API layer. " + INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
        return Response.status(HttpStatus.SC_BAD_REQUEST).entity(INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED)
                .build();

    }
}

From source file:org.wso2.carbon.device.mgt.jaxrs.api.DashboardImpl.java

@GET
@Path("feature-non-compliant-devices-with-details")
public Response getFeatureNonCompliantDevicesWithDetails(
        @QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
        @QueryParam(PLATFORM) String platform, @QueryParam(OWNERSHIP) String ownership,
        @QueryParam(PAGINATION_ENABLED) String paginationEnabled, @QueryParam(START_INDEX) int startIndex,
        @QueryParam(RESULT_COUNT) int resultCount) {
    if (paginationEnabled == null) {

        log.error("Bad request on retrieving a filtered set of feature non-compliant devices with "
                + "details @ Dashboard API layer. " + REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
        return Response.status(HttpStatus.SC_BAD_REQUEST).entity(REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED)
                .build();/*ww w.  j  av a 2  s  .c om*/

    } else if (FLAG_TRUE.equals(paginationEnabled)) {

        // getting gadget data service
        GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();

        // constructing filter set
        BasicFilterSet filterSet = new BasicFilterSet();
        filterSet.setPlatform(platform);
        filterSet.setOwnership(ownership);

        PaginationResult paginationResult;
        try {
            paginationResult = gadgetDataService.getFeatureNonCompliantDevicesWithDetails(
                    nonCompliantFeatureCode, filterSet, startIndex, resultCount);
        } catch (InvalidFeatureCodeValueException e) {
            log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                    + "invalid (query) parameter value. This was while trying to execute relevant data service "
                    + "function @ Dashboard API layer to retrieve a filtered set of "
                    + "feature non-compliant devices with details.", e);
            return Response.status(HttpStatus.SC_BAD_REQUEST)
                    .entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
        } catch (InvalidStartIndexValueException e) {
            log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                    + "invalid (query) parameter value. This was while trying to execute relevant data service "
                    + "function @ Dashboard API layer to retrieve a filtered set of "
                    + "feature non-compliant devices with details.", e);
            return Response.status(HttpStatus.SC_BAD_REQUEST).entity(INVALID_QUERY_PARAM_VALUE_START_INDEX)
                    .build();
        } catch (InvalidResultCountValueException e) {
            log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                    + "invalid (query) parameter value. This was while trying to execute relevant data service "
                    + "function @ Dashboard API layer to retrieve a filtered set of "
                    + "feature non-compliant devices with details.", e);
            return Response.status(HttpStatus.SC_BAD_REQUEST).entity(INVALID_QUERY_PARAM_VALUE_RESULT_COUNT)
                    .build();
        } catch (DataAccessLayerException e) {
            log.error("An internal error occurred while trying to execute relevant data service function "
                    + "@ Dashboard API layer to retrieve a filtered set of feature "
                    + "non-compliant devices with details.", e);
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
                    .entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
        }

        DashboardPaginationGadgetDataWrapper dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper();
        dashboardPaginationGadgetDataWrapper
                .setContext("Filtered-and-paginated-feature-non-compliant-devices-with-details");
        dashboardPaginationGadgetDataWrapper.setGroupingAttribute(null);
        dashboardPaginationGadgetDataWrapper.setData(paginationResult.getData());
        dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());

        List<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
        responsePayload.add(dashboardPaginationGadgetDataWrapper);

        return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();

    } else if (FLAG_FALSE.equals(paginationEnabled)) {

        // getting gadget data service
        GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();

        // constructing filter set
        BasicFilterSet filterSet = new BasicFilterSet();
        filterSet.setPlatform(platform);
        filterSet.setOwnership(ownership);

        List<DeviceWithDetails> featureNonCompliantDevicesWithDetails;
        try {
            featureNonCompliantDevicesWithDetails = gadgetDataService
                    .getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet);
        } catch (InvalidFeatureCodeValueException e) {
            log.error("Bad request and error occurred @ Gadget Data Service layer due to "
                    + "invalid (query) parameter value. This was while trying to execute relevant data service "
                    + "function @ Dashboard API layer to retrieve a filtered set of "
                    + "feature non-compliant devices with details.", e);
            return Response.status(HttpStatus.SC_BAD_REQUEST)
                    .entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
        } catch (DataAccessLayerException e) {
            log.error("An internal error occurred while trying to execute relevant data service function "
                    + "@ Dashboard API layer to retrieve a filtered set of feature "
                    + "non-compliant devices with details.", e);
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
                    .entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
        }

        DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
        dashboardGadgetDataWrapper.setContext("Filtered-feature-non-compliant-devices-with-details");
        dashboardGadgetDataWrapper.setGroupingAttribute(null);
        dashboardGadgetDataWrapper.setData(featureNonCompliantDevicesWithDetails);

        List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
        responsePayload.add(dashboardGadgetDataWrapper);

        return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();

    } else {

        log.error("Bad request on retrieving a filtered set of feature non-compliant devices with "
                + "details @ Dashboard API layer. " + INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
        return Response.status(HttpStatus.SC_BAD_REQUEST).entity(INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED)
                .build();

    }
}

From source file:org.wso2.carbon.device.mgt.jaxrs.api.impl.PolicyImpl.java

@Override
@PUT/*from   w  w  w  . j  av  a2 s  . c  o  m*/
@Path("priorities")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response updatePolicyPriorities(List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies) {
    PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
    List<org.wso2.carbon.policy.mgt.common.Policy> policiesToUpdate = new ArrayList<>(
            priorityUpdatedPolicies.size());
    int i;
    for (i = 0; i < priorityUpdatedPolicies.size(); i++) {
        org.wso2.carbon.policy.mgt.common.Policy policyObj = new org.wso2.carbon.policy.mgt.common.Policy();
        policyObj.setId(priorityUpdatedPolicies.get(i).getId());
        policyObj.setPriorityId(priorityUpdatedPolicies.get(i).getPriority());
        policiesToUpdate.add(policyObj);
    }
    boolean policiesUpdated;
    try {
        PolicyAdministratorPoint pap = policyManagementService.getPAP();
        policiesUpdated = pap.updatePolicyPriorities(policiesToUpdate);
    } catch (PolicyManagementException e) {
        String msg = "Exception in updating policy priorities.";
        log.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
    }
    ResponsePayload responsePayload = new ResponsePayload();
    if (policiesUpdated) {
        responsePayload.setStatusCode(HttpStatus.SC_OK);
        responsePayload.setMessageFromServer("Policy Priorities successfully updated.");
        return Response.status(Response.Status.OK).entity(responsePayload).build();
    } else {
        responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
        responsePayload.setMessageFromServer("Policy priorities did not update. Bad Request.");
        return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
    }
}

From source file:org.wso2.carbon.device.mgt.jaxrs.api.impl.PolicyImpl.java

@Override
@POST/*from  w  ww.jav  a  2 s .  c o  m*/
@Path("bulk-remove")
@Consumes("application/json")
@Produces("application/json")
public Response bulkRemovePolicy(List<Integer> policyIds) {
    PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
    boolean policyDeleted = true;
    try {
        PolicyAdministratorPoint pap = policyManagementService.getPAP();
        for (int i : policyIds) {
            org.wso2.carbon.policy.mgt.common.Policy policy = pap.getPolicy(i);
            if (!pap.deletePolicy(policy)) {
                policyDeleted = false;
            }
        }
    } catch (PolicyManagementException e) {
        String msg = "Exception in deleting policies.";
        log.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
    }
    ResponsePayload responsePayload = new ResponsePayload();
    if (policyDeleted) {
        responsePayload.setStatusCode(HttpStatus.SC_OK);
        responsePayload.setMessageFromServer("Policies have been successfully deleted.");
        return Response.status(Response.Status.OK).entity(responsePayload).build();
    } else {
        responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
        responsePayload.setMessageFromServer("Policy does not exist.");
        return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
    }
}

From source file:org.wso2.carbon.device.mgt.jaxrs.api.impl.UserImpl.java

/**
 * Method to get user information from emm-user-store.
 *
 * @param username User-name of the user
 * @return {Response} Status of the request wrapped inside Response object.
 *///from   w w w .  java2s .  c  o m
@Override
@GET
@Path("view")
@Produces({ MediaType.APPLICATION_JSON })
public Response getUser(@QueryParam("username") String username) {
    ResponsePayload responsePayload = new ResponsePayload();
    try {
        UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
        if (userStoreManager.isExistingUser(username)) {
            UserWrapper user = new UserWrapper();
            user.setUsername(username);
            user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
            user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
            user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
            // Outputting debug message upon successful retrieval of user
            if (log.isDebugEnabled()) {
                log.debug("User by username: " + username + " was found.");
            }
            responsePayload.setStatusCode(HttpStatus.SC_OK);
            responsePayload.setMessageFromServer("User information was retrieved successfully.");
            responsePayload.setResponseContent(user);
            return Response.status(Response.Status.OK).entity(responsePayload).build();
        } else {
            // Outputting debug message upon trying to remove non-existing user
            if (log.isDebugEnabled()) {
                log.debug("User by username: " + username + " does not exist.");
            }
            // returning response with bad request state
            responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
            responsePayload.setMessageFromServer("User by username: " + username + " does not exist.");
            return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
        }
    } catch (UserStoreException | MDMAPIException e) {
        String msg = "Exception in trying to retrieve user by username: " + username;
        log.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
    }
}

From source file:org.wso2.carbon.device.mgt.jaxrs.api.impl.UserImpl.java

/**
 * Method to remove user from emm-user-store.
 *
 * @param username Username of the user//from w  w  w  . j  a v a2s  .  co  m
 * @return {Response} Status of the request wrapped inside Response object.
 */
@Override
@DELETE
@Produces({ MediaType.APPLICATION_JSON })
public Response removeUser(@QueryParam("username") String username) {
    ResponsePayload responsePayload = new ResponsePayload();
    try {
        UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
        if (userStoreManager.isExistingUser(username)) {
            // if user already exists, trying to remove user
            userStoreManager.deleteUser(username);
            // Outputting debug message upon successful removal of user
            if (log.isDebugEnabled()) {
                log.debug("User by username: " + username + " was successfully removed.");
            }
            // returning response with success state
            responsePayload.setStatusCode(HttpStatus.SC_OK);
            responsePayload
                    .setMessageFromServer("User by username: " + username + " was successfully removed.");
            return Response.status(Response.Status.OK).entity(responsePayload).build();
        } else {
            // Outputting debug message upon trying to remove non-existing user
            if (log.isDebugEnabled()) {
                log.debug("User by username: " + username + " does not exist for removal.");
            }
            // returning response with bad request state
            responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
            responsePayload
                    .setMessageFromServer("User by username: " + username + " does not exist for removal.");
            return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
        }
    } catch (UserStoreException | MDMAPIException e) {
        String msg = "Exception in trying to remove user by username: " + username;
        log.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
    }
}

From source file:org.wso2.carbon.device.mgt.jaxrs.api.impl.UserImpl.java

/**
 * Get user's roles by username/*from  ww w. j a v a 2 s . co  m*/
 *
 * @param username Username of the user
 * @return {Response} Status of the request wrapped inside Response object.
 */
@Override
@GET
@Path("roles")
@Produces({ MediaType.APPLICATION_JSON })
public Response getRolesOfUser(@QueryParam("username") String username) {
    ResponsePayload responsePayload = new ResponsePayload();
    try {
        UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
        if (userStoreManager.isExistingUser(username)) {
            responsePayload.setResponseContent(
                    Collections.singletonList(getFilteredRoles(userStoreManager, username)));
            // Outputting debug message upon successful removal of user
            if (log.isDebugEnabled()) {
                log.debug("User by username: " + username + " was successfully removed.");
            }
            // returning response with success state
            responsePayload.setStatusCode(HttpStatus.SC_OK);
            responsePayload.setMessageFromServer("User roles obtained for user " + username);
            return Response.status(Response.Status.OK).entity(responsePayload).build();
        } else {
            // Outputting debug message upon trying to remove non-existing user
            if (log.isDebugEnabled()) {
                log.debug("User by username: " + username + " does not exist for role retrieval.");
            }
            // returning response with bad request state
            responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
            responsePayload.setMessageFromServer(
                    "User by username: " + username + " does not exist for role retrieval.");
            return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
        }
    } catch (UserStoreException | MDMAPIException e) {
        String msg = "Exception in trying to retrieve roles for user by username: " + username;
        log.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
    }
}