diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/pom.xml b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/pom.xml new file mode 100644 index 0000000000..b18f4a042d --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/pom.xml @@ -0,0 +1,149 @@ + + + + + org.wso2.carbon.devicemgt-plugins + extensions + 2.2.3-SNAPSHOT + ../pom.xml + + 4.0.0 + 2.2.3-SNAPSHOT + org.wso2.carbon.appmgt.mdm.osgiconnector + bundle + WSO2 Carbon - App Manager WSO2 MDM OSGI Connector Component + http://maven.apache.org + + + + + org.apache.felix + maven-scr-plugin + + + generate-scr-scrdescriptor + + scr + + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + org.wso2.carbon.appmgt.mdm.osgiconnector.internal + + org.wso2.carbon.device.mgt.core.*, + org.wso2.carbon.appmgt.mobile.utils.*, + org.wso2.carbon.appmgt.mobile.mdm.*, + org.wso2.carbon.appmgt.mobile.interfaces.*, + *;resolution:=optional + + + !org.wso2.carbon.appmgt.mdm.osgiconnector.internal, + org.wso2.carbon.appmgt.mdm.osgiconnector.* + + + + + + + + + org.wso2.carbon.appmgt + org.wso2.carbon.appmgt.mobile + + + org.apache.ws.commons.axiom + axiom-api + + + org.apache.ws.commons.axiom + axiom-impl + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + + + org.apache.ws.commons.axiom + axiom-api + + + org.apache.ws.commons.axiom + axiom-impl + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.core + + + org.apache.ws.commons.axiom + axiom-api + + + org.apache.ws.commons.axiom + axiom-impl + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + org.apache.ws.commons.axiom + axiom-api + + + org.apache.ws.commons.axiom + axiom-impl + + + + + commons-io.wso2 + commons-io + + + com.googlecode.json-simple.wso2 + json-simple + + + com.googlecode.plist + dd-plist + + + org.apache.felix + org.apache.felix.scr + + + com.google.code.gson + gson + + + + diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java new file mode 100644 index 0000000000..766698c9c7 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.MobileApp; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.MobileAppTypes; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util.AndroidApplicationOperationUtil; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util.IOSApplicationOperationUtil; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util.MDMAppConstants; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util.MDMServiceAPIUtils; +import org.wso2.carbon.appmgt.mobile.beans.ApplicationOperationAction; +import org.wso2.carbon.appmgt.mobile.beans.ApplicationOperationDevice; +import org.wso2.carbon.appmgt.mobile.interfaces.ApplicationOperations; +import org.wso2.carbon.appmgt.mobile.mdm.App; +import org.wso2.carbon.appmgt.mobile.mdm.Device; +import org.wso2.carbon.appmgt.mobile.utils.MobileApplicationException; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.Platform; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +public class ApplicationOperationsImpl implements ApplicationOperations { + + private static final Log log = LogFactory.getLog(ApplicationOperationsImpl.class); + + /** + * @param applicationOperationAction holds the information needs to perform an action on mdm. + * @throws MobileApplicationException + */ + public String performAction(ApplicationOperationAction applicationOperationAction) + throws MobileApplicationException { + if (log.isDebugEnabled()) { + log.debug(applicationOperationAction.getAction() + " action is triggered for " + + applicationOperationAction.getType() +"."); + } + + Operation operation = null; + List deviceIdentifiers = new ArrayList<>(); + List deviceList; + if (MDMAppConstants.USER.equals(applicationOperationAction.getType())) { + String userName = null; + try { + for (String param : applicationOperationAction.getParams()) { + userName = param; + + deviceList = MDMServiceAPIUtils + .getDeviceManagementService(applicationOperationAction.getTenantId()). + getDevicesOfUser(userName); + + for (org.wso2.carbon.device.mgt.common.Device device : deviceList) { + if(applicationOperationAction.getApp().getPlatform().equalsIgnoreCase(device.getType())){ + deviceIdentifiers.add(getDeviceIdentifierByDevice(device)); + } + } + } + } catch (DeviceManagementException devEx) { + String errorMsg = "Error occurred fetch device for user " + userName + + " at app installation"; + logError(errorMsg, devEx); + throw new MobileApplicationException(errorMsg, devEx); + } + } else if (MDMAppConstants.ROLE.equals(applicationOperationAction.getType())) { + String userRole = null; + try { + for (String param : applicationOperationAction.getParams()) { + userRole = param; + + deviceList = MDMServiceAPIUtils + .getDeviceManagementService(applicationOperationAction.getTenantId()). + getAllDevicesOfRole(userRole); + + for (org.wso2.carbon.device.mgt.common.Device device : deviceList) { + deviceIdentifiers.add(getDeviceIdentifierByDevice(device)); + } + } + } catch (DeviceManagementException devMgtEx) { + String errorMsg = "Error occurred fetch device for user role " + userRole + + " at app installation"; + logError(errorMsg, devMgtEx); + throw new MobileApplicationException(errorMsg, devMgtEx); + } + + } else if (MDMAppConstants.DEVICE.equals(applicationOperationAction.getType())) { + DeviceIdentifier deviceIdentifier; + for (String param : applicationOperationAction.getParams()) { + deviceIdentifier = new DeviceIdentifier(); + if (isValidJSON(param)) { + JSONParser parser = new JSONParser(); + try { + JSONObject parsedObj = (JSONObject) parser.parse(param); + deviceIdentifier.setId((String) parsedObj.get(MDMAppConstants.ID)); + deviceIdentifier.setType((String) parsedObj.get(MDMAppConstants.TYPE)); + deviceIdentifiers.add(deviceIdentifier); + } catch (ParseException e) { + logError("Device Identifier is not valid json object.", e); + throw new MobileApplicationException(e); + } + + } + } + } else { + throw new IllegalStateException("invalid type is received from app store."); + } + App app = applicationOperationAction.getApp(); + MobileApp mobileApp = new MobileApp(); + mobileApp.setId(app.getId()); + mobileApp.setType(MobileAppTypes.valueOf(app.getType().toUpperCase())); + mobileApp.setAppIdentifier(app.getAppIdentifier()); + mobileApp.setIconImage(app.getIconImage()); + mobileApp.setIdentifier(app.getIdentifier()); + mobileApp.setLocation(app.getLocation()); + mobileApp.setName(app.getName()); + mobileApp.setPackageName(app.getPackageName()); + mobileApp.setPlatform(app.getPlatform()); + mobileApp.setVersion(app.getVersion()); + Properties properties = new Properties(); + + if (MDMAppConstants.IOS.equals(app.getPlatform())) { + if (MDMAppConstants.ENTERPRISE.equals(app.getType())) { + properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); + properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); + } else if (MDMAppConstants.IOSConstants.PUBLIC.equals(app.getType())) { + properties.put(MDMAppConstants.IOSConstants.I_TUNES_ID, app.getIdentifier()); + properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); + properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); + } else if (MDMAppConstants.WEBAPP.equals(app.getType())) { + properties.put(MDMAppConstants.IOSConstants.LABEL, app.getName()); + properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); + } + } else if (MDMAppConstants.WEBAPP.equals(app.getPlatform())) { + properties.put(MDMAppConstants.IOSConstants.LABEL, app.getName()); + properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); + } + mobileApp.setProperties(properties); + Activity activity = null; + try { + if (deviceIdentifiers.size() > 0) { + if (deviceIdentifiers.get(0).getType().equalsIgnoreCase(Platform.ANDROID.toString())) { + if (MDMAppConstants.INSTALL.equals(applicationOperationAction.getAction())) { + operation = AndroidApplicationOperationUtil + .createInstallAppOperation(mobileApp, applicationOperationAction.getSchedule()); + } else if (MDMAppConstants.UPDATE.equals(applicationOperationAction.getAction())) { + operation = AndroidApplicationOperationUtil + .createUpdateAppOperation(mobileApp, applicationOperationAction.getSchedule()); + } else { + operation = AndroidApplicationOperationUtil + .createAppUninstallOperation(mobileApp, applicationOperationAction.getSchedule()); + } + } else if (deviceIdentifiers.get(0).getType().equalsIgnoreCase(Platform.IOS.toString())) { + if (MDMAppConstants.INSTALL.equals(applicationOperationAction.getAction())) { + operation = + IOSApplicationOperationUtil.createInstallAppOperation(mobileApp); + } else { + operation = + IOSApplicationOperationUtil.createAppUninstallOperation(mobileApp); + } + } + activity = MDMServiceAPIUtils.getAppManagementService(applicationOperationAction.getTenantId()) + .installApplicationForDevices(operation, deviceIdentifiers); + + + } + + if(activity != null){ + return activity.getActivityId(); + } + + return null; + + } catch (DeviceApplicationException mdmExce) { + logError("Error in creating operation object using app.", mdmExce); + throw new MobileApplicationException(mdmExce.getMessage()); + } catch (ApplicationManagementException appMgtExce) { + logError("Error in app installation.", appMgtExce); + throw new MobileApplicationException(appMgtExce.getErrorMessage()); + } + + } + + /** + * Create a new device identifier from Device object. + * @param device device which is to be retrieved type and id + * @return created device identifier + */ + private static DeviceIdentifier getDeviceIdentifierByDevice( + org.wso2.carbon.device.mgt.common.Device device) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(device.getDeviceIdentifier()); + deviceIdentifier.setType(device.getType()); + + return deviceIdentifier; + } + + /** + * @param applicationOperationDevice holds the information needs to retrieve device list. + * @return List of devices + * @throws MobileApplicationException + */ + public List getDevices(ApplicationOperationDevice applicationOperationDevice) + throws MobileApplicationException { + + List devices; + try { + List deviceList = MDMServiceAPIUtils + .getDeviceManagementService(applicationOperationDevice.getTenantId()). + getDevicesOfUser( + applicationOperationDevice.getCurrentUser().getUsername()); + devices = new ArrayList<>(deviceList.size()); + if(log.isDebugEnabled()){ + log.debug("device list got from mdm "+ deviceList.toString()); + } + for (org.wso2.carbon.device.mgt.common.Device commonDevice : deviceList) { + if (MDMAppConstants.ACTIVE + .equals(commonDevice.getEnrolmentInfo().getStatus().toString(). + toLowerCase())) { + Device device = new Device(); + org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier deviceIdentifier = + new org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier(); + deviceIdentifier.setId(commonDevice.getDeviceIdentifier()); + deviceIdentifier.setType(commonDevice.getType()); + device.setDeviceIdentifier(deviceIdentifier); + device.setName(commonDevice.getName()); + device.setModel(commonDevice.getName()); + device.setType(MDMAppConstants.MOBILE_DEVICE); + String imgUrl; + if (MDMAppConstants.ANDROID.equalsIgnoreCase(commonDevice.getType())) { + imgUrl = String.format(applicationOperationDevice.getConfigParams() + .get(MDMAppConstants.IMAGE_URL), + MDMAppConstants.NEXUS); + } else if (MDMAppConstants.IOS.equalsIgnoreCase(commonDevice.getType())) { + imgUrl = String.format(applicationOperationDevice.getConfigParams() + .get(MDMAppConstants.IMAGE_URL), + MDMAppConstants.IPHONE); + } else { + imgUrl = String.format(applicationOperationDevice.getConfigParams() + .get(MDMAppConstants.IMAGE_URL), + MDMAppConstants.NONE); + } + device.setImage(imgUrl); + device.setPlatform(commonDevice.getType()); + devices.add(device); + } + } + } catch (DeviceManagementException e) { + logError("Error While retrieving Device List.", e); + throw new MobileApplicationException(e.getMessage()); + + } + return devices; + } + + private boolean isValidJSON(String json) { + JSONParser parser = new JSONParser(); + try { + parser.parse(json); + } catch (ParseException e) { + return false; + } + return true; + } + + private void logError(String errorMessage, Throwable e) { + if (log.isDebugEnabled()) { + log.error(errorMessage, e); + } else { + log.error(errorMessage); + } + } + +} + diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/internal/DeviceApplicationServiceComponent.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/internal/DeviceApplicationServiceComponent.java new file mode 100644 index 0000000000..085f3a6501 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/internal/DeviceApplicationServiceComponent.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.appmgt.mdm.osgiconnector.ApplicationOperationsImpl; +import org.wso2.carbon.appmgt.mobile.interfaces.ApplicationOperations; + +/** + * @scr.component name="org.wso2.carbon.appmgt.mdm.osgiconnector" immediate="true" + */ + +public class DeviceApplicationServiceComponent { + + private static final Log log = LogFactory.getLog(DeviceApplicationServiceComponent.class); + + private ServiceRegistration mdmServiceRegistration; + + protected void activate(ComponentContext context) { + BundleContext bundleContext = context.getBundleContext(); + mdmServiceRegistration = bundleContext + .registerService(ApplicationOperations.class.getName(), new ApplicationOperationsImpl(), null); + if (log.isDebugEnabled()) { + log.debug("Device Application Service Component activated."); + } + + } + + protected void deactivate(ComponentContext context) { + if (mdmServiceRegistration != null) { + mdmServiceRegistration.unregister(); + mdmServiceRegistration = null; + } + if (log.isDebugEnabled()) { + log.debug("Device Application Service Component deactivated."); + } + + } + +} + + diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileApp.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileApp.java new file mode 100644 index 0000000000..2933669a45 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileApp.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.beans; + +import java.util.Properties; + +/** + * This class represents the generic mobile Application information + * which is used by AppM. + */ +public class MobileApp { + + private String id; + private String name; + private MobileAppTypes type; + private String platform; + private String version; + private String identifier; + private String iconImage; + private String packageName; + private String appIdentifier; + private String location; + private Properties properties; + + public MobileAppTypes getType() { + return type; + } + + public void setType(MobileAppTypes type) { + this.type = type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public String getIconImage() { + return iconImage; + } + + public void setIconImage(String iconImage) { + this.iconImage = iconImage; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileAppTypes.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileAppTypes.java new file mode 100644 index 0000000000..9b1b306c03 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileAppTypes.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.beans; + +public enum MobileAppTypes { + ENTERPRISE, WEBAPP, PUBLIC + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AndroidApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AndroidApplication.java new file mode 100644 index 0000000000..d638d7b111 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AndroidApplication.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +public class AndroidApplication { + private String type; + private String appIdentifier; + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String toJSON() throws DeviceApplicationException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AppStoreApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AppStoreApplication.java new file mode 100644 index 0000000000..6f78eb2443 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AppStoreApplication.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +import java.io.Serializable; + +/** + * This class represents the Appstore Application information. + */ +public class AppStoreApplication extends AndroidApplication implements Serializable { + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/EnterpriseApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/EnterpriseApplication.java new file mode 100644 index 0000000000..f8990e5856 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/EnterpriseApplication.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +import java.io.Serializable; + +/** + * This class represents the Enterprise Application information. + */ +public class EnterpriseApplication extends AndroidApplication implements Serializable { + + private String url; + private String schedule; + private String packageName; + + public String getSchedule() { + return schedule; + } + + public void setSchedule(String schedule) { + this.schedule = schedule; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/WebApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/WebApplication.java new file mode 100644 index 0000000000..08a35e08e7 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/WebApplication.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +import java.io.Serializable; + +/** + * This class represents the Web Application information. + */ +public class WebApplication implements Serializable { + + private String name; + private String url; + private String type; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String toJSON() throws DeviceApplicationException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/AppStoreApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/AppStoreApplication.java new file mode 100644 index 0000000000..b8e6a4e09f --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/AppStoreApplication.java @@ -0,0 +1,34 @@ +/* + * 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.appmgt.mdm.osgiconnector.mdmmgt.beans.ios; + +import java.io.Serializable; + +public class AppStoreApplication extends IOSApplication implements Serializable { + + private int iTunesStoreID; + + public int getiTunesStoreID() { + return iTunesStoreID; + } + + public void setiTunesStoreID(int iTunesStoreID) { + this.iTunesStoreID = iTunesStoreID; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/EnterpriseApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/EnterpriseApplication.java new file mode 100644 index 0000000000..3a09b73252 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/EnterpriseApplication.java @@ -0,0 +1,35 @@ +/* + * 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.appmgt.mdm.osgiconnector.mdmmgt.beans.ios; + +import java.io.Serializable; + +public class EnterpriseApplication extends IOSApplication implements Serializable { + + private String manifestURL; + + public String getManifestURL() { + return manifestURL; + } + + public void setManifestURL(String manifestURL) { + this.manifestURL = manifestURL; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/IOSApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/IOSApplication.java new file mode 100644 index 0000000000..12a8db23ab --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/IOSApplication.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.beans.ios; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +public class IOSApplication { + + private String identifier; + private boolean removeAppUponMDMProfileRemoval; + private boolean preventBackupOfAppData; + private String bundleId; + private String UUID; + + public String getUUID() { + return UUID; + } + + public void setUUID(String UUID) { + this.UUID = UUID; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public boolean isRemoveAppUponMDMProfileRemoval() { + return removeAppUponMDMProfileRemoval; + } + + public void setRemoveAppUponMDMProfileRemoval(boolean removeAppUponMDMProfileRemoval) { + this.removeAppUponMDMProfileRemoval = removeAppUponMDMProfileRemoval; + } + + public boolean isPreventBackupOfAppData() { + return preventBackupOfAppData; + } + + public void setPreventBackupOfAppData(boolean preventBackupOfAppData) { + this.preventBackupOfAppData = preventBackupOfAppData; + } + + public String getBundleId() { + return bundleId; + } + + public void setBundleId(String bundleId) { + this.bundleId = bundleId; + } + + public String toJSON() throws DeviceApplicationException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/RemoveApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/RemoveApplication.java new file mode 100644 index 0000000000..22c7963def --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/RemoveApplication.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.beans.ios; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +import java.io.Serializable; + +public class RemoveApplication implements Serializable { + + private String bundleId; + + public String getBundleId() { + return bundleId; + } + + public void setBundleId(String bundleId) { + this.bundleId = bundleId; + } + + public String toJSON() throws DeviceApplicationException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/WebClip.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/WebClip.java new file mode 100644 index 0000000000..000374c433 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/WebClip.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.beans.ios; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +public class WebClip { + + private String URL; + private String label; + private String icon; + private String isRemovable; + private String UUID; + + public String getUUID() { + return UUID; + } + + public void setUUID(String UUID) { + this.UUID = UUID; + } + + public String getURL() { + return URL; + } + + public void setURL(String URL) { + this.URL = URL; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getIsRemovable() { + return isRemovable; + } + + public void setIsRemovable(String isRemovable) { + this.isRemovable = isRemovable; + } + + public String toJSON() throws DeviceApplicationException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/common/DeviceApplicationException.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/common/DeviceApplicationException.java new file mode 100644 index 0000000000..84818e4a08 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/common/DeviceApplicationException.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.common; + +public class DeviceApplicationException extends Exception { + + private static final long serialVersionUID = 5136875495185597926L; + private String errorMessage; + + public DeviceApplicationException(String msg, Exception e) { + super(msg, e); + setErrorMessage(msg); + } + + public DeviceApplicationException(String msg, Throwable cause) { + super(msg, cause); + setErrorMessage(msg); + } + + public DeviceApplicationException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public DeviceApplicationException() { + super(); + } + + public DeviceApplicationException(Throwable cause) { + super(cause); + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/AndroidApplicationOperationUtil.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/AndroidApplicationOperationUtil.java new file mode 100644 index 0000000000..7c1288b1ac --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/AndroidApplicationOperationUtil.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.util; + +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.MobileApp; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.android.AppStoreApplication; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.android.EnterpriseApplication; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.android.WebApplication; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; + +/** + * This class contains the all the operations related to Android. + */ +public class AndroidApplicationOperationUtil { + + /** + * Create Install Application operation. + * + * @param application MobileApp application + * @return operation + * @throws DeviceApplicationException + */ + public static Operation createInstallAppOperation(MobileApp application, String schedule) throws + DeviceApplicationException { + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + switch (application.getType()) { + case ENTERPRISE: + EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); + enterpriseApplication.setType(application.getType().toString()); + enterpriseApplication.setUrl(application.getLocation()); + enterpriseApplication.setSchedule(schedule); + enterpriseApplication.setPackageName(application.getPackageName()); + operation.setPayLoad(enterpriseApplication.toJSON()); + break; + case PUBLIC: + setOperationForPublicApp(operation, application); + break; + case WEBAPP: + setOperationForWebApp(operation, application); + break; + default: + String errorMessage = "Invalid application type."; + throw new DeviceApplicationException(errorMessage); + } + return operation; + } + + /** + * Create Update Application operation. + * + * @param application MobileApp application + * @return operation + * @throws DeviceApplicationException + */ + public static Operation createUpdateAppOperation(MobileApp application, String schedule) throws + DeviceApplicationException { + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UPDATE_APPLICATION); + operation.setType(Operation.Type.PROFILE); + switch (application.getType()) { + case ENTERPRISE: + EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); + enterpriseApplication.setType(application.getType().toString()); + enterpriseApplication.setUrl(application.getLocation()); + enterpriseApplication.setSchedule(schedule); + operation.setPayLoad(enterpriseApplication.toJSON()); + break; + case PUBLIC: + setOperationForPublicApp(operation, application); + break; + case WEBAPP: + setOperationForWebApp(operation, application); + break; + default: + String errorMessage = "Invalid application type."; + throw new DeviceApplicationException(errorMessage); + } + return operation; + } + + /** + * Create Uninstall Application operation. + * + * @param application MobileApp application + * @return operation + * @throws DeviceApplicationException + */ + public static Operation createAppUninstallOperation(MobileApp application, String schedule) throws + DeviceApplicationException { + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + + switch (application.getType()) { + case ENTERPRISE: + EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); + enterpriseApplication.setType(application.getType().toString()); + enterpriseApplication.setAppIdentifier(application.getIdentifier()); + enterpriseApplication.setSchedule(schedule); + operation.setPayLoad(enterpriseApplication.toJSON()); + break; + case PUBLIC: + setOperationForPublicApp(operation, application); + break; + case WEBAPP: + setOperationForWebApp(operation, application); + break; + default: + String errorMessage = "Invalid application type."; + throw new DeviceApplicationException(errorMessage); + } + return operation; + } + + private static void setOperationForPublicApp(Operation operation, MobileApp application) + throws DeviceApplicationException { + AppStoreApplication appStoreApplication = new AppStoreApplication(); + appStoreApplication.setType(application.getType().toString()); + appStoreApplication.setAppIdentifier(application.getIdentifier()); + operation.setPayLoad(appStoreApplication.toJSON()); + } + + private static void setOperationForWebApp(Operation operation, MobileApp application) + throws DeviceApplicationException { + WebApplication webApplication = new WebApplication(); + webApplication.setUrl(application.getLocation()); + webApplication.setName(application.getName()); + webApplication.setType(application.getType().toString()); + operation.setPayLoad(webApplication.toJSON()); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/IOSApplicationOperationUtil.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/IOSApplicationOperationUtil.java new file mode 100644 index 0000000000..3167ed8d3c --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/IOSApplicationOperationUtil.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.util; + +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.MobileApp; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios.AppStoreApplication; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios.WebClip; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios.EnterpriseApplication; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios.RemoveApplication; + +import java.util.Properties; + +/** + * This class contains the all the operations related to IOS. + */ +public class IOSApplicationOperationUtil { + + /** + * Create Install Application operation. + * + * @param application MobileApp application + * @return operation + * @throws DeviceApplicationException + */ + public static Operation createInstallAppOperation(MobileApp application) throws + DeviceApplicationException { + + ProfileOperation operation = new ProfileOperation(); + switch (application.getType()) { + case ENTERPRISE: + EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); + enterpriseApplication.setBundleId(application.getId()); + enterpriseApplication.setIdentifier(application.getIdentifier()); + enterpriseApplication.setManifestURL(application.getLocation()); + + Properties properties = application.getProperties(); + enterpriseApplication.setPreventBackupOfAppData( + (Boolean) properties.get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP)); + enterpriseApplication.setRemoveAppUponMDMProfileRemoval( + (Boolean) properties.get(MDMAppConstants.IOSConstants.IS_REMOVE_APP)); + operation.setCode( + MDMAppConstants.IOSConstants.OPCODE_INSTALL_ENTERPRISE_APPLICATION); + operation.setPayLoad(enterpriseApplication.toJSON()); + operation.setType(Operation.Type.COMMAND); + break; + case PUBLIC: + AppStoreApplication appStoreApplication = new AppStoreApplication(); + appStoreApplication.setRemoveAppUponMDMProfileRemoval( + (Boolean) application.getProperties() + .get(MDMAppConstants.IOSConstants.IS_REMOVE_APP)); + appStoreApplication.setIdentifier(application.getIdentifier()); + appStoreApplication.setPreventBackupOfAppData((Boolean) application.getProperties(). + get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP)); + appStoreApplication.setBundleId(application.getId()); + appStoreApplication.setiTunesStoreID((Integer) application.getProperties(). + get(MDMAppConstants.IOSConstants.I_TUNES_ID)); + operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_STORE_APPLICATION); + operation.setType(Operation.Type.COMMAND); + operation.setPayLoad(appStoreApplication.toJSON()); + break; + case WEBAPP: + WebClip webClip = new WebClip(); + webClip.setIcon(application.getIconImage()); + webClip.setIsRemovable(application.getProperties(). + getProperty(MDMAppConstants.IOSConstants.IS_REMOVE_APP)); + webClip.setLabel(application.getProperties(). + getProperty(MDMAppConstants.IOSConstants.LABEL)); + webClip.setURL(application.getLocation()); + operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_WEB_APPLICATION); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(webClip.toJSON()); + break; + default: + String errorMessage = "Invalid application type."; + throw new DeviceApplicationException(errorMessage); + } + return operation; + } + + /** + * Create uninstall operations. + * + * @param application + * @return Uninstall operation + * @throws DeviceApplicationException + */ + public static Operation createAppUninstallOperation(MobileApp application) throws + DeviceApplicationException { + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.IOSConstants.OPCODE_REMOVE_APPLICATION); + operation.setType(Operation.Type.PROFILE); + RemoveApplication removeApplication = new RemoveApplication(); + removeApplication.setBundleId(application.getIdentifier()); + operation.setPayLoad(removeApplication.toJSON()); + return operation; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMAppConstants.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMAppConstants.java new file mode 100644 index 0000000000..5903b64843 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMAppConstants.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.util; + +/** + * This class holds all the constants used for IOS and Android. + */ +public class MDMAppConstants { + + public static final String USER = "user"; + public static final String ROLE = "role"; + public static final String IOS = "ios"; + public static final String ANDROID = "android"; + public static final String WEBAPP = "webapp"; + public static final String INSTALL = "install"; + public static final String UPDATE = "update"; + public static final String ACTIVE = "active"; + public static final String ENTERPRISE = "enterprise"; + public static final String DEVICE = "device"; + public static final String MOBILE_DEVICE = "mobileDevice"; + public static final String NEXUS = "nexus"; + public static final String IPHONE = "iphone"; + public static final String NONE = "none"; + public static final String IMAGE_URL = "ImageURL"; + public static final String TYPE = "type"; + public static final String ID = "id"; + + public class IOSConstants { + + private IOSConstants() { + throw new AssertionError(); + } + + public static final String IS_REMOVE_APP = "isRemoveApp"; + public static final String IS_PREVENT_BACKUP = "isPreventBackup"; + public static final String I_TUNES_ID = "iTunesId"; + public static final String LABEL = "label"; + public static final String PUBLIC = "public"; + public static final String OPCODE_INSTALL_ENTERPRISE_APPLICATION = + "INSTALL_ENTERPRISE_APPLICATION"; + public static final String OPCODE_INSTALL_STORE_APPLICATION = "INSTALL_STORE_APPLICATION"; + public static final String OPCODE_INSTALL_WEB_APPLICATION = "WEB_CLIP"; + public static final String OPCODE_REMOVE_APPLICATION = "REMOVE_APPLICATION"; + } + + public class AndroidConstants { + private AndroidConstants() { + throw new AssertionError(); + } + + public static final String OPCODE_INSTALL_APPLICATION = "INSTALL_APPLICATION"; + public static final String OPCODE_UPDATE_APPLICATION = "UPDATE_APPLICATION"; + public static final String OPCODE_UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION"; + } + + public class RegistryConstants { + private RegistryConstants() { + throw new AssertionError(); + } + + public static final String GENERAL_CONFIG_RESOURCE_PATH = "general"; + } + + public class APPManagerConstants { + private static final String APP_MANAGER_MDM_SERVICE_NAME = + "org.wso2.carbon.appmgt.mobile.interfaces.MDMOperations"; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMServiceAPIUtils.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMServiceAPIUtils.java new file mode 100644 index 0000000000..922f017326 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMServiceAPIUtils.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.appmgt.mdm.osgiconnector.mdmmgt.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; + +/** + * MDMServiceAPIUtils class provides utility function. + */ +public class MDMServiceAPIUtils { + + private static Log log = LogFactory.getLog(MDMServiceAPIUtils.class); + + /** + * Returns the DeviceManagementProviderService osgi service. + * + * @param tenantId tenant id + * @return DeviceManagementProviderService + */ + public static DeviceManagementProviderService getDeviceManagementService(int tenantId) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantId(tenantId, true); + DeviceManagementProviderService deviceManagementProviderService = + (DeviceManagementProviderService) ctx + .getOSGiService(DeviceManagementProviderService.class, null); + if (deviceManagementProviderService == null) { + String msg = "Device Management provider service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return deviceManagementProviderService; + } + + /** + * Returns the ApplicationManagementProviderService osgi service. + * + * @param tenantId tenant id + * @return ApplicationManagementProviderService + */ + public static ApplicationManagementProviderService getAppManagementService(int tenantId) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantId(tenantId, true); + ApplicationManagementProviderService applicationManagementProviderService = + (ApplicationManagementProviderService) ctx. + getOSGiService( + ApplicationManagementProviderService.class, + null); + if (applicationManagementProviderService == null) { + String msg = "Application management service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return applicationManagementProviderService; + } + +} diff --git a/components/extensions/pom.xml b/components/extensions/pom.xml new file mode 100644 index 0000000000..3b49a46c28 --- /dev/null +++ b/components/extensions/pom.xml @@ -0,0 +1,58 @@ + + + + + + + org.wso2.carbon.devicemgt-plugins + carbon-device-mgt-plugins-parent + 2.2.3-SNAPSHOT + ../../pom.xml + + + 4.0.0 + extensions + pom + WSO2 Carbon - Mobile Plugins Extensions + http://wso2.org + + + org.wso2.carbon.appmgt.mdm.osgiconnector + + + + + + + org.apache.felix + maven-scr-plugin + 1.7.2 + + + generate-scr-scrdescriptor + + scr + + + + + + + + diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml index 65ec96153c..7ad40f2e74 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml @@ -21,7 +21,7 @@ androidsense-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml index 7f947a267c..7d0f0930e0 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml @@ -3,7 +3,7 @@ androidsense-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/pom.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/pom.xml index 128a2d56c2..0e6ae941d2 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/pom.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/pom.xml @@ -14,7 +14,7 @@ androidsense-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java index 830f375707..e8851df8a1 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java @@ -92,8 +92,13 @@ public class AndroidSenseUtils { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(datasource); DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); - log.info("Initializing device management repository database schema"); - initializer.createRegistryDatabase(); + String checkSql = "select * from ANDROID_SENSE_DEVICE"; + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing device management repository database schema"); + initializer.createRegistryDatabase(); + } else { + log.info("Device management repository database already exists. Not creating a new database."); + } } catch (NamingException e) { log.error("Error while looking up the data source: " + datasource, e); diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml index 81fed2632d..b82da289a0 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml @@ -22,7 +22,7 @@ androidsense-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/analytics-view.js b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/analytics-view.js index 144acffcc4..feb70be8bc 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/analytics-view.js +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/analytics-view.js @@ -24,15 +24,15 @@ function onRequest(context) { if (devices) { return { "devices": stringify(devices), - "backendApiUri": devicemgtProps["httpsURL"] + "/android_sense/stats/" + "backendApiUri": "/android_sense/stats/" }; } else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var device = deviceModule.viewDevice(deviceType, deviceId); if (device && device.status != "error") { return { - "device": device, - "backendApiUrl": devicemgtProps["httpsURL"] + "/android_sense/stats/" + deviceId + "/sensors/" + "device": device.content, + "backendApiUrl": "/android_sense/stats/" + deviceId + "/sensors/" }; } else { response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js index 4df1abcff1..fd445273c7 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js @@ -29,7 +29,7 @@ function onRequest(context) { var device = deviceModule.viewDevice(deviceType, deviceId); if (device && device.status != "error") { return { - "device": device, + "device": device.content, "backendApiUri": devicemgtProps["httpsURL"] + "/android_sense/", "autoCompleteParams": autoCompleteParams }; diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.platform.configuration/public/js/platform-configuration.js b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.platform.configuration/public/js/platform-configuration.js index fba0c0d831..950b6c5008 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.platform.configuration/public/js/platform-configuration.js +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.platform.configuration/public/js/platform-configuration.js @@ -18,7 +18,7 @@ $(document).ready(function () { invokerUtil.get( - "/devicemgt_admin/configuration", + "/api/device-mgt/android_sense/v1.0/configuration", function (data) { data = JSON.parse(data); if (data && data.configuration) { @@ -52,7 +52,7 @@ var addConfiguration = function () { var errorMsgWrapper = "#android_sense-config-error-msg"; var errorMsg = "#android_sense-config-error-msg span"; var addConfigFormData = {}; - var configList = new Array(); + var configList = []; var mqttEp = $("input#mqtt-endpoint").val(); var mqttConfig = { "name": "ANDROID_SENSE_MQTT_EP", @@ -61,10 +61,10 @@ var addConfiguration = function () { }; configList.push(mqttConfig); - addConfigFormData.type = "android_sense" + addConfigFormData.type = "android_sense"; addConfigFormData.configuration = configList; - var addConfigAPI = "/devicemgt_admin/configuration"; + var addConfigAPI = "/api/device-mgt/android_sense/v1.0/configuration"; invokerUtil.post( addConfigAPI, addConfigFormData, diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/js/download.js b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/js/download.js index 250d07109b..831e47df2c 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/js/download.js +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/js/download.js @@ -16,9 +16,9 @@ * under the License. */ -var modalPopup = ".wr-modalpopup"; -var modalPopupContainer = modalPopup + " .modalpopup-container"; -var modalPopupContent = modalPopup + " .modalpopup-content"; +var modalPopup = ".modal"; +var modalPopupContainer = modalPopup + " .modal-content"; +var modalPopupContent = modalPopup + " .modal-content"; var body = "body"; /* @@ -33,7 +33,7 @@ function setPopupMaxHeight() { * show popup function. */ function showPopup() { - $(modalPopup).show(); + $(modalPopup).modal('show'); setPopupMaxHeight(); $('#downloadForm').validate({ rules: { @@ -65,7 +65,7 @@ function hidePopup() { $('label[for=deviceName]').remove(); $('.control-group').removeClass('success').removeClass('error'); $(modalPopupContent).html(''); - $(modalPopup).hide(); + $(modalPopup).modal('hide'); } /* diff --git a/components/iot-plugins/androidsense-plugin/pom.xml b/components/iot-plugins/androidsense-plugin/pom.xml index 7717fd9abd..124096df5a 100644 --- a/components/iot-plugins/androidsense-plugin/pom.xml +++ b/components/iot-plugins/androidsense-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml index 525cb8a84c..e3ae696d24 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml @@ -21,7 +21,7 @@ arduino-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml index eb46d078c5..3a3618bc78 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml @@ -21,7 +21,7 @@ arduino-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/pom.xml index ac9022f375..6697a93a59 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/pom.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/pom.xml @@ -22,7 +22,7 @@ arduino-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java index 91a17cf213..f4207d72e0 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java @@ -105,8 +105,13 @@ public class ArduinoUtils { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(datasource); DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); - log.info("Initializing device management repository database schema"); - initializer.createRegistryDatabase(); + String checkSql = "select * from ARDUINO_DEVICE"; + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing device management repository database schema"); + initializer.createRegistryDatabase(); + } else { + log.info("Device management repository database already exists. Not creating a new database."); + } } catch (NamingException e) { log.error("Error while looking up the data source: " + datasource, e); diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml index 0860bea8fe..0e93a5f8eb 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml @@ -23,7 +23,7 @@ arduino-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/analytics-view.js b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/analytics-view.js index ef49dbe960..448d2eeffb 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/analytics-view.js +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/analytics-view.js @@ -26,15 +26,15 @@ function onRequest(context) { if (devices) { return { "devices": stringify(devices), - "backendApiUri": devicemgtProps["httpsURL"] + "/arduino/device/stats/" + "backendApiUri": "/arduino/device/stats/" }; } else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var device = deviceModule.viewDevice(deviceType, deviceId); if (device && device.status != "error") { return { - "device": device, - "backendApiUri": devicemgtProps["httpsURL"] + "/arduino/device/stats/" + deviceId + "device": device.content, + "backendApiUri": "/arduino/device/stats/" + deviceId }; } else { response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.js b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.js index 3ec4bb34cd..513b9a55c1 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.js +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.js @@ -28,7 +28,7 @@ function onRequest(context) { var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var device = deviceModule.viewDevice(deviceType, deviceId); if (device && device.status != "error") { - return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/arduino/", "autoCompleteParams" : autoCompleteParams}; + return {"device": device.content, "backendApiUri" : devicemgtProps["httpsURL"] + "/arduino/", "autoCompleteParams" : autoCompleteParams}; } else { response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); exit(); diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.platform.configuration/public/js/platform-configuration.js b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.platform.configuration/public/js/platform-configuration.js index 202eefaa3c..b2f6a8fd58 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.platform.configuration/public/js/platform-configuration.js +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.platform.configuration/public/js/platform-configuration.js @@ -18,7 +18,7 @@ $(document).ready(function () { invokerUtil.get( - "/devicemgt_admin/configuration", + "/api/device-mgt/arduino/v1.0/configuration", function (data) { data = JSON.parse(data); if (data && data.configuration) { @@ -69,10 +69,10 @@ var addConfiguration = function () { configList.push(httpConfig); configList.push(httpsConfig); - addConfigFormData.type = "arduino" + addConfigFormData.type = "arduino"; addConfigFormData.configuration = configList; - var addConfigAPI = "/devicemgt_admin/configuration"; + var addConfigAPI = "/api/device-mgt/arduino/v1.0/configuration"; invokerUtil.post( addConfigAPI, addConfigFormData, diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/public/js/download.js b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/public/js/download.js index 0c22e50997..3b104cd53b 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/public/js/download.js +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/public/js/download.js @@ -16,9 +16,9 @@ * under the License. */ -var modalPopup = ".wr-modalpopup"; -var modalPopupContainer = modalPopup + " .modalpopup-container"; -var modalPopupContent = modalPopup + " .modalpopup-content"; +var modalPopup = ".modal"; +var modalPopupContainer = modalPopup + " .modal-content"; +var modalPopupContent = modalPopup + " .modal-content"; var body = "body"; /* @@ -33,7 +33,7 @@ function setPopupMaxHeight() { * show popup function. */ function showPopup() { - $(modalPopup).show(); + $(modalPopup).modal('show'); setPopupMaxHeight(); $('#downloadForm').validate({ rules: { @@ -65,7 +65,7 @@ function hidePopup() { $('label[for=deviceName]').remove(); $('.control-group').removeClass('success').removeClass('error'); $(modalPopupContent).html(''); - $(modalPopup).hide(); + $(modalPopup).modal('hide'); } /* diff --git a/components/iot-plugins/arduino-plugin/pom.xml b/components/iot-plugins/arduino-plugin/pom.xml index 5ce90ec6b7..dfd5fae93e 100644 --- a/components/iot-plugins/arduino-plugin/pom.xml +++ b/components/iot-plugins/arduino-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml index f4f18972c1..20ffb7c6bb 100644 --- a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt-plugins iot-analytics - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/iot-analytics/pom.xml b/components/iot-plugins/iot-analytics/pom.xml index 543f0b6855..87d6a690be 100644 --- a/components/iot-plugins/iot-analytics/pom.xml +++ b/components/iot-plugins/iot-analytics/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.extension/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.extension/pom.xml index 15c7faf1b1..c6f403d3cc 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.extension/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.extension/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.http/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.http/pom.xml index 37d4e2f0b4..48ae683219 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.http/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.http/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/pom.xml index b44d3effd1..8e686e4578 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/pom.xml index 48b716bdd7..2f6515abdc 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.mqtt/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.mqtt/pom.xml index 74c1ee4ae3..00cc95d9cd 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.mqtt/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.mqtt/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/pom.xml index 97a3aca545..185336ccab 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/pom.xml @@ -22,7 +22,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml index 1d0bc0a6f3..a16503429a 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml @@ -21,7 +21,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml @@ -75,6 +75,10 @@ org.wso2.carbon.identity org.wso2.carbon.identity.oauth.stub + + commons-pool.wso2 + commons-pool + diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.xmpp/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.xmpp/pom.xml index 30b001022a..43a001ff7c 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.xmpp/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.xmpp/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/pom.xml index 033d480987..eca0cb6ae2 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/pom.xml @@ -23,7 +23,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.edit/public/js/policy-edit.js b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.edit/public/js/policy-edit.js index d42dd0109a..edea5b06d4 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.edit/public/js/policy-edit.js +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.edit/public/js/policy-edit.js @@ -248,7 +248,7 @@ var updatePolicy = function (policy, state) { payload["roles"] = []; } - var serviceURL = "/devicemgt_admin/policies/" + getParameterByName("id"); + var serviceURL = "/api/device-mgt/v1.0/policies/" + getParameterByName("id"); invokerUtil.put( serviceURL, payload, @@ -257,7 +257,7 @@ var updatePolicy = function (policy, state) { if (state == "save"){ var policyList = []; policyList.push(getParameterByName("id")); - serviceURL = "/devicemgt_admin/policies/inactivate"; + serviceURL = "/api/device-mgt/v1.0/policies/inactivate"; invokerUtil.put( serviceURL, policyList, @@ -274,7 +274,7 @@ var updatePolicy = function (policy, state) { }else if(state == "publish"){ var policyList = []; policyList.push(getParameterByName("id")); - serviceURL = "/devicemgt_admin/policies/activate"; + serviceURL = "/api/device-mgt/v1.0/policies/activate"; invokerUtil.put( serviceURL, policyList, @@ -451,7 +451,7 @@ $(document).ready(function () { data: function (params) { var postData = {}; postData.actionMethod = "GET"; - postData.actionUrl = "/devicemgt_admin/users?q=ad"; + postData.actionUrl = "/api/device-mgt/v1.0/users?q=ad"; postData.actionPayload = JSON.stringify({ q: params.term, // search term page: params.page @@ -479,7 +479,7 @@ $(document).ready(function () { var policyPayloadObj; invokerUtil.get( - "/devicemgt_admin/policies/" + getParameterByName("id"), + "/api/device-mgt/v1.0/policies/" + getParameterByName("id"), // on success function (data) { data = JSON.parse(data); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.view/public/js/policy-view.js b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.view/public/js/policy-view.js index 67e2c7f8ac..ad5b87a5ee 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.view/public/js/policy-view.js +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.view/public/js/policy-view.js @@ -111,7 +111,7 @@ $(document).ready(function () { var policyPayloadObj; invokerUtil.get( - "/devicemgt_admin/policies/" + getParameterByName("id"), + "/api/device-mgt/v1.0/policies/" + getParameterByName("id"), // on success function (data) { // console.log("success: " + JSON.stringify(data)); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/public/js/policy-create.js b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/public/js/policy-create.js index 4c838a1c48..45e73a71ef 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/public/js/policy-create.js +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/public/js/policy-create.js @@ -241,9 +241,9 @@ var savePolicy = function (policy, state) { var serviceURL; if (state == "save") { - serviceURL = "/devicemgt_admin/policies/inactive-policy" + serviceURL = "/api/device-mgt/v1.0/policies/inactive-policy" } else if (state == "publish") { - serviceURL = "/devicemgt_admin/policies/active-policy" + serviceURL = "/api/device-mgt/v1.0/policies/active-policy" } invokerUtil.post( serviceURL, @@ -414,7 +414,7 @@ $(document).ready(function () { data: function (params) { var postData = {}; postData.actionMethod = "GET"; - postData.actionUrl = "/devicemgt_admin/users"; + postData.actionUrl = "/api/device-mgt/v1.0/users"; postData.actionPayload = JSON.stringify({ q: params.term, // search term page: params.page @@ -442,7 +442,7 @@ $(document).ready(function () { templateSelection: formatRepoSelection // omitted for brevity, see the source of this page }); - $("#groups-input").select2({ + $("#groups-input").select2({ multiple: true, tags: true, ajax: { @@ -457,7 +457,7 @@ $(document).ready(function () { var postData = {}; postData.actionMethod = "GET"; var username = $("#platform").data("username"); - postData.actionUrl = "/devicemgt_admin/groups/user/" + username + + postData.actionUrl = "/api/device-mgt/v1.0/groups/user/" + username + "/search?groupName=" + params.term; return JSON.stringify(postData); }, diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/pom.xml index cd604ac20f..270a5835fc 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/pom.xml @@ -23,7 +23,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml @@ -72,7 +72,7 @@ org.wso2.carbon.utils, javax.xml.bind, javax.xml.bind.annotation, - javax.xml.parsers, + javax.xml.parsers; version="${javax.xml.parsers.import.pkg.version}", org.w3c.dom diff --git a/components/iot-plugins/iot-base-plugin/pom.xml b/components/iot-plugins/iot-base-plugin/pom.xml index fda9d0340b..48797062f7 100644 --- a/components/iot-plugins/iot-base-plugin/pom.xml +++ b/components/iot-plugins/iot-base-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/pom.xml b/components/iot-plugins/pom.xml index 63c049947f..2cdf6e223b 100644 --- a/components/iot-plugins/pom.xml +++ b/components/iot-plugins/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins carbon-device-mgt-plugins-parent - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../../pom.xml diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/pom.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/pom.xml index f06f8a0b11..9775cb6c66 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/pom.xml +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/pom.xml @@ -21,7 +21,7 @@ raspberrypi-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/pom.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/pom.xml index 9da1f7225f..3bc1f3e86a 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/pom.xml +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/pom.xml @@ -21,7 +21,7 @@ raspberrypi-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/pom.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/pom.xml index 61851bdde0..9041e3396b 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/pom.xml +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/pom.xml @@ -23,7 +23,7 @@ raspberrypi-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/util/RaspberrypiUtils.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/util/RaspberrypiUtils.java index e2ce1f44a1..8bd1b6e2e9 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/util/RaspberrypiUtils.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/util/RaspberrypiUtils.java @@ -94,8 +94,13 @@ public class RaspberrypiUtils { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(datasource); DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); - log.info("Initializing device management repository database schema"); - initializer.createRegistryDatabase(); + String checkSql = "select * from RASPBERRYPI_DEVICE"; + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing device management repository database schema"); + initializer.createRegistryDatabase(); + } else { + log.info("Device management repository database already exists. Not creating a new database."); + } } catch (NamingException e) { log.error("Error while looking up the data source: " + datasource, e); } catch (Exception e) { diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/pom.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/pom.xml index 65224364ca..c652a43af8 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/pom.xml +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/pom.xml @@ -23,7 +23,7 @@ raspberrypi-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.analytics-view/analytics-view.js b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.analytics-view/analytics-view.js index f9b7d08014..8f28d69198 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.analytics-view/analytics-view.js +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.analytics-view/analytics-view.js @@ -26,15 +26,15 @@ function onRequest(context) { if (devices) { return { "devices": stringify(devices), - "backendApiUri": devicemgtProps["httpsURL"] + "/raspberrypi/device/stats/" + "backendApiUri": "/raspberrypi/device/stats/" }; } else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var device = deviceModule.viewDevice(deviceType, deviceId); if (device && device.status != "error") { return { - "device": device, - "backendApiUri": devicemgtProps["httpsURL"] + "/raspberrypi/device/stats/" + deviceId + "device": device.content, + "backendApiUri": "/raspberrypi/device/stats/" + deviceId }; } else { response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.device-view/device-view.js b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.device-view/device-view.js index 62305b58eb..051344e708 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.device-view/device-view.js +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.device-view/device-view.js @@ -28,7 +28,7 @@ function onRequest(context) { var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var device = deviceModule.viewDevice(deviceType, deviceId); if (device && device.status != "error") { - return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/raspberrypi/", "autoCompleteParams" : autoCompleteParams}; + return {"device": device.content, "backendApiUri" : devicemgtProps["httpsURL"] + "/raspberrypi/", "autoCompleteParams" : autoCompleteParams}; } else { response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); exit(); diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.platform.configuration/public/js/platform-configuration.js b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.platform.configuration/public/js/platform-configuration.js index ca2136dbba..c82bba71b3 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.platform.configuration/public/js/platform-configuration.js +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.platform.configuration/public/js/platform-configuration.js @@ -18,7 +18,7 @@ $(document).ready(function () { invokerUtil.get( - "/devicemgt_admin/configuration", + "/api/device-mgt/raspberrypi/v1.0/configuration", function (data) { data = JSON.parse(data); if (data && data.configuration) { @@ -79,10 +79,10 @@ var addConfiguration = function () { configList.push(httpConfig); configList.push(httpsConfig); configList.push(mqttConfig); - addConfigFormData.type = "raspberrypi" + addConfigFormData.type = "raspberrypi"; addConfigFormData.configuration = configList; - var addConfigAPI = "/devicemgt_admin/configuration"; + var addConfigAPI = "/api/device-mgt/raspberrypi/v1.0/configuration"; invokerUtil.post( addConfigAPI, addConfigFormData, diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/public/js/download.js b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/public/js/download.js index c8901643b3..f6b9f1e648 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/public/js/download.js +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/public/js/download.js @@ -16,9 +16,9 @@ * under the License. */ -var modalPopup = ".wr-modalpopup"; -var modalPopupContainer = modalPopup + " .modalpopup-container"; -var modalPopupContent = modalPopup + " .modalpopup-content"; +var modalPopup = ".modal"; +var modalPopupContainer = modalPopup + " .modal-content"; +var modalPopupContent = modalPopup + " .modal-content"; var body = "body"; /* @@ -33,7 +33,7 @@ function setPopupMaxHeight() { * show popup function. */ function showPopup() { - $(modalPopup).show(); + $(modalPopup).modal('show'); setPopupMaxHeight(); $('#downloadForm').validate({ rules: { @@ -65,7 +65,7 @@ function hidePopup() { $('label[for=deviceName]').remove(); $('.control-group').removeClass('success').removeClass('error'); $(modalPopupContent).html(''); - $(modalPopup).hide(); + $(modalPopup).modal('hide'); } /* diff --git a/components/iot-plugins/raspberrypi-plugin/pom.xml b/components/iot-plugins/raspberrypi-plugin/pom.xml index 945aa67ea6..1da19057c2 100644 --- a/components/iot-plugins/raspberrypi-plugin/pom.xml +++ b/components/iot-plugins/raspberrypi-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/pom.xml index ff51ce2e86..30dd47b53a 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/pom.xml @@ -23,7 +23,7 @@ virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml index caec718265..624bcb9b37 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml @@ -23,7 +23,7 @@ virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml index 645db78305..c5d8434bbc 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml @@ -21,7 +21,7 @@ virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/pom.xml index 386afd16ae..a0e37cdfd6 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/pom.xml @@ -23,7 +23,7 @@ virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java index 7377967350..66d5d7747c 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java @@ -99,8 +99,13 @@ public class VirtualFireAlarmUtils { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(datasourceName); DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); - log.info("Initializing device management repository database schema"); - initializer.createRegistryDatabase(); + String checkSql = "select * from VIRTUAL_FIREALARM_DEVICE"; + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing device management repository database schema"); + initializer.createRegistryDatabase(); + } else { + log.info("Device management repository database already exists. Not creating a new database."); + } } catch (NamingException e) { log.error("Error while looking up the data source: " + datasourceName, e); } catch (Exception e) { diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml index bb43a08664..760620d35d 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml @@ -21,7 +21,7 @@ virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml index 7900363175..8b7eba3756 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml @@ -23,7 +23,7 @@ virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/analytics-view.js b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/analytics-view.js index 2e8285abf8..1bc948efc7 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/analytics-view.js +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/analytics-view.js @@ -26,15 +26,15 @@ function onRequest(context) { if (devices) { return { "devices": stringify(devices), - "backendApiUri": devicemgtProps["httpsURL"] + "/virtual_firealarm/device/stats/" + "backendApiUri": "/virtual_firealarm/device/stats/" }; } else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var device = deviceModule.viewDevice(deviceType, deviceId); if (device && device.status != "error") { return { - "device": device, - "backendApiUri": devicemgtProps["httpsURL"] + "/virtual_firealarm/device/stats/" + deviceId + "device": device.content, + "backendApiUri": "/virtual_firealarm/device/stats/" + deviceId }; } else { response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js index 2e3ea2abf1..8bcdce4739 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js @@ -28,7 +28,7 @@ function onRequest(context) { var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var device = deviceModule.viewDevice(deviceType, deviceId); if (device && device.status != "error") { - return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/virtual_firealarm/", "autoCompleteParams" : autoCompleteParams}; + return {"device": device.content, "backendApiUri" : devicemgtProps["httpsURL"] + "/virtual_firealarm/", "autoCompleteParams" : autoCompleteParams}; } else { response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); exit(); diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.platform.configuration/public/js/platform-configuration.js b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.platform.configuration/public/js/platform-configuration.js index 57013c1a3e..19f1c9ff3e 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.platform.configuration/public/js/platform-configuration.js +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.platform.configuration/public/js/platform-configuration.js @@ -18,7 +18,7 @@ $(document).ready(function () { invokerUtil.get( - "/devicemgt_admin/configuration", + "/api/device-mgt/virtual_firealarm/v1.0/configuration", function (data) { data = JSON.parse(data); if (data && data.configuration) { @@ -69,10 +69,10 @@ var addConfiguration = function () { configList.push(httpConfig); configList.push(httpsConfig); configList.push(mqttConfig); - addConfigFormData.type = "virtual_firealarm" + addConfigFormData.type = "virtual_firealarm"; addConfigFormData.configuration = configList; - var addConfigAPI = "/devicemgt_admin/configuration"; + var addConfigAPI = "/api/device-mgt/virtual_firealarm/v1.0/configuration"; invokerUtil.post( addConfigAPI, addConfigFormData, diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.js b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.js index e4b0e14b0f..92d60d83d1 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.js +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.js @@ -18,27 +18,30 @@ function onRequest(context) { var log = new Log("stats.js"); + var carbonServer = require("carbon").server; var device = context.unit.params.device; var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var constants = require("/app/modules/constants.js"); + var websocketEndpoint = devicemgtProps["wssURL"].replace("https", "wss"); - var jwtService = carbon.server.osgiService('org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService'); + var jwtService = carbonServer.osgiService( + 'org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService'); var jwtClient = jwtService.getJWTClient(); - var encodedClientKeys = session.get(constants.ENCODED_CLIENT_KEYS_IDENTIFIER); + var encodedClientKeys = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]); if (encodedClientKeys) { - var tokenUtil = require("/app/modules/util.js").util; - var resp = tokenUtil.decode(encodedClientKeys).split(","); - var user = session.get(constants.USER_SESSION_KEY); - var deviceParam = "{\"scope\":\"stats\",\"deviceIdentifiers\":[{\"id\":\""+device.deviceIdentifier+" \", \"type\":\""+device.type+"\"}]}"; + var tokenUtil = require("/app/modules/oauth/token-handler-utils.js")["utils"]; + var resp = tokenUtil.decode(encodedClientKeys).split(":"); + var deviceParam = "{\"scope\":\"stats\",\"deviceIdentifiers\":[{\"id\":\"" + device.deviceIdentifier + + "\", \"type\":\"" + device.type + "\"}]}"; var encodedScope = tokenUtil.encode(deviceParam); - var tokenPair = jwtClient.getAccessToken(resp[0], resp[1], user.username, null, - "{\"device\": \"" +encodedScope+"\"}"); + var tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username,"default", + {"device": encodedScope}); var token = ""; if (tokenPair) { token = tokenPair.accessToken; } websocketEndpoint = websocketEndpoint + "/secured-outputui/org.wso2.iot.devices.temperature/1.0.0?" + - "token=" + token + "&deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type; + "token=" + token + "&deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type; } - return {"device": device, "websocketEndpoint" : websocketEndpoint}; + return {"device": device, "websocketEndpoint": websocketEndpoint}; } \ No newline at end of file diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/public/js/download.js b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/public/js/download.js index e2c9e8a415..9917968255 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/public/js/download.js +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/public/js/download.js @@ -16,9 +16,9 @@ * under the License. */ -var modalPopup = ".wr-modalpopup"; -var modalPopupContainer = modalPopup + " .modalpopup-container"; -var modalPopupContent = modalPopup + " .modalpopup-content"; +var modalPopup = ".modal"; +var modalPopupContainer = modalPopup + " .modal-content"; +var modalPopupContent = modalPopup + " .modal-content"; var body = "body"; /* @@ -33,7 +33,7 @@ function setPopupMaxHeight() { * Shows agent download popup. */ function showAgentDownloadPopup() { - $(modalPopup).show(); + $(modalPopup).modal('show'); setPopupMaxHeight(); var deviceType = ""; $('.deviceType').each(function () { @@ -50,7 +50,7 @@ function hideAgentDownloadPopup() { $('label[for=deviceName]').remove(); $('.control-group').removeClass('success').removeClass('error'); $(modalPopupContent).html(''); - $(modalPopup).hide(); + $(modalPopup).modal('hide'); } /* diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/pom.xml index 134555f71e..dc6652b825 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml index 46e9fad751..e7273de60f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml @@ -21,7 +21,7 @@ android-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml @@ -176,6 +176,12 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.analytics.data.publisher provided + + + org.slf4j + slf4j-api + + org.wso2.carbon.analytics @@ -199,6 +205,12 @@ io.swagger swagger-jaxrs + + + org.slf4j + slf4j-api + + javax.servlet diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationInstallation.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationInstallation.java index 454dc905a8..4c90d42cb6 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationInstallation.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationInstallation.java @@ -45,6 +45,9 @@ public class ApplicationInstallation extends AndroidOperation implements Seriali @ApiModelProperty(name = "url", value = "Application URL", required = true) private String url; + @ApiModelProperty(name = "schedule", value = "Schedule of the App installation.") + private String schedule; + public String getAppIdentifier() { return appIdentifier; } @@ -68,4 +71,14 @@ public class ApplicationInstallation extends AndroidOperation implements Seriali public void setUrl(String url) { this.url = url; } + + @SuppressWarnings("unused") + public String getSchedule() { + return schedule; + } + + @SuppressWarnings("unused") + public void setSchedule(String schedule) { + this.schedule = schedule; + } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java index 5c078f87db..a5356ae59c 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java @@ -43,10 +43,6 @@ public class ApplicationUninstallation extends AndroidOperation implements Seria @Pattern(regexp = "^[A-Za-z]*$") private String type; - @ApiModelProperty(name = "name", value = "The name of the application.", required = true) - @Size(min = 2, max = 45) - private String name; - public String getAppIdentifier() { return appIdentifier; } @@ -63,11 +59,4 @@ public class ApplicationUninstallation extends AndroidOperation implements Seria this.type = type; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java index 14f7c31dbc..95241b4443 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java @@ -44,7 +44,7 @@ public class ApplicationUpdate extends AndroidOperation implements Serializable private String type; @ApiModelProperty(name = "url", value = "The URL of the application.", required = true) private String url; - @ApiModelProperty(name = "schedule", value = "Application update schedule.", required = true) + @ApiModelProperty(name = "schedule", value = "Application update schedule.", required = false) private String schedule; public String getAppIdentifier() { diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java index 1b21523255..748ee0e598 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java @@ -30,7 +30,7 @@ import java.io.Serializable; description = "This class carries all information related to UpgradeFirmware.") public class UpgradeFirmware extends AndroidOperation implements Serializable { - @ApiModelProperty(name = "schedule", value = "Schedule of the UpgradeFirmware.", required = true) + @ApiModelProperty(name = "schedule", value = "Schedule of the UpgradeFirmware.") private String schedule; @ApiModelProperty(name = "server", value = "Firmware package server.") diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java index 291177ff75..66b84a875f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java @@ -204,7 +204,7 @@ public interface DeviceManagementService { @ApiResponse( code = 500, message = "Internal Server Error. \n " + - "Server error occurred while adding a new policy.") + "Server error occurred while adding a new device.") }) @Permission(name = "Enroll Device", permission = "/device-mgt/devices/enroll/android") Response enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll") diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java deleted file mode 100644 index 6eb87f0024..0000000000 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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.services.android.services.event; - -import io.swagger.annotations.*; -import org.wso2.carbon.mdm.services.android.bean.DeviceState; -import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; - -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -/** - * APIs related to events published from Android agent are implemented here. - */ -@Api(value = "EventService", description = "Android Device Management REST-API implementation.") -public interface EventService { - String ACCEPT = "Accept"; - - @POST - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Event Publishing via REST API.", - notes = "Publish events received by the WSO2 EMM Android client to WSO2 DAS using this API." - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Event is published successfully."), - @ApiResponse(code = 500, message = "Error occurred while publishing the events from Android agent.") - }) - Response publishEvents(@ApiParam(name = "acceptHeader", value = "Accept Header.") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "eventBeanWrapper", - value = "Information of the agent event to be published on DAS.") - EventBeanWrapper eventBeanWrapper); - - @GET - @Path("{deviceId}") - @Produces("application/json") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Event Details of a Device.", - notes = "Get the event details received by an Android device using this API.", - response = DeviceState.class, - responseContainer = "List" - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "List of Device statuses."), - @ApiResponse(code = 500, - message = "Error occurred while getting published events for specific given device.") - }) - Response retrieveAlert(@ApiParam(name = "acceptHeader", value = "Accept Header.") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "deviceId", value = "DeviceId which need to retrieve published events.") - @PathParam("deviceId") String deviceId); - - @GET - @Path("{deviceId}/date") - @Produces("application/json") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Event Details for a Given Time Period.", - notes = "Get the event details of a device for a given time duration using this API.", - response = DeviceState.class, - responseContainer = "List" - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "event details of a device for a given time duration"), - @ApiResponse(code = 500, message = "Error occurred while getting published events for" + - " specific device on given Date.") - }) - Response retrieveAlertFromDate(@ApiParam(name = "acceptHeader", value = "Accept Header.") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "deviceId", - value = "Device Identifier to be need to retrieve events.") - @PathParam("deviceId") String deviceId, - @ApiParam(name = "from", value = "From Date.") - @QueryParam("from") long from, - @ApiParam(name = "to", value = "To Date.") - @QueryParam("to") long to); - - @GET - @Path("{deviceId}/type/{type}") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Event Details for a Given Time Period.", - notes = "Get the event details of a device for a given time duration using this API.", - response = DeviceState.class, - responseContainer = "List" - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "event details of a device for a given time duration"), - @ApiResponse(code = 500, message = "Error occurred while getting published events for" + - " specific device on given Date.") - }) - Response retrieveAlertType(@ApiParam(name = "acceptHeader", value = "Accept Header.") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "deviceId", value = "Device Identifier to be need to retrieve events.") - @PathParam("deviceId") String deviceId, - @ApiParam(name = "type", value = "Type of the Alert to be need to retrieve events.") - @PathParam("type") String type); -} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/impl/EventServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/impl/EventServiceImpl.java deleted file mode 100644 index 00f9f9759a..0000000000 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/impl/EventServiceImpl.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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.services.android.services.event.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; -import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; -import org.wso2.carbon.mdm.services.android.bean.DeviceState; -import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; -import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.services.event.EventService; -import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; -import org.wso2.carbon.mdm.services.android.util.Message; - -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.List; - -public class EventServiceImpl implements EventService { - - private static final String ACCEPT = "Accept"; - private static Log log = LogFactory.getLog(EventService.class); - private static final String EVENT_STREAM_DEFINITION = "android_agent"; - - @POST - public Response publishEvents(@HeaderParam(ACCEPT) String acceptHeader, - EventBeanWrapper eventBeanWrapper) { - - if (log.isDebugEnabled()) { - log.debug("Invoking Android device even logging."); - } - Message message = new Message(); - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); - - Object payload[] = {eventBeanWrapper.getDeviceIdentifier(), eventBeanWrapper.getPayload(), - eventBeanWrapper.getType()}; - try { - if (AndroidAPIUtils.getEventPublisherService().publishEvent( - EVENT_STREAM_DEFINITION, "1.0.0", new Object[0], new Object[0], payload)) { - message.setResponseCode("Event is published successfully."); - return Response.status(Response.Status.CREATED).entity(message).type(responseMediaType).build(); - } else { - message.setResponseCode("Error occurred while publishing the event."); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR). - entity(message).type(responseMediaType).build(); - } - } catch (DataPublisherConfigurationException e) { - String msg = "Error occurred while publishing the events from Android agent."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); - } - } - - @Path("{deviceId}") - @Produces("application/json") - @GET - public Response retrieveAlert(@HeaderParam(ACCEPT) String acceptHeader, - @PathParam("deviceId") String deviceId) { - - if (log.isDebugEnabled()) { - log.debug("Retrieving events for given device Identifier."); - } - Message message = new Message(); - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); - String query = "deviceIdentifier:" + deviceId; - List deviceStates; - try { - deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); - if (deviceStates == null) { - message.setResponseCode("No any alerts are published for Device: " + deviceId + "."); - return Response.status(Response.Status.OK).entity(message).type(responseMediaType).build(); - - } else { - return Response.status(Response.Status.OK).entity(deviceStates).build(); - } - } catch (AnalyticsException e) { - String msg = "Error occurred while getting published events for specific " + - "Device: " + deviceId + "."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); - } - } - - @Path("{deviceId}/date") - @Produces("application/json") - @GET - public Response retrieveAlertFromDate(@HeaderParam(ACCEPT) String acceptHeader, - @PathParam("deviceId") String deviceId, @QueryParam("from") long from, - @QueryParam("to") long to) { - String fromDate = String.valueOf(from); - String toDate = String.valueOf(to); - if (log.isDebugEnabled()) { - log.debug("Retrieving events for given device Identifier and time period."); - } - Message message = new Message(); - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); - - String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]"; - List deviceStates; - try { - deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); - if (deviceStates == null) { - message. - setResponseCode("No any alerts are published on given date for given Device: " + deviceId + "."); - return Response.status(Response.Status.OK).entity(message).build(); - - } else { - return Response.status(Response.Status.OK).entity(deviceStates).type(responseMediaType).build(); - } - } catch (AnalyticsException e) { - String msg = "Error occurred while getting published events for specific " + - "Device: " + deviceId + " on given Date."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); - } - } - - @Path("{deviceId}/type/{type}") - @GET - public Response retrieveAlertType(@HeaderParam(ACCEPT) String acceptHeader, - @PathParam("deviceId") String deviceId, @PathParam("type") String type) { - - if (log.isDebugEnabled()) { - log.debug("Retrieving events for given device identifier and type."); - } - Message message = new Message(); - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); - String query = "deviceIdentifier:" + deviceId + " AND type:" + type; - List deviceStates; - try { - deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); - if (deviceStates == null) { - message.setResponseCode("No any alerts are published for given Device: " - + deviceId + " on specific date."); - return Response.status(Response.Status.OK).entity(message).build(); - - } else { - return Response.status(Response.Status.OK).entity(deviceStates).type(responseMediaType).build(); - } - } catch (AnalyticsException e) { - String msg = "Error occurred while getting published events for specific " + - "Device: " + deviceId + "and given device Type."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); - } - - } -} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java index 11840a6697..b7fcd5f92b 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java @@ -21,7 +21,6 @@ package org.wso2.carbon.mdm.services.android.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; -import org.json.JSONObject; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; @@ -78,9 +77,7 @@ import java.net.URL; import java.net.URLConnection; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Date; import java.util.List; -import java.util.Map; @Path("/admin/devices") @Produces(MediaType.APPLICATION_JSON) @@ -88,7 +85,7 @@ import java.util.Map; public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminService { private static final Log log = LogFactory.getLog(DeviceManagementAdminServiceImpl.class); - private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssXXX"; + private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; @POST @Path("/lock-devices") @@ -536,45 +533,14 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } ApplicationInstallation applicationInstallation = applicationInstallationBeanWrapper.getOperation(); - JSONObject payload = new JSONObject(applicationInstallation.toJSON()); - - try { - URL url = new URL(payload.getString("url")); - URLConnection conn = url.openConnection(); - - //get all headers - Map> headerFields = conn.getHeaderFields(); - boolean isFile = false; - for (Map.Entry> entry : headerFields.entrySet()) { - if ("Content-Type".equals(entry.getKey()) && entry.getValue() != null - && entry.getValue().size() > 0 && "application/octet-stream".equals(entry.getValue().get(0))) { - isFile = true; - break; - } - } - if (!isFile) { - String errorMessage = "URL is not pointed to a downloadable file."; - log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); - } - validateType(payload); - } catch (MalformedURLException e) { - String errorMessage = "Malformed application url."; - log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); - } catch (IOException e) { - String errorMessage = "Invalid application url."; - log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); - } + validateApplicationUrl(applicationInstallation.getUrl()); + validateApplicationType(applicationInstallation.getType()); + validateScheduleDate(applicationInstallation.getSchedule()); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.INSTALL_APPLICATION); operation.setType(Operation.Type.PROFILE); - operation.setPayLoad(payload.toString()); + operation.setPayLoad(applicationInstallation.toJSON()); return AndroidAPIUtils.getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(), operation); } catch (JSONException e) { @@ -616,6 +582,10 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); + validateApplicationUrl(applicationUpdate.getUrl()); + validateApplicationType(applicationUpdate.getType()); + validateScheduleDate(applicationUpdate.getSchedule()); + ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.UPDATE_APPLICATION); operation.setType(Operation.Type.PROFILE); @@ -658,8 +628,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } ApplicationUninstallation applicationUninstallation = applicationUninstallationBeanWrapper.getOperation(); - JSONObject payload = new JSONObject(applicationUninstallation.toJSON()); - validateType(payload); + validateApplicationType(applicationUninstallation.getType()); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.UNINSTALL_APPLICATION); @@ -686,25 +655,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } } - private void validateType(JSONObject payload) { - if (payload.has("type")) { - String type = payload.getString("type"); - if (!"enterprise".equalsIgnoreCase(type) - && !"public".equalsIgnoreCase(type) - && !"webapp".equalsIgnoreCase(type)) { - String errorMessage = "Invalid application type."; - log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); - } - } else { - String errorMessage = "Application type is missing."; - log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); - } - } - @POST @Path("/blacklist-applications") @Override @@ -761,13 +711,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); - - //validate date - if(upgradeFirmware != null && upgradeFirmware.getSchedule() != null){ - SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); - sdf.setLenient(false); - Date date = sdf.parse(upgradeFirmware.getSchedule()); - } + validateScheduleDate(upgradeFirmware.getSchedule()); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE); @@ -789,11 +733,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe log.error(errorMessage, e); throw new UnexpectedServerErrorException( new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); - } catch (ParseException e) { - String errorMessage = "Issue in validating the schedule date"; - log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } } @@ -1079,4 +1018,71 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } } + private static boolean hasValidAPKContentType(String contentType){ + if (contentType != null){ + switch (contentType) { + case MediaType.APPLICATION_OCTET_STREAM: + case "application/android": + return true; + } + } + return false; + } + + private static void validateApplicationUrl(String apkUrl) { + try { + URL url = new URL(apkUrl); + URLConnection conn = url.openConnection(); + if (!hasValidAPKContentType(conn.getContentType())) { + String errorMessage = "URL is not pointed to a downloadable file."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } catch (MalformedURLException e) { + String errorMessage = "Malformed application url."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (IOException e) { + String errorMessage = "Invalid application url."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } + + private static void validateApplicationType(String type) { + if (type != null) { + if (!"enterprise".equalsIgnoreCase(type) + && !"public".equalsIgnoreCase(type) + && !"webapp".equalsIgnoreCase(type)) { + String errorMessage = "Invalid application type."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } else { + String errorMessage = "Application type is missing."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } + + private static void validateScheduleDate(String dateString){ + try { + if (dateString != null) { + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); + sdf.setLenient(false); + sdf.parse(dateString); + } + } catch (ParseException e) { + String errorMessage = "Issue in validating the schedule date"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } + } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml index c2bdaba51c..85537c4feb 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml @@ -23,13 +23,13 @@ android-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.mobile.android.ui - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT WSO2 Carbon - Mobile Android UI pom diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js index 4407e222fe..56c11ec664 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js @@ -23,7 +23,7 @@ function onRequest(context) { if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; - var device = deviceModule.viewDevice(deviceType, deviceId); + var device = deviceModule.viewDevice(deviceType, deviceId)["content"]; if (device) { var viewModel = {}; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/public/js/device-detail.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/public/js/device-detail.js index 49c3512b9e..20cf3c165e 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/public/js/device-detail.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/public/js/device-detail.js @@ -21,57 +21,265 @@ var deviceIdentifier = deviceId.data("deviceid"); var deviceType = deviceId.data("type"); var payload = [deviceIdentifier]; - var serviceUrl = "/mdm-android-agent/operation/device-info"; - invokerUtil.post(serviceUrl, payload, - function (message) { - console.log(message); - }, function (message) { - console.log(message); - }); + var operationTable; + if (deviceType == "ios") { + serviceUrl = "/ios/operation/deviceinfo"; + } else if (deviceType == "android") { + //var serviceUrl = "/mdm-android-agent/operation/device-info"; + serviceUrl = "/api/device-mgt/android/v1.0/admin/devices/info"; + } + if (serviceUrl) { + invokerUtil.post(serviceUrl, payload, + function (message) { + console.log(message); + }, function (message) { + console.log(message); + }); + } $(document).ready(function () { $(".panel-body").removeClass("hidden"); $("#loading-content").remove(); + + loadOperationsLog(); loadApplicationsList(); + loadPolicyCompliance(); + + $("#refresh-policy").click(function () { + $('#policy-spinner').removeClass('hidden'); + loadPolicyCompliance(); + }); $("#refresh-apps").click(function () { $('#apps-spinner').removeClass('hidden'); loadApplicationsList(); }); + + $("#refresh-operations").click(function () { + $('#operations-spinner').removeClass('hidden'); + loadOperationsLog(true); + }); loadOperationBar(deviceType); }); + function loadOperationsLog(update) { + var operationsLogTable = "#operations-log-table"; + if (update) { + operationTable = $(operationsLogTable).DataTable(); + operationTable.ajax.reload(false); + return; + } + operationTable = $(operationsLogTable) + .datatables_extended({ + serverSide: true, + processing: false, + searching: false, + ordering: false, + pageLength: 10, + order: [], + ajax: { + url: context + "/api/operation/paginate", + data: { + deviceId: deviceIdentifier, + deviceType: deviceType + }, + dataSrc: function (json) { + $("#operations-spinner").addClass( + "hidden"); + $("#operations-log-container").empty(); + return json.data; + } + }, + columnDefs: [ + {targets: 0, data: "code"}, + { + targets: 1, + data: "status", + render: function (status) { + var html; + switch (status) { + case "COMPLETED" : + html = + " Completed"; + break; + case "PENDING" : + html = + " Pending"; + break; + case "ERROR" : + html = + " Error"; + break; + case "IN_PROGRESS" : + html = + " In Progress"; + break; + case "REPEATED" : + html = + " Repeated"; + break; + } + return html; + } + }, + { + targets: 2, + data: "createdTimeStamp", + render: function (date) { + var value = String(date); + return value.slice(0, 16); + } + } + ], + "createdRow": function (row, data) { + $(row).attr("data-type", "selectable"); + $(row).attr("data-id", data["id"]); + $.each($("td", row), + function (colIndex) { + switch (colIndex) { + case 1: + $(this).attr( + "data-grid-label", + "Code"); + $(this).attr( + "data-display", + data["code"]); + break; + case 2: + $(this).attr( + "data-grid-label", + "Status"); + $(this).attr( + "data-display", + data["status"]); + break; + case 3: + $(this).attr( + "data-grid-label", + "Created Timestamp"); + $(this).attr( + "data-display", + data["createdTimeStamp"]); + break; + } + } + ); + } + }); + } + function loadApplicationsList() { var applicationsList = $("#applications-list"); - var deviceListingSrc = applicationsList.attr("src"); + var applicationListingTemplate = applicationsList.attr("src"); var deviceId = applicationsList.data("device-id"); var deviceType = applicationsList.data("device-type"); - $.template("application-list", deviceListingSrc, function (template) { - var serviceURL = "/devicemgt_admin/operations/" + deviceType + "/" + deviceId + "/apps"; + $.template("application-list", applicationListingTemplate, function (template) { + var serviceURL = "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/applications"; + invokerUtil.get( + serviceURL, + // success-callback + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + data = JSON.parse(data); + $("#apps-spinner").addClass("hidden"); + if (data.length > 0) { + for (var i = 0; i < data.length; i++) { + data[i]["name"] = decodeURIComponent(data[i]["name"]); + data[i]["platform"] = deviceType; + } - var successCallback = function (data) { - data = JSON.parse(data); - $('#apps-spinner').addClass('hidden'); - var viewModel = {}; - if (data != null && data.length > 0) { - for (var i = 0; i < data.length; i++) { - data[i].name = data[i].name.replace(/[^\w\s]/gi, ' '); - data[i].name = data[i].name.replace(/[0-9]/g, ' '); + var viewModel = {}; + viewModel["applications"] = data; + viewModel["deviceType"] = deviceType; + var content = template(viewModel); + $("#applications-list-container").html(content); + } else { + $("#applications-list-container"). + html("

