diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java index b9f1c933711..401611ea9a7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java @@ -74,8 +74,10 @@ public class Application { */ private List unrestrictedRoles; - //todo reomve this and get the idea from unrestrictefRoles list size - private int isRestricted; + /** + * If unrestricted roles are defined then isRestricted value is true otherwise it is false. + */ + private boolean isRestricted; /** * Related device type of the application. @@ -147,11 +149,11 @@ public class Application { this.paymentCurrency = paymentCurrency; } - public int getIsRestricted() { + public boolean getIsRestricted() { return isRestricted; } - public void setIsRestricted(int isRestricted) { + public void setIsRestricted(boolean isRestricted) { this.isRestricted = isRestricted; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java index b0fc1a89041..697b30a9af8 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java @@ -70,7 +70,7 @@ public class Util { application.setAppCategory(rs.getString("APP_CATEGORY")); application.setSubType(rs.getString("SUB_TYPE")); application.setPaymentCurrency(rs.getString("CURRENCY")); - application.setIsRestricted(rs.getInt("RESTRICTED")); + application.setIsRestricted(rs.getBoolean("RESTRICTED")); List tags = new ArrayList<>(); Tag tag = new Tag(); @@ -130,7 +130,7 @@ public class Util { application.setAppCategory(rs.getString("APP_CATEGORY")); application.setSubType(rs.getString("SUB_TYPE")); application.setPaymentCurrency(rs.getString("CURRENCY")); - application.setIsRestricted(rs.getInt("RESTRICTED")); + application.setIsRestricted(rs.getBoolean("RESTRICTED")); } Tag tag = new Tag(); 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 5ba7b98215e..e5e2153261c 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 @@ -65,17 +65,16 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic int applicationId = -1; try { conn = this.getDBConnection(); - stmt = conn.prepareStatement("INSERT INTO AP_APP (NAME, TYPE, APP_CATEGORY, SUB_TYPE, PAYMENT_CURRENCY, " - + "RESTRICTED, TENANT_ID, DM_DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", + stmt = conn.prepareStatement("INSERT INTO AP_APP (NAME, TYPE, APP_CATEGORY, SUB_TYPE, RESTRICTED, " + + "TENANT_ID, DM_DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, application.getName()); stmt.setString(2, application.getType()); stmt.setString(3, application.getAppCategory()); stmt.setString(4, application.getSubType()); - stmt.setString(5, application.getPaymentCurrency()); - stmt.setInt(6, application.getIsRestricted()); - stmt.setInt(7, application.getUser().getTenantId()); - stmt.setInt(8, deviceId); + stmt.setBoolean(5, application.getIsRestricted()); + stmt.setInt(6, application.getUser().getTenantId()); + stmt.setInt(7, deviceId); stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); @@ -136,8 +135,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic ApplicationList applicationList = new ApplicationList(); Pagination pagination = new Pagination(); String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY" - + - " AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, " + + " AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, " + "AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE " + "AS ROLE FROM ((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) " + "LEFT JOIN AP_UNRESTRICTED_ROLES ON AP_APP.ID = AP_UNRESTRICTED_ROLES.AP_APP_ID) " @@ -461,7 +459,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic stmt.setString(paramIndex++, application.getAppCategory()); } if (application.getIsRestricted() != existingApplication.getIsRestricted()) { - stmt.setInt(paramIndex++, application.getIsRestricted()); + stmt.setBoolean(paramIndex++, application.getIsRestricted()); } if (!application.getSubType().equals(existingApplication.getSubType())) { stmt.setString(paramIndex++, application.getSubType()); @@ -603,7 +601,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic application.setAppCategory(rs.getString("APP_CATEGORY")); application.setSubType(rs.getString("SUB_TYPE")); application.setPaymentCurrency(rs.getString("CURRENCY")); - application.setIsRestricted(rs.getInt("RESTRICTED")); + application.setIsRestricted(rs.getBoolean("RESTRICTED")); UnrestrictedRole unrestrictedRole = new UnrestrictedRole(); unrestrictedRole.setRole(rs.getString("ROLE")); 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 f5fa3ebe35b..2dfad505f27 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 @@ -60,8 +60,6 @@ import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.sql.Timestamp; -import java.util.Date; /** * Default Concrete implementation of Application Management related implementations. @@ -117,10 +115,11 @@ public class ApplicationManagerImpl implements ApplicationManager { if (!application.getTags().isEmpty()) { this.applicationDAO.addTags(application.getTags(), appId, tenantId); } - if (application.getIsRestricted() == 1 && !application.getUnrestrictedRoles().isEmpty()) { + if (!application.getUnrestrictedRoles().isEmpty()) { + application.setIsRestricted(true); this.visibilityDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), appId, tenantId); } else { - application.setIsRestricted(0); + application.setIsRestricted(false); } if (application.getApplicationReleases().size() > 1 ){ throw new ApplicationManagementException( @@ -858,14 +857,13 @@ public class ApplicationManagerImpl implements ApplicationManager { } } if (existingApplication.getIsRestricted() != application.getIsRestricted()) { - if (existingApplication.getIsRestricted() == 0 && existingApplication.getUnrestrictedRoles() == null) { + if (!existingApplication.getIsRestricted() && existingApplication.getUnrestrictedRoles() == null) { if (application.getUnrestrictedRoles() == null || application.getUnrestrictedRoles().isEmpty()) { throw new ApplicationManagementException("If you are going to add role restriction for non role " + "restricted Application, Unrestricted role list " + "won't be empty or null"); } visibilityDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), application.getId(), tenantId); - } else if (existingApplication.getIsRestricted() == 1 - && existingApplication.getUnrestrictedRoles() != null) { + } else if (existingApplication.getIsRestricted() && existingApplication.getUnrestrictedRoles() != null) { if (application.getUnrestrictedRoles() != null && !application.getUnrestrictedRoles().isEmpty()) { throw new ApplicationManagementException("If you are going to remove role restriction from role " + "restricted Application, Unrestricted role list should be empty or null"); @@ -874,7 +872,7 @@ public class ApplicationManagerImpl implements ApplicationManager { tenantId); } } else if (existingApplication.getIsRestricted() == application.getIsRestricted() - && existingApplication.getIsRestricted() == 1) { + && existingApplication.getIsRestricted()) { addingRoleList = getDifference(application.getUnrestrictedRoles(), existingApplication.getUnrestrictedRoles()); removingRoleList = getDifference(existingApplication.getUnrestrictedRoles(), diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index 4fe2e43298f..5609ba9c2ef 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -141,7 +141,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { attachments.add(screenshot.getDataHandler().getInputStream()); } - if (applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); }