working state on happy path app create

4.x.x
inoshperera 6 years ago
parent 27e4dc14d3
commit 4512a4e2d7

@ -100,13 +100,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ " the user : " + application.getUser().getUserName());
}
ConnectionManagerUtil.openDBConnection();
validateAppCreatingRequest(application);
validateAppReleasePayload(application.getApplicationReleases().get(0));
DeviceType deviceType;
ApplicationRelease applicationRelease;
List<ApplicationRelease> applicationReleases = new ArrayList<>();
try {
ConnectionManagerUtil.getDBConnection();
ConnectionManagerUtil.beginDBTransaction();
MAMDeviceConnectorImpl mamDeviceConnector = new MAMDeviceConnectorImpl();
// Getting the device type details to get device type ID for internal mappings
@ -743,7 +744,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
state.setUpdatedBy(userName);
if (state.getCurrentState() != null && state.getPreviousState() != null) {
if (lifecycleStateManger.isValidStateChange(state.getPreviousState(), state.getCurrentState())) {
if (getLifecycleManagementService().isValidStateChange(state.getPreviousState(), state.getCurrentState())) {
this.lifecycleStateDAO
.addLifecycleState(state, applicationId, releaseId, tenantId);
} else {
@ -859,4 +861,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
return list;
}
public LifecycleStateManger getLifecycleManagementService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
LifecycleStateManger deviceManagementProviderService =
(LifecycleStateManger) ctx.getOSGiService(LifecycleStateManger.class, null);
if (deviceManagementProviderService == null) {
String msg = "DeviceImpl Management provider service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return deviceManagementProviderService;
}
}

@ -103,6 +103,7 @@ public class ApplicationManagementServiceComponent {
getConfiguration().getLifecycleStates();
LifecycleStateManger lifecycleStateManger = new LifecycleStateManger(lifecycleStates);
DataHolder.getInstance().setLifecycleStateManger(lifecycleStateManger);
bundleContext.registerService(LifecycleStateManger.class.getName(), lifecycleStateManger, null);
log.info("ApplicationManagement core bundle has been successfully initialized");
} catch (Throwable e) {

@ -3,6 +3,7 @@ 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.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -26,9 +27,36 @@ public class LifecycleStateManger {
}
public boolean isValidStateChange(String currentState, String nextState) {
if (lifecycleStates.get(currentState).getProceedingStates().contains(nextState)) {
if (currentState.equalsIgnoreCase(nextState)) {
return true;
}
State state = getMatchingState(currentState);
if (state != null) {
return getMatchingNextState(state.getProceedingStates(), nextState);
}
return false;
}
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)) {
return lifecycleStates.get(pair.getKey().toString());
}
it.remove();
}
return null;
}
private boolean getMatchingNextState(Set<String> proceedingStates, String nextState) {
for (String state: proceedingStates) {
if (state.equalsIgnoreCase(nextState)) {
return true;
}
}
return false;
}
}

Loading…
Cancel
Save