Skip to content

Commit

Permalink
Merge pull request #422 from mp-access/dev
Browse files Browse the repository at this point in the history
Release 0.15.0
  • Loading branch information
a-a-hofmann authored Dec 11, 2019
2 parents 16e2cf0 + 05405c9 commit 7fbe1f0
Show file tree
Hide file tree
Showing 38 changed files with 487 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public boolean hasAdminAccessToCourse(CourseAuthentication authentication, Cours
return authentication.hasAdminAccess(course.getId());
}

/**
* Evaluates if current logged in user has access to a course
*
* @param authentication contains the information to which course a user has access to
* @param courseId course to access
* @return
* @see CourseAuthentication#getCourseAccesses()
*/
public boolean hasAdminAccessToCourse(CourseAuthentication authentication, String courseId) {
return authentication.hasAdminAccess(courseId);
}

/**
* Evaluates if current logged in user has access to the exercise.
* <p>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/uzh/ifi/access/course/dao/CourseDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ List<Exercise> lookForBreakingChanges(Course before, Course after) {
List<Exercise> breakingChangesForAssignment = beforeExercises
.stream()
.filter(beforeExercise -> {
Optional<Exercise> optAfterExercise = afterAssignment.getExercises().stream().filter(afterExercise -> afterExercise.hasSameIndex(beforeExercise)).findFirst();
Optional<Exercise> optAfterExercise = afterAssignment.getExercises().stream().filter(afterExercise -> afterExercise.hasSameOrder(beforeExercise)).findFirst();
// if an exercise is found, check if it is a breaking change, else exercise was removed and is considered a breaking change
return optAfterExercise.map(beforeExercise::isBreakingChange).orElse(true);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class AssignmentMetadataDTO implements HasPublishingDate, HasDueDate {
private boolean isPublished;
private boolean isPastDueDate;

private int index;

private List<BreadCrumb> breadCrumbs;
private List<ExerciseMetadataDTO> exercises = new ArrayList<>();

Expand All @@ -31,6 +33,7 @@ public AssignmentMetadataDTO(Assignment assignment) {
this.isPublished = assignment.isPublished();
this.isPastDueDate = assignment.isPastDueDate();
this.breadCrumbs = assignment.getBreadCrumbs();
this.index = assignment.getIndex();

if (assignment.getExercises() != null) {
for (Exercise e : assignment.getExercises()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ExerciseMetadataDTO {
private String language;
private Boolean isGraded;
private double maxScore;
private int index;

public ExerciseMetadataDTO(Exercise exercise) {
this.id = exercise.getId();
Expand All @@ -25,5 +26,6 @@ public ExerciseMetadataDTO(Exercise exercise) {
this.language = exercise.getLanguage();
this.isGraded = exercise.getIsGraded();
this.maxScore = exercise.getMaxScore();
this.index = exercise.getIndex();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import ch.uzh.ifi.access.course.model.ExerciseConfig;
import ch.uzh.ifi.access.course.model.VirtualFile;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
public class ExerciseWithSolutionsDTO extends ExerciseConfig {

private final String id;
Expand Down Expand Up @@ -48,5 +50,6 @@ public ExerciseWithSolutionsDTO(Exercise exercise) {
this.courseId = exercise.getCourseId();
this.assignmentId = exercise.getAssignmentId();
this.breadCrumbs = exercise.getBreadCrumbs();
this.index = exercise.getIndex();
}
}
30 changes: 18 additions & 12 deletions src/main/java/ch/uzh/ifi/access/course/model/Assignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Assignment extends AssignmentConfig implements IndexedCollection<Exercise>, Indexed<Assignment>, HasBreadCrumbs {
public class Assignment extends AssignmentConfig implements OrderedCollection<Exercise>, Ordered<Assignment>, HasBreadCrumbs {
private final String id;
private int index;
private int order;

@JsonIgnore
@ToString.Exclude
Expand All @@ -33,10 +34,10 @@ public Assignment(String name) {
}

@Builder
private Assignment(String title, String description, ZonedDateTime publishDate, ZonedDateTime dueDate, String id, int index, Course course, List<Exercise> exercises) {
private Assignment(String title, String description, ZonedDateTime publishDate, ZonedDateTime dueDate, String id, int order, Course course, List<Exercise> exercises) {
super(title, description, publishDate, dueDate);
this.id = id;
this.index = index;
this.order = order;
this.course = course;
this.exercises = exercises;
}
Expand All @@ -50,13 +51,14 @@ public void set(AssignmentConfig other) {

public void update(Assignment other) {
set(other);
this.update(other.getIndexedItems());
this.update(other.getOrderedItems());
}

public void addExercise(Exercise ex) {
exercises.add(ex);
ex.setAssignment(this);
exercises.sort(Comparator.comparing(Exercise::getIndex));
exercises.sort(Comparator.comparing(Exercise::getOrder));
indexExercises();
}

public void addExercises(Exercise... exercises) {
Expand All @@ -75,19 +77,23 @@ public double getMaxScore() {


@Override
public List<Exercise> getIndexedItems() {
public List<Exercise> getOrderedItems() {
return exercises;
}

@Override
public List<BreadCrumb> getBreadCrumbs() {
List<BreadCrumb> bc = new ArrayList<>();
BreadCrumb c = new BreadCrumb(this.getCourse().title, "courses/" + this.getCourse().getId());
BreadCrumb a = new BreadCrumb(this.title, "courses/" + this.getCourse().getId() + "/assignments/" + this.id);
bc.add(c);
bc.add(a);
BreadCrumb course = new BreadCrumb(this.getCourse().title, "courses/" + this.getCourse().getId());
BreadCrumb assignment = new BreadCrumb(this.title, "courses/" + this.getCourse().getId() + "/assignments/" + this.id, this.index);

return bc;
return List.of(course, assignment);
}

private void indexExercises() {
for (var i = 0; i < exercises.size(); i++) {
var exercise = exercises.get(i);
exercise.setIndex(i + 1);
}
}
}

6 changes: 6 additions & 0 deletions src/main/java/ch/uzh/ifi/access/course/model/BreadCrumb.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
public class BreadCrumb {
public String title;
public String url;
public int index;

public BreadCrumb(String title, String url){
this(title, url, -1);
}

public BreadCrumb(String title, String url, int index){
this.title = title;
this.url = url;
this.index = index;
}
}
26 changes: 18 additions & 8 deletions src/main/java/ch/uzh/ifi/access/course/model/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Course extends CourseConfig implements IndexedCollection<Assignment>, HasBreadCrumbs {
public class Course extends CourseConfig implements OrderedCollection<Assignment>, HasBreadCrumbs {
private final String id;

@ToString.Exclude
Expand Down Expand Up @@ -61,13 +61,14 @@ public void update(Course other) {
set(other);
this.gitHash = other.gitHash;

this.update(other.getIndexedItems());
this.update(other.getOrderedItems());
}

public void addAssignment(Assignment a) {
a.setCourse(this);
assignments.add(a);
assignments.sort(Comparator.comparing(Assignment::getIndex));
assignments.sort(Comparator.comparing(Assignment::getOrder));
indexAssignments();
}

public void addAssignments(Assignment... assignments) {
Expand All @@ -82,7 +83,7 @@ public Optional<Assignment> getAssignmentById(String id) {

@JsonIgnore
@Override
public List<Assignment> getIndexedItems() {
public List<Assignment> getOrderedItems() {
return assignments;
}

Expand All @@ -93,10 +94,19 @@ public List<Exercise> getExercises() {

@Override
public List<BreadCrumb> getBreadCrumbs() {
List<BreadCrumb> bc = new ArrayList<>();
BreadCrumb c = new BreadCrumb(this.title, "courses/" + this.id);
bc.add(c);
BreadCrumb course = new BreadCrumb(this.title, "courses/" + this.id);

return bc;
return List.of(course);
}

private void indexAssignments() {
for (var i = 0; i < assignments.size(); i++) {
var assignment = assignments.get(i);
assignment.setIndex(i + 1);
}
}

public boolean hasParticipant(String emailAddress) {
return students.contains(emailAddress) || assistants.contains(emailAddress) || admins.contains(emailAddress);
}
}
27 changes: 14 additions & 13 deletions src/main/java/ch/uzh/ifi/access/course/model/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
public class Exercise extends ExerciseConfig implements Indexed<Exercise>, HasBreadCrumbs, HasSetupScript {
public class Exercise extends ExerciseConfig implements Ordered<Exercise>, HasBreadCrumbs, HasSetupScript {

private final String id;
private int index;
private int order;
@ToString.Exclude
private String gitHash;

Expand Down Expand Up @@ -52,10 +53,10 @@ public Exercise(String name) {
}

@Builder
private Exercise(ExerciseType type, String language, Boolean isGraded, int maxScore, int maxSubmits, String gradingSetup, List<String> options, List<String> solutions, List<String> hints, String id, int index, String gitHash, Assignment assignment, String question, List<VirtualFile> private_files, List<VirtualFile> solution_files, List<VirtualFile> resource_files, List<VirtualFile> public_files, CodeExecutionLimits executionLimits, String title, String longTitle, Rounding rounding) {
private Exercise(ExerciseType type, String language, Boolean isGraded, int maxScore, int maxSubmits, String gradingSetup, List<String> options, List<String> solutions, List<String> hints, String id, int order, String gitHash, Assignment assignment, String question, List<VirtualFile> private_files, List<VirtualFile> solution_files, List<VirtualFile> resource_files, List<VirtualFile> public_files, CodeExecutionLimits executionLimits, String title, String longTitle, Rounding rounding) {
super(title, longTitle, type, language, isGraded, maxScore, maxSubmits, gradingSetup, rounding, options, solutions, hints, executionLimits);
this.id = id;
this.index = index;
this.order = order;
this.gitHash = gitHash;
this.assignment = assignment;
this.question = question;
Expand Down Expand Up @@ -189,7 +190,7 @@ public boolean isBreakingChange(Exercise other) {
!Objects.equals(this.solutions, other.solutions) ||
!Objects.equals(this.executionLimits, other.executionLimits) ||

!Objects.equals(this.index, other.index) ||
!Objects.equals(this.order, other.order) ||
!Objects.equals(this.question, other.question) ||
!Objects.equals(this.private_files, other.private_files) ||
!Objects.equals(this.resource_files, other.resource_files) ||
Expand All @@ -200,14 +201,14 @@ public boolean isBreakingChange(Exercise other) {

@Override
public List<BreadCrumb> getBreadCrumbs() {
List<BreadCrumb> bc = new ArrayList<>();
BreadCrumb c = new BreadCrumb(this.getAssignment().getCourse().getTitle(), "courses/" + this.getAssignment().getCourse().getId());
BreadCrumb a = new BreadCrumb(this.getAssignment().getTitle(), "courses/" + this.getAssignment().getCourse().getId() + "/assignments/" + this.getAssignment().getId());
BreadCrumb e = new BreadCrumb(this.getTitle(), "exercises/" + this.id);
bc.add(c);
bc.add(a);
bc.add(e);

return bc;
BreadCrumb course = new BreadCrumb(this.getAssignment().getCourse().getTitle(), "courses/" + this.getAssignment().getCourse().getId());
BreadCrumb assignment = new BreadCrumb(this.getAssignment().getTitle(), "courses/" + this.getAssignment().getCourse().getId() + "/assignments/" + this.getAssignment().getId(), getAssignment().getIndex());
BreadCrumb exercise = new BreadCrumb(this.getTitle(), "exercises/" + this.id, this.index);

return List.of(course, assignment, exercise);
}

public String getAssignmentExerciseIndexing() {
return String.format("ex%s-t%s", this.assignment.getIndex(), this.index);
}
}
12 changes: 0 additions & 12 deletions src/main/java/ch/uzh/ifi/access/course/model/Indexed.java

This file was deleted.

12 changes: 12 additions & 0 deletions src/main/java/ch/uzh/ifi/access/course/model/Ordered.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ch.uzh.ifi.access.course.model;

public interface Ordered<T> {

int getOrder();

void update(T update);

default boolean hasSameOrder(Ordered other) {
return other != null && getOrder() == other.getOrder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
import java.util.List;
import java.util.Optional;

public interface IndexedCollection<T extends Indexed<T>> {
public interface OrderedCollection<T extends Ordered<T>> {

default void update(List<T> otherItems) {
List<T> thisItems = this.getIndexedItems();
List<T> thisItems = this.getOrderedItems();

thisItems.removeIf(thisItem -> otherItems.stream().noneMatch(otherItem -> otherItem.hasSameIndex(thisItem)));
thisItems.removeIf(thisItem -> otherItems.stream().noneMatch(otherItem -> otherItem.hasSameOrder(thisItem)));

otherItems.forEach(otherItem -> {
Optional<T> first = thisItems.stream().filter(thisItem -> thisItem.hasSameIndex(otherItem)).findFirst();
Optional<T> first = thisItems.stream().filter(thisItem -> thisItem.hasSameOrder(otherItem)).findFirst();
first.ifPresentOrElse(thisItem -> thisItem.update(otherItem), () -> thisItems.add(otherItem));
});

thisItems.sort(Comparator.comparing(Indexed::getIndex));
thisItems.sort(Comparator.comparing(Ordered::getOrder));
}

List<T> getIndexedItems();
List<T> getOrderedItems();
}
8 changes: 4 additions & 4 deletions src/main/java/ch/uzh/ifi/access/course/util/RepoCacher.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,20 @@ private void cacheRepo(File file, Object context) {
Course c = ((Course) context);

String cleanName = cleanFolderName(file.getName());
int index = Integer.parseInt(cleanName.replace(ASSIGNMENT_FOLDER_PREFIX, ""));
int order = Integer.parseInt(cleanName.replace(ASSIGNMENT_FOLDER_PREFIX, ""));

Assignment assignment = new Assignment(c.getGitURL() + cleanName);
assignment.setIndex(index);
assignment.setOrder(order);
c.addAssignment(assignment);
next_context = assignment;
} else if (file.getName().startsWith(EXERCISE_FOLDER_PREFIX)) {
Assignment a = ((Assignment) context);

String cleanName = cleanFolderName(file.getName());
int index = Integer.parseInt(cleanName.replace(EXERCISE_FOLDER_PREFIX, ""));
int order = Integer.parseInt(cleanName.replace(EXERCISE_FOLDER_PREFIX, ""));

Exercise exercise = new Exercise(a.getId() + cleanName);
exercise.setIndex(index);
exercise.setOrder(order);
exercise.setGitHash(((Assignment) context).getCourse().getGitHash());
a.addExercise(exercise);
next_context = exercise;
Expand Down
Loading

0 comments on commit 7fbe1f0

Please sign in to comment.