Skip to content

Commit

Permalink
Merge pull request #155 from Want100Cookies/develop
Browse files Browse the repository at this point in the history
Getting ready for final release
  • Loading branch information
cassshh authored Jan 26, 2018
2 parents 105352b + 9d95ef8 commit 0b7ef8a
Show file tree
Hide file tree
Showing 70 changed files with 1,056 additions and 361 deletions.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
[![Build Status](https://travis-ci.com/Want100Cookies/GradeMaster.svg?token=sKpyGyXRMBtmPh6qJBuM&branch=develop)](https://travis-ci.com/Want100Cookies/GradeMaster)

# GradeMaster
A small application to ease the grading of groups for teachers.
A small application to ease the grading of project groups for teachers.

### Features:
- Teachers can assign and deadline a grade to a group
- Students can grade fellow group members before the deadline ends
- Teachers can finalize the given grades and export it to CSV/PDF

### Documentation
To view the documentation run the Spring boot app and visit [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html)
Swagger is used to document the API.
To view the documentation, run the Spring boot app and visit [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html)

### Setup
##### Backend
Docker is being used to run all the needed backend services:
```
$ docker-compose up -d
```

To run the backend the following environment variables should exist:
- EMAIL_HOST
- EMAIL_PORT
- EMAIL_USERNAME
- EMAIL_PASSWORD

*For intellij; Edit configurations... > **Select configuration** > Environment variables*

##### Frontend
```
$ cd ./src/main/resources/public
$ npm install
```

##### Now you're ready to run the Spring boot app :)

### Requirements
- Java SDK >= 8.x
- NPM >= 5.x
- Node >= 9.x
- Docker >= 17.x
- Docker-compose >= 1.18.x
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@SpringBootApplication
public class GradeMasterApplication {

public static void main(String[] args) { SpringApplication.run(GradeMasterApplication.class, args); }
public static void main(String[] args) {
SpringApplication.run(GradeMasterApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ public Group getGroup(@PathVariable Long groupId) {
public Group changeGroup(@PathVariable Long groupId, @RequestBody Group group) throws Exception {
Group existing = groupService.findById(groupId);
if (existing == null) throw new InvalidParameterException("Group id not found");
Set<User> users = group.getUsers();
group.setUsers(null); // hacks
group.copyNonNullProperties(existing);
return groupService.save(existing);
return groupService.save(existing, users);
}

@RequestMapping(value = "/groups/{groupId}", method = RequestMethod.DELETE)
Expand Down Expand Up @@ -105,8 +107,7 @@ public Set<User> getGroupUsers(@PathVariable Long groupId) {
public Group setGroupUsers(@PathVariable Long groupId, @RequestBody Set<User> users) {
Group group = groupService.findById(groupId);
if (group == null) throw new InvalidParameterException("Group id not found");
group.setUsers(users);
return groupService.save(group);
return groupService.save(group, users);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Notification markNotificationSeen(Authentication authentication, @PathVar
User user = ((UserDetails) authentication.getPrincipal()).getUser();

Notification notification = notificationService.findById(notificationId);
if(notification.getUser().getId().equals(user.getId())) {
if (notification.getUser().getId().equals(user.getId())) {
notification.setSeen(true);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/datbois/grademaster/model/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class Email {
private String link;
private String linkText;

public Email(){}
public Email() {
}

public Email(String to, String subject, String body) {
this.to = to;
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/datbois/grademaster/model/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,41 @@ public void setGrades(List<Grade> grades) {
this.grades = grades;
}

public Integer getGradingProgress() {
if (getGroupGrade() == null) {
return 0;
}

Integer gradesFromTeachers = (int) getGrades()
.stream()
.filter(grade -> grade.getFromUser().hasAnyRole("TEACHER_ROLE"))
.count();

if (gradesFromTeachers > 0) {
return 100;
}

if (getGrades().size() == 0) {
return 10;
}

Integer gradesFromStudents = getGrades()
.stream()
.filter(grade -> grade.getFromUser().hasAnyRole("STUDENT_ROLE"))
.toArray()
.length;

Double noStudents = (double) getUsers()
.stream()
.filter(user -> user.hasAnyRole("STUDENT_ROLE"))
.toArray()
.length;

Double studentsThatGraded = gradesFromStudents / noStudents;

return (int) (studentsThatGraded / noStudents * 100);
}

@JsonIgnore
public Status getGradingStatusForUser(User user) {
Status status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class GroupGrade extends BaseModel {
@ManyToOne(fetch = FetchType.LAZY)
private User teacher;

@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime deadline; // Needs this format: 1970-01-01T00:00:00.000+0000

public GroupGrade() {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/datbois/grademaster/model/Period.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.datbois.grademaster.model;

public enum Period {
Q1, Q2, Q3, Q4;
Q1,
Q2,
Q3,
Q4
}
5 changes: 4 additions & 1 deletion src/main/java/com/datbois/grademaster/model/Role.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.datbois.grademaster.model;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;

@Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.datbois.grademaster.repository;


import com.datbois.grademaster.model.Grade;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

@Repository
public interface GroupRepository extends JpaRepository<Group, Long> {
Group findByGroupNameContainingIgnoreCase(String groupName);
Group findById(Long id);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.datbois.grademaster.repository;

import com.datbois.grademaster.model.Notification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.datbois.grademaster.model.Notification;

@Repository
public interface NotificationRepository extends JpaRepository<Notification, Long> {

Notification findById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;

public interface EmailService {

void sendToEmailQueue(Email email);

void sendEmail(Email email) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.datbois.grademaster.model.Grade;

public interface GradeService{
Grade save (Grade grade);
public interface GradeService {
Grade save(Grade grade);

Grade findById(Long id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
public interface GroupService {
Group save(Group group);

Group save(Group group, Set<User> users);

List<Group> findAll();

Group findById(Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;

public interface NotificationService {

List<Notification> findAll();

Notification save(Notification notification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public Group save(Group group) {
return groupRepository.save(setUsers(groupRepository.save(group), group.getUsers()));
}

@Override
public Group save(Group group, Set<User> users) {
return groupRepository.save(setUsers(groupRepository.save(group), users));
}

@Override
public List<Group> findAll() {
return groupRepository.findAll();
Expand Down Expand Up @@ -67,6 +72,16 @@ public void delete(Long id) {
@Override
public Group setUsers(Group group, Set<User> users) {
if (users == null) return group;
Group existingGroup = groupRepository.findById(group.getId());

for (User u : existingGroup.getUsers()) { // Delete group from the users
User user = userService.findById(u.getId());
Set<Group> groups = user.getGroups();
groups.remove(group);
user.setGroups(groups);
userService.save(user);
}

group.setUsers(users);
for (User u : users) {
User user = userService.findById(u.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.datbois.grademaster.service.EmailService;
import com.datbois.grademaster.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
Expand Down
28 changes: 10 additions & 18 deletions src/main/java/com/datbois/grademaster/util/CssInliner.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
package com.datbois.grademaster.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import com.steadystate.css.parser.CSSOMParser;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;
import org.w3c.css.sac.InputSource;
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.css.CSSRuleList;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.CSSStyleRule;
import org.w3c.dom.css.CSSStyleSheet;
import org.w3c.dom.css.*;

import com.steadystate.css.parser.CSSOMParser;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class CssInliner {

private CssInliner() {

}

public static String inlineCss(File css, String html) throws FileNotFoundException, IOException {
public static String inlineCss(File css, String html) throws IOException {
CSSOMParser parser = new CSSOMParser();
CSSStyleSheet styleSheet = parser.parseStyleSheet(new InputSource(new FileReader(css)));
final Document document = Jsoup.parse(html);
Expand Down Expand Up @@ -58,7 +51,7 @@ private static String inlineCss(CSSStyleSheet styleSheet, Document document) {
final Elements selectedElements = document.select(selector);
for (final Element selected : selectedElements) {
if (!elementStyles.containsKey(selected)) {
elementStyles.put(selected, new LinkedHashMap<String, String>());
elementStyles.put(selected, new LinkedHashMap<>());
}

final CSSStyleDeclaration styleDeclaration = styleRule.getStyle();
Expand Down Expand Up @@ -91,5 +84,4 @@ private static String inlineCss(CSSStyleSheet styleSheet, Document document) {
}
return document.html();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public void writeLine(Writer w, List<String> values, char separators, char custo
sb.append("\n");
w.append(sb.toString());


}

}
Loading

0 comments on commit 0b7ef8a

Please sign in to comment.