Merge branch 'application-mgt' of https://github.com/wso2/carbon-device-mgt into application-mgt

merge-requests/7/head
amalhub 7 years ago
commit e54ab93d15

@ -46,6 +46,8 @@ public class Filter {
private String sortBy;
private String userName;
public int getLimit() {
return limit;
}
@ -102,6 +104,14 @@ public class Filter {
this.sortBy = sortBy;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public boolean hasCondition() {
if (filterProperties != null || searchQuery != null || filter != null) {
return true;
@ -109,5 +119,4 @@ public class Filter {
return false;
}
}

@ -37,7 +37,7 @@ public interface ApplicationDAO {
ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException;
Application getApplication(String uuid, int tenantId) throws ApplicationManagementDAOException;
Application getApplication(String uuid, int tenantId, String userName) throws ApplicationManagementDAOException;
int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException;

@ -60,6 +60,7 @@ public class DAOFactory {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new GenericApplicationDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
@ -90,6 +91,7 @@ public class DAOFactory {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new GenericLifecycleStateImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
@ -107,6 +109,7 @@ public class DAOFactory {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new GenericApplicationReleaseDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);

@ -140,18 +140,27 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "APP.APPLICATION_CATEGORY_ID = CAT.ID INNER JOIN APPM_LIFECYCLE_STATE AS "
+ "LS ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ? ";
String userName = filter.getUserName();
if (!userName.equals("ALL")) {
sql += " AND APP.CREATED_BY = ? ";
}
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
sql += "AND APP.NAME LIKE ? ";
}
sql += "LIMIT ?,?;";
sql += "LIMIT ? OFFSET ?;";
stmt = conn.prepareStatement(sql);
stmt.setInt(++index, tenantId);
if (!userName.equals("ALL")) {
stmt.setString(++index, userName);
}
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
stmt.setString(++index, "%" + filter.getSearchQuery() + "%");
}
stmt.setInt(++index, filter.getOffset());
stmt.setInt(++index, filter.getLimit());
stmt.setInt(++index, filter.getOffset());
rs = stmt.executeQuery();
@ -244,7 +253,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
@Override
public Application getApplication(String uuid, int tenantId) throws ApplicationManagementDAOException {
public Application getApplication(String uuid, int tenantId, String userName) throws
ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting application with the UUID(" + uuid + ") from the database");
}
@ -261,11 +271,17 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS "
+ "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON "
+ "APP.APPLICATION_CATEGORY_ID = CAT.ID INNER JOIN APPM_LIFECYCLE_STATE AS "
+ "LS ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE UUID = ? AND APP.TENANT_ID = ?";
+ "LS ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE UUID = ? AND APP.TENANT_ID = ? ";
stmt = conn.prepareStatement(sql);
stmt.setString(1, uuid);
stmt.setInt(2, tenantId);
if (!userName.equals("ALL")) {
sql += "AND APP.CREATED_BY = ?";
stmt.setString(3, userName);
}
rs = stmt.executeQuery();
if (log.isDebugEnabled()) {
@ -409,26 +425,26 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
try {
conn = this.getDBConnection();
int index = 0;
sql += "UPDATE APPM_APPLICATION SET NAME = IFNULL (?, NAME), SHORT_DESCRIPTION = IFNULL "
+ "(?, SHORT_DESCRIPTION), DESCRIPTION = IFNULL (?, DESCRIPTION), SCREEN_SHOT_COUNT = IFNULL (?, "
+ "SCREEN_SHOT_COUNT), VIDEO_NAME = IFNULL (?, VIDEO_NAME), "
+ "MODIFIED_AT = IFNULL (?, MODIFIED_AT), ";
sql += "UPDATE APPM_APPLICATION SET NAME = COALESCE (?, NAME), SHORT_DESCRIPTION = COALESCE "
+ "(?, SHORT_DESCRIPTION), DESCRIPTION = COALESCE (?, DESCRIPTION), SCREEN_SHOT_COUNT = "
+ "COALESCE (?, SCREEN_SHOT_COUNT), VIDEO_NAME = COALESCE (?, VIDEO_NAME), MODIFIED_AT = COALESCE "
+ "(?, MODIFIED_AT), ";
if (application.getPayment() != null) {
sql += " IS_FREE = IFNULL (?, IS_FREE), ";
sql += " IS_FREE = COALESCE (?, IS_FREE), ";
if (application.getPayment().getPaymentCurrency() != null) {
sql += "PAYMENT_CURRENCY = IFNULL (?, PAYMENT_CURRENCY), ";
sql += "PAYMENT_CURRENCY = COALESCE (?, PAYMENT_CURRENCY), ";
}
sql += "PAYMENT_PRICE = IFNULL (?, PAYMENT_PRICE), ";
sql += "PAYMENT_PRICE = COALESCE (?, PAYMENT_PRICE), ";
}
if (application.getCategory() != null && application.getCategory().getId() != 0) {
sql += "APPLICATION_CATEGORY_ID = IFNULL (?, APPLICATION_CATEGORY_ID), ";
sql += "APPLICATION_CATEGORY_ID = COALESCE (?, APPLICATION_CATEGORY_ID), ";
}
if (application.getPlatform() != null && application.getPlatform().getId() != 0) {
sql += "PLATFORM_ID = IFNULL (?, PLATFORM_ID), ";
sql += "PLATFORM_ID = COALESCE (?, PLATFORM_ID), ";
}
sql += "TENANT_ID = IFNULL (?, TENANT_ID) WHERE UUID = ?";
sql += "TENANT_ID = COALESCE (?, TENANT_ID) WHERE UUID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(++index, application.getName());

@ -174,6 +174,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try {
if (isAuthorized(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
userName = "ALL";
}
} catch (UserStoreException e) {
throw new ApplicationManagementException("User-store exception while checking whether the user " +
userName + " of tenant " + tenantId + " has the publisher permission");
}
filter.setUserName(userName);
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
@ -278,9 +290,19 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override
public Application getApplication(String uuid) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try {
if (isAuthorized(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
userName = "ALL";
}
} catch (UserStoreException e) {
throw new ApplicationManagementException(
"User-store exception while getting application with the UUID " + uuid);
}
try {
ConnectionManagerUtil.openDBConnection();
return DAOFactory.getApplicationDAO().getApplication(uuid, tenantId);
return DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -304,7 +326,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
try {
ConnectionManagerUtil.openDBConnection();
Application application = DAOFactory.getApplicationDAO().getApplication(applicationUUID, tenantId);
Application application = DAOFactory.getApplicationDAO()
.getApplication(applicationUUID, tenantId, userName);
return application.getUser().getUserName().equals(userName)
&& application.getUser().getTenantId() == tenantId;
} finally {

@ -41,4 +41,206 @@ FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE,
PRIMARY KEY (ID, TENANT_ID, PLATFORM_ID)
);
CREATE INDEX FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC);
CREATE INDEX FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC);
DROP TABLE IF EXISTS APPM_APPLICATION_CATEGORY;
DROP SEQUENCE IF EXISTS APPM_APPLICATION_CATEGORY_PK_SEQ;
CREATE SEQUENCE APPM_APPLICATION_CATEGORY_PK_SEQ;
CREATE TABLE IF NOT EXISTS APPM_APPLICATION_CATEGORY (
ID INT DEFAULT NEXTVAL('APPM_APPLICATION_CATEGORY_PK_SEQ'),
NAME VARCHAR(100) NOT NULL,
DESCRIPTION TEXT NULL,
PUBLISHED BOOLEAN DEFAULT FALSE,
PRIMARY KEY (ID));
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION, PUBLISHED) VALUES ('Enterprise', 'Enterprise level
applications which the artifacts need to be provided', TRUE);
INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION, PUBLISHED) VALUES ('Public', 'Public category in which the
application need to be downloaded from the public application store', TRUE);
DROP TABLE IF EXISTS APPM_LIFECYCLE_STATE;
DROP SEQUENCE IF EXISTS APPM_LIFECYCLE_STATE_PK_SEQ;
CREATE SEQUENCE APPM_LIFECYCLE_STATE_PK_SEQ;
-- -----------------------------------------------------
-- Table APPM_LIFECYCLE_STATE
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS APPM_LIFECYCLE_STATE (
ID INT DEFAULT NEXTVAL('APPM_LIFECYCLE_STATE_PK_SEQ'),
NAME VARCHAR(100) NOT NULL,
IDENTIFIER VARCHAR(100) NOT NULL,
DESCRIPTION TEXT NULL,
PRIMARY KEY (ID));
DROP INDEX IF EXISTS APPM_LIFECYCLE_STATE_IDENTIFIER_UNIQUE;
CREATE INDEX APPM_LIFECYCLE_STATE_IDENTIFIER_UNIQUE ON APPM_LIFECYCLE_STATE(IDENTIFIER ASC);
INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION) VALUES ('CREATED', 'CREATED', 'Application creation
initial state');
INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION)
VALUES ('IN REVIEW', 'IN REVIEW', 'Application is in in-review state');
INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION)
VALUES ('APPROVED', 'APPROVED', 'State in which Application is approved after reviewing.');
INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION)
VALUES ('REJECTED', 'REJECTED', 'State in which Application is rejected after reviewing.');
INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION)
VALUES ('PUBLISHED', 'PUBLISHED', 'State in which Application is in published state.');
INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION)
VALUES ('UNPUBLISHED', 'UNPUBLISHED', 'State in which Application is in un published state.');
INSERT INTO APPM_LIFECYCLE_STATE (NAME, IDENTIFIER, DESCRIPTION)
VALUES ('RETIRED', 'RETIRED', 'Retiring an application to indicate end of life state,');
DROP TABLE IF EXISTS APPM_LIFECYCLE_STATE_TRANSITION;
DROP SEQUENCE IF EXISTS APPM_LIFECYCLE_STATE_TRANSITION_PK_SEQ;
CREATE SEQUENCE APPM_LIFECYCLE_STATE_TRANSITION_PK_SEQ;
CREATE TABLE IF NOT EXISTS APPM_LIFECYCLE_STATE_TRANSITION
(
ID INT DEFAULT NEXTVAL('APPM_LIFECYCLE_STATE_TRANSITION_PK_SEQ'),
INITIAL_STATE INT,
NEXT_STATE INT,
PERMISSION VARCHAR(1024),
DESCRIPTION VARCHAR(2048),
PRIMARY KEY (INITIAL_STATE, NEXT_STATE),
FOREIGN KEY (INITIAL_STATE) REFERENCES APPM_LIFECYCLE_STATE(ID) ON DELETE CASCADE,
FOREIGN KEY (NEXT_STATE) REFERENCES APPM_LIFECYCLE_STATE(ID) ON DELETE CASCADE
);
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(1, 2, null, 'Submit for review');
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(2, 1, null, 'Revoke from review');
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(2, 3, '/permission/admin/manage/device-mgt/application/review', 'APPROVE');
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(2, 4, '/permission/admin/manage/device-mgt/application/review', 'REJECT');
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(3, 4, '/permission/admin/manage/device-mgt/application/review', 'REJECT');
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(3, 5, null, 'PUBLISH');
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(5, 6, null, 'UN PUBLISH');
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(6, 5, null, 'PUBLISH');
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(4, 1, null, 'Return to CREATE STATE');
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(6, 1, null, 'Return to CREATE STATE');
INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESCRIPTION) VALUES
(6, 7, null, 'Retire');
DROP TABLE IF EXISTS APPM_APPLICATION;
DROP SEQUENCE IF EXISTS APPM_APPLICATION_PK_SEQ;
CREATE SEQUENCE APPM_APPLICATION_PK_SEQ;
CREATE TABLE IF NOT EXISTS APPM_APPLICATION (
ID INT DEFAULT NEXTVAL('APPM_APPLICATION_PK_SEQ') UNIQUE,
UUID VARCHAR(100) NOT NULL,
IDENTIFIER VARCHAR(255) NULL,
NAME VARCHAR(100) NOT NULL,
SHORT_DESCRIPTION VARCHAR(255) NULL,
DESCRIPTION TEXT NULL,
SCREEN_SHOT_COUNT INT DEFAULT 0,
VIDEO_NAME VARCHAR(100) NULL,
CREATED_BY VARCHAR(255) NULL,
CREATED_AT TIMESTAMP NOT NULL,
MODIFIED_AT TIMESTAMP NULL,
IS_FREE BOOLEAN DEFAULT TRUE,
PAYMENT_CURRENCY VARCHAR(45) NULL,
PAYMENT_PRICE DECIMAL(10,2) NULL,
APPLICATION_CATEGORY_ID INT NOT NULL,
LIFECYCLE_STATE_ID INT NOT NULL,
LIFECYCLE_STATE_MODIFIED_BY VARCHAR(255) NULL,
LIFECYCLE_STATE_MODIFIED_AT TIMESTAMP NULL,
TENANT_ID INT NOT NULL,
PLATFORM_ID INT NOT NULL,
PRIMARY KEY (ID, APPLICATION_CATEGORY_ID, LIFECYCLE_STATE_ID, PLATFORM_ID),
FOREIGN KEY (APPLICATION_CATEGORY_ID)
REFERENCES APPM_APPLICATION_CATEGORY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_APPM_APPLICATION_APPM_LIFECYCLE_STATE1
FOREIGN KEY (LIFECYCLE_STATE_ID)
REFERENCES APPM_LIFECYCLE_STATE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_APPM_APPLICATION_APPM_PLATFORM1
FOREIGN KEY (PLATFORM_ID)
REFERENCES APPM_PLATFORM (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE INDEX IF NOT EXISTS FK_APPLICATION_APPLICATION_CATEGORY ON APPM_APPLICATION(APPLICATION_CATEGORY_ID ASC);
CREATE INDEX IF NOT EXISTS UK_APPLICATION_UUID ON APPM_APPLICATION(UUID ASC);
DROP TABLE IF EXISTS APPM_APPLICATION_PROPERTY;
-- -----------------------------------------------------
-- Table APPM_APPLICATION_PROPERTY
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS APPM_APPLICATION_PROPERTY (
PROP_KEY VARCHAR(255) NOT NULL,
PROP_VAL TEXT NULL,
APPLICATION_ID INT NOT NULL,
PRIMARY KEY (PROP_KEY, APPLICATION_ID),
CONSTRAINT FK_APPLICATION_PROPERTY_APPLICATION
FOREIGN KEY (APPLICATION_ID)
REFERENCES APPM_APPLICATION (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE INDEX FK_APPLICATION_PROPERTY_APPLICATION ON APPM_APPLICATION_PROPERTY(APPLICATION_ID ASC);
CREATE TABLE IF NOT EXISTS APPM_APPLICATION_TAG (
NAME VARCHAR(45) NOT NULL,
APPLICATION_ID INT NOT NULL,
PRIMARY KEY (APPLICATION_ID, NAME),
CONSTRAINT fk_APPM_APPLICATION_TAG_APPM_APPLICATION1
FOREIGN KEY (APPLICATION_ID)
REFERENCES APPM_APPLICATION (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE INDEX IF NOT EXISTS FK_APPLICATION_TAG_APPLICATION ON APPM_APPLICATION_TAG(APPLICATION_ID ASC);
DROP TABLE IF EXISTS APPM_APPLICATION_RELEASE;
DROP SEQUENCE IF EXISTS APPM_APPLICATION_RELEASE_PK_SEQ;
CREATE SEQUENCE APPM_APPLICATION_RELEASE_PK_SEQ;
-- -----------------------------------------------------
-- Table APPM_APPLICATION_RELEASE
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS APPM_APPLICATION_RELEASE (
ID INT DEFAULT NEXTVAL('APPM_APPLICATION_RELEASE_PK_SEQ') UNIQUE,
VERSION_NAME VARCHAR(100) NOT NULL,
RESOURCE TEXT NULL,
RELEASE_CHANNEL VARCHAR(50) DEFAULT 'ALPHA',
RELEASE_DETAILS TEXT NULL,
CREATED_AT TIMESTAMP NOT NULL,
APPM_APPLICATION_ID INT NOT NULL,
IS_DEFAULT BOOLEAN DEFAULT FALSE,
PRIMARY KEY (APPM_APPLICATION_ID, VERSION_NAME),
CONSTRAINT FK_APPLICATION_VERSION_APPLICATION
FOREIGN KEY (APPM_APPLICATION_ID)
REFERENCES APPM_APPLICATION (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE INDEX FK_APPLICATION_VERSION_APPLICATION ON APPM_APPLICATION_RELEASE(APPM_APPLICATION_ID ASC);
DROP TABLE IF EXISTS APPM_RELEASE_PROPERTY;
-- -----------------------------------------------------
-- Table APPM_RELEASE_PROPERTY
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS APPM_RELEASE_PROPERTY (
PROP_KEY VARCHAR(255) NOT NULL,
PROP_VALUE TEXT NULL,
APPLICATION_RELEASE_ID INT NOT NULL,
PRIMARY KEY (PROP_KEY, APPLICATION_RELEASE_ID),
CONSTRAINT FK_RELEASE_PROPERTY_APPLICATION_RELEASE
FOREIGN KEY (APPLICATION_RELEASE_ID)
REFERENCES APPM_APPLICATION_RELEASE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE INDEX FK_RELEASE_PROPERTY_APPLICATION_RELEASE ON APPM_RELEASE_PROPERTY(APPLICATION_RELEASE_ID ASC);

Loading…
Cancel
Save