From f0c63e4cbea7f59c0b30585118c40f81bca80a9a Mon Sep 17 00:00:00 2001 From: amanda <74random.amanda@gmail.com> Date: Thu, 16 Apr 2020 15:18:23 +0530 Subject: [PATCH 1/5] Change DB scripts --- .../dbscripts/cdm/application-mgt/h2.sql | 46 +++++++++++ .../dbscripts/cdm/application-mgt/mssql.sql | 48 +++++++++++ .../dbscripts/cdm/application-mgt/mysql.sql | 42 ++++++++++ .../dbscripts/cdm/application-mgt/oracle.sql | 80 +++++++++++++++++++ .../cdm/application-mgt/postgresql.sql | 49 ++++++++++++ 5 files changed, 265 insertions(+) diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index f16927301b..d2255a78ff 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -12,9 +12,55 @@ CREATE TABLE IF NOT EXISTS AP_APP( CURRENCY VARCHAR(45) NULL DEFAULT '$', RATING DOUBLE NULL DEFAULT NULL, DEVICE_TYPE_ID INTEGER NOT NULL, + ADAM_ID VARCHAR(45) NULL DEFAULT '0' UNIQUE , PRIMARY KEY (ID) ); +-- ----------------------------------------------------- +-- Table AP_VPP_LICENSE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AP_VPP_LICENSE +( + LICENSE_ID INTEGER NOT NULL AUTO_INCREMENT, + ADAM_ID VARCHAR(45) NOT NULL UNIQUE , + AVAILABILITY VARCHAR(350) NOT NULL, + PRIMARY KEY (LICENSE_ID), + CONSTRAINT fk_AP_VPP_LICENSE_AP_APP1 + FOREIGN KEY (ADAM_ID) + REFERENCES AP_APP (ADAM_ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); +CREATE INDEX fk_AP_VPP_LICENSE_AP_APP1_idx ON AP_VPP_LICENSE (ADAM_ID ASC); + +-- ----------------------------------------------------- +-- Table AP_VPP_DEVICE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AP_VPP_DEVICE +( + ID INTEGER NOT NULL AUTO_INCREMENT, + SERIAL_NUMBER INTEGER NOT NULL, + USER_ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +-- ----------------------------------------------------- +-- Table AP_VPP_DEVICE_LICENSE_MAPPING +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AP_VPP_DEVICE_LICENSE_MAPPING +( + LICENSE_ID INTEGER NOT NULL, + DEVICE_ID INTEGER NOT NULL, + PRIMARY KEY (LICENSE_ID, DEVICE_ID), + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES AP_VPP_DEVICE (ID), + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE + FOREIGN KEY (LICENSE_ID) + REFERENCES AP_VPP_LICENSE (LICENSE_ID) +); +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE_idx ON AP_VPP_DEVICE (ID ASC); +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE_idx ON AP_VPP_LICENSE (LICENSE_ID ASC); + + -- ----------------------------------------------------- -- Table AP_APP_RELEASE -- ----------------------------------------------------- diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql index 78e05c1371..b6899600b2 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql @@ -12,9 +12,57 @@ CREATE TABLE AP_APP( CURRENCY VARCHAR(45) NULL DEFAULT '$', RATING FLOAT NULL DEFAULT NULL, DEVICE_TYPE_ID INTEGER NOT NULL, + ADAM_ID VARCHAR(45) NULL DEFAULT '0' , + CONSTRAINT ADAM_ID_CONSTRAINT UNIQUE (ADAM_ID), PRIMARY KEY (ID) ); +-- ----------------------------------------------------- +-- Table AP_VPP_LICENSE +-- ----------------------------------------------------- +CREATE TABLE AP_VPP_LICENSE +( + LICENSE_ID INTEGER NOT NULL IDENTITY, + ADAM_ID VARCHAR(45) NOT NULL , + AVAILABILITY VARCHAR(350) NOT NULL, + PRIMARY KEY (LICENSE_ID), + CONSTRAINT ADAMID_CONSTRAINT UNIQUE (ADAM_ID), + CONSTRAINT fk_AP_VPP_LICENSE_AP_APP1 + FOREIGN KEY (ADAM_ID) + REFERENCES AP_APP (ADAM_ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); +CREATE INDEX fk_AP_VPP_LICENSE_AP_APP1_idx ON AP_VPP_LICENSE (ADAM_ID ASC); + +-- ----------------------------------------------------- +-- Table AP_VPP_DEVICE +-- ----------------------------------------------------- +CREATE TABLE AP_VPP_DEVICE +( + ID INTEGER NOT NULL IDENTITY,, + SERIAL_NUMBER INTEGER NOT NULL, + USER_ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +-- ----------------------------------------------------- +-- Table AP_VPP_DEVICE_LICENSE_MAPPING +-- ----------------------------------------------------- +CREATE TABLE AP_VPP_DEVICE_LICENSE_MAPPING +( + LICENSE_ID INTEGER NOT NULL, + DEVICE_ID INTEGER NOT NULL, + PRIMARY KEY (LICENSE_ID, DEVICE_ID), + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES AP_VPP_DEVICE (ID), + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE + FOREIGN KEY (LICENSE_ID) + REFERENCES AP_VPP_LICENSE (LICENSE_ID) +); +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE_idx ON AP_VPP_DEVICE (ID ASC); +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE_idx ON AP_VPP_LICENSE (LICENSE_ID ASC); + + -- ----------------------------------------------------- -- Table AP_APP_RELEASE -- ----------------------------------------------------- diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 1daa796858..cb1dd50e59 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -12,9 +12,51 @@ CREATE TABLE IF NOT EXISTS AP_APP( CURRENCY VARCHAR(45) NULL DEFAULT '$', RATING DOUBLE NULL DEFAULT NULL, DEVICE_TYPE_ID INTEGER NOT NULL, + ADAM_ID VARCHAR(45) NULL DEFAULT '0' UNIQUE , PRIMARY KEY (ID) ); +-- ----------------------------------------------------- +-- Table AP_VPP_LICENSE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AP_VPP_LICENSE( + LICENSE_ID INTEGER NOT NULL AUTO_INCREMENT, + ADAM_ID VARCHAR(45) NOT NULL UNIQUE , + AVAILABILITY VARCHAR(350) NOT NULL, + PRIMARY KEY (LICENSE_ID), + CONSTRAINT fk_AP_VPP_LICENSE_AP_APP1 + FOREIGN KEY (ADAM_ID) + REFERENCES AP_APP (ADAM_ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); +CREATE INDEX fk_AP_VPP_LICENSE_AP_APP1_idx ON AP_VPP_LICENSE (ADAM_ID ASC); + +-- ----------------------------------------------------- +-- Table AP_VPP_DEVICE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AP_VPP_DEVICE( + ID INTEGER NOT NULL AUTO_INCREMENT, + SERIAL_NUMBER INTEGER NOT NULL, + USER_ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +-- ----------------------------------------------------- +-- Table AP_VPP_DEVICE_LICENSE_MAPPING +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AP_VPP_DEVICE_LICENSE_MAPPING( + LICENSE_ID INTEGER NOT NULL, + DEVICE_ID INTEGER NOT NULL, + PRIMARY KEY (LICENSE_ID, DEVICE_ID), + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES AP_VPP_DEVICE (ID), + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE + FOREIGN KEY (LICENSE_ID) + REFERENCES AP_VPP_LICENSE (LICENSE_ID) +); +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE_idx ON AP_VPP_DEVICE (ID ASC); +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE_idx ON AP_VPP_LICENSE (LICENSE_ID ASC); + -- ----------------------------------------------------- -- Table AP_APP_RELEASE -- ----------------------------------------------------- diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql index c4f2c99f06..c952127b97 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql @@ -228,6 +228,7 @@ INSERT INTO APPM_LC_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESC CREATE TABLE APPM_APPLICATION ( ID INT UNIQUE, UUID VARCHAR(100) NOT NULL, + ADAM_ID VARCHAR(100) DEFAULT '0', IDENTIFIER VARCHAR(255) NULL, NAME VARCHAR(100) NOT NULL, SHORT_DESCRIPTION VARCHAR(255) NULL, @@ -255,6 +256,9 @@ CREATE TABLE APPM_APPLICATION ( CREATE INDEX UUID_UNIQUE ON APPM_APPLICATION(UUID ASC) / +CREATE INDEX ADAM_ID_UNIQUE ON APPM_APPLICATION(ADAM_ID ASC) +/ + CREATE INDEX FK_APP_APP_CATEGORY ON APPM_APPLICATION(APPLICATION_CATEGORY_ID ASC) / @@ -277,6 +281,82 @@ CREATE OR REPLACE TRIGGER APPM_APPLICATION_TRIG END; / +-- ----------------------------------------------------- +-- Table AP_VPP_LICENSE +-- ----------------------------------------------------- +CREATE TABLE AP_VPP_LICENSE( + LICENSE_ID NUMBER(10) NOT NULL, + ADAM_ID VARCHAR2(45) NOT NULL UNIQUE , + AVAILABILITY VARCHAR2(350) NOT NULL, + PRIMARY KEY (LICENSE_ID), + CONSTRAINT FK_AP_VPP_LICENSE_AP_APP + FOREIGN KEY (ADAM_ID) + REFERENCES APPM_APPLICATION (ADAM_ID) +); +/ + +CREATE SEQUENCE AP_VPP_LICENSE_SEQ START WITH 1 INCREMENT BY 1; +/ + +CREATE OR REPLACE TRIGGER AP_VPP_LICENSE_TRIG + BEFORE INSERT + ON AP_VPP_LICENSE + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT AP_VPP_LICENSE_SEQ.nextval INTO :NEW.LICENSE_ID FROM dual; + END; +/ + +CREATE INDEX fk_AP_VPP_LICENSE_AP_APP1_idx ON AP_VPP_LICENSE (ADAM_ID ASC); +/ + +-- ----------------------------------------------------- +-- Table AP_VPP_DEVICE +-- ----------------------------------------------------- +CREATE TABLE AP_VPP_DEVICE( + ID NUMBER(10) NOT NULL, + SERIAL_NUMBER NUMBER(10) NOT NULL, + USER_ID NUMBER(10) NOT NULL, + PRIMARY KEY (ID) +); +/ + +CREATE SEQUENCE AP_VPP_DEVICE_SEQ START WITH 1 INCREMENT BY 1; +/ + +CREATE OR REPLACE TRIGGER AP_VPP_DEVICE_TRIG + BEFORE INSERT + ON AP_VPP_DEVICE + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT AP_VPP_DEVICE_SEQ.nextval INTO :NEW.ID FROM dual; + END; +/ + +-- ----------------------------------------------------- +-- Table AP_VPP_DEVICE_LICENSE_MAPPING +-- ----------------------------------------------------- +CREATE TABLE AP_VPP_DEVICE_LICENSE_MAPPING( + LICENSE_ID NUMBER(10) NOT NULL, + DEVICE_ID NUMBER(10) NOT NULL, + PRIMARY KEY (LICENSE_ID, DEVICE_ID), + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES AP_VPP_DEVICE (ID), + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE + FOREIGN KEY (LICENSE_ID) + REFERENCES AP_VPP_LICENSE (LICENSE_ID) +); +/ + +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE_idx ON AP_VPP_DEVICE (ID ASC); +/ + +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE_idx ON AP_VPP_LICENSE (LICENSE_ID ASC); +/ + -- ----------------------------------------------------- -- Table APPM_APPLICATION_PROPERTY -- ----------------------------------------------------- diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index 5c20aa4a75..e30249eb8f 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -14,9 +14,58 @@ CREATE TABLE IF NOT EXISTS AP_APP( CURRENCY VARCHAR(45) NULL DEFAULT '$', RATING DOUBLE PRECISION NULL DEFAULT NULL, DEVICE_TYPE_ID INTEGER NOT NULL, + ADAM_ID VARCHAR(45) NULL DEFAULT '0' UNIQUE, PRIMARY KEY (ID) ); +-- ----------------------------------------------------- +-- Table AP_VPP_LICENSE +-- ----------------------------------------------------- +CREATE SEQUENCE AP_VPP_LICENSE_seq; + +CREATE TABLE IF NOT EXISTS AP_VPP_LICENSE( + LICENSE_ID INTEGER NOT NULL DEFAULT NEXTVAL ('AP_VPP_LICENSE_seq'), + ADAM_ID VARCHAR(45) NOT NULL UNIQUE , + AVAILABILITY VARCHAR(350) NOT NULL, + PRIMARY KEY (LICENSE_ID), + CONSTRAINT fk_AP_VPP_LICENSE_AP_APP1 + FOREIGN KEY (ADAM_ID) + REFERENCES AP_APP (ADAM_ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); +CREATE INDEX fk_AP_VPP_LICENSE_AP_APP1_idx ON AP_VPP_LICENSE (ADAM_ID ASC); + +-- ----------------------------------------------------- +-- Table AP_VPP_DEVICE +-- ----------------------------------------------------- +CREATE SEQUENCE AP_VPP_DEVICE_seq; + +CREATE TABLE IF NOT EXISTS AP_VPP_DEVICE +( + ID INTEGER NOT NULL DEFAULT NEXTVAL ('AP_VPP_DEVICE_seq'), + SERIAL_NUMBER INTEGER NOT NULL, + USER_ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +-- ----------------------------------------------------- +-- Table AP_VPP_DEVICE_LICENSE_MAPPING +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AP_VPP_DEVICE_LICENSE_MAPPING +( + LICENSE_ID INTEGER NOT NULL, + DEVICE_ID INTEGER NOT NULL, + PRIMARY KEY (LICENSE_ID, DEVICE_ID), + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES AP_VPP_DEVICE (ID), + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE + FOREIGN KEY (LICENSE_ID) + REFERENCES AP_VPP_LICENSE (LICENSE_ID) +); +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE_idx ON AP_VPP_DEVICE (ID ASC); +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE_idx ON AP_VPP_LICENSE (LICENSE_ID ASC); + + -- ----------------------------------------------------- -- Table AP_APP_RELEASE -- ----------------------------------------------------- From 3ca5ca5a6e96f6d25a396e8f2a9def4c5496b560 Mon Sep 17 00:00:00 2001 From: amanda <74random.amanda@gmail.com> Date: Thu, 16 Apr 2020 15:23:48 +0530 Subject: [PATCH 2/5] Change getApplications --- .../application/mgt/common/dto/ApplicationDTO.java | 12 ++++++++++++ .../impl/application/GenericApplicationDAOImpl.java | 1 + .../impl/application/OracleApplicationDAOImpl.java | 1 + .../application/SQLServerApplicationDAOImpl.java | 1 + .../device/application/mgt/core/util/DAOUtil.java | 1 + 5 files changed, 16 insertions(+) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java index 57ec6991f9..f924e2774f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java @@ -96,6 +96,18 @@ public class ApplicationDTO { value = "package name of the application") private String packageName; + @ApiModelProperty(name = "adamId", + value = "adamID is the asset ID given by iTunes") + private String adamId; + + public String getAdamId() { + return adamId; + } + + public void setAdamId(String adamId) { + this.adamId = adamId; + } + public String getPackageName() { return packageName; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 8ad0152096..04604d6ccf 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -115,6 +115,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.RATING AS APP_RATING, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP.ADAM_ID AS APP_ADAM_ID, " + "AP_APP_RELEASE.ID AS RELEASE_ID, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java index d39469eedf..59129b2cb7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java @@ -62,6 +62,7 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { + "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.RATING AS APP_RATING, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP.ADAM_ID AS APP_ADAM_ID, " + "AP_APP_RELEASE.ID AS RELEASE_ID, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java index 9e07d8ccea..f34b18a566 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java @@ -61,6 +61,7 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { + "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.RATING AS APP_RATING, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP.ADAM_ID AS APP_ADAM_ID, " + "AP_APP_RELEASE.ID AS RELEASE_ID, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java index c56df53109..1e4a66eb66 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java @@ -80,6 +80,7 @@ public class DAOUtil { application.setStatus(rs.getString("APP_STATUS")); application.setAppRating(rs.getDouble("APP_RATING")); application.setDeviceTypeId(rs.getInt("APP_DEVICE_TYPE_ID")); + application.setAdamId(rs.getString("APP_ADAM_ID")); application.setPackageName(rs.getString("PACKAGE_NAME")); application.getApplicationReleaseDTOs().add(constructAppReleaseDTO(rs)); } else { From a73ec6748519530e690f7ecd0d47671412a55f2a Mon Sep 17 00:00:00 2001 From: amanda <74random.amanda@gmail.com> Date: Thu, 16 Apr 2020 16:26:48 +0530 Subject: [PATCH 3/5] Remove default value for ADAM_ID --- .../src/main/resources/dbscripts/cdm/application-mgt/h2.sql | 2 +- .../src/main/resources/dbscripts/cdm/application-mgt/mssql.sql | 2 +- .../src/main/resources/dbscripts/cdm/application-mgt/mysql.sql | 2 +- .../src/main/resources/dbscripts/cdm/application-mgt/oracle.sql | 2 +- .../main/resources/dbscripts/cdm/application-mgt/postgresql.sql | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index d2255a78ff..c624d00460 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS AP_APP( CURRENCY VARCHAR(45) NULL DEFAULT '$', RATING DOUBLE NULL DEFAULT NULL, DEVICE_TYPE_ID INTEGER NOT NULL, - ADAM_ID VARCHAR(45) NULL DEFAULT '0' UNIQUE , + ADAM_ID VARCHAR(45) NULL UNIQUE , PRIMARY KEY (ID) ); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql index b6899600b2..98b48194f4 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql @@ -12,7 +12,7 @@ CREATE TABLE AP_APP( CURRENCY VARCHAR(45) NULL DEFAULT '$', RATING FLOAT NULL DEFAULT NULL, DEVICE_TYPE_ID INTEGER NOT NULL, - ADAM_ID VARCHAR(45) NULL DEFAULT '0' , + ADAM_ID VARCHAR(45) NULL , CONSTRAINT ADAM_ID_CONSTRAINT UNIQUE (ADAM_ID), PRIMARY KEY (ID) ); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index cb1dd50e59..4802f08e0a 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS AP_APP( CURRENCY VARCHAR(45) NULL DEFAULT '$', RATING DOUBLE NULL DEFAULT NULL, DEVICE_TYPE_ID INTEGER NOT NULL, - ADAM_ID VARCHAR(45) NULL DEFAULT '0' UNIQUE , + ADAM_ID VARCHAR(45) NULL UNIQUE , PRIMARY KEY (ID) ); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql index c952127b97..f4e98e5418 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql @@ -228,7 +228,7 @@ INSERT INTO APPM_LC_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESC CREATE TABLE APPM_APPLICATION ( ID INT UNIQUE, UUID VARCHAR(100) NOT NULL, - ADAM_ID VARCHAR(100) DEFAULT '0', + ADAM_ID VARCHAR(100) NULL, IDENTIFIER VARCHAR(255) NULL, NAME VARCHAR(100) NOT NULL, SHORT_DESCRIPTION VARCHAR(255) NULL, diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index e30249eb8f..5c360e33c0 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS AP_APP( CURRENCY VARCHAR(45) NULL DEFAULT '$', RATING DOUBLE PRECISION NULL DEFAULT NULL, DEVICE_TYPE_ID INTEGER NOT NULL, - ADAM_ID VARCHAR(45) NULL DEFAULT '0' UNIQUE, + ADAM_ID VARCHAR(45) NULL UNIQUE, PRIMARY KEY (ID) ); From 008b24dc37629bf3528ae685cefd8eebd494925f Mon Sep 17 00:00:00 2001 From: amanda <74random.amanda@gmail.com> Date: Wed, 6 May 2020 06:50:38 +0530 Subject: [PATCH 4/5] Add VPP DAOs --- .../mgt/common/dto/ApplicationDTO.java | 14 +++- .../mgt/common/dto/LicenseDTO.java | 56 +++++++++++++ .../mgt/common/dto/VPPDeviceDTO.java | 46 ++++++++++ .../mgt/core/dao/ApplicationDAO.java | 8 +- .../GenericApplicationDAOImpl.java | 83 ++++++++++++++++++- .../mgt/core/impl/ApplicationManagerImpl.java | 9 ++ .../main/resources/conf/application-mgt.xml | 1 + .../dbscripts/cdm/application-mgt/mysql.sql | 32 +++---- 8 files changed, 232 insertions(+), 17 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/LicenseDTO.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/VPPDeviceDTO.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java index f924e2774f..c2c617ac49 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ApplicationDTO.java @@ -97,9 +97,13 @@ public class ApplicationDTO { private String packageName; @ApiModelProperty(name = "adamId", - value = "adamID is the asset ID given by iTunes") + value = "The unique identifier for a product in the iTunes Store") private String adamId; + @ApiModelProperty(name = "licenses", + value = "List of application licenses") + private List licenses; + public String getAdamId() { return adamId; } @@ -108,6 +112,14 @@ public class ApplicationDTO { this.adamId = adamId; } + public List getLicenses() { + return licenses; + } + + public void setLicenses(List licenses) { + this.licenses = licenses; + } + public String getPackageName() { return packageName; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/LicenseDTO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/LicenseDTO.java new file mode 100644 index 0000000000..7b35233f6e --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/LicenseDTO.java @@ -0,0 +1,56 @@ +package org.wso2.carbon.device.application.mgt.common.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "LicenseDTO", description = "LicenseDTO represents License details.") +public class LicenseDTO { + @ApiModelProperty(name = "id", + value = "The ID given to the license when it is stored in the APPM database") + private int id; + + @ApiModelProperty(name = "licenseId", + value = "The identifier of the assigned license") + private String licenseId; + + @ApiModelProperty(name = "adamId", + value = "The unique identifier for a product in the iTunes Store") + private String adamId; + + @ApiModelProperty(name = "status", + value = "The current state of the license", + example = "Available, Refunded") + private String status; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getLicenseId() { + return licenseId; + } + + public void setLicenseId(String licenseId) { + this.licenseId = licenseId; + } + + public String getAdamId() { + return adamId; + } + + public void setAdamId(String adamId) { + this.adamId = adamId; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/VPPDeviceDTO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/VPPDeviceDTO.java new file mode 100644 index 0000000000..9a74a9d1f3 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/VPPDeviceDTO.java @@ -0,0 +1,46 @@ +package org.wso2.carbon.device.application.mgt.common.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "VPPDeviceDTO", description = "VPPDeviceDTO represents VPP Device details.") +public class VPPDeviceDTO { + + @ApiModelProperty(name = "id", + value = "The ID given to the device when it is stored in the APPM database") + private int id; + + @ApiModelProperty(name = "serialNumber", + value = "serialNumber of the ios device", + required = true) + private String serialNumber; + + @ApiModelProperty(name = "userId", + value = "userId of the device owner", + required = true) + private String userId; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getSerialNumber() { + return serialNumber; + } + + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java index 73784e4813..44c8600d7c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java @@ -20,7 +20,9 @@ package org.wso2.carbon.device.application.mgt.core.dao; import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO; -import org.wso2.carbon.device.application.mgt.common.dto.TagDTO; +import org.wso2.carbon.device.application.mgt.common.dto.VPPDeviceDTO; +import org.wso2.carbon.device.application.mgt.common.dto.LicenseDTO; +import org.wso2.carbon.device.application.mgt.common.dto.TagDTO;; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import java.util.List; @@ -39,6 +41,10 @@ public interface ApplicationDAO { */ int createApplication(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementDAOException; + int createVPPDevice(VPPDeviceDTO vppDeviceDTO, int tenantId) throws ApplicationManagementDAOException; + + void addLicenses(List licenses, int tenantId) throws ApplicationManagementDAOException; + /** * To add tags for a particular application. * diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 04604d6ccf..df79c04ccc 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -23,6 +23,8 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.common.AppLifecycleState; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO; +import org.wso2.carbon.device.application.mgt.common.dto.VPPDeviceDTO; +import org.wso2.carbon.device.application.mgt.common.dto.LicenseDTO; import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.dto.TagDTO; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; @@ -61,7 +63,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "TYPE, " + "SUB_TYPE, " + "TENANT_ID, " - + "DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?)"; + + "DEVICE_TYPE_ID," + + "ADAM_ID) VALUES (?, ?, ?, ?, ?, ?, ?)"; int applicationId = -1; try { Connection conn = this.getDBConnection(); @@ -72,6 +75,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic stmt.setString(4, applicationDTO.getSubType()); stmt.setInt(5, tenantId); stmt.setInt(6, applicationDTO.getDeviceTypeId()); + if(!StringUtils.isEmpty(applicationDTO.getAdamId())){ + stmt.setString(7, applicationDTO.getAdamId()); + } else{ + stmt.setString(7, null); + } stmt.executeUpdate(); try (ResultSet rs = stmt.getGeneratedKeys()) { if (rs.next()) { @@ -93,6 +101,45 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } + @Override + public int createVPPDevice(VPPDeviceDTO vppDeviceDTO, int tenantId) throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to create a VPP Device"); + log.debug("VPPDeviceDTO Details : "); + log.debug("Serial number : " + vppDeviceDTO.getSerialNumber() + " User ID : " + vppDeviceDTO.getUserId()); + } + String sql = "INSERT INTO AP_VPP_DEVICE " + + "(SERIAL_NUMBER, " + + "USER_ID, " + + "TENANT_ID) VALUES (?, ?, ?)"; + int deviceId = -1; + try { + Connection conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { + stmt.setString(1, vppDeviceDTO.getSerialNumber()); + stmt.setString(2, vppDeviceDTO.getUserId()); + stmt.setInt(3, tenantId); + stmt.executeUpdate(); + try (ResultSet rs = stmt.getGeneratedKeys()) { + if (rs.next()) { + deviceId = rs.getInt(1); + } + return deviceId; + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to create a VPP Device which has " + + "Serial number : " + vppDeviceDTO.getSerialNumber(); + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing SQL to create a VPP Device which has Serial number : " + + vppDeviceDTO.getSerialNumber(); + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } + @Override public List getApplications(Filter filter, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException { @@ -748,6 +795,40 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } + @Override + public void addLicenses(List licenses, int tenantId) throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to add Licenses"); + } + String sql = "INSERT INTO AP_LICENSE " + + "(LICENSE_ID, " + + "ADAM_ID, " + + "STATUS, " + + "TENANT_ID) " + + "VALUES (?, ?, ?, ?)"; + try { + Connection conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + for (LicenseDTO license : licenses) { + stmt.setString(1, license.getLicenseId()); + stmt.setString(2, license.getAdamId()); + stmt.setString(3, license.getStatus()); + stmt.setInt(4, tenantId); + stmt.addBatch(); + } + stmt.executeBatch(); + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection when adding licenses"; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "SQL Error occurred while adding licenses. Executed Query: " + sql; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } + @Override public List getAllTags(int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 55ddd7d3f3..bbcb126409 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 @@ -898,6 +898,15 @@ public class ApplicationManagerImpl implements ApplicationManager { } } + //adding licenses + if (applicationDTO.getLicenses() != null && !applicationDTO.getLicenses().isEmpty()) { + this.applicationDAO.addLicenses(applicationDTO.getLicenses(), tenantId); + if (log.isDebugEnabled()) { + log.debug("Licenses added to AP_LICENSE table. App Id:" + appId + + " AdamId : " + applicationDTO.getAdamId()); + } + } + //adding application tags if (tags != null && !tags.isEmpty()) { List registeredTags = applicationDAO.getAllTags(tenantId); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index d0d02a058a..39c32da8e3 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -168,6 +168,7 @@ Video Players & Editors Weather GooglePlaySyncedApp + LicensedVPPAssets diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 4802f08e0a..869bd32fae 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -17,26 +17,29 @@ CREATE TABLE IF NOT EXISTS AP_APP( ); -- ----------------------------------------------------- --- Table AP_VPP_LICENSE --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS AP_VPP_LICENSE( - LICENSE_ID INTEGER NOT NULL AUTO_INCREMENT, - ADAM_ID VARCHAR(45) NOT NULL UNIQUE , - AVAILABILITY VARCHAR(350) NOT NULL, - PRIMARY KEY (LICENSE_ID), - CONSTRAINT fk_AP_VPP_LICENSE_AP_APP1 +-- Table AP_LICENSE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AP_LICENSE( + ID INTEGER NOT NULL AUTO_INCREMENT, + TENANT_ID INTEGER NOT NULL, + LICENSE_ID VARCHAR(45) NOT NULL UNIQUE , + ADAM_ID VARCHAR(45) NOT NULL , + STATUS VARCHAR(350) NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_AP_LICENSE_AP_APP1 FOREIGN KEY (ADAM_ID) REFERENCES AP_APP (ADAM_ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE INDEX fk_AP_VPP_LICENSE_AP_APP1_idx ON AP_VPP_LICENSE (ADAM_ID ASC); +CREATE INDEX fk_AP_LICENSE_AP_APP1_idx ON AP_LICENSE (ADAM_ID ASC); -- ----------------------------------------------------- -- Table AP_VPP_DEVICE -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS AP_VPP_DEVICE( ID INTEGER NOT NULL AUTO_INCREMENT, - SERIAL_NUMBER INTEGER NOT NULL, - USER_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL, + SERIAL_NUMBER VARCHAR(45) NOT NULL, + USER_ID VARCHAR(45) NOT NULL, PRIMARY KEY (ID) ); @@ -46,16 +49,17 @@ CREATE TABLE IF NOT EXISTS AP_VPP_DEVICE( CREATE TABLE IF NOT EXISTS AP_VPP_DEVICE_LICENSE_MAPPING( LICENSE_ID INTEGER NOT NULL, DEVICE_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL, PRIMARY KEY (LICENSE_ID, DEVICE_ID), CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES AP_VPP_DEVICE (ID), - CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE + CONSTRAINT fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_LICENSE FOREIGN KEY (LICENSE_ID) - REFERENCES AP_VPP_LICENSE (LICENSE_ID) + REFERENCES AP_LICENSE (ID) ); CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_DEVICE_idx ON AP_VPP_DEVICE (ID ASC); -CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_VPP_LICENSE_idx ON AP_VPP_LICENSE (LICENSE_ID ASC); +CREATE INDEX fk_AP_VPP_DEVICE_LICENSE_MAPPING_AP_LICENSE_idx ON AP_LICENSE (LICENSE_ID ASC); -- ----------------------------------------------------- -- Table AP_APP_RELEASE From 37c8a50bf3556727f8665f162bb8ddf4b921092e Mon Sep 17 00:00:00 2001 From: amanda <74random.amanda@gmail.com> Date: Mon, 11 May 2020 09:26:34 +0530 Subject: [PATCH 5/5] Implement VPP app creation --- .../mgt/common/response/Application.java | 13 ++ .../common/services/ApplicationManager.java | 10 + .../common/wrapper/VPPAppReleaseWrapper.java | 192 ++++++++++++++++++ .../mgt/common/wrapper/VPPAppWrapper.java | 152 ++++++++++++++ .../GenericApplicationDAOImpl.java | 16 +- .../GenericApplicationReleaseDAOImpl.java | 8 +- .../mgt/core/impl/ApplicationManagerImpl.java | 119 +++++++++++ .../application/mgt/core/util/APIUtil.java | 37 ++++ 8 files changed, 538 insertions(+), 9 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/VPPAppReleaseWrapper.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/VPPAppWrapper.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/Application.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/Application.java index 778f7fc08d..037b4af51d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/Application.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/Application.java @@ -26,6 +26,11 @@ public class Application { required = true) private int id; + @ApiModelProperty(name = "adamId", + value = "The unique identifier for a product in the iTunes Store", + required = true) + private String adamId; + @ApiModelProperty(name = "name", value = "Name of the application", required = true) @@ -107,6 +112,14 @@ public class Application { this.packageName = packageName; } + public String getAdamId() { + return adamId; + } + + public void setAdamId(String adamId) { + this.adamId = adamId; + } + public int getId() { return id; } public void setId(int id) { this.id = id; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index ab031305f8..8e9b5800be 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -36,6 +36,7 @@ import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWr import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.VPPAppWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; @@ -66,6 +67,15 @@ public interface ApplicationManager { Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException; + /** + * The method is responsible to add new VPP Asset into entgra App Manager. + * + * @param vppAppWrapper Asset that need to be created. + * @return {@link Application} + * @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException} + */ + Application createVPPApp(VPPAppWrapper vppAppWrapper) throws ApplicationManagementException; + /** * Check the existence of an application for given application name and the device type. * diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/VPPAppReleaseWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/VPPAppReleaseWrapper.java new file mode 100644 index 0000000000..87e4b7b40f --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/VPPAppReleaseWrapper.java @@ -0,0 +1,192 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.device.application.mgt.common.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; + +@ApiModel(value = "VPP App Release Wrapper", description = "This class holds the details when releasing a VPP App" + + " Release to application store") +public class VPPAppReleaseWrapper { + + @ApiModelProperty(name = "description", + value = "Description of the VPP app release") + @NotNull + private String description; + + @ApiModelProperty(name = "releaseType", + value = "Release type of the VPP app release", + required = true, + example = "alpha, beta etc") + @NotNull + private String releaseType; + + @ApiModelProperty(name = "price", + value = "Price of the VPP app release", + required = true) + private Double price; + + @ApiModelProperty(name = "isSharedWithAllTenants", + value = "If VPP app release is shared with all tenants it is equal to 1 otherwise 0", + required = true) + @NotNull + private boolean isSharedWithAllTenants; + + @ApiModelProperty(name = "metaData", + value = "Meta data of the VPP app release", + required = true) + private String metaData; + + @ApiModelProperty(name = "version", + value = "Version of the VPP app release.", + required = true) + @NotNull + private String version; + + @ApiModelProperty(name = "packageName", + value = "Package name of the VPP app release.", + required = true) + @NotNull + private String packageName; + + @ApiModelProperty(name = "supportedOsVersions", + value = "Application release supported OS versions", + required = true, + example = "4.0-10.0") + @NotNull + private String supportedOsVersions; + + @ApiModelProperty(name = "smallIconName", + value = "icon file location", + required = true) + @NotNull + private String smallIconName; + + @ApiModelProperty(name = "largeIconName", + value = "icon file location", + required = true) + @NotNull + private String largeIconName; + + @ApiModelProperty(name = "installerName", + value = "VPP app URL", + required = true) + @NotNull + private String installerName; + + @ApiModelProperty(name = "ratedUsers", + value = "Number of users who has rated the application release") + private int ratedUsers; + + @ApiModelProperty(name = "rating", + value = "Rating value of the application release") + private double rating; + + public String getReleaseType() { + return releaseType; + } + + public void setReleaseType(String releaseType) { + this.releaseType = releaseType; + } + + public void setIsSharedWithAllTenants(boolean isSharedWithAllTenants) { + this.isSharedWithAllTenants = isSharedWithAllTenants; + } + + public String getSmallIconName() { + return smallIconName; + } + + public void setSmallIconName(String smallIconName) { + this.smallIconName = smallIconName; + } + + public String getLargeIconName() { + return largeIconName; + } + + public void setLargeIconName(String largeIconName) { + this.largeIconName = largeIconName; + } + + public String getInstallerName() { + return installerName; + } + + public void setInstallerName(String installerName) { + this.installerName = installerName; + } + + public int getRatedUsers() { + return ratedUsers; + } + + public void setRatedUsers(int ratedUsers) { + this.ratedUsers = ratedUsers; + } + + public double getRating() { + return rating; + } + + public void setRating(double rating) { + this.rating = rating; + } + + public void setMetaData(String metaData) { + this.metaData = metaData; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } + + public boolean getIsSharedWithAllTenants() { + return isSharedWithAllTenants; + } + + public String getMetaData() { + return metaData; + } + + public String getDescription() { return description; } + + public void setDescription(String description) { this.description = description; } + + public boolean isSharedWithAllTenants() { return isSharedWithAllTenants; } + + public void setSharedWithAllTenants(boolean sharedWithAllTenants) { isSharedWithAllTenants = sharedWithAllTenants; } + + public String getVersion() { return version; } + + public void setVersion(String version) { this.version = version; } + + public String getPackageName() { return packageName; } + + public void setPackageName(String packageName) { this.packageName = packageName; } + + public String getSupportedOsVersions() { return supportedOsVersions; } + + public void setSupportedOsVersions(String supportedOsVersions) { this.supportedOsVersions = supportedOsVersions; } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/VPPAppWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/VPPAppWrapper.java new file mode 100644 index 0000000000..152efa34a1 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/VPPAppWrapper.java @@ -0,0 +1,152 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.device.application.mgt.common.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; +import java.util.List; + +@ApiModel(value = "VPPAppWrapper", description = "VPPAppWrapper represents an Application in App Store") +public class VPPAppWrapper { + + @ApiModelProperty(name = "adamId", + value = "The unique identifier for a product in the iTunes Store", + required = true) + @NotNull + private String adamId; + + @ApiModelProperty(name = "name", + value = "Name of the VPP app", + required = true) + @NotNull + private String name; + + @ApiModelProperty(name = "deviceType", + value = "Related device type of the public app", + required = true, + example = "IoS, Android, Arduino, RaspberryPi etc") + @NotNull + private String deviceType; + + @ApiModelProperty(name = "description", + value = "Description of the VPP app", + required = true) + @NotNull + private String description; + + @ApiModelProperty(name = "categories", + value = "List of Categories", + required = true, + example = "Educational, Gaming, Travel, Entertainment etc") + @NotNull + private List categories; + + @ApiModelProperty(name = "subType", + value = "Subscription method of the VPP app", + required = true, + example = "PAID, FREE") + @NotNull + private String subMethod; + + @ApiModelProperty(name = "paymentCurrency", + value = "Payment currency of the VPP app", + required = true, + example = "$") + private String paymentCurrency; + + @ApiModelProperty(name = "tags", + value = "List of tags") + @NotNull + private List tags; + + @ApiModelProperty(name = "unrestrictedRoles", + value = "List of roles that users should have to view the VPP app") + @NotNull + private List unrestrictedRoles; + + @ApiModelProperty(name = "applicationReleaseWrappers", + value = "List of VPP app releases", + required = true) + @NotNull + private List vppAppReleaseWrappers; + + @ApiModelProperty(name = "rating", + value = "Rating value of the application release") + private double rating; + + public String getName() { + return name; + } + + public void setName(String name) { this.name = name; } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getAdamId() { + return adamId; + } + + public void setAdamId(String adamId) { + this.adamId = adamId; + } + + public double getRating() { + return rating; + } + + public void setRating(double rating) { + this.rating = rating; + } + + public List getTags() { return tags; } + + public void setTags(List tags) { this.tags = tags; } + + public String getPaymentCurrency() { return paymentCurrency; } + + public void setPaymentCurrency(String paymentCurrency) { this.paymentCurrency = paymentCurrency; } + + public List getUnrestrictedRoles() { return unrestrictedRoles; } + + public void setUnrestrictedRoles(List unrestrictedRoles) { this.unrestrictedRoles = unrestrictedRoles; } + + public String getDescription() { return description; } + + public void setDescription(String description) { this.description = description; } + + public List getVppAppReleaseWrappers() { return vppAppReleaseWrappers; } + + public void setVppAppReleaseWrappers(List vppAppReleaseWrappers) { + this.vppAppReleaseWrappers = vppAppReleaseWrappers; } + + public List getCategories() { return categories; } + + public void setCategories(List categories) { this.categories = categories; } + + public String getSubMethod() { return subMethod; } + + public void setSubMethod(String subMethod) { this.subMethod = subMethod; } +} + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index df79c04ccc..1bfd5a9bf9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -63,8 +63,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "TYPE, " + "SUB_TYPE, " + "TENANT_ID, " - + "DEVICE_TYPE_ID," - + "ADAM_ID) VALUES (?, ?, ?, ?, ?, ?, ?)"; + + "DEVICE_TYPE_ID, " + + "RATING, " + + "ADAM_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; int applicationId = -1; try { Connection conn = this.getDBConnection(); @@ -75,11 +76,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic stmt.setString(4, applicationDTO.getSubType()); stmt.setInt(5, tenantId); stmt.setInt(6, applicationDTO.getDeviceTypeId()); - if(!StringUtils.isEmpty(applicationDTO.getAdamId())){ - stmt.setString(7, applicationDTO.getAdamId()); - } else{ - stmt.setString(7, null); - } + stmt.setDouble(7, applicationDTO.getAppRating()); + stmt.setString(8, applicationDTO.getAdamId()); stmt.executeUpdate(); try (ResultSet rs = stmt.getGeneratedKeys()) { if (rs.next()) { @@ -402,6 +400,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.RATING AS APP_RATING, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP.ADAM_ID AS APP_ADAM_ID, " + "AP_APP_RELEASE.ID AS RELEASE_ID, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " @@ -475,6 +474,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.RATING AS APP_RATING, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP.ADAM_ID AS APP_ADAM_ID, " + "AP_APP_RELEASE.ID AS RELEASE_ID, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " @@ -552,6 +552,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.RATING AS APP_RATING, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP.ADAM_ID AS APP_ADAM_ID, " + "AP_APP_RELEASE.ID AS RELEASE_ID, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " @@ -622,6 +623,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "AP_APP.CURRENCY AS APP_CURRENCY, " + "AP_APP.RATING AS APP_RATING, " + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP.ADAM_ID AS APP_ADAM_ID, " + "AP_APP_RELEASE.ID AS RELEASE_ID, " + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java index ffe45ba3d3..da74f67597 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java @@ -66,8 +66,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements + "APP_META_INFO," + "SUPPORTED_OS_VERSIONS," + "CURRENT_STATE," + + "RATING," + + "RATED_USERS," + "AP_APP_ID) " - + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; try { Connection connection = this.getDBConnection(); @@ -90,7 +92,9 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements statement.setString(16, applicationReleaseDTO.getMetaData()); statement.setString(17, applicationReleaseDTO.getSupportedOsVersions()); statement.setString(18, applicationReleaseDTO.getCurrentState().toUpperCase()); - statement.setInt(19, appId); + statement.setDouble(19, applicationReleaseDTO.getRating()); + statement.setInt(20, applicationReleaseDTO.getRatedUsers()); + statement.setInt(21, appId); statement.executeUpdate(); try(ResultSet resultSet = statement.getGeneratedKeys()){ if (resultSet.next()) { 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 bbcb126409..7406aba633 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 @@ -63,6 +63,8 @@ import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWr import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.VPPAppReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.VPPAppWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; @@ -232,6 +234,42 @@ public class ApplicationManagerImpl implements ApplicationManager { return addAppDataIntoDB(applicationDTO, tenantId); } + @Override + public Application createVPPApp(VPPAppWrapper vppAppWrapper) + throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + + if (log.isDebugEnabled()) { + log.debug("VPP app creating request is received. App name: " + vppAppWrapper.getName() + + " Adam ID: " + vppAppWrapper.getAdamId()); + } + ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(vppAppWrapper); + ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); + applicationReleaseDTO.setUuid(UUID.randomUUID().toString()); + applicationReleaseDTO.setAppHashValue(DigestUtils.md5Hex(applicationReleaseDTO.getPackageName())); + + try { + ConnectionManagerUtil.openDBConnection(); + List exitingPubAppReleases = applicationReleaseDAO + .getReleaseByPackages(Collections.singletonList(applicationReleaseDTO.getPackageName()), tenantId); + if (!exitingPubAppReleases.isEmpty()) { + String msg = "VPP app release exists for package name " + applicationReleaseDTO.getPackageName() + + ". Hence you can't add new VPP app for package name " + + applicationReleaseDTO.getPackageName(); + log.error(msg); + throw new BadRequestException(msg); + } + } catch (ApplicationManagementDAOException e) { + String msg = "Error Occurred when fetching release: " + vppAppWrapper.getName(); + log.error(msg); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + //insert application data into database + return addAppDataIntoDB(applicationDTO, tenantId); + } + @Override public Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { @@ -3186,6 +3224,48 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new BadRequestException(msg); } unrestrictedRoles = publicAppWrapper.getUnrestrictedRoles(); + } else if (param instanceof VPPAppWrapper) { + VPPAppWrapper vppAppWrapper = (VPPAppWrapper) param; + appName = vppAppWrapper.getName(); + if (StringUtils.isEmpty(appName)) { + String msg = "Application name cannot be empty for VPP app."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(vppAppWrapper.getAdamId())) { + String msg = "Adam ID cannot be empty for VPP Asset."; + log.error(msg); + throw new BadRequestException(msg); + } + appCategories = vppAppWrapper.getCategories(); + if (appCategories == null) { + String msg = "Application category can't be null."; + log.error(msg); + throw new BadRequestException(msg); + } + if (appCategories.isEmpty()) { + String msg = "Application category can't be empty."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(vppAppWrapper.getDeviceType())) { + String msg = "Device type can't be empty for the VPP application."; + log.error(msg); + throw new BadRequestException(msg); + } + DeviceType deviceType = APIUtil.getDeviceTypeData(vppAppWrapper.getDeviceType()); + deviceTypeId = deviceType.getId(); + + List vppAppReleaseWrappers; + vppAppReleaseWrappers = vppAppWrapper.getVppAppReleaseWrappers(); + + if (vppAppReleaseWrappers == null || vppAppReleaseWrappers.size() != 1) { + String msg = "Invalid VPP app creating request. Request must have single release. Application name:" + + vppAppWrapper.getName() + "Adam ID: " + vppAppWrapper.getAdamId() + "."; + log.error(msg); + throw new BadRequestException(msg); + } + unrestrictedRoles = vppAppWrapper.getUnrestrictedRoles(); } else if (param instanceof CustomAppWrapper) { CustomAppWrapper customAppWrapper = (CustomAppWrapper) param; appName = customAppWrapper.getName(); @@ -3366,6 +3446,45 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } + } else if (param instanceof VPPAppReleaseWrapper) { + VPPAppReleaseWrapper vppAppReleaseWrapper = (VPPAppReleaseWrapper) param; + if (StringUtils.isEmpty(vppAppReleaseWrapper.getSupportedOsVersions())) { + String msg = "Supported OS Version shouldn't be null or empty for VPP app release creating request."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(vppAppReleaseWrapper.getVersion())) { + String msg = "Version shouldn't be empty or null for the VPP App release creating request."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(vppAppReleaseWrapper.getPackageName())) { + String msg = "Package name shouldn't be empty or null for the VPP App release creating request."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(vppAppReleaseWrapper.getInstallerName())) { + String msg = "Installer name name shouldn't be empty or null for the VPP App release creating request."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(vppAppReleaseWrapper.getSmallIconName())) { + String msg = "Small Icon shouldn't be empty or null for the VPP App release creating request."; + log.error(msg); + throw new BadRequestException(msg); + } + if (StringUtils.isEmpty(vppAppReleaseWrapper.getLargeIconName())) { + String msg = "Large Icon shouldn't be empty or null for the VPP App release creating request."; + log.error(msg); + throw new BadRequestException(msg); + } + if (isInvalidOsVersionRange(vppAppReleaseWrapper.getSupportedOsVersions(), deviceType)) { + String msg = "You are trying to create application which has an application release contains invalid or " + + "unsupported OS versions in the supportedOsVersions section. Hence, please re-evaluate the " + + "request payload."; + log.error(msg); + throw new BadRequestException(msg); + } } else if (param instanceof CustomAppReleaseWrapper) { CustomAppReleaseWrapper customAppReleaseWrapper = (CustomAppReleaseWrapper) param; if (StringUtils.isEmpty(customAppReleaseWrapper.getVersion())) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index 12d28191b7..779b46435a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -40,6 +40,8 @@ import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppReleaseWra import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.VPPAppReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.VPPAppWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; @@ -275,6 +277,23 @@ public class APIUtil { List applicationReleaseEntities = publicAppWrapper.getPublicAppReleaseWrappers() .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); + } else if (param instanceof VPPAppWrapper) { + VPPAppWrapper vppAppWrapper = (VPPAppWrapper) param; + DeviceType deviceType = getDeviceTypeData(vppAppWrapper.getDeviceType()); + applicationDTO.setAdamId(vppAppWrapper.getAdamId()); + applicationDTO.setName(vppAppWrapper.getName()); + applicationDTO.setDescription(vppAppWrapper.getDescription()); + applicationDTO.setAppCategories(vppAppWrapper.getCategories()); + applicationDTO.setType(ApplicationType.PUBLIC.toString()); + applicationDTO.setSubType(vppAppWrapper.getSubMethod()); + applicationDTO.setPaymentCurrency(vppAppWrapper.getPaymentCurrency()); + applicationDTO.setTags(vppAppWrapper.getTags()); + applicationDTO.setUnrestrictedRoles(vppAppWrapper.getUnrestrictedRoles()); + applicationDTO.setDeviceTypeId(deviceType.getId()); + applicationDTO.setAppRating(vppAppWrapper.getRating()); + List applicationReleaseEntities = vppAppWrapper.getVppAppReleaseWrappers() + .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); + applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); } else if (param instanceof CustomAppWrapper){ CustomAppWrapper customAppWrapper = (CustomAppWrapper) param; DeviceType deviceType = getDeviceTypeData(customAppWrapper.getDeviceType()); @@ -325,6 +344,21 @@ public class APIUtil { applicationReleaseDTO.setIsSharedWithAllTenants(publicAppReleaseWrapper.getIsSharedWithAllTenants()); applicationReleaseDTO.setMetaData(publicAppReleaseWrapper.getMetaData()); applicationReleaseDTO.setSupportedOsVersions(publicAppReleaseWrapper.getSupportedOsVersions()); + } else if (param instanceof VPPAppReleaseWrapper) { + VPPAppReleaseWrapper vppAppReleaseWrapper = (VPPAppReleaseWrapper) param; + applicationReleaseDTO.setDescription(vppAppReleaseWrapper.getDescription()); + applicationReleaseDTO.setReleaseType(vppAppReleaseWrapper.getReleaseType()); + applicationReleaseDTO.setVersion(vppAppReleaseWrapper.getVersion()); + applicationReleaseDTO.setPackageName(vppAppReleaseWrapper.getPackageName()); + applicationReleaseDTO.setPrice(vppAppReleaseWrapper.getPrice()); + applicationReleaseDTO.setIsSharedWithAllTenants(vppAppReleaseWrapper.getIsSharedWithAllTenants()); + applicationReleaseDTO.setMetaData(vppAppReleaseWrapper.getMetaData()); + applicationReleaseDTO.setSupportedOsVersions(vppAppReleaseWrapper.getSupportedOsVersions()); + applicationReleaseDTO.setIconName(vppAppReleaseWrapper.getSmallIconName()); + applicationReleaseDTO.setScreenshotName1(vppAppReleaseWrapper.getSmallIconName()); + applicationReleaseDTO.setInstallerName(vppAppReleaseWrapper.getInstallerName()); + applicationReleaseDTO.setRatedUsers(vppAppReleaseWrapper.getRatedUsers()); + applicationReleaseDTO.setRating(vppAppReleaseWrapper.getRating()); } else if (param instanceof CustomAppReleaseWrapper) { CustomAppReleaseWrapper customAppReleaseWrapper = (CustomAppReleaseWrapper) param; applicationReleaseDTO.setDescription(customAppReleaseWrapper.getDescription()); @@ -363,6 +397,9 @@ public class APIUtil { .contains("GooglePlaySyncedApp")) { application.setAndroidEnterpriseApp(true); } + if (!StringUtils.isEmpty(applicationDTO.getAdamId())) { + application.setAdamId(applicationDTO.getAdamId()); + } for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) { applicationReleases.add(releaseDtoToRelease(applicationReleaseDTO)); }