List of usage examples for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST
int SC_BAD_REQUEST
To view the source code for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST.
Click Source Link
From source file:org.wso2.carbon.device.mgt.jaxrs.api.util.CredentialManagementResponseBuilder.java
/** * Builds the response to change the password of a user * @param credentials - User credentials * @return Response Object// w w w .ja v a 2s . c om */ public static Response buildChangePasswordResponse(UserCredentialWrapper credentials) { ResponsePayload responsePayload = new ResponsePayload(); try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword()); byte[] decodedOldPassword = Base64.decodeBase64(credentials.getOldPassword()); userStoreManager.updateCredential(credentials.getUsername(), new String(decodedNewPassword, "UTF-8"), new String(decodedOldPassword, "UTF-8")); responsePayload.setStatusCode(HttpStatus.SC_CREATED); responsePayload.setMessageFromServer( "UserImpl password by username: " + credentials.getUsername() + " was successfully changed."); return Response.status(Response.Status.CREATED).entity(responsePayload).build(); } catch (UserStoreException e) { log.error(e.getMessage(), e); responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST); responsePayload.setMessageFromServer("Old password does not match."); return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build(); } catch (UnsupportedEncodingException e) { String errorMsg = "Could not change the password of the user: " + credentials.getUsername() + ". The Character Encoding is not supported."; log.error(errorMsg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMsg).build(); } catch (MDMAPIException e) { log.error(e.getErrorMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getErrorMessage()).build(); } }
From source file:org.wso2.carbon.device.mgt.jaxrs.api.util.CredentialManagementResponseBuilder.java
/** * Builds the response to reset the password of a user * @param credentials - User credentials * @return Response Object/*from w ww. j a v a 2 s .c o m*/ */ public static Response buildResetPasswordResponse(UserCredentialWrapper credentials) { ResponsePayload responsePayload = new ResponsePayload(); try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword()); userStoreManager.updateCredentialByAdmin(credentials.getUsername(), new String(decodedNewPassword, "UTF-8")); responsePayload.setStatusCode(HttpStatus.SC_CREATED); responsePayload.setMessageFromServer( "UserImpl password by username: " + credentials.getUsername() + " was successfully changed."); return Response.status(Response.Status.CREATED).entity(responsePayload).build(); } catch (UserStoreException e) { log.error(e.getMessage(), e); responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST); responsePayload.setMessageFromServer("Could not change the password."); return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build(); } catch (UnsupportedEncodingException e) { String errorMsg = "Could not change the password of the user: " + credentials.getUsername() + ". The Character Encoding is not supported."; log.error(errorMsg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMsg).build(); } catch (MDMAPIException e) { log.error(e.getErrorMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getErrorMessage()).build(); } }
From source file:org.wso2.carbon.mdm.api.Dashboard.java
@GET @Path("non-compliant-device-counts-by-features") public Response getNonCompliantDeviceCountsByFeatures(@QueryParam(START_INDEX) int startIndex, @QueryParam(RESULT_COUNT) int resultCount) throws MDMAPIException { GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService(); DashboardPaginationGadgetDataWrapper dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper(); PaginationResult paginationResult;//ww w . java 2s. c o m try { paginationResult = gadgetDataService.getNonCompliantDeviceCountsByFeatures(startIndex, resultCount); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("This was while trying to execute relevant data service " + "function @ Dashboard API layer to retrieve a non-compliant set of device counts by features."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "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."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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.mdm.api.Dashboard.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) throws MDMAPIException { // getting gadget data service GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService(); // constructing filter set FilterSet filterSet = new FilterSet(); filterSet.setConnectivityStatus(connectivityStatus); filterSet.setPotentialVulnerability(potentialVulnerability); filterSet.setPlatform(platform);// w ww .ja va 2s. com filterSet.setOwnership(ownership); // creating device-Counts-by-platforms Data Wrapper List<DeviceCountByGroupEntry> deviceCountsByPlatforms; try { deviceCountsByPlatforms = gadgetDataService.getDeviceCountsByPlatforms(filterSet); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("This was while trying to execute relevant data service " + "function @ Dashboard API layer to retrieve a filtered set of device counts by platforms."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "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."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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<DeviceCountByGroupEntry> deviceCountsByOwnerships; try { deviceCountsByOwnerships = gadgetDataService.getDeviceCountsByOwnershipTypes(filterSet); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("This was while trying to execute relevant data service " + "function @ Dashboard API layer to retrieve a filtered set of device counts by ownerships."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "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."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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.mdm.api.Dashboard.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) throws MDMAPIException { // getting gadget data service GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService(); // constructing filter set FilterSet filterSet = new FilterSet(); filterSet.setPlatform(platform);//from w ww.j a va 2 s . c o m filterSet.setOwnership(ownership); // creating feature-non-compliant-device-Counts-by-platforms Data Wrapper List<DeviceCountByGroupEntry> featureNonCompliantDeviceCountsByPlatforms; try { featureNonCompliantDeviceCountsByPlatforms = gadgetDataService .getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("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."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "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."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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<DeviceCountByGroupEntry> featureNonCompliantDeviceCountsByOwnerships; try { featureNonCompliantDeviceCountsByOwnerships = gadgetDataService .getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("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."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "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."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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.mdm.api.Dashboard.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) throws MDMAPIException { // getting gadget data service GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService(); // constructing filter set FilterSet filterSet = new FilterSet(); filterSet.setConnectivityStatus(connectivityStatus); filterSet.setPotentialVulnerability(potentialVulnerability); filterSet.setPlatform(platform);/*from w w w . j av a 2s.c o m*/ filterSet.setOwnership(ownership); // creating filteredDeviceCount Data Wrapper DeviceCountByGroupEntry filteredDeviceCount; try { filteredDeviceCount = gadgetDataService.getDeviceCount(filterSet); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("This was while trying to execute relevant data service " + "function @ Dashboard API layer to retrieve a filtered device count over the total."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "An internal error occurred while trying to execute relevant data service function " + "@ Dashboard API layer to retrieve a filtered device count over the total."; log.error(msg, e); throw new MDMAPIException(msg, e); } // creating TotalDeviceCount Data Wrapper DeviceCountByGroupEntry totalDeviceCount; try { totalDeviceCount = gadgetDataService.getTotalDeviceCount(); } catch (DataAccessLayerException e) { String msg = "An internal error occurred while trying to execute relevant data service function " + "@ Dashboard API layer to retrieve the total device count over filtered."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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.mdm.api.Dashboard.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) throws MDMAPIException { // getting gadget data service GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService(); // constructing filter set FilterSet filterSet = new FilterSet(); filterSet.setPlatform(platform);/*w w w. j av a 2s . c o m*/ filterSet.setOwnership(ownership); // creating featureNonCompliantDeviceCount Data Wrapper DeviceCountByGroupEntry featureNonCompliantDeviceCount; try { featureNonCompliantDeviceCount = gadgetDataService .getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("This was while trying to execute relevant data service " + "function @ Dashboard API layer to retrieve a feature non-compliant device count over the total."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "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."; log.error(msg, e); throw new MDMAPIException(msg, e); } // creating TotalDeviceCount Data Wrapper DeviceCountByGroupEntry totalDeviceCount; try { totalDeviceCount = gadgetDataService.getTotalDeviceCount(); } catch (DataAccessLayerException e) { String msg = "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."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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.mdm.api.Dashboard.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) throws MDMAPIException { if (paginationEnabled == null) { Message message = new Message(); message.setErrorMessage("Missing required query parameter."); message.setDescription("Pagination-enabled query parameter with value true or false is required."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } else if (FLAG_TRUE.equals(paginationEnabled)) { // getting gadget data service GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService(); // constructing filter set FilterSet filterSet = new FilterSet(); filterSet.setConnectivityStatus(connectivityStatus); filterSet.setPotentialVulnerability(potentialVulnerability); filterSet.setPlatform(platform); filterSet.setOwnership(ownership); PaginationResult paginationResult; try {//from ww w. j a v a 2 s .c om paginationResult = gadgetDataService.getDevicesWithDetails(filterSet, startIndex, resultCount); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("This was while trying to execute relevant data service " + "function @ Dashboard API layer to retrieve a filtered set of devices with details."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "An internal error occurred while trying to execute relevant data service function " + "@ Dashboard API layer to retrieve a filtered set of devices with details."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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 = MDMAPIUtils.getGadgetDataService(); // constructing filter set FilterSet filterSet = new FilterSet(); filterSet.setConnectivityStatus(connectivityStatus); filterSet.setPotentialVulnerability(potentialVulnerability); filterSet.setPlatform(platform); filterSet.setOwnership(ownership); List<DetailedDeviceEntry> devicesWithDetails; try { devicesWithDetails = gadgetDataService.getDevicesWithDetails(filterSet); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("This was while trying to execute relevant data service " + "function @ Dashboard API layer to retrieve a filtered set of devices with details."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "An internal error occurred while trying to execute relevant data service function " + "@ Dashboard API layer to retrieve a filtered set of devices with details."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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 { Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription( "Invalid value for query parameter pagination-enabled. " + "Should be either true or false."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } }
From source file:org.wso2.carbon.mdm.api.Dashboard.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) throws MDMAPIException { if (paginationEnabled == null) { Message message = new Message(); message.setErrorMessage("Missing required query parameters."); message.setDescription("Query parameter pagination-enabled with value true or false is required."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } else if (FLAG_TRUE.equals(paginationEnabled)) { // getting gadget data service GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService(); // constructing filter set FilterSet filterSet = new FilterSet(); filterSet.setPlatform(platform); filterSet.setOwnership(ownership); PaginationResult paginationResult; try {/*from ww w .j a v a2 s . c om*/ paginationResult = gadgetDataService.getFeatureNonCompliantDevicesWithDetails( nonCompliantFeatureCode, filterSet, startIndex, resultCount); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("This was while trying to execute relevant service layer " + "function @ Dashboard API layer to retrieve a filtered set of " + "feature non-compliant devices with details."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "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."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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 = MDMAPIUtils.getGadgetDataService(); // constructing filter set FilterSet filterSet = new FilterSet(); filterSet.setPlatform(platform); filterSet.setOwnership(ownership); List<DetailedDeviceEntry> featureNonCompliantDevicesWithDetails; try { featureNonCompliantDevicesWithDetails = gadgetDataService .getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet); } catch (InvalidParameterValueException e) { log.error("Error occurred @ Gadget Data Service layer due to invalid parameter value.", e); Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription("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."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } catch (DataAccessLayerException e) { String msg = "An internal error occurred while trying to execute relevant data service function " + "@ Dashboard API layer to retrieve a filtered set of feature " + "non-compliant set of devices with details."; log.error(msg, e); throw new MDMAPIException(msg, e); } 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 { Message message = new Message(); message.setErrorMessage("Invalid query parameter value."); message.setDescription( "Invalid value for " + "query parameter pagination-enabled. Should be either true or false."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build(); } }
From source file:org.wso2.carbon.mdm.api.Policy.java
@PUT @Path("priorities") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public Response updatePolicyPriorities(List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies) throws MDMAPIException { PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService(); List<org.wso2.carbon.policy.mgt.common.Policy> policiesToUpdate = new ArrayList<org.wso2.carbon.policy.mgt.common.Policy>( priorityUpdatedPolicies.size()); int i;/*ww w .jav a 2 s .c om*/ 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 error = "Exception in updating policy priorities."; log.error(error, e); throw new MDMAPIException(error, e); } ResponsePayload responsePayload = new ResponsePayload(); if (policiesUpdated) { responsePayload.setStatusCode(HttpStatus.SC_OK); responsePayload.setMessageFromServer("Policy Priorities successfully updated."); return Response.status(HttpStatus.SC_OK).entity(responsePayload).build(); } else { responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST); responsePayload.setMessageFromServer("Policy priorities did not update. Bad Request."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build(); } }