diff --git a/build.gradle b/build.gradle index 0b226e3..d0366e2 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ apply plugin: 'war' apply plugin: 'application' group = 'de.jottyfan.camporganizer' -version = '0.2.3' +version = '0.2.4' sourceCompatibility = 17 mainClassName = "de.jottyfan.camporganizer.Main" diff --git a/src/main/java/de/jottyfan/camporganizer/module/camplist/BookingBean.java b/src/main/java/de/jottyfan/camporganizer/module/camplist/BookingBean.java index 5357a9f..9ab7f29 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/camplist/BookingBean.java +++ b/src/main/java/de/jottyfan/camporganizer/module/camplist/BookingBean.java @@ -3,6 +3,8 @@ package de.jottyfan.camporganizer.module.camplist; import java.io.Serializable; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole; import de.jottyfan.camporganizer.db.jooq.enums.EnumSex; @@ -42,6 +44,12 @@ public class BookingBean implements Serializable { private Boolean accept; private String subscriber; + private List documents; + + public BookingBean() { + this.documents = new ArrayList<>(); + } + public Boolean isFemale() { return EnumSex.female.equals(sex); } @@ -400,4 +408,8 @@ public class BookingBean implements Serializable { this.subscriber = subscriber; } + public List getDocuments() { + return documents; + } + } diff --git a/src/main/java/de/jottyfan/camporganizer/module/camplist/CamplistGateway.java b/src/main/java/de/jottyfan/camporganizer/module/camplist/CamplistGateway.java index 927fecf..f8234b3 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/camplist/CamplistGateway.java +++ b/src/main/java/de/jottyfan/camporganizer/module/camplist/CamplistGateway.java @@ -1,5 +1,8 @@ package de.jottyfan.camporganizer.module.camplist; +import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMPDOCUMENT; +import static de.jottyfan.camporganizer.db.jooq.Tables.T_DOCUMENT; +import static de.jottyfan.camporganizer.db.jooq.Tables.T_DOCUMENTROLE; import static de.jottyfan.camporganizer.db.jooq.Tables.T_PERSON; import static de.jottyfan.camporganizer.db.jooq.Tables.T_PROFILE; import static de.jottyfan.camporganizer.db.jooq.Tables.V_CAMP; @@ -14,12 +17,15 @@ import org.apache.logging.log4j.Logger; import org.jooq.Condition; import org.jooq.DSLContext; import org.jooq.Record; +import org.jooq.Record2; +import org.jooq.SelectConditionStep; import org.jooq.SelectSeekStep1; import org.jooq.SelectSeekStep2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; +import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole; import de.jottyfan.camporganizer.db.jooq.tables.TProfile; import de.jottyfan.camporganizer.db.jooq.tables.records.VCampRecord; @@ -61,6 +67,7 @@ public class CamplistGateway { T_PERSON.EMAIL, T_PERSON.SEX, T_PERSON.ACCEPT, + T_PERSON.FK_CAMP, T_PROFILE.FORENAME, T_PROFILE.SURNAME, REGISTRATOR.FORENAME, @@ -85,6 +92,7 @@ public class CamplistGateway { LOGGER.debug(sql.toString()); List list = new ArrayList<>(); for (Record r : sql.fetch()) { + Integer fkCamp = r.get(T_PERSON.FK_CAMP); BookingBean bean = new BookingBean(); bean.setPk(r.get(T_PERSON.PK)); bean.setForename(r.get(T_PERSON.FORENAME)); @@ -126,6 +134,29 @@ public class CamplistGateway { } buf.append(regSurname != null ? regSurname : ""); bean.setSubscriber(buf.toString()); + bean.getDocuments().addAll(getAllDocumentBeans(fkCamp, bean.getCamprole())); + list.add(bean); + } + return list; + } + + private List getAllDocumentBeans(Integer fkCamp, EnumCamprole camprole) { + SelectConditionStep> sql = jooq + // @formatter:off + .select(T_DOCUMENT.NAME, + T_DOCUMENT.PK) + .from(T_CAMPDOCUMENT) + .leftJoin(T_DOCUMENT).on(T_DOCUMENT.PK.eq(T_CAMPDOCUMENT.FK_DOCUMENT)) + .leftJoin(T_DOCUMENTROLE).on(T_DOCUMENTROLE.FK_DOCUMENT.eq(T_DOCUMENT.PK)) + .where(T_CAMPDOCUMENT.FK_CAMP.eq(fkCamp)) + .and(T_DOCUMENTROLE.CAMPROLE.eq(camprole)); + // @formatter:on + LOGGER.debug(sql.toString()); + List list = new ArrayList<>(); + for (Record r : sql.fetch()) { + DocumentBean bean = new DocumentBean(); + bean.setPk(r.get(T_DOCUMENT.PK)); + bean.setName(r.get(T_DOCUMENT.NAME)); list.add(bean); } return list; diff --git a/src/main/java/de/jottyfan/camporganizer/module/camplist/DocumentBean.java b/src/main/java/de/jottyfan/camporganizer/module/camplist/DocumentBean.java new file mode 100644 index 0000000..7b86ae6 --- /dev/null +++ b/src/main/java/de/jottyfan/camporganizer/module/camplist/DocumentBean.java @@ -0,0 +1,37 @@ +package de.jottyfan.camporganizer.module.camplist; + +import java.io.Serializable; + +/** + * + * @author jotty + * + */ +public class DocumentBean implements Serializable { + private static final long serialVersionUID = 1L; + + private Integer pk; + private String name; + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + public Integer getPk() { + return pk; + } + + public void setPk(Integer pk) { + this.pk = pk; + } +} diff --git a/src/main/java/de/jottyfan/camporganizer/module/document/DocumentController.java b/src/main/java/de/jottyfan/camporganizer/module/document/DocumentController.java new file mode 100644 index 0000000..6036b92 --- /dev/null +++ b/src/main/java/de/jottyfan/camporganizer/module/document/DocumentController.java @@ -0,0 +1,44 @@ +package de.jottyfan.camporganizer.module.document; + +import java.util.Base64; + +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * + * @author jotty + * + */ +@RestController +public class DocumentController { + + @Autowired + private DocumentService service; + + @RequestMapping(path = "/document/{id}", method = RequestMethod.GET) + public ResponseEntity getDocument(@PathVariable Integer id, HttpServletResponse response) { + DownloadBean bean = service.getDocument(id); + if (bean != null) { + byte[] decoded = Base64.getDecoder().decode(bean.getContent()); + HttpHeaders header = new HttpHeaders(); + header.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + bean.getName() + "." + bean.getFiletype()); + MediaType contentType = MediaType.parseMediaType("application/octet-stream"); + Integer length = decoded.length; + ByteArrayResource resource = new ByteArrayResource(decoded); + return ResponseEntity.ok().headers(header).contentLength(length).contentType(contentType).body(resource); + } else { + return ResponseEntity.notFound().build(); + } + } +} diff --git a/src/main/java/de/jottyfan/camporganizer/module/document/DocumentRepository.java b/src/main/java/de/jottyfan/camporganizer/module/document/DocumentRepository.java new file mode 100644 index 0000000..aa5fb18 --- /dev/null +++ b/src/main/java/de/jottyfan/camporganizer/module/document/DocumentRepository.java @@ -0,0 +1,52 @@ +package de.jottyfan.camporganizer.module.document; + +import static de.jottyfan.camporganizer.db.jooq.Tables.T_DOCUMENT; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jooq.DSLContext; +import org.jooq.SelectConditionStep; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import de.jottyfan.camporganizer.db.jooq.tables.records.TDocumentRecord; + +/** + * + * @author jotty + * + */ +@Repository +@Transactional(transactionManager = "transactionManager") +public class DocumentRepository { + private static final Logger LOGGER = LogManager.getLogger(DocumentRepository.class); + + @Autowired + private DSLContext jooq; + + /** + * get the document or null + * + * @param id the id of the document + * @return the download bean or null (if not found) + */ + public DownloadBean getDocument(Integer id) { + SelectConditionStep sql = jooq + // @formatter:off + .selectFrom(T_DOCUMENT) + .where(T_DOCUMENT.PK.eq(id)); + // @formatter:on + LOGGER.debug(sql.toString()); + TDocumentRecord r = sql.fetchOne(); + if (r == null) { + return null; + } else { + DownloadBean bean = new DownloadBean(); + bean.setName(r.getName()); + bean.setFiletype(r.getFiletype()); + bean.setContent(r.getDocument()); + return bean; + } + } +} diff --git a/src/main/java/de/jottyfan/camporganizer/module/document/DocumentService.java b/src/main/java/de/jottyfan/camporganizer/module/document/DocumentService.java new file mode 100644 index 0000000..80e1af7 --- /dev/null +++ b/src/main/java/de/jottyfan/camporganizer/module/document/DocumentService.java @@ -0,0 +1,25 @@ +package de.jottyfan.camporganizer.module.document; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * + * @author jotty + * + */ +@Service +public class DocumentService { + + @Autowired + private DocumentRepository repository; + + /** + * get the document of id + * + * @param id the id of the document + */ + public DownloadBean getDocument(Integer id) { + return repository.getDocument(id); + } +} diff --git a/src/main/java/de/jottyfan/camporganizer/module/document/DownloadBean.java b/src/main/java/de/jottyfan/camporganizer/module/document/DownloadBean.java new file mode 100644 index 0000000..946482b --- /dev/null +++ b/src/main/java/de/jottyfan/camporganizer/module/document/DownloadBean.java @@ -0,0 +1,60 @@ +package de.jottyfan.camporganizer.module.document; + +import java.io.Serializable; + +import de.jottyfan.camporganizer.db.jooq.enums.EnumFiletype; + +/** + * + * @author jotty + * + */ +public class DownloadBean implements Serializable { + private static final long serialVersionUID = 1L; + + private String name; + private EnumFiletype filetype; + private String content; + + /** + * @return the filetype + */ + public EnumFiletype getFiletype() { + return filetype; + } + + /** + * @param filetype the filetype to set + */ + public void setFiletype(EnumFiletype filetype) { + this.filetype = filetype; + } + + /** + * @return the content + */ + public String getContent() { + return content; + } + + /** + * @param content the content to set + */ + public void setContent(String content) { + this.content = content; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/resources/templates/dashboard.html b/src/main/resources/templates/dashboard.html index 77c8f7d..66d2003 100644 --- a/src/main/resources/templates/dashboard.html +++ b/src/main/resources/templates/dashboard.html @@ -83,8 +83,8 @@ } - -
+ +

+
+
Dokumente
+
+
+
+
+ +
+
+
+
+
Teilnehmerdaten
@@ -169,8 +181,8 @@
-
Foto-Einverständnis:
- +
Foto-Einverständnis:
+
Kommentar: