From 8c6690a59759117a2eaaf420f4658a4e819b1612 Mon Sep 17 00:00:00 2001 From: charithag Date: Wed, 30 Mar 2016 02:10:31 +0530 Subject: [PATCH] Update MDM admin content from product-emm --- .../org/wso2/carbon/mdm/api/Certificate.java | 25 +++--- .../wso2/carbon/mdm/api/Configuration.java | 2 +- .../carbon/mdm/api/DeviceInformation.java | 83 +++++++++++++++++++ .../org/wso2/carbon/mdm/api/DeviceSearch.java | 56 +++++++++++++ .../java/org/wso2/carbon/mdm/api/Feature.java | 7 +- .../org/wso2/carbon/mdm/api/MobileDevice.java | 4 +- .../java/org/wso2/carbon/mdm/api/Role.java | 8 +- .../wso2/carbon/mdm/api/util/MDMAPIUtils.java | 28 +++++++ .../carbon/mdm/api/util/ResponsePayload.java | 11 +-- .../src/main/webapp/META-INF/permissions.xml | 19 +++++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 24 ++++++ 11 files changed, 237 insertions(+), 30 deletions(-) create mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/DeviceInformation.java create mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/DeviceSearch.java diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Certificate.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Certificate.java index c637252a5e..e7ba2fd3e7 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Certificate.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Certificate.java @@ -18,6 +18,7 @@ package org.wso2.carbon.mdm.api; +import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException; @@ -29,19 +30,13 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.mdm.api.common.MDMAPIException; import org.wso2.carbon.mdm.api.util.MDMAPIUtils; +import org.wso2.carbon.mdm.api.util.ResponsePayload; import org.wso2.carbon.mdm.beans.EnrollmentCertificate; +import org.wso2.carbon.mdm.exception.*; import org.wso2.carbon.mdm.exception.BadRequestException; -import org.wso2.carbon.mdm.exception.Message; +import org.wso2.carbon.mdm.util.MDMUtil; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.ArrayList; @@ -50,8 +45,7 @@ import java.util.List; /** * All the certificate related tasks such as saving certificates, can be done through this endpoint. */ -@SuppressWarnings("NonJaxWsWebServices") -@Produces({"application/json", "application/xml" }) +@Produces({ "application/json", "application/xml" }) @Consumes({ "application/json", "application/xml" }) public class Certificate { @@ -71,7 +65,8 @@ public class Certificate { EnrollmentCertificate[] enrollmentCertificates) throws MDMAPIException { MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader); CertificateManagementService certificateService; - List certificates = new ArrayList<>(); + List certificates = new ArrayList(); org.wso2.carbon.certificate.mgt.core.bean.Certificate certificate; certificateService = MDMAPIUtils.getCertificateManagementService(); try { @@ -184,9 +179,9 @@ public class Certificate { try { deleted = certificateService.removeCertificate(serialNumber); if(deleted){ - return Response.status(Response.Status.OK).entity(true).type(responseMediaType).build(); + return Response.status(Response.Status.OK).entity(deleted).type(responseMediaType).build(); } else { - return Response.status(Response.Status.GONE).entity(false).type(responseMediaType).build(); + return Response.status(Response.Status.GONE).entity(deleted).type(responseMediaType).build(); } } catch (CertificateManagementDAOException e) { String msg = "Error occurred while converting PEM file to X509Certificate"; diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Configuration.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Configuration.java index 6fd806f331..eb8a5e1388 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Configuration.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Configuration.java @@ -79,7 +79,7 @@ public class Configuration { configurationEntry.setValue(PolicyManagerUtil.getMonitoringFequency()); List configList = tenantConfiguration.getConfiguration(); if (configList == null) { - configList = new ArrayList<>(); + configList = new ArrayList(); } configList.add(configurationEntry); tenantConfiguration.setConfiguration(configList); diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/DeviceInformation.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/DeviceInformation.java new file mode 100644 index 0000000000..c8503d32f3 --- /dev/null +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/DeviceInformation.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +package org.wso2.carbon.mdm.api; + +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; +import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; +import org.wso2.carbon.mdm.api.common.MDMAPIException; +import org.wso2.carbon.mdm.api.util.MDMAPIUtils; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +public class DeviceInformation { + + private static Log log = LogFactory.getLog(DeviceInformation.class); + + @GET + @Path("{type}/{id}") + public Response getDeviceInfo(@PathParam("type") String type, @PathParam("id") String id) throws MDMAPIException { + DeviceInformationManager informationManager; + DeviceInfo deviceInfo; + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(id); + deviceIdentifier.setType(type); + informationManager = MDMAPIUtils.getDeviceInformationManagerService(); + deviceInfo = informationManager.getDeviceInfo(deviceIdentifier); + + } catch (DeviceDetailsMgtException e) { + String msg = "Error occurred while getting the device information."; + log.error(msg, e); + throw new MDMAPIException(msg, e); + } + return Response.status(HttpStatus.SC_OK).entity(deviceInfo).build(); + } + + + @GET + @Path("location/{type}/{id}") + public Response getDeviceLocation(@PathParam("type") String type, @PathParam("id") String id) throws MDMAPIException { + DeviceInformationManager informationManager; + DeviceLocation deviceLocation; + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(id); + deviceIdentifier.setType(type); + informationManager = MDMAPIUtils.getDeviceInformationManagerService(); + deviceLocation = informationManager.getDeviceLocation(deviceIdentifier); + + } catch (DeviceDetailsMgtException e) { + String msg = "Error occurred while getting the device location."; + log.error(msg, e); + throw new MDMAPIException(msg, e); + } + return Response.status(HttpStatus.SC_OK).entity(deviceLocation).build(); + } +} + diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/DeviceSearch.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/DeviceSearch.java new file mode 100644 index 0000000000..ab1bf51943 --- /dev/null +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/DeviceSearch.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +package org.wso2.carbon.mdm.api; + +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; +import org.wso2.carbon.device.mgt.common.search.SearchContext; +import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; +import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException; +import org.wso2.carbon.mdm.api.common.MDMAPIException; +import org.wso2.carbon.mdm.api.util.MDMAPIUtils; + +import javax.ws.rs.GET; +import javax.ws.rs.core.Response; +import java.util.List; + +public class DeviceSearch { + + private static Log log = LogFactory.getLog(DeviceSearch.class); + + @GET + public Response getDeviceInfo(SearchContext searchContext) throws MDMAPIException { + SearchManagerService searchManagerService; + List devices; + try { + searchManagerService = MDMAPIUtils.getSearchManagerService(); + devices = searchManagerService.search(searchContext); + + } catch (SearchMgtException e) { + String msg = "Error occurred while searching the device information."; + log.error(msg, e); + throw new MDMAPIException(msg, e); + } + return Response.status(HttpStatus.SC_OK).entity(devices).build(); + } +} + diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Feature.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Feature.java index 1cd357b94a..b98baab481 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Feature.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Feature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -11,10 +11,11 @@ * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ + package org.wso2.carbon.mdm.api; import org.apache.commons.logging.Log; @@ -39,7 +40,7 @@ public class Feature { * Get all features for Mobile Device Type * * @return Feature - * @throws org.wso2.carbon.mdm.api.common.MDMAPIException + * @throws MDMAPIException * */ @GET diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/MobileDevice.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/MobileDevice.java index be7c9bda30..f377817473 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/MobileDevice.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/MobileDevice.java @@ -133,7 +133,7 @@ public class MobileDevice { * @param user User Name * @param tenantDomain tenant domain * @return Device - * @throws org.wso2.carbon.mdm.api.common.MDMAPIException + * @throws MDMAPIException */ @GET @Path("user/{user}/{tenantDomain}") @@ -184,7 +184,7 @@ public class MobileDevice { public List getDevicesByName(@PathParam("name") String deviceName, @PathParam("tenantDomain") String tenantDomain) throws MDMAPIException { - List devices; + List devices; try { devices = MDMAPIUtils.getDeviceManagementService().getDevicesByName(deviceName); } catch (DeviceManagementException e) { diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Role.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Role.java index dda4f243fa..f0157ef4e9 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Role.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/Role.java @@ -49,7 +49,7 @@ public class Role { * Get user roles (except all internal roles) from system. * * @return A list of users - * @throws org.wso2.carbon.mdm.api.common.MDMAPIException + * @throws MDMAPIException */ @GET @Produces ({MediaType.APPLICATION_JSON}) @@ -85,7 +85,7 @@ public class Role { * Get user roles by user store(except all internal roles) from system. * * @return A list of users - * @throws org.wso2.carbon.mdm.api.common.MDMAPIException + * @throws MDMAPIException */ @GET @Path ("{userStore}") @@ -122,7 +122,7 @@ public class Role { * Get user roles by providing a filtering criteria(except all internal roles & system roles) from system. * * @return A list of users - * @throws org.wso2.carbon.mdm.api.common.MDMAPIException + * @throws MDMAPIException */ @GET @Path ("search") @@ -205,7 +205,7 @@ public class Role { * Get user role of the system * * @return user role - * @throws org.wso2.carbon.mdm.api.common.MDMAPIException + * @throws MDMAPIException */ @GET @Path("role") diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/util/MDMAPIUtils.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/util/MDMAPIUtils.java index 6b7cbab596..d2a3fb9d2f 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/util/MDMAPIUtils.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/util/MDMAPIUtils.java @@ -30,6 +30,8 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfigurationManagementService; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; +import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.mdm.api.common.MDMAPIException; import org.wso2.carbon.ntask.core.TaskManager; @@ -282,4 +284,30 @@ public class MDMAPIUtils { return responseMediaType; } + + public static DeviceInformationManager getDeviceInformationManagerService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceInformationManager deviceInformationManager = + (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null); + if (deviceInformationManager == null) { + String msg = "Device information Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return deviceInformationManager; + } + + + + public static SearchManagerService getSearchManagerService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + SearchManagerService searchManagerService = + (SearchManagerService) ctx.getOSGiService(SearchManagerService.class, null); + if (searchManagerService == null) { + String msg = "Device search manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return searchManagerService; + } } diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/util/ResponsePayload.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/util/ResponsePayload.java index 8cc7d3591a..6294000663 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/util/ResponsePayload.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/java/org/wso2/carbon/mdm/api/util/ResponsePayload.java @@ -15,6 +15,7 @@ * specific language governing permissions and limitations * under the License. */ + package org.wso2.carbon.mdm.api.util; import javax.xml.bind.annotation.XmlElement; @@ -54,21 +55,21 @@ public class ResponsePayload { this.responseContent = responseContent; } - private ResponsePayload.ResponsePayloadBuilder getBuilder() { - return new ResponsePayload.ResponsePayloadBuilder(); + private ResponsePayloadBuilder getBuilder() { + return new ResponsePayloadBuilder(); } - public static ResponsePayload.ResponsePayloadBuilder statusCode(int statusCode) { + public static ResponsePayloadBuilder statusCode(int statusCode) { ResponsePayload message = new ResponsePayload(); return message.getBuilder().statusCode(statusCode); } - public static ResponsePayload.ResponsePayloadBuilder messageFromServer(String messageFromServer) { + public static ResponsePayloadBuilder messageFromServer(String messageFromServer) { ResponsePayload message = new ResponsePayload(); return message.getBuilder().messageFromServer(messageFromServer); } - public static ResponsePayload.ResponsePayloadBuilder responseContent(String responseContent) { + public static ResponsePayloadBuilder responseContent(String responseContent) { ResponsePayload message = new ResponsePayload(); return message.getBuilder().responseContent(responseContent); } diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/webapp/META-INF/permissions.xml b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/webapp/META-INF/permissions.xml index 0d5ae5347d..d2442641f1 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/webapp/META-INF/permissions.xml +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/webapp/META-INF/permissions.xml @@ -772,6 +772,25 @@ + + + + Device Information + /device-mgt/emm-admin/information/get + /information/*/* + GET + + + + Device Search + /device-mgt/emm-admin/search + /information/* + GET + + + + + diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 5db3ba5226..e4b794b8a9 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -123,6 +123,26 @@ + + + + + + + + + + + + + + + + + + + +