From 1c6393959d67f35d8a9fcc43db88ab3eac87f3ba Mon Sep 17 00:00:00 2001 From: lasantha Date: Thu, 23 Nov 2017 12:57:28 +0530 Subject: [PATCH] adding app manager changes - not complete --- .../services/ApplicationManagementAPI.java | 11 +- .../impl/ApplicationManagementAPIImpl.java | 9 +- .../common/services/ApplicationManager.java | 2 +- .../mgt/core/impl/ApplicationManagerImpl.java | 102 ++++++------------ 4 files changed, 41 insertions(+), 83 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java index 0c4d21eabb..8bb9f107ac 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java @@ -290,7 +290,7 @@ public interface ApplicationManagementAPI { @Valid Application application); @POST - @Path("/release") + @Path("{appId}/release") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @ApiOperation( @@ -319,13 +319,10 @@ public interface ApplicationManagementAPI { }) 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); + @Multipart(value = "binaryFile") Attachment binaryFile, + @PathParam("appId") int applicationId)); + @POST @Path("/upload-artifacts/{uuid}") diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java index af6ee5407d..dd3515faff 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java @@ -199,16 +199,15 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } } - //working on this// @POST @Consumes("application/json") public Response createApplication(@Valid Application application) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - Application application2 = applicationManager.createApplication(application); + Application createdApplication = applicationManager.createApplication(application); if (application != null){ - return Response.status(Response.Status.CREATED).entity(application2).build(); + return Response.status(Response.Status.CREATED).entity(createdApplication).build(); }else{ String msg = "Given device type is not matched with existing device types"; log.error(msg); @@ -225,9 +224,11 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } } + //working on this// + @Override @POST - @Path("/release") + @Path("{appId}/release") public Response createApplicationRelease(@Multipart("applicationRelease") ApplicationRelease applicationRelease, @Multipart("binaryFile") Attachment binaryFile) { ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); 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 21c7c41a5d..21841f0159 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 @@ -39,7 +39,7 @@ public interface ApplicationManager { * @throws ApplicationManagementException Application Management Exception */ Application createApplication(Application application) - throws ApplicationManagementException, DeviceManagementDAOException, DeviceManagementDAOException; + throws ApplicationManagementException, DeviceManagementDAOException; /** * Updates an already existing 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 c8c5b9f7a5..e81f0a1b7d 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 @@ -27,6 +27,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; +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.exception.ValidationException; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; @@ -46,7 +47,7 @@ public class ApplicationManagerImpl implements ApplicationManager { private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class); private DeviceTypeDAO deviceTypeDAO; - private LifecycleDAO lifecycleDAO; + private VisibilityDAO visibilityDAO; private LifecycleStateDAO lifecycleStateDAO; private ApplicationDAO applicationDAO; @@ -57,7 +58,7 @@ public class ApplicationManagerImpl implements ApplicationManager { private void initDataAccessObjects() { this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO(); - this.lifecycleDAO = ApplicationManagementDAOFactory.getLifecycleDAO(); + this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); @@ -67,8 +68,9 @@ public class ApplicationManagerImpl implements ApplicationManager { public Application createApplication(Application application) throws ApplicationManagementException, DeviceManagementDAOException { - application.setUser(new User(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(), - PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true))); + User loggedInUser = new User(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(), + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); + application.setUser(loggedInUser); if (log.isDebugEnabled()) { log.debug("Create Application received for the tenant : " + application.getUser().getTenantId() + " From" + " the user : " + application.getUser().getUserName()); @@ -96,7 +98,7 @@ public class ApplicationManagerImpl implements ApplicationManager { this.applicationDAO.addTags(application.getTags(), appId, tenantId); } if (application.getIsRestricted() == 1 && !application.getUnrestrictedRoles().isEmpty()){ - this.applicationDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), appId, tenantId); + this.visibilityDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), appId, tenantId); }else{ application.setIsRestricted(0); } @@ -118,48 +120,6 @@ public class ApplicationManagerImpl implements ApplicationManager { }finally { ConnectionManagerUtil.closeDBConnection(); } - -// validateApplication(application); -// application.setUuid(HelperUtil.generateApplicationUuid()); -//// application.setCreatedAt(new Date()); -//// application.setModifiedAt(new Date()); -// -//// Category category = DataHolder.getInstance().getCategoryManager() -//// .getCategory(application.getCategory().getName()); -//// if (category == null) { -//// throw new NotFoundException("Invalid Category is provided for the application " + application.getUuid()); -//// } -//// application.setCategory(category); -// try { -// ConnectionManagerUtil.beginDBTransaction(); -//// if (log.isDebugEnabled()) { -//// log.debug("Application creation pre-conditions are met and the platform mentioned by identifier " -//// + platform.getIdentifier() + " is found"); -//// } -// LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); -// LifecycleState lifecycleState = lifecycleStateDAO.getLifeCycleStateByIdentifier(CREATED); -// -// if (lifecycleState == null) { -// ConnectionManagerUtil.commitDBTransaction(); -// throw new NotFoundException("Invalid lifecycle state."); -// } -// -// Lifecycle lifecycle = new Lifecycle(); -// lifecycle.setCreatedAt(new Date()); -// lifecycle.setCreatedBy(application.getUser().getUserName()); -// -// -//// application.setCurrentLifecycle(lifecycle); -// application = ApplicationManagementDAOFactory.getApplicationDAO().createApplication(application); -//// DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility()); -// ConnectionManagerUtil.commitDBTransaction(); -// return application; -// } catch (ApplicationManagementException e) { -// ConnectionManagerUtil.rollbackDBTransaction(); -// throw e; -// } finally { -// ConnectionManagerUtil.closeDBConnection(); -// } } @Override @@ -254,30 +214,30 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { -// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); -// String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); -// -// try { -// if (isAuthorized(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { -// userName = "ALL"; -// } -// } catch (UserStoreException e) { -// throw new ApplicationManagementException("User-store exception while checking whether the user " + -// userName + " of tenant " + tenantId + " has the publisher permission"); -// } -// filter.setUserName(userName); -// -// try { -// ConnectionManagerUtil.openDBConnection(); -// ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); -// ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId); -// for (Application application : applicationList.getApplications()) { -// application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId())); -// } -// return applicationList; -// } finally { -// ConnectionManagerUtil.closeDBConnection(); -// } + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + + try { + if (isAuthorized(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { + userName = "ALL"; + } + } catch (UserStoreException e) { + throw new ApplicationManagementException("User-store exception while checking whether the user " + + userName + " of tenant " + tenantId + " has the publisher permission"); + } + filter.setUserName(userName); + + try { + ConnectionManagerUtil.openDBConnection(); + ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); + ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId); + for (Application application : applicationList.getApplications()) { + application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId())); + } + return applicationList; + } finally { + ConnectionManagerUtil.closeDBConnection(); + } } @Override