Fixing minor issues

merge-requests/7/head
megala21 7 years ago
parent c10f4e3587
commit 9c31b93937

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

@ -140,12 +140,17 @@ 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 ?,?;";
stmt = conn.prepareStatement(sql);
stmt.setString(++index, userName);
stmt.setInt(++index, tenantId);
if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) {
stmt.setString(++index, "%" + filter.getSearchQuery() + "%");
@ -244,7 +249,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 +267,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()) {

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

Loading…
Cancel
Save