Skip to content

Commit

Permalink
SAK-46685 Assignment move TimeSheet to be it's own independent service (
Browse files Browse the repository at this point in the history
sakaiproject#10096)

* SAK-46685 Getting TimeSheet independent of assignment

* Minor changes and unit tests

* Update kernel/api/src/main/java/org/sakaiproject/timesheet/api/TimeSheetEntry.java

Co-authored-by: Earle Nietzel <[email protected]>

* Changing TimeSheetEntry index and format changes

Co-authored-by: Earle Nietzel <[email protected]>
  • Loading branch information
Fernando Alvarez-Castellanos Rojo and ern authored Jan 13, 2022
1 parent 1b0a09a commit 2be7718
Show file tree
Hide file tree
Showing 22 changed files with 502 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.sakaiproject.assignment.api.model.AssignmentSubmission;
import org.sakaiproject.assignment.api.model.AssignmentSubmissionSubmitter;
import org.sakaiproject.content.api.ContentResource;
import org.sakaiproject.assignment.api.model.TimeSheetEntry;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityProducer;
import org.sakaiproject.entity.api.Reference;
Expand All @@ -43,6 +42,7 @@
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.site.api.Group;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.timesheet.api.TimeSheetEntry;
import org.sakaiproject.user.api.User;

/**
Expand Down Expand Up @@ -759,8 +759,6 @@ public String getDeepLinkWithPermissions(String context, String assignmentId, bo
*/
public void postReviewableSubmissionAttachments(AssignmentSubmission submission);

boolean isTimeSheetEnabled(String siteId);

/**
* This will return the internationalized title of the tool.
* This is used when creating a new gradebook item.
Expand Down Expand Up @@ -823,11 +821,11 @@ public String getDeepLinkWithPermissions(String context, String assignmentId, bo
*/
public List<MultiGroupRecord> checkSubmissionForUsersInMultipleGroups(String siteId, Group submissionGroup, Collection<Group> asnGroups);

public boolean isValidTimesheetTime(String timeSheet);
public boolean isValidTimeSheetTime(String timeSheet);

public TimeSheetEntry getTimeSheetEntry(Long timeSheetId) throws PermissionException;
public List<TimeSheetEntry> getTimeSheetEntries(AssignmentSubmissionSubmitter submissionSubmitter);

public void newTimeSheetEntry(AssignmentSubmissionSubmitter submissionSubmitter, TimeSheetEntry timeSheet) throws PermissionException;
public void saveTimeSheetEntry(AssignmentSubmissionSubmitter submissionSubmitter, TimeSheetEntry timeSheet) throws PermissionException;

public void deleteTimeSheetEntry(Long timeSheetId) throws PermissionException;

