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

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

Introduction

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

Prototype

int SC_INTERNAL_SERVER_ERROR

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

Click Source Link

Document

<tt>500 Server Error</tt> (HTTP/1.0 - RFC 1945)

Usage

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

@GET
@Path("device-counts-by-potential-vulnerabilities")
public Response getDeviceCountsByPotentialVulnerabilities() {
    GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();

    List<DeviceCountByGroup> deviceCountsByPotentialVulnerabilities;
    try {//from   w ww. ja  va 2  s  .  co  m
        deviceCountsByPotentialVulnerabilities = gadgetDataService.getDeviceCountsByPotentialVulnerabilities();
    } catch (DataAccessLayerException e) {
        log.error("An internal error occurred while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve device counts by potential vulnerabilities.", e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ERROR_IN_RETRIEVING_REQUESTED_DATA)
                .build();
    }

    DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
    dashboardGadgetDataWrapper.setContext("Device-counts-by-potential-vulnerabilities");
    dashboardGadgetDataWrapper.setGroupingAttribute(POTENTIAL_VULNERABILITY);
    dashboardGadgetDataWrapper.setData(deviceCountsByPotentialVulnerabilities);

    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("non-compliant-device-counts-by-features")
public Response getNonCompliantDeviceCountsByFeatures(@QueryParam(START_INDEX) int startIndex,
        @QueryParam(RESULT_COUNT) int resultCount) {

    GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
    DashboardPaginationGadgetDataWrapper dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper();

    PaginationResult paginationResult;/*from   ww w  .  ja  v a  2  s  .  c  o m*/
    try {
        paginationResult = gadgetDataService.getNonCompliantDeviceCountsByFeatures(startIndex, resultCount);
    } 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 non-compliant set "
                + "of device counts by features.", 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 non-compliant set "
                + "of device counts by features.", 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 non-compliant set of device counts by features.",
                e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ERROR_IN_RETRIEVING_REQUESTED_DATA)
                .build();
    }

    dashboardPaginationGadgetDataWrapper.setContext("Non-compliant-device-counts-by-features");
    dashboardPaginationGadgetDataWrapper.setGroupingAttribute(NON_COMPLIANT_FEATURE_CODE);
    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();
}

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

@GET
@Path("device-counts-by-groups")
public Response getDeviceCountsByGroups(@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   w  w  w  .ja v a 2  s  .c  o  m
    filterSet.setOwnership(ownership);

    // creating device-Counts-by-platforms Data Wrapper
    List<DeviceCountByGroup> deviceCountsByPlatforms;
    try {
        deviceCountsByPlatforms = gadgetDataService.getDeviceCountsByPlatforms(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 device counts by platforms.",
                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 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("Device-counts-by-platforms");
    dashboardGadgetDataWrapper1.setGroupingAttribute(PLATFORM);
    dashboardGadgetDataWrapper1.setData(deviceCountsByPlatforms);

    // creating device-Counts-by-ownership-types Data Wrapper
    List<DeviceCountByGroup> deviceCountsByOwnerships;
    try {
        deviceCountsByOwnerships = gadgetDataService.getDeviceCountsByOwnershipTypes(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 device counts by ownerships.",
                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 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("Device-counts-by-ownerships");
    dashboardGadgetDataWrapper2.setGroupingAttribute(OWNERSHIP);
    dashboardGadgetDataWrapper2.setData(deviceCountsByOwnerships);

    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("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  av  a 2 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);/*  w w w.  j  ava  2  s .c  om*/
    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  w w  w. ja  v a2s .co  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 . ja  v a  2 s. c  om*/

    } 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();/*from www.ja va 2 s .com*/

    } 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.mdm.services.android.Operation.java

@GET
@Path("{id}")
public List<org.wso2.carbon.device.mgt.common.Operation> getPendingOperations(@PathParam("id") String id)
        throws AndroidAgentException {

    List<org.wso2.carbon.device.mgt.common.Operation> operations;
    String msg;//ww  w .  ja v  a 2 s  . com
    DeviceManagementService dmService;

    try {
        dmService = AndroidAPIUtils.getDeviceManagementService();
        DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
        operations = dmService
                .getOperationManager(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID)
                .getPendingOperations(deviceIdentifier);
        Response.status(HttpStatus.SC_OK);
        return operations;
    } catch (DeviceManagementServiceException e) {
        msg = "Device management service error";
        log.error(msg, e);
        throw new AndroidAgentException(msg, e);
    } catch (DeviceManagementException e) {
        msg = "Error occurred while fetching the operation manager for the device type.";
        log.error(msg, e);
        Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        throw new AndroidAgentException(msg, e);
    } catch (OperationManagementException e) {
        msg = "Error occurred while fetching the operation list for the device.";
        log.error(msg, e);
        Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        throw new AndroidAgentException(msg, e);
    }
}

From source file:org.wso2.carbon.mdm.services.android.Operation.java

@PUT
public Message updateOperation() throws AndroidAgentException {
    String msg;/*from  ww  w  . j  ava2s . c  o  m*/
    DeviceManagementService dmService;
    Message responseMsg = new Message();
    try {
        dmService = AndroidAPIUtils.getDeviceManagementService();

        //TODO: need to complete updateOperation logic
        boolean result = dmService.getOperationManager("").addOperation(null, null);
        if (result) {
            Response.status(HttpStatus.SC_OK);
            responseMsg.setResponseMessage("Device has already enrolled");
        } else {
            Response.status(HttpStatus.SC_NOT_FOUND);
            responseMsg.setResponseMessage("Operation not found");
        }
        return responseMsg;
    } catch (DeviceManagementServiceException e) {
        msg = "Device management service error";
        log.error(msg, e);
        throw new AndroidAgentException(msg, e);
    } catch (DeviceManagementException e) {
        msg = "Error occurred while fetching the operation manager for the device type.";
        log.error(msg, e);
        Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        throw new AndroidAgentException(msg, e);
    } catch (OperationManagementException e) {
        msg = "Error occurred while updating the operation status for the device.";
        log.error(msg, e);
        Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        throw new AndroidAgentException(msg, e);
    }
}