|
|
@ -22,19 +22,11 @@ import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.CarbonConstants;
|
|
|
|
import org.wso2.carbon.CarbonConstants;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Application;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.*;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Filter;
|
|
|
|
|
|
|
|
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.LifecycleStateTransition;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Platform;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.User;
|
|
|
|
|
|
|
|
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.LifecycleStateDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
|
|
|
|
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.exception.NotFoundException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
|
|
@ -71,14 +63,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
application.setCreatedAt(new Date());
|
|
|
|
application.setCreatedAt(new Date());
|
|
|
|
application.setModifiedAt(new Date());
|
|
|
|
application.setModifiedAt(new Date());
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
Platform platform = DataHolder.getInstance().getPlatformManager().getPlatform(application.getUser()
|
|
|
|
|
|
|
|
.getTenantId(), application.getPlatform().getIdentifier());
|
|
|
|
|
|
|
|
|
|
|
|
// Validating the platform
|
|
|
|
|
|
|
|
Platform platform = DataHolder.getInstance().getPlatformManager()
|
|
|
|
|
|
|
|
.getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier());
|
|
|
|
|
|
|
|
if (platform == null) {
|
|
|
|
if (platform == null) {
|
|
|
|
throw new NotFoundException("Invalid platform");
|
|
|
|
throw new NotFoundException("Invalid platform");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Validating the platform
|
|
|
|
application.setPlatform(platform);
|
|
|
|
application.setPlatform(platform);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Application creation pre-conditions are met and the platform mentioned by identifier "
|
|
|
|
log.debug("Application creation pre-conditions are met and the platform mentioned by identifier "
|
|
|
@ -97,6 +90,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
application.setCurrentLifecycle(lifecycle);
|
|
|
|
application.setCurrentLifecycle(lifecycle);
|
|
|
|
|
|
|
|
|
|
|
|
application = DAOFactory.getApplicationDAO().createApplication(application);
|
|
|
|
application = DAOFactory.getApplicationDAO().createApplication(application);
|
|
|
|
|
|
|
|
DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility());
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
return application;
|
|
|
|
return application;
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
@ -120,24 +114,27 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
+ "application with the UUID " + application.getUuid());
|
|
|
|
+ "application with the UUID " + application.getUuid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
|
|
|
if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) {
|
|
|
|
if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) {
|
|
|
|
Platform platform = DataHolder.getInstance().getPlatformManager()
|
|
|
|
Platform platform = DataHolder.getInstance().getPlatformManager()
|
|
|
|
.getPlatform(tenantId, application.getPlatform().getIdentifier());
|
|
|
|
.getPlatform(tenantId, application.getPlatform().getIdentifier());
|
|
|
|
if (platform == null) {
|
|
|
|
if (platform == null) {
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
throw new NotFoundException(
|
|
|
|
throw new NotFoundException(
|
|
|
|
"Platform specified by identifier " + application.getPlatform().getIdentifier()
|
|
|
|
"Platform specified by identifier " + application.getPlatform().getIdentifier()
|
|
|
|
+ " is not found. Please give a valid platform identifier.");
|
|
|
|
+ " is not found. Please give a valid platform identifier.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
application.setPlatform(platform);
|
|
|
|
application.setPlatform(platform);
|
|
|
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
|
|
|
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
|
|
|
|
|
|
|
|
application.setModifiedAt(new Date());
|
|
|
|
|
|
|
|
Application modifiedApplication = applicationDAO.editApplication(application, tenantId);
|
|
|
|
|
|
|
|
Visibility visibility = DataHolder.getInstance().getVisibilityManager().put(application.getId(),
|
|
|
|
|
|
|
|
application.getVisibility());
|
|
|
|
|
|
|
|
modifiedApplication.setVisibility(visibility);
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
return modifiedApplication;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new NotFoundException("Platform information not available with the application!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
|
|
|
|
|
|
|
|
application.setModifiedAt(new Date());
|
|
|
|
|
|
|
|
Application modifiedApplication = applicationDAO.editApplication(application, tenantId);
|
|
|
|
|
|
|
|
DataHolder.getInstance().getVisibilityManager().put(application.getUuid(), application.getVisibility());
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
return modifiedApplication;
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
throw e;
|
|
|
|
throw e;
|
|
|
@ -160,8 +157,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
int appId = applicationDAO.getApplicationId(uuid, tenantId);
|
|
|
|
int appId = applicationDAO.getApplicationId(uuid, tenantId);
|
|
|
|
applicationDAO.deleteTags(appId);
|
|
|
|
applicationDAO.deleteTags(appId);
|
|
|
|
applicationDAO.deleteProperties(appId);
|
|
|
|
applicationDAO.deleteProperties(appId);
|
|
|
|
|
|
|
|
DataHolder.getInstance().getVisibilityManager().remove(appId);
|
|
|
|
applicationDAO.deleteApplication(uuid, tenantId);
|
|
|
|
applicationDAO.deleteApplication(uuid, tenantId);
|
|
|
|
DataHolder.getInstance().getVisibilityManager().remove(uuid);
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
@ -192,7 +189,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
|
|
|
|
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
|
|
|
|
ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId);
|
|
|
|
ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId);
|
|
|
|
for (Application application : applicationList.getApplications()) {
|
|
|
|
for (Application application : applicationList.getApplications()) {
|
|
|
|
application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getUuid()));
|
|
|
|
application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return applicationList;
|
|
|
|
return applicationList;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -307,8 +304,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
Application application = DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName);
|
|
|
|
Application application = DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName);
|
|
|
|
application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(uuid));
|
|
|
|
if (application != null) {
|
|
|
|
|
|
|
|
application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId()));
|
|
|
|
|
|
|
|
}
|
|
|
|
return application;
|
|
|
|
return application;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|