Skip to content
Snippets Groups Projects
Commit 9f1a8b46 authored by tudtianus's avatar tudtianus
Browse files

feat: Service for testing and first rest API

parent f9477c66
No related branches found
No related tags found
No related merge requests found
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;
}
}
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);
}
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;
}
}
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment