generated from 2martens/template-service
Extracted retrieval into service
This commit is contained in:
parent
21f04fa6e2
commit
c960f40ff3
|
@ -2,8 +2,9 @@ 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.Organization;
|
||||
import de.twomartens.oparlservice.entity.System;
|
||||
import de.twomartens.oparlservice.service.OParlService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -12,81 +13,31 @@ 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.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping(path = "/v1.1")
|
||||
public class OParlController {
|
||||
private final OParlServiceProperties properties;
|
||||
private final OParlService service;
|
||||
|
||||
OParlController(OParlServiceProperties properties) {
|
||||
this.properties = properties;
|
||||
OParlController(OParlService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@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();
|
||||
return service.getSystem();
|
||||
}
|
||||
|
||||
@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);
|
||||
return this.service.getBodies();
|
||||
}
|
||||
|
||||
@GetMapping("/body/{id}")
|
||||
|
@ -94,42 +45,18 @@ public class OParlController {
|
|||
public Body body(
|
||||
@PathVariable
|
||||
@Parameter(description = "body ID", example = "0")
|
||||
String id) {
|
||||
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();
|
||||
return service.getBody(id);
|
||||
}
|
||||
|
||||
@GetMapping("/body/{id}/organizations")
|
||||
@Operation(summary = "List of all organizations in body", description = "returns a list of all organizations in requested body")
|
||||
public List<Organization> organizations(
|
||||
@PathVariable
|
||||
@Parameter(description = "body ID", example = "0")
|
||||
String id) {
|
||||
log.info("invoked method /v1.1/body/{}/organizations", id);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package de.twomartens.oparlservice.service;
|
||||
|
||||
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 org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class OParlService {
|
||||
|
||||
private OParlServiceProperties properties;
|
||||
private final Body exampleBody;
|
||||
private final LegislativeTerm exampleTerm;
|
||||
private final System system;
|
||||
|
||||
public OParlService(OParlServiceProperties properties) {
|
||||
this.properties = properties;
|
||||
|
||||
this.exampleTerm = 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();
|
||||
this.exampleBody = 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(exampleTerm))
|
||||
.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();
|
||||
this.system = 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();
|
||||
}
|
||||
|
||||
public List<Body> getBodies() {
|
||||
return List.of(exampleBody);
|
||||
}
|
||||
|
||||
public Body getBody(String id) {
|
||||
return exampleBody;
|
||||
}
|
||||
|
||||
public System getSystem() {
|
||||
return system;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue