oparl-service/oparl-server/src/main/java/de/twomartens/oparlservice/control/OParlController.java

136 lines
6.4 KiB
Java

package de.twomartens.oparlservice.control;
import de.twomartens.oparlservice.configs.OParlServiceProperties;
import de.twomartens.oparlservice.entity.Body;
import de.twomartens.oparlservice.entity.LegislativeTerm;
import de.twomartens.oparlservice.entity.System;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.List;
@Slf4j
@RestController
@RequestMapping(path = "/v1.1")
public class OParlController {
private final OParlServiceProperties properties;
OParlController(OParlServiceProperties properties) {
this.properties = properties;
}
@GetMapping("/")
@Operation(summary = "System information", description = "returns information about the OParl system")
public System system() {
log.info("method invoked /v1.1");
return System.builder()
.id(properties.getUrl() + "/v1.1")
.type("https://schema.oparl.org/1.1/System")
.license("https://www.govdata.de/dl-de/by-2-0")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.oparlVersion("https://schema.oparl.org/1.1/")
.name("OParl interface for ALLRIS of Hamburg Eimsbüttel")
.contactEmail("github@2martens.de")
.contactName("Jim Martens")
.website("https://sitzungsdienst-eimsbuettel.hamburg.de/bi/")
.vendor("https://2martens.de")
.product("https://git.2martens.de/2martens/oparl-service")
.body(properties.getUrl() + "/bodies")
.build();
}
@GetMapping("/bodies")
@Operation(summary = "List of available bodies", description = "returns a list of available bodies in this OParl system")
public List<Body> bodies() {
log.info("method invoked /v1.1/bodies");
LegislativeTerm term = LegislativeTerm.builder()
.id(properties.getUrl() + "/v1.1/term/21")
.type("https://schema.oparl.org/1.1/LegislativeTerm")
.body(properties.getUrl() + "/v1.1/body/0")
.name("21. Wahlperiode")
.startDate(LocalDate.parse("2019-05-27"))
.endDate(LocalDate.parse("2024-05-26"))
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.build();
Body eimsbuettel = Body.builder()
.id(properties.getUrl() + "/v1.1/body/0")
.type("https://schema.oparl.org/1.1/Body")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.shortName("Hamburg")
.name("Bezirk Eimsbüttel")
.system(properties.getUrl() + "/v1.1")
.legislativeTerm(List.of(term))
.website("https://www.hamburg.de/eimsbuettel")
.ags("02000000")
.rgs("020000000000")
.equivalent(List.of("http://dbpedia.org/page/Eimsb%C3%BCttel", "http://d-nb.info/1208293575"))
.organization(properties.getUrl() + "/v1.1/organizations/0")
.person(properties.getUrl() + "/v1.1/persons/0")
.meeting(properties.getUrl() + "/v1.1/meetings/0")
.paper(properties.getUrl() + "/v1.1/papers/0")
.agendaItem(properties.getUrl() + "/v1.1/agendaItems/0")
.consultation(properties.getUrl() + "/v1.1/consultations/0")
.file(properties.getUrl() + "/v1.1/files/0")
.locationList(properties.getUrl() + "/v1.1/locations/0")
.legislativeTermList(properties.getUrl() + "/v1.1/terms")
.membership(properties.getUrl() + "/v1.1/memberships/0")
.classification("Bezirk")
.build();
return List.of(eimsbuettel);
}
@GetMapping("/body/{id}")
@Operation(summary = "information about body", description = "returns information about the requested body")
public Body body(
@PathVariable
@Parameter(description = "body ID", example = "0")
String id) {
log.info("method invoked /v1.1/body/{}", id);
LegislativeTerm term = LegislativeTerm.builder()
.id(properties.getUrl() + "/v1.1/term/21")
.type("https://schema.oparl.org/1.1/LegislativeTerm")
.body(properties.getUrl() + "/v1.1/body/0")
.name("21. Wahlperiode")
.startDate(LocalDate.parse("2019-05-27"))
.endDate(LocalDate.parse("2024-05-26"))
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.build();
return Body.builder()
.id(properties.getUrl() + "/v1.1/body/0")
.type("https://schema.oparl.org/1.1/Body")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.shortName("Hamburg")
.name("Bezirk Eimsbüttel")
.system(properties.getUrl() + "/v1.1")
.legislativeTerm(List.of(term))
.website("https://www.hamburg.de/eimsbuettel")
.ags("02000000")
.rgs("020000000000")
.equivalent(List.of("http://dbpedia.org/page/Eimsb%C3%BCttel", "http://d-nb.info/1208293575"))
.organization(properties.getUrl() + "/v1.1/organizations/0")
.person(properties.getUrl() + "/v1.1/persons/0")
.meeting(properties.getUrl() + "/v1.1/meetings/0")
.paper(properties.getUrl() + "/v1.1/papers/0")
.agendaItem(properties.getUrl() + "/v1.1/agendaItems/0")
.consultation(properties.getUrl() + "/v1.1/consultations/0")
.file(properties.getUrl() + "/v1.1/files/0")
.locationList(properties.getUrl() + "/v1.1/locations/0")
.legislativeTermList(properties.getUrl() + "/v1.1/terms")
.membership(properties.getUrl() + "/v1.1/memberships/0")
.classification("Bezirk")
.build();
}
}