Skip to content

Commit 1034262

Browse files
Merge 25.11 to 25.12
2 parents 33f70ec + 45c5ac3 commit 1034262

18 files changed

Lines changed: 497 additions & 487 deletions

File tree

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,22 @@
11
SELECT
2-
ar.date as report_date,
3-
4-
card_info.card_id,
5-
cards.exempt,
6-
cards.exempt_reason,
7-
personsList.lastTbClearance,
8-
personsList.measles_required,
9-
personsList.isArchived,
10-
11-
card_info.first_name,
12-
card_info.last_name,
13-
card_info.middle_name,
14-
15-
access_info.access_levels,
16-
17-
persons_to_cards.personid
18-
19-
FROM (
20-
SELECT
21-
report_id,
22-
card_id,
23-
GROUP_CONCAT(access_level, ';') as access_levels
24-
25-
26-
FROM (
27-
SELECT
28-
reports.report_id,
29-
report_data.card_id,
30-
report_data.access_level,
31-
32-
33-
FROM wnprc_compliance.access_reports reports, wnprc_compliance.access_report_data report_data
34-
WHERE (
35-
reports.date = (SELECT MAX(date) FROM wnprc_compliance.access_reports)
36-
AND (
37-
report_data.report_id = reports.report_id
38-
)
39-
)
40-
)
41-
42-
GROUP BY report_id, card_id
43-
) as access_info
44-
45-
LEFT JOIN wnprc_compliance.card_info card_info
46-
on (
47-
access_info.card_id = card_info.card_id
48-
AND
49-
access_info.report_id = card_info.report_id
50-
)
51-
52-
LEFT JOIN wnprc_compliance.cards cards
53-
ON (
54-
cards.card_id = access_info.card_id
55-
)
56-
57-
LEFT JOIN wnprc_compliance.persons_to_cards persons_to_cards
58-
ON (
59-
persons_to_cards.cardid = access_info.card_id
60-
)
61-
62-
LEFT JOIN wnprc_compliance.personsList personsList
63-
ON (
64-
personsList.personid = persons_to_cards.personid
65-
)
66-
67-
LEFT JOIN wnprc_compliance.access_reports ar
68-
ON (
69-
ar.report_id = access_info.report_id
70-
)
2+
ar.date as report_date,
3+
card_info.card_id,
4+
cards.exempt,
5+
cards.exempt_reason,
6+
personsList.lastTbClearance,
7+
personsList.measles_required,
8+
personsList.isArchived,
9+
card_info.first_name,
10+
card_info.last_name,
11+
card_info.middle_name,
12+
persons_to_cards.personid
13+
FROM wnprc_compliance.access_reports ar
14+
INNER JOIN wnprc_compliance.card_info card_info
15+
ON ar.report_id = card_info.report_id
16+
LEFT JOIN wnprc_compliance.cards cards
17+
ON cards.card_id = card_info.card_id
18+
LEFT JOIN wnprc_compliance.persons_to_cards persons_to_cards
19+
ON persons_to_cards.cardid = card_info.card_id
20+
LEFT JOIN wnprc_compliance.personsList personsList
21+
ON personsList.personid = persons_to_cards.personid
22+
WHERE ar.date = (SELECT MAX(date) FROM wnprc_compliance.access_reports)

WNPRC_Compliance/src/org/labkey/wnprc_compliance/AccessReportRowParser.java

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
*/
2626
public class AccessReportRowParser {
2727
enum ColumnName {
28-
FIRST_NAME (false, "Name (Last, First, Middle)"),
29-
LAST_NAME (false, "Name (Last, First, Middle)"),
30-
MIDDLE_NAME (false, "Name (Last, First, Middle)"),
31-
CARD_NUMBER (true, "Badge ID(Issue)"),
32-
CARD_ISSUED (false, "Badge Active"),
33-
CARD_EXPIRE (false, "Badge Deactive"),
28+
FIRST_NAME (false, "First Name"),
29+
LAST_NAME (false, "Last Name"),
30+
MIDDLE_NAME (false, "Middle Name"),
31+
CARD_NUMBER (true, "Badge ID"),
32+
CARD_ISSUED (false, "Badge Activate"),
33+
CARD_EXPIRE (false, "Badge Deactivate"),
3434
BADGE_TYPE (false, "Badge Type"),
35-
CARD_ISSUE_CODE (false, "Badge Id(Issue)"),
3635
;
3736

3837
boolean required;
@@ -87,7 +86,7 @@ public AccessReportRowParser(Row headerRow) throws MalformedReportException {
8786
}
8887
}
8988

90-
public Pair<CardInfo, AccessInfo> parseRow(String reportId, Row row, Container container) throws ParseException
89+
public CardInfo parseRow(Row row) throws ParseException
9190
{
9291
Map<ColumnName, Object> values = new HashMap<>();
9392

@@ -96,23 +95,16 @@ public Pair<CardInfo, AccessInfo> parseRow(String reportId, Row row, Container c
9695
for (ColumnName columnName : cellIndexLookup.keySet()) {
9796
Cell cell = row.getCell(cellIndexLookup.get(columnName));
9897
if (cell != null ) {
99-
if (columnName.headerText.equals(ColumnName.FIRST_NAME.headerText))
100-
{
101-
if (cell.getCellType() == CellType.STRING && !cell.getStringCellValue().isEmpty())
102-
{
103-
Matcher matcher = Pattern.compile("^(.*?),\\s+(\\w+)(?:\\s+(\\w+))?$").matcher(cell.getStringCellValue());
104-
105-
if (matcher.find())
106-
{
107-
values.put(ColumnName.FIRST_NAME, matcher.group(2));
108-
values.put(ColumnName.LAST_NAME, matcher.group(1));
109-
values.put(ColumnName.MIDDLE_NAME, matcher.group(3));
110-
}
111-
}
112-
98+
if(columnName == ColumnName.FIRST_NAME){
99+
values.put(ColumnName.FIRST_NAME, cell.getStringCellValue());
113100
}
114-
115-
if (columnName.headerText.equals(ColumnName.CARD_ISSUED.headerText))
101+
else if (columnName == ColumnName.MIDDLE_NAME){
102+
values.put(ColumnName.MIDDLE_NAME, cell.getStringCellValue());
103+
}else if (columnName == ColumnName.LAST_NAME){
104+
values.put(ColumnName.LAST_NAME, cell.getStringCellValue());
105+
}else if (columnName == ColumnName.BADGE_TYPE){
106+
values.put(ColumnName.BADGE_TYPE, cell.getStringCellValue());
107+
}else if (columnName == ColumnName.CARD_ISSUED)
116108
{
117109
if (!cell.toString().isEmpty())
118110
{
@@ -121,42 +113,32 @@ public Pair<CardInfo, AccessInfo> parseRow(String reportId, Row row, Container c
121113
values.put(ColumnName.CARD_ISSUED, d);
122114

123115
}
124-
}
125-
if (columnName.headerText.equals(ColumnName.CARD_EXPIRE.headerText))
116+
}else if (columnName == ColumnName.CARD_EXPIRE)
126117
{
127118
if (!cell.toString().isEmpty())
128119
{
129120
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
130121
Date d = df.parse(cell.toString());
131122
values.put(ColumnName.CARD_EXPIRE, d);
132123
}
124+
}else if (columnName == ColumnName.CARD_NUMBER)
125+
{
126+
values.put(ColumnName.CARD_NUMBER, cell.getStringCellValue());
133127
}
134128

135-
if (columnName.headerText.equals(ColumnName.CARD_NUMBER.headerText))
136-
{
137129

138-
if (cell.getCellType() == CellType.STRING && !cell.getStringCellValue().isEmpty())
139-
{
140-
Matcher matcher = Pattern.compile("(\\d+)\\s*\\((\\d+)\\)").matcher(cell.getStringCellValue());
141-
if (matcher.find())
142-
{
143-
values.put(ColumnName.CARD_NUMBER, matcher.group(1));
144-
values.put(ColumnName.CARD_ISSUE_CODE, matcher.group(2));
145-
}
146-
}
147-
}
148130

149131
String value = "";
150132
if (cell.getCellType() == CellType.STRING) {
151133
value = cell.getStringCellValue();
152134
}
153135
if (!values.containsKey(columnName))
154136
values.put(columnName, value);
137+
155138
}
156139
}
157140

158-
Pair<CardInfo, AccessInfo> pair = new Pair<>(new CardInfo(values), new AccessInfo(values));
159-
return pair;
141+
return new CardInfo(values);
160142
}
161143

162144
public static class CardInfo {
@@ -187,9 +169,6 @@ public Date getCardIssued() {
187169
public Date getCardExpire() {
188170
return (Date) this.values.get(ColumnName.CARD_EXPIRE);
189171
}
190-
public String getIssueCode() {
191-
return (String) this.values.get(ColumnName.CARD_ISSUE_CODE);
192-
}
193172
public String getCardType() {
194173
return (String) this.values.get(ColumnName.BADGE_TYPE);
195174
}
@@ -200,24 +179,16 @@ public Map<ColumnName, Object> getValues() {
200179

201180
}
202181

203-
public static class AccessInfo {
204-
private Map<ColumnName, Object> values;
205-
206-
public AccessInfo(Map<ColumnName, Object> values) {
207-
this.values = values;
208-
}
209-
210-
}
211-
212182
public static class MalformedReportException extends Exception {
213183
public MalformedReportException(String message) {
214184
super(message);
215185
}
216186
}
217187

218188
public static Date parseDate(String dateString) {
219-
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ssa");
189+
SimpleDateFormat dateFormat = new SimpleDateFormat("MM.dd.yy");
220190
SimpleDateFormat shortDateFormat = new SimpleDateFormat("MM/dd/yyyy");
191+
SimpleDateFormat fullDateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ssa");
221192

222193
Date date;
223194

@@ -229,7 +200,12 @@ public static Date parseDate(String dateString) {
229200
date = shortDateFormat.parse(dateString);
230201
}
231202
catch(ParseException e2) {
232-
throw new ApiUsageException("Unrecognized Date format: " + dateString);
203+
try {
204+
date = fullDateFormat.parse(dateString);
205+
}
206+
catch(ParseException e3) {
207+
throw new ApiUsageException("Unrecognized Date format: " + dateString);
208+
}
233209
}
234210
}
235211

WNPRC_Compliance/src/org/labkey/wnprc_compliance/AccessReportService.java

Lines changed: 16 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,25 @@ public AccessReportService(User user, Container container) {
5454
this.container = container;
5555
}
5656

57-
public void importReport(InputStream stream) throws IOException, AccessReportRowParser.MalformedReportException, ParseException
57+
public void importReport(InputStream stream, String filename) throws IOException, AccessReportRowParser.MalformedReportException, ParseException
5858
{
5959
String reportid = UUID.randomUUID().toString().toUpperCase();
6060
Sheet sheet = new ExcelLoader(stream,false, null).getSheet();
6161

62-
Row titleRow = sheet.getRow(1);
63-
if (!titleRow.getCell(0).getStringCellValue().equalsIgnoreCase("Access Level Assignments to Cardholders")) {
62+
// Ensure all necessary columns are present in an uploaded report
63+
Row columnHeaderRow = sheet.getRow(0);
64+
if(!columnHeaderRow.getCell(3).getStringCellValue().equalsIgnoreCase("Last Name")
65+
|| !columnHeaderRow.getCell(5).getStringCellValue().equalsIgnoreCase("First Name")
66+
|| !columnHeaderRow.getCell(7).getStringCellValue().equalsIgnoreCase("Middle Name")
67+
|| !columnHeaderRow.getCell(23).getStringCellValue().equalsIgnoreCase("Badge Type")
68+
|| !columnHeaderRow.getCell(25).getStringCellValue().equalsIgnoreCase("Badge ID")
69+
|| !columnHeaderRow.getCell(30).getStringCellValue().equalsIgnoreCase("Badge Activate")
70+
|| !columnHeaderRow.getCell(32).getStringCellValue().equalsIgnoreCase("Badge Deactivate")){
6471
throw new ApiUsageException("You can only upload area rights reports here.");
6572
}
6673

67-
Row dateRow = sheet.getRow(6);
68-
//the report created date is the 13th column over
69-
Matcher matcher = Pattern.compile("Report\\s+Date:\\s*(\\d{2}/\\d{2}/\\d{4}\\s+\\d{1,2}:\\d{2}:\\d{2}[AP]M)").matcher(dateRow.getCell(14).getStringCellValue());
74+
//the report created is in the file name
75+
Matcher matcher = Pattern.compile("(\\d{1,2}\\.\\d{1,2}\\.\\d{2})").matcher(filename);
7076
String reportDateTime;
7177
Date generatedOn;
7278
if (matcher.find())
@@ -88,73 +94,20 @@ public void importReport(InputStream stream) throws IOException, AccessReportRow
8894
}
8995

9096
Map<String, JSONObject> cardInfos = new HashMap<>();
91-
List<Map<String, Object>> accessData = new ArrayList<>();
92-
93-
94-
//if the cell contains Prim and Barrier
95-
Pattern accessLevelPattern = Pattern.compile("Access Level:\\s*");
96-
9797
Iterator<Row> rows = sheet.rowIterator();
98-
AccessReportRowParser rowParser = null;
99-
String accessLevel = "";
100-
outer:
98+
AccessReportRowParser rowParser = new AccessReportRowParser(columnHeaderRow);
10199
while (rows.hasNext()) {
102100
Row currentRow = rows.next();
103-
//don't parse items until we reach the main block
104-
if (currentRow.getRowNum() < 8)
105-
{
106-
continue;
107-
}
108-
if (currentRow.getCell(4) == null)
109-
{
101+
// Skip header row
102+
if(currentRow.getRowNum() == 0){
110103
continue;
111104
}
112-
String firstCellText = currentRow.getCell(0).getStringCellValue();
113-
114-
Matcher accessLevelMatcher = accessLevelPattern.matcher(firstCellText);
115-
//we've encountered an access level block of text
116-
//we can grab the header and skip a row
117-
if (accessLevelMatcher.matches())
118-
{
119-
accessLevel = currentRow.getCell(4).getStringCellValue();
120-
121-
// We are about to go into a block of values. First, eat the blank line
122-
rows.next();
123-
124-
// Now eat the header line
125-
Row headerRow = rows.next();
126-
//sets up the column names from the header row?
127-
128-
//
129-
rowParser = new AccessReportRowParser(headerRow);
130105

131-
currentRow = rows.next();
132-
}
133-
if (rowParser == null)
134-
{
135-
continue;
136-
}
137-
Pair<AccessReportRowParser.CardInfo, AccessReportRowParser.AccessInfo> results = rowParser.parseRow(reportid, currentRow, container);
138-
AccessReportRowParser.CardInfo cardInfo = results.first;
139-
AccessReportRowParser.AccessInfo accessInfo = results.second;
106+
AccessReportRowParser.CardInfo cardInfo = rowParser.parseRow(currentRow);
140107

141108
if (cardInfo.getValues().isEmpty())
142109
continue;
143110

144-
145-
//end of spreadsheet pattern
146-
Pattern endOfSheetPattern = Pattern.compile("Total Badges Required for Download:");
147-
if (endOfSheetPattern.matcher(cardInfo.getFirstName()).matches())
148-
{
149-
int getNumCards = (int) currentRow.getCell(10).getNumericCellValue();
150-
if (cardInfos.size() != getNumCards)
151-
{
152-
throw new RuntimeException("Card number does not equal total badge count in sheet, upload failed.");
153-
}
154-
break;
155-
}
156-
157-
158111
String cardNumber = cardInfo.getCardNumber();
159112
if (cardNumber == null || cardNumber.equals(""))
160113
{
@@ -171,19 +124,10 @@ public void importReport(InputStream stream) throws IOException, AccessReportRow
171124
cardInfoJSON.put("middle_name", cardInfo.getMiddleName());
172125
cardInfoJSON.put("date_issued", cardInfo.getCardIssued());
173126
cardInfoJSON.put("date_expire", cardInfo.getCardExpire());
174-
cardInfoJSON.put("issue_code", cardInfo.getIssueCode());
175127
cardInfoJSON.put("card_type", cardInfo.getCardType());
176128
cardInfoJSON.put("container", container.getId());
177129

178130
cardInfos.put(cardNumber, cardInfoJSON);
179-
180-
JSONObject accessInfoJSON = new JSONObject();
181-
accessInfoJSON.put("report_id", reportid);
182-
accessInfoJSON.put("access_level", accessLevel);
183-
accessInfoJSON.put("card_id", cardNumber);
184-
accessInfoJSON.put("container", container.getId());
185-
186-
accessData.add(accessInfoJSON.toMap());
187131
}
188132

189133
try (DbScope.Transaction transaction = DbSchema.get(WNPRC_ComplianceSchema.NAME, DbSchemaType.Module).getScope().ensureTransaction()) {
@@ -204,9 +148,6 @@ public void importReport(InputStream stream) throws IOException, AccessReportRow
204148
}
205149
cardsUpdater.upsert(cardsList);
206150

207-
SimpleQueryUpdater dataUpdater = new SimpleQueryUpdater(user, container, WNPRC_ComplianceSchema.NAME, "access_report_data");
208-
dataUpdater.upsert(accessData);
209-
210151
List<Map<String, Object>> cardInfoList = new ArrayList<>(cardInfos.values().stream().map(JSONObject::toMap).toList());
211152
SimpleQueryUpdater cardInfoUpdater = new SimpleQueryUpdater(user, container, WNPRC_ComplianceSchema.NAME, "card_info");
212153
cardInfoUpdater.upsert(cardInfoList);

0 commit comments

Comments
 (0)