Modify isRestricted data type

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 4316cb0ef4
commit 222225121c

@ -74,8 +74,10 @@ public class Application {
*/ */
private List<UnrestrictedRole> unrestrictedRoles; private List<UnrestrictedRole> 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. * Related device type of the application.
@ -147,11 +149,11 @@ public class Application {
this.paymentCurrency = paymentCurrency; this.paymentCurrency = paymentCurrency;
} }
public int getIsRestricted() { public boolean getIsRestricted() {
return isRestricted; return isRestricted;
} }
public void setIsRestricted(int isRestricted) { public void setIsRestricted(boolean isRestricted) {
this.isRestricted = isRestricted; this.isRestricted = isRestricted;
} }

@ -70,7 +70,7 @@ public class Util {
application.setAppCategory(rs.getString("APP_CATEGORY")); application.setAppCategory(rs.getString("APP_CATEGORY"));
application.setSubType(rs.getString("SUB_TYPE")); application.setSubType(rs.getString("SUB_TYPE"));
application.setPaymentCurrency(rs.getString("CURRENCY")); application.setPaymentCurrency(rs.getString("CURRENCY"));
application.setIsRestricted(rs.getInt("RESTRICTED")); application.setIsRestricted(rs.getBoolean("RESTRICTED"));
List<Tag> tags = new ArrayList<>(); List<Tag> tags = new ArrayList<>();
Tag tag = new Tag(); Tag tag = new Tag();
@ -130,7 +130,7 @@ public class Util {
application.setAppCategory(rs.getString("APP_CATEGORY")); application.setAppCategory(rs.getString("APP_CATEGORY"));
application.setSubType(rs.getString("SUB_TYPE")); application.setSubType(rs.getString("SUB_TYPE"));
application.setPaymentCurrency(rs.getString("CURRENCY")); application.setPaymentCurrency(rs.getString("CURRENCY"));
application.setIsRestricted(rs.getInt("RESTRICTED")); application.setIsRestricted(rs.getBoolean("RESTRICTED"));
} }
Tag tag = new Tag(); Tag tag = new Tag();

@ -65,17 +65,16 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
int applicationId = -1; int applicationId = -1;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
stmt = conn.prepareStatement("INSERT INTO AP_APP (NAME, TYPE, APP_CATEGORY, SUB_TYPE, PAYMENT_CURRENCY, " stmt = conn.prepareStatement("INSERT INTO AP_APP (NAME, TYPE, APP_CATEGORY, SUB_TYPE, RESTRICTED, "
+ "RESTRICTED, TENANT_ID, DM_DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", + "TENANT_ID, DM_DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
Statement.RETURN_GENERATED_KEYS); Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, application.getName()); stmt.setString(1, application.getName());
stmt.setString(2, application.getType()); stmt.setString(2, application.getType());
stmt.setString(3, application.getAppCategory()); stmt.setString(3, application.getAppCategory());
stmt.setString(4, application.getSubType()); stmt.setString(4, application.getSubType());
stmt.setString(5, application.getPaymentCurrency()); stmt.setBoolean(5, application.getIsRestricted());
stmt.setInt(6, application.getIsRestricted()); stmt.setInt(6, application.getUser().getTenantId());
stmt.setInt(7, application.getUser().getTenantId()); stmt.setInt(7, deviceId);
stmt.setInt(8, deviceId);
stmt.executeUpdate(); stmt.executeUpdate();
rs = stmt.getGeneratedKeys(); rs = stmt.getGeneratedKeys();
@ -136,8 +135,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
ApplicationList applicationList = new ApplicationList(); ApplicationList applicationList = new ApplicationList();
Pagination pagination = new Pagination(); 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" 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 " + "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) " + "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) " + "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()); stmt.setString(paramIndex++, application.getAppCategory());
} }
if (application.getIsRestricted() != existingApplication.getIsRestricted()) { if (application.getIsRestricted() != existingApplication.getIsRestricted()) {
stmt.setInt(paramIndex++, application.getIsRestricted()); stmt.setBoolean(paramIndex++, application.getIsRestricted());
} }
if (!application.getSubType().equals(existingApplication.getSubType())) { if (!application.getSubType().equals(existingApplication.getSubType())) {
stmt.setString(paramIndex++, application.getSubType()); stmt.setString(paramIndex++, application.getSubType());
@ -603,7 +601,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
application.setAppCategory(rs.getString("APP_CATEGORY")); application.setAppCategory(rs.getString("APP_CATEGORY"));
application.setSubType(rs.getString("SUB_TYPE")); application.setSubType(rs.getString("SUB_TYPE"));
application.setPaymentCurrency(rs.getString("CURRENCY")); application.setPaymentCurrency(rs.getString("CURRENCY"));
application.setIsRestricted(rs.getInt("RESTRICTED")); application.setIsRestricted(rs.getBoolean("RESTRICTED"));
UnrestrictedRole unrestrictedRole = new UnrestrictedRole(); UnrestrictedRole unrestrictedRole = new UnrestrictedRole();
unrestrictedRole.setRole(rs.getString("ROLE")); unrestrictedRole.setRole(rs.getString("ROLE"));

@ -60,8 +60,6 @@ import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.sql.Timestamp;
import java.util.Date;
/** /**
* Default Concrete implementation of Application Management related implementations. * Default Concrete implementation of Application Management related implementations.
@ -117,10 +115,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (!application.getTags().isEmpty()) { if (!application.getTags().isEmpty()) {
this.applicationDAO.addTags(application.getTags(), appId, tenantId); 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); this.visibilityDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), appId, tenantId);
} else { } else {
application.setIsRestricted(0); application.setIsRestricted(false);
} }
if (application.getApplicationReleases().size() > 1 ){ if (application.getApplicationReleases().size() > 1 ){
throw new ApplicationManagementException( throw new ApplicationManagementException(
@ -858,14 +857,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
if (existingApplication.getIsRestricted() != application.getIsRestricted()) { 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()) { if (application.getUnrestrictedRoles() == null || application.getUnrestrictedRoles().isEmpty()) {
throw new ApplicationManagementException("If you are going to add role restriction for non role " 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"); + "restricted Application, Unrestricted role list " + "won't be empty or null");
} }
visibilityDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), application.getId(), tenantId); visibilityDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), application.getId(), tenantId);
} else if (existingApplication.getIsRestricted() == 1 } else if (existingApplication.getIsRestricted() && existingApplication.getUnrestrictedRoles() != null) {
&& existingApplication.getUnrestrictedRoles() != null) {
if (application.getUnrestrictedRoles() != null && !application.getUnrestrictedRoles().isEmpty()) { if (application.getUnrestrictedRoles() != null && !application.getUnrestrictedRoles().isEmpty()) {
throw new ApplicationManagementException("If you are going to remove role restriction from role " throw new ApplicationManagementException("If you are going to remove role restriction from role "
+ "restricted Application, Unrestricted role list should be empty or null"); + "restricted Application, Unrestricted role list should be empty or null");
@ -874,7 +872,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
tenantId); tenantId);
} }
} else if (existingApplication.getIsRestricted() == application.getIsRestricted() } else if (existingApplication.getIsRestricted() == application.getIsRestricted()
&& existingApplication.getIsRestricted() == 1) { && existingApplication.getIsRestricted()) {
addingRoleList = getDifference(application.getUnrestrictedRoles(), addingRoleList = getDifference(application.getUnrestrictedRoles(),
existingApplication.getUnrestrictedRoles()); existingApplication.getUnrestrictedRoles());
removingRoleList = getDifference(existingApplication.getUnrestrictedRoles(), removingRoleList = getDifference(existingApplication.getUnrestrictedRoles(),

@ -141,7 +141,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
attachments.add(screenshot.getDataHandler().getInputStream()); attachments.add(screenshot.getDataHandler().getInputStream());
} }
if (applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null) { if (applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }

Loading…
Cancel
Save