Skip to content

Commit

Permalink
Merge pull request #6 from pfgray/ags
Browse files Browse the repository at this point in the history
Ags
  • Loading branch information
pfgray committed Dec 5, 2018
2 parents 600fa87 + fb03094 commit 2876dd1
Show file tree
Hide file tree
Showing 20 changed files with 457 additions and 34 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,7 @@ release.properties
nb-configuration.xml
*.iml
node_modules/
.settings
.classpath
.factorypath
.project
9 changes: 9 additions & 0 deletions pom.xml
Expand Up @@ -113,6 +113,10 @@
<artifactId>lti-spring</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
Expand All @@ -137,6 +141,11 @@
<artifactId>scala-library</artifactId>
<version>2.11.7</version>
</dependency>
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-java8-compat_2.11</artifactId>
<version>0.9.0</version>
</dependency>
</dependencies>

<build>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/paulgray/mocklti2/MockLti2App.java
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.scala.DefaultScalaModule;
import com.fasterxml.jackson.module.scala.DefaultScalaModule$;
import org.springframework.boot.*;
Expand Down Expand Up @@ -31,13 +32,13 @@ public static void main(String[] args) throws Exception {

public static ObjectMapper standardMapper() {
ObjectMapper mapper = new ObjectMapper();
return mapper.registerModules(new Jdk8Module(), new DefaultScalaModule());
return mapper.registerModules(new Jdk8Module(), new DefaultScalaModule(), new JavaTimeModule());
}

@Bean
public Jackson2ObjectMapperBuilderCustomizer addJdk8Module() {
return (mapperBuilder) -> {
mapperBuilder.modules(new Jdk8Module(), new DefaultScalaModule());
mapperBuilder.modules(new Jdk8Module(), new DefaultScalaModule(), new JavaTimeModule());
};
}
}
5 changes: 4 additions & 1 deletion src/main/java/net/paulgray/mocklti2/config/ViewConfig.java
Expand Up @@ -7,6 +7,9 @@
package net.paulgray.mocklti2.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.scala.DefaultScalaModule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -41,7 +44,7 @@ public InternalResourceViewResolver viewResolver() {

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter(om));
converters.add(new MappingJackson2HttpMessageConverter(om.registerModules(new Jdk8Module(), new DefaultScalaModule(), new JavaTimeModule())));
}

}
Expand Up @@ -26,6 +26,14 @@ public class GradebookCell {
public GradebookCell() {
}

public GradebookCell(Integer id, Integer gradebookLineItemId, String studentId, String grade, String source) {
this.id = id;
this.gradebookLineItemId = gradebookLineItemId;
this.studentId = studentId;
this.grade = grade;
this.source = source;
}

public GradebookCell(Integer gradebookLineItemId, String studentId, String grade, String source) {
this.gradebookLineItemId = gradebookLineItemId;
this.studentId = studentId;
Expand Down
@@ -1,6 +1,7 @@
package net.paulgray.mocklti2.gradebook;

import javax.persistence.*;
import java.math.BigDecimal;

/**
* Created by paul on 10/24/16.
Expand Down Expand Up @@ -29,6 +30,15 @@ public class GradebookLineItem {
@Column(name = "activity_id")
private String activityId;

@Column(name = "resource_id")
private String resourceId;

@Column(name = "tag")
private String tag;

@Column(name = "score_maximum")
private BigDecimal scoreMaximum;

public GradebookLineItem() {
}

Expand All @@ -48,6 +58,18 @@ public GradebookLineItem(Integer gradebookId, String resourceLinkId, String titl
this.source = source;
}

public GradebookLineItem(Integer id, Integer gradebookId, String resourceLinkId, String title, String source, String activityId, String resourceId, String tag, BigDecimal scoreMaximum) {
this.id = id;
this.gradebookId = gradebookId;
this.resourceLinkId = resourceLinkId;
this.title = title;
this.source = source;
this.activityId = activityId;
this.resourceId = resourceId;
this.tag = tag;
this.scoreMaximum = scoreMaximum;
}

public String getResourceLinkId() {
return resourceLinkId;
}
Expand Down Expand Up @@ -95,4 +117,28 @@ public String getSource() {
public void setSource(String source) {
this.source = source;
}

public String getResourceId() {
return resourceId;
}

public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}

public String getTag() {
return tag;
}

public void setTag(String tag) {
this.tag = tag;
}

public BigDecimal getScoreMaximum() {
return scoreMaximum;
}

public void setScoreMaximum(BigDecimal scoreMaximum) {
this.scoreMaximum = scoreMaximum;
}
}
Expand Up @@ -19,10 +19,14 @@ public interface GradebookService {

Optional<GradebookLineItem> getGradebookLineItemByResourceId(Integer gradebookId, String resourceId);

GradebookLineItem getOrCreateGradebookLineItemByResourceId(Integer gradebookId, String resourceId, String source);
Optional<GradebookLineItem> getGradebookLineItemById(Integer gradebookId, Integer lineItemId);

GradebookLineItem getOrCreateGradebookLineItemByResourceLinkId(Integer gradebookId, String resourceLinkId, String source);

GradebookLineItem updateLineItem(GradebookLineItem lineItem);

void deleteLineItem(GradebookLineItem lineItem);

GradebookLineItem addLineItem(GradebookLineItem lineItem);

Map<Integer, List<GradebookCell>> getGradebookCells(List<Integer> columnIds);
Expand Down
Expand Up @@ -60,11 +60,19 @@ public Optional<GradebookLineItem> getGradebookLineItemByResourceId(Integer grad
return Optional.ofNullable((GradebookLineItem) crit.uniqueResult());
}

@Override
public Optional<GradebookLineItem> getGradebookLineItemById(Integer gradebookId, Integer lineItemId) {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(GradebookLineItem.class);
crit.add(Restrictions.eq("gradebookId", gradebookId));
crit.add(Restrictions.eq("id", lineItemId));
return Optional.ofNullable((GradebookLineItem) crit.uniqueResult());
}

@Override
@Transactional
public GradebookLineItem getOrCreateGradebookLineItemByResourceId(Integer gradebookId, String resourceId, String source) {
return getGradebookLineItemByResourceId(gradebookId, resourceId)
.orElseGet(() -> addLineItem(new GradebookLineItem(gradebookId, resourceId, source)));
public GradebookLineItem getOrCreateGradebookLineItemByResourceLinkId(Integer gradebookId, String resourceLinkId, String source) {
return getGradebookLineItemByResourceId(gradebookId, resourceLinkId)
.orElseGet(() -> addLineItem(new GradebookLineItem(gradebookId, resourceLinkId, source)));
}

@Override
Expand All @@ -77,6 +85,12 @@ public GradebookLineItem updateLineItem(GradebookLineItem lineItem) {
return (GradebookLineItem) crit.uniqueResult();
}

@Override
@Transactional
public void deleteLineItem(GradebookLineItem lineItem) {
sessionFactory.getCurrentSession().delete(lineItem);
}

@Override
@Transactional
public GradebookLineItem addLineItem(GradebookLineItem lineItem) {
Expand Down
Expand Up @@ -11,15 +11,11 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.w3c.dom.Document;
Expand All @@ -33,7 +29,6 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -86,7 +81,7 @@ public ResponseEntity<LineItem> createLineItems(@PathVariable String contextId,
String title = lineItem.getLabel().get("@value").textValue();
String activityId = lineItem.getActivity().get("@id").textValue();

GradebookLineItem newLineItem = gradebookService.getOrCreateGradebookLineItemByResourceId(gb.getId(), UUID.randomUUID().toString(), body);
GradebookLineItem newLineItem = gradebookService.getOrCreateGradebookLineItemByResourceLinkId(gb.getId(), UUID.randomUUID().toString(), body);

newLineItem.setTitle(title);
newLineItem.setActivityId(activityId);
Expand Down Expand Up @@ -161,7 +156,7 @@ public ResponseEntity<String> handleOutcomes1(HttpServletRequest request) throws
Gradebook gb = gradebookService.getOrCreateGradebook(out.contextId);

GradebookLineItem lineItem =
gradebookService.getOrCreateGradebookLineItemByResourceId(gb.getId(), out.resourceId, null);
gradebookService.getOrCreateGradebookLineItemByResourceLinkId(gb.getId(), out.resourceId, null);

GradebookCell cell =
gradebookService.getOrCreateGradebookCell(lineItem.getId(), out.studentId, body);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/paulgray/mocklti2/web/LtiController.java
Expand Up @@ -76,7 +76,7 @@ private GradebookCell getCellForLineItem(GradebookLineItem lineItem, UnsignedLti
private GradebookLineItem getLineItemForGradebook(Gradebook gb, UnsignedLtiLaunchRequest request) {
String resourceId = request.getLaunchParameters().get("resource_link_id");
String resourceTitle = request.getLaunchParameters().get("resource_link_title");
GradebookLineItem lineItem = gradebookService.getOrCreateGradebookLineItemByResourceId(gb.getId(), resourceId, null);
GradebookLineItem lineItem = gradebookService.getOrCreateGradebookLineItemByResourceLinkId(gb.getId(), resourceId, null);
lineItem.setTitle(resourceTitle);
return gradebookService.updateLineItem(lineItem);
}
Expand All @@ -89,7 +89,7 @@ public Gradebook getGradebookForReq(UnsignedLtiLaunchRequest request){
private List<GradebookLineItem> generateRandomColumns(Gradebook gb) {
List<GradebookLineItem> assignments = new LinkedList<>();
for (int i = 1; i<31; i++) {
GradebookLineItem assignment = gradebookService.getOrCreateGradebookLineItemByResourceId(gb.getId(), "assignment_" + i, null);
GradebookLineItem assignment = gradebookService.getOrCreateGradebookLineItemByResourceLinkId(gb.getId(), "assignment_" + i, null);
assignment.setTitle("Assignment #" + i);
gradebookService.updateLineItem(assignment);
assignments.add(assignment);
Expand Down

0 comments on commit 2876dd1

Please sign in to comment.