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
12 changes: 8 additions & 4 deletions container/oracle/initdb.d/02_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ CREATE TABLE BTM_OWNER.CC_ACC_HOUR
(
CC_ACC_HOUR_ID INTEGER NOT NULL,
DAY_AND_HOUR TIMESTAMP(0) WITH LOCAL TIME ZONE NOT NULL,
TUNING_SECONDS NUMBER(4, 0) DEFAULT 0 NOT NULL,
UP_SECONDS NUMBER(4, 0) DEFAULT 0 NOT NULL,
SAD_SECONDS NUMBER(4, 0) DEFAULT 0 NOT NULL,
DOWN_SECONDS NUMBER(4, 0) DEFAULT 0 NOT NULL,
Expand All @@ -342,8 +343,9 @@ CREATE TABLE BTM_OWNER.CC_ACC_HOUR
CONSTRAINT CC_ACC_HOUR_CK5 CHECK (STUDIES_SECONDS BETWEEN 0 AND 3600),
CONSTRAINT CC_ACC_HOUR_CK6 CHECK (ACC_SECONDS BETWEEN 0 AND 3600),
CONSTRAINT CC_ACC_HOUR_CK7 CHECK (RESTORE_SECONDS BETWEEN 0 AND 3600),
CONSTRAINT CC_ACC_HOUR_CK8 CHECK (
UP_SECONDS + SAD_SECONDS + DOWN_SECONDS + STUDIES_SECONDS + RESTORE_SECONDS + ACC_SECONDS = 3600 )
CONSTRAINT CC_ACC_HOUR_CK8 CHECK (TUNING_SECONDS BETWEEN 0 AND 3600),
CONSTRAINT CC_ACC_HOUR_CK9 CHECK (
UP_SECONDS + TUNING_SECONDS + SAD_SECONDS + DOWN_SECONDS + STUDIES_SECONDS + RESTORE_SECONDS + ACC_SECONDS = 3600 )
);

CREATE TABLE BTM_OWNER.CC_ACC_HOUR_AUD
Expand All @@ -353,6 +355,7 @@ CREATE TABLE BTM_OWNER.CC_ACC_HOUR_AUD
REVTYPE NUMBER(3, 0) NOT NULL,
DAY_AND_HOUR TIMESTAMP(0) WITH LOCAL TIME ZONE NOT NULL,
UP_SECONDS NUMBER(4, 0) DEFAULT 0 NOT NULL,
TUNING_SECONDS NUMBER(4, 0) DEFAULT 0 NOT NULL,
SAD_SECONDS NUMBER(4, 0) DEFAULT 0 NOT NULL,
DOWN_SECONDS NUMBER(4, 0) DEFAULT 0 NOT NULL,
STUDIES_SECONDS NUMBER(4, 0) DEFAULT 0 NOT NULL,
Expand All @@ -368,8 +371,9 @@ CREATE TABLE BTM_OWNER.CC_ACC_HOUR_AUD
CONSTRAINT CC_ACC_HOUR_AUD_CK5 CHECK (STUDIES_SECONDS BETWEEN 0 AND 3600),
CONSTRAINT CC_ACC_HOUR_AUD_CK6 CHECK (ACC_SECONDS BETWEEN 0 AND 3600),
CONSTRAINT CC_ACC_HOUR_AUD_CK7 CHECK (RESTORE_SECONDS BETWEEN 0 AND 3600),
CONSTRAINT CC_ACC_HOUR_AUD_CK8 CHECK (
UP_SECONDS + SAD_SECONDS + DOWN_SECONDS + STUDIES_SECONDS + RESTORE_SECONDS + ACC_SECONDS = 3600 )
CONSTRAINT CC_ACC_HOUR_AUD_CK8 CHECK (TUNING_SECONDS BETWEEN 0 AND 3600),
CONSTRAINT CC_ACC_HOUR_AUD_CK9 CHECK (
UP_SECONDS + TUNING_SECONDS + SAD_SECONDS + DOWN_SECONDS + STUDIES_SECONDS + RESTORE_SECONDS + ACC_SECONDS = 3600 )
);

CREATE TABLE BTM_OWNER.EXP_SIGNATURE
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/org/jlab/btm/business/service/CcAccHourService.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ public List<CcAccHour> findInEpics(Date start, Date end) throws CALoadException
public CcAccSum findSummary(Date start, Date end) {
Query q =
em.createNativeQuery(
"select :start0, :end0, sum(up_seconds), sum(sad_seconds), sum(down_seconds), sum(studies_seconds), sum(restore_seconds), sum(acc_seconds) "
"select :start0, :end0, sum(up_seconds), sum(tuning_seconds), sum(sad_seconds), sum(down_seconds), sum(studies_seconds), sum(restore_seconds), sum(acc_seconds) "
+ "from ("
+ "select up_seconds, sad_seconds, down_seconds, studies_seconds, restore_seconds, acc_seconds from CC_acc_hour "
+ "select up_seconds, tuning_seconds, sad_seconds, down_seconds, studies_seconds, restore_seconds, acc_seconds from CC_acc_hour "
+ "where day_and_hour >= :start1 and day_and_hour < :end1 "
+ "union all select 0, 0, 0, 0, 0, 0 from dual)");
+ "union all select 0, 0, 0, 0, 0, 0, 0 from dual)");

q.setParameter("start0", start);
q.setParameter("end0", end);
Expand Down Expand Up @@ -138,6 +138,10 @@ public CcAccShiftTotals calculateTotals(List<CcAccHour> accHourList) {
totals.getUpSeconds() == null
? hour.getUpSeconds()
: totals.getUpSeconds() + hour.getUpSeconds());
totals.setTuningSeconds(
totals.getTuningSeconds() == null
? hour.getTuningSeconds()
: totals.getTuningSeconds() + hour.getTuningSeconds());
totals.setSadSeconds(
totals.getSadSeconds() == null
? hour.getSadSeconds()
Expand Down Expand Up @@ -168,6 +172,7 @@ public CcAccShiftTotals calculateTotals(List<CcAccHour> accHourList) {
public void editAccHours(
Date[] hourArray,
Short[] upArray,
Short[] tuningArray,
Short[] sadArray,
Short[] downArray,
Short[] studiesArray,
Expand All @@ -176,6 +181,7 @@ public void editAccHours(
throws UserFriendlyException {
if (hourArray == null
|| upArray == null
|| tuningArray == null
|| sadArray == null
|| downArray == null
|| studiesArray == null
Expand All @@ -193,7 +199,7 @@ public void editAccHours(
}

if (hourArray.length != upArray.length
|| hourArray.length != upArray.length
|| hourArray.length != tuningArray.length
|| hourArray.length != sadArray.length
|| hourArray.length != downArray.length
|| hourArray.length != studiesArray.length
Expand Down Expand Up @@ -228,7 +234,13 @@ public void editAccHours(
CcAccHour accHour = hourMap.get(hour);

int total =
upArray[i] + sadArray[i] + downArray[i] + studiesArray[i] + restoreArray[i] + accArray[i];
upArray[i]
+ tuningArray[i]
+ sadArray[i]
+ downArray[i]
+ studiesArray[i]
+ restoreArray[i]
+ accArray[i];

if (total != 3600) {
SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
Expand All @@ -242,6 +254,7 @@ public void editAccHours(
}

accHour.setUpSeconds(upArray[i]);
accHour.setTuningSeconds(tuningArray[i]);
accHour.setSadSeconds(sadArray[i]);
accHour.setDownSeconds(downArray[i]);
accHour.setStudiesSeconds(studiesArray[i]);
Expand Down Expand Up @@ -314,7 +327,7 @@ public void manualAudit(CcAccHour hour, RevisionType type) {

Query audq =
em.createNativeQuery(
"insert into cc_acc_hour_aud (REVTYPE, DAY_AND_HOUR, UP_SECONDS, SAD_SECONDS, DOWN_SECONDS, STUDIES_SECONDS, RESTORE_SECONDS, ACC_SECONDS, CC_ACC_HOUR_ID, REV) values (:revtype, to_timestamp_tz(:dayAndHour, 'YYYY-MM-DD HH24 TZD'), :up, :sad, :down, :studies, :restore, :acc, :hour_id, :rev)");
"insert into cc_acc_hour_aud (REVTYPE, DAY_AND_HOUR, UP_SECONDS, TUNING_SECONDS, SAD_SECONDS, DOWN_SECONDS, STUDIES_SECONDS, RESTORE_SECONDS, ACC_SECONDS, CC_ACC_HOUR_ID, REV) values (:revtype, to_timestamp_tz(:dayAndHour, 'YYYY-MM-DD HH24 TZD'), :up, :tuning, :sad, :down, :studies, :restore, :acc, :hour_id, :rev)");

String dayAndHourStr = TimeUtil.formatDatabaseDateTimeTZ(hour.getDayAndHour());

Expand All @@ -326,6 +339,7 @@ public void manualAudit(CcAccHour hour, RevisionType type) {
audq.setParameter("revtype", type.getRepresentation());
audq.setParameter("dayAndHour", dayAndHourStr);
audq.setParameter("up", hour.getUpSeconds());
audq.setParameter("tuning", hour.getTuningSeconds());
audq.setParameter("sad", hour.getSadSeconds());
audq.setParameter("down", hour.getDownSeconds());
audq.setParameter("studies", hour.getStudiesSeconds());
Expand Down Expand Up @@ -356,6 +370,7 @@ private CcAccHour manualInsert(CcAccHour hour) {
q.setParameter("id", id);
q.setParameter("dayAndHour", dayAndHourStr);
q.setParameter("up", hour.getUpSeconds());
q.setParameter("tuning", hour.getTuningSeconds());
q.setParameter("sad", hour.getSadSeconds());
q.setParameter("down", hour.getDownSeconds());
q.setParameter("studies", hour.getStudiesSeconds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ public Long[] findScheduledHallTime(Date start, Date end) {

@PermitAll
public PdAccSum findSummary(Date start, Date end) {
Long[] values = new Long[5];
Long[] values = new Long[6];

// PD Shift Plans line up with CC Shifts
start = TimeUtil.getCcShiftStart(start);
end = TimeUtil.isCrewChiefShiftStart(end) ? end : TimeUtil.getCcShiftEnd(end);

Query q =
em.createNativeQuery(
"select sum(physics_seconds), sum(sad_seconds), sum(studies_seconds), sum(restore_seconds), sum(acc_seconds) from pd_shift_plan where start_day_and_hour < :end and start_day_and_hour >= :start");
"select sum(physics_seconds), 0, sum(sad_seconds), sum(studies_seconds), sum(restore_seconds), sum(acc_seconds) from pd_shift_plan where start_day_and_hour < :end and start_day_and_hour >= :start");

q.setParameter("start", start);
q.setParameter("end", end);
Expand All @@ -105,13 +105,14 @@ public PdAccSum findSummary(Date start, Date end) {

if (resultList != null && resultList.size() == 1) {
Object[] row = (Object[]) resultList.get(0);
for (int i = 0; i < 5; i++) {
for (int i = 0; i < 6; i++) {
Object item = row[i];
Number n = (Number) item;
values[i] = n == null ? 0 : n.longValue();
}
}

return new PdAccSum(start, end, values[0], values[1], values[2], values[3], values[4]);
return new PdAccSum(
start, end, values[0], values[1], values[2], values[3], values[4], values[5]);
}
}
17 changes: 16 additions & 1 deletion src/main/java/org/jlab/btm/persistence/entity/CcAccHour.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@NamedNativeQuery(
name = "CcAccHour.insertNATIVE",
query =
"INSERT into CC_ACC_HOUR (CC_ACC_HOUR_ID, DAY_AND_HOUR, UP_SECONDS, SAD_SECONDS, DOWN_SECONDS, STUDIES_SECONDS, ACC_SECONDS, RESTORE_SECONDS) values (:id, to_timestamp_tz(:dayAndHour, 'YYYY-MM-DD HH24 TZD'), :up, :sad, :down, :studies, :acc, :restore)",
"INSERT into CC_ACC_HOUR (CC_ACC_HOUR_ID, DAY_AND_HOUR, UP_SECONDS, TUNING_SECONDS, SAD_SECONDS, DOWN_SECONDS, STUDIES_SECONDS, ACC_SECONDS, RESTORE_SECONDS) values (:id, to_timestamp_tz(:dayAndHour, 'YYYY-MM-DD HH24 TZD'), :up, :tuning, :sad, :down, :studies, :acc, :restore)",
resultClass = CcAccHour.class)
})
public class CcAccHour implements Serializable, HourEntity {
Expand Down Expand Up @@ -51,6 +51,13 @@ public class CcAccHour implements Serializable, HourEntity {
@Min(value = 0, message = "PHYSICS must be greater than or equal to 0")
private short upSeconds;

@Basic(optional = false)
@NotNull
@Column(name = "TUNING_SECONDS", nullable = false)
@Max(value = 3600, message = "TUNING must be less than or equal to 1 hour")
@Min(value = 0, message = "TUNING must be greater than or equal to 0")
private short tuningSeconds;

@Basic(optional = false)
@NotNull
@Column(name = "SAD_SECONDS", nullable = false)
Expand Down Expand Up @@ -130,6 +137,14 @@ public void setUpSeconds(short upSeconds) {
this.upSeconds = upSeconds;
}

public short getTuningSeconds() {
return tuningSeconds;
}

public void setTuningSeconds(short tuningSeconds) {
this.tuningSeconds = tuningSeconds;
}

public short getSadSeconds() {
return sadSeconds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public class CcAccHourAud implements Serializable {
@Min(value = 0, message = "PHYSICS must be greater than or equal to 0")
private short upSeconds;

@Basic(optional = false)
@NotNull
@Column(name = "TUNING_SECONDS", nullable = false)
@Max(value = 3600, message = "TUNING must be less than or equal to 1 hour")
@Min(value = 0, message = "TUNING must be greater than or equal to 0")
private short tuningSeconds;

@Basic(optional = false)
@NotNull
@Column(name = "SAD_SECONDS", nullable = false)
Expand Down Expand Up @@ -115,6 +122,14 @@ public void setUpSeconds(short upSeconds) {
this.upSeconds = upSeconds;
}

public short getTuningSeconds() {
return tuningSeconds;
}

public void setTuningSeconds(short tuningSeconds) {
this.tuningSeconds = tuningSeconds;
}

public short getSadSeconds() {
return sadSeconds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
public class CcAccShiftTotals {
private Integer upSeconds;
private Integer tuningSeconds;
private Integer sadSeconds;
private Integer downSeconds;
private Integer studiesSeconds;
Expand All @@ -19,6 +20,14 @@ public void setUpSeconds(Integer upSeconds) {
this.upSeconds = upSeconds;
}

public Integer getTuningSeconds() {
return tuningSeconds;
}

public void setTuningSeconds(Integer tuningSeconds) {
this.tuningSeconds = tuningSeconds;
}

public Integer getSadSeconds() {
return sadSeconds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class CcAccSum {
private final long possibleDownSeconds; // Physics and Internal Down
private final long programSeconds; // anything but OFF (SAM) or implied OFF
private final long upSeconds;
private final long tuningSeconds;
private final long sadSeconds;
private final long downSeconds;
private final long studiesSeconds;
Expand All @@ -31,6 +32,7 @@ public CcAccSum(
Date start,
Date end,
Number upSeconds,
Number tuningSeconds,
Number sadSeconds,
Number downSeconds,
Number studiesSeconds,
Expand All @@ -39,6 +41,7 @@ public CcAccSum(
this.start = start;
this.end = end;
this.upSeconds = upSeconds.longValue();
this.tuningSeconds = tuningSeconds.longValue();
this.sadSeconds = sadSeconds.longValue();
this.downSeconds = downSeconds.longValue();
this.studiesSeconds = studiesSeconds.longValue();
Expand All @@ -47,6 +50,7 @@ public CcAccSum(

this.programSeconds =
this.getUpSeconds()
+ this.getTuningSeconds()
+ this.getStudiesSeconds()
+ this.getRestoreSeconds()
+ this.getAccSeconds()
Expand All @@ -64,6 +68,10 @@ public long getUpSeconds() {
return upSeconds;
}

public long getTuningSeconds() {
return tuningSeconds;
}

public long getSadSeconds() {
return sadSeconds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
public class PacAccSum {
public int programDays = 0; // Anything but OFF or implied OFF
public int tuningDays = 0;
public int restoreDays = 0;
public int physicsDays = 0;
public int studiesDays = 0;
Expand Down Expand Up @@ -42,6 +43,14 @@ public int getPhysicsDays() {
return physicsDays;
}

public int getTuningDays() {
return tuningDays;
}

public void setTuningDays(int tuningDays) {
this.tuningDays = tuningDays;
}

public void setPhysicsDays(int physicsDays) {
this.physicsDays = physicsDays;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class PdAccSum {

private final long programSeconds; // anything but OFF (SAM) or implied OFF
private final long physicsSeconds;
private final long tuningSeconds;
private final long offSeconds;
private final long studiesSeconds;
private final long restoreSeconds;
Expand All @@ -27,20 +28,23 @@ public PdAccSum(
Date start,
Date end,
Number physicsSeconds,
Number tuningSeconds,
Number offSeconds,
Number studiesSeconds,
Number restoreSeconds,
Number accSeconds) {
this.start = start;
this.end = end;
this.physicsSeconds = physicsSeconds.longValue();
this.tuningSeconds = tuningSeconds.longValue();
this.offSeconds = offSeconds.longValue();
this.studiesSeconds = studiesSeconds.longValue();
this.restoreSeconds = restoreSeconds.longValue();
this.accSeconds = accSeconds.longValue();

this.programSeconds =
this.getPhysicsSeconds()
+ this.getTuningSeconds()
+ this.getStudiesSeconds()
+ this.getRestoreSeconds()
+ this.getAccSeconds();
Expand All @@ -55,6 +59,10 @@ public long getPhysicsSeconds() {
return physicsSeconds;
}

public long getTuningSeconds() {
return tuningSeconds;
}

public long getOffSeconds() {
return offSeconds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)

Date[] hourArray = BtmParamConverter.convertDayHourArray(request, "hour[]");
Short[] upArray = ParamConverter.convertShortArray(request, "up[]", (short) 0);
Short[] tuningArray = ParamConverter.convertShortArray(request, "tuning[]", (short) 0);
Short[] sadArray = ParamConverter.convertShortArray(request, "sad[]", (short) 0);
Short[] downArray = ParamConverter.convertShortArray(request, "down[]", (short) 0);
Short[] studiesArray = ParamConverter.convertShortArray(request, "studies[]", (short) 0);
Short[] restoreArray = ParamConverter.convertShortArray(request, "restore[]", (short) 0);
Short[] accArray = ParamConverter.convertShortArray(request, "acc[]", (short) 0);

accHourService.editAccHours(
hourArray, upArray, sadArray, downArray, studiesArray, restoreArray, accArray);
hourArray,
upArray,
tuningArray,
sadArray,
downArray,
studiesArray,
restoreArray,
accArray);
} catch (NumberFormatException e) {
logger.log(Level.WARNING, "Unable to edit accelerator availability hours", e);
errorReason = "Numeric field out of range or not a number";
Expand Down
Loading