From fdac04dd3eec5d1f3bb2992ec67d584ebc631f4c Mon Sep 17 00:00:00 2001 From: lasantha Date: Sun, 4 Feb 2018 04:05:04 +0530 Subject: [PATCH] complete app release getting flow and fixed related bugs --- .../common/services/ApplicationManager.java | 13 +- .../services/ApplicationReleaseManager.java | 13 +- ...ager.java => UnrestrictedRoleManager.java} | 8 +- .../mgt/core/impl/ApplicationManagerImpl.java | 9 + .../impl/ApplicationReleaseManagerImpl.java | 5 +- .../impl/ApplicationStorageManagerImpl.java | 27 +- ....java => UnrestrictedRoleManagerImpl.java} | 19 +- .../mgt/core/internal/DataHolder.java | 12 +- .../mgt/core/internal/ServiceComponent.java | 8 +- .../core/util/ApplicationManagementUtil.java | 6 +- .../src/test/resources/application-mgt.xml | 2 +- .../mgt/publisher/api/APIUtil.java | 54 ++- .../services/ApplicationManagementAPI.java | 390 ------------------ .../ApplicationReleaseManagementAPI.java | 43 +- .../api/services/LifecycleManagementAPI.java | 89 +++- .../impl/ApplicationManagementAPIImpl.java | 336 +-------------- .../ApplicationReleaseManagementAPIImpl.java | 113 ++--- .../impl/LifecycleManagementAPIImpl.java | 58 +++ .../ApplicationReleaseManagementAPI.java | 206 +++++++++ .../ApplicationReleaseManagementAPIImpl.java | 127 ++++++ .../main/resources/conf/application-mgt.xml | 2 +- 21 files changed, 653 insertions(+), 887 deletions(-) rename components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/{VisibilityManager.java => UnrestrictedRoleManager.java} (87%) rename components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/{VisibilityManagerImpl.java => UnrestrictedRoleManagerImpl.java} (88%) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationReleaseManagementAPI.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationReleaseManagementAPIImpl.java 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 2e6f362e98..03bba4ba79 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 @@ -18,10 +18,7 @@ */ package org.wso2.carbon.device.application.mgt.common.services; -import org.wso2.carbon.device.application.mgt.common.Application; -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.LifecycleStateTransition; +import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; @@ -121,4 +118,12 @@ public interface ApplicationManager { * @throws ApplicationManagementException Application Management Exception. */ Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementException; + + /** + * To get Application with the given UUID. + * + * @return the boolean value, whether user has assigned unrestricted roles to access the application + * * @throws ApplicationManagementException Application Management Exception. + */ + Boolean isUserAllowable(List unrestrictedRoles, String userName) 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/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 c21d7bc957..a03d8050bb 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 @@ -51,14 +51,23 @@ public interface ApplicationReleaseManager { */ ApplicationRelease getRelease(String applicationUuid, String version, String releaseType) throws ApplicationManagementException; + /** + * To get the application release of the Application/ + * + * @param applicationUuid UUID of the Application. + * @return ApplicationRelease related with particular Application UUID and version. + * @throws ApplicationManagementException ApplicationManagementException + */ + ApplicationRelease getReleaseByUuid(String applicationUuid) throws ApplicationManagementException; + /** * To get all the releases of a particular Application. * - * @param applicationUuid UUID of the Application to get all the releases. + * @param applicationId ID of the Application to get all the releases. * @return the List of the Application releases related with the particular Application. * @throws ApplicationManagementException Application Management Exception. */ - List getReleases(String applicationUuid) throws ApplicationManagementException; + List getReleases(int applicationId) throws ApplicationManagementException; /** * To make a particular application release as the default / not default-one diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/UnrestrictedRoleManager.java similarity index 87% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/UnrestrictedRoleManager.java index 7a760854a4..93b7b3a0c9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/UnrestrictedRoleManager.java @@ -18,15 +18,18 @@ package org.wso2.carbon.device.application.mgt.common.services; +import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole; import org.wso2.carbon.device.application.mgt.common.Visibility; import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException; +import java.util.List; + /** * This interface manages all the operations related with Application Visibility. * This will be invoking the necessary backend calls for the data bases layer * and provide the functional implementation. */ -public interface VisibilityManager { +public interface UnrestrictedRoleManager { /** * Add (if there is no visibility configuration for the application) or @@ -42,9 +45,10 @@ public interface VisibilityManager { * Returns the Visibility configuration of the provided applicationUUID. * * @param applicationID The ID of the application + * @param tenantId tenant Id * @return Visibility configuration */ - Visibility get(int applicationID) throws VisibilityManagementException; + List getUnrestrictedRoles(int applicationID, int tenantId) throws VisibilityManagementException; /** * Remove the visibility configuration mapping for the provided application. 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 237bdf2756..0abfe97566 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 @@ -454,6 +454,15 @@ public class ApplicationManagerImpl implements ApplicationManager { } } + public Boolean isUserAllowable(List unrestrictedRoles, String userName) throws ApplicationManagementException{ + try { + return isRoleExists(unrestrictedRoles, userName); + } catch (UserStoreException e) { + throw new ApplicationManagementException("User-store exception while verifying whether user have assigned" + + "unrestricted roles or not"); } + } + + /** * To check whether current user is application owner or admin. 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 6ff9715fae..ea6b43e90f 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 @@ -83,9 +83,10 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager } @Override - public List getReleases(String applicationUuid) throws ApplicationManagementException { + public List getReleases(int applicationId) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - Application application = validateApplicationRelease(applicationUuid); + + Application application = validateApplication(applicationId); if (log.isDebugEnabled()) { log.debug("Request is received to retrieve all the releases related with the application " + application.toString()); 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 e05ab02004..e18afd3adf 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 @@ -31,6 +31,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; +import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.Constants; @@ -158,6 +159,7 @@ 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; @@ -181,6 +183,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager @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); @@ -193,6 +196,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager @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); @@ -205,6 +209,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager @Override public void deleteAllApplicationReleaseArtifacts(String applicationUUID) throws ApplicationStorageManagementException { + // todo this should be validate application release validateApplication(applicationUUID); try { List applicationReleases = DataHolder.getInstance().getApplicationReleaseManager() @@ -222,6 +227,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager @Override public ImageArtifact getImageArtifact(String applicationUUID, String name, int count) throws ApplicationStorageManagementException { + // todo this should be validate application release Application application = validateApplication(applicationUUID); validateImageArtifactNames(name); String imageArtifactPath = storagePath + application.getId() + File.separator + name.toLowerCase(); @@ -267,7 +273,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager * To validate the Application before storing and retrieving the artifacts of a particular application. * * @param appId ID of the Application - * @return {@link Application} if it is validated + * @return boolean if it is validated * @throws ApplicationStorageManagementException Application Storage Management Exception will be thrown if a * valid application related with the specific UUID * could not be found. @@ -284,6 +290,25 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager return isAppExist; } + /** + * To validate the pre-request of the ApplicationRelease. + * + * @param applicationUuid UUID of the Application. + * @return Application related with the UUID + */ + private ApplicationRelease validateApplicationRelease(String applicationUuid) throws ApplicationManagementException { + if (applicationUuid == null) { + throw new ApplicationManagementException("Application UUID is null. Application UUID is a required " + + "parameter to get the relevant application."); + } + ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager().getRelease(); + if (applicationRelease == null) { + throw new NotFoundException( + "Application with UUID " + applicationUuid + " does not exist."); + } + return applicationRelease; + } + private String getMD5(InputStream binaryFile) throws ApplicationStorageManagementException { String md5; try { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.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 similarity index 88% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/UnrestrictedRoleManagerImpl.java index 5ba26f74de..938cebc7c3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.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 @@ -17,18 +17,21 @@ */ package org.wso2.carbon.device.application.mgt.core.impl; +import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole; import org.wso2.carbon.device.application.mgt.common.Visibility; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException; -import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; +import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager; import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; +import java.util.List; + /** * This is the default implementation for the visibility manager. */ -public class VisibilityManagerImpl implements VisibilityManager { +public class UnrestrictedRoleManagerImpl implements UnrestrictedRoleManager { @Override public Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException { @@ -68,15 +71,13 @@ public class VisibilityManagerImpl implements VisibilityManager { } @Override - public Visibility get(int applicationID) throws VisibilityManagementException { + public List getUnrestrictedRoles(int applicationID, int tenantId) throws VisibilityManagementException { try { VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); - Visibility visibility = visibilityDAO.get(applicationID); - if (visibility.getType() == null && (visibility.getAllowedList() == null || - visibility.getAllowedList().isEmpty())) { - visibility.setType(Visibility.Type.PUBLIC); - } - return visibility; + List unrestrictedRoles = visibilityDAO.getUnrestrictedRoles(applicationID, tenantId); + if (unrestrictedRoles == null) + return null; + return unrestrictedRoles; } catch (ApplicationManagementException e) { throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - " + applicationID, e); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java index c9ed93e864..8088293c28 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java @@ -24,7 +24,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; -import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; +import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.user.core.service.RealmService; @@ -47,7 +47,7 @@ public class DataHolder { private SubscriptionManager subscriptionManager; - private VisibilityManager visibilityManager; + private UnrestrictedRoleManager unrestrictedRoleManager; private ApplicationStorageManager applicationStorageManager; @@ -109,12 +109,12 @@ public class DataHolder { this.subscriptionManager = subscriptionManager; } - public VisibilityManager getVisibilityManager() { - return visibilityManager; + public UnrestrictedRoleManager getVisibilityManager() { + return unrestrictedRoleManager; } - public void setVisibilityManager(VisibilityManager visibilityManager) { - this.visibilityManager = visibilityManager; + public void setVisibilityManager(UnrestrictedRoleManager unrestrictedRoleManager) { + this.unrestrictedRoleManager = unrestrictedRoleManager; } public RealmService getRealmService() { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java index b27df7f626..c7a7ad0317 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java @@ -29,7 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; -import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; +import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; @@ -93,9 +93,9 @@ public class ServiceComponent { DataHolder.getInstance().setSubscriptionManager(subscriptionManager); bundleContext.registerService(SubscriptionManager.class.getName(), subscriptionManager, null); - VisibilityManager visibilityManager = ApplicationManagementUtil.getVisibilityManagerInstance(); - DataHolder.getInstance().setVisibilityManager(visibilityManager); - bundleContext.registerService(VisibilityManager.class.getName(), visibilityManager, null); + UnrestrictedRoleManager unrestrictedRoleManager = ApplicationManagementUtil.getVisibilityManagerInstance(); + DataHolder.getInstance().setVisibilityManager(unrestrictedRoleManager); + bundleContext.registerService(UnrestrictedRoleManager.class.getName(), unrestrictedRoleManager, null); ApplicationStorageManager applicationStorageManager = ApplicationManagementUtil .getApplicationStorageManagerInstance(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java index ea682c44b3..72f2407dcb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java @@ -27,7 +27,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; -import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; +import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.Extension; @@ -66,10 +66,10 @@ public class ApplicationManagementUtil { return getInstance(extension, LifecycleStateManager.class); } - public static VisibilityManager getVisibilityManagerInstance() throws InvalidConfigurationException { + public static UnrestrictedRoleManager getVisibilityManagerInstance() throws InvalidConfigurationException { ConfigurationManager configurationManager = ConfigurationManager.getInstance(); Extension extension = configurationManager.getExtension(Extension.Name.VisibilityManager); - return getInstance(extension, VisibilityManager.class); + return getInstance(extension, UnrestrictedRoleManager.class); } public static SubscriptionManager getSubscriptionManagerInstance() throws InvalidConfigurationException { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml index 618a2093b9..974cd4df3a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/application-mgt.xml @@ -51,7 +51,7 @@ org.wso2.carbon.device.application.mgt.core.impl.SubscriptionManagerImpl - org.wso2.carbon.device.application.mgt.core.impl.VisibilityManagerImpl + org.wso2.carbon.device.application.mgt.core.impl.UnrestrictedRoleManagerImpl org.wso2.carbon.device.application.mgt.core.impl.VisibilityTypeManagerImpl 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/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/APIUtil.java index ce4ee92588..0e399d2d07 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/APIUtil.java @@ -21,12 +21,8 @@ package org.wso2.carbon.device.application.mgt.publisher.api; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.application.mgt.common.services.*; import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import javax.ws.rs.core.Response; @@ -43,7 +39,8 @@ public class APIUtil { private static ApplicationReleaseManager applicationReleaseManager; private static ApplicationStorageManager applicationStorageManager; private static SubscriptionManager subscriptionManager; - private static CategoryManager categoryManager; + private static UnrestrictedRoleManager unrestrictedRoleManager; + public static ApplicationManager getApplicationManager() { if (applicationManager == null) { @@ -127,28 +124,6 @@ public class APIUtil { return applicationStorageManager; } - /** - * To get the Category Manager from the osgi context. - * - * @return CategoryManager instance in the current osgi context. - */ - public static CategoryManager getCategoryManager() { - if (categoryManager == null) { - synchronized (APIUtil.class) { - if (categoryManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - 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); } @@ -185,4 +160,27 @@ public class APIUtil { return subscriptionManager; } + + /** + * To get the Unrestricted Role manager from the osgi context. + * @return Unrestricted Role manager instance in the current osgi context. + */ + public static UnrestrictedRoleManager getUnrestrictedRoleManager() { + if (unrestrictedRoleManager == null) { + synchronized (APIUtil.class) { + if (unrestrictedRoleManager == null) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + unrestrictedRoleManager = + (UnrestrictedRoleManager) ctx.getOSGiService(UnrestrictedRoleManager.class, null); + if (unrestrictedRoleManager == null) { + String msg = "Subscription Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + } + } + } + + return unrestrictedRoleManager; + } } 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/ApplicationManagementAPI.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/ApplicationManagementAPI.java index 4302402396..409124752c 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/ApplicationManagementAPI.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/ApplicationManagementAPI.java @@ -289,156 +289,6 @@ public interface ApplicationManagementAPI { required = true) @Valid Application application); - - @POST - @Path("/upload-artifacts/{uuid}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.MULTIPART_FORM_DATA) - @ApiOperation( - consumes = MediaType.MULTIPART_FORM_DATA, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Upload artifacts", - notes = "This will create a new application", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application:create") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 201, - message = "OK. \n Successfully uploaded artifacts."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while getting the application list.", - response = ErrorResponse.class) - }) - Response uploadApplicationArtifacts( - @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}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.MULTIPART_FORM_DATA) - @ApiOperation( - consumes = MediaType.MULTIPART_FORM_DATA, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Upload artifacts", - notes = "This will create a new application", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application:create") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 201, - message = "OK. \n Successfully uploaded artifacts."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while getting the application list.", - response = ErrorResponse.class) - }) - Response updateApplicationArtifacts( - @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); - - - - @PUT - @Consumes("application/json") - @Path("/{uuid}/lifecycle") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "PUT", - value = "Change the life cycle state of the application", - notes = "This will change the life-cycle state of the application", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application-mgt:login") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully changed application state."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while getting the application list.", - response = ErrorResponse.class) - }) - Response changeLifecycleState( - @ApiParam( - name = "UUID", - value = "Unique identifier of the Application", - required = true) - @PathParam("uuid") String applicationUUID, - @ApiParam( - name = "state", - value = "Lifecycle State that need to be changed to", - required = true) - @QueryParam("state") String state); - - @GET - @Consumes("application/json") - @Path("/{uuid}/lifecycle") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Change the life cycle state of the application", - notes = "This will retrieve the next life cycle states of the application based on the user and the " - + "current state", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application-mgt:login") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully retrieved the lifecycle states.", - response = List.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while getting the life-cycle states.", - response = ErrorResponse.class) - }) - Response getNextLifeCycleStates( - @ApiParam( - name = "UUID", - value = "Unique identifier of the Application", - required = true) - @PathParam("uuid") String applicationUUID); - @DELETE @Consumes("application/json") @Path("/{appuuid}") @@ -473,246 +323,6 @@ public interface ApplicationManagementAPI { required = true) @PathParam("appuuid") String applicationUUID); - @POST - @Path("/release/{uuid}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.MULTIPART_FORM_DATA) - @ApiOperation( - consumes = MediaType.MULTIPART_FORM_DATA, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Create an application release", - notes = "This will create a new application release", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application:create") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 201, - message = "OK. \n Successfully created an application release.", - response = ApplicationRelease.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while releasing the application.", - response = ErrorResponse.class) - }) - - Response createApplicationRelease( - @ApiParam( - name = "UUID", - value = "Unique identifier of the Application", - required = true) - @PathParam("uuid") String applicationUUID, - @Multipart(value = "applicationRelease", type = "application/json") ApplicationRelease applicationRelease, - @Multipart(value = "binaryFile") Attachment binaryFile); - - @PUT - @Path("/release/{uuid}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.MULTIPART_FORM_DATA) - @ApiOperation( - consumes = MediaType.MULTIPART_FORM_DATA, - produces = MediaType.APPLICATION_JSON, - httpMethod = "PUT", - value = "Update an application release", - notes = "This will update a new application release", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application:update") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 201, - message = "OK. \n Successfully created an application release.", - response = ApplicationRelease.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while releasing the application.", - response = ErrorResponse.class) - }) - - Response updateApplicationRelease( - @ApiParam( - name = "UUID", - value = "Unique identifier of the Application", - required = true) - @PathParam("uuid") String applicationUUID, - @Multipart(value = "applicationRelease", required = false, type = "application/json") - ApplicationRelease applicationRelease, - @Multipart(value = "binaryFile", required = false) Attachment binaryFile); - - @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) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Get all the releases or specific release of an application", - notes = "This will retrieve the all 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 retrieved the Application release."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while releasing the application.", - response = ErrorResponse.class) - }) - Response getApplicationReleases( - @ApiParam( - name = "UUID", - value = "Unique identifier of the Application", - required = true) - @PathParam("uuid") String applicationUUID, - @ApiParam( - name = "version", - value = "Version of the application", - required = false) - @QueryParam("version") String version); - - @DELETE - @Path("/release/{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:delete") - }) - } - ) - @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 deleteApplicationRelease( - @ApiParam( - name = "UUID", - value = "Unique identifier of the Application", - required = true) - @PathParam("uuid") String applicationUUID, - @ApiParam( - name = "version", - value = "Version of the application") - @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); - @PUT @Consumes("application/json") @Path("/{uuid}/{version}/{channel}") 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 9d7e53fad3..75fcbe51eb 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 @@ -232,40 +232,6 @@ public interface ApplicationReleaseManagementAPI { @Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart(value = "screenshot", required = false) List screenshots); - @POST - @Path("/release/{uuid}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.MULTIPART_FORM_DATA) - @ApiOperation( - consumes = MediaType.MULTIPART_FORM_DATA, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Create an application release", - notes = "This will create a new application release", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application:create") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 201, - message = "OK. \n Successfully created an application release.", - response = ApplicationRelease.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while releasing the application.", - response = ErrorResponse.class) - }) - - Response createApplicationRelease( - @ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID, - @Multipart(value = "applicationRelease", type = "application/json") ApplicationRelease applicationRelease, - @Multipart(value = "binaryFile") Attachment binaryFile); - @PUT @Path("/release/{uuid}") @Produces(MediaType.APPLICATION_JSON) @@ -333,7 +299,7 @@ public interface ApplicationReleaseManagementAPI { @ApiParam(name = "Version", value = "Version of the Application release need to be retrieved", required = true) @PathParam("version") String version); @GET - @Path("/release/{uuid}") + @Path("/{appId}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( @@ -359,9 +325,8 @@ public interface ApplicationReleaseManagementAPI { message = "Internal Server Error. \n Error occurred while releasing the application.", response = ErrorResponse.class) }) - Response getApplicationReleases( - @ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID, - @ApiParam(name = "version", value = "Version of the application", required = false) @QueryParam("version") String version); + Response getApplicationReleases(@ApiParam(name = "appId", value = "Unique identifier of the Application", + required = true) @PathParam("appId") int applicationId); @DELETE @Path("/release/{uuid}") @@ -384,7 +349,7 @@ public interface ApplicationReleaseManagementAPI { value = { @ApiResponse( code = 200, - message = "OK. \n Successfully deleted the Application release."), + message = "OK. \nI Successfully deleted the Application release."), @ApiResponse( code = 500, message = "Internal Server Error. \n Error occurred while deleting the release of a" 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/LifecycleManagementAPI.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/LifecycleManagementAPI.java index a4ffd41010..274b07777c 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/LifecycleManagementAPI.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/LifecycleManagementAPI.java @@ -17,15 +17,7 @@ */ package org.wso2.carbon.device.application.mgt.publisher.api.services; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.Info; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Tag; +import io.swagger.annotations.*; import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse; @@ -33,11 +25,7 @@ import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.LifecycleState; import java.util.List; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -177,4 +165,77 @@ public interface LifecycleManagementAPI { response = ErrorResponse.class) }) Response deleteLifecycleState(@PathParam("identifier") String identifier); + + @PUT + @Consumes("application/json") + @Path("/{uuid}/lifecycle") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Change the life cycle state of the application", + notes = "This will change the life-cycle state of the application", + tags = "Application Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:application-mgt:login") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully changed application state."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the application list.", + response = ErrorResponse.class) + }) + Response changeLifecycleState( + @ApiParam( + name = "UUID", + value = "Unique identifier of the Application", + required = true) + @PathParam("uuid") String applicationUUID, + @ApiParam( + name = "state", + value = "Lifecycle State that need to be changed to", + required = true) + @QueryParam("state") String state); + + @GET + @Consumes("application/json") + @Path("/{uuid}/lifecycle") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Change the life cycle state of the application", + notes = "This will retrieve the next life cycle states of the application based on the user and the " + + "current state", + tags = "Application Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:application-mgt:login") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully retrieved the lifecycle states.", + response = List.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the life-cycle states.", + response = ErrorResponse.class) + }) + Response getNextLifeCycleStates( + @ApiParam( + name = "UUID", + value = "Unique identifier of the Application", + required = true) + @PathParam("uuid") String applicationUUID); } 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 dadddad75a..2a398de8f4 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 @@ -91,10 +91,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { ApplicationList applications = applicationManager.getApplications(filter); for (Application application : applications.getApplications()) { -// ToDo : use better approach to solve this String uuId = applicationManager.getUuidOfLatestRelease(application.getId()); if (uuId != null){ - application.setUuidOfLatestRelease(uuId); ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(uuId, Constants.IMAGE_ARTIFACTS[0], 0); application.setIconOfLatestRelease(imageArtifact); }else{ @@ -127,10 +125,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { .entity("Application with UUID " + appType + " not found").build(); } - // ToDo : use better approach to solve this String uuId = applicationManager.getUuidOfLatestRelease(application.getId()); if (uuId != null){ - application.setUuidOfLatestRelease(uuId); ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(uuId, Constants.IMAGE_ARTIFACTS[0], 0); application.setIconOfLatestRelease(imageArtifact); }else{ @@ -175,6 +171,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } + //Todo Not complete @PUT @Consumes("application/json") public Response editApplication(@Valid Application application) { @@ -184,13 +181,14 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } catch (NotFoundException e) { return APIUtil.getResponse(e, Response.Status.NOT_FOUND); } catch (ApplicationManagementException e) { - String msg = "Error occurred while creating the application"; + String msg = "Error occurred while modifying the application"; log.error(msg, e); return APIUtil.getResponse(e, Response.Status.BAD_REQUEST); } return Response.status(Response.Status.OK).entity(application).build(); } + //todo this need to be rethink and fix --- > This is somthing change lifecycle @DELETE @Path("/{appuuid}") public Response deleteApplication(@PathParam("appuuid") String uuid) { @@ -215,333 +213,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } } -// ToDo - - @PUT - @Consumes("application/json") - @Path("/{uuid}/lifecycle") - public Response changeLifecycleState(@PathParam("uuid") String applicationUUID, @QueryParam("state") String state) { - ApplicationManager applicationManager = APIUtil.getApplicationManager(); - - if (!Arrays.asList(Constants.LIFE_CYCLES).contains(state)) { - log.warn("Provided lifecycle state " + state + " is not valid. Please select one from" - + Arrays.toString(Constants.LIFE_CYCLES)); - return Response.status(Response.Status.BAD_REQUEST) - .entity("Provided lifecycle state " + state + " is not valid. Please select one from " - + Arrays.toString(Constants.LIFE_CYCLES)).build(); - } - try { - applicationManager.changeLifecycle(applicationUUID, state); - return Response.status(Response.Status.OK) - .entity("Successfully changed the lifecycle state of the application: " + applicationUUID).build(); - } catch (NotFoundException e) { - return Response.status(Response.Status.NOT_FOUND).build(); - } catch (ApplicationManagementException e) { - String msg = "Error occurred while changing the lifecycle of application: " + applicationUUID; - log.error(msg, e); - return APIUtil.getResponse(e, Response.Status.BAD_REQUEST); - } - } - - @GET - @Path("/{uuid}/lifecycle") - @Override - public Response getNextLifeCycleStates(@PathParam("uuid") String applicationUUID) { - ApplicationManager applicationManager = APIUtil.getApplicationManager(); - try { - if (applicationManager.getApplication(applicationUUID) == null) { - if (log.isDebugEnabled()) { - log.debug("Application with the UUID '" + applicationUUID + "' is not found."); - } - return Response.status(Response.Status.NOT_FOUND).entity("Application with the UUID '" + - applicationUUID + "' is not found.").build(); - } - - if (log.isDebugEnabled()) { - log.debug("Application with UUID '" + applicationUUID + "' is found. Request received for getting " - + "next life-cycle states for the particular application."); - } - return Response.status(Response.Status.OK).entity(applicationManager.getLifeCycleStates(applicationUUID)) - .build(); - } catch (NotFoundException e) { - return Response.status(Response.Status.NOT_FOUND).build(); - } catch (ApplicationManagementException e) { - log.error("Application Management Exception while trying to get next states for the applications with " - + "the application ID", e); - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); - } - } - - @Override - @POST - @Path("/upload-image-artifacts/{uuid}") - public Response uploadApplicationArtifacts(@PathParam("uuid") String applicationUUID, - @Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, - @Multipart("screenshot") List attachmentList) { - ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); - try { - InputStream iconFileStream; - InputStream bannerFileStream; - 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); - return Response.status(Response.Status.OK) - .entity("Successfully uploaded artifacts for the application " + applicationUUID).build(); - } catch (NotFoundException e) { - return Response.status(Response.Status.NOT_FOUND).build(); - } catch (ApplicationManagementException e) { - String msg = "Error occurred while creating the application"; - log.error(msg, e); - return APIUtil.getResponse(e, Response.Status.BAD_REQUEST); - } catch (IOException e) { - log.error("Exception while trying to read icon, banner files for the application " + applicationUUID); - return APIUtil.getResponse(new ApplicationManagementException( - "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); - } - } - - @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) { - ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); - 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()); - } - } - applicationStorageManager - .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments); - return Response.status(Response.Status.OK) - .entity("Successfully updated artifacts for the application " + applicationUUID).build(); - } catch (IOException e) { - log.error("Exception while trying to read icon, banner files for the application " + applicationUUID); - return APIUtil.getResponse(new ApplicationManagementException( - "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); - } - } - - - @Override - @POST - @Path("/release/{uuid}") - public Response createApplicationRelease(@PathParam("uuid") String applicationUUID, - @Multipart("applicationRelease") ApplicationRelease applicationRelease, - @Multipart("binaryFile") Attachment binaryFile) { - ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); - ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); - try { - applicationRelease = applicationReleaseManager.createRelease(applicationUUID, applicationRelease); - - if (binaryFile != null) { - applicationStorageManager.uploadReleaseArtifacts(applicationUUID, applicationRelease.getVersion(), - binaryFile.getDataHandler().getInputStream()); - } - return Response.status(Response.Status.CREATED).entity(applicationRelease).build(); - } catch (ApplicationManagementException e) { - log.error("Error while creating an application release for the application with UUID " + applicationUUID, - e); - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); - } catch (IOException e) { - String errorMessage = - "Error while uploading binary file for the application release of the application with UUID " - + applicationUUID; - log.error(errorMessage, e); - return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e), - Response.Status.INTERNAL_SERVER_ERROR); - } catch (ResourceManagementException e) { - log.error("Error occurred while uploading 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); - } - } - - @Override - @PUT - @Path("/release/{uuid}") - public Response updateApplicationRelease(@PathParam("uuid") String applicationUUID, @Multipart - ("applicationRelease") ApplicationRelease applicationRelease, @Multipart("binaryFile") Attachment - binaryFile) { - ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); - ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); - try { - if (applicationRelease != null) { - applicationRelease = applicationReleaseManager.updateRelease(applicationUUID, applicationRelease); - } - if (binaryFile != null) { - String version = applicationRelease == null ? null : applicationRelease.getVersion(); - - if (version == null) { - return Response.status(Response.Status.BAD_REQUEST).entity("Version cannot be null. Version is a " - + "mandatory parameter to update the release artifacts").build(); - } - applicationStorageManager - .uploadReleaseArtifacts(applicationUUID, version, binaryFile.getDataHandler().getInputStream()); - } - return Response.status(Response.Status.OK).entity(applicationRelease).build(); - } catch (NotFoundException e) { - return Response.status(Response.Status.NOT_FOUND).build(); - } catch (ApplicationManagementException e) { - 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); - } - } - - @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 - @Path("/release/{uuid}") - @GET - public Response getApplicationReleases(@PathParam("uuid") String applicationUUID, - @QueryParam("version") String version) { - ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); - try { - if (version == null || version.isEmpty()) { - List applicationReleases = applicationReleaseManager.getReleases(applicationUUID); - return Response.status(Response.Status.OK).entity(applicationReleases).build(); - } else { - ApplicationRelease applicationRelease = applicationReleaseManager.getRelease(applicationUUID, version); - return Response.status(Response.Status.OK).entity(applicationRelease).build(); - } - } catch (NotFoundException e) { - return Response.status(Response.Status.NOT_FOUND).build(); - } catch (ApplicationManagementException e) { - log.error("Error while getting all the application releases for the application with the UUID " - + applicationUUID, e); - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); - } - } - - @Override - @DELETE - @Path("/release/{uuid}") - public Response deleteApplicationRelease(@PathParam("uuid") String applicationUUID, - @QueryParam("version") String version) { - ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); - ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); - try { - if (version != null && !version.isEmpty()) { - applicationStorageManager.deleteApplicationReleaseArtifacts(applicationUUID, version); - applicationReleaseManager.deleteApplicationRelease(applicationUUID, version); - return Response.status(Response.Status.OK) - .entity("Successfully deleted Application release with " + "version " + version - + " for the application with UUID " + applicationUUID).build(); - } else { - applicationStorageManager.deleteAllApplicationReleaseArtifacts(applicationUUID); - applicationReleaseManager.deleteApplicationReleases(applicationUUID); - return Response.status(Response.Status.OK) - .entity("Successfully deleted Application releases for the " + "application with UUID " - + applicationUUID).build(); - } - } catch (NotFoundException e) { - return Response.status(Response.Status.NOT_FOUND).build(); - } catch (ApplicationManagementException e) { - log.error("Error while deleting application release with the application UUID " + applicationUUID, e); - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); - } catch (ApplicationStorageManagementException e) { - log.error("Error occurred while deleting the releases artifacts of the application with the uuid " - + applicationUUID + " for the release " + version, e); - 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); - } - } - + // todo I think we must remove this @Override @PUT @Consumes("application/json") 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 a34f57f6df..3d4c3a3651 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 @@ -22,12 +22,15 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil; import org.wso2.carbon.device.application.mgt.publisher.api.FileStreamingOutput; @@ -107,6 +110,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa applicationRelease.setUuid(UUID.randomUUID().toString()); applicationRelease = applicationReleaseManager.createRelease(applicationId, applicationRelease); + //Todo insert lifecycle into lifecycle table return Response.status(Response.Status.CREATED).entity(applicationRelease).build(); @@ -128,6 +132,35 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa } } + @Override + @Path("/{appId}") + @GET + public Response getApplicationReleases(@PathParam("appId") int applicationId){ + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); + UnrestrictedRoleManager unrestrictedRoleManager = APIUtil.getUnrestrictedRoleManager(); + ApplicationManager applicationManager = APIUtil.getApplicationManager(); + List applicationReleases; + try { + List unrestrictedRoles = unrestrictedRoleManager.getUnrestrictedRoles(applicationId, tenantId); + if(applicationManager.isUserAllowable(unrestrictedRoles,userName)){ + applicationReleases= applicationReleaseManager.getReleases(applicationId); + return Response.status(Response.Status.OK).entity(applicationReleases).build(); + + } + return Response.status(Response.Status.UNAUTHORIZED).build(); + + } catch (NotFoundException e) { + return Response.status(Response.Status.NOT_FOUND).build(); + } catch (ApplicationManagementException e) { + log.error("Error while getting all the application releases for the application with the id " + + applicationId, e); + return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + } + + //todo I think we can remove this DLPDS or this has to be update Image artifacts not upload application artifact @Override @POST @Path("/upload-image-artifacts/{uuid}") @@ -160,8 +193,8 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa throw new ApplicationManagementException( "Screen-shot are not uploaded for the application " + applicationUUID); } - applicationStorageManager - .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments); +// applicationStorageManager +// .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments); return Response.status(Response.Status.OK) .entity("Successfully uploaded artifacts for the application " + applicationUUID).build(); } catch (NotFoundException e) { @@ -175,11 +208,12 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa return APIUtil.getResponse(new ApplicationManagementException( "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); +// } } @Override @@ -205,8 +239,8 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa attachments.add(screenshot.getDataHandler().getInputStream()); } } - applicationStorageManager - .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments); +// applicationStorageManager +// .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments); return Response.status(Response.Status.OK) .entity("Successfully updated artifacts for the application " + applicationUUID).build(); } catch (IOException e) { @@ -214,16 +248,14 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa return APIUtil.getResponse(new ApplicationManagementException( "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); +// } } - - - @Override @PUT @Path("/release/{uuid}") @@ -243,8 +275,8 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa return Response.status(Response.Status.BAD_REQUEST).entity("Version cannot be null. Version is a " + "mandatory parameter to update the release artifacts").build(); } - applicationStorageManager - .uploadReleaseArtifacts(applicationUUID, version, binaryFile.getDataHandler().getInputStream()); +// applicationStorageManager +// .uploadReleaseArtifacts(applicationUUID, version, binaryFile.getDataHandler().getInputStream()); } return Response.status(Response.Status.OK).entity(applicationRelease).build(); } catch (NotFoundException e) { @@ -252,18 +284,21 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa } catch (ApplicationManagementException e) { 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 I think we must remove this DLPDS @Override @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @@ -288,28 +323,6 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa } } - @Override - @Path("/release/{uuid}") - @GET - public Response getApplicationReleases(@PathParam("uuid") String applicationUUID, - @QueryParam("version") String version) { - ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); - try { - if (version == null || version.isEmpty()) { - List applicationReleases = applicationReleaseManager.getReleases(applicationUUID); - return Response.status(Response.Status.OK).entity(applicationReleases).build(); - } else { - ApplicationRelease applicationRelease = applicationReleaseManager.getRelease(applicationUUID, version); - return Response.status(Response.Status.OK).entity(applicationRelease).build(); - } - } catch (NotFoundException e) { - return Response.status(Response.Status.NOT_FOUND).build(); - } catch (ApplicationManagementException e) { - log.error("Error while getting all the application releases for the application with the UUID " - + applicationUUID, e); - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); - } - } @Override @DELETE @@ -321,7 +334,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa try { if (version != null && !version.isEmpty()) { applicationStorageManager.deleteApplicationReleaseArtifacts(applicationUUID, version); - applicationReleaseManager.deleteApplicationRelease(applicationUUID, version); +// applicationReleaseManager.deleteApplicationRelease(applicationUUID, version); return Response.status(Response.Status.OK) .entity("Successfully deleted Application release with " + "version " + version + " for the application with UUID " + applicationUUID).build(); @@ -344,6 +357,8 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa } } + //todo I think we must remove this DLPDS + @Override @GET @Path("/image-artifacts/{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 600c49210d..7b297fd336 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 @@ -138,4 +138,62 @@ public class LifecycleManagementAPIImpl implements LifecycleManagementAPI { // return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); // } // } + + // ToDo + + @PUT + @Consumes("application/json") + @Path("/{uuid}/lifecycle") + public Response changeLifecycleState(@PathParam("uuid") String applicationUUID, @QueryParam("state") String state) { + ApplicationManager applicationManager = APIUtil.getApplicationManager(); + + if (!Arrays.asList(Constants.LIFE_CYCLES).contains(state)) { + log.warn("Provided lifecycle state " + state + " is not valid. Please select one from" + + Arrays.toString(Constants.LIFE_CYCLES)); + return Response.status(Response.Status.BAD_REQUEST) + .entity("Provided lifecycle state " + state + " is not valid. Please select one from " + + Arrays.toString(Constants.LIFE_CYCLES)).build(); + } + try { + applicationManager.changeLifecycle(applicationUUID, state); + return Response.status(Response.Status.OK) + .entity("Successfully changed the lifecycle state of the application: " + applicationUUID).build(); + } catch (NotFoundException e) { + return Response.status(Response.Status.NOT_FOUND).build(); + } catch (ApplicationManagementException e) { + String msg = "Error occurred while changing the lifecycle of application: " + applicationUUID; + log.error(msg, e); + return APIUtil.getResponse(e, Response.Status.BAD_REQUEST); + } + } + + @GET + @Path("/{uuid}/lifecycle") + @Override + public Response getNextLifeCycleStates(@PathParam("uuid") String applicationUUID) { + ApplicationManager applicationManager = APIUtil.getApplicationManager(); + try { +// if (applicationManager.getApplication(applicationUUID) == null) { +// if (log.isDebugEnabled()) { +// log.debug("Application with the UUID '" + applicationUUID + "' is not found."); +// } +// return Response.status(Response.Status.NOT_FOUND).entity("Application with the UUID '" + +// applicationUUID + "' is not found.").build(); +// } + + if (log.isDebugEnabled()) { + log.debug("Application with UUID '" + applicationUUID + "' is found. Request received for getting " + + "next life-cycle states for the particular application."); + } + return Response.status(Response.Status.OK).entity(applicationManager.getLifeCycleStates(applicationUUID)) + .build(); + } catch (NotFoundException e) { + return Response.status(Response.Status.NOT_FOUND).build(); + } catch (ApplicationManagementException e) { + log.error("Application Management Exception while trying to get next states for the applications with " + + "the application ID", e); + return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + } + } + } 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/ApplicationReleaseManagementAPI.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/ApplicationReleaseManagementAPI.java new file mode 100644 index 0000000000..911c9488c6 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationReleaseManagementAPI.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.application.mgt.store.api.services; + +import io.swagger.annotations.*; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; +import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +/** + * APIs to handle application management related tasks. + */ +@SwaggerDefinition( + info = @Info( + version = "1.0.0", + title = "Application Management Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "ApplicationManagementService"), + @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/applications"), + }) + } + ), + tags = { + @Tag(name = "application_management, device_management", description = "Application Management related " + + "APIs") + } +) +@Scopes( + scopes = { + @Scope( + name = "Get Application Details", + description = "Get application details", + key = "perm:application:get", + permissions = {"/device-mgt/application/get"} + ), + @Scope( + name = "Create an Application", + description = "Create an application", + key = "perm:application:create", + permissions = {"/device-mgt/application/create"} + ), + @Scope( + name = "Update an Application", + description = "Update an application", + key = "perm:application:update", + permissions = {"/device-mgt/application/update"} + ), + @Scope( + name = "Create an Application", + description = "Create an application", + key = "perm:application-mgt:login", + permissions = {"/device-mgt/application-mgt/login"} + ), + @Scope( + name = "Delete an Application", + description = "Delete an application", + key = "perm:application:delete", + permissions = {"/device-mgt/application/delete"} + ), + @Scope( + name = "Create an application category", + description = "Create an application category", + key = "perm:application-category:create", + permissions = {"/device-mgt/application/category/create"} + ), + @Scope( + name = "Delete an Application category", + description = "Delete an application category", + key = "perm:application-category:delete", + permissions = {"/device-mgt/application/category/delete"} + ) + + + } +) +@Path("/publisher/release") +@Api(value = "Application Management", description = "This API carries all application management related operations " + + "such as get all the applications, add application, etc.") +@Produces(MediaType.APPLICATION_JSON) +public interface ApplicationReleaseManagementAPI { + + + String SCOPE = "scope"; + + @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) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Get all the releases or specific release of an application", + notes = "This will retrieve the all 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 retrieved the Application release."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while releasing the application.", + response = ErrorResponse.class) + }) + Response getApplicationReleasesById( + @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/ApplicationReleaseManagementAPIImpl.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/ApplicationReleaseManagementAPIImpl.java new file mode 100644 index 0000000000..a9e1eec247 --- /dev/null +++ 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/ApplicationReleaseManagementAPIImpl.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.application.mgt.store.api.services.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; +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; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; +import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; +import org.wso2.carbon.device.application.mgt.store.api.APIUtil; +import org.wso2.carbon.device.application.mgt.store.api.FileStreamingOutput; +import org.wso2.carbon.device.application.mgt.store.api.services.ApplicationReleaseManagementAPI; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * Implementation of Application Management related APIs. + */ +@Produces({"application/json"}) +@Path("/publisher/release") +public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseManagementAPI { + + private static final int DEFAULT_LIMIT = 20; + private static Log log = LogFactory.getLog(ApplicationReleaseManagementAPIImpl.class); + + + @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 + @Path("/release/{uuid}") + @GET + public Response getApplicationReleasesById(@PathParam("uuid") String applicationUUID, + @QueryParam("version") String version) { + ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); + try { + if (version == null || version.isEmpty()) { + List applicationReleases = applicationReleaseManager.getReleases(applicationUUID); + return Response.status(Response.Status.OK).entity(applicationReleases).build(); + } else { + ApplicationRelease applicationRelease = applicationReleaseManager.getRelease(applicationUUID, version); + return Response.status(Response.Status.OK).entity(applicationRelease).build(); + } + } catch (NotFoundException e) { + return Response.status(Response.Status.NOT_FOUND).build(); + } catch (ApplicationManagementException e) { + log.error("Error while getting all the application releases for the application with the UUID " + + applicationUUID, e); + 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.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index 38bf6168c7..26a011de63 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -44,7 +44,7 @@ org.wso2.carbon.device.application.mgt.core.impl.SubscriptionManagerImpl - org.wso2.carbon.device.application.mgt.core.impl.VisibilityManagerImpl + org.wso2.carbon.device.application.mgt.core.impl.UnrestrictedRoleManagerImpl org.wso2.carbon.device.application.mgt.core.impl.ApplicationStorageManagerImpl