Commit 643cea84 authored by Michael Schimpelsberger's avatar Michael Schimpelsberger
Browse files

Datenspeicherung Student implementiert.

parent 41439c68
package university.at.jku.ce.dao;
import java.util.List;
import java.util.Map;
import university.at.jku.ce.model.Student;
public interface StudentDao {
public Student getStudent(long matrNr);
public Map<Long,Student>getAllStudents();
}
package university.at.jku.ce.dao;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import university.at.jku.ce.model.Student;
import university.at.jku.ce.model.Study;
public class TextStudentDao implements StudentDao {
Map <Long,Student> students;
@Override
public Student getStudent(long matrNr) {
getAllStudents();
return students.get(matrNr);
}
@Override
public Map<Long,Student> getAllStudents() {
ArrayList <String> lineList=new ArrayList<String>();
students=new HashMap<Long,Student>();
try {
FileReader fr = new FileReader("C:\\Users\\Michael\\development\\workspace-ce5\\at.jku.ce\\src\\main\\resources\\Students.txt");
BufferedReader br = new BufferedReader(fr);
String line="";
do{
line = br.readLine();
lineList.add(line);
}
while (line != null);
br.close();
} catch (Throwable t) {t.printStackTrace();}
for(String s: lineList) {
if (s!=null) {
int i=0;
Long matrNr;
String firstName;
String lastName;
StringBuilder b=new StringBuilder();
while (s.charAt(i)!='|') {
b.append(s.charAt(i));
i++;
}
matrNr=Long.parseLong(b.toString());
b=new StringBuilder();
i++;
while (s.charAt(i)!='|') {
b.append(s.charAt(i));
i++;
}
firstName=b.toString();
b=new StringBuilder();
i++;
while (i<s.length()) {
b.append(s.charAt(i));
i++;
}
lastName=b.toString();
students.put(matrNr, new Student(matrNr,firstName,lastName));
}
}
return students;
}
}
......@@ -23,7 +23,7 @@ public class Student {
this.lastName=lastName;
}
public Student(int matrNr, String firstName, String lastName) {
public Student(long matrNr, String firstName, String lastName) {
this.matrNr=matrNr;
this.firstName=firstName;
this.lastName=lastName;
......
......@@ -25,48 +25,48 @@ public class StudentResource {
Service service=new ServiceImpl();
// @GET
// @Produces(MediaType.APPLICATION_JSON)
// public Response getStudents() {
// List<Student>list= studentService.getAllStudents();
// GenericEntity<List<Student>> entity=new GenericEntity<List<Student>>(list) {};
// return Response.ok(entity).build();
// }
//
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getStudents() {
List<Student>list= service.getAllStudents();
GenericEntity<List<Student>> entity=new GenericEntity<List<Student>>(list) {};
return Response.ok(entity).build();
}
//// @GET
//// @Produces(MediaType.APPLICATION_XML)
//// public List <Student> getStudents() {
//// return studentService.getAllStudents();
//// }
//
// @POST
// @Consumes(MediaType.APPLICATION_JSON)
// @Produces(MediaType.APPLICATION_JSON)
// public Student addStudent(Student student) {
// return studentService.addStudent(student);
// return service.addStudent(student);
// }
//
//// @POST
//// @Consumes(MediaType.APPLICATION_XML)
//// @Produces(MediaType.APPLICATION_XML)
//// public Student addMessage(Student student) {
//// return studentService.addStudent(student);
//// }
//
// @GET
// @Path("/{studentMatrNr}")
// @Produces(MediaType.APPLICATION_JSON)
// public Student getStudent(@PathParam("studentMatrNr")long matrNr) {
// return studentService.getStudent(matrNr);
// }
//
@GET
@Path("/{studentMatrNr}")
@Produces(MediaType.APPLICATION_JSON)
public Student getStudent(@PathParam("studentMatrNr")long matrNr) {
return service.getStudent(matrNr);
}
//// @GET
//// @Path("/{studentMatrNr}")
//// @Produces(MediaType.APPLICATION_XML)
//// public Student getStudent(@PathParam("studentMatrNr")long matrNr) {
//// return studentService.getStudent(matrNr);
//// }
//
// @PUT
// @Path("/{studentMatrNr}")
// @Consumes(MediaType.APPLICATION_JSON)
......@@ -75,7 +75,7 @@ public class StudentResource {
// student.setMatrNr(matrNr); //if User does not send correct id it is still used correct id from URL
// return studentService.updateStudent(student);
// }
//
//// @PUT
//// @Path("/{studentMatrNr}")
//// @Consumes(MediaType.APPLICATION_XML)
......@@ -84,14 +84,14 @@ public class StudentResource {
//// student.setMatrNr(matrNr); //if User does not send correct id it is still used correct id from URL
//// return studentService.updateStudent(student);
//// }
//
// @DELETE
// @Path("/{studentMatrNr}")
// @Produces(MediaType.APPLICATION_JSON)
// public void deleteStudent(@PathParam("studentMatrNr")long matrNr) {
// studentService.removeStudent(matrNr);
// }
//
//// @DELETE
//// @Path("/{studentMatrNr}")
//// @Produces(MediaType.APPLICATION_XML)
......
......@@ -4,6 +4,7 @@ import java.util.ArrayList;
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;
......@@ -27,4 +28,10 @@ public interface Service {
public Subject updateSubject (long studyId, Subject subject);
public void removeSubject (long studyId, long id);
public Student getStudent(Long matrNr);
public List<Student>getAllStudents();
}
......@@ -4,10 +4,14 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import university.at.jku.ce.dao.StudentDao;
import university.at.jku.ce.dao.StudyDao;
import university.at.jku.ce.dao.SubjectDao;
import university.at.jku.ce.dao.TextStudentDao;
import university.at.jku.ce.dao.TextStudyDao;
import university.at.jku.ce.dao.TextSubjectDao;
import university.at.jku.ce.model.Student;
import university.at.jku.ce.model.Study;
import university.at.jku.ce.model.Subject;
......@@ -15,6 +19,7 @@ public class ServiceImpl implements Service{
private StudyDao studyDao=new TextStudyDao();
private SubjectDao subjectDao=new TextSubjectDao();
private StudentDao studentDao=new TextStudentDao();
public ServiceImpl() {
}
......@@ -70,4 +75,14 @@ private SubjectDao subjectDao=new TextSubjectDao();
public void removeSubject (long studyId, long id) {
subjectDao.removeSubject(studyId,id);
}
@Override
public Student getStudent(Long matrNr) {
return studentDao.getStudent(matrNr);
}
@Override
public List<Student> getAllStudents() {
return new ArrayList<Student>(studentDao.getAllStudents().values());
}
}
1|Franz|Reischl
2|Michael|Schimpelsberger
\ No newline at end of file
1|1|Datenmodellierung|Grundlagen Datenmodellierung
2|1|Softwareenticklung|Soft1
2|2|inf|Einführung inf
1|1|Softwareentwicklung 2|Soft 2
1|2|Informationmanagement|Grundlagen IM
Subproject commit e020166a1ddfbf402cf2389a0bc4b7340fb963ed
Subproject commit 3aa4125b377b8de8a9330f8139ded46155e234c5
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