Skip to content
Snippets Groups Projects
Commit 7ff1d7b1 authored by Thomas Schnaak's avatar Thomas Schnaak
Browse files

feat: added rest interface for pdf export

parent 0cc182d5
No related branches found
No related tags found
No related merge requests found
...@@ -56,5 +56,8 @@ public interface IJournal { ...@@ -56,5 +56,8 @@ public interface IJournal {
EPortfolio getFinalPortfolioForAssessment(Project project, User user) ; EPortfolio getFinalPortfolioForAssessment(Project project, User user) ;
EPortfolio getPortfolio(String project, String user);
byte[] exportPortfolioToPdf(EPortfolio ePortfolio); byte[] exportPortfolioToPdf(EPortfolio ePortfolio);
} }
...@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; ...@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import unipotsdam.gf.core.management.project.Project; import unipotsdam.gf.core.management.project.Project;
import unipotsdam.gf.core.management.user.User; import unipotsdam.gf.core.management.user.User;
import unipotsdam.gf.interfaces.IJournal; import unipotsdam.gf.interfaces.IJournal;
import unipotsdam.gf.interfaces.ResearchReports;
import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier; import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier;
import unipotsdam.gf.modules.journal.model.EPortfolio; import unipotsdam.gf.modules.journal.model.EPortfolio;
import unipotsdam.gf.modules.journal.model.Journal; import unipotsdam.gf.modules.journal.model.Journal;
...@@ -15,7 +16,6 @@ import unipotsdam.gf.modules.peer2peerfeedback.Category; ...@@ -15,7 +16,6 @@ import unipotsdam.gf.modules.peer2peerfeedback.Category;
import unipotsdam.gf.modules.researchreport.ResearchReport; import unipotsdam.gf.modules.researchreport.ResearchReport;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
...@@ -62,23 +62,33 @@ public class IJournalImpl implements IJournal { ...@@ -62,23 +62,33 @@ public class IJournalImpl implements IJournal {
@Override @Override
public void uploadJournalEntry(Journal journalEntry, User student) { public void uploadJournalEntry(Journal journalEntry, User student) {
//TODO journalService.saveJournal("0",student.getId(),journalEntry.getStudentIdentifier().getProjectId(),journalEntry.getEntryMD(),journalEntry.getVisibility().toString(),journalEntry.getCategory().toString());
} }
@Override @Override
public void uploadFinalPortfolio(Project project, List<Journal> journalEntries, ResearchReport finalResearchReport, File presentation, User user) { public void uploadFinalPortfolio(Project project, List<Journal> journalEntries, ResearchReport finalResearchReport, File presentation, User user) {
//TODO //TODO for version 2
} }
@Override @Override
public EPortfolio getFinalPortfolioForAssessment(Project project, User user) { public EPortfolio getFinalPortfolioForAssessment(Project project, User user) {
return getPortfolio(project.getId(), user.getId());
}
@Override
public EPortfolio getPortfolio(String project, String user) {
EPortfolio result = new EPortfolio(); EPortfolio result = new EPortfolio();
StudentIdentifier studentIdentifier = new StudentIdentifier(project.getId(), user.getId()); StudentIdentifier studentIdentifier = new StudentIdentifier(project, user);
ResearchReports researchReports /*TODO = ??*/;
result.setDescription(descriptionService.getProjectByStudent(studentIdentifier)); result.setDescription(descriptionService.getProjectByStudent(studentIdentifier));
result.setJournals(journalService.getAllJournals(user.getId(), project.getId())); result.setJournals(journalService.getAllJournals(user, project));
//TODO result.setReport(...); /*
TODO wenn von Quark implementiert
result.setReport(getReports(new StudentIdentifier(project,user));
*/
return result; return result;
} }
...@@ -86,6 +96,7 @@ public class IJournalImpl implements IJournal { ...@@ -86,6 +96,7 @@ public class IJournalImpl implements IJournal {
@Override @Override
public byte[] exportPortfolioToPdf(EPortfolio ePortfolio) { public byte[] exportPortfolioToPdf(EPortfolio ePortfolio) {
//IntelliJs solution for lambda statement
final byte[][] res = new byte[1][1]; final byte[][] res = new byte[1][1];
//Build String //Build String
...@@ -97,25 +108,13 @@ public class IJournalImpl implements IJournal { ...@@ -97,25 +108,13 @@ public class IJournalImpl implements IJournal {
.newConverter() .newConverter()
.readFrom(() -> input) .readFrom(() -> input)
.writeTo(out -> { .writeTo(out -> {
//TODO für rest anpassen
FileOutputStream outputStream;
res[0] = out; res[0] = out;
try {
outputStream = new FileOutputStream("C:\\Users\\thomas\\Desktop\\test_" + new Date().getTime() + ".pdf");
outputStream.write(out);
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}) })
.doIt(); .doIt();
} catch (ConversionException | Markdown2PdfLogicException e) { } catch (ConversionException | Markdown2PdfLogicException e) {
//TODO
e.printStackTrace(); e.printStackTrace();
} }
//Return
return res[0]; return res[0];
} }
...@@ -150,7 +149,7 @@ public class IJournalImpl implements IJournal { ...@@ -150,7 +149,7 @@ public class IJournalImpl implements IJournal {
result.append(researchReport.getMethod()).append("\n"); result.append(researchReport.getMethod()).append("\n");
//TODO ??????? //TODO zuordnung Absprechen
result.append(journalStringByCategory(journals, Category.UNTERSUCHUNGSKONZEPT)); result.append(journalStringByCategory(journals, Category.UNTERSUCHUNGSKONZEPT));
result.append(journalStringByCategory(journals, Category.METHODIK)); result.append(journalStringByCategory(journals, Category.METHODIK));
...@@ -221,6 +220,4 @@ public class IJournalImpl implements IJournal { ...@@ -221,6 +220,4 @@ public class IJournalImpl implements IJournal {
private String journalAsString(Journal j) { private String journalAsString(Journal j) {
return jdf.format(new Date(j.getTimestamp())) + " " + j.getCategory() + "\n" + j.getEntryMD() + "\n"; return jdf.format(new Date(j.getTimestamp())) + " " + j.getCategory() + "\n" + j.getEntryMD() + "\n";
} }
} }
...@@ -29,7 +29,6 @@ public class JournalUtils { ...@@ -29,7 +29,6 @@ public class JournalUtils {
c = Category.valueOf(category); c = Category.valueOf(category);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
c = Category.TITEL; c = Category.TITEL;
//TODO extra Category for fail?
JournalUtils.log.debug("Illegal argument for visibility, default to TITLE"); JournalUtils.log.debug("Illegal argument for visibility, default to TITLE");
} }
return c; return c;
......
package unipotsdam.gf.modules.journal.view;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import unipotsdam.gf.interfaces.IJournal;
import unipotsdam.gf.modules.journal.model.EPortfolio;
import unipotsdam.gf.modules.journal.service.IJournalImpl;
import unipotsdam.gf.modules.journal.service.JournalService;
import unipotsdam.gf.modules.journal.service.JournalServiceImpl;
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.MediaType;
import javax.ws.rs.core.Response;
/**
* View for exporting the EPortfolio
*/
@Path("/eportfolio")
public class EPortfolioView {
private final Logger log = LoggerFactory.getLogger(EPortfolioView.class);
private final JournalService journalService = new JournalServiceImpl();
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Path("/pdf/{student}/{project}")
public Response getPdf (@PathParam("student") String student, @PathParam("project") String project){
IJournal iJournal = new IJournalImpl();
EPortfolio ePortfolio = iJournal.getPortfolio(project,student);
byte[] pdf = iJournal.exportPortfolioToPdf(ePortfolio);
return Response.ok(pdf).build();
}
}
...@@ -18,7 +18,7 @@ import java.util.ArrayList; ...@@ -18,7 +18,7 @@ import java.util.ArrayList;
/** /**
* View for the learning journal * View for the learning journal
* *
* TODO error handling, (maybe) method to change visibility * TODO (maybe) method to change visibility
*/ */
@Path("/journal") @Path("/journal")
...@@ -92,7 +92,6 @@ public class JournalView { ...@@ -92,7 +92,6 @@ public class JournalView {
journalService.saveJournal(id, student, project, text, visibility, category); journalService.saveJournal(id, student, project, text, visibility, category);
//TODO token
URI location; URI location;
try { try {
location = new URI("../pages/eportfolio.jsp?token=" + student + "&projectId=" + project); location = new URI("../pages/eportfolio.jsp?token=" + student + "&projectId=" + project);
...@@ -139,7 +138,6 @@ public class JournalView { ...@@ -139,7 +138,6 @@ public class JournalView {
StudentIdentifier student = journalService.getJournal(journal).getStudentIdentifier(); StudentIdentifier student = journalService.getJournal(journal).getStudentIdentifier();
journalService.closeJournal(journal); journalService.closeJournal(journal);
//TODO token
try { try {
URI location = new URI("../pages/eportfolio.jsp?token=" + student.getStudentId() + "&projectId=" + student.getProjectId()); URI location = new URI("../pages/eportfolio.jsp?token=" + student.getStudentId() + "&projectId=" + student.getProjectId());
log.debug("<<< closeJournal: redirect to " +location.toString()); log.debug("<<< closeJournal: redirect to " +location.toString());
......
...@@ -16,7 +16,6 @@ import java.net.URISyntaxException; ...@@ -16,7 +16,6 @@ import java.net.URISyntaxException;
/** /**
* View for the project description * View for the project description
* *
* TODO error handling
*/ */
@Path("/projectdescription") @Path("/projectdescription")
...@@ -47,7 +46,6 @@ public class ProjectDescriptionView { ...@@ -47,7 +46,6 @@ public class ProjectDescriptionView {
log.debug(">>> saveText: " + text); log.debug(">>> saveText: " + text);
descriptionService.saveProjectText(new StudentIdentifier(project,student),text); descriptionService.saveProjectText(new StudentIdentifier(project,student),text);
//TODO token
try { try {
URI location = new URI("../pages/eportfolio.jsp?token=" + student + "&projectId=" + project); URI location = new URI("../pages/eportfolio.jsp?token=" + student + "&projectId=" + project);
log.debug("<<< saveText: redirect to " +location.toString()); log.debug("<<< saveText: redirect to " +location.toString());
...@@ -99,7 +97,6 @@ public class ProjectDescriptionView { ...@@ -99,7 +97,6 @@ public class ProjectDescriptionView {
log.debug(">>> deleteLink: " + link); log.debug(">>> deleteLink: " + link);
descriptionService.deleteLink(link); descriptionService.deleteLink(link);
//TODO token
try { try {
URI location = new URI("../pages/eportfolio.jsp"); URI location = new URI("../pages/eportfolio.jsp");
log.debug("<<< deleteLink: redirect to " +location.toString()); log.debug("<<< deleteLink: redirect to " +location.toString());
......
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