-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from softwaremagico/260-download-all-generate…
…d-info-in-a-zip-file 260 download all generated info in a zip file
- Loading branch information
Showing
19 changed files
with
245 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../kendo-tournament-pdf/src/main/java/com/softwaremagico/kt/html/controller/ZipContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.softwaremagico.kt.html.controller; | ||
|
||
public class ZipContent { | ||
private final String name; | ||
private final String extension; | ||
|
||
private final byte[] content; | ||
|
||
ZipContent(String name, String extension, byte[] content) { | ||
this.name = name; | ||
this.extension = extension; | ||
this.content = content; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getExtension() { | ||
return extension; | ||
} | ||
|
||
public byte[] getContent() { | ||
return content; | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...ndo-tournament-pdf/src/main/java/com/softwaremagico/kt/html/controller/ZipController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.softwaremagico.kt.html.controller; | ||
|
||
import com.softwaremagico.kt.core.controller.RankingController; | ||
import com.softwaremagico.kt.core.controller.models.ScoreOfCompetitorDTO; | ||
import com.softwaremagico.kt.core.controller.models.ScoreOfTeamDTO; | ||
import com.softwaremagico.kt.core.controller.models.TournamentDTO; | ||
import com.softwaremagico.kt.logger.KendoTournamentLogger; | ||
import com.softwaremagico.kt.pdf.EmptyPdfBodyException; | ||
import com.softwaremagico.kt.pdf.InvalidXmlElementException; | ||
import com.softwaremagico.kt.pdf.controller.PdfController; | ||
import org.springframework.stereotype.Controller; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
@Controller | ||
public class ZipController { | ||
|
||
private final PdfController pdfController; | ||
private final HtmlController htmlController; | ||
|
||
private final RankingController rankingController; | ||
|
||
public ZipController(PdfController pdfController, HtmlController htmlController, RankingController rankingController) { | ||
this.pdfController = pdfController; | ||
this.htmlController = htmlController; | ||
this.rankingController = rankingController; | ||
} | ||
|
||
|
||
public byte[] createZipData(Locale locale, TournamentDTO tournament) throws IOException { | ||
final List<ZipContent> content = new ArrayList<>(); | ||
//Role List | ||
try { | ||
content.add(new ZipContent("Role List - " + tournament.getName(), "pdf", | ||
pdfController.generateClubList(locale, tournament).generate())); | ||
} catch (EmptyPdfBodyException | InvalidXmlElementException e) { | ||
KendoTournamentLogger.errorMessage(this.getClass(), e); | ||
} | ||
//Team List | ||
try { | ||
content.add(new ZipContent("Team List - " + tournament.getName(), "pdf", | ||
pdfController.generateTeamList(tournament).generate())); | ||
} catch (EmptyPdfBodyException | InvalidXmlElementException e) { | ||
KendoTournamentLogger.errorMessage(this.getClass(), e); | ||
} | ||
//Fight List | ||
try { | ||
content.add(new ZipContent("Fight List - " + tournament.getName(), "pdf", | ||
pdfController.generateFightsSummaryList(locale, tournament).generate())); | ||
} catch (EmptyPdfBodyException | InvalidXmlElementException e) { | ||
KendoTournamentLogger.errorMessage(this.getClass(), e); | ||
} | ||
//Team Ranking | ||
try { | ||
final List<ScoreOfTeamDTO> scores = rankingController.getTeamsScoreRanking(tournament); | ||
content.add(new ZipContent("Team Ranking - " + tournament.getName(), "pdf", | ||
pdfController.generateTeamsScoreList(locale, tournament, scores).generate())); | ||
} catch (EmptyPdfBodyException | InvalidXmlElementException e) { | ||
KendoTournamentLogger.errorMessage(this.getClass(), e); | ||
} | ||
//Competitors Ranking | ||
try { | ||
final List<ScoreOfCompetitorDTO> scores = rankingController.getCompetitorsScoreRanking(tournament); | ||
content.add(new ZipContent("Competitors Ranking - " + tournament.getName(), "pdf", | ||
pdfController.generateCompetitorsScoreList(locale, tournament, scores).generate())); | ||
} catch (EmptyPdfBodyException | InvalidXmlElementException e) { | ||
KendoTournamentLogger.errorMessage(this.getClass(), e); | ||
} | ||
//BlogCode | ||
content.add(new ZipContent("Wordpress code - " + tournament.getName(), "txt", | ||
htmlController.generateBlogCode(locale, tournament).getWordpressFormat().getBytes(StandardCharsets.UTF_8))); | ||
return createZipData(content); | ||
} | ||
|
||
|
||
public byte[] createZipData(List<ZipContent> content) throws IOException { | ||
if (content == null || content.isEmpty()) { | ||
return null; | ||
} | ||
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
final ZipOutputStream zipOutputStream = new ZipOutputStream(byteArrayOutputStream); | ||
for (ZipContent zipContent : content) { | ||
try { | ||
final ZipEntry entry = new ZipEntry(zipContent.getName() + "." + zipContent.getExtension()); | ||
zipOutputStream.putNextEntry(entry); | ||
final byte[] data = zipContent.getContent(); | ||
zipOutputStream.write(data, 0, data.length); | ||
zipOutputStream.closeEntry(); | ||
} catch (IOException e) { | ||
KendoTournamentLogger.errorMessage(this.getClass(), e); | ||
} | ||
} | ||
zipOutputStream.close(); | ||
return byteArrayOutputStream.toByteArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.