Skip to content

Commit

Permalink
Add last modified by and date fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ottenhoff committed Dec 13, 2024
1 parent a100f46 commit bf5160c
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<one-to-many class="org.sakaiproject.attendance.model.AttendanceRecord" />
</set>
<one-to-one name="stats" cascade="all" lazy="false" class="AttendanceItemStats" />
<property name="lastModifiedBy" column="LAST_MODIFIED_BY" type="java.lang.String" length="99" not-null="true" />
<property name="lastModifiedDate" column="LAST_MODIFIED_DATE" type="timestamp" not-null="true" />

</class>

<query name="getAttendanceEvent">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<property name="override" column="OVERRIDE" type="java.lang.Boolean" />

<many-to-one name="attendanceSite" column="A_SITE_ID" unique="false" not-null="true" class="org.sakaiproject.attendance.model.AttendanceSite" lazy="false"/>
<property name="lastModifiedBy" column="LAST_MODIFIED_BY" type="java.lang.String" length="99" not-null="true" />
<property name="lastModifiedDate" column="LAST_MODIFIED_DATE" type="timestamp" not-null="true" />

</class>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<property name="status" column="STATUS" type="org.sakaiproject.attendance.types.StatusUserType" length="20" />
<property name="comment" column="RECORD_COMMENT" type="text" length="4000" />

<property name="lastModifiedBy" column="LAST_MODIFIED_BY" type="java.lang.String" length="99" not-null="true" />
<property name="lastModifiedDate" column="LAST_MODIFIED_DATE" type="timestamp" not-null="true" />

<many-to-one name="attendanceEvent" column="A_EVENT_ID" unique="false" not-null="true" class="AttendanceEvent" lazy="false" unique-key="user_record" />
</class>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
<property name="startRange" column="START_RANGE" type="java.lang.Integer" not-null="true"/>
<property name="endRange" column="END_RANGE" type="java.lang.Integer" />
<property name="points" column="POINTS" type="java.lang.Double" not-null="true"/>

<property name="lastModifiedBy" column="LAST_MODIFIED_BY" type="java.lang.String" length="99" not-null="true" />
<property name="lastModifiedDate" column="LAST_MODIFIED_DATE" type="timestamp" not-null="true" />
</class>

<query name="getGradingRulesForSite">
Expand Down
28 changes: 16 additions & 12 deletions api/src/java/org/sakaiproject/attendance/model/AttendanceEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,28 @@
* @author David Bauer [dbauer1 (at) udayton (dot) edu]
* @author Steve Swinsburg ([email protected])
*/
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(exclude={"records","stats"})
public class AttendanceEvent implements Serializable {
private static final long serialVersionUID = 1L;

@Getter @Setter private Long id;
@Getter @Setter private String name;
@Getter @Setter private Date startDateTime;
@Getter @Setter private Date endDateTime;
@Getter @Setter private Boolean isReoccurring;
@Getter @Setter private Long reoccurringID;
@Getter @Setter private Boolean isRequired;
@Getter @Setter private String releasedTo;
@Getter @Setter private AttendanceSite attendanceSite;
@Getter @Setter private String location;
@Getter @Setter private Set<AttendanceRecord> records = new HashSet<AttendanceRecord>(0);
@Getter @Setter private AttendanceItemStats stats;
private Long id;
private String name;
private Date startDateTime;
private Date endDateTime;
private Boolean isReoccurring;
private Long reoccurringID;
private Boolean isRequired;
private String releasedTo;
private AttendanceSite attendanceSite;
private String location;
private Set<AttendanceRecord> records = new HashSet<AttendanceRecord>(0);
private AttendanceItemStats stats;
private String lastModifiedBy;
private Date lastModifiedDate;

// Copy constructor
public AttendanceEvent(AttendanceEvent attendanceEvent){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
* The AttendanceGrade earned for the all AttendanceItems
Expand All @@ -38,8 +39,9 @@ public class AttendanceGrade implements Serializable {
private Double grade;
private String userID;
private Boolean override;

private AttendanceSite attendanceSite;
private String lastModifiedBy;
private Date lastModifiedDate;

public AttendanceGrade(AttendanceSite aS, String userId){
this.attendanceSite = aS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.*;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
Expand All @@ -28,17 +29,21 @@
* @author David Bauer [dbauer1 (at) udayton (dot) edu]
* @author Steve Swinsburg ([email protected])
*/
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public class AttendanceRecord implements Serializable {
private static final long serialVersionUID = 1L;

@Getter @Setter private Long id;
@Getter @Setter private AttendanceEvent attendanceEvent;
@Getter @Setter private String userID;
@Getter @Setter private Status status;
@Getter @Setter private String comment;
private Long id;
private AttendanceEvent attendanceEvent;
private String userID;
private Status status;
private String comment;
private String lastModifiedBy;
private Date lastModifiedDate;

public AttendanceRecord(AttendanceEvent e, String uId, Status s) {
this.attendanceEvent = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
* @author David P. Bauer [dbauer1 (at) udayton (dot) edu]
Expand All @@ -37,6 +38,8 @@ public class GradingRule implements Serializable {
private Integer startRange;
private Integer endRange;
private Double points;
private String lastModifiedBy;
private Date lastModifiedDate;

public GradingRule(AttendanceSite attendanceSite) {
this.attendanceSite = attendanceSite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public boolean deleteAttendanceEvent(AttendanceEvent aE) {
getHibernateTemplate().delete(getHibernateTemplate().merge(aE));
return true;
} catch (DataAccessException e) {
log.error("deleteAttendanceEvent, " + aE.getId() + ", failed.", e);
log.error("deleteAttendanceEvent, {}, failed.", aE.getId(), e);
return false;
}
}
Expand Down Expand Up @@ -424,13 +424,13 @@ public boolean addGradingRule(GradingRule gradingRule) {
* {@inheritDoc}
*/
public boolean deleteGradingRule(GradingRule gradingRule) {
log.debug("Delete grading rule from site " + gradingRule.getAttendanceSite().getSiteID() + " grading rule: " + gradingRule.getId());
log.debug("Delete grading rule from site {} grading rule: {}", gradingRule.getAttendanceSite().getSiteID(), gradingRule.getId());

try {
getHibernateTemplate().delete(getHibernateTemplate().merge(gradingRule));
return true;
} catch (DataAccessException e) {
log.error("deleteGradingRule, " + gradingRule.getId() + ", failed.", e);
log.error("deleteGradingRule, {}, failed.", gradingRule.getId(), e);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public List<AttendanceEvent> getAttendanceEventsForCurrentSite(){
* {@inheritDoc}
*/
public Serializable addAttendanceEventNow(AttendanceEvent e) {
updateModifier(e);
return dao.addAttendanceEventNow(e);
}

Expand All @@ -117,6 +118,7 @@ public boolean updateAttendanceEvent(AttendanceEvent aE) throws IllegalArgumentE
throw new IllegalArgumentException("AttendanceEvent is null");
}

updateModifier(aE);
return dao.updateAttendanceEvent(aE);
}

Expand All @@ -140,6 +142,7 @@ public boolean deleteAttendanceEvent(AttendanceEvent aE) throws IllegalArgumentE
}
}

sakaiProxy.postEvent("attendance.event.delete", aE.getId() + "", true);
return dao.deleteAttendanceEvent(aE);
}

Expand Down Expand Up @@ -206,9 +209,26 @@ public boolean updateAttendanceRecord(AttendanceRecord aR, Status oldStatus) thr

updateStats(aR, oldStatus);
regradeForAttendanceRecord(aR);
updateModifier(aR);
return dao.updateAttendanceRecord(aR);
}

private void updateModifier(Object obj) {
if (obj instanceof AttendanceRecord aR) {
aR.setLastModifiedBy(sakaiProxy.getCurrentUserId());
aR.setLastModifiedDate(new Date());
} else if (obj instanceof AttendanceEvent aE) {
aE.setLastModifiedBy(sakaiProxy.getCurrentUserId());
aE.setLastModifiedDate(new Date());
} else if (obj instanceof AttendanceGrade aG) {
aG.setLastModifiedBy(sakaiProxy.getCurrentUserId());
aG.setLastModifiedDate(new Date());
} else if (obj instanceof GradingRule gR) {
gR.setLastModifiedBy(sakaiProxy.getCurrentUserId());
gR.setLastModifiedDate(new Date());
}
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -278,6 +298,7 @@ public void updateAttendanceRecordsForEvent(AttendanceEvent aE, Status s, String
aR.setStatus(s);
updateUserStats(aR, oldStatus);
regradeForAttendanceRecord(aR);
updateModifier(aR);
dao.updateAttendanceRecord(aR); //change the actual data for the student we've just iterated past. This saves looping through it again as part of dao.updateAttendanceRecords on a whole array.
}

Expand Down Expand Up @@ -491,6 +512,7 @@ public boolean updateAttendanceGrade(AttendanceGrade aG) throws IllegalArgumentE
throw new IllegalArgumentException("AttendanceGrade cannot be null");
}

updateModifier(aG);
boolean saved = dao.updateAttendanceGrade(aG);

if(saved && aG.getAttendanceSite().getSendToGradebook()) {
Expand Down Expand Up @@ -525,14 +547,18 @@ public int getStatsForStatus(AttendanceStats stats, Status status) {
* {@inheritDoc}
*/
public boolean addGradingRule(GradingRule gradingRule) {
return gradingRule != null && dao.addGradingRule(gradingRule);
if (gradingRule == null) return false;
updateModifier(gradingRule);
return dao.addGradingRule(gradingRule);
}

/**
* {@inheritDoc}
*/
public boolean deleteGradingRule(GradingRule gradingRule) {
return gradingRule != null && dao.deleteGradingRule(gradingRule);
if (gradingRule == null) return false;
updateModifier(gradingRule);
return dao.deleteGradingRule(gradingRule);
}

/**
Expand Down

0 comments on commit bf5160c

Please sign in to comment.