mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Application mgt new (#7)
* Improve lifecycle state management * Add unit tests for lifecycle management * Add class level comments to lifecycle management
This commit is contained in:
parent
421dc5edf1
commit
7d59c342b2
@ -150,7 +150,7 @@ public interface ApplicationManager {
|
|||||||
* @param applicationUuid UUID of the Application Release.
|
* @param applicationUuid UUID of the Application Release.
|
||||||
* @throws ApplicationManagementException Application Management Exception.
|
* @throws ApplicationManagementException Application Management Exception.
|
||||||
*/
|
*/
|
||||||
void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws ApplicationManagementException;
|
void changeLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws ApplicationManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the application if application is an accessible one.
|
* Get the application if application is an accessible one.
|
||||||
|
|||||||
@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.application.mgt.core.config;
|
package org.wso2.carbon.device.application.mgt.core.config;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||||
@ -37,6 +39,8 @@ public class Configuration {
|
|||||||
|
|
||||||
private PaginationConfiguration paginationConfiguration;
|
private PaginationConfiguration paginationConfiguration;
|
||||||
|
|
||||||
|
private List<LifecycleState> lifecycleStates;
|
||||||
|
|
||||||
@XmlElement(name = "DatasourceName", required = true)
|
@XmlElement(name = "DatasourceName", required = true)
|
||||||
public String getDatasourceName() {
|
public String getDatasourceName() {
|
||||||
return datasourceName;
|
return datasourceName;
|
||||||
@ -60,6 +64,17 @@ public class Configuration {
|
|||||||
public PaginationConfiguration getPaginationConfiguration() {
|
public PaginationConfiguration getPaginationConfiguration() {
|
||||||
return paginationConfiguration;
|
return paginationConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@XmlElementWrapper(name = "LifecycleStates")
|
||||||
|
@XmlElement(name = "LifecycleState")
|
||||||
|
public List<LifecycleState> getLifecycleStates() {
|
||||||
|
return lifecycleStates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLifecycleStates(
|
||||||
|
List<LifecycleState> lifecycleStates) {
|
||||||
|
this.lifecycleStates = lifecycleStates;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,6 @@ import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole;
|
|||||||
import org.wso2.carbon.device.application.mgt.common.User;
|
import org.wso2.carbon.device.application.mgt.common.User;
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
|
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
|
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
|
||||||
@ -49,6 +48,7 @@ import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagement
|
|||||||
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
||||||
import org.wso2.carbon.device.application.mgt.core.exception.ValidationException;
|
import org.wso2.carbon.device.application.mgt.core.exception.ValidationException;
|
||||||
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
|
||||||
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||||
@ -73,10 +73,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
private ApplicationDAO applicationDAO;
|
private ApplicationDAO applicationDAO;
|
||||||
private ApplicationReleaseDAO applicationReleaseDAO;
|
private ApplicationReleaseDAO applicationReleaseDAO;
|
||||||
private LifecycleStateDAO lifecycleStateDAO;
|
private LifecycleStateDAO lifecycleStateDAO;
|
||||||
|
private LifecycleStateManger lifecycleStateManger;
|
||||||
|
|
||||||
|
|
||||||
public ApplicationManagerImpl() {
|
public ApplicationManagerImpl() {
|
||||||
initDataAccessObjects();
|
initDataAccessObjects();
|
||||||
|
lifecycleStateManger = DataHolder.getInstance().getLifecycleStateManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDataAccessObjects() {
|
private void initDataAccessObjects() {
|
||||||
@ -139,7 +141,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
LifecycleState lifecycleState = new LifecycleState();
|
LifecycleState lifecycleState = new LifecycleState();
|
||||||
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
||||||
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
||||||
addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState);
|
changeLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState);
|
||||||
|
|
||||||
applicationRelease.setLifecycleState(lifecycleState);
|
applicationRelease.setLifecycleState(lifecycleState);
|
||||||
applicationReleases.add(applicationRelease);
|
applicationReleases.add(applicationRelease);
|
||||||
@ -216,7 +218,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
LifecycleState lifecycleState = new LifecycleState();
|
LifecycleState lifecycleState = new LifecycleState();
|
||||||
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
||||||
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
||||||
addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState);
|
changeLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState);
|
||||||
|
|
||||||
ConnectionManagerUtil.commitDBTransaction();
|
ConnectionManagerUtil.commitDBTransaction();
|
||||||
return applicationRelease;
|
return applicationRelease;
|
||||||
@ -406,7 +408,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
LifecycleState newAppLifecycleState = new LifecycleState();
|
LifecycleState newAppLifecycleState = new LifecycleState();
|
||||||
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
||||||
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
||||||
addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
|
changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
|
||||||
storedLocations.add(applicationRelease.getAppHashValue());
|
storedLocations.add(applicationRelease.getAppHashValue());
|
||||||
}
|
}
|
||||||
ConnectionManagerUtil.openDBConnection();
|
ConnectionManagerUtil.openDBConnection();
|
||||||
@ -437,7 +439,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
LifecycleState newAppLifecycleState = new LifecycleState();
|
LifecycleState newAppLifecycleState = new LifecycleState();
|
||||||
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
||||||
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
||||||
addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
|
changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
|
||||||
}else{
|
}else{
|
||||||
throw new ApplicationManagementException("Can't delete the application release, You have to move the " +
|
throw new ApplicationManagementException("Can't delete the application release, You have to move the " +
|
||||||
"lifecycle state from "+ currentState + " to acceptable " +
|
"lifecycle state from "+ currentState + " to acceptable " +
|
||||||
@ -689,7 +691,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
+ applicationUuid);
|
+ applicationUuid);
|
||||||
|
|
||||||
}
|
}
|
||||||
lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState()));
|
lifecycleState.setNextStates(new ArrayList<>(lifecycleStateManger.
|
||||||
|
getNextLifecycleStates(lifecycleState.getCurrentState())));
|
||||||
} catch (ApplicationManagementDAOException e) {
|
} catch (ApplicationManagementDAOException e) {
|
||||||
throw new ApplicationManagementException("Failed to get lifecycle state", e);
|
throw new ApplicationManagementException("Failed to get lifecycle state", e);
|
||||||
} catch (ApplicationManagementException e) {
|
} catch (ApplicationManagementException e) {
|
||||||
@ -701,7 +704,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state)
|
public void changeLifecycleState(int applicationId, String applicationUuid, LifecycleState state)
|
||||||
throws ApplicationManagementException {
|
throws ApplicationManagementException {
|
||||||
try {
|
try {
|
||||||
ConnectionManagerUtil.openDBConnection();
|
ConnectionManagerUtil.openDBConnection();
|
||||||
@ -712,9 +715,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
state.setUpdatedBy(userName);
|
state.setUpdatedBy(userName);
|
||||||
|
|
||||||
if (state.getCurrentState() != null && state.getPreviousState() != null) {
|
if (state.getCurrentState() != null && state.getPreviousState() != null) {
|
||||||
validateLifecycleState(state);
|
if (lifecycleStateManger.isValidStateChange(state.getPreviousState(), state.getCurrentState())) {
|
||||||
this.lifecycleStateDAO
|
this.lifecycleStateDAO
|
||||||
.addLifecycleState(state, application.getId(), applicationRelease.getId(), tenantId);
|
.addLifecycleState(state, application.getId(), applicationRelease.getId(), tenantId);
|
||||||
|
} else {
|
||||||
|
log.error("Invalid lifecycle state transition from '" + state.getPreviousState() + "'"
|
||||||
|
+ " to '" + state.getCurrentState() + "'");
|
||||||
|
throw new ApplicationManagementException("Lifecycle State Validation failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (LifeCycleManagementDAOException | DBConnectionException e) {
|
} catch (LifeCycleManagementDAOException | DBConnectionException e) {
|
||||||
throw new ApplicationManagementException("Failed to add lifecycle state", e);
|
throw new ApplicationManagementException("Failed to add lifecycle state", e);
|
||||||
@ -725,99 +733,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getNextLifecycleStates(String currentLifecycleState) {
|
|
||||||
List<String> nextLifecycleStates = new ArrayList<>();
|
|
||||||
if (AppLifecycleState.CREATED.toString().equals(currentLifecycleState)) {
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.IN_REVIEW.toString());
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.IN_REVIEW.toString().equals(currentLifecycleState)) {
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.APPROVED.toString());
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.REJECTED.toString());
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.REJECTED.toString().equals(currentLifecycleState)) {
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.IN_REVIEW.toString());
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.REMOVED.toString());
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.APPROVED.toString().equals(currentLifecycleState)) {
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.PUBLISHED.toString());
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.PUBLISHED.toString().equals(currentLifecycleState)) {
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.UNPUBLISHED.toString());
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.DEPRECATED.toString());
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.UNPUBLISHED.toString().equals(currentLifecycleState)) {
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.PUBLISHED.toString());
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.REMOVED.toString());
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.DEPRECATED.toString().equals(currentLifecycleState)) {
|
|
||||||
nextLifecycleStates.add(AppLifecycleState.REMOVED.toString());
|
|
||||||
}
|
|
||||||
return nextLifecycleStates;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateLifecycleState(LifecycleState state) throws LifecycleManagementException {
|
|
||||||
|
|
||||||
if (AppLifecycleState.CREATED.toString().equals(state.getCurrentState())) {
|
|
||||||
throw new LifecycleManagementException("Current State Couldn't be " + state.getCurrentState());
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.IN_REVIEW.toString().equals(state.getCurrentState()) && !AppLifecycleState.CREATED
|
|
||||||
.toString().equals(state.getPreviousState()) && !AppLifecycleState.REJECTED.toString()
|
|
||||||
.equals(state.getPreviousState())) {
|
|
||||||
throw new LifecycleManagementException(
|
|
||||||
"If Current State is " + state.getCurrentState() + "Previous State should be either "
|
|
||||||
+ AppLifecycleState.CREATED.toString() + " or " + AppLifecycleState.REJECTED.toString());
|
|
||||||
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.APPROVED.toString().equals(state.getCurrentState()) && !AppLifecycleState.IN_REVIEW
|
|
||||||
.toString().equals(state.getPreviousState())) {
|
|
||||||
throw new LifecycleManagementException(
|
|
||||||
"If Current State is " + state.getCurrentState() + "Previous State should be "
|
|
||||||
+ AppLifecycleState.IN_REVIEW.toString());
|
|
||||||
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.PUBLISHED.toString().equals(state.getCurrentState()) && !AppLifecycleState.APPROVED
|
|
||||||
.toString().equals(state.getPreviousState()) && !AppLifecycleState.UNPUBLISHED.toString()
|
|
||||||
.equals(state.getPreviousState())) {
|
|
||||||
throw new LifecycleManagementException(
|
|
||||||
"If Current State is " + state.getCurrentState() + "Previous State should be either "
|
|
||||||
+ AppLifecycleState.APPROVED.toString() + " or " + AppLifecycleState.UNPUBLISHED
|
|
||||||
.toString());
|
|
||||||
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.UNPUBLISHED.toString().equals(state.getCurrentState()) && !AppLifecycleState.PUBLISHED
|
|
||||||
.toString().equals(state.getPreviousState())) {
|
|
||||||
throw new LifecycleManagementException(
|
|
||||||
"If Current State is " + state.getCurrentState() + "Previous State should be "
|
|
||||||
+ AppLifecycleState.PUBLISHED.toString());
|
|
||||||
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.REJECTED.toString().equals(state.getCurrentState()) && !AppLifecycleState.IN_REVIEW
|
|
||||||
.toString().equals(state.getPreviousState())) {
|
|
||||||
throw new LifecycleManagementException(
|
|
||||||
"If Current State is " + state.getCurrentState() + "Previous State should be "
|
|
||||||
+ AppLifecycleState.IN_REVIEW.toString());
|
|
||||||
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.DEPRECATED.toString().equals(state.getCurrentState()) && !AppLifecycleState.PUBLISHED
|
|
||||||
.toString().equals(state.getPreviousState())) {
|
|
||||||
|
|
||||||
throw new LifecycleManagementException(
|
|
||||||
"If Current State is " + state.getCurrentState() + "Previous State should be "
|
|
||||||
+ AppLifecycleState.PUBLISHED.toString());
|
|
||||||
|
|
||||||
}
|
|
||||||
if (AppLifecycleState.REMOVED.toString().equals(state.getCurrentState()) && !AppLifecycleState.DEPRECATED
|
|
||||||
.toString().equals(state.getPreviousState()) && !AppLifecycleState.REJECTED.toString()
|
|
||||||
.equals(state.getPreviousState()) && !AppLifecycleState.UNPUBLISHED.toString()
|
|
||||||
.equals(state.getPreviousState())) {
|
|
||||||
|
|
||||||
throw new LifecycleManagementException(
|
|
||||||
"If Current State is " + state.getCurrentState() + "Previous State should be either "
|
|
||||||
+ AppLifecycleState.DEPRECATED.toString() + " or " + AppLifecycleState.REJECTED.toString()
|
|
||||||
+ " or " + AppLifecycleState.UNPUBLISHED.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Application updateApplication(Application application) throws ApplicationManagementException {
|
public Application updateApplication(Application application) throws ApplicationManagementException {
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
|
|||||||
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
|
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
|
||||||
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
|
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
|
||||||
import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager;
|
import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
@ -45,6 +46,8 @@ public class DataHolder {
|
|||||||
|
|
||||||
private ApplicationStorageManager applicationStorageManager;
|
private ApplicationStorageManager applicationStorageManager;
|
||||||
|
|
||||||
|
private LifecycleStateManger lifecycleStateManger;
|
||||||
|
|
||||||
private static final DataHolder applicationMgtDataHolder = new DataHolder();
|
private static final DataHolder applicationMgtDataHolder = new DataHolder();
|
||||||
|
|
||||||
private DataHolder() {
|
private DataHolder() {
|
||||||
@ -110,4 +113,12 @@ public class DataHolder {
|
|||||||
public ApplicationStorageManager getApplicationStorageManager() {
|
public ApplicationStorageManager getApplicationStorageManager() {
|
||||||
return applicationStorageManager;
|
return applicationStorageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LifecycleStateManger getLifecycleStateManager() {
|
||||||
|
return lifecycleStateManger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLifecycleStateManger(LifecycleStateManger lifecycleStateManger) {
|
||||||
|
this.lifecycleStateManger = lifecycleStateManger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,12 +31,15 @@ import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleMa
|
|||||||
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
|
||||||
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
|
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @scr.component name="org.wso2.carbon.application.mgt.service" immediate="true"
|
* @scr.component name="org.wso2.carbon.application.mgt.service" immediate="true"
|
||||||
@ -93,6 +96,12 @@ public class ServiceComponent {
|
|||||||
|
|
||||||
ApplicationManagementDAOFactory.init(datasourceName);
|
ApplicationManagementDAOFactory.init(datasourceName);
|
||||||
ApplicationManagementDAOFactory.initDatabases();
|
ApplicationManagementDAOFactory.initDatabases();
|
||||||
|
|
||||||
|
List<LifecycleState> lifecycleStates = ConfigurationManager.getInstance().
|
||||||
|
getConfiguration().getLifecycleStates();
|
||||||
|
LifecycleStateManger lifecycleStateManger = new LifecycleStateManger(lifecycleStates);
|
||||||
|
DataHolder.getInstance().setLifecycleStateManger(lifecycleStateManger);
|
||||||
|
|
||||||
log.info("ApplicationManagement core bundle has been successfully initialized");
|
log.info("ApplicationManagement core bundle has been successfully initialized");
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
log.error("Error while activating Application Management core component. ", e);
|
log.error("Error while activating Application Management core component. ", e);
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
package org.wso2.carbon.device.application.mgt.core.lifecycle;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the activities related to lifecycle management
|
||||||
|
*/
|
||||||
|
public class LifecycleStateManger {
|
||||||
|
|
||||||
|
private Map<String, State> lifecycleStates;
|
||||||
|
|
||||||
|
public LifecycleStateManger(List<LifecycleState> states) {
|
||||||
|
lifecycleStates = new HashMap<>();
|
||||||
|
for (LifecycleState s : states) {
|
||||||
|
lifecycleStates.put(s.getName(), new State(s.getName(), s.getProceedingStates()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getNextLifecycleStates(String currentLifecycleState) {
|
||||||
|
return lifecycleStates.get(currentLifecycleState).getProceedingStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValidStateChange(String currentState, String nextState) {
|
||||||
|
if (lifecycleStates.get(currentState).getProceedingStates().contains(nextState)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package org.wso2.carbon.device.application.mgt.core.lifecycle;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the state of the lifecycle
|
||||||
|
*/
|
||||||
|
public class State {
|
||||||
|
|
||||||
|
private Set<String> proceedingStates;
|
||||||
|
private String stateName;
|
||||||
|
|
||||||
|
public State(String stateName, List<String> states) {
|
||||||
|
this.stateName = stateName;
|
||||||
|
if (states != null && !states.isEmpty()) {
|
||||||
|
proceedingStates = new HashSet<>(states);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getState() {
|
||||||
|
return stateName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getProceedingStates() {
|
||||||
|
return proceedingStates;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package org.wso2.carbon.device.application.mgt.core.lifecycle.config;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the lifecycle state config
|
||||||
|
*/
|
||||||
|
public class LifecycleState {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private List<String> proceedingStates;
|
||||||
|
|
||||||
|
@XmlAttribute(name = "name")
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElementWrapper(name = "ProceedingStates")
|
||||||
|
@XmlElement(name = "State")
|
||||||
|
public List<String> getProceedingStates() {
|
||||||
|
return proceedingStates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProceedingStates(List<String> proceedingStates) {
|
||||||
|
this.proceedingStates = proceedingStates;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,25 +17,30 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.application.mgt.core;
|
package org.wso2.carbon.device.application.mgt.core;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
|
|
||||||
import org.wso2.carbon.device.application.mgt.core.config.Configuration;
|
import org.wso2.carbon.device.application.mgt.core.config.Configuration;
|
||||||
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.List;
|
||||||
|
|
||||||
public class ConfigurationTest {
|
public class ConfigurationTest {
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void init() throws InvalidConfigurationException {
|
|
||||||
File configPath = new File("src/test/resources/application-mgt.xml");
|
|
||||||
ConfigurationManager.setConfigLocation(configPath.getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateConfiguration() {
|
public void validateConfiguration() {
|
||||||
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
|
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
|
||||||
Configuration configuration = configurationManager.getConfiguration();
|
Configuration configuration = configurationManager.getConfiguration();
|
||||||
|
Assert.assertNotNull("Invalid app manager configuration", configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void validateLifecycleStateConfiguration() {
|
||||||
|
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
|
||||||
|
Configuration configuration = configurationManager.getConfiguration();
|
||||||
|
List<LifecycleState> lifecycleStates = configuration.getLifecycleStates();
|
||||||
|
Assert.assertNotNull("Invalid lifecycle states configuration", lifecycleStates);
|
||||||
|
Assert.assertTrue("Invalid lifecycle states configuration. Lifecycle states cannot be empty",
|
||||||
|
!lifecycleStates.isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,20 @@
|
|||||||
|
package org.wso2.carbon.device.application.mgt.core;
|
||||||
|
|
||||||
|
import org.testng.annotations.BeforeSuite;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class initializes the required configurations prior running the tests
|
||||||
|
*/
|
||||||
|
public class InitTest {
|
||||||
|
|
||||||
|
@BeforeSuite
|
||||||
|
public void init() throws InvalidConfigurationException {
|
||||||
|
File configPath = new File("src/test/resources/application-mgt.xml");
|
||||||
|
ConfigurationManager.setConfigLocation(configPath.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package org.wso2.carbon.device.application.mgt.core;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.config.Configuration;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class LifecycleManagementTest {
|
||||||
|
|
||||||
|
private List<LifecycleState> lifecycleStates;
|
||||||
|
private LifecycleStateManger lifecycleStateManger;
|
||||||
|
|
||||||
|
private final String CURRENT_STATE = "Approved";
|
||||||
|
private final String NEXT_STATE = "Published";
|
||||||
|
private final String BOGUS_STATE = "Removed";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void init() {
|
||||||
|
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
|
||||||
|
Configuration configuration = configurationManager.getConfiguration();
|
||||||
|
lifecycleStates = configuration.getLifecycleStates();
|
||||||
|
lifecycleStateManger = new LifecycleStateManger(lifecycleStates);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkValidNextLifecycleState() {
|
||||||
|
Set<String> proceedingStates = lifecycleStateManger.getNextLifecycleStates(CURRENT_STATE);
|
||||||
|
Assert.assertTrue("Invalid proceeding state of: " + CURRENT_STATE,
|
||||||
|
proceedingStates.contains(NEXT_STATE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkInvalidNextLifecycleState() {
|
||||||
|
Set<String> proceedingStates = lifecycleStateManger.getNextLifecycleStates(CURRENT_STATE);
|
||||||
|
Assert.assertFalse("Invalid proceeding state of: " + CURRENT_STATE,
|
||||||
|
proceedingStates.contains(BOGUS_STATE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkValidStateChange() {
|
||||||
|
Assert.assertTrue("Invalid state transition from: " + CURRENT_STATE + " to: " + NEXT_STATE,
|
||||||
|
lifecycleStateManger.isValidStateChange(CURRENT_STATE, NEXT_STATE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkInvalidStateChange() {
|
||||||
|
Assert.assertFalse("Invalid state transition from: " + CURRENT_STATE + " to: " + BOGUS_STATE,
|
||||||
|
lifecycleStateManger.isValidStateChange(CURRENT_STATE, BOGUS_STATE));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -58,4 +58,47 @@
|
|||||||
</Extension>
|
</Extension>
|
||||||
</Extensions>
|
</Extensions>
|
||||||
|
|
||||||
|
<LifecycleStates>
|
||||||
|
<LifecycleState name="Created">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>In-Review</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="In-Review">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>Rejected</State>
|
||||||
|
<State>Approved</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Approved">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>Published</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Rejected">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>In-Review</State>
|
||||||
|
<State>Removed</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Published">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>Unpublished</State>
|
||||||
|
<State>Deprecated</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Unpublished">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>Removed</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Deprecated">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>Removed</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Removed">
|
||||||
|
</LifecycleState>
|
||||||
|
</LifecycleStates>
|
||||||
|
|
||||||
</ApplicationManagementConfiguration>
|
</ApplicationManagementConfiguration>
|
||||||
|
|||||||
@ -22,8 +22,11 @@
|
|||||||
<suite name="ApplicationManagementCore">
|
<suite name="ApplicationManagementCore">
|
||||||
<test name="Util classes tests" preserve-order="true">
|
<test name="Util classes tests" preserve-order="true">
|
||||||
<classes>
|
<classes>
|
||||||
|
<class name="org.wso2.carbon.device.application.mgt.core.InitTest"/>
|
||||||
<class name="org.wso2.carbon.device.application.mgt.core.ArtifactParserTest"/>
|
<class name="org.wso2.carbon.device.application.mgt.core.ArtifactParserTest"/>
|
||||||
<class name="org.wso2.carbon.device.application.mgt.core.StorageManagementUtilTest"/>
|
<class name="org.wso2.carbon.device.application.mgt.core.StorageManagementUtilTest"/>
|
||||||
|
<class name="org.wso2.carbon.device.application.mgt.core.ConfigurationTest"/>
|
||||||
|
<class name="org.wso2.carbon.device.application.mgt.core.LifecycleManagementTest"/>
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
||||||
@ -448,7 +448,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
|||||||
LifecycleState state) {
|
LifecycleState state) {
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
try {
|
try {
|
||||||
applicationManager.addLifecycleState(applicationId, applicationUuid, state);
|
applicationManager.changeLifecycleState(applicationId, applicationUuid, state);
|
||||||
} catch (ApplicationManagementException e) {
|
} catch (ApplicationManagementException e) {
|
||||||
String msg = "Error occurred while adding lifecycle state.";
|
String msg = "Error occurred while adding lifecycle state.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
|
|||||||
@ -60,4 +60,61 @@
|
|||||||
</Parameters>
|
</Parameters>
|
||||||
</Extension>
|
</Extension>
|
||||||
</Extensions>
|
</Extensions>
|
||||||
|
|
||||||
|
<!-- This is for publisher lifecycle -->
|
||||||
|
<!-- The current lifecycle as follows
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
[Created] -> [In-Review] -> [Approved] -> [Published] -> [Unpublished] -> [Removed]
|
||||||
|
^ | ^
|
||||||
|
| | |
|
||||||
|
| |-> [Deprecated] - - - - - - - -|
|
||||||
|
| |
|
||||||
|
|-> [Rejected] - - - - - - - - - - - - - - - - - - - - - - - - |
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<LifecycleStates>
|
||||||
|
<LifecycleState name="Created">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>In-Review</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="In-Review">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>Rejected</State>
|
||||||
|
<State>Approved</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Approved">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>Published</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Rejected">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>In-Review</State>
|
||||||
|
<State>Removed</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Published">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>Unpublished</State>
|
||||||
|
<State>Deprecated</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Unpublished">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>Removed</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Deprecated">
|
||||||
|
<ProceedingStates>
|
||||||
|
<State>Removed</State>
|
||||||
|
</ProceedingStates>
|
||||||
|
</LifecycleState>
|
||||||
|
<LifecycleState name="Removed">
|
||||||
|
</LifecycleState>
|
||||||
|
</LifecycleStates>
|
||||||
|
|
||||||
</ApplicationManagementConfiguration>
|
</ApplicationManagementConfiguration>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user