diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/DummyJournalService.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/DummyJournalService.java new file mode 100644 index 0000000000000000000000000000000000000000..08087068a86aad45a7dcb95019e546edadfbf304 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/DummyJournalService.java @@ -0,0 +1,82 @@ +package unipotsdam.gf.modules.journal.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import unipotsdam.gf.interfaces.IJournal; +import unipotsdam.gf.modules.assessment.controller.StudentIdentifier; +import unipotsdam.gf.modules.journal.model.Journal; +import unipotsdam.gf.modules.journal.model.Visibility; +import unipotsdam.gf.modules.journal.view.JournalView; + +import java.util.ArrayList; +import java.util.Calendar; + +/** + * Service Implementation to test the Rest + */ +public class DummyJournalService implements JournalService, IJournal { + + Logger log = LoggerFactory.getLogger(DummyJournalService.class); + + + Calendar cal = Calendar.getInstance(); + StudentIdentifier studentIdentifier = new StudentIdentifier("0","0"); + StudentIdentifier studentIdentifier2 = new StudentIdentifier("0","1"); + + Journal j1 = new Journal(studentIdentifier,"test", cal.getTimeInMillis() , Visibility.All, "test1"); + Journal j2 = new Journal(studentIdentifier,"test2", cal.getTimeInMillis() , Visibility.NONE, "test2"); + Journal j3 = new Journal(studentIdentifier,"test3", cal.getTimeInMillis() , Visibility.GROUP, "test3"); + Journal j4 = new Journal(studentIdentifier,"test4", cal.getTimeInMillis() , Visibility.DOZENT ,"test4"); + Journal j5 = new Journal(studentIdentifier2,"test5", cal.getTimeInMillis() , Visibility.GROUP, "test5"); + + ArrayList<Journal> journals = new ArrayList<>(); + + + @Override + public ArrayList<Journal> getAllJournals(String student, String project) { + + log.debug(">> get all journals(" + student , "," + project + ")"); + + ArrayList<Journal> result = new ArrayList<>(); + + for (Journal j: journals) { + + if (j.getVisibility() == Visibility.All){ + result.add(j); + } + if (j.getVisibility()== Visibility.NONE && j.getStudentIdentifier().getStudentId().equals(student)){ + result.add(j); + } + + //Goup != Project, but for testing ok + if (j.getVisibility()== Visibility.NONE && j.getStudentIdentifier().getProjectId().equals(project)){ + result.add(j); + } + + //if Dozent + + } + log.debug("<< get all journals(" + student , "," + project + ")"); + + return result; + } + + + @Override + public String exportJournal(StudentIdentifier student) { + return null; + } + + ArrayList<Journal> resetList () { + journals = new ArrayList<>(); + + journals.add(j1); + journals.add(j2); + journals.add(j3); + journals.add(j4); + journals.add(j5); + + return journals; + } + +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/JournalService.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/JournalService.java new file mode 100644 index 0000000000000000000000000000000000000000..c93917e504d2b71cd181981309055034c5eee60f --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/JournalService.java @@ -0,0 +1,9 @@ +package unipotsdam.gf.modules.journal.service; + +import unipotsdam.gf.modules.journal.model.Journal; + +import java.util.ArrayList; + +public interface JournalService { + ArrayList<Journal> getAllJournals(String student, String project); +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/view/JournalListResponse.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/view/JournalListResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..8426949f50b0e72b70980e16feb4b0c2de518a49 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/view/JournalListResponse.java @@ -0,0 +1,23 @@ +package unipotsdam.gf.modules.journal.view; + +import unipotsdam.gf.modules.journal.model.Journal; + +import java.util.List; + +/** + * Wrapper Class to return a List in REST + */ +public class JournalListResponse { + + private List<Journal> journals; + + public void setJournals(List<Journal> journals) { + this.journals = journals; + } + + public List<Journal> getJournals() { + return journals; + + + } +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/view/JournalView.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/view/JournalView.java new file mode 100644 index 0000000000000000000000000000000000000000..75d1395fd0160d020db5db6f1af5ea7810902304 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/view/JournalView.java @@ -0,0 +1,49 @@ +package unipotsdam.gf.modules.journal.view; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import unipotsdam.gf.modules.journal.model.Journal; +import unipotsdam.gf.modules.journal.service.DummyJournalService; +import unipotsdam.gf.modules.journal.service.JournalService; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.ArrayList; + +@Path("/journal") +public class JournalView { + + Logger log = LoggerFactory.getLogger(JournalView.class); + JournalService journalService = new DummyJournalService(); + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String test() { + return "Journal"; + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/journals/{student}/{project}") + public Response getAllJournals(@PathParam("student") String student, @PathParam("project") String project) { + + log.debug(">> called getAllJournals(" + student + "," + project + ")"); + try { + ArrayList<Journal> journals = journalService.getAllJournals(student, project); + + JournalListResponse result = new JournalListResponse(); + result.setJournals(journals); + + return Response.ok(new GenericEntity<JournalListResponse>(result) { + }).build(); + } catch (Exception e) { + e.printStackTrace(); + return Response.noContent().build(); + } + } +} \ No newline at end of file