Adding DAO layer changes

feature/appm-store/pbac
lasantha 7 years ago
parent 45c668ecce
commit d196e3e0e1

@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.common;
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude; import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -28,10 +29,6 @@ import java.util.List;
*/ */
public class ApplicationRelease { public class ApplicationRelease {
private enum ReleaseType {
PRODUCTION, ALPHA, BETA
}
@Exclude @Exclude
private int id; private int id;
@ -51,14 +48,36 @@ public class ApplicationRelease {
private String screenshotLoc3; private String screenshotLoc3;
private ReleaseType releaseType; private String applicationCreator;
private String releaseType;
private Double price; private Double price;
private Timestamp createdAt;
private String publishedBy;
private Timestamp publishedAt;
private int starts;
private String modifiedBy;
private Timestamp modifiedAt;
private ImageArtifact icon; private ImageArtifact icon;
private ImageArtifact banner; private ImageArtifact banner;
private String currentState;
private String previouseState;
private String stateModifiedBy;
private Timestamp stateModifiedAt;
private List<ImageArtifact> screenShots = new ArrayList<>(); private List<ImageArtifact> screenShots = new ArrayList<>();
private String appHashValue; private String appHashValue;
@ -67,10 +86,6 @@ public class ApplicationRelease {
private String metaData; private String metaData;
private List<Comment> comments;
private Lifecycle lifecycle;
public void setId(int id) { public void setId(int id) {
this.id = id; this.id = id;
} }
@ -91,7 +106,11 @@ public class ApplicationRelease {
this.uuid = uuid; this.uuid = uuid;
} }
public void setReleaseType(ReleaseType releaseType) { public String getReleaseType() {
return releaseType;
}
public void setReleaseType(String releaseType) {
this.releaseType = releaseType; this.releaseType = releaseType;
} }
@ -127,10 +146,6 @@ public class ApplicationRelease {
return tenantId; return tenantId;
} }
public ReleaseType getReleaseType() {
return releaseType;
}
public Double getPrice() { public Double getPrice() {
return price; return price;
} }
@ -139,6 +154,38 @@ public class ApplicationRelease {
this.price = price; this.price = price;
} }
public String getCurrentState() {
return currentState;
}
public void setCurrentState(String currentState) {
this.currentState = currentState;
}
public String getPreviouseState() {
return previouseState;
}
public void setPreviouseState(String previouseState) {
this.previouseState = previouseState;
}
public String getStateModifiedBy() {
return stateModifiedBy;
}
public void setStateModifiedBy(String stateModifiedBy) {
this.stateModifiedBy = stateModifiedBy;
}
public Timestamp getStateModifiedAt() {
return stateModifiedAt;
}
public void setStateModifiedAt(Timestamp stateModifiedAt) {
this.stateModifiedAt = stateModifiedAt;
}
public ImageArtifact getIcon() { public ImageArtifact getIcon() {
return icon; return icon;
} }
@ -163,12 +210,6 @@ public class ApplicationRelease {
return metaData; return metaData;
} }
public List<Comment> getComments() { return comments; }
public void setComments(List<Comment> comments) {
this.comments = comments;
}
public String getAppStoredLoc() { public String getAppStoredLoc() {
return appStoredLoc; return appStoredLoc;
} }
@ -209,11 +250,59 @@ public class ApplicationRelease {
this.screenshotLoc3 = screenshotLoc3; this.screenshotLoc3 = screenshotLoc3;
} }
public Lifecycle getLifecycle() { public String getApplicationCreator() {
return lifecycle; return applicationCreator;
}
public void setApplicationCreator(String applicationCreator) {
this.applicationCreator = applicationCreator;
}
public Timestamp getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Timestamp createdAt) {
this.createdAt = createdAt;
}
public String getPublishedBy() {
return publishedBy;
}
public void setPublishedBy(String publishedBy) {
this.publishedBy = publishedBy;
}
public Timestamp getPublishedAt() {
return publishedAt;
}
public void setPublishedAt(Timestamp publishedAt) {
this.publishedAt = publishedAt;
}
public int getStarts() {
return starts;
}
public void setStarts(int starts) {
this.starts = starts;
}
public String getModifiedBy() {
return modifiedBy;
}
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
public Timestamp getModifiedAt() {
return modifiedAt;
} }
public void setLifecycle(Lifecycle lifecycle) { public void setModifiedAt(Timestamp modifiedAt) {
this.lifecycle = lifecycle; this.modifiedAt = modifiedAt;
} }
} }

@ -18,18 +18,25 @@
*/ */
package org.wso2.carbon.device.application.mgt.common; package org.wso2.carbon.device.application.mgt.common;
/** import java.sql.Timestamp;
* Represents a state in {@link Lifecycle}.
*/
public class LifecycleState { public class LifecycleState {
private int id; private int id;
private String name; private String currentState;
private String previousState;
private String updatedBy;
private Timestamp updatedAt;
private int tenantId;
private String identifier; private int releaseId;
private String description; private int appId;
public int getId() { public int getId() {
return id; return id;
@ -39,27 +46,60 @@ public class LifecycleState {
this.id = id; this.id = id;
} }
public String getName() { public String getCurrentState() {
return name; return currentState;
}
public void setCurrentState(String currentState) {
this.currentState = currentState;
}
public String getPreviousState() {
return previousState;
}
public void setPreviousState(String previousState) {
this.previousState = previousState;
} }
public void setName(String name) { public String getUpdatedBy() {
this.name = name; return updatedBy;
} }
public String getIdentifier() { public void setUpdatedBy(String updatedBy) {
return identifier; this.updatedBy = updatedBy;
} }
public void setIdentifier(String identifier) { public Timestamp getUpdatedAt() {
this.identifier = identifier; return updatedAt;
} }
public String getDescription() { public void setUpdatedAt(Timestamp updatedAt) {
return description; this.updatedAt = updatedAt;
} }
public void setDescription(String description) { public int getTenantId() {
this.description = description; return tenantId;
} }
public void setTenantId(int tenantId) {
this.tenantId = tenantId;
}
public int getReleaseId() {
return releaseId;
}
public void setReleaseId(int releaseId) {
this.releaseId = releaseId;
}
public int getAppId() {
return appId;
}
public void setAppId(int appId) {
this.appId = appId;
}
} }

@ -19,9 +19,8 @@
package org.wso2.carbon.device.application.mgt.core.dao; package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.sql.Timestamp;
import java.util.List; import java.util.List;
/** /**
@ -104,16 +103,16 @@ public interface ApplicationDAO {
* @return Updated Application. * @return Updated Application.
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException; Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException,
ApplicationManagementException;
/** /**
* To delete the application identified by the UUID * To delete the application
* *
* @param uuid UUID of the application. * @param appId ID of the application.
* @param tenantId ID of tenant which the Application belongs to.
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
void deleteApplication(String uuid, int tenantId) throws ApplicationManagementDAOException; void deleteApplication(int appId) throws ApplicationManagementDAOException;
/** /**
* To get the application count that satisfies gives search query. * To get the application count that satisfies gives search query.
@ -124,13 +123,6 @@ public interface ApplicationDAO {
*/ */
int getApplicationCount(Filter filter) throws ApplicationManagementDAOException; int getApplicationCount(Filter filter) throws ApplicationManagementDAOException;
/**
* To delete the properties of a application.
*
* @param applicationId ID of the application to delete the properties.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void deleteProperties(int applicationId) throws ApplicationManagementDAOException;
/** /**
* To delete the tags of a application. * To delete the tags of a application.
@ -139,59 +131,5 @@ public interface ApplicationDAO {
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
void deleteTags(int applicationId) throws ApplicationManagementDAOException; void deleteTags(int applicationId) throws ApplicationManagementDAOException;
/**
* To change the lifecycle state of the application.
*
* @param applicationUUID UUID of the application.
* @param lifecycleIdentifier New lifecycle state.
* @param username Name of the user.
* @param tenantId ID of the tenant.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void changeLifecycle(String applicationUUID, String lifecycleIdentifier, String username, int tenantId)
throws ApplicationManagementDAOException;
/**
* To get the next possible lifecycle states for the application.
*
* @param applicationUUID UUID of the application.
* @param tenantId ID of the tenant.
* @return Next possible lifecycle states.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
List<LifecycleStateTransition> getNextLifeCycleStates(String applicationUUID, int tenantId)
throws ApplicationManagementDAOException;
/**
* To get the next possible lifecycle states for the application.
*
* @param lifecycle lifecycle of the application.
* @param tenantId tenantId of the application useer.
* @param appReleaseId relesse id of the application.
* @param appId application id of the application.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
public void addLifecycle(Lifecycle lifecycle, int tenantId, int appReleaseId, int appId)
throws ApplicationManagementDAOException;
/**
* To update the screen-shot count of a application.
*
* @param applicationUUID UUID of the application.
* @param tenantId ID of the tenant.
* @param count New count of the screen-shots.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void updateScreenShotCount(String applicationUUID, int tenantId, int count)
throws ApplicationManagementDAOException;
/**
* To check whether atleast one application exist under category.
*
* @param categoryName Name of the category.
* @return true if atleast one application exist under the given category, otherwise false.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
boolean isApplicationExist(String categoryName) throws ApplicationManagementDAOException;
} }

@ -40,22 +40,29 @@ public interface ApplicationReleaseDAO {
/** /**
* To get a release details with the particular version. * To get a release details with the particular version.
* @param applicationUuid UUID of the application to get the release. * @param applicationName name of the application to get the release.
* @param versionName Name of the version * @param versionName Name of the version
* @param applicationType Type of the application release
* @param releaseType type of the release
* @param tenantId tenantId of the application
* @return ApplicationRelease for the particular version of the given application * @return ApplicationRelease for the particular version of the given application
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
ApplicationRelease getRelease(String applicationUuid, String versionName, int tenantId) throws ApplicationRelease getRelease(String applicationName,String applicationType, String versionName,
String releaseType, int tenantId) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
/** /**
* To get all the releases of a particular application. * To get all the releases of a particular application.
* *
* @param applicationUUID Application UUID * @param applicationName Name of the Application
* @param applicationType Type of the Application
* @param tenantId tenant id of the application
* @return list of the application releases * @return list of the application releases
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
List<ApplicationRelease> getApplicationReleases(String applicationUUID, int tenantId) throws List<ApplicationRelease> getApplicationReleases(String applicationName, String applicationType, int tenantId) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
/** /**
@ -66,6 +73,15 @@ public interface ApplicationReleaseDAO {
*/ */
ApplicationRelease updateRelease(ApplicationRelease applicationRelease) throws ApplicationManagementDAOException; ApplicationRelease updateRelease(ApplicationRelease applicationRelease) throws ApplicationManagementDAOException;
/**
* To update an Application release.
* @param id id of the ApplicationRelease that need to be updated.
* @param stars given stars for the application.
* @throws ApplicationManagementDAOException Application Management DAO Exception
*/
void updateStars(int id, int stars) throws ApplicationManagementDAOException;
/** /**
* To delete a particular release. * To delete a particular release.
* *
@ -75,23 +91,4 @@ public interface ApplicationReleaseDAO {
*/ */
void deleteRelease(int id, String version) throws ApplicationManagementDAOException; void deleteRelease(int id, String version) throws ApplicationManagementDAOException;
/**
* To delete the propertied of a particular Application Release.
*
* @param id ID of the ApplicationRelease in which properties need to be deleted.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void deleteReleaseProperties(int id) throws ApplicationManagementDAOException;
/**
* To change the default version of a particular release channel.
* @param uuid UUID of the application
* @param version Version of the application
* @param isDefault true if the request is to make the application as default one unless false
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void changeReleaseDefault(String uuid, String version, boolean isDefault, String releaseChannel, int tenantId)
throws ApplicationManagementDAOException;
} }

@ -1,43 +0,0 @@
/*
*
* Copyright (c) ${date}, 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.
* /
*/
package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.Lifecycle;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException;
import java.util.List;
/**
* This is responsible for all the DAO operations related to Lifecycle state.
*/
public interface LifecycleDAO {
Lifecycle getLifeCycleOfApplication(int identifier) throws LifeCycleManagementDAOException;
List<Lifecycle> getLifecyclesOfAllAppVersions (int identifier) throws LifeCycleManagementDAOException;
void addLifecycle(Lifecycle lifecycle) throws LifeCycleManagementDAOException;
void updateLifecycleOfApplication(LifecycleState state) throws LifeCycleManagementDAOException;
void deleteLifecycleOfApplication(String identifier) throws LifeCycleManagementDAOException;
}

@ -29,12 +29,12 @@ import java.util.List;
*/ */
public interface LifecycleStateDAO { public interface LifecycleStateDAO {
LifecycleState getLifeCycleStateByIdentifier(String identifier) throws ApplicationManagementDAOException; LifecycleState getLatestLifeCycleStateByReleaseID(int identifier) throws ApplicationManagementDAOException;
List<LifecycleState> getLifecycleStates() throws LifeCycleManagementDAOException; List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException;
void addLifecycleState(LifecycleState state) throws LifeCycleManagementDAOException; void addLifecycleState(LifecycleState state) throws LifeCycleManagementDAOException;
void deleteLifecycleState(String identifier) throws LifeCycleManagementDAOException; void deleteLifecycleState(int identifier) throws LifeCycleManagementDAOException;
} }

@ -26,7 +26,6 @@ import org.wso2.carbon.device.application.mgt.core.dao.*;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecycle.GenericLifecycleImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.subscription.GenericSubscriptionDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.subscription.GenericSubscriptionDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl;
@ -160,23 +159,6 @@ public class ApplicationManagementDAOFactory {
throw new IllegalStateException("Database engine has not initialized properly."); throw new IllegalStateException("Database engine has not initialized properly.");
} }
/**
* To get the instance of LifecycleDAOImplementation of the particular database engine.
* @return GenericLifecycleDAOImpl
*/
public static LifecycleDAO getLifecycleDAO() {
if (databaseEngine != null) {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new GenericLifecycleImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
}
/** /**
* This method initializes the databases by creating the database. * This method initializes the databases by creating the database.
* *

@ -111,12 +111,13 @@ public class Util {
*/ */
public static Application loadApplication(ResultSet rs) throws SQLException, JSONException { public static Application loadApplication(ResultSet rs) throws SQLException, JSONException {
Application application = new Application(); Application application = null;
int applicatioId = -1; int applicatioId = -1;
int iteration = 0; int iteration = 0;
while (rs.next()){ while (rs.next()){
if (iteration == 0){ if (iteration == 0){
application = new Application();
applicatioId = rs.getInt("APP_ID"); applicatioId = rs.getInt("APP_ID");
application.setId(applicatioId); application.setId(applicatioId);
application.setName(rs.getString("APP_NAME")); application.setName(rs.getString("APP_NAME"));

@ -22,18 +22,15 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.*;
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.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
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.util.ConnectionManagerUtil;
import java.sql.*; import java.sql.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* This handles ApplicationDAO related operations. * This handles ApplicationDAO related operations.
@ -76,7 +73,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
return applicationId; return applicationId;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection when application creation", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding the application", e); throw new ApplicationManagementDAOException("Error occurred while adding the application", e);
} finally { } finally {
@ -93,8 +90,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int index = 0; int index = 0;
String sql = "INSERT INTO AP_APP_TAG (TAG, TENANT_ID, AP_APP_ID) " String sql = "INSERT INTO AP_APP_TAG (TAG, TENANT_ID, AP_APP_ID) VALUES (?, ?, ?)";
+ "VALUES (?, ?, ?)";
try{ try{
conn = this.getDBConnection(); conn = this.getDBConnection();
conn.setAutoCommit(false); conn.setAutoCommit(false);
@ -108,7 +104,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.executeBatch(); stmt.executeBatch();
}catch (DBConnectionException e) { }catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection when adding tags", e);
}catch (SQLException e) { }catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding tags", e); throw new ApplicationManagementDAOException("Error occurred while adding tags", e);
} finally { } finally {
@ -125,8 +121,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int index = 0; int index = 0;
String sql = "INSERT INTO AP_UNRESTRICTED_ROLES (ROLE, TENANT_ID, AP_APP_ID) " String sql = "INSERT INTO AP_UNRESTRICTED_ROLES (ROLE, TENANT_ID, AP_APP_ID) VALUES (?, ?, ?)";
+ "VALUES (?, ?, ?)";
try{ try{
conn = this.getDBConnection(); conn = this.getDBConnection();
conn.setAutoCommit(false); conn.setAutoCommit(false);
@ -140,13 +135,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.executeBatch(); stmt.executeBatch();
}catch (DBConnectionException e) { }catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection when adding roles", e);
}catch (SQLException e) { }catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding unrestricted roles", e); throw new ApplicationManagementDAOException("Error occurred while adding unrestricted roles", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, rs);
} }
} }
@Override @Override
@ -175,13 +169,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
return isExist; return isExist;
}catch (DBConnectionException e) { }catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection when verifying application existence", e);
}catch (SQLException e) { }catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding unrestricted roles", e); throw new ApplicationManagementDAOException("Error occurred while adding unrestricted roles", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, rs);
} }
} }
@Override @Override
@ -258,12 +251,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
return applicationList; return applicationList;
} }
@Override @Override
public int getApplicationCount(Filter filter) throws ApplicationManagementDAOException { public int getApplicationCount(Filter filter) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting application count from the database"); log.debug("Getting application count from the database");
log.debug(String.format("Filter: limit=%s, offset=%", filter.getLimit(), filter.getOffset())); log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset()));
} }
Connection conn; Connection conn;
@ -336,8 +328,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error occurred while getting application details with app name " + appName + " While executing query " "Error occurred while getting application details with app name " + appName + " While executing query ", e);
+ sql, e);
} catch (JSONException e) { } catch (JSONException e) {
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
@ -348,228 +339,57 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public void addLifecycle(Lifecycle lifecycle, int tenantId, int appReleaseId, int appId) public Application editApplication(Application application, int tenantId) throws ApplicationManagementException {
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Life cycle is created by" + lifecycle.getCreatedBy() + " at "
+ lifecycle.getCreatedAt());
}
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { Application existingApplication = this.getApplication(application.getName(), application.getType(), tenantId);
conn = this.getDBConnection();
String sql = "INSERT INTO AP_APP_LIFECYCLE (CREATED_BY, CREATED_TIMESTAMP, TENANT_ID, AP_APP_RELEASE_ID, "
+ "AP_APP_ID) VALUES (?, ?, ?, ? ,?);";
stmt = conn.prepareStatement(sql);
stmt.setString(1, lifecycle.getCreatedBy());
stmt.setTimestamp(2, (Timestamp) lifecycle.getCreatedAt());
stmt.setInt(3, tenantId);
stmt.setInt(4, appReleaseId);
stmt.setInt(5, appId);
stmt.executeUpdate();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding the lifecycle of application", e);
} finally {
Util.cleanupResources(stmt, null);
}
if (existingApplication == null){
throw new ApplicationManagementException("There doesn't have an application for updating");
} }
@Override
public void changeLifecycle(String applicationUUID, String lifecycleIdentifier, String userName, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Change Life cycle status change " + lifecycleIdentifier + "request received to the DAO "
+ "level for the application with " + "the UUID '" + applicationUUID + "' from the user "
+ userName);
}
Connection conn;
PreparedStatement stmt = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "UPDATE APPM_APPLICATION SET " int index = 0;
+ "LIFECYCLE_STATE_ID = (SELECT ID FROM APPM_LIFECYCLE_STATE WHERE IDENTIFIER = ?), " String sql = "UPDATE AP_APP SET ";
+ "LIFECYCLE_STATE_MODIFIED_BY = ?, LIFECYCLE_STATE_MODIFIED_AT = ? WHERE UUID = ? AND TENANT_ID "
+ "= ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, lifecycleIdentifier);
stmt.setString(2, userName);
stmt.setDate(3, new Date(System.currentTimeMillis()));
stmt.setString(4, applicationUUID);
stmt.setInt(5, tenantId);
stmt.executeUpdate();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while changing lifecycle of application: " + applicationUUID + " to: "
+ lifecycleIdentifier + " state.", e);
} finally {
Util.cleanupResources(stmt, null);
}
}
@Override
public List<LifecycleStateTransition> getNextLifeCycleStates(String applicationUUID, int tenantId)
throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String sql = "SELECT STATE.NAME, TRANSITION.DESCRIPTION, TRANSITION.PERMISSION FROM ( SELECT * FROM "
+ "APPM_LIFECYCLE_STATE ) STATE RIGHT JOIN (SELECT * FROM APPM_LC_STATE_TRANSITION WHERE "
+ "INITIAL_STATE = (SELECT LIFECYCLE_STATE_ID FROM APPM_APPLICATION WHERE UUID = ? AND TENANT_ID = ?)) "
+ "TRANSITION ON TRANSITION.NEXT_STATE = STATE.ID";
try {
connection = this.getDBConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, applicationUUID);
preparedStatement.setInt(2, tenantId);
resultSet = preparedStatement.executeQuery();
List<LifecycleStateTransition> lifecycleStateTransitions = new ArrayList<>();
while (resultSet.next()) {
LifecycleStateTransition lifecycleStateTransition = new LifecycleStateTransition();
lifecycleStateTransition.setDescription(resultSet.getString(2));
lifecycleStateTransition.setNextState(resultSet.getString(1));
lifecycleStateTransition.setPermission(resultSet.getString(3));
lifecycleStateTransitions.add(lifecycleStateTransition);
}
return lifecycleStateTransitions;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error while getting the DBConnection for getting the life "
+ "cycle states for the application with the UUID : " + applicationUUID, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL exception while executing the query '" + sql + "'.", e);
} finally {
Util.cleanupResources(preparedStatement, resultSet);
}
}
@Override
public void updateScreenShotCount(String applicationUUID, int tenantId, int count)
throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "UPDATE APPM_APPLICATION SET SCREEN_SHOT_COUNT = ? where UUID = ? and TENANT_ID = ?";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
statement.setInt(1, count);
statement.setString(2, applicationUUID);
statement.setInt(3, tenantId);
statement.executeUpdate();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection while trying to update the screen-shot "
+ "count for the application with UUID " + applicationUUID + " for the tenant " + tenantId);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL exception while executing the query '" + sql + "' .", e);
} finally {
Util.cleanupResources(statement, null);
}
}
@Override if (application.getName() != null && !application.getName().equals(existingApplication.getName())) {
public boolean isApplicationExist(String categoryName) throws ApplicationManagementDAOException { sql += "NAME = ?, ";
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM APPM_APPLICATION WHERE APPLICATION_CATEGORY_ID = (SELECT ID FROM "
+ "APPM_APPLICATION_CATEGORY WHERE NAME = ?)";
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, categoryName);
rs = stmt.executeQuery();
return rs.next();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database Connection Exception while trying to check the " + "applications for teh category "
+ categoryName, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"SQL Exception while trying to get the application related with categories, while executing " + sql,
e);
} finally {
Util.cleanupResources(stmt, rs);
}
} }
if (application.getType() != null && !application.getType().equals(existingApplication.getType())){
@Override sql += "TYPE = ?, ";
public Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
String sql = "";
boolean isBatchExecutionSupported = ConnectionManagerUtil.isBatchQuerySupported();
try {
conn = this.getDBConnection();
int index = 0;
sql += "UPDATE APPM_APPLICATION SET NAME = COALESCE (?, NAME), SHORT_DESCRIPTION = COALESCE "
+ "(?, SHORT_DESCRIPTION), DESCRIPTION = COALESCE (?, DESCRIPTION), SCREEN_SHOT_COUNT = "
+ "COALESCE (?, SCREEN_SHOT_COUNT), VIDEO_NAME = COALESCE (?, VIDEO_NAME), MODIFIED_AT = COALESCE "
+ "(?, MODIFIED_AT), ";
if (application.getPayment() != null) {
sql += " IS_FREE = COALESCE (?, IS_FREE), ";
if (application.getPayment().getPaymentCurrency() != null) {
sql += "PAYMENT_CURRENCY = COALESCE (?, PAYMENT_CURRENCY), ";
} }
sql += "PAYMENT_PRICE = COALESCE (?, PAYMENT_PRICE), "; if (application.getAppCategory() != null && !application.getAppCategory().equals(existingApplication.getAppCategory())){
sql += "APP_CATEGORY = ?, ";
} }
if (application.getCategory() != null && application.getCategory().getId() != 0) { if (application.getIsRestricted() != existingApplication.getIsRestricted()){
sql += "APPLICATION_CATEGORY_ID = COALESCE (?, APPLICATION_CATEGORY_ID), "; sql += "RESTRICTED = ? ";
} }
if (application.getPlatform() != null && application.getPlatform().getId() != 0) { if (application.getIsFree() != existingApplication.getIsFree()){
sql += "PLATFORM_ID = COALESCE (?, PLATFORM_ID), "; sql += "IS_FREE = ? ";
} }
sql += "TENANT_ID = COALESCE (?, TENANT_ID) WHERE UUID = ?"; sql += "WHERE ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
if (application.getName() != null && !application.getName().equals(existingApplication.getName())) {
stmt.setString(++index, application.getName()); stmt.setString(++index, application.getName());
stmt.setString(++index, application.getShortDescription());
stmt.setString(++index, application.getDescription());
stmt.setInt(++index, application.getScreenShotCount());
stmt.setString(++index, application.getVideoName());
stmt.setDate(++index, new Date(application.getModifiedAt().getTime()));
if (application.getPayment() != null) {
stmt.setBoolean(++index, application.getPayment().isFreeApp());
if (application.getPayment().getPaymentCurrency() != null) {
stmt.setString(++index, application.getPayment().getPaymentCurrency());
} }
stmt.setFloat(++index, application.getPayment().getPaymentPrice()); if (application.getType() != null && !application.getType().equals(existingApplication.getType())){
stmt.setString(++index, application.getType());
} }
if (application.getAppCategory() != null && !application.getAppCategory().equals(existingApplication.getAppCategory())){
if (application.getCategory() != null && application.getCategory().getId() != 0) { stmt.setString(++index, application.getAppCategory());
stmt.setInt(++index, application.getCategory().getId());
} }
if (application.getPlatform() != null && application.getPlatform().getId() != 0) { if (application.getIsRestricted() != existingApplication.getIsRestricted()){
stmt.setInt(++index, application.getPlatform().getId()); stmt.setInt(++index, application.getIsRestricted());
}
if (application.getIsFree() != existingApplication.getIsFree()){
stmt.setInt(++index, application.getIsFree());
} }
stmt.setInt(++index, tenantId);
stmt.setString(++index, application.getUuid());
stmt.executeUpdate();
application.setId(getApplicationId(application.getUuid(), tenantId));
sql = "DELETE FROM APPM_APPLICATION_TAG WHERE APPLICATION_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, application.getId());
stmt.executeUpdate();
// delete existing properties and add new ones. if no properties are set, existing ones will be deleted. stmt.setInt(++index, application.getId());
sql = "DELETE FROM APPM_APPLICATION_PROPERTY WHERE APPLICATION_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, application.getId());
stmt.executeUpdate(); stmt.executeUpdate();
insertApplicationTagsAndProperties(application, stmt, conn, isBatchExecutionSupported);
return application; return application;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
@ -580,90 +400,21 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
} }
/**
* To insert application properties and Tags
*
* @param application Application in which the properties and tags need to be inserted
*/
private void insertApplicationTagsAndProperties(Application application, PreparedStatement stmt, Connection
conn, boolean isBatchExecutionSupported) throws SQLException {
String sql;
if (application.getTags() != null && application.getTags().size() > 0) {
sql = "INSERT INTO APPM_APPLICATION_TAG (NAME, APPLICATION_ID) VALUES (?, ?); ";
stmt = conn.prepareStatement(sql);
for (String tag : application.getTags()) {
stmt.setString(1, tag);
stmt.setInt(2, application.getId());
if (isBatchExecutionSupported) {
stmt.addBatch();
} else {
stmt.execute();
}
}
if (isBatchExecutionSupported) {
stmt.executeBatch();
}
}
if (application.getProperties() != null && application.getProperties().size() > 0) {
sql = "INSERT INTO APPM_APPLICATION_PROPERTY (PROP_KEY, PROP_VAL, APPLICATION_ID) VALUES (?, ?, ?); ";
stmt = conn.prepareStatement(sql);
Iterator it = application.getProperties().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> property = (Map.Entry) it.next();
stmt.setString(1, property.getKey());
stmt.setString(2, property.getValue());
stmt.setInt(3, application.getId());
if (isBatchExecutionSupported) {
stmt.addBatch();
} else {
stmt.execute();
}
}
if (isBatchExecutionSupported) {
stmt.executeBatch();
}
}
}
@Override
public void deleteApplication(String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getDBConnection();
String sql = "DELETE FROM APPM_APPLICATION WHERE UUID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, uuid);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while deleting the application: " + uuid, e);
} finally {
Util.cleanupResources(stmt, null);
}
}
@Override @Override
public void deleteProperties(int applicationId) throws ApplicationManagementDAOException { public void deleteApplication(int appId) throws ApplicationManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "DELETE FROM APPM_APPLICATION_PROPERTY WHERE APPLICATION_ID = ?"; String sql = "DELETE FROM AP_APP WHERE ID = ? ";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, applicationId); stmt.setInt(1, appId);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException("Error occurred while deleting the application: " , e);
"Error occurred while deleting properties of application: " + applicationId, e);
} finally { } finally {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
} }
@ -717,5 +468,4 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
return id; return id;
} }
} }

@ -25,23 +25,26 @@ import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
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.util.ConnectionManagerUtil;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* GenericApplicationReleaseDAOImpl holds the implementation of ApplicationRelease related DAO operations. * GenericApplicationReleaseDAOImpl holds the implementation of ApplicationRelease related DAO operations.
*/ */
public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements ApplicationReleaseDAO { public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements ApplicationReleaseDAO {
/**
* To insert the Application Release Details.
*
* @param appId Id of the application
* @param applicationRelease Application Release the properties of which that need to be inserted.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
@Override @Override
public ApplicationRelease createRelease(ApplicationRelease applicationRelease, int appId) throws public ApplicationRelease createRelease(ApplicationRelease applicationRelease, int appId) throws
ApplicationManagementDAOException { ApplicationManagementDAOException {
@ -51,7 +54,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE,APP_PRICE,STORED_LOCATION, " String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE,APP_PRICE,STORED_LOCATION, "
+ "BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE,SHARED_WITH_ALL_TENANTS, " + "BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE,SHARED_WITH_ALL_TENANTS, "
+ "APP_META_INFO,AP_APP_ID) VALUES " + "APP_META_INFO,CREATED_BY,AP_APP_ID) VALUES "
+ "(?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
int index = 0; int index = 0;
@ -71,13 +74,13 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
statement.setString(++index, applicationRelease.getAppHashValue()); statement.setString(++index, applicationRelease.getAppHashValue());
statement.setInt(++index, applicationRelease.getIsSharedWithAllTenants()); statement.setInt(++index, applicationRelease.getIsSharedWithAllTenants());
statement.setString(++index, applicationRelease.getMetaData()); statement.setString(++index, applicationRelease.getMetaData());
statement.setString(++index, applicationRelease.getApplicationCreator());
statement.setInt(++index, appId); statement.setInt(++index, appId);
statement.executeUpdate(); statement.executeUpdate();
resultSet = statement.getGeneratedKeys(); resultSet = statement.getGeneratedKeys();
if (resultSet.next()) { if (resultSet.next()) {
applicationRelease.setId(resultSet.getInt(1)); applicationRelease.setId(resultSet.getInt(1));
} }
insertApplicationReleaseProperties(connection, applicationRelease);
return applicationRelease; return applicationRelease;
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
@ -90,142 +93,170 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
} }
/**
* To get release details of a specific application.
*
* @param applicationName Name of the application.
* @param applicationType Type of the application.
* @param versionName version name of the application.
* @param releaseType type of the application release.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
@Override @Override
public ApplicationRelease getRelease(String applicationUuid, String versionName, int tenantId) public ApplicationRelease getRelease(String applicationName,String applicationType, String versionName,
throws ApplicationManagementDAOException { String releaseType, int tenantId) throws ApplicationManagementDAOException {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
String sql = "SELECT * FROM APPM_APPLICATION_RELEASE WHERE VERSION_NAME = ? AND APPM_APPLICATION_ID = "
+ "(SELECT ID FROM APPM_APPLICATION WHERE UUID = ? and TENANT_ID = ?)";
ApplicationRelease applicationRelease = null; ApplicationRelease applicationRelease = null;
ResultSet rsProperties = null; String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE,"
+ " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, "
+ "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, "
+ "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR.PUBLISHED_BY, "
+ "AR.PUBLISHED_AT, AR.STARS, AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM "
+ "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL "
+ "WHERE AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME=? AND TYPE=? AND TENANT_ID=?)"
+ " AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND AL.AP_APP_RELEASE_ID=AR.ID "
+ "AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1, versionName); statement.setString(1, applicationName);
statement.setString(2, applicationUuid); statement.setString(2, applicationType);
statement.setInt(3, tenantId); statement.setInt(3, tenantId);
statement.setString(4, versionName);
statement.setString(5, releaseType);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
if (resultSet.next()) { if (resultSet.next()) {
applicationRelease = new ApplicationRelease(); applicationRelease = new ApplicationRelease();
applicationRelease.setVersion(versionName); applicationRelease.setId(resultSet.getInt("RELESE_ID"));
applicationRelease.setDefault(resultSet.getBoolean("IS_DEFAULT")); applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setCreatedAt(resultSet.getDate("CREATED_AT")); applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_CHANNEL")); applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setReleaseDetails(resultSet.getString("RELEASE_DETAILS")); applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setResource(resultSet.getString("RELEASE_RESOURCE")); applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));
sql = "SELECT * FROM APPM_RELEASE_PROPERTY WHERE APPLICATION_RELEASE_ID=?"; applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1"));
statement = connection.prepareStatement(sql); applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2"));
statement.setInt(1, resultSet.getInt("ID")); applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3"));
rsProperties = statement.executeQuery(); applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE"));
applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED"));
Map<String, String> properties = new HashMap<>(); applicationRelease.setMetaData(resultSet.getString("APP_META_INFO"));
while (rsProperties.next()) { applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY"));
properties.put(rsProperties.getString("PROP_KEY"), applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT"));
rsProperties.getString("PROP_VAL")); applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
} applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setProperties(properties); applicationRelease.setStarts(resultSet.getInt("STARS"));
applicationRelease.setCurrentState(resultSet.getString("CURRENT_STATE"));
applicationRelease.setPreviouseState(resultSet.getString("PREVIOUSE_STATE"));
applicationRelease.setStateModifiedBy(resultSet.getString("UPDATED_BY"));
applicationRelease.setStateModifiedAt(resultSet.getTimestamp("UPDATED_AT"));
} }
return applicationRelease; return applicationRelease;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection exception while trying to get the " throw new ApplicationManagementDAOException("Database connection exception while trying to get the "
+ "release details of the application with UUID " + applicationUuid + " and version " + + "release details of the application with " + applicationName + " and version " +
versionName, e); versionName, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error while getting release details of the application " + throw new ApplicationManagementDAOException("Error while getting release details of the application " +
applicationUuid + " and version " + versionName + " , while executing the query " + sql, e); applicationName + " and version " + versionName + " , while executing the query " + sql, e);
} finally { } finally {
Util.cleanupResources(statement, resultSet); Util.cleanupResources(statement, resultSet);
Util.cleanupResources(null, rsProperties);
} }
} }
/**
* To insert the application release properties.
*
* @param applicationName Name of the application.
* @param applicationType Type of the application.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
@Override @Override
public List<ApplicationRelease> getApplicationReleases(String applicationUUID, int tenantId) public List<ApplicationRelease> getApplicationReleases(String applicationName, String applicationType, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
String sql = "SELECT * FROM APPM_APPLICATION_RELEASE WHERE APPM_APPLICATION_ID = (SELECT ID FROM "
+ "APPM_APPLICATION WHERE UUID = ? AND TENANT_ID = ?)";
List<ApplicationRelease> applicationReleases = new ArrayList<>(); List<ApplicationRelease> applicationReleases = new ArrayList<>();
ResultSet rsProperties = null; String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE,"
+ " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS "
+ "SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, "
+ "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, "
+ "AR.PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS FROM AP_APP_RELEASE AS "
+ "AR where AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME = ? AND TYPE = ? "
+ "AND TENANT_ID = ?) AND AR.TENANT_ID = ? ;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1, applicationUUID); statement.setString(1, applicationName);
statement.setInt(2, tenantId); statement.setString(2, applicationType);
statement.setInt(3, tenantId);
statement.setInt(4, tenantId);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
ApplicationRelease applicationRelease = new ApplicationRelease(); ApplicationRelease applicationRelease = new ApplicationRelease();
applicationRelease.setVersion(resultSet.getString("VERSION_NAME")); applicationRelease.setId(resultSet.getInt("RELESE_ID"));
applicationRelease.setDefault(resultSet.getBoolean("IS_DEFAULT")); applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setCreatedAt(resultSet.getDate("CREATED_AT")); applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_CHANNEL")); applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setReleaseDetails(resultSet.getString("RELEASE_DETAILS")); applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setResource(resultSet.getString("RELEASE_RESOURCE")); applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));
sql = "SELECT * FROM APPM_RELEASE_PROPERTY WHERE APPLICATION_RELEASE_ID= ?"; applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1"));
statement = connection.prepareStatement(sql); applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2"));
statement.setInt(1, resultSet.getInt("ID")); applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3"));
rsProperties = statement.executeQuery(); applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE"));
applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED"));
Map<String, String> properties = new HashMap<>(); applicationRelease.setMetaData(resultSet.getString("APP_META_INFO"));
while (rsProperties.next()) { applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY"));
properties.put(rsProperties.getString("PROP_KEY"), rsProperties.getString("PROP_VAL")); applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT"));
} applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
applicationRelease.setProperties(properties); applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setStarts(resultSet.getInt("STARS"));
applicationReleases.add(applicationRelease); applicationReleases.add(applicationRelease);
} }
return applicationReleases; return applicationReleases;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection exception while trying to get the " throw new ApplicationManagementDAOException("Database connection exception while trying to get the "
+ "release details of the application with UUID " + applicationUUID, e); + "release details of the application with Name " + applicationName, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error while getting all the release details of the " + "application " + applicationUUID "Error while getting all the release details of the " + applicationName + " application"
+ ", while executing the query " + sql, e); + ", while executing the query " + sql, e);
} finally { } finally {
Util.cleanupResources(statement, resultSet); Util.cleanupResources(statement, resultSet);
Util.cleanupResources(null, rsProperties);
} }
} }
/**
* To Update starts of an application release.
*
* @param id Id of the application Release.
* @param stars given stars for the application release.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
@Override @Override
public ApplicationRelease updateRelease(ApplicationRelease applicationRelease) public void updateStars(int id, int stars) throws ApplicationManagementDAOException {
throws ApplicationManagementDAOException {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
String sql = "UPDATE APPM_APPLICATION_RELEASE SET RELEASE_RESOURCE = IFNULL (?, RELEASE_RESOURCE)," + String sql = "UPDATE AP_APP_RELEASE SET STARS = ? WHERE ID = ?;";
" RELEASE_CHANNEL = IFNULL (?, RELEASE_CHANNEL), RELEASE_DETAILS = IFNULL (?, RELEASE_DETAILS), " +
"IS_DEFAULT = IFNULL (?, IS_DEFAULT) WHERE APPM_APPLICATION_ID = ? AND VERSION_NAME = ?";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1, applicationRelease.getResource()); statement.setInt(1, stars);
statement.setString(2, String.valueOf(applicationRelease.getReleaseType())); statement.setInt(2, id);
statement.setString(3, applicationRelease.getReleaseDetails());
statement.setBoolean(4, applicationRelease.isDefault());
statement.setInt(5, applicationRelease.getApplication().getId());
statement.setString(6, applicationRelease.getVersion());
statement.executeUpdate(); statement.executeUpdate();
sql = "DELETE FROM APPM_RELEASE_PROPERTY WHERE APPLICATION_RELEASE_ID = ?";
statement = connection.prepareStatement(sql);
statement.setInt(1, applicationRelease.getId());
statement.executeUpdate();
insertApplicationReleaseProperties(connection, applicationRelease);
return applicationRelease;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection exception while trying to update the " throw new ApplicationManagementDAOException(
+ "Application release for the application with UUID " + applicationRelease.getApplication() "Database connection exception while trying to update the application release", e);
.getUuid() + " for the version " + applicationRelease.getVersion(), e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"SQL exception while updating the release ,while executing the query " + sql, e); "SQL exception while updating the release ,while executing the query " + sql, e);
@ -234,11 +265,34 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
} }
// have to complete
//Todo
/**
* To insert the application release properties.
*
* @param applicationRelease Application Release the properties of which that need to be inserted.
* @throws SQLException SQL Exception.
*/
@Override
public ApplicationRelease updateRelease(ApplicationRelease applicationRelease)
throws ApplicationManagementDAOException {
return applicationRelease;
}
//
/**
* To delete an application release.
*
* @param id Id of the application Release.
* @param version version name of the application release.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
@Override @Override
public void deleteRelease(int id, String version) throws ApplicationManagementDAOException { public void deleteRelease(int id, String version) throws ApplicationManagementDAOException {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
String sql = "DELETE FROM APPM_APPLICATION_RELEASE WHERE APPM_APPLICATION_ID = ? AND VERSION_NAME = ?"; String sql = "DELETE FROM AP_APP_RELEASE WHERE ID = ? AND VERSION = ?";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
@ -257,116 +311,4 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
} }
@Override
public void deleteReleaseProperties(int id) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "DELETE FROM APPM_RELEASE_PROPERTY WHERE APPLICATION_RELEASE_ID = ?";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
statement.setInt(1, id);
statement.executeUpdate();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database connection exception while trying to delete the release properties ", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"SQL exception while deleting the properties of application release with the id " + id, e);
} finally {
Util.cleanupResources(statement, null);
}
}
@Override
public void changeReleaseDefault(String uuid, String version, boolean isDefault, String releaseChannel,
int tenantId) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "UPDATE APPM_APPLICATION_RELEASE SET IS_DEFAULT = ? AND RELEASE_CHANNEL = ? WHERE "
+ "APPM_APPLICATION_ID = (SELECT ID from APPM_APPLICATION WHERE UUID = ? AND TENANT_ID = ?) "
+ "AND VERSION_NAME = ?";
try {
if (isDefault) {
removeDefaultReleases(uuid, releaseChannel, tenantId);
}
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
statement.setBoolean(1, isDefault);
statement.setString(2, releaseChannel.toUpperCase());
statement.setString(3, uuid);
statement.setInt(4, tenantId);
statement.setString(5, version);
statement.executeUpdate();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database Connection exception while try to change the " + "default release of the release channel "
+ releaseChannel + " for the application " + uuid, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"SQL Exception while trying to change the default release of " + "the release channel "
+ releaseChannel + " for the application " + uuid, e);
} finally {
Util.cleanupResources(statement, null);
}
}
/**
* To insert the application release properties.
*
* @param connection Database Connection
* @param applicationRelease Application Release the properties of which that need to be inserted.
* @throws SQLException SQL Exception.
*/
private void insertApplicationReleaseProperties(Connection connection, ApplicationRelease applicationRelease)
throws SQLException {
String sql;
boolean isBatchExecutionSupported = ConnectionManagerUtil.isBatchQuerySupported();
if (applicationRelease.getProperties() != null && applicationRelease.getProperties().size() != 0) {
sql = "INSERT INTO APPM_RELEASE_PROPERTY (PROP_KEY, PROP_VALUE, APPLICATION_RELEASE_ID) VALUES (?,?,?)";
PreparedStatement statement = connection.prepareStatement(sql);
for (Object entry : applicationRelease.getProperties().entrySet()) {
Map.Entry<String, String> property = (Map.Entry) entry;
statement.setString(1, property.getKey());
statement.setString(2, property.getValue());
statement.setInt(3, applicationRelease.getId());
if (isBatchExecutionSupported) {
statement.addBatch();
} else {
statement.execute();
}
}
if (isBatchExecutionSupported) {
statement.executeBatch();
}
}
}
/**
* To make all the releases of particular release channel as non-default ones.
*
* @param uuid UUID of the Application.
* @param releaseChannel ReleaseChannel for which we need to make all the releases as non-default ones.
* @param tenantId ID of the tenant.
* @throws DBConnectionException Database Connection Exception.
* @throws SQLException SQL Exception.
*/
private void removeDefaultReleases(String uuid, String releaseChannel, int tenantId)
throws DBConnectionException, SQLException {
PreparedStatement statement = null;
try {
Connection connection = this.getDBConnection();
String sql = "UPDATE APPM_APPLICATION_RELEASE SET IS_DEFAULT = FALSE WHERE APPM_APPLICATION_ID = (SELECT "
+ "ID from APPM_APPLICATION WHERE UUID = ? AND TENANT_ID = ?) AND RELEASE_CHANNEL = ?";
statement = connection.prepareStatement(sql);
statement.setString(1, uuid);
statement.setInt(2, tenantId);
statement.setString(3, releaseChannel.toUpperCase());
statement.executeUpdate();
} finally {
Util.cleanupResources(statement, null);
}
}
} }

@ -1,187 +0,0 @@
/*
*
* Copyright (c) ${date}, 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.
* /
*/
package org.wso2.carbon.device.application.mgt.core.dao.impl.lifecycle;
import org.wso2.carbon.device.application.mgt.common.Lifecycle;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
/**
* Concrete implementation for Lifecycle related DB operations.
*/
public class GenericLifecycleImpl extends AbstractDAOImpl implements LifecycleDAO {
@Override
public Lifecycle getLifeCycleOfApplication(int identifier) throws LifeCycleManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql = "SELECT ID, CREATED_BY, CREATED_TIMESTAMP, APPROVED, APPROVED_TIMESTAMP, APPROVED_BY, "
+ "PUBLISHED, PUBLISHED_BY, PUBLISHED_TIMESTAMP, RETIRED FROM AP_APP_LIFECYCLE WHERE "
+ "AP_APP_RELEASE_ID = ? ";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, identifier);
rs = stmt.executeQuery();
Lifecycle lifecycle = null;
if (rs.next()) {
lifecycle = new Lifecycle();
lifecycle.setId(rs.getInt("ID"));
lifecycle.setCreatedBy(rs.getString("CREATED_BY"));
lifecycle.setCreatedAt(rs.getDate("CREATED_TIMESTAMP"));
lifecycle.setIsApproved(rs.getInt("APPROVED"));
lifecycle.setApprovedAt(rs.getDate("APPROVED_TIMESTAMP"));
lifecycle.setApprovedBy(rs.getString("APPROVED_BY"));
lifecycle.setIsPublished(rs.getInt("PUBLISHED"));
lifecycle.setPublishedBy(rs.getString("PUBLISHED_BY"));
lifecycle.setPublishedAt(rs.getDate("PUBLISHED_TIMESTAMP"));
lifecycle.setIsRetired(rs.getInt("RETIRED"));
}
return lifecycle;
} catch (SQLException e) {
throw new LifeCycleManagementDAOException("Error occurred while getting application List", e);
} catch (DBConnectionException e) {
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override
public List<Lifecycle> getLifecyclesOfAllAppVersions(int identifier) throws LifeCycleManagementDAOException {
List<Lifecycle> lifecycles = new ArrayList<>();
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql = "SELECT ID, CREATED_BY, CREATED_TIMESTAMP, APPROVED, APPROVED_TIMESTAMP, APPROVED_BY, "
+ "PUBLISHED, PUBLISHED_BY, PUBLISHED_TIMESTAMP, RETIRED FROM AP_APP_LIFECYCLE WHERE "
+ "AP_APP_ID = ? ";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, identifier);
rs = stmt.executeQuery();
while (rs.next()) {
Lifecycle lifecycle = new Lifecycle();
lifecycle.setId(rs.getInt("ID"));
lifecycle.setCreatedBy(rs.getString("CREATED_BY"));
lifecycle.setCreatedAt(rs.getDate("CREATED_TIMESTAMP"));
lifecycle.setIsApproved(rs.getInt("APPROVED"));
lifecycle.setApprovedAt(rs.getDate("APPROVED_TIMESTAMP"));
lifecycle.setApprovedBy(rs.getString("APPROVED_BY"));
lifecycle.setIsPublished(rs.getInt("PUBLISHED"));
lifecycle.setPublishedBy(rs.getString("PUBLISHED_BY"));
lifecycle.setPublishedAt(rs.getDate("PUBLISHED_TIMESTAMP"));
lifecycle.setIsRetired(rs.getInt("RETIRED"));
lifecycles.add(lifecycle);
}
} catch (DBConnectionException e) {
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) {
throw new LifeCycleManagementDAOException("Error occurred while retrieving lifecycle states.", e);
} finally {
Util.cleanupResources(stmt, rs);
}
return lifecycles;
}
@Override
public void addLifecycle(Lifecycle lifecycle) throws LifeCycleManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql = "INSERT INTO AP_APP_LIFECYCLE ('CREATED_BY', 'CREATED_TIMESTAMP') VALUES (?, ?)";
stmt = conn.prepareStatement(sql);
stmt.setString(1, lifecycle.getCreatedBy());
stmt.setDate(2, new Date(lifecycle.getCreatedAt().getTime()));
stmt.executeUpdate();
} catch (DBConnectionException e) {
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) {
throw new LifeCycleManagementDAOException("Error occurred while adding lifecycle ", e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
// have to modify
@Override
public void updateLifecycleOfApplication(LifecycleState state) throws LifeCycleManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql = "INSERT INTO APPM_LIFECYCLE_STATE ('NAME', 'IDENTIFIER',) VALUES (?, ?)";
stmt = conn.prepareStatement(sql);
stmt.setString(1, state.getName());
stmt.setString(2, state.getIdentifier());
stmt.executeUpdate();
} catch (DBConnectionException e) {
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) {
throw new LifeCycleManagementDAOException("Error occurred while adding lifecycle: " + state.getIdentifier(), e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override
public void deleteLifecycleOfApplication(String identifier) throws LifeCycleManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql = "DELETE FROM APPM_LIFECYCLE_STATE WHERE IDENTIFIER = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, identifier);
stmt.executeUpdate();
} catch (DBConnectionException e) {
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) {
throw new LifeCycleManagementDAOException("Error occurred while deleting lifecycle: " + identifier, e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
// end modification
}

@ -39,59 +39,68 @@ import java.util.List;
public class GenericLifecycleStateImpl extends AbstractDAOImpl implements LifecycleStateDAO { public class GenericLifecycleStateImpl extends AbstractDAOImpl implements LifecycleStateDAO {
@Override @Override
public LifecycleState getLifeCycleStateByIdentifier(String identifier) throws ApplicationManagementDAOException { public LifecycleState getLatestLifeCycleStateByReleaseID(int identifier) throws ApplicationManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "SELECT * FROM APPM_LIFECYCLE_STATE WHERE IDENTIFIER = ? "; String sql = "SELECT ID, CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM "
+ "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID=? ORDER BY UPDATED_AT DESC;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, identifier); stmt.setInt(1, identifier);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
LifecycleState lifecycleState = null; LifecycleState lifecycleState = null;
if (rs.next()) { if (rs.next()) {
lifecycleState = new LifecycleState(); lifecycleState = new LifecycleState();
lifecycleState.setId(rs.getInt("ID")); lifecycleState.setId(rs.getInt("ID"));
lifecycleState.setName(rs.getString("NAME")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setIdentifier(rs.getString("IDENTIFIER")); lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE"));
lifecycleState.setDescription(rs.getString("DESCRIPTION")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT"));
lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY"));
} }
return lifecycleState; return lifecycleState;
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application List", e); throw new ApplicationManagementDAOException("Error occurred while getting application List", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection to get latest"
+ " lifecycle state for a specific application", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, rs);
} }
} }
@Override @Override
public List<LifecycleState> getLifecycleStates() throws LifeCycleManagementDAOException { public List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException {
List<LifecycleState> lifecycleStates = new ArrayList<>(); List<LifecycleState> lifecycleStates = new ArrayList<>();
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int index = 0;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "SELECT IDENTIFIER, NAME, DESCRIPTION FROM APPM_LIFECYCLE_STATE"; String sql = "SELECT ID, CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM "
+ "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID = ? ORDER BY UPDATED_AT ASC;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(++index,appReleaseId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
LifecycleState lifecycleState = new LifecycleState(); LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setIdentifier(rs.getString("IDENTIFIER")); lifecycleState.setId(rs.getInt("ID"));
lifecycleState.setName(rs.getString("NAME")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setDescription(rs.getString("DESCRIPTION")); lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE"));
lifecycleState.setTenantId(rs.getInt("TENANT_ID"));
lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT"));
lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY"));
lifecycleStates.add(lifecycleState); lifecycleStates.add(lifecycleState);
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection when getting "
+ "lifecycle states for an application", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new LifeCycleManagementDAOException("Error occurred while retrieving lifecycle states.", e); throw new LifeCycleManagementDAOException("Error occurred while retrieving lifecycle states.", e);
} finally { } finally {
@ -104,35 +113,38 @@ public class GenericLifecycleStateImpl extends AbstractDAOImpl implements Lifecy
public void addLifecycleState(LifecycleState state) throws LifeCycleManagementDAOException { public void addLifecycleState(LifecycleState state) throws LifeCycleManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "INSERT INTO APPM_LIFECYCLE_STATE ('NAME', 'IDENTIFIER', 'DESCRIPTION') VALUES (?, ?, ?)"; String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_BY, "
+ "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,?,?);";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, state.getName()); stmt.setString(1, state.getCurrentState());
stmt.setString(2, state.getIdentifier()); stmt.setString(2, state.getPreviousState());
stmt.setString(3, state.getDescription()); stmt.setInt(3, state.getTenantId());
stmt.setString(4, state.getUpdatedBy());
stmt.setInt(5, state.getReleaseId());
stmt.setInt(6, state.getAppId());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new LifeCycleManagementDAOException("Error occurred while adding lifecycle: " + state.getIdentifier(), e); throw new LifeCycleManagementDAOException("Error occurred while adding lifecycle: " + state.getCurrentState(), e);
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, null);
} }
} }
@Override @Override
public void deleteLifecycleState(String identifier) throws LifeCycleManagementDAOException { public void deleteLifecycleState(int identifier) throws LifeCycleManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "DELETE FROM APPM_LIFECYCLE_STATE WHERE IDENTIFIER = ?"; String sql = "DELETE FROM AP_APP_LIFECYCLE_STATE WHERE ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, identifier); stmt.setInt(1, identifier);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {

@ -26,21 +26,17 @@ import org.wso2.carbon.device.application.mgt.common.*;
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.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.LifecycleDAO;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
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.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.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.HelperUtil;
import org.wso2.carbon.device.mgt.core.dao.*; import org.wso2.carbon.device.mgt.core.dao.*;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**

Loading…
Cancel
Save