From 45c7924e694dad8ab030dfc26e898af23720a220 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 28 May 2019 18:01:26 +0530 Subject: [PATCH 01/14] Improve review response in APPM --- .../mgt/core/impl/ReviewManagerImpl.java | 1 + .../util/AndroidApplicationOperationUtil.java | 53 ------------------- 2 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/AndroidApplicationOperationUtil.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java index 8c0a41ac6f4..f7eb2d2408c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java @@ -224,6 +224,7 @@ public class ReviewManagerImpl implements ReviewManager { review.setCreatedAt(reviewDTO.getCreatedAt()); review.setModifiedAt(reviewDTO.getModifiedAt()); review.setRating(reviewDTO.getRating()); + review.setUsername(reviewDTO.getUsername()); review.setReplies(new ArrayList<>()); return review; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/AndroidApplicationOperationUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/AndroidApplicationOperationUtil.java deleted file mode 100644 index bb1f5d955ae..00000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/AndroidApplicationOperationUtil.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2018, 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.core.util; - -import org.wso2.carbon.device.application.mgt.common.AppOperation; -import org.wso2.carbon.device.application.mgt.common.EnterpriseApplication; -import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; -import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; - -public class AndroidApplicationOperationUtil { -// public static Operation installApp(AppOperation appOperation) { -// ProfileOperation operation = new ProfileOperation(); -// operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION); -// operation.setType(Operation.Type.PROFILE); -// switch (appOperation.getApplication().getType()) { -// case "ENTERPRISE"://TODO: fix with ENUM -// EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); -// enterpriseApplication.setType(appOperation.getApplication().toString()); -// enterpriseApplication.setUrl(application.getLocation()); -// enterpriseApplication.setSchedule(appOperation.getScheduledDateTime()); -// enterpriseApplication.setPackageName(appOperation.getApplication().get); -// operation.setPayLoad(enterpriseApplication.toJSON()); -// break; -// case "PUBLIC": -// setOperationForPublicApp(operation, application); -// break; -// case "WEBAPP": -// setOperationForWebApp(operation, application); -// break; -// default: -// String errorMessage = "Invalid application type."; -// throw new DeviceApplicationException(errorMessage); -// } -// return operation; -// } - -} From 4ddc50e901e5618fe7c8f1d07649822bb572c4e1 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 28 May 2019 19:40:12 +0530 Subject: [PATCH 02/14] Add review managemente Admin API mapping --- .../mgt/common/EnterpriseApplication.java | 57 ------------------- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 + 2 files changed, 2 insertions(+), 57 deletions(-) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/EnterpriseApplication.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/EnterpriseApplication.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/EnterpriseApplication.java deleted file mode 100644 index 9fa337a2845..00000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/EnterpriseApplication.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018, 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.common; - -import java.io.Serializable; - -/** - * This class represents the Enterprise ApplicationDTO information. - */ -public class EnterpriseApplication extends AndroidApplication implements Serializable { - - private String url; - private String schedule; - private String packageName; - - private static final long serialVersionUID = 660343716452348222L; - - public String getSchedule() { - return schedule; - } - - public void setSchedule(String schedule) { - this.schedule = schedule; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getPackageName() { - return packageName; - } - - public void setPackageName(String packageName) { - this.packageName = packageName; - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml index da9e97cceab..da49a119c7e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -26,6 +26,7 @@ + @@ -55,6 +56,7 @@ + From b244208c49b3b64ab8f0ab4cf02c8d9fd672a5bb Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 28 May 2019 20:22:37 +0530 Subject: [PATCH 03/14] Improve review management interface --- .../mgt/store/api/services/ReviewManagementAPI.java | 4 ++-- .../store/api/services/admin/ReviewManagementAdminAPI.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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/ReviewManagementAPI.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/ReviewManagementAPI.java index 1776364de33..29ba58fb3ec 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.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/ReviewManagementAPI.java @@ -56,7 +56,7 @@ import java.util.List; @SwaggerDefinition( info = @Info( version = "1.0.0", - title = "Store Management Service", + title = "Review Management Service", extensions = { @Extension(properties = { @ExtensionProperty(name = "name", value = "ReviewManagementService"), @@ -86,7 +86,7 @@ import java.util.List; ) @Path("/reviews") -@Api(value = "Review Management") +@Api(value = "Review Management API") @Produces(MediaType.APPLICATION_JSON) public interface ReviewManagementAPI { String SCOPE = "scope"; 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/admin/ReviewManagementAdminAPI.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/admin/ReviewManagementAdminAPI.java index df2780fcd1f..765419cf220 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/ReviewManagementAdminAPI.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/admin/ReviewManagementAdminAPI.java @@ -49,7 +49,7 @@ import javax.ws.rs.core.Response; @SwaggerDefinition( info = @Info( version = "1.0.0", - title = "Store Management Admin Service", + title = "Admin Review Management Admin Service", extensions = { @Extension(properties = { @ExtensionProperty(name = "name", value = "ReviewManagementAdminService"), @@ -73,7 +73,7 @@ scopes = { ) @Path("/admin/reviews") -@Api(value = "Review Management") +@Api(value = "Review Management Admin API") @Produces(MediaType.APPLICATION_JSON) public interface ReviewManagementAdminAPI { String SCOPE = "scope"; From e41742b7779d40ed49f5903fc4c0eccd74b32701 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 29 May 2019 15:32:40 +0530 Subject: [PATCH 04/14] Improve app subscription functionality Further integrate app management component with device mgt --- .../mgt/common/AndroidApplication.java | 51 ----- .../ApplicationReleaseArtifactPaths.java | 42 ---- .../application/mgt/common/SubAction.java | 22 +++ .../common/services/SubscriptionManager.java | 4 +- .../mgt/core/impl/ApplicationManagerImpl.java | 2 +- .../core/impl/SubscriptionManagerImpl.java | 179 +++++++++++------- .../react-app/.env | 0 .../services/SubscriptionManagementAPI.java | 10 +- .../admin/ReviewManagementAdminAPI.java | 2 +- .../impl/SubscriptionManagementAPIImpl.java | 9 +- .../jaxrs/util/MDMAndroidOperationUtil.java | 8 +- .../mgt/jaxrs/util/MDMIOSOperationUtil.java | 8 +- .../app/mgt}/android/AppStoreApplication.java | 2 +- .../mgt}/android/EnterpriseApplication.java | 2 +- .../app/mgt}/android/WebApplication.java | 2 +- .../app/mgt}/ios/AppStoreApplication.java | 2 +- .../app/mgt}/ios/EnterpriseApplication.java | 2 +- .../app/mgt}/ios/RemoveApplication.java | 2 +- .../mgt/common/app/mgt}/ios/WebClip.java | 2 +- 19 files changed, 165 insertions(+), 186 deletions(-) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/AndroidApplication.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationReleaseArtifactPaths.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubAction.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/.env rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt}/android/AppStoreApplication.java (95%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt}/android/EnterpriseApplication.java (96%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt}/android/WebApplication.java (95%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt}/ios/AppStoreApplication.java (97%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt}/ios/EnterpriseApplication.java (97%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt}/ios/RemoveApplication.java (95%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt}/ios/WebClip.java (96%) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/AndroidApplication.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/AndroidApplication.java deleted file mode 100644 index 139c74b79b0..00000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/AndroidApplication.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2018, 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.common; - -import com.google.gson.Gson; -import org.wso2.carbon.device.application.mgt.common.exception.DeviceConnectorException; - -public class AndroidApplication { - private String type; - private String appIdentifier; - - private static final long serialVersionUID = 760343716452548282L; - - public String getAppIdentifier() { - return appIdentifier; - } - - public void setAppIdentifier(String appIdentifier) { - this.appIdentifier = appIdentifier; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String toJSON() throws DeviceConnectorException { - Gson gson = new Gson(); - return gson.toJson(this); - } - -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationReleaseArtifactPaths.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationReleaseArtifactPaths.java deleted file mode 100644 index 8692d7d11f2..00000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationReleaseArtifactPaths.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.wso2.carbon.device.application.mgt.common;/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. - * - * Entgra (Pvt) Ltd. 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. - */ - -import java.util.List; - -public class ApplicationReleaseArtifactPaths { - - private String installerPath; - private String iconPath; - private String bannerPath; - private List screenshotPaths; - - public String getInstallerPath() { return installerPath; } - - public void setInstallerPath(String installerPath) { this.installerPath = installerPath; } - - public String getIconPath() { return iconPath; } - - public void setIconPath(String iconPath) { this.iconPath = iconPath; } - - public String getBannerPath() { return bannerPath; } - - public void setBannerPath(String bannerPath) { this.bannerPath = bannerPath; } - - public List getScreenshotPaths() { return screenshotPaths; } - - public void setScreenshotPaths(List screenshotPaths) { this.screenshotPaths = screenshotPaths; } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubAction.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubAction.java new file mode 100644 index 00000000000..fde06081efd --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubAction.java @@ -0,0 +1,22 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.common; + +public enum SubAction { + INSTALL, UNINSTALL +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java index 1a21c601832..1f0e86b5842 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java @@ -39,8 +39,8 @@ public interface SubscriptionManager { ApplicationInstallResponse installApplicationForDevices(String applicationUUID, List deviceList) throws ApplicationManagementException; - ApplicationInstallResponse addBulkApInstallation(String applicationUUID, List subscriberList, - String subType) throws ApplicationManagementException; + ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List params, String subType) + throws ApplicationManagementException; /** * To install an application to given list of users. 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 21f4331363f..e458bbf5a26 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 @@ -619,7 +619,7 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); ApplicationList applicationList = new ApplicationList(); List appDTOs; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 2288f30310c..7dabbe941ce 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -24,6 +24,8 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.AppOperation; import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse; import org.wso2.carbon.device.application.mgt.common.ApplicationType; +import org.wso2.carbon.device.application.mgt.common.DeviceTypes; +import org.wso2.carbon.device.application.mgt.common.SubAction; import org.wso2.carbon.device.application.mgt.common.SubsciptionType; import org.wso2.carbon.device.application.mgt.common.SubscribingDeviceIdHolder; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; @@ -65,6 +67,7 @@ import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -87,7 +90,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); } - @Override public ApplicationInstallResponse installApplicationForDevices(String applicationUUID, + @Override + public ApplicationInstallResponse installApplicationForDevices(String applicationUUID, List deviceIdentifiers) throws ApplicationManagementException { if (log.isDebugEnabled()) { log.debug("Install application which has UUID: " + applicationUUID + " to " + deviceIdentifiers.size() @@ -99,102 +103,94 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error(msg); throw new BadRequestException(msg); } - DeviceManagementProviderService deviceManagementProviderService = HelperUtil - .getDeviceManagementProviderService(); ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); DeviceIDHolder filteredDeviceHolder = filterDeviceIdentifiers(applicationDTO, deviceIdentifiers); List errorDeviceIdentifiers = filteredDeviceHolder.getErrorDeviceIdList(); - List filteredDeviceObjs = new ArrayList<>(); - - //getting device objects by using device identifiers - for (DeviceIdentifier deviceIdentifier : filteredDeviceHolder.getValidDeviceIDList()) { - try { - Device device = deviceManagementProviderService.getDevice(deviceIdentifier, false); - if (device == null) { - String msg = "Couldn't found an device for device identifier " + deviceIdentifier.getId() - + " and device type: " + deviceIdentifier.getType(); - log.warn(msg); - errorDeviceIdentifiers.add(deviceIdentifier); - } else { - filteredDeviceObjs.add(device); - } - } catch (DeviceManagementException e) { - String msg = "Error occurred when getting device data for device identifier " + deviceIdentifier.getId() - + " and device type " + deviceIdentifier.getType(); - log.warn(msg); - errorDeviceIdentifiers.add(deviceIdentifier); - throw new ApplicationManagementException(msg, e); - } - } - - if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { - DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); - String deviceTypeName = deviceType.getName(); - ApplicationInstallResponse applicationInstallResponse = installToDevices(deviceTypeName, filteredDeviceObjs, - applicationDTO, SubsciptionType.DEVICE.toString(), null); - applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers); - return applicationInstallResponse; - } else { - //todo improve thos - ApplicationInstallResponse applicationInstallResponse = installToDevices(null, filteredDeviceObjs, - applicationDTO, SubsciptionType.DEVICE.toString(), null); - applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers); - return applicationInstallResponse; - } + ApplicationInstallResponse applicationInstallResponse = performBulkAppInstallation(applicationUUID, + filteredDeviceHolder.getValidDeviceIDList(), SubsciptionType.DEVICE.toString()); + applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers); + return applicationInstallResponse; } + @Override - public ApplicationInstallResponse addBulkApInstallation(String applicationUUID, List subscriberList, + public ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List params, String subType) throws ApplicationManagementException { if (log.isDebugEnabled()) { - log.debug("Install application release which has UUID " + applicationUUID + " to " + subscriberList.size() + log.debug("Install application release which has UUID " + applicationUUID + " to " + params.size() + " users."); } - try { - if (subscriberList.isEmpty()) { - String msg = "In order to install application release which has UUID " + applicationUUID + ", you shou" - + "ld provide list of subscribers. But found an empty list of users."; + if (params.isEmpty()) { + String msg = "In order to install application release which has UUID " + applicationUUID + ", you should" + + " provide list of subscribers. But found an empty list of users."; log.error(msg); throw new BadRequestException(msg); } - if (SubsciptionType.USER.toString().equals(subType) && !SubsciptionType.ROLE.toString().equals(subType) - && SubsciptionType.GROUP.toString().equals(subType)) { + + boolean isValidSubType = Arrays.stream(SubsciptionType.values()) + .anyMatch(sub -> sub.name().equalsIgnoreCase(subType)); + if (!isValidSubType) { String msg = "Found invalid subscription type to install application release witch has UUID: " + applicationUUID + ". Subscription type is " + subType; log.error(msg); throw new BadRequestException(msg); } - ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); GroupManagementProviderService groupManagementProviderService = HelperUtil .getGroupManagementProviderService(); List filteredDevices = new ArrayList<>(); - List subscriberDevices = new ArrayList<>(); - for (String subscriber : subscriberList) { - if (SubsciptionType.USER.toString().equals(subType)) { - subscriberDevices.addAll(deviceManagementProviderService.getDevicesOfUser(subscriber)); - } else if (SubsciptionType.ROLE.toString().equals(subType)) { - subscriberDevices.addAll(deviceManagementProviderService.getAllDevicesOfRole(subscriber)); - } else if (SubsciptionType.GROUP.toString().equals(subType)) { - subscriberDevices.addAll(groupManagementProviderService.getAllDevicesOfGroup(subscriber)); + List devices = new ArrayList<>(); + List subscribers = new ArrayList<>(); + + ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); + + if (SubsciptionType.DEVICE.toString().equals(subType)) { + for (T param : params) { + DeviceIdentifier deviceIdentifier = (DeviceIdentifier) param; + devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false)); + } + } else if (SubsciptionType.USER.toString().equals(subType)) { + for (T param : params) { + String username = (String) param; + subscribers.add(username); + devices.addAll(deviceManagementProviderService.getDevicesOfUser(username)); + } + } else if (SubsciptionType.ROLE.toString().equals(subType)) { + for (T param : params) { + String roleName = (String) param; + subscribers.add(roleName); + devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName)); + } + } else if (SubsciptionType.GROUP.toString().equals(subType)) { + for (T param : params) { + String groupName = (String) param; + subscribers.add(groupName); + devices.addAll(groupManagementProviderService.getAllDevicesOfGroup(groupName)); } } if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); String deviceTypeName = deviceType.getName(); - for (Device device : subscriberDevices) { + for (Device device : devices) { if (deviceTypeName.equals(device.getType())) { filteredDevices.add(device); } } - return installToDevices(deviceTypeName, filteredDevices, applicationDTO, subType, subscriberList); +// if (SubsciptionType.DEVICE.toString().equals(subType)) { +// return installToDevices(deviceTypeName, filteredDevices, applicationDTO, subType, null); +// +// } + return installToDevices(deviceTypeName, filteredDevices, applicationDTO, subType, subscribers); } else { //todo improve this - return installToDevices(null, subscriberDevices, applicationDTO, subType, subscriberList); +// if (SubsciptionType.DEVICE.toString().equals(subType)) { +// return installToDevices(null, filteredDevices, applicationDTO, subType, null); +// } + return installToDevices(null, devices, applicationDTO, subType, subscribers); } } catch (DeviceManagementException e) { String msg = "Error occurred while getting devices of given users or given roles."; @@ -207,6 +203,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + @Override + public List uninstallApplication(String applicationUUID, + List deviceList) throws ApplicationManagementException { + return null; + } + private ApplicationInstallResponse installToDevices(String deviceType, List devices, ApplicationDTO applicationDTO, String subType, List subscribers) throws ApplicationManagementException { @@ -566,17 +568,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager { return response; } - @Override public List uninstallApplication(String applicationUUID, - List deviceList) throws ApplicationManagementException { - return null; - } - private Activity addAppInstallOperationToDevices(ApplicationDTO application, List deviceIdentifierList, String deviceType) throws ApplicationManagementException { DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); try { - Operation operation = generateOperationPayloadByDeviceType(deviceType, application); + Operation operation = generateOperationPayloadByDeviceType(deviceType, application, null); //todo refactor add operation code to get successful operations return deviceManagementProviderService.addOperation(deviceType, operation, deviceIdentifierList); } catch (OperationManagementException e) { @@ -602,7 +599,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { .collect(Collectors.groupingBy(DeviceIdentifier::getType)); for (Map.Entry> entry : deviceTypeIdentifierMap.entrySet()) { - Operation operation = generateOperationPayloadByDeviceType(entry.getKey(), application); + Operation operation = generateOperationPayloadByDeviceType(entry.getKey(), application, null); try { Activity activity = deviceManagementProviderService .addOperation(entry.getKey(), operation, entry.getValue()); @@ -643,11 +640,57 @@ public class SubscriptionManagerImpl implements SubscriptionManager { return response; } - private Operation generateOperationPayloadByDeviceType(String deviceType, ApplicationDTO application) { + private Operation generateOperationPayloadByDeviceType(String deviceType, ApplicationDTO application, String action) { ProfileOperation operation = new ProfileOperation(); operation.setCode(INSTALL_APPLICATION); operation.setType(Operation.Type.PROFILE); +// if (DeviceTypes.ANDROID.toString().equalsIgnoreCase(deviceType)) { +// if (ApplicationType.ENTERPRISE.toString().equalsIgnoreCase(application.getType())) { +// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } +// } else if (ApplicationType.PUBLIC.toString().equalsIgnoreCase(application.getType())) { +// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } +// +// } else if (ApplicationType.WEB_CLIP.toString().equalsIgnoreCase(application.getType())) { +// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } +// } +// } else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) { +// if (ApplicationType.ENTERPRISE.toString().equalsIgnoreCase(application.getType())) { +// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } +// } else if (ApplicationType.PUBLIC.toString().equalsIgnoreCase(application.getType())) { +// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } +// } else if (ApplicationType.WEB_CLIP.toString().equalsIgnoreCase()) +// application.getType() { +// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { +// log.error("aaaa"); +// } +// } +// +// } + + //todo: generate operation payload correctly for all types of devices. operation.setPayLoad( "{'type':'enterprise', 'url':'" + application.getApplicationReleaseDTOs().get(0).getInstallerName() diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/.env b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/.env deleted file mode 100644 index e69de29bb2d..00000000000 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/SubscriptionManagementAPI.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/SubscriptionManagementAPI.java index 53e84b37699..8ced8ef49ed 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.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/SubscriptionManagementAPI.java @@ -129,7 +129,7 @@ public interface SubscriptionManagementAPI { ); @POST - @Path("/install/{uuid}/{subType}") + @Path("/install/{uuid}/{subType}/{action}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( @@ -149,7 +149,7 @@ public interface SubscriptionManagementAPI { value = { }) - Response addBulkAppInstalltion( + Response performBulkAppInstallation( @ApiParam( name = "uuid", value = "The application release UUID", @@ -162,6 +162,12 @@ public interface SubscriptionManagementAPI { required = true ) @PathParam("subType") String subType, + @ApiParam( + name = "action", + value = "Performing action.", + required = true + ) + @PathParam("action") String action, @ApiParam( name = "subscribers", value = "Subscriber list of the application release.", 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/admin/ReviewManagementAdminAPI.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/admin/ReviewManagementAdminAPI.java index 765419cf220..471924a1228 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/ReviewManagementAdminAPI.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/admin/ReviewManagementAdminAPI.java @@ -49,7 +49,7 @@ import javax.ws.rs.core.Response; @SwaggerDefinition( info = @Info( version = "1.0.0", - title = "Admin Review Management Admin Service", + title = "Review Management Admin Service", extensions = { @Extension(properties = { @ExtensionProperty(name = "name", value = "ReviewManagementAdminService"), 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/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java index a009b83fa9f..0a50229615b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java @@ -80,14 +80,15 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @Override @POST - @Path("/install/{uuid}/{subType}") - public Response addBulkAppInstalltion( + @Path("/install/{uuid}/{subType}/{action}") + public Response performBulkAppInstallation( @PathParam("uuid") String uuid, - @PathParam("uuid") String subType, + @PathParam("subType") String subType, + @PathParam("action") String sction, @Valid List subscribers) { try { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); - ApplicationInstallResponse response = subscriptionManager.addBulkApInstallation(uuid, subscribers, subType); + ApplicationInstallResponse response = subscriptionManager.performBulkAppInstallation(uuid, subscribers, subType); return Response.status(Response.Status.OK).entity(response).build(); } catch (NotFoundException e) { String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMAndroidOperationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMAndroidOperationUtil.java index ce04cdc1374..64b215162c3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMAndroidOperationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMAndroidOperationUtil.java @@ -18,12 +18,12 @@ package org.wso2.carbon.device.mgt.jaxrs.util; -import org.wso2.carbon.device.mgt.jaxrs.beans.MobileApp; -import org.wso2.carbon.device.mgt.jaxrs.beans.android.AppStoreApplication; -import org.wso2.carbon.device.mgt.jaxrs.beans.android.EnterpriseApplication; +import org.wso2.carbon.device.mgt.common.app.mgt.android.AppStoreApplication; +import org.wso2.carbon.device.mgt.common.app.mgt.android.EnterpriseApplication; +import org.wso2.carbon.device.mgt.common.app.mgt.android.WebApplication; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; -import org.wso2.carbon.device.mgt.jaxrs.beans.android.WebApplication; +import org.wso2.carbon.device.mgt.jaxrs.beans.MobileApp; import org.wso2.carbon.device.mgt.jaxrs.exception.UnknownApplicationTypeException; /** diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMIOSOperationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMIOSOperationUtil.java index 91ad342e5e8..cebe68a5a54 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMIOSOperationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMIOSOperationUtil.java @@ -18,11 +18,11 @@ package org.wso2.carbon.device.mgt.jaxrs.util; +import org.wso2.carbon.device.mgt.common.app.mgt.ios.AppStoreApplication; +import org.wso2.carbon.device.mgt.common.app.mgt.ios.EnterpriseApplication; +import org.wso2.carbon.device.mgt.common.app.mgt.ios.RemoveApplication; +import org.wso2.carbon.device.mgt.common.app.mgt.ios.WebClip; import org.wso2.carbon.device.mgt.jaxrs.beans.MobileApp; -import org.wso2.carbon.device.mgt.jaxrs.beans.ios.AppStoreApplication; -import org.wso2.carbon.device.mgt.jaxrs.beans.ios.EnterpriseApplication; -import org.wso2.carbon.device.mgt.jaxrs.beans.ios.RemoveApplication; -import org.wso2.carbon.device.mgt.jaxrs.beans.ios.WebClip; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/android/AppStoreApplication.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/AppStoreApplication.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/android/AppStoreApplication.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/AppStoreApplication.java index 951ab365e2a..50126814ca3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/android/AppStoreApplication.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/AppStoreApplication.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.beans.android; +package org.wso2.carbon.device.mgt.common.app.mgt.android; import com.google.gson.Gson; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/android/EnterpriseApplication.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/EnterpriseApplication.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/android/EnterpriseApplication.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/EnterpriseApplication.java index 2bd8633d92d..f087013a186 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/android/EnterpriseApplication.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/EnterpriseApplication.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.beans.android; +package org.wso2.carbon.device.mgt.common.app.mgt.android; import com.google.gson.Gson; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/android/WebApplication.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/WebApplication.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/android/WebApplication.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/WebApplication.java index 7cb7243753d..32574292694 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/android/WebApplication.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/WebApplication.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.beans.android; +package org.wso2.carbon.device.mgt.common.app.mgt.android; import com.google.gson.Gson; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/AppStoreApplication.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/AppStoreApplication.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/AppStoreApplication.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/AppStoreApplication.java index 1925d6db772..23c514710b8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/AppStoreApplication.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/AppStoreApplication.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.beans.ios; +package org.wso2.carbon.device.mgt.common.app.mgt.ios; import com.google.gson.Gson; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/EnterpriseApplication.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/EnterpriseApplication.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/EnterpriseApplication.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/EnterpriseApplication.java index 2ac2879b743..8bf36b46024 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/EnterpriseApplication.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/EnterpriseApplication.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.beans.ios; +package org.wso2.carbon.device.mgt.common.app.mgt.ios; import com.google.gson.Gson; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/RemoveApplication.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/RemoveApplication.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/RemoveApplication.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/RemoveApplication.java index 95f85984a07..c723812d48e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/RemoveApplication.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/RemoveApplication.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.beans.ios; +package org.wso2.carbon.device.mgt.common.app.mgt.ios; import com.google.gson.Gson; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/WebClip.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/WebClip.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/WebClip.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/WebClip.java index 3e73197d08c..f78577432c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ios/WebClip.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ios/WebClip.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.beans.ios; +package org.wso2.carbon.device.mgt.common.app.mgt.ios; import com.google.gson.Gson; From c0398949bd0f8bfaa826ef2a99dbba1a94d49882 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 30 May 2019 02:11:15 +0530 Subject: [PATCH 05/14] Refactor App subscription method --- ...ApiApplicationRegistrationServiceImpl.java | 4 +- .../extension/api/util/APIUtil.java | 2 +- .../mgt/core/impl/ApplicationManagerImpl.java | 2 +- .../mgt/core/impl/MAMDeviceConnectorImpl.java | 2 +- .../core/impl/SubscriptionManagerImpl.java | 98 ++++++++----------- .../application/mgt/core/util/APIUtil.java | 4 +- .../dao/ApplicationManagementDAOTest.java | 2 +- .../mgt/core/scep/SCEPManagerImpl.java | 3 +- .../BaseDeviceManagementCertificateTest.java | 2 +- ...CertificateManagementServiceImplTests.java | 2 +- .../provider/fcm/FCMNotificationStrategy.java | 2 +- .../provider/http/HTTPMessageExecutor.java | 2 +- .../http/HTTPNotificationStrategy.java | 2 +- .../mqtt/MQTTNotificationStrategy.java | 2 +- .../xmpp/XMPPNotificationStrategy.java | 2 +- .../mgt/jaxrs/beans/ApplicationWrapper.java | 1 + .../impl/ConfigurationServiceImpl.java | 2 +- .../service/impl/DeviceAgentServiceImpl.java | 7 +- .../DeviceEventManagementServiceImpl.java | 2 +- .../impl/DeviceManagementServiceImpl.java | 8 +- .../impl/DeviceTypeManagementServiceImpl.java | 4 +- .../impl/GeoLocationBasedServiceImpl.java | 2 +- .../impl/GroupManagementServiceImpl.java | 3 +- .../impl/PolicyManagementServiceImpl.java | 2 +- .../impl/UserManagementServiceImpl.java | 2 +- ...ApplicationManagementAdminServiceImpl.java | 8 +- .../DeviceManagementAdminServiceImpl.java | 9 +- .../DeviceTypeManagementAdminServiceImpl.java | 2 +- .../admin/UserManagementAdminServiceImpl.java | 5 +- .../mgt/jaxrs/util/DeviceMgtAPIUtils.java | 3 +- .../service/impl/DeviceAgentServiceTest.java | 2 +- .../impl/DeviceManagementServiceImplTest.java | 5 +- .../DeviceTypeManagementAdminServiceTest.java | 2 +- .../impl/DeviceTypeManagementServiceTest.java | 2 +- .../impl/GeoLocationBasedServiceImplTest.java | 2 +- .../impl/GroupManagementServiceImplTest.java | 2 +- .../impl/UserManagementServiceImplTest.java | 2 +- .../device/mgt/common/DeviceManager.java | 1 + .../device/mgt/common/FeatureManager.java | 2 + .../device/mgt/common}/MDMAppConstants.java | 2 +- .../device/mgt/common/app/mgt}/MobileApp.java | 3 +- .../mgt/common/app/mgt}/MobileAppTypes.java | 2 +- .../DeviceManagementException.java | 2 +- .../DeviceNotFoundException.java | 2 +- .../DeviceTypeNotFoundException.java | 2 +- .../EntityDoesNotExistException.java | 2 +- .../FeatureManagementException.java | 2 +- .../IllegalTransactionStateException.java | 2 +- .../InvalidConfigurationException.java | 2 +- .../InvalidDeviceException.java | 2 +- .../PrivacyComplianceException.java | 2 +- .../TransactionManagementException.java | 2 +- .../UnauthorizedDeviceAccessException.java | 2 +- .../UnknownApplicationTypeException.java | 2 +- .../UnsupportedDatabaseEngineException.java | 2 +- .../UserNotFoundException.java | 2 +- .../operation/mgt/OperationManager.java | 4 +- .../common/spi/DeviceManagementService.java | 1 + .../DeviceManagementPluginRepository.java | 4 +- ...ApplicationManagerProviderServiceImpl.java | 6 +- .../core/archival/ArchivalServiceImpl.java | 5 +- .../dao/ArchivalDestinationDAOFactory.java | 4 +- .../dao/ArchivalSourceDAOFactory.java | 4 +- .../DeviceAccessAuthorizationServiceImpl.java | 2 +- .../config/DeviceConfigurationManager.java | 6 +- .../core/dao/DeviceManagementDAOFactory.java | 7 +- .../core/dao/GroupManagementDAOFactory.java | 6 +- .../impl/DeviceInformationManagerImpl.java | 4 +- .../DeviceManagementServiceComponent.java | 2 +- .../NotificationManagementServiceImpl.java | 8 +- .../dao/NotificationManagementDAOFactory.java | 6 +- .../operation/mgt/OperationManagerImpl.java | 6 +- .../dao/OperationManagementDAOFactory.java | 6 +- .../privacy/PrivacyComplianceProvider.java | 2 +- .../impl/PrivacyComplianceProviderImpl.java | 6 +- .../task/PushNotificationSchedulerTask.java | 4 +- .../DeviceManagementProviderService.java | 8 +- .../DeviceManagementProviderServiceImpl.java | 12 +-- .../GroupManagementProviderService.java | 2 +- .../GroupManagementProviderServiceImpl.java | 6 +- .../task/impl/DeviceStatusMonitoringTask.java | 2 +- .../task/impl/DeviceDetailsRetrieverTask.java | 2 +- .../core/task/impl/DeviceTaskManagerImpl.java | 4 +- .../mgt/core/util/DeviceManagerUtil.java | 5 +- .../core}/util/MDMAndroidOperationUtil.java | 7 +- .../mgt/core}/util/MDMIOSOperationUtil.java | 5 +- .../core/DeviceManagementRepositoryTests.java | 3 +- .../mgt/core/TestDeviceManagementService.java | 1 + .../device/mgt/core/TestDeviceManager.java | 1 + ...licationManagementProviderServiceTest.java | 3 +- .../DeviceAccessAuthorizationServiceTest.java | 4 +- .../cache/DeviceCacheManagerImplTest.java | 2 +- .../core/common/BaseDeviceManagementTest.java | 2 +- .../mgt/core/dao/DevicePersistTests.java | 2 +- .../mgt/core/dao/GroupPersistTests.java | 3 +- ...otificationManagementServiceImplTests.java | 2 +- ...tionManagementNegativeDBOperationTest.java | 2 +- .../OperationManagementNoDBSchemaTests.java | 4 +- .../operation/OperationManagementTests.java | 4 +- .../ScheduledTaskOperationTests.java | 4 +- .../PushNotificationSchedulerTaskTest.java | 2 +- .../search/SearchManagementServiceTest.java | 2 +- .../DeviceManagementProviderServiceTest.java | 6 +- ...ManagementProviderServiceNegativeTest.java | 2 +- .../GroupManagementProviderServiceTest.java | 4 +- .../mgt/core/task/DeviceTaskManagerTest.java | 5 +- .../type/template/DeviceTypeManager.java | 2 +- .../template/DeviceTypeManagerService.java | 2 +- .../ConfigurationBasedFeatureManager.java | 2 +- .../DeviceTypeManagerNegativeTest.java | 2 +- .../DeviceTypeManagerServiceTest.java | 5 +- .../type/template/DeviceTypeManagerTest.java | 2 +- ...rviceAndDeviceTypeGeneratorServceTest.java | 2 +- .../mgt/core/PolicyManagerServiceImpl.java | 2 +- .../core/dao/PolicyManagementDAOFactory.java | 4 +- .../mgt/core/enforcement/DelegationTask.java | 2 +- .../PolicyEnforcementDelegatorImpl.java | 2 +- .../impl/ComplianceDecisionPointImpl.java | 2 + .../core/impl/PolicyInformationPointImpl.java | 2 +- .../core/mgt/impl/MonitoringManagerImpl.java | 5 +- .../mgt/core/mgt/impl/PolicyManagerImpl.java | 4 +- .../policy/mgt/core/task/MonitoringTask.java | 2 +- .../mgt/core/BasePolicyManagementDAOTest.java | 4 +- .../policy/mgt/core/MonitoringTestCase.java | 3 +- .../policy/mgt/core/PolicyDAOTestCase.java | 2 + .../mgt/core/PolicyEvaluationTestCase.java | 2 +- .../core/PolicyManagerServiceImplTest.java | 2 + .../core/mgt/impl/FeatureManagerImplTest.java | 2 +- .../mgt/impl/MonitoringManagerImplTest.java | 4 +- .../core/mgt/impl/ProfileManagerImplTest.java | 2 +- .../mock/TypeXDeviceManagementService.java | 2 +- .../mgt/core/mock/TypeXDeviceManager.java | 2 +- .../CertificateAuthenticatorTest.java | 2 +- 133 files changed, 240 insertions(+), 279 deletions(-) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common}/MDMAppConstants.java (97%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt}/MobileApp.java (97%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt}/MobileAppTypes.java (93%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/DeviceManagementException.java (95%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/DeviceNotFoundException.java (95%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/DeviceTypeNotFoundException.java (95%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/EntityDoesNotExistException.java (96%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/FeatureManagementException.java (95%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/IllegalTransactionStateException.java (96%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/InvalidConfigurationException.java (96%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/InvalidDeviceException.java (95%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/PrivacyComplianceException.java (95%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/TransactionManagementException.java (96%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/UnauthorizedDeviceAccessException.java (96%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions}/UnknownApplicationTypeException.java (96%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/UnsupportedDatabaseEngineException.java (96%) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/{ => exceptions}/UserNotFoundException.java (95%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs => org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core}/util/MDMAndroidOperationUtil.java (94%) rename components/device-mgt/{org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs => org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core}/util/MDMIOSOperationUtil.java (96%) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java index 46566539883..445e621f530 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java @@ -21,7 +21,6 @@ package org.wso2.carbon.apimgt.application.extension.api; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.json.simple.JSONObject; import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; import org.wso2.carbon.apimgt.application.extension.api.util.APIUtil; import org.wso2.carbon.apimgt.application.extension.api.util.RegistrationProfile; @@ -30,10 +29,9 @@ import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.user.api.UserStoreException; -import javax.ws.rs.DELETE; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java index ad8d57cfa4d..452b02d56ba 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java @@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.registry.api.Resource; import org.wso2.carbon.registry.core.Registry; 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 e458bbf5a26..01909c468a6 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 @@ -77,7 +77,7 @@ import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManag import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.user.api.UserRealm; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/MAMDeviceConnectorImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/MAMDeviceConnectorImpl.java index 1599d1a7fb3..e1727bc8c5b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/MAMDeviceConnectorImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/MAMDeviceConnectorImpl.java @@ -30,7 +30,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagem import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException;; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import java.util.ArrayList; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 7dabbe941ce..9141cd083bd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -51,8 +51,11 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.HelperUtil; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.app.mgt.MobileApp; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.UnknownApplicationTypeException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; @@ -65,6 +68,8 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.util.DeviceIDHolder; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; +import org.wso2.carbon.device.mgt.core.util.MDMAndroidOperationUtil; +import org.wso2.carbon.device.mgt.core.util.MDMIOSOperationUtil; import java.util.ArrayList; import java.util.Arrays; @@ -640,62 +645,43 @@ public class SubscriptionManagerImpl implements SubscriptionManager { return response; } - private Operation generateOperationPayloadByDeviceType(String deviceType, ApplicationDTO application, String action) { - ProfileOperation operation = new ProfileOperation(); - operation.setCode(INSTALL_APPLICATION); - operation.setType(Operation.Type.PROFILE); - -// if (DeviceTypes.ANDROID.toString().equalsIgnoreCase(deviceType)) { -// if (ApplicationType.ENTERPRISE.toString().equalsIgnoreCase(application.getType())) { -// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } -// } else if (ApplicationType.PUBLIC.toString().equalsIgnoreCase(application.getType())) { -// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } -// -// } else if (ApplicationType.WEB_CLIP.toString().equalsIgnoreCase(application.getType())) { -// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } -// } -// } else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) { -// if (ApplicationType.ENTERPRISE.toString().equalsIgnoreCase(application.getType())) { -// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } -// } else if (ApplicationType.PUBLIC.toString().equalsIgnoreCase(application.getType())) { -// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } -// } else if (ApplicationType.WEB_CLIP.toString().equalsIgnoreCase()) -// application.getType() { -// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { -// log.error("aaaa"); -// } -// } -// -// } + private Operation generateOperationPayloadByDeviceType(String deviceType, ApplicationDTO application, String action) + throws ApplicationManagementException { + try { + //todo rethink and modify the {@link MobileApp} usage + MobileApp mobileApp = new MobileApp(); + if (DeviceTypes.ANDROID.toString().equalsIgnoreCase(deviceType)) { + if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { + return MDMAndroidOperationUtil.createInstallAppOperation(mobileApp); + } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { + return MDMAndroidOperationUtil.createAppUninstallOperation(mobileApp); + } else { + String msg = "Invalid Action is found. Action: " + action; + log.error(msg); + throw new ApplicationManagementException(msg); + } + } else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) { + if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { + return MDMIOSOperationUtil.createInstallAppOperation(mobileApp); + } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { + return MDMIOSOperationUtil.createAppUninstallOperation(mobileApp); + } else { + String msg = "Invalid Action is found. Action: " + action; + log.error(msg); + throw new ApplicationManagementException(msg); + } + } else { + String msg = "Invalid device type is found. Device Type: " + deviceType; + log.error(msg); + throw new ApplicationManagementException(msg); + } - //todo: generate operation payload correctly for all types of devices. - operation.setPayLoad( - "{'type':'enterprise', 'url':'" + application.getApplicationReleaseDTOs().get(0).getInstallerName() - + "', 'app':'" + application.getApplicationReleaseDTOs().get(0).getUuid() + "'}"); - return operation; + } catch (UnknownApplicationTypeException e) { + String msg = "Unknown Application type is found."; + log.error(msg); + throw new ApplicationManagementException(msg); + } } /** diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index 0e84edef815..0bd459c4eab 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -18,16 +18,14 @@ package org.wso2.carbon.device.application.mgt.core.util; -import org.apache.commons.lang.StringUtils; 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.Filter; import org.wso2.carbon.device.application.mgt.common.services.*; import org.wso2.carbon.device.application.mgt.common.ErrorResponse; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import javax.ws.rs.core.Response; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/dao/ApplicationManagementDAOTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/dao/ApplicationManagementDAOTest.java index 625669ec8dc..6d07b0c688d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/dao/ApplicationManagementDAOTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/dao/ApplicationManagementDAOTest.java @@ -10,7 +10,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagem import org.wso2.carbon.device.application.mgt.core.dto.ApplicationsDTO; import org.wso2.carbon.device.application.mgt.core.dto.DeviceTypeCreator; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/scep/SCEPManagerImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/scep/SCEPManagerImpl.java index dfcc05626e4..13b1048891b 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/scep/SCEPManagerImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/scep/SCEPManagerImpl.java @@ -23,13 +23,12 @@ import org.wso2.carbon.certificate.mgt.core.internal.CertificateManagementDataHo import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import java.sql.SQLException; import java.util.HashMap; public class SCEPManagerImpl implements SCEPManager { diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/test/java/org/wso2/carbon/certificate/mgt/core/common/BaseDeviceManagementCertificateTest.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/test/java/org/wso2/carbon/certificate/mgt/core/common/BaseDeviceManagementCertificateTest.java index 38a16a7fa07..592a9b0e7ce 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/test/java/org/wso2/carbon/certificate/mgt/core/common/BaseDeviceManagementCertificateTest.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/test/java/org/wso2/carbon/certificate/mgt/core/common/BaseDeviceManagementCertificateTest.java @@ -27,7 +27,7 @@ import org.w3c.dom.Document; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.certificate.mgt.core.util.TestUtils; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/test/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateManagementServiceImplTests.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/test/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateManagementServiceImplTests.java index a7e0629e5d2..985ffa080da 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/test/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateManagementServiceImplTests.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/test/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateManagementServiceImplTests.java @@ -43,7 +43,7 @@ import org.wso2.carbon.certificate.mgt.core.util.CSRGenerator; import org.wso2.carbon.certificate.mgt.core.util.CertificateManagementConstants; import org.wso2.carbon.certificate.mgt.core.util.DummyCertificate; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import sun.misc.BASE64Encoder; import java.io.ByteArrayInputStream; diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java index 7c1700c2108..432ea0360f8 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java @@ -24,7 +24,7 @@ import com.google.gson.JsonPrimitive; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPMessageExecutor.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPMessageExecutor.java index d8338568836..5c8ab798d15 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPMessageExecutor.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPMessageExecutor.java @@ -8,7 +8,7 @@ import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.InvalidConfigurationException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidConfigurationException; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import java.net.UnknownHostException; diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPNotificationStrategy.java index 2e4e237c695..fe8126d2a91 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPNotificationStrategy.java @@ -22,7 +22,7 @@ import org.apache.commons.httpclient.HostConfiguration; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.InvalidConfigurationException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidConfigurationException; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java index 59653e78319..cb83c0fa1c7 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.InvalidConfigurationException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidConfigurationException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java index d091ecfd9de..6b5d0fa4746 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.InvalidConfigurationException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidConfigurationException; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ApplicationWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ApplicationWrapper.java index 39d6de263e6..10d2953782f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ApplicationWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ApplicationWrapper.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.app.mgt.MobileApp; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java index 064984f19d5..1e176c623b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java @@ -27,7 +27,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.service.api.ConfigurationManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; -import org.wso2.carbon.device.mgt.jaxrs.util.MDMAppConstants; +import org.wso2.carbon.device.mgt.common.MDMAppConstants; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java index 5bda5a70a76..bb5bbc6755a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java @@ -22,7 +22,6 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonParser; -import io.swagger.annotations.ApiParam; import org.apache.axis2.AxisFault; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,18 +29,16 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -import org.wso2.carbon.device.mgt.common.InvalidConfigurationException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidConfigurationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; -import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; -import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AttributeType; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java index 2bbcee2d43a..1e0ad92632b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java @@ -20,7 +20,7 @@ import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AttributeType; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 5c69f0bd4d4..0b6f882c189 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -24,13 +24,13 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceTypeNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceTypeNotFoundException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.FeatureManager; -import org.wso2.carbon.device.mgt.common.InvalidConfigurationException; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidConfigurationException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.app.mgt.Application; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java index e9129c4c6eb..77a610e8722 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java @@ -37,8 +37,8 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceTypeNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceTypeNotFoundException; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index add4acef72a..ffb433eaec9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -32,7 +32,7 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.geo.service.*; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java index 49f0b4ad767..3d4d8fe29bf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java @@ -22,11 +22,10 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; -import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index 01dd4880c11..bf9fc8b7bd0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 329c5599032..915aac0b163 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -40,7 +40,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.http.HttpStatus; import org.eclipse.wst.common.uriresolver.internal.util.URIEncoder; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java index 5141399fa1a..f42ebe45913 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java @@ -27,14 +27,14 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; -import org.wso2.carbon.device.mgt.jaxrs.exception.UnknownApplicationTypeException; +import org.wso2.carbon.device.mgt.common.exceptions.UnknownApplicationTypeException; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.ApplicationManagementAdminService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; -import org.wso2.carbon.device.mgt.jaxrs.util.MDMAndroidOperationUtil; -import org.wso2.carbon.device.mgt.jaxrs.util.MDMIOSOperationUtil; +import org.wso2.carbon.device.mgt.core.util.MDMAndroidOperationUtil; +import org.wso2.carbon.device.mgt.core.util.MDMIOSOperationUtil; import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper; -import org.wso2.carbon.device.mgt.jaxrs.beans.MobileApp; +import org.wso2.carbon.device.mgt.common.app.mgt.MobileApp; import javax.ws.rs.Consumes; import javax.ws.rs.POST; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java index 38e58047517..3864276fe82 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java @@ -20,23 +20,20 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.common.StringUtils; -import org.wso2.carbon.apimgt.integration.generated.client.publisher.StringUtil; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.PaginationRequest; -import org.wso2.carbon.device.mgt.common.UserNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; -import javax.validation.constraints.Past; import javax.validation.constraints.Size; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java index d7f659871db..3edaf7af965 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java @@ -38,7 +38,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.core.dto.DeviceType; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java index f5dbb3d3b6d..b4cf3a02bbc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java @@ -18,13 +18,10 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin; -import io.swagger.annotations.ApiParam; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.netbeans.lib.cvsclient.commandLine.command.log; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.PrivacyComplianceException; +import org.wso2.carbon.device.mgt.common.exceptions.PrivacyComplianceException; import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.UserManagementAdminService; import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index a795fca1a54..eaaf3d3febd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -38,7 +38,7 @@ import org.wso2.carbon.core.util.Utils; import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; @@ -84,7 +84,6 @@ import javax.cache.Caching; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManagerFactory; -import javax.ws.rs.core.MediaType; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceTest.java index 44c23440d9a..5e60c5e05a7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceTest.java @@ -39,7 +39,7 @@ import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublish import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherServiceImpl; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImplTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImplTest.java index 27e84c7fc9c..818c8102f38 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImplTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImplTest.java @@ -31,10 +31,9 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; import org.wso2.carbon.context.CarbonContext; -import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceTypeNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceTypeNotFoundException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementAdminServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementAdminServiceTest.java index 9c129cd5932..ca151c7bd28 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementAdminServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementAdminServiceTest.java @@ -30,7 +30,7 @@ import org.testng.IObjectFactory; import org.testng.annotations.BeforeClass; import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceTest.java index fa320b5b5fd..16a99deb0a1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceTest.java @@ -29,7 +29,7 @@ import org.testng.IObjectFactory; import org.testng.annotations.BeforeClass; import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java index befc2b47d60..5553e02d227 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java @@ -6,7 +6,7 @@ import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.geo.GeoCluster; import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImplTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImplTest.java index 9a4829cb568..559a8cabee2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImplTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImplTest.java @@ -34,7 +34,7 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImplTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImplTest.java index d6984503cba..13942afb251 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImplTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImplTest.java @@ -32,7 +32,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; import org.wso2.carbon.context.CarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java index ebb225ae4fc..6c8bf5dc0da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.common; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java index 884311e935d..c60c2e25605 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java @@ -18,6 +18,8 @@ */ package org.wso2.carbon.device.mgt.common; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; + import java.util.List; public interface FeatureManager { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMAppConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MDMAppConstants.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMAppConstants.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MDMAppConstants.java index 32f3c4c2f17..8dc62592a46 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMAppConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MDMAppConstants.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.util; +package org.wso2.carbon.device.mgt.common; /** * This class holds all the constants used for IOS and Android. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/MobileApp.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/MobileApp.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/MobileApp.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/MobileApp.java index fe7f4e02682..0e85d4bafe0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/MobileApp.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/MobileApp.java @@ -16,10 +16,11 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.beans; +package org.wso2.carbon.device.mgt.common.app.mgt; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.device.mgt.common.app.mgt.MobileAppTypes; import java.util.Properties; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/MobileAppTypes.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/MobileAppTypes.java similarity index 93% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/MobileAppTypes.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/MobileAppTypes.java index 3997da90d72..3149ac5721d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/MobileAppTypes.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/MobileAppTypes.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.beans; +package org.wso2.carbon.device.mgt.common.app.mgt; public enum MobileAppTypes { ENTERPRISE,WEBAPP,PUBLIC diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceManagementException.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceManagementException.java index 3a304a3b713..70464ccf509 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceManagementException.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; public class DeviceManagementException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceNotFoundException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceNotFoundException.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceNotFoundException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceNotFoundException.java index 7115405c2b0..ecacdd3e214 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceNotFoundException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceNotFoundException.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; public class DeviceNotFoundException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeNotFoundException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceTypeNotFoundException.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeNotFoundException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceTypeNotFoundException.java index d8034cc8cff..a443c4ff82e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeNotFoundException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceTypeNotFoundException.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; public class DeviceTypeNotFoundException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EntityDoesNotExistException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/EntityDoesNotExistException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EntityDoesNotExistException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/EntityDoesNotExistException.java index 13b68210014..b4582505bcd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EntityDoesNotExistException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/EntityDoesNotExistException.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; public class EntityDoesNotExistException extends RuntimeException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/FeatureManagementException.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/FeatureManagementException.java index 8552c6b815d..d8e2083fe3b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/FeatureManagementException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; public class FeatureManagementException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/IllegalTransactionStateException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/IllegalTransactionStateException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/IllegalTransactionStateException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/IllegalTransactionStateException.java index 1cc0594ba7d..6601633742d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/IllegalTransactionStateException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/IllegalTransactionStateException.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; public class IllegalTransactionStateException extends RuntimeException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InvalidConfigurationException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/InvalidConfigurationException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InvalidConfigurationException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/InvalidConfigurationException.java index e6b291b6055..8ad731f62b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InvalidConfigurationException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/InvalidConfigurationException.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; /** * This exception is thrown when configured with invalid configuration. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InvalidDeviceException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/InvalidDeviceException.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InvalidDeviceException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/InvalidDeviceException.java index dd900744cd8..4f305b938c2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InvalidDeviceException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/InvalidDeviceException.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; public class InvalidDeviceException extends Exception { private static final long serialVersionUID = -3151279311929070297L; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PrivacyComplianceException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/PrivacyComplianceException.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PrivacyComplianceException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/PrivacyComplianceException.java index a9bf316de0c..2aae4d6d167 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PrivacyComplianceException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/PrivacyComplianceException.java @@ -17,7 +17,7 @@ */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; public class PrivacyComplianceException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/TransactionManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/TransactionManagementException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/TransactionManagementException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/TransactionManagementException.java index d96d462077f..f6e046c929b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/TransactionManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/TransactionManagementException.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; public class TransactionManagementException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UnauthorizedDeviceAccessException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UnauthorizedDeviceAccessException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UnauthorizedDeviceAccessException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UnauthorizedDeviceAccessException.java index 2f35d878f2c..997b541c9d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UnauthorizedDeviceAccessException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UnauthorizedDeviceAccessException.java @@ -17,7 +17,7 @@ * */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; public class UnauthorizedDeviceAccessException extends RuntimeException { private static final long serialVersionUID = -3151289331929070297L; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/UnknownApplicationTypeException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UnknownApplicationTypeException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/UnknownApplicationTypeException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UnknownApplicationTypeException.java index 459335abd8b..644cc9b2e00 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/UnknownApplicationTypeException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UnknownApplicationTypeException.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.jaxrs.exception; +package org.wso2.carbon.device.mgt.common.exceptions; public class UnknownApplicationTypeException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UnsupportedDatabaseEngineException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UnsupportedDatabaseEngineException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UnsupportedDatabaseEngineException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UnsupportedDatabaseEngineException.java index 8e1d33ec4be..93a29c31875 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UnsupportedDatabaseEngineException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UnsupportedDatabaseEngineException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; /** * This runtime exception will be thrown if the server has configured with unsupported DB engine. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UserNotFoundException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UserNotFoundException.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UserNotFoundException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UserNotFoundException.java index 640e28b7527..247db71fc8b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UserNotFoundException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/UserNotFoundException.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.common.exceptions; /* * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index 78bfdec53f0..720383952e8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -18,8 +18,8 @@ package org.wso2.carbon.device.mgt.common.operation.mgt; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java index b14a5ab920a..33a9ac867bc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.common.spi; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.general.GeneralConfig; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index 44b740a0974..d16ad2c2885 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -21,9 +21,9 @@ import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; -import org.wso2.carbon.device.mgt.common.InvalidConfigurationException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidConfigurationException; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 53f7da75af1..60209c0c13d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -24,9 +24,9 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/ArchivalServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/ArchivalServiceImpl.java index a4b8405d09d..33dffa1c8f2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/ArchivalServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/ArchivalServiceImpl.java @@ -21,16 +21,13 @@ package org.wso2.carbon.device.mgt.core.archival; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.core.archival.beans.*; import org.wso2.carbon.device.mgt.core.archival.dao.*; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; public class ArchivalServiceImpl implements ArchivalService { private static Log log = LogFactory.getLog(ArchivalServiceImpl.class); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/dao/ArchivalDestinationDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/dao/ArchivalDestinationDAOFactory.java index 9554b9932f6..8b68e7a3c33 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/dao/ArchivalDestinationDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/dao/ArchivalDestinationDAOFactory.java @@ -20,8 +20,8 @@ package org.wso2.carbon.device.mgt.core.archival.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.core.archival.dao.impl.DataDeletionDAOImpl; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/dao/ArchivalSourceDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/dao/ArchivalSourceDAOFactory.java index 4ed5845f920..0f669a50eff 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/dao/ArchivalSourceDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/archival/dao/ArchivalSourceDAOFactory.java @@ -21,8 +21,8 @@ package org.wso2.carbon.device.mgt.core.archival.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.core.archival.dao.impl.ArchivalDAOImpl; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.archival.ArchivalTaskConfiguration; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java index 10699b2f4d4..bdc6f54e16f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java @@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAuthorizationResult; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java index 47b6caa11f5..027ddd2417c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java @@ -20,17 +20,13 @@ package org.wso2.carbon.device.mgt.core.config; import org.w3c.dom.Document; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.utils.CarbonUtils; -import org.xml.sax.SAXException; -import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; import java.io.File; /** diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java index 9a76db22ac6..34faf473050 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java @@ -21,12 +21,11 @@ package org.wso2.carbon.device.mgt.core.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; -import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.UnsupportedDatabaseEngineException; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; -import org.wso2.carbon.device.mgt.core.dao.impl.AbstractApplicationDAOImpl; import org.wso2.carbon.device.mgt.core.dao.impl.ApplicationMappingDAOImpl; import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl; import org.wso2.carbon.device.mgt.core.dao.impl.EnrollmentDAOImpl; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GroupManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GroupManagementDAOFactory.java index a962f91773d..d4d3f535879 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GroupManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GroupManagementDAOFactory.java @@ -21,9 +21,9 @@ package org.wso2.carbon.device.mgt.core.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; -import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.UnsupportedDatabaseEngineException; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.dao.impl.group.GenericGroupDAOImpl; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index 39937baae46..2bd9914ca84 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -25,8 +25,8 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 65decec77f1..c78e2204ccf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -21,7 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java index 2660ba757d5..7623ef1dcc9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java @@ -22,16 +22,14 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.EntityDoesNotExistException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.EntityDoesNotExistException; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; -import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationDAO; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationManagementDAOFactory.java index d280dd643ec..73548668794 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationManagementDAOFactory.java @@ -21,9 +21,9 @@ package org.wso2.carbon.device.mgt.core.notification.mgt.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; -import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.UnsupportedDatabaseEngineException; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl.*; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index eba0477fc33..83788448145 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -24,13 +24,13 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java index bfa28a66528..db253ed8ea7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java @@ -21,9 +21,9 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; -import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.UnsupportedDatabaseEngineException; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/privacy/PrivacyComplianceProvider.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/privacy/PrivacyComplianceProvider.java index e661dbb212b..2809c17cf1f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/privacy/PrivacyComplianceProvider.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/privacy/PrivacyComplianceProvider.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.core.privacy; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.PrivacyComplianceException; +import org.wso2.carbon.device.mgt.common.exceptions.PrivacyComplianceException; public interface PrivacyComplianceProvider { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/privacy/impl/PrivacyComplianceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/privacy/impl/PrivacyComplianceProviderImpl.java index fc461a8713d..4eb38939881 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/privacy/impl/PrivacyComplianceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/privacy/impl/PrivacyComplianceProviderImpl.java @@ -24,9 +24,9 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.PrivacyComplianceException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.PrivacyComplianceException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.privacy.PrivacyComplianceProvider; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java index 4f79999c8e0..28bdf863b78 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java @@ -20,8 +20,8 @@ package org.wso2.carbon.device.mgt.core.push.notification.mgt.task; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 3fa92a1aed7..47be9083b79 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -19,16 +19,16 @@ package org.wso2.carbon.device.mgt.core.service; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceTypeNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceTypeNotFoundException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.FeatureManager; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; -import org.wso2.carbon.device.mgt.common.UserNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index ecb7463be27..965dffb2870 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -34,22 +34,22 @@ import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublish import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceEnrollmentInfoNotification; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManager; -import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.DeviceNotification; import org.wso2.carbon.device.mgt.common.DevicePropertyNotification; -import org.wso2.carbon.device.mgt.common.DeviceTypeNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceTypeNotFoundException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.common.InitialOperationConfig; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; -import org.wso2.carbon.device.mgt.common.UserNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java index 731075a07ff..182606eaa51 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.core.service; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index df491dc5594..62a5a7982c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -25,11 +25,11 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java index 101e549c633..667f65b57ce 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java @@ -24,7 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java index f411c3d9f84..7fd52fa9718 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.core.task.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java index 602e656f90e..2e59448a447 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java @@ -23,8 +23,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index 44701e6f47d..14a00443464 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -26,11 +26,11 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; @@ -47,7 +47,6 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; -import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants; import org.wso2.carbon.device.mgt.core.operation.mgt.util.DeviceIDHolder; import org.wso2.carbon.user.api.TenantManager; import org.wso2.carbon.user.api.UserStoreException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMAndroidOperationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java similarity index 94% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMAndroidOperationUtil.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java index 64b215162c3..85d3cb573d3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMAndroidOperationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java @@ -16,15 +16,16 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.util; +package org.wso2.carbon.device.mgt.core.util; +import org.wso2.carbon.device.mgt.common.MDMAppConstants; import org.wso2.carbon.device.mgt.common.app.mgt.android.AppStoreApplication; import org.wso2.carbon.device.mgt.common.app.mgt.android.EnterpriseApplication; import org.wso2.carbon.device.mgt.common.app.mgt.android.WebApplication; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; -import org.wso2.carbon.device.mgt.jaxrs.beans.MobileApp; -import org.wso2.carbon.device.mgt.jaxrs.exception.UnknownApplicationTypeException; +import org.wso2.carbon.device.mgt.common.app.mgt.MobileApp; +import org.wso2.carbon.device.mgt.common.exceptions.UnknownApplicationTypeException; /** * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMIOSOperationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMIOSOperationUtil.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMIOSOperationUtil.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMIOSOperationUtil.java index cebe68a5a54..c057a01de7b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/MDMIOSOperationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMIOSOperationUtil.java @@ -16,13 +16,14 @@ * under the License. */ -package org.wso2.carbon.device.mgt.jaxrs.util; +package org.wso2.carbon.device.mgt.core.util; +import org.wso2.carbon.device.mgt.common.MDMAppConstants; import org.wso2.carbon.device.mgt.common.app.mgt.ios.AppStoreApplication; import org.wso2.carbon.device.mgt.common.app.mgt.ios.EnterpriseApplication; import org.wso2.carbon.device.mgt.common.app.mgt.ios.RemoveApplication; import org.wso2.carbon.device.mgt.common.app.mgt.ios.WebClip; -import org.wso2.carbon.device.mgt.jaxrs.beans.MobileApp; +import org.wso2.carbon.device.mgt.common.app.mgt.MobileApp; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java index cd39bd57b51..c8754d37158 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java @@ -20,9 +20,8 @@ package org.wso2.carbon.device.mgt.core; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; -import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerServiceImpl; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index d9449f6a498..e0b3de1c406 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.general.GeneralConfig; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java index 47a01c9e592..72c23ee6433 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java @@ -17,6 +17,7 @@ package org.wso2.carbon.device.mgt.core; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java index 862156d7afb..1be7f4881ef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java @@ -22,9 +22,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.Application; -import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceTest.java index 5a47f0f8779..e884dc47281 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceTest.java @@ -30,8 +30,8 @@ import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAuthorizationResult; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/cache/DeviceCacheManagerImplTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/cache/DeviceCacheManagerImplTest.java index 4d6fa893759..567a435ab68 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/cache/DeviceCacheManagerImplTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/cache/DeviceCacheManagerImplTest.java @@ -25,7 +25,7 @@ import org.testng.annotations.Test; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.cache.impl.DeviceCacheManagerImpl; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java index b5565814b4e..d991f92957e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java @@ -29,7 +29,7 @@ import org.testng.annotations.Parameters; import org.w3c.dom.Document; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.TestUtils; import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DevicePersistTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DevicePersistTests.java index c1143b91981..129b1255fac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DevicePersistTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DevicePersistTests.java @@ -26,7 +26,7 @@ import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.core.TestUtils; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java index 442e4ae06ac..f75522800af 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java @@ -25,8 +25,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java index 3bfa6f4a49d..f440f3a7384 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java @@ -24,7 +24,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.EntityDoesNotExistException; +import org.wso2.carbon.device.mgt.common.exceptions.EntityDoesNotExistException; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNegativeDBOperationTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNegativeDBOperationTest.java index b55c77d0853..fc790f09a90 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNegativeDBOperationTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNegativeDBOperationTest.java @@ -24,7 +24,7 @@ import org.testng.annotations.Test; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNoDBSchemaTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNoDBSchemaTests.java index 92310af40c1..4b92b1a39ab 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNoDBSchemaTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNoDBSchemaTests.java @@ -25,8 +25,8 @@ import org.testng.annotations.Test; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java index b1734948d42..a71360c85b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java @@ -27,9 +27,9 @@ import org.testng.annotations.Test; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/ScheduledTaskOperationTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/ScheduledTaskOperationTests.java index d064497b0aa..1a5dc523db1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/ScheduledTaskOperationTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/ScheduledTaskOperationTests.java @@ -24,8 +24,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTaskTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTaskTest.java index 64a01788bfe..b5992a7e8d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTaskTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTaskTest.java @@ -23,7 +23,7 @@ import org.mockito.Mockito; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java index 9a2099b6cc6..0c027ee0810 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java @@ -24,7 +24,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.search.Condition; import org.wso2.carbon.device.mgt.common.search.SearchContext; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java index ffff69c6a51..480b970e5a5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java @@ -17,18 +17,17 @@ package org.wso2.carbon.device.mgt.core.service; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.mockito.Mock; import org.mockito.Mockito; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; @@ -63,7 +62,6 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Properties; -import javax.sql.DataSource; public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceNegativeTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceNegativeTest.java index ccaf84652e7..528b64a5e8b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceNegativeTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceNegativeTest.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.core.service; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException; import org.wso2.carbon.device.mgt.core.TestUtils; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java index e1c3be07cc0..02296282026 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java @@ -23,10 +23,10 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManagerTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManagerTest.java index 4b558f07086..eb6e6a4d2bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManagerTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManagerTest.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.task; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.testng.Assert; import org.testng.annotations.AfterClass; @@ -27,9 +26,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.MonitoringOperation; -import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java index b84d1658148..e5879db164f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java @@ -24,7 +24,7 @@ import org.w3c.dom.Document; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.FeatureManager; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java index ca245a1d001..72657f55771 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.device.type.template; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; import org.wso2.carbon.device.mgt.common.InitialOperationConfig; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java index 091123ab7da..9d9b038168c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java @@ -18,7 +18,7 @@ */ package org.wso2.carbon.device.mgt.extensions.device.type.template.feature; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Operation; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java index 0d177c6c265..4307316c36e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java @@ -25,7 +25,7 @@ import org.testng.annotations.Test; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DataSource; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java index efc36afe078..dd27329f99e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java @@ -24,16 +24,13 @@ import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.base.MultitenantConstants; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; import org.wso2.carbon.device.mgt.common.InitialOperationConfig; -import org.wso2.carbon.device.mgt.common.InitialOperationConfig; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig; -import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; -import org.wso2.carbon.device.mgt.common.general.GeneralConfig; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerTest.java index 0e61a40e8bf..05baffd1c3b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerTest.java @@ -24,7 +24,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java index 09435166dc8..7e7e14efd29 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java @@ -23,7 +23,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java index 946f1c49a6a..11c2f317211 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -22,7 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java index f17ec30d059..78d5434d01e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java @@ -21,8 +21,8 @@ package org.wso2.carbon.policy.mgt.core.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; -import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.UnsupportedDatabaseEngineException; import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.policy.mgt.core.dao.impl.MonitoringDAOImpl; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java index e941312da1d..2cb4a295734 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java @@ -21,7 +21,7 @@ package org.wso2.carbon.policy.mgt.core.enforcement; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java index fa02314460f..03caa2b0012 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java @@ -22,7 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java index cdb72095d7e..050bfa88557 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java @@ -39,6 +39,8 @@ package org.wso2.carbon.policy.mgt.core.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java index 6dd0ebbc5a0..20fddc6cdbd 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java @@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java index 2ccbe94778e..ec9e7ef806a 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java @@ -20,11 +20,10 @@ package org.wso2.carbon.policy.mgt.core.mgt.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index a656b66ea85..59c34abfa2f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -22,8 +22,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java index f489a1386a6..550334d946c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java @@ -23,7 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/BasePolicyManagementDAOTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/BasePolicyManagementDAOTest.java index ef4d9ea831c..c55155cd7a7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/BasePolicyManagementDAOTest.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/BasePolicyManagementDAOTest.java @@ -29,8 +29,8 @@ import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/MonitoringTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/MonitoringTestCase.java index e78f58ef8f3..58fadeef8da 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/MonitoringTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/MonitoringTestCase.java @@ -22,11 +22,10 @@ package org.wso2.carbon.policy.mgt.core; import junit.framework.Assert; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java index 032acdb8787..9142aa45b4d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java @@ -24,6 +24,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyCriterion; import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java index 2c47b72b211..ac7fa971f49 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java @@ -26,7 +26,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImplTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImplTest.java index cbc3f5c0bb7..e88343bc2de 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImplTest.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImplTest.java @@ -24,6 +24,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImplTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImplTest.java index 9d2e67be3a3..6d92754b3f7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImplTest.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImplTest.java @@ -26,7 +26,7 @@ import org.testng.annotations.Test; import org.testng.internal.collections.Pair; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImplTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImplTest.java index 6da2d3ca0ac..ee05fddbc3d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImplTest.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImplTest.java @@ -12,8 +12,8 @@ import org.testng.internal.collections.Pair; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.policy.mgt.DeviceGroupWrapper; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImplTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImplTest.java index 23898f4a523..ccbce497496 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImplTest.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImplTest.java @@ -25,7 +25,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.testng.internal.collections.Pair; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java index 0f76246da64..4d40c434499 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java @@ -17,7 +17,7 @@ */ package org.wso2.carbon.policy.mgt.core.mock; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; import org.wso2.carbon.device.mgt.common.InitialOperationConfig; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManager.java index d9477b5119f..f096589ab34 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManager.java @@ -19,7 +19,7 @@ package org.wso2.carbon.policy.mgt.core.mock; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.FeatureManager; diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticatorTest.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticatorTest.java index 05d8bf1eb07..48f0d2342cc 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticatorTest.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/test/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticatorTest.java @@ -46,7 +46,7 @@ import org.wso2.carbon.certificate.mgt.core.scep.TenantedDeviceWrapper; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementServiceImpl; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.webapp.authenticator.framework.AuthenticationInfo; From dd7803522780286d1a16ecae559c1be3f133e4d1 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 30 May 2019 21:43:17 +0530 Subject: [PATCH 06/14] Improve APPM subscription handeling --- .../common/ApplicationInstallResponse.java | 22 +- .../mgt/common/SubscribingDeviceIdHolder.java | 22 +- .../common/services/SubscriptionManager.java | 56 +-- .../core/impl/SubscriptionManagerImpl.java | 438 ++++-------------- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 + .../services/SubscriptionManagementAPI.java | 300 +----------- .../impl/SubscriptionManagementAPIImpl.java | 115 +---- 7 files changed, 139 insertions(+), 816 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationInstallResponse.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationInstallResponse.java index 6bc83c9a57e..0b60de01ddb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationInstallResponse.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationInstallResponse.java @@ -26,11 +26,11 @@ import java.util.List; public class ApplicationInstallResponse { @ApiModelProperty( - name = "alreadyInstalledDevices", + name = "ignoredDeviceIdentifiers", value = "List of devices that application release is already installed.", dataType = "List[org.wso2.carbon.device.mgt.common.DeviceIdentifier]" ) - private List alreadyInstalledDevices; + private List ignoredDeviceIdentifiers; @ApiModelProperty( name = "errorDevices", @@ -44,22 +44,22 @@ public class ApplicationInstallResponse { name = "activity", value = "Activity corresponding to the operation" ) - private Activity activity; + private List activities; - public Activity getActivity() { - return activity; + public List getActivities() { + return activities; } - public void setActivity(Activity activity) { - this.activity = activity; + public void setActivities(List activity) { + this.activities = activity; } - public List getAlreadyInstalledDevices() { - return alreadyInstalledDevices; + public List getIgnoredDeviceIdentifiers() { + return ignoredDeviceIdentifiers; } - public void setAlreadyInstalledDevices(List alreadyInstalledDevices) { - this.alreadyInstalledDevices = alreadyInstalledDevices; + public void setIgnoredDeviceIdentifiers(List ignoredDeviceIdentifiers) { + this.ignoredDeviceIdentifiers = ignoredDeviceIdentifiers; } public List getErrorDevices() { return errorDevices; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java index 6c7a3cb04b4..82e87c8b680 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java @@ -20,30 +20,28 @@ package org.wso2.carbon.device.application.mgt.common; import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; public class SubscribingDeviceIdHolder { - private List installedDevices = new ArrayList<>(); - private Map compatibleDevices = new HashMap<>(); + private Map subscribedDevices = new HashMap<>(); + private Map subscribableDevices = new HashMap<>(); private Map deviceSubscriptions = new HashMap<>(); - public List getInstalledDevices() { - return installedDevices; + public Map getSubscribedDevices() { + return subscribedDevices; } - public void setInstalledDevices(List installedDevices) { - this.installedDevices = installedDevices; + public void setSubscribedDevices(Map subscribedDevices) { + this.subscribedDevices = subscribedDevices; } - public Map getCompatibleDevices() { - return compatibleDevices; + public Map getSubscribableDevices() { + return subscribableDevices; } - public void setCompatibleDevices(Map compatibleDevices) { - this.compatibleDevices = compatibleDevices; + public void setSubscribableDevices(Map subscribableDevices) { + this.subscribableDevices = subscribableDevices; } public Map getDeviceSubscriptions() { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java index 1f0e86b5842..e1c10ea9a9c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java @@ -19,9 +19,7 @@ package org.wso2.carbon.device.application.mgt.common.services; import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse; -import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponseTmp; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.util.List; @@ -29,56 +27,6 @@ import java.util.List; * This interface manages all the operations related with ApplicationDTO Subscription. */ public interface SubscriptionManager { - /** - * To install an application to given list of devices. - * @param applicationUUID ID of the application to install - * @param deviceList list of device ID's to install the application - * @return {@link ApplicationInstallResponse} object which contains installed application and devices - * @throws ApplicationManagementException if unable to install the application to the given devices - */ - ApplicationInstallResponse installApplicationForDevices(String applicationUUID, List deviceList) - throws ApplicationManagementException; - - ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List params, String subType) - throws ApplicationManagementException; - - /** - * To install an application to given list of users. - * @param applicationUUID ID of the application to install - * @param userList list of users to install the application - * @return {@link ApplicationInstallResponseTmp} object which contains installed application and devices - * @throws ApplicationManagementException if unable to install the application to devices belong to given users - */ - ApplicationInstallResponse installApplicationForUsers(String applicationUUID, List userList) - throws ApplicationManagementException; - - /** - * To install an application to given list of roles. - * @param applicationUUID ID of the application to install - * @param roleList list of roles to install the application - * @return {@link ApplicationInstallResponseTmp} object which contains installed application and devices - * @throws ApplicationManagementException if unable to install the application to devices belong to given roles - */ - ApplicationInstallResponseTmp installApplicationForRoles(String applicationUUID, List roleList) - throws ApplicationManagementException; - - /** - * To install an application to given list of roles. - * @param applicationUUID ID of the application to install - * @param deviceGroupList list of device groups to install the application - * @return {@link ApplicationInstallResponseTmp} object which contains installed application and devices - * @throws ApplicationManagementException if unable to install the application to devices belong to given groups - */ - ApplicationInstallResponseTmp installApplicationForGroups(String applicationUUID, List deviceGroupList) - throws ApplicationManagementException; - - /** - * To uninstall an application from a given list of devices. - * @param applicationUUID ApplicationDTO ID - * @param deviceList Device list - * @return Failed Device List which the application was unable to uninstall - * @throws ApplicationManagementException ApplicationDTO Management Exception - */ - List uninstallApplication(String applicationUUID, List deviceList) - throws ApplicationManagementException; + ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List params, String subType, + String action) throws ApplicationManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 9141cd083bd..1a4d2991e5a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -21,7 +21,6 @@ import org.apache.commons.lang.StringUtils; 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.AppOperation; import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse; import org.wso2.carbon.device.application.mgt.common.ApplicationType; import org.wso2.carbon.device.application.mgt.common.DeviceTypes; @@ -29,13 +28,11 @@ import org.wso2.carbon.device.application.mgt.common.SubAction; import org.wso2.carbon.device.application.mgt.common.SubsciptionType; import org.wso2.carbon.device.application.mgt.common.SubscribingDeviceIdHolder; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; -import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponseTmp; import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; @@ -51,23 +48,18 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.HelperUtil; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.MobileApp; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.exceptions.UnknownApplicationTypeException; -import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; -import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; -import org.wso2.carbon.device.mgt.core.operation.mgt.util.DeviceIDHolder; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; -import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.MDMAndroidOperationUtil; import org.wso2.carbon.device.mgt.core.util.MDMIOSOperationUtil; @@ -84,7 +76,6 @@ import java.util.stream.Collectors; public class SubscriptionManagerImpl implements SubscriptionManager { private static final Log log = LogFactory.getLog(SubscriptionManagerImpl.class); - private static final String INSTALL_APPLICATION = "INSTALL_APPLICATION"; private SubscriptionDAO subscriptionDAO; private ApplicationDAO applicationDAO; private LifecycleStateManager lifecycleStateManager; @@ -95,32 +86,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); } - @Override - public ApplicationInstallResponse installApplicationForDevices(String applicationUUID, - List deviceIdentifiers) throws ApplicationManagementException { - if (log.isDebugEnabled()) { - log.debug("Install application which has UUID: " + applicationUUID + " to " + deviceIdentifiers.size() - + "devices."); - } - if (deviceIdentifiers.isEmpty()){ - String msg = "In order to install application release which has UUID " + applicationUUID + ", you should " - + "provide list of device identifiers. But found an empty list of identifiers."; - log.error(msg); - throw new BadRequestException(msg); - } - ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); - DeviceIDHolder filteredDeviceHolder = filterDeviceIdentifiers(applicationDTO, deviceIdentifiers); - List errorDeviceIdentifiers = filteredDeviceHolder.getErrorDeviceIdList(); - ApplicationInstallResponse applicationInstallResponse = performBulkAppInstallation(applicationUUID, - filteredDeviceHolder.getValidDeviceIDList(), SubsciptionType.DEVICE.toString()); - applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers); - return applicationInstallResponse; - } - - @Override public ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List params, - String subType) throws ApplicationManagementException { + String subType, String action) throws ApplicationManagementException { if (log.isDebugEnabled()) { log.debug("Install application release which has UUID " + applicationUUID + " to " + params.size() + " users."); @@ -149,12 +117,31 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List filteredDevices = new ArrayList<>(); List devices = new ArrayList<>(); List subscribers = new ArrayList<>(); + List errorDeviceIdentifiers = new ArrayList<>(); + ApplicationInstallResponse applicationInstallResponse; ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); - if (SubsciptionType.DEVICE.toString().equals(subType)) { for (T param : params) { DeviceIdentifier deviceIdentifier = (DeviceIdentifier) param; + if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils + .isEmpty(deviceIdentifier.getType())) { + log.warn("Found a device identifier which has either empty identity of the device or empty" + + " device type. Hence ignoring the device identifier. "); + } + if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { + DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); + + if (!deviceType.getName().equals(deviceIdentifier.getType())) { + String msg = + "Found a device identifier which is not matched with the application device Type. " + + "Application device type is " + deviceType.getName() + " and the " + + "identifier of which has a " + "different device type is " + + deviceIdentifier.getId(); + log.warn(msg); + errorDeviceIdentifiers.add(deviceIdentifier); + } + } devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false)); } } else if (SubsciptionType.USER.toString().equals(subType)) { @@ -185,18 +172,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager { filteredDevices.add(device); } } -// if (SubsciptionType.DEVICE.toString().equals(subType)) { -// return installToDevices(deviceTypeName, filteredDevices, applicationDTO, subType, null); -// -// } - return installToDevices(deviceTypeName, filteredDevices, applicationDTO, subType, subscribers); + applicationInstallResponse = performActionOnDevices(deviceTypeName, filteredDevices, applicationDTO, + subType, subscribers, action); + + //todo add db insert to here } else { //todo improve this -// if (SubsciptionType.DEVICE.toString().equals(subType)) { -// return installToDevices(null, filteredDevices, applicationDTO, subType, null); -// } - return installToDevices(null, devices, applicationDTO, subType, subscribers); + applicationInstallResponse = performActionOnDevices(null, devices, applicationDTO, subType, + subscribers, action); + //todo add db insert to here } + applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers); + return applicationInstallResponse; } catch (DeviceManagementException e) { String msg = "Error occurred while getting devices of given users or given roles."; log.error(msg); @@ -208,56 +195,98 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } - @Override - public List uninstallApplication(String applicationUUID, - List deviceList) throws ApplicationManagementException { - return null; - } - - private ApplicationInstallResponse installToDevices(String deviceType, List devices, - ApplicationDTO applicationDTO, String subType, List subscribers) + private ApplicationInstallResponse performActionOnDevices(String deviceType, List devices, + ApplicationDTO applicationDTO, String subType, List subscribers, String action) throws ApplicationManagementException { SubscribingDeviceIdHolder subscribingDeviceIdHolder = getSubscribingDeviceIdHolder(devices); - if (subscribingDeviceIdHolder.getCompatibleDevices().isEmpty()) { + List activityList = new ArrayList<>(); + List deviceIdentifiers = new ArrayList<>(); + List ignoredDeviceIdentifiers = new ArrayList<>(); + Map> deviceIdentifierMap = new HashMap<>(); + + if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { + deviceIdentifiers = new ArrayList<>(subscribingDeviceIdHolder.getSubscribableDevices().keySet()); + ignoredDeviceIdentifiers = new ArrayList<>(subscribingDeviceIdHolder.getSubscribedDevices().keySet()); + + if (deviceIdentifiers.isEmpty()) { + ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); + applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers); + return applicationInstallResponse; + } + } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { + deviceIdentifiers = new ArrayList<>(subscribingDeviceIdHolder.getSubscribedDevices().keySet()); + ignoredDeviceIdentifiers = new ArrayList<>(subscribingDeviceIdHolder.getSubscribableDevices().keySet()); + if (deviceIdentifiers.isEmpty()) { + ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); + applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers); + return applicationInstallResponse; + } + } + + if (deviceType == null) { + for (DeviceIdentifier identifier : deviceIdentifiers) { + List identifiers; + if (!deviceIdentifierMap.containsKey(identifier.getType())) { + identifiers = new ArrayList<>(); + identifiers.add(identifier); + deviceIdentifierMap.put(identifier.getType(), identifiers); + } else { + identifiers = deviceIdentifierMap.get(identifier.getType()); + identifiers.add(identifier); + deviceIdentifierMap.put(identifier.getType(), identifiers); + } + } + + for (String type : deviceIdentifierMap.keySet()) { + Activity activity = addAppInstallOperationToDevices(applicationDTO, + new ArrayList<>(deviceIdentifierMap.get(type)), type); + activityList.add(activity); + } + ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); - applicationInstallResponse.setAlreadyInstalledDevices(subscribingDeviceIdHolder.getInstalledDevices()); + applicationInstallResponse.setActivities(activityList); + applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers); return applicationInstallResponse; } - Activity activity = addAppInstallOperationToDevices(applicationDTO, - new ArrayList<>(subscribingDeviceIdHolder.getCompatibleDevices().keySet()), deviceType); + //todo consider action + + Activity activity = addAppInstallOperationToDevices(applicationDTO, deviceIdentifiers, deviceType); + activityList.add(activity); ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); - applicationInstallResponse.setActivity(activity); - applicationInstallResponse.setAlreadyInstalledDevices(subscribingDeviceIdHolder.getInstalledDevices()); + applicationInstallResponse.setActivities(activityList); + applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers); + //todo addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity, - subscribingDeviceIdHolder.getCompatibleDevices(), + subscribingDeviceIdHolder.getSubscribableDevices(), new ArrayList<>(subscribingDeviceIdHolder.getDeviceSubscriptions().keySet()), subscribers, subType); return applicationInstallResponse; } private SubscribingDeviceIdHolder getSubscribingDeviceIdHolder(List devices) throws ApplicationManagementException { - List installedDevices = new ArrayList<>(); - Map compatibleDevices = new HashMap<>(); + Map subscribedDevices = new HashMap<>(); + Map subscribableDevices = new HashMap<>(); List filteredDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList()); + //get device subscriptions for given device id list. Map deviceSubscriptions = getDeviceSubscriptions(filteredDeviceIds); for (Device device : devices) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); DeviceSubscriptionDTO deviceSubscriptionDTO = deviceSubscriptions.get(device.getId()); if (deviceSubscriptionDTO != null && !deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED .toString().equals(deviceSubscriptionDTO.getStatus())) { - installedDevices.add(deviceIdentifier); + subscribedDevices.put(deviceIdentifier, device.getId()); } else { - compatibleDevices.put(deviceIdentifier, device.getId()); + subscribableDevices.put(deviceIdentifier, device.getId()); } } SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder(); - subscribingDeviceIdHolder.setCompatibleDevices(compatibleDevices); - subscribingDeviceIdHolder.setInstalledDevices(installedDevices); + subscribingDeviceIdHolder.setSubscribableDevices(subscribableDevices); + subscribingDeviceIdHolder.setSubscribedDevices(subscribedDevices); subscribingDeviceIdHolder.setDeviceSubscriptions(deviceSubscriptions); return subscribingDeviceIdHolder; } @@ -297,51 +326,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } - private DeviceIDHolder filterDeviceIdentifiers(ApplicationDTO applicationDTO, - List deviceIdentifiers) throws ApplicationManagementException { - List errorDeviceIdList = new ArrayList<>(); - List validDeviceIDList = new ArrayList<>(); - if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { - DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); - for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { - if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils.isEmpty(deviceIdentifier.getType())) { - log.warn("Found a device identifier which has either empty identity of the device or empty device " - + "type. Hence ignoring the device identifier. "); - continue; - } - if (!deviceType.getName().equals(deviceIdentifier.getType())) { - String msg = - "Found a device identifier which is not matched with the application device Type. Application " - + "device type is " + deviceType.getName() + " and the identifier of which has a " - + "different device type is " + deviceIdentifier.getId(); - log.warn(msg); - errorDeviceIdList.add(deviceIdentifier); - } else { - validDeviceIDList.add(deviceIdentifier); - } - } - } else { - for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { - if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils.isEmpty(deviceIdentifier.getType())) { - log.warn("Found a device identifier which has either empty identity of the device or empty device " - + "type. Hence ignoring the device identifier. "); - continue; - } - validDeviceIDList.add(deviceIdentifier); - } - } - - if (validDeviceIDList.isEmpty()) { - String msg = "Couldn't found at least one valid device identifier to install the application."; - log.error(msg); - throw new BadRequestException(msg); - } - DeviceIDHolder deviceIDHolder = new DeviceIDHolder(); - deviceIDHolder.setValidDeviceIDList(validDeviceIDList); - deviceIDHolder.setErrorDeviceIdList(errorDeviceIdList); - return deviceIDHolder; - } - private void addSubscriptions(int applicationReleaseId, Activity activity, Map compatibleDevices, List subDeviceIds, List subscribers, String subType) throws ApplicationManagementException { @@ -426,153 +410,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } - //todo remove below methods - - @Override public ApplicationInstallResponse installApplicationForUsers(String applicationUUID, - List userList) throws ApplicationManagementException { - if (log.isDebugEnabled()) { - log.debug("Install application release which has UUID " + applicationUUID + " to " + userList.size() - + " users."); - } - - //todo check valid user list - throw BadRequest exception - ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); - DeviceType appDeviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); - Map compatibleDevices = new HashMap<>(); - List installedDeviceIdentifiers = new ArrayList<>(); - Map deviceSubscriptions = new HashMap<>(); - - for (String user : userList) { - try { - List userDevices = HelperUtil.getDeviceManagementProviderService().getDevicesOfUser(user); - List filteredDevices = new ArrayList<>(); - - //todo improve for web clips - for (Device device : userDevices) { - if (appDeviceType.getName().equals(device.getType())) { - filteredDevices.add(device); - } - } - - SubscribingDeviceIdHolder subscribingDeviceIdHolder = getSubscribingDeviceIdHolder(filteredDevices); - compatibleDevices.putAll(subscribingDeviceIdHolder.getCompatibleDevices()); - deviceSubscriptions.putAll(subscribingDeviceIdHolder.getDeviceSubscriptions()); - installedDeviceIdentifiers.addAll(subscribingDeviceIdHolder.getInstalledDevices()); - } catch (DeviceManagementException e) { - String msg = "Error occurred when extracting the device list of user[" + user + "]."; - log.error(msg); - throw new ApplicationManagementException(msg, e); - } - } - - if (compatibleDevices.keySet().isEmpty()) { - ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); - applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers); - return applicationInstallResponse; - } - Activity activity = addAppInstallOperationToDevices(applicationDTO, new ArrayList<>(compatibleDevices.keySet()), - appDeviceType.getName()); - - ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); - applicationInstallResponse.setActivity(activity); - applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers); - - addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity, compatibleDevices, - new ArrayList<>(deviceSubscriptions.keySet()), userList, SubsciptionType.USER.toString()); - return applicationInstallResponse; - } - - //todo not implemented below code properly - - @Override public ApplicationInstallResponseTmp installApplicationForRoles(String applicationUUID, - List roleList) throws ApplicationManagementException { - if (log.isDebugEnabled()) { - log.debug("Install application: " + applicationUUID + " to " + roleList.size() + " roles."); - } - ApplicationManager applicationManager = DataHolder.getInstance().getApplicationManager(); - ApplicationDTO application = applicationManager.getApplicationByRelease(applicationUUID); - List deviceList = new ArrayList<>(); - for (String role : roleList) { - try { - List devicesOfRole = HelperUtil.getDeviceManagementProviderService().getAllDevicesOfRole(role); - devicesOfRole.stream() - .map(device -> new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())) - .forEach(deviceList::add); - if (log.isDebugEnabled()) { - log.debug(devicesOfRole.size() + " found for role: " + role); - } - } catch (DeviceManagementException e) { - throw new ApplicationManagementException( - "Error when extracting the device list from role[" + role + "].", e); - } - } - - ApplicationInstallResponseTmp response = installToDevicesTmp(application, deviceList); - - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - int applicationReleaseId = application.getApplicationReleaseDTOs().get(0).getId(); - - try { - ConnectionManagerUtil.openDBConnection(); - subscriptionDAO.subscribeRoleToApplication(tenantId, subscriber, roleList, application.getId(), - applicationReleaseId); - } catch (ApplicationManagementDAOException e) { - //todo - throw new ApplicationManagementException(""); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } - - return response; - } - - @Override public ApplicationInstallResponseTmp installApplicationForGroups(String applicationUUID, - List deviceGroupList) throws ApplicationManagementException { - if (log.isDebugEnabled()) { - log.debug("Install application: " + applicationUUID + " to " + deviceGroupList.size() + " groups."); - } - ApplicationManager applicationManager = DataHolder.getInstance().getApplicationManager(); - ApplicationDTO application = applicationManager.getApplicationByRelease(applicationUUID); - GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService(); - List groupList = new ArrayList<>(); - List deviceList = new ArrayList<>(); - for (String groupName : deviceGroupList) { - try { - DeviceGroup deviceGroup = groupManagementProviderService.getGroup(groupName); - groupList.add(deviceGroup); - int deviceCount = groupManagementProviderService.getDeviceCount(deviceGroup.getGroupId()); - List devicesOfGroups = groupManagementProviderService - .getDevices(deviceGroup.getGroupId(), 0, deviceCount); - devicesOfGroups.stream() - .map(device -> new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())) - .forEach(deviceList::add); - } catch (GroupManagementException e) { - throw new ApplicationManagementException( - "Error when extracting the device list from group[" + groupName + "].", e); - } - } - - ApplicationInstallResponseTmp response = installToDevicesTmp(application, deviceList); - - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - int applicationReleaseId = application.getApplicationReleaseDTOs().get(0).getId(); - - try { - ConnectionManagerUtil.openDBConnection(); - subscriptionDAO.subscribeGroupToApplication(tenantId, subscriber, groupList, application.getId(), - applicationReleaseId); - } catch (ApplicationManagementDAOException e) { - //todo - throw new ApplicationManagementException(""); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } - - return response; - } - private Activity addAppInstallOperationToDevices(ApplicationDTO application, List deviceIdentifierList, String deviceType) throws ApplicationManagementException { DeviceManagementProviderService deviceManagementProviderService = HelperUtil @@ -590,61 +427,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } - private ApplicationInstallResponseTmp installToDevicesTmp(ApplicationDTO application, - List deviceIdentifierList) throws ApplicationManagementException { - DeviceManagementProviderService deviceManagementProviderService = HelperUtil - .getDeviceManagementProviderService(); - - ApplicationInstallResponseTmp response = validateDevices(deviceIdentifierList); - /* - Group the valid device list by device type. Following lambda expression produces a map containing device type - as the key and the list of device identifiers as the corresponding value. - */ - Map> deviceTypeIdentifierMap = response.getSuccessfulDevices().stream() - .collect(Collectors.groupingBy(DeviceIdentifier::getType)); - - for (Map.Entry> entry : deviceTypeIdentifierMap.entrySet()) { - Operation operation = generateOperationPayloadByDeviceType(entry.getKey(), application, null); - try { - Activity activity = deviceManagementProviderService - .addOperation(entry.getKey(), operation, entry.getValue()); - response.setActivity(activity); - } catch (OperationManagementException e) { - response.setSuccessfulDevices(null); - response.setFailedDevices(deviceIdentifierList); - throw new ApplicationManagementException( - "Error occurred while adding the application install " + "operation to devices", e); - } catch (InvalidDeviceException e) { - //This exception should not occur because the validation has already been done. - throw new ApplicationManagementException("The list of device identifiers are invalid"); - } - } - - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - int applicationReleaseId = application.getApplicationReleaseDTOs().get(0).getId(); - try { - ConnectionManagerUtil.openDBConnection(); - List deviceList = new ArrayList<>(); - for (DeviceIdentifier deviceIdentifier : response.getSuccessfulDevices()) { - try { - deviceList.add(deviceManagementProviderService.getDevice(deviceIdentifier)); - } catch (DeviceManagementException e) { - log.error("Unable to fetch device for device identifier: " + deviceIdentifier.toString()); - } - } - subscriptionDAO.subscribeDeviceToApplicationTmp(tenantId, subscriber, deviceList, application.getId(), - applicationReleaseId, String.valueOf(AppOperation.InstallState.UNINSTALLED)); - } catch (ApplicationManagementDAOException e) { - //todo - throw new ApplicationManagementException(""); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } - - return response; - } - private Operation generateOperationPayloadByDeviceType(String deviceType, ApplicationDTO application, String action) throws ApplicationManagementException { try { @@ -684,38 +466,4 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } - /** - * Validates the preconditions which is required to satisfy from the device which is required to install the - * application. - *

- * This method check two preconditions whether the application type is compatible to install in the device and - * whether the device is enrolled in the system. - * - * @param deviceIdentifierList List of {@link DeviceIdentifier} which the validation happens - * @return {@link ApplicationInstallResponseTmp} which contains compatible and incompatible device identifiers - */ - private ApplicationInstallResponseTmp validateDevices(List deviceIdentifierList) { - ApplicationInstallResponseTmp applicationInstallResponseTmp = new ApplicationInstallResponseTmp(); - List failedDevices = new ArrayList<>(); - List compatibleDevices = new ArrayList<>(); - - for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) { - try { - if (!DeviceManagerUtil.isValidDeviceIdentifier(deviceIdentifier)) { - log.error("Device with ID: [" + deviceIdentifier.getId() + "] is not valid to install the " - + "application."); - applicationInstallResponseTmp.getFailedDevices().add(deviceIdentifier); - } - } catch (DeviceManagementException e) { - log.error("Error occurred while validating the device: [" + deviceIdentifier.getId() + "]", e); - failedDevices.add(deviceIdentifier); - } - compatibleDevices.add(deviceIdentifier); - } - applicationInstallResponseTmp.setFailedDevices(failedDevices); - applicationInstallResponseTmp.setSuccessfulDevices(compatibleDevices); - - return applicationInstallResponseTmp; - } - } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 7b060ca0894..661cc26f85b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -26,6 +26,7 @@ + @@ -53,6 +54,7 @@ + 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/SubscriptionManagementAPI.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/SubscriptionManagementAPI.java index 8ced8ef49ed..b6a4878789c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.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/SubscriptionManagementAPI.java @@ -20,7 +20,6 @@ package org.wso2.carbon.device.application.mgt.store.api.services; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import io.swagger.annotations.Extension; import io.swagger.annotations.ExtensionProperty; @@ -28,22 +27,14 @@ import io.swagger.annotations.Info; import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.Tag; import org.wso2.carbon.apimgt.annotations.api.Scopes; -import org.wso2.carbon.device.application.mgt.common.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.PaginationResult; -import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; -import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponseTmp; -import org.wso2.carbon.device.application.mgt.common.EnterpriseInstallationDetails; -import org.wso2.carbon.device.application.mgt.common.InstallationDetails; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import javax.validation.Valid; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; @@ -84,16 +75,14 @@ import java.util.List; } ) @Path("/subscription") -@Api(value = "Subscription Management", description = "This API carries all subscription management related " + - "operations " + - "such as install application to device, uninstall application from device, etc.") +@Api(value = "Subscription Management") @Produces(MediaType.APPLICATION_JSON) public interface SubscriptionManagementAPI { String SCOPE = "scope"; @POST - @Path("/install/{uuid}/devices") + @Path("/install/{uuid}/devices/{action}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( @@ -113,13 +102,19 @@ public interface SubscriptionManagementAPI { value = { }) - Response installApplicationForDevices( + Response performAppOperationForDevices( @ApiParam( name = "installationDetails", value = "The application ID and list of devices/users/roles", required = true ) @PathParam("uuid") String uuid, + @ApiParam( + name = "action", + value = "Performing action.", + required = true + ) + @PathParam("action") String action, @ApiParam( name = "installationDetails", value = "The application ID and list of devices/users/roles", @@ -149,7 +144,7 @@ public interface SubscriptionManagementAPI { value = { }) - Response performBulkAppInstallation( + Response performBulkAppOperation( @ApiParam( name = "uuid", value = "The application release UUID", @@ -175,279 +170,4 @@ public interface SubscriptionManagementAPI { ) @Valid List subscribers ); - - @POST - @Path("/install/{uuid}/devices") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Install an application for devices", - notes = "This will install an application to a given list of devices", - tags = "Subscription Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install") - }) - } - ) - @ApiResponses( - value = { - - }) - Response installApplicationForUsers( - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @PathParam("uuid") String uuid, - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @Valid List users - ); - - @POST - @Path("/install/{uuid}/devices") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Install an application for devices", - notes = "This will install an application to a given list of devices", - tags = "Subscription Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully add an operation to install application for user devices..", - response = PaginationResult.class, - responseContainer = "PaginationResult"), - @ApiResponse( - code = 400, - message = - "Bad Request. \n Found invalid payload with the request."), - @ApiResponse( - code = 403, - message = "Don't have permission to install application release."), - @ApiResponse( - code = 404, - message = "Not Found. \n Not found an application release for requested UUID."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while adding operation to install " - + "application for users.", - response = ErrorResponse.class) - - }) - Response installApplicationForRoles ( - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @PathParam("uuid") String uuid, - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @Valid List roles - ); - - @POST - @Path("/install/{uuid}/devices") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Install an application for devices", - notes = "This will install an application to a given list of devices", - tags = "Subscription Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install") - }) - } - ) - @ApiResponses( - value = { - - }) - Response installApplicationForGroups ( - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @PathParam("uuid") String uuid, - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @Valid List groups - ); - -// ########################### - - - @POST - @Path("/uninstall/{uuid}/devices") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Install an application for devices", - notes = "This will install an application to a given list of devices", - tags = "Subscription Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:subscription:uninstall") - }) - } - ) - @ApiResponses( - value = { - - }) - Response uninstallApplicationForDevices( - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @PathParam("uuid") String uuid, - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @Valid List deviceIdentifiers - ); - - @POST - @Path("/uninstall/{uuid}/devices") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Install an application for devices", - notes = "This will install an application to a given list of devices", - tags = "Subscription Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:subscription:uninstall") - }) - } - ) - @ApiResponses( - value = { - - }) - Response uninstallApplicationForUsers( - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @PathParam("uuid") String uuid, - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @Valid List users - ); - - @POST - @Path("/uninstall/{uuid}/devices") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Install an application for devices", - notes = "This will install an application to a given list of devices", - tags = "Subscription Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:subscription:uninstall") - }) - } - ) - @ApiResponses( - value = { - - }) - Response uninstallApplicationForRoles ( - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @PathParam("uuid") String uuid, - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @Valid List roles - ); - - @POST - @Path("/uninstall/{uuid}/devices") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Install an application for devices", - notes = "This will install an application to a given list of devices", - tags = "Subscription Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:subscription:uninstall") - }) - } - ) - @ApiResponses( - value = { - - }) - Response uninstallApplicationForGroups ( - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @PathParam("uuid") String uuid, - @ApiParam( - name = "installationDetails", - value = "The application ID and list of devices/users/roles", - required = true - ) - @Valid List groups - ); } 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/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java index 0a50229615b..94d70c08d10 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.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/SubscriptionManagementAPIImpl.java @@ -20,6 +20,7 @@ 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.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse; +import org.wso2.carbon.device.application.mgt.common.SubsciptionType; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; @@ -48,14 +49,15 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @Override @POST - @Path("/install/{uuid}/devices") - public Response installApplicationForDevices( + @Path("/install/{uuid}/devices/{action}") + public Response performAppOperationForDevices( @PathParam("uuid") String uuid, + @PathParam("action") String action, @Valid List deviceIdentifiers) { try { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); ApplicationInstallResponse response = subscriptionManager - .installApplicationForDevices(uuid, deviceIdentifiers); + .performBulkAppInstallation(uuid, deviceIdentifiers, SubsciptionType.DEVICE.toString(), action); return Response.status(Response.Status.OK).entity(response).build(); } catch (NotFoundException e) { String msg = "Couldn't found an application release for UUI: " + uuid; @@ -67,7 +69,8 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ log.error(msg); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { - String msg = "Application release is not in the installable state. Hence you are not permitted to install the aplication."; + String msg = "Application release is not in the installable state. Hence you are not permitted to install " + + "the application."; log.error(msg); return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -81,54 +84,15 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @Override @POST @Path("/install/{uuid}/{subType}/{action}") - public Response performBulkAppInstallation( + public Response performBulkAppOperation( @PathParam("uuid") String uuid, @PathParam("subType") String subType, - @PathParam("action") String sction, + @PathParam("action") String action, @Valid List subscribers) { try { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); - ApplicationInstallResponse response = subscriptionManager.performBulkAppInstallation(uuid, subscribers, subType); - return Response.status(Response.Status.OK).entity(response).build(); - } catch (NotFoundException e) { - String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload"; - log.error(msg); - return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); - } catch (BadRequestException e) { - String msg = "Found invalid payload for installing application which has UUID: " + uuid - + ". Hence verify the payload"; - log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); - } catch (ForbiddenException e) { - String msg = "Application release is not in the installable state. Hence you are not permitted to install " - + "the application."; - log.error(msg); - return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); - } catch (ApplicationManagementException e) { - String msg = "Error occurred while installing the application release which has UUID: " + uuid - + " for user devices"; - log.error(msg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - } - - //todo remove following unwanted APIs - - @Override - @POST - @Path("/install/{uuid}/users") - public Response installApplicationForUsers( - @PathParam("uuid") String uuid, - @Valid List users) { - if (users.isEmpty()) { - String msg = "In order to install application release which has UUID " + uuid + ", you should provide list " - + "of users. But found an empty list of users."; - log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); - } - try { - SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); - ApplicationInstallResponse response = subscriptionManager.installApplicationForUsers(uuid, users); + ApplicationInstallResponse response = subscriptionManager + .performBulkAppInstallation(uuid, subscribers, subType, action); return Response.status(Response.Status.OK).entity(response).build(); } catch (NotFoundException e) { String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload"; @@ -151,61 +115,4 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } - - @Override - @POST - @Path("/install/{uuid}/roles") - public Response installApplicationForRoles( - @PathParam("uuid") String uuid, - @Valid List roles) { - return Response.status(Response.Status.BAD_REQUEST).entity("").build(); - } - - @Override - @POST - @Path("/install/{uuid}/groups") - public Response installApplicationForGroups( - @PathParam("uuid") String uuid, - @Valid List groups) { - return Response.status(Response.Status.BAD_REQUEST).entity("").build(); - } - - - @Override - @POST - @Path("/uninstall/{uuid}/devices") - public Response uninstallApplicationForDevices( - @PathParam("uuid") String uuid, - @Valid List deviceIdentifiers) { - return Response.status(Response.Status.BAD_REQUEST).entity("").build(); - } - - @Override - @POST - @Path("/uninstall/{uuid}/users") - public Response uninstallApplicationForUsers( - @PathParam("uuid") String uuid, - @Valid List users) { - return Response.status(Response.Status.BAD_REQUEST).entity("").build(); - } - - @Override - @POST - @Path("/uninstall/{uuid}/roles") - public Response uninstallApplicationForRoles( - @PathParam("uuid") String uuid, - @Valid List roles) { - return Response.status(Response.Status.BAD_REQUEST).entity("").build(); - } - - @Override - @POST - @Path("/uninstall/{uuid}/groups") - public Response uninstallApplicationForGroups( - @PathParam("uuid") String uuid, - @Valid List groups) { - return Response.status(Response.Status.BAD_REQUEST).entity("").build(); - - } - } From f1c783cdb9ddf3fce497bd0b52214a48f6b88210 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 31 May 2019 12:59:27 +0530 Subject: [PATCH 07/14] Improve APPm sub storing method --- .../mgt/common/SubscribingDeviceIdHolder.java | 16 ++++----- .../core/impl/SubscriptionManagerImpl.java | 36 +++++++++++-------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java index 82e87c8b680..ac7dc9de7cd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java @@ -26,7 +26,7 @@ import java.util.Map; public class SubscribingDeviceIdHolder { private Map subscribedDevices = new HashMap<>(); private Map subscribableDevices = new HashMap<>(); - private Map deviceSubscriptions = new HashMap<>(); +// private Map deviceSubscriptions = new HashMap<>(); public Map getSubscribedDevices() { return subscribedDevices; @@ -44,11 +44,11 @@ public class SubscribingDeviceIdHolder { this.subscribableDevices = subscribableDevices; } - public Map getDeviceSubscriptions() { - return deviceSubscriptions; - } - - public void setDeviceSubscriptions(Map deviceSubscriptions) { - this.deviceSubscriptions = deviceSubscriptions; - } +// public Map getDeviceSubscriptions() { +// return deviceSubscriptions; +// } +// +// public void setDeviceSubscriptions(Map deviceSubscriptions) { +// this.deviceSubscriptions = deviceSubscriptions; +// } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 1a4d2991e5a..f83a2788f0c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -131,7 +131,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); - if (!deviceType.getName().equals(deviceIdentifier.getType())) { String msg = "Found a device identifier which is not matched with the application device Type. " @@ -238,9 +237,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } - for (String type : deviceIdentifierMap.keySet()) { + for (Map.Entry> entry : deviceIdentifierMap.entrySet()) { Activity activity = addAppInstallOperationToDevices(applicationDTO, - new ArrayList<>(deviceIdentifierMap.get(type)), type); + new ArrayList<>(entry.getValue()), entry.getKey()); activityList.add(activity); } @@ -259,9 +258,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers); //todo - addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity, - subscribingDeviceIdHolder.getSubscribableDevices(), - new ArrayList<>(subscribingDeviceIdHolder.getDeviceSubscriptions().keySet()), subscribers, subType); + addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity, subscribingDeviceIdHolder, + subscribers, subType, action); return applicationInstallResponse; } @@ -287,7 +285,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder(); subscribingDeviceIdHolder.setSubscribableDevices(subscribableDevices); subscribingDeviceIdHolder.setSubscribedDevices(subscribedDevices); - subscribingDeviceIdHolder.setDeviceSubscriptions(deviceSubscriptions); +// subscribingDeviceIdHolder.setDeviceSubscriptions(deviceSubscriptions); return subscribingDeviceIdHolder; } @@ -326,9 +324,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + //todo pass SubscribingDeviceIdHolder and action private void addSubscriptions(int applicationReleaseId, Activity activity, - Map compatibleDevices, List subDeviceIds, List subscribers, - String subType) throws ApplicationManagementException { + SubscribingDeviceIdHolder subscribingDeviceIdHolder, List subscribers, String subType, String action) + throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); try { @@ -337,6 +336,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List deviceSubscriptingIds; if (SubsciptionType.USER.toString().equals(subType)) { + //todo check action List subscribedUsers = subscriptionDAO.getSubscribedUsernames(subscribers, tenantId); if (!subscribedUsers.isEmpty()) { subscriptionDAO @@ -352,16 +352,22 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List activityStatuses = activity.getActivityStatus(); for (ActivityStatus status : activityStatuses) { if (status.getStatus().equals(ActivityStatus.Status.PENDING)) { - deviceIds.add(compatibleDevices.get(status.getDeviceIdentifier())); + //todo +// deviceIds.add(compatibleDevices.get(status.getDeviceIdentifier())); } } int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]); - if (!subDeviceIds.isEmpty()) { - deviceResubscribingIds = subscriptionDAO.updateDeviceSubscription(subscriber, subDeviceIds, subType, - Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); - deviceIds.removeAll(subDeviceIds); - } + //todo if INSTALL get Ids of subscribable devices and update those ids and insert other ids + + + //todo + +// if (!subDeviceIds.isEmpty()) { +// deviceResubscribingIds = subscriptionDAO.updateDeviceSubscription(subscriber, subDeviceIds, subType, +// Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); +// deviceIds.removeAll(subDeviceIds); +// } deviceSubscriptingIds = subscriptionDAO .subscribeDeviceToApplication(subscriber, deviceIds, subType, Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); From 9dad03b7c90a6b77690ca1ca95aa114f5d069063 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 31 May 2019 18:31:55 +0530 Subject: [PATCH 08/14] Improve category adding API --- .../core/dao/impl/application/GenericApplicationDAOImpl.java | 2 +- .../admin/ApplicationManagementPublisherAdminAPIImpl.java | 2 +- .../src/main/resources/conf/application-mgt.xml | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 587a5cafb74..4840cf1e5cc 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -813,7 +813,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { Connection conn = this.getDBConnection(); List distinctCategoryIds = new ArrayList<>(); - String sql = "SELECT DISTINCT AP_APP_CATEGORY.ID AS ID FROM AP_APP_CATEGORY"; + String sql = "SELECT DISTINCT AP_APP_CATEGORY_ID AS ID FROM AP_APP_CATEGORY_MAPPING;"; try (PreparedStatement ps = conn.prepareStatement(sql)) { try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { 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/admin/ApplicationManagementPublisherAdminAPIImpl.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/admin/ApplicationManagementPublisherAdminAPIImpl.java index 9890d037b8b..ddca629ac66 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/admin/ApplicationManagementPublisherAdminAPIImpl.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/admin/ApplicationManagementPublisherAdminAPIImpl.java @@ -43,7 +43,7 @@ import java.util.List; * Implementation of Application Management related APIs. */ @Produces({"application/json"}) -@Path("/applications") +@Path("/admin/applications") public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationManagementPublisherAdminAPI { private static Log log = LogFactory.getLog(ApplicationManagementPublisherAdminAPIImpl.class); 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 2d6dc36c31e..11ce3c44c09 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 @@ -151,6 +151,10 @@ perm:app:publisher:view perm:app:publisher:update perm:app:store:view + perm:app:subscription:install + perm:app:subscription:uninstall + perm:admin:app:review:update + perm:admin:app:publisher:update app-mgt From cf658bf96dc2cae728d0e06f56e28ddb700fc41a Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sat, 1 Jun 2019 09:11:39 +0530 Subject: [PATCH 09/14] Imporove APPM subscriptions --- .../mgt/common/SubscribingDeviceIdHolder.java | 11 - .../mgt/common/dto/DeviceSubscriptionDTO.java | 6 +- .../mgt/core/dao/SubscriptionDAO.java | 64 ++-- .../GenericSubscriptionDAOImpl.java | 288 +++++++++++------- .../mgt/core/impl/MAMDeviceConnectorImpl.java | 125 -------- .../core/impl/SubscriptionManagerImpl.java | 191 ++++++------ .../application/mgt/core/util/APIUtil.java | 67 ++++ .../application/mgt/core/util/DAOUtil.java | 2 +- .../dbscripts/cdm/application-mgt/h2.sql | 6 +- .../dbscripts/cdm/application-mgt/mysql.sql | 23 +- 10 files changed, 385 insertions(+), 398 deletions(-) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/MAMDeviceConnectorImpl.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java index ac7dc9de7cd..3f2866e8f71 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/SubscribingDeviceIdHolder.java @@ -17,7 +17,6 @@ package org.wso2.carbon.device.application.mgt.common; -import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.util.HashMap; @@ -26,8 +25,6 @@ import java.util.Map; public class SubscribingDeviceIdHolder { private Map subscribedDevices = new HashMap<>(); private Map subscribableDevices = new HashMap<>(); -// private Map deviceSubscriptions = new HashMap<>(); - public Map getSubscribedDevices() { return subscribedDevices; } @@ -43,12 +40,4 @@ public class SubscribingDeviceIdHolder { public void setSubscribableDevices(Map subscribableDevices) { this.subscribableDevices = subscribableDevices; } - -// public Map getDeviceSubscriptions() { -// return deviceSubscriptions; -// } -// -// public void setDeviceSubscriptions(Map deviceSubscriptions) { -// this.deviceSubscriptions = deviceSubscriptions; -// } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/DeviceSubscriptionDTO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/DeviceSubscriptionDTO.java index c2ea605ab0c..58809c1b2ed 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/DeviceSubscriptionDTO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/DeviceSubscriptionDTO.java @@ -27,7 +27,7 @@ public class DeviceSubscriptionDTO { private boolean isUnsubscribed; private String unsubscribedBy; private Timestamp unsubscribedTimestamp; - private String subscribedFrom; + private String actionTriggeredFrom; private String status; private int deviceId; @@ -59,9 +59,9 @@ public class DeviceSubscriptionDTO { this.unsubscribedTimestamp = unsubscribedTimestamp; } - public String getSubscribedFrom() { return subscribedFrom; } + public String getActionTriggeredFrom() { return actionTriggeredFrom; } - public void setSubscribedFrom(String subscribedFrom) { this.subscribedFrom = subscribedFrom; } + public void setActionTriggeredFrom(String actionTriggeredFrom) { this.actionTriggeredFrom = actionTriggeredFrom; } public String getStatus() { return status; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java index 6947616888b..0e77e38b8a9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java @@ -23,9 +23,7 @@ import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,24 +33,12 @@ import java.util.Map; */ public interface SubscriptionDAO { - /** - * Adds a mapping between devices and the application which the application is installed on. - * - * @param tenantId id of the tenant - * @param subscribedBy username of the user who subscribe the application - * @param deviceList List of {@link Device} which the application is installed on - * @param appId id of the {@link ApplicationDTO} which installs - * @param releaseId id of the {@link ApplicationReleaseDTO} - * @throws ApplicationManagementDAOException If unable to add a mapping between device and application - */ - void subscribeDeviceToApplicationTmp(int tenantId, String subscribedBy, List deviceList, int appId, - int releaseId, String installStatus) throws ApplicationManagementDAOException; - - List subscribeDeviceToApplication(String subscribedBy, List deviceIds, String subscribedFrom, + List addDeviceSubscription(String subscribedBy, List deviceIds, String subscribedFrom, String installStatus, int releaseId, int tenantId ) throws ApplicationManagementDAOException; - List updateDeviceSubscription(String subscribedBy, List deviceIds, - String subscribedFrom, String installStatus, int releaseId, int tenantId) throws ApplicationManagementDAOException; + List updateDeviceSubscription(String updateBy, List deviceIds, boolean isUnsubscribed, + String actionTriggeredFrom, String installStatus, int releaseId, int tenantId) + throws ApplicationManagementDAOException; void addOperationMapping (int operationId, List deviceSubscriptionId, int tenantId) throws ApplicationManagementDAOException; @@ -62,40 +48,18 @@ public interface SubscriptionDAO { * * @param tenantId id of the tenant * @param subscribedBy username of the user who subscribe the application - * @param userList list of user names of the users whose devices are subscribed to the application + * @param users list of user names of the users whose devices are subscribed to the application * @param releaseId id of the {@link ApplicationReleaseDTO} * @throws ApplicationManagementDAOException If unable to add a mapping between device and application */ - void subscribeUserToApplication(int tenantId, String subscribedBy, List userList, int releaseId) + void addUserSubscriptions(int tenantId, String subscribedBy, List users, int releaseId) throws ApplicationManagementDAOException; - /** - * Adds a mapping between user and the application which the application is installed on. This mapping will be - * added when an enterprise installation triggered to the role. - * - * @param tenantId id of the tenant - * @param subscribedBy username of the user who subscribe the application - * @param roleList list of roles which belongs devices are subscribed to the application - * @param appId id of the {@link ApplicationDTO} which installs - * @param releaseId id of the {@link ApplicationReleaseDTO} - * @throws ApplicationManagementDAOException If unable to add a mapping between device and application - */ - void subscribeRoleToApplication(int tenantId, String subscribedBy, List roleList, int appId, int releaseId) + void addRoleSubscriptions(int tenantId, String subscribedBy, List roles, int releaseId) throws ApplicationManagementDAOException; - /** - * Adds a mapping between user and the application which the application is installed on. This mapping will be - * added when an enterprise installation triggered to the role. - * - * @param tenantId id of the tenant - * @param subscribedBy username of the user who subscribe the application - * @param groupList list of {@link DeviceGroup} which belongs the devices that are subscribed to the application - * @param appId id of the {@link ApplicationDTO} which installs - * @param releaseId id of the {@link ApplicationReleaseDTO} - * @throws ApplicationManagementDAOException If unable to add a mapping between device and application - */ - void subscribeGroupToApplication(int tenantId, String subscribedBy, List groupList, int appId, - int releaseId) throws ApplicationManagementDAOException; + void addGroupSubscriptions(int tenantId, String subscribedBy, List groups, int releaseId) + throws ApplicationManagementDAOException; List getDeviceSubscriptions(int appReleaseId, int tenantId) throws ApplicationManagementDAOException; @@ -106,8 +70,14 @@ public interface SubscriptionDAO { List getSubscribedUsernames(List users, int tenantId) throws ApplicationManagementDAOException; - void updateUserSubscription(int tenantId, String updateBy, boolean isUnsubscribed, List userList, - int releaseId) throws ApplicationManagementDAOException; + List getSubscribedRolenames(List roles, int tenantId) throws + ApplicationManagementDAOException; + + List getSubscribedGroupnames(List groups, int tenantId) throws + ApplicationManagementDAOException; + + void updateSubscriptions(int tenantId, String updateBy, List paramList, + int releaseId, String subType, String action) throws ApplicationManagementDAOException; List getSubscribedDeviceIds(List deviceIds, int tenantId) throws ApplicationManagementDAOException; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 3206ebdb559..63fcecb5e3f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -19,14 +19,14 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.subscription; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.SubAction; +import org.wso2.carbon.device.application.mgt.common.SubsciptionType; import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import java.sql.Connection; import java.sql.PreparedStatement; @@ -44,41 +44,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc private static Log log = LogFactory.getLog(GenericSubscriptionDAOImpl.class); @Override - public void subscribeDeviceToApplicationTmp(int tenantId, String subscribedBy, List deviceList, int appId, - int releaseId, String installStatus) throws ApplicationManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - try { - conn = this.getDBConnection(); - long time = System.currentTimeMillis() / 1000; - String sql = "INSERT INTO AP_DEVICE_SUBSCRIPTION(TENANT_ID, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, " - + "DM_DEVICE_ID, AP_APP_RELEASE_ID, AP_APP_ID, INSTALL_STATUS) VALUES (?, ?, ?, ?, ?, ?, ?)"; - stmt = conn.prepareStatement(sql); - for (Device device : deviceList) { - stmt.setInt(1, tenantId); - stmt.setString(2, subscribedBy); - stmt.setLong(3, time); - stmt.setInt(4, device.getId()); - stmt.setInt(5, releaseId); - stmt.setInt(6, appId); - stmt.setString(7, installStatus); - stmt.addBatch(); - if (log.isDebugEnabled()) { - log.debug("Adding a mapping to device ID[" + device.getId() + "] to the application [" + appId - + "], release[" + releaseId + "]"); - } - } - stmt.executeBatch(); - } catch (SQLException | DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB", - e); - } finally { - DAOUtil.cleanupResources(stmt, null); - } - } - - @Override - public List subscribeDeviceToApplication(String subscribedBy, List deviceIds, + public List addDeviceSubscription(String subscribedBy, List deviceIds, String subscribedFrom, String installStatus, int releaseId, int tenantId) throws ApplicationManagementDAOException { Connection conn; @@ -87,7 +53,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc + "AP_DEVICE_SUBSCRIPTION(" + "SUBSCRIBED_BY, " + "SUBSCRIBED_TIMESTAMP, " - + "SUBSCRIBED_FROM, " + + "ACTION_TRIGGERED_FROM, " + "STATUS, " + "DM_DEVICE_ID, " + "AP_APP_RELEASE_ID," @@ -122,30 +88,34 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public List updateDeviceSubscription(String subscribedBy, List deviceIds, - String subscribedFrom, String installStatus, int releaseId, int tenantId) throws ApplicationManagementDAOException { + public List updateDeviceSubscription(String updateBy, List deviceIds, + boolean isUnsubscribed, String actionTriggeredFrom, String installStatus, int releaseId, int tenantId) + throws ApplicationManagementDAOException { Connection conn; try { conn = this.getDBConnection(); - String sql = "UPDATE AP_USER_SUBSCRIPTION " - + "SET " - + "SUBSCRIBED_BY = ?, " - + "SUBSCRIBED_TIMESTAMP = ?, " - + "SUBSCRIBED_FROM = ?, " - + "STATUS = ? " - + "WHERE " - + "DM_DEVICE_ID = ? AND " - + "AP_APP_RELEASE_ID = ? AND " - + "TENANT_ID = ?"; + String sql = "UPDATE AP_USER_SUBSCRIPTION " + "SET "; + + if (isUnsubscribed) { + sql += "UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP = ? "; + } else { + sql += "SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP = ? "; + } + sql += "ACTION_TRIGGERED_FROM = ?, " + + "STATUS = ? " + + "WHERE " + + "DM_DEVICE_ID = ? AND " + + "AP_APP_RELEASE_ID = ? AND " + + "TENANT_ID = ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { Calendar calendar = Calendar.getInstance(); Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); for (Integer deviceId : deviceIds) { - stmt.setString(1, subscribedBy); + stmt.setString(1, updateBy); stmt.setTimestamp(2, timestamp); - stmt.setString(3, subscribedFrom); + stmt.setString(3, actionTriggeredFrom); stmt.setString(4, installStatus); stmt.setInt(5, deviceId); stmt.setInt(6, releaseId); @@ -162,8 +132,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc log.error(msg); throw new ApplicationManagementDAOException(msg, e); } - - return deviceIds; } @@ -198,7 +166,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public void subscribeUserToApplication(int tenantId, String subscribedBy, List userList, int releaseId) + public void addUserSubscriptions(int tenantId, String subscribedBy, List users, int releaseId) throws ApplicationManagementDAOException { Connection conn; try { @@ -212,7 +180,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc + "VALUES (?, ?, ?, ?, ?)"; conn = this.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { - for (String user : userList) { + for (String user : users) { Calendar calendar = Calendar.getInstance(); Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); stmt.setInt(1, tenantId); @@ -234,68 +202,74 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } @Override - public void subscribeRoleToApplication(int tenantId, String subscribedBy, List roleList, int appId, - int releaseId) throws ApplicationManagementDAOException { + public void addRoleSubscriptions(int tenantId, String subscribedBy, List roles, int releaseId) + throws ApplicationManagementDAOException { Connection conn; - PreparedStatement stmt = null; try { + String sql = "INSERT INTO " + + "AP_ROLE_SUBSCRIPTION(" + + "TENANT_ID, " + + "SUBSCRIBED_BY, " + + "SUBSCRIBED_TIMESTAMP, " + + "ROLE_NAME, " + + "AP_APP_RELEASE_ID) " + + "VALUES (?, ?, ?, ?, ?)"; conn = this.getDBConnection(); - long time = System.currentTimeMillis() / 1000; - String sql = "INSERT INTO AP_ROLE_SUBSCRIPTION(TENANT_ID, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, " - + "ROLE_NAME, AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?, ?, ?, ?, ?, ?)"; - stmt = conn.prepareStatement(sql); - for (String role : roleList) { - stmt.setInt(1, tenantId); - stmt.setString(2, subscribedBy); - stmt.setLong(3, time); - stmt.setString(4, role); - stmt.setInt(5, releaseId); - stmt.setInt(6, appId); - stmt.addBatch(); - if (log.isDebugEnabled()) { - log.debug("Adding a mapping to role[" + role + "] to the application [" + appId + "], release[" - + releaseId + "]"); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + for (String role : roles) { + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + stmt.setInt(1, tenantId); + stmt.setString(2, subscribedBy); + stmt.setTimestamp(3, timestamp); + stmt.setString(4, role); + stmt.setInt(5, releaseId); + stmt.addBatch(); + if (log.isDebugEnabled()) { + log.debug("Adding a mapping to role[" + role + "] to the application release[" + releaseId + "]"); + } } + stmt.executeBatch(); } - stmt.executeBatch(); } catch (SQLException | DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB", + throw new ApplicationManagementDAOException("Error occurred while adding role subscription to APPM DB", e); - } finally { - DAOUtil.cleanupResources(stmt, null); } } @Override - public void subscribeGroupToApplication(int tenantId, String subscribedBy, List groupList, int appId, - int releaseId) throws ApplicationManagementDAOException { + public void addGroupSubscriptions(int tenantId, String subscribedBy, List groups, int releaseId) + throws ApplicationManagementDAOException { Connection conn; - PreparedStatement stmt = null; try { + String sql = "INSERT INTO " + + "AP_GROUP_SUBSCRIPTION(" + + "TENANT_ID, " + + "SUBSCRIBED_BY, " + + "SUBSCRIBED_TIMESTAMP, " + + "GROUP_NAME, " + + "AP_APP_RELEASE_ID) " + + "VALUES (?, ?, ?, ?, ?)"; conn = this.getDBConnection(); - long time = System.currentTimeMillis() / 1000; - String sql = "INSERT INTO AP_GROUP_SUBSCRIPTION(TENANT_ID, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, " - + "DM_GROUP_ID, AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?, ?, ?, ?, ?, ?)"; - stmt = conn.prepareStatement(sql); - for (DeviceGroup group : groupList) { - stmt.setInt(1, tenantId); - stmt.setString(2, subscribedBy); - stmt.setLong(3, time); - stmt.setInt(4, group.getGroupId()); - stmt.setInt(5, releaseId); - stmt.setInt(6, appId); - stmt.addBatch(); - if (log.isDebugEnabled()) { - log.debug("Adding a mapping to group ID[" + group.getGroupId() + "] to the application [" + appId - + "], release[" + releaseId + "]"); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + for (String group : groups) { + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + stmt.setInt(1, tenantId); + stmt.setString(2, subscribedBy); + stmt.setTimestamp(3, timestamp); + stmt.setString(4, group); + stmt.setInt(5, releaseId); + stmt.addBatch(); + if (log.isDebugEnabled()) { + log.debug("Adding a mapping to group[" + group + "] to the application release[" + releaseId + "]"); + } } + stmt.executeBatch(); } - stmt.executeBatch(); } catch (SQLException | DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB", + throw new ApplicationManagementDAOException("Error occurred while adding group subscription to APPM DB", e); - } finally { - DAOUtil.cleanupResources(stmt, null); } } @@ -316,7 +290,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc + "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, " + "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, " + "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, " - + "DS.SUBSCRIBED_FROM AS SUBSCRIBED_FROM, " + + "DS.ACTION_TRIGGERED_FROM AS ACTION_TRIGGERED_FROM, " + "DS.DM_DEVICE_ID AS DEVICE_ID " + "FROM AP_DEVICE_SUBSCRIPTION DS " + "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.TENANT_ID=?"; @@ -363,7 +337,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc + "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, " + "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, " + "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, " - + "DS.SUBSCRIBED_FROM AS SUBSCRIBED_FROM, " + + "DS.ACTION_TRIGGERED_FROM AS ACTION_TRIGGERED_FROM, " + "DS.DM_DEVICE_ID AS DEVICE_ID, " + "DS.STATUS AS STATUS " + "FROM AP_DEVICE_SUBSCRIPTION DS " @@ -431,6 +405,83 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } } + @Override + public List getSubscribedRolenames(List roles, int tenantId) + throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug( + "Request received in DAO Layer to get already subscribed role names for given list of role names."); + } + try { + Connection conn = this.getDBConnection(); + int index = 1; + List subscribedUsers = new ArrayList<>(); + StringJoiner joiner = new StringJoiner(",", + "SELECT RS.ROLE_NAME AS ROLE " + + "FROM AP_ROLE_SUBSCRIPTION RS " + + "WHERE RS.ROLE_NAME IN (", ") AND TENANT_ID = ?"); + roles.stream().map(ignored -> "?").forEach(joiner::add); + String query = joiner.toString(); + try (PreparedStatement ps = conn.prepareStatement(query)) { + for (String roleName : roles) { + ps.setObject(index++, roleName); + } + ps.setInt(index, tenantId); + try (ResultSet rs = ps.executeQuery()) { + while (rs.next()) { + subscribedUsers.add(rs.getString("ROLE")); + } + } + } + return subscribedUsers; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when getting subscribed roles for given " + + "role names.", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("SWL Error occurred while getting subscribes roles for given" + + " role names.", e); + } + } + + @Override + public List getSubscribedGroupnames(List groups, int tenantId) + throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to get already subscribed groups for given list of group names."); + } + try { + Connection conn = this.getDBConnection(); + int index = 1; + List subscribedUsers = new ArrayList<>(); + StringJoiner joiner = new StringJoiner(",", + "SELECT GS.GROUP_NAME AS GROUP " + + "FROM AP_GROUP_SUBSCRIPTION GS " + + "WHERE GS.GROUP_NAME IN (", ") AND TENANT_ID = ?"); + groups.stream().map(ignored -> "?").forEach(joiner::add); + String query = joiner.toString(); + try (PreparedStatement ps = conn.prepareStatement(query)) { + for (String groupName : groups) { + ps.setObject(index++, groupName); + } + ps.setInt(index, tenantId); + try (ResultSet rs = ps.executeQuery()) { + while (rs.next()) { + subscribedUsers.add(rs.getString("GROUP")); + } + } + } + return subscribedUsers; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when getting subscribed groups for given " + + "group names.", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("SWL Error occurred while getting subscribed groups for given" + + " group names.", e); + } + } + @Override public List getSubscribedDeviceIds(List deviceIds, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { @@ -468,25 +519,42 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } } @Override - public void updateUserSubscription(int tenantId, String updateBy, boolean isUnsubscribed, - List userList, int releaseId) throws ApplicationManagementDAOException { + public void updateSubscriptions(int tenantId, String updateBy, List paramList, int releaseId, + String subType, String action) throws ApplicationManagementDAOException { Connection conn; try { conn = this.getDBConnection(); - String sql = "UPDATE AP_USER_SUBSCRIPTION SET "; + String sql = "UPDATE "; + if (SubsciptionType.USER.toString().equalsIgnoreCase(subType)) { + sql += "AP_USER_SUBSCRIPTION "; + } else if (SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)) { + sql += "AP_ROLE_SUBSCRIPTION "; + } else if (SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) { + sql += "AP_GROUP_SUBSCRIPTION "; + } - if (isUnsubscribed){ - sql += "UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP "; + if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { + sql += "SET UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP = ? "; } else { - sql += "SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP =? "; + sql += "SET SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP = ? "; + } + + sql += "WHERE "; + + if (SubsciptionType.USER.toString().equalsIgnoreCase(subType)) { + sql += "USER_NAME = ? "; + } else if (SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)) { + sql += "ROLE_NAME = ? "; + } else if (SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) { + sql += "GROUP_NAME = ? "; } - sql += "WHERE USER_NAME = ? AND AP_APP_RELEASE_ID = ? AND AND TENANT_ID = ?"; + sql += "AND AP_APP_RELEASE_ID = ? AND AND TENANT_ID = ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { Calendar calendar = Calendar.getInstance(); Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); - for (String username : userList) { + for (String username : paramList) { stmt.setString(1, updateBy); stmt.setTimestamp(2, timestamp); stmt.setString(3, username); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/MAMDeviceConnectorImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/MAMDeviceConnectorImpl.java deleted file mode 100644 index e1727bc8c5b..00000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/MAMDeviceConnectorImpl.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2018, 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.core.impl; - -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.AppOperation; -import org.wso2.carbon.device.application.mgt.common.exception.DeviceConnectorException; -import org.wso2.carbon.device.application.mgt.common.services.DeviceConnector; -import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; -import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; -import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; -import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;; -import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; - -import java.util.ArrayList; -import java.util.List; - -public class MAMDeviceConnectorImpl implements DeviceConnector{ - private static final Log log = LogFactory.getLog(MAMDeviceConnectorImpl.class); - private ApplicationDAO applicationDAO; - private SubscriptionDAO subscriptionDAO; - - public MAMDeviceConnectorImpl() { - this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); - this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO(); - } - - @Override - public Boolean sendOperationToDevice(AppOperation appOperation, DeviceIdentifier deviceIdentifier) throws DeviceConnectorException { - if (String.valueOf(appOperation.getType()).equals("INSTALL")) { - - } else if (String.valueOf(appOperation.getType()).equals("UNINSTALL")) { - - } else if (String.valueOf(appOperation.getType()).equals("UPDATE")) { - - } - return null; - } - - @Override - public Boolean sendOperationToGroup(AppOperation appOperation, String groupID) throws DeviceConnectorException { - return null; - } - - @Override - public Boolean sendOperationToUser(AppOperation appOperation, List userList) throws DeviceConnectorException { - if (String.valueOf(appOperation.getType()).equals("INSTALL")) { - //First subscribe the user to the app. - try { - - subscriptionDAO.subscribeUserToApplication(appOperation.getTenantId(), appOperation.getSubscribedBy(), - userList, appOperation.getAppReleaseId()); - for (String username: userList) { - List devices = getDeviceManagementService().getDevicesOfUser(username); - List deviceIdentifiers = convertDeviceToDeviceIdentifier(devices); -// getDeviceManagementService().addOperation(appOperation.getApplication().getDeviceTypeName(), -// operationEKA, devices); - subscriptionDAO.subscribeDeviceToApplicationTmp(appOperation.getTenantId(), appOperation.getSubscribedBy(), - devices, appOperation.getApplication().getId(), appOperation.getAppReleaseId(), - String.valueOf(AppOperation.InstallState.PENDING)); - } - } catch (ApplicationManagementDAOException e) { - String msg = "Error subscribing the user to the application Id" + appOperation.getApplication().getId(); - log.error(msg, e); - throw new DeviceConnectorException(msg, e); - } catch (DeviceManagementException e) { - String msg = "Error getting the list of user devices."; - log.error(msg, e); - throw new DeviceConnectorException(msg, e); - } - - } else if (String.valueOf(appOperation.getType()).equals("UNINSTALL")) { - - } else if (String.valueOf(appOperation.getType()).equals("UPDATE")) { - - } - return null; - } - - @Override - public Boolean sendOperationToRole(AppOperation appOperation, String role) throws DeviceConnectorException { - return null; - } - - private List convertDeviceToDeviceIdentifier(List devices) { - List deviceIdentifiers = new ArrayList<>(); - for (Device device:devices) { - deviceIdentifiers.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - } - return deviceIdentifiers; - } - - public DeviceManagementProviderService getDeviceManagementService() { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - DeviceManagementProviderService deviceManagementProviderService = - (DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null); - if (deviceManagementProviderService == null) { - String msg = "DeviceImpl Management provider service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - return deviceManagementProviderService; - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index f83a2788f0c..13a7b2336c0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -33,6 +33,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException; +import org.wso2.carbon.device.application.mgt.common.response.Application; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; @@ -94,22 +95,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { + " users."); } try { - if (params.isEmpty()) { - String msg = "In order to install application release which has UUID " + applicationUUID + ", you should" - + " provide list of subscribers. But found an empty list of users."; - log.error(msg); - throw new BadRequestException(msg); - } - - boolean isValidSubType = Arrays.stream(SubsciptionType.values()) - .anyMatch(sub -> sub.name().equalsIgnoreCase(subType)); - if (!isValidSubType) { - String msg = "Found invalid subscription type to install application release witch has UUID: " - + applicationUUID + ". Subscription type is " + subType; - log.error(msg); - throw new BadRequestException(msg); - } - + validateRequest(params, subType, action); DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); GroupManagementProviderService groupManagementProviderService = HelperUtil @@ -120,6 +106,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List errorDeviceIdentifiers = new ArrayList<>(); ApplicationInstallResponse applicationInstallResponse; + //todo validate users, groups and roles ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); if (SubsciptionType.DEVICE.toString().equals(subType)) { for (T param : params) { @@ -143,19 +130,19 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false)); } - } else if (SubsciptionType.USER.toString().equals(subType)) { + } else if (SubsciptionType.USER.toString().equalsIgnoreCase(subType)) { for (T param : params) { String username = (String) param; subscribers.add(username); devices.addAll(deviceManagementProviderService.getDevicesOfUser(username)); } - } else if (SubsciptionType.ROLE.toString().equals(subType)) { + } else if (SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)) { for (T param : params) { String roleName = (String) param; subscribers.add(roleName); devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName)); } - } else if (SubsciptionType.GROUP.toString().equals(subType)) { + } else if (SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) { for (T param : params) { String groupName = (String) param; subscribers.add(groupName); @@ -166,6 +153,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); String deviceTypeName = deviceType.getName(); + //filter devices by device type for (Device device : devices) { if (deviceTypeName.equals(device.getType())) { filteredDevices.add(device); @@ -173,13 +161,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } applicationInstallResponse = performActionOnDevices(deviceTypeName, filteredDevices, applicationDTO, subType, subscribers, action); - - //todo add db insert to here } else { - //todo improve this applicationInstallResponse = performActionOnDevices(null, devices, applicationDTO, subType, subscribers, action); - //todo add db insert to here } applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers); return applicationInstallResponse; @@ -194,6 +178,29 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + private void validateRequest(List params, String subType, String action) throws BadRequestException { + if (params.isEmpty()) { + String msg = "In order to install application release, you should provide list of subscribers. " + + "But found an empty list of users."; + log.error(msg); + throw new BadRequestException(msg); + } + boolean isValidSubType = Arrays.stream(SubsciptionType.values()) + .anyMatch(sub -> sub.name().equalsIgnoreCase(subType)); + if (!isValidSubType) { + String msg = "Found invalid subscription type " + subType+ " to install application release" ; + log.error(msg); + throw new BadRequestException(msg); + } + boolean isValidAction = Arrays.stream(SubAction.values()) + .anyMatch(sub -> sub.name().equalsIgnoreCase(action)); + if (!isValidAction) { + String msg = "Found invalid action " + action +" to perform on application release"; + log.error(msg); + throw new BadRequestException(msg); + } + } + private ApplicationInstallResponse performActionOnDevices(String deviceType, List devices, ApplicationDTO applicationDTO, String subType, List subscribers, String action) throws ApplicationManagementException { @@ -236,30 +243,21 @@ public class SubscriptionManagerImpl implements SubscriptionManager { deviceIdentifierMap.put(identifier.getType(), identifiers); } } - for (Map.Entry> entry : deviceIdentifierMap.entrySet()) { - Activity activity = addAppInstallOperationToDevices(applicationDTO, - new ArrayList<>(entry.getValue()), entry.getKey()); + Activity activity = addAppOperationOnDevices(applicationDTO, new ArrayList<>(entry.getValue()), + entry.getKey(), action); activityList.add(activity); } - - ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); - applicationInstallResponse.setActivities(activityList); - applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers); - return applicationInstallResponse; + } else { + Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action); + activityList.add(activity); } - - //todo consider action - - Activity activity = addAppInstallOperationToDevices(applicationDTO, deviceIdentifiers, deviceType); - activityList.add(activity); ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); applicationInstallResponse.setActivities(activityList); applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers); - //todo - addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity, subscribingDeviceIdHolder, - subscribers, subType, action); + updateSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activityList, + subscribingDeviceIdHolder, subscribers, subType, action); return applicationInstallResponse; } @@ -285,7 +283,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder(); subscribingDeviceIdHolder.setSubscribableDevices(subscribableDevices); subscribingDeviceIdHolder.setSubscribedDevices(subscribedDevices); -// subscribingDeviceIdHolder.setDeviceSubscriptions(deviceSubscriptions); return subscribingDeviceIdHolder; } @@ -324,55 +321,65 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } - //todo pass SubscribingDeviceIdHolder and action - private void addSubscriptions(int applicationReleaseId, Activity activity, - SubscribingDeviceIdHolder subscribingDeviceIdHolder, List subscribers, String subType, String action) - throws ApplicationManagementException { + private void updateSubscriptions(int applicationReleaseId, List activities, + SubscribingDeviceIdHolder subscribingDeviceIdHolder, List params, String subType, + String action) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); try { ConnectionManagerUtil.beginDBTransaction(); - List deviceResubscribingIds = new ArrayList<>(); - List deviceSubscriptingIds; + List deviceIds = new ArrayList<>(); + List subscribedEntities = new ArrayList<>(); if (SubsciptionType.USER.toString().equals(subType)) { - //todo check action - List subscribedUsers = subscriptionDAO.getSubscribedUsernames(subscribers, tenantId); - if (!subscribedUsers.isEmpty()) { - subscriptionDAO - .updateUserSubscription(tenantId, subscriber, false, subscribedUsers, applicationReleaseId); - subscribers.removeAll(subscribedUsers); + subscribedEntities = subscriptionDAO.getSubscribedUsernames(params, tenantId); + if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { + params.removeAll(subscribedEntities); + subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId); } - subscriptionDAO.subscribeUserToApplication(tenantId, subscriber, subscribers, applicationReleaseId); - } - - //todo add for other subscription types + } else if (SubsciptionType.ROLE.toString().equals(subType)) { + subscribedEntities = subscriptionDAO.getSubscribedRolenames(params, tenantId); + if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { + params.removeAll(subscribedEntities); + subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId); - List deviceIds = new ArrayList<>(); - List activityStatuses = activity.getActivityStatus(); - for (ActivityStatus status : activityStatuses) { - if (status.getStatus().equals(ActivityStatus.Status.PENDING)) { - //todo -// deviceIds.add(compatibleDevices.get(status.getDeviceIdentifier())); + } + } else if (SubsciptionType.GROUP.toString().equals(subType)) { + subscribedEntities = subscriptionDAO.getSubscribedGroupnames(params, tenantId); + if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { + params.removeAll(subscribedEntities); + subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId); } } - - int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]); - //todo if INSTALL get Ids of subscribable devices and update those ids and insert other ids - - - //todo - -// if (!subDeviceIds.isEmpty()) { -// deviceResubscribingIds = subscriptionDAO.updateDeviceSubscription(subscriber, subDeviceIds, subType, -// Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); -// deviceIds.removeAll(subDeviceIds); -// } - deviceSubscriptingIds = subscriptionDAO - .subscribeDeviceToApplication(subscriber, deviceIds, subType, Operation.Status.PENDING.toString(), - applicationReleaseId, tenantId); - deviceSubscriptingIds.addAll(deviceResubscribingIds); - subscriptionDAO.addOperationMapping(operationId, deviceSubscriptingIds, tenantId); + subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType, + action); + + for (Activity activity : activities) { + int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]); + List operationAddedDeviceIds = getOperationAddedDeviceIds(activity, + subscribingDeviceIdHolder.getSubscribableDevices()); + List alreadySubscribedDevices = subscriptionDAO + .getSubscribedDeviceIds(operationAddedDeviceIds, tenantId); + if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { + if (!alreadySubscribedDevices.isEmpty()) { + List deviceResubscribingIds = subscriptionDAO + .updateDeviceSubscription(username, alreadySubscribedDevices, false, subType, + Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); + operationAddedDeviceIds.removeAll(alreadySubscribedDevices); + deviceIds.addAll(deviceResubscribingIds); + } + List subscribingDevices = subscriptionDAO + .addDeviceSubscription(username, operationAddedDeviceIds, subType, + Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); + deviceIds.addAll(subscribingDevices); + } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action) && !alreadySubscribedDevices.isEmpty()) { + List deviceResubscribingIds = subscriptionDAO + .updateDeviceSubscription(username, alreadySubscribedDevices, false, subType, + Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); + deviceIds.addAll(deviceResubscribingIds); + } + subscriptionDAO.addOperationMapping(operationId, deviceIds, tenantId); + } ConnectionManagerUtil.commitDBTransaction(); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); @@ -395,6 +402,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } + private List getOperationAddedDeviceIds(Activity activity, Map deviceMap) { + List deviceIds = new ArrayList<>(); + List activityStatuses = activity.getActivityStatus(); + for (ActivityStatus status : activityStatuses) { + if (status.getStatus().equals(ActivityStatus.Status.PENDING)) { + deviceIds.add(deviceMap.get(status.getDeviceIdentifier())); + } + } + return deviceIds; + } + private Map getDeviceSubscriptions(List filteredDeviceIds) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -416,13 +434,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } - private Activity addAppInstallOperationToDevices(ApplicationDTO application, - List deviceIdentifierList, String deviceType) throws ApplicationManagementException { + private Activity addAppOperationOnDevices(ApplicationDTO applicationDTO, + List deviceIdentifierList, String deviceType, String action) + throws ApplicationManagementException { DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); try { - Operation operation = generateOperationPayloadByDeviceType(deviceType, application, null); - //todo refactor add operation code to get successful operations + Application application = APIUtil.appDtoToAppResponse(applicationDTO); + Operation operation = generateOperationPayloadByDeviceType(deviceType, application, action); return deviceManagementProviderService.addOperation(deviceType, operation, deviceIdentifierList); } catch (OperationManagementException e) { throw new ApplicationManagementException( @@ -433,7 +452,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } } - private Operation generateOperationPayloadByDeviceType(String deviceType, ApplicationDTO application, String action) + private Operation generateOperationPayloadByDeviceType(String deviceType, Application application, String action) throws ApplicationManagementException { try { @@ -464,12 +483,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager { log.error(msg); throw new ApplicationManagementException(msg); } - } catch (UnknownApplicationTypeException e) { String msg = "Unknown Application type is found."; log.error(msg); throw new ApplicationManagementException(msg); } } - } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index 0bd459c4eab..a16dca83579 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -18,18 +18,26 @@ package org.wso2.carbon.device.application.mgt.core.util; +import org.apache.commons.lang.StringUtils; 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.dto.ApplicationDTO; +import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; +import org.wso2.carbon.device.application.mgt.common.response.Application; +import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.services.*; import org.wso2.carbon.device.application.mgt.common.ErrorResponse; +import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import javax.ws.rs.core.Response; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * Holds util methods required for ApplicationDTO-Mgt API component. @@ -204,4 +212,63 @@ public class APIUtil { } } + public static Application appDtoToAppResponse(ApplicationDTO applicationDTO) + throws BadRequestException, UnexpectedServerErrorException { + + Application application = new Application(); + DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); + application.setId(applicationDTO.getId()); + application.setName(applicationDTO.getName()); + application.setDescription(applicationDTO.getDescription()); + application.setAppCategories(applicationDTO.getAppCategories()); + application.setType(applicationDTO.getType()); + application.setSubType(applicationDTO.getSubType()); + application.setPaymentCurrency(applicationDTO.getPaymentCurrency()); + application.setTags(applicationDTO.getTags()); + application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles()); + application.setDeviceType(deviceType.getName()); + application.setRating(applicationDTO.getAppRating()); + List applicationReleases = applicationDTO.getApplicationReleaseDTOs() + .stream().map(APIUtil::releaseDtoToRelease).collect(Collectors.toList()); + application.setApplicationReleases(applicationReleases); + return application; + } + + public static ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO){ + String artifactDownloadEndpoint = ConfigurationManager.getInstance().getConfiguration() + .getArtifactDownloadEndpoint(); + String basePath = artifactDownloadEndpoint + Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid() + + Constants.FORWARD_SLASH; + List screenshotPaths = new ArrayList<>(); + ApplicationRelease applicationRelease = new ApplicationRelease(); + applicationRelease.setDescription(applicationReleaseDTO.getDescription()); + applicationRelease.setVersion(applicationReleaseDTO.getVersion()); + applicationRelease.setUuid(applicationReleaseDTO.getUuid()); + applicationRelease.setReleaseType(applicationReleaseDTO.getReleaseType()); + applicationRelease.setPrice(applicationReleaseDTO.getPrice()); + applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); + applicationRelease.setMetaData(applicationReleaseDTO.getMetaData()); + applicationRelease.setUrl(applicationReleaseDTO.getUrl()); + applicationRelease.setCurrentStatus(applicationReleaseDTO.getCurrentState()); + applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); + applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions()); + applicationRelease.setRating(applicationReleaseDTO.getRating()); + applicationRelease + .setInstallerPath(basePath + applicationReleaseDTO.getInstallerName()); + applicationRelease.setIconPath(basePath + applicationReleaseDTO.getIconName()); + applicationRelease.setBannerPath(basePath + applicationReleaseDTO.getBannerName()); + + if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) { + screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName1()); + } + if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) { + screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName2()); + } + if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) { + screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName3()); + } + applicationRelease.setScreenshots(screenshotPaths); + return applicationRelease; + } + } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java index ca2587d690c..8c4137b2817 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java @@ -121,7 +121,7 @@ public class DAOUtil { deviceSubscriptionDTO.setUnsubscribed(rs.getBoolean("IS_UNSUBSCRIBED")); deviceSubscriptionDTO.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY")); deviceSubscriptionDTO.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_AT")); - deviceSubscriptionDTO.setSubscribedFrom(rs.getString("SUBSCRIBED_FROM")); + deviceSubscriptionDTO.setActionTriggeredFrom(rs.getString("ACTION_TRIGGERED_FROM")); deviceSubscriptionDTO.setDeviceId(rs.getInt("DEVICE_ID")); deviceSubscriptionDTO.setStatus(rs.getString("STATUS")); return deviceSubscriptionDTO; diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index 528e7c74da3..e0d12e92890 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -54,7 +54,7 @@ CREATE INDEX fk_AP_APP_RELEASE_AP_APP1_idx ON AP_APP_RELEASE (AP_APP_ID ASC); CREATE TABLE IF NOT EXISTS AP_APP_REVIEW( ID INTEGER NOT NULL AUTO_INCREMENT, TENANT_ID INTEGER NOT NULL, - COMMENT VARCHAR(250) NOT NULL, + COMMENT TEXT NOT NULL, ROOT_PARENT_ID INTEGER NOT NULL, IMMEDIATE_PARENT_ID INTEGER NOT NULL, CREATED_AT TIMESTAMP NOT NULL, @@ -110,7 +110,7 @@ CREATE TABLE IF NOT EXISTS AP_DEVICE_SUBSCRIPTION( UNSUBSCRIBED BOOLEAN NULL DEFAULT NULL, UNSUBSCRIBED_BY VARCHAR(100) NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, - SUBSCRIBED_FROM VARCHAR(45) NOT NULL, + ACTION_TRIGGERED_FROM VARCHAR(45) NOT NULL, STATUS VARCHAR(45) NOT NULL, DM_DEVICE_ID INTEGER NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, @@ -133,7 +133,7 @@ CREATE TABLE IF NOT EXISTS AP_GROUP_SUBSCRIPTION( UNSUBSCRIBED BOOLEAN NULL DEFAULT NULL, UNSUBSCRIBED_BY VARCHAR(100) NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, - DM_GROUP_ID INTEGER NOT NULL, + GROUP_NAME VARCHAR(100) NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, AP_APP_ID INTEGER NOT NULL, PRIMARY KEY (ID), diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 0db2a022ef5..ff4b953c9e3 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -62,15 +62,16 @@ CREATE TABLE IF NOT EXISTS `APP_MANAGER`.`AP_APP_RELEASE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `APP_MANAGER`.`AP_APP_REVIEW` ( - `ID` INT(11) NOT NULL, - `TENANT_ID` INT(11) NOT NULL, - `COMMENT` VARCHAR(250) NOT NULL, - `REPLY_COMMENT` VARCHAR(250) NULL, - `CREATED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `MODIFIED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `RATING` INT(11) NOT NULL, - `USERNAME` VARCHAR(45) NOT NULL, - `AP_APP_RELEASE_ID` INT(11) NOT NULL, + `ID` INT(11) NOT NULL, + `TENANT_ID` INT(11) NOT NULL, + `COMMENT` TEXT NOT NULL, + `ROOT_PARENT_ID` INT(11) NOT NULL, + `IMMEDIATE_PARENT_ID` INT(11) NOT NULL, + `CREATED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `MODIFIED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `RATING` INT(11) NOT NULL, + `USERNAME` VARCHAR(45) NOT NULL, + `AP_APP_RELEASE_ID` INT(11) NOT NULL, PRIMARY KEY (`ID`), INDEX `fk_AP_APP_REVIEW_AP_APP_RELEASE1_idx` (`AP_APP_RELEASE_ID` ASC), CONSTRAINT `fk_AP_APP_REVIEW_AP_APP_RELEASE1` @@ -134,7 +135,7 @@ CREATE TABLE IF NOT EXISTS `APP_MANAGER`.`AP_DEVICE_SUBSCRIPTION` `UNSUBSCRIBED` TINYINT(1) NULL DEFAULT NULL, `UNSUBSCRIBED_BY` VARCHAR(100) NULL DEFAULT NULL, `UNSUBSCRIBED_TIMESTAMP` TIMESTAMP NULL DEFAULT NULL, - `SUBSCRIBED_FROM` VARCHAR(45) NULL, + `ACTION_TRIGGERED_FROM` VARCHAR(45) NULL, `DM_DEVICE_ID` INT(11) NOT NULL, `AP_APP_RELEASE_ID` INT(11) NOT NULL, PRIMARY KEY (`ID`), @@ -161,7 +162,7 @@ CREATE TABLE IF NOT EXISTS `APP_MANAGER`.`AP_GROUP_SUBSCRIPTION` `UNSUBSCRIBED` TINYINT(1) NULL DEFAULT NULL, `UNSUBSCRIBED_BY` VARCHAR(100) NULL DEFAULT NULL, `UNSUBSCRIBED_TIMESTAMP` TIMESTAMP NULL DEFAULT NULL, - `DM_GROUP_ID` INT(11) NOT NULL, + `GROUP_NAME` VARCHAR(100) NOT NULL, `AP_APP_RELEASE_ID` INT(11) NOT NULL, INDEX `fk_AP_GROUP_SUBSCRIPTION_AP_APP_RELEASE1_idx` (`AP_APP_RELEASE_ID` ASC), PRIMARY KEY (`ID`), From 0ae7479d4965c124e081c2c419caf4eb9372438c Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 3 Jun 2019 18:42:47 +0530 Subject: [PATCH 10/14] Add web clip support for APPM --- .../common/services/ApplicationManager.java | 13 +- .../wrapper/ApplicationReleaseWrapper.java | 12 - .../common/wrapper/WebClipReleaseWrapper.java | 97 ++++ .../mgt/common/wrapper/WebClipWrapper.java | 102 ++++ .../mgt/core/dao/ApplicationDAO.java | 3 + .../GenericApplicationDAOImpl.java | 34 ++ .../mgt/core/impl/ApplicationManagerImpl.java | 502 ++++++++++++------ .../application/mgt/core/util/APIUtil.java | 62 +++ .../ApplicationManagementPublisherAPI.java | 66 +++ ...ApplicationManagementPublisherAPIImpl.java | 44 +- 10 files changed, 761 insertions(+), 174 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipReleaseWrapper.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipWrapper.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 cf49bf2a326..a0979e449c0 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 @@ -35,6 +35,7 @@ import org.wso2.carbon.device.application.mgt.common.response.Tag; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; import java.util.List; @@ -53,6 +54,9 @@ public interface ApplicationManager { Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException, RequestValidatingException; + Application createWebClip(WebClipWrapper webClipWrapper, ApplicationArtifact applicationArtifact) + throws ApplicationManagementException; + /** * Updates an already existing application. * @@ -203,19 +207,14 @@ public interface ApplicationManager { /*** * To validate the application creating request * - * @param applicationWrapper {@link ApplicationDTO} - * @throws RequestValidatingException if the payload contains invalid inputs. */ - void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException; + void validateAppCreatingRequest(T param) throws ApplicationManagementException; /*** * - * @param applicationReleaseWrapper {@link ApplicationReleaseDTO} - * @param applicationType Type of the application * @throws RequestValidatingException throws if payload does not satisfy requrements. */ - void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType) - throws RequestValidatingException; + void validateReleaseCreatingRequest(T param) 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/wrapper/ApplicationReleaseWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationReleaseWrapper.java index 3d991776474..b220ab7d917 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationReleaseWrapper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationReleaseWrapper.java @@ -47,10 +47,6 @@ public class ApplicationReleaseWrapper { required = true) private String metaData; - @ApiModelProperty(name = "url", - value = "URL which is used for WEB-CLIP") - private String url; - @ApiModelProperty(name = "supportedOsVersions", value = "ApplicationDTO release supported OS versions") private String supportedOsVersions; @@ -87,14 +83,6 @@ public class ApplicationReleaseWrapper { return metaData; } - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipReleaseWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipReleaseWrapper.java new file mode 100644 index 00000000000..8187eda76b2 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipReleaseWrapper.java @@ -0,0 +1,97 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.common.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store") +public class WebClipReleaseWrapper { + + @ApiModelProperty(name = "description", + value = "Description of the web clip release") + private String description; + + @ApiModelProperty(name = "releaseType", + value = "Release type of the web clip release", + required = true, + example = "alpha, beta etc") + private String releaseType; + + @ApiModelProperty(name = "price", + value = "Price of the web clip release", + required = true) + private Double price; + + @ApiModelProperty(name = "isSharedWithAllTenants", + value = "If web clip release is shared with all tenants it is equal to 1 otherwise 0", + required = true) + private boolean isSharedWithAllTenants; + + @ApiModelProperty(name = "metaData", + value = "Meta data of the web clip release", + required = true) + private String metaData; + + @ApiModelProperty(name = "url", + value = "URL which is used for WEB-CLIP") + private String url; + + public String getReleaseType() { + return releaseType; + } + + public void setReleaseType(String releaseType) { + this.releaseType = releaseType; + } + + public void setIsSharedWithAllTenants(boolean isSharedWithAllTenants) { + this.isSharedWithAllTenants = isSharedWithAllTenants; + } + + public void setMetaData(String metaData) { + this.metaData = metaData; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } + + public boolean getIsSharedWithAllTenants() { + return isSharedWithAllTenants; + } + + public String getMetaData() { + return metaData; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getDescription() { return description; } + + public void setDescription(String description) { this.description = description; } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipWrapper.java new file mode 100644 index 00000000000..b5c1b5ce420 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipWrapper.java @@ -0,0 +1,102 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.common.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel(value = "WebClipWrapper", description = "WebClipWrapper represents an ApplicationDTO in ApplicationDTO Store") +public class WebClipWrapper { + + @ApiModelProperty(name = "name", + value = "Name of the web clip", + required = true) + private String name; + + @ApiModelProperty(name = "description", + value = "Description of the web clip", + required = true) + private String description; + + @ApiModelProperty(name = "categories", + value = "List of Categories", + required = true, + example = "Educational, Gaming, Travel, Entertainment etc") + private List categories; + + @ApiModelProperty(name = "subType", + value = "Subscription method of the web clip", + required = true, + example = "PAID, FREE") + private String subMethod; + + @ApiModelProperty(name = "paymentCurrency", + value = "Payment currency of the web clip", + required = true, + example = "$") + private String paymentCurrency; + + @ApiModelProperty(name = "tags", + value = "List of tags") + private List tags; + + @ApiModelProperty(name = "unrestrictedRoles", + value = "List of roles that users should have to view the web clip") + private List unrestrictedRoles; + + @ApiModelProperty(name = "applicationReleaseWrappers", + value = "List of web clip releases", + required = true) + private List webClipReleaseWrappers; + + public String getName() { + return name; + } + + public void setName(String name) { this.name = name; } + + public List getTags() { return tags; } + + public void setTags(List tags) { this.tags = tags; } + + public String getPaymentCurrency() { return paymentCurrency; } + + public void setPaymentCurrency(String paymentCurrency) { this.paymentCurrency = paymentCurrency; } + + public List getUnrestrictedRoles() { return unrestrictedRoles; } + + public void setUnrestrictedRoles(List unrestrictedRoles) { this.unrestrictedRoles = unrestrictedRoles; } + + public String getDescription() { return description; } + + public void setDescription(String description) { this.description = description; } + + public List getWebClipReleaseWrappers() { return webClipReleaseWrappers; } + + public void setWebClipReleaseWrappers(List webClipReleaseWrappers) { + this.webClipReleaseWrappers = webClipReleaseWrappers; } + + public List getCategories() { return categories; } + + public void setCategories(List categories) { this.categories = categories; } + + public String getSubMethod() { return subMethod; } + + public void setSubMethod(String subMethod) { this.subMethod = subMethod; } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java index 7e24b9ac367..30d7beb3e3c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java @@ -83,6 +83,9 @@ public interface ApplicationDAO { List getAllCategories(int tenantId) throws ApplicationManagementDAOException; + List getCategoryIdsForCategoryNames(List CatgeoryNames, int tenantId) + throws ApplicationManagementDAOException; + List getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException; CategoryDTO getCategoryForCategoryName(String categoryName, int tenantId) throws ApplicationManagementDAOException; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 4840cf1e5cc..e98096d865f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -805,6 +805,40 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } + @Override + public List getCategoryIdsForCategoryNames(List categoryNames, int tenantId) + throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to get tag ids for given tag names"); + } + try { + Connection conn = this.getDBConnection(); + int index = 1; + List tagIds = new ArrayList<>(); + StringJoiner joiner = new StringJoiner(",", + "SELECT AP_APP_CATEGORY.ID AS ID FROM AP_APP_CATEGORY WHERE AP_APP_CATEGORY.CATEGORY IN (", ") AND TENANT_ID = ?"); + categoryNames.stream().map(ignored -> "?").forEach(joiner::add); + String query = joiner.toString(); + try (PreparedStatement ps = conn.prepareStatement(query)) { + for (String categoryName : categoryNames) { + ps.setObject(index++, categoryName); + } + ps.setInt(index, tenantId); + try (ResultSet rs = ps.executeQuery()) { + while (rs.next()) { + tagIds.add(rs.getInt("ID")); + } + } + } + return tagIds; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when getting categories", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("Error occurred while getting categories", e); + } + } + @Override public List getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { 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 01909c468a6..a0152321d3f 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 @@ -17,6 +17,7 @@ package org.wso2.carbon.device.application.mgt.core.impl; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.validator.routines.UrlValidator; @@ -57,6 +58,8 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; @@ -64,6 +67,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; 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.APIUtil; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; @@ -149,7 +153,7 @@ public class ApplicationManagerImpl implements ApplicationManager { //validating and verifying application data try { ConnectionManagerUtil.openDBConnection(); - applicationDTO = appWrapperToAppDTO(applicationWrapper); + applicationDTO = APIUtil.convertToAppDTO(applicationWrapper); unrestrictedRoles = applicationWrapper.getUnrestrictedRoles(); tags = applicationWrapper.getTags(); @@ -316,7 +320,7 @@ public class ApplicationManagerImpl implements ApplicationManager { .addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); applicationReleaseEntities.add(applicationReleaseDTO); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); - Application application = appDtoToAppResponse(applicationDTO); + Application application = APIUtil.appDtoToAppResponse(applicationDTO); ConnectionManagerUtil.commitDBTransaction(); return application; } @@ -617,6 +621,182 @@ public class ApplicationManagerImpl implements ApplicationManager { return applicationReleaseDTO; } + @Override + public Application createWebClip(WebClipWrapper webClipWrapper, ApplicationArtifact applicationArtifact) + throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + if (log.isDebugEnabled()) { + log.debug("Application create request is received for the tenant : " + tenantId + " From" + " the user : " + + userName); + } + + List categoryIds; + ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webClipWrapper); + List unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); + List tags = applicationDTO.getTags(); + List categories = applicationDTO.getAppCategories(); + try { + ConnectionManagerUtil.openDBConnection(); + categoryIds = applicationDAO.getCategoryIdsForCategoryNames(categories, tenantId); + } catch (DBConnectionException e) { + String msg = "Error occurred while getting database connection."; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } catch (ApplicationManagementDAOException e) { + String msg = "Error occurred while getting data which is related to application. application name: " + + webClipWrapper.getName() + "."; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + + ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); + String uuid = UUID.randomUUID().toString(); + applicationReleaseDTO.setUuid(uuid); + String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName()); + applicationReleaseDTO.setAppHashValue(md5); + applicationDTO.setType(ApplicationType.WEB_CLIP.toString()); + + //uploading application artifacts + try { + applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact); + applicationDTO.getApplicationReleaseDTOs().clear(); + applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); + } catch (ResourceManagementException e) { + String msg = "Error Occured when uploading artifacts of the application: " + webClipWrapper.getName(); + log.error(msg); + throw new ApplicationManagementException(msg, e); + } + + //insert application data into database + ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + try { + List applicationReleaseEntities = new ArrayList<>(); + + ConnectionManagerUtil.beginDBTransaction(); + // Insert to application table + int appId = this.applicationDAO.createApplication(applicationDTO, tenantId); + if (appId == -1) { + log.error("Application data storing is Failed."); + ConnectionManagerUtil.rollbackDBTransaction(); + deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); + return null; + } else { + if (log.isDebugEnabled()) { + log.debug("New ApplicationDTO entry added to AP_APP table. App Id:" + appId); + } + //add application categories + this.applicationDAO.addCategoryMapping(categoryIds, appId, tenantId); + + //adding application unrestricted roles + if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { + this.visibilityDAO.addUnrestrictedRoles(unrestrictedRoles, appId, tenantId); + if (log.isDebugEnabled()) { + log.debug("New restricted roles to app ID mapping added to AP_UNRESTRICTED_ROLE table." + + " App Id:" + appId); + } + } + + //adding application tags + if (tags != null && !tags.isEmpty()) { + List registeredTags = applicationDAO.getAllTags(tenantId); + List registeredTagNames = new ArrayList<>(); + List tagIds = new ArrayList<>(); + + for (TagDTO tagDTO : registeredTags) { + registeredTagNames.add(tagDTO.getTagName()); + } + List newTags = getDifference(tags, registeredTagNames); + if (!newTags.isEmpty()) { + this.applicationDAO.addTags(newTags, tenantId); + if (log.isDebugEnabled()) { + log.debug("New tags entry added to AP_APP_TAG table. App Id:" + appId); + } + tagIds = this.applicationDAO.getTagIdsForTagNames(tags, tenantId); + } else { + for (TagDTO tagDTO : registeredTags) { + for (String tagName : tags) { + if (tagName.equals(tagDTO.getTagName())) { + tagIds.add(tagDTO.getId()); + break; + } + } + } + } + this.applicationDAO.addTagMapping(tagIds, appId, tenantId); + } + + if (log.isDebugEnabled()) { + log.debug("Creating a new release. App Id:" + appId); + } + String initialLifecycleState = lifecycleStateManager.getInitialState(); + applicationReleaseDTO.setCurrentState(initialLifecycleState); + applicationReleaseDTO = this.applicationReleaseDAO + .createRelease(applicationReleaseDTO, appId, tenantId); + LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState, + initialLifecycleState); + this.lifecycleStateDAO + .addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); + applicationReleaseEntities.add(applicationReleaseDTO); + applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); + Application application = APIUtil.appDtoToAppResponse(applicationDTO); + ConnectionManagerUtil.commitDBTransaction(); + return application; + } + } catch (LifeCycleManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = + "Error occurred while adding lifecycle state. application name: " + webClipWrapper.getName() + "."; + log.error(msg); + try { + applicationStorageManager.deleteAllApplicationReleaseArtifacts( + Collections.singletonList(applicationReleaseDTO.getAppHashValue())); + } catch (ApplicationStorageManagementException ex) { + String errorLog = + "Error occurred when deleting application artifacts. Application artifacts are tried to " + + "delete because of lifecycle state adding issue in the application creating operation."; + log.error(errorLog); + throw new ApplicationManagementException(errorLog, e); + } + throw new ApplicationManagementException(msg, e); + } catch (ApplicationManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred while adding application or application release. application name: " + + webClipWrapper.getName() + "."; + log.error(msg); + deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); + throw new ApplicationManagementException(msg, e); + } catch (LifecycleManagementException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred when getting initial lifecycle state. application name: " + webClipWrapper + .getName() + "."; + log.error(msg); + deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); + throw new ApplicationManagementException(msg, e); + } catch (DBConnectionException e) { + String msg = "Error occurred while getting database connection."; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } catch (VisibilityManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = + "Error occurred while adding unrestricted roles. application name: " + webClipWrapper.getName() + + "."; + log.error(msg); + deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); + throw new ApplicationManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Error occurred while disabling AutoCommit."; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + + } + @Override public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -688,7 +868,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } for (ApplicationDTO appDTO : filteredApplications) { - applications.add(appDtoToAppResponse(appDTO)); + applications.add(APIUtil.appDtoToAppResponse(appDTO)); } Pagination pagination = new Pagination(); @@ -752,7 +932,7 @@ public class ApplicationManagerImpl implements ApplicationManager { .createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId); this.lifecycleStateDAO .addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); - applicationRelease = releaseDtoToRelease(applicationReleaseDTO); + applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO); ConnectionManagerUtil.commitDBTransaction(); return applicationRelease; } catch (TransactionManagementException e) { @@ -807,7 +987,7 @@ public class ApplicationManagerImpl implements ApplicationManager { try { DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(), - deviceType.getName(), releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact, + deviceType.getName(), APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact, true); return addImageArtifacts(applicationReleaseDTO, applicationArtifact); } catch (ResourceManagementException e) { @@ -861,7 +1041,7 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new ForbiddenException(msg); } - return appDtoToAppResponse(applicationDTO); + return APIUtil.appDtoToAppResponse(applicationDTO); } catch (LifecycleManagementException e){ String msg = "Error occurred when getting the last state of the application lifecycle flow"; log.error(msg); @@ -911,7 +1091,7 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new ForbiddenException(msg); } - return releaseDtoToRelease(applicationReleaseDTO); + return APIUtil.releaseDtoToRelease(applicationReleaseDTO); } catch (LifecycleManagementException e) { String msg = "Error occurred when getting the end state of the application lifecycle flow"; log.error(msg); @@ -977,7 +1157,7 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new ForbiddenException(msg); } - return appDtoToAppResponse(applicationDTO); + return APIUtil.appDtoToAppResponse(applicationDTO); } catch (LifecycleManagementException e) { String msg = "Error occurred when getting the last state of the application lifecycle flow"; log.error(msg); @@ -1542,7 +1722,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); ConnectionManagerUtil.commitDBTransaction(); - return releaseDtoToRelease(applicationReleaseDTO); + return APIUtil.releaseDtoToRelease(applicationReleaseDTO); } else { String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'" + " to '" + lifecycleChanger.getAction() + "'"; @@ -2267,78 +2447,188 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override - public void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException { + public void validateAppCreatingRequest(T param) throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - String applicationType = applicationWrapper.getType(); + if (param instanceof ApplicationWrapper){ + ApplicationWrapper applicationWrapper = (ApplicationWrapper) param; + if (StringUtils.isEmpty(applicationWrapper.getName())) { + String msg = "Application name cannot be empty."; + log.error(msg); + throw new BadRequestException(msg); + } + if (applicationWrapper.getAppCategories() == null) { + String msg = "Application category can't be null."; + log.error(msg); + throw new BadRequestException(msg); + } + if (applicationWrapper.getAppCategories().isEmpty()) { + String msg = "Application category can't be empty."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(applicationWrapper.getType())) { + String msg = "Application type can't be empty."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(applicationWrapper.getDeviceType())) { + String msg = "Device type can't be empty for the application."; + log.error(msg); + throw new BadRequestException(msg); + } - if (StringUtils.isEmpty(applicationWrapper.getName())) { - String msg = "Application name cannot be empty."; - log.error(msg); - throw new RequestValidatingException(msg); - } - if (applicationWrapper.getAppCategories() == null) { - String msg = "Application category can't be null."; - log.error(msg); - throw new RequestValidatingException(msg); - } - if (applicationWrapper.getAppCategories().isEmpty()) { - String msg = "Application category can't be empty."; - log.error(msg); - throw new RequestValidatingException(msg); - } - if (StringUtils.isEmpty(applicationType)) { - String msg = "Application type can't be empty."; - log.error(msg); - throw new RequestValidatingException(msg); - } - if (StringUtils.isEmpty(applicationWrapper.getDeviceType())) { - String msg = "Device type can't be empty for the application."; - log.error(msg); - throw new RequestValidatingException(msg); - } + List applicationReleaseWrappers; + applicationReleaseWrappers = applicationWrapper.getApplicationReleaseWrappers(); - List applicationReleaseWrappers; - applicationReleaseWrappers = applicationWrapper.getApplicationReleaseWrappers(); + if (applicationReleaseWrappers == null || applicationReleaseWrappers.size() != 1) { + String msg = "Invalid application creating request. Application creating request must have single " + + "application release. Application name:" + applicationWrapper.getName() + " and type: " + + applicationWrapper.getType(); + log.error(msg); + throw new BadRequestException(msg); + } + } else if (param instanceof WebClipWrapper) { + WebClipWrapper webClipWrapper = (WebClipWrapper) param; + if (StringUtils.isEmpty(webClipWrapper.getName())) { + String msg = "Web Clip name cannot be empty."; + log.error(msg); + throw new BadRequestException(msg); + } + if (webClipWrapper.getCategories() == null) { + String msg = "Web Clip category can't be null."; + log.error(msg); + throw new BadRequestException(msg); + } + if (webClipWrapper.getCategories().isEmpty()) { + String msg = "Web clip category can't be empty."; + log.error(msg); + throw new BadRequestException(msg); + } - if (applicationReleaseWrappers == null || applicationReleaseWrappers.size() != 1) { - String msg = - "Invalid application creating request. ApplicationDTO creating request must have single application " - + "release. ApplicationDTO name:" + applicationWrapper.getName() + " and type: " + applicationWrapper - .getType(); - log.error(msg); - throw new RequestValidatingException(msg); + List webClipReleaseWrappers; + webClipReleaseWrappers = webClipWrapper.getWebClipReleaseWrappers(); + + if (webClipReleaseWrappers == null || webClipReleaseWrappers.size() != 1) { + String msg = "Invalid web clip creating request. Web clip creating request must have single " + + "web clip release. Web clip name:" + webClipWrapper.getName() + "."; + log.error(msg); + throw new BadRequestException(msg); + } + + try { + ConnectionManagerUtil.openDBConnection(); + List unrestrictedRoles = webClipWrapper.getUnrestrictedRoles(); + + if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { + if (!isValidRestrictedRole(unrestrictedRoles)) { + String msg = "Unrestricted role list contain role/roles which are not in the user store."; + log.error(msg); + throw new ApplicationManagementException(msg); + } + if (!hasUserRole(unrestrictedRoles, userName)) { + String msg = "You are trying to restrict the visibility of the application for a role set, but " + + "in order to perform the action at least one role should be assigned to user: " + + userName; + log.error(msg); + throw new BadRequestException(msg); + } + } + + Filter filter = new Filter(); + filter.setFullMatch(true); + filter.setAppName(webClipWrapper.getName().trim()); + filter.setOffset(0); + filter.setLimit(1); + List applicationList = applicationDAO.getApplications(filter, -1, tenantId); + if (!applicationList.isEmpty()) { + String msg = + "Already an application registered with same name - " + applicationList.get(0).getName() + + "."; + log.error(msg); + throw new BadRequestException(msg); + } + + List registeredCategories = this.applicationDAO.getAllCategories(tenantId); + List appCategories = webClipWrapper.getCategories(); + + if (registeredCategories.isEmpty()) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = + "Registered application category set is empty. Since it is mandatory to add application " + + "category when adding new application, registered application category list shouldn't be null."; + log.error(msg); + throw new ApplicationManagementException(msg); + } + for (String cat : appCategories) { + boolean isValidCategory = false; + for (CategoryDTO obj : registeredCategories) { + if (cat.equals(obj.getCategoryName())) { + isValidCategory = true; + break; + } + } + if (!isValidCategory) { + String msg = + "Application Creating request contains invalid categories. Hence please verify the " + + "application creating payload."; + log.error(msg); + throw new BadRequestException(msg); + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while getting database connection."; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } catch (ApplicationManagementDAOException e) { + String msg = "Error occurred while getting data which is related to web clip. web clip name: " + + webClipWrapper.getName() + "."; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } catch (UserStoreException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred when validating the unrestricted roles given for the web clip"; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } } } @Override - public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, - String applicationType) throws RequestValidatingException { + public void validateReleaseCreatingRequest(T param) throws ApplicationManagementException { - if (applicationReleaseWrapper == null){ - String msg = "Application Release shouldn't be null."; + if (param == null){ + String msg = "In order to validate release creating request param shouldn't be null."; log.error(msg); - throw new RequestValidatingException(msg); + throw new BadRequestException(msg); } - if (ApplicationType.WEB_CLIP.toString().equals(applicationType)) { + if (param instanceof ApplicationReleaseWrapper){ + ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param; + + if (StringUtils.isEmpty(applicationReleaseWrapper.getSupportedOsVersions())){ + String msg = "Supported OS Version shouldn't be null or empty."; + log.error(msg); + throw new BadRequestException(msg); + } + } if (param instanceof WebClipReleaseWrapper){ + WebClipReleaseWrapper webClipReleaseWrapper = (WebClipReleaseWrapper) param; UrlValidator urlValidator = new UrlValidator(); if (StringUtils - .isEmpty(applicationReleaseWrapper.getUrl())){ + .isEmpty(webClipReleaseWrapper.getUrl())){ String msg = "URL should't be null for the application release creating request for application type WEB_CLIP"; log.error(msg); - throw new RequestValidatingException(msg); + throw new BadRequestException(msg); } - if (!urlValidator.isValid(applicationReleaseWrapper.getUrl())){ + if (!urlValidator.isValid(webClipReleaseWrapper.getUrl())){ String msg = "Request payload contains an invalid Web Clip URL."; log.error(msg); - throw new RequestValidatingException(msg); + throw new BadRequestException(msg); } } - if (StringUtils.isEmpty(applicationReleaseWrapper.getSupportedOsVersions())){ - String msg = "Supported OS Version shouldn't be null or empty."; - log.error(msg); - throw new RequestValidatingException(msg); - } } @@ -2383,98 +2673,6 @@ public class ApplicationManagerImpl implements ApplicationManager { } } - - private ApplicationDTO appWrapperToAppDTO(ApplicationWrapper applicationWrapper) - throws BadRequestException, UnexpectedServerErrorException { - - DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType()); - ApplicationDTO applicationDTO = new ApplicationDTO(); - applicationDTO.setName(applicationWrapper.getName()); - applicationDTO.setDescription(applicationWrapper.getDescription()); - applicationDTO.setAppCategories(applicationWrapper.getAppCategories()); - applicationDTO.setType(applicationWrapper.getType()); - applicationDTO.setSubType(applicationWrapper.getSubType()); - applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency()); - applicationDTO.setTags(applicationWrapper.getTags()); - applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles()); - applicationDTO.setDeviceTypeId(deviceType.getId()); - List applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers() - .stream().map(this::releaseWrapperToReleaseDTO).collect(Collectors.toList()); - applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); - return applicationDTO; - } - - private ApplicationReleaseDTO releaseWrapperToReleaseDTO(ApplicationReleaseWrapper applicationReleaseWrapper){ - ApplicationReleaseDTO applicationReleaseDTO = new ApplicationReleaseDTO(); - applicationReleaseDTO.setDescription(applicationReleaseWrapper.getDescription()); - applicationReleaseDTO.setReleaseType(applicationReleaseWrapper.getReleaseType()); - applicationReleaseDTO.setPrice(applicationReleaseWrapper.getPrice()); - applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseWrapper.getIsSharedWithAllTenants()); - applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData()); - applicationReleaseDTO.setUrl(applicationReleaseWrapper.getUrl()); - applicationReleaseDTO.setSupportedOsVersions(applicationReleaseWrapper.getSupportedOsVersions()); - return applicationReleaseDTO; - } - - private Application appDtoToAppResponse(ApplicationDTO applicationDTO) - throws BadRequestException, UnexpectedServerErrorException { - - Application application = new Application(); - DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); - application.setId(applicationDTO.getId()); - application.setName(applicationDTO.getName()); - application.setDescription(applicationDTO.getDescription()); - application.setAppCategories(applicationDTO.getAppCategories()); - application.setType(applicationDTO.getType()); - application.setSubType(applicationDTO.getSubType()); - application.setPaymentCurrency(applicationDTO.getPaymentCurrency()); - application.setTags(applicationDTO.getTags()); - application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles()); - application.setDeviceType(deviceType.getName()); - application.setRating(applicationDTO.getAppRating()); - List applicationReleases = applicationDTO.getApplicationReleaseDTOs() - .stream().map(this::releaseDtoToRelease).collect(Collectors.toList()); - application.setApplicationReleases(applicationReleases); - return application; - } - - private ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO){ - String artifactDownloadEndpoint = ConfigurationManager.getInstance().getConfiguration() - .getArtifactDownloadEndpoint(); - String basePath = artifactDownloadEndpoint + Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid() - + Constants.FORWARD_SLASH; - List screenshotPaths = new ArrayList<>(); - ApplicationRelease applicationRelease = new ApplicationRelease(); - applicationRelease.setDescription(applicationReleaseDTO.getDescription()); - applicationRelease.setVersion(applicationReleaseDTO.getVersion()); - applicationRelease.setUuid(applicationReleaseDTO.getUuid()); - applicationRelease.setReleaseType(applicationReleaseDTO.getReleaseType()); - applicationRelease.setPrice(applicationReleaseDTO.getPrice()); - applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); - applicationRelease.setMetaData(applicationReleaseDTO.getMetaData()); - applicationRelease.setUrl(applicationReleaseDTO.getUrl()); - applicationRelease.setCurrentStatus(applicationReleaseDTO.getCurrentState()); - applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); - applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions()); - applicationRelease.setRating(applicationReleaseDTO.getRating()); - applicationRelease - .setInstallerPath(basePath + applicationReleaseDTO.getInstallerName()); - applicationRelease.setIconPath(basePath + applicationReleaseDTO.getIconName()); - applicationRelease.setBannerPath(basePath + applicationReleaseDTO.getBannerName()); - - if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) { - screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName1()); - } - if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) { - screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName2()); - } - if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) { - screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName3()); - } - applicationRelease.setScreenshots(screenshotPaths); - return applicationRelease; - } - private DeviceType getDeviceTypeData( T deviceTypeAttr) throws BadRequestException, UnexpectedServerErrorException { List deviceTypes; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index a16dca83579..47f95cf0e63 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -28,6 +28,10 @@ import org.wso2.carbon.device.application.mgt.common.response.Application; import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.services.*; import org.wso2.carbon.device.application.mgt.common.ErrorResponse; +import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; @@ -212,6 +216,64 @@ public class APIUtil { } } + public static ApplicationDTO convertToAppDTO(T param) + throws BadRequestException, UnexpectedServerErrorException { + ApplicationDTO applicationDTO = new ApplicationDTO(); + + if (param instanceof ApplicationWrapper){ + ApplicationWrapper applicationWrapper = (ApplicationWrapper) param; + DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType()); + applicationDTO.setName(applicationWrapper.getName()); + applicationDTO.setDescription(applicationWrapper.getDescription()); + applicationDTO.setAppCategories(applicationWrapper.getAppCategories()); + applicationDTO.setType(applicationWrapper.getType()); + applicationDTO.setSubType(applicationWrapper.getSubType()); + applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency()); + applicationDTO.setTags(applicationWrapper.getTags()); + applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles()); + applicationDTO.setDeviceTypeId(deviceType.getId()); + List applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers() + .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); + applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); + } else if (param instanceof WebClipWrapper){ + WebClipWrapper webClipWrapper = (WebClipWrapper) param; + applicationDTO.setName(webClipWrapper.getName()); + applicationDTO.setDescription(webClipWrapper.getDescription()); + applicationDTO.setAppCategories(webClipWrapper.getCategories()); + applicationDTO.setSubType(webClipWrapper.getSubMethod()); + applicationDTO.setPaymentCurrency(webClipWrapper.getPaymentCurrency()); + applicationDTO.setTags(webClipWrapper.getTags()); + applicationDTO.setUnrestrictedRoles(webClipWrapper.getUnrestrictedRoles()); + List applicationReleaseEntities = webClipWrapper.getWebClipReleaseWrappers() + .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); + applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); + } + + return applicationDTO; + } + + public static ApplicationReleaseDTO releaseWrapperToReleaseDTO(T param){ + ApplicationReleaseDTO applicationReleaseDTO = new ApplicationReleaseDTO(); + if (param instanceof ApplicationReleaseWrapper){ + ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param; + applicationReleaseDTO.setDescription(applicationReleaseWrapper.getDescription()); + applicationReleaseDTO.setReleaseType(applicationReleaseWrapper.getReleaseType()); + applicationReleaseDTO.setPrice(applicationReleaseWrapper.getPrice()); + applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseWrapper.getIsSharedWithAllTenants()); + applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData()); + applicationReleaseDTO.setSupportedOsVersions(applicationReleaseWrapper.getSupportedOsVersions()); + } else if (param instanceof WebClipReleaseWrapper){ + WebClipReleaseWrapper webClipReleaseWrapper = (WebClipReleaseWrapper) param; + applicationReleaseDTO.setDescription(webClipReleaseWrapper.getDescription()); + applicationReleaseDTO.setReleaseType(webClipReleaseWrapper.getReleaseType()); + applicationReleaseDTO.setPrice(webClipReleaseWrapper.getPrice()); + applicationReleaseDTO.setInstallerName(webClipReleaseWrapper.getUrl()); + applicationReleaseDTO.setIsSharedWithAllTenants(webClipReleaseWrapper.getIsSharedWithAllTenants()); + applicationReleaseDTO.setMetaData(webClipReleaseWrapper.getMetaData()); + } + return applicationReleaseDTO; + } + public static Application appDtoToAppResponse(ApplicationDTO applicationDTO) throws BadRequestException, UnexpectedServerErrorException { 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/ApplicationManagementPublisherAPI.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/ApplicationManagementPublisherAPI.java index 19323962e16..2aef9d23af5 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/ApplicationManagementPublisherAPI.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/ApplicationManagementPublisherAPI.java @@ -42,6 +42,7 @@ import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; import java.util.List; import javax.validation.Valid; @@ -337,6 +338,71 @@ public interface ApplicationManagementPublisherAPI { @Multipart(value = "screenshot3") Attachment screenshot3 ); + @POST + @Path("/web-app") + @Produces(MediaType.APPLICATION_JSON) + @Consumes("multipart/mixed") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Create an web app", + notes = "This will create a new web app", + tags = "Application Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 201, + message = "OK. \n Successfully created a web application.", + response = ApplicationDTO.class), + @ApiResponse( + code = 400, + message = "Bad Request. \n " + + "Web app creating payload contains unacceptable or vulnerable data"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while creating the web app.", + response = ErrorResponse.class) + }) + Response createWebApp( + @ApiParam( + name = "webapp", + value = "The web app that need to be created.", + required = true) + @Multipart("webapp") WebClipWrapper webClipWrapper, + @ApiParam( + name = "icon", + value = "Icon of the uploading web app", + required = true) + @Multipart(value = "icon") Attachment iconFile, + @ApiParam( + name = "banner", + value = "Banner of the uploading web app", + required = true) + @Multipart(value = "banner") Attachment bannerFile, + @ApiParam( + name = "screenshot1", + value = "Screen Shots of the uploading web app", + required = true) + @Multipart(value = "screenshot1") Attachment screenshot1, + @ApiParam( + name = "screenshot2", + value = "Screen Shots of the uploading web app", + required = false) + @Multipart(value = "screenshot2") Attachment screenshot2, + @ApiParam( + name = "screenshot3", + value = "Screen Shots of the uploading web app", + required = false) + @Multipart(value = "screenshot3") Attachment screenshot3 + ); + @POST @Produces(MediaType.APPLICATION_JSON) @Consumes("multipart/mixed") 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/ApplicationManagementPublisherAPIImpl.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/ApplicationManagementPublisherAPIImpl.java index 9d53177a031..d2e696944e3 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/ApplicationManagementPublisherAPIImpl.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/ApplicationManagementPublisherAPIImpl.java @@ -32,6 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; @@ -179,8 +180,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem List attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); try { applicationManager.validateAppCreatingRequest(applicationWrapper); - applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0), - applicationWrapper.getType()); + applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0)); applicationManager.validateBinaryArtifact(binaryFile, applicationWrapper.getType()); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); @@ -205,6 +205,44 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem } } + @POST + @Consumes("multipart/mixed") + @Path("/web-app") + public Response createWebApp( + @Multipart("webapp") WebClipWrapper webClipWrapper, + @Multipart("icon") Attachment iconFile, + @Multipart("banner") Attachment bannerFile, + @Multipart("screenshot1") Attachment screenshot1, + @Multipart("screenshot2") Attachment screenshot2, + @Multipart("screenshot3") Attachment screenshot3) { + ApplicationManager applicationManager = APIUtil.getApplicationManager(); + List attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); + try { + applicationManager.validateAppCreatingRequest(webClipWrapper); + applicationManager.validateReleaseCreatingRequest(webClipWrapper.getWebClipReleaseWrappers().get(0)); + applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); + + // Created new application entry + Application application = applicationManager.createWebClip(webClipWrapper, + constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); + if (application != null) { + return Response.status(Response.Status.CREATED).entity(application).build(); + } else { + String msg = "Web app creation is failed"; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } catch (ApplicationManagementException e) { + String msg = "Error occurred while creating the web application"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (RequestValidatingException e) { + String msg = "Error occurred while handling the web app creating request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } + } + @POST @Consumes("multipart/mixed") @Path("/{appType}/{appId}") @@ -221,7 +259,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem ApplicationManager applicationManager = APIUtil.getApplicationManager(); List attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); try { - applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper, appType); + applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper); applicationManager.validateBinaryArtifact(binaryFile, appType); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); From 28bc9f3a77463fb920debd82daabeda41e9e4d47 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 4 Jun 2019 15:28:15 +0530 Subject: [PATCH 11/14] Improve web clip registering in APPM --- .../mgt/common/ApplicationType.java | 2 +- .../common/services/ApplicationManager.java | 4 +- ...Wrapper.java => WebAppReleaseWrapper.java} | 23 +++++++- ...WebClipWrapper.java => WebAppWrapper.java} | 31 ++++++++--- .../GenericApplicationDAOImpl.java | 2 +- .../mgt/core/impl/ApplicationManagerImpl.java | 54 +++++++++---------- .../application/mgt/core/util/APIUtil.java | 49 +++++++++-------- .../mgt/handler/util/HandlerUtil.java | 8 +++ .../ApplicationManagementPublisherAPI.java | 4 +- ...ApplicationManagementPublisherAPIImpl.java | 10 ++-- .../dbscripts/cdm/application-mgt/h2.sql | 2 +- 11 files changed, 121 insertions(+), 68 deletions(-) rename components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/{WebClipReleaseWrapper.java => WebAppReleaseWrapper.java} (81%) rename components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/{WebClipWrapper.java => WebAppWrapper.java} (78%) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java index 3b0049e51aa..289e36938ee 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java @@ -23,6 +23,6 @@ package org.wso2.carbon.device.application.mgt.common; * Application Types. */ public enum ApplicationType { - ENTERPRISE, PUBLIC, WEB, WEB_CLIP + ENTERPRISE, PUBLIC, WEB_APP, WEB_CLIP } 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 a0979e449c0..ce66315c1de 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 @@ -35,7 +35,7 @@ import org.wso2.carbon.device.application.mgt.common.response.Tag; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import java.util.List; @@ -54,7 +54,7 @@ public interface ApplicationManager { Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException, RequestValidatingException; - Application createWebClip(WebClipWrapper webClipWrapper, ApplicationArtifact applicationArtifact) + Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) 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/wrapper/WebClipReleaseWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppReleaseWrapper.java similarity index 81% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipReleaseWrapper.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppReleaseWrapper.java index 8187eda76b2..9cf11f23744 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipReleaseWrapper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppReleaseWrapper.java @@ -19,17 +19,22 @@ package org.wso2.carbon.device.application.mgt.common.wrapper; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotNull; + +//todo add version attribute @ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store") -public class WebClipReleaseWrapper { +public class WebAppReleaseWrapper { @ApiModelProperty(name = "description", value = "Description of the web clip release") + @NotNull private String description; @ApiModelProperty(name = "releaseType", value = "Release type of the web clip release", required = true, example = "alpha, beta etc") + @NotNull private String releaseType; @ApiModelProperty(name = "price", @@ -40,6 +45,7 @@ public class WebClipReleaseWrapper { @ApiModelProperty(name = "isSharedWithAllTenants", value = "If web clip release is shared with all tenants it is equal to 1 otherwise 0", required = true) + @NotNull private boolean isSharedWithAllTenants; @ApiModelProperty(name = "metaData", @@ -47,8 +53,15 @@ public class WebClipReleaseWrapper { required = true) private String metaData; + @ApiModelProperty(name = "version", + value = "Version of the web app release.", + required = true) + @NotNull + private String version; + @ApiModelProperty(name = "url", value = "URL which is used for WEB-CLIP") + @NotNull private String url; public String getReleaseType() { @@ -94,4 +107,12 @@ public class WebClipReleaseWrapper { public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } + + public boolean isSharedWithAllTenants() { return isSharedWithAllTenants; } + + public void setSharedWithAllTenants(boolean sharedWithAllTenants) { isSharedWithAllTenants = sharedWithAllTenants; } + + public String getVersion() { return version; } + + public void setVersion(String version) { this.version = version; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppWrapper.java similarity index 78% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipWrapper.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppWrapper.java index b5c1b5ce420..1c5bba1d201 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipWrapper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppWrapper.java @@ -19,33 +19,45 @@ package org.wso2.carbon.device.application.mgt.common.wrapper; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotNull; import java.util.List; -@ApiModel(value = "WebClipWrapper", description = "WebClipWrapper represents an ApplicationDTO in ApplicationDTO Store") -public class WebClipWrapper { +@ApiModel(value = "WebAppWrapper", description = "WebAppWrapper represents an ApplicationDTO in ApplicationDTO Store") +public class WebAppWrapper { @ApiModelProperty(name = "name", value = "Name of the web clip", required = true) + @NotNull private String name; @ApiModelProperty(name = "description", value = "Description of the web clip", required = true) + @NotNull private String description; @ApiModelProperty(name = "categories", value = "List of Categories", required = true, example = "Educational, Gaming, Travel, Entertainment etc") + @NotNull private List categories; @ApiModelProperty(name = "subType", value = "Subscription method of the web clip", required = true, example = "PAID, FREE") + @NotNull private String subMethod; + @ApiModelProperty(name = "Web App Type", + value = "Type of the web app", + required = true, + example = "WEB_APP, WEB_CLIP") + @NotNull + private String type; + @ApiModelProperty(name = "paymentCurrency", value = "Payment currency of the web clip", required = true, @@ -54,16 +66,19 @@ public class WebClipWrapper { @ApiModelProperty(name = "tags", value = "List of tags") + @NotNull private List tags; @ApiModelProperty(name = "unrestrictedRoles", value = "List of roles that users should have to view the web clip") + @NotNull private List unrestrictedRoles; @ApiModelProperty(name = "applicationReleaseWrappers", value = "List of web clip releases", required = true) - private List webClipReleaseWrappers; + @NotNull + private List webAppReleaseWrappers; public String getName() { return name; @@ -87,10 +102,10 @@ public class WebClipWrapper { public void setDescription(String description) { this.description = description; } - public List getWebClipReleaseWrappers() { return webClipReleaseWrappers; } + public List getWebAppReleaseWrappers() { return webAppReleaseWrappers; } - public void setWebClipReleaseWrappers(List webClipReleaseWrappers) { - this.webClipReleaseWrappers = webClipReleaseWrappers; } + public void setWebAppReleaseWrappers(List webAppReleaseWrappers) { + this.webAppReleaseWrappers = webAppReleaseWrappers; } public List getCategories() { return categories; } @@ -99,4 +114,8 @@ public class WebClipWrapper { public String getSubMethod() { return subMethod; } public void setSubMethod(String subMethod) { this.subMethod = subMethod; } + + public String getType() { return type; } + + public void setType(String type) { this.type = type; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index e98096d865f..023a854cf1b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -1028,7 +1028,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic Connection conn; String sql = "UPDATE " + "AP_APP_CATEGORY cat " + - "SET cat.CATEGORY_NAME = ? " + + "SET cat.CATEGORY = ? " + "WHERE " + "cat.ID = ? AND " + "cat.TENANT_ID = ?"; 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 a0152321d3f..55859fd1274 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 @@ -58,8 +58,8 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipReleaseWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; @@ -622,7 +622,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public Application createWebClip(WebClipWrapper webClipWrapper, ApplicationArtifact applicationArtifact) + public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); @@ -632,7 +632,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } List categoryIds; - ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webClipWrapper); + ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper); List unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); List tags = applicationDTO.getTags(); List categories = applicationDTO.getAppCategories(); @@ -645,7 +645,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { String msg = "Error occurred while getting data which is related to application. application name: " - + webClipWrapper.getName() + "."; + + webAppWrapper.getName() + "."; log.error(msg); throw new ApplicationManagementException(msg, e); } finally { @@ -665,7 +665,7 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); } catch (ResourceManagementException e) { - String msg = "Error Occured when uploading artifacts of the application: " + webClipWrapper.getName(); + String msg = "Error Occured when uploading artifacts of the application: " + webAppWrapper.getName(); log.error(msg); throw new ApplicationManagementException(msg, e); } @@ -748,7 +748,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (LifeCycleManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); String msg = - "Error occurred while adding lifecycle state. application name: " + webClipWrapper.getName() + "."; + "Error occurred while adding lifecycle state. application name: " + webAppWrapper.getName() + "."; log.error(msg); try { applicationStorageManager.deleteAllApplicationReleaseArtifacts( @@ -764,13 +764,13 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); String msg = "Error occurred while adding application or application release. application name: " - + webClipWrapper.getName() + "."; + + webAppWrapper.getName() + "."; log.error(msg); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); throw new ApplicationManagementException(msg, e); } catch (LifecycleManagementException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred when getting initial lifecycle state. application name: " + webClipWrapper + String msg = "Error occurred when getting initial lifecycle state. application name: " + webAppWrapper .getName() + "."; log.error(msg); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); @@ -782,7 +782,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (VisibilityManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); String msg = - "Error occurred while adding unrestricted roles. application name: " + webClipWrapper.getName() + "Error occurred while adding unrestricted roles. application name: " + webAppWrapper.getName() + "."; log.error(msg); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); @@ -2489,37 +2489,37 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } - } else if (param instanceof WebClipWrapper) { - WebClipWrapper webClipWrapper = (WebClipWrapper) param; - if (StringUtils.isEmpty(webClipWrapper.getName())) { + } else if (param instanceof WebAppWrapper) { + WebAppWrapper webAppWrapper = (WebAppWrapper) param; + if (StringUtils.isEmpty(webAppWrapper.getName())) { String msg = "Web Clip name cannot be empty."; log.error(msg); throw new BadRequestException(msg); } - if (webClipWrapper.getCategories() == null) { + if (webAppWrapper.getCategories() == null) { String msg = "Web Clip category can't be null."; log.error(msg); throw new BadRequestException(msg); } - if (webClipWrapper.getCategories().isEmpty()) { + if (webAppWrapper.getCategories().isEmpty()) { String msg = "Web clip category can't be empty."; log.error(msg); throw new BadRequestException(msg); } - List webClipReleaseWrappers; - webClipReleaseWrappers = webClipWrapper.getWebClipReleaseWrappers(); + List webAppReleaseWrappers; + webAppReleaseWrappers = webAppWrapper.getWebAppReleaseWrappers(); - if (webClipReleaseWrappers == null || webClipReleaseWrappers.size() != 1) { + if (webAppReleaseWrappers == null || webAppReleaseWrappers.size() != 1) { String msg = "Invalid web clip creating request. Web clip creating request must have single " - + "web clip release. Web clip name:" + webClipWrapper.getName() + "."; + + "web clip release. Web clip name:" + webAppWrapper.getName() + "."; log.error(msg); throw new BadRequestException(msg); } try { ConnectionManagerUtil.openDBConnection(); - List unrestrictedRoles = webClipWrapper.getUnrestrictedRoles(); + List unrestrictedRoles = webAppWrapper.getUnrestrictedRoles(); if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { if (!isValidRestrictedRole(unrestrictedRoles)) { @@ -2538,7 +2538,7 @@ public class ApplicationManagerImpl implements ApplicationManager { Filter filter = new Filter(); filter.setFullMatch(true); - filter.setAppName(webClipWrapper.getName().trim()); + filter.setAppName(webAppWrapper.getName().trim()); filter.setOffset(0); filter.setLimit(1); List applicationList = applicationDAO.getApplications(filter, -1, tenantId); @@ -2551,7 +2551,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } List registeredCategories = this.applicationDAO.getAllCategories(tenantId); - List appCategories = webClipWrapper.getCategories(); + List appCategories = webAppWrapper.getCategories(); if (registeredCategories.isEmpty()) { ConnectionManagerUtil.rollbackDBTransaction(); @@ -2583,7 +2583,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { String msg = "Error occurred while getting data which is related to web clip. web clip name: " - + webClipWrapper.getName() + "."; + + webAppWrapper.getName() + "."; log.error(msg); throw new ApplicationManagementException(msg, e); } catch (UserStoreException e) { @@ -2614,16 +2614,16 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } - } if (param instanceof WebClipReleaseWrapper){ - WebClipReleaseWrapper webClipReleaseWrapper = (WebClipReleaseWrapper) param; + } if (param instanceof WebAppReleaseWrapper){ + WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param; UrlValidator urlValidator = new UrlValidator(); if (StringUtils - .isEmpty(webClipReleaseWrapper.getUrl())){ + .isEmpty(webAppReleaseWrapper.getUrl())){ String msg = "URL should't be null for the application release creating request for application type WEB_CLIP"; log.error(msg); throw new BadRequestException(msg); } - if (!urlValidator.isValid(webClipReleaseWrapper.getUrl())){ + if (!urlValidator.isValid(webAppReleaseWrapper.getUrl())){ String msg = "Request payload contains an invalid Web Clip URL."; log.error(msg); throw new BadRequestException(msg); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index 47f95cf0e63..74c49c11878 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -30,8 +30,8 @@ import org.wso2.carbon.device.application.mgt.common.services.*; import org.wso2.carbon.device.application.mgt.common.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipReleaseWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; @@ -235,16 +235,17 @@ public class APIUtil { List applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers() .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); - } else if (param instanceof WebClipWrapper){ - WebClipWrapper webClipWrapper = (WebClipWrapper) param; - applicationDTO.setName(webClipWrapper.getName()); - applicationDTO.setDescription(webClipWrapper.getDescription()); - applicationDTO.setAppCategories(webClipWrapper.getCategories()); - applicationDTO.setSubType(webClipWrapper.getSubMethod()); - applicationDTO.setPaymentCurrency(webClipWrapper.getPaymentCurrency()); - applicationDTO.setTags(webClipWrapper.getTags()); - applicationDTO.setUnrestrictedRoles(webClipWrapper.getUnrestrictedRoles()); - List applicationReleaseEntities = webClipWrapper.getWebClipReleaseWrappers() + } else if (param instanceof WebAppWrapper){ + WebAppWrapper webAppWrapper = (WebAppWrapper) param; + applicationDTO.setName(webAppWrapper.getName()); + applicationDTO.setDescription(webAppWrapper.getDescription()); + applicationDTO.setAppCategories(webAppWrapper.getCategories()); + applicationDTO.setSubType(webAppWrapper.getSubMethod()); + applicationDTO.setPaymentCurrency(webAppWrapper.getPaymentCurrency()); + applicationDTO.setType(webAppWrapper.getType()); + applicationDTO.setTags(webAppWrapper.getTags()); + applicationDTO.setUnrestrictedRoles(webAppWrapper.getUnrestrictedRoles()); + List applicationReleaseEntities = webAppWrapper.getWebAppReleaseWrappers() .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); } @@ -262,14 +263,15 @@ public class APIUtil { applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseWrapper.getIsSharedWithAllTenants()); applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData()); applicationReleaseDTO.setSupportedOsVersions(applicationReleaseWrapper.getSupportedOsVersions()); - } else if (param instanceof WebClipReleaseWrapper){ - WebClipReleaseWrapper webClipReleaseWrapper = (WebClipReleaseWrapper) param; - applicationReleaseDTO.setDescription(webClipReleaseWrapper.getDescription()); - applicationReleaseDTO.setReleaseType(webClipReleaseWrapper.getReleaseType()); - applicationReleaseDTO.setPrice(webClipReleaseWrapper.getPrice()); - applicationReleaseDTO.setInstallerName(webClipReleaseWrapper.getUrl()); - applicationReleaseDTO.setIsSharedWithAllTenants(webClipReleaseWrapper.getIsSharedWithAllTenants()); - applicationReleaseDTO.setMetaData(webClipReleaseWrapper.getMetaData()); + } else if (param instanceof WebAppReleaseWrapper){ + WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param; + applicationReleaseDTO.setDescription(webAppReleaseWrapper.getDescription()); + applicationReleaseDTO.setReleaseType(webAppReleaseWrapper.getReleaseType()); + applicationReleaseDTO.setVersion(webAppReleaseWrapper.getVersion()); + applicationReleaseDTO.setPrice(webAppReleaseWrapper.getPrice()); + applicationReleaseDTO.setInstallerName(webAppReleaseWrapper.getUrl()); + applicationReleaseDTO.setIsSharedWithAllTenants(webAppReleaseWrapper.getIsSharedWithAllTenants()); + applicationReleaseDTO.setMetaData(webAppReleaseWrapper.getMetaData()); } return applicationReleaseDTO; } @@ -278,7 +280,11 @@ public class APIUtil { throws BadRequestException, UnexpectedServerErrorException { Application application = new Application(); - DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); + //This is for handling web-apps + if (applicationDTO.getDeviceTypeId() > 0) { + DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); + application.setDeviceType(deviceType.getName()); + } application.setId(applicationDTO.getId()); application.setName(applicationDTO.getName()); application.setDescription(applicationDTO.getDescription()); @@ -288,7 +294,6 @@ public class APIUtil { application.setPaymentCurrency(applicationDTO.getPaymentCurrency()); application.setTags(applicationDTO.getTags()); application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles()); - application.setDeviceType(deviceType.getName()); application.setRating(applicationDTO.getAppRating()); List applicationReleases = applicationDTO.getApplicationReleaseDTOs() .stream().map(APIUtil::releaseDtoToRelease).collect(Collectors.toList()); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerUtil.java index cf14b96651c..e49659c9809 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerUtil.java @@ -24,8 +24,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; +import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.json.JSONException; @@ -60,6 +62,12 @@ public class HandlerUtil { } else if (httpMethod instanceof HttpGet) { HttpGet method = (HttpGet) httpMethod; response = client.execute(method); + } else if (httpMethod instanceof HttpPut) { + HttpPut method = (HttpPut) httpMethod; + response = client.execute(method); + } else if (httpMethod instanceof HttpDelete) { + HttpDelete method = (HttpDelete) httpMethod; + response = client.execute(method); } ProxyResponse proxyResponse = new ProxyResponse(); 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/ApplicationManagementPublisherAPI.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/ApplicationManagementPublisherAPI.java index 2aef9d23af5..aa97ff02432 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/ApplicationManagementPublisherAPI.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/ApplicationManagementPublisherAPI.java @@ -42,7 +42,7 @@ import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import java.util.List; import javax.validation.Valid; @@ -375,7 +375,7 @@ public interface ApplicationManagementPublisherAPI { name = "webapp", value = "The web app that need to be created.", required = true) - @Multipart("webapp") WebClipWrapper webClipWrapper, + @Multipart("webapp") WebAppWrapper webAppWrapper, @ApiParam( name = "icon", value = "Icon of the uploading web app", 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/ApplicationManagementPublisherAPIImpl.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/ApplicationManagementPublisherAPIImpl.java index d2e696944e3..323f476b7a6 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/ApplicationManagementPublisherAPIImpl.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/ApplicationManagementPublisherAPIImpl.java @@ -32,7 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; @@ -209,7 +209,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Consumes("multipart/mixed") @Path("/web-app") public Response createWebApp( - @Multipart("webapp") WebClipWrapper webClipWrapper, + @Multipart("webapp") WebAppWrapper webAppWrapper, @Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, @Multipart("screenshot1") Attachment screenshot1, @@ -218,12 +218,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem ApplicationManager applicationManager = APIUtil.getApplicationManager(); List attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); try { - applicationManager.validateAppCreatingRequest(webClipWrapper); - applicationManager.validateReleaseCreatingRequest(webClipWrapper.getWebClipReleaseWrappers().get(0)); + applicationManager.validateAppCreatingRequest(webAppWrapper); + applicationManager.validateReleaseCreatingRequest(webAppWrapper.getWebAppReleaseWrappers().get(0)); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); // Created new application entry - Application application = applicationManager.createWebClip(webClipWrapper, + Application application = applicationManager.createWebClip(webAppWrapper, constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); if (application != null) { return Response.status(Response.Status.CREATED).entity(application).build(); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index e0d12e92890..b2816cb5f1f 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_RELEASE( APP_HASH_VALUE VARCHAR(1000) NOT NULL, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, APP_META_INFO CLOB NULL DEFAULT NULL, - SUPPORTED_OS_VERSIONS VARCHAR(45) NOT NULL, + SUPPORTED_OS_VERSIONS VARCHAR(45) NULL DEFAULT NULL, RATING DOUBLE NULL DEFAULT NULL, CURRENT_STATE VARCHAR(45) NOT NULL, RATED_USERS INTEGER NULL, From 9b66b8e44cef9bf0f0ecdef6c03d5ede4a760cf9 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 4 Jun 2019 16:14:12 +0530 Subject: [PATCH 12/14] Fix issues in category updating functionality --- .../common/response/ApplicationRelease.java | 12 ----------- .../GenericApplicationDAOImpl.java | 4 ++-- .../application/mgt/core/util/APIUtil.java | 21 ++++++++++++++----- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java index 78be9b6bbc2..fe81d500deb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java @@ -81,10 +81,6 @@ public class ApplicationRelease { required = true) private String metaData; - @ApiModelProperty(name = "url", - value = "URL which is used for WEB-CLIP") - private String url; - @ApiModelProperty(name = "supportedOsVersions", value = "ApplicationDTO release supported OS versions") private String supportedOsVersions; @@ -125,14 +121,6 @@ public class ApplicationRelease { return metaData; } - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 023a854cf1b..d3f79ab433e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -1036,8 +1036,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic conn = this.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setString(1, categoryDTO.getCategoryName()); - stmt.setInt(1, categoryDTO.getId()); - stmt.setInt(2, tenantId); + stmt.setInt(2, categoryDTO.getId()); + stmt.setInt(3, tenantId); stmt.executeUpdate(); } } catch (DBConnectionException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index 74c49c11878..7611e08ca81 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -21,7 +21,9 @@ package org.wso2.carbon.device.application.mgt.core.util; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.commons.validator.routines.UrlValidator; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.application.mgt.common.ApplicationType; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.response.Application; @@ -280,10 +282,11 @@ public class APIUtil { throws BadRequestException, UnexpectedServerErrorException { Application application = new Application(); - //This is for handling web-apps - if (applicationDTO.getDeviceTypeId() > 0) { + if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); application.setDeviceType(deviceType.getName()); + } else { + application.setDeviceType("ANY"); } application.setId(applicationDTO.getId()); application.setName(applicationDTO.getName()); @@ -306,8 +309,11 @@ public class APIUtil { .getArtifactDownloadEndpoint(); String basePath = artifactDownloadEndpoint + Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid() + Constants.FORWARD_SLASH; + List screenshotPaths = new ArrayList<>(); ApplicationRelease applicationRelease = new ApplicationRelease(); + UrlValidator urlValidator = new UrlValidator(); + applicationRelease.setDescription(applicationReleaseDTO.getDescription()); applicationRelease.setVersion(applicationReleaseDTO.getVersion()); applicationRelease.setUuid(applicationReleaseDTO.getUuid()); @@ -315,16 +321,21 @@ public class APIUtil { applicationRelease.setPrice(applicationReleaseDTO.getPrice()); applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); applicationRelease.setMetaData(applicationReleaseDTO.getMetaData()); - applicationRelease.setUrl(applicationReleaseDTO.getUrl()); applicationRelease.setCurrentStatus(applicationReleaseDTO.getCurrentState()); applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions()); applicationRelease.setRating(applicationReleaseDTO.getRating()); - applicationRelease - .setInstallerPath(basePath + applicationReleaseDTO.getInstallerName()); applicationRelease.setIconPath(basePath + applicationReleaseDTO.getIconName()); applicationRelease.setBannerPath(basePath + applicationReleaseDTO.getBannerName()); + if (urlValidator.isValid(applicationReleaseDTO.getInstallerName())){ + applicationRelease + .setInstallerPath(applicationReleaseDTO.getInstallerName()); + } else { + applicationRelease + .setInstallerPath(basePath + applicationReleaseDTO.getInstallerName()); + } + if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) { screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName1()); } From be7c1005f6f6f74a9958cdefcc71a42a8162b1af Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 5 Jun 2019 18:26:23 +0530 Subject: [PATCH 13/14] Improve web clip registering method --- .../mgt/core/impl/ApplicationManagerImpl.java | 735 +++++++----------- .../application/mgt/core/util/APIUtil.java | 1 + .../dbscripts/cdm/application-mgt/h2.sql | 2 +- 3 files changed, 265 insertions(+), 473 deletions(-) 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 55859fd1274..c005463aded 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 @@ -145,94 +145,7 @@ public class ApplicationManagerImpl implements ApplicationManager { + userName); } - ApplicationDTO applicationDTO; - List unrestrictedRoles; - List categoryIds = new ArrayList<>(); - List tags; - - //validating and verifying application data - try { - ConnectionManagerUtil.openDBConnection(); - applicationDTO = APIUtil.convertToAppDTO(applicationWrapper); - unrestrictedRoles = applicationWrapper.getUnrestrictedRoles(); - tags = applicationWrapper.getTags(); - - if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { - if (!isValidRestrictedRole(unrestrictedRoles)) { - String msg = "Unrestricted role list contain role/roles which are not in the user store."; - log.error(msg); - throw new ApplicationManagementException(msg); - } - if (!hasUserRole(unrestrictedRoles, userName)) { - String msg = "You are trying to restrict the visibility of the application for a role set, but " - + "in order to perform the action at least one role should be assigned to user: " - + userName; - log.error(msg); - throw new BadRequestException(msg); - } - } - - Filter filter = new Filter(); - filter.setFullMatch(true); - filter.setAppName(applicationDTO.getName().trim()); - filter.setOffset(0); - filter.setLimit(1); - List applicationList = applicationDAO - .getApplications(filter, applicationDTO.getDeviceTypeId(), tenantId); - if (!applicationList.isEmpty()) { - String msg = "Already an application registered with same name - " + applicationList.get(0).getName() - + " for the device type " + applicationWrapper.getDeviceType(); - log.error(msg); - throw new RequestValidatingException(msg); - } - - List registeredCategories = this.applicationDAO.getAllCategories(tenantId); - List appCategories = applicationWrapper.getAppCategories(); - - if (registeredCategories.isEmpty()) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Registered application category set is empty. Since it is mandatory to add application " - + "category when adding new application, registered application category list shouldn't be null."; - log.error(msg); - throw new ApplicationManagementException(msg); - } - for (String cat : appCategories) { - boolean isValidCategory = false; - for (CategoryDTO obj : registeredCategories) { - if (cat.equals(obj.getCategoryName())) { - categoryIds.add(obj.getId()); - isValidCategory = true; - break; - } - } - if (!isValidCategory) { - String msg = "Application Creating request contains invalid categories. Hence please verify the " - + "application creating payload."; - log.error(msg); - throw new BadRequestException(msg); - } - } - } catch (DBConnectionException e) { - String msg = "Error occurred while getting database connection."; - log.error(msg); - throw new ApplicationManagementException(msg, e); - } catch (UnexpectedServerErrorException e) { - String msg = "Error occurred when getting Device Type data."; - log.error(msg); - throw new ApplicationManagementException(msg, e); - } catch (ApplicationManagementDAOException e) { - String msg = "Error occurred while getting data which is related to application. application name: " - + applicationWrapper.getName() + " and application type: " + applicationWrapper.getType(); - log.error(msg); - throw new ApplicationManagementException(msg, e); - } catch (UserStoreException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred when validating the unrestricted roles given for the application"; - log.error(msg); - throw new ApplicationManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } + ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper); //uploading application artifacts try { @@ -247,133 +160,7 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new ApplicationManagementException(msg, e); } - - //insert application data into database - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); - ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); - try { - List applicationReleaseEntities = new ArrayList<>(); - - ConnectionManagerUtil.beginDBTransaction(); - // Insert to application table - int appId = this.applicationDAO.createApplication(applicationDTO, tenantId); - if (appId == -1) { - log.error("Application data storing is Failed."); - ConnectionManagerUtil.rollbackDBTransaction(); - deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); - return null; - } else { - if (log.isDebugEnabled()) { - log.debug("New ApplicationDTO entry added to AP_APP table. App Id:" + appId); - } - //add application categories - this.applicationDAO.addCategoryMapping(categoryIds, appId, tenantId); - - //adding application unrestricted roles - if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { - this.visibilityDAO.addUnrestrictedRoles(unrestrictedRoles, appId, tenantId); - if (log.isDebugEnabled()) { - log.debug("New restricted roles to app ID mapping added to AP_UNRESTRICTED_ROLE table." - + " App Id:" + appId); - } - } - - //adding application tags - if (tags != null && !tags.isEmpty()) { - List registeredTags = applicationDAO.getAllTags(tenantId); - List registeredTagNames = new ArrayList<>(); - List tagIds = new ArrayList<>(); - - for (TagDTO tagDTO : registeredTags) { - registeredTagNames.add(tagDTO.getTagName()); - } - List newTags = getDifference(tags, registeredTagNames); - if (!newTags.isEmpty()) { - this.applicationDAO.addTags(newTags, tenantId); - if (log.isDebugEnabled()) { - log.debug("New tags entry added to AP_APP_TAG table. App Id:" + appId); - } - tagIds = this.applicationDAO.getTagIdsForTagNames(tags, tenantId); - } else { - for (TagDTO tagDTO : registeredTags) { - for (String tagName : tags) { - if (tagName.equals(tagDTO.getTagName())) { - tagIds.add(tagDTO.getId()); - break; - } - } - } - } - this.applicationDAO.addTagMapping(tagIds, appId, tenantId); - } - - if (log.isDebugEnabled()) { - log.debug("Creating a new release. App Id:" + appId); - } - String initialLifecycleState = lifecycleStateManager.getInitialState(); - applicationReleaseDTO.setCurrentState(initialLifecycleState); - applicationReleaseDTO = this.applicationReleaseDAO - .createRelease(applicationReleaseDTO, appId, tenantId); - LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState, - initialLifecycleState); - this.lifecycleStateDAO - .addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); - applicationReleaseEntities.add(applicationReleaseDTO); - applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); - Application application = APIUtil.appDtoToAppResponse(applicationDTO); - ConnectionManagerUtil.commitDBTransaction(); - return application; - } - } catch (LifeCycleManagementDAOException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = - "Error occurred while adding lifecycle state. application name: " + applicationWrapper.getName() - + " application type: is " + applicationWrapper.getType(); - log.error(msg); - try { - applicationStorageManager.deleteAllApplicationReleaseArtifacts( - Collections.singletonList(applicationReleaseDTO.getAppHashValue())); - } catch (ApplicationStorageManagementException ex) { - String errorLog = - "Error occurred when deleting application artifacts. Application artifacts are tried to " - + "delete because of lifecycle state adding issue in the application creating operation."; - log.error(errorLog); - throw new ApplicationManagementException(errorLog, e); - } - throw new ApplicationManagementException(msg, e); - } catch (ApplicationManagementDAOException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred while adding application or application release. application name: " - + applicationWrapper.getName() + " application type: " + applicationWrapper.getType(); - log.error(msg); - deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); - throw new ApplicationManagementException(msg, e); - } catch (LifecycleManagementException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred when getting initial lifecycle state. application name: " + applicationWrapper - .getName() + " application type: is " + applicationWrapper.getType(); - log.error(msg); - deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); - throw new ApplicationManagementException(msg, e); - } catch (DBConnectionException e) { - String msg = "Error occurred while getting database connection."; - log.error(msg); - throw new ApplicationManagementException(msg, e); - } catch (VisibilityManagementDAOException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = - "Error occurred while adding unrestricted roles. application name: " + applicationWrapper.getName() - + " application type: " + applicationWrapper.getType(); - log.error(msg); - deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); - throw new ApplicationManagementException(msg, e); - } catch (TransactionManagementException e) { - String msg = "Error occurred while disabling AutoCommit."; - log.error(msg); - throw new ApplicationManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } + return addAppDataIntoDB(applicationDTO, tenantId); } private void deleteApplicationArtifacts(List directoryPaths) throws ApplicationManagementException { @@ -612,189 +399,44 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationReleaseDTO.setScreenshotName3(scName); } counter++; - } - - // Upload images - applicationReleaseDTO = applicationStorageManager - .uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(), - applicationArtifact.getBannerStream(), new ArrayList<>(screenshots.values())); - return applicationReleaseDTO; - } - - @Override - public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) - throws ApplicationManagementException { - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - if (log.isDebugEnabled()) { - log.debug("Application create request is received for the tenant : " + tenantId + " From" + " the user : " - + userName); - } - - List categoryIds; - ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper); - List unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); - List tags = applicationDTO.getTags(); - List categories = applicationDTO.getAppCategories(); - try { - ConnectionManagerUtil.openDBConnection(); - categoryIds = applicationDAO.getCategoryIdsForCategoryNames(categories, tenantId); - } catch (DBConnectionException e) { - String msg = "Error occurred while getting database connection."; - log.error(msg); - throw new ApplicationManagementException(msg, e); - } catch (ApplicationManagementDAOException e) { - String msg = "Error occurred while getting data which is related to application. application name: " - + webAppWrapper.getName() + "."; - log.error(msg); - throw new ApplicationManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } - - ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); - String uuid = UUID.randomUUID().toString(); - applicationReleaseDTO.setUuid(uuid); - String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName()); - applicationReleaseDTO.setAppHashValue(md5); - applicationDTO.setType(ApplicationType.WEB_CLIP.toString()); - - //uploading application artifacts - try { - applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact); - applicationDTO.getApplicationReleaseDTOs().clear(); - applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); - } catch (ResourceManagementException e) { - String msg = "Error Occured when uploading artifacts of the application: " + webAppWrapper.getName(); - log.error(msg); - throw new ApplicationManagementException(msg, e); - } - - //insert application data into database - ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); - try { - List applicationReleaseEntities = new ArrayList<>(); - - ConnectionManagerUtil.beginDBTransaction(); - // Insert to application table - int appId = this.applicationDAO.createApplication(applicationDTO, tenantId); - if (appId == -1) { - log.error("Application data storing is Failed."); - ConnectionManagerUtil.rollbackDBTransaction(); - deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); - return null; - } else { - if (log.isDebugEnabled()) { - log.debug("New ApplicationDTO entry added to AP_APP table. App Id:" + appId); - } - //add application categories - this.applicationDAO.addCategoryMapping(categoryIds, appId, tenantId); - - //adding application unrestricted roles - if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { - this.visibilityDAO.addUnrestrictedRoles(unrestrictedRoles, appId, tenantId); - if (log.isDebugEnabled()) { - log.debug("New restricted roles to app ID mapping added to AP_UNRESTRICTED_ROLE table." - + " App Id:" + appId); - } - } - - //adding application tags - if (tags != null && !tags.isEmpty()) { - List registeredTags = applicationDAO.getAllTags(tenantId); - List registeredTagNames = new ArrayList<>(); - List tagIds = new ArrayList<>(); - - for (TagDTO tagDTO : registeredTags) { - registeredTagNames.add(tagDTO.getTagName()); - } - List newTags = getDifference(tags, registeredTagNames); - if (!newTags.isEmpty()) { - this.applicationDAO.addTags(newTags, tenantId); - if (log.isDebugEnabled()) { - log.debug("New tags entry added to AP_APP_TAG table. App Id:" + appId); - } - tagIds = this.applicationDAO.getTagIdsForTagNames(tags, tenantId); - } else { - for (TagDTO tagDTO : registeredTags) { - for (String tagName : tags) { - if (tagName.equals(tagDTO.getTagName())) { - tagIds.add(tagDTO.getId()); - break; - } - } - } - } - this.applicationDAO.addTagMapping(tagIds, appId, tenantId); - } - - if (log.isDebugEnabled()) { - log.debug("Creating a new release. App Id:" + appId); - } - String initialLifecycleState = lifecycleStateManager.getInitialState(); - applicationReleaseDTO.setCurrentState(initialLifecycleState); - applicationReleaseDTO = this.applicationReleaseDAO - .createRelease(applicationReleaseDTO, appId, tenantId); - LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState, - initialLifecycleState); - this.lifecycleStateDAO - .addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); - applicationReleaseEntities.add(applicationReleaseDTO); - applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); - Application application = APIUtil.appDtoToAppResponse(applicationDTO); - ConnectionManagerUtil.commitDBTransaction(); - return application; - } - } catch (LifeCycleManagementDAOException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = - "Error occurred while adding lifecycle state. application name: " + webAppWrapper.getName() + "."; - log.error(msg); - try { - applicationStorageManager.deleteAllApplicationReleaseArtifacts( - Collections.singletonList(applicationReleaseDTO.getAppHashValue())); - } catch (ApplicationStorageManagementException ex) { - String errorLog = - "Error occurred when deleting application artifacts. Application artifacts are tried to " - + "delete because of lifecycle state adding issue in the application creating operation."; - log.error(errorLog); - throw new ApplicationManagementException(errorLog, e); - } - throw new ApplicationManagementException(msg, e); - } catch (ApplicationManagementDAOException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred while adding application or application release. application name: " - + webAppWrapper.getName() + "."; - log.error(msg); - deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); - throw new ApplicationManagementException(msg, e); - } catch (LifecycleManagementException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred when getting initial lifecycle state. application name: " + webAppWrapper - .getName() + "."; - log.error(msg); - deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); - throw new ApplicationManagementException(msg, e); - } catch (DBConnectionException e) { - String msg = "Error occurred while getting database connection."; - log.error(msg); - throw new ApplicationManagementException(msg, e); - } catch (VisibilityManagementDAOException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = - "Error occurred while adding unrestricted roles. application name: " + webAppWrapper.getName() - + "."; - log.error(msg); - deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); - throw new ApplicationManagementException(msg, e); - } catch (TransactionManagementException e) { - String msg = "Error occurred while disabling AutoCommit."; + } + + // Upload images + applicationReleaseDTO = applicationStorageManager + .uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(), + applicationArtifact.getBannerStream(), new ArrayList<>(screenshots.values())); + return applicationReleaseDTO; + } + + @Override + public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) + throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + if (log.isDebugEnabled()) { + log.debug("Application create request is received for the tenant : " + tenantId + " From" + " the user : " + + userName); + } + + ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper); + ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); + String uuid = UUID.randomUUID().toString(); + String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName()); + applicationReleaseDTO.setUuid(uuid); + applicationReleaseDTO.setAppHashValue(md5); + + //uploading application artifacts + try { + applicationDTO.getApplicationReleaseDTOs().clear(); + applicationDTO.getApplicationReleaseDTOs().add(addImageArtifacts(applicationReleaseDTO, applicationArtifact)); + } catch (ResourceManagementException e) { + String msg = "Error Occured when uploading artifacts of the application: " + webAppWrapper.getName(); log.error(msg); throw new ApplicationManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); } + //insert application data into database + return addAppDataIntoDB(applicationDTO, tenantId); } @Override @@ -911,6 +553,145 @@ public class ApplicationManagerImpl implements ApplicationManager { return false; } + /*** + * This method is responsible to add application data into APPM database. However, before call this method it is + * required to do the validation of request and check the existence of application releaseDTO. + * + * @param applicationDTO Application DTO object. + * @param tenantId Tenant Id + * @return {@link Application} + * @throws ApplicationManagementException which throws if error occurs while during application management. + */ + private Application addAppDataIntoDB(ApplicationDTO applicationDTO, int tenantId) + throws ApplicationManagementException { + ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); + List unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); + ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); + List categories = applicationDTO.getAppCategories(); + List tags = applicationDTO.getTags(); + List applicationReleaseEntities = new ArrayList<>(); + try { + ConnectionManagerUtil.beginDBTransaction(); + // Insert to application table + int appId = this.applicationDAO.createApplication(applicationDTO, tenantId); + if (appId == -1) { + log.error("Application data storing is Failed."); + ConnectionManagerUtil.rollbackDBTransaction(); + deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); + return null; + } else { + if (log.isDebugEnabled()) { + log.debug("New ApplicationDTO entry added to AP_APP table. App Id:" + appId); + } + //add application categories + + List categoryIds = applicationDAO.getCategoryIdsForCategoryNames(categories, tenantId); + this.applicationDAO.addCategoryMapping(categoryIds, appId, tenantId); + + //adding application unrestricted roles + if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { + this.visibilityDAO.addUnrestrictedRoles(unrestrictedRoles, appId, tenantId); + if (log.isDebugEnabled()) { + log.debug("New restricted roles to app ID mapping added to AP_UNRESTRICTED_ROLE table." + + " App Id:" + appId); + } + } + + //adding application tags + if (tags != null && !tags.isEmpty()) { + List registeredTags = applicationDAO.getAllTags(tenantId); + List registeredTagNames = new ArrayList<>(); + List tagIds = new ArrayList<>(); + + for (TagDTO tagDTO : registeredTags) { + registeredTagNames.add(tagDTO.getTagName()); + } + List newTags = getDifference(tags, registeredTagNames); + if (!newTags.isEmpty()) { + this.applicationDAO.addTags(newTags, tenantId); + if (log.isDebugEnabled()) { + log.debug("New tags entry added to AP_APP_TAG table. App Id:" + appId); + } + tagIds = this.applicationDAO.getTagIdsForTagNames(tags, tenantId); + } else { + for (TagDTO tagDTO : registeredTags) { + for (String tagName : tags) { + if (tagName.equals(tagDTO.getTagName())) { + tagIds.add(tagDTO.getId()); + break; + } + } + } + } + this.applicationDAO.addTagMapping(tagIds, appId, tenantId); + } + + if (log.isDebugEnabled()) { + log.debug("Creating a new release. App Id:" + appId); + } + String initialLifecycleState = lifecycleStateManager.getInitialState(); + applicationReleaseDTO.setCurrentState(initialLifecycleState); + applicationReleaseDTO = this.applicationReleaseDAO + .createRelease(applicationReleaseDTO, appId, tenantId); + LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState, initialLifecycleState); + this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); + applicationReleaseEntities.add(applicationReleaseDTO); + applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); + Application application = APIUtil.appDtoToAppResponse(applicationDTO); + ConnectionManagerUtil.commitDBTransaction(); + return application; + } + } catch (LifeCycleManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = + "Error occurred while adding lifecycle state. application name: " + applicationDTO.getName() + "."; + log.error(msg); + try { + applicationStorageManager.deleteAllApplicationReleaseArtifacts( + Collections.singletonList(applicationReleaseDTO.getAppHashValue())); + } catch (ApplicationStorageManagementException ex) { + String errorLog = + "Error occurred when deleting application artifacts. Application artifacts are tried to " + + "delete because of lifecycle state adding issue in the application creating operation."; + log.error(errorLog); + throw new ApplicationManagementException(errorLog, e); + } + throw new ApplicationManagementException(msg, e); + } catch (ApplicationManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred while adding application or application release. application name: " + + applicationDTO.getName() + "."; + log.error(msg); + deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); + throw new ApplicationManagementException(msg, e); + } catch (LifecycleManagementException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = + "Error occurred when getting initial lifecycle state. application name: " + applicationDTO.getName() + + "."; + log.error(msg); + deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); + throw new ApplicationManagementException(msg, e); + } catch (DBConnectionException e) { + String msg = "Error occurred while getting database connection."; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } catch (VisibilityManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred while adding unrestricted roles. application name: " + applicationDTO.getName() + + "."; + log.error(msg); + deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); + throw new ApplicationManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Error occurred while disabling AutoCommit."; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + @Override public ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { @@ -2450,20 +2231,26 @@ public class ApplicationManagerImpl implements ApplicationManager { public void validateAppCreatingRequest(T param) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + int deviceTypeId = -1; + String appName; + List appCategories; + List unrestrictedRoles; - if (param instanceof ApplicationWrapper){ - ApplicationWrapper applicationWrapper = (ApplicationWrapper) param; - if (StringUtils.isEmpty(applicationWrapper.getName())) { + if (param instanceof ApplicationWrapper) { + ApplicationWrapper applicationWrapper = (ApplicationWrapper) param; + appName = applicationWrapper.getName(); + if (StringUtils.isEmpty(appName)) { String msg = "Application name cannot be empty."; log.error(msg); throw new BadRequestException(msg); } - if (applicationWrapper.getAppCategories() == null) { + appCategories = applicationWrapper.getAppCategories(); + if (appCategories == null) { String msg = "Application category can't be null."; log.error(msg); throw new BadRequestException(msg); } - if (applicationWrapper.getAppCategories().isEmpty()) { + if (appCategories.isEmpty()) { String msg = "Application category can't be empty."; log.error(msg); throw new BadRequestException(msg); @@ -2478,30 +2265,35 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } + DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType()); + deviceTypeId = deviceType.getId(); List applicationReleaseWrappers; applicationReleaseWrappers = applicationWrapper.getApplicationReleaseWrappers(); if (applicationReleaseWrappers == null || applicationReleaseWrappers.size() != 1) { String msg = "Invalid application creating request. Application creating request must have single " - + "application release. Application name:" + applicationWrapper.getName() + " and type: " + - applicationWrapper.getType(); + + "application release. Application name:" + applicationWrapper.getName() + " and type: " + + applicationWrapper.getType(); log.error(msg); throw new BadRequestException(msg); } + unrestrictedRoles = applicationWrapper.getUnrestrictedRoles(); } else if (param instanceof WebAppWrapper) { WebAppWrapper webAppWrapper = (WebAppWrapper) param; - if (StringUtils.isEmpty(webAppWrapper.getName())) { + appName = webAppWrapper.getName(); + if (StringUtils.isEmpty(appName)) { String msg = "Web Clip name cannot be empty."; log.error(msg); throw new BadRequestException(msg); } - if (webAppWrapper.getCategories() == null) { + appCategories = webAppWrapper.getCategories(); + if (appCategories == null) { String msg = "Web Clip category can't be null."; log.error(msg); throw new BadRequestException(msg); } - if (webAppWrapper.getCategories().isEmpty()) { + if (appCategories.isEmpty()) { String msg = "Web clip category can't be empty."; log.error(msg); throw new BadRequestException(msg); @@ -2516,84 +2308,83 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } + unrestrictedRoles = webAppWrapper.getUnrestrictedRoles(); + } else { + String msg = "Invalid payload found with the request. Hence verify the request payload object."; + log.error(msg); + throw new ApplicationManagementException(msg); + } - try { - ConnectionManagerUtil.openDBConnection(); - List unrestrictedRoles = webAppWrapper.getUnrestrictedRoles(); - - if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { - if (!isValidRestrictedRole(unrestrictedRoles)) { - String msg = "Unrestricted role list contain role/roles which are not in the user store."; - log.error(msg); - throw new ApplicationManagementException(msg); - } - if (!hasUserRole(unrestrictedRoles, userName)) { - String msg = "You are trying to restrict the visibility of the application for a role set, but " - + "in order to perform the action at least one role should be assigned to user: " - + userName; - log.error(msg); - throw new BadRequestException(msg); - } + try { + ConnectionManagerUtil.openDBConnection(); + if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { + if (!isValidRestrictedRole(unrestrictedRoles)) { + String msg = "Unrestricted role list contain role/roles which are not in the user store."; + log.error(msg); + throw new ApplicationManagementException(msg); } - - Filter filter = new Filter(); - filter.setFullMatch(true); - filter.setAppName(webAppWrapper.getName().trim()); - filter.setOffset(0); - filter.setLimit(1); - List applicationList = applicationDAO.getApplications(filter, -1, tenantId); - if (!applicationList.isEmpty()) { - String msg = - "Already an application registered with same name - " + applicationList.get(0).getName() - + "."; + if (!hasUserRole(unrestrictedRoles, userName)) { + String msg = "You are trying to restrict the visibility of the application for a role set, but " + + "in order to perform the action at least one role should be assigned to user: " + + userName; log.error(msg); throw new BadRequestException(msg); } + } - List registeredCategories = this.applicationDAO.getAllCategories(tenantId); - List appCategories = webAppWrapper.getCategories(); - - if (registeredCategories.isEmpty()) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = - "Registered application category set is empty. Since it is mandatory to add application " - + "category when adding new application, registered application category list shouldn't be null."; - log.error(msg); - throw new ApplicationManagementException(msg); - } - for (String cat : appCategories) { - boolean isValidCategory = false; - for (CategoryDTO obj : registeredCategories) { - if (cat.equals(obj.getCategoryName())) { - isValidCategory = true; - break; - } - } - if (!isValidCategory) { - String msg = - "Application Creating request contains invalid categories. Hence please verify the " - + "application creating payload."; - log.error(msg); - throw new BadRequestException(msg); - } - } - } catch (DBConnectionException e) { - String msg = "Error occurred while getting database connection."; - log.error(msg); - throw new ApplicationManagementException(msg, e); - } catch (ApplicationManagementDAOException e) { - String msg = "Error occurred while getting data which is related to web clip. web clip name: " - + webAppWrapper.getName() + "."; + Filter filter = new Filter(); + filter.setFullMatch(true); + filter.setAppName(appName); + filter.setOffset(0); + filter.setLimit(1); + List applicationList = applicationDAO.getApplications(filter, deviceTypeId, tenantId); + if (!applicationList.isEmpty()) { + String msg = + "Already an application registered with same name - " + applicationList.get(0).getName() + "."; log.error(msg); - throw new ApplicationManagementException(msg, e); - } catch (UserStoreException e) { + throw new BadRequestException(msg); + } + + List registeredCategories = this.applicationDAO.getAllCategories(tenantId); + + if (registeredCategories.isEmpty()) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred when validating the unrestricted roles given for the web clip"; + String msg = "Registered application category set is empty. Since it is mandatory to add application " + + "category when adding new application, registered application category list shouldn't be null."; log.error(msg); - throw new ApplicationManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); + throw new ApplicationManagementException(msg); + } + for (String cat : appCategories) { + boolean isValidCategory = false; + for (CategoryDTO obj : registeredCategories) { + if (cat.equals(obj.getCategoryName())) { + isValidCategory = true; + break; + } + } + if (!isValidCategory) { + String msg = "Application Creating request contains invalid categories. Hence please verify the " + + "application creating payload."; + log.error(msg); + throw new BadRequestException(msg); + } } + } catch (DBConnectionException e) { + String msg = "Error occurred while getting database connection."; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } catch (ApplicationManagementDAOException e) { + String msg = + "Error occurred while getting data which is related to web clip. web clip name: " + appName + "."; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } catch (UserStoreException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred when validating the unrestricted roles given for the web clip"; + log.error(msg); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index 7611e08ca81..5dbce185644 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -273,6 +273,7 @@ public class APIUtil { applicationReleaseDTO.setPrice(webAppReleaseWrapper.getPrice()); applicationReleaseDTO.setInstallerName(webAppReleaseWrapper.getUrl()); applicationReleaseDTO.setIsSharedWithAllTenants(webAppReleaseWrapper.getIsSharedWithAllTenants()); + applicationReleaseDTO.setSupportedOsVersions("ANY"); applicationReleaseDTO.setMetaData(webAppReleaseWrapper.getMetaData()); } return applicationReleaseDTO; diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index b2816cb5f1f..e0d12e92890 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_RELEASE( APP_HASH_VALUE VARCHAR(1000) NOT NULL, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, APP_META_INFO CLOB NULL DEFAULT NULL, - SUPPORTED_OS_VERSIONS VARCHAR(45) NULL DEFAULT NULL, + SUPPORTED_OS_VERSIONS VARCHAR(45) NOT NULL, RATING DOUBLE NULL DEFAULT NULL, CURRENT_STATE VARCHAR(45) NOT NULL, RATED_USERS INTEGER NULL, From 3179653b6a8eb0e298e518daff781a5cf6a077b8 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 6 Jun 2019 20:02:23 +0530 Subject: [PATCH 14/14] Add APPM public app support --- .../common/services/ApplicationManager.java | 6 +- .../wrapper/ApplicationReleaseWrapper.java | 7 + .../common/wrapper/ApplicationWrapper.java | 18 +- .../wrapper/PublicAppReleaseWrapper.java | 124 +++++++++++++ .../mgt/common/wrapper/PublicAppWrapper.java | 121 +++++++++++++ .../common/wrapper/WebAppReleaseWrapper.java | 1 - .../GenericSubscriptionDAOImpl.java | 2 +- .../mgt/core/impl/ApplicationManagerImpl.java | 169 ++++++++++++++---- .../application/mgt/core/util/APIUtil.java | 36 +++- .../application/mgt/core/util/Constants.java | 5 + .../management/ApplicationManagementTest.java | 1 - .../ApplicationManagementPublisherAPI.java | 76 +++++++- ...ApplicationManagementPublisherAPIImpl.java | 57 +++++- 13 files changed, 557 insertions(+), 66 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppReleaseWrapper.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppWrapper.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 ce66315c1de..7f34760d233 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 @@ -35,6 +35,7 @@ import org.wso2.carbon.device.application.mgt.common.response.Tag; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import java.util.List; @@ -57,6 +58,9 @@ public interface ApplicationManager { Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException; + Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact) + throws ApplicationManagementException; + /** * Updates an already existing application. * @@ -226,7 +230,7 @@ public interface ApplicationManager { void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List attachmentList) throws RequestValidatingException; - void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException; + void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException; void addAplicationCategories(List categories) 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/wrapper/ApplicationReleaseWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationReleaseWrapper.java index b220ab7d917..fb7def99631 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationReleaseWrapper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationReleaseWrapper.java @@ -19,27 +19,33 @@ package org.wso2.carbon.device.application.mgt.common.wrapper; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotNull; + @ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store") public class ApplicationReleaseWrapper { @ApiModelProperty(name = "description", value = "Description of the application release") + @NotNull private String description; @ApiModelProperty(name = "releaseType", value = "Release type of the application release", required = true, example = "alpha, beta etc") + @NotNull private String releaseType; @ApiModelProperty(name = "price", value = "Price of the application release", required = true) + @NotNull private Double price; @ApiModelProperty(name = "isSharedWithAllTenants", value = "If application release is shared with all tenants it is eqal to 1 otherwise 0", required = true) + @NotNull private boolean isSharedWithAllTenants; @ApiModelProperty(name = "metaData", @@ -49,6 +55,7 @@ public class ApplicationReleaseWrapper { @ApiModelProperty(name = "supportedOsVersions", value = "ApplicationDTO release supported OS versions") + @NotNull private String supportedOsVersions; public String getReleaseType() { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationWrapper.java index 02c05b3b0d7..706aae0dc06 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationWrapper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationWrapper.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.application.mgt.common.wrapper; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotNull; import java.util.List; @ApiModel(value = "ApplicationWrapper", description = "ApplicationWrapper represents the an ApplicationDTO in ApplicationDTO Store") @@ -28,29 +29,28 @@ public class ApplicationWrapper { @ApiModelProperty(name = "name", value = "Name of the application", required = true) + @NotNull private String name; @ApiModelProperty(name = "description", value = "Description of the application", required = true) + @NotNull private String description; @ApiModelProperty(name = "appCategories", value = "CategoryDTO of the application", required = true, example = "Educational, Gaming, Travel, Entertainment etc") + @NotNull private List appCategories; - @ApiModelProperty(name = "type", - value = "Type of the application", - required = true, - example = "ENTERPRISE, PUBLIC, WEB, WEB_CLIP etc") - private String type; @ApiModelProperty(name = "subType", value = "Subscription type of the application", required = true, example = "PAID, FREE") + @NotNull private String subType; @ApiModelProperty(name = "paymentCurrency", @@ -61,21 +61,25 @@ public class ApplicationWrapper { @ApiModelProperty(name = "tags", value = "List of application tags") + @NotNull private List tags; @ApiModelProperty(name = "unrestrictedRoles", value = "List of roles that users should have to access the application") + @NotNull private List unrestrictedRoles; @ApiModelProperty(name = "deviceType", value = "Related device type of the application", required = true, example = "IoS, Android, Arduino, RaspberryPi etc") + @NotNull private String deviceType; @ApiModelProperty(name = "applicationReleaseWrappers", value = "List of application releases", required = true) + @NotNull private List applicationReleaseWrappers; @@ -95,10 +99,6 @@ public class ApplicationWrapper { public void setTags(List tags) { this.tags = tags; } - public String getType() { return type; } - - public void setType(String type) { this.type = type; } - public String getSubType() { return subType; } public void setSubType(String subType) { this.subType = subType; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppReleaseWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppReleaseWrapper.java new file mode 100644 index 00000000000..46f274dd2d3 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppReleaseWrapper.java @@ -0,0 +1,124 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.common.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; + +@ApiModel(value = "Public App Release Wrapper", description = "This class holds the details when releasing an Public App" + + " Release to application store") +public class PublicAppReleaseWrapper { + + @ApiModelProperty(name = "description", + value = "Description of the public app release") + @NotNull + private String description; + + @ApiModelProperty(name = "releaseType", + value = "Release type of the public app release", + required = true, + example = "alpha, beta etc") + @NotNull + private String releaseType; + + @ApiModelProperty(name = "price", + value = "Price of the public app release", + required = true) + private Double price; + + @ApiModelProperty(name = "isSharedWithAllTenants", + value = "If public app release is shared with all tenants it is equal to 1 otherwise 0", + required = true) + @NotNull + private boolean isSharedWithAllTenants; + + @ApiModelProperty(name = "metaData", + value = "Meta data of the public app release", + required = true) + private String metaData; + + @ApiModelProperty(name = "version", + value = "Version of the public app release.", + required = true) + @NotNull + private String version; + + @ApiModelProperty(name = "packageName", + value = "Package name of the public app release.", + required = true) + @NotNull + private String packageName; + + @ApiModelProperty(name = "supportedOsVersions", + value = "ApplicationDTO release supported OS versions") + @NotNull + private String supportedOsVersions; + + public String getReleaseType() { + return releaseType; + } + + public void setReleaseType(String releaseType) { + this.releaseType = releaseType; + } + + public void setIsSharedWithAllTenants(boolean isSharedWithAllTenants) { + this.isSharedWithAllTenants = isSharedWithAllTenants; + } + + public void setMetaData(String metaData) { + this.metaData = metaData; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } + + public boolean getIsSharedWithAllTenants() { + return isSharedWithAllTenants; + } + + public String getMetaData() { + return metaData; + } + + public String getDescription() { return description; } + + public void setDescription(String description) { this.description = description; } + + public boolean isSharedWithAllTenants() { return isSharedWithAllTenants; } + + public void setSharedWithAllTenants(boolean sharedWithAllTenants) { isSharedWithAllTenants = sharedWithAllTenants; } + + public String getVersion() { return version; } + + public void setVersion(String version) { this.version = version; } + + public String getPackageName() { return packageName; } + + public void setPackageName(String packageName) { this.packageName = packageName; } + + public String getSupportedOsVersions() { return supportedOsVersions; } + + public void setSupportedOsVersions(String supportedOsVersions) { this.supportedOsVersions = supportedOsVersions; } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppWrapper.java new file mode 100644 index 00000000000..beb66706fdd --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppWrapper.java @@ -0,0 +1,121 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.common.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; +import java.util.List; + +@ApiModel(value = "PublicAppWrapper", description = "PublicAppWrapper represents an Application in App Store") +public class PublicAppWrapper { + + @ApiModelProperty(name = "name", + value = "Name of the public app", + required = true) + @NotNull + private String name; + + @ApiModelProperty(name = "description", + value = "Description of the public app", + required = true) + @NotNull + private String description; + + @ApiModelProperty(name = "categories", + value = "List of Categories", + required = true, + example = "Educational, Gaming, Travel, Entertainment etc") + @NotNull + private List categories; + + @ApiModelProperty(name = "subType", + value = "Subscription method of the public app", + required = true, + example = "PAID, FREE") + @NotNull + private String subMethod; + + @ApiModelProperty(name = "deviceType", + value = "Related device type of the public app", + required = true, + example = "IoS, Android, Arduino, RaspberryPi etc") + @NotNull + private String deviceType; + + @ApiModelProperty(name = "paymentCurrency", + value = "Payment currency of the web clip", + required = true, + example = "$") + private String paymentCurrency; + + @ApiModelProperty(name = "tags", + value = "List of tags") + @NotNull + private List tags; + + @ApiModelProperty(name = "unrestrictedRoles", + value = "List of roles that users should have to view the public app") + @NotNull + private List unrestrictedRoles; + + @ApiModelProperty(name = "applicationReleaseWrappers", + value = "List of public app releases", + required = true) + @NotNull + private List publicAppReleaseWrappers; + + public String getName() { + return name; + } + + public void setName(String name) { this.name = name; } + + public List getTags() { return tags; } + + public void setTags(List tags) { this.tags = tags; } + + public String getDeviceType() { return deviceType; } + + public void setDeviceType(String deviceType) { this.deviceType = deviceType; } + + public String getPaymentCurrency() { return paymentCurrency; } + + public void setPaymentCurrency(String paymentCurrency) { this.paymentCurrency = paymentCurrency; } + + public List getUnrestrictedRoles() { return unrestrictedRoles; } + + public void setUnrestrictedRoles(List unrestrictedRoles) { this.unrestrictedRoles = unrestrictedRoles; } + + public String getDescription() { return description; } + + public void setDescription(String description) { this.description = description; } + + public List getPublicAppReleaseWrappers() { return publicAppReleaseWrappers; } + + public void setPublicAppReleaseWrappers(List publicAppReleaseWrappers) { + this.publicAppReleaseWrappers = publicAppReleaseWrappers; } + + public List getCategories() { return categories; } + + public void setCategories(List categories) { this.categories = categories; } + + public String getSubMethod() { return subMethod; } + + public void setSubMethod(String subMethod) { this.subMethod = subMethod; } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppReleaseWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppReleaseWrapper.java index 9cf11f23744..02435bcc8eb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppReleaseWrapper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppReleaseWrapper.java @@ -21,7 +21,6 @@ import io.swagger.annotations.ApiModelProperty; import javax.validation.constraints.NotNull; -//todo add version attribute @ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store") public class WebAppReleaseWrapper { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 63fcecb5e3f..cb23fac1ea3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -549,7 +549,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc sql += "GROUP_NAME = ? "; } - sql += "AND AP_APP_RELEASE_ID = ? AND AND TENANT_ID = ?"; + sql += "AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { Calendar calendar = Calendar.getInstance(); 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 c005463aded..9cfe93dc38f 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 @@ -29,6 +29,7 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact; import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller; +import org.wso2.carbon.device.application.mgt.common.DeviceTypes; import org.wso2.carbon.device.application.mgt.common.LifecycleChanger; import org.wso2.carbon.device.application.mgt.common.Pagination; import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration; @@ -58,6 +59,8 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; @@ -414,13 +417,14 @@ public class ApplicationManagerImpl implements ApplicationManager { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); if (log.isDebugEnabled()) { - log.debug("Application create request is received for the tenant : " + tenantId + " From" + " the user : " + log.debug("Web clip create request is received for the tenant : " + tenantId + " From" + " the user : " + userName); } ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); String uuid = UUID.randomUUID().toString(); + //todo check installer name exists or not, do it in the validation method String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName()); applicationReleaseDTO.setUuid(uuid); applicationReleaseDTO.setAppHashValue(md5); @@ -430,7 +434,49 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().add(addImageArtifacts(applicationReleaseDTO, applicationArtifact)); } catch (ResourceManagementException e) { - String msg = "Error Occured when uploading artifacts of the application: " + webAppWrapper.getName(); + String msg = "Error Occured when uploading artifacts of the web clip: " + webAppWrapper.getName(); + log.error(msg); + throw new ApplicationManagementException(msg, e); + } + + //insert application data into database + return addAppDataIntoDB(applicationDTO, tenantId); + } + + @Override + public Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact) + throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + String publicAppStorePath = ""; + if (log.isDebugEnabled()) { + log.debug("Public app creating request is received for the tenant : " + tenantId + " From" + " the user : " + + userName); + } + + if (DeviceTypes.ANDROID.toString().equals(publicAppWrapper.getDeviceType())) { + publicAppStorePath = Constants.GOOGLE_PLAY_STORE_URL; + } else if (DeviceTypes.IOS.toString().equals(publicAppWrapper.getDeviceType())) { + publicAppStorePath = Constants.APPLE_STORE_URL; + } + + ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(publicAppWrapper); + ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); + String uuid = UUID.randomUUID().toString(); + String appInstallerUrl = publicAppStorePath + applicationReleaseDTO.getPackageName(); + //todo check app package name exist or not, do it in validation method + applicationReleaseDTO.setInstallerName(appInstallerUrl); + String md5 = DigestUtils.md5Hex(appInstallerUrl); + applicationReleaseDTO.setUuid(uuid); + applicationReleaseDTO.setAppHashValue(md5); + + //uploading application artifacts + try { + applicationDTO.getApplicationReleaseDTOs().clear(); + applicationDTO.getApplicationReleaseDTOs() + .add(addImageArtifacts(applicationReleaseDTO, applicationArtifact)); + } catch (ResourceManagementException e) { + String msg = "Error Occured when uploading artifacts of the public app: " + publicAppWrapper.getName(); log.error(msg); throw new ApplicationManagementException(msg, e); } @@ -2255,11 +2301,6 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } - if (StringUtils.isEmpty(applicationWrapper.getType())) { - String msg = "Application type can't be empty."; - log.error(msg); - throw new BadRequestException(msg); - } if (StringUtils.isEmpty(applicationWrapper.getDeviceType())) { String msg = "Device type can't be empty for the application."; log.error(msg); @@ -2273,8 +2314,7 @@ public class ApplicationManagerImpl implements ApplicationManager { if (applicationReleaseWrappers == null || applicationReleaseWrappers.size() != 1) { String msg = "Invalid application creating request. Application creating request must have single " - + "application release. Application name:" + applicationWrapper.getName() + " and type: " - + applicationWrapper.getType(); + + "application release. Application name:" + applicationWrapper.getName() + "."; log.error(msg); throw new BadRequestException(msg); } @@ -2298,6 +2338,14 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } + if (StringUtils.isEmpty(webAppWrapper.getType()) || (!ApplicationType.WEB_CLIP.toString() + .equals(webAppWrapper.getType()) && !ApplicationType.WEB_APP.toString() + .equals(webAppWrapper.getType()))) { + String msg = "Web app wrapper contains invalid application type with the request. Hence please verify " + + "the request payload.."; + log.error(msg); + throw new BadRequestException(msg); + } List webAppReleaseWrappers; webAppReleaseWrappers = webAppWrapper.getWebAppReleaseWrappers(); @@ -2309,6 +2357,43 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new BadRequestException(msg); } unrestrictedRoles = webAppWrapper.getUnrestrictedRoles(); + } else if (param instanceof PublicAppWrapper) { + PublicAppWrapper publicAppWrapper = (PublicAppWrapper) param; + appName = publicAppWrapper.getName(); + if (StringUtils.isEmpty(appName)) { + String msg = "Application name cannot be empty for public app."; + log.error(msg); + throw new BadRequestException(msg); + } + appCategories = publicAppWrapper.getCategories(); + if (appCategories == null) { + String msg = "Application category can't be null."; + log.error(msg); + throw new BadRequestException(msg); + } + if (appCategories.isEmpty()) { + String msg = "Application category can't be empty."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(publicAppWrapper.getDeviceType())) { + String msg = "Device type can't be empty for the public application."; + log.error(msg); + throw new BadRequestException(msg); + } + DeviceType deviceType = getDeviceTypeData(publicAppWrapper.getDeviceType()); + deviceTypeId = deviceType.getId(); + + List publicAppReleaseWrappers; + publicAppReleaseWrappers = publicAppWrapper.getPublicAppReleaseWrappers(); + + if (publicAppReleaseWrappers == null || publicAppReleaseWrappers.size() != 1) { + String msg = "Invalid public app creating request. Request must have single release. Application name:" + + publicAppWrapper.getName() + "."; + log.error(msg); + throw new BadRequestException(msg); + } + unrestrictedRoles = publicAppWrapper.getUnrestrictedRoles(); } else { String msg = "Invalid payload found with the request. Hence verify the request payload object."; log.error(msg); @@ -2390,35 +2475,62 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override public void validateReleaseCreatingRequest(T param) throws ApplicationManagementException { - - if (param == null){ + if (param == null) { String msg = "In order to validate release creating request param shouldn't be null."; log.error(msg); throw new BadRequestException(msg); } - if (param instanceof ApplicationReleaseWrapper){ + if (param instanceof ApplicationReleaseWrapper) { ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param; - - if (StringUtils.isEmpty(applicationReleaseWrapper.getSupportedOsVersions())){ + if (StringUtils.isEmpty(applicationReleaseWrapper.getSupportedOsVersions())) { String msg = "Supported OS Version shouldn't be null or empty."; log.error(msg); throw new BadRequestException(msg); } - } if (param instanceof WebAppReleaseWrapper){ + } + if (param instanceof WebAppReleaseWrapper) { WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param; UrlValidator urlValidator = new UrlValidator(); - if (StringUtils - .isEmpty(webAppReleaseWrapper.getUrl())){ - String msg = "URL should't be null for the application release creating request for application type WEB_CLIP"; + if (StringUtils.isEmpty(webAppReleaseWrapper.getVersion())) { + String msg = "Version shouldn't be empty or null for the WEB CLIP release creating request."; log.error(msg); throw new BadRequestException(msg); } - if (!urlValidator.isValid(webAppReleaseWrapper.getUrl())){ + if (StringUtils.isEmpty(webAppReleaseWrapper.getUrl())) { + String msg = "URL should't be null for the application release creating request for application type " + + "WEB_CLIP"; + log.error(msg); + throw new BadRequestException(msg); + } + if (!urlValidator.isValid(webAppReleaseWrapper.getUrl())) { String msg = "Request payload contains an invalid Web Clip URL."; log.error(msg); throw new BadRequestException(msg); } + } else if (param instanceof PublicAppReleaseWrapper) { + PublicAppReleaseWrapper publicAppReleaseWrapper = (PublicAppReleaseWrapper) param; + if (StringUtils.isEmpty(publicAppReleaseWrapper.getSupportedOsVersions())) { + String msg = "Supported OS Version shouldn't be null or empty for public app release creating request."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(publicAppReleaseWrapper.getVersion())) { + String msg = "Version shouldn't be empty or null for the Public App release creating request."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(publicAppReleaseWrapper.getPackageName())) { + String msg = "Package name shouldn't be empty or null for the Public App release creating request."; + log.error(msg); + throw new BadRequestException(msg); + } + + } else { + String msg = "Invalid payload found with the release creating request. Hence verify the release creating " + + "request payload object."; + log.error(msg); + throw new ApplicationManagementException(msg); } } @@ -2431,6 +2543,7 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new RequestValidatingException(msg); } + //todo remove this check, because banner is not mandatory to have if (bannerFile == null) { String msg = "Banner file is not found with the application release creating request."; log.error(msg); @@ -2444,21 +2557,11 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException { + public void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException { - if (StringUtils.isEmpty(applicationType)) { - String msg = "Application type can't be empty."; - log.error(msg); - throw new RequestValidatingException(msg); - } - if (!isValidAppType(applicationType)) { - String msg = "App Type contains in the application creating payload doesn't match with supported app types."; - log.error(msg); - throw new RequestValidatingException(msg); - } - if (binaryFile == null && ApplicationType.ENTERPRISE.toString().equals(applicationType)) { - String msg = "Binary file is not found with the application release creating request. ApplicationDTO type: " - + applicationType; + if (binaryFile == null) { + String msg = "Binary file is not found with the application release creating request for ENTERPRISE app " + + "creating request."; log.error(msg); throw new RequestValidatingException(msg); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index 5dbce185644..73226f58187 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.commons.validator.routines.UrlValidator; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.ApplicationType; +import org.wso2.carbon.device.application.mgt.common.DeviceTypes; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.response.Application; @@ -32,6 +33,8 @@ import org.wso2.carbon.device.application.mgt.common.services.*; import org.wso2.carbon.device.application.mgt.common.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; @@ -228,7 +231,7 @@ public class APIUtil { applicationDTO.setName(applicationWrapper.getName()); applicationDTO.setDescription(applicationWrapper.getDescription()); applicationDTO.setAppCategories(applicationWrapper.getAppCategories()); - applicationDTO.setType(applicationWrapper.getType()); + applicationDTO.setType(ApplicationType.ENTERPRISE.toString()); applicationDTO.setSubType(applicationWrapper.getSubType()); applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency()); applicationDTO.setTags(applicationWrapper.getTags()); @@ -250,8 +253,22 @@ public class APIUtil { List applicationReleaseEntities = webAppWrapper.getWebAppReleaseWrappers() .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); + } else if (param instanceof PublicAppWrapper) { + PublicAppWrapper publicAppWrapper = (PublicAppWrapper) param; + DeviceType deviceType = getDeviceTypeData(publicAppWrapper.getDeviceType()); + applicationDTO.setName(publicAppWrapper.getName()); + applicationDTO.setDescription(publicAppWrapper.getDescription()); + applicationDTO.setAppCategories(publicAppWrapper.getCategories()); + applicationDTO.setType(ApplicationType.PUBLIC.toString()); + applicationDTO.setSubType(publicAppWrapper.getSubMethod()); + applicationDTO.setPaymentCurrency(publicAppWrapper.getPaymentCurrency()); + applicationDTO.setTags(publicAppWrapper.getTags()); + applicationDTO.setUnrestrictedRoles(publicAppWrapper.getUnrestrictedRoles()); + applicationDTO.setDeviceTypeId(deviceType.getId()); + List applicationReleaseEntities = publicAppWrapper.getPublicAppReleaseWrappers() + .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); + applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); } - return applicationDTO; } @@ -273,8 +290,19 @@ public class APIUtil { applicationReleaseDTO.setPrice(webAppReleaseWrapper.getPrice()); applicationReleaseDTO.setInstallerName(webAppReleaseWrapper.getUrl()); applicationReleaseDTO.setIsSharedWithAllTenants(webAppReleaseWrapper.getIsSharedWithAllTenants()); - applicationReleaseDTO.setSupportedOsVersions("ANY"); + applicationReleaseDTO.setSupportedOsVersions(Constants.ANY); + applicationReleaseDTO.setPackageName(Constants.DEFAULT_PCK_NAME); applicationReleaseDTO.setMetaData(webAppReleaseWrapper.getMetaData()); + } else if (param instanceof PublicAppReleaseWrapper) { + PublicAppReleaseWrapper publicAppReleaseWrapper = (PublicAppReleaseWrapper) param; + applicationReleaseDTO.setDescription(publicAppReleaseWrapper.getDescription()); + applicationReleaseDTO.setReleaseType(publicAppReleaseWrapper.getReleaseType()); + applicationReleaseDTO.setVersion(publicAppReleaseWrapper.getVersion()); + applicationReleaseDTO.setPackageName(publicAppReleaseWrapper.getPackageName()); + applicationReleaseDTO.setPrice(publicAppReleaseWrapper.getPrice()); + applicationReleaseDTO.setIsSharedWithAllTenants(publicAppReleaseWrapper.getIsSharedWithAllTenants()); + applicationReleaseDTO.setMetaData(publicAppReleaseWrapper.getMetaData()); + applicationReleaseDTO.setSupportedOsVersions(publicAppReleaseWrapper.getSupportedOsVersions()); } return applicationReleaseDTO; } @@ -287,7 +315,7 @@ public class APIUtil { DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); application.setDeviceType(deviceType.getName()); } else { - application.setDeviceType("ANY"); + application.setDeviceType(Constants.ANY); } application.setId(applicationDTO.getId()); application.setName(applicationDTO.getName()); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java index cbe0692336f..179bc51a63c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java @@ -38,6 +38,11 @@ public class Constants { public static final String APP_EXTENSION = ".app"; public static final String FORWARD_SLASH = "/"; + public static final String ANY = "ANY"; + public static final String DEFAULT_PCK_NAME = "default.app.com"; + + public static final String GOOGLE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id="; + public static final String APPLE_STORE_URL = "https://itunes.apple.com/country/app/app-name/id"; /** * Database types supported by Application Management. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java index edfc733a28c..1f002a74b10 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java @@ -60,7 +60,6 @@ public class ApplicationManagementTest extends BaseTestCase { applicationWrapper.setDeviceType("android"); applicationWrapper.setName("Test Application"); applicationWrapper.setSubType("Test Sub type"); - applicationWrapper.setType("ENTERPRISE"); List tags = new ArrayList<>(); tags.add("abc"); 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/ApplicationManagementPublisherAPI.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/ApplicationManagementPublisherAPI.java index aa97ff02432..5efd2bec44c 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/ApplicationManagementPublisherAPI.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/ApplicationManagementPublisherAPI.java @@ -42,6 +42,7 @@ import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import java.util.List; @@ -270,6 +271,7 @@ public interface ApplicationManagementPublisherAPI { ); @POST + @Path("/ent-app") @Produces(MediaType.APPLICATION_JSON) @Consumes("multipart/mixed") @ApiOperation( @@ -300,7 +302,7 @@ public interface ApplicationManagementPublisherAPI { message = "Internal Server Error. \n Error occurred while creating the application.", response = ErrorResponse.class) }) - Response createApplication( + Response createEntApp( @ApiParam( name = "application", value = "The application that need to be created.", @@ -404,9 +406,72 @@ public interface ApplicationManagementPublisherAPI { ); @POST + @Path("/public-app") @Produces(MediaType.APPLICATION_JSON) @Consumes("multipart/mixed") - @Path("/{appType}/{appId}") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Create an public app", + notes = "This will create a new public app", + tags = "Application Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 201, + message = "OK. \n Successfully created a public app.", + response = ApplicationDTO.class), + @ApiResponse( + code = 400, + message = "Bad Request. \n " + + "public app creating payload contains unacceptable or vulnerable data"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while creating the public app.", + response = ErrorResponse.class) + }) + Response createPubApp( + @ApiParam( + name = "public-app", + value = "The public app that need to be created.", + required = true) + @Multipart("public-app") PublicAppWrapper publicAppWrapper, + @ApiParam( + name = "icon", + value = "Icon of the uploading public app", + required = true) + @Multipart(value = "icon") Attachment iconFile, + @ApiParam( + name = "banner", + value = "Banner of the uploading public app", + required = true) + @Multipart(value = "banner") Attachment bannerFile, + @ApiParam( + name = "screenshot1", + value = "Screen Shots of the uploading public app", + required = true) + @Multipart(value = "screenshot1") Attachment screenshot1, + @ApiParam( + name = "screenshot2", + value = "Screen Shots of the uploading public app") + @Multipart(value = "screenshot2") Attachment screenshot2, + @ApiParam( + name = "screenshot3", + value = "Screen Shots of the uploading public app") + @Multipart(value = "screenshot3") Attachment screenshot3 + ); + + @POST + @Produces(MediaType.APPLICATION_JSON) + @Consumes("multipart/mixed") + @Path("/ent-app/{appId}") @ApiOperation( consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, @@ -435,12 +500,7 @@ public interface ApplicationManagementPublisherAPI { message = "Internal Server Error. \n Error occurred while creating the application.", response = ErrorResponse.class) }) - Response createRelease( - @ApiParam( - name = "appType", - value = "Application Type.", - required = true) - @PathParam("appType") String appType, + Response createEntAppRelease( @ApiParam( name = "appId", value = "Id of the application.", 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/ApplicationManagementPublisherAPIImpl.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/ApplicationManagementPublisherAPIImpl.java index 323f476b7a6..8ef252d4de1 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/ApplicationManagementPublisherAPIImpl.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/ApplicationManagementPublisherAPIImpl.java @@ -32,6 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; @@ -168,7 +169,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @POST @Consumes("multipart/mixed") - public Response createApplication( + @Path("/ent-app") + public Response createEntApp( @Multipart("application") ApplicationWrapper applicationWrapper, @Multipart("binaryFile") Attachment binaryFile, @Multipart("icon") Attachment iconFile, @@ -181,7 +183,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem try { applicationManager.validateAppCreatingRequest(applicationWrapper); applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0)); - applicationManager.validateBinaryArtifact(binaryFile, applicationWrapper.getType()); + applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); // Created new application entry @@ -245,9 +247,46 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @POST @Consumes("multipart/mixed") - @Path("/{appType}/{appId}") - public Response createRelease( - @PathParam("appType") String appType, + @Path("/public-app") + public Response createPubApp( + @Multipart("public-app") PublicAppWrapper publicAppWrapper, + @Multipart("icon") Attachment iconFile, + @Multipart("banner") Attachment bannerFile, + @Multipart("screenshot1") Attachment screenshot1, + @Multipart("screenshot2") Attachment screenshot2, + @Multipart("screenshot3") Attachment screenshot3) { + ApplicationManager applicationManager = APIUtil.getApplicationManager(); + List attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); + try { + applicationManager.validateAppCreatingRequest(publicAppWrapper); + applicationManager.validateReleaseCreatingRequest(publicAppWrapper.getPublicAppReleaseWrappers().get(0)); + applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); + + // Created new application entry + Application application = applicationManager.createPublicApp(publicAppWrapper, + constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); + if (application != null) { + return Response.status(Response.Status.CREATED).entity(application).build(); + } else { + String msg = "Web app creation is failed"; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } catch (ApplicationManagementException e) { + String msg = "Error occurred while creating the public app."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (RequestValidatingException e) { + String msg = "Error occurred while handling the public app creating request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } + } + + @POST + @Consumes("multipart/mixed") + @Path("/ent-app/{appId}") + public Response createEntAppRelease( @PathParam("appId") int appId, @Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper, @Multipart("binaryFile") Attachment binaryFile, @@ -260,7 +299,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem List attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); try { applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper); - applicationManager.validateBinaryArtifact(binaryFile, appType); + applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); // Created new application release @@ -339,7 +378,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } ApplicationManager applicationManager = APIUtil.getApplicationManager(); - applicationManager.validateBinaryArtifact(binaryFile, appType); + //todo check again + applicationManager.validateBinaryArtifact(binaryFile); applicationManager.updateApplicationArtifact(deviceType, appType, applicationReleaseUuid, constructApplicationArtifact(binaryFile, null, null, null)); return Response.status(Response.Status.OK) @@ -402,7 +442,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem ApplicationManager applicationManager = APIUtil.getApplicationManager(); List screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); try { - applicationManager.validateBinaryArtifact(binaryFile, appType); + //todo check again + applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots); if (!applicationManager.updateRelease(deviceType, appType, applicationUUID, applicationReleaseWrapper, constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) {