automatically-create-ex-partner-relation #35
@ -26,6 +26,8 @@ import jakarta.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.EX_PARTNER;
|
||||
|
||||
@RestController
|
||||
|
||||
public class HsOfficePartnerController implements HsOfficePartnersApi {
|
||||
@ -128,14 +130,23 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var current = partnerRepo.findByUuid(partnerUuid).orElseThrow();
|
||||
final var previousPartnerRel = current.getPartnerRel();
|
||||
|
||||
new HsOfficePartnerEntityPatcher(em, current).apply(body);
|
||||
|
||||
final var saved = partnerRepo.save(current);
|
||||
optionallyCreateExPartnerRelation(saved, previousPartnerRel);
|
||||
|
||||
final var mapped = mapper.map(saved, HsOfficePartnerResource.class);
|
||||
return ResponseEntity.ok(mapped);
|
||||
}
|
||||
|
||||
private void optionallyCreateExPartnerRelation(final HsOfficePartnerEntity saved, final HsOfficeRelationEntity previousPartnerRel) {
|
||||
if (!saved.getPartnerRel().getUuid().equals(previousPartnerRel.getUuid())) {
|
||||
relationRepo.save(previousPartnerRel.toBuilder().uuid(null).type(EX_PARTNER).build());
|
||||
}
|
||||
}
|
||||
|
||||
private HsOfficePartnerEntity createPartnerEntity(final HsOfficePartnerInsertResource body) {
|
||||
final var entityToSave = new HsOfficePartnerEntity();
|
||||
entityToSave.setPartnerNumber(body.getPartnerNumber());
|
||||
|
@ -30,7 +30,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@Table(name = "hs_office_relation_rv")
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@Builder(toBuilder = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@FieldNameConstants
|
||||
|
@ -410,10 +410,10 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
});
|
||||
|
||||
// and an ex-partner-relation got created
|
||||
final var partnerPersonUUid = givenPartner.getPartnerRel().getAnchor().getUuid();
|
||||
assertThat(relationRepo.findRelationRelatedToPersonUuidAndRelationType(partnerPersonUUid, EX_PARTNER))
|
||||
final var anchorpartnerPersonUUid = givenPartner.getPartnerRel().getAnchor().getUuid();
|
||||
assertThat(relationRepo.findRelationRelatedToPersonUuidAndRelationType(anchorpartnerPersonUUid, EX_PARTNER))
|
||||
.map(HsOfficeRelationEntity::toShortString)
|
||||
.contains("xxx");
|
||||
.contains("rel(anchor='LP Hostsharing eG', type='EX_PARTNER', holder='UF Erben Bessler')");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user