From 669881eae7a154c243bca05f9fd60d01e2ef2e9b Mon Sep 17 00:00:00 2001 From: lasantha Date: Mon, 5 Feb 2018 19:23:57 +0530 Subject: [PATCH] adding appliction release functionalites and fixed build failure --- .../common/services/ApplicationManager.java | 2 +- .../services/ApplicationReleaseManager.java | 4 +- .../services/ApplicationStorageManager.java | 26 +++ .../services/LifecycleStateManager.java | 4 +- .../pom.xml | 5 +- .../GenericApplicationReleaseDAOImpl.java | 11 +- .../release/OracleApplicationDAOImpl.java | 82 ++++---- .../mgt/core/impl/ApplicationManagerImpl.java | 5 +- .../impl/ApplicationReleaseManagerImpl.java | 97 ++++----- .../impl/ApplicationStorageManagerImpl.java | 193 +++++++++++------- .../core/impl/LifecycleStateManagerImpl.java | 6 +- .../core/impl/SubscriptionManagerImpl.java | 89 ++++---- .../impl/UnrestrictedRoleManagerImpl.java | 112 +++++----- .../pom.xml | 2 +- .../ApplicationReleaseManagementAPI.java | 12 +- .../impl/ApplicationManagementAPIImpl.java | 10 +- .../ApplicationReleaseManagementAPIImpl.java | 125 ++++++------ .../impl/LifecycleManagementAPIImpl.java | 40 ++-- .../application/mgt/store/api/APIUtil.java | 95 ++------- .../services/ApplicationManagementAPI.java | 70 ------- .../impl/ApplicationManagementAPIImpl.java | 47 ----- .../pom.xml | 29 ++- 22 files changed, 497 insertions(+), 569 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 03bba4ba79..6a094688e9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -36,7 +36,7 @@ public interface ApplicationManager { * @throws ApplicationManagementException Application Management Exception */ Application createApplication(Application application) - throws ApplicationManagementException, DeviceManagementDAOException; + throws ApplicationManagementException; /** * Updates an already existing application. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java index a03d8050bb..9f181dacf6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java @@ -84,12 +84,12 @@ public interface ApplicationReleaseManager { /** * To update with a new release for an Application. * - * @param applicationUuid UUID of the Application + * @param appId ID of the Application * @param applicationRelease ApplicationRelease * @return Updated Application Release. * @throws ApplicationManagementException Application Management Exception. */ - ApplicationRelease updateRelease(String applicationUuid, ApplicationRelease applicationRelease) + ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws ApplicationManagementException; /** diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java index dad387970a..705c897a55 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationStorageManager.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.application.mgt.common.services; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.ImageArtifact; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; @@ -43,6 +44,20 @@ public interface ApplicationStorageManager { ApplicationRelease uploadImageArtifacts(int applicationId, ApplicationRelease applicationRelease, InputStream iconFile, InputStream bannerFile, List screenshots) throws ResourceManagementException; + /** + * To upload image artifacts related with an Application. + * + * @param applicationId ID of the application + * @param uuid Unique Identifier of the application + * @param iconFile Icon File input stream + * @param bannerFile Banner File input stream + * @param screenshots Input Streams of screenshots + * @throws ResourceManagementException Resource Management Exception. + */ + ApplicationRelease updateImageArtifacts(int applicationId, String uuid, InputStream iconFile, + InputStream bannerFile, List screenshots) + throws ResourceManagementException, ApplicationManagementException; + /** * To upload release artifacts for an Application. * @@ -54,6 +69,17 @@ public interface ApplicationStorageManager { ApplicationRelease uploadReleaseArtifacts(int applicationId, ApplicationRelease applicationRelease, InputStream binaryFile) throws ResourceManagementException; + /** + * To upload release artifacts for an Application. + * + * @param applicationId Id of the application. + * @param applicationUuid UUID of the application related with the release. + * @param binaryFile Binary File for the release. + * @throws ResourceManagementException Resource Management Exception. + */ + ApplicationRelease updateReleaseArtifacts(int applicationId, String applicationUuid, InputStream binaryFile) + throws ResourceManagementException; + /** * To get released artifacts for the particular version of the application. * diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/LifecycleStateManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/LifecycleStateManager.java index 82238a716a..0e2e8a5c54 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/LifecycleStateManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/LifecycleStateManager.java @@ -28,9 +28,9 @@ import java.util.List; */ public interface LifecycleStateManager { - List getLifecycleStates() throws LifecycleManagementException; + List getLifecycleStates(int appReleaseId) throws LifecycleManagementException; void addLifecycleState(LifecycleState state) throws LifecycleManagementException; - void deleteLifecycleState(String identifier) throws LifecycleManagementException; + void deleteLifecycleState(int identifier) throws LifecycleManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml index 3fd6f5a8a6..31014dc167 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml @@ -78,7 +78,10 @@ org.wso2.carbon, org.apache.commons.io, org.apache.commons.codec.binary;version="${commons-codec.wso2.osgi.version.range}", - org.wso2.carbon.base + org.apache.commons.codec.digest;version="${commons-codec.wso2.osgi.version.range}", + org.wso2.carbon.base, + org.wso2.carbon.device.mgt.core.dto.*;version="${carbon.device.mgt.version}", + org.wso2.carbon.device.mgt.core.dao.*;version="${carbon.device.mgt.version}" !org.wso2.carbon.device.application.mgt.core.internal.*, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java index 2a0ec268b5..7b31d32d47 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java @@ -22,6 +22,7 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; +import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; 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.ApplicationManagementDAOException; @@ -104,7 +105,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements * @throws ApplicationManagementDAOException Application Management DAO Exception. */ @Override - public ApplicationRelease getRelease(String applicationName,String applicationType, String versionName, + public ApplicationRelease getRelease(String applicationName, String applicationType, String versionName, String releaseType, int tenantId) throws ApplicationManagementDAOException { Connection connection; @@ -133,7 +134,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements if (resultSet.next()) { applicationRelease = new ApplicationRelease(); - applicationRelease.setId(resultSet.getInt("RELESE_ID")); + applicationRelease.setId(resultSet.getInt("RELEASE_ID")); applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION")); applicationRelease.setUuid(resultSet.getString("UUID")); applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE")); @@ -221,7 +222,11 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY")); applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT")); applicationRelease.setStarts(resultSet.getInt("STARS")); - applicationReleases.add(applicationRelease); + if ("REMOVED".equals(ApplicationManagementDAOFactory.getLifecycleStateDAO(). + getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())){ + applicationReleases.add(applicationRelease); + } + } return applicationReleases; } catch (DBConnectionException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/OracleApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/OracleApplicationDAOImpl.java index b35a8219cb..2769c5a678 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/OracleApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/OracleApplicationDAOImpl.java @@ -31,46 +31,46 @@ import java.sql.SQLException; */ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { - @Override - protected PreparedStatement generateGetApplicationsStatement(Filter filter, Connection conn, - int tenantId) throws SQLException { - int index = 0; - String sql = "SELECT APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER, CAT.ID AS CAT_ID, " - + "CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, " - + "LS.DESCRIPTION AS LS_DESCRIPTION " + "FROM APPM_APPLICATION APP " + "INNER JOIN APPM_PLATFORM APL " - + "ON APP.PLATFORM_ID = APL.ID " + "INNER JOIN APPM_APPLICATION_CATEGORY CAT " - + "ON APP.APPLICATION_CATEGORY_ID = CAT.ID " + "INNER JOIN APPM_LIFECYCLE_STATE LS " - + "ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ? "; - - String userName = filter.getUserName(); - if (!userName.equals("ALL")) { - sql += " AND APP.CREATED_BY = ? "; - } - if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { - sql += "AND LOWER (APP.NAME) "; - if (filter.isFullMatch()) { - sql += "= ?"; - } else { - sql += "LIKE ?"; - } - } - sql += " ORDER BY APP.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; - PreparedStatement stmt = conn.prepareStatement(sql); - stmt.setInt(++index, tenantId); - - if (!userName.equals("ALL")) { - stmt.setString(++index, userName); - } - if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { - if (filter.isFullMatch()) { - stmt.setString(++index, filter.getSearchQuery().toLowerCase()); - } else { - stmt.setString(++index, "%" + filter.getSearchQuery().toLowerCase() + "%"); - } - } - stmt.setInt(++index, filter.getOffset()); - stmt.setInt(++index, filter.getLimit()); - return stmt; - } +// @Override +// protected PreparedStatement generateGetApplicationsStatement(Filter filter, Connection conn, +// int tenantId) throws SQLException { +// int index = 0; +// String sql = "SELECT APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER, CAT.ID AS CAT_ID, " +// + "CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, " +// + "LS.DESCRIPTION AS LS_DESCRIPTION " + "FROM APPM_APPLICATION APP " + "INNER JOIN APPM_PLATFORM APL " +// + "ON APP.PLATFORM_ID = APL.ID " + "INNER JOIN APPM_APPLICATION_CATEGORY CAT " +// + "ON APP.APPLICATION_CATEGORY_ID = CAT.ID " + "INNER JOIN APPM_LIFECYCLE_STATE LS " +// + "ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ? "; +// +// String userName = filter.getUserName(); +// if (!userName.equals("ALL")) { +// sql += " AND APP.CREATED_BY = ? "; +// } +// if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { +// sql += "AND LOWER (APP.NAME) "; +// if (filter.isFullMatch()) { +// sql += "= ?"; +// } else { +// sql += "LIKE ?"; +// } +// } +// sql += " ORDER BY APP.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; +// PreparedStatement stmt = conn.prepareStatement(sql); +// stmt.setInt(++index, tenantId); +// +// if (!userName.equals("ALL")) { +// stmt.setString(++index, userName); +// } +// if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { +// if (filter.isFullMatch()) { +// stmt.setString(++index, filter.getSearchQuery().toLowerCase()); +// } else { +// stmt.setString(++index, "%" + filter.getSearchQuery().toLowerCase() + "%"); +// } +// } +// stmt.setInt(++index, filter.getOffset()); +// stmt.setInt(++index, filter.getLimit()); +// return stmt; +// } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 0abfe97566..95aacb423e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -66,8 +66,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public Application createApplication(Application application) - throws ApplicationManagementException, DeviceManagementDAOException { + public Application createApplication(Application application) throws ApplicationManagementException { User loggedInUser = new User(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(), PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); @@ -112,7 +111,7 @@ public class ApplicationManagerImpl implements ApplicationManager { String msg = "Error occurred while getting device type id of " + application.getType(); log.error(msg, e); ConnectionManagerUtil.rollbackDBTransaction(); - throw new DeviceManagementDAOException(msg, e); + throw new ApplicationManagementException(msg, e); } catch(ApplicationManagementException e){ String msg = "Error occurred while adding application"; log.error(msg, e); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationReleaseManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationReleaseManagerImpl.java index 01f0023a75..957421223d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationReleaseManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationReleaseManagerImpl.java @@ -45,7 +45,7 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager public ApplicationRelease createRelease(int applicationId, ApplicationRelease applicationRelease) throws ApplicationManagementException { Application application = validateApplication(applicationId); - validateReleaseCreateRequest(applicationRelease.getUuid(), applicationRelease); + validateReleaseCreateRequest(applicationRelease); if (log.isDebugEnabled()) { log.debug("Application release request is received for the application " + application.toString()); } @@ -64,24 +64,27 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager } } + //todo @Override public ApplicationRelease getRelease(String applicationUuid, String version, String releaseType) throws ApplicationManagementException { - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - Application application = validateApplicationRelease(applicationUuid); - if (log.isDebugEnabled()) { - log.debug("Application release retrieval request is received for the application " + - application.toString() + " and version " + version); - } - try { - ConnectionManagerUtil.openDBConnection(); - return ApplicationManagementDAOFactory.getApplicationReleaseDAO() - .getRelease(application.getName(), application.getType(), version, releaseType, tenantId ); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } + return null; +// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); +// Application application = validateApplicationRelease(applicationUuid); +// if (log.isDebugEnabled()) { +// log.debug("Application release retrieval request is received for the application " + +// application.toString() + " and version " + version); +// } +// try { +// ConnectionManagerUtil.openDBConnection(); +// return ApplicationManagementDAOFactory.getApplicationReleaseDAO() +// .getRelease(application.getName(), application.getType(), version, releaseType, tenantId ); +// } finally { +// ConnectionManagerUtil.closeDBConnection(); +// } } + //todo @Override public ApplicationRelease getReleaseByUuid(String applicationUuid) throws ApplicationManagementException { return null; } @@ -130,7 +133,7 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager // ToDo @Override - public ApplicationRelease updateRelease(String applicationUuid, ApplicationRelease applicationRelease) + public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws ApplicationManagementException { // Application application = validateApplicationRelease(applicationUuid); // ApplicationRelease oldApplicationRelease = null; @@ -162,36 +165,38 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager return null; } + //todo @Override public void deleteApplicationRelease(String applicationUuid, String version, String releaseType) throws ApplicationManagementException { - Application application = validateApplicationRelease(applicationUuid); - ApplicationRelease applicationRelease = getRelease(applicationUuid, version, releaseType); - if (applicationRelease == null) { - throw new ApplicationManagementException( - "Cannot delete a non-existing application release for the " + "application with UUID " - + applicationUuid); - } - try { - ConnectionManagerUtil.beginDBTransaction(); - ApplicationManagementDAOFactory.getApplicationReleaseDAO().deleteRelease(application.getId(), version); -// ToDO remove storage details as well - ConnectionManagerUtil.commitDBTransaction(); - } catch (ApplicationManagementDAOException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - throw e; - } finally { - ConnectionManagerUtil.closeDBConnection(); - } +// Application application = validateApplicationRelease(applicationUuid); +// ApplicationRelease applicationRelease = getRelease(applicationUuid, version, releaseType); +// if (applicationRelease == null) { +// throw new ApplicationManagementException( +// "Cannot delete a non-existing application release for the " + "application with UUID " +// + applicationUuid); +// } +// try { +// ConnectionManagerUtil.beginDBTransaction(); +// ApplicationManagementDAOFactory.getApplicationReleaseDAO().deleteRelease(application.getId(), version); +//// ToDO remove storage details as well +// ConnectionManagerUtil.commitDBTransaction(); +// } catch (ApplicationManagementDAOException e) { +// ConnectionManagerUtil.rollbackDBTransaction(); +// throw e; +// } finally { +// ConnectionManagerUtil.closeDBConnection(); +// } } + //todo @Override public void deleteApplicationReleases(String applicationUuid) throws ApplicationManagementException { - List applicationReleases = getReleases(applicationUuid); - - for (ApplicationRelease applicationRelease : applicationReleases) { - deleteApplicationRelease(applicationUuid, applicationRelease.getVersion()); - } +// List applicationReleases = getReleases(applicationUuid); +// +// for (ApplicationRelease applicationRelease : applicationReleases) { +// deleteApplicationRelease(applicationUuid, applicationRelease.getVersion()); +// } } /** @@ -224,7 +229,8 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager throw new ApplicationManagementException("Application UUID is null. Application UUID is a required " + "parameter to get the relevant application."); } - ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager().getRelease(); + ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager() + .getReleaseByUuid(applicationUuid); if (applicationRelease == null) { throw new NotFoundException( "Application with UUID " + applicationUuid + " does not exist."); @@ -235,21 +241,20 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager /** * To validate a create release request to make sure all the pre-conditions satisfied. * - * @param applicationUuid UUID of the Application. * @param applicationRelease ApplicationRelease that need to be created. * @throws ApplicationManagementException Application Management Exception. */ - private void validateReleaseCreateRequest(String applicationUuid, ApplicationRelease applicationRelease) + private void validateReleaseCreateRequest(ApplicationRelease applicationRelease) throws ApplicationManagementException { if (applicationRelease == null || applicationRelease.getVersion() == null) { throw new ApplicationManagementException("ApplicationRelease version name is a mandatory parameter for " + "creating release. It cannot be found."); } - if (getRelease(applicationUuid, applicationRelease.getVersion()) != null) { - throw new ApplicationManagementException( - "Application Release for the Application UUID " + applicationUuid + " " + "with the version " - + applicationRelease.getVersion() + " already exists. Cannot create an " - + "application release with the same version."); + if (getRelease(applicationRelease.getUuid(), applicationRelease.getVersion(), + applicationRelease.getReleaseType()) != null) { + throw new ApplicationManagementException( "Application Release for the Application UUID " + + applicationRelease.getUuid() + " " + "with the version " + applicationRelease.getVersion() + + " already exists. Cannot create an " + "application release with the same version."); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java index 2195922185..6006aab780 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java @@ -117,8 +117,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager count++; } } - - } return applicationRelease; } catch (IOException e) { @@ -126,7 +124,32 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager "IO Exception while saving the screens hots for the " + "application " + applicationId, e); } catch (ApplicationStorageManagementException e) { ConnectionManagerUtil.rollbackDBTransaction(); - throw new ApplicationStorageManagementException("Application Management DAO exception while trying to" + throw new ApplicationStorageManagementException("Application Management DAO exception while trying to " + + "update the screen-shot count for the application " + applicationId + " for the tenant id " + + tenantId, e); + } + + } + + @Override + public ApplicationRelease updateImageArtifacts(int applicationId, String uuid, InputStream iconFileStream, + InputStream bannerFileStream, List screenShotStreams) + throws ResourceManagementException, ApplicationManagementException { + + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + + try { + ApplicationRelease applicationRelease = validateApplicationRelease(uuid); + applicationRelease = uploadImageArtifacts(applicationId, applicationRelease, iconFileStream, bannerFileStream, screenShotStreams); + return applicationRelease; + } catch (ApplicationStorageManagementException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + throw new ApplicationStorageManagementException("Application Storage exception while trying to" + + " update the screen-shot count for the application " + applicationId + " for the tenant " + + tenantId, e); + } catch (ApplicationManagementException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + throw new ApplicationManagementException("Application Management DAO exception while trying to" + " update the screen-shot count for the application " + applicationId + " for the tenant " + tenantId, e); } @@ -167,100 +190,125 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager } @Override - public InputStream getReleasedArtifacts(String applicationUUID, String versionName) - throws ApplicationStorageManagementException { - // todo this should be validate application release - Application application = validateApplication(applicationUUID); - String artifactPath = storagePath + application.getId() + File.separator + versionName; - - if (log.isDebugEnabled()) { - log.debug("ApplicationRelease artifacts are searched in the location " + artifactPath); - } + public ApplicationRelease updateReleaseArtifacts(int applicationId, String applicationUuid, InputStream binaryFile) + throws ResourceManagementException { - File binaryFile = new File(artifactPath); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - if (!binaryFile.exists()) { - throw new ApplicationStorageManagementException("Binary file does not exist for this release"); - } else { - try { - return new FileInputStream(artifactPath); - } catch (FileNotFoundException e) { - throw new ApplicationStorageManagementException( - "Binary file does not exist for the version " + versionName + " for the application ", e); - } + ApplicationRelease applicationRelease = null; + try { + applicationRelease = validateApplicationRelease(applicationUuid); + applicationRelease = uploadReleaseArtifacts(applicationId, applicationRelease,binaryFile); + return applicationRelease; + } catch (ApplicationManagementException e) { + throw new ApplicationStorageManagementException("Application Management exception while trying to" + + " update the Application artifact for the application " + applicationId + " for the tenant " + + tenantId, e); } } + //todo @Override - public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException { + public InputStream getReleasedArtifacts(String applicationUUID, String versionName) + throws ApplicationStorageManagementException { + return null; // todo this should be validate application release - Application application = validateApplication(applicationUUID); - String artifactDirectoryPath = storagePath + application.getId(); - File artifactDirectory = new File(artifactDirectoryPath); +// Application application = validateApplication(applicationUUID); +// String artifactPath = storagePath + application.getId() + File.separator + versionName; +// +// if (log.isDebugEnabled()) { +// log.debug("ApplicationRelease artifacts are searched in the location " + artifactPath); +// } +// +// File binaryFile = new File(artifactPath); +// +// if (!binaryFile.exists()) { +// throw new ApplicationStorageManagementException("Binary file does not exist for this release"); +// } else { +// try { +// return new FileInputStream(artifactPath); +// } catch (FileNotFoundException e) { +// throw new ApplicationStorageManagementException( +// "Binary file does not exist for the version " + versionName + " for the application ", e); +// } +// } + } - if (artifactDirectory.exists()) { - StorageManagementUtil.deleteDir(artifactDirectory); - } + //todo + @Override + public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException { + // todo this should be validate application release +// Application application = validateApplication(applicationUUID); +// String artifactDirectoryPath = storagePath + application.getId(); +// File artifactDirectory = new File(artifactDirectoryPath); +// +// if (artifactDirectory.exists()) { +// StorageManagementUtil.deleteDir(artifactDirectory); +// } } + //todo @Override public void deleteApplicationReleaseArtifacts(String applicationUUID, String version) throws ApplicationStorageManagementException { // todo this should be validate application release - Application application = validateApplication(applicationUUID); - String artifactPath = storagePath + application.getId() + File.separator + version; - File artifact = new File(artifactPath); - - if (artifact.exists()) { - StorageManagementUtil.deleteDir(artifact); - } +// Application application = validateApplication(applicationUUID); +// String artifactPath = storagePath + application.getId() + File.separator + version; +// File artifact = new File(artifactPath); +// +// if (artifact.exists()) { +// StorageManagementUtil.deleteDir(artifact); +// } } + //todo @Override public void deleteAllApplicationReleaseArtifacts(String applicationUUID) throws ApplicationStorageManagementException { // todo this should be validate application release - validateApplication(applicationUUID); - try { - List applicationReleases = DataHolder.getInstance().getApplicationReleaseManager() - .getReleases(applicationUUID); - for (ApplicationRelease applicationRelease : applicationReleases) { - deleteApplicationReleaseArtifacts(applicationUUID, applicationRelease.getVersion()); - } - } catch (ApplicationManagementException e) { - throw new ApplicationStorageManagementException( - "Application Management Exception while getting releases " + "for the application " - + applicationUUID, e); - } +// validateApplication(applicationUUID); +// try { +// List applicationReleases = DataHolder.getInstance().getApplicationReleaseManager() +// .getReleases(applicationUUID); +// for (ApplicationRelease applicationRelease : applicationReleases) { +// deleteApplicationReleaseArtifacts(applicationUUID, applicationRelease.getVersion()); +// } +// } catch (ApplicationManagementException e) { +// throw new ApplicationStorageManagementException( +// "Application Management Exception while getting releases " + "for the application " +// + applicationUUID, e); +// } } + //todo @Override public ImageArtifact getImageArtifact(String applicationUUID, String name, int count) throws ApplicationStorageManagementException { + return null; // todo this should be validate application release - Application application = validateApplication(applicationUUID); - validateImageArtifactNames(name); - String imageArtifactPath = storagePath + application.getId() + File.separator + name.toLowerCase(); - - if (name.equalsIgnoreCase(Constants.IMAGE_ARTIFACTS[2])) { - imageArtifactPath += count; - } - File imageFile = new File(imageArtifactPath); - if (!imageFile.exists()) { - throw new ApplicationStorageManagementException( - "Image artifact " + name + " does not exist for the " + "application with UUID " + applicationUUID); - } else { - try { - return StorageManagementUtil.createImageArtifact(imageFile, imageArtifactPath); - } catch (FileNotFoundException e) { - throw new ApplicationStorageManagementException( - "File not found exception while trying to get the image artifact " + name + " for the " - + "application " + applicationUUID, e); - } catch (IOException e) { - throw new ApplicationStorageManagementException("IO Exception while trying to detect the image " - + "artifact " + name + " for the application " + applicationUUID, e); - } - } +// Application application = validateApplication(applicationUUID); +// validateImageArtifactNames(name); +// String imageArtifactPath = storagePath + application.getId() + File.separator + name.toLowerCase(); +// +// if (name.equalsIgnoreCase(Constants.IMAGE_ARTIFACTS[2])) { +// imageArtifactPath += count; +// } +// File imageFile = new File(imageArtifactPath); +// if (!imageFile.exists()) { +// throw new ApplicationStorageManagementException( +// "Image artifact " + name + " does not exist for the " + "application with UUID " + applicationUUID); +// } else { +// try { +// return StorageManagementUtil.createImageArtifact(imageFile, imageArtifactPath); +// } catch (FileNotFoundException e) { +// throw new ApplicationStorageManagementException( +// "File not found exception while trying to get the image artifact " + name + " for the " +// + "application " + applicationUUID, e); +// } catch (IOException e) { +// throw new ApplicationStorageManagementException("IO Exception while trying to detect the image " +// + "artifact " + name + " for the application " + applicationUUID, e); +// } +// } } /** @@ -311,7 +359,8 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager throw new ApplicationManagementException("Application UUID is null. Application UUID is a required " + "parameter to get the relevant application."); } - ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager().getRelease(); + ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager(). + getReleaseByUuid(applicationUuid); if (applicationRelease == null) { throw new NotFoundException( "Application with UUID " + applicationUuid + " does not exist."); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/LifecycleStateManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/LifecycleStateManagerImpl.java index afd62e4c9b..b88c2e382c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/LifecycleStateManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/LifecycleStateManagerImpl.java @@ -38,12 +38,12 @@ public class LifecycleStateManagerImpl implements LifecycleStateManager { private static final Log log = LogFactory.getLog(LifecycleStateManagerImpl.class); @Override - public List getLifecycleStates() throws LifecycleManagementException { + public List getLifecycleStates(int appReleaseId) throws LifecycleManagementException { List lifecycleStates = null; try { ConnectionManagerUtil.openDBConnection(); LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); - lifecycleStates = lifecycleStateDAO.getLifecycleStates(); + lifecycleStates = lifecycleStateDAO.getLifecycleStates(appReleaseId); } catch (LifeCycleManagementDAOException | DBConnectionException e) { throw new LifecycleManagementException("Failed get lifecycle states.", e); } finally { @@ -66,7 +66,7 @@ public class LifecycleStateManagerImpl implements LifecycleStateManager { } @Override - public void deleteLifecycleState(String identifier) throws LifecycleManagementException { + public void deleteLifecycleState(int identifier) throws LifecycleManagementException { try { ConnectionManagerUtil.openDBConnection(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 2e01146661..b6bb3f5349 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -98,52 +98,53 @@ public class SubscriptionManagerImpl implements SubscriptionManager { private List installApplication(String applicationUUID, List deviceList, String versionName) throws ApplicationManagementException { - List failedDeviceList = new ArrayList<>(deviceList); - // Todo: try whether we can optimise this by sending bulk inserts to db - // Todo: atomicity is not maintained as deveice managment provider service uses separate db connection. fix this?? - log.info("Install application: " + applicationUUID + "[" + versionName + "]" + " to: " - + deviceList.size() + " devices."); - for (DeviceIdentifier device : deviceList) { - org.wso2.carbon.device.mgt.common.DeviceIdentifier deviceIdentifier = new org.wso2.carbon.device.mgt - .common.DeviceIdentifier(device.getId(), device.getType()); - try { - DeviceManagementProviderService dmpService = HelperUtil.getDeviceManagementProviderService(); - if (!dmpService.isEnrolled(deviceIdentifier)) { - log.error("Device with ID: [" + device.getId() + "] is not enrolled to install the application."); - } else { - if (log.isDebugEnabled()) { - log.debug("Installing application to : " + device.getId()); - } - //Todo: generating one time download link for the application and put install operation to device. - - // put app install operation to the device - ProfileOperation operation = new ProfileOperation(); - operation.setCode(INSTALL_APPLICATION); - operation.setType(Operation.Type.PROFILE); - operation.setPayLoad("{'type':'enterprise', 'url':'http://10.100.5.76:8000/app-debug.apk', 'app':'" - + applicationUUID + "'}"); - List deviceIdentifiers = new ArrayList<>(); - deviceIdentifiers.add(deviceIdentifier); - dmpService.addOperation(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, - operation, deviceIdentifiers); - - DeviceApplicationMapping deviceApp = new DeviceApplicationMapping(); - deviceApp.setDeviceIdentifier(device.getId()); - deviceApp.setApplicationUUID(applicationUUID); - deviceApp.setVersionName(versionName); - deviceApp.setInstalled(false); - dmpService.addDeviceApplicationMapping(deviceApp); -// DeviceManagementDAOFactory.openConnection(); -// ApplicationManagementDAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false); - failedDeviceList.remove(device); - } - } catch (DeviceManagementException | OperationManagementException | InvalidDeviceException e) { - log.error("Error while installing application to device[" + deviceIdentifier.getId() + "]", e); - } + return null; +// List failedDeviceList = new ArrayList<>(deviceList); +// // Todo: try whether we can optimise this by sending bulk inserts to db +// // Todo: atomicity is not maintained as deveice managment provider service uses separate db connection. fix this?? +// log.info("Install application: " + applicationUUID + "[" + versionName + "]" + " to: " +// + deviceList.size() + " devices."); +// for (DeviceIdentifier device : deviceList) { +// org.wso2.carbon.device.mgt.common.DeviceIdentifier deviceIdentifier = new org.wso2.carbon.device.mgt +// .common.DeviceIdentifier(device.getId(), device.getType()); +// try { +// DeviceManagementProviderService dmpService = HelperUtil.getDeviceManagementProviderService(); +// if (!dmpService.isEnrolled(deviceIdentifier)) { +// log.error("Device with ID: [" + device.getId() + "] is not enrolled to install the application."); +// } else { +// if (log.isDebugEnabled()) { +// log.debug("Installing application to : " + device.getId()); +// } +// //Todo: generating one time download link for the application and put install operation to device. +// +// // put app install operation to the device +// ProfileOperation operation = new ProfileOperation(); +// operation.setCode(INSTALL_APPLICATION); +// operation.setType(Operation.Type.PROFILE); +// operation.setPayLoad("{'type':'enterprise', 'url':'http://10.100.5.76:8000/app-debug.apk', 'app':'" +// + applicationUUID + "'}"); +// List deviceIdentifiers = new ArrayList<>(); +// deviceIdentifiers.add(deviceIdentifier); +// dmpService.addOperation(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, +// operation, deviceIdentifiers); +// +// DeviceApplicationMapping deviceApp = new DeviceApplicationMapping(); +// deviceApp.setDeviceIdentifier(device.getId()); +// deviceApp.setApplicationUUID(applicationUUID); +// deviceApp.setVersionName(versionName); +// deviceApp.setInstalled(false); +// dmpService.addDeviceApplicationMapping(deviceApp); +//// DeviceManagementDAOFactory.openConnection(); +//// ApplicationManagementDAOFactory.getSubscriptionDAO().addDeviceApplicationMapping(device.getId(), applicationUUID, false); +// failedDeviceList.remove(device); +// } +// } catch (DeviceManagementException | OperationManagementException | InvalidDeviceException e) { +// log.error("Error while installing application to device[" + deviceIdentifier.getId() + "]", e); +// } // finally { // DeviceManagementDAOFactory.closeConnection(); // } - } - return failedDeviceList; +// } +// return failedDeviceList; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/UnrestrictedRoleManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/UnrestrictedRoleManagerImpl.java index 162e638e7d..c4ab85ee8f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/UnrestrictedRoleManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/UnrestrictedRoleManagerImpl.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import java.util.List; +//todo need to work on business logic /** * This is the default implementation for the visibility manager. */ @@ -35,39 +36,40 @@ public class UnrestrictedRoleManagerImpl implements UnrestrictedRoleManager { @Override public Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException { - if (visibility == null) { - visibility = new Visibility(); - visibility.setType(Visibility.Type.PUBLIC); - } - if (visibility.getAllowedList() == null && !visibility.getType().equals(Visibility.Type.PUBLIC)) { - throw new VisibilityManagementException("Visibility is configured for '" + visibility.getType() - + "' but doesn't have any allowed list provided!"); - } - boolean isTransactionStarted = false; - try { - isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); - if (!isTransactionStarted) { - ConnectionManagerUtil.beginDBTransaction(); - } - VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); - int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType()); - visibilityDAO.delete(applicationID); - visibilityDAO.add(applicationID, visibilityTypeId, visibility.getAllowedList()); - if (!isTransactionStarted) { - ConnectionManagerUtil.commitDBTransaction(); - } - return visibility; - } catch (ApplicationManagementException e) { - if (!isTransactionStarted) { - ConnectionManagerUtil.rollbackDBTransaction(); - } - throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - " - + applicationID, e); - } finally { - if (!isTransactionStarted) { - ConnectionManagerUtil.closeDBConnection(); - } - } + return null; +// if (visibility == null) { +// visibility = new Visibility(); +// visibility.setType(Visibility.Type.PUBLIC); +// } +// if (visibility.getAllowedList() == null && !visibility.getType().equals(Visibility.Type.PUBLIC)) { +// throw new VisibilityManagementException("Visibility is configured for '" + visibility.getType() +// + "' but doesn't have any allowed list provided!"); +// } +// boolean isTransactionStarted = false; +// try { +// isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); +// if (!isTransactionStarted) { +// ConnectionManagerUtil.beginDBTransaction(); +// } +// VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); +// int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType()); +// visibilityDAO.delete(applicationID); +// visibilityDAO.add(applicationID, visibilityTypeId, visibility.getAllowedList()); +// if (!isTransactionStarted) { +// ConnectionManagerUtil.commitDBTransaction(); +// } +// return visibility; +// } catch (ApplicationManagementException e) { +// if (!isTransactionStarted) { +// ConnectionManagerUtil.rollbackDBTransaction(); +// } +// throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - " +// + applicationID, e); +// } finally { +// if (!isTransactionStarted) { +// ConnectionManagerUtil.closeDBConnection(); +// } +// } } @Override @@ -87,28 +89,28 @@ public class UnrestrictedRoleManagerImpl implements UnrestrictedRoleManager { @Override public void remove(int applicationID) throws VisibilityManagementException { - boolean isTransactionStarted = false; - try { - isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); - if (!isTransactionStarted) { - ConnectionManagerUtil.beginDBTransaction(); - } - VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); - visibilityDAO.delete(applicationID); - if (!isTransactionStarted) { - ConnectionManagerUtil.commitDBTransaction(); - } - } catch (ApplicationManagementException e) { - if (!isTransactionStarted) { - ConnectionManagerUtil.rollbackDBTransaction(); - } - throw new VisibilityManagementException("Problem occurred when trying to fetch the application with ID - " - + applicationID, e); - } finally { - if (!isTransactionStarted) { - ConnectionManagerUtil.closeDBConnection(); - } - } +// boolean isTransactionStarted = false; +// try { +// isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); +// if (!isTransactionStarted) { +// ConnectionManagerUtil.beginDBTransaction(); +// } +// VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); +// visibilityDAO.delete(applicationID); +// if (!isTransactionStarted) { +// ConnectionManagerUtil.commitDBTransaction(); +// } +// } catch (ApplicationManagementException e) { +// if (!isTransactionStarted) { +// ConnectionManagerUtil.rollbackDBTransaction(); +// } +// throw new VisibilityManagementException("Problem occurred when trying to fetch the application with ID - " +// + applicationID, e); +// } finally { +// if (!isTransactionStarted) { +// ConnectionManagerUtil.closeDBConnection(); +// } +// } } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml index e6dfe6199c..ca0acc2be0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml @@ -66,7 +66,7 @@ - + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationReleaseManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationReleaseManagementAPI.java index cb8d57fa13..5e402b81ae 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationReleaseManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationReleaseManagementAPI.java @@ -168,7 +168,7 @@ public interface ApplicationReleaseManagementAPI { @POST - @Path("/upload-artifacts/{uuid}") + @Path("/update-image-artifacts/{appId}/{uuid}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @ApiOperation( @@ -195,12 +195,13 @@ public interface ApplicationReleaseManagementAPI { response = ErrorResponse.class) }) Response updateApplicationImageArtifacts( + @ApiParam(name = "appId", value = "ID of the application", required = true) @PathParam("appId") int applicatioId, @ApiParam(name = "uuid", value = "UUID of the application", required = true) @PathParam("uuid") String applicationUUID, @Multipart(value = "icon") Attachment iconFile, @Multipart(value = "banner") Attachment bannerFile, @Multipart(value = "screenshot") List screenshots); @PUT - @Path("/upload-artifacts/{uuid}") + @Path("/update-artifacts/{appId}/{uuid}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @ApiOperation( @@ -226,11 +227,10 @@ public interface ApplicationReleaseManagementAPI { message = "Internal Server Error. \n Error occurred while getting the application list.", response = ErrorResponse.class) }) - Response updateApplicationArtifacts( + Response updateApplicationArtifact( + @ApiParam(name = "id", value = "Id of the application", required = true) @PathParam("uuid") int applicationId, @ApiParam(name = "uuid", value = "UUID of the application", required = true) @PathParam("uuid") String applicationUUID, - @Multipart(value = "icon", required = false) Attachment iconFile, - @Multipart(value = "banner", required = false) Attachment bannerFile, - @Multipart(value = "screenshot", required = false) List screenshots); + @Multipart("binaryFile") Attachment binaryFile ); @PUT @Path("/{appId}/{uuid}") diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index cfd33e8107..6ad9d04893 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -58,7 +58,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - /** * Implementation of Application Management related APIs. */ @@ -70,7 +69,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class); - //todo need to pass uuid @GET @Override @Consumes("application/json") @@ -117,7 +115,9 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @GET @Consumes("application/json") @Path("/{appType}") - public Response getApplication(@PathParam("appType") String appType, @QueryParam("appName") String appName) { + public Response getApplication( + @PathParam("appType") String appType, + @QueryParam("appName") String appName) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { @@ -161,10 +161,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { log.error(msg); return Response.status(Response.Status.BAD_REQUEST).build(); } - }catch (DeviceManagementDAOException e) { - String msg = "Error occurred while getting the device type"; - log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).build(); }catch (ApplicationManagementException e) { String msg = "Error occurred while creating the application"; log.error(msg, e); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationReleaseManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationReleaseManagementAPIImpl.java index ea67e0d09c..5c38bb1d24 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationReleaseManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationReleaseManagementAPIImpl.java @@ -145,7 +145,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa try { List unrestrictedRoles = unrestrictedRoleManager.getUnrestrictedRoles(applicationId, tenantId); if(unrestrictedRoles == null || applicationManager.isUserAllowable(unrestrictedRoles,userName)){ - applicationReleases= applicationReleaseManager.getReleases(applicationId); + applicationReleases = applicationReleaseManager.getReleases(applicationId); return Response.status(Response.Status.OK).entity(applicationReleases).build(); } @@ -204,7 +204,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa iconFileStream, bannerFileStream, attachments); if (applicationRelease != null) { - applicationRelease = applicationReleaseManager.updateRelease(applicationUUID, applicationRelease); + applicationRelease = applicationReleaseManager.updateRelease(applicationId, applicationRelease); } return Response.status(Response.Status.OK).entity(applicationRelease).build(); } catch (NotFoundException e) { @@ -213,54 +213,52 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa log.error("Error while updating the application release of the application with UUID " + applicationUUID); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); } - catch (IOException e) { - log.error("Error while updating the release artifacts of the application with UUID " + applicationUUID); - return APIUtil.getResponse(new ApplicationManagementException( - "Error while updating the release artifacts of the application with UUID " - + applicationUUID), Response.Status.INTERNAL_SERVER_ERROR); - } - catch (ResourceManagementException e) { - log.error("Error occurred while updating the releases artifacts of the application with the uuid " - + applicationUUID + " for the release " + applicationRelease.getVersion(), e); - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); - } + catch (IOException e) { + log.error("Error while updating the release artifacts of the application with UUID " + applicationUUID); + return APIUtil.getResponse(new ApplicationManagementException( + "Error while updating the release artifacts of the application with UUID " + + applicationUUID), Response.Status.INTERNAL_SERVER_ERROR); + } + catch (ResourceManagementException e) { + log.error("Error occurred while updating the releases artifacts of the application with the uuid " + + applicationUUID + " for the release " + applicationRelease.getVersion(), e); + return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } } - //todo @Override @POST - @Path("/upload-image-artifacts/{uuid}") - public Response updateApplicationImageArtifacts(@PathParam("uuid") String applicationUUID, - @Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, + @Path("/update-image-artifacts/{appId}/{uuid}") + public Response updateApplicationImageArtifacts( + @PathParam("appId") int appId, + @PathParam("uuid") String applicationUUID, + @Multipart("icon") Attachment iconFile, + @Multipart("banner") Attachment bannerFile, @Multipart("screenshot") List attachmentList) { + ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); + ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); + ApplicationRelease applicationRelease = null; + try { - InputStream iconFileStream; - InputStream bannerFileStream; + InputStream iconFileStream = null; + InputStream bannerFileStream = null; List attachments = new ArrayList<>(); if (iconFile != null) { iconFileStream = iconFile.getDataHandler().getInputStream(); - } else { - throw new ApplicationManagementException( - "Icon file is not uploaded for the application " + applicationUUID); } if (bannerFile != null) { bannerFileStream = bannerFile.getDataHandler().getInputStream(); - } else { - throw new ApplicationManagementException( - "Banner file is not uploaded for the application " + applicationUUID); } if (attachmentList != null && !attachmentList.isEmpty()) { for (Attachment screenshot : attachmentList) { attachments.add(screenshot.getDataHandler().getInputStream()); } - } else { - throw new ApplicationManagementException( - "Screen-shot are not uploaded for the application " + applicationUUID); } -// applicationStorageManager -// .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments); + applicationRelease = applicationStorageManager.updateImageArtifacts + (appId, applicationUUID, iconFileStream, bannerFileStream, attachments); + applicationReleaseManager.updateRelease(appId,applicationRelease); return Response.status(Response.Status.OK) .entity("Successfully uploaded artifacts for the application " + applicationUUID).build(); } catch (NotFoundException e) { @@ -275,54 +273,53 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa "Exception while trying to read icon, " + "banner files for the application " + applicationUUID, e), Response.Status.BAD_REQUEST); } -// catch (ResourceManagementException e) { -// log.error("Error occurred while uploading the image artifacts of the application with the uuid " -// + applicationUUID, e); -// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); -// } + catch (ResourceManagementException e) { + log.error("Error occurred while uploading the image artifacts of the application with the uuid " + + applicationUUID, e); + return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } } - //todo @Override @PUT - @Path("/upload-image-artifacts/{uuid}") - public Response updateApplicationArtifacts(@PathParam("uuid") String applicationUUID, - @Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, - @Multipart("screenshot") List attachmentList) { + @Path("/update-artifacts/{appId}/{uuid}") + public Response updateApplicationArtifact( + @PathParam("appId") int applicationId, + @PathParam("uuid") String applicationUuuid, + @Multipart("binaryFile") Attachment binaryFile) { ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); + ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); + ApplicationRelease applicationRelease = null; try { - InputStream iconFileStream = null; - InputStream bannerFileStream = null; - List attachments = new ArrayList<>(); - if (iconFile != null) { - iconFileStream = iconFile.getDataHandler().getInputStream(); - } - if (bannerFile != null) { - bannerFileStream = bannerFile.getDataHandler().getInputStream(); - } - if (attachmentList != null) { - for (Attachment screenshot : attachmentList) { - attachments.add(screenshot.getDataHandler().getInputStream()); - } + if (binaryFile != null) { + applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationId, applicationUuuid, + binaryFile.getDataHandler().getInputStream()); + applicationReleaseManager.updateRelease(applicationId, applicationRelease); + return Response.status(Response.Status.OK) + .entity("Successfully uploaded artifacts for the application " + applicationUuuid).build(); + } -// applicationStorageManager -// .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments); - return Response.status(Response.Status.OK) - .entity("Successfully updated artifacts for the application " + applicationUUID).build(); + return Response.status(Response.Status.BAD_REQUEST) + .entity("Uploading artifacts for the application is failed " + applicationUuuid).build(); } catch (IOException e) { - log.error("Exception while trying to read icon, banner files for the application " + applicationUUID); + log.error("Exception while trying to read icon, banner files for the application " + applicationUuuid); return APIUtil.getResponse(new ApplicationManagementException( "Exception while trying to read icon, banner files for the application " + - applicationUUID, e), Response.Status.BAD_REQUEST); + applicationUuuid, e), Response.Status.BAD_REQUEST); + } + catch (ResourceManagementException e) { + log.error("Error occurred while uploading the image artifacts of the application with the uuid " + + applicationUuuid, e); + return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } catch (ApplicationManagementException e) { + log.error("Error occurred while updating the image artifacts of the application with the uuid " + + applicationUuuid, e); + return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); } -// catch (ResourceManagementException e) { -// log.error("Error occurred while uploading the image artifacts of the application with the uuid " -// + applicationUUID, e); -// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); -// } } + //todo @Override @DELETE @Path("/release/{uuid}") diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/LifecycleManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/LifecycleManagementAPIImpl.java index 7b297fd336..8f8829d6f2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/LifecycleManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/LifecycleManagementAPIImpl.java @@ -45,16 +45,17 @@ public class LifecycleManagementAPIImpl implements LifecycleManagementAPI { @GET public Response getLifecycleStates() { - LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager(); - List lifecycleStates = new ArrayList<>(); - try { - lifecycleStates = lifecycleStateManager.getLifecycleStates(); - } catch (LifecycleManagementException e) { - String msg = "Error occurred while retrieving lifecycle states."; - log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).build(); - } - return Response.status(Response.Status.OK).entity(lifecycleStates).build(); + return null; +// LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager(); +// List lifecycleStates = new ArrayList<>(); +// try { +// lifecycleStates = lifecycleStateManager.getLifecycleStates(); +// } catch (LifecycleManagementException e) { +// String msg = "Error occurred while retrieving lifecycle states."; +// log.error(msg, e); +// return Response.status(Response.Status.BAD_REQUEST).build(); +// } +// return Response.status(Response.Status.OK).entity(lifecycleStates).build(); } @POST @@ -73,15 +74,16 @@ public class LifecycleManagementAPIImpl implements LifecycleManagementAPI { @DELETE @Path("/{identifier}") public Response deleteLifecycleState(@PathParam("identifier") String identifier) { - LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager(); - try { - lifecycleStateManager.deleteLifecycleState(identifier); - } catch (LifecycleManagementException e) { - String msg = "Error occurred while deleting lifecycle state."; - log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).build(); - } - return Response.status(Response.Status.OK).entity("Lifecycle state deleted successfully.").build(); + return null; +// LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager(); +// try { +// lifecycleStateManager.deleteLifecycleState(identifier); +// } catch (LifecycleManagementException e) { +// String msg = "Error occurred while deleting lifecycle state."; +// log.error(msg, e); +// return Response.status(Response.Status.BAD_REQUEST).build(); +// } +// return Response.status(Response.Status.OK).entity("Lifecycle state deleted successfully.").build(); } // @PUT diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java index ced7976b48..0f824e3ea2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java @@ -21,24 +21,13 @@ package org.wso2.carbon.device.application.mgt.store.api; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -<<<<<<< HEAD:components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java -import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse; -======= -import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; ->>>>>>> de78869eeae15c1d3bfe854092cbbb05be87c4a9:components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; -import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; -<<<<<<< HEAD:components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; -======= ->>>>>>> de78869eeae15c1d3bfe854092cbbb05be87c4a9:components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; -import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; -import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; +import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse; import javax.ws.rs.core.Response; @@ -49,16 +38,12 @@ public class APIUtil { private static Log log = LogFactory.getLog(APIUtil.class); -<<<<<<< HEAD:components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java private static ApplicationManager applicationManager; private static LifecycleStateManager lifecycleStateManager; private static ApplicationReleaseManager applicationReleaseManager; private static ApplicationStorageManager applicationStorageManager; private static SubscriptionManager subscriptionManager; - private static CategoryManager categoryManager; -======= ->>>>>>> de78869eeae15c1d3bfe854092cbbb05be87c4a9:components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java public static ApplicationManager getApplicationManager() { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ApplicationManager applicationManager = (ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null); @@ -70,20 +55,6 @@ public class APIUtil { return applicationManager; } -<<<<<<< HEAD:components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java -======= - public static PlatformManager getPlatformManager() { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - PlatformManager platformManager = (PlatformManager) ctx.getOSGiService(PlatformManager.class, null); - if (platformManager == null) { - String msg = "Platform Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - return platformManager; - } - ->>>>>>> de78869eeae15c1d3bfe854092cbbb05be87c4a9:components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java public static LifecycleStateManager getLifecycleStateManager() { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); LifecycleStateManager lifecycleStateManager = (LifecycleStateManager) ctx @@ -130,55 +101,6 @@ public class APIUtil { return applicationStorageManager; } - /** -<<<<<<< HEAD:components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java -======= - * To get the Platform Storage Manager from the osgi context. - * - * @return PlatformStoreManager instance in the current osgi context. - */ - public static PlatformStorageManager getPlatformStorageManager() { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - PlatformStorageManager platformStorageManager = (PlatformStorageManager) ctx - .getOSGiService(PlatformStorageManager.class, null); - if (platformStorageManager == null) { - String msg = "Platform Storage Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - return platformStorageManager; - } - - /** ->>>>>>> de78869eeae15c1d3bfe854092cbbb05be87c4a9:components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java - * To get the Category Manager from the osgi context. - * - * @return CategoryManager instance in the current osgi context. - */ - public static CategoryManager getCategoryManager() { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - CategoryManager categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null); - if (categoryManager == null) { - String msg = "Category Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - return categoryManager; - } - - public static Response getResponse(Exception ex, Response.Status status) { - return getResponse(ex.getMessage(), status); - } - - public static Response getResponse(String message, Response.Status status) { - ErrorResponse errorMessage = new ErrorResponse(); - errorMessage.setMessage(message); - if (status == null) { - status = Response.Status.INTERNAL_SERVER_ERROR; - } - errorMessage.setCode(status.getStatusCode()); - return Response.status(status).entity(errorMessage).build(); - } /** * To get the Subscription Manager from the osgi context. @@ -213,4 +135,19 @@ public class APIUtil { } return commentsManager; } + + public static Response getResponse(Exception ex, Response.Status status) { + return getResponse(ex.getMessage(), status); + } + + public static Response getResponse(String message, Response.Status status) { + ErrorResponse errorMessage = new ErrorResponse(); + errorMessage.setMessage(message); + if (status == null) { + status = Response.Status.INTERNAL_SERVER_ERROR; + } + errorMessage.setCode(status.getStatusCode()); + return Response.status(status).entity(errorMessage).build(); + } + } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java index 055ce1ec7f..b3ec06d16b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java @@ -217,42 +217,6 @@ public interface ApplicationManagementAPI { @QueryParam("appName") String appName ); - - - - - @GET - @Path("/release-artifacts/{uuid}/{version}") - @Produces(MediaType.APPLICATION_OCTET_STREAM) - @Consumes(MediaType.MULTIPART_FORM_DATA) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_OCTET_STREAM, - httpMethod = "GET", - value = "Get an application release", - notes = "This will return the application release indicated by Application UUID and version", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application:get") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully retrieved the Application release.", - response = Attachment.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while releasing the application.", - response = ErrorResponse.class) - }) - Response getApplicationReleaseArtifacts( - @ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID, - @ApiParam(name = "Version", value = "Version of the Application release need to be retrieved", required = true) @PathParam("version") String version); - @GET @Path("/release/{uuid}") @Produces(MediaType.APPLICATION_JSON) @@ -284,38 +248,4 @@ public interface ApplicationManagementAPI { @ApiParam(name = "ID", value = "Identifier of the Application", required = true) @PathParam("uuid") String applicationUUID, @ApiParam(name = "version", value = "Version of the application", required = false) @QueryParam("version") String version); - @GET - @Path("/image-artifacts/{uuid}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "DELETE", - value = "Delete the releases of a particular applicaion", - notes = "This will delete the releases or specific release of an application", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application:get") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully deleted the Application release."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while deleting the release of a" - + "particular application.", - response = ErrorResponse.class) - }) - Response getApplicationImageArtifacts( - @ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID, - @ApiParam(name = "name", value = "Name of the artifact to be retrieved", required = true) @QueryParam("name") String name, - @ApiParam(name = "count", value = "Count of the screen-shot artifact to be retrieved", required = false) @QueryParam("count") int count); - - } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java index cf16547384..d4a2f2e3e4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java @@ -163,51 +163,4 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { // } } - //todo We must remove following methods - By DLPDS - @Override - @GET - @Produces(MediaType.APPLICATION_OCTET_STREAM) - @Path("/release-artifacts/{uuid}/{version}") - public Response getApplicationReleaseArtifacts(@PathParam("uuid") String applicationUUID, - @PathParam("version") String version) { - ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); - try { - InputStream binaryFile = applicationStorageManager.getReleasedArtifacts(applicationUUID, version); - FileStreamingOutput fileStreamingOutput = new FileStreamingOutput(binaryFile); - Response.ResponseBuilder response = Response.status(Response.Status.OK).entity(fileStreamingOutput); - response.header("Content-Disposition", "attachment; filename=\"" + version + "\""); - return response.build(); - } catch (ApplicationStorageManagementException e) { - log.error("Error while retrieving the binary file of the application release for the application UUID " + - applicationUUID + " and version " + version, e); - if (e.getMessage().contains("Binary file does not exist")) { - return APIUtil.getResponse(e, Response.Status.NOT_FOUND); - } else { - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); - } - } - } - - @Override - @GET - @Path("/image-artifacts/{uuid}") - @Produces(MediaType.APPLICATION_JSON) - public Response getApplicationImageArtifacts(@PathParam("uuid") String applicationUUID, - @QueryParam("name") String name, @QueryParam("count") int count) { - if (name == null || name.isEmpty()) { - return Response.status(Response.Status.BAD_REQUEST).entity("Name should not be null. Name is mandatory to" - + " retrieve the particular image artifact of the release").build(); - } - ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); - try { - ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(applicationUUID, name, count); - Response.ResponseBuilder response = Response.status(Response.Status.OK).entity(imageArtifact); - return response.build(); - } catch (ApplicationStorageManagementException e) { - log.error("Application Storage Management Exception while getting the image artifact " + name + " of " - + "the application with UUID " + applicationUUID, e); - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); - } - } - } diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/pom.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/pom.xml index c79cd8c49e..a1ee5c87f1 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/pom.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.api.feature/pom.xml @@ -41,7 +41,7 @@ maven-dependency-plugin - copy + publisher-copy package copy @@ -50,7 +50,7 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.device.application.mgt.api + org.wso2.carbon.device.application.mgt.publisher.api ${project.version} war @@ -58,7 +58,30 @@ ${project.build.directory}/maven-shared-archive-resources/webapps - api#application-mgt#v1.0.war + api#application-mgt-publisher#v1.0.war + + + + + + store-copy + package + + copy + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.application.mgt.store.api + + ${project.version} + war + true + + ${project.build.directory}/maven-shared-archive-resources/webapps + + api#application-mgt-store#v1.0.war