Add VPP DAOs

vpp^2
amanda 5 years ago
parent a73ec67485
commit 008b24dc37

@ -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<LicenseDTO> licenses;
public String getAdamId() {
return adamId;
}
@ -108,6 +112,14 @@ public class ApplicationDTO {
this.adamId = adamId;
}
public List<LicenseDTO> getLicenses() {
return licenses;
}
public void setLicenses(List<LicenseDTO> licenses) {
this.licenses = licenses;
}
public String getPackageName() {
return packageName;
}

@ -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;
}
}

@ -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;
}
}

@ -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<LicenseDTO> licenses, int tenantId) throws ApplicationManagementDAOException;
/**
* To add tags for a particular application.
*

@ -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<ApplicationDTO> 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<LicenseDTO> 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<TagDTO> getAllTags(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {

@ -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<TagDTO> registeredTags = applicationDAO.getAllTags(tenantId);

@ -168,6 +168,7 @@
<Category>Video Players &amp; Editors</Category>
<Category>Weather</Category>
<Category>GooglePlaySyncedApp</Category>
<Category>LicensedVPPAssets</Category>
</AppCategories>
<RatingConfig>

@ -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

Loading…
Cancel
Save