data scoping for additional fields (WIP)
This commit is contained in:
+41
-3
@@ -521,10 +521,14 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
|||||||
columnHeaders.add(rsch);
|
columnHeaders.add(rsch);
|
||||||
} while (rsmd.next());
|
} while (rsmd.next());
|
||||||
|
|
||||||
sql = "select " + selectFieldList + " from `" + type
|
String unScopedSQL = "select " + selectFieldList + " from `"
|
||||||
+ "` t left join `" + fullDatasetName
|
+ type + "` t ${dataScopeCriteria} left join `"
|
||||||
+ "` s on s.id = t.id " + " where t.id = " + id;
|
+ fullDatasetName + "` s on s.id = t.id "
|
||||||
|
+ " where t.id = " + id;
|
||||||
|
|
||||||
|
sql = dataScopedSQL(unScopedSQL, type);
|
||||||
|
|
||||||
|
logger.info("addition fields sql: " + sql);
|
||||||
db_statement3 = db_connection.createStatement();
|
db_statement3 = db_connection.createStatement();
|
||||||
ResultSet rs = db_statement3.executeQuery(sql);
|
ResultSet rs = db_statement3.executeQuery(sql);
|
||||||
|
|
||||||
@@ -546,6 +550,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
|||||||
resultsetDataRows.add(resultsetDataRow);
|
resultsetDataRows.add(resultsetDataRow);
|
||||||
} while (rs.next());
|
} while (rs.next());
|
||||||
} else {
|
} else {
|
||||||
|
// could also be not found because of data scope
|
||||||
throw new AdditionalFieldsNotFoundException(type, id);
|
throw new AdditionalFieldsNotFoundException(type, id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -565,6 +570,37 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String dataScopedSQL(String unScopedSQL, String type) {
|
||||||
|
String dataScopeCriteria = null;
|
||||||
|
/*
|
||||||
|
* unfortunately have to, one way or another, be able to restrict data
|
||||||
|
* to the users office hierarchy. Here it's hardcoded for client and
|
||||||
|
* loan. They are the main application tables. But if additional fields
|
||||||
|
* are needed on other tables like group, loan_transaction or others the
|
||||||
|
* same applies (hardcoding of some sort)
|
||||||
|
*/
|
||||||
|
|
||||||
|
AppUser currentUser = context.authenticatedUser();
|
||||||
|
if (type.equalsIgnoreCase("m_client")) {
|
||||||
|
dataScopeCriteria = " join m_office o on o.id = t.office_id and o.hierarchy like '"
|
||||||
|
+ currentUser.getOffice().getHierarchy() + "%'";
|
||||||
|
}
|
||||||
|
if (type.equalsIgnoreCase("m_loan")) {
|
||||||
|
dataScopeCriteria = " join m_client c on c.id = t.client_id "
|
||||||
|
+ " join m_office o on o.id = c.office_id and o.hierarchy like '"
|
||||||
|
+ currentUser.getOffice().getHierarchy() + "%'";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataScopeCriteria == null) {
|
||||||
|
throw new PlatformDataIntegrityException(
|
||||||
|
"error.msg.invalid.dataScopeCriteria", "Type: " + type
|
||||||
|
+ " not catered for in data Scoping");
|
||||||
|
}
|
||||||
|
|
||||||
|
return replace(unScopedSQL, "${dataScopeCriteria}", dataScopeCriteria);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private String getFullDatasetName(final String type, final String set) {
|
private String getFullDatasetName(final String type, final String set) {
|
||||||
return type + "_x" + set;
|
return type + "_x" + set;
|
||||||
}
|
}
|
||||||
@@ -586,6 +622,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
|||||||
@Override
|
@Override
|
||||||
public void updateExtraData(String type, String set, Long id,
|
public void updateExtraData(String type, String set, Long id,
|
||||||
Map<String, String> queryParams) {
|
Map<String, String> queryParams) {
|
||||||
|
// TODO should be in a Write class
|
||||||
logger.info("updateExtraData - type: " + type + " set: " + set
|
logger.info("updateExtraData - type: " + type + " set: " + set
|
||||||
+ " id: " + id);
|
+ " id: " + id);
|
||||||
|
|
||||||
@@ -614,6 +651,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkResourceTypeThere(String type, String set) {
|
private void checkResourceTypeThere(String type, String set) {
|
||||||
|
|
||||||
String sql = "select 'f' from stretchydata_datasettype t join stretchydata_dataset d on d.datasettype_id = t.id where d.`name` = '"
|
String sql = "select 'f' from stretchydata_datasettype t join stretchydata_dataset d on d.datasettype_id = t.id where d.`name` = '"
|
||||||
+ set + "' and t.`name` = '" + type + "'";
|
+ set + "' and t.`name` = '" + type + "'";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user