Skip to content

Commit

Permalink
Simple cleanup and lombok (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottenhoff authored Dec 13, 2024
1 parent 765bc4a commit c7824b5
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public class AttendanceDaoImpl extends HibernateDaoSupport implements Attendance
*/
@SuppressWarnings("unchecked")
public AttendanceSite getAttendanceSite(final String siteID) {
if(log.isDebugEnabled()){
log.debug("getSiteBySite_ID ");
}
log.debug("getSiteBySite_ID ");

HibernateCallback hcb = new HibernateCallback() {
@Override
Expand All @@ -69,7 +67,7 @@ public Object doInHibernate(Session session) throws HibernateException {
*/
@SuppressWarnings("unchecked")
public AttendanceSite getAttendanceSite(final Long id) {
log.debug("getAttendanceSite by ID: " + id);
log.debug("getAttendanceSite by ID: {}", id);

return (AttendanceSite) getByIDHelper(id, QUERY_GET_SITE_BY_ID);
}
Expand All @@ -79,9 +77,7 @@ public AttendanceSite getAttendanceSite(final Long id) {
*/
@SuppressWarnings("unchecked")
public boolean addAttendanceSite(AttendanceSite aS) {
if(log.isDebugEnabled()) {
log.debug("addAttendanceSite ( " + aS.toString() + ")");
}
log.debug("addAttendanceSite ( {})", aS.toString());

try {
getHibernateTemplate().save(aS);
Expand Down Expand Up @@ -110,9 +106,7 @@ public boolean updateAttendanceSite(AttendanceSite aS) {
*/
@SuppressWarnings("unchecked")
public AttendanceEvent getAttendanceEvent(final long id) {
if(log.isDebugEnabled()) {
log.debug("getAttendanceEvent()" + String.valueOf(id));
}
log.debug("getAttendanceEvent(){}", id);

return (AttendanceEvent) getByIDHelper(id, QUERY_GET_ATTENDANCE_EVENT);
}
Expand All @@ -122,9 +116,7 @@ public AttendanceEvent getAttendanceEvent(final long id) {
*/
@SuppressWarnings("unchecked")
public List<AttendanceEvent> getAttendanceEventsForSite(final AttendanceSite aS) {
if(log.isDebugEnabled()) {
log.debug("getAttendanceEventsForSite(AttendanceSite id)");
}
log.debug("getAttendanceEventsForSite(AttendanceSite id)");

return getEventsForAttendanceSiteHelper(aS);
}
Expand All @@ -133,10 +125,7 @@ public List<AttendanceEvent> getAttendanceEventsForSite(final AttendanceSite aS)
* {@inheritDoc}
*/
public Serializable addAttendanceEventNow(AttendanceEvent attendanceEvent) {

if(log.isDebugEnabled()) {
log.debug("addAttendanceEventNow( " + attendanceEvent.toString() + ")");
}
log.debug("addAttendanceEventNow( {})", attendanceEvent.toString());

try{
return getHibernateTemplate().save(attendanceEvent);
Expand All @@ -150,9 +139,7 @@ public Serializable addAttendanceEventNow(AttendanceEvent attendanceEvent) {
* {@inheritDoc}
*/
public boolean updateAttendanceEvent(AttendanceEvent aE) {
if(log.isDebugEnabled()) {
log.debug("updateAttendanceEvent aE: " + aE.getName());
}
log.debug("updateAttendanceEvent aE: {}", aE.getName());

try{
getHibernateTemplate().saveOrUpdate(aE);
Expand All @@ -167,9 +154,7 @@ public boolean updateAttendanceEvent(AttendanceEvent aE) {
* {@inheritDoc}
*/
public boolean deleteAttendanceEvent(AttendanceEvent aE) {
if(log.isDebugEnabled()) {
log.debug("deleteAttendanceEvent aE: " + aE.getName());
}
log.debug("deleteAttendanceEvent aE: {}", aE.getName());

if(aE.getStats() !=null && aE.getStats().getId() == null){
aE.setStats(null);
Expand All @@ -188,9 +173,7 @@ public boolean deleteAttendanceEvent(AttendanceEvent aE) {
* {@inheritDoc}
*/
public AttendanceRecord getStatusRecord(final long id) {
if(log.isDebugEnabled()) {
log.debug("getAttendanceRecord()" + String.valueOf(id));
}
log.debug("getAttendanceRecord(){}", id);

return (AttendanceRecord) getByIDHelper(id, QUERY_GET_ATTENDANCE_RECORD);
}
Expand All @@ -199,9 +182,7 @@ public AttendanceRecord getStatusRecord(final long id) {
* {@inheritDoc}
*/
public boolean addAttendanceRecord(AttendanceRecord aR) {
if(log.isDebugEnabled()){
log.debug("addAttendanceRecord sR for User '" + aR.getUserID() + "' event " + aR.getAttendanceEvent().getName() + " with Status " + aR.getStatus().toString());
}
log.debug("addAttendanceRecord sR for User '{}' event {} with Status {}", aR.getUserID(), aR.getAttendanceEvent().getName(), aR.getStatus().toString());

try {
getHibernateTemplate().save(aR);
Expand Down Expand Up @@ -258,9 +239,7 @@ public void updateAttendanceStatuses(List<AttendanceStatus> attendanceStatusList
*/
@SuppressWarnings("unchecked")
public List<AttendanceStatus> getActiveStatusesForSite(final AttendanceSite attendanceSite) {
if(log.isDebugEnabled()){
log.debug("getActiveStatusesForSite(AttendanceSite " + attendanceSite.getSiteID() + " )");
}
log.debug("getActiveStatusesForSite(AttendanceSite {} )", attendanceSite.getSiteID());

try {
return getHibernateTemplate().execute(session -> session
Expand All @@ -278,9 +257,7 @@ public List<AttendanceStatus> getActiveStatusesForSite(final AttendanceSite atte
*/
@SuppressWarnings("unchecked")
public List<AttendanceStatus> getAllStatusesForSite(final AttendanceSite attendanceSite) {
if(log.isDebugEnabled()){
log.debug("getAllStatusesForSite(AttendanceSite attendanceSite)");
}
log.debug("getAllStatusesForSite(AttendanceSite attendanceSite)");

try {
return getHibernateTemplate().execute(session -> session
Expand All @@ -297,9 +274,7 @@ public List<AttendanceStatus> getAllStatusesForSite(final AttendanceSite attenda
* {@inheritDoc}
*/
public AttendanceStatus getAttendanceStatusById(final Long id) {
if(log.isDebugEnabled()) {
log.debug("getAttendanceStatus()" + String.valueOf(id));
}
log.debug("getAttendanceStatus(){}", id);

return (AttendanceStatus) getByIDHelper(id, QUERY_GET_ATTENDANCE_STATUS);
}
Expand All @@ -308,9 +283,7 @@ public AttendanceStatus getAttendanceStatusById(final Long id) {
* {@inheritDoc}
*/
public AttendanceGrade getAttendanceGrade(final Long id) {
if(log.isDebugEnabled()) {
log.debug("getAttendanceGrade, id: " + id.toString());
}
log.debug("getAttendanceGrade, id: " + id.toString());

return (AttendanceGrade) getByIDHelper(id, QUERY_GET_ATTENDANCE_GRADE_BY_ID);
}
Expand All @@ -319,9 +292,7 @@ public AttendanceGrade getAttendanceGrade(final Long id) {
* {@inheritDoc}
*/
public AttendanceGrade getAttendanceGrade(final String userID, final AttendanceSite aS) {
if(log.isDebugEnabled()) {
log.debug("getAttendanceGrades for user " + userID + " in site " + aS.getSiteID());
}
log.debug("getAttendanceGrades for user {} in site {}", userID, aS.getSiteID());

try{
return (AttendanceGrade) getHibernateTemplate().execute(session -> session
Expand All @@ -340,9 +311,7 @@ public AttendanceGrade getAttendanceGrade(final String userID, final AttendanceS
*/
@SuppressWarnings("unchecked")
public List<AttendanceGrade> getAttendanceGrades(final AttendanceSite aS) {
if(log.isDebugEnabled()){
log.debug("getAttendanceGrades for: " + aS.getSiteID());
}
log.debug("getAttendanceGrades for: {}", aS.getSiteID());

try{
return getHibernateTemplate().execute(session -> session
Expand All @@ -359,9 +328,7 @@ public List<AttendanceGrade> getAttendanceGrades(final AttendanceSite aS) {
* {@inheritDoc}
*/
public boolean addAttendanceGrade(AttendanceGrade aG) {
if(log.isDebugEnabled()){
log.debug("addAttendanceGrade for User '" + aG.getUserID() + "' grade " + aG.getGrade() + " for site " + aG.getAttendanceSite().getSiteID());
}
log.debug("addAttendanceGrade for User '{}' grade {} for site {}", aG.getUserID(), aG.getGrade(), aG.getAttendanceSite().getSiteID());

try {
getHibernateTemplate().save(aG);
Expand All @@ -376,9 +343,7 @@ public boolean addAttendanceGrade(AttendanceGrade aG) {
* {@inheritDoc}
*/
public boolean updateAttendanceGrade(AttendanceGrade aG) {
if(log.isDebugEnabled()){
log.debug("updateAttendanceGrade for User '" + aG.getUserID() + "' grade " + aG.getGrade() + " for site " + aG.getAttendanceSite().getSiteID());
}
log.debug("updateAttendanceGrade for User '{}' grade {} for site {}", aG.getUserID(), aG.getGrade(), aG.getAttendanceSite().getSiteID());

try {
getHibernateTemplate().saveOrUpdate(aG);
Expand All @@ -393,7 +358,7 @@ public boolean updateAttendanceGrade(AttendanceGrade aG) {
* {@inheritDoc}
*/
public AttendanceUserStats getAttendanceUserStats(final String userId, final AttendanceSite aS) {
log.debug("getAttendanceUserStats for User '" + userId + "' and Site: '" + aS.getSiteID() + "'.");
log.debug("getAttendanceUserStats for User '{}' and Site: '{}'.", userId, aS.getSiteID());

try{
return (AttendanceUserStats) getHibernateTemplate().execute(session -> session
Expand All @@ -402,7 +367,7 @@ public AttendanceUserStats getAttendanceUserStats(final String userId, final Att
.setParameter(USER_ID, userId)
.uniqueResult());
} catch (DataAccessException e) {
log.error("DataAccessException getting AttendanceUserStats for User '" + userId + "' and Site: '" + aS.getSiteID() + "'.", e);
log.error("DataAccessException getting AttendanceUserStats for User '{}' and Site: '{}'.", userId, aS.getSiteID(), e);
return null;
}
}
Expand All @@ -412,7 +377,7 @@ public AttendanceUserStats getAttendanceUserStats(final String userId, final Att
*/
@SuppressWarnings("unchecked")
public List<AttendanceUserStats> getAttendanceUserStatsForSite(final AttendanceSite aS) {
log.debug("getAttendanceUserStatsForSite for site: " + aS.getSiteID());
log.debug("getAttendanceUserStatsForSite for site: {}", aS.getSiteID());

try{
return getHibernateTemplate().execute(session -> session
Expand All @@ -429,13 +394,13 @@ public List<AttendanceUserStats> getAttendanceUserStatsForSite(final AttendanceS
* {@inheritDoc}
*/
public boolean updateAttendanceUserStats(AttendanceUserStats aUS) {
log.debug("updateAttendanceUserStats for User '" + aUS.getUserID() + "' and Site: '" + aUS.getAttendanceSite().getSiteID() + "'.");
log.debug("updateAttendanceUserStats for User '{}' and Site: '{}'.", aUS.getUserID(), aUS.getAttendanceSite().getSiteID());

try {
getHibernateTemplate().saveOrUpdate(aUS);
return true;
} catch (DataAccessException e) {
log.error("updateAttendanceUserStats, id: '" + aUS.getId() + "' failed.", e);
log.error("updateAttendanceUserStats, id: '{}' failed.", aUS.getId(), e);
return false;
}
}
Expand All @@ -444,13 +409,8 @@ public boolean updateAttendanceUserStats(AttendanceUserStats aUS) {
* {@inheritDoc}
*/
public boolean addGradingRule(GradingRule gradingRule) {
if (log.isDebugEnabled()) {
log.debug("add grading rule to site " + gradingRule.getAttendanceSite().getSiteID() +
" status: " + gradingRule.getStatus() +
" range: " + gradingRule.getStartRange() +
" - " + gradingRule.getEndRange() +
" points: " + gradingRule.getPoints());
}
log.debug("add grading rule to site {} status: {} range: {} - {} points: {}", gradingRule.getAttendanceSite().getSiteID(), gradingRule.getStatus(), gradingRule.getStartRange(), gradingRule.getEndRange(), gradingRule.getPoints());

try {
getHibernateTemplate().save(gradingRule);
return true;
Expand Down Expand Up @@ -479,15 +439,15 @@ public boolean deleteGradingRule(GradingRule gradingRule) {
* {@inheritDoc}
*/
public AttendanceItemStats getAttendanceItemStats(AttendanceEvent aE) {
log.debug("getAttendanceUserStats for Event '" + aE.getName() + "' and Site: '" + aE.getAttendanceSite().getSiteID() + "'.");
log.debug("getAttendanceUserStats for Event '{}' and Site: '{}'.", aE.getName(), aE.getAttendanceSite().getSiteID());

try{
return (AttendanceItemStats) getHibernateTemplate().execute(session -> session
.getNamedQuery(QUERY_GET_ATTENDANCE_ITEM_STATS)
.setParameter(ATTENDANCE_EVENT, aE)
.uniqueResult());
} catch (DataAccessException e) {
log.error("DataAccessException getting AttendanceItemStats for Event '" + aE.getName() + "' and Site: '" + aE.getAttendanceSite().getSiteID() + "'.", e);
log.error("DataAccessException getting AttendanceItemStats for Event '{}' and Site: '{}'.", aE.getName(), aE.getAttendanceSite().getSiteID(), e);
return null;
}
}
Expand All @@ -496,7 +456,7 @@ public AttendanceItemStats getAttendanceItemStats(AttendanceEvent aE) {
* {@inheritDoc}
*/
public boolean updateAttendanceItemStats(AttendanceItemStats aIS) {
log.debug("updateAttendanceItemStats, '" + aIS.getId() + "', for Event '" + aIS.getAttendanceEvent().getName() + "' and site: '" + aIS.getAttendanceEvent().getAttendanceSite().getSiteID() + "'.");
log.debug("updateAttendanceItemStats, '{}', for Event '{}' and site: '{}'.", aIS.getId(), aIS.getAttendanceEvent().getName(), aIS.getAttendanceEvent().getAttendanceSite().getSiteID());

try {
getHibernateTemplate().saveOrUpdate(aIS);
Expand All @@ -512,9 +472,7 @@ public boolean updateAttendanceItemStats(AttendanceItemStats aIS) {
*/
@SuppressWarnings("unchecked")
public List<GradingRule> getGradingRulesForSite(AttendanceSite attendanceSite) {
if(log.isDebugEnabled()){
log.debug("getGradingRulesForSite(AttendanceSite " + attendanceSite.getSiteID() + " )");
}
log.debug("getGradingRulesForSite(AttendanceSite {} )", attendanceSite.getSiteID());

try {
return getHibernateTemplate().execute(session -> session
Expand Down Expand Up @@ -589,9 +547,7 @@ public void init() {

@SuppressWarnings("unchecked")
private List<AttendanceEvent> getEventsForAttendanceSiteHelper(final AttendanceSite aS){
if(log.isDebugEnabled()){
log.debug("getAttendanceEventsForSiteHelper()");
}
log.debug("getAttendanceEventsForSiteHelper()");

try {
return getHibernateTemplate().execute(session -> session
Expand All @@ -607,9 +563,7 @@ private List<AttendanceEvent> getEventsForAttendanceSiteHelper(final AttendanceS

// Generic Function to get something by it's ID.
private Object getByIDHelper(final long id, final String queryString) {
if(log.isDebugEnabled()) {
log.debug("getByIDHelper() id: '" + String.valueOf(id) + "' String: " + queryString);
}
log.debug("getByIDHelper() id: '{}' String: {}", id, queryString);

try {
return getHibernateTemplate().execute(session -> session
Expand All @@ -619,7 +573,7 @@ private Object getByIDHelper(final long id, final String queryString) {
.uniqueResult());

} catch (DataAccessException e) {
log.error("getByIDHelper for " + queryString + " failed", e);
log.error("getByIDHelper for {} failed", queryString, e);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void buildDocumentShell(OutputStream outputStream, boolean isSignInSheet
document.close(); // no need to close PDFwriter?

} catch (DocumentException e) {
e.printStackTrace();
log.warn("Exception creating PDF", e);
}
}

Expand All @@ -135,7 +135,7 @@ private PdfPTable signInSheetTable() {
table.addCell(nameHeader);
table.addCell(signatureHeader);

Collections.sort(users, new SortNameUserComparator());
users.sort(new SortNameUserComparator());

for(User user : users) {

Expand Down Expand Up @@ -190,7 +190,7 @@ private PdfPTable attendanceSheetTable() {
table.addCell(statusHeader);
}

Collections.sort(users, new SortNameUserComparator());
users.sort(new SortNameUserComparator());

for(User user : users) {

Expand Down
Loading

0 comments on commit c7824b5

Please sign in to comment.