diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/model/Journal.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/model/Journal.java index 65a17d1fea783d016f0422414d5dbed66ee4b671..87d775b8873508d183b0aab58962b95c9f616f1f 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/model/Journal.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/model/Journal.java @@ -1,8 +1,11 @@ package unipotsdam.gf.modules.journal.model; +import unipotsdam.gf.core.management.utils.Category; import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier; +import java.util.Date; + import static unipotsdam.gf.core.management.utils.MarkdownUtils.convertMarkdownToHtml; /** @@ -10,39 +13,57 @@ import static unipotsdam.gf.core.management.utils.MarkdownUtils.convertMarkdownT */ public class Journal { - private long id; + private String id; private StudentIdentifier studentIdentifier; - private String creator; private String entryHTML; private String entryMD; private long timestamp; private Visibility visibility; - private String category;//TODO enum + private Category category; + private boolean open; 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.studentIdentifier = studentIdentifier; - // TODO setName per StudentID - this.entryHTML = convertMarkdownToHtml(entry); - this.entryMD = entry; + entryHTML = convertMarkdownToHtml(entryMD); + this.entryMD = entryMD; + 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.visibility = visibility; this.category = category; + this.open = open; } - public void setEntry(String entry){ - this.entryMD = entry; - this.entryHTML = convertMarkdownToHtml(entry); + public boolean isOpen() { + return open; + } + + 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; } - public void setId(long id) { + public void setId(String id) { this.id = id; } @@ -78,40 +99,34 @@ public class Journal { this.visibility = visibility; } - public String getCategory() { + public Category getCategory() { return category; } - public void setCategory(String category) { + public void setCategory(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 public String toString() { return "Journal{" + "id=" + id + ", studentIdentifier=" + studentIdentifier + - ", creator='" + creator + '\'' + ", entryHTML='" + entryHTML + '\'' + + ", entryMD='" + entryMD + '\'' + ", timestamp=" + timestamp + ", visibility=" + visibility + - ", category='" + category + '\'' + + ", category=" + category + + ", open=" + open + '}'; } + + public String getEntryMD() { + return entryMD; + } + + public void setEntryMD(String entryMD) { + this.entryMD = entryMD; + } + } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/model/JournalDAO.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/model/JournalDAO.java new file mode 100644 index 0000000000000000000000000000000000000000..81074a2d9abb40237c0e1cda6451e033b07c227a --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/model/JournalDAO.java @@ -0,0 +1,22 @@ +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); + +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/model/JournalDAOImpl.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/model/JournalDAOImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..2905132040f75fc1e2d10b461abb036171199ba8 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/model/JournalDAOImpl.java @@ -0,0 +1,211 @@ +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); + + } +} 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 index d005bbd9dd17092bd316eea835c49ce5f8c66661..829e4320b932aa46da3b2abd94f5df82189a7415 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/DummyJournalService.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/DummyJournalService.java @@ -1,159 +1,159 @@ -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.Journal; -import unipotsdam.gf.modules.journal.model.JournalFilter; -import unipotsdam.gf.modules.journal.model.Visibility; - -import java.util.ArrayList; -import java.util.Calendar; - -/** - * Service Implementation to test rest, no Database operations - */ - -public class DummyJournalService implements JournalService { - - private Logger log = LoggerFactory.getLogger(DummyJournalService.class); - - - private Calendar cal = Calendar.getInstance(); - - private long id = 4; - - private ArrayList<Journal> journals = new ArrayList<>(); - - public DummyJournalService(){ - - resetList(); - } - - @Override - public Journal getJournal(String id) { - for (Journal j : journals) { - if(j.getId() == Long.valueOf(id)){ - return j; - } - } - 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<>(); - - for (Journal j: journals) { - - //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 getAllJournals(student,project,JournalFilter.ALL); - } - - @Override - public boolean saveJournal(long id, String student, String project, String text, String visibility, String category) { - if (id == -1){ - - StudentIdentifier studentId = new StudentIdentifier(student,project); - journals.add(new Journal(this.id++, studentId, text , cal.getTimeInMillis(), stringToVisibility(visibility) , category)); - - } else { - for (Journal j : journals){ - if(j.getId() == id){ - j.setEntry(text); - j.setVisibility(stringToVisibility(visibility)); - j.setCategory(category); - } - } - resetList(); - } - return true; - } - - @Override - public boolean deleteJournal(long id) { - for (Journal j : journals) { - if (j.getId() == id) { - journals.remove(j); - return true; - } - } - return false; - } - - @Override - public void closeJournal(String journal) { - - } - - private Visibility stringToVisibility(String visibility) { - // If String does not match enum IllegalArgumentException - Visibility v ; - try{ - v = Visibility.valueOf(visibility); - }catch (IllegalArgumentException e){ - v = Visibility.MINE; - log.debug("Illegal argument for visibility, default to MINE"); - } - return v; - } - - private void resetList() { - - StudentIdentifier studentIdentifier = new StudentIdentifier("0","0"); - 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."; - - Journal j1 = new Journal(0,studentIdentifier,test, cal.getTimeInMillis() , Visibility.ALL, "Recherche"); - j1.setCreator("Test Test"); - Journal j2 = new Journal(1,studentIdentifier,test, cal.getTimeInMillis() , Visibility.MINE, "Untersuchungskonzept"); - j2.setCreator("Test Test"); - Journal j3 = new Journal(2,studentIdentifier,test, cal.getTimeInMillis() , Visibility.GROUP, "Methodik"); - j3.setCreator("Test Test"); - Journal j4 = new Journal(3,studentIdentifier,test, cal.getTimeInMillis() , Visibility.DOZENT ,"Recherche"); - j4.setCreator("Test Test"); - Journal j5 = new Journal(4,studentIdentifier2,test, cal.getTimeInMillis() , Visibility.GROUP, "Durchführung"); - j5.setCreator("ASD DSA"); - - journals = new ArrayList<>(); - - journals.add(j1); - journals.add(j2); - journals.add(j3); - journals.add(j4); - journals.add(j5); - - } - - - -} +//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.Journal; +//import unipotsdam.gf.modules.journal.model.JournalFilter; +//import unipotsdam.gf.modules.journal.model.Visibility; +// +//import java.util.ArrayList; +//import java.util.Calendar; +// +///** +// * Service Implementation to test rest, no Database operations +// */ +// +//public class DummyJournalService implements JournalService { +// +// private final Logger log = LoggerFactory.getLogger(DummyJournalService.class); +// +// +// private final Calendar cal = Calendar.getInstance(); +// +// private long id = 4; +// +// private ArrayList<Journal> journals = new ArrayList<>(); +// +// public DummyJournalService(){ +// +// resetList(); +// } +// +// @Override +// public Journal getJournal(String id) { +// for (Journal j : journals) { +// if(j.getId() == Long.valueOf(id)){ +// return j; +// } +// } +// 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<>(); +// +// for (Journal j: journals) { +// +// //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 getAllJournals(student,project,JournalFilter.ALL); +// } +// +// @Override +// public boolean saveJournal(long id, String student, String project, String text, String visibility, String category) { +// if (id == -1){ +// +// StudentIdentifier studentId = new StudentIdentifier(student,project); +// journals.add(new Journal(this.id++, studentId, text , cal.getTimeInMillis(), stringToVisibility(visibility) , category)); +// +// } else { +// for (Journal j : journals){ +// if(j.getId() == id){ +// j.setEntry(text); +// j.setVisibility(stringToVisibility(visibility)); +// j.setCategory(category); +// } +// } +// resetList(); +// } +// return true; +// } +// +// @Override +// public boolean deleteJournal(long id) { +// for (Journal j : journals) { +// if (j.getId() == id) { +// journals.remove(j); +// return true; +// } +// } +// return false; +// } +// +// @Override +// public void closeJournal(String journal) { +// +// } +// +// private Visibility stringToVisibility(String visibility) { +// // If String does not match enum IllegalArgumentException +// Visibility v ; +// try{ +// v = Visibility.valueOf(visibility); +// }catch (IllegalArgumentException e){ +// v = Visibility.MINE; +// log.debug("Illegal argument for visibility, default to MINE"); +// } +// return v; +// } +// +// private void resetList() { +// +// StudentIdentifier studentIdentifier = new StudentIdentifier("0","0"); +// 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."; +// +// Journal j1 = new Journal(0,studentIdentifier,test, cal.getTimeInMillis() , Visibility.ALL, "Recherche"); +// j1.setAuthor("Test Test"); +// Journal j2 = new Journal(1,studentIdentifier,test, cal.getTimeInMillis() , Visibility.MINE, "Untersuchungskonzept"); +// j2.setAuthor("Test Test"); +// Journal j3 = new Journal(2,studentIdentifier,test, cal.getTimeInMillis() , Visibility.GROUP, "Methodik"); +// j3.setAuthor("Test Test"); +// Journal j4 = new Journal(3,studentIdentifier,test, cal.getTimeInMillis() , Visibility.DOZENT ,"Recherche"); +// j4.setAuthor("Test Test"); +// Journal j5 = new Journal(4,studentIdentifier2,test, cal.getTimeInMillis() , Visibility.GROUP, "Durchführung"); +// j5.setAuthor("ASD DSA"); +// +// journals = new ArrayList<>(); +// +// journals.add(j1); +// journals.add(j2); +// journals.add(j3); +// journals.add(j4); +// journals.add(j5); +// +// } +// +// +// +//} 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 index c247215c82bb98e7f41d807fb22a8c9a2f87d360..755b1cf594ca1fb3516d4096567bbc2eba522b8f 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/JournalService.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/JournalService.java @@ -43,16 +43,14 @@ public interface JournalService { * @param text content of the Journal * @param visibility visibility 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 * @param id id of the Journal - * @return true if success */ - boolean deleteJournal(long id); + void deleteJournal(String id); void closeJournal(String journal); diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/JournalServiceImpl.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/JournalServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..da139f7a7c3f31e03a286c95e8aedbda5b1d8714 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/JournalServiceImpl.java @@ -0,0 +1,84 @@ +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) { + + } + + +} + diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/ProjectDescriptionImpl.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/ProjectDescriptionImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..17b2e1a79988c2ccd5c6455d61ee03cbb4a09582 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/service/ProjectDescriptionImpl.java @@ -0,0 +1,30 @@ +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) { + + } +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/util/JournalUtils.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/util/JournalUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..6a3700f2934ff55310cb69584b414cecabd4e1e9 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/util/JournalUtils.java @@ -0,0 +1,36 @@ +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; + } +} 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 index 697d3e2f3da2db57e88cca6f5dc18798f2abc46a..7fda61ff148db31fc97ed00349825fc09913e28f 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/view/JournalView.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/journal/view/JournalView.java @@ -4,8 +4,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import unipotsdam.gf.modules.journal.model.Journal; 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.JournalServiceImpl; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; @@ -23,8 +23,8 @@ import java.util.ArrayList; @Path("/journal") public class JournalView { - private Logger log = LoggerFactory.getLogger(JournalView.class); - private JournalService journalService = new DummyJournalService(); + private final Logger log = LoggerFactory.getLogger(JournalView.class); + private final JournalService journalService = new JournalServiceImpl(); /** * Returns a specific Journal @@ -67,25 +67,6 @@ public class JournalView { 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 @@ -102,11 +83,11 @@ public class JournalView { @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_PLAIN) @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("visibility") String visibility, @FormParam("category") String category) { - log.debug(">>> saveJournal"); + log.debug(">>> createJournal"); journalService.saveJournal(id, student, project, text, visibility, category); @@ -114,15 +95,15 @@ public class JournalView { URI location; try { 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(); } catch (URISyntaxException e) { e.printStackTrace(); - log.debug("saveJournal: redirect failed" ); + log.debug("createJournal: redirect failed"); } - log.debug("<<< saveJournal"); + log.debug("<<< createJournal"); return Response.ok().build(); @@ -137,7 +118,7 @@ public class JournalView { @GET @Produces(MediaType.TEXT_PLAIN) @Path("/delete/{id}") - public Response deleteJournal(@PathParam("id") long id) { + public Response deleteJournal(@PathParam("id") String id) { log.debug(">>> deleteJournal: id=" + id); diff --git a/gemeinsamforschen/src/main/webapp/assets/js/e-portfolio.js b/gemeinsamforschen/src/main/webapp/assets/js/e-portfolio.js index 45fdee037dfd5c1d814acbd1a3c68ee8c2ebf959..ac304c91d02f8402333f2fa7919b3c590451ff0f 100644 --- a/gemeinsamforschen/src/main/webapp/assets/js/e-portfolio.js +++ b/gemeinsamforschen/src/main/webapp/assets/js/e-portfolio.js @@ -19,7 +19,7 @@ $(document).ready(function() { }); $.ajax({ - url: "../rest/journal//journals/0/0" + url: "../rest/journal//journals/0/0/ALL" }).then(function(data) { loadJournals(data); console.log(data); diff --git a/gemeinsamforschen/src/scripts/dbschema/journal.sql b/gemeinsamforschen/src/scripts/dbschema/journal.sql new file mode 100644 index 0000000000000000000000000000000000000000..ce8ac8ec7f773253c664ee8f4c22e78d9b9e62ce --- /dev/null +++ b/gemeinsamforschen/src/scripts/dbschema/journal.sql @@ -0,0 +1,17 @@ +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;