|
|
@ -31,6 +31,7 @@ import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
|
|
|
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 java.sql.Timestamp;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
@ -41,18 +42,18 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
|
|
|
|
private static Log log = LogFactory.getLog(ApplicationReleaseManagerImpl.class);
|
|
|
|
private static Log log = LogFactory.getLog(ApplicationReleaseManagerImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ApplicationRelease createRelease(String appicationUuid, ApplicationRelease applicationRelease) throws
|
|
|
|
public ApplicationRelease createRelease(int applicationId, ApplicationRelease applicationRelease) throws
|
|
|
|
ApplicationManagementException {
|
|
|
|
ApplicationManagementException {
|
|
|
|
Application application = validateApplication(appicationUuid);
|
|
|
|
Application application = validateApplication(applicationId);
|
|
|
|
validateReleaseCreateRequest(appicationUuid, applicationRelease);
|
|
|
|
validateReleaseCreateRequest(applicationRelease.getUuid(), applicationRelease);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Application release request is received for the application " + application.toString());
|
|
|
|
log.debug("Application release request is received for the application " + application.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applicationRelease.setCreatedAt(new Date());
|
|
|
|
applicationRelease.setCreatedAt((Timestamp) new Date());
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
applicationRelease.setApplication(application);
|
|
|
|
applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO().
|
|
|
|
applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO().createRelease(applicationRelease);
|
|
|
|
createRelease(applicationRelease, application.getId());
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
return applicationRelease;
|
|
|
|
return applicationRelease;
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
@ -64,18 +65,18 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ApplicationRelease getRelease(String applicationUuid, String version) throws
|
|
|
|
public ApplicationRelease getRelease(String applicationUuid, String version, String releaseType) throws
|
|
|
|
ApplicationManagementException {
|
|
|
|
ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
Application application = validateApplication(applicationUuid);
|
|
|
|
Application application = validateApplicationRelease(applicationUuid);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Application release retrieval request is received for the application " +
|
|
|
|
log.debug("Application release retrieval request is received for the application " +
|
|
|
|
application.toString() + " and version " + version);
|
|
|
|
application.toString() + " and version " + version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
return ApplicationManagementDAOFactory
|
|
|
|
return ApplicationManagementDAOFactory.getApplicationReleaseDAO()
|
|
|
|
.getApplicationReleaseDAO().getRelease(applicationUuid, version, tenantId);
|
|
|
|
.getRelease(application.getName(), application.getType(), version, releaseType, tenantId );
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -84,47 +85,49 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<ApplicationRelease> getReleases(String applicationUuid) throws ApplicationManagementException {
|
|
|
|
public List<ApplicationRelease> getReleases(String applicationUuid) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
Application application = validateApplication(applicationUuid);
|
|
|
|
Application application = validateApplicationRelease(applicationUuid);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Request is received to retrieve all the releases related with the application " +
|
|
|
|
log.debug("Request is received to retrieve all the releases related with the application " +
|
|
|
|
application.toString());
|
|
|
|
application.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
return ApplicationManagementDAOFactory
|
|
|
|
return ApplicationManagementDAOFactory.getApplicationReleaseDAO()
|
|
|
|
.getApplicationReleaseDAO().getApplicationReleases(applicationUuid, tenantId);
|
|
|
|
.getApplicationReleases(application.getName(), application.getType(), tenantId);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ToDo
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void changeDefaultRelease(String uuid, String version, boolean isDefault, String releaseChannel) throws
|
|
|
|
public void changeDefaultRelease(String uuid, String version, boolean isDefault, String releaseChannel) throws
|
|
|
|
ApplicationManagementException {
|
|
|
|
ApplicationManagementException {
|
|
|
|
Application application = validateApplication(uuid);
|
|
|
|
// Application application = validateApplicationRelease(uuid);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
// if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Request received to change the default release for the release channel " + releaseChannel
|
|
|
|
// log.debug("Request received to change the default release for the release channel " + releaseChannel
|
|
|
|
+ "for the application " + application.toString());
|
|
|
|
// + "for the application " + application.toString());
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
// ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ApplicationManagementDAOFactory.getApplicationReleaseDAO()
|
|
|
|
// ApplicationManagementDAOFactory.getApplicationReleaseDAO()
|
|
|
|
.changeReleaseDefault(uuid, version, isDefault, releaseChannel, tenantId);
|
|
|
|
// .changeReleaseDefault(uuid, version, isDefault, releaseChannel, tenantId);
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
// ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
// } catch (ApplicationManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
// ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
throw e;
|
|
|
|
// throw e;
|
|
|
|
} finally {
|
|
|
|
// } finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
// ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ToDo
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ApplicationRelease updateRelease(String applicationUuid, ApplicationRelease applicationRelease)
|
|
|
|
public ApplicationRelease updateRelease(String applicationUuid, ApplicationRelease applicationRelease)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
// Application application = validateApplication(applicationUuid);
|
|
|
|
// Application application = validateApplicationRelease(applicationUuid);
|
|
|
|
// ApplicationRelease oldApplicationRelease = null;
|
|
|
|
// ApplicationRelease oldApplicationRelease = null;
|
|
|
|
// if (applicationRelease == null || applicationRelease.getVersion() != null) {
|
|
|
|
// if (applicationRelease == null || applicationRelease.getVersion() != null) {
|
|
|
|
// throw new ApplicationManagementException(
|
|
|
|
// throw new ApplicationManagementException(
|
|
|
@ -151,13 +154,14 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
|
|
|
|
// } finally {
|
|
|
|
// } finally {
|
|
|
|
// ConnectionManagerUtil.closeDBConnection();
|
|
|
|
// ConnectionManagerUtil.closeDBConnection();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteApplicationRelease(String applicationUuid, String version)
|
|
|
|
public void deleteApplicationRelease(String applicationUuid, String version, String releaseType)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
Application application = validateApplication(applicationUuid);
|
|
|
|
Application application = validateApplicationRelease(applicationUuid);
|
|
|
|
ApplicationRelease applicationRelease = getRelease(applicationUuid, version);
|
|
|
|
ApplicationRelease applicationRelease = getRelease(applicationUuid, version, releaseType);
|
|
|
|
if (applicationRelease == null) {
|
|
|
|
if (applicationRelease == null) {
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
"Cannot delete a non-existing application release for the " + "application with UUID "
|
|
|
|
"Cannot delete a non-existing application release for the " + "application with UUID "
|
|
|
@ -166,7 +170,7 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ApplicationManagementDAOFactory.getApplicationReleaseDAO().deleteRelease(application.getId(), version);
|
|
|
|
ApplicationManagementDAOFactory.getApplicationReleaseDAO().deleteRelease(application.getId(), version);
|
|
|
|
ApplicationManagementDAOFactory.getApplicationReleaseDAO().deleteReleaseProperties(applicationRelease.getId());
|
|
|
|
// ToDO remove storage details as well
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
@ -185,23 +189,42 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* To validate the pre-request of the ApplicationRelease.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param applicationID ID of the Application.
|
|
|
|
|
|
|
|
* @return Application related with the UUID
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Application validateApplication(int applicationID) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
if (applicationID <= 0) {
|
|
|
|
|
|
|
|
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
|
|
|
|
|
|
|
|
+ "parameter to get the relevant application.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Application application = DataHolder.getInstance().getApplicationManager().getApplicationById(applicationID);
|
|
|
|
|
|
|
|
if (application == null) {
|
|
|
|
|
|
|
|
throw new NotFoundException(
|
|
|
|
|
|
|
|
"Application of the " + applicationID + " does not exist.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return application;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* To validate the pre-request of the ApplicationRelease.
|
|
|
|
* To validate the pre-request of the ApplicationRelease.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param applicationUuid UUID of the Application.
|
|
|
|
* @param applicationUuid UUID of the Application.
|
|
|
|
* @return Application related with the UUID
|
|
|
|
* @return Application related with the UUID
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Application validateApplication(String applicationUuid) throws ApplicationManagementException {
|
|
|
|
private ApplicationRelease validateApplicationRelease(String applicationUuid) throws ApplicationManagementException {
|
|
|
|
if (applicationUuid == null) {
|
|
|
|
if (applicationUuid == null) {
|
|
|
|
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
|
|
|
|
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
|
|
|
|
+ "parameter to get the relevant application.");
|
|
|
|
+ "parameter to get the relevant application.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUuid);
|
|
|
|
ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager().getRelease();
|
|
|
|
if (application == null) {
|
|
|
|
if (applicationRelease == null) {
|
|
|
|
throw new NotFoundException(
|
|
|
|
throw new NotFoundException(
|
|
|
|
"Application with UUID " + applicationUuid + " does not exist.");
|
|
|
|
"Application with UUID " + applicationUuid + " does not exist.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return application;
|
|
|
|
return applicationRelease;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|