Skip to content

Commit

Permalink
Stored templates to persistence and added error tests labels. It
Browse files Browse the repository at this point in the history
always loses connection on the first student.
  • Loading branch information
nhamberg committed May 14, 2012
1 parent 04f46ab commit 09ab5cc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 66 deletions.
26 changes: 23 additions & 3 deletions ATEP Web App/src/edu/gac/ATEP/client/ATEP_Web_App.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class ATEP_Web_App implements EntryPoint {

private Label updatingLabel;
private Label failureLabel;
private Label failureLabel2;
private Label tempFailLabel;
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
Expand Down Expand Up @@ -127,10 +129,16 @@ public void onModuleLoad() {
statusPanel.setHeight("3em");
updatingLabel = new Label("Updating...");
updatingLabel.setVisible(false);
failureLabel = new Label("Lost connection to server.");
failureLabel = new Label("Lost connection to server -- harry.");
failureLabel.setVisible(false);
failureLabel2 = new Label("Lost connection to server -- mary.");
failureLabel2.setVisible(false);
tempFailLabel = new Label("Lost connection to server while storing assessment templates.");
tempFailLabel.setVisible(false);
statusPanel.add(updatingLabel);
statusPanel.add(failureLabel);
statusPanel.add(failureLabel2);
statusPanel.add(tempFailLabel);
mainPanel.add(statusPanel);

//TODO This code is redundant, but all i could think of at the time. Lets make it more efficient.
Expand Down Expand Up @@ -194,6 +202,18 @@ public void onSuccess(Void result) {
}
});

assessmentStore.storeAssessmentTemplate(faceTemplate,
new AsyncCallback<Void>(){
@Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
}

@Override
public void onSuccess(Void result) {
}
});

studentStore.storeStudent(harry,
new AsyncCallback<Void>(){
@Override
Expand All @@ -213,12 +233,12 @@ public void onSuccess(Void result) {
new AsyncCallback<Void>(){
@Override
public void onFailure(Throwable caught) {
failureLabel.setVisible(true);
failureLabel2.setVisible(true);
}

@Override
public void onSuccess(Void result) {
failureLabel.setVisible(false);
failureLabel2.setVisible(false);
updateStudentList();
}
});
Expand Down
26 changes: 0 additions & 26 deletions ATEP Web App/src/edu/gac/ATEP/shared/AssessmentTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.DiscriminatorStrategy;
import javax.jdo.annotations.Discriminator;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import java.util.ArrayList;
import java.io.Serializable;
import edu.gac.ATEP.server.AssessmentTempStoreImpl;


@PersistenceCapable(identityType=IdentityType.APPLICATION)
Expand All @@ -20,9 +18,6 @@ public class AssessmentTemplate implements Serializable {
private String name;
@Persistent(mappedBy="owner")
private ArrayList<Category> categories;
@Persistent(valueStrategy=IdGeneratorStrategy.SEQUENCE)
private Long ID;
public static ArrayList<AssessmentTemplate> templates;

private int classYear; // used to determine who should take this assessment

Expand All @@ -49,27 +44,6 @@ public ArrayList<Category> getCategories() {
return categories;
}

ArrayList<Category> categoriesBones = new ArrayList<Category>();
ArrayList<Question> questionsBones = new ArrayList<Question>();
AssessmentTemplate bonesTemplate = new AssessmentTemplate("Bones Assessment", categoriesBones, 2);
Category bones = new Category("Bones", questionsBones);
Question bones1 = new Question("How come bones?");
//questionsBones.add(bones1);
//categoriesBones.add(bones);

ArrayList<Category> categoriesFace = new ArrayList<Category>();
ArrayList<Question> questionsFace = new ArrayList<Question>();
AssessmentTemplate faceTemplate = new AssessmentTemplate("Face Assessment", categoriesFace, 3);
Category face = new Category("Face", questionsFace);
Question questionC1 = new Question("What's wrong with your face?");
//questionsFace.add(questionC1);
//categoriesFace.add(face);

public Long getID() {
return ID;
}

@SuppressWarnings("unused")
private AssessmentTemplate(){}
}

40 changes: 3 additions & 37 deletions ATEP Web App/src/edu/gac/ATEP/shared/Student.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
package edu.gac.ATEP.shared;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import edu.gac.ATEP.client.StudentPanel;
import edu.gac.ATEP.shared.AssessmentTempStore;

import javax.jdo.PersistenceManager;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Student extends User implements Serializable {
/**
*
*/
private Long nextID = 1L;
private final AssessmentTempStoreAsync tempStore = GWT.create(AssessmentTempStore.class);
private static final long serialVersionUID = 1L;
@Persistent(valueStrategy=IdGeneratorStrategy.SEQUENCE)
private Long ID;
Expand All @@ -34,9 +26,8 @@ public class Student extends User implements Serializable {

public Student(String n, int cY) {
super(n);
this.classYear = cY;
this.myAssessments = new ArrayList<Assessment>();

classYear = cY;
myAssessments = new ArrayList<Assessment>();
}

public int getClassYear() {
Expand All @@ -47,31 +38,6 @@ public void addAssessment(Assessment a) {
myAssessments.add(a);
}

public void populateAssessmentList(Student stud){
final Student student1 = stud;
tempStore.getAssessmentTemplates(nextID,
new AsyncCallback<List<AssessmentTemplate>>(){

@Override
public void onFailure(Throwable caught) {
}

@Override
public void onSuccess(List<AssessmentTemplate> tempList) {
for(AssessmentTemplate temp : tempList){
if (temp.getClassYear() == student1.getClassYear()){
Assessment newAssessment = new Assessment(temp, student1);
student1.addAssessment(newAssessment);
}
}
if(!tempList.isEmpty()){
nextID = tempList.get(0).getID() + 1;
}
}

});
}

public ArrayList<Assessment> getMyAssessments() {
if (myAssessments == null) {
return new ArrayList<Assessment>();
Expand Down

0 comments on commit 09ab5cc

Please sign in to comment.