diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/public/conf/config.json b/components/device-mgt/io.entgra.device.mgt.ui/react-app/public/conf/config.json index aa72ba06e4..916421e377 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/public/conf/config.json +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/public/conf/config.json @@ -1,6 +1,6 @@ { "theme": { - "logo" : "https://localhost:9443/entgra/public/images/logo.svg", + "logo" : "https://entgra.io/assets/images/svg/logo.svg", "primaryColor": "rgb(24, 144, 255)" }, "serverConfig": { diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/public/images/logo.svg b/components/device-mgt/io.entgra.device.mgt.ui/react-app/public/images/logo.svg index 05eb79a811..7986a8d1b4 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/public/images/logo.svg +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/public/images/logo.svg @@ -1 +1,798 @@ -logo \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/App.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/App.js index 68f8823e1a..5f8f429e8e 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/App.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/App.js @@ -67,11 +67,8 @@ class App extends React.Component { axios.get( window.location.origin + "/entgra/public/conf/config.json", ).then(res => { - console.log(res); - this.setState({ - loading: false, - config: res.data - }) + const config = res.data; + this.checkUserLoggedIn(config); }).catch((error) => { this.setState({ loading: false, @@ -80,6 +77,44 @@ class App extends React.Component { }); } + checkUserLoggedIn = (config) => { + axios.post( + window.location.origin + "/entgra-ui-request-handler/user", + "platform=entgra" + ).then(res => { + config.user = res.data.data; + const pageURL = window.location.pathname; + const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); + if (lastURLSegment === "login") { + window.location.href = window.location.origin + `/entgra/`; + } else { + this.setState({ + loading: false, + config: config + }); + } + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + const redirectUrl = encodeURI(window.location.href); + const pageURL = window.location.pathname; + const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); + if (lastURLSegment !== "login") { + window.location.href = window.location.origin + `/entgra/login?redirect=${redirectUrl}`; + } else { + this.setState({ + loading: false, + config: config + }) + } + } else { + this.setState({ + loading: false, + error: true + }) + } + }); + }; + render() { const {loading, error} = this.state; 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 new file mode 100644 index 0000000000..ee5bed4129 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/DeviceTypes/DeviceTypesTable.js @@ -0,0 +1,135 @@ +/* + * 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 axios from "axios"; +import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider, Card, Col, Row, Select} 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"; + +const {Text} = Typography; + +let config = null; +let apiUrl; + +class DeviceTypesTable extends React.Component { + constructor(props) { + super(props); + config = this.props.context; + TimeAgo.addLocale(en); + this.state = { + data: [], + pagination: {}, + loading: false, + selectedRows: [] + }; + } + + componentDidMount() { + this.fetchUsers(); + } + + //fetch data from api + fetchUsers = (params = {}) => { + const config = this.props.context; + this.setState({loading: true}); + + // get current page + const currentPage = (params.hasOwnProperty("page")) ? params.page : 1; + + const extraParams = { + offset: 10 * (currentPage - 1), //calculate the offset + limit: 10, + }; + + const encodedExtraParams = Object.keys(extraParams) + .map(key => key + '=' + extraParams[key]).join('&'); + + apiUrl = window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.deviceMgt + + "/device-types"; + + //send request to the invokerss + axios.get(apiUrl).then(res => { + if (res.status === 200) { + const pagination = {...this.state.pagination}; + this.setState({ + loading: false, + data: JSON.parse(res.data.data), + pagination, + }); + } + console.log(JSON.parse(res.data.data)) + + }).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 device types.", + }); + } + + this.setState({loading: false}); + }); + }; + + handleTableChange = (pagination, filters, sorter) => { + const pager = {...this.state.pagination}; + pager.current = pagination.current; + this.setState({ + pagination: pager, + }); + this.fetch({ + results: pagination.pageSize, + page: pagination.current, + sortField: sorter.field, + sortOrder: sorter.order, + ...filters, + }); + }; + + render() { + + const {data, pagination, loading, selectedRows} = this.state; + + const itemCard = data.map((data) => + + + {data.name} + + + ); + return ( +
+ + {itemCard} + +
+ ); + } +} + +export default withConfigContext(DeviceTypesTable); \ No newline at end of file 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 62cb0c9f14..21fe449b48 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 @@ -176,7 +176,7 @@ class DeviceTable extends React.Component { this.setState({ loading: false, data: res.data.data.devices, - pagination, + pagination }); } @@ -253,7 +253,7 @@ class DeviceTable extends React.Component { message: "Done", duration: 4, description: - "Successfully disenrolled the device.", + "Successfully dis-enrolled the device.", }); } }).catch((error) => { @@ -266,7 +266,7 @@ class DeviceTable extends React.Component { message: "There was a problem", duration: 0, description: - "Error occurred while trying to disenroll devices.", + "Error occurred while trying to dis-enroll devices.", }); } 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 d71f141e96..5d24e85986 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 @@ -112,18 +112,7 @@ const columns = [ return {timeAgoString}; } // todo add filtering options - }, - { - title: 'Action', - key: 'action', - render: () => ( - - - - - - ), - }, + } ]; const getTimeAgo = (time) => { 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 new file mode 100644 index 0000000000..f411c0782a --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Groups/GroupsTable.js @@ -0,0 +1,174 @@ +/* + * 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 axios from "axios"; +import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider} 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"; + +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); +}; + +class GroupsTable extends React.Component { + constructor(props) { + super(props); + config = this.props.context; + TimeAgo.addLocale(en); + this.state = { + data: [], + pagination: {}, + loading: false, + selectedRows: [] + }; + } + + rowSelection = { + onChange: (selectedRowKeys, selectedRows) => { + this.setState({ + selectedRows: selectedRows + }) + } + }; + + componentDidMount() { + this.fetchGroups(); + } + + //fetch data from api + fetchGroups = (params = {}) => { + const config = this.props.context; + this.setState({loading: true}); + + // get current page + const currentPage = (params.hasOwnProperty("page")) ? params.page : 1; + + const extraParams = { + offset: 10 * (currentPage - 1), //calculate the offset + limit: 10, + }; + + const encodedExtraParams = Object.keys(extraParams) + .map(key => key + '=' + extraParams[key]).join('&'); + + apiUrl = window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.deviceMgt + + "/admin/groups?" + encodedExtraParams; + + //send request to the invokerss + axios.get(apiUrl).then(res => { + if (res.status === 200) { + const pagination = {...this.state.pagination}; + this.setState({ + loading: false, + data: res.data.data.deviceGroups, + pagination, + }); + } + + }).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 device groups.", + }); + } + + this.setState({loading: false}); + }); + }; + + handleTableChange = (pagination, filters, sorter) => { + const pager = {...this.state.pagination}; + pager.current = pagination.current; + this.setState({ + pagination: pager, + }); + this.fetch({ + results: pagination.pageSize, + page: pagination.current, + sortField: sorter.field, + sortOrder: sorter.order, + ...filters, + }); + }; + + 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} + scroll={{x: 1000}} + /> + + ); + } +} + +export default withConfigContext(GroupsTable); \ No newline at end of file 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 new file mode 100644 index 0000000000..6808350646 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Roles/RolesTable.js @@ -0,0 +1,147 @@ +/* + * 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 axios from "axios"; +import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider, Card, Col, Row, Select} 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"; + +const {Text} = Typography; + +let config = null; +let apiUrl; + +const columns = [ + { + title: 'User Name', + dataIndex: 'username', + width: 100, + } +]; + +const getTimeAgo = (time) => { + const timeAgo = new TimeAgo('en-US'); + return timeAgo.format(time); +}; + +class RolesTable extends React.Component { + constructor(props) { + super(props); + config = this.props.context; + TimeAgo.addLocale(en); + this.state = { + data: [], + pagination: {}, + loading: false, + selectedRows: [] + }; + } + + componentDidMount() { + this.fetchUsers(); + } + + //fetch data from api + fetchUsers = (params = {}) => { + const config = this.props.context; + this.setState({loading: true}); + + // get current page + const currentPage = (params.hasOwnProperty("page")) ? params.page : 1; + + const extraParams = { + offset: 10 * (currentPage - 1), //calculate the offset + limit: 10, + }; + + const encodedExtraParams = Object.keys(extraParams) + .map(key => key + '=' + extraParams[key]).join('&'); + + 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) { + const pagination = {...this.state.pagination}; + this.setState({ + loading: false, + data: res.data.data.roles, + pagination, + }); + } + + }).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 users.", + }); + } + + this.setState({loading: false}); + }); + }; + + handleTableChange = (pagination, filters, sorter) => { + const pager = {...this.state.pagination}; + pager.current = pagination.current; + this.setState({ + pagination: pager, + }); + this.fetch({ + results: pagination.pageSize, + page: pagination.current, + sortField: sorter.field, + sortOrder: sorter.order, + ...filters, + }); + }; + + render() { + + const {data, pagination, loading, selectedRows} = this.state; + + const itemCard = data.map((data) => + + + {data} + + + ); + return ( +
+ + {itemCard} + +
+ ); + } +} + +export default withConfigContext(RolesTable); \ No newline at end of file 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 new file mode 100644 index 0000000000..beb34a94d6 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Users/UsersTable.js @@ -0,0 +1,134 @@ +/* + * 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 axios from "axios"; +import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider, Card, Col, Row, Select} 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"; + +const {Text} = Typography; + +let config = null; +let apiUrl; + +class UsersTable extends React.Component { + constructor(props) { + super(props); + config = this.props.context; + TimeAgo.addLocale(en); + this.state = { + data: [], + pagination: {}, + loading: false, + selectedRows: [] + }; + } + + componentDidMount() { + this.fetchUsers(); + } + + //fetch data from api + fetchUsers = (params = {}) => { + const config = this.props.context; + this.setState({loading: true}); + + // get current page + const currentPage = (params.hasOwnProperty("page")) ? params.page : 1; + + const extraParams = { + offset: 10 * (currentPage - 1), //calculate the offset + limit: 10, + }; + + const encodedExtraParams = Object.keys(extraParams) + .map(key => key + '=' + extraParams[key]).join('&'); + + apiUrl = window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.deviceMgt + + "/users"; + + //send request to the invokerss + axios.get(apiUrl).then(res => { + if (res.status === 200) { + const pagination = {...this.state.pagination}; + this.setState({ + loading: false, + data: res.data.data.users, + pagination, + }); + } + + }).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 users.", + }); + } + + this.setState({loading: false}); + }); + }; + + handleTableChange = (pagination, filters, sorter) => { + const pager = {...this.state.pagination}; + pager.current = pagination.current; + this.setState({ + pagination: pager, + }); + this.fetch({ + results: pagination.pageSize, + page: pagination.current, + sortField: sorter.field, + sortOrder: sorter.order, + ...filters, + }); + }; + + render() { + + const {data, pagination, loading, selectedRows} = this.state; + + const itemCard = data.map((data) => + + + {data.username} + + + ); + return ( +
+ + {itemCard} + +
+ ); + } +} + +export default withConfigContext(UsersTable); \ No newline at end of file diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/index.js index b8206d16d7..8eeca9f07c 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/index.js @@ -26,6 +26,11 @@ import './index.css'; import Devices from "./pages/Dashboard/Devices/Devices"; import Reports from "./pages/Dashboard/Reports/Reports"; import Geo from "./pages/Dashboard/Geo/Geo"; +import Groups from "./pages/Dashboard/Groups/Groups"; +import Users from "./pages/Dashboard/Users/Users"; +import Policies from "./pages/Dashboard/Policies/Policies"; +import Roles from "./pages/Dashboard/Roles/Roles"; +import DeviceTypes from "./pages/Dashboard/DeviceTypes/DeviceTypes"; const routes = [ { @@ -52,6 +57,31 @@ const routes = [ path: '/entgra/reports', component: Reports, exact: true + }, + { + path: '/entgra/groups', + component: Groups, + exact: true + }, + { + path: '/entgra/users', + component: Users, + exact: true + }, + { + path: '/entgra/policies', + component: Policies, + exact: true + }, + { + path: '/entgra/roles', + component: Roles, + exact: true + }, + { + path: '/entgra/devicetypes', + component: DeviceTypes, + exact: true } ] } diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Dashboard.css b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Dashboard.css index edb16b4c68..7923d0a9fc 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Dashboard.css +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Dashboard.css @@ -54,8 +54,11 @@ } .layout .logo-image img { - height: 32px; - margin: 16px; + height: 55px; + margin-top: 5px; + margin-left: 16px; + margin-right: 16px; + margin-bottom: 5px; } @media only screen and (min-width: 760px) { diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Dashboard.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Dashboard.js index 9a20fb39a8..0ab9a85619 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Dashboard.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Dashboard.js @@ -42,9 +42,11 @@ class Dashboard extends React.Component { mobileWidth }; this.logo = this.props.context.theme.logo; + this.config = this.props.context; } toggle = () => { + console.log(this.config) this.setState({ isNavBarCollapsed: !this.state.isNavBarCollapsed, }); @@ -63,8 +65,7 @@ class Dashboard extends React.Component { >
- logo - Entgra + logo
@@ -85,6 +86,36 @@ class Dashboard extends React.Component { Reports + + + + Groups + + + + + + Users + + + + + + Policies + + + + + + Roles + + + + + + Device Types + + @@ -109,9 +140,8 @@ class Dashboard extends React.Component { title={ - - } - > + {this.config.user} + }> diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/DeviceTypes/DeviceTypes.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/DeviceTypes/DeviceTypes.js new file mode 100644 index 0000000000..de9625bcc1 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/DeviceTypes/DeviceTypes.js @@ -0,0 +1,65 @@ +/* + * 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 { + PageHeader, + Typography, + Breadcrumb, + Icon +} from "antd"; +import {Link} from "react-router-dom"; +import DeviceTypesTable from "../../../components/DeviceTypes/DeviceTypesTable"; + +const {Paragraph} = Typography; + +class DeviceTypes extends React.Component { + routes; + + constructor(props) { + super(props); + this.routes = props.routes; + } + + render() { + return ( +
+ + + + Home + + Device Types + +
+

Device Types

+ All device types for device management. +
+
+ +
+
+
+ +
+
+ ); + } +} + +export default DeviceTypes; diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Devices/Devices.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Devices/Devices.js index f78f1c89f9..3adf87207c 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Devices/Devices.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Devices/Devices.js @@ -49,8 +49,7 @@ class Devices extends React.Component {

Devices

- Lorem ipsum dolor sit amet, est similique constituto at, quot inermis id mel, an - illud incorrupte nam. + All enrolled devices
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 new file mode 100644 index 0000000000..e17cac8665 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Groups/Groups.js @@ -0,0 +1,62 @@ +/* + * 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 { + PageHeader, + Typography, + Breadcrumb, + Icon +} from "antd"; +import {Link} from "react-router-dom"; +import GroupsTable from "../../../components/Groups/GroupsTable"; + +const {Paragraph} = Typography; + +class Groups extends React.Component { + routes; + + constructor(props) { + super(props); + this.routes = props.routes; + } + + render() { + return ( +
+ + + + Home + + Groups + +
+

Groups

+ All device groups. +
+
+ +
+
+
+ ); + } +} + +export default Groups; 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 new file mode 100644 index 0000000000..bedaff0b57 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Policies/Policies.js @@ -0,0 +1,61 @@ +/* + * 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 { + PageHeader, + Typography, + Breadcrumb, + Icon +} from "antd"; +import {Link} from "react-router-dom"; + +const {Paragraph} = Typography; + +class Policies extends React.Component { + routes; + + constructor(props) { + super(props); + this.routes = props.routes; + } + + render() { + return ( +
+ + + + Home + + Policies + +
+

Policies

+ All policies for device management +
+
+ +
+
+
+ ); + } +} + +export default Policies; diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Roles/Roles.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Roles/Roles.js new file mode 100644 index 0000000000..03a8f5e78f --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Roles/Roles.js @@ -0,0 +1,65 @@ +/* + * 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 { + PageHeader, + Typography, + Breadcrumb, + Icon +} from "antd"; +import {Link} from "react-router-dom"; +import RolesTable from "../../../components/Roles/RolesTable"; + +const {Paragraph} = Typography; + +class Roles extends React.Component { + routes; + + constructor(props) { + super(props); + this.routes = props.routes; + } + + render() { + return ( +
+ + + + Home + + Roles + +
+

Roles

+ All user roles +
+
+ +
+
+
+ +
+
+ ); + } +} + +export default Roles; diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Users/Users.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Users/Users.js new file mode 100644 index 0000000000..dcd9a1d0f8 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/pages/Dashboard/Users/Users.js @@ -0,0 +1,65 @@ +/* + * 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 { + PageHeader, + Typography, + Breadcrumb, + Icon +} from "antd"; +import {Link} from "react-router-dom"; +import UsersTable from "../../../components/Users/UsersTable"; + +const {Paragraph} = Typography; + +class Users extends React.Component { + routes; + + constructor(props) { + super(props); + this.routes = props.routes; + } + + render() { + return ( +
+ + + + Home + + Users + +
+

Users

+ All users for device management. +
+
+ +
+
+
+ +
+
+ ); + } +} + +export default Users; 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 3e47728c3d..c42739f296 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 @@ -142,7 +142,13 @@ public interface GroupManagementAdminService { value = "Provide how many device details you require from the starting pagination index/offset.", defaultValue = "5") @QueryParam("limit") - int limit); + int limit, + + @ApiParam( + name = "status", + value = "status of group to be retrieve.") + @QueryParam("status") + String status); @Path("/count") @GET @@ -190,6 +196,10 @@ public interface GroupManagementAdminService { message = "Internal Server Error. \n Server error occurred while fetching the group count.", response = ErrorResponse.class) }) - Response getGroupCount(); + Response getGroupCount(@ApiParam( + name = "status", + value = "status of groups of which count should be retrieved") + @QueryParam("status") + String status); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java index e2cda27c0c..2c11397b9a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java @@ -29,6 +29,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; 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.common.group.mgt.RoleDoesNotExistException; @@ -100,6 +101,7 @@ public class GroupManagementServiceImpl implements GroupManagementService { return Response.status(Response.Status.BAD_REQUEST).build(); } group.setOwner(owner); + group.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE); try { DeviceMgtAPIUtils.getGroupManagementProviderService().createGroup(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS); return Response.status(Response.Status.CREATED).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/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 f1783cb619..dcb0238204 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,6 +20,7 @@ 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.GroupManagementException; @@ -36,7 +37,7 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ private static final Log log = LogFactory.getLog(GroupManagementAdminServiceImpl.class); @Override - public Response getGroups(String name, String owner, int offset, int limit) { + public Response getGroups(String name, String owner, int offset, int limit, String status) { try { RequestValidationUtil.validatePaginationParameters(offset, limit); GroupPaginationRequest request = new GroupPaginationRequest(offset, limit); @@ -46,6 +47,9 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ if (owner != null) { request.setOwner(owner.toUpperCase()); } + if (status != null && !status.isEmpty()) { + request.setStatus(status.toUpperCase()); + } PaginationResult deviceGroupsResult = DeviceMgtAPIUtils.getGroupManagementProviderService() .getGroups(request); DeviceGroupList deviceGroupList = new DeviceGroupList(); @@ -65,9 +69,14 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ } @Override - public Response getGroupCount() { + public Response getGroupCount(String status) { try { - int count = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroupCount(); + int count; + if (status == null || status.isEmpty()) { + count = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroupCount(); + } else { + count = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroupCountByStatus(status); + } return Response.status(Response.Status.OK).entity(count).build(); } catch (GroupManagementException e) { String msg = "ErrorResponse occurred while retrieving group count."; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/GroupPaginationRequest.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/GroupPaginationRequest.java index 3c17ce32a9..d7a74f199b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/GroupPaginationRequest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/GroupPaginationRequest.java @@ -27,12 +27,21 @@ public class GroupPaginationRequest { private int rowCount; private String owner; private String groupName; + private String status; public GroupPaginationRequest(int start, int rowCount) { this.startIndex = start; this.rowCount = rowCount; } + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + public int getStartIndex() { return startIndex; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/DeviceGroup.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/DeviceGroup.java index 9dff875672..20ed01fb49 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/DeviceGroup.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/DeviceGroup.java @@ -44,6 +44,17 @@ public class DeviceGroup implements Serializable { private String owner; + @ApiModelProperty(name = "status", value = "The status of group that needs updating/retrieval.") + private String status; + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + private Map groupProperties; public DeviceGroup() {} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/DeviceGroupConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/DeviceGroupConstants.java index aab0fc16f3..039219bfe8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/DeviceGroupConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/DeviceGroupConstants.java @@ -65,6 +65,11 @@ public class DeviceGroupConstants { public static final String DEFAULT_VIEW_EVENTS = "view-events"; } + public static class GroupStatus { + public static final String ACTIVE = "ACTIVE"; + public static final String INACTIVE = "INACTIVE"; + } + public static class Permissions { public static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/groups", "/permission/device-mgt/user/groups"}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GroupDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GroupDAO.java index c181004dc4..9c2264b3f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GroupDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GroupDAO.java @@ -158,7 +158,7 @@ public interface GroupDAO { * @return List of all Device Groups in tenant. * @throws GroupManagementDAOException */ - int getGroupCount(int tenantId) throws GroupManagementDAOException; + int getGroupCount(int tenantId, String status) throws GroupManagementDAOException; /** * Get paginated count of Device Groups in tenant. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java index cb893438b4..d4207c4047 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.dao.impl; +import org.apache.solr.common.StringUtils; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; @@ -46,14 +47,25 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { PreparedStatement stmt = null; ResultSet rs; int groupId = -1; + boolean hasStatus = false; try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID) VALUES (?, ?, ?, ?)"; + String sql; + if(deviceGroup.getStatus() == null || deviceGroup.getStatus().isEmpty()){ + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID) VALUES (?, ?, ?, ?)"; + } else { + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, STATUS) VALUES (?, ?, ?, ?, ?)"; + hasStatus = true; + } stmt = conn.prepareStatement(sql, new String[]{"ID"}); stmt.setString(1, deviceGroup.getDescription()); stmt.setString(2, deviceGroup.getName()); stmt.setString(3, deviceGroup.getOwner()); stmt.setInt(4, tenantId); + if(hasStatus) { + stmt.setString(5, deviceGroup.getStatus()); + } + stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); if (rs.next()) { @@ -128,16 +140,26 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { public void updateGroup(DeviceGroup deviceGroup, int groupId, int tenantId) throws GroupManagementDAOException { PreparedStatement stmt = null; + boolean hasStatus = false; try { Connection conn = GroupManagementDAOFactory.getConnection(); String sql = "UPDATE DM_GROUP SET DESCRIPTION = ?, GROUP_NAME = ?, OWNER = ? WHERE ID = ? AND TENANT_ID = ?"; + + if(deviceGroup.getStatus() != null && !deviceGroup.getStatus().isEmpty()){ + sql = "UPDATE DM_GROUP SET DESCRIPTION = ?, GROUP_NAME = ?, OWNER = ?, STATUS = ? WHERE ID = ? AND TENANT_ID = ?"; + hasStatus = true; + } stmt = conn.prepareStatement(sql); - stmt.setString(1, deviceGroup.getDescription()); - stmt.setString(2, deviceGroup.getName()); - stmt.setString(3, deviceGroup.getOwner()); - stmt.setInt(4, groupId); - stmt.setInt(5, tenantId); + int paramIndex = 1; + stmt.setString(paramIndex++, deviceGroup.getDescription()); + stmt.setString(paramIndex++, deviceGroup.getName()); + stmt.setString(paramIndex++, deviceGroup.getOwner()); + if(hasStatus) { + stmt.setString(paramIndex++, deviceGroup.getStatus()); + } + stmt.setInt(paramIndex++, groupId); + stmt.setInt(paramIndex++, tenantId); stmt.executeUpdate(); } catch (SQLException e) { throw new GroupManagementDAOException("Error occurred while updating deviceGroup '" + @@ -213,8 +235,8 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { Map properties = new HashMap(); try { Connection conn = GroupManagementDAOFactory.getConnection(); - stmt = conn.prepareStatement( - "SELECT PROPERTY_NAME, PROPERTY_VALUE FROM GROUP_PROPERTIES WHERE GROUP_ID = ? AND TENANT_ID = ?"); + String sql = "SELECT PROPERTY_NAME, PROPERTY_VALUE FROM GROUP_PROPERTIES WHERE GROUP_ID = ? AND TENANT_ID = ?"; + stmt = conn.prepareStatement(sql); stmt.setInt(1, groupId); stmt.setInt(2, tenantId); resultSet = stmt.executeQuery(); @@ -304,14 +326,22 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { } @Override - public int getGroupCount(int tenantId) throws GroupManagementDAOException { + public int getGroupCount(int tenantId, String status) throws GroupManagementDAOException { PreparedStatement stmt = null; ResultSet resultSet = null; + boolean statusAvailable = false; try { Connection conn = GroupManagementDAOFactory.getConnection(); String sql = "SELECT COUNT(ID) AS GROUP_COUNT FROM DM_GROUP WHERE TENANT_ID = ?"; + if(!StringUtils.isEmpty(status)){ + sql += " AND STATUS = ?"; + statusAvailable = true; + } stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); + if(statusAvailable){ + stmt.setString(2, status); + } resultSet = stmt.executeQuery(); if (resultSet.next()) { return resultSet.getInt("GROUP_COUNT"); @@ -335,6 +365,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { boolean hasGroupName = false; String owner = request.getOwner(); boolean hasOwner = false; + boolean hasStatus = false; try { Connection conn = GroupManagementDAOFactory.getConnection(); @@ -347,6 +378,10 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { sql += " AND OWNER LIKE ?"; hasOwner = true; } + if(!StringUtils.isEmpty(request.getStatus())){ + sql += " AND STATUS = ?"; + hasStatus = true; + } int paramIndex = 1; stmt = conn.prepareStatement(sql); @@ -357,6 +392,9 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { if (hasOwner) { stmt.setString(paramIndex, owner + "%"); } + if (hasStatus) { + stmt.setString(paramIndex, request.getStatus()); + } resultSet = stmt.executeQuery(); if (resultSet.next()) { return resultSet.getInt("GROUP_COUNT"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/GenericGroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/GenericGroupDAOImpl.java index 8ef981e701..ebfa129d42 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/GenericGroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/GenericGroupDAOImpl.java @@ -48,7 +48,9 @@ public class GenericGroupDAOImpl extends AbstractGroupDAOImpl { String groupName = request.getGroupName(); boolean hasGroupName = false; String owner = request.getOwner(); + String status = request.getStatus(); boolean hasOwner = false; + boolean hasStatus = false; boolean hasLimit = request.getRowCount() != 0; try { @@ -62,6 +64,10 @@ public class GenericGroupDAOImpl extends AbstractGroupDAOImpl { sql += " AND UPPER(OWNER) LIKE ?"; hasOwner = true; } + if (status != null && !status.isEmpty()) { + sql += " AND STATUS = ?"; + hasStatus = true; + } if (hasLimit) { sql += " LIMIT ?, ?"; } @@ -75,6 +81,9 @@ public class GenericGroupDAOImpl extends AbstractGroupDAOImpl { if (hasOwner) { stmt.setString(paramIndex++, owner + "%"); } + if (hasStatus) { + stmt.setString(paramIndex++, status.toUpperCase()); + } if (hasLimit) { stmt.setInt(paramIndex++, request.getStartIndex()); stmt.setInt(paramIndex, request.getRowCount()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/OracleGroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/OracleGroupDAOImpl.java index ecbe0013b7..7a540643f2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/OracleGroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/OracleGroupDAOImpl.java @@ -49,7 +49,9 @@ public class OracleGroupDAOImpl extends AbstractGroupDAOImpl { String groupName = request.getGroupName(); boolean hasGroupName = false; String owner = request.getOwner(); + String status = request.getStatus(); boolean hasOwner = false; + boolean hasStatus = false; boolean hasLimit = request.getRowCount() != 0; try { @@ -63,6 +65,10 @@ public class OracleGroupDAOImpl extends AbstractGroupDAOImpl { sql += " AND OWNER LIKE ?"; hasOwner = true; } + if (status != null && !status.isEmpty()) { + sql += " AND STATUS = ?"; + hasStatus = true; + } if (hasLimit) { sql += " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; } @@ -76,6 +82,9 @@ public class OracleGroupDAOImpl extends AbstractGroupDAOImpl { if (hasOwner) { stmt.setString(paramIndex++, owner + "%"); } + if (hasStatus) { + stmt.setString(paramIndex++, status.toUpperCase()); + } if (hasLimit) { stmt.setInt(paramIndex++, request.getStartIndex()); stmt.setInt(paramIndex, request.getRowCount()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java index 83020796ef..a677f467ed 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.dao.impl.group; +import org.apache.solr.common.StringUtils; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; @@ -44,15 +45,26 @@ public class PostgreSQLGroupDAOImpl extends AbstractGroupDAOImpl { PreparedStatement stmt = null; ResultSet rs; int groupId = -1; + boolean hasStatus = false; try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID) " + - "VALUES (?, ?, ?, ?) RETURNING ID"; + String sql; + if(StringUtils.isEmpty(deviceGroup.getStatus())) { + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID) " + + "VALUES (?, ?, ?, ?) RETURNING ID"; + } else { + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, STATUS) " + + "VALUES (?, ?, ?, ?, ?) RETURNING ID"; + hasStatus = true; + } stmt = conn.prepareStatement(sql); stmt.setString(1, deviceGroup.getDescription()); stmt.setString(2, deviceGroup.getName()); stmt.setString(3, deviceGroup.getOwner()); stmt.setInt(4, tenantId); + if(hasStatus) { + stmt.setString(5, deviceGroup.getStatus()); + } stmt.execute(); rs = stmt.getGeneratedKeys(); if (rs.next()) { @@ -77,7 +89,9 @@ public class PostgreSQLGroupDAOImpl extends AbstractGroupDAOImpl { String groupName = request.getGroupName(); boolean hasGroupName = false; String owner = request.getOwner(); + String status = request.getStatus(); boolean hasOwner = false; + boolean hasStatus = false; boolean hasLimit = request.getRowCount() != 0; try { @@ -91,6 +105,10 @@ public class PostgreSQLGroupDAOImpl extends AbstractGroupDAOImpl { sql += " AND OWNER LIKE ?"; hasOwner = true; } + if (status != null && !status.isEmpty()) { + sql += " AND STATUS = ?"; + hasStatus = true; + } if (hasLimit) { sql += " LIMIT ? OFFSET ?"; } @@ -104,6 +122,9 @@ public class PostgreSQLGroupDAOImpl extends AbstractGroupDAOImpl { if (hasOwner) { stmt.setString(paramIndex++, owner + "%"); } + if (hasStatus) { + stmt.setString(paramIndex++, status.toUpperCase()); + } if (hasLimit) { stmt.setInt(paramIndex++, request.getRowCount()); stmt.setInt(paramIndex, request.getStartIndex()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/SQLServerGroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/SQLServerGroupDAOImpl.java index 34810ae5ab..f4f2bddc8c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/SQLServerGroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/SQLServerGroupDAOImpl.java @@ -50,6 +50,8 @@ public class SQLServerGroupDAOImpl extends AbstractGroupDAOImpl { boolean hasGroupName = false; String owner = request.getOwner(); boolean hasOwner = false; + String status = request.getStatus(); + boolean hasStatus = false; boolean hasLimit = request.getRowCount() != 0; try { @@ -63,6 +65,10 @@ public class SQLServerGroupDAOImpl extends AbstractGroupDAOImpl { sql += " AND OWNER LIKE ?"; hasOwner = true; } + if (status != null && !status.isEmpty()) { + sql += " AND STATUS = ?"; + hasStatus = true; + } if (hasLimit) { sql += " ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; } @@ -76,6 +82,9 @@ public class SQLServerGroupDAOImpl extends AbstractGroupDAOImpl { if (hasOwner) { stmt.setString(paramIndex++, owner + "%"); } + if (hasStatus) { + stmt.setString(paramIndex++, status.toUpperCase()); + } if (hasLimit) { stmt.setInt(paramIndex++, request.getStartIndex()); stmt.setInt(paramIndex, request.getRowCount()); 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 613bb80167..a012fff0c8 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 @@ -2794,6 +2794,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv defaultGroup = new DeviceGroup(groupName); // Setting system level user (wso2.system.user) as the owner defaultGroup.setOwner(CarbonConstants.REGISTRY_SYSTEM_USERNAME); + defaultGroup.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE); defaultGroup.setDescription("Default system group for devices with " + groupName + " ownership."); try { service.createGroup(defaultGroup, DeviceGroupConstants.Roles.DEFAULT_ADMIN_ROLE, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java index 4e3dda809d..6951862a77 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java @@ -127,6 +127,14 @@ public interface GroupManagementProviderService { */ int getGroupCount() throws GroupManagementException; + /** + * Get all device group count in tenant by group status + * + * @return group count + * @throws GroupManagementException + */ + int getGroupCountByStatus(String status) throws GroupManagementException; + /** * Get device group count of user * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 7266bf83da..457e1217c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -472,7 +472,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); GroupManagementDAOFactory.openConnection(); - return groupDAO.getGroupCount(tenantId); + return groupDAO.getGroupCount(tenantId, null); } catch (GroupManagementDAOException | SQLException e) { String msg = "Error occurred while retrieving all groups in tenant"; log.error(msg, e); @@ -485,6 +485,29 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid GroupManagementDAOFactory.closeConnection(); } } + @Override + public int getGroupCountByStatus(String status) throws GroupManagementException { + if (log.isDebugEnabled()) { + log.debug("Get groups count by Status"); + } + int tenantId = -1; + try { + tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + GroupManagementDAOFactory.openConnection(); + return groupDAO.getGroupCount(tenantId, status); + } catch (GroupManagementDAOException | SQLException e) { + String msg = "Error occurred while retrieving all groups in tenant " + tenantId + +" by status : " + status; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred"; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } finally { + GroupManagementDAOFactory.closeConnection(); + } + } private int getGroupCount(GroupPaginationRequest request) throws GroupManagementException { if (log.isDebugEnabled()) { @@ -882,6 +905,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid DeviceGroup defaultGroup = this.getGroup(groupName); if (defaultGroup == null) { defaultGroup = new DeviceGroup(groupName); + defaultGroup.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE); // Setting system level user (wso2.system.user) as the owner defaultGroup.setOwner(CarbonConstants.REGISTRY_SYSTEM_USERNAME); defaultGroup.setDescription("Default system group for devices with " + groupName + " ownership."); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index 89eaa6d335..80ac0335be 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -11,6 +11,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( CREATE TABLE IF NOT EXISTS DM_GROUP ( ID INTEGER AUTO_INCREMENT NOT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL, + STATUS VARCHAR(50) DEFAULT NULL, DESCRIPTION TEXT DEFAULT NULL, OWNER VARCHAR(45) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index 1e4587c5c4..e6b1f3300e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS DM_GROUP ( ID INTEGER AUTO_INCREMENT NOT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL, DESCRIPTION TEXT DEFAULT NULL, + STATUS VARCHAR(50) DEFAULT NULL, DATE_OF_CREATE BIGINT DEFAULT NULL, DATE_OF_LAST_UPDATE BIGINT DEFAULT NULL, OWNER VARCHAR(45) DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index 8cbd423c4f..a3658e474a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -20,6 +20,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( CREATE TABLE IF NOT EXISTS DM_GROUP ( ID INTEGER AUTO_INCREMENT NOT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL, + STATUS VARCHAR(50) DEFAULT NULL, DESCRIPTION TEXT DEFAULT NULL, OWNER VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index b4aa5e731a..bf7c12351e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -29,6 +29,7 @@ IF NOT EXISTS(SELECT * CREATE TABLE DM_GROUP ( ID INTEGER IDENTITY (1, 1) NOT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL, + STATUS VARCHAR(50) DEFAULT NULL, DESCRIPTION VARCHAR(MAX) DEFAULT NULL, OWNER VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index c6fab7ef01..cb6df2f762 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( CREATE TABLE IF NOT EXISTS DM_GROUP ( ID INTEGER AUTO_INCREMENT NOT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL, + STATUS VARCHAR(50) DEFAULT NULL, DESCRIPTION TEXT DEFAULT NULL, OWNER VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index 371b4a4697..ce735f70e9 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -48,6 +48,7 @@ CREATE TABLE DM_GROUP ( ID NUMBER(10) NOT NULL, DESCRIPTION CLOB DEFAULT NULL, GROUP_NAME VARCHAR2(100) DEFAULT NULL, + STATUS VARCHAR2(50) DEFAULT NULL, OWNER VARCHAR2(255) DEFAULT NULL, TENANT_ID NUMBER(10) DEFAULT 0, CONSTRAINT PK_DM_GROUP PRIMARY KEY (ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index d5d11f6b35..f52bed8d00 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( CREATE TABLE IF NOT EXISTS DM_GROUP ( ID BIGSERIAL NOT NULL PRIMARY KEY, GROUP_NAME VARCHAR(100) DEFAULT NULL, + STATUS VARCHAR(50) DEFAULT NULL, DESCRIPTION TEXT DEFAULT NULL, OWNER VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0