From bb808fd9e3d43efbdfcf201d061e81a81505b704 Mon Sep 17 00:00:00 2001 From: Gathika94 Date: Fri, 29 Mar 2019 14:26:35 +0530 Subject: [PATCH] Rechange the app manager lifecycle xml file, add comments and headers --- .../core/lifecycle/LifecycleStateManger.java | 69 ++++++++++++++----- .../core/lifecycle/config/LifecycleState.java | 48 ++++++++----- .../main/resources/conf/application-mgt.xml | 63 ++++++++--------- 3 files changed, 110 insertions(+), 70 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java index 86f4381e40f..6dd29f5ea3e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java @@ -1,3 +1,39 @@ +/* + * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Copyright (c) 2019, Entgra Inc. (http://www.entgra.io) All Rights Reserved. + * + * Entgra Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.device.application.mgt.core.lifecycle; import org.apache.commons.logging.Log; @@ -32,16 +68,15 @@ public class LifecycleStateManger { s.getProceedingStates().replaceAll(String::toUpperCase); } lifecycleStates.put(s.getName().toUpperCase(), new State(s.getName().toUpperCase(), - s.getProceedingStates(), s.getPermission(),s.isAppUpdatable(),s.isAppInstallable(), - s.isInitialState(),s.isEndState())); + s.getProceedingStates(), s.getPermission(), s.isAppUpdatable(), s.isAppInstallable(), + s.isInitialState(), s.isEndState())); try { PermissionUtils.putPermission(s.getPermission()); } catch (PermissionManagementException e) { - log.error("Error when adding permission " + s.getPermission() + " related to the state: " - + s.getName(), e); - throw new LifecycleManagementException ( - "Error when adding permission " + s.getPermission() + " related to the state: " - + s.getName(), e); + String msg = "Error when adding permission " + s.getPermission() + " related to the state: " + + s.getName(); + log.error(msg, e); + throw new LifecycleManagementException(msg, e); } } } @@ -53,9 +88,9 @@ public class LifecycleStateManger { public boolean isValidStateChange(String currentState, String nextState, String username, int tenantId) throws LifecycleManagementException { - UserRealm userRealm = null; + UserRealm userRealm; String permission = getPermissionForStateChange(nextState); - if(permission != null) { + if (permission != null) { try { userRealm = DataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId); if (userRealm != null && userRealm.getAuthorizationManager() != null && @@ -77,17 +112,17 @@ public class LifecycleStateManger { "UserStoreException exception from changing the state from : " + currentState + " to: " + nextState + " with username : " + username + " and tenant Id : " + tenantId, e); } - }else{ + } else { throw new LifecycleManagementException( - "Required permissions cannot be found for the state : "+nextState); + "Required permissions cannot be found for the state : " + nextState); } } private State getMatchingState(String currentState) { Iterator it = lifecycleStates.entrySet().iterator(); while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - if(pair.getKey().toString().equalsIgnoreCase(currentState)) { + Map.Entry pair = (Map.Entry) it.next(); + if (pair.getKey().toString().equalsIgnoreCase(currentState)) { return lifecycleStates.get(pair.getKey().toString()); } it.remove(); @@ -97,7 +132,7 @@ public class LifecycleStateManger { private boolean getMatchingNextState(Set proceedingStates, String nextState) { - for (String state: proceedingStates) { + for (String state : proceedingStates) { if (state.equalsIgnoreCase(nextState)) { return true; } @@ -105,12 +140,12 @@ public class LifecycleStateManger { return false; } - private String getPermissionForStateChange(String nextState){ + private String getPermissionForStateChange(String nextState) { Iterator it = lifecycleStates.entrySet().iterator(); State nextLifecycleState; while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - if(pair.getKey().toString().equalsIgnoreCase(nextState)) { + Map.Entry pair = (Map.Entry) it.next(); + if (pair.getKey().toString().equalsIgnoreCase(nextState)) { nextLifecycleState = lifecycleStates.get(nextState); return nextLifecycleState.getPermission(); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/config/LifecycleState.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/config/LifecycleState.java index 69142b9db16..b24042e6a43 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/config/LifecycleState.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/config/LifecycleState.java @@ -37,35 +37,49 @@ public class LifecycleState { this.proceedingStates = proceedingStates; } - @XmlElement(name="Permission") - public String getPermission(){return permission;} + @XmlElement(name = "Permission") + public String getPermission() { + return permission; + } + + public void setPermission(String permission) { + this.permission = permission; + } - public void setPermission(String permission){ - this.permission=permission; + @XmlElement(name = "IsAppInstallable") + public boolean isAppInstallable() { + return isAppInstallable; } - @XmlElement(name="IsAppInstallable") - public boolean isAppInstallable(){ - return isAppInstallable; + public void setAppInstallable(boolean isAppInstallable) { + this.isAppInstallable = isAppInstallable; } - public void setAppInstallable(boolean isAppInstallable){ this.isAppInstallable =isAppInstallable;} - @XmlElement(name="IsAppUpdatable") - public boolean isAppUpdatable(){ + @XmlElement(name = "IsAppUpdatable") + public boolean isAppUpdatable() { return isAppUpdatable; } - public void setAppUpdatable(boolean isAppUpdatable){ this.isAppUpdatable=isAppUpdatable;} - @XmlElement(name="IsInitialState") - public boolean isInitialState(){ + public void setAppUpdatable(boolean isAppUpdatable) { + this.isAppUpdatable = isAppUpdatable; + } + + @XmlElement(name = "IsInitialState") + public boolean isInitialState() { return isInitialState; } - public void setInitialState(boolean isInitialState){ this.isInitialState=isInitialState;} - @XmlElement(name="IsEndState") - public boolean isEndState(){ + public void setInitialState(boolean isInitialState) { + this.isInitialState = isInitialState; + } + + @XmlElement(name = "IsEndState") + public boolean isEndState() { return isEndState; } - public void setEndState(boolean isEndState){ this.isEndState=isEndState;} + + public void setEndState(boolean isEndState) { + this.isEndState = isEndState; + } } diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index ff8963bd134..450705e4371 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -56,13 +56,26 @@ If there is a requirement to introduce a new state to the lifecycle, please refer above diagram and add relevant state to the below configuration appropriately. --> - - + + + + true + true /device-mgt/applications/life-cycle/create @@ -71,10 +84,6 @@ - false - true - false - false /device-mgt/applications/life-cycle/in-review @@ -84,37 +93,27 @@ - false - false - false - false - /device-mgt/applications/life-cycle/approved + /device-mgt/applications/life-cycle/approve Published + Created - false - false - false - false - /device-mgt/applications/life-cycle/rejected + /device-mgt/applications/life-cycle/reject - In-Review + Created Removed true - false - false - false - /device-mgt/applications/life-cycle/published + /device-mgt/applications/life-cycle/publish Unpublished @@ -122,36 +121,28 @@ - false - false - false - false - /device-mgt/applications/life-cycle/unpublished + /device-mgt/applications/life-cycle/unpublish + Published + In-Review Removed - false - false - false - false - /device-mgt/applications/life-cycle/deprecated + /device-mgt/applications/life-cycle/deprecate Removed + In-Review - false - false - false true - /device-mgt/applications/life-cycle/removed + /device-mgt/applications/life-cycle/remove