ical extension
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
40
src/main/java/de/jottyfan/bico/modules/ical/IcalService.java
Normal file
40
src/main/java/de/jottyfan/bico/modules/ical/IcalService.java
Normal 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);;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user