-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename norms table to dokumente and add RegelungstextMapper
RISDEV-6261
- Loading branch information
1 parent
a4198d8
commit cbb796c
Showing
28 changed files
with
773 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 31 additions & 21 deletions
52
...main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/NormMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,52 @@ | ||
package de.bund.digitalservice.ris.norms.adapter.output.database.mapper; | ||
|
||
import de.bund.digitalservice.ris.norms.adapter.output.database.dto.NormDto; | ||
import de.bund.digitalservice.ris.norms.adapter.output.database.dto.DokumentDto; | ||
import de.bund.digitalservice.ris.norms.domain.entity.Norm; | ||
import de.bund.digitalservice.ris.norms.domain.entity.Regelungstext; | ||
import de.bund.digitalservice.ris.norms.utils.XmlMapper; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nonnull; | ||
|
||
/** Mapper class for converting between {@link NormDto} and {@link Norm}. */ | ||
/** Mapper class for converting between {@link DokumentDto} and {@link Norm}. */ | ||
public class NormMapper { | ||
|
||
// Private constructor to hide the implicit public one and prevent instantiation | ||
private NormMapper() {} | ||
|
||
/** | ||
* Maps a {@link NormDto} to the domain {@link Norm}. | ||
* Maps multiple {@link DokumentDto}s to the domain {@link Norm}. | ||
* | ||
* @param normDto The input {@link NormDto} to be mapped. | ||
* @return A new {@link Norm} mapped from the input {@link NormDto}. | ||
* @param dokumentDtos The input {@link DokumentDto}s to be mapped. | ||
* @return A new {@link Norm} mapped from the input {@link DokumentDto}. | ||
*/ | ||
public static Norm mapToDomain(final NormDto normDto) { | ||
return Norm | ||
.builder() | ||
.regelungstexte(Set.of(new Regelungstext(XmlMapper.toDocument(normDto.getXml())))) | ||
.publishState(normDto.getPublishState()) | ||
.build(); | ||
public static Optional<Norm> mapToDomain(@Nonnull final Collection<DokumentDto> dokumentDtos) { | ||
if (dokumentDtos.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of( | ||
Norm | ||
.builder() | ||
.regelungstexte( | ||
dokumentDtos.stream().map(RegelungstextMapper::mapToDomain).collect(Collectors.toSet()) | ||
) | ||
.publishState(dokumentDtos.stream().findFirst().get().getPublishState()) | ||
.build() | ||
); | ||
} | ||
|
||
/** | ||
* Maps a domain {@link Norm} to {@link NormDto}. | ||
* Maps a domain {@link Norm} to {@link DokumentDto}s for each of the dokuments of the norm. | ||
* | ||
* @param norm The input {@link Norm} to be mapped. | ||
* @return A new {@link NormDto} mapped from the input {@link Norm}. | ||
* @return A new {@link DokumentDto}s mapped from the input {@link Norm}. | ||
*/ | ||
public static NormDto mapToDto(final Norm norm) { | ||
return NormDto | ||
.builder() | ||
.xml(XmlMapper.toString(norm.getDocument())) | ||
.publishState(norm.getPublishState()) | ||
.build(); | ||
public static Set<DokumentDto> mapToDtos(final Norm norm) { | ||
return norm | ||
.getRegelungstexte() | ||
.stream() | ||
.map(regelungstext -> RegelungstextMapper.mapToDto(regelungstext, norm.getPublishState())) | ||
.collect(Collectors.toSet()); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../de/bund/digitalservice/ris/norms/adapter/output/database/mapper/RegelungstextMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package de.bund.digitalservice.ris.norms.adapter.output.database.mapper; | ||
|
||
import de.bund.digitalservice.ris.norms.adapter.output.database.dto.DokumentDto; | ||
import de.bund.digitalservice.ris.norms.domain.entity.Norm; | ||
import de.bund.digitalservice.ris.norms.domain.entity.NormPublishState; | ||
import de.bund.digitalservice.ris.norms.domain.entity.Regelungstext; | ||
import de.bund.digitalservice.ris.norms.utils.XmlMapper; | ||
|
||
/** Mapper class for converting between {@link DokumentDto} and {@link Regelungstext}. */ | ||
public class RegelungstextMapper { | ||
|
||
// Private constructor to hide the implicit public one and prevent instantiation | ||
private RegelungstextMapper() {} | ||
|
||
/** | ||
* Maps a {@link DokumentDto} to the domain {@link Norm}. | ||
* | ||
* @param dokumentDto The input {@link DokumentDto} to be mapped. | ||
* @return A new {@link Regelungstext} mapped from the input {@link DokumentDto}. | ||
*/ | ||
public static Regelungstext mapToDomain(final DokumentDto dokumentDto) { | ||
return new Regelungstext(XmlMapper.toDocument(dokumentDto.getXml())); | ||
} | ||
|
||
/** | ||
* Maps a domain {@link Regelungstext} to {@link DokumentDto}. | ||
* | ||
* @param regelungstext The input {@link Regelungstext} to be mapped. | ||
* @param publishState The publishState of the {@link Norm} associated with the {@link Regelungstext}. For now this is still stored on every dokument. | ||
* @return A new {@link DokumentDto} mapped from the input {@link Regelungstext}. | ||
*/ | ||
public static DokumentDto mapToDto( | ||
final Regelungstext regelungstext, | ||
final NormPublishState publishState | ||
) { | ||
return DokumentDto | ||
.builder() | ||
.xml(XmlMapper.toString(regelungstext.getDocument())) | ||
.publishState(publishState) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.