diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml index 01ea40d9da0..0fd0804917c 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml @@ -22,13 +22,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.annotations - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - API Management Annotations WSO2 Carbon - API Management Custom Annotation Module diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml index c6969f29b14..b8a95d4d448 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml @@ -21,12 +21,12 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT org.wso2.carbon.apimgt.application.extension.api war WSO2 Carbon - API Application Management API diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml index 2194b0ae8a8..c6f6ac6df0d 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml @@ -22,12 +22,12 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT org.wso2.carbon.apimgt.application.extension bundle WSO2 Carbon - API Application Management diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java index 487177ed613..aaa3cb87c11 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java @@ -26,6 +26,7 @@ import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; import org.wso2.carbon.apimgt.application.extension.internal.APIApplicationManagerExtensionDataHolder; import org.wso2.carbon.apimgt.application.extension.util.APIManagerUtil; +import org.wso2.carbon.apimgt.integration.client.OAuthRequestInterceptor; import org.wso2.carbon.apimgt.integration.client.store.*; import org.wso2.carbon.apimgt.integration.generated.client.store.model.*; import org.wso2.carbon.context.PrivilegedCarbonContext; @@ -58,8 +59,19 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe tenantDomain, CONTENT_TYPE, null, null); return true; } catch (FeignException e) { - return false; - } + if (e.status() == 401) { + OAuthRequestInterceptor oAuthRequestInterceptor = new OAuthRequestInterceptor(); + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + oAuthRequestInterceptor.removeToken(username, tenantDomain); + try { + storeClient.getIndividualTier().tiersTierLevelTierNameGet(ApiApplicationConstants.DEFAULT_TIER, + APP_TIER_TYPE,tenantDomain, CONTENT_TYPE, null, null); + } catch (FeignException ex) { + log.error("Invalid Attempt : " + ex); + return false; + } + } } + return false; } @Override diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml index aa8d4afcd2d..ac33013a802 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml @@ -21,13 +21,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.handlers - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - API Security Handler Component WSO2 Carbon - API Management Security Handler Module diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml index 7fb37938edc..d3f8d3d2aef 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml @@ -13,13 +13,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.integration.client - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - API Management Integration Client WSO2 Carbon - API Management Integration Client diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml index c76eff78383..eb528f56693 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml @@ -13,13 +13,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.integration.generated.client - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - API Management Integration Generated Client WSO2 Carbon - API Management Integration Client diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 51bb5ed8867..40a49e9b704 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -22,13 +22,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.webapp.publisher - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - API Management Webapp Publisher WSO2 Carbon - API Management Webapp Publisher diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 06747b53842..f5e1623791c 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 apimgt-extensions - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - API Management Extensions Component http://wso2.org diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.authhandler/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.authhandler/pom.xml index 1bdb6b03d33..a8cd2bb66fc 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.authhandler/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.authhandler/pom.xml @@ -24,11 +24,11 @@ org.wso2.carbon.devicemgt application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT org.wso2.carbon.device.application.mgt.authhandler - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT war WSO2 Carbon - Application Management Authentication Handler API Proxy Service for Authentication Handling in WSO2 App Manager. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml index 85c6edd29ad..56c2dd16226 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml @@ -21,13 +21,13 @@ org.wso2.carbon.devicemgt application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.common - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Application Management Common WSO2 Carbon - Application Management Common diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java index 401611ea9a7..eb08e78034b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java @@ -19,72 +19,73 @@ package org.wso2.carbon.device.application.mgt.common; -import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import java.util.List; -/** - * Application represents the an Application in Application Store. - */ + +@ApiModel(value = "Application", description = "Application represents the an Application in Application Store") public class Application { - @Exclude + @ApiModelProperty(name = "id", + value = "The ID given to the application when it is stored in the APPM database") private int id; - /** - * Name of the application - */ + @ApiModelProperty(name = "name", + value = "Name of the application", + required = true) private String name; - /** - * Category of the application. - * e.g: Educational, Gaming, Travel, Entertainment etc. - */ + @ApiModelProperty(name = "appCategory", + value = "Category of the application", + required = true, + example = "Educational, Gaming, Travel, Entertainment etc") private String appCategory; - /** - * Type of the application - * e.g. Mobile, Web, Web Clip etc - */ + @ApiModelProperty(name = "type", + value = "Type of the application", + required = true, + example = "Mobile, Web, Web Clip etc") private String type; - /** - * Subscription type of the application. - * e.g: PAID, FREE - */ + @ApiModelProperty(name = "subType", + value = "Subscription type of the application", + required = true, + example = "PAID, FREE") private String subType; - /** - * Payment currency of the application and the default value is '$'. - */ + @ApiModelProperty(name = "paymentCurrency", + value = "Payment currency of the application", + required = true, + example = "$") private String paymentCurrency; - /** - * List of application tags - */ + @ApiModelProperty(name = "tags", + value = "List of application tags") private List tags; - /** - * Application creating user - */ + @ApiModelProperty(name = "user", + value = "Application creating user") private User user; - /** - * List of roles that users should have to access the application - */ + @ApiModelProperty(name = "unrestrictedRoles", + value = "List of roles that users should have to access the application") private List unrestrictedRoles; - /** - * If unrestricted roles are defined then isRestricted value is true otherwise it is false. - */ + @ApiModelProperty(name = "isRestricted", + value = "If unrestricted roles are defined then isRestricted value is true otherwise it is false") private boolean isRestricted; - /** - * Related device type of the application. - * e.g: IoS, Android, Arduino, RaspberryPi etc - */ + @ApiModelProperty(name = "deviceType", + value = "Related device type of the application", + required = true, + example = "IoS, Android, Arduino, RaspberryPi etc") private String deviceType; + @ApiModelProperty(name = "applicationReleases", + value = "List of application releases", + required = true) private List applicationReleases; public int getId() { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java index 6c425ab8c8c..2d23fed141b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java @@ -18,107 +18,91 @@ */ package org.wso2.carbon.device.application.mgt.common; -import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; -import java.sql.Timestamp; - -/** - * This class holds the details when releasing an Application to application store. - */ +@ApiModel(value = "ApplicationRelease", description = "This class holds the details when releasing an Application to application store") public class ApplicationRelease { - @Exclude + @ApiModelProperty(name = "id", + value = "ID of the application release") private int id; - /** - * Version of the application release - */ + @ApiModelProperty(name = "version", + value = "Version of the application release") private String version; - /** - * UUID of the application release - */ + @ApiModelProperty(name = "uuid", + value = "UUID of the application release") private String uuid; - /** - * Application storing location - */ + @ApiModelProperty(name = "appStoredLoc", + value = "Application storing location") private String appStoredLoc; - /** - * Banner file storing location - */ + @ApiModelProperty(name = "bannerLoc", + value = "Banner file storing location") private String bannerLoc; - /** - * Screenshot storing location - */ + @ApiModelProperty(name = "screenshotLoc1", + value = "Screenshot storing location") private String screenshotLoc1; - /** - * Screenshot storing location - */ + @ApiModelProperty(name = "screenshotLoc2", + value = "Screenshot storing location") private String screenshotLoc2; - /** - * Screenshot storing location - */ + @ApiModelProperty(name = "screenshotLoc3", + value = "Screenshot storing location") private String screenshotLoc3; - /** - * Application release creator - */ + @ApiModelProperty(name = "iconLoc", + value = "icon file storing location") + private String iconLoc; + + @ApiModelProperty(name = "applicationCreator", + value = "Application release creator") private String applicationCreator; - /** - * Release type of the application release - * e.g: alpha, beta etc - */ + @ApiModelProperty(name = "releaseType", + value = "Release type of the application release", + required = true, + example = "alpha, beta etc") private String releaseType; - /** - * Price of the application release - */ + @ApiModelProperty(name = "price", + value = "Price of the application release", + required = true) private Double price; - /** - * icon file storing location - */ - private String iconLoc; - - /** - * Hash value of the application release - */ + @ApiModelProperty(name = "appHashValue", + value = "Hash value of the application release") private String appHashValue; - /** - * If application release is shared with all tenants it is eqal to 1 otherwise 0 - */ + @ApiModelProperty(name = "isSharedWithAllTenants", + value = "If application release is shared with all tenants it is eqal to 1 otherwise 0", + required = true) private int isSharedWithAllTenants; - /** - * MEta data of the application release - */ + @ApiModelProperty(name = "metaData", + value = "Meta data of the application release", + required = true) private String metaData; - /** - * Number of users who has rated the application release - */ + @ApiModelProperty(name = "ratedUsers", + value = "Number of users who has rated the application release") private int ratedUsers; - /** - * Rating value of the application release - */ + @ApiModelProperty(name = "rating", + value = "Rating value of the application release") private Double rating; - /** - * URL which is used for WEB-CLIP - */ + @ApiModelProperty(name = "url", + value = "URL which is used for WEB-CLIP") private String url; - /** - * Latest Lifecycle state of the application release - */ + @ApiModelProperty(name = "lifecycleState", + value = "Latest Lifecycle state of the application release") private LifecycleState lifecycleState; public int getRatedUsers() { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/LifecycleState.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/LifecycleState.java index fdb1a27c51d..2c0dc8349bb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/LifecycleState.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/LifecycleState.java @@ -19,28 +19,41 @@ package org.wso2.carbon.device.application.mgt.common; import java.sql.Timestamp; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.util.List; +@ApiModel(value = "LifecycleState", description = "LifecycleState represents the an Lifecycle state for an application release") public class LifecycleState { + @ApiModelProperty(name = "id", + value = "ID of the application release lifecycle", + required = true) private int id; + @ApiModelProperty(name = "currentState", + value = "Current state of the application release", + required = true) private String currentState; + @ApiModelProperty(name = "previousState", + value = "Previous state of the application release", + required = true) private String previousState; + @ApiModelProperty(name = "nextStates", + value = "Next possible transferring states from the current state") private List nextStates; + @ApiModelProperty(name = "updatedBy", + value = "Username who is update the application release state") private String updatedBy; + @ApiModelProperty(name = "updatedAt", + value = "Timestamp of the lifecycle has been updated") private Timestamp updatedAt; - private int tenantId; - - private int releaseId; - - private int appId; - public int getId() { return id; } @@ -81,30 +94,6 @@ public class LifecycleState { this.updatedAt = updatedAt; } - public int getTenantId() { - return tenantId; - } - - public void setTenantId(int tenantId) { - this.tenantId = tenantId; - } - - public int getReleaseId() { - return releaseId; - } - - public void setReleaseId(int releaseId) { - this.releaseId = releaseId; - } - - public int getAppId() { - return appId; - } - - public void setAppId(int appId) { - this.appId = appId; - } - public List getNextStates() { return nextStates; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml index ac895fa9e58..73d7905adf2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml @@ -21,13 +21,13 @@ org.wso2.carbon.devicemgt application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.core - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Application Management Core WSO2 Carbon - Application Management Core diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java index d9d12356ec2..6fec1ee2b03 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/LifecycleStateDAO.java @@ -33,7 +33,7 @@ public interface LifecycleStateDAO { List getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException; - void addLifecycleState(LifecycleState state) throws LifeCycleManagementDAOException; + void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException; void deleteLifecycleState(int identifier) throws LifeCycleManagementDAOException; 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/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index e2a0b0198ab..c9286d0ffc0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -92,7 +92,6 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif lifecycleState.setId(rs.getInt("ID")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE")); - lifecycleState.setTenantId(rs.getInt("TENANT_ID")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); lifecycleStates.add(lifecycleState); @@ -109,7 +108,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif } @Override - public void addLifecycleState(LifecycleState state) throws LifeCycleManagementDAOException { + public void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException { Connection conn = null; PreparedStatement stmt = null; try { @@ -119,10 +118,10 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif stmt = conn.prepareStatement(sql); stmt.setString(1, state.getCurrentState()); stmt.setString(2, state.getPreviousState()); - stmt.setInt(3, state.getTenantId()); + stmt.setInt(3, tenantId); stmt.setString(4, state.getUpdatedBy()); - stmt.setInt(5, state.getReleaseId()); - stmt.setInt(6, state.getAppId()); + stmt.setInt(5, releaseId); + stmt.setInt(6, appId); 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/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 2dfad505f27..6ffa3699604 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 @@ -126,21 +126,23 @@ public class ApplicationManagerImpl implements ApplicationManager { "Invalid payload. Application creating payload should contains one application release, but " + "the payload contains more than one"); } - ConnectionManagerUtil.commitDBTransaction(); applicationRelease = application.getApplicationReleases().get(0); applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO(). createRelease(applicationRelease, application.getId(), tenantId); + LifecycleState lifecycleState = new LifecycleState(); - lifecycleState.setAppId(application.getId()); - lifecycleState.setReleaseId(applicationRelease.getId()); lifecycleState.setUpdatedBy(userName); - lifecycleState.setTenantId(tenantId); lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString()); lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString()); addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState); + LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); + lifecycleStateDAO.addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId); + applicationRelease.setLifecycleState(lifecycleState); applicationReleases.add(applicationRelease); application.setApplicationReleases(applicationReleases); + + ConnectionManagerUtil.commitDBTransaction(); } return application; @@ -155,7 +157,12 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg, e); ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationManagementException(msg, e); - } finally { + } catch (LifeCycleManagementDAOException e) { + String msg = "Error occurred while adding application lifecycle state"; + log.error(msg, e); + ConnectionManagerUtil.rollbackDBTransaction(); + throw new ApplicationManagementException(msg, e); + }finally { ConnectionManagerUtil.closeDBConnection(); } } @@ -399,7 +406,6 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState newAppLifecycleState = new LifecycleState(); newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState()); newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString()); - newAppLifecycleState.setTenantId(tenantId); newAppLifecycleState.setUpdatedBy(userName); addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState); storedLocations.add(applicationRelease.getAppHashValue()); @@ -437,7 +443,6 @@ public class ApplicationManagerImpl implements ApplicationManager { LifecycleState newAppLifecycleState = new LifecycleState(); newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState()); newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString()); - newAppLifecycleState.setTenantId(tenantId); newAppLifecycleState.setUpdatedBy(userName); addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState); }else{ @@ -710,17 +715,12 @@ public class ApplicationManagerImpl implements ApplicationManager { Application application = validateApplication(applicationId); ApplicationRelease applicationRelease = validateApplicationRelease(applicationId, applicationUuid); LifecycleStateDAO lifecycleStateDAO; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - if (application != null) { - state.setAppId(applicationId); - } - if (applicationRelease != null) { - state.setReleaseId(applicationRelease.getId()); - } if (state.getCurrentState() != null && state.getPreviousState() != null && state.getUpdatedBy() != null) { validateLifecycleState(state); lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); - lifecycleStateDAO.addLifecycleState(state); + lifecycleStateDAO.addLifecycleState(state, application.getId(), applicationRelease.getId(), tenantId); } } catch (LifeCycleManagementDAOException | DBConnectionException e) { throw new ApplicationManagementException("Failed to add lifecycle state", e); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java index 26bed21ca5a..899887f7ca5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java @@ -36,6 +36,8 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorag import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; +import org.wso2.carbon.device.application.mgt.core.exception.ParsingException; +import org.wso2.carbon.device.application.mgt.core.util.ArtifactsParser; 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; @@ -207,27 +209,11 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager } if (ApplicationType.ANDROID.toString().equals(deviceType)) { - String prefix = "stream2file"; - String suffix = ".apk"; - File tempFile = File.createTempFile(prefix, suffix); - FileOutputStream out = new FileOutputStream(tempFile); - IOUtils.copy(binaryFile, out); - try (ApkFile apkFile = new ApkFile(tempFile)){ - ApkMeta apkMeta = apkFile.getApkMeta(); - applicationRelease.setVersion(apkMeta.getVersionName()); - Files.delete(tempFile.toPath()); - } - + ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(binaryFile); + applicationRelease.setVersion(apkMeta.getVersionName()); } else if (ApplicationType.IOS.toString().equals(deviceType)) { - String prefix = "stream2file"; - String suffix = ".ipa"; - - File tempFile = File.createTempFile(prefix, suffix); - FileOutputStream out = new FileOutputStream(tempFile); - IOUtils.copy(binaryFile, out); - Map plistInfo = getIPAInfo(tempFile); - applicationRelease.setVersion(plistInfo.get("CFBundleVersion")); - Files.delete(tempFile.toPath()); + NSDictionary plistInfo = ArtifactsParser.readiOSManifestFile(binaryFile); + applicationRelease.setVersion(plistInfo.objectForKey(ArtifactsParser.IPA_BUNDLE_VERSION_KEY).toString()); } else { throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " + "application types " + applicationRelease.getUuid()); @@ -249,6 +235,10 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager throw new ApplicationStorageManagementException( "IO Exception while saving the release artifacts in the server for the application UUID " + applicationRelease.getUuid(), e); + } catch (ParsingException e) { + throw new ApplicationStorageManagementException( + "Error occured while parsing the artifact file. Application release UUID is " + applicationRelease + .getUuid(), e); } 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/ArtifactsParser.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java index a696c466401..09b37e4e789 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java @@ -37,6 +37,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; import java.util.UUID; import java.nio.file.Files; import java.util.zip.ZipEntry; @@ -55,19 +56,22 @@ public class ArtifactsParser { File tempFile = null; ApkMeta apkMeta; try { - tempFile = File.createTempFile("temp" + UUID.randomUUID(), ".apk"); try (FileOutputStream out = new FileOutputStream(tempFile)) { IOUtils.copy(inputStream, out); + try (ApkFile apkFile = new ApkFile(tempFile)) { + apkMeta = apkFile.getApkMeta(); + } } - - ApkFile apkFile = new ApkFile(tempFile); - apkMeta = apkFile.getApkMeta(); } catch (IOException e) { throw new ParsingException("Error while parsing the apk.", e); } finally { if (tempFile != null) { - tempFile.delete(); + try { + Files.delete(tempFile.toPath()); + } catch (IOException e) { + log.error("Error occured while deleting the temp file", e); + } } } return apkMeta; @@ -75,42 +79,37 @@ public class ArtifactsParser { public static NSDictionary readiOSManifestFile(InputStream inputStream) throws ParsingException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - File tempFile = null; NSDictionary rootDict; - ZipInputStream stream = null; - FileOutputStream out = null; - + File tempFile = null; try { tempFile = File.createTempFile("temp" + UUID.randomUUID(), ".ipa"); - out = new FileOutputStream(tempFile); - IOUtils.copy(inputStream, out); - stream = new ZipInputStream(new FileInputStream(tempFile)); - - ZipEntry entry; - while ((entry = stream.getNextEntry()) != null) { - if (entry.getName().matches("^(Payload/)(.)+(.app/Info.plist)$")) { - InputStream is = stream; - - int nRead; - byte[] data = new byte[16384]; - - while ((nRead = is.read(data, 0, data.length)) != -1) { - buffer.write(data, 0, nRead); + try (FileOutputStream out = new FileOutputStream(tempFile)) { + IOUtils.copy(inputStream, out); + try (ZipInputStream stream = new ZipInputStream(new FileInputStream(tempFile))) { + ZipEntry entry; + while ((entry = stream.getNextEntry()) != null) { + if (entry.getName().matches("^(Payload/)(.)+(.app/Info.plist)$")) { + InputStream is = stream; + int nRead; + byte[] data = new byte[16384]; + + while ((nRead = is.read(data, 0, data.length)) != -1) { + buffer.write(data, 0, nRead); + } + buffer.flush(); + break; + } + } + try { + rootDict = (NSDictionary) BinaryPropertyListParser.parse(buffer.toByteArray()); + } catch (IllegalArgumentException e) { + log.debug("Uploaded file didn't have a Binary Plist"); + try { + rootDict = (NSDictionary) PropertyListParser.parse(buffer.toByteArray()); + } catch (Exception e1) { + throw new ParsingException("Error while parsing the non binary plist.", e1); + } } - - buffer.flush(); - break; - } - } - - try { - rootDict = (NSDictionary) BinaryPropertyListParser.parse(buffer.toByteArray()); - } catch (IllegalArgumentException e) { - log.debug("Uploaded file didn't have a Binary Plist"); - try { - rootDict = (NSDictionary) PropertyListParser.parse(buffer.toByteArray()); - } catch (Exception e1) { - throw new ParsingException("Error while parsing the non binary plist.", e1); } } } catch (PropertyListFormatException e1) { @@ -128,7 +127,6 @@ public class ArtifactsParser { } } } - return rootDict; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml index ebb2c88188c..f32092e1553 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/pom.xml @@ -22,13 +22,13 @@ application-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.publisher.api - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT war WSO2 Carbon - Application Management API WSO2 Carbon - Application Management API diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java index b7d73018c54..aee5a524e3b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java @@ -279,10 +279,6 @@ public interface ApplicationManagementAPI { value = "The application that need to be created.", required = true) @Valid Application application, - @ApiParam( - name = "applicationRelease", - value = "Application Release") - @Valid ApplicationRelease applicationRelease, @ApiParam( name = "binaryFile", value = "Binary file of uploading 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/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index f36ef23f831..7c4fe746c35 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -109,7 +109,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Consumes("application/json") public Response createApplication( @Valid Application application, - @Valid ApplicationRelease applicationRelease, @Multipart("binaryFile") Attachment binaryFile, @Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, @@ -120,18 +119,24 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { InputStream bannerFileStream; List attachments = new ArrayList<>(); List applicationReleases = new ArrayList<>(); + ApplicationRelease applicationRelease; try { - if (!isValidAppCreatingRequest(binaryFile, iconFile, bannerFile, attachmentList, application)) { return Response.status(Response.Status.BAD_REQUEST).build(); - } else if (binaryFile == null && ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + } + if (ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + applicationRelease = application.getApplicationReleases().get(0); applicationRelease = applicationStorageManager .uploadReleaseArtifact(applicationRelease, application.getType(), application.getDeviceType(), null); - } else if (binaryFile != null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + } else { + applicationRelease = application.getApplicationReleases().get(0); applicationRelease = applicationStorageManager .uploadReleaseArtifact(applicationRelease, application.getType(), application.getDeviceType(), binaryFile.getDataHandler().getInputStream()); + if (applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } } iconFileStream = iconFile.getDataHandler().getInputStream(); @@ -140,13 +145,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { for (Attachment screenshot : attachmentList) { attachments.add(screenshot.getDataHandler().getInputStream()); } - - if (applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } applicationRelease = applicationStorageManager.uploadImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments); - applicationRelease.setUuid(UUID.randomUUID().toString()); applicationReleases.add(applicationRelease); application.setApplicationReleases(applicationReleases); @@ -452,6 +452,14 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { private boolean isValidAppCreatingRequest(Attachment binaryFile, Attachment iconFile, Attachment bannerFile, List attachmentList, Application application){ + if (application.getApplicationReleases().size() > 1) { + log.error( + "Invalid application creating request. Application creating request must have single application " + + "release. Application name:" + application.getName() + " and type: " + + application.getType()); + return false; + } + if (iconFile == null) { log.error("Icon file is not found for the application release. Application name: " + application.getName() + " and type: " + application.getType()); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml index 19083272f15..e903f7eff60 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml @@ -22,12 +22,12 @@ org.wso2.carbon.devicemgt application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT 4.0.0 org.wso2.carbon.device.application.mgt.publisher.ui - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Application Management Publisher UI WSO2 Carbon - Application Management Publisher UI React Application http://wso2.org diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml index e65148da2e6..f87d02d27cd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml @@ -22,13 +22,13 @@ application-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.application.mgt.store.api - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT war WSO2 Carbon - Application Management API WSO2 Carbon - Application Management API diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml index 4962a730b64..4b37665d874 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/pom.xml @@ -24,10 +24,10 @@ org.wso2.carbon.devicemgt application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT org.wso2.carbon.device.application.mgt.store.ui - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml index 68f8b0e0e51..166a68acb10 100644 --- a/components/application-mgt/pom.xml +++ b/components/application-mgt/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 application-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Application Management Component WSO2 Carbon - Application Management Component diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml index 89067020852..721d500b624 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml index a9b3d9bd2ff..f65f0428f10 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.v09.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.v09.api/pom.xml index ba0d7533c98..ea10e11948d 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.v09.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.v09.api/pom.xml @@ -24,7 +24,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index e3e8a518664..a9679046edd 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -21,13 +21,13 @@ org.wso2.carbon.devicemgt certificate-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.certificate.mgt.core - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Certificate Management Core WSO2 Carbon - Certificate Management Core diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.v09.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.v09.api/pom.xml index ff336875bb0..a4205aafd60 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.v09.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.v09.api/pom.xml @@ -24,7 +24,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml index 07ec8f8208b..5347bdaf42d 100644 --- a/components/certificate-mgt/pom.xml +++ b/components/certificate-mgt/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt certificate-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Certificate Management Component http://wso2.org diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml index 3482bd10028..3c8242ddf84 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml index bcc88b81354..4d7c55ff183 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml index 4fda8ced249..2a2022a5b75 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 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 83a9289442f..7c1700c2108 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 @@ -64,7 +64,9 @@ public class FCMNotificationStrategy implements NotificationStrategy { if (NOTIFIER_TYPE_FCM.equals(config.getType())) { Device device = FCMDataHolder.getInstance().getDeviceManagementProviderService() .getDeviceWithTypeProperties(ctx.getDeviceId()); - this.sendWakeUpCall(ctx.getOperation().getCode(), device); + if(getFCMToken(device.getProperties()) != null) { + this.sendWakeUpCall(ctx.getOperation().getCode(), device); + } } else { if (log.isDebugEnabled()) { log.debug("Not using FCM notifier as notifier type is set to " + config.getType() + diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml index 68182482bb4..987e978b6c5 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index d64997df98d..8e137e6769a 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml index 4dae1edd0d7..8856d0b0743 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index 230f122bae8..3557236080a 100644 --- a/components/device-mgt-extensions/pom.xml +++ b/components/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml index b8530ce1ca9..f1887215276 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DataPublisherUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DataPublisherUtil.java index a86b38ee1d2..1d65b3092e5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DataPublisherUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DataPublisherUtil.java @@ -18,17 +18,24 @@ */ package org.wso2.carbon.device.mgt.analytics.data.publisher; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; -import org.wso2.carbon.databridge.agent.DataPublisher; +import org.wso2.carbon.databridge.agent.exception.DataEndpointConfigurationException; import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class DataPublisherUtil { + private static final Log log = LogFactory.getLog(DataPublisherUtil.class); + private DataPublisherUtil(){ } @@ -46,4 +53,72 @@ public class DataPublisherUtil { } } + public static ArrayList getEndpointGroups(String urlSet) { + ArrayList urlGroups = new ArrayList<>(); + Pattern regex = Pattern.compile("\\{.*?\\}"); + Matcher regexMatcher = regex.matcher(urlSet); + + while(regexMatcher.find()) { + urlGroups.add(regexMatcher.group().replace("{", "").replace("}", "")); + } + + if (urlGroups.size() == 0) { + urlGroups.add(urlSet.replace("{", "").replace("}", "")); + } + return urlGroups; + } + + public static String[] getEndpoints(String aURLGroup) throws DataEndpointConfigurationException { + boolean isLBURL = false; + boolean isFailOverURL = false; + if (aURLGroup.contains(",")) { + isLBURL = true; + } + + if (aURLGroup.contains("|")) { + isFailOverURL = true; + } + + if (isLBURL && isFailOverURL) { + String msg = "Invalid data endpoints URL set provided : " + aURLGroup + + ", a URL group can be configured as failover OR load balancing endpoints."; + log.error(msg); + throw new DataEndpointConfigurationException(msg); + } else { + String[] urls; + if (isLBURL) { + urls = aURLGroup.split(","); + } else if (isFailOverURL) { + urls = aURLGroup.split("\\|"); + } else { + urls = new String[]{aURLGroup}; + } + return urls; + } + } + + public static int obtainHashId(String deviceId, int urlGroupsCount) { + byte[] chars = deviceId.getBytes(); + int sum = 0; + for (byte b : chars) { + sum += b; + } + return sum % urlGroupsCount; + } + + @SuppressWarnings("Duplicates") + public static String replaceProperty(String urlWithPlaceholders) { + String regex = "\\$\\{(.*?)\\}"; + Pattern pattern = Pattern.compile(regex); + Matcher matchPattern = pattern.matcher(urlWithPlaceholders); + while (matchPattern.find()) { + String sysPropertyName = matchPattern.group(1); + String sysPropertyValue = System.getProperty(sysPropertyName); + if (sysPropertyValue != null && !sysPropertyName.isEmpty()) { + urlWithPlaceholders = urlWithPlaceholders.replaceAll("\\$\\{(" + sysPropertyName + ")\\}", sysPropertyValue); + } + } + return urlWithPlaceholders; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DeviceDataPublisher.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DeviceDataPublisher.java index 8753dc2af7b..18d5be42874 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DeviceDataPublisher.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/DeviceDataPublisher.java @@ -18,6 +18,8 @@ */ package org.wso2.carbon.device.mgt.analytics.data.publisher; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.databridge.agent.DataPublisher; import org.wso2.carbon.databridge.agent.exception.DataEndpointAgentConfigurationException; import org.wso2.carbon.databridge.agent.exception.DataEndpointAuthenticationException; @@ -26,15 +28,25 @@ import org.wso2.carbon.databridge.agent.exception.DataEndpointException; import org.wso2.carbon.databridge.commons.exception.TransportException; import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration; import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherServiceImpl; + +import java.util.HashMap; +import java.util.Map; /** * This is used to manage data publisher per tenant. */ public class DeviceDataPublisher { - private DataPublisher dataPublisher; + private static Log log = LogFactory.getLog(EventsPublisherServiceImpl.class); + + private Map dataPublishers; private static DeviceDataPublisher deviceDataPublisher; + private DeviceDataPublisher() { + dataPublishers = new HashMap<>(); + } + public static DeviceDataPublisher getInstance() { if (deviceDataPublisher == null) { synchronized (DeviceDataPublisher.class) { @@ -47,45 +59,52 @@ public class DeviceDataPublisher { } /** - * this return the data publisher for the tenant. + * This returns the data publisher for the tenant based on the analytics node id. * + * @param analyticsConfig Analytics configurations + * @param receiverURLSet Data receiver URL set as string * @return instance of data publisher - * @throws DataPublisherConfigurationException - * + * @throws DataPublisherConfigurationException on exception */ - public DataPublisher getDataPublisher() throws DataPublisherConfigurationException { - if (this.dataPublisher == null) { - synchronized (this) { - if (this.dataPublisher == null) { - AnalyticsConfiguration analyticsConfig = AnalyticsConfiguration.getInstance(); - if (!analyticsConfig.isEnable()) { - return null; - } - String analyticsServerUrlGroups = analyticsConfig.getReceiverServerUrl(); - String analyticsServerUsername = analyticsConfig.getAdminUsername(); - String analyticsServerPassword = analyticsConfig.getAdminPassword(); - try { - this.dataPublisher = new DataPublisher(analyticsServerUrlGroups, analyticsServerUsername, - analyticsServerPassword); - } catch (DataEndpointAgentConfigurationException e) { - throw new DataPublisherConfigurationException("Configuration Exception on data publisher for " + - "ReceiverGroup = " + analyticsServerUrlGroups + " for username " + analyticsServerUsername, e); - } catch (DataEndpointException e) { - throw new DataPublisherConfigurationException("Invalid ReceiverGroup = " + analyticsServerUrlGroups, e); - } catch (DataEndpointConfigurationException e) { - throw new DataPublisherConfigurationException("Invalid Data endpoint configuration.", e); - } catch (DataEndpointAuthenticationException e) { - throw new DataPublisherConfigurationException("Authentication Failed for user " + - analyticsServerUsername, e); - } catch (TransportException e) { - throw new DataPublisherConfigurationException("Error occurred while retrieving data publisher", e); - } - } else { - return this.dataPublisher; + public DataPublisher getDataPublisher(AnalyticsConfiguration analyticsConfig, String receiverURLSet) + throws DataPublisherConfigurationException { + synchronized (this) { + if (this.dataPublishers.containsKey(receiverURLSet)) { + return this.dataPublishers.get(receiverURLSet); + } else { + String analyticsServerUrlGroups = analyticsConfig.getReceiverServerUrl(); + String analyticsServerUsername = analyticsConfig.getAdminUsername(); + String analyticsServerPassword = analyticsConfig.getAdminPassword(); + + try { + DataPublisher dataPublisher = new DataPublisher(receiverURLSet, analyticsServerUsername, + analyticsServerPassword); + this.dataPublishers.put(receiverURLSet, dataPublisher); + return dataPublisher; + } catch (DataEndpointAgentConfigurationException e) { + String msg = "Configuration Exception on data publisher for " + + "ReceiverGroup = " + analyticsServerUrlGroups + " for username " + analyticsServerUsername; + log.error(msg, e); + throw new DataPublisherConfigurationException(msg, e); + } catch (DataEndpointException e) { + String msg = "Invalid ReceiverGroup = " + analyticsServerUrlGroups; + log.error(msg, e); + throw new DataPublisherConfigurationException(msg, e); + } catch (DataEndpointConfigurationException e) { + String msg = "Invalid Data endpoint configuration."; + log.error(msg, e); + throw new DataPublisherConfigurationException(msg, e); + } catch (DataEndpointAuthenticationException e) { + String msg = "Authentication Failed for user " + analyticsServerUsername; + log.error(msg, e); + throw new DataPublisherConfigurationException(msg, e); + } catch (TransportException e) { + String msg = "Error occurred while retrieving data publisher"; + log.error(msg, e); + throw new DataPublisherConfigurationException(msg, e); } } } - return this.dataPublisher; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/config/AnalyticsConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/config/AnalyticsConfiguration.java index b758d4cf1c8..67a8c36333d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/config/AnalyticsConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/config/AnalyticsConfiguration.java @@ -39,6 +39,7 @@ import java.io.File; public class AnalyticsConfiguration { private String receiverServerUrl; + private String analyticsPublisherUrl; private String adminUsername; private String adminPassword; private boolean enable; @@ -81,13 +82,22 @@ public class AnalyticsConfiguration { @XmlElement(name = "ReceiverServerUrl", required = true) public String getReceiverServerUrl() { - return receiverServerUrl; + return DataPublisherUtil.replaceProperty(receiverServerUrl); } public void setReceiverServerUrl(String receiverServerUrl) { this.receiverServerUrl = receiverServerUrl; } + @XmlElement(name = "AnalyticsPublisherUrl", required = true) + public String getAnalyticsPublisherUrl() { + return DataPublisherUtil.replaceProperty(analyticsPublisherUrl); + } + + public void setAnalyticsPublisherUrl(String analyticsPublisherUrl) { + this.analyticsPublisherUrl = analyticsPublisherUrl; + } + @XmlElement(name = "Enabled", required = true) public boolean isEnable() { return enable; @@ -102,8 +112,14 @@ public class AnalyticsConfiguration { } public static void init(String analyticsConfigPath) throws DataPublisherConfigurationException { + File authConfig = new File(analyticsConfigPath); + if (!authConfig.exists()) { + log.warn(DEVICE_ANALYTICS_CONFIG_PATH + " does not exist. Disabling AnalyticsConfiguration."); + config = new AnalyticsConfiguration(); + config.setEnable(false); + return; + } try { - File authConfig = new File(analyticsConfigPath); Document doc = DataPublisherUtil.convertToDocument(authConfig); /* Un-marshaling device analytics configuration */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/service/EventsPublisherService.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/service/EventsPublisherService.java index 7be1ac574b8..f75496d0e2f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/service/EventsPublisherService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/service/EventsPublisherService.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.analytics.data.publisher.service; import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; /** - * This service can be used to publish and retreive data from the Analytics Server. + * This service can be used to publish and retrieve data from the Analytics Server. */ public interface EventsPublisherService { @@ -32,8 +32,8 @@ public interface EventsPublisherService { * @param metaDataArray - meta data that needs to pushed * @param correlationDataArray - correlation data that needs to be pushed * @param payloadDataArray - payload data that needs to be pushed - * @return - * @throws DataPublisherConfigurationException + * @return if success returns true + * @throws DataPublisherConfigurationException on exception */ boolean publishEvent(String streamName, String version, Object[] metaDataArray, Object[] correlationDataArray, Object[] payloadDataArray) throws DataPublisherConfigurationException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/service/EventsPublisherServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/service/EventsPublisherServiceImpl.java index 4c039221c81..6b7b81aa36b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/service/EventsPublisherServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/src/main/java/org/wso2/carbon/device/mgt/analytics/data/publisher/service/EventsPublisherServiceImpl.java @@ -24,44 +24,67 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.databridge.agent.DataPublisher; import org.wso2.carbon.databridge.commons.utils.DataBridgeCommonsUtils; +import org.wso2.carbon.device.mgt.analytics.data.publisher.DataPublisherUtil; import org.wso2.carbon.device.mgt.analytics.data.publisher.DeviceDataPublisher; +import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration; import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; +import java.util.ArrayList; + /** * This is the implementation of Osgi Service which can be used to publish and retireved * event/records. */ public class EventsPublisherServiceImpl implements EventsPublisherService { + private static Log log = LogFactory.getLog(EventsPublisherServiceImpl.class); /** * @param streamName is the name of the stream that the data needs to pushed * @param version is the version of the stream - * @param metaDataArray - meta data that needs to pushed - * @param correlationDataArray - correlation data that needs to be pushed - * @param payloadDataArray - payload data that needs to be pushed + * @param metaDataArray meta data that needs to pushed + * @param correlationDataArray correlation data that needs to be pushed + * @param payloadDataArray payload data that needs to be pushed * @return if success returns true - * @throws DataPublisherConfigurationException + * @throws DataPublisherConfigurationException on exception */ @Override public boolean publishEvent(String streamName, String version, Object[] metaDataArray, Object[] correlationDataArray, Object[] payloadDataArray) throws DataPublisherConfigurationException { + AnalyticsConfiguration analyticsConfig = AnalyticsConfiguration.getInstance(); + if (!analyticsConfig.isEnable()) { + log.warn("Analytics data publishing not enabled."); + return false; + } + + if (metaDataArray == null || metaDataArray.length == 0) { + String msg = "meta data[0] must have the device Id field"; + log.error(msg); + throw new DataPublisherConfigurationException(msg); + } + + ArrayList receiverURLGroups = DataPublisherUtil.getEndpointGroups(analyticsConfig.getReceiverServerUrl()); + int hashId = DataPublisherUtil.obtainHashId(metaDataArray[0].toString(), receiverURLGroups.size()); + if (receiverURLGroups.size() <= hashId) { + String msg = "Invalid receiver url group size. Expected to be higher than: " + hashId + " Actual: " + + receiverURLGroups.size(); + log.error(msg); + throw new DataPublisherConfigurationException(msg); + } + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { - if (metaDataArray == null || metaDataArray.length == 0) { - throw new DataPublisherConfigurationException("meta data[0] should have the device Id field"); - } else { - metaDataArray[0] = tenantDomain + "@" + metaDataArray[0]; - } + metaDataArray[0] = tenantDomain + "@" + metaDataArray[0]; } PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); try { - DataPublisher dataPublisher = DeviceDataPublisher.getInstance().getDataPublisher(); + DataPublisher dataPublisher = DeviceDataPublisher.getInstance() + .getDataPublisher(analyticsConfig, receiverURLGroups.get(hashId)); if (dataPublisher != null) { String streamId = DataBridgeCommonsUtils.generateStreamId(streamName, version); return dataPublisher.tryPublish(streamId, System.currentTimeMillis(), metaDataArray, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/pom.xml new file mode 100644 index 00000000000..4ca94f1c85f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/pom.xml @@ -0,0 +1,80 @@ + + + + + device-mgt + org.wso2.carbon.devicemgt + 3.1.40-SNAPSHOT + + 4.0.0 + + org.wso2.carbon.device.mgt.analytics.wsproxy + war + WSO2 - Webapp for Web Socket Proxy + http://wso2.org + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics.data.publisher + provided + + + javax.ws.rs + javax.ws.rs-api + + + org.apache.cxf + cxf-rt-frontend-jaxrs + + + + + secured-websocket-proxy + + + org.jacoco + jacoco-maven-plugin + + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/site + + + + + + + + \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/exception/WSProxyException.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/exception/WSProxyException.java new file mode 100644 index 00000000000..7937ada3710 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/exception/WSProxyException.java @@ -0,0 +1,37 @@ +/* + * 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.mgt.analytics.wsproxy.exception; + +/** + * Indicates an error with deployment tinkerer + * + * @since 1.0.0 + */ +public class WSProxyException extends Exception { + + /** + * Constructs a new exception with the message provided and the cause. + * + * @param message the detailed message of the exception + * @param cause the cause of the exception + */ + public WSProxyException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/SubscriptionEndpoint.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/SubscriptionEndpoint.java new file mode 100644 index 00000000000..14db789fa9d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/SubscriptionEndpoint.java @@ -0,0 +1,146 @@ +/* + * 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.mgt.analytics.wsproxy.inbound; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.databridge.agent.exception.DataEndpointConfigurationException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.DataPublisherUtil; +import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration; +import org.wso2.carbon.device.mgt.analytics.wsproxy.exception.WSProxyException; +import org.wso2.carbon.device.mgt.analytics.wsproxy.outbound.AnalyticsClient; + +import javax.websocket.CloseReason; +import javax.websocket.Session; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Interface for subscription and un-subscription for web socket + */ + +public class SubscriptionEndpoint { + + private static final Log log = LogFactory.getLog(SubscriptionEndpoint.class); + private Map> analyticsClientsMap = new HashMap<>(); + + /** + * Web socket onOpen - When client sends a message + * + * @param session - Users registered session. + */ + public void onOpen(Session session) { + if (log.isDebugEnabled()) { + log.debug("WebSocket opened, for Session id: " + session.getId()); + } + + AnalyticsConfiguration analyticsConfig = AnalyticsConfiguration.getInstance(); + ArrayList publisherGroups = + DataPublisherUtil.getEndpointGroups(analyticsConfig.getAnalyticsPublisherUrl()); + List analyticsClients = new ArrayList<>(); + for (String publisherURLGroup : publisherGroups) { + try { + String[] endpoints = DataPublisherUtil.getEndpoints(publisherURLGroup); + for (String endpoint : endpoints) { + try { + endpoint = endpoint.trim(); + if (!endpoint.endsWith("/")) { + endpoint += "/"; + } + endpoint += session.getRequestURI().getSchemeSpecificPart().replace("secured-websocket-proxy",""); + AnalyticsClient analyticsClient = new AnalyticsClient(session); + analyticsClient.connectClient(new URI(endpoint)); + analyticsClients.add(analyticsClient); + } catch (URISyntaxException e) { + log.error("Unable to create URL from: " + endpoint, e); + } catch (WSProxyException e) { + log.error("Unable to create WS client for: " + endpoint, e); + } + } + } catch (DataEndpointConfigurationException e) { + log.error("Unable to obtain endpoints from receiverURLGroup: " + publisherURLGroup, e); + } + } + if (log.isDebugEnabled()) { + log.debug("Configured " + analyticsClients.size() + " analytics clients for Session id: " + + session.getId()); + } + analyticsClientsMap.put(session.getId(), analyticsClients); + } + + /** + * Web socket onClose - Remove the registered sessions + * + * @param session - Users registered session. + * @param reason - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + * @param tenantDomain - Domain of the tenant. + */ + public void onClose(Session session, CloseReason reason, String streamName, String version, String tenantDomain) { + if (log.isDebugEnabled()) { + log.debug("Closing a WebSocket due to " + reason.getReasonPhrase() + ", for session ID:" + + session.getId() + ", for request URI - " + session.getRequestURI()); + } + for (AnalyticsClient analyticsClient : analyticsClientsMap.get(session.getId())) { + if (analyticsClient != null) { + try { + analyticsClient.closeConnection(reason); + } catch (WSProxyException e) { + log.error("Error occurred while closing ws connection due to " + reason.getReasonPhrase() + + ", for session ID:" + session.getId() + ", for request URI - " + session.getRequestURI(), e); + } + } + } + analyticsClientsMap.remove(session.getId()); + } + + /** + * Web socket onMessage - When client sens a message + * + * @param session - Users registered session. + * @param message - Status code for web-socket close. + */ + public void onMessage(Session session, String message) { + for (AnalyticsClient analyticsClient : analyticsClientsMap.get(session.getId())) { + if (analyticsClient != null) { + analyticsClient.sendMessage(message); + } + } + } + + /** + * Web socket onError + * + * @param session - Users registered session. + * @param throwable - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + * @param tenantDomain - Domain of the tenant. + */ + public void onError(Session session, Throwable throwable, String streamName, String version, String tenantDomain) { + log.error("Error occurred in session ID: " + session.getId() + ", for request URI - " + + session.getRequestURI() + ", " + throwable.getMessage(), throwable); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/SuperTenantSubscriptionEndpoint.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/SuperTenantSubscriptionEndpoint.java new file mode 100644 index 00000000000..0e4bc3684d9 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/SuperTenantSubscriptionEndpoint.java @@ -0,0 +1,104 @@ +/* + * 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.mgt.analytics.wsproxy.inbound; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.base.MultitenantConstants; + +import javax.websocket.CloseReason; +import javax.websocket.EndpointConfig; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; + +/** + * Connect to web socket with Super tenant + */ + +@ServerEndpoint(value = "/{destination}/{streamname}/{version}") +public class SuperTenantSubscriptionEndpoint extends SubscriptionEndpoint { + + private static final Log log = LogFactory.getLog(SuperTenantSubscriptionEndpoint.class); + + /** + * Web socket onOpen - When client sends a message + * + * @param session - Users registered session. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + @OnOpen + public void onOpen(Session session, EndpointConfig config, @PathParam("streamname") String streamName, + @PathParam("version") String version) { + if (log.isDebugEnabled()) { + log.debug("WebSocket opened, for Session id: " + session.getId() + ", for the Stream:" + streamName); + } + super.onOpen(session); + } + + /** + * Web socket onMessage - When client sens a message + * + * @param session - Users registered session. + * @param message - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + */ + @OnMessage + public void onMessage(Session session, String message, @PathParam("streamname") String streamName) { + if (log.isDebugEnabled()) { + log.debug("Received message from client. Message: " + message + ", " + + "for Session id: " + session.getId() + ", for the Stream:" + streamName); + } + super.onMessage(session, message); + } + + /** + * Web socket onClose - Remove the registered sessions + * + * @param session - Users registered session. + * @param reason - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + @OnClose + public void onClose(Session session, CloseReason reason, @PathParam("streamname") String streamName, + @PathParam("version") String version) { + super.onClose(session, reason, streamName, version, MultitenantConstants.SUPER_TENANT_NAME); + } + + /** + * Web socket onError - Remove the registered sessions + * + * @param session - Users registered session. + * @param throwable - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + @OnError + public void onError(Session session, Throwable throwable, @PathParam("streamname") String streamName, + @PathParam("version") String version) { + super.onError(session, throwable, streamName, version, MultitenantConstants.SUPER_TENANT_NAME); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/TenantSubscriptionEndpoint.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/TenantSubscriptionEndpoint.java new file mode 100644 index 00000000000..02e55cfed6c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/TenantSubscriptionEndpoint.java @@ -0,0 +1,103 @@ +/* + * 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.mgt.analytics.wsproxy.inbound; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.websocket.CloseReason; +import javax.websocket.EndpointConfig; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; + +/** + * Connect to web socket with a tenant + */ + +@ServerEndpoint(value = "/{destination}/t/{tdomain}/{streamname}/{version}") +public class TenantSubscriptionEndpoint extends SubscriptionEndpoint { + + private static final Log log = LogFactory.getLog(TenantSubscriptionEndpoint.class); + + /** + * Web socket onOpen - When client sends a message + * + * @param session - Users registered session. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + * @param tdomain - Tenant domain extracted from ws url. + */ + @OnOpen + public void onOpen(Session session, EndpointConfig config, @PathParam("streamname") String streamName, + @PathParam("version") String version, @PathParam("tdomain") String tdomain) { + if (log.isDebugEnabled()) { + log.debug("WebSocket opened, for Session id: " + session.getId() + ", for the Stream:" + streamName); + } + super.onOpen(session); + } + + /** + * Web socket onMessage - When client sens a message + * + * @param session - Users registered session. + * @param message - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + */ + @OnMessage + public void onMessage(Session session, String message, @PathParam("streamname") String streamName, @PathParam("tdomain") String tdomain) { + if (log.isDebugEnabled()) { + log.debug("Received message from client. Message: " + message + ", for Session id: " + + session.getId() + ", for tenant domain" + tdomain + ", for the Adaptor:" + streamName); + } + super.onMessage(session, message); + } + + /** + * Web socket onClose - Remove the registered sessions + * + * @param session - Users registered session. + * @param reason - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + @OnClose + public void onClose(Session session, CloseReason reason, @PathParam("streamname") String streamName, + @PathParam("version") String version, @PathParam("tdomain") String tdomain) { + super.onClose(session, reason, streamName, version, tdomain); + } + + /** + * Web socket onError - Remove the registered sessions + * + * @param session - Users registered session. + * @param throwable - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + @OnError + public void onError(Session session, Throwable throwable, @PathParam("streamname") String streamName, + @PathParam("version") String version, @PathParam("tdomain") String tdomain) { + super.onError(session, throwable, streamName, version, tdomain); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/outbound/AnalyticsClient.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/outbound/AnalyticsClient.java new file mode 100644 index 00000000000..7bfd480288e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/outbound/AnalyticsClient.java @@ -0,0 +1,120 @@ +/* + * 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.mgt.analytics.wsproxy.outbound; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.analytics.wsproxy.exception.WSProxyException; + +import javax.websocket.CloseReason; +import javax.websocket.ContainerProvider; +import javax.websocket.DeploymentException; +import javax.websocket.OnClose; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import javax.websocket.WebSocketContainer; +import java.io.IOException; +import java.net.URI; + +/** + * This class holds web socket client implementation + * + * @since 1.0.0 + */ +@javax.websocket.ClientEndpoint +public class AnalyticsClient { + + private static final Log log = LogFactory.getLog(AnalyticsClient.class); + + private WebSocketContainer container; + private Session analyticsSession = null; + private Session clientSession; + + /** + * Create {@link AnalyticsClient} instance. + */ + public AnalyticsClient(Session clientSession) { + container = ContainerProvider.getWebSocketContainer(); + this.clientSession = clientSession; + } + + /** + * Create web socket client connection using {@link WebSocketContainer}. + */ + public void connectClient(URI endpointURI) throws WSProxyException { + try { + analyticsSession = container.connectToServer(this, endpointURI); + } catch (DeploymentException | IOException e) { + String msg = "Error occurred while connecting to remote endpoint " + endpointURI.toString(); + log.error(msg, e); + throw new WSProxyException(msg, e); + } + } + + /** + * Callback hook for Connection close events. + * + * @param userSession the analyticsSession which is getting closed. + * @param reason the reason for connection close + */ + @OnClose + public void onClose(Session userSession, CloseReason reason) { + if (log.isDebugEnabled()) { + log.debug("Closing web socket session: '" + userSession.getId() + "'. Code: " + + reason.getCloseCode().toString() + " Reason: " + reason.getReasonPhrase()); + } + this.analyticsSession = null; + } + + /** + * Callback hook for Message Events. + * + *

This method will be invoked when a client send a message. + * + * @param message The text message. + */ + @OnMessage + public void onMessage(String message) { + this.clientSession.getAsyncRemote().sendText(message); + } + + /** + * Send a message. + * + * @param message the message which is going to send. + */ + public void sendMessage(String message) { + this.analyticsSession.getAsyncRemote().sendText(message); + } + + /** + * Close current connection. + */ + public void closeConnection(CloseReason closeReason) throws WSProxyException { + if (this.analyticsSession != null) { + try { + this.analyticsSession.close(closeReason); + } catch (IOException e) { + String msg = "Error on closing WS connection."; + log.error(msg, e); + throw new WSProxyException(msg, e); + } + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/webapp/WEB-INF/web.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000000..bf625c9256d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,46 @@ + + + + + Output WebSocket Proxy + + + ContentTypeBasedCachePreventionFilter + org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter + + patterns + text/html" ,application/json" ,text/plain + + + filterAction + enforce + + + httpHeaders + Cache-Control: no-store, no-cache, must-revalidate, private + + + + + ContentTypeBasedCachePreventionFilter + /* + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index d58eef3345c..33e23468525 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java index b1c84d48423..ec72dc6d16f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java @@ -429,6 +429,12 @@ public interface ActivityInfoProviderService { "Example: Mon, 05 Jan 2014 15:10:00 +0200", required = false) @QueryParam("since") String since, + @ApiParam( + name = "initiatedBy", + value = "The user, who initiated the operation. If is done by the task, the SYSTEM will be returned." + + " And if a user adds the operation, username is returned", + required = false) + @QueryParam("initiatedBy") String initiatedBy, @ApiParam( name = "offset", value = "The starting pagination index for the complete list of qualified items.", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java index 45ad77ee78e..d115659e188 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java @@ -216,8 +216,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService @GET @Override - public Response getActivities(@QueryParam("since") String since, @QueryParam("offset") int offset, - @QueryParam("limit") int limit, + public Response getActivities(@QueryParam("since") String since, @QueryParam("initiatedBy")String initiatedBy, + @QueryParam("offset") int offset, @QueryParam("limit") int limit, @HeaderParam("If-Modified-Since") String ifModifiedSince) { long ifModifiedSinceTimestamp; @@ -267,6 +267,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService Response response = validateAdminUser(); if (response == null) { List activities; + int count = 0; ActivityList activityList = new ActivityList(); DeviceManagementProviderService dmService; try { @@ -274,15 +275,28 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService log.debug("Calling database to get activities."); } dmService = DeviceMgtAPIUtils.getDeviceManagementService(); - activities = dmService.getActivitiesUpdatedAfter(timestamp, limit, offset); - activityList.setList(activities); - if (log.isDebugEnabled()) { - log.debug("Calling database to get activity count."); - } - int count = dmService.getActivityCountUpdatedAfter(timestamp); - if (log.isDebugEnabled()) { - log.debug("Activity count: " + count); + if (initiatedBy == null || initiatedBy.isEmpty()) { + activities = dmService.getActivitiesUpdatedAfter(timestamp, limit, offset); + + if (log.isDebugEnabled()) { + log.debug("Calling database to get activity count with timestamp."); + } + count = dmService.getActivityCountUpdatedAfter(timestamp); + if (log.isDebugEnabled()) { + log.debug("Activity count: " + count); + } + } else { + activities = dmService.getActivitiesUpdatedAfterByUser(timestamp, initiatedBy, limit, offset); + + if (log.isDebugEnabled()) { + log.debug("Calling database to get activity count with timestamp and user."); + } + count = dmService.getActivityCountUpdatedAfterByUser(timestamp, initiatedBy); + if (log.isDebugEnabled()) { + log.debug("Activity count: " + count); + } } + activityList.setList(activities); activityList.setCount(count); if (activities == null || activities.size() == 0) { if (isIfModifiedSinceSet) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index ac98ec15b7e..81442311420 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -21,7 +21,7 @@ device-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 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 6dc9d55305a..567cc1a1d68 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 @@ -22,6 +22,8 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; + import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import java.util.List; @@ -44,6 +46,10 @@ public interface OperationManager { Activity addOperation(Operation operation, List devices) throws OperationManagementException, InvalidDeviceException; + + void addOperationsForPolicyRevoke(Policy policy, List devices) throws OperationManagementException, + InvalidDeviceException; + /** * Method to retrieve the list of all operations to a device. * @@ -102,12 +108,16 @@ public interface OperationManager { int getTotalCountOfFilteredActivities(String operationCode) throws OperationManagementException; + List getActivitiesUpdatedAfterByUser(long timestamp, String user, int limit, int offset) throws OperationManagementException; + int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException; + int getActivityCountUpdatedAfterByUser(long timestamp, String user) throws OperationManagementException; + /** * retrive the push notification strategy. * @return NotificationStrategy */ NotificationStrategy getNotificationStrategy(); -} \ No newline at end of file +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 2ac107ef43b..5b7ce8b77c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 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 78d393b0487..88d5e291f3d 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 @@ -38,6 +38,8 @@ 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.common.operation.mgt.OperationManager; +import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; +import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; 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; @@ -64,13 +66,7 @@ import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerImpl; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * This class implements all the functionality exposed as part of the OperationManager. Any transaction initiated @@ -161,8 +157,8 @@ public class OperationManagerImpl implements OperationManager { List validDeviceIds = deviceValidationResult.getValidDeviceIDList(); if (validDeviceIds.size() > 0) { DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds); - List authorizedDeviceList = deviceAuthorizationResult.getValidDeviceIDList(); - if (authorizedDeviceList.size() <= 0) { + List authorizedDeviceIds = deviceAuthorizationResult.getValidDeviceIDList(); + if (authorizedDeviceIds.size() <= 0) { log.warn("User : " + getUser() + " is not authorized to perform operations on given device-list."); Activity activity = new Activity(); //Send the operation statuses only for admin triggered operations @@ -189,86 +185,71 @@ public class OperationManagerImpl implements OperationManager { OperationManagementDAOFactory.beginTransaction(); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = OperationDAOUtil.convertOperation(operation); + int enrolmentId; + String operationCode = operationDto.getCode(); + + List authorizedDevices = new ArrayList<>(); + List ignoredDevices = new ArrayList<>(); + for (DeviceIdentifier deviceId : authorizedDeviceIds) { + Device device = getDevice(deviceId); + authorizedDevices.add(device); + } + + if (operationDto.getControl() == + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) { + int existingOperationID; + for (Device device : authorizedDevices) { + enrolmentId = device.getEnrolmentInfo().getId(); + existingOperationID = operationDAO.getExistingOperationID(enrolmentId, operationCode); + if (existingOperationID > 0) { + ignoredDevices.add(device); + operation.setId(existingOperationID); + this.sendNotification(operation, device); + } + } + } + + if (ignoredDevices.size() > 0) { + if (authorizedDevices.size() == ignoredDevices.size()) { + if (log.isDebugEnabled()) { + log.debug("All the devices contain a pending operation for the Operation Code: " + + operationCode); + } + Activity activity = new Activity(); + //Send the operation statuses only for admin triggered operations + String deviceType = validDeviceIds.get(0).getType(); + activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult, + deviceType)); + return activity; + } else { + authorizedDevices.removeAll(ignoredDevices); + } + } + int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); - boolean isNotRepeated = false; + boolean isScheduled = false; NotificationStrategy notificationStrategy = getNotificationStrategy(); // check whether device list is greater than batch size notification strategy has enable to send push // notification using scheduler task if (DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). - getPushNotificationConfiguration().getSchedulerBatchSize() <= authorizedDeviceList.size() && + getPushNotificationConfiguration().getSchedulerBatchSize() <= authorizedDeviceIds.size() && notificationStrategy != null) { isScheduled = notificationStrategy.getConfig().isScheduled(); } - boolean hasExistingTaskOperation; - int enrolmentId; - List devices = new ArrayList<>(); - if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT == operationDto. - getControl()) { - isNotRepeated = true; - } - //TODO have to create a sql to load device details from deviceDAO using single query. - String operationCode = operationDto.getCode(); - for (DeviceIdentifier deviceId : authorizedDeviceList) { - Device device = getDevice(deviceId); - devices.add(device); + for (Device device : authorizedDevices) { enrolmentId = device.getEnrolmentInfo().getId(); //Do not repeat the task operations - if (isScheduledOperation) { - hasExistingTaskOperation = operationDAO.updateTaskOperation(enrolmentId, operationCode); - if (!hasExistingTaskOperation) { - operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled); - } - } else if (isNotRepeated) { - operationDAO.updateEnrollmentOperationsStatus(enrolmentId, operationCode, - org.wso2.carbon.device.mgt.core.dto.operation.mgt. - Operation.Status.PENDING, - org.wso2.carbon.device.mgt.core.dto.operation.mgt. - Operation.Status.REPEATED); - operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled); - } else { - operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled); - } + operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled); } OperationManagementDAOFactory.commitTransaction(); - /* - If notification strategy has not enable to send push notification using scheduler task we will send - notification immediately. This is done in separate loop inorder to prevent overlap with DB insert - operations with the possible db update operations trigger followed by pending operation call. - Otherwise device may call pending operation while DB is locked for write and deadlock can occur. - */ - if (notificationStrategy != null && !isScheduled) { - for (Device device : devices) { - DeviceIdentifier deviceId = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); - if (log.isDebugEnabled()) { - log.debug("Sending push notification to " + deviceId + " from add operation method."); - } - operation.setId(operationId); - operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); - try { - notificationStrategy.execute(new NotificationContext(deviceId, operation)); - } catch (PushNotificationExecutionFailedException e) { - log.error("Error occurred while sending push notifications to " + deviceId.getType() + - " device carrying id '" + deviceId + "'", e); - /* - Reschedule if push notification failed. Doing db transactions in atomic way to prevent - deadlocks. - */ - enrolmentId = device.getEnrolmentInfo().getId(); - try { - operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon - .device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED); - OperationManagementDAOFactory.commitTransaction(); - } catch (OperationManagementDAOException ex) { - // Not throwing this exception in order to keep sending remaining notifications if any. - log.error("Error occurred while setting push notification status to SCHEDULED.", ex); - OperationManagementDAOFactory.rollbackTransaction(); - } - } + if (isScheduled) { + for (Device device : authorizedDevices) { + this.sendNotification(operation, device); } } @@ -298,6 +279,195 @@ public class OperationManagerImpl implements OperationManager { } } + private Operation getPolicyRevokeOperation() { + CommandOperation policyRevokeOperation = new CommandOperation(); + policyRevokeOperation.setEnabled(true); + policyRevokeOperation.setCode(OperationMgtConstants.OperationCodes.POLICY_REVOKE); + policyRevokeOperation.setType(Operation.Type.COMMAND); + return policyRevokeOperation; + } + private Operation transformPolicy(Policy policy) { + List effectiveFeatures = policy.getProfile().getProfileFeaturesList(); + List profileOperationList = new ArrayList(); + PolicyOperation policyOperation = new PolicyOperation(); + policyOperation.setEnabled(true); + policyOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.POLICY); + policyOperation.setCode(PolicyOperation.POLICY_OPERATION_CODE); + for (ProfileFeature feature : effectiveFeatures) { + ProfileOperation profileOperation = new ProfileOperation(); + profileOperation.setCode(feature.getFeatureCode()); + profileOperation.setEnabled(true); + profileOperation.setStatus(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Status.PENDING); + profileOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.PROFILE); + profileOperation.setPayLoad(feature.getContent()); + profileOperationList.add(profileOperation); + } + policyOperation.setProfileOperations(profileOperationList); + policyOperation.setPayLoad(policyOperation.getProfileOperations()); + return policyOperation; + } + @Override + public void addOperationsForPolicyRevoke(Policy policy, List deviceIds) + throws OperationManagementException, InvalidDeviceException { + Operation revokeOperation = getPolicyRevokeOperation(); + Operation operation = transformPolicy(policy); + if (log.isDebugEnabled()) { + log.debug("operation:[" + operation.toString() + "]"); + for (DeviceIdentifier deviceIdentifier : deviceIds) { + log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + + deviceIdentifier.getType() + "]"); + } + } + try { + DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds); + List validDeviceIds = deviceValidationResult.getValidDeviceIDList(); + if (validDeviceIds.size() > 0) { + DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds); + List authorizedDeviceList = deviceAuthorizationResult.getValidDeviceIDList(); + OperationManagementDAOFactory.beginTransaction(); + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation policyOperationDto = + OperationDAOUtil.convertOperation(operation); + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation revokeOperationDto = + OperationDAOUtil.convertOperation(revokeOperation); + boolean isScheduledOperation = this.isTaskScheduledOperation(operation); + boolean isNotRepeated = false; + boolean isScheduled = false; + NotificationStrategy notificationStrategy = getNotificationStrategy(); + // check whether device list is greater than batch size notification strategy has enable to send push + // notification using scheduler task + if (DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). + getPushNotificationConfiguration().getSchedulerBatchSize() <= authorizedDeviceList.size() && + notificationStrategy != null) { + isScheduled = notificationStrategy.getConfig().isScheduled(); + } + List operationList = new LinkedList(); + operationList.add(revokeOperationDto); + operationList.add(policyOperationDto); + List operationIds = this.lookupOperationDAO(operation).addOperations(operationList); + List devices = new ArrayList<>(); + if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT == policyOperationDto. + getControl()) { + isNotRepeated = true; + } + //Need to happen for both revoke and new policy operation + addOperationMappings(authorizedDeviceList, revokeOperationDto, operationIds.get(0), isScheduledOperation, + isNotRepeated, isScheduled, devices); + sendPushNotifications(revokeOperation, operationIds.get(0), isScheduled, notificationStrategy, devices); + //Need to happen for both revoke and new policy operation + addOperationMappings(authorizedDeviceList, policyOperationDto, operationIds.get(1), isScheduledOperation, + isNotRepeated, isScheduled, devices); + sendPushNotifications(operation, operationIds.get(1), isScheduled, notificationStrategy, devices); + OperationManagementDAOFactory.commitTransaction(); + } else { + throw new InvalidDeviceException("Invalid device Identifiers found."); + } + } catch (OperationManagementDAOException e) { + OperationManagementDAOFactory.rollbackTransaction(); + throw new OperationManagementException("Error occurred while adding operation", e); + } catch (TransactionManagementException e) { + throw new OperationManagementException("Error occurred while initiating the transaction", e); + } finally { + OperationManagementDAOFactory.closeConnection(); + } + } + private String addOperationMappings(List authorizedDeviceList, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto, int operationId, boolean isScheduledOperation, boolean isNotRepeated, boolean isScheduled, List devices) throws OperationManagementException, OperationManagementDAOException { + int enrolmentId; + int existingTaskOperationId;//TODO have to create a sql to load device details from deviceDAO using single query. + String operationCode = operationDto.getCode(); + for (DeviceIdentifier deviceId : authorizedDeviceList) { + Device device = getDevice(deviceId); + devices.add(device); + enrolmentId = device.getEnrolmentInfo().getId(); + //Do not repeat the task operations + if (isScheduledOperation) { + existingTaskOperationId = operationDAO.getExistingOperationID(enrolmentId, operationCode); + if (existingTaskOperationId != -1) { + operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled); + } + } else if (isNotRepeated) { + operationDAO.updateEnrollmentOperationsStatus(enrolmentId, operationCode, + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING, + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.REPEATED); + operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled); + } else { + operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled); + } + } + return operationCode; + } + /* + * If notification strategy has not enable to send push notification using scheduler task we will send + * notification immediately. This is done in separate loop inorder to prevent overlap with DB insert + * operations with the possible db update operations trigger followed by pending operation call. + * Otherwise device may call pending operation while DB is locked for write and deadlock can occur. + */ + private void sendPushNotifications(Operation operation, int operationId, boolean isScheduled, NotificationStrategy notificationStrategy, List devices) { + int enrolmentId; + if (notificationStrategy != null && !isScheduled) { + for (Device device : devices) { + DeviceIdentifier deviceId = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); + if (log.isDebugEnabled()) { + log.debug("Sending push notification to " + deviceId + " from add operation method."); + } + operation.setId(operationId); + operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); + try { + notificationStrategy.execute(new NotificationContext(deviceId, operation)); + } catch (PushNotificationExecutionFailedException e) { + log.error("Error occurred while sending push notifications to " + deviceId.getType() + + " device carrying id '" + deviceId + "'", e); + /* + Reschedule if push notification failed. Doing db transactions in atomic way to prevent + deadlocks. + */ + enrolmentId = device.getEnrolmentInfo().getId(); + try { + operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon + .device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED); + } catch (OperationManagementDAOException ex) { + // Not throwing this exception in order to keep sending remaining notifications if any. + log.error("Error occurred while setting push notification status to SCHEDULED.", ex); + } + } + } + } + } + + private void sendNotification(Operation operation, Device device) { + NotificationStrategy notificationStrategy = getNotificationStrategy(); + /* + * If notification strategy has not enable to send push notification using scheduler task we will send + * notification immediately. This is done in separate loop inorder to prevent overlap with DB insert + * operations with the possible db update operations trigger followed by pending operation call. + * Otherwise device may call pending operation while DB is locked for write and deadlock can occur. + */ + if (notificationStrategy != null) { + if (log.isDebugEnabled()) { + log.debug("Sending push notification to " + device.getDeviceIdentifier() + " from add operation method."); + } + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); + try { + notificationStrategy.execute(new NotificationContext(deviceIdentifier, operation)); + } catch (PushNotificationExecutionFailedException e) { + log.error("Error occurred while sending push notifications to " + device.getType() + + " device carrying id '" + device.getDeviceIdentifier() + "'", e); + /* + * Reschedule if push notification failed. Doing db transactions in atomic way to prevent + * deadlocks. + */ + try { + operationMappingDAO.updateOperationMapping(operation.getId(), device.getEnrolmentInfo().getId(), org.wso2.carbon + .device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED); + OperationManagementDAOFactory.commitTransaction(); + } catch (OperationManagementDAOException ex) { + // Not throwing this exception in order to keep sending remaining notifications if any. + log.error("Error occurred while setting push notification status to SCHEDULED.", ex); + OperationManagementDAOFactory.rollbackTransaction(); + } + } + } + } + private List getActivityStatus(DeviceIDHolder deviceIdValidationResult, DeviceIDHolder deviceAuthResult, String deviceType) { List activityStatuses = new ArrayList<>(); @@ -906,6 +1076,22 @@ public class OperationManagerImpl implements OperationManager { } } + @Override + public List getActivitiesUpdatedAfterByUser(long timestamp, String user, int limit, int offset) + throws OperationManagementException { + try { + OperationManagementDAOFactory.openConnection(); + return operationDAO.getActivitiesUpdatedAfterByUser(timestamp, user, limit, offset); + } catch (SQLException e) { + throw new OperationManagementException("Error occurred while opening a connection to the data source.", e); + } catch (OperationManagementDAOException e) { + throw new OperationManagementException("Error occurred while getting the activity list changed after a " + + "given time which are added by user : " + user, e); + } finally { + OperationManagementDAOFactory.closeConnection(); + } + } + @Override public int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException { try { @@ -921,6 +1107,21 @@ public class OperationManagerImpl implements OperationManager { } } + @Override + public int getActivityCountUpdatedAfterByUser(long timestamp, String user) throws OperationManagementException { + try { + OperationManagementDAOFactory.openConnection(); + return operationDAO.getActivityCountUpdatedAfterByUser(timestamp, user); + } catch (SQLException e) { + throw new OperationManagementException("Error occurred while opening a connection to the data source.", e); + } catch (OperationManagementDAOException e) { + throw new OperationManagementException("Error occurred while getting the activity count changed after a " + + "given time which are added by user :" + user, e); + } finally { + OperationManagementDAOFactory.closeConnection(); + } + } + private OperationDAO lookupOperationDAO(Operation operation) { if (operation instanceof CommandOperation) { @@ -1065,4 +1266,4 @@ public class OperationManagerImpl implements OperationManager { private boolean isSameUser(String user, String owner) { return user.equalsIgnoreCase(owner); } -} \ No newline at end of file +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index 908068b394c..a40c0c5e8f4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -30,6 +30,8 @@ public interface OperationDAO { int addOperation(Operation operation) throws OperationManagementDAOException; + List addOperations(List operations) throws OperationManagementDAOException; + Operation getOperation(int operationId) throws OperationManagementDAOException; Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException; @@ -54,7 +56,7 @@ public interface OperationDAO { void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus, Operation.Status newStatus) throws OperationManagementDAOException; - boolean updateTaskOperation(int enrolmentId, String operationCode) throws OperationManagementDAOException; + int getExistingOperationID(int enrolmentId, String operationCode) throws OperationManagementDAOException; void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) throws OperationManagementDAOException; @@ -71,8 +73,12 @@ public interface OperationDAO { int getTotalCountOfFilteredActivities(String operationCode) throws OperationManagementDAOException; + List getActivitiesUpdatedAfterByUser(long timestamp, String user, int limit, int offset) throws OperationManagementDAOException; + int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementDAOException; + int getActivityCountUpdatedAfterByUser(long timestamp, String user) throws OperationManagementDAOException; + /** * This method provides operation mappings for given status * @param opStatus Operation status @@ -84,4 +90,4 @@ public interface OperationDAO { Map> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushNotificationStatus pushNotificationStatus, int limit) throws OperationManagementDAOException; -} \ No newline at end of file +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 0078ce11d7f..3ea9ba1f5e5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -86,6 +86,37 @@ public class GenericOperationDAOImpl implements OperationDAO { } } + //This implementation has been done this way due to H2 not supporting batch inserts properly. + //Even though records are added in batch mode, only the id of the last added record will be returned, which is a problem. + public List addOperations(List operations) throws OperationManagementDAOException { + List ids = new LinkedList(); + for (Operation operation : operations) { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection connection = OperationManagementDAOFactory.getConnection(); + String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE) " + + "VALUES (?, ?, ?, ?)"; + stmt = connection.prepareStatement(sql, new String[]{"id"}); + stmt.setString(1, operation.getType().toString()); + stmt.setTimestamp(2, new Timestamp(new Date().getTime())); + stmt.setTimestamp(3, null); + stmt.setString(4, operation.getCode()); + stmt.executeUpdate(); + rs = stmt.getGeneratedKeys(); + int id = -1; + if (rs.next()) { + ids.add(rs.getInt(1)); + } + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + } + return ids; + } + public boolean updateOperationStatus(int enrolmentId, int operationId, Operation.Status status) throws OperationManagementDAOException { PreparedStatement stmt = null; @@ -150,14 +181,14 @@ public class GenericOperationDAOImpl implements OperationDAO { } @Override - public boolean updateTaskOperation(int enrolmentId, String operationCode) + public int getExistingOperationID(int enrolmentId, String operationCode) throws OperationManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; - boolean result = false; + int result = -1; try { Connection connection = OperationManagementDAOFactory.getConnection(); - String query = "SELECT EOM.ID FROM DM_ENROLMENT_OP_MAPPING EOM INNER JOIN DM_OPERATION DM " + String query = "SELECT DM.ID FROM DM_ENROLMENT_OP_MAPPING EOM INNER JOIN DM_OPERATION DM " + "ON DM.ID = EOM.OPERATION_ID WHERE EOM.ENROLMENT_ID = ? AND DM.OPERATION_CODE = ? AND " + "EOM.STATUS = ?"; stmt = connection.prepareStatement(query); @@ -167,7 +198,7 @@ public class GenericOperationDAOImpl implements OperationDAO { // This will return only one result always. rs = stmt.executeQuery(); if (rs.next()) { - result = true; + result = rs.getInt("ID"); } } catch (SQLException e) { throw new OperationManagementDAOException( @@ -705,6 +736,171 @@ public class GenericOperationDAOImpl implements OperationDAO { return 0; } + @Override + public List getActivitiesUpdatedAfterByUser(long timestamp, String user, int limit, int offset) + throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + List activities = new ArrayList<>(); + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + String sql = "SELECT " + + " opr.ENROLMENT_ID, " + + " opr.CREATED_TIMESTAMP, " + + " opr.UPDATED_TIMESTAMP, " + + " opr.OPERATION_ID, " + + " opr.OPERATION_CODE, " + + " opr.OPERATION_TYPE, " + + " opr.STATUS, " + + " opr.DEVICE_ID, " + + " opr.DEVICE_IDENTIFICATION, " + + " opr.DEVICE_TYPE, " + + " ops.RECEIVED_TIMESTAMP, " + + " ops.ID OP_RES_ID, " + + " ops.OPERATION_RESPONSE , " + + " opr.INITIATED_BY " + + " FROM " + + " (SELECT " + + " opm.ID MAPPING_ID, " + + " opm.ENROLMENT_ID, " + + " opm.CREATED_TIMESTAMP, " + + " opm.UPDATED_TIMESTAMP, " + + " opm.OPERATION_ID, " + + " op.OPERATION_CODE, " + + " op.INITIATED_BY, " + + " op.TYPE OPERATION_TYPE, " + + " opm.STATUS, " + + " en.DEVICE_ID, " + + " de.DEVICE_IDENTIFICATION, " + + " dt.NAME DEVICE_TYPE, " + + " de.TENANT_ID " + + " FROM" + + " DM_ENROLMENT_OP_MAPPING opm " + + " INNER JOIN DM_OPERATION op ON opm.OPERATION_ID = op.ID " + + " INNER JOIN DM_ENROLMENT en ON opm.ENROLMENT_ID = en.ID " + + " INNER JOIN DM_DEVICE de ON en.DEVICE_ID = de.ID " + + " INNER JOIN DM_DEVICE_TYPE dt ON dt.ID = de.DEVICE_TYPE_ID " + + " WHERE " + + " opm.UPDATED_TIMESTAMP > ? AND op.INITIATED_BY = ?" + + " AND de.TENANT_ID = ? " + + " ORDER BY opm.UPDATED_TIMESTAMP " + + " LIMIT ? OFFSET ?) opr " + + " LEFT JOIN DM_DEVICE_OPERATION_RESPONSE ops ON opr.MAPPING_ID = ops.EN_OP_MAP_ID " + + " WHERE " + + " opr.UPDATED_TIMESTAMP > ? AND opr.INITIATED_BY = ?" + + " AND opr.TENANT_ID = ? "; + + stmt = conn.prepareStatement(sql); + + stmt.setLong(1, timestamp); + stmt.setString(2, user); + stmt.setInt(3, tenantId); + stmt.setInt(4, limit); + stmt.setInt(5, offset); + stmt.setLong(6, timestamp); + stmt.setString(7, user); + stmt.setInt(8, tenantId); + + rs = stmt.executeQuery(); + + int operationId = 0; + int enrolmentId = 0; + int responseId = 0; + Activity activity = null; + ActivityStatus activityStatus = null; + while (rs.next()) { + + if (operationId != rs.getInt("OPERATION_ID")) { + activity = new Activity(); + activities.add(activity); + List statusList = new ArrayList<>(); + activityStatus = new ActivityStatus(); + + operationId = rs.getInt("OPERATION_ID"); + enrolmentId = rs.getInt("ENROLMENT_ID"); + + activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); + activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + activity.setCode(rs.getString("OPERATION_CODE")); + activity.setInitiatedBy(rs.getString("INITIATED_BY")); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + deviceIdentifier.setType(rs.getString("DEVICE_TYPE")); + activityStatus.setDeviceIdentifier(deviceIdentifier); + + activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS"))); + + List operationResponses = new ArrayList<>(); + if (rs.getInt("UPDATED_TIMESTAMP") != 0) { + activityStatus.setUpdatedTimestamp(new java.util.Date( + rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + + } + if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) { + operationResponses.add(OperationDAOUtil.getOperationResponse(rs)); + responseId = rs.getInt("OP_RES_ID"); + } + activityStatus.setResponses(operationResponses); + statusList.add(activityStatus); + activity.setActivityStatus(statusList); + activity.setActivityId(OperationDAOUtil.getActivityId(rs.getInt("OPERATION_ID"))); + + } + + if (operationId == rs.getInt("OPERATION_ID") && enrolmentId != rs.getInt("ENROLMENT_ID")) { + activityStatus = new ActivityStatus(); + + activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); + activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + activity.setCode(rs.getString("OPERATION_CODE")); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + deviceIdentifier.setType(rs.getString("DEVICE_TYPE")); + activityStatus.setDeviceIdentifier(deviceIdentifier); + + activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS"))); + + List operationResponses = new ArrayList<>(); + if (rs.getInt("UPDATED_TIMESTAMP") != 0) { + activityStatus.setUpdatedTimestamp(new java.util.Date( + rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + } + if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) { + operationResponses.add(OperationDAOUtil.getOperationResponse(rs)); + responseId = rs.getInt("OP_RES_ID"); + } + activityStatus.setResponses(operationResponses); + activity.getActivityStatus().add(activityStatus); + + enrolmentId = rs.getInt("ENROLMENT_ID"); + } + + if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) { + if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) { + activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs)); + responseId = rs.getInt("OP_RES_ID"); + } + } + } + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while getting the operation details from " + + "the database.", e); + } catch (ClassNotFoundException e) { + throw new OperationManagementDAOException("Error occurred while converting the operation response to string.", e); + } catch (IOException e) { + throw new OperationManagementDAOException("IO exception occurred while converting the operations responses.", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + + return activities; + + } + @Override public List getActivitiesUpdatedAfter(long timestamp, int limit, @@ -888,6 +1084,40 @@ public class GenericOperationDAOImpl implements OperationDAO { return 0; } + @Override + public int getActivityCountUpdatedAfterByUser(long timestamp, String user) throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + String sql = "SELECT \n" + + " COUNT(*) AS COUNT\n" + + "FROM\n" + + " DM_ENROLMENT_OP_MAPPING AS m\n" + + " INNER JOIN\n" + + " DM_ENROLMENT AS d ON m.ENROLMENT_ID = d.ID\n" + + " INNER JOIN \n" + + " DM_OPERATION dp ON dp.ID = m.OPERATION_ID \n" + + "WHERE\n" + + " m.UPDATED_TIMESTAMP > ? AND dp.INITIATED_BY = ?\n" + + " AND d.TENANT_ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setLong(1, timestamp); + stmt.setString(2, user); + stmt.setInt(3, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + rs = stmt.executeQuery(); + if (rs.next()) { + return rs.getInt("COUNT"); + } + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while getting the activity count from " + + "the database.", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + return 0; + } + @Override public Operation getOperation(int id) throws OperationManagementDAOException { PreparedStatement stmt = null; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java index 7f142b7d04c..15bf7cbe65d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; @@ -46,7 +47,6 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl { operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setId(operationId); operation.setEnabled(true); - PolicyOperation policyOperation = (PolicyOperation) operation; Connection conn = OperationManagementDAOFactory.getConnection(); stmt = conn.prepareStatement("INSERT INTO DM_POLICY_OPERATION(OPERATION_ID, OPERATION_DETAILS) " + "VALUES(?, ?)"); @@ -82,6 +82,79 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl { return operationId; } + + private int addCommandOperation(int operationId, Operation operation) throws OperationManagementDAOException { + CommandOperation commandOp = (CommandOperation) operation; + PreparedStatement stmt = null; + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + stmt = conn.prepareStatement("INSERT INTO DM_COMMAND_OPERATION(OPERATION_ID, ENABLED) VALUES(?, ?)"); + stmt.setInt(1, operationId); + stmt.setBoolean(2, commandOp.isEnabled()); + stmt.executeUpdate(); + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while adding command operation", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt); + } + return operationId; + } + @Override + public List addOperations(List operations) throws OperationManagementDAOException { + List operationIds; + int counter = 0; + operationIds = super.addOperations(operations); + for(Operation operation : operations) { + if(operation.getType().equals(Operation.Type.COMMAND)){ + addCommandOperation(operationIds.get(counter), operation); + } else if(operation.getType().equals(Operation.Type.POLICY)){ + addPolicyOperation(operationIds.get(counter), operation); + } + counter++; + } + return operationIds; + } + private void addPolicyOperation(int operationId, Operation operation) throws OperationManagementDAOException { + PreparedStatement stmt = null; + ByteArrayOutputStream bao = null; + ObjectOutputStream oos = null; + try { + operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); + operation.setId(operationId); + operation.setEnabled(true); + Connection conn = OperationManagementDAOFactory.getConnection(); + stmt = conn.prepareStatement("INSERT INTO DM_POLICY_OPERATION(OPERATION_ID, OPERATION_DETAILS) " + + "VALUES(?, ?)"); + bao = new ByteArrayOutputStream(); + oos = new ObjectOutputStream(bao); + oos.writeObject(operation); + stmt.setInt(1, operationId); + stmt.setBytes(2, bao.toByteArray()); + stmt.executeUpdate(); + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while adding policy operation", e); + } catch (IOException e) { + throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e); + } finally { + if (bao != null) { + try { + bao.close(); + } catch (IOException e) { + log.warn("Error occurred while closing ByteArrayOutputStream", e); + } + } + if (oos != null) { + try { + oos.close(); + } catch (IOException e) { + log.warn("Error occurred while closing ObjectOutputStream", e); + } + } + OperationManagementDAOUtil.cleanupResources(stmt); + } + } + + @Override public Operation getOperation(int operationId) throws OperationManagementDAOException { PreparedStatement stmt = null; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/MySQLOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/MySQLOperationDAOImpl.java index 23377c695cf..0aa25c8c84b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/MySQLOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/MySQLOperationDAOImpl.java @@ -375,6 +375,170 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl { return activities; } + @Override + public List getActivitiesUpdatedAfterByUser(long timestamp, String user, int limit, int offset) + throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + List activities = new ArrayList<>(); + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + String sql = "SELECT " + + " opr.ENROLMENT_ID, " + + " opr.CREATED_TIMESTAMP, " + + " opr.UPDATED_TIMESTAMP, " + + " opr.OPERATION_ID, " + + " opr.OPERATION_CODE, " + + " opr.INITIATED_BY, " + + " opr.OPERATION_TYPE, " + + " opr.STATUS, " + + " opr.DEVICE_ID, " + + " opr.DEVICE_IDENTIFICATION, " + + " opr.DEVICE_TYPE, " + + " ops.RECEIVED_TIMESTAMP, " + + " ops.ID OP_RES_ID, " + + " ops.OPERATION_RESPONSE " + + " FROM " + + " (SELECT " + + " opm.ID MAPPING_ID, " + + " opm.ENROLMENT_ID, " + + " opm.CREATED_TIMESTAMP, " + + " opm.UPDATED_TIMESTAMP, " + + " opm.OPERATION_ID, " + + " op.OPERATION_CODE, " + + " op.INITIATED_BY, " + + " op.TYPE OPERATION_TYPE, " + + " opm.STATUS, " + + " en.DEVICE_ID, " + + " de.DEVICE_IDENTIFICATION, " + + " dt.NAME DEVICE_TYPE, " + + " de.TENANT_ID " + + " FROM" + + " DM_ENROLMENT_OP_MAPPING opm FORCE INDEX (IDX_ENROLMENT_OP_MAPPING) " + + " INNER JOIN DM_OPERATION op ON opm.OPERATION_ID = op.ID " + + " INNER JOIN DM_ENROLMENT en ON opm.ENROLMENT_ID = en.ID " + + " INNER JOIN DM_DEVICE de ON en.DEVICE_ID = de.ID " + + " INNER JOIN DM_DEVICE_TYPE dt ON dt.ID = de.DEVICE_TYPE_ID " + + " WHERE" + + " opm.UPDATED_TIMESTAMP > ? AND op.INITIATED_BY = ?" + + " AND de.TENANT_ID = ? " + + " ORDER BY opm.UPDATED_TIMESTAMP " + + " LIMIT ? OFFSET ?) opr " + + " LEFT JOIN DM_DEVICE_OPERATION_RESPONSE ops ON opr.MAPPING_ID = ops.EN_OP_MAP_ID " + + " WHERE " + + " opr.UPDATED_TIMESTAMP > ? AND opr.INITIATED_BY = ? " + + " AND opr.TENANT_ID = ? "; + + stmt = conn.prepareStatement(sql); + + stmt.setLong(1, timestamp); + stmt.setString(2, user); + stmt.setInt(3, tenantId); + stmt.setInt(4, limit); + stmt.setInt(5, offset); + stmt.setLong(6, timestamp); + stmt.setString(7, user); + stmt.setInt(8, tenantId); + + rs = stmt.executeQuery(); + + int operationId = 0; + int enrolmentId = 0; + int responseId = 0; + Activity activity = null; + ActivityStatus activityStatus = null; + while (rs.next()) { + + if (operationId != rs.getInt("OPERATION_ID")) { + activity = new Activity(); + activities.add(activity); + List statusList = new ArrayList<>(); + activityStatus = new ActivityStatus(); + + operationId = rs.getInt("OPERATION_ID"); + enrolmentId = rs.getInt("ENROLMENT_ID"); + + activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); + activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + activity.setCode(rs.getString("OPERATION_CODE")); + activity.setInitiatedBy(rs.getString("INITIATED_BY")); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + deviceIdentifier.setType(rs.getString("DEVICE_TYPE")); + activityStatus.setDeviceIdentifier(deviceIdentifier); + + activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS"))); + + List operationResponses = new ArrayList<>(); + if (rs.getInt("UPDATED_TIMESTAMP") != 0) { + activityStatus.setUpdatedTimestamp(new java.util.Date( + rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + + } + if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) { + operationResponses.add(OperationDAOUtil.getOperationResponse(rs)); + responseId = rs.getInt("OP_RES_ID"); + } + activityStatus.setResponses(operationResponses); + statusList.add(activityStatus); + activity.setActivityStatus(statusList); + activity.setActivityId(OperationDAOUtil.getActivityId(rs.getInt("OPERATION_ID"))); + + } + + if (operationId == rs.getInt("OPERATION_ID") && enrolmentId != rs.getInt("ENROLMENT_ID")) { + activityStatus = new ActivityStatus(); + + activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); + activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + activity.setCode(rs.getString("OPERATION_CODE")); + activity.setInitiatedBy(rs.getString("INITIATED_BY")); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + deviceIdentifier.setType(rs.getString("DEVICE_TYPE")); + activityStatus.setDeviceIdentifier(deviceIdentifier); + + activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS"))); + + List operationResponses = new ArrayList<>(); + if (rs.getInt("UPDATED_TIMESTAMP") != 0) { + activityStatus.setUpdatedTimestamp(new java.util.Date( + rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + } + if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) { + operationResponses.add(OperationDAOUtil.getOperationResponse(rs)); + responseId = rs.getInt("OP_RES_ID"); + } + activityStatus.setResponses(operationResponses); + activity.getActivityStatus().add(activityStatus); + + enrolmentId = rs.getInt("ENROLMENT_ID"); + } + + if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) { + if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) { + activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs)); + responseId = rs.getInt("OP_RES_ID"); + } + } + } + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while getting the operation details from " + + "the database.", e); + } catch (ClassNotFoundException e) { + throw new OperationManagementDAOException("Error occurred while converting the operation response to string.", e); + } catch (IOException e) { + throw new OperationManagementDAOException("IO exception occurred while converting the operations responses.", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + return activities; + } + private Integer[] getIntArrayOfActivityIds(List activityIds) { Integer[] arr = new Integer[activityIds.size()]; int x = 0; 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 96967441d0e..4c27f08efd1 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 @@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.common.license.mgt.License; 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; +import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; @@ -542,6 +543,10 @@ public interface DeviceManagementProviderService { Activity addOperation(String type, Operation operation, List devices) throws OperationManagementException, InvalidDeviceException; + void addPolicyOperations(String type, Policy policy, + List devices) throws OperationManagementException, InvalidDeviceException; + + List getOperations(DeviceIdentifier deviceId) throws OperationManagementException; PaginationResult getOperations(DeviceIdentifier deviceId, @@ -577,8 +582,12 @@ public interface DeviceManagementProviderService { int getTotalCountOfFilteredActivities(String operationCode) throws OperationManagementException; + List getActivitiesUpdatedAfterByUser(long timestamp, String user, int limit, int offset) throws OperationManagementException; + int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException; + int getActivityCountUpdatedAfterByUser(long timestamp, String user) throws OperationManagementException; + List getMonitoringOperationList(String deviceType); int getDeviceMonitoringFrequency(String deviceType); 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 b9e309b54b2..d5170a620d2 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 @@ -58,6 +58,7 @@ 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; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; +import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; @@ -1430,6 +1431,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return pluginRepository.getOperationManager(type, this.getTenantId()).addOperation(operation, devices); } + @Override + public void addPolicyOperations(String type, Policy policy, + List devices) throws OperationManagementException, InvalidDeviceException { + pluginRepository.getOperationManager(type, this.getTenantId()).addOperationsForPolicyRevoke(policy, devices); + } + @Override public List getOperations(DeviceIdentifier deviceId) throws OperationManagementException { return pluginRepository.getOperationManager(deviceId.getType(), this.getTenantId()).getOperations(deviceId); @@ -1563,11 +1570,22 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return DeviceManagementDataHolder.getInstance().getOperationManager().getTotalCountOfFilteredActivities(operationCode); } + @Override + public List getActivitiesUpdatedAfterByUser(long timestamp, String user, int limit, int offset) throws OperationManagementException { + limit = DeviceManagerUtil.validateActivityListPageSize(limit); + return DeviceManagementDataHolder.getInstance().getOperationManager().getActivitiesUpdatedAfterByUser(timestamp, user, limit, offset); + } + @Override public int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException { return DeviceManagementDataHolder.getInstance().getOperationManager().getActivityCountUpdatedAfter(timestamp); } + @Override + public int getActivityCountUpdatedAfterByUser(long timestamp, String user) throws OperationManagementException { + return DeviceManagementDataHolder.getInstance().getOperationManager().getActivityCountUpdatedAfterByUser(timestamp, user); + } + @Override public List getMonitoringOperationList(String deviceType) { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index eab1586373f..2d2c40b3b48 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml index 136d8c91f9f..8aec5fcc0da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index 6a59e99d0fa..406dde9f3a0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -5,8 +5,8 @@ "managerHTTPSURL": "https://%iot.manager.host%:%iot.manager.https.port%", "httpsURL": "https://%iot.gateway.host%:%iot.gateway.https.port%", "httpURL": "http://%iot.gateway.host%:%iot.gateway.http.port%", - "wssURL": "https://%iot.analytics.host%:%iot.analytics.https.port%", - "remoteSessionWSURL": "https://%iot.core.host%:%iot.core.https.port%", + "wssURL": "https://%iot.core.host%:%iot.core.https.port%", + "remoteSessionWSURL": "https://%iot.manager.host%:%iot.manager.https.port%", "portalURL": "https://%iot.analytics.host%:%iot.analytics.https.port%", "dashboardServerURL": "%https.ip%", "androidAgentDownloadURL": "%https.ip%/devicemgt/public/cdmf.unit.device.type.android.type-view/assets/android-agent.apk", @@ -56,7 +56,7 @@ "roleNameHelpMsg": "should be in minimum 3 characters long and do not include any whitespaces." }, "generalConfig": { - "host": "%http.ip%", + "host": "https://%iot.manager.host%:%iot.manager.https.port%", "companyName": "WSO2 Carbon Device Manager", "browserTitle": "WSO2 Device Manager", "copyrightPrefix": "\u00A9 %date-year%, ", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.js index cfefa850e02..a13b87502f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.js @@ -43,14 +43,14 @@ function onRequest(context) { if (tokenPair) { token = tokenPair.accessToken; } - websocketEndpoint = websocketEndpoint + "/secured-websocket/iot.per.device.stream." + tenantDomain + "." + device.type + "/1.0.0?" + websocketEndpoint = websocketEndpoint + "/secured-websocket-proxy/secured-websocket/iot.per.device.stream." + tenantDomain + "." + device.type + "/1.0.0?" + "deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type + "&websocketToken=" + token; } else { var tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username + "@" + tenantDomain,"default", {}); if (tokenPair) { token = tokenPair.accessToken; } - websocketEndpoint = websocketEndpoint + "/secured-websocket" + "/t/" + tenantDomain + "/iot.per.device.stream." + tenantDomain + websocketEndpoint = websocketEndpoint + "/secured-websocket-proxy/secured-websocket/t/" + tenantDomain + "/iot.per.device.stream." + tenantDomain + "." + device.type + "/1.0.0?" + "deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type + "&websocketToken=" + token; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.footer/footer.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.footer/footer.hbs index 2a6e296cc4b..5dc662d3dbb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.footer/footer.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.footer/footer.hbs @@ -17,8 +17,8 @@ }} {{#zone "footer"}}

- - WSO2 IoT Server{{#unless isCloud}} 3.2.0{{/unless}} | © , + + WSO2 IoT Server{{#unless isCloud}} 3.3.1{{/unless}} | © , Inc. All Rights Reserved.

{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.js index de15fc40e46..b44eb2be496 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.js @@ -37,14 +37,14 @@ function onRequest(context) { tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username,"default", {}); if (tokenPair) { token = tokenPair.accessToken; - wsEndpoint = devicemgtProps["wssURL"].replace("https", "wss") + "/secured-websocket/"; + wsEndpoint = devicemgtProps["wssURL"].replace("https", "wss") + "/secured-websocket-proxy/secured-websocket/"; } } else { tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username + "@" + context.user.domain, "default", {}); if (tokenPair) { token = tokenPair.accessToken; - wsEndpoint = devicemgtProps["wssURL"].replace("https", "wss") + "/secured-websocket/t/" + + wsEndpoint = devicemgtProps["wssURL"].replace("https", "wss") + "/secured-websocket-proxy/secured-websocket/t/" + context.user.domain + "/"; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/application_options.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/application_options.js index cd1915e67a9..8b18b96158b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/application_options.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/application_options.js @@ -32,7 +32,7 @@ var ApplicationOptions = { CEP_WEB_SOCKET_OUTPUT_ADAPTOR_NAME: 'iot.per.device.stream.geo.FusedSpatialEvent', CEP_ON_ALERT_WEB_SOCKET_OUTPUT_ADAPTOR_NAME: 'org.wso2.geo.AlertsNotifications', CEP_Traffic_STREAM_WEB_SOCKET_OUTPUT_ADAPTOR_NAME: 'DefaultWebsocketOutputAdaptorOnTrafficStream', - CEP_WEB_SOCKET_OUTPUT_ADAPTOR_WEBAPP_NAME: 'secured-websocket', + CEP_WEB_SOCKET_OUTPUT_ADAPTOR_WEBAPP_NAME: 'secured-websocket-proxy', TENANT_INDEX: 't', COLON : ':', PATH_SEPARATOR : '/', diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/geo-devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/geo-devices.js index eddb14ea91b..9db76cedadf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/geo-devices.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/geo-devices.js @@ -38,13 +38,13 @@ function onRequest(context) { tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username,"default", {}); if (tokenPair) { token = tokenPair.accessToken; - wsEndpoint = devicemgtProps["wssURL"].replace("https", "wss") + "/secured-websocket/"; + wsEndpoint = devicemgtProps["wssURL"].replace("https", "wss") + "/secured-websocket-proxy/secured-websocket/"; } } else { tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username + "@" + context.user.domain,"default", {}); if (tokenPair) { token = tokenPair.accessToken; - wsEndpoint = devicemgtProps["wssURL"].replace("https", "wss") + "/secured-websocket/t/"+context.user.domain+"/"; + wsEndpoint = devicemgtProps["wssURL"].replace("https", "wss") + "/secured-websocket-proxy/secured-websocket/t/"+context.user.domain+"/"; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/public/js/application_options.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/public/js/application_options.js index 2ca6536b452..bba55e27002 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/public/js/application_options.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/public/js/application_options.js @@ -32,7 +32,7 @@ var ApplicationOptions = { CEP_WEB_SOCKET_OUTPUT_ADAPTOR_NAME: 'iot.per.device.stream.geo.FusedSpatialEvent', CEP_ON_ALERT_WEB_SOCKET_OUTPUT_ADAPTOR_NAME: 'org.wso2.geo.AlertsNotifications', CEP_Traffic_STREAM_WEB_SOCKET_OUTPUT_ADAPTOR_NAME: 'DefaultWebsocketOutputAdaptorOnTrafficStream', - CEP_WEB_SOCKET_OUTPUT_ADAPTOR_WEBAPP_NAME: 'secured-websocket', + CEP_WEB_SOCKET_OUTPUT_ADAPTOR_WEBAPP_NAME: 'secured-websocket-proxy', TENANT_INDEX: 't', COLON : ':', PATH_SEPARATOR : '/', diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.footer/footer.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.footer/footer.hbs index a5127d5622f..f981d80ffc7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.footer/footer.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.footer/footer.hbs @@ -17,8 +17,8 @@ }} {{#zone "footer"}}

- - WSO2 IoT Server 3.2.0 | © , + + WSO2 IoT Server 3.3.1 | © , Inc. All Rights Reserved.

{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml index bd7ff13ac44..efce704909b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml @@ -23,7 +23,7 @@ device-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/pom.xml index 5b18baf745f..4db9aba1092 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml index 7ec456690fa..956cecaab09 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml @@ -41,6 +41,7 @@ org.wso2.carbon.device.mgt.v09.api org.wso2.carbon.device.mgt.analytics.data.publisher org.wso2.carbon.device.mgt.url.printer + org.wso2.carbon.device.mgt.analytics.wsproxy diff --git a/components/email-sender/org.wso2.carbon.email.sender.core/pom.xml b/components/email-sender/org.wso2.carbon.email.sender.core/pom.xml index 165a0031361..6b0cf581e56 100644 --- a/components/email-sender/org.wso2.carbon.email.sender.core/pom.xml +++ b/components/email-sender/org.wso2.carbon.email.sender.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/email-sender/pom.xml b/components/email-sender/pom.xml index 3128e1d5359..71457804e7a 100644 --- a/components/email-sender/pom.xml +++ b/components/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml index 11a8a6b89e2..64740b93fb0 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt identity-extensions - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.oauth.extensions - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - OAuth Extensions http://wso2.org diff --git a/components/identity-extensions/org.wso2.carbon.identity.authenticator.backend.oauth/pom.xml b/components/identity-extensions/org.wso2.carbon.identity.authenticator.backend.oauth/pom.xml index f4398939c9d..f31f23be368 100644 --- a/components/identity-extensions/org.wso2.carbon.identity.authenticator.backend.oauth/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.identity.authenticator.backend.oauth/pom.xml @@ -21,7 +21,7 @@ identity-extensions org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT 4.0.0 diff --git a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml index a3bfc5c39e0..f226f70e1f1 100644 --- a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/components/identity-extensions/pom.xml b/components/identity-extensions/pom.xml index 1978500c005..f8df563ab36 100644 --- a/components/identity-extensions/pom.xml +++ b/components/identity-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml index fa505e75f5a..ade03b5551b 100644 --- a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt policy-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.complex.policy.decision.point - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Policy Decision Point WSO2 Carbon - Policy Decision Point diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml index df4a1d4e53b..4af9ff57237 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml @@ -3,14 +3,14 @@ org.wso2.carbon.devicemgt policy-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.policy.decision.point - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Policy Decision Point WSO2 Carbon - Policy Decision Point diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml index b0420139bd0..1f664458e5b 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml @@ -11,7 +11,7 @@ 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.policy.information.point - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Policy Information Point WSO2 Carbon - Policy Information Point diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index 4e2f3e57801..6b117fe4211 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt policy-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.policy.mgt.common - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Policy Management Common WSO2 Carbon - Policy Management Common diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index 53436fc9591..d0e55b8c065 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt policy-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.policy.mgt.core - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Policy Management Core WSO2 Carbon - Policy Management Core diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java index aac07ce6000..c603be7d842 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java @@ -33,4 +33,7 @@ public interface PolicyEnforcementDelegator { void addPolicyRevokeOperation(List deviceIdentifiers) throws PolicyDelegationException; + void revokePolicyOperation(List deviceIdentifiers, Policy policy) throws PolicyDelegationException; + + } 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..7471b7ae9f4 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 @@ -81,8 +81,7 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato */ if (devicePolicy == null || devicePolicy.getId() != policy.getId() || updatedPolicyIds.contains (policy.getId())) { - this.addPolicyRevokeOperation(deviceIdentifiers); - this.addPolicyOperation(deviceIdentifiers, policy); + this.revokePolicyOperation(deviceIdentifiers, policy); } } else { //This means all the applicable policies have been removed from device. Hence calling a policy revoke. @@ -167,6 +166,27 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato return policyRevokeOperation; } + @Override + public void revokePolicyOperation(List deviceIdentifiers, Policy policy) throws + PolicyDelegationException { + try { + String type = null; + if (deviceIdentifiers.size() > 0) { + type = deviceIdentifiers.get(0).getType(); + } + PolicyManagementDataHolder.getInstance().getDeviceManagementService().addPolicyOperations(type, policy, + deviceIdentifiers); + } catch (InvalidDeviceException e) { + String msg = "Invalid DeviceIdentifiers found."; + log.error(msg, e); + throw new PolicyDelegationException(msg, e); + } catch (OperationManagementException e) { + String msg = "Error occurred while adding the operation to device."; + log.error(msg, e); + throw new PolicyDelegationException(msg, e); + } + } + /** * Provides the applied policy for give device * diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml index d10a353cb0e..fe86127fcc6 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -23,13 +23,13 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 policy-mgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Policy Management Component http://wso2.org diff --git a/components/test-coverage/pom.xml b/components/test-coverage/pom.xml index 27f904b310e..bdd3c31c121 100644 --- a/components/test-coverage/pom.xml +++ b/components/test-coverage/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml index 3c4bc0c3be5..2abd6ce664f 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml @@ -21,14 +21,14 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.webapp.authenticator.framework - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT bundle WSO2 Carbon - Web Application Authenticator Framework Bundle WSO2 Carbon - Web Application Authenticator Framework Bundle diff --git a/components/webapp-authenticator-framework/pom.xml b/components/webapp-authenticator-framework/pom.xml index 16429f6b033..84b26e6ff97 100644 --- a/components/webapp-authenticator-framework/pom.xml +++ b/components/webapp-authenticator-framework/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt webapp-authenticator-framework - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Webapp Authenticator Framework http://wso2.org diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml index ef9ee953dff..c274e075f43 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml @@ -21,14 +21,14 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.application.extension.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - API Management Application Extension Feature http://wso2.org This feature contains an implementation of a api application registration, which takes care of subscription diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.handler.server.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.handler.server.feature/pom.xml index 020e7e41319..1c6417c2fc4 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.handler.server.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.handler.server.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.handler.server.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Device Management - APIM handler Server Feature http://wso2.org This feature contains the handler for the api authentications diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.integration.client.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.integration.client.feature/pom.xml index a2a856c92cf..e840d193cf7 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.integration.client.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.integration.client.feature/pom.xml @@ -21,13 +21,13 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.integration.client.feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - APIM Integration Client Feature http://wso2.org diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml index d58b098ed8a..166063800f2 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml @@ -21,14 +21,14 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.webapp.publisher.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - API Management Webapp Publisher Feature http://wso2.org This feature contains an implementation of a Tomcat lifecycle listener, which takes care of publishing diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml index 43cc7ec3bc1..745a2a13c16 100644 --- a/features/apimgt-extensions/pom.xml +++ b/features/apimgt-extensions/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt apimgt-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - API Management Extensions Feature http://wso2.org diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml index 86ce3dd5c14..47566f02fd4 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml index 30fd9d28b98..5bd2da78e22 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml index bdc83d82baa..a33d6301bf9 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.certificate.mgt.server.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Certificate Management Server Feature http://wso2.org This feature contains the core bundles required for back-end Certificate Management functionality diff --git a/features/certificate-mgt/pom.xml b/features/certificate-mgt/pom.xml index abd1046616c..53270854fbe 100644 --- a/features/certificate-mgt/pom.xml +++ b/features/certificate-mgt/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt certificate-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Certificate Management Feature http://wso2.org diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml index 970d029acf8..1345a8c8934 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Device Type Deployer Feature http://wso2.org WSO2 Carbon - Device Type Deployer Feature diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml index c61b38a9340..ab9703cad27 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - FCM Based Push Notification Provider Feature http://wso2.org WSO2 Carbon - MQTT Based Push Notification Provider Feature diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml index ddd5573447e..e5d2eaf644f 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - MQTT Based Push Notification Provider Feature http://wso2.org WSO2 Carbon - MQTT Based Push Notification Provider Feature diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml index 6f782cc2c06..1e045ac88a0 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - MQTT Based Push Notification Provider Feature http://wso2.org WSO2 Carbon - MQTT Based Push Notification Provider Feature diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml index 299d02fa117..391d971aa81 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - XMPP Based Push Notification Provider Feature http://wso2.org WSO2 Carbon - XMPP Based Push Notification Provider Feature diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml index 8275b908b39..a6d152ad1d5 100644 --- a/features/device-mgt-extensions/pom.xml +++ b/features/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/p2.inf deleted file mode 100644 index 70f1acd33f8..00000000000 --- a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/p2.inf +++ /dev/null @@ -1,2 +0,0 @@ -instructions.configure = \ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.analytics.data.publisher_${feature.version}/conf/device-analytics-config.xml,target:${installFolder}/../../conf/etc/device-analytics-config.xml,overwrite:true);\ \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.feature/pom.xml similarity index 74% rename from features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/pom.xml rename to features/device-mgt/org.wso2.carbon.device.mgt.analytics.feature/pom.xml index f59d768e6c4..ada5e767487 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.feature/pom.xml @@ -1,6 +1,6 @@ + true - false - tcp://localhost:7612 + tcp://${iot.analytics.host}:${iot.analytics.thrift.port} + + wss://${iot.analytics.host}:${iot.analytics.https.port} admin admin diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.feature/src/main/resources/p2.inf new file mode 100644 index 00000000000..a0a1b3d0058 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.feature/src/main/resources/p2.inf @@ -0,0 +1,4 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.analytics_${feature.version}/conf/device-analytics-config.xml,target:${installFolder}/../../conf/etc/device-analytics-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.analytics_${feature.version}/webapps/secured-websocket-proxy.war,target:${installFolder}/../../deployment/server/webapps/secured-websocket-proxy.war,overwrite:true);\ \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml index b34626ff573..8866f6a624b 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml index bf9b2075ac2..fce238a85b6 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml index cb9ec56f1ee..d022f0a089b 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml @@ -4,14 +4,14 @@ org.wso2.carbon.devicemgt device-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.extensions.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Device Management Extensions Feature http://wso2.org This feature contains common extensions used by key device management functionalities diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml index 0d730bc030a..2cb920b0963 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index 1a565a139b2..6ce6a14b886 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt device-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.server.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Device Management Server Feature http://wso2.org This feature contains the core bundles required for Back-end Device Management functionality diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml index bf0aae0b0b0..411739ea506 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml index fe70581b8a9..9c13ebb88f7 100644 --- a/features/device-mgt/pom.xml +++ b/features/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml @@ -39,7 +39,7 @@ org.wso2.carbon.device.mgt.api.feature org.wso2.carbon.device.mgt.feature org.wso2.carbon.device.mgt.extensions.feature - org.wso2.carbon.device.mgt.analytics.data.publisher.feature + org.wso2.carbon.device.mgt.analytics.feature diff --git a/features/email-sender/org.wso2.carbon.email.sender.feature/pom.xml b/features/email-sender/org.wso2.carbon.email.sender.feature/pom.xml index 7b373067dde..d2306d35f53 100644 --- a/features/email-sender/org.wso2.carbon.email.sender.feature/pom.xml +++ b/features/email-sender/org.wso2.carbon.email.sender.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt email-sender-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.email.sender.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Email Sender Feature http://wso2.org This feature contains the core bundles required for email sender related functionality diff --git a/features/email-sender/pom.xml b/features/email-sender/pom.xml index 8dc9237d46d..27a19920d64 100644 --- a/features/email-sender/pom.xml +++ b/features/email-sender/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt email-sender-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Email Sender Feature http://wso2.org diff --git a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml index 9136c38f147..3bb5043ccbe 100644 --- a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml +++ b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml @@ -23,14 +23,14 @@ org.wso2.carbon.devicemgt jwt-client-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.identity.jwt.client.extension.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - JWT Client Feature http://wso2.org This feature contains jwt client implementation from which we can get a access token using the jwt diff --git a/features/jwt-client/pom.xml b/features/jwt-client/pom.xml index d8c03de017a..79c53c0d2fd 100644 --- a/features/jwt-client/pom.xml +++ b/features/jwt-client/pom.xml @@ -23,13 +23,13 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 jwt-client-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - JWT Client Extension Feature http://wso2.org diff --git a/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml b/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml index d71e5f9c69e..2b06e5c5ff0 100644 --- a/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml +++ b/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml @@ -23,14 +23,14 @@ org.wso2.carbon.devicemgt oauth-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.oauth.extensions.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Device Mgt OAuth Extensions Feature http://wso2.org This feature contains devicemgt related OAuth extensions diff --git a/features/oauth-extensions/pom.xml b/features/oauth-extensions/pom.xml index ae22ee1ad66..d183fe0bb4e 100644 --- a/features/oauth-extensions/pom.xml +++ b/features/oauth-extensions/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt oauth-extensions-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Device Management OAuth Extensions Feature http://wso2.org diff --git a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml index e7cff33fdbe..d7f2aff01bf 100644 --- a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml +++ b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml @@ -23,14 +23,14 @@ org.wso2.carbon.devicemgt policy-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.policy.mgt.server.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Policy Management Server Feature http://wso2.org This feature contains the core bundles required for Back-end Device Management functionality diff --git a/features/policy-mgt/pom.xml b/features/policy-mgt/pom.xml index 2f137eadd95..2c940317d6c 100644 --- a/features/policy-mgt/pom.xml +++ b/features/policy-mgt/pom.xml @@ -23,14 +23,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt policy-mgt-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Policy Management Feature http://wso2.org diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml index fc474d0f18a..1d0bd6a4a0e 100644 --- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml +++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.webapp.authenticator.framework.server.feature pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Webapp Authenticator Framework Server Feature http://wso2.org This feature contains the core bundles required for Back-end Device Management functionality diff --git a/features/webapp-authenticator-framework/pom.xml b/features/webapp-authenticator-framework/pom.xml index 07762e66faf..eca35681ecc 100644 --- a/features/webapp-authenticator-framework/pom.xml +++ b/features/webapp-authenticator-framework/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt webapp-authenticator-framework-feature - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT pom WSO2 Carbon - Webapp Authenticator Framework Feature http://wso2.org diff --git a/pom.xml b/pom.xml index 43e2268bf2d..129a80971c0 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt pom - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT WSO2 Carbon - Device Management - Parent http://wso2.org WSO2 Connected Device Manager Components @@ -277,6 +277,11 @@ org.wso2.carbon.device.mgt.analytics.data.publisher ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics.wsproxy + ${carbon.device.mgt.version} + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.server.feature @@ -1385,11 +1390,11 @@ provided - + mysql mysql-connector-java - ${tomcat.version} + ${mysql.connector.version} test @@ -1735,6 +1740,19 @@ apk-parser ${net.dongliu.version} + + + + javax.websocket + javax.websocket-api + ${javax.websocket.version} + + + org.apache.tomcat + tomcat-websocket-api + ${tomcat.websocket.version} + provided + @@ -1997,8 +2015,8 @@ 1.2.140.wso2v3 - 7.0.59.wso2v1 - 7.0.59.wso2v1 + 7.0.85.wso2v1 + 7.0.85.wso2v1 7.0.34.wso2v2 @@ -2028,7 +2046,7 @@ 1.2.11.wso2v10 - 3.1.34-SNAPSHOT + 3.1.40-SNAPSHOT 4.6.21 @@ -2106,8 +2124,8 @@ (3.2.0, 3.3.0] 1.8 - - 5.1.34 + + 5.1.34 3.0.4.wso2v1 @@ -2179,6 +2197,10 @@ 1.8 2.4.2 + + 7.0.85 + 1.0 + 1.13.1