No applications found.

" + + "

Please try refreshing the list in a while.

"); + } } - } - viewModel.applications = data; - viewModel.deviceType = deviceType; - if (data.length > 0) { - var content = template(viewModel); - $("#applications-list-container").html(content); - } - - }; - invokerUtil.get(serviceURL, - successCallback, function (message) { - console.log(message); + }, + // error-callback + function () { + $("#applications-list-container"). + html("

 Loading application list " + + "was not successful. please try refreshing the list in a while.

"); }); }); } + function loadPolicyCompliance() { + var policyCompliance = $("#policy-view"); + var policyComplianceTemplate = policyCompliance.attr("src"); + var deviceId = policyCompliance.data("device-id"); + var deviceType = policyCompliance.data("device-type"); + var activePolicy = null; + + $.template( + "policy-view", + policyComplianceTemplate, + function (template) { + var getEffectivePolicyURL = "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/effective-policy"; + var getDeviceComplianceURL = "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/compliance-data"; + + invokerUtil.get( + getEffectivePolicyURL, + // success-callback + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + data = JSON.parse(data); + $("#policy-spinner").addClass("hidden"); + if (data["active"] == true) { + activePolicy = data; + invokerUtil.get( + getDeviceComplianceURL, + // success-callback + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + var viewModel = {}; + viewModel["policy"] = activePolicy; + viewModel["deviceType"] = deviceType; + data = JSON.parse(data); + var content; + if (data["complianceData"]) { + if (data["complianceData"]["complianceFeatures"] && + data["complianceData"]["complianceFeatures"].length > 0) { + viewModel["compliance"] = "NON-COMPLIANT"; + viewModel["complianceFeatures"] = data["complianceData"]["complianceFeatures"]; + content = template(viewModel); + $("#policy-list-container").html(content); + } else { + viewModel["compliance"] = "COMPLIANT"; + content = template(viewModel); + $("#policy-list-container").html(content); + $("#policy-compliance-table").addClass("hidden"); + } + } else { + $("#policy-list-container"). + html("

