diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java index dde186109c..63e830cdfe 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java @@ -26,6 +26,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Calendar; @@ -175,7 +176,7 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { + "VALUES (?, ?, ?, ?, ?, ?, ?)"; try { Connection conn = this.getDBConnection(); - try (PreparedStatement stmt = conn.prepareStatement(sql)) { + try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { Calendar calendar = Calendar.getInstance(); Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); List deviceSubIds = new ArrayList<>(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/package.json b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/package.json index 565064db72..dece5f9363 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/package.json +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/package.json @@ -15,11 +15,15 @@ "acorn": "^6.2.0", "antd": "^3.23.6", "axios": "^0.19.0", + "babel-eslint": "^9.0.0", "d3": "^5.9.7", "dagre": "^0.8.4", + "eslint": "^5.16.0", + "eslint-plugin-import": "^2.18.2", + "eslint-plugin-jsx-a11y": "^6.2.3", + "eslint-plugin-react": "^7.16.0", "fetch": "^1.1.0", - "gapi": "0.0.3", - "gapi-client": "0.0.3", + "imagemin": "^6.1.0", "keymirror": "^0.1.1", "rc-tween-one": "^2.4.1", "react-d3-graph": "^2.1.0", @@ -34,7 +38,8 @@ "react-star-ratings": "^2.3.0", "redux-thunk": "^2.3.0", "shade-blend-color": "^1.0.0", - "storm-react-diagrams": "^5.2.1" + "storm-react-diagrams": "^5.2.1", + "typescript": "^3.6.4" }, "devDependencies": { "@babel/core": "^7.5.0", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js index 01250e3791..69ecede98c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js @@ -64,6 +64,7 @@ class App extends React.Component { } componentDidMount() { + this.updateFavicon(); axios.get( window.location.origin + "/publisher/public/conf/config.json", ).then(res => { @@ -130,6 +131,14 @@ class App extends React.Component { }); }; + updateFavicon = () =>{ + const link = document.querySelector("link[rel*='icon']") || document.createElement('link'); + link.type = 'image/x-icon'; + link.rel = 'shortcut icon'; + link.href = window.location.origin+'/devicemgt/public/uuf.unit.favicon/img/favicon.png'; + document.getElementsByTagName('head')[0].appendChild(link); + }; + render() { const {loading, error} = this.state; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/ListApps.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/ListApps.js index 2c7b4f5e25..401b35b79d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/ListApps.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/ListApps.js @@ -57,10 +57,10 @@ class ListApps extends React.Component { return ( - + - + Apps @@ -82,4 +82,4 @@ class ListApps extends React.Component { } } -export default ListApps; \ No newline at end of file +export default ListApps; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/edit-release/EditRelease.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/edit-release/EditRelease.js index 4b1c5f97cf..062fa56542 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/edit-release/EditRelease.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/edit-release/EditRelease.js @@ -34,6 +34,7 @@ import { Select } from 'antd'; import axios from "axios"; +import "@babel/polyfill"; import {withConfigContext} from "../../../../context/ConfigContext"; const {TextArea} = Input; @@ -59,7 +60,7 @@ function getBase64(file) { } class EditReleaseModal extends React.Component { - + // To add subscription type & tenancy sharing, refer https://gitlab.com/entgra/carbon-device-mgt/merge_requests/331 constructor(props) { super(props); this.state = { @@ -162,12 +163,6 @@ class EditReleaseModal extends React.Component { }, releaseDescription: { value: release.description - }, - price: { - value: release.price - }, - isSharedWithAllTenants: { - value: release.isSharedWithAllTenants } }); @@ -252,7 +247,7 @@ class EditReleaseModal extends React.Component { this.setState({ loading: true }); - const {price, isSharedWithAllTenants, releaseDescription, releaseType} = values; + const {releaseDescription, releaseType} = values; const {icons, screenshots, binaryFiles} = this.state; @@ -261,8 +256,8 @@ class EditReleaseModal extends React.Component { //add release data const release = { description: releaseDescription, - price: (price === undefined) ? 0 : parseInt(price), - isSharedWithAllTenants, + price: 0, + isSharedWithAllTenants: false, metaData: JSON.stringify(this.state.metaData), releaseType: releaseType, }; @@ -282,10 +277,6 @@ class EditReleaseModal extends React.Component { if (specificElements.hasOwnProperty("url")) { release.url = values.url; } - // - // if (specificElements.hasOwnProperty("packageName")) { - // release.packageName = values.packageName; - // } if (icons.length === 1) { data.append('icon', icons[0].originFileObj); @@ -589,30 +580,6 @@ class EditReleaseModal extends React.Component { )} )} - - {getFieldDecorator('price', { - rules: [{ - required: false - }], - })( - - )} - - - - {getFieldDecorator('isSharedWithAllTenants', { - rules: [{ - required: true, - message: 'Please select' - }], - initialValue: false - })( - } - unCheckedChildren={} - /> - )} - - {getFieldDecorator('meta', { rules: [{ @@ -699,4 +666,4 @@ class EditReleaseModal extends React.Component { const EditRelease = withConfigContext(Form.create({name: 'add-new-release'})(EditReleaseModal)); -export default EditRelease; \ No newline at end of file +export default EditRelease; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/new-app/subForms/NewAppUploadForm.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/new-app/subForms/NewAppUploadForm.js index 79fd42a5f5..c7916c2c13 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/new-app/subForms/NewAppUploadForm.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/new-app/subForms/NewAppUploadForm.js @@ -91,8 +91,8 @@ class NewAppUploadForm extends React.Component { //add release data const release = { description: releaseDescription, - price: (price === undefined) ? 0 : parseInt(price), - isSharedWithAllTenants, + price: 0, + isSharedWithAllTenants: false, metaData: JSON.stringify(this.state.metaData), releaseType: releaseType }; @@ -111,19 +111,19 @@ class NewAppUploadForm extends React.Component { let isFormValid = true; // flag to check if this form is valid if (formConfig.installationType !== "WEB_CLIP" && formConfig.installationType !== "CUSTOM") { - if(this.lowerOsVersion==null || this.upperOsVersion==null){ + if (this.lowerOsVersion == null || this.upperOsVersion == null) { isFormValid = false; this.setState({ osVersionsHelperText: 'Please select supported OS versions', osVersionsValidateStatus: 'error', }); - }else if(this.lowerOsVersion>=this.upperOsVersion){ + } else if (this.lowerOsVersion >= this.upperOsVersion) { isFormValid = false; this.setState({ osVersionsHelperText: 'Please select valid range', osVersionsValidateStatus: 'error', }); - }else{ + } else { release.supportedOsVersions = `${this.lowerOsVersion}-${this.upperOsVersion}`; } } @@ -152,7 +152,7 @@ class NewAppUploadForm extends React.Component { screenshotHelperText: 'Please select 3 screenshots' }); } - if(isFormValid) { + if (isFormValid) { data.append('icon', icon[0].originFileObj); data.append('screenshot1', screenshots[0].originFileObj); data.append('screenshot2', screenshots[1].originFileObj); @@ -405,7 +405,12 @@ class NewAppUploadForm extends React.Component { label="Supported OS Versions" validateStatus={osVersionsValidateStatus} help={osVersionsHelperText}> - {getFieldDecorator('supportedOS')( + {getFieldDecorator('supportedOS', { + rules: [{ + required: true + }], + initialValue: false + })(
@@ -428,7 +433,14 @@ class NewAppUploadForm extends React.Component { - - - , - )} - - - {getFieldDecorator('price', { - rules: [{ - required: !isFree - }], - })( - `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')} - parser={value => value.replace(/\$\s?|(,*)/g, '')} - /> - )} - - - {getFieldDecorator('isSharedWithAllTenants', { - rules: [{ - required: true, - message: 'Please select' - }], - initialValue: false - })( - } - unCheckedChildren={} - /> - )} - {getFieldDecorator('meta', {})(
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js index 7031c03cc8..fd047221ee 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js @@ -64,6 +64,7 @@ class App extends React.Component { } componentDidMount() { + this.updateFavicon(); axios.get( window.location.origin + "/store/public/conf/config.json", ).then(res => { @@ -77,6 +78,14 @@ class App extends React.Component { }); } + updateFavicon = () =>{ + const link = document.querySelector("link[rel*='icon']") || document.createElement('link'); + link.type = 'image/x-icon'; + link.rel = 'shortcut icon'; + link.href = window.location.origin+'/devicemgt/public/uuf.unit.favicon/img/favicon.png'; + document.getElementsByTagName('head')[0].appendChild(link); + }; + checkUserLoggedIn = (config) => { axios.post( window.location.origin + "/store-ui-request-handler/user", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js index aac62976b7..2fddb9bf58 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js @@ -29,46 +29,9 @@ const { Text } = Typography; class DetailedRating extends React.Component{ - constructor(props){ - super(props); - this.state={ - detailedRating: null - } - } - - componentDidMount() { - const {type,uuid} = this.props; - this.getData(type,uuid); - } - - componentDidUpdate(prevProps, prevState) { - if (prevProps.uuid !== this.props.uuid) { - const {type,uuid} = this.props; - this.getData(type,uuid); - } - } - - - getData = (type, uuid)=>{ - const config = this.props.context; - - return axios.get( - window.location.origin+ config.serverConfig.invoker.uri +config.serverConfig.invoker.store+"/reviews/"+uuid+"/"+type+"-rating", - ).then(res => { - if (res.status === 200) { - let detailedRating = res.data.data; - this.setState({ - detailedRating - }) - } - - }).catch(function (error) { - handleApiError(error,"Error occurred while trying to load ratings."); - }); - }; render() { - const detailedRating = this.state.detailedRating; + const {detailedRating} = this.props; if(detailedRating ==null){ return null; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js index 18624ffbfa..63bb008e8c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js @@ -29,6 +29,7 @@ import AppUninstallModal from "./install/AppUninstallModal"; import CurrentUsersReview from "./review/CurrentUsersReview"; import {withConfigContext} from "../../../context/ConfigContext"; import {handleApiError} from "../../../js/Utils"; +import ReviewContainer from "./review/ReviewContainer"; const {Title, Text, Paragraph} = Typography; @@ -193,15 +194,7 @@ class ReleaseView extends React.Component { {(metaData.length === 0) && (No meta data available.)} - - - REVIEWS - - - - - - +
); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js index e30cac30bb..f15c6b812b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js @@ -86,10 +86,7 @@ class AddReview extends React.Component { description: 'Your review has been posted successfully.', }); - - setTimeout(() => { - window.location.href = uuid; - }, 2000) + this.props.onUpdateReview(); } else { this.setState({ loading: false, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/CurrentUsersReview.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/CurrentUsersReview.js index 2173db1921..8489a26800 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/CurrentUsersReview.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/CurrentUsersReview.js @@ -28,48 +28,9 @@ const {Text, Paragraph} = Typography; class CurrentUsersReview extends React.Component { - constructor(props) { - super(props); - this.state = { - data: [] - - }; - } - - componentDidMount() { - this.fetchData(); - } - - fetchData = () => { - const {uuid} = this.props; - const config = this.props.context; - - axios.get( - window.location.origin+ config.serverConfig.invoker.uri + config.serverConfig.invoker.store + "/reviews/app/user/" + uuid, - ).then(res => { - if (res.status === 200) { - const data = res.data.data.data; - this.setState({data}); - } - - }).catch((error) => { - handleApiError(error,"Error occurred while trying to get your review."); - }); - }; - - deleteCallback = () =>{ - this.setState({ - data: [] - }); - }; - - addCallBack =(review) =>{ - - }; render() { - const {data} = this.state; - const {uuid} = this.props; + const {uuid, currentUserReviews} = this.props; return (
MY REVIEW @@ -78,13 +39,20 @@ class CurrentUsersReview extends React.Component { paddingTop: 8, paddingLeft: 24 }}> - {data.length > 0 && ( + {currentUserReviews.length > 0 && (
( - + )} > @@ -92,7 +60,7 @@ class CurrentUsersReview extends React.Component {
)} - {data.length === 0 && ( + {currentUserReviews.length === 0 && (
{/**/} - +
)} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/ReviewContainer.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/ReviewContainer.js new file mode 100644 index 0000000000..2b8f124cb2 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/ReviewContainer.js @@ -0,0 +1,119 @@ +/* + * 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 CurrentUsersReview from "./CurrentUsersReview"; +import {Col, Divider, Row, Typography} from "antd"; +import DetailedRating from "../DetailedRating"; +import Reviews from "./Reviews"; +import axios from "axios"; +import {handleApiError} from "../../../../js/Utils"; +import {withConfigContext} from "../../../../context/ConfigContext"; + +const {Text} = Typography; + +class ReviewContainer extends React.Component { + constructor(props) { + super(props); + this.state = { + currentUserReviews: [], + detailedRating: null + } + } + + componentDidMount() { + this.fetchCurrentUserReviews(); + this.fetchDetailedRating("app", this.props.uuid); + } + + fetchCurrentUserReviews = () => { + const {uuid} = this.props; + const config = this.props.context; + + axios.get( + window.location.origin + config.serverConfig.invoker.uri + config.serverConfig.invoker.store + "/reviews/app/user/" + uuid, + ).then(res => { + if (res.status === 200) { + const currentUserReviews = res.data.data.data; + this.setState({currentUserReviews}); + } + + }).catch((error) => { + handleApiError(error, "Error occurred while trying to get your review."); + }); + }; + + deleteCurrentUserReviewCallback = () => { + this.setState({ + currentUserReviews: [] + }); + this.fetchDetailedRating("app", this.props.uuid); + }; + + fetchDetailedRating = (type, uuid) => { + const config = this.props.context; + + axios.get( + window.location.origin + config.serverConfig.invoker.uri + config.serverConfig.invoker.store + "/reviews/" + uuid + "/" + type + "-rating", + ).then(res => { + if (res.status === 200) { + let detailedRating = res.data.data; + this.setState({ + detailedRating + }) + } + + }).catch(function (error) { + handleApiError(error, "Error occurred while trying to load ratings."); + }); + }; + + onUpdateReview = () => { + this.fetchCurrentUserReviews(); + this.fetchDetailedRating("app", this.props.uuid); + }; + + render() { + const {uuid} = this.props; + const {currentUserReviews,detailedRating} = this.state; + return ( +
+ + + REVIEWS + + + + + + +
+ ) + } +} + +export default withConfigContext(ReviewContainer); \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js index 59020a26d6..7c74574b6b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js @@ -107,6 +107,7 @@ class Reviews extends React.Component { data: res, }); }); + this.props.deleteCallback(); }; render() { @@ -119,16 +120,14 @@ class Reviews extends React.Component { pageStart={0} loadMore={this.handleInfiniteOnLoad} hasMore={!loading && hasMore} - useWindow={true} - > + useWindow={true}> ( - )} - > + )}> {loading && hasMore && (
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/SingleReview.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/SingleReview.js index fe6ae73b9e..7ed1b366c9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/SingleReview.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/SingleReview.js @@ -52,6 +52,7 @@ class SingleReview extends React.Component { this.setState({ review }); + this.props.onUpdateReview(); }; deleteReview = () => { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java index a5306c825f..92e07aeab1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java @@ -14,6 +14,23 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + * + * + * 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. */ package org.wso2.carbon.device.mgt.jaxrs.beans; @@ -21,6 +38,7 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.policy.mgt.CorrectiveAction; import org.wso2.carbon.device.mgt.common.policy.mgt.DeviceGroupWrapper; import javax.validation.constraints.NotNull; @@ -108,6 +126,12 @@ public class PolicyWrapper { @NotNull private String policyType; + @ApiModelProperty( + name = "correctiveActions", + value = "List of corrective actions to be applied when the policy is violated" + ) + private List correctiveActions; + public String getPolicyType() { return policyType; } @@ -196,4 +220,11 @@ public class PolicyWrapper { this.deviceGroups = deviceGroups; } + public List getCorrectiveActions() { + return correctiveActions; + } + + public void setCorrectiveActions(List correctiveActions) { + this.correctiveActions = correctiveActions; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index b5b92e7a0c..5f9f9c9063 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -1,19 +1,36 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * 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. + * + * + * 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. * */ package org.wso2.carbon.device.mgt.jaxrs.service.impl; @@ -117,6 +134,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { policy.setPolicyName(policyWrapper.getPolicyName()); policy.setDescription(policyWrapper.getDescription()); policy.setProfile(DeviceMgtUtil.convertProfile(policyWrapper.getProfile())); + policy.setCorrectiveActions(policyWrapper.getCorrectiveActions()); policy.setOwnershipType(policyWrapper.getOwnershipType()); policy.setActive(policyWrapper.isActive()); policy.setRoles(policyWrapper.getRoles()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java new file mode 100644 index 0000000000..dece7db618 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java @@ -0,0 +1,81 @@ +/* + * 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. + */ +package org.wso2.carbon.device.mgt.common.policy.mgt; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +import java.util.List; + +@ApiModel( + value = "CorrectiveAction", + description = "This bean carries all information related corrective action which is required " + + "when a policy is violated." +) +public class CorrectiveAction implements Serializable { + + private static final long serialVersionUID = -3414709449056070148L; + + @ApiModelProperty( + name = "action", + value = "Corrective action type (POLICY or OPERATION) to trigger when a policy is violated.", + example = "POLICY", + required = true + ) + private String actionType; + + @ApiModelProperty( + name = "policyId", + value = "When corrective action is POLICY, the corrective policy ID to be applied when a policy " + + "is violated.", + example = "1" + ) + private int policyId; + + @ApiModelProperty( + name = "operations", + value = "When corrective action is OPERATION, the list of operations in features to be applied " + + "when a policy is violated." + ) + private List operations; + + public String getActionType() { + return actionType; + } + + public void setActionType(String actionType) { + this.actionType = actionType; + } + + public int getPolicyId() { + return policyId; + } + + public void setPolicyId(int policyId) { + this.policyId = policyId; + } + + public List getOperations() { + return operations; + } + + public void setOperations(List operations) { + this.operations = operations; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/Policy.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/Policy.java index 977fd60d38..452521286b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/Policy.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/Policy.java @@ -14,6 +14,23 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + * + * + * 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. */ package org.wso2.carbon.device.mgt.common.policy.mgt; @@ -184,6 +201,13 @@ public class Policy implements Comparable, Serializable { example = "GENERAL") private String policyType; + @ApiModelProperty( + name = "correctiveActions", + value = "List of corrective actions to be applied when the policy is violated", + example = "[{'actionType': 'POLICY', 'policyId': 1}]" + ) + private List correctiveActions; + @XmlElement public int getId() { return id; @@ -355,6 +379,16 @@ public class Policy implements Comparable, Serializable { this.policyType = policyType; } + @XmlElement + public List getCorrectiveActions() { + return correctiveActions; + } + + public void setCorrectiveActions( + List correctiveActions) { + this.correctiveActions = correctiveActions; + } + @Override public int compareTo(Policy o) { if (this.priorityId == o.priorityId) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js index 147b664ba6..8c881ef3df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js @@ -62,6 +62,8 @@ policyModule = function () { policyObjectToView["priorityId"] = policyObjectFromRestEndpoint["priorityId"]; policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"]; policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"]; + policyObjectFromRestEndpoint["policyType"] = policyListFromRestEndpoint["policyType"]; + policyObjectFromRestEndpoint["correctiveActions"] = policyListFromRestEndpoint["correctiveActions"]; if (policyObjectToView["platform"] == "ios") { policyObjectToView["deviceTypeIcon"] = "apple"; } else { @@ -168,6 +170,27 @@ policyModule = function () { } }; + /** + * Retrieve all policies based on policy type + */ + publicMethods.getAllPoliciesByType = function (policyType) { + var carbonUser = session.get(constants["USER_SESSION_KEY"]); + if (!carbonUser) { + log.error("User object was not found in the session"); + userModule.logout(function () { + response.sendRedirect(devicemgtProps["appContext"] + "login"); + }); + } + try { + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/policies/type/" + policyType + "?offset=0&limit=100"; + return serviceInvokers.XMLHttp.get(url, privateMethods.handleGetAllPoliciesResponse); + } catch (e) { + log.error("Error occurred while retrieving policies by policy type " + policyType); + throw e; + } + }; + /* Get policies count from backend services. */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.corrective-action/corrective-action.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.corrective-action/corrective-action.json new file mode 100644 index 0000000000..fd25901297 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.corrective-action/corrective-action.json @@ -0,0 +1,3 @@ +{ + "version" : "1.0.0" +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.corrective-action/public/js/policy-corrective-action.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.corrective-action/public/js/policy-corrective-action.js new file mode 100644 index 0000000000..7af005f2ce --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.corrective-action/public/js/policy-corrective-action.js @@ -0,0 +1,25 @@ +/* + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.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. + */ + + +$(document).ready(function () { + + $("select.select2").select2(); + +}); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.corrective-action/public/templates/policy-corrective-action.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.corrective-action/public/templates/policy-corrective-action.hbs new file mode 100644 index 0000000000..6bd184a0c1 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.corrective-action/public/templates/policy-corrective-action.hbs @@ -0,0 +1,35 @@ + +{{#equal deviceType "android"}} +
+
+
+ Select Corrective Policy + + + + + +
+
+
+ +
+{{/equal}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs index e3f6cdfde9..c67f099c5b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs @@ -2,36 +2,44 @@ {{#if isAuthorized}}