From 48ffb02cb4360019987864130506721c2865952d Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Tue, 22 Oct 2019 23:40:49 +0530 Subject: [PATCH 01/11] Fix apple logo not displaying in UI DEP config --- .../app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs index 8c80bd6fc7..b071abf81d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs @@ -118,7 +118,7 @@ {{/if}} {{#if iosPluginFlag}}
  • - + DEP Configurations
  • From e57dd65dd8e0ce481ac8c95863a98cc5e7773a9b Mon Sep 17 00:00:00 2001 From: achala007 Date: Wed, 23 Oct 2019 09:54:00 +0530 Subject: [PATCH 02/11] Update geo featur UI and date time picker --- .../react-app/package.json | 4 +- .../Geo/geo-dashboard/GeoDashboard.js | 49 +++++++------------ .../src/pages/Dashboard/Dashboard.js | 25 +++++++--- 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/package.json b/components/device-mgt/io.entgra.device.mgt.ui/react-app/package.json index 3f4470ef19..2471a872d9 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/package.json +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/package.json @@ -17,12 +17,11 @@ "moment": "latest", "prop-types": "latest", "rc-viewer": "0.0.9", - "react-advanced-datetimerange-picker": "^1.0.8", + "react-bootstrap": "^1.0.0-beta.12", "react-highlight-words": "^0.16.0", "react-image-viewer-zoom": "^1.0.36", "react-infinite-scroller": "^1.2.4", "react-leaflet": "^2.4.0", - "react-bootstrap": "^1.0.0-beta.12", "react-moment": "^0.9.2", "react-router": "^5.0.1", "react-router-config": "^5.0.1", @@ -31,6 +30,7 @@ "react-star-ratings": "^2.3.0", "react-twemoji": "^0.2.3", "react-virtualized": "^9.21.1", + "react-websocket": "^2.1.0", "reqwest": "^2.0.5", "storm-react-diagrams": "^5.2.1" }, diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Geo/geo-dashboard/GeoDashboard.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Geo/geo-dashboard/GeoDashboard.js index 63367f3afd..07be907074 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Geo/geo-dashboard/GeoDashboard.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Geo/geo-dashboard/GeoDashboard.js @@ -18,8 +18,7 @@ import React from "react"; import moment from "moment"; -import DateTimeRangeContainer from "react-advanced-datetimerange-picker"; -import {Button, Select, message, notification, Tag, Tooltip, Empty} from "antd"; +import {Button, Select, message, notification, Tag, Tooltip, Empty, DatePicker} from "antd"; import axios from "axios"; import {withConfigContext} from "../../../context/ConfigContext"; import GeoCustomMap from "../geo-custom-map/GeoCustomMap"; @@ -29,15 +28,16 @@ class GeoDashboard extends React.Component { constructor(props) { super(props); - let start = moment(new Date()); + let start = moment( + new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 0, 0, 0, 0) + ); let end = moment(start) - .add(5, "days") - .subtract(1, "minute"); + .add(1, "days") + .subtract(1, "seconds"); this.state = { deviceData: [], selectedDevice: '', locationData: [], - // currentLocation: [], loading: false, start: start, end: end, @@ -55,11 +55,11 @@ class GeoDashboard extends React.Component { * @param startDate - start date * @param endDate - end date */ - applyCallback = (startDate, endDate) => { + applyCallback = (dates, dateStrings) => { console.log("Apply Callback"); this.setState({ - start: startDate, - end: endDate + start: dateStrings[0], + end: dateStrings[1] }); }; @@ -180,6 +180,7 @@ class GeoDashboard extends React.Component { */ controllerBar = () => { + const {RangePicker} = DatePicker; let now = new Date(); let start = moment( new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0) @@ -199,32 +200,20 @@ class GeoDashboard extends React.Component { "2 Weeks": [moment(start).subtract(14, "days"), moment(end)], "1 Month": [moment(start).subtract(1, "months"), moment(end)], }; - let local = { - format: "DD-MM-YYYY HH:mm", - sundayFirst: false - }; - let maxDate = moment(start).add(24, "hour"); - let value = - ` - ${this.state.start.format("DD-MM-YYYY HH:mm")} - ${this.state.end.format("DD-MM-YYYY HH:mm")} - `; + let {deviceData} = this.state; return (
    + - - {value} - - + />
    ); diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js index f411c0782a..1fdaedec49 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js @@ -18,7 +18,7 @@ import React from "react"; import axios from "axios"; -import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider} from "antd"; +import { message, notification, Table, Typography} from "antd"; import TimeAgo from 'javascript-time-ago' // Load locale-specific relative date/time formatting rules. @@ -164,7 +164,6 @@ class GroupsTable extends React.Component { loading={loading} onChange={this.handleTableChange} rowSelection={this.rowSelection} - scroll={{x: 1000}} /> ); diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Policies/PoliciesTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Policies/PoliciesTable.js index 29394b9cde..5a1fbb3692 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Policies/PoliciesTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Policies/PoliciesTable.js @@ -18,7 +18,7 @@ import React from "react"; import axios from "axios"; -import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider} from "antd"; +import {message, notification, Table, Typography} from "antd"; import TimeAgo from 'javascript-time-ago' // Load locale-specific relative date/time formatting rules. @@ -171,7 +171,6 @@ class PoliciesTable extends React.Component { loading={loading} onChange={this.handleTableChange} rowSelection={this.rowSelection} - scroll={{x: 1000}} /> ); diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Roles/RolesTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Roles/RolesTable.js index 6808350646..1080cddddb 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Roles/RolesTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Roles/RolesTable.js @@ -126,16 +126,26 @@ class RolesTable extends React.Component { render() { const {data, pagination, loading, selectedRows} = this.state; - + const { Meta } = Card; const itemCard = data.map((data) => - - - {data} - + + , + ,]} + > + } + title={data} + /> + ); return ( -
    +
    {itemCard} diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersDevices.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersDevices.js index 13ce62e98e..75529becc1 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersDevices.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersDevices.js @@ -240,7 +240,6 @@ class UsersDevices extends React.Component { loading={loading} onChange={this.handleTableChange} rowSelection={this.rowSelection} - scroll={{x: 1000}} />
    ); diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersTable.js index ac7fc9c66a..a1651111ff 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersTable.js @@ -18,7 +18,7 @@ import React from "react"; import axios from "axios"; -import {message, notification, Table, Typography, Panel, Collapse, Button, List, Modal, Icon} from "antd"; +import {message, notification, Table, Typography, Panel, Collapse, Button, List, Modal, Icon, Tabs} from "antd"; import TimeAgo from 'javascript-time-ago' // Load locale-specific relative date/time formatting rules. @@ -174,9 +174,9 @@ class UsersTable extends React.Component { }; render() { - const {data, pagination, loading, selectedRows} = this.state; const { Panel } = Collapse; + const { TabPane } = Tabs; const columns = [ { title: 'User Name', @@ -231,30 +231,44 @@ class UsersTable extends React.Component { loading={loading} onChange={this.handleTableChange} rowSelection={this.rowSelection} - scroll={{x: 1000}} />
    - - + + + + Roles + + } + key="1" + > {item}} /> - - + + + + Enrolled Devices + + } + key="2" + > - - + +
    From 9807a360989102f43d3480bb10128f5bc93f7216 Mon Sep 17 00:00:00 2001 From: Jayasanka Weerasinghe Date: Thu, 24 Oct 2019 15:37:29 +0000 Subject: [PATCH 05/11] Add ui improvements to APPM Publisher UI The following changes are with this commit - View subscription status of devices in release view - Display server error response in add new app form --- .../AppDetailsDrawer/AppDetailsDrawer.js | 55 +++++++++++++++---- .../apps/list-apps/appsTable/AppsTable.js | 32 +++++++++-- .../apps/release/InstalledDevicesTable.js | 20 +------ .../components/apps/release/ReleaseView.js | 5 +- 4 files changed, 76 insertions(+), 36 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppDetailsDrawer/AppDetailsDrawer.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppDetailsDrawer/AppDetailsDrawer.js index 335e1c46dd..fc54ab399b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppDetailsDrawer/AppDetailsDrawer.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppDetailsDrawer/AppDetailsDrawer.js @@ -30,7 +30,7 @@ import { Spin, message, Icon, - Card + Card, Badge } from 'antd'; import DetailedRating from "../../detailed-rating/DetailedRating"; import {Link} from "react-router-dom"; @@ -487,18 +487,14 @@ class AppDetailsDrawer extends React.Component { )} Releases - {/*display add new release only if app type is enterprise*/} -
    - - {(app.type === "ENTERPRISE") && ( - )} (
    @@ -507,7 +503,27 @@ class AppDetailsDrawer extends React.Component { +
    + {(release.currentStatus === "PUBLISHED") ? ( + + }> + + + ) : ( + + )} +
    } title={release.version} description={ @@ -529,10 +545,27 @@ class AppDetailsDrawer extends React.Component {
    )} /> -
    + {/*display add new release only if app type is enterprise*/} + {(app.type === "ENTERPRISE") && ( +
    +
    + + Add new release for the application + +
    + + + +
    )} + Description {!isDescriptionEditEnabled && ( diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/appsTable/AppsTable.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/appsTable/AppsTable.js index 24e43a89c6..d008cf5609 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/appsTable/AppsTable.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/appsTable/AppsTable.js @@ -17,7 +17,7 @@ */ import React from "react"; -import {Avatar, Table, Tag, Icon, message, notification, Col} from "antd"; +import {Avatar, Table, Tag, Icon, message, notification, Col, Badge} from "antd"; import axios from "axios"; import pSBC from 'shade-blend-color'; import "./AppsTable.css"; @@ -47,7 +47,31 @@ const columns = [ ); } else { - avatar = ( + const {applicationReleases} = row; + let hasPublishedRelease = false; + for (let i = 0; i < applicationReleases.length; i++) { + if (applicationReleases[i].currentStatus === "PUBLISHED") { + hasPublishedRelease = true; + break; + } + } + avatar = (hasPublishedRelease) ? ( + + }> + + + ) : ( - ) + ); } return (
    {avatar} - {name} + {name}
    ); } }, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/InstalledDevicesTable.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/InstalledDevicesTable.js index 1b6642f3d4..39fd3ef27c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/InstalledDevicesTable.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/InstalledDevicesTable.js @@ -24,6 +24,7 @@ import TimeAgo from 'javascript-time-ago' // Load locale-specific relative date/time formatting rules. import en from 'javascript-time-ago/locale/en' import {withConfigContext} from "../../../context/ConfigContext"; +import {handleApiError} from "../../../js/Utils"; const {Text} = Typography; @@ -180,19 +181,7 @@ class InstalledDevicesTable extends React.Component { } }).catch((error) => { - if (error.hasOwnProperty("response") && error.response.status === 401) { - //todo display a popop with error - message.error('You are not logged in'); - window.location.href = window.location.origin + '/entgra/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to load devices.", - }); - } - + handleApiError(error, "Something went wrong when trying to load subscription data."); this.setState({loading: false}); }); }; @@ -203,10 +192,7 @@ class InstalledDevicesTable extends React.Component {
    - Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque - laudantium, - totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae - dicta sunt explicabo. + The following are the subscription details of the application in each respective device.
    - + From a78d3e17d4b5bf40bf10246818a899a3983c1a91 Mon Sep 17 00:00:00 2001 From: Shamalka Navod Date: Fri, 25 Oct 2019 05:53:07 +0000 Subject: [PATCH 06/11] Group create/edit/delete/share functions --- .../DeviceTypes/DeviceTypesTable.js | 3 +- .../src/components/Devices/DevicesTable.js | 3 +- .../components/Devices/ReportDevicesTable.js | 3 +- .../src/components/Groups/AddGroup.js | 176 ++++++++ .../src/components/Groups/GroupActions.js | 377 ++++++++++++++++++ .../src/components/Groups/GroupsTable.js | 97 +++-- .../src/components/Roles/RolesTable.js | 4 +- .../src/components/Users/UsersDevices.js | 3 +- .../src/components/Users/UsersTable.js | 4 +- .../src/pages/Dashboard/Groups/Groups.js | 1 + .../src/pages/Dashboard/Policies/Policies.js | 2 +- .../service/api/GroupManagementService.java | 2 + 12 files changed, 621 insertions(+), 54 deletions(-) create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/AddGroup.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupActions.js diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/DeviceTypes/DeviceTypesTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/DeviceTypes/DeviceTypesTable.js index 42af8271b7..19a7b3f1b6 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/DeviceTypes/DeviceTypesTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/DeviceTypes/DeviceTypesTable.js @@ -18,9 +18,8 @@ import React from "react"; import axios from "axios"; -import {message, notification, Typography, Icon, Card, Col, Row} from "antd"; +import {Card, Col, Icon, message, notification, Row, Typography} from "antd"; import TimeAgo from 'javascript-time-ago' - // Load locale-specific relative date/time formatting rules. import en from 'javascript-time-ago/locale/en' import {withConfigContext} from "../../context/ConfigContext"; diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/DevicesTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/DevicesTable.js index 38e5444aeb..d129d6a601 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/DevicesTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/DevicesTable.js @@ -18,9 +18,8 @@ import React from "react"; import axios from "axios"; -import {Tag, message, notification, Table, Typography, Tooltip, Icon, Modal, Select} from "antd"; +import {Icon, message, Modal, notification, Select, Table, Tag, Tooltip, Typography} from "antd"; import TimeAgo from 'javascript-time-ago' - // Load locale-specific relative date/time formatting rules. import en from 'javascript-time-ago/locale/en' import {withConfigContext} from "../../context/ConfigContext"; diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/ReportDevicesTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/ReportDevicesTable.js index 604d540e00..61a8635564 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/ReportDevicesTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/ReportDevicesTable.js @@ -18,9 +18,8 @@ import React from "react"; import axios from "axios"; -import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider} from "antd"; +import {Icon, message, notification, Table, Tag, Tooltip, Typography} from "antd"; import TimeAgo from 'javascript-time-ago' - // Load locale-specific relative date/time formatting rules. import en from 'javascript-time-ago/locale/en' import {withConfigContext} from "../../context/ConfigContext"; diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/AddGroup.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/AddGroup.js new file mode 100644 index 0000000000..00db115bec --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/AddGroup.js @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. 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. + */ + +import React from "react"; +import {Button, Form, Input, message, Modal, notification, Typography} from "antd"; +import axios from "axios"; +import {withConfigContext} from "../../context/ConfigContext"; + +const {Text} = Typography; +let config = null; + +class AddGroup extends React.Component { + + constructor(props) { + super(props); + config = this.props.context; + this.state = { + addModalVisible: false, + name:'', + description:'', + } + } + + onConfirmAdGroup = () => { + const config = this.props.context; + + const groupData = { + name: this.state.name, + description: this.state.description + } + + //send request to the invoker + axios.post( + window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.deviceMgt + + "/groups", + groupData, + {headers: {'Content-Type': 'application/json'}} + ).then(res => { + if (res.status === 201) { + this.props.fetchGroups(); + notification["success"]({ + message: "Done", + duration: 4, + description: + "Successfully added the group.", + }); + } + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + //todo display a popop with error + message.error('You are not logged in'); + window.location.href = window.location.origin + '/entgra/login'; + } else { + notification["error"]({ + message: "There was a problem", + duration: 0, + description: + "Error occurred while trying to add group.", + }); + } + }); + }; + + openAddModal = () => { + this.setState({ + addModalVisible:true + }) + }; + + handleAddOk = e => { + this.props.form.validateFields(err => { + if (!err) { + this.onConfirmAdGroup(); + this.setState({ + addModalVisible: false, + }); + } + }); + }; + + handleAddCancel = e => { + this.setState({ + addModalVisible: false, + }); + }; + + onChangeName = (e) => { + this.setState({ + name:e.currentTarget.value + }) + }; + + onChangeDescription = (e) => { + this.setState({ + description:e.currentTarget.value + }) + }; + + render() { + const { getFieldDecorator } = this.props.form; + return( +
    +
    + +
    +
    + + Cancel + , + , + ]} + > +
    +

    Create new device group on IoT Server.

    +
    + + {getFieldDecorator('name', { + rules: [ + { + required: true, + message: 'Please input group name', + }, + ], + })()} + + + {getFieldDecorator('description', { + rules: [ + { + required: true, + message: 'Please input group description', + }, + ], + })()} + + +
    +
    +
    +
    + ) + } +} + +export default withConfigContext(Form.create({name: 'add-group'})(AddGroup)); \ No newline at end of file diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupActions.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupActions.js new file mode 100644 index 0000000000..3a3e6e83b5 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupActions.js @@ -0,0 +1,377 @@ +/* + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. 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. + */ + +import React from "react"; +import { + Button, + Divider, + Form, + Icon, + Input, + message, + Modal, + notification, + Popconfirm, + Select, + Tooltip, + Typography +} from "antd"; +import axios from "axios"; +import {withConfigContext} from "../../context/ConfigContext"; + +const {Text} = Typography; +let config = null; + +class GroupActions extends React.Component { + + constructor(props) { + super(props); + config = this.props.context; + this.state = { + editModalVisible: false, + shareModalVisible: false, + name:this.props.data.name, + description:this.props.data.description, + groupDataObject:{}, + rolesData:[], + shareRolesData:[] + } + } + + onConfirmDeleteGroup = () => { + const config = this.props.context; + + //send request to the invoker + axios.delete( + window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.deviceMgt + + "/groups/id/" + this.props.data.id, + {headers: {'Content-Type': 'application/json'}} + + ).then(res => { + if (res.status === 200) { + this.props.fetchGroups(); + notification["success"]({ + message: "Done", + duration: 4, + description: + "Successfully deleted the group.", + }); + } + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + //todo display a popop with error + message.error('You are not logged in'); + window.location.href = window.location.origin + '/entgra/login'; + } else { + notification["error"]({ + message: "There was a problem", + duration: 0, + description: + "Error occurred while trying to delete group.", + }); + } + }); + }; + + onConfirmUpdateGroup = (data) => { + const config = this.props.context; + + //send request to the invoker + axios.put( + window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.deviceMgt + + "/groups/id/" + this.props.data.id, + data + ).then(res => { + if (res.status === 200) { + this.props.fetchGroups(); + notification["success"]({ + message: "Done", + duration: 4, + description: + "Successfully updated the group.", + }); + } + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + //todo display a popop with error + message.error('You are not logged in'); + window.location.href = window.location.origin + '/entgra/login'; + } else { + notification["error"]({ + message: "There was a problem", + duration: 0, + description: + "Error occurred while trying to update group.", + }); + } + }); + }; + + fetchUserRoles = (params = {}) => { + const config = this.props.context; + + const apiUrl = window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.deviceMgt + + "/roles"; + + //send request to the invokerss + axios.get(apiUrl).then(res => { + if (res.status === 200) { + this.setState({ + rolesData: res.data.data.roles, + }); + } + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + //todo display a popop with error + message.error('You are not logged in'); + window.location.href = window.location.origin + '/entgra/login'; + } else { + notification["error"]({ + message: "There was a problem", + duration: 0, + description:"Error occurred while trying to load roles.", + }); + } + }); + }; + + onConfirmShareGroup = (data) => { + const config = this.props.context; + + //send request to the invoker + axios.post( + window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.deviceMgt + + "/groups/id/" + this.props.data.id + "/share", + data + ).then(res => { + if (res.status === 200) { + this.props.fetchGroups(); + notification["success"]({ + message: "Done", + duration: 4, + description: + "Successfully shared the group.", + }); + } + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + //todo display a popop with error + message.error('You are not logged in'); + window.location.href = window.location.origin + '/entgra/login'; + } else { + notification["error"]({ + message: "There was a problem", + duration: 0, + description: + "Error occurred while trying to share group.", + }); + } + }); + } + + openEditModal = () => { + this.setState({ + editModalVisible:true + }) + }; + + openShareModal = () => { + this.fetchUserRoles(); + this.setState({ + shareModalVisible:true + }) + } + + handleEditOk = e => { + this.state.groupDataObject = { + name:this.state.name, + description:this.state.description, + id:this.props.data.id, + owner:this.props.data.owner, + groupProperties:this.props.data.groupProperties + }; + this.props.form.validateFields(err => { + if (!err) { + this.onConfirmUpdateGroup(this.state.groupDataObject); + this.setState({ + editModalVisible: false, + }); + } + }); + }; + + handleEditCancel = e => { + this.setState({ + editModalVisible: false, + }); + }; + + handleShareOk = e => { + this.setState({ + shareModalVisible: false, + }); + this.onConfirmShareGroup(this.state.shareRolesData); + }; + + handleShareCancel = e => { + this.setState({ + shareModalVisible: false, + }); + }; + + onChangeName = (e) => { + this.setState({ + name:e.currentTarget.value + }) + }; + + onChangeDescription = (e) => { + this.setState({ + description:e.currentTarget.value + }) + }; + + handleRolesDropdownChange = (value) => { + this.setState({ + shareRolesData:value + }) + }; + + render() { + const isAdminGroups = this.props.data.id==1 || this.props.data.id==2; + const { Option } = Select; + const { getFieldDecorator } = this.props.form; + let item = this.state.rolesData.map((data) => + + {data} + ); + return( +
    +
    + + + + + + + + + + + + + +
    +
    + + Cancel + , + , + ]} + > +
    +

    Enter new name and description for the group

    +
    + + {getFieldDecorator( + 'name', + { + initialValue: this.props.data.name, + rules: [ + { + required: true, + message: 'Please input group name', + }, + ], + })()} + + + {getFieldDecorator( + 'description', + { + initialValue: this.props.data.description, + rules: [ + { + required: true, + message: 'Please input group description', + }, + ], + })()} + + +
    +
    +
    +
    + + Cancel + , + , + ]} + > + , + + +
    +
    + ) + } +} + +export default withConfigContext(Form.create({name: 'group-actions'})(GroupActions)); \ No newline at end of file diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js index 1fdaedec49..6bc8d6527a 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js @@ -18,40 +18,19 @@ import React from "react"; import axios from "axios"; -import { message, notification, Table, Typography} from "antd"; +import {message, notification, Table, Typography} from "antd"; import TimeAgo from 'javascript-time-ago' - // Load locale-specific relative date/time formatting rules. import en from 'javascript-time-ago/locale/en' import {withConfigContext} from "../../context/ConfigContext"; +import GroupActions from "./GroupActions"; +import AddGroup from "./AddGroup"; const {Text} = Typography; let config = null; let apiUrl; -const columns = [ - { - title: 'Group Name', - dataIndex: 'name', - width: 100, - }, - { - title: 'Owner', - dataIndex: 'owner', - key: 'owner', - // render: enrolmentInfo => enrolmentInfo.owner - // todo add filtering options - }, - { - title: 'Description', - dataIndex: 'description', - key: 'description', - // render: enrolmentInfo => enrolmentInfo.ownership - // todo add filtering options - } -]; - const getTimeAgo = (time) => { const timeAgo = new TimeAgo('en-US'); return timeAgo.format(time); @@ -70,6 +49,38 @@ class GroupsTable extends React.Component { }; } + columns = [ + { + title: 'Group Name', + dataIndex: 'name', + width: 100, + }, + { + title: 'Owner', + dataIndex: 'owner', + key: 'owner', + // render: enrolmentInfo => enrolmentInfo.owner + // todo add filtering options + }, + { + title: 'Description', + dataIndex: 'description', + key: 'description', + // render: enrolmentInfo => enrolmentInfo.ownership + // todo add filtering options + }, + { + title: 'Action', + dataIndex: 'id', + key: 'action', + render: (id, row) => ( + + + + ), + }, + ]; + rowSelection = { onChange: (selectedRowKeys, selectedRows) => { this.setState({ @@ -130,6 +141,8 @@ class GroupsTable extends React.Component { }); }; + + handleTableChange = (pagination, filters, sorter) => { const pager = {...this.state.pagination}; pager.current = pagination.current; @@ -148,23 +161,29 @@ class GroupsTable extends React.Component { render() { const {data, pagination, loading, selectedRows} = this.state; + return (
    -
    (record.id)} - dataSource={data} - pagination={{ - ...pagination, - size: "small", - // position: "top", - showTotal: (total, range) => `showing ${range[0]}-${range[1]} of ${total} groups` - // showQuickJumper: true - }} - loading={loading} - onChange={this.handleTableChange} - rowSelection={this.rowSelection} - /> +
    + +
    +
    +
    (record.id)} + dataSource={data} + pagination={{ + ...pagination, + size: "small", + // position: "top", + showTotal: (total, range) => `showing ${range[0]}-${range[1]} of ${total} groups` + // showQuickJumper: true + }} + loading={loading} + onChange={this.handleTableChange} + rowSelection={this.rowSelection} + /> + ); } diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Roles/RolesTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Roles/RolesTable.js index 1080cddddb..3d85bbe344 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Roles/RolesTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Roles/RolesTable.js @@ -18,9 +18,8 @@ import React from "react"; import axios from "axios"; -import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider, Card, Col, Row, Select} from "antd"; +import {Card, Col, Icon, message, notification, Row, Typography} from "antd"; import TimeAgo from 'javascript-time-ago' - // Load locale-specific relative date/time formatting rules. import en from 'javascript-time-ago/locale/en' import {withConfigContext} from "../../context/ConfigContext"; @@ -124,7 +123,6 @@ class RolesTable extends React.Component { }; render() { - const {data, pagination, loading, selectedRows} = this.state; const { Meta } = Card; const itemCard = data.map((data) => diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersDevices.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersDevices.js index 75529becc1..eca727ac9a 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersDevices.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersDevices.js @@ -18,9 +18,8 @@ import React from "react"; import axios from "axios"; -import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider} from "antd"; +import {Icon, message, notification, Table, Tag, Tooltip, Typography} from "antd"; import TimeAgo from 'javascript-time-ago' - // Load locale-specific relative date/time formatting rules. import en from 'javascript-time-ago/locale/en' import {withConfigContext} from "../../context/ConfigContext"; diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersTable.js index a1651111ff..6684329e67 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersTable.js @@ -18,13 +18,11 @@ import React from "react"; import axios from "axios"; -import {message, notification, Table, Typography, Panel, Collapse, Button, List, Modal, Icon, Tabs} from "antd"; +import {Button, Collapse, Icon, List, message, Modal, notification, Table, Tabs, Typography} from "antd"; import TimeAgo from 'javascript-time-ago' - // Load locale-specific relative date/time formatting rules. import en from 'javascript-time-ago/locale/en' import {withConfigContext} from "../../context/ConfigContext"; -import DeviceTable from "../Devices/DevicesTable"; import UsersDevices from "./UsersDevices"; const {Text} = Typography; diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Groups/Groups.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Groups/Groups.js index b96f869872..b259c3256a 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Groups/Groups.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Groups/Groups.js @@ -25,6 +25,7 @@ import { } from "antd"; import {Link} from "react-router-dom"; import GroupsTable from "../../../components/Groups/GroupsTable"; +import AddGroup from "../../../components/Groups/AddGroup"; const {Paragraph} = Typography; diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Policies/Policies.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Policies/Policies.js index 7c32b7a0a2..09955efb4d 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Policies/Policies.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Policies/Policies.js @@ -55,7 +55,7 @@ class Policies extends React.Component {
    - +

    sghdfugjhskf

    ); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java index 0e5673dd29..9ea2e4b2bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java @@ -458,8 +458,10 @@ public interface GroupManagementService { @Path("/id/{groupId}") @DELETE + @Consumes(MediaType.WILDCARD) @ApiOperation( produces = MediaType.APPLICATION_JSON, + consumes = MediaType.WILDCARD, httpMethod = HTTPConstants.HEADER_DELETE, value = "Deleting a Group", notes = "If you wish to remove an existing group, that can be done by updating the group using this API.", From 2c2584bcaed859843ee987a7fd925a0953bc1fba Mon Sep 17 00:00:00 2001 From: Shamalka Navod Date: Fri, 25 Oct 2019 10:13:17 +0000 Subject: [PATCH 07/11] Add devicemgt React app UI improvements --- .../src/components/Groups/AddGroup.js | 5 ++--- .../src/components/Groups/GroupActions.js | 18 ++++++++++-------- .../src/components/Groups/GroupsTable.js | 4 ++-- .../src/pages/Dashboard/Policies/Policies.js | 2 +- .../react-app/src/pages/Login.js | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/AddGroup.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/AddGroup.js index 00db115bec..d828d20a88 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/AddGroup.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/AddGroup.js @@ -124,7 +124,7 @@ class AddGroup extends React.Component {
    Create new device group on IoT Server.

    {getFieldDecorator('name', { diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupActions.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupActions.js index 3a3e6e83b5..b82489a14a 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupActions.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupActions.js @@ -291,7 +291,7 @@ class GroupActions extends React.Component {
    Enter new name and description for the group

    {getFieldDecorator( @@ -351,22 +350,25 @@ class GroupActions extends React.Component { onOk={this.handleShareOk} onCancel={this.handleShareCancel} footer={[ - , + , , ]} > +

    Select user role(s)

    , -
    diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js index 6bc8d6527a..cf782973b3 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js @@ -164,8 +164,8 @@ class GroupsTable extends React.Component { return (
    -
    - +
    +
    -

    sghdfugjhskf

    +
    ); diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Login.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Login.js index 19bbf40a27..3ac1408ba0 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Login.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Login.js @@ -157,7 +157,7 @@ class NormalLoginForm extends React.Component { )}
    Forgot password - From 7f5325b8bb5fe76cc81be0e06e7395f392f05778 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Fri, 25 Oct 2019 17:07:21 +0530 Subject: [PATCH 08/11] fix for corrective policy --- .../wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java index 0d31dc2e07..714421c431 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java @@ -155,8 +155,8 @@ public class PolicyManagerUtil { PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl(); try { Policy correctivePolicy = pap.getPolicy(correctiveAction.getPolicyId()); - if (correctivePolicy == null || PolicyManagementConstants.CORRECTIVE_POLICY_TYPE - .equalsIgnoreCase(correctivePolicy.getPolicyType())) { + if (correctivePolicy == null || !PolicyManagementConstants.CORRECTIVE_POLICY_TYPE + .equalsIgnoreCase(correctivePolicy.getPolicyType() )) { String msg = "No corrective policy was found for the policy " + policy.getPolicyName() + " and policy ID " + policy.getId(); log.error(msg); From 35be7cc79597bfa8b82517cfc59b60813badf182 Mon Sep 17 00:00:00 2001 From: nipunnadeen Date: Fri, 25 Oct 2019 21:49:13 +0530 Subject: [PATCH 09/11] Fix the mysql based syntax issues --- .../dbscripts/cdm/application-mgt/mysql.sql | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 383210ef9f..3ca9a0c985 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS AP_APP( ID INTEGER NOT NULL AUTO_INCREMENT, NAME VARCHAR(45) NOT NULL, - DESCRIPTION CLOB NULL, + DESCRIPTION VARCHAR(200) NOT NULL, TYPE VARCHAR(200) NOT NULL, TENANT_ID INTEGER NOT NULL, STATUS VARCHAR(45) NOT NULL DEFAULT 'ACTIVE', @@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS AP_APP( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS AP_APP_RELEASE( ID INTEGER NOT NULL AUTO_INCREMENT, - DESCRIPTION CLOB NOT NULL, + DESCRIPTION VARCHAR(200) NOT NULL, VERSION VARCHAR(70) NOT NULL, TENANT_ID INTEGER NOT NULL, UUID VARCHAR(200) NOT NULL, @@ -35,7 +35,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_RELEASE( SC_3_LOCATION VARCHAR(100) NULL DEFAULT NULL, APP_HASH_VALUE VARCHAR(1000) NOT NULL, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, - APP_META_INFO CLOB NULL DEFAULT NULL, + APP_META_INFO VARCHAR(150) NULL DEFAULT NULL, SUPPORTED_OS_VERSIONS VARCHAR(45) NOT NULL, RATING DOUBLE NULL DEFAULT NULL, CURRENT_STATE VARCHAR(45) NOT NULL, @@ -57,8 +57,8 @@ CREATE TABLE IF NOT EXISTS AP_APP_REVIEW( COMMENT TEXT NOT NULL, ROOT_PARENT_ID INTEGER NOT NULL, IMMEDIATE_PARENT_ID INTEGER NOT NULL, - CREATED_AT TIMESTAMP NOT NULL, - MODIFIED_AT TIMESTAMP NOT NULL, + CREATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + MODIFIED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, RATING INTEGER NULL, USERNAME VARCHAR(45) NOT NULL, ACTIVE_REVIEW BOOLEAN NOT NULL DEFAULT TRUE, @@ -267,14 +267,11 @@ CREATE TABLE IF NOT EXISTS AP_SCHEDULED_SUBSCRIPTION( ID INTEGER NOT NULL AUTO_INCREMENT, TASK_NAME VARCHAR(100) NOT NULL, APPLICATION_UUID VARCHAR(36) NOT NULL, - SUBSCRIBER_LIST LONGVARCHAR NOT NULL, + SUBSCRIBER_LIST TEXT NOT NULL, STATUS VARCHAR(15) NOT NULL, - SCHEDULED_AT TIMESTAMP NOT NULL, + SCHEDULED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, SCHEDULED_BY VARCHAR(100) NOT NULL, - SCHEDULED_TIMESTAMP TIMESTAMP NOT NULL, + SCHEDULED_TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, DELETED BOOLEAN, - PRIMARY KEY (ID), - CONSTRAINT fk_AP_SCHEDULED_SUBSCRIPTION_AP_APP_RELEASE - FOREIGN KEY (APPLICATION_UUID) - REFERENCES AP_APP_RELEASE (UUID) ON DELETE NO ACTION ON UPDATE NO ACTION -); + PRIMARY KEY (ID) +); \ No newline at end of file From d6845cd40a0438356fd38c959b748502b8b5f943 Mon Sep 17 00:00:00 2001 From: charitha Date: Sat, 26 Oct 2019 01:03:44 +0530 Subject: [PATCH 10/11] Add new API endpoints - Change device status as bulk - Get total device count - Add group with different owner --- .../service/api/DeviceManagementService.java | 35 +++------ .../admin/DeviceManagementAdminService.java | 55 +++++++++++++ .../admin/GroupManagementAdminService.java | 77 ++++++++++++++++++- .../impl/DeviceManagementServiceImpl.java | 38 +++------ .../DeviceManagementAdminServiceImpl.java | 32 +++++++- .../GroupManagementAdminServiceImpl.java | 28 ++++++- .../DeviceManagementProviderService.java | 6 +- .../DeviceManagementProviderServiceImpl.java | 17 ++-- 8 files changed, 217 insertions(+), 71 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index 3531154a6e..f80d3326fe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -1713,16 +1713,16 @@ public interface DeviceManagementService { @Valid OperationRequest operationRequest); @GET - @Path("/status/count/{tenantDomain}/{type}/{status}") + @Path("/type/{type}/status/{status}/count") @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Get Device Count with status", - notes = "Get specified device count with status.", + notes = "Get specified device count with type and status.", tags = "Device Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:details") + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") }) } ) @@ -1730,7 +1730,7 @@ public interface DeviceManagementService { value = { @ApiResponse( code = 200, - message = "OK. \n Successfully fetched the details of the device.", + message = "OK. \n Successfully fetched the count of matching devices.", response = int.class, responseHeaders = { @ResponseHeader( @@ -1764,13 +1764,6 @@ public interface DeviceManagementService { response = ErrorResponse.class) }) Response getDeviceCountByStatus( - @ApiParam( - name = "tenantDomain", - value = "The tenant doamin.", - required = true) - @PathParam("tenantDomain") - @Size(max = 45) - String tenantDomain, @ApiParam( name = "type", value = "The device type name, such as ios, android, windows or fire-alarm.", @@ -1788,17 +1781,16 @@ public interface DeviceManagementService { @GET - @Path("/status/ids/{tenantDomain}/{type}/{status}") + @Path("/type/{type}/status/{status}/ids") @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", - value = "Getting Details of a Device", - notes = "Get the details of a device by specifying the device type and device identifier and optionally " + - "the owner.", + value = "Getting ids of devices with specified type and status", + notes = "Get the ids of a device by specifying the device type and status.", tags = "Device Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:details") + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") }) } ) @@ -1840,13 +1832,6 @@ public interface DeviceManagementService { response = ErrorResponse.class) }) Response getDeviceIdentifiersByStatus( - @ApiParam( - name = "tenantDomain", - value = "The tenant domain.", - required = true) - @PathParam("tenantDomain") - @Size(max = 45) - String tenantDomain, @ApiParam( name = "type", value = "The device type name, such as ios, android, windows or fire-alarm.", @@ -1863,7 +1848,7 @@ public interface DeviceManagementService { String status); @PUT - @Path("/status/update/{tenantDomain}/{type}/{status}") + @Path("/type/{type}/status/{status}") @ApiOperation( produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON, @@ -1915,8 +1900,6 @@ public interface DeviceManagementService { response = ErrorResponse.class) }) Response bulkUpdateDeviceStatus( - @ApiParam(name = "tenantDomain", value = "The tenant domain.", required = true) - @PathParam("tenantDomain") String tenantDomain, @ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true) @PathParam("type") String type, @ApiParam(name = "status", value = "The device type, such as ios, android or windows.", required = true) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java index 1ac3169189..29d8a2cb43 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java @@ -45,9 +45,11 @@ import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ResponseHeader; +import org.apache.axis2.transport.http.HTTPConstants; import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; @@ -198,6 +200,59 @@ public interface DeviceManagementAdminService { defaultValue = "5") @QueryParam("limit") int limit); + @Path("/count") + @GET + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = HTTPConstants.HEADER_GET, + value = "Get the count of devices.", + notes = "Returns count of all devices enrolled with the system.", + tags = "Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:devices:view") + }) + } + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device count.", + response = Integer.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client has already the latest version of " + + "the requested resource."), + @ApiResponse( + code = 404, + message = "No groups found.", + response = ErrorResponse.class), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching the device count.", + response = ErrorResponse.class) + }) + Response getDeviceCount(@ApiParam( + name = "status", + value = "status of group of which count should be retrieved") + @QueryParam("status") + String status); + + @PUT @Path("/device-owner") @ApiOperation( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java index c42739f296..304a00d380 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java @@ -33,10 +33,12 @@ import io.swagger.annotations.ResponseHeader; import org.apache.axis2.transport.http.HTTPConstants; import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; +import javax.validation.Valid; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -75,6 +77,12 @@ import javax.ws.rs.core.Response; description = "", key = "perm:admin-groups:count", permissions = {"/device-mgt/admin/groups/view"} + ), + @Scope( + name = "Add groups", + description = "", + key = "perm:admin-groups:add", + permissions = {"/device-mgt/admin/groups/add"} ) } ) @@ -166,7 +174,7 @@ public interface GroupManagementAdminService { ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.", - response = DeviceGroupList.class, + response = Integer.class, responseHeaders = { @ResponseHeader( name = "Content-Type", @@ -202,4 +210,71 @@ public interface GroupManagementAdminService { @QueryParam("status") String status); + @POST + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = HTTPConstants.HEADER_POST, + value = "Adding a New Device Group", + notes = "Add device group with the current user as the owner.", + tags = "Device Group Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:admin-groups:add") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 201, + message = "Created. \n Device group has successfully been created", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL of the added group."), + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time" + + ".\n" + "Used by caches, or in conditional requests.") + } + ), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location " + + "header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 401, + message = "Unauthorized. \n Current logged in user is not authorized to add device groups.", + response = ErrorResponse.class), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported " + + "format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new device group.", + response = ErrorResponse.class) + }) + Response createGroup(@ApiParam( + name = "group", + value = "Define the group object with data.", + required = true) + @Valid DeviceGroup group); + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index ef89eb6ef8..c058b1ac69 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -973,66 +973,48 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @GET @Override - @Path("/status/count/{tenantDomain}/{type}/{status}") - public Response getDeviceCountByStatus(@PathParam("tenantDomain") String tenantDomain, @PathParam("type") String type, @PathParam("status") String status) { + @Path("/type/{type}/status/{status}/count") + public Response getDeviceCountByStatus(@PathParam("type") String type, @PathParam("status") String status) { int deviceCount; try { - int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain); - deviceCount = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCountOfTypeByStatus(tenantId, type, status); + deviceCount = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCountOfTypeByStatus(type, status); return Response.status(Response.Status.OK).entity(deviceCount).build(); } catch (DeviceManagementException e) { String errorMessage = "Error while retrieving device count."; log.error(errorMessage, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); - } catch (UserStoreException e) { - String errorMessage = "Error resolving tenant Domain"; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @GET @Override - @Path("/status/ids/{tenantDomain}/{type}/{status}") - public Response getDeviceIdentifiersByStatus(@PathParam("tenantDomain") String tenantDomain, @PathParam("type") String type, @PathParam("status") String status) { + @Path("/type/{type}/status/{status}/ids") + public Response getDeviceIdentifiersByStatus(@PathParam("type") String type, @PathParam("status") String status) { List deviceIds; try { - int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain); - deviceIds = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceIdentifiersByStatus(tenantId, type, status); + deviceIds = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceIdentifiersByStatus(type, status); return Response.status(Response.Status.OK).entity(deviceIds.toArray(new String[0])).build(); } catch (DeviceManagementException e) { String errorMessage = "Error while obtaining list of devices"; log.error(errorMessage, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); - } catch (UserStoreException e) { - String errorMessage = "Error resolving tenant Domain"; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @PUT @Override - @Path("/status/update/{tenantDomain}/{type}/{status}") - public Response bulkUpdateDeviceStatus(@PathParam("tenantDomain") String tenantDomain, @PathParam("type") String type, - @PathParam("status") String status, @Valid List deviceList) { + @Path("/type/{type}/status/{status}") + public Response bulkUpdateDeviceStatus(@PathParam("type") String type, @PathParam("status") String status, + @Valid List deviceList) { try { - int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain); - DeviceMgtAPIUtils.getDeviceManagementService().bulkUpdateDeviceStatus(tenantId, type, deviceList, status); + DeviceMgtAPIUtils.getDeviceManagementService().bulkUpdateDeviceStatus(type, deviceList, status); } catch (DeviceManagementException e) { String errorMessage = "Error while updating device status in bulk."; log.error(errorMessage, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); - } catch (UserStoreException e) { - String errorMessage = "Error resolving tenant Domain"; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } return Response.status(Response.Status.OK).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java index 4b30cb4112..9533c43a42 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java @@ -40,10 +40,10 @@ import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; -import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; @@ -53,7 +53,13 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import javax.validation.constraints.Size; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; @@ -107,6 +113,26 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } } + @Override + @Path("/count") + @GET + public Response getDeviceCount(@QueryParam("status") String status) { + int deviceCount; + try { + if (status == null) { + deviceCount = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCount(); + } else { + deviceCount = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCount(EnrolmentInfo.Status.valueOf(status)); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while fetching device count."; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + return Response.status(Response.Status.OK).entity(deviceCount).build(); + } + @PUT @Override @Path("/device-owner") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java index dcb0238204..1971890b43 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java @@ -20,9 +20,11 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.common.StringUtils; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; +import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.GroupManagementAdminService; @@ -36,6 +38,10 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ private static final Log log = LogFactory.getLog(GroupManagementAdminServiceImpl.class); + private static final String DEFAULT_ADMIN_ROLE = "admin"; + private static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/admin/groups", + "/permission/device-mgt/user/groups"}; + @Override public Response getGroups(String name, String owner, int offset, int limit, String status) { try { @@ -84,4 +90,24 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } + + @Override + public Response createGroup(DeviceGroup group) { + if (group == null) { + return Response.status(Response.Status.BAD_REQUEST).build(); + } + group.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE); + try { + DeviceMgtAPIUtils.getGroupManagementProviderService().createGroup(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS); + return Response.status(Response.Status.CREATED).build(); + } catch (GroupManagementException e) { + String msg = "Error occurred while adding new group."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (GroupAlreadyExistException e) { + String msg = "Group already exists with name " + group.getName() + "."; + log.warn(msg); + return Response.status(Response.Status.CONFLICT).entity(msg).build(); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 43bb5ba713..8765ed22e5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -752,11 +752,11 @@ public interface DeviceManagementProviderService { List findGeoClusters(String deviceType, GeoCoordinate southWest, GeoCoordinate northEast, int geohashLength) throws DeviceManagementException; - int getDeviceCountOfTypeByStatus(int tenantId, String deviceType, String deviceStatus) throws DeviceManagementException; + int getDeviceCountOfTypeByStatus(String deviceType, String deviceStatus) throws DeviceManagementException; - List getDeviceIdentifiersByStatus(int tenantId, String deviceType, String deviceStatus) throws DeviceManagementException; + List getDeviceIdentifiersByStatus(String deviceType, String deviceStatus) throws DeviceManagementException; - boolean bulkUpdateDeviceStatus(int tenantId, String deviceType, List deviceList, String status) throws DeviceManagementException; + boolean bulkUpdateDeviceStatus(String deviceType, List deviceList, String status) throws DeviceManagementException; boolean updateEnrollment(String owner, List deviceIdentifiers) throws DeviceManagementException, UserNotFoundException, InvalidDeviceException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index a012fff0c8..2669d292bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -3125,10 +3125,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public int getDeviceCountOfTypeByStatus(int tenantId, String deviceType, String deviceStatus) throws DeviceManagementException { + public int getDeviceCountOfTypeByStatus(String deviceType, String deviceStatus) throws DeviceManagementException { try { DeviceManagementDAOFactory.openConnection(); - return deviceDAO.getDeviceCount(deviceType, deviceStatus, tenantId); + return deviceDAO.getDeviceCount(deviceType, deviceStatus, getTenantId()); } catch (DeviceManagementDAOException e) { String msg = "Error occurred in while retrieving device count by status for deviceType :" +deviceType + " status : " + deviceStatus; log.error(msg, e); @@ -3143,11 +3143,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public List getDeviceIdentifiersByStatus(int tenantId, String deviceType, String deviceStatus) throws DeviceManagementException { + public List getDeviceIdentifiersByStatus(String deviceType, String deviceStatus) throws DeviceManagementException { List deviceIds; try { DeviceManagementDAOFactory.openConnection(); - deviceIds = deviceDAO.getDeviceIdentifiers(deviceType, deviceStatus, tenantId); + deviceIds = deviceDAO.getDeviceIdentifiers(deviceType, deviceStatus, getTenantId()); } catch (DeviceManagementDAOException e) { String msg = "Error occurred in while retrieving devices by status for deviceType :" +deviceType + " status : " + deviceStatus; log.error(msg, e); @@ -3163,17 +3163,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public boolean bulkUpdateDeviceStatus(int tenantId, String deviceType, - List deviceList, String status) + public boolean bulkUpdateDeviceStatus(String deviceType, List deviceList, String status) throws DeviceManagementException { boolean success; try { DeviceManagementDAOFactory.openConnection(); - success = deviceDAO.setEnrolmentStatusInBulk(deviceType, status, tenantId, deviceList); + success = deviceDAO.setEnrolmentStatusInBulk(deviceType, status, getTenantId(), deviceList); DeviceManagementDAOFactory.commitTransaction(); } catch (DeviceManagementDAOException e) { - String msg = "Error occurred in while updating status of devices :" + deviceType + " status : " + deviceList - .toString(); + DeviceManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred in while updating status of devices :" + deviceType + " status : " + status; log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (SQLException e) { From 253afa517a06132fb4ae419b4f77a8975ef82bfe Mon Sep 17 00:00:00 2001 From: charitha Date: Sat, 26 Oct 2019 01:42:37 +0530 Subject: [PATCH 11/11] Fix transaction handling --- .../mgt/core/service/DeviceManagementProviderServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 2669d292bb..a2f9a9769e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -3167,7 +3167,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv throws DeviceManagementException { boolean success; try { - DeviceManagementDAOFactory.openConnection(); + DeviceManagementDAOFactory.beginTransaction(); success = deviceDAO.setEnrolmentStatusInBulk(deviceType, status, getTenantId(), deviceList); DeviceManagementDAOFactory.commitTransaction(); } catch (DeviceManagementDAOException e) { @@ -3175,7 +3175,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv String msg = "Error occurred in while updating status of devices :" + deviceType + " status : " + status; log.error(msg, e); throw new DeviceManagementException(msg, e); - } catch (SQLException e) { + } catch (TransactionManagementException e) { String msg = "Error occurred while opening a connection to the data source"; log.error(msg, e); throw new DeviceManagementException(msg, e);