This device " + + "has no policy applied.

"); + } + } + }, + // error-callback + function () { + $("#policy-list-container"). + html("

Loading policy compliance related data " + + "was not successful. please try refreshing data in a while.

"); + } + ); + } + } + }, + // error-callback + function () { + $("#policy-list-container"). + html("

Loading policy compliance related data " + + "was not successful. please try refreshing data in a while.

"); + } + ); + } + ); + } }()); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml index 6c7015ed8d..f2f8ffc4e7 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml @@ -22,7 +22,7 @@ android-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/android-plugin/pom.xml b/components/mobile-plugins/android-plugin/pom.xml index b76b85d9ae..fa92b8b142 100644 --- a/components/mobile-plugins/android-plugin/pom.xml +++ b/components/mobile-plugins/android-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins mobile-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/pom.xml b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/pom.xml index 99c47c633d..8ed09cb39b 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/pom.xml +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/pom.xml @@ -23,7 +23,7 @@ mobile-base-plugin org.wso2.carbon.devicemgt-plugins - 2.2.2-SNAPSHOT + 2.2.3-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.devices/devices.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.devices/devices.hbs index fa4688cda2..3662eb6b1d 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.devices/devices.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.devices/devices.hbs @@ -50,7 +50,7 @@ {{/if}} {{#if permissions.ADVANCED_SEARCH}}
  • + Policies @@ -41,25 +42,29 @@ {{#zone "navbarActions"}} {{#if permissions.ADD_ADMIN_POLICY}} -
  • - - - - - - Add Policy - -
  • + {{#equal noPolicy false}} +
  • + + + + + + +  Add New Policy + +
  • + {{/equal}} {{/if}} {{#if permissions.CHANGE_POLICY_PRIORITY}} {{#equal noPolicy false}}
  • + - Policy Priority +  Policy Priority
  • {{/equal}} @@ -70,7 +75,7 @@ - Apply Changes To Devices +  Apply Changes To Devices {{/zone}} @@ -82,18 +87,21 @@ {{#equal noPolicy true}}
    @@ -229,6 +237,7 @@ data-display="{{status}}"> + +
    {{unit "mdm.unit.device.operation-mod"}}
    {{/zone}} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js index b6ac6b5f8c..512edff658 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js @@ -16,8 +16,8 @@ * under the License. */ -function onRequest() { - // var log = new Log("mdm.unit.device.operation-bar"); +function onRequest(context) { + var log = new Log("mdm.unit.device.operation-bar"); var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var viewModel = {}; var permissions = {}; @@ -93,10 +93,14 @@ function onRequest() { if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/windows/ring")) { permissions["windows"].push("DEVICE_RING"); } - if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/windows/lockreset")) { + if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/operations/windows/lock-reset")) { permissions["windows"].push("LOCK_RESET"); } viewModel["permissions"] = stringify(permissions); + + viewModel["deviceType"] = context.unit.params.deviceType; + viewModel["ownership"] = context.unit.params.ownership; + return viewModel; } \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js index a3186092ac..90ce9ce4a2 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js @@ -21,8 +21,8 @@ */ var operations = '.wr-operations', - modalPopup = '.wr-modalpopup', - modalPopupContent = modalPopup + ' .modalpopup-content', + modalPopup = '.modal', + modalPopupContent = modalPopup + ' .modal-content', navHeight = $('#nav').height(), headerHeight = $('header').height(), offset = (headerHeight + navHeight), @@ -31,6 +31,14 @@ var operations = '.wr-operations', "ANDROID": "android", "IOS": "ios", "WINDOWS": "windows" + }, + ownershipTypeConstants = { + "BYOD": "BYOD", + "COPE": "COPE" + }, + operationBarModeConstants = { + "BULK": "BULK_OPERATION_MODE", + "SINGLE": "SINGLE_OPERATION_MODE" }; /* @@ -43,9 +51,9 @@ function getSelectedDeviceIds() { var deviceId = device.data('deviceid'); var deviceType = device.data('type'); deviceIdentifierList.push({ - "id": deviceId, - "type": deviceType - }); + "id": deviceId, + "type": deviceType + }); }); if (deviceIdentifierList.length == 0) { var thisTable = $(".DTTT_selected").closest('.dataTables_wrapper').find('.dataTable').dataTable(); @@ -54,9 +62,9 @@ function getSelectedDeviceIds() { var deviceId = $(thisTable.api().row(this).node()).data('deviceid'); var deviceType = $(thisTable.api().row(this).node()).data('devicetype'); deviceIdentifierList.push({ - "id": deviceId, - "type": deviceType - }); + "id": deviceId, + "type": deviceType + }); } }); } @@ -94,62 +102,90 @@ function getDevicesByTypes(deviceList) { return deviceTypes; } -function unloadOperationBar() { - $("#showOperationsBtn").addClass("hidden"); - $(".wr-operations").html(""); -} +//function unloadOperationBar() { +// $("#showOperationsBtn").addClass("hidden"); +// $(".wr-operations").html(""); +//} -function loadOperationBar(deviceType) { +function loadOperationBar(deviceType, ownership, mode) { var operationBar = $("#operations-bar"); var operationBarSrc = operationBar.attr("src"); - var platformType = deviceType; - //var selectedDeviceID = deviceId; + $.template("operations-bar", operationBarSrc, function (template) { - //var serviceURL = "/mdm-admin/features/" + platformType; - var serviceURL = "/api/device-mgt/v1.0/devices/" + platformType + "/*/features"; - var successCallback = function (data) { - var permittedOperations = []; - var i; - var permissionList = $("#operations-mod").data("permissions"); - var totalFeatures = JSON.parse(data); - for (i = 0; i < permissionList[deviceType].length; i++) { - var j; - for (j = 0; j < totalFeatures.length; j++) { - if (permissionList[deviceType][i] == totalFeatures[j]["code"]) { - permittedOperations.push(totalFeatures[j]); + var serviceURL = "/api/device-mgt/v1.0/devices/" + deviceType + "/*/features"; + invokerUtil.get( + serviceURL, + // success callback + function (data) { + var permittedOperations = []; + var i; + var permissionList = $("#operations-mod").data("permissions"); + var totalFeatures = JSON.parse(data); + for (i = 0; i < permissionList[deviceType].length; i++) { + var j; + for (j = 0; j < totalFeatures.length; j++) { + if (permissionList[deviceType][i] == totalFeatures[j]["code"]) { + if (deviceType == platformTypeConstants.ANDROID) { + if (totalFeatures[j]["code"] == "DEVICE_UNLOCK") { + if (ownership == ownershipTypeConstants.COPE) { + permittedOperations.push(totalFeatures[j]); + } + } else if (totalFeatures[j]["code"] == "WIPE_DATA") { + if (mode == operationBarModeConstants.BULK) { + if (ownership == ownershipTypeConstants.COPE) { + permittedOperations.push(totalFeatures[j]); + } + } else { + permittedOperations.push(totalFeatures[j]); + } + } else { + permittedOperations.push(totalFeatures[j]); + } + } else { + permittedOperations.push(totalFeatures[j]); + } + } } } - } - var viewModel = {}; - permittedOperations = permittedOperations.filter(function (current) { - var iconName; - switch (deviceType) { - case platformTypeConstants.ANDROID: - iconName = operationModule.getAndroidIconForFeature(current.code); - current.type = deviceType; - break; - case platformTypeConstants.WINDOWS: - iconName = operationModule.getWindowsIconForFeature(current.code); - break; - case platformTypeConstants.IOS: - iconName = operationModule.getIOSIconForFeature(current.code); - break; - } + var viewModel = {}; + permittedOperations = permittedOperations.filter(function (current) { + var iconName; + switch (deviceType) { + case platformTypeConstants.ANDROID: + iconName = operationModule.getAndroidIconForFeature(current.code); + break; + case platformTypeConstants.WINDOWS: + iconName = operationModule.getWindowsIconForFeature(current.code); + break; + case platformTypeConstants.IOS: + iconName = operationModule.getIOSIconForFeature(current.code); + break; + } + + /* adding ownership in addition to device-type + as it's vital in cases where UI for the same feature should change + according to ownership + */ + if (ownership) { + current.ownership = ownership; + } + + if (iconName) { + current.icon = iconName; + } - if (iconName) { - current.icon = iconName; return current; - } - }); + }); - viewModel.features = permittedOperations; - var content = template(viewModel); - $(".wr-operations").html(content); - }; - invokerUtil.get(serviceURL, successCallback, function (message) { - $(".wr-operations").html(message); - }); + viewModel.features = permittedOperations; + var content = template(viewModel); + $(".wr-operations").html(content); + }, + // error callback + function (message) { + $(".wr-operations").html(message); + }); }); } @@ -172,14 +208,16 @@ function runOperation(operationName) { var payload, serviceEndPoint; if (list[platformTypeConstants.IOS]) { - payload = operationModule.generatePayload(platformTypeConstants.IOS, operationName, list[platformTypeConstants.IOS]); + payload = + operationModule.generatePayload(platformTypeConstants.IOS, operationName, list[platformTypeConstants.IOS]); serviceEndPoint = operationModule.getIOSServiceEndpoint(operationName); } else if (list[platformTypeConstants.ANDROID]) { payload = operationModule .generatePayload(platformTypeConstants.ANDROID, operationName, list[platformTypeConstants.ANDROID]); serviceEndPoint = operationModule.getAndroidServiceEndpoint(operationName); } else if (list[platformTypeConstants.WINDOWS]) { - payload = operationModule.generatePayload(platformTypeConstants.WINDOWS, operationName, list[platformTypeConstants.WINDOWS]); + payload = operationModule.generatePayload(platformTypeConstants.WINDOWS, operationName, + list[platformTypeConstants.WINDOWS]); serviceEndPoint = operationModule.getWindowsServiceEndpoint(operationName); } if (operationName == "NOTIFICATION") { diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/operations.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/operations.hbs index cd32216746..0b94ae0881 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/operations.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/operations.hbs @@ -107,14 +107,16 @@
    @@ -907,9 +907,9 @@ -
    - This configuration can be used to create a black list or white list of applications. -
    +
    + This configuration can be used to create a black list or white list of applications. +

    diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/public/templates/hidden-operations-android.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/public/templates/hidden-operations-android.hbs index 73b1018733..520ddaf374 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/public/templates/hidden-operations-android.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/public/templates/hidden-operations-android.hbs @@ -1320,7 +1320,7 @@
    - This configuration can be used to set a passcode policy to an Android Device. + This configuration can be used to set system update policy to an Android Device in COSU. Once this configuration profile is installed on a device, corresponding users will not be able to modify these settings on their devices. @@ -1472,7 +1472,7 @@
    - This configuration can be used to set a passcode policy to an Android Device. + This configuration can be used to whitelist applications in lock task mode of an Android Device in COSU. Once this configuration profile is installed on a device, corresponding users will not be able to modify these settings on their devices. diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/public/templates/hidden-operations-android.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/public/templates/hidden-operations-android.hbs index e9e3a0a7ed..e75127b616 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/public/templates/hidden-operations-android.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/public/templates/hidden-operations-android.hbs @@ -73,14 +73,14 @@ - + Whitelist Apps (COSU) - - - + + +
    @@ -230,7 +230,7 @@