Skip to content

Commit

Permalink
Changed to HSQL test database
Browse files Browse the repository at this point in the history
Code changes as per SonarLint recommendations
  • Loading branch information
point85 committed Jul 31, 2020
1 parent 61671e8 commit 7d598ea
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 145 deletions.
78 changes: 78 additions & 0 deletions database/hssql/create_ws_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
-- HSQLDB schema creation script file
-- set to your schema
SET AUTOCOMMIT TRUE;

/****** WORK_SCHEDULE table ******/
DROP TABLE WORK_SCHEDULE IF EXISTS;

CREATE CACHED TABLE WORK_SCHEDULE (
WS_KEY bigint GENERATED BY DEFAULT AS IDENTITY,
VERSION int NULL,
NAME nvarchar(64) NULL,
DESCRIPTION nvarchar(512) NULL,
PRIMARY KEY (WS_KEY)
);

/****** SHIFT table ******/
DROP TABLE SHIFT IF EXISTS;

CREATE CACHED TABLE SHIFT (
SHIFT_KEY bigint GENERATED BY DEFAULT AS IDENTITY,
NAME nvarchar(64) NULL,
DESCRIPTION nvarchar(128) NULL,
START_TIME time(3) NULL,
DURATION bigint NULL,
WS_KEY bigint NULL,
PRIMARY KEY (SHIFT_KEY)
);

/****** TEAM table ******/
DROP TABLE TEAM IF EXISTS;

CREATE CACHED TABLE TEAM (
TEAM_KEY bigint GENERATED BY DEFAULT AS IDENTITY,
NAME nvarchar(64) NULL,
DESCRIPTION nvarchar(128) NULL,
WS_KEY bigint NULL,
ROTATION_KEY bigint NULL,
ROTATION_START date NULL,
PRIMARY KEY (TEAM_KEY)
);

/****** ROTATION table ******/
DROP TABLE ROTATION IF EXISTS;

CREATE CACHED TABLE ROTATION (
ROTATION_KEY bigint GENERATED BY DEFAULT AS IDENTITY,
NAME nvarchar(64) NULL,
DESCRIPTION nvarchar(128) NULL,
WS_KEY bigint NULL,
PRIMARY KEY (ROTATION_KEY)
);

/****** ROTATION_SEGMENT table ******/
DROP TABLE ROTATION_SEGMENT IF EXISTS;

CREATE CACHED TABLE ROTATION_SEGMENT (
SEGMENT_KEY bigint GENERATED BY DEFAULT AS IDENTITY,
ROTATION_KEY bigint NULL,
SEQUENCE smallint NULL,
SHIFT_KEY bigint NULL,
DAYS_ON smallint NULL,
DAYS_OFF smallint NULL,
PRIMARY KEY (SEGMENT_KEY)
);

/****** NON_WORKING_PERIOD table ******/
DROP TABLE NON_WORKING_PERIOD IF EXISTS;

CREATE CACHED TABLE NON_WORKING_PERIOD (
PERIOD_KEY bigint GENERATED BY DEFAULT AS IDENTITY,
NAME nvarchar(64) NULL,
DESCRIPTION nvarchar(128) NULL,
START_DATE_TIME datetime(3) NULL,
DURATION bigint NULL,
WS_KEY bigint NULL,
LOSS nvarchar(32) NULL,
PRIMARY KEY (PERIOD_KEY)
);
Binary file modified javadoc/javadoc.zip
Binary file not shown.
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.point85</groupId>
<artifactId>workschedule</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<packaging>jar</packaging>

<name>workschedule</name>
Expand Down Expand Up @@ -53,6 +53,15 @@
<scope>test</scope>
</dependency>

<!-- HSQLDB DATABASE for testing -->
<!-- https://mvnrepository.com/artifact/org.hsqldb/hsqldb -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.4.1</version>
<scope>test</scope>
</dependency>

<!-- jUnit for testing. See: http://junit.org/junit4/ -->
<dependency>
<groupId>junit</groupId>
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/org/point85/workschedule/Named.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ abstract class Named {

// description
private String description;

// database primary key
private Long primaryKey;

protected Named() {

}

protected Named(String name, String description) throws Exception {
Expand All @@ -63,10 +63,8 @@ public String getName() {
/**
* Set name
*
* @param name
* Name
* @throws Exception
* exception
* @param name Name
* @throws Exception exception
*/
public void setName(String name) throws Exception {
if (name == null) {
Expand All @@ -87,8 +85,7 @@ public String getDescription() {
/**
* Set description
*
* @param description
* Description
* @param description Description
*/
public void setDescription(String description) {
this.description = description;
Expand All @@ -102,13 +99,17 @@ public void setDescription(String description) {
@Override
public boolean equals(Object other) {

if (other == null || !(other instanceof Named)) {
if (!(other instanceof Named)) {
return false;
}

if (getName() == null || ((Named) other).getName() == null) {
return false;
}

return getName().equals(((Named) other).getName());
}

/**
* Get the hash code
*
Expand All @@ -118,7 +119,7 @@ public boolean equals(Object other) {
public int hashCode() {
return Objects.hashCode(getName());
}

/**
* Get the database record's primary key
*
Expand All @@ -131,8 +132,7 @@ public Long getKey() {
/**
* Set the database record's primary key
*
* @param key
* Key
* @param key Key
*/
public void setKey(Long key) {
this.primaryKey = key;
Expand Down
61 changes: 43 additions & 18 deletions src/main/java/org/point85/workschedule/NonWorkingPeriod.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;

/**
* Class NonWorkingPeriod represents named non-working, non-recurring periods.
Expand Down Expand Up @@ -71,10 +72,8 @@ public LocalDateTime getStartDateTime() {
/**
* Set period start date and time
*
* @param startDateTime
* Period start
* @throws Exception
* exception
* @param startDateTime Period start
* @throws Exception exception
*/
public void setStartDateTime(LocalDateTime startDateTime) throws Exception {
if (startDateTime == null) {
Expand All @@ -88,8 +87,7 @@ public void setStartDateTime(LocalDateTime startDateTime) throws Exception {
* Get period end date and time
*
* @return Period end
* @throws Exception
* exception
* @throws Exception exception
*/
public LocalDateTime getEndDateTime() throws Exception {
return startDateTime.plus(duration);
Expand All @@ -107,10 +105,8 @@ public Duration getDuration() {
/**
* Set duration
*
* @param duration
* Duration
* @throws Exception
* exception
* @param duration Duration
* @throws Exception exception
*/
public void setDuration(Duration duration) throws Exception {
if (duration == null || duration.getSeconds() == 0) {
Expand Down Expand Up @@ -139,18 +135,49 @@ public String toString() {
}

/**
* Compare this non-working period to another such period by start date and
* time of day
* Compare this non-working period to another such period by start date and time
* of day
*
* @param other
* {@link NonWorkingPeriod}
* @param other {@link NonWorkingPeriod}
* @return negative if less than, 0 if equal and positive if greater than
*/
@Override
public int compareTo(NonWorkingPeriod other) {
return getStartDateTime().compareTo(other.getStartDateTime());
}

/**
* Compare this NonWorkingPeriod to another NonWorkingPeriod
*
* @return true if equal
*/
@Override
public boolean equals(Object other) {
if (!(other instanceof NonWorkingPeriod)) {
return false;
}
NonWorkingPeriod otherNonWorkingPeriod = (NonWorkingPeriod) other;

// same work schedule
if (getWorkSchedule() != null && otherNonWorkingPeriod.getWorkSchedule() != null) {
if (!getWorkSchedule().equals(otherNonWorkingPeriod.getWorkSchedule())) {
return false;
}
}

return super.equals(other);
}

/**
* Get the hash code
*
* @return hash code
*/
@Override
public int hashCode() {
return Objects.hash(getName(), getWorkSchedule());
}

/**
* Get the work schedule that owns this non-working period
*
Expand All @@ -167,11 +194,9 @@ void setWorkSchedule(WorkSchedule workSchedule) {
/**
* Check to see if this day is contained in the non-working period
*
* @param day
* Date to check
* @param day Date to check
* @return True if in the non-working period
* @throws Exception
* Exception
* @throws Exception Exception
*/
public boolean isInPeriod(LocalDate day) throws Exception {
boolean isInPeriod = false;
Expand Down
41 changes: 36 additions & 5 deletions src/main/java/org/point85/workschedule/Rotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* Class Rotation maintains a sequenced list of shift and off-shift time
Expand All @@ -43,7 +44,7 @@ public class Rotation extends Named implements Comparable<Rotation> {
private List<RotationSegment> rotationSegments = new ArrayList<>();

// list of working and non-working days
private transient List<TimePeriod> periods;
private List<TimePeriod> periods;

// name of the day off time period
private static final String DAY_OFF_NAME = "DAY_OFF";
Expand Down Expand Up @@ -194,6 +195,38 @@ void setWorkSchedule(WorkSchedule workSchedule) {
public int compareTo(Rotation other) {
return getName().compareTo(other.getName());
}

/**
* Compare this Rotation to another Rotation
*
* @return true if equal
*/
@Override
public boolean equals(Object other) {
if (!(other instanceof Rotation)) {
return false;
}
Rotation otherRotation = (Rotation) other;

// same work schedule
if (getWorkSchedule() != null && otherRotation.getWorkSchedule() != null) {
if (!getWorkSchedule().equals(otherRotation.getWorkSchedule())) {
return false;
}
}

return super.equals(other);
}

/**
* Get the hash code
*
* @return hash code
*/
@Override
public int hashCode() {
return Objects.hash(getName(), getWorkSchedule());
}

/**
* Build a string representation of this rotation
Expand All @@ -219,9 +252,7 @@ public String toString() {
periodsString += period.getName() + " (" + onOff + ")";
}

String text = named + "\n" + rper + ": [" + periodsString + "], " + rd + ": " + getDuration() + ", " + rda
+ ": " + getDuration().toDays() + ", " + rw + ": " + getWorkingTime();

return text;
return named + "\n" + rper + ": [" + periodsString + "], " + rd + ": " + getDuration() + ", " + rda + ": "
+ getDuration().toDays() + ", " + rw + ": " + getWorkingTime();
}
}
Loading

0 comments on commit 7d598ea

Please sign in to comment.