Fix get lifecycle issue

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent f4e1ca6815
commit 409f6fce14

@ -122,25 +122,15 @@ public interface ApplicationManager {
*/ */
Boolean isUserAllowable(List<UnrestrictedRole> unrestrictedRoles, String userName) throws ApplicationManagementException; Boolean isUserAllowable(List<UnrestrictedRole> unrestrictedRoles, String userName) throws ApplicationManagementException;
// todo
// /**
// * To get all the releases of a particular Application.
// *
// * @param applicationId ID of the Application to get all the releases.
// * @return the List of the Application releases related with the particular Application.
// * @throws ApplicationManagementException Application Management Exception.
// */
// List<ApplicationRelease> getinstallableReleases(int applicationId) throws ApplicationManagementException;
/** /**
* To get all the releases of a particular Application. * To get all the releases of a particular Application.
* *
* @param applicationId ID of the Application . * @param applicationId ID of the Application .
* @param applicationUuid UUID of the Application Release. * @param releaseUuid UUID of the Application Release.
* @return the LifecycleState of the Application releases related with the particular Application. * @return the LifecycleState of the Application releases related with the particular Application.
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws ApplicationManagementException; LifecycleState getLifecycleState(int applicationId, String releaseUuid) throws ApplicationManagementException;
/** /**
* To get all the releases of a particular Application. * To get all the releases of a particular Application.

@ -31,6 +31,8 @@ public interface LifecycleStateDAO {
LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws ApplicationManagementDAOException; LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws ApplicationManagementDAOException;
LifecycleState getLatestLifeCycleState(int appId, String uuid) throws ApplicationManagementDAOException;
List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException; List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException;
void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException; void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException;

@ -74,6 +74,44 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
} }
} }
public LifecycleState getLatestLifeCycleState(int appId, String uuid) throws ApplicationManagementDAOException{
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql = "SELECT ID, CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM "
+ "AP_APP_LIFECYCLE_STATE WHERE AP_APP_ID=? AND AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE "
+ "WHERE UUID=?) ORDER BY UPDATED_AT DESC;";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, appId);
stmt.setString(2, uuid);
rs = stmt.executeQuery();
LifecycleState lifecycleState = null;
if (rs.next()) {
lifecycleState = new LifecycleState();
lifecycleState.setId(rs.getInt("ID"));
lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE"));
lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT"));
lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY"));
}
return lifecycleState;
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application List", e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection to get latest"
+ " lifecycle state for a specific application", e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override @Override
public List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException { public List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException {
List<LifecycleState> lifecycleStates = new ArrayList<>(); List<LifecycleState> lifecycleStates = new ArrayList<>();
@ -116,8 +154,8 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_BY, " String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_BY, "
+ "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,?,?);"; + "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,?,?);";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, state.getCurrentState()); stmt.setString(1, state.getCurrentState().toUpperCase());
stmt.setString(2, state.getPreviousState()); stmt.setString(2, state.getPreviousState().toUpperCase());
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
stmt.setString(4, state.getUpdatedBy()); stmt.setString(4, state.getUpdatedBy());
stmt.setInt(5, releaseId); stmt.setInt(5, releaseId);

@ -67,7 +67,6 @@ import java.util.List;
public class ApplicationManagerImpl implements ApplicationManager { public class ApplicationManagerImpl implements ApplicationManager {
private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class); private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class);
private DeviceTypeDAO deviceTypeDAO;
private VisibilityDAO visibilityDAO; private VisibilityDAO visibilityDAO;
private ApplicationDAO applicationDAO; private ApplicationDAO applicationDAO;
private ApplicationReleaseDAO applicationReleaseDAO; private ApplicationReleaseDAO applicationReleaseDAO;
@ -81,7 +80,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
private void initDataAccessObjects() { private void initDataAccessObjects() {
this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO();
this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
@ -422,35 +420,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
// todo
// public List<ApplicationRelease> getinstallableReleases(int applicationId) throws ApplicationManagementException {
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
//
// Application application = getApplicationIfAccessible(applicationId);
// List<ApplicationRelease> applicationReleases;
// List<ApplicationRelease> filteredApplicationReleases = new ArrayList<>();
// if (log.isDebugEnabled()) {
// log.debug("Request is received to retrieve all the releases related with the application " + application
// .toString());
// }
// ConnectionManagerUtil.getDBConnection();
// applicationReleases = this.applicationReleaseDAO.getReleases(application.getName(), application.getType(), tenantId);
// for (ApplicationRelease applicationRelease : applicationReleases) {
// LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO().
// getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
// if (lifecycleState != null) {
// applicationRelease.setLifecycleState(lifecycleState);
//
// if (!AppLifecycleState.REMOVED.toString()
// .equals(applicationRelease.getLifecycleState().getCurrentState())) {
// filteredApplicationReleases.add(applicationRelease);
// }
// }
// }
// return filteredApplicationReleases;
//
// }
private List<ApplicationRelease> getReleases(Application application, boolean requirePublishedRelease) private List<ApplicationRelease> getReleases(Application application, boolean requirePublishedRelease)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -785,19 +754,19 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws public LifecycleState getLifecycleState(int applicationId, String releaseUuid) throws
ApplicationManagementException { ApplicationManagementException {
LifecycleState lifecycleState; LifecycleState lifecycleState;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationId); lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleState(applicationId, releaseUuid);
if (lifecycleState == null) { if (lifecycleState == null) {
throw new NotFoundException( throw new NotFoundException(
"Couldn't find the lifecycle data for appid: " + applicationId + " and app release UUID: " "Couldn't find the lifecycle data for appid: " + applicationId + " and app release UUID: "
+ applicationUuid); + releaseUuid);
} }
lifecycleState.setNextStates(new ArrayList<>(lifecycleStateManger. lifecycleState.setNextStates(new ArrayList<>(getLifecycleManagementService().
getNextLifecycleStates(lifecycleState.getCurrentState()))); 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);

@ -18,7 +18,11 @@ public class LifecycleStateManger {
public LifecycleStateManger(List<LifecycleState> states) { public LifecycleStateManger(List<LifecycleState> states) {
lifecycleStates = new HashMap<>(); lifecycleStates = new HashMap<>();
for (LifecycleState s : states) { for (LifecycleState s : states) {
lifecycleStates.put(s.getName(), new State(s.getName(), s.getProceedingStates())); if (s.getProceedingStates() != null) {
s.getProceedingStates().replaceAll(String::toUpperCase);
}
lifecycleStates.put(s.getName().toUpperCase(), new State(s.getName().toUpperCase(), s.getProceedingStates()));
} }
} }

@ -16,9 +16,9 @@ public class LifecycleManagementTest {
private List<LifecycleState> lifecycleStates; private List<LifecycleState> lifecycleStates;
private LifecycleStateManger lifecycleStateManger; private LifecycleStateManger lifecycleStateManger;
private final String CURRENT_STATE = "Approved"; private final String CURRENT_STATE = "APPROVED";
private final String NEXT_STATE = "Published"; private final String NEXT_STATE = "PUBLISHED";
private final String BOGUS_STATE = "Removed"; private final String BOGUS_STATE = "REMOVED";
@BeforeClass @BeforeClass
public void init() { public void init() {

Loading…
Cancel
Save