Commit 5c37dd54 authored by Michael Schimpelsberger's avatar Michael Schimpelsberger
Browse files

# WARNING: head commit changed in the meantime

test
parent 40ed1054
......@@ -3,10 +3,15 @@ package university.at.jku.ce;
import java.util.HashMap;
import java.util.Map;
import university.at.jku.ce.model.Student;
import university.at.jku.ce.model.Study;
import university.at.jku.ce.model.Subject;
public class Database {
private static Map<Long ,Student> students=new HashMap<Long,Student>();
private static Map<Long ,Subject> subjects=new HashMap<Long,Subject>();
private static Map<Long ,Study> studies=new HashMap<Long,Study>();
public static Map<Long, Student> getStudents() {
return students;
......@@ -15,6 +20,11 @@ public class Database {
return subjects;
}
public static Map<Long, Study> getStudies() {
return studies;
}
}
package university.at.jku.ce;
package university.at.jku.ce.model;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
@XmlRootElement
......@@ -12,21 +15,13 @@ public class Student {
private long matrNr;
private String firstName;
private String lastName;
List <Subject> subjects;
public Student () {};
public Student(String firstName, String lastName, List<Subject> subjects) {
this.firstName=firstName;
this.lastName=lastName;
this.subjects=subjects;
}
public Student(int matrNr, String firstName, String lastName, List<Subject> subjects) {
public Student(int matrNr, String firstName, String lastName) {
this.matrNr=matrNr;
this.firstName=firstName;
this.lastName=lastName;
this.subjects=subjects;
}
public String getFirstName() {
......@@ -52,12 +47,5 @@ public class Student {
public void setMatrNr(long matrNr) {
this.matrNr = matrNr;
}
public List<Subject> getSubjects() {
return subjects;
}
public void setSubjects(List<Subject> subjects) {
this.subjects = subjects;
}
}
package university.at.jku.ce.model;
import java.util.HashMap;
import java.util.Map;
import javax.json.bind.annotation.JsonbTransient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
@XmlRootElement
public class Study {
private long studyId;
private String name;
private Map <Long, Subject> subjects=new HashMap<Long,Subject>();
public Study() {}
public Study(long studyId, String name, Map<Long, Subject> subjects) {
this.name=name;
this.studyId=studyId;
this.subjects=subjects;
}
public long getStudyId() {
return studyId;
}
public void setStudyId(long studyId) {
this.studyId = studyId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@JsonbTransient
public Map<Long, Subject> getSubjects() {
return subjects;
}
public void setSubjects(Map<Long, Subject> subjects) {
this.subjects = subjects;
}
}
package university.at.jku.ce;
package university.at.jku.ce.model;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Subject {
String name;
String info;
private long id;
private String name;
private String info;
public Subject() {};
public Subject(String name, String info) {
public Subject(long id, String name, String info) {
this.id=id;
this.name=name;
this.info=info;
}
......@@ -29,7 +31,12 @@ public class Subject {
public void setInfo(String info) {
this.info = info;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
package university.at.jku.ce;
package university.at.jku.ce.resource;
import javax.ws.rs.core.GenericEntity;
import java.util.List;
......@@ -14,6 +14,9 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import university.at.jku.ce.model.Student;
import university.at.jku.ce.service.StudentService;
@Path("/students")
public class StudentResource {
......
package university.at.jku.ce.resource;
import javax.ws.rs.core.GenericEntity;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import university.at.jku.ce.model.Student;
import university.at.jku.ce.model.Study;
import university.at.jku.ce.service.StudentService;
import university.at.jku.ce.service.StudyService;
@Path("/studies")
public class StudyResource {
StudyService studyService=new StudyService();
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getStudies() {
List<Study>list= studyService.getAllStudies();
GenericEntity<List<Study>> entity=new GenericEntity<List<Study>>(list) {};
return Response.ok(entity).build();
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Study addStudy(Study study) {
return studyService.addStudy(study);
}
@GET
@Path("/{studyId}")
@Produces(MediaType.APPLICATION_JSON)
public Study getStudy(@PathParam("studyId")long studyId) {
return studyService.getStudy(studyId);
}
@PUT
@Path("/{studyId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Study updateStudy(@PathParam("studyId")long studyId,Study study) {
study.setStudyId(studyId); //if User does not send correct id it is still used correct id from URL
return studyService.updateStudy(study);
}
@DELETE
@Path("/{studyId}")
@Produces(MediaType.APPLICATION_JSON)
public void deleteStudent(@PathParam("studyId")long studyId) {
studyService.removeStudy(studyId);
}
@Path("/{studyId}/subjects")
public SubjectResource getSubjectResource() {
return new SubjectResource();
}
}
package university.at.jku.ce.resource;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import university.at.jku.ce.model.Subject;
import university.at.jku.ce.service.SubjectService;
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class SubjectResource {
private SubjectService subjectService=new SubjectService();
@GET
public List getAllSubjects(@PathParam("studyId")long studyId) {
return subjectService.getAllSubjects(studyId);
}
@POST
public Subject addSubject(@PathParam("studyId")long studyId, Subject subject) {
return subjectService.addSubject(studyId, subject);
}
@PUT
@Path("/{id}")
public Subject updateSubject(@PathParam("studyId")long studyId,@PathParam("id")long id, Subject subject) {
subject.setId(id);
return subjectService.updateSubject(studyId, subject);
}
@DELETE
@Path("/{id}")
public Subject removeSubject(@PathParam("studyId")long studyId,@PathParam("id")long id) {
return subjectService.removeSubject(studyId, id);
}
@GET
@Path("/{id}")
public Subject getSubject(@PathParam("studyId")long studyId,@PathParam("id")long id) {
return subjectService.getSubject(studyId, id);
}
}
package university.at.jku.ce;
package university.at.jku.ce.service;
import java.util.ArrayList;
import university.at.jku.ce.Database;
import java.util.List;
import java.util.Map;
import university.at.jku.ce.model.Student;
import university.at.jku.ce.model.Subject;
public class StudentService {
private Map <Long, Student> students=Database.getStudents();
//private Map <Long,Subject> subjects=Database.getSubjects();
public StudentService() {
List<Subject> subjects1=new ArrayList<Subject>();
subjects1.add(new Subject("Softwareenwicklung", "Grundlegendes zu Java"));
subjects1.add(new Subject("Datenmodellierung","Grundlegendes zu SQL und Relationalen Datenbanken"));
subjects1.add(new Subject("Communications Engineering","Grundlegendes Verteilten Systemen"));
List<Subject>subjects2=new ArrayList<Subject>();
subjects2.add(new Subject("Softwareenwicklung2", "Weiterführendes zu Java"));
subjects2.add(new Subject("DKE","Weiterführendes zu Data and Knowledge Engineering"));
Student s2=new Student(1, "Michael", "Schimpelsberger", subjects1);
Student s1=new Student(2,"Franz", "Reschl", null);
Student s3=new Student(3,"Susanne", "Zaunmayr", subjects2);
Student s2=new Student(1, "Michael", "Schimpelsberger");
Student s1=new Student(2,"Franz", "Reschl");
Student s3=new Student(3,"Susanne", "Zaunmayr");
students.put(s1.getMatrNr(),s1);
students.put(s2.getMatrNr(),s2);
......
package university.at.jku.ce.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import university.at.jku.ce.Database;
import university.at.jku.ce.model.Study;
import university.at.jku.ce.model.Subject;
public class StudyService {
private Map <Long, Study> studies=Database.getStudies();
public StudyService() {
Map<Long,Subject> win=new HashMap<Long,Subject>();
win.put((long)1, new Subject(1,"Einführung Softwareentwicklung","Grundlagen der Softwareentwicklung"));
win.put((long)2, new Subject(2,"Datenmodellierung","Datenmodelle und Datenbanksysteme"));
Map<Long,Subject> inf=new HashMap<Long,Subject>();
inf.put((long)1, new Subject(1,"Einführung Softwareentwicklung","Grundlagen der Softwareentwicklung"));
inf.put((long)2, new Subject(2,"Relationale Algebra","Grundlegendes zu Relationalen Algebra"));
Study s1=new Study(1,"Wirtschaftsinformatik",win);
Study s2=new Study(2,"Informatik", inf);
Study s3=new Study(3,"Wirtschaftswissenschaften",null);
studies.put(s1.getStudyId(),s1);
studies.put(s2.getStudyId(),s2);
studies.put(s3.getStudyId(), s3);
}
public List<Study> getAllStudies(){
return new ArrayList<Study>(studies.values());
}
public Study getStudy(Long id) {
return studies.get(id);
}
public Study addStudy(Study study) {
if (study!=null) {
study.setStudyId(studies.size()+1);
studies.put(study.getStudyId(), study);
}
return study;
}
public Study updateStudy(Study study) {
if (study!=null&&studies.containsKey(study.getStudyId()));
studies.put(study.getStudyId(), study);
return study;
}
public Study removeStudy(long studyId) {
return studies.remove(studyId);
}
}
package university.at.jku.ce.service;
import java.util.ArrayList;
import university.at.jku.ce.Database;
import java.util.List;
import java.util.Map;
import university.at.jku.ce.model.Student;
import university.at.jku.ce.model.Study;
import university.at.jku.ce.model.Subject;
public class SubjectService {
private Map <Long, Study> studies=Database.getStudies();
public List<Subject> getAllSubjects(long studyId){
Map<Long,Subject> subjects=studies.get(studyId).getSubjects();
return new ArrayList<Subject>(subjects.values());
}
public Subject getSubject(long studyId,long id){
Map<Long,Subject> subjects=studies.get(studyId).getSubjects();
return subjects.get(id);
}
public Subject addSubject (long studyId, Subject subject) {
Map<Long,Subject> subjects=studies.get(studyId).getSubjects();
subject.setId(subjects.size()+1);
subjects.put(subject.getId(),subject);
return subject;
}
public Subject updateSubject (long studyId, Subject subject) {
Map<Long,Subject> subjects=studies.get(studyId).getSubjects();
if (subject.getId()<=0) return null;
subjects.put(subject.getId(),subject);
return subject;
}
public Subject removeSubject (long studyId, long id) {
Map<Long,Subject> subjects=studies.get(studyId).getSubjects();
return subjects.remove(id);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment