Skip to content

Commit

Permalink
Merge pull request #384 from it-at-m/143-implementierung-von-referend…
Browse files Browse the repository at this point in the history
…umvorlagen-laden

143 implementierung von referendumvorlagen laden
  • Loading branch information
MrSebastian authored Jul 26, 2024
2 parents 3025cb1 + bd148c9 commit ebd57c0
Show file tree
Hide file tree
Showing 38 changed files with 1,668 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
id: add authorities basisdaten referendumvorlagen
author: MrSebastian
realm: ${SSO_REALM}
changes:
- addRole:
name: Basisdaten_BUSINESSACTION_GetReferendumvorlagen
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allBasisdatenAuthorities
role: Basisdaten_BUSINESSACTION_GetReferendumvorlagen
clientId: ${SSO_CLIENT_ID}

- addRole:
name: Basisdaten_READ_Referendumvorlagen
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allBasisdatenAuthorities
role: Basisdaten_READ_Referendumvorlagen
clientId: ${SSO_CLIENT_ID}

- addRole:
name: Basisdaten_WRITE_Referendumvorlagen
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allBasisdatenAuthorities
role: Basisdaten_WRITE_Referendumvorlagen
clientId: ${SSO_CLIENT_ID}

- addRole:
name: Basisdaten_DELETE_Referendumvorlagen
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allBasisdatenAuthorities
role: Basisdaten_DELETE_Referendumvorlagen
clientId: ${SSO_CLIENT_ID}

- addRole:
name: Basisdaten_READ_Referendumvorlage
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allBasisdatenAuthorities
role: Basisdaten_READ_Referendumvorlage
clientId: ${SSO_CLIENT_ID}

- addRole:
name: Basisdaten_WRITE_Referendumvorlage
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allBasisdatenAuthorities
role: Basisdaten_WRITE_Referendumvorlage
clientId: ${SSO_CLIENT_ID}

- addRole:
name: Basisdaten_DELETE_Referendumvorlage
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allBasisdatenAuthorities
role: Basisdaten_DELETE_Referendumvorlage
clientId: ${SSO_CLIENT_ID}
1 change: 1 addition & 0 deletions stack/keycloak/migration/keycloak-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ includes:
- path: add-authorities-basisdaten-wahltage.yml
- path: add-authorities-basisdaten-ungueltigewahlscheine.yml
- path: add-authorities-eai-wahlbeteiligung.yml
- path: add-authorities-basisdaten-referendumvorlagen.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package de.muenchen.oss.wahllokalsystem.basisdatenservice.clients;

import de.muenchen.oss.wahllokalsystem.basisdatenservice.configuration.Profiles;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.referendumvorlagen.ReferendumoptionModel;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.referendumvorlagen.ReferendumvorlageModel;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.referendumvorlagen.ReferendumvorlagenClient;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.referendumvorlagen.ReferendumvorlagenModel;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.referendumvorlagen.ReferendumvorlagenReferenceModel;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltag.WahltagModel;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltag.WahltageClient;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlvorschlag.KandidatModel;
Expand All @@ -17,7 +22,7 @@

@Component
@Profile(Profiles.DUMMY_CLIENTS)
public class DummyClientImpl implements WahlvorschlaegeClient, WahltageClient {
public class DummyClientImpl implements WahlvorschlaegeClient, WahltageClient, ReferendumvorlagenClient {

@Override
public WahlvorschlaegeModel getWahlvorschlaege(BezirkUndWahlID bezirkUndWahlID) {
Expand All @@ -38,4 +43,12 @@ public List<WahltagModel> getWahltage(LocalDate tag) {
new WahltagModel("wahltagID3", LocalDate.now().plusMonths(1), "Beschreibung Wahltag 3", "2"),
new WahltagModel("wahltagID2", LocalDate.now().minusMonths(1), "Beschreibung Wahltag 2", "1"));
}

@Override
public ReferendumvorlagenModel getReferendumvorlagen(ReferendumvorlagenReferenceModel referendumvorlagenReferenceModel) {
return new ReferendumvorlagenModel("stimmzettelgebiedID", Set.of(new ReferendumvorlageModel("wahlvorschlagID1", 1L, "kurzname1", "frage1",
Set.of(new ReferendumoptionModel("optionID11", "option11", 1L), new ReferendumoptionModel("optionID12", "option12", 2L))),
new ReferendumvorlageModel("wahlvorschlagID2", 2L, "kurzname2", "frage2",
Set.of(new ReferendumoptionModel("optionID21", "option21", 1L), new ReferendumoptionModel("optionID22", "option22", 2L)))));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.muenchen.oss.wahllokalsystem.basisdatenservice.clients;

import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.ReferendumvorlageDTO;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.ReferendumvorlagenDTO;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.referendumvorlagen.ReferendumvorlageModel;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.referendumvorlagen.ReferendumvorlagenModel;
import org.mapstruct.Mapper;

@Mapper
public interface ReferendumvorlagenClientMapper {
ReferendumvorlagenModel toModel(ReferendumvorlagenDTO referendumvorlagenDTO);

ReferendumvorlageModel toModel(ReferendumvorlageDTO referendumvorlageDTO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import de.muenchen.oss.wahllokalsystem.basisdatenservice.configuration.Profiles;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.client.WahlvorschlagControllerApi;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.ReferendumvorlagenDTO;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.WahlvorschlaegeDTO;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.referendumvorlagen.ReferendumvorlagenClient;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.referendumvorlagen.ReferendumvorlagenModel;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.referendumvorlagen.ReferendumvorlagenReferenceModel;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlvorschlag.WahlvorschlaegeClient;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlvorschlag.WahlvorschlaegeModel;
import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory;
Expand All @@ -17,12 +21,13 @@
@Profile(Profiles.NOT + Profiles.DUMMY_CLIENTS)
@RequiredArgsConstructor
@Slf4j
public class WahlvorschlaegeClientImpl implements WahlvorschlaegeClient {
public class WahlvorschlaegeClientImpl implements WahlvorschlaegeClient, ReferendumvorlagenClient {

private final ExceptionFactory exceptionFactory;

private final WahlvorschlagControllerApi wahlvorschlagControllerApi;
private final WahlvorschlaegeClientMapper wahlvorschlaegeClientMapper;
private final ReferendumvorlagenClientMapper referendumvorlagenClientMapper;

@Override
public WahlvorschlaegeModel getWahlvorschlaege(final BezirkUndWahlID bezirkUndWahlID) {
Expand All @@ -39,4 +44,20 @@ public WahlvorschlaegeModel getWahlvorschlaege(final BezirkUndWahlID bezirkUndWa

return wahlvorschlaegeClientMapper.toModel(wahlvorschlaege);
}

@Override
public ReferendumvorlagenModel getReferendumvorlagen(ReferendumvorlagenReferenceModel referendumvorlagenReferenceModel) {
final ReferendumvorlagenDTO referendumvorlagen;
try {
referendumvorlagen = wahlvorschlagControllerApi.loadReferendumvorlagen(referendumvorlagenReferenceModel.wahlID(),
referendumvorlagenReferenceModel.wahlbezirkID());
} catch (final Exception exception) {
log.info("exception on loadrefendumvorlagen from external", exception);
throw exceptionFactory.createTechnischeWlsException(ExceptionConstants.FAILED_COMMUNICATION_WITH_EAI);
}
if (referendumvorlagen == null) {
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.NULL_FROM_CLIENT);
}
return referendumvorlagenClientMapper.toModel(referendumvorlagen);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.referendumvorlagen;

import jakarta.persistence.Embeddable;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Embeddable
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@EqualsAndHashCode
@ToString(onlyExplicitlyIncluded = true)
public class Referendumoption {

@NotNull
@ToString.Include
private String id;

@NotNull
@ToString.Include
private String name;

@ToString.Include
private Long position;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.referendumvorlagen;

import static java.sql.Types.VARCHAR;

import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import java.util.Set;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.annotations.UuidGenerator;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@EqualsAndHashCode
@ToString(onlyExplicitlyIncluded = true)
public class Referendumvorlage {

@Id
@GeneratedValue(generator = "uuid")
@UuidGenerator
@JdbcTypeCode(VARCHAR)
@ToString.Include
private UUID id;

@ManyToOne
@JoinColumn(name = "referendumvorlagenID")
@EqualsAndHashCode.Exclude
private Referendumvorlagen referendumvorlagen;

@NotNull
@ToString.Include
private String wahlvorschlagID;

@NotNull
@ToString.Include
private Long ordnungszahl;

@NotNull
@ToString.Include
private String kurzname;

@NotNull
@ToString.Include
private String frage;

@ElementCollection
@CollectionTable(name = "referendumoption", joinColumns = @JoinColumn(name = "referendumvorlageID"))
@NotNull
private Set<Referendumoption> referendumoptionen;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.referendumvorlagen;

import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.repository.CrudRepository;
import org.springframework.security.access.prepost.PreAuthorize;

@PreAuthorize("hasAuthority('Basisdaten_READ_Referendumvorlage')")
public interface ReferendumvorlageRepository extends CrudRepository<Referendumvorlage, UUID> {

String CACHE = "WLSREFERENDUMVORSCHLAEGE_CACHE";

@Override
List<Referendumvorlage> findAll();

@Override
@Cacheable(value = CACHE, key = "#p0")
Optional<Referendumvorlage> findById(UUID referendumvorlageId);

@Override
@CachePut(value = CACHE, key = "#p0.bezirkUndWahlID")
@PreAuthorize("hasAuthority('Basisdaten_WRITE_Referendumvorlage')")
<S extends Referendumvorlage> S save(S entity);

@Override
@CacheEvict(value = CACHE, allEntries = true)
@PreAuthorize("hasAuthority('Basisdaten_WRITE_Referendumvorlage')")
<S extends Referendumvorlage> Iterable<S> saveAll(Iterable<S> entities);

@Override
@CacheEvict(value = CACHE, key = "#p0")
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Referendumvorlage')")
void deleteById(UUID referendumvorlageId);

@Override
@CacheEvict(value = CACHE, key = "#p0.bezirkUndWahlID")
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Referendumvorlage')")
void delete(Referendumvorlage entity);

@Override
@CacheEvict(value = CACHE, allEntries = true)
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Referendumvorlage')")
void deleteAll(Iterable<? extends Referendumvorlage> entities);

@Override
@CacheEvict(value = CACHE, allEntries = true)
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Referendumvorlage')")
void deleteAll();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.referendumvorlagen;

import static java.sql.Types.VARCHAR;

import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.UuidGenerator;

@Entity
@Getter
@Setter
@EqualsAndHashCode
@ToString(onlyExplicitlyIncluded = true)
@NoArgsConstructor
@AllArgsConstructor
public class Referendumvorlagen {

@Id
@GeneratedValue(generator = "uuid")
@UuidGenerator
@JdbcTypeCode(VARCHAR)
@ToString.Include
private UUID id;

@NaturalId
@Embedded
private BezirkUndWahlID bezirkUndWahlID;

@NotNull
private String stimmzettelgebietID;

@OneToMany(mappedBy = "referendumvorlagen", orphanRemoval = true)
@NotNull
private Set<Referendumvorlage> referendumvorlagen = new HashSet<>();

public void addReferendumvorlage(Referendumvorlage referendumvorlage) {
referendumvorlage.setReferendumvorlagen(this);
referendumvorlagen.add(referendumvorlage);
}
}
Loading

0 comments on commit ebd57c0

Please sign in to comment.