diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java index da0931e10f..1ede29f3e8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java @@ -374,7 +374,7 @@ public interface PolicyManagementService { required = true) List policyIds); - @POST + @PUT @Path("/deactivate-policy") @ApiOperation( consumes = MediaType.APPLICATION_JSON, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java index 82e3108149..ecbafd974c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java @@ -150,6 +150,9 @@ public class Application implements Serializable { if (applicationIdentifier != null ? !applicationIdentifier.equals(that.applicationIdentifier) : that.applicationIdentifier != null) { return false; } + if (version != null ? !version.equals(that.version) : that.version != null) { + return false; + } return true; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 18f61261f0..d03d7b1612 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -97,8 +97,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem if (deviceIds.size() > 0) { type = deviceIds.get(0).getType().toLowerCase(); } - Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(). - addOperation(type, operation, deviceIds); + Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(). + addOperation(type, operation, deviceIds); DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().notifyOperationToDevices (operation, deviceIds); return activity; @@ -217,13 +217,14 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem appIdsToRemove.add(installedApp.getId()); } } - + applicationMappingDAO.removeApplicationMapping(device.getId(), appIdsToRemove, tenantId); Application installedApp; List applicationIds = new ArrayList<>(); for (Application application : applications) { if (!installedAppList.contains(application)) { - installedApp = applicationDAO.getApplication(application.getApplicationIdentifier(), tenantId); + installedApp = applicationDAO.getApplication(application.getApplicationIdentifier(), + application.getVersion(), tenantId); if (installedApp == null) { appsToAdd.add(application); } else { @@ -244,7 +245,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem if (log.isDebugEnabled()) { log.debug("num of remove app Ids:" + appIdsToRemove.size()); } - applicationMappingDAO.removeApplicationMapping(device.getId(), appIdsToRemove, tenantId); + DeviceManagementDAOFactory.commitTransaction(); } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationDAO.java index 5cc8b3c7d6..e5e91f28bc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationDAO.java @@ -32,5 +32,7 @@ public interface ApplicationDAO { Application getApplication(String identifier, int tenantId) throws DeviceManagementDAOException; + Application getApplication(String identifier, String version,int tenantId) throws DeviceManagementDAOException; + List getInstalledApplications(int deviceId) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java index a9312623ae..c391f1057f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java @@ -228,6 +228,34 @@ public class ApplicationDAOImpl implements ApplicationDAO { } } + @Override + public Application getApplication(String identifier, String version, int tenantId) throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + Application application = null; + try { + conn = this.getConnection(); + stmt = conn.prepareStatement("SELECT ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " + + "LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " + + "AND VERSION = ? AND TENANT_ID = ?"); + stmt.setString(1, identifier); + stmt.setString(2, version); + stmt.setInt(3, tenantId); + rs = stmt.executeQuery(); + + if (rs.next()) { + application = this.loadApplication(rs); + } + return application; + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while retrieving application application '" + + identifier + "' and version '" + version + "'.", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, rs); + } + } + private Connection getConnection() throws SQLException { return DeviceManagementDAOFactory.getConnection(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.hbs index 6295e4b87d..7b1a0775fe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.hbs @@ -15,7 +15,7 @@ specific language governing permissions and limitations under the License. }} -{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}} +{{unit "cdmf.unit.ui.title" pageTitle="Policy Management | Policy Priorities"}} {{#zone "breadcrumbs"}}
  • @@ -24,10 +24,17 @@
  • + Policies
  • +
  • + + + Priorities + +
  • {{/zone}} {{#zone "content"}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.json index 96ec4c8d85..b8be6d8bbb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.json @@ -1,5 +1,5 @@ { "version": "1.0.0", - "uri": "/policy/priority", + "uri": "/policy/priority", "layout": "cdmf.layout.default" } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs index 5a7fea7f8a..f4c6ff7754 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs @@ -15,20 +15,19 @@ specific language governing permissions and limitations under the License. }} +
     Policy List by priority order
    -
    -
    -
    - {{policyListingStatusMsg}} - -
    - {{#each policyListToView}} - +
    +
    + {{policyListingStatusMsg}} +
    + {{#each policyListToView}} +
    @@ -40,15 +39,7 @@ - {{#equal platform "android"}} - - {{/equal}} - {{#equal platform "windows"}} - - {{/equal}} - {{#equal platform "ios"}} - - {{/equal}} +

    {{name}}

    @@ -62,19 +53,20 @@ Ownership Type : {{ownershipType}}
    - {{#if roles}} + {{#equal roles "None"}}
    - Assigned Role(s) : {{roles}} + Assigned User(s) : {{users}}
    - {{else}} + {{/equal}} + {{#equal users "None"}}
    - Assigned User(s) : {{users}} + Assigned Role(s) : {{roles}}
    - {{/if}} + {{/equal}}
    Compliance Type : {{compliance}} @@ -84,120 +76,112 @@
    - {{/each}} -
    - {{#equal noPolicy false}} -
    - - + {{/each}}
    - {{/equal}} + {{#equal noPolicy false}} +
    + + +
    + {{/equal}} +
    -
    -
    -
    -
    -
    -

    Do you really want to apply changes to all policies?

    - -
    - - Yes - - - No - +
    +
    +
    +
    +

    Do you really want to apply changes to all policies?

    + +
    -
    -
    -
    -
    -
    -

    Done. Changes applied successfully.

    - -
    - - Ok - +
    +
    +
    +
    +

    Done. Changes applied successfully.

    + +
    -
    -
    -
    -
    -
    -

    An unexpected error occurred. Please try again later.

    - -
    - - Ok - +
    +
    +
    +
    +

    An unexpected error occurred. Please try again later.

    + +
    -
    -
    -
    -
    -
    -

    An unexpected error occurred. Please try again later.

    - -
    - - Ok - +
    +
    +
    +
    +

    An unexpected error occurred. Please try again later.

    + +
    -
    -
    -
    -
    -
    -

    Done. New Policy priorities were successfully updated.

    - -
    - - Ok - +
    +
    +
    +
    +

    Done. New Policy priorities were successfully updated.

    + +
    -
    -
    -
    -
    -
    -

    An unexpected error occurred. Please try again later.

    -

    - -
    - - Ok - +
    +
    +
    +
    +

    An unexpected error occurred. Please try again later.

    +
    diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js index 2ba2155ac2..a6afb10f6b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js @@ -1,17 +1,17 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2015, 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 + * 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 + * "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. */ @@ -27,8 +27,9 @@ function onRequest(context) { return options.fn(this); } }); - var policyModule = require("/app/modules/business-controllers/group.js")["groupModule"]; + var policyModule = require("/app/modules/business-controllers/policy.js")["policyModule"]; var response = policyModule.getAllPolicies(); + if (response["status"] == "success") { var policyListToView = response["content"]; context["policyListToView"] = policyListToView; @@ -38,7 +39,7 @@ function onRequest(context) { context["saveNewPrioritiesButtonEnabled"] = false; context["noPolicy"] = true; } else if (policyCount == 1) { - context["policyListingStatusMsg"] = "Add more policies to set up a priority order."; + context["policyListingStatusMsg"] = "Two or more policies should be available to set up a priority order."; context["saveNewPrioritiesButtonEnabled"] = false; context["noPolicy"] = false; } else { @@ -47,9 +48,11 @@ function onRequest(context) { context["noPolicy"] = false; } } else { + // here, response["status"] == "error" context["policyListToView"] = []; - context["policyListingStatusMsg"] = response["content"]; + context["policyListingStatusMsg"] = "Error in retrieving policies. Please try reloading the page."; context["saveNewPrioritiesButtonEnabled"] = false; } + return context; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/policy-priority.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/policy-priority.js index f2ccc3b9d1..f6b5514d7e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/policy-priority.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/policy-priority.js @@ -1,17 +1,17 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2015, 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 + * 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 + * "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. */ @@ -78,58 +78,66 @@ $(document).ready(function () { newPolicyPriorityList.push(policy); } - var updatePolicyAPI = "/devicemgt_admin/policies/priorities"; + var updatePolicyAPI = "/api/device-mgt/v1.0/policies/priorities"; invokerUtil.put( updatePolicyAPI, newPolicyPriorityList, - function () { - $(modalPopupContent).html($('#save-policy-priorities-success-content').html()); - showPopup(); - $("a#save-policy-priorities-success-link").click(function () { - hidePopup(); - }); + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + $(modalPopupContent).html($('#save-policy-priorities-success-content').html()); + showPopup(); + $("a#save-policy-priorities-success-link").click(function () { + hidePopup(); + }); + } }, - function () { - $("#save-policy-priorities-error-content").find(".message-from-server").html( - "Message From Server : " + data["statusText"]); - $(modalPopupContent).html($('#save-policy-priorities-error-content').html()); - showPopup(); - $("a#save-policy-priorities-error-link").click(function () { - hidePopup(); - }); + // on error + function (jqXHR) { + if (jqXHR.status == 400 || jqXHR.status == 500) { + $(modalPopupContent).html($("#save-policy-priorities-error-content").html()); + showPopup(); + $("a#save-policy-priorities-error-link").click(function () { + hidePopup(); + }); + } } ); }); $(applyChangesBtn).click(function () { - var applyPolicyChangesAPI = "/devicemgt_admin/policies/apply-changes"; - $(modalPopupContent).html($('#change-policy-modal-content').html()); + var applyPolicyChangesAPI = "/api/device-mgt/v1.0/policies/apply-changes"; + $(modalPopupContent).html($("#apply-changes-modal-content").html()); showPopup(); - $("a#change-policy-yes-link").click(function () { + $("a#apply-changes-yes-link").click(function () { invokerUtil.put( applyPolicyChangesAPI, null, // on success - function () { - $(modalPopupContent).html($('#change-policy-success-content').html()); - showPopup(); - $("a#change-policy-success-link").click(function () { - hidePopup(); - }); + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + $(modalPopupContent).html($("#apply-changes-success-content").html()); + showPopup(); + $("a#apply-changes-success-link").click(function () { + hidePopup(); + }); + } }, // on error - function () { - $(modalPopupContent).html($('#change-policy-error-content').html()); - showPopup(); - $("a#change-policy-error-link").click(function () { - hidePopup(); - }); + function (jqXHR) { + if (jqXHR.status == 500) { + $(modalPopupContent).html($("#apply-changes-error-content").html()); + showPopup(); + $("a#apply-changes-error-link").click(function () { + hidePopup(); + }); + } } ); }); - $("a#change-policy-cancel-link").click(function () { + $("a#apply-changes-cancel-link").click(function () { hidePopup(); }); }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/sortable-list.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/sortable-list.js index c4f78b1bc1..c436e2ac56 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/sortable-list.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/sortable-list.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2015, 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 @@ -47,7 +47,7 @@ var sortableListFunction = (function () { } /** - * on input text field focus autocomplete bind function + * on input text field focus auto-complete bind function */ $(sortableElem).on('focus', '.wr-sort-index input.index', function () { currentElemId = $(this).val();