Merge branch 'master' into 'master'

Fix APPM lifEcycle history loading issue

See merge request entgra/carbon-device-mgt!565
revert-70ac1926
Dharmakeerthi Lasantha 5 years ago
commit a1106bec84

@ -72,7 +72,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
+ "application. Application release UUID: " + uuid + ". Executed Query: " + sql; + "application. Application release UUID: " + uuid + ". Executed Query: " + sql;
log.error(msg, e); log.error(msg, e);
throw new LifeCycleManagementDAOException(msg, e); throw new LifeCycleManagementDAOException(msg, e);
} }
} }
@Override @Override
@ -117,7 +117,6 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
@Override @Override
public List<LifecycleState> getLifecycleStates(int appReleaseId, int tenantId) throws LifeCycleManagementDAOException { public List<LifecycleState> getLifecycleStates(int appReleaseId, int tenantId) throws LifeCycleManagementDAOException {
List<LifecycleState> lifecycleStates = new ArrayList<>();
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
String sql = "SELECT " String sql = "SELECT "
@ -133,9 +132,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
stmt.setInt(1,appReleaseId); stmt.setInt(1,appReleaseId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()){ try (ResultSet rs = stmt.executeQuery()){
while (rs.next()) { return getLifecycleStates(rs);
lifecycleStates.add(constructLifecycle(rs));
}
} }
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
@ -149,7 +146,6 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
log.error(msg, e); log.error(msg, e);
throw new LifeCycleManagementDAOException(msg, e); throw new LifeCycleManagementDAOException(msg, e);
} }
return lifecycleStates;
} }
@Override @Override
@ -254,7 +250,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
private LifecycleState constructLifecycle(ResultSet rs) throws LifeCycleManagementDAOException { private LifecycleState constructLifecycle(ResultSet rs) throws LifeCycleManagementDAOException {
LifecycleState lifecycleState = null; LifecycleState lifecycleState = null;
try { try {
if (rs !=null && rs.next()) { if (rs.next()) {
lifecycleState = new LifecycleState(); lifecycleState = new LifecycleState();
lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE"));
@ -268,4 +264,31 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
} }
return lifecycleState; return lifecycleState;
} }
/**
* Get the list of lifecycle states by using Result Set
*
* @param rs ResultSet object
* @return List of life cycle states
* @throws LifeCycleManagementDAOException if error occurred while getting lifecycle state data from ResultSet
* object
*/
private List<LifecycleState> getLifecycleStates(ResultSet rs) throws LifeCycleManagementDAOException {
List<LifecycleState> lifecycleStates = new ArrayList<>();
try {
while (rs.next()) {
LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE"));
lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT"));
lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY"));
lifecycleStates.add(lifecycleState);
}
} catch (SQLException e) {
String msg = "Error occurred while construct lifecycle state by data which is retrieved from SQL query";
log.error(msg, e);
throw new LifeCycleManagementDAOException(msg, e);
}
return lifecycleStates;
}
} }

Loading…
Cancel
Save