Compare commits

..

No commits in common. "f8e9d770575797b180cfefd98ba13e99ae80695d" and "ec1deb890360085f2c540bc1acfed7375e29404c" have entirely different histories.

4 changed files with 17 additions and 65 deletions

View File

@ -26,7 +26,6 @@ import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.persistence.Version;
import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Pattern;
import java.io.IOException; import java.io.IOException;
import java.util.UUID; import java.util.UUID;

View File

@ -26,8 +26,6 @@ import jakarta.persistence.PersistenceContext;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.EX_PARTNER;
@RestController @RestController
public class HsOfficePartnerController implements HsOfficePartnersApi { public class HsOfficePartnerController implements HsOfficePartnersApi {
@ -130,23 +128,14 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var current = partnerRepo.findByUuid(partnerUuid).orElseThrow(); final var current = partnerRepo.findByUuid(partnerUuid).orElseThrow();
final var previousPartnerRel = current.getPartnerRel();
new HsOfficePartnerEntityPatcher(em, current).apply(body); new HsOfficePartnerEntityPatcher(em, current).apply(body);
final var saved = partnerRepo.save(current); final var saved = partnerRepo.save(current);
optionallyCreateExPartnerRelation(saved, previousPartnerRel);
final var mapped = mapper.map(saved, HsOfficePartnerResource.class); final var mapped = mapper.map(saved, HsOfficePartnerResource.class);
return ResponseEntity.ok(mapped); 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) { private HsOfficePartnerEntity createPartnerEntity(final HsOfficePartnerInsertResource body) {
final var entityToSave = new HsOfficePartnerEntity(); final var entityToSave = new HsOfficePartnerEntity();
entityToSave.setPartnerNumber(body.getPartnerNumber()); entityToSave.setPartnerNumber(body.getPartnerNumber());

View File

@ -30,7 +30,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@Table(name = "hs_office_relation_rv") @Table(name = "hs_office_relation_rv")
@Getter @Getter
@Setter @Setter
@Builder(toBuilder = true) @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@FieldNameConstants @FieldNameConstants

View File

@ -21,7 +21,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.UUID; import java.util.UUID;
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.EX_PARTNER;
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid; import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
import static net.hostsharing.test.JsonMatcher.lenientlyEquals; import static net.hostsharing.test.JsonMatcher.lenientlyEquals;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -42,7 +41,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
HsOfficePartnerRepository partnerRepo; HsOfficePartnerRepository partnerRepo;
@Autowired @Autowired
HsOfficeRelationRepository relationRepo; HsOfficeRelationRepository relationRepository;
@Autowired @Autowired
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@ -377,45 +376,6 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
}); });
} }
@Test
void patchingThePartnerRelCreatesExPartnerRel() {
context.define("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler(20011);
final var givenPartnerRel = givenSomeTemporaryPartnerRel("Third OHG", "third contact");
RestAssured // @formatter:off
.given()
.header("current-user", "superuser-alex@hostsharing.net")
.contentType(ContentType.JSON)
.body("""
{
"partnerRelUuid": "%s"
}
""".formatted(givenPartnerRel.getUuid()))
.port(port)
.when()
.patch("http://localhost/api/hs/office/partners/" + givenPartner.getUuid())
.then().log().body()
.assertThat().statusCode(200);
// @formatter:on
// then the partner got actually updated
context.define("superuser-alex@hostsharing.net");
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent().get()
.matches(partner -> {
assertThat(partner.getPartnerRel().getHolder().getTradeName()).isEqualTo("Third OHG");
assertThat(partner.getPartnerRel().getContact().getLabel()).isEqualTo("third contact");
return true;
});
// and an ex-partner-relation got created
final var anchorpartnerPersonUUid = givenPartner.getPartnerRel().getAnchor().getUuid();
assertThat(relationRepo.findRelationRelatedToPersonUuidAndRelationType(anchorpartnerPersonUUid, EX_PARTNER))
.map(HsOfficeRelationEntity::toShortString)
.contains("rel(anchor='LP Hostsharing eG', type='EX_PARTNER', holder='UF Erben Bessler')");
}
@Test @Test
void globalAdmin_withoutAssumedRole_canPatchPartialPropertiesOfArbitraryPartner() { void globalAdmin_withoutAssumedRole_canPatchPartialPropertiesOfArbitraryPartner() {
@ -442,19 +402,23 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.statusCode(200) .statusCode(200)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body("uuid", isUuidValid()) .body("uuid", isUuidValid())
.body("details.birthName", is("Maja Schmidt")) .body("details.birthName", is("Maja Schmidt"));
.body("partnerRel.contact.label", is(givenPartner.getPartnerRel().getContact().getLabel())); // TODO: assert partnerRel
// .body("contact.label", is(givenPartner.getContact().getLabel()))
// .body("person.tradeName", is(givenPartner.getPerson().getTradeName()));
// @formatter:on // @formatter:on
// finally, the partner details and only the partner details are actually updated // finally, the partner is actually updated
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent().get() assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent().get()
.matches(partner -> { .matches(person -> {
assertThat(partner.getPartnerRel().getContact().getLabel()).isEqualTo(givenPartner.getPartnerRel().getContact().getLabel()); // TODO: assert partnerRel
assertThat(partner.getDetails().getRegistrationOffice()).isEqualTo("Temp Registergericht Leer"); // assertThat(person.getPerson().getTradeName()).isEqualTo(givenPartner.getPerson().getTradeName());
assertThat(partner.getDetails().getRegistrationNumber()).isEqualTo("333333"); // assertThat(person.getContact().getLabel()).isEqualTo(givenPartner.getContact().getLabel());
assertThat(partner.getDetails().getBirthName()).isEqualTo("Maja Schmidt"); assertThat(person.getDetails().getRegistrationOffice()).isEqualTo("Temp Registergericht Leer");
assertThat(partner.getDetails().getBirthday()).isEqualTo("1938-04-08"); assertThat(person.getDetails().getRegistrationNumber()).isEqualTo("333333");
assertThat(partner.getDetails().getDateOfDeath()).isEqualTo("2022-01-12"); assertThat(person.getDetails().getBirthName()).isEqualTo("Maja Schmidt");
assertThat(person.getDetails().getBirthday()).isEqualTo("1938-04-08");
assertThat(person.getDetails().getDateOfDeath()).isEqualTo("2022-01-12");
return true; return true;
}); });
} }
@ -482,7 +446,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
// then the given partner is gone // then the given partner is gone
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isEmpty(); assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isEmpty();
assertThat(relationRepo.findByUuid(givenPartner.getPartnerRel().getUuid())).isEmpty(); assertThat(relationRepository.findByUuid(givenPartner.getPartnerRel().getUuid())).isEmpty();
} }
@Test @Test