ical extension

This commit is contained in:
Jottyfan
2024-09-02 21:29:07 +02:00
parent d28f6b45fc
commit 8d5a493bf7
5 changed files with 107 additions and 1 deletions

View File

@ -8,7 +8,7 @@ plugins {
} }
group = 'de.jottyfan.bico' group = 'de.jottyfan.bico'
version = '0.1.2' version = '0.1.3'
description = """BibleClassOrganizer""" description = """BibleClassOrganizer"""
@ -49,6 +49,8 @@ war {
dependencies { dependencies {
implementation 'de.jottyfan:bicolib:4' implementation 'de.jottyfan:bicolib:4'
implementation 'org.mnode.ical4j:ical4j:4.0.3'
implementation 'org.springframework.boot:spring-boot-starter-jooq' implementation 'org.springframework.boot:spring-boot-starter-jooq'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

View File

@ -0,0 +1,30 @@
package de.jottyfan.bico.modules.ical;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import de.jottyfan.bico.modules.CommonController;
import jakarta.servlet.http.HttpServletResponse;
/**
*
* @author jotty
*
*/
@Controller
public class IcalController extends CommonController{
@Autowired
private IcalService service;
@GetMapping("/ical")
public void getIcalExport(HttpServletResponse response) throws Exception {
response.setHeader("Content-Disposition", "attachment; filename=bico.ical");
response.setContentType("application/octet-stream");
response.setHeader("Content-Transfer-Encoding", "binary");
response.setHeader("Accept-Ranges", "bytes");
service.createCalendar(response.getOutputStream());
response.flushBuffer();
}
}

View File

@ -0,0 +1,31 @@
package de.jottyfan.bico.modules.ical;
import static de.jottyfan.bico.db.Tables.V_CALENDAR;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jooq.DSLContext;
import org.jooq.SelectWhereStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.db.tables.records.VCalendarRecord;
/**
*
* @author jotty
*
*/
@Repository
public class IcalRepository {
private static final Logger LOGGER = LogManager.getLogger(IcalRepository.class);
@Autowired
private DSLContext jooq;
public VCalendarRecord[] getAllDates() {
SelectWhereStep<VCalendarRecord> sql = jooq.selectFrom(V_CALENDAR);
LOGGER.trace(sql);
return sql.fetchArray();
}
}

View File

@ -0,0 +1,40 @@
package de.jottyfan.bico.modules.ical;
import java.io.IOException;
import java.io.OutputStream;
import java.time.LocalDateTime;
import java.time.LocalTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.bico.db.tables.records.VCalendarRecord;
import net.fortuna.ical4j.data.CalendarOutputter;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.component.VEvent;
import net.fortuna.ical4j.validate.ValidationException;
/**
*
* @author jotty
*
*/
@Service
public class IcalService {
@Autowired
private IcalRepository repository;
public void createCalendar(OutputStream stream) throws ValidationException, IOException {
Calendar calendar = new Calendar();
CalendarOutputter out = new CalendarOutputter();
for (VCalendarRecord record : repository.getAllDates()) {
String summary = record.getFullname();
LocalDateTime startEvent = LocalDateTime.of(record.getSlotDay(), LocalTime.of(10, 30));
LocalDateTime endEvent = LocalDateTime.of(record.getSlotDay(), LocalTime.of(12, 0));
VEvent event = new VEvent(startEvent, endEvent, summary);
calendar.add(event);
}
out.output(calendar, stream);;
}
}

View File

@ -29,6 +29,9 @@
</ul> </ul>
<ul layout:fragment="header"></ul> <ul layout:fragment="header"></ul>
<ul class="nav navbar-nav ms-auto"> <ul class="nav navbar-nav ms-auto">
<li class="nav-item">
<a th:href="@{/ical}" class="btn btn-outline-secondary"><i class="bi bi-calendar-week"></i></a>
</li>
<li class="nav-item"> <li class="nav-item">
<a href="https://git.jottyfan.de/church/BiCO" class="btn btn-outline-secondary" target="_blank" th:text="${'v' + @manifestBean.getVersion()}"></a> <a href="https://git.jottyfan.de/church/BiCO" class="btn btn-outline-secondary" target="_blank" th:text="${'v' + @manifestBean.getVersion()}"></a>
</li> </li>