Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions container/oracle/initdb.d/02_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ CREATE TABLE JAM_OWNER.BEAM_DESTINATION_AUTHORIZATION
CW_LIMIT NUMBER(24,12) NULL,
COMMENTS VARCHAR2(256 CHAR) NULL,
EXPIRATION_DATE DATE NULL,
CHANGED_YN VARCHAR2(1 CHAR) DEFAULT 'N' NOT NULL,
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_PK PRIMARY KEY (BEAM_DESTINATION_ID,BEAM_AUTHORIZATION_ID),
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_FK1 FOREIGN KEY (BEAM_DESTINATION_ID, FACILITY_ID) REFERENCES JAM_OWNER.BEAM_DESTINATION (BEAM_DESTINATION_ID, FACILITY_ID),
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_FK2 FOREIGN KEY (BEAM_AUTHORIZATION_ID, FACILITY_ID) REFERENCES JAM_OWNER.BEAM_AUTHORIZATION (BEAM_AUTHORIZATION_ID, FACILITY_ID),
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_CK1 CHECK (BEAM_MODE IN ('None', 'Tune', 'CW', 'Ceramic Viewer', 'Viewer Limited', 'High Duty Cycle', 'BLM Checkout', 'RF Only'))
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_CK1 CHECK (BEAM_MODE IN ('None', 'Tune', 'CW', 'Ceramic Viewer', 'Viewer Limited', 'High Duty Cycle', 'BLM Checkout', 'RF Only')),
CONSTRAINT BEAM_DESTINATION_AUTHORIZATION_CK2 CHECK (CHANGED_YN IN ('Y', 'N'))
);

CREATE TABLE JAM_OWNER.RF_SEGMENT_AUTHORIZATION
Expand All @@ -203,10 +205,12 @@ CREATE TABLE JAM_OWNER.RF_SEGMENT_AUTHORIZATION
HIGH_POWER_RF_YN VARCHAR2(1 CHAR) DEFAULT 'N' NOT NULL,
COMMENTS VARCHAR2(256 CHAR) NULL,
EXPIRATION_DATE DATE NULL,
CHANGED_YN VARCHAR2(1 CHAR) DEFAULT 'N' NOT NULL,
CONSTRAINT RF_SEGMENT_AUTHORIZATION_PK PRIMARY KEY (RF_SEGMENT_ID,RF_AUTHORIZATION_ID),
CONSTRAINT RF_SEGMENT_AUTHORIZATION_FK1 FOREIGN KEY (RF_SEGMENT_ID, FACILITY_ID) REFERENCES JAM_OWNER.RF_SEGMENT (RF_SEGMENT_ID, FACILITY_ID),
CONSTRAINT RF_SEGMENT_AUTHORIZATION_FK2 FOREIGN KEY (RF_AUTHORIZATION_ID, FACILITY_ID) REFERENCES JAM_OWNER.RF_AUTHORIZATION (RF_AUTHORIZATION_ID, FACILITY_ID),
CONSTRAINT RF_SEGMENT_AUTHORIZATION_CK1 CHECK (HIGH_POWER_RF_YN IN ('Y', 'N'))
CONSTRAINT RF_SEGMENT_AUTHORIZATION_CK1 CHECK (HIGH_POWER_RF_YN IN ('Y', 'N')),
CONSTRAINT RF_SEGMENT_AUTHORIZATION_CK2 CHECK (CHANGED_YN IN ('Y', 'N'))
);

CREATE TABLE JAM_OWNER.CREDITED_CONTROL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.jlab.jam.persistence.entity.BeamAuthorization;
import org.jlab.jam.persistence.entity.BeamDestination;
import org.jlab.jam.persistence.entity.BeamDestinationAuthorization;
import org.jlab.jam.persistence.entity.Facility;
import org.jlab.jam.business.util.EqualityHelper;
import org.jlab.jam.persistence.entity.*;
import org.jlab.jam.persistence.enumeration.OperationsType;
import org.jlab.smoothness.business.exception.UserFriendlyException;

Expand Down Expand Up @@ -145,6 +143,8 @@ public BigInteger saveAuthorization(
authorizerFacade.isAuthorizer(facility, OperationsType.BEAM, username);
}

BeamAuthorization previousAuth = findCurrent(facility);

BeamAuthorization beamAuthorization = new BeamAuthorization();
beamAuthorization.setFacility(facility);
beamAuthorization.setComments(comments);
Expand Down Expand Up @@ -198,11 +198,18 @@ public BigInteger saveAuthorization(
} else { // mode = NONE (OFF)
// We force expiration to empty
da.setExpirationDate(null);
da.setCwLimit(null);
da.setComments(null);
}

da.setAuthorization(beamAuthorization);
da.getDestinationAuthorizationPK()
.setAuthorizationId(beamAuthorization.getBeamAuthorizationId());

boolean changed = isChanged(da, previousAuth);

da.setChanged(changed);

em.persist(da);
}

Expand All @@ -213,6 +220,67 @@ public BigInteger saveAuthorization(
return beamAuthorization.getBeamAuthorizationId();
}

private boolean isChanged(
BeamDestinationAuthorization newDestAuth, BeamAuthorization previousAuth) {
boolean changed = true;

// System.err.println("Beam Authorization changed?: " + newDestAuth);

if (previousAuth != null) {
List<BeamDestinationAuthorization> destList = previousAuth.getDestinationAuthorizationList();

// System.err.println("destList: " + destList == null ? "null" : destList.size());

for (BeamDestinationAuthorization oldDestAuth : destList) {
if (oldDestAuth
.getDestinationAuthorizationPK()
.getBeamDestinationId()
.equals(newDestAuth.getDestinationAuthorizationPK().getBeamDestinationId())) {
/*System.err.println("Found matching destination \"" + oldDestAuth.getDestination() + "\"");
System.err.println(
"Beam Mode Change \""
+ !EqualityHelper.nullableStringEqual(
oldDestAuth.getBeamMode(), newDestAuth.getBeamMode())
+ "\"");
System.err.println(
"Current Limit Change \""
+ !EqualityHelper.nullableObjEqual(
oldDestAuth.getCwLimit(), newDestAuth.getCwLimit())
+ "\"");
System.err.println(
"Date Change \""
+ !EqualityHelper.nullableDateEqual(
oldDestAuth.getExpirationDate(), newDestAuth.getExpirationDate())
+ "\" - \""
+ oldDestAuth.getExpirationDate()
+ "\" vs \""
+ newDestAuth.getExpirationDate()
+ "\"");
System.err.println(
"Comment Change \""
+ !EqualityHelper.nullableStringEqual(
oldDestAuth.getComments(), newDestAuth.getComments())
+ "\"");*/

// Check if change
changed =
(!EqualityHelper.nullableStringEqual(
oldDestAuth.getBeamMode(), newDestAuth.getBeamMode()))
|| (!EqualityHelper.nullableObjEqual(
oldDestAuth.getCwLimit(), newDestAuth.getCwLimit()))
|| !EqualityHelper.nullableDateEqual(
oldDestAuth.getExpirationDate(), newDestAuth.getExpirationDate())
|| !EqualityHelper.nullableStringEqual(
oldDestAuth.getComments(), newDestAuth.getComments());

break;
}
}
}

return changed;
}

@PermitAll
public void setLogEntry(BigInteger beamAuthorizationId, Long logId, String logbookServer) {
BeamAuthorization current = find(beamAuthorizationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.jlab.jam.business.util.EqualityHelper;
import org.jlab.jam.persistence.entity.*;
import org.jlab.jam.persistence.enumeration.OperationsType;
import org.jlab.smoothness.business.exception.UserFriendlyException;
Expand Down Expand Up @@ -137,6 +138,8 @@ public BigInteger saveAuthorization(
authorizerFacade.isAuthorizer(facility, OperationsType.RF, username);
}

RFAuthorization previousAuth = findCurrent(facility);

RFAuthorization authorization = new RFAuthorization();
authorization.setFacility(facility);
authorization.setComments(comments);
Expand Down Expand Up @@ -189,10 +192,16 @@ public BigInteger saveAuthorization(
} else { // High Power = OFF
// We force expiration to empty
da.setExpirationDate(null);
da.setComments(null);
}

da.setRFAuthorization(authorization);
da.getSegmentAuthorizationPK().setRFAuthorizationId(authorization.getRfAuthorizationId());

boolean changed = isChanged(da, previousAuth);

da.setChanged(changed);

em.persist(da);
}

Expand All @@ -203,6 +212,55 @@ public BigInteger saveAuthorization(
return authorization.getRfAuthorizationId();
}

private boolean isChanged(RFSegmentAuthorization newSegAuth, RFAuthorization previousAuth) {
boolean changed = true;

// System.err.println("RF Authorization changed?: " + newSegAuth);

if (previousAuth != null) {
List<RFSegmentAuthorization> segList = previousAuth.getRFSegmentAuthorizationList();

// System.err.println("segList: " + segList == null ? "null" : segList.size());

for (RFSegmentAuthorization oldSegAuth : segList) {
if (oldSegAuth
.getSegmentAuthorizationPK()
.getRFSegmentId()
.equals(newSegAuth.getSegmentAuthorizationPK().getRFSegmentId())) {
/*System.err.println("Found matching segment \"" + oldSegAuth.getSegment() + "\"");
System.err.println(
"RF Change \"" + (oldSegAuth.isHighPowerRf() != newSegAuth.isHighPowerRf()) + "\"");
System.err.println(
"Date Change \""
+ !EqualityHelper.nullableDateEqual(
oldSegAuth.getExpirationDate(), newSegAuth.getExpirationDate())
+ "\" - \""
+ oldSegAuth.getExpirationDate()
+ "\" vs \""
+ newSegAuth.getExpirationDate()
+ "\"");
System.err.println(
"Comment Change \""
+ !EqualityHelper.nullableStringEqual(
oldSegAuth.getComments(), newSegAuth.getComments())
+ "\"");*/

// Check if change
changed =
(oldSegAuth.isHighPowerRf() != newSegAuth.isHighPowerRf())
|| !EqualityHelper.nullableDateEqual(
oldSegAuth.getExpirationDate(), newSegAuth.getExpirationDate())
|| !EqualityHelper.nullableStringEqual(
oldSegAuth.getComments(), newSegAuth.getComments());

break;
}
}
}

return changed;
}

@PermitAll
public void setLogEntry(BigInteger rfAuthorizationId, Long logId, String logbookServer) {
RFAuthorization current = find(rfAuthorizationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private boolean populateReducedPermissionsDueToVerification(
operationAuth.setBeamMode("None");
operationAuth.setCwLimit(null);
operationAuth.setExpirationDate(null);
operationAuth.setChanged(true);
operationAuth.setComments(
"Permission automatically revoked due to credited control "
+ verification.getCreditedControl().getName()
Expand All @@ -66,12 +67,9 @@ private boolean populateReducedPermissionsDueToVerification(
}

if (atLeastOne) {
String comments = clone.getComments();
if (comments == null) {
comments = "";
}
String comments = ""; // We replace Change Notes completely with changes
String csv = IOUtil.toCsv(revokedDestinationList.toArray());
comments = comments + "\nCHANGE: Destination control verification revoked: " + csv;
comments = comments + "\nDestination control verification revoked: " + csv;
clone.setComments(comments);
}

Expand Down Expand Up @@ -107,6 +105,7 @@ private boolean populateReducedPermissionDueToAuthorizationExpiration(
operationAuth.setBeamMode("None");
operationAuth.setCwLimit(null);
operationAuth.setExpirationDate(null);
operationAuth.setChanged(true);
operationAuth.setComments(
"Permission automatically revoked due to director's authorization expiration");
atLeastOne = true;
Expand All @@ -116,12 +115,9 @@ private boolean populateReducedPermissionDueToAuthorizationExpiration(
}

if (atLeastOne) {
String comments = clone.getComments();
if (comments == null) {
comments = "";
}
String comments = ""; // We replace Change Notes completely with changes
String csv = IOUtil.toCsv(revokedDestinationList.toArray());
comments = comments + "\nCHANGE: Destination authorization revoked: " + csv;
comments = comments + "\nDestination authorization revoked: " + csv;
clone.setComments(comments);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private boolean populateReducedPermissionsDueToVerification(
if (segmentId.equals(verification.getRFSegment().getRFSegmentId())) {
operationAuth.setHighPowerRf(false);
operationAuth.setExpirationDate(null);
operationAuth.setChanged(true);
operationAuth.setComments(
"Permission automatically revoked due to credited control "
+ verification.getCreditedControl().getName()
Expand All @@ -66,12 +67,9 @@ private boolean populateReducedPermissionsDueToVerification(
}

if (atLeastOne) {
String comments = clone.getComments();
if (comments == null) {
comments = "";
}
String comments = ""; // We replace Change Notes completely with changes
String csv = IOUtil.toCsv(revokedSegmentList.toArray());
comments = comments + "\nCHANGE: Segment control verification revoked: " + csv;
comments = comments + "\nSegment control verification revoked: " + csv;
clone.setComments(comments);
}

Expand Down Expand Up @@ -104,6 +102,7 @@ private boolean populateReducedPermissionDueToAuthorizationExpiration(
if (containsName(segmentList, operationAuth)) {
operationAuth.setHighPowerRf(false);
operationAuth.setExpirationDate(null);
operationAuth.setChanged(true);
operationAuth.setComments(
"Permission automatically revoked due to director's authorization expiration");
atLeastOne = true;
Expand All @@ -113,12 +112,9 @@ private boolean populateReducedPermissionDueToAuthorizationExpiration(
}

if (atLeastOne) {
String comments = clone.getComments();
if (comments == null) {
comments = "";
}
String comments = ""; // We replace Change Notes completely with changes
String csv = IOUtil.toCsv(revokedSegmentList.toArray());
comments = comments + "\nCHANGE: Segment authorization revoked: " + csv;
comments = comments + "\nSegment authorization revoked: " + csv;
clone.setComments(comments);
}

Expand Down
74 changes: 74 additions & 0 deletions src/main/java/org/jlab/jam/business/util/EqualityHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.jlab.jam.business.util;

import java.util.Date;

public final class EqualityHelper {
private EqualityHelper() {
// Can't instantiate because private
}

public static boolean nullableObjEqual(Object one, Object two) {
boolean equal = false;

if (one == null) {
if (two == null) {
equal = true;
}
} else {
equal = one.equals(two);
}

return equal;
}

public static boolean nullableStringEqual(String one, String two) {
// String can be null, or contain just whitespace and we treat them as equal

boolean equal = false;

if (one != null && one.isBlank()) {
one = null;
}

if (two != null && two.isBlank()) {
two = null;
}

if (one == null) {
if (two == null) {
equal = true;
}
} else {
equal = one.equals(two);
}

return equal;
}

public static boolean nullableDateEqual(Date one, Date two) {
// Dates can be of type sql.Date vs util.Date and we treat them as equal

boolean equal = false;

Long oneUnix = null;
Long twoUnix = null;

if (one != null) {
oneUnix = one.getTime();
}

if (two != null) {
twoUnix = two.getTime();
}

if (one == null) {
if (two == null) {
equal = true;
}
} else {
equal = oneUnix.equals(twoUnix);
}

return equal;
}
}
Loading
Loading