Expand All @@ -843,4 +841,14 @@ public String getDeepLinkWithPermissions(String context, String assignmentId, bo
* @return
*/
public String createContentReviewAssignment(Assignment a, String assignmentRef, Instant openTime, Instant dueTime, Instant closeTime);

public String getTotalTimeSheet(AssignmentSubmissionSubmitter asnSubmissionSubmiter);

public boolean existsTimeSheetEntries(AssignmentSubmissionSubmitter asnSubmissionSubmitter);

public Integer timeToInt(String time);

public String intToTime(int time);

public boolean isTimeSheetEnabled(String siteId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import com.fasterxml.jackson.annotation.JsonManagedReference;

/**
* Defines a relation between a submission and the submission's submitters.
* <br/> - A submitter can have its own grade separate from the grade of the submission,
Expand Down Expand Up @@ -98,9 +89,4 @@ public class AssignmentSubmissionSubmitter {
@Column(name = "TIME_SPENT", length = 255)
private String timeSpent;

@OneToMany(mappedBy = "assignmentSubmissionSubmitter", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy("startTime ASC")
@JsonManagedReference
private Set<TimeSheetEntry> timeSheetEntries = new HashSet<>();

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.sakaiproject.assignment.api.model.Assignment;
import org.sakaiproject.assignment.api.model.AssignmentSubmission;
import org.sakaiproject.assignment.api.model.AssignmentSubmissionSubmitter;
import org.sakaiproject.assignment.api.model.TimeSheetEntry;
import org.sakaiproject.serialization.SerializableRepository;

/**
Expand Down Expand Up @@ -95,12 +94,4 @@ AssignmentSubmission newSubmission(String assignmentId,

Collection<String> findGroupsForAssignmentById(String assignmentId);

void newTimeSheetEntry(AssignmentSubmissionSubmitter submissionSubmitter, TimeSheetEntry timeSheetEntry);

boolean existsTimeSheetEntry(Long timeSheetId);

TimeSheetEntry findTimeSheetEntry(Long timeSheetId);

void deleteTimeSheetEntry(Long timeSheetId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
import org.sakaiproject.assignment.api.model.AssignmentSubmissionSubmitter;
import org.sakaiproject.assignment.api.model.AssignmentSupplementItemAttachment;
import org.sakaiproject.assignment.api.model.AssignmentSupplementItemService;
import org.sakaiproject.assignment.api.model.TimeSheetEntry;
import org.sakaiproject.assignment.api.persistence.AssignmentRepository;
import org.sakaiproject.assignment.api.reminder.AssignmentDueReminderService;
import org.sakaiproject.assignment.api.taggable.AssignmentActivityProducer;
Expand Down Expand Up @@ -167,6 +166,8 @@
import org.sakaiproject.tasks.api.TaskService;
import org.sakaiproject.time.api.TimeService;
import org.sakaiproject.time.api.UserTimeService;
import org.sakaiproject.timesheet.api.TimeSheetEntry;
import org.sakaiproject.timesheet.api.TimeSheetService;
import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.tool.api.Tool;
import org.sakaiproject.tool.api.ToolManager;
Expand Down Expand Up @@ -245,13 +246,12 @@ public class AssignmentServiceImpl implements AssignmentService, EntityTransferr
@Setter private UserDirectoryService userDirectoryService;
@Resource private UserMessagingService userMessagingService;
@Setter private UserTimeService userTimeService;
@Setter private TimeSheetService timeSheetService;

private boolean allowSubmitByInstructor;
private boolean exposeContentReviewErrorsToUI;
private boolean createGroupsOnImport;

private Pattern timesheetTimePattern;

private static ResourceLoader rb = new ResourceLoader("assignment");

public void init() {
Expand Down Expand Up @@ -286,16 +286,11 @@ public void init() {
userMessagingService.importTemplateFromResourceXmlFile("templates/releaseResubmission.xml", AssignmentConstants.TOOL_ID + ".releaseresubmission");
userMessagingService.importTemplateFromResourceXmlFile("templates/submission.xml", AssignmentConstants.TOOL_ID + ".submission");
userMessagingService.importTemplateFromResourceXmlFile("templates/dueReminder.xml", AssignmentConstants.TOOL_ID + ".duereminder");

timesheetTimePattern = Pattern.compile(serverConfigurationService.getString("assignment.timesheet.timePattern", SAK_PROP_ASSIGNMENT_TIMESHEET_TIME_PATTERN_DEFAULT));
}

@Override
public boolean isTimeSheetEnabled(String siteId) {
List<String> timesheetConfig = serverConfigurationService.getStringList(SAK_PROP_ASSIGNMENT_TIMESHEET_SITES_ALLOWED, Collections.singletonList("none"));

// TODO logic for determining whether this feature is enabled in the current site
return Stream.of("all", siteId).filter(Objects::nonNull).anyMatch(timesheetConfig::contains);
return timeSheetService.isTimeSheetEnabled(siteId);
}

@Override
Expand Down Expand Up @@ -856,35 +851,48 @@ public Assignment addAssignment(String context) throws PermissionException {
return assignment;
}

@Override
@Transactional
public void newTimeSheetEntry(AssignmentSubmissionSubmitter submissionSubmitter, TimeSheetEntry timeSheetEntry) throws PermissionException {
@Override
public void saveTimeSheetEntry(AssignmentSubmissionSubmitter submissionSubmitter, TimeSheetEntry timeSheetEntry) throws PermissionException {
if (submissionSubmitter != null && timeSheetEntry != null) {
AssignmentSubmission submission = submissionSubmitter.getSubmission();
String siteId = AssignmentReferenceReckoner.reckoner().submission(submission).reckon().getContext();
if (!allowAddSubmission(siteId)) {
throw new PermissionException(sessionManager.getCurrentSessionUserId(), SECURE_ADD_ASSIGNMENT_SUBMISSION, null);
}
assignmentRepository.newTimeSheetEntry(submissionSubmitter, timeSheetEntry);
timeSheetEntry.setReference(AssignmentReferenceReckoner.reckoner().submission(submission).reckon().getReference());
timeSheetService.create(timeSheetEntry);
log.debug("Add time sheet entry for submitter: {}", submissionSubmitter);
}
}

@Override
@Transactional
@Override
public void deleteTimeSheetEntry(Long timeSheetEntryId) throws PermissionException {
TimeSheetEntry timeSheetEntry = getTimeSheetEntry(timeSheetEntryId);
if (timeSheetEntry != null) {
String siteId = AssignmentReferenceReckoner.reckoner().submission(timeSheetEntry.getAssignmentSubmissionSubmitter().getSubmission()).reckon().getContext();
if (!allowAddSubmission(siteId)) {
throw new PermissionException(sessionManager.getCurrentSessionUserId(), SECURE_UPDATE_ASSIGNMENT_SUBMISSION, null);
}
assignmentRepository.deleteTimeSheetEntry(timeSheetEntryId);
log.debug("Deleting time sheet entry: {}", timeSheetEntryId);
String timeSheetEntryReference = getTimeSheetEntryReference(timeSheetEntryId);
if (StringUtils.isNotBlank(timeSheetEntryReference)) {
String siteId = AssignmentReferenceReckoner.reckoner().reference(timeSheetEntryReference).reckon().getContext();
if (!allowAddSubmission(siteId)) {
throw new PermissionException(sessionManager.getCurrentSessionUserId(), SECURE_UPDATE_ASSIGNMENT_SUBMISSION, null);
}
timeSheetService.delete(timeSheetEntryId);
log.debug("Deleting time sheet entry: {}", timeSheetEntryId);
} else {
log.warn("Attempted to delete time sheet entry: {} however it does not exist.", timeSheetEntryId);
}
}

@Override
public List<TimeSheetEntry> getTimeSheetEntries(AssignmentSubmissionSubmitter submissionSubmitter) {
if (submissionSubmitter != null) {
String reference = AssignmentReferenceReckoner.reckoner().submission(submissionSubmitter.getSubmission()).reckon().getReference();
return timeSheetService.getByReference(reference);
} else {
log.warn("Attempted to delete time sheet entry: {} however it does not exist.", timeSheetEntryId);
// submission is null
log.debug("SubmissionSubmitter is null");
return null;
}
}
}

public String getTimeSpent(AssignmentSubmission submission) {
return submission.getSubmitters().stream().findAny().get().getTimeSpent();
Expand Down Expand Up @@ -1725,23 +1733,9 @@ public AssignmentSubmission getSubmission(String submissionId) throws Permission
return null;
}

@Override
public TimeSheetEntry getTimeSheetEntry(Long timeSheetId) throws PermissionException {
if (timeSheetId != null) {
TimeSheetEntry timeSheet = assignmentRepository.findTimeSheetEntry(timeSheetId);
if (timeSheet != null) {
String reference = AssignmentReferenceReckoner.reckoner().submission(timeSheet.getAssignmentSubmissionSubmitter().getSubmission()).reckon().getReference();
if (allowGetSubmission(reference)) {
return timeSheet;
} else {
throw new PermissionException(sessionManager.getCurrentSessionUserId(), SECURE_ACCESS_ASSIGNMENT_SUBMISSION, reference);
}
} else {
// timesheet not found
log.debug("TimeSheet does not exist {}", timeSheetId);
}
}
return null;
private String getTimeSheetEntryReference(Long timeSheetId) {
return timeSheetService.getTimeSheetEntryReference(timeSheetId);

}

@Override
Expand Down Expand Up @@ -5002,7 +4996,33 @@ private List<MultiGroupRecord> usersInMultipleGroups(String siteId, Collection<S
return dupes;
}

public boolean isValidTimesheetTime(String time) {
return timesheetTimePattern.matcher(time).matches();
@Override
public boolean existsTimeSheetEntries(AssignmentSubmissionSubmitter asnSubmissionSubmitter) {
AssignmentSubmission submission = asnSubmissionSubmitter.getSubmission();
String reference = AssignmentReferenceReckoner.reckoner().submission(submission).reckon().getReference();
return timeSheetService.existsAny(reference);
}

@Override
public boolean isValidTimeSheetTime(String time) {
return timeSheetService.isValidTimeSheetTime(time);
}

@Override
public String getTotalTimeSheet(AssignmentSubmissionSubmitter asnSubmissionSubmitter) {
AssignmentSubmission submission = asnSubmissionSubmitter.getSubmission();
String reference = AssignmentReferenceReckoner.reckoner().submission(submission).reckon().getReference();
return timeSheetService.getTotalTimeSheet(reference);
}

@Override
public Integer timeToInt(String time) {
return timeSheetService.timeToInt(time);
}

@Override
public String intToTime(int time) {
return timeSheetService.intToTime(time);
}

}
Loading

0 comments on commit 2be7718

Please sign in to comment.