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

feat: connect Journal to DB

parent a8c365b2
No related branches found
No related tags found
No related merge requests found
Showing
with 618 additions and 224 deletions
package unipotsdam.gf.modules.journal.model; package unipotsdam.gf.modules.journal.model;
import unipotsdam.gf.core.management.utils.Category;
import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier; import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier;
import java.util.Date;
import static unipotsdam.gf.core.management.utils.MarkdownUtils.convertMarkdownToHtml; import static unipotsdam.gf.core.management.utils.MarkdownUtils.convertMarkdownToHtml;
/** /**
...@@ -10,39 +13,57 @@ import static unipotsdam.gf.core.management.utils.MarkdownUtils.convertMarkdownT ...@@ -10,39 +13,57 @@ import static unipotsdam.gf.core.management.utils.MarkdownUtils.convertMarkdownT
*/ */
public class Journal { public class Journal {
private long id; private String id;
private StudentIdentifier studentIdentifier; private StudentIdentifier studentIdentifier;
private String creator;
private String entryHTML; private String entryHTML;
private String entryMD; private String entryMD;
private long timestamp; private long timestamp;
private Visibility visibility; private Visibility visibility;
private String category;//TODO enum private Category category;
private boolean open;
public Journal() {} public Journal() {}
public Journal(long id, StudentIdentifier studentIdentifier, String entry, long timestamp, Visibility visibility, String category) { public Journal(String id, StudentIdentifier studentIdentifier, String entryMD, Visibility visibility, Category category) {
this.id = id; this.id = id;
this.studentIdentifier = studentIdentifier; this.studentIdentifier = studentIdentifier;
// TODO setName per StudentID entryHTML = convertMarkdownToHtml(entryMD);
this.entryHTML = convertMarkdownToHtml(entry); this.entryMD = entryMD;
this.entryMD = entry; this.visibility = visibility;
this.category = category;
open = true;
timestamp = new Date().getTime();
}
public Journal(String id, StudentIdentifier studentIdentifier, String entryMD, long timestamp, Visibility visibility, Category category, boolean open) {
this.id = id;
this.studentIdentifier = studentIdentifier;
entryHTML = convertMarkdownToHtml(entryMD);
this.entryMD = entryMD;
this.timestamp = timestamp; this.timestamp = timestamp;
this.visibility = visibility; this.visibility = visibility;
this.category = category; this.category = category;
this.open = open;
} }
public void setEntry(String entry){ public boolean isOpen() {
this.entryMD = entry; return open;
this.entryHTML = convertMarkdownToHtml(entry); }
public void setOpen(boolean open) {
this.open = open;
} }
public void setEntry(String entry){
entryMD = entry;
entryHTML = convertMarkdownToHtml(entry);
}
public long getId() { public String getId() {
return id; return id;
} }
public void setId(long id) { public void setId(String id) {
this.id = id; this.id = id;
} }
...@@ -78,40 +99,34 @@ public class Journal { ...@@ -78,40 +99,34 @@ public class Journal {
this.visibility = visibility; this.visibility = visibility;
} }
public String getCategory() { public Category getCategory() {
return category; return category;
} }
public void setCategory(String category) { public void setCategory(Category category) {
this.category = category; this.category = category;
} }
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
public String getEntryMD() {
return entryMD;
}
public void setEntryMD(String entryMD) {
this.entryMD = entryMD;
}
@Override @Override
public String toString() { public String toString() {
return "Journal{" + return "Journal{" +
"id=" + id + "id=" + id +
", studentIdentifier=" + studentIdentifier + ", studentIdentifier=" + studentIdentifier +
", creator='" + creator + '\'' +
", entryHTML='" + entryHTML + '\'' + ", entryHTML='" + entryHTML + '\'' +
", entryMD='" + entryMD + '\'' +
", timestamp=" + timestamp + ", timestamp=" + timestamp +
", visibility=" + visibility + ", visibility=" + visibility +
", category='" + category + '\'' + ", category=" + category +
", open=" + open +
'}'; '}';
} }
public String getEntryMD() {
return entryMD;
}
public void setEntryMD(String entryMD) {
this.entryMD = entryMD;
}
} }
package unipotsdam.gf.modules.journal.model;
import java.util.ArrayList;
public interface JournalDAO {
void createJournal(Journal journal);
void updateJournal(Journal journal);
void deleteJournal(String id);
Journal getJournal(String id);
ArrayList<Journal> getAllByProject(String project);
ArrayList<Journal> getAllByProjectAndFilter(String project, String student, JournalFilter filter);
void closeJournal(String id);
}
package unipotsdam.gf.modules.journal.model;
import unipotsdam.gf.core.database.mysql.MysqlConnect;
import unipotsdam.gf.core.database.mysql.VereinfachtesResultSet;
import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier;
import unipotsdam.gf.modules.journal.util.JournalUtils;
import java.util.ArrayList;
import java.util.UUID;
public class JournalDAOImpl implements JournalDAO {
@Override
public void createJournal(Journal journal) {
// create a new id if we found no id.
String uuid = UUID.randomUUID().toString();
while (existsJournalId(uuid)) {
uuid = UUID.randomUUID().toString();
}
// establish connection
MysqlConnect connection = new MysqlConnect();
connection.connect();
// build and execute request
String request = "INSERT INTO journals (`id`, `timestamp`, `author`, `project`, `text`, `visibility`,`category`, `open` ) VALUES (?,?,?,?,?,?,?,?);";
connection.issueInsertOrDeleteStatement(request, uuid, journal.getTimestamp(), journal.getStudentIdentifier().getStudentId(),
journal.getStudentIdentifier().getProjectId(), journal.getEntryMD(), journal.getVisibility(), journal.getCategory(), true);
//close connection
connection.close();
}
@Override
public void updateJournal(Journal journal) {
// establish connection
MysqlConnect connection = new MysqlConnect();
connection.connect();
// build and execute request
String request = "UPDATE journals SET text=?, visibility=?, category=? WHERE id = ?";
connection.issueUpdateStatement(request, journal.getEntryMD(), journal.getVisibility(), journal.getCategory(), journal.getId());
//close connection
connection.close();
}
@Override
public void deleteJournal(String id) {
// establish connection
MysqlConnect connection = new MysqlConnect();
connection.connect();
// build and execute request
String request = "DELETE FROM journals WHERE id = ?;";
connection.issueInsertOrDeleteStatement(request, id);
// close connection
connection.close();
}
@Override
public Journal getJournal(String id) {
// establish connection
MysqlConnect connection = new MysqlConnect();
connection.connect();
// build and execute request
String request = "SELECT * FROM journals WHERE id = ?;";
VereinfachtesResultSet rs = connection.issueSelectStatement(request, id);
if (rs.next()) {
// save journal
Journal journal = getJournalFromResultSet(rs);
// close connection
connection.close();
return journal;
} else {
// close connection
connection.close();
return null;
}
}
@Override
public ArrayList<Journal> getAllByProject(String project) {
ArrayList<Journal> journals = new ArrayList<>();
// establish connection
MysqlConnect connection = new MysqlConnect();
connection.connect();
// build and execute request
String request = "SELECT * FROM journals WHERE project= ?;";
VereinfachtesResultSet rs = connection.issueSelectStatement(request, project);
while (rs.next()) {
journals.add(getJournalFromResultSet(rs));
}
// close connection
connection.close();
return journals;
}
private ArrayList<Journal> getAllByStudent(String student) {
ArrayList<Journal> journals = new ArrayList<>();
// establish connection
MysqlConnect connection = new MysqlConnect();
connection.connect();
// build and execute request
String request = "SELECT * FROM journals WHERE author= ?;";
VereinfachtesResultSet rs = connection.issueSelectStatement(request, student);
while (rs.next()) {
journals.add(getJournalFromResultSet(rs));
}
// close connection
connection.close();
return journals;
}
@Override
public ArrayList<Journal> getAllByProjectAndFilter(String project, String student, JournalFilter filter) {
if (filter == JournalFilter.ALL) {
return getAllByProject(project);
} else {
return getAllByStudent(student);
}
}
@Override
public void closeJournal(String id) {
// establish connection
MysqlConnect connection = new MysqlConnect();
connection.connect();
// build and execute request
String request = "UPDATE journals SET open=? WHERE id = ?";
connection.issueUpdateStatement(request, false, id);
//close connection
connection.close();
}
public boolean existsJournalId(String annotationId) {
// establish connection
MysqlConnect connection = new MysqlConnect();
connection.connect();
// build and execute request
String request = "SELECT COUNT(*) > 0 AS `exists` FROM journals WHERE id = ?;";
VereinfachtesResultSet rs = connection.issueSelectStatement(request, annotationId);
if (rs.next()) {
// save the response
int count = rs.getInt("exists");
// close connection
connection.close();
// return true if we found the id
if (count < 1) {
return false;
} else {
return true;
}
}
// something happened
return true;
}
private Journal getJournalFromResultSet(VereinfachtesResultSet rs) {
String id = rs.getString("id");
long timestamp = rs.getTimestamp(2).getTime();
String student = rs.getString("author");
String project = rs.getString("project");
String text = rs.getString("text");
String visibility = rs.getString("visibility");
String category = rs.getString("category");
boolean open = rs.getBoolean("open");
return new Journal(id, new StudentIdentifier(student, project), text, timestamp, JournalUtils.stringToVisibility(visibility), JournalUtils.stringToCategory(category), open);
}
}
package unipotsdam.gf.modules.journal.service; //package unipotsdam.gf.modules.journal.service;
//
import org.slf4j.Logger; //import org.slf4j.Logger;
import org.slf4j.LoggerFactory; //import org.slf4j.LoggerFactory;
import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier; //import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier;
import unipotsdam.gf.modules.journal.model.Journal; //import unipotsdam.gf.modules.journal.model.Journal;
import unipotsdam.gf.modules.journal.model.JournalFilter; //import unipotsdam.gf.modules.journal.model.JournalFilter;
import unipotsdam.gf.modules.journal.model.Visibility; //import unipotsdam.gf.modules.journal.model.Visibility;
//
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.Calendar; //import java.util.Calendar;
//
/** ///**
* Service Implementation to test rest, no Database operations // * Service Implementation to test rest, no Database operations
*/ // */
//
public class DummyJournalService implements JournalService { //public class DummyJournalService implements JournalService {
//
private Logger log = LoggerFactory.getLogger(DummyJournalService.class); // private final Logger log = LoggerFactory.getLogger(DummyJournalService.class);
//
//
private Calendar cal = Calendar.getInstance(); // private final Calendar cal = Calendar.getInstance();
//
private long id = 4; // private long id = 4;
//
private ArrayList<Journal> journals = new ArrayList<>(); // private ArrayList<Journal> journals = new ArrayList<>();
//
public DummyJournalService(){ // public DummyJournalService(){
//
resetList(); // resetList();
} // }
//
@Override // @Override
public Journal getJournal(String id) { // public Journal getJournal(String id) {
for (Journal j : journals) { // for (Journal j : journals) {
if(j.getId() == Long.valueOf(id)){ // if(j.getId() == Long.valueOf(id)){
return j; // return j;
} // }
} // }
return null; // return null;
} // }
//
@Override // @Override
public ArrayList<Journal> getAllJournals(String student, String project, JournalFilter filter) { // public ArrayList<Journal> getAllJournals(String student, String project, JournalFilter filter) {
log.debug(">> get all journals(" + student + "," + project + "," + filter + ")"); // log.debug(">> get all journals(" + student + "," + project + "," + filter + ")");
//
ArrayList<Journal> result = new ArrayList<>(); // ArrayList<Journal> result = new ArrayList<>();
//
for (Journal j: journals) { // for (Journal j: journals) {
//
//always show own Journals // //always show own Journals
if(j.getStudentIdentifier().getStudentId().equals(student)){ // if(j.getStudentIdentifier().getStudentId().equals(student)){
result.add(j); // result.add(j);
}else{ // }else{
//
// if Visibility All, show if Filter allows it // // if Visibility All, show if Filter allows it
if (j.getVisibility() == Visibility.ALL && filter==JournalFilter.ALL){ // if (j.getVisibility() == Visibility.ALL && filter==JournalFilter.ALL){
result.add(j); // result.add(j);
} // }
//
//If Visibility Group, show if student is in group and filter allows it // //If Visibility Group, show if student is in group and filter allows it
//TODO: project != Group, for testing ok, change for real Service // //TODO: project != Group, for testing ok, change for real Service
if (j.getVisibility()== Visibility.GROUP && j.getStudentIdentifier().getProjectId().equals(project) && filter == JournalFilter.ALL){ // if (j.getVisibility()== Visibility.GROUP && j.getStudentIdentifier().getProjectId().equals(project) && filter == JournalFilter.ALL){
result.add(j); // result.add(j);
} // }
//
//TODO if Dozent // //TODO if Dozent
} // }
//
} // }
log.debug("<< get all journals(" + student , "," + project + ")"); // log.debug("<< get all journals(" + student , "," + project + ")");
//
return result; // return result;
} // }
//
@Override // @Override
public ArrayList<Journal> getAllJournals(String student, String project) { // public ArrayList<Journal> getAllJournals(String student, String project) {
return getAllJournals(student,project,JournalFilter.ALL); // return getAllJournals(student,project,JournalFilter.ALL);
} // }
//
@Override // @Override
public boolean saveJournal(long id, String student, String project, String text, String visibility, String category) { // public boolean saveJournal(long id, String student, String project, String text, String visibility, String category) {
if (id == -1){ // if (id == -1){
//
StudentIdentifier studentId = new StudentIdentifier(student,project); // StudentIdentifier studentId = new StudentIdentifier(student,project);
journals.add(new Journal(this.id++, studentId, text , cal.getTimeInMillis(), stringToVisibility(visibility) , category)); // journals.add(new Journal(this.id++, studentId, text , cal.getTimeInMillis(), stringToVisibility(visibility) , category));
//
} else { // } else {
for (Journal j : journals){ // for (Journal j : journals){
if(j.getId() == id){ // if(j.getId() == id){
j.setEntry(text); // j.setEntry(text);
j.setVisibility(stringToVisibility(visibility)); // j.setVisibility(stringToVisibility(visibility));
j.setCategory(category); // j.setCategory(category);
} // }
} // }
resetList(); // resetList();
} // }
return true; // return true;
} // }
//
@Override // @Override
public boolean deleteJournal(long id) { // public boolean deleteJournal(long id) {
for (Journal j : journals) { // for (Journal j : journals) {
if (j.getId() == id) { // if (j.getId() == id) {
journals.remove(j); // journals.remove(j);
return true; // return true;
} // }
} // }
return false; // return false;
} // }
//
@Override // @Override
public void closeJournal(String journal) { // public void closeJournal(String journal) {
//
} // }
//
private Visibility stringToVisibility(String visibility) { // private Visibility stringToVisibility(String visibility) {
// If String does not match enum IllegalArgumentException // // If String does not match enum IllegalArgumentException
Visibility v ; // Visibility v ;
try{ // try{
v = Visibility.valueOf(visibility); // v = Visibility.valueOf(visibility);
}catch (IllegalArgumentException e){ // }catch (IllegalArgumentException e){
v = Visibility.MINE; // v = Visibility.MINE;
log.debug("Illegal argument for visibility, default to MINE"); // log.debug("Illegal argument for visibility, default to MINE");
} // }
return v; // return v;
} // }
//
private void resetList() { // private void resetList() {
//
StudentIdentifier studentIdentifier = new StudentIdentifier("0","0"); // StudentIdentifier studentIdentifier = new StudentIdentifier("0","0");
StudentIdentifier studentIdentifier2 = new StudentIdentifier("0","1"); // StudentIdentifier studentIdentifier2 = new StudentIdentifier("0","1");
//
String test = "**nec** nec facilisis nibh, sed sagittis tortor. Suspendisse vel felis ac leo dignissim efficitur. Nunc non egestas eros, sit amet vestibulum nunc. Sed bibendum varius molestie. Proin augue mauris, mollis sed efficitur efficitur, sagittis quis eros. Praesent tincidunt tincidunt porttitor. Maecenas quis ornare tellus. Nunc euismod vestibulum neque, sed luctus neque convallis in. Duis molestie ex ut nunc dignissim condimentum ut vitae dui. Vestibulum diam lorem, eleifend sit amet lobortis nec, vulputate a leo. In nec ante felis. Maecenas interdum nunc et odio placerat fringilla. Aenean felis purus, mollis id lectus non, fringilla tincidunt mi. Nunc sed rutrum ex, vel tempus odio."; // String test = "**nec** nec facilisis nibh, sed sagittis tortor. Suspendisse vel felis ac leo dignissim efficitur. Nunc non egestas eros, sit amet vestibulum nunc. Sed bibendum varius molestie. Proin augue mauris, mollis sed efficitur efficitur, sagittis quis eros. Praesent tincidunt tincidunt porttitor. Maecenas quis ornare tellus. Nunc euismod vestibulum neque, sed luctus neque convallis in. Duis molestie ex ut nunc dignissim condimentum ut vitae dui. Vestibulum diam lorem, eleifend sit amet lobortis nec, vulputate a leo. In nec ante felis. Maecenas interdum nunc et odio placerat fringilla. Aenean felis purus, mollis id lectus non, fringilla tincidunt mi. Nunc sed rutrum ex, vel tempus odio.";
//
Journal j1 = new Journal(0,studentIdentifier,test, cal.getTimeInMillis() , Visibility.ALL, "Recherche"); // Journal j1 = new Journal(0,studentIdentifier,test, cal.getTimeInMillis() , Visibility.ALL, "Recherche");
j1.setCreator("Test Test"); // j1.setAuthor("Test Test");
Journal j2 = new Journal(1,studentIdentifier,test, cal.getTimeInMillis() , Visibility.MINE, "Untersuchungskonzept"); // Journal j2 = new Journal(1,studentIdentifier,test, cal.getTimeInMillis() , Visibility.MINE, "Untersuchungskonzept");
j2.setCreator("Test Test"); // j2.setAuthor("Test Test");
Journal j3 = new Journal(2,studentIdentifier,test, cal.getTimeInMillis() , Visibility.GROUP, "Methodik"); // Journal j3 = new Journal(2,studentIdentifier,test, cal.getTimeInMillis() , Visibility.GROUP, "Methodik");
j3.setCreator("Test Test"); // j3.setAuthor("Test Test");
Journal j4 = new Journal(3,studentIdentifier,test, cal.getTimeInMillis() , Visibility.DOZENT ,"Recherche"); // Journal j4 = new Journal(3,studentIdentifier,test, cal.getTimeInMillis() , Visibility.DOZENT ,"Recherche");
j4.setCreator("Test Test"); // j4.setAuthor("Test Test");
Journal j5 = new Journal(4,studentIdentifier2,test, cal.getTimeInMillis() , Visibility.GROUP, "Durchführung"); // Journal j5 = new Journal(4,studentIdentifier2,test, cal.getTimeInMillis() , Visibility.GROUP, "Durchführung");
j5.setCreator("ASD DSA"); // j5.setAuthor("ASD DSA");
//
journals = new ArrayList<>(); // journals = new ArrayList<>();
//
journals.add(j1); // journals.add(j1);
journals.add(j2); // journals.add(j2);
journals.add(j3); // journals.add(j3);
journals.add(j4); // journals.add(j4);
journals.add(j5); // journals.add(j5);
//
} // }
//
//
//
} //}
...@@ -43,16 +43,14 @@ public interface JournalService { ...@@ -43,16 +43,14 @@ public interface JournalService {
* @param text content of the Journal * @param text content of the Journal
* @param visibility visibility of the Journal * @param visibility visibility of the Journal
* @param category category of the Journal * @param category category of the Journal
* @return true if success
*/ */
boolean saveJournal(long id, String student, String project, String text, String visibility, String category); void saveJournal(String id, String student, String project, String text, String visibility, String category);
/** /**
* deletes a Journal * deletes a Journal
* @param id id of the Journal * @param id id of the Journal
* @return true if success
*/ */
boolean deleteJournal(long id); void deleteJournal(String id);
void closeJournal(String journal); void closeJournal(String journal);
......
package unipotsdam.gf.modules.journal.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier;
import unipotsdam.gf.modules.journal.model.*;
import unipotsdam.gf.modules.journal.util.JournalUtils;
import java.util.ArrayList;
public class JournalServiceImpl implements JournalService {
private final Logger log = LoggerFactory.getLogger(JournalServiceImpl.class);
JournalDAO journalDAO = new JournalDAOImpl();
@Override
public Journal getJournal(String id) {
return null;
}
@Override
public ArrayList<Journal> getAllJournals(String student, String project, JournalFilter filter) {
log.debug(">> get all journals(" + student + "," + project + "," + filter + ")");
ArrayList<Journal> result = new ArrayList<>();
ArrayList<Journal> dbJournals = journalDAO.getAllByProjectAndFilter(project, student, filter);
for (Journal j : dbJournals) {
//always show own Journals
if (j.getStudentIdentifier().getStudentId().equals(student)) {
result.add(j);
} else {
// if Visibility All, show if Filter allows it
if (j.getVisibility() == Visibility.ALL && filter == JournalFilter.ALL) {
result.add(j);
}
//If Visibility Group, show if student is in group and filter allows it
//TODO: project != Group, for testing ok, change for real Service
if (j.getVisibility() == Visibility.GROUP && j.getStudentIdentifier().getProjectId().equals(project) && filter == JournalFilter.ALL) {
result.add(j);
}
//TODO if Dozent
}
}
log.debug("<< get all journals(" + student, "," + project + ")");
return result;
}
@Override
public ArrayList<Journal> getAllJournals(String student, String project) {
return journalDAO.getAllByProject(project);
}
@Override
public void saveJournal(String id, String student, String project, String text, String visibility, String category) {
Journal journal = new Journal(id, new StudentIdentifier(student, project), text, JournalUtils.stringToVisibility(visibility), JournalUtils.stringToCategory(category));
//if id = 0 new Journal else update
if (id.equals("0")) {
journalDAO.createJournal(journal);
} else {
journalDAO.updateJournal(journal);
}
}
@Override
public void deleteJournal(String id) {
}
@Override
public void closeJournal(String journal) {
}
}
package unipotsdam.gf.modules.journal.service;
import unipotsdam.gf.modules.journal.model.ProjectDescription;
public class ProjectDescriptionImpl implements ProjectDescriptionService {
@Override
public ProjectDescription getProject(String project) {
return null;
}
@Override
public void saveProjectText(String text) {
}
@Override
public void addLink(String link, String name) {
}
@Override
public void deleteLink(String link) {
}
@Override
public void closeDescription(String desc) {
}
}
package unipotsdam.gf.modules.journal.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import unipotsdam.gf.core.management.utils.Category;
import unipotsdam.gf.modules.journal.model.Visibility;
public class JournalUtils {
public static final Logger log = LoggerFactory.getLogger(JournalUtils.class);
public static Category stringToCategory(String category) {
// If String does not match enum IllegalArgumentException
Category c;
try {
c = Category.valueOf(category);
} catch (IllegalArgumentException e) {
c = Category.TITEL;
//TODO extra Category for fail?
JournalUtils.log.debug("Illegal argument for visibility, default to TITLR");
}
return c;
}
public static Visibility stringToVisibility(String visibility) {
// If String does not match enum IllegalArgumentException
Visibility v;
try {
v = Visibility.valueOf(visibility);
} catch (IllegalArgumentException e) {
v = Visibility.MINE;
JournalUtils.log.debug("Illegal argument for visibility, default to MINE");
}
return v;
}
}
...@@ -4,8 +4,8 @@ import org.slf4j.Logger; ...@@ -4,8 +4,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import unipotsdam.gf.modules.journal.model.Journal; import unipotsdam.gf.modules.journal.model.Journal;
import unipotsdam.gf.modules.journal.model.JournalFilter; import unipotsdam.gf.modules.journal.model.JournalFilter;
import unipotsdam.gf.modules.journal.service.DummyJournalService;
import unipotsdam.gf.modules.journal.service.JournalService; import unipotsdam.gf.modules.journal.service.JournalService;
import unipotsdam.gf.modules.journal.service.JournalServiceImpl;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
...@@ -23,8 +23,8 @@ import java.util.ArrayList; ...@@ -23,8 +23,8 @@ import java.util.ArrayList;
@Path("/journal") @Path("/journal")
public class JournalView { public class JournalView {
private Logger log = LoggerFactory.getLogger(JournalView.class); private final Logger log = LoggerFactory.getLogger(JournalView.class);
private JournalService journalService = new DummyJournalService(); private final JournalService journalService = new JournalServiceImpl();
/** /**
* Returns a specific Journal * Returns a specific Journal
...@@ -67,25 +67,6 @@ public class JournalView { ...@@ -67,25 +67,6 @@ public class JournalView {
return Response.ok(result).build(); return Response.ok(result).build();
} }
/**
* Returns all Journals for a student
* @param student the requested student
* @param project the requested project
* @return Json of all Journals
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/journals/{student}/{project}")
public Response getAllJournals (@PathParam("student") String student, @PathParam("project") String project){
log.debug(">>> getJournals: student=" + student + " project=" + project );
ArrayList<Journal> result = journalService.getAllJournals(student,project);
log.debug(">>> getJournals: size=" + result.size());
return Response.ok(result).build();
}
/** /**
* Saves or edits a Journal * Saves or edits a Journal
...@@ -102,11 +83,11 @@ public class JournalView { ...@@ -102,11 +83,11 @@ public class JournalView {
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
@Path("/save") @Path("/save")
public Response saveJournal(@FormParam("id") long id, @FormParam("student") String student, public Response saveJournal(@FormParam("id") String id, @FormParam("student") String student,
@FormParam("project") String project, @FormParam("text") String text, @FormParam("project") String project, @FormParam("text") String text,
@FormParam("visibility") String visibility, @FormParam("category") String category) { @FormParam("visibility") String visibility, @FormParam("category") String category) {
log.debug(">>> saveJournal"); log.debug(">>> createJournal");
journalService.saveJournal(id, student, project, text, visibility, category); journalService.saveJournal(id, student, project, text, visibility, category);
...@@ -114,15 +95,15 @@ public class JournalView { ...@@ -114,15 +95,15 @@ public class JournalView {
URI location; URI location;
try { try {
location = new URI("../pages/eportfolio.jsp"); location = new URI("../pages/eportfolio.jsp");
log.debug("<<< saveJournal: redirect to " +location.toString()); log.debug("<<< createJournal: redirect to " + location.toString());
return Response.temporaryRedirect(location).build(); return Response.temporaryRedirect(location).build();
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); e.printStackTrace();
log.debug("saveJournal: redirect failed" ); log.debug("createJournal: redirect failed");
} }
log.debug("<<< saveJournal"); log.debug("<<< createJournal");
return Response.ok().build(); return Response.ok().build();
...@@ -137,7 +118,7 @@ public class JournalView { ...@@ -137,7 +118,7 @@ public class JournalView {
@GET @GET
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
@Path("/delete/{id}") @Path("/delete/{id}")
public Response deleteJournal(@PathParam("id") long id) { public Response deleteJournal(@PathParam("id") String id) {
log.debug(">>> deleteJournal: id=" + id); log.debug(">>> deleteJournal: id=" + id);
......
...@@ -19,7 +19,7 @@ $(document).ready(function() { ...@@ -19,7 +19,7 @@ $(document).ready(function() {
}); });
$.ajax({ $.ajax({
url: "../rest/journal//journals/0/0" url: "../rest/journal//journals/0/0/ALL"
}).then(function(data) { }).then(function(data) {
loadJournals(data); loadJournals(data);
console.log(data); console.log(data);
......
USE `fltrail`;
CREATE TABLE if not exists `journals` (
`id` varchar(400) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP,
`author` varchar(400) NOT NULL,
`project` varchar(400) NOT NULL,
`text` text,
`visibility` varchar(50),
`category` varchar(50),
`open` TINYINT(1)
)
ENGINE = InnoDB
DEFAULT CHARSET = utf8;
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