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

#65 feat: added methods for pdf export of EPortfolio

parent 76d97422
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -207,6 +207,11 @@ ...@@ -207,6 +207,11 @@
<version>7.1.1.RELEASE</version> <version>7.1.1.RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>eu.de-swaef.pdf</groupId>
<artifactId>Markdown2Pdf</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -10,8 +10,6 @@ import unipotsdam.gf.modules.researchreport.ResearchReport; ...@@ -10,8 +10,6 @@ import unipotsdam.gf.modules.researchreport.ResearchReport;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier;
/** /**
* Interface for learning journal * Interface for learning journal
*/ */
...@@ -20,14 +18,14 @@ public interface IJournal { ...@@ -20,14 +18,14 @@ public interface IJournal {
/** /**
* check if all students have prepared their portfolios to be evaluated * check if all students have prepared their portfolios to be evaluated
* @return * @return true if all students have prepared their portfolios
* @param project * @param project project
*/ */
Boolean getPortfoliosForEvaluationPrepared(Project project) ; Boolean getPortfoliosForEvaluationPrepared(Project project) ;
/** /**
* find out, who hasn't prepared their portfolio for evaluation and send message or highlight in view * find out, who hasn't prepared their portfolio for evaluation and send message or highlight in view
* @param project * @param project project
*/ */
void assignMissingPortfolioTasks(Project project) ; void assignMissingPortfolioTasks(Project project) ;
...@@ -52,9 +50,11 @@ public interface IJournal { ...@@ -52,9 +50,11 @@ public interface IJournal {
/** /**
* Gets EPortfolio for assesment * Gets EPortfolio for assesment
* @param project * @param project project
* @return EPortfolio (containing Report, ProjectDescription and Journal) * @return EPortfolio (containing Report, ProjectDescription and Journal)
*/ */
EPortfolio getFinalPortfolioForAssessment(Project project, User user) ; EPortfolio getFinalPortfolioForAssessment(Project project, User user) ;
byte[] exportPortfolioToPdf(EPortfolio ePortfolio);
} }
package unipotsdam.gf.modules.journal.service; package unipotsdam.gf.modules.journal.service;
import com.qkyrie.markdown2pdf.Markdown2PdfConverter;
import com.qkyrie.markdown2pdf.internal.exceptions.ConversionException;
import com.qkyrie.markdown2pdf.internal.exceptions.Markdown2PdfLogicException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import unipotsdam.gf.core.management.project.Project; import unipotsdam.gf.core.management.project.Project;
...@@ -8,10 +11,14 @@ import unipotsdam.gf.interfaces.IJournal; ...@@ -8,10 +11,14 @@ import unipotsdam.gf.interfaces.IJournal;
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;
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.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
public class IJournalImpl implements IJournal { public class IJournalImpl implements IJournal {
...@@ -21,6 +28,7 @@ public class IJournalImpl implements IJournal { ...@@ -21,6 +28,7 @@ public class IJournalImpl implements IJournal {
private final JournalService journalService = new JournalServiceImpl(); private final JournalService journalService = new JournalServiceImpl();
private final ProjectDescriptionService descriptionService = new ProjectDescriptionImpl(); private final ProjectDescriptionService descriptionService = new ProjectDescriptionImpl();
private final SimpleDateFormat jdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
@Override @Override
public Boolean getPortfoliosForEvaluationPrepared(Project project) { public Boolean getPortfoliosForEvaluationPrepared(Project project) {
...@@ -33,7 +41,7 @@ public class IJournalImpl implements IJournal { ...@@ -33,7 +41,7 @@ public class IJournalImpl implements IJournal {
ArrayList<User> descUser = descriptionService.getOpenUserByProject(project); ArrayList<User> descUser = descriptionService.getOpenUserByProject(project);
for(User user : descUser){ for (User user : descUser) {
log.debug("Send close description message to user {}", user.getId()); log.debug("Send close description message to user {}", user.getId());
//TODO send message when implemented //TODO send message when implemented
...@@ -42,7 +50,7 @@ public class IJournalImpl implements IJournal { ...@@ -42,7 +50,7 @@ public class IJournalImpl implements IJournal {
ArrayList<User> journalUser = journalService.getOpenUserByProject(project); ArrayList<User> journalUser = journalService.getOpenUserByProject(project);
for(User user : journalUser){ for (User user : journalUser) {
log.debug("Send close journal message to user {}", user.getId()); log.debug("Send close journal message to user {}", user.getId());
//TODO send message when implemented //TODO send message when implemented
...@@ -66,14 +74,153 @@ public class IJournalImpl implements IJournal { ...@@ -66,14 +74,153 @@ public class IJournalImpl implements IJournal {
public EPortfolio getFinalPortfolioForAssessment(Project project, User user) { public EPortfolio getFinalPortfolioForAssessment(Project project, User user) {
EPortfolio result = new EPortfolio(); EPortfolio result = new EPortfolio();
StudentIdentifier studentIdentifier = new StudentIdentifier(project.getId(),user.getId()); StudentIdentifier studentIdentifier = new StudentIdentifier(project.getId(), user.getId());
result.setDescription(descriptionService.getProjectByStudent(studentIdentifier)); result.setDescription(descriptionService.getProjectByStudent(studentIdentifier));
result.setJournals(journalService.getAllJournals(user.getId(),project.getId())); result.setJournals(journalService.getAllJournals(user.getId(), project.getId()));
//TODO result.setReport(...); //TODO result.setReport(...);
return result; return result;
} }
@Override
public byte[] exportPortfolioToPdf(EPortfolio ePortfolio) {
final byte[][] res = new byte[1][1];
//Build String
String input = ePortfolioToString(ePortfolio);
//Convert
try {
Markdown2PdfConverter
.newConverter()
.readFrom(() -> input)
.writeTo(out -> {
//TODO für rest anpassen
FileOutputStream outputStream;
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();
} catch (ConversionException | Markdown2PdfLogicException e) {
//TODO
e.printStackTrace();
}
//Return
return res[0];
}
//TODO Formatierung
private String ePortfolioToString(EPortfolio ePortfolio) {
StringBuilder result = new StringBuilder();
//If Description exists, add to pdf
if (ePortfolio.getDescription() != null) {
result.append("#Portfolio# \n\n");
result.append(ePortfolio.getDescription().getDescriptionMD()).append("\n");
}
//If Journals and Report exists combine
if (ePortfolio.getReport() != null && ePortfolio.getJournals() != null && !ePortfolio.getJournals().isEmpty()) {
ArrayList<Journal> journals = ePortfolio.getJournals();
ResearchReport researchReport = ePortfolio.getReport();
//TODO zuordnung Absprechen
result.append(researchReport.getTitle()).append("\n");
result.append(journalStringByCategory(journals, Category.TITEL));
result.append(researchReport.getResearchQuestion()).append("\n");
result.append(journalStringByCategory(journals, Category.FORSCHUNGSFRAGE));
for (String s : researchReport.getLearningGoals()) {
result.append(s).append("\n");
}
result.append(researchReport.getMethod()).append("\n");
//TODO ???????
result.append(journalStringByCategory(journals, Category.UNTERSUCHUNGSKONZEPT));
result.append(journalStringByCategory(journals, Category.METHODIK));
result.append(researchReport.getResearch()).append("\n");
result.append(journalStringByCategory(journals, Category.RECHERCHE));
result.append(researchReport.getResearchResult()).append("\n");
result.append(journalStringByCategory(journals, Category.DURCHFUEHRUNG));
result.append(researchReport.getEvaluation()).append("\n");
result.append(journalStringByCategory(journals, Category.AUSWERTUNG));
//TODO Extract String when implemented
result.append(researchReport.getBibliography()).append("\n");
result.append(journalStringByCategory(journals, Category.LITERATURVERZEICHNIS));
}
//if Report but no Journals, add Report
else if (ePortfolio.getReport() != null) {
ResearchReport report = ePortfolio.getReport();
result.append(report.getTitle()).append("\n");
result.append(report.getResearchQuestion()).append("\n");
for (String s : report.getLearningGoals()) {
result.append(s).append("\n");
}
result.append(report.getMethod()).append("\n");
result.append(report.getResearch()).append("\n");
result.append(report.getResearchResult()).append("\n");
result.append(report.getEvaluation()).append("\n");
//TODO Extract String when implemented
result.append(report.getBibliography()).append("\n");
}
//If Journal but no Report
else if (ePortfolio.getJournals() != null) {
result.append("##Lerntagebuch## \n\n");
for (Journal j : ePortfolio.getJournals()) {
result.append(journalAsString(j));
}
}
return result.toString();
}
private String journalStringByCategory(ArrayList<Journal> journals, Category c) {
StringBuilder str = new StringBuilder();
for (Journal j : journals) {
if (j.getCategory().equals(c)) {
str.append(journalAsString(j));
}
}
return str.toString();
}
private String journalAsString(Journal j) {
return jdf.format(new Date(j.getTimestamp())) + " " + j.getCategory() + "\n" + j.getEntryMD() + "\n";
}
} }
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