Skip to content

Commit fc1445e

Browse files
authored
Highlight changed auth rows (#64)
Fixes #63
1 parent 39cc9ee commit fc1445e

17 files changed

+369
-59
lines changed

container/oracle/initdb.d/02_ddl.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ CREATE TABLE JAM_OWNER.BEAM_DESTINATION_AUTHORIZATION
189189
CW_LIMIT NUMBER(24,12) NULL,
190190
COMMENTS VARCHAR2(256 CHAR) NULL,
191191
EXPIRATION_DATE DATE NULL,
192+
CHANGED_YN VARCHAR2(1 CHAR) DEFAULT 'N' NOT NULL,
192193
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_PK PRIMARY KEY (BEAM_DESTINATION_ID,BEAM_AUTHORIZATION_ID),
193194
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_FK1 FOREIGN KEY (BEAM_DESTINATION_ID, FACILITY_ID) REFERENCES JAM_OWNER.BEAM_DESTINATION (BEAM_DESTINATION_ID, FACILITY_ID),
194195
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_FK2 FOREIGN KEY (BEAM_AUTHORIZATION_ID, FACILITY_ID) REFERENCES JAM_OWNER.BEAM_AUTHORIZATION (BEAM_AUTHORIZATION_ID, FACILITY_ID),
195-
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_CK1 CHECK (BEAM_MODE IN ('None', 'Tune', 'CW', 'Ceramic Viewer', 'Viewer Limited', 'High Duty Cycle', 'BLM Checkout', 'RF Only'))
196+
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_CK1 CHECK (BEAM_MODE IN ('None', 'Tune', 'CW', 'Ceramic Viewer', 'Viewer Limited', 'High Duty Cycle', 'BLM Checkout', 'RF Only')),
197+
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_CK2 CHECK (CHANGED_YN IN ('Y', 'N'))
196198
);
197199

198200
CREATE TABLE JAM_OWNER.RF_SEGMENT_AUTHORIZATION
@@ -203,10 +205,12 @@ CREATE TABLE JAM_OWNER.RF_SEGMENT_AUTHORIZATION
203205
HIGH_POWER_RF_YN VARCHAR2(1 CHAR) DEFAULT 'N' NOT NULL,
204206
COMMENTS VARCHAR2(256 CHAR) NULL,
205207
EXPIRATION_DATE DATE NULL,
208+
CHANGED_YN VARCHAR2(1 CHAR) DEFAULT 'N' NOT NULL,
206209
CONSTRAINT RF_SEGMENT_AUTHORIZATION_PK PRIMARY KEY (RF_SEGMENT_ID,RF_AUTHORIZATION_ID),
207210
CONSTRAINT RF_SEGMENT_AUTHORIZATION_FK1 FOREIGN KEY (RF_SEGMENT_ID, FACILITY_ID) REFERENCES JAM_OWNER.RF_SEGMENT (RF_SEGMENT_ID, FACILITY_ID),
208211
CONSTRAINT RF_SEGMENT_AUTHORIZATION_FK2 FOREIGN KEY (RF_AUTHORIZATION_ID, FACILITY_ID) REFERENCES JAM_OWNER.RF_AUTHORIZATION (RF_AUTHORIZATION_ID, FACILITY_ID),
209-
CONSTRAINT RF_SEGMENT_AUTHORIZATION_CK1 CHECK (HIGH_POWER_RF_YN IN ('Y', 'N'))
212+
CONSTRAINT RF_SEGMENT_AUTHORIZATION_CK1 CHECK (HIGH_POWER_RF_YN IN ('Y', 'N')),
213+
CONSTRAINT RF_SEGMENT_AUTHORIZATION_CK2 CHECK (CHANGED_YN IN ('Y', 'N'))
210214
);
211215

212216
CREATE TABLE JAM_OWNER.CREDITED_CONTROL

src/main/java/org/jlab/jam/business/session/BeamAuthorizationFacade.java

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
import javax.persistence.PersistenceContext;
1717
import javax.persistence.Query;
1818
import javax.persistence.TypedQuery;
19-
import org.jlab.jam.persistence.entity.BeamAuthorization;
20-
import org.jlab.jam.persistence.entity.BeamDestination;
21-
import org.jlab.jam.persistence.entity.BeamDestinationAuthorization;
22-
import org.jlab.jam.persistence.entity.Facility;
19+
import org.jlab.jam.business.util.EqualityHelper;
20+
import org.jlab.jam.persistence.entity.*;
2321
import org.jlab.jam.persistence.enumeration.OperationsType;
2422
import org.jlab.smoothness.business.exception.UserFriendlyException;
2523

@@ -145,6 +143,8 @@ public BigInteger saveAuthorization(
145143
authorizerFacade.isAuthorizer(facility, OperationsType.BEAM, username);
146144
}
147145

146+
BeamAuthorization previousAuth = findCurrent(facility);
147+
148148
BeamAuthorization beamAuthorization = new BeamAuthorization();
149149
beamAuthorization.setFacility(facility);
150150
beamAuthorization.setComments(comments);
@@ -198,11 +198,18 @@ public BigInteger saveAuthorization(
198198
} else { // mode = NONE (OFF)
199199
// We force expiration to empty
200200
da.setExpirationDate(null);
201+
da.setCwLimit(null);
202+
da.setComments(null);
201203
}
202204

203205
da.setAuthorization(beamAuthorization);
204206
da.getDestinationAuthorizationPK()
205207
.setAuthorizationId(beamAuthorization.getBeamAuthorizationId());
208+
209+
boolean changed = isChanged(da, previousAuth);
210+
211+
da.setChanged(changed);
212+
206213
em.persist(da);
207214
}
208215

@@ -213,6 +220,67 @@ public BigInteger saveAuthorization(
213220
return beamAuthorization.getBeamAuthorizationId();
214221
}
215222

223+
private boolean isChanged(
224+
BeamDestinationAuthorization newDestAuth, BeamAuthorization previousAuth) {
225+
boolean changed = true;
226+
227+
// System.err.println("Beam Authorization changed?: " + newDestAuth);
228+
229+
if (previousAuth != null) {
230+
List<BeamDestinationAuthorization> destList = previousAuth.getDestinationAuthorizationList();
231+
232+
// System.err.println("destList: " + destList == null ? "null" : destList.size());
233+
234+
for (BeamDestinationAuthorization oldDestAuth : destList) {
235+
if (oldDestAuth
236+
.getDestinationAuthorizationPK()
237+
.getBeamDestinationId()
238+
.equals(newDestAuth.getDestinationAuthorizationPK().getBeamDestinationId())) {
239+
/*System.err.println("Found matching destination \"" + oldDestAuth.getDestination() + "\"");
240+
System.err.println(
241+
"Beam Mode Change \""
242+
+ !EqualityHelper.nullableStringEqual(
243+
oldDestAuth.getBeamMode(), newDestAuth.getBeamMode())
244+
+ "\"");
245+
System.err.println(
246+
"Current Limit Change \""
247+
+ !EqualityHelper.nullableObjEqual(
248+
oldDestAuth.getCwLimit(), newDestAuth.getCwLimit())
249+
+ "\"");
250+
System.err.println(
251+
"Date Change \""
252+
+ !EqualityHelper.nullableDateEqual(
253+
oldDestAuth.getExpirationDate(), newDestAuth.getExpirationDate())
254+
+ "\" - \""
255+
+ oldDestAuth.getExpirationDate()
256+
+ "\" vs \""
257+
+ newDestAuth.getExpirationDate()
258+
+ "\"");
259+
System.err.println(
260+
"Comment Change \""
261+
+ !EqualityHelper.nullableStringEqual(
262+
oldDestAuth.getComments(), newDestAuth.getComments())
263+
+ "\"");*/
264+
265+
// Check if change
266+
changed =
267+
(!EqualityHelper.nullableStringEqual(
268+
oldDestAuth.getBeamMode(), newDestAuth.getBeamMode()))
269+
|| (!EqualityHelper.nullableObjEqual(
270+
oldDestAuth.getCwLimit(), newDestAuth.getCwLimit()))
271+
|| !EqualityHelper.nullableDateEqual(
272+
oldDestAuth.getExpirationDate(), newDestAuth.getExpirationDate())
273+
|| !EqualityHelper.nullableStringEqual(
274+
oldDestAuth.getComments(), newDestAuth.getComments());
275+
276+
break;
277+
}
278+
}
279+
}
280+
281+
return changed;
282+
}
283+
216284
@PermitAll
217285
public void setLogEntry(BigInteger beamAuthorizationId, Long logId, String logbookServer) {
218286
BeamAuthorization current = find(beamAuthorizationId);

src/main/java/org/jlab/jam/business/session/RFAuthorizationFacade.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import javax.persistence.PersistenceContext;
1414
import javax.persistence.Query;
1515
import javax.persistence.TypedQuery;
16+
import org.jlab.jam.business.util.EqualityHelper;
1617
import org.jlab.jam.persistence.entity.*;
1718
import org.jlab.jam.persistence.enumeration.OperationsType;
1819
import org.jlab.smoothness.business.exception.UserFriendlyException;
@@ -137,6 +138,8 @@ public BigInteger saveAuthorization(
137138
authorizerFacade.isAuthorizer(facility, OperationsType.RF, username);
138139
}
139140

141+
RFAuthorization previousAuth = findCurrent(facility);
142+
140143
RFAuthorization authorization = new RFAuthorization();
141144
authorization.setFacility(facility);
142145
authorization.setComments(comments);
@@ -189,10 +192,16 @@ public BigInteger saveAuthorization(
189192
} else { // High Power = OFF
190193
// We force expiration to empty
191194
da.setExpirationDate(null);
195+
da.setComments(null);
192196
}
193197

194198
da.setRFAuthorization(authorization);
195199
da.getSegmentAuthorizationPK().setRFAuthorizationId(authorization.getRfAuthorizationId());
200+
201+
boolean changed = isChanged(da, previousAuth);
202+
203+
da.setChanged(changed);
204+
196205
em.persist(da);
197206
}
198207

@@ -203,6 +212,55 @@ public BigInteger saveAuthorization(
203212
return authorization.getRfAuthorizationId();
204213
}
205214

215+
private boolean isChanged(RFSegmentAuthorization newSegAuth, RFAuthorization previousAuth) {
216+
boolean changed = true;
217+
218+
// System.err.println("RF Authorization changed?: " + newSegAuth);
219+
220+
if (previousAuth != null) {
221+
List<RFSegmentAuthorization> segList = previousAuth.getRFSegmentAuthorizationList();
222+
223+
// System.err.println("segList: " + segList == null ? "null" : segList.size());
224+
225+
for (RFSegmentAuthorization oldSegAuth : segList) {
226+
if (oldSegAuth
227+
.getSegmentAuthorizationPK()
228+
.getRFSegmentId()
229+
.equals(newSegAuth.getSegmentAuthorizationPK().getRFSegmentId())) {
230+
/*System.err.println("Found matching segment \"" + oldSegAuth.getSegment() + "\"");
231+
System.err.println(
232+
"RF Change \"" + (oldSegAuth.isHighPowerRf() != newSegAuth.isHighPowerRf()) + "\"");
233+
System.err.println(
234+
"Date Change \""
235+
+ !EqualityHelper.nullableDateEqual(
236+
oldSegAuth.getExpirationDate(), newSegAuth.getExpirationDate())
237+
+ "\" - \""
238+
+ oldSegAuth.getExpirationDate()
239+
+ "\" vs \""
240+
+ newSegAuth.getExpirationDate()
241+
+ "\"");
242+
System.err.println(
243+
"Comment Change \""
244+
+ !EqualityHelper.nullableStringEqual(
245+
oldSegAuth.getComments(), newSegAuth.getComments())
246+
+ "\"");*/
247+
248+
// Check if change
249+
changed =
250+
(oldSegAuth.isHighPowerRf() != newSegAuth.isHighPowerRf())
251+
|| !EqualityHelper.nullableDateEqual(
252+
oldSegAuth.getExpirationDate(), newSegAuth.getExpirationDate())
253+
|| !EqualityHelper.nullableStringEqual(
254+
oldSegAuth.getComments(), newSegAuth.getComments());
255+
256+
break;
257+
}
258+
}
259+
}
260+
261+
return changed;
262+
}
263+
206264
@PermitAll
207265
public void setLogEntry(BigInteger rfAuthorizationId, Long logId, String logbookServer) {
208266
RFAuthorization current = find(rfAuthorizationId);

src/main/java/org/jlab/jam/business/session/ReducedBeamAuthorizationBuilder.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private boolean populateReducedPermissionsDueToVerification(
5252
operationAuth.setBeamMode("None");
5353
operationAuth.setCwLimit(null);
5454
operationAuth.setExpirationDate(null);
55+
operationAuth.setChanged(true);
5556
operationAuth.setComments(
5657
"Permission automatically revoked due to credited control "
5758
+ verification.getCreditedControl().getName()
@@ -66,12 +67,9 @@ private boolean populateReducedPermissionsDueToVerification(
6667
}
6768

6869
if (atLeastOne) {
69-
String comments = clone.getComments();
70-
if (comments == null) {
71-
comments = "";
72-
}
70+
String comments = ""; // We replace Change Notes completely with changes
7371
String csv = IOUtil.toCsv(revokedDestinationList.toArray());
74-
comments = comments + "\nCHANGE: Destination control verification revoked: " + csv;
72+
comments = comments + "\nDestination control verification revoked: " + csv;
7573
clone.setComments(comments);
7674
}
7775

@@ -107,6 +105,7 @@ private boolean populateReducedPermissionDueToAuthorizationExpiration(
107105
operationAuth.setBeamMode("None");
108106
operationAuth.setCwLimit(null);
109107
operationAuth.setExpirationDate(null);
108+
operationAuth.setChanged(true);
110109
operationAuth.setComments(
111110
"Permission automatically revoked due to director's authorization expiration");
112111
atLeastOne = true;
@@ -116,12 +115,9 @@ private boolean populateReducedPermissionDueToAuthorizationExpiration(
116115
}
117116

118117
if (atLeastOne) {
119-
String comments = clone.getComments();
120-
if (comments == null) {
121-
comments = "";
122-
}
118+
String comments = ""; // We replace Change Notes completely with changes
123119
String csv = IOUtil.toCsv(revokedDestinationList.toArray());
124-
comments = comments + "\nCHANGE: Destination authorization revoked: " + csv;
120+
comments = comments + "\nDestination authorization revoked: " + csv;
125121
clone.setComments(comments);
126122
}
127123

src/main/java/org/jlab/jam/business/session/ReducedRFAuthorizationBuilder.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private boolean populateReducedPermissionsDueToVerification(
5252
if (segmentId.equals(verification.getRFSegment().getRFSegmentId())) {
5353
operationAuth.setHighPowerRf(false);
5454
operationAuth.setExpirationDate(null);
55+
operationAuth.setChanged(true);
5556
operationAuth.setComments(
5657
"Permission automatically revoked due to credited control "
5758
+ verification.getCreditedControl().getName()
@@ -66,12 +67,9 @@ private boolean populateReducedPermissionsDueToVerification(
6667
}
6768

6869
if (atLeastOne) {
69-
String comments = clone.getComments();
70-
if (comments == null) {
71-
comments = "";
72-
}
70+
String comments = ""; // We replace Change Notes completely with changes
7371
String csv = IOUtil.toCsv(revokedSegmentList.toArray());
74-
comments = comments + "\nCHANGE: Segment control verification revoked: " + csv;
72+
comments = comments + "\nSegment control verification revoked: " + csv;
7573
clone.setComments(comments);
7674
}
7775

@@ -104,6 +102,7 @@ private boolean populateReducedPermissionDueToAuthorizationExpiration(
104102
if (containsName(segmentList, operationAuth)) {
105103
operationAuth.setHighPowerRf(false);
106104
operationAuth.setExpirationDate(null);
105+
operationAuth.setChanged(true);
107106
operationAuth.setComments(
108107
"Permission automatically revoked due to director's authorization expiration");
109108
atLeastOne = true;
@@ -113,12 +112,9 @@ private boolean populateReducedPermissionDueToAuthorizationExpiration(
113112
}
114113

115114
if (atLeastOne) {
116-
String comments = clone.getComments();
117-
if (comments == null) {
118-
comments = "";
119-
}
115+
String comments = ""; // We replace Change Notes completely with changes
120116
String csv = IOUtil.toCsv(revokedSegmentList.toArray());
121-
comments = comments + "\nCHANGE: Segment authorization revoked: " + csv;
117+
comments = comments + "\nSegment authorization revoked: " + csv;
122118
clone.setComments(comments);
123119
}
124120

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package org.jlab.jam.business.util;
2+
3+
import java.util.Date;
4+
5+
public final class EqualityHelper {
6+
private EqualityHelper() {
7+
// Can't instantiate because private
8+
}
9+
10+
public static boolean nullableObjEqual(Object one, Object two) {
11+
boolean equal = false;
12+
13+
if (one == null) {
14+
if (two == null) {
15+
equal = true;
16+
}
17+
} else {
18+
equal = one.equals(two);
19+
}
20+
21+
return equal;
22+
}
23+
24+
public static boolean nullableStringEqual(String one, String two) {
25+
// String can be null, or contain just whitespace and we treat them as equal
26+
27+
boolean equal = false;
28+
29+
if (one != null && one.isBlank()) {
30+
one = null;
31+
}
32+
33+
if (two != null && two.isBlank()) {
34+
two = null;
35+
}
36+
37+
if (one == null) {
38+
if (two == null) {
39+
equal = true;
40+
}
41+
} else {
42+
equal = one.equals(two);
43+
}
44+
45+
return equal;
46+
}
47+
48+
public static boolean nullableDateEqual(Date one, Date two) {
49+
// Dates can be of type sql.Date vs util.Date and we treat them as equal
50+
51+
boolean equal = false;
52+
53+
Long oneUnix = null;
54+
Long twoUnix = null;
55+
56+
if (one != null) {
57+
oneUnix = one.getTime();
58+
}
59+
60+
if (two != null) {
61+
twoUnix = two.getTime();
62+
}
63+
64+
if (one == null) {
65+
if (two == null) {
66+
equal = true;
67+
}
68+
} else {
69+
equal = oneUnix.equals(twoUnix);
70+
}
71+
72+
return equal;
73+
}
74+
}

0 commit comments

Comments
 (0)