Compare commits

..

No commits in common. "cdd35ef4b8683506f30db26d77dc06471303d516" and "e4e1216a854c179bc072bdcf1d2a79fca700ff52" have entirely different histories.

52 changed files with 264 additions and 602 deletions

View File

@ -1,36 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ImportHostingAssets" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="HSADMINNG_MIGRATION_DATA_PATH" value="migration-prod" />
<entry key="HSADMINNG_POSTGRES_ADMIN_USERNAME" value="admin" />
<entry key="HSADMINNG_POSTGRES_RESTRICTED_USERNAME" value="restricted" />
</map>
</option>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value=":importHostingAssets" />
<option value="--tests" />
<option value="&quot;net.hostsharing.hsadminng.hs.migration.ImportHostingAssets&quot;" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<EXTENSION ID="com.intellij.execution.ExternalSystemRunConfigurationJavaExtension">
<extension name="coverage" sample_coverage="false" />
</EXTENSION>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>true</RunAsTest>
<method v="2" />
</configuration>
</component>

View File

@ -1,36 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ImportOfficeData" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="HSADMINNG_MIGRATION_DATA_PATH" value="migration" />
<entry key="HSADMINNG_POSTGRES_ADMIN_USERNAME" value="admin" />
<entry key="HSADMINNG_POSTGRES_RESTRICTED_USERNAME" value="restricted" />
</map>
</option>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value=":importOfficeData" />
<option value="--tests" />
<option value="&quot;net.hostsharing.hsadminng.hs.migration.ImportOfficeData&quot;" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<EXTENSION ID="com.intellij.execution.ExternalSystemRunConfigurationJavaExtension">
<extension name="coverage" sample_coverage="false" />
</EXTENSION>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>true</RunAsTest>
<method v="2" />
</configuration>
</component>

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
@ -36,7 +36,7 @@ public interface HsHostingAsset extends Stringifyable, RbacObject<HsHostingAsset
String getIdentifier(); String getIdentifier();
HsBookingItemEntity getBookingItem(); HsBookingItemEntity getBookingItem();
HsHostingAsset getAssignedToAsset(); HsHostingAsset getAssignedToAsset();
HsOfficeContactBareEntity getAlarmContact(); HsOfficeContactEntity getAlarmContact();
List<? extends HsHostingAsset> getSubHostingAssets(); List<? extends HsHostingAsset> getSubHostingAssets();
String getCaption(); String getCaption();
Map<String, Object> getConfig(); Map<String, Object> getConfig();

View File

@ -8,8 +8,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
@ -91,7 +90,7 @@ public class HsHostingAssetEntity implements HsHostingAsset {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "alarmcontactuuid") @JoinColumn(name = "alarmcontactuuid")
private HsOfficeContactBareEntity alarmContact; private HsOfficeContactEntity alarmContact;
@OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY)
@JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid") @JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid")
@ -161,7 +160,7 @@ public class HsHostingAssetEntity implements HsHostingAsset {
directlyFetchedByDependsOnColumn(), directlyFetchedByDependsOnColumn(),
NULLABLE) NULLABLE)
.importEntityAlias("alarmContact", HsOfficeContactRbacEntity.class, usingDefaultCase(), .importEntityAlias("alarmContact", HsOfficeContactEntity.class, usingDefaultCase(),
dependsOnColumn("alarmContactUuid"), dependsOnColumn("alarmContactUuid"),
directlyFetchedByDependsOnColumn(), directlyFetchedByDependsOnColumn(),
NULLABLE) NULLABLE)

View File

@ -1,7 +1,7 @@
package net.hostsharing.hsadminng.hs.hosting.asset; package net.hostsharing.hsadminng.hs.hosting.asset;
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.mapper.EntityPatcher; import net.hostsharing.hsadminng.mapper.EntityPatcher;
import net.hostsharing.hsadminng.mapper.KeyValueMap; import net.hostsharing.hsadminng.mapper.KeyValueMap;
import net.hostsharing.hsadminng.mapper.OptionalFromJson; import net.hostsharing.hsadminng.mapper.OptionalFromJson;
@ -29,7 +29,7 @@ public class HsHostingAssetEntityPatcher implements EntityPatcher<HsHostingAsset
// HOWTO: patch nullable JSON resource uuid to an ntity reference // HOWTO: patch nullable JSON resource uuid to an ntity reference
.ifPresent(newValue -> entity.setAlarmContact( .ifPresent(newValue -> entity.setAlarmContact(
Optional.ofNullable(newValue) Optional.ofNullable(newValue)
.map(uuid -> em.getReference(HsOfficeContactBareEntity.class, newValue)) .map(uuid -> em.getReference(HsOfficeContactEntity.class, newValue))
.orElse(null))); .orElse(null)));
} }
} }

View File

@ -5,7 +5,7 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry; import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.validation.HsEntityValidator; import net.hostsharing.hsadminng.hs.validation.HsEntityValidator;
import net.hostsharing.hsadminng.hs.validation.ValidatableProperty; import net.hostsharing.hsadminng.hs.validation.ValidatableProperty;
@ -213,7 +213,7 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator<HsHo
} }
} }
static class AlarmContact extends ReferenceValidator<HsOfficeContactBareEntity, Enum<?>> { static class AlarmContact extends ReferenceValidator<HsOfficeContactEntity, Enum<?>> {
AlarmContact(final HsHostingAssetType.RelationPolicy policy) { AlarmContact(final HsHostingAssetType.RelationPolicy policy) {
super(policy, HsHostingAsset::getAlarmContact); super(policy, HsHostingAsset::getAlarmContact);

View File

@ -1,23 +0,0 @@
package net.hostsharing.hsadminng.hs.office.contact;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;
import net.hostsharing.hsadminng.errors.DisplayName;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
@Entity
@Table(name = "hs_office_contact")
@Getter
@Setter
@NoArgsConstructor
@SuperBuilder(toBuilder = true)
@FieldNameConstants
@DisplayName("BareContact")
public class HsOfficeContactBareEntity extends HsOfficeContact {
}

View File

@ -29,7 +29,7 @@ public class HsOfficeContactController implements HsOfficeContactsApi {
private Mapper mapper; private Mapper mapper;
@Autowired @Autowired
private HsOfficeContactRbacRepository contactRepo; private HsOfficeContactRepository contactRepo;
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
@ -54,7 +54,7 @@ public class HsOfficeContactController implements HsOfficeContactsApi {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var entityToSave = mapper.map(body, HsOfficeContactRbacEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER); final var entityToSave = mapper.map(body, HsOfficeContactEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER);
final var saved = contactRepo.save(entityToSave); final var saved = contactRepo.save(entityToSave);
@ -119,7 +119,7 @@ public class HsOfficeContactController implements HsOfficeContactsApi {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final BiConsumer<HsOfficeContactInsertResource, HsOfficeContactRbacEntity> RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { final BiConsumer<HsOfficeContactInsertResource, HsOfficeContactEntity> RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
entity.putEmailAddresses(from(resource.getEmailAddresses())); entity.putEmailAddresses(from(resource.getEmailAddresses()));
entity.putPhoneNumbers(from(resource.getPhoneNumbers())); entity.putPhoneNumbers(from(resource.getPhoneNumbers()));
}; };

View File

@ -1,47 +1,45 @@
package net.hostsharing.hsadminng.hs.office.contact; package net.hostsharing.hsadminng.hs.office.contact;
import io.hypersistence.utils.hibernate.type.json.JsonType; import io.hypersistence.utils.hibernate.type.json.JsonType;
import lombok.AccessLevel; import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.FieldNameConstants; import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
import jakarta.persistence.Column; import jakarta.persistence.*;
import jakarta.persistence.GeneratedValue; import java.io.IOException;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Transient;
import jakarta.persistence.Version;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.GLOBAL;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.*;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.*;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor;
import static net.hostsharing.hsadminng.stringify.Stringify.stringify; import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@MappedSuperclass @Entity
@Table(name = "hs_office_contact_rv")
@Getter @Getter
@Setter @Setter
@Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@SuperBuilder(toBuilder = true)
@FieldNameConstants @FieldNameConstants
@DisplayName("Contact") @DisplayName("Contact")
public class HsOfficeContact implements Stringifyable, RbacObject<HsOfficeContact> { public class HsOfficeContactEntity implements Stringifyable, RbacObject<HsOfficeContactEntity> {
private static Stringify<HsOfficeContact> toString = stringify(HsOfficeContact.class, "contact") private static Stringify<HsOfficeContactEntity> toString = stringify(HsOfficeContactEntity.class, "contact")
.withProp(Fields.caption, HsOfficeContact::getCaption) .withProp(Fields.caption, HsOfficeContactEntity::getCaption)
.withProp(Fields.emailAddresses, HsOfficeContact::getEmailAddresses); .withProp(Fields.emailAddresses, HsOfficeContactEntity::getEmailAddresses);
@Id @Id
@GeneratedValue(generator = "UUID") @GeneratedValue(generator = "UUID")
@ -76,10 +74,7 @@ public class HsOfficeContact implements Stringifyable, RbacObject<HsOfficeContac
private PatchableMapWrapper<String> phoneNumbersWrapper; private PatchableMapWrapper<String> phoneNumbersWrapper;
public PatchableMapWrapper<String> getEmailAddresses() { public PatchableMapWrapper<String> getEmailAddresses() {
return PatchableMapWrapper.of( return PatchableMapWrapper.of(emailAddressesWrapper, (newWrapper) -> {emailAddressesWrapper = newWrapper; }, emailAddresses );
emailAddressesWrapper,
(newWrapper) -> {emailAddressesWrapper = newWrapper;},
emailAddresses);
} }
public void putEmailAddresses(Map<String, String> newEmailAddresses) { public void putEmailAddresses(Map<String, String> newEmailAddresses) {
@ -87,7 +82,7 @@ public class HsOfficeContact implements Stringifyable, RbacObject<HsOfficeContac
} }
public PatchableMapWrapper<String> getPhoneNumbers() { public PatchableMapWrapper<String> getPhoneNumbers() {
return PatchableMapWrapper.of(phoneNumbersWrapper, (newWrapper) -> {phoneNumbersWrapper = newWrapper;}, phoneNumbers); return PatchableMapWrapper.of(phoneNumbersWrapper, (newWrapper) -> {phoneNumbersWrapper = newWrapper; }, phoneNumbers );
} }
public void putPhoneNumbers(Map<String, String> newPhoneNumbers) { public void putPhoneNumbers(Map<String, String> newPhoneNumbers) {
@ -103,4 +98,26 @@ public class HsOfficeContact implements Stringifyable, RbacObject<HsOfficeContac
public String toShortString() { public String toShortString() {
return caption; return caption;
} }
public static RbacView rbac() {
return rbacViewFor("contact", HsOfficeContactEntity.class)
.withIdentityView(SQL.projection("caption"))
.withUpdatableColumns("caption", "postalAddress", "emailAddresses", "phoneNumbers")
.createRole(OWNER, (with) -> {
with.owningUser(CREATOR);
with.incomingSuperRole(GLOBAL, ADMIN);
with.permission(DELETE);
})
.createSubRole(ADMIN, (with) -> {
with.permission(UPDATE);
})
.createSubRole(REFERRER, (with) -> {
with.permission(SELECT);
})
.toRole(GLOBAL, GUEST).grantPermission(INSERT);
}
public static void main(String[] args) throws IOException {
rbac().generateWithBaseFileName("5-hs-office/501-contact/5013-hs-office-contact-rbac");
}
} }

View File

@ -9,9 +9,9 @@ import java.util.Optional;
class HsOfficeContactEntityPatcher implements EntityPatcher<HsOfficeContactPatchResource> { class HsOfficeContactEntityPatcher implements EntityPatcher<HsOfficeContactPatchResource> {
private final HsOfficeContactRbacEntity entity; private final HsOfficeContactEntity entity;
HsOfficeContactEntityPatcher(final HsOfficeContactRbacEntity entity) { HsOfficeContactEntityPatcher(final HsOfficeContactEntity entity) {
this.entity = entity; this.entity = entity;
} }

View File

@ -1,51 +0,0 @@
package net.hostsharing.hsadminng.hs.office.contact;
import lombok.*;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;
import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
import jakarta.persistence.*;
import java.io.IOException;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.GLOBAL;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.*;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.*;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor;
@Entity
@Table(name = "hs_office_contact_rv")
@Getter
@Setter
@NoArgsConstructor
@SuperBuilder(toBuilder = true)
@FieldNameConstants
@DisplayName("RbacContact")
public class HsOfficeContactRbacEntity extends HsOfficeContact {
public static RbacView rbac() {
return rbacViewFor("contact", HsOfficeContactRbacEntity.class)
.withIdentityView(SQL.projection("caption"))
.withUpdatableColumns("caption", "postalAddress", "emailAddresses", "phoneNumbers")
.createRole(OWNER, (with) -> {
with.owningUser(CREATOR);
with.incomingSuperRole(GLOBAL, ADMIN);
with.permission(DELETE);
})
.createSubRole(ADMIN, (with) -> {
with.permission(UPDATE);
})
.createSubRole(REFERRER, (with) -> {
with.permission(SELECT);
})
.toRole(GLOBAL, GUEST).grantPermission(INSERT);
}
public static void main(String[] args) throws IOException {
rbac().generateWithBaseFileName("5-hs-office/501-contact/5013-hs-office-contact-rbac");
}
}

View File

@ -1,26 +0,0 @@
package net.hostsharing.hsadminng.hs.office.contact;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface HsOfficeContactRbacRepository extends Repository<HsOfficeContactRbacEntity, UUID> {
Optional<HsOfficeContactRbacEntity> findByUuid(UUID id);
@Query("""
SELECT c FROM HsOfficeContactRbacEntity c
WHERE :caption is null
OR c.caption like concat(cast(:caption as text), '%')
""")
List<HsOfficeContactRbacEntity> findContactByOptionalCaptionLike(String caption);
HsOfficeContactRbacEntity save(final HsOfficeContactRbacEntity entity);
int deleteByUuid(final UUID uuid);
long count();
}

View File

@ -7,18 +7,18 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public interface HsOfficeContactBareRepository extends Repository<HsOfficeContactBareEntity, UUID> { public interface HsOfficeContactRepository extends Repository<HsOfficeContactEntity, UUID> {
Optional<HsOfficeContactBareEntity> findByUuid(UUID id); Optional<HsOfficeContactEntity> findByUuid(UUID id);
@Query(""" @Query("""
SELECT c FROM HsOfficeContactBareEntity c SELECT c FROM HsOfficeContactEntity c
WHERE :caption is null WHERE :caption is null
OR c.caption like concat(cast(:caption as text), '%') OR c.caption like concat(cast(:caption as text), '%')
""") """)
List<HsOfficeContactBareEntity> findContactByOptionalCaptionLike(String caption); List<HsOfficeContactEntity> findContactByOptionalCaptionLike(String caption);
HsOfficeContactBareEntity save(final HsOfficeContactBareEntity entity); HsOfficeContactEntity save(final HsOfficeContactEntity entity);
int deleteByUuid(final UUID uuid); int deleteByUuid(final UUID uuid);

View File

@ -33,7 +33,7 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
JOIN HsOfficePersonEntity person JOIN HsOfficePersonEntity person
ON person.uuid = partner.partnerRel.holder.uuid ON person.uuid = partner.partnerRel.holder.uuid
OR person.uuid = debitor.debitorRel.holder.uuid OR person.uuid = debitor.debitorRel.holder.uuid
JOIN HsOfficeContactBareEntity contact JOIN HsOfficeContactEntity contact
ON contact.uuid = debitor.debitorRel.contact.uuid ON contact.uuid = debitor.debitorRel.contact.uuid
OR contact.uuid = partner.partnerRel.contact.uuid OR contact.uuid = partner.partnerRel.contact.uuid
WHERE :name is null WHERE :name is null

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.errors.ReferenceNotFoundException; import net.hostsharing.hsadminng.errors.ReferenceNotFoundException;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficePartnersApi; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficePartnersApi;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerInsertResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerInsertResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource;
@ -10,7 +10,6 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartne
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerRelInsertResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerRelInsertResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.mapper.Mapper; import net.hostsharing.hsadminng.mapper.Mapper;
@ -157,11 +156,11 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
} }
private HsOfficeRelationEntity persistPartnerRel(final HsOfficePartnerRelInsertResource resource) { private HsOfficeRelationEntity persistPartnerRel(final HsOfficePartnerRelInsertResource resource) {
final var entity = new HsOfficeRelationRbacEntity(); final var entity = new HsOfficeRelationEntity();
entity.setType(HsOfficeRelationType.PARTNER); entity.setType(HsOfficeRelationType.PARTNER);
entity.setAnchor(ref(HsOfficePersonEntity.class, resource.getAnchorUuid())); entity.setAnchor(ref(HsOfficePersonEntity.class, resource.getAnchorUuid()));
entity.setHolder(ref(HsOfficePersonEntity.class, resource.getHolderUuid())); entity.setHolder(ref(HsOfficePersonEntity.class, resource.getHolderUuid()));
entity.setContact(ref(HsOfficeContactBareEntity.class, resource.getContactUuid())); entity.setContact(ref(HsOfficeContactEntity.class, resource.getContactUuid()));
em.persist(entity); em.persist(entity);
return entity; return entity;
} }

View File

@ -6,7 +6,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContact; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
@ -52,7 +52,7 @@ public class HsOfficePartnerEntity implements Stringifyable, RbacObject<HsOffice
.orElse(null)) .orElse(null))
.withProp(p -> ofNullable(p.getPartnerRel()) .withProp(p -> ofNullable(p.getPartnerRel())
.map(HsOfficeRelationEntity::getContact) .map(HsOfficeRelationEntity::getContact)
.map(HsOfficeContact::toShortString) .map(HsOfficeContactEntity::toShortString)
.orElse(null)) .orElse(null))
.quotedValues(false); .quotedValues(false);

View File

@ -16,7 +16,7 @@ public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEnt
@Query(""" @Query("""
SELECT partner FROM HsOfficePartnerEntity partner SELECT partner FROM HsOfficePartnerEntity partner
JOIN HsOfficeRelationEntity rel ON rel.uuid = partner.partnerRel.uuid JOIN HsOfficeRelationEntity rel ON rel.uuid = partner.partnerRel.uuid
JOIN HsOfficeContactBareEntity contact ON contact.uuid = rel.contact.uuid JOIN HsOfficeContactEntity contact ON contact.uuid = rel.contact.uuid
JOIN HsOfficePersonEntity person ON person.uuid = rel.holder.uuid JOIN HsOfficePersonEntity person ON person.uuid = rel.holder.uuid
WHERE :name is null WHERE :name is null
OR partner.details.birthName like concat(cast(:name as text), '%') OR partner.details.birthName like concat(cast(:name as text), '%')

View File

@ -1,24 +0,0 @@
package net.hostsharing.hsadminng.hs.office.relation;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
@Entity
@Table(name = "hs_office_relation")
@SuperBuilder
@NoArgsConstructor
@Getter
@Setter
public class HsOfficeRelationBareEntity extends HsOfficeRelationEntity {
@Override
public HsOfficeRelationEntityBuilder<?, ?> toBuilder() {
return null; // FIXME: also the ugly generics, if possible
}
}

View File

@ -1,7 +1,7 @@
package net.hostsharing.hsadminng.hs.office.relation; package net.hostsharing.hsadminng.hs.office.relation;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeRelationsApi; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeRelationsApi;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.*; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.*;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
@ -37,7 +37,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
private HsOfficePersonRepository holderRepo; private HsOfficePersonRepository holderRepo;
@Autowired @Autowired
private HsOfficeContactBareRepository contactBareRepo; private HsOfficeContactRepository contactRepo;
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
@ -68,7 +68,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var entityToSave = new HsOfficeRelationRbacEntity(); final var entityToSave = new HsOfficeRelationEntity();
entityToSave.setType(HsOfficeRelationType.valueOf(body.getType())); entityToSave.setType(HsOfficeRelationType.valueOf(body.getType()));
entityToSave.setMark(body.getMark()); entityToSave.setMark(body.getMark());
entityToSave.setAnchor(holderRepo.findByUuid(body.getAnchorUuid()).orElseThrow( entityToSave.setAnchor(holderRepo.findByUuid(body.getAnchorUuid()).orElseThrow(
@ -77,7 +77,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
entityToSave.setHolder(holderRepo.findByUuid(body.getHolderUuid()).orElseThrow( entityToSave.setHolder(holderRepo.findByUuid(body.getHolderUuid()).orElseThrow(
() -> new NoSuchElementException("cannot find holderUuid " + body.getHolderUuid()) () -> new NoSuchElementException("cannot find holderUuid " + body.getHolderUuid())
)); ));
entityToSave.setContact(contactBareRepo.findByUuid(body.getContactUuid()).orElseThrow( entityToSave.setContact(contactRepo.findByUuid(body.getContactUuid()).orElseThrow(
() -> new NoSuchElementException("cannot find contactUuid " + body.getContactUuid()) () -> new NoSuchElementException("cannot find contactUuid " + body.getContactUuid())
)); ));

View File

@ -2,9 +2,7 @@ package net.hostsharing.hsadminng.hs.office.relation;
import lombok.*; import lombok.*;
import lombok.experimental.FieldNameConstants; import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
@ -17,7 +15,6 @@ import jakarta.persistence.Column;
import java.io.IOException; import java.io.IOException;
import java.util.UUID; import java.util.UUID;
import static jakarta.persistence.InheritanceType.TABLE_PER_CLASS;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.*; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.*;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inCaseOf; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inCaseOf;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inOtherCases; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inOtherCases;
@ -31,14 +28,14 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.directlyFetche
import static net.hostsharing.hsadminng.stringify.Stringify.stringify; import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@Entity @Entity
@Inheritance(strategy = TABLE_PER_CLASS) @Table(name = "hs_office_relation_rv")
@Getter @Getter
@Setter @Setter
@SuperBuilder @Builder(toBuilder = true)
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@FieldNameConstants @FieldNameConstants
public abstract class HsOfficeRelationEntity implements RbacObject<HsOfficeRelationEntity>, Stringifyable { public class HsOfficeRelationEntity implements RbacObject, Stringifyable {
private static Stringify<HsOfficeRelationEntity> toString = stringify(HsOfficeRelationEntity.class, "rel") private static Stringify<HsOfficeRelationEntity> toString = stringify(HsOfficeRelationEntity.class, "rel")
.withProp(Fields.anchor, HsOfficeRelationEntity::getAnchor) .withProp(Fields.anchor, HsOfficeRelationEntity::getAnchor)
@ -69,7 +66,7 @@ public abstract class HsOfficeRelationEntity implements RbacObject<HsOfficeRelat
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "contactuuid") @JoinColumn(name = "contactuuid")
private HsOfficeContactBareEntity contact; private HsOfficeContactEntity contact;
@Column(name = "type") @Column(name = "type")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
@ -97,8 +94,6 @@ public abstract class HsOfficeRelationEntity implements RbacObject<HsOfficeRelat
return toShortString.apply(this); return toShortString.apply(this);
} }
public abstract <T extends HsOfficeRelationEntity> HsOfficeRelationEntityBuilder<T, ?> toBuilder();
public static RbacView rbac() { public static RbacView rbac() {
return rbacViewFor("relation", HsOfficeRelationEntity.class) return rbacViewFor("relation", HsOfficeRelationEntity.class)
.withIdentityView(SQL.projection(""" .withIdentityView(SQL.projection("""
@ -117,7 +112,7 @@ public abstract class HsOfficeRelationEntity implements RbacObject<HsOfficeRelat
dependsOnColumn("holderUuid"), dependsOnColumn("holderUuid"),
directlyFetchedByDependsOnColumn(), directlyFetchedByDependsOnColumn(),
NOT_NULL) NOT_NULL)
.importEntityAlias("contact", HsOfficeContactRbacEntity.class, usingDefaultCase(), .importEntityAlias("contact", HsOfficeContactEntity.class, usingDefaultCase(),
dependsOnColumn("contactUuid"), dependsOnColumn("contactUuid"),
directlyFetchedByDependsOnColumn(), directlyFetchedByDependsOnColumn(),
NOT_NULL) NOT_NULL)

View File

@ -1,6 +1,6 @@
package net.hostsharing.hsadminng.hs.office.relation; package net.hostsharing.hsadminng.hs.office.relation;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationPatchResource;
import net.hostsharing.hsadminng.mapper.EntityPatcher; import net.hostsharing.hsadminng.mapper.EntityPatcher;
import net.hostsharing.hsadminng.mapper.OptionalFromJson; import net.hostsharing.hsadminng.mapper.OptionalFromJson;
@ -22,7 +22,7 @@ class HsOfficeRelationEntityPatcher implements EntityPatcher<HsOfficeRelationPat
public void apply(final HsOfficeRelationPatchResource resource) { public void apply(final HsOfficeRelationPatchResource resource) {
OptionalFromJson.of(resource.getContactUuid()).ifPresent(newValue -> { OptionalFromJson.of(resource.getContactUuid()).ifPresent(newValue -> {
verifyNotNull(newValue, "contact"); verifyNotNull(newValue, "contact");
entity.setContact(em.getReference(HsOfficeContactBareEntity.class, newValue)); entity.setContact(em.getReference(HsOfficeContactEntity.class, newValue));
}); });
} }

View File

@ -1,126 +0,0 @@
package net.hostsharing.hsadminng.hs.office.relation;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import java.io.IOException;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inCaseOf;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inOtherCases;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Column.dependsOnColumn;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.ColumnValue.usingDefaultCase;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.GLOBAL;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Nullable.NOT_NULL;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.DELETE;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.INSERT;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.SELECT;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.UPDATE;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.ADMIN;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.AGENT;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.OWNER;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.REFERRER;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.TENANT;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.directlyFetchedByDependsOnColumn;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor;
@Entity
@Table(name = "hs_office_relation_rv")
@SuperBuilder
@NoArgsConstructor
@Getter
@Setter
public class HsOfficeRelationRbacEntity extends HsOfficeRelationEntity {
@Override
public HsOfficeRelationRbacEntityBuilder<HsOfficeRelationRbacEntity, ?> toBuilder() {
return null;
}
public static RbacView rbac() {
return rbacViewFor("relation", HsOfficeRelationRbacEntity.class)
.withIdentityView(SQL.projection("""
(select idName from hs_office_person_iv p where p.uuid = anchorUuid)
|| '-with-' || target.type || '-'
|| (select idName from hs_office_person_iv p where p.uuid = holderUuid)
"""))
.withRestrictedViewOrderBy(SQL.expression(
"(select idName from hs_office_person_iv p where p.uuid = target.holderUuid)"))
.withUpdatableColumns("contactUuid")
.importEntityAlias("anchorPerson", HsOfficePersonEntity.class, usingDefaultCase(),
dependsOnColumn("anchorUuid"),
directlyFetchedByDependsOnColumn(),
NOT_NULL)
.importEntityAlias("holderPerson", HsOfficePersonEntity.class, usingDefaultCase(),
dependsOnColumn("holderUuid"),
directlyFetchedByDependsOnColumn(),
NOT_NULL)
.importEntityAlias("contact", HsOfficeContactRbacEntity.class, usingDefaultCase(),
dependsOnColumn("contactUuid"),
directlyFetchedByDependsOnColumn(),
NOT_NULL)
.switchOnColumn(
"type",
inCaseOf("REPRESENTATIVE", then -> {
then.createRole(OWNER, (with) -> {
with.owningUser(CREATOR);
with.incomingSuperRole(GLOBAL, ADMIN);
with.incomingSuperRole("holderPerson", ADMIN);
with.permission(DELETE);
})
.createSubRole(ADMIN, (with) -> {
with.outgoingSubRole("anchorPerson", OWNER);
with.permission(UPDATE);
})
.createSubRole(AGENT, (with) -> {
with.incomingSuperRole("anchorPerson", ADMIN);
})
.createSubRole(TENANT, (with) -> {
with.incomingSuperRole("contact", ADMIN);
with.outgoingSubRole("anchorPerson", REFERRER);
with.outgoingSubRole("holderPerson", REFERRER);
with.outgoingSubRole("contact", REFERRER);
with.permission(SELECT);
});
}),
// inCaseOf("DEBITOR", then -> {}), TODO.spec: needs to be defined
inOtherCases(then -> {
then.createRole(OWNER, (with) -> {
with.owningUser(CREATOR);
with.incomingSuperRole(GLOBAL, ADMIN);
with.incomingSuperRole("anchorPerson", ADMIN);
with.permission(DELETE);
})
.createSubRole(ADMIN, (with) -> {
with.permission(UPDATE);
})
.createSubRole(AGENT, (with) -> {
// TODO.rbac: we need relation:PROXY, to allow changing the relation contact.
// the alternative would be to move this to the relation:ADMIN role,
// but then the partner holder person could update the partner relation itself,
// see partner entity.
with.incomingSuperRole("holderPerson", ADMIN);
})
.createSubRole(TENANT, (with) -> {
with.incomingSuperRole("contact", ADMIN);
with.outgoingSubRole("anchorPerson", REFERRER);
with.outgoingSubRole("holderPerson", REFERRER);
with.outgoingSubRole("contact", REFERRER);
with.permission(SELECT);
});
}))
.toRole("anchorPerson", ADMIN).grantPermission(INSERT);
}
public static void main(String[] args) throws IOException {
rbac().generateWithBaseFileName("5-hs-office/503-relation/5033-hs-office-relation-rbac");
}
}

View File

@ -8,11 +8,11 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static java.lang.Boolean.TRUE; import static java.lang.Boolean.TRUE;
import static java.util.Optional.ofNullable;
public final class Stringify<B> { public final class Stringify<B> {
@ -32,14 +32,11 @@ public final class Stringify<B> {
public <T extends B> Stringify<T> using(final Class<T> subClass) { public <T extends B> Stringify<T> using(final Class<T> subClass) {
//noinspection unchecked //noinspection unchecked
final var stringify = new Stringify<T>(subClass, null) return (Stringify<T>) new Stringify<T>(subClass, null)
.withIdProp(cast(idProp)) .withIdProp(cast(idProp))
.withProps(cast(props)) .withProps(cast(props))
.withSeparator(separator); .withSeparator(separator)
if (quotedValues != null) { .quotedValues(quotedValues);
stringify.quotedValues(quotedValues);
}
return stringify;
} }
private Stringify(final Class<B> clazz, final String name) { private Stringify(final Class<B> clazz, final String name) {
@ -99,7 +96,7 @@ public final class Stringify<B> {
} }
private String propName(final PropertyValue<B> propVal, final String delimiter) { private String propName(final PropertyValue<B> propVal, final String delimiter) {
return ofNullable(propVal.prop.name).map(v -> v + delimiter).orElse(""); return Optional.ofNullable(propVal.prop.name).map(v -> v + delimiter).orElse("");
} }
private String optionallyQuoted(final PropertyValue<B> propVal) { private String optionallyQuoted(final PropertyValue<B> propVal) {

View File

@ -8,8 +8,8 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
@ -62,7 +62,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
HsOfficeDebitorRepository debitorRepo; HsOfficeDebitorRepository debitorRepo;
@Autowired @Autowired
HsOfficeContactRbacRepository contactRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
JpaAttempt jpaAttempt; JpaAttempt jpaAttempt;
@ -732,7 +732,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
private HsOfficeContactRbacEntity givenContact() { private HsOfficeContactEntity givenContact() {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
return contactRepo.findContactByOptionalCaptionLike("second").stream().findFirst().orElseThrow(); return contactRepo.findContactByOptionalCaptionLike("second").stream().findFirst().orElseThrow();

View File

@ -32,7 +32,7 @@ import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_C
import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM; import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM;
import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET;
import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET; import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET;
import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareTestEntity.TEST_BARE_CONTACT; import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.TEST_CONTACT;
import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals; import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -75,7 +75,7 @@ public class HsHostingAssetControllerRestTest {
.bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM) .bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM)
.identifier("vm1234") .identifier("vm1234")
.caption("some fake cloud-server") .caption("some fake cloud-server")
.alarmContact(TEST_BARE_CONTACT) .alarmContact(TEST_CONTACT)
.build()), .build()),
""" """
[ [
@ -101,7 +101,7 @@ public class HsHostingAssetControllerRestTest {
.bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM)
.identifier("vm1234") .identifier("vm1234")
.caption("some fake managed-server") .caption("some fake managed-server")
.alarmContact(TEST_BARE_CONTACT) .alarmContact(TEST_CONTACT)
.config(Map.ofEntries( .config(Map.ofEntries(
entry("monit_max_ssd_usage", 70), entry("monit_max_ssd_usage", 70),
entry("monit_max_cpu_usage", 80), entry("monit_max_cpu_usage", 80),

View File

@ -1,8 +1,7 @@
package net.hostsharing.hsadminng.hs.hosting.asset; package net.hostsharing.hsadminng.hs.hosting.asset;
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
import net.hostsharing.hsadminng.mapper.KeyValueMap; import net.hostsharing.hsadminng.mapper.KeyValueMap;
import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -49,7 +48,7 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
entry("SSD", 256), entry("SSD", 256),
entry("MEM", 64) entry("MEM", 64)
); );
final HsOfficeContactBareEntity givenInitialContact = HsOfficeContactBareEntity.builder() final HsOfficeContactEntity givenInitialContact = HsOfficeContactEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.build(); .build();
@ -63,8 +62,8 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
void initMocks() { void initMocks() {
lenient().when(em.getReference(eq(HsHostingAssetEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsHostingAssetEntity.class), any())).thenAnswer(invocation ->
HsHostingAssetEntity.builder().uuid(invocation.getArgument(1)).build()); HsHostingAssetEntity.builder().uuid(invocation.getArgument(1)).build());
lenient().when(em.getReference(eq(HsOfficeContactRbacEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation ->
HsOfficeContactRbacEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build());
} }
@Override @Override
@ -112,7 +111,7 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
); );
} }
static HsOfficeContactBareEntity newContact(final UUID uuid) { static HsOfficeContactEntity newContact(final UUID uuid) {
return HsOfficeContactBareEntity.builder().uuid(uuid).build(); return HsOfficeContactEntity.builder().uuid(uuid).build();
} }
} }

View File

@ -10,7 +10,7 @@ import lombok.Setter;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -42,7 +42,7 @@ import java.util.UUID;
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class HsHostingAssetBareEntity implements HsHostingAsset { public class HsHostingAssetRawEntity implements HsHostingAsset {
@Id @Id
@GeneratedValue @GeneratedValue
@ -57,11 +57,11 @@ public class HsHostingAssetBareEntity implements HsHostingAsset {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parentassetuuid") @JoinColumn(name = "parentassetuuid")
private HsHostingAssetBareEntity parentAsset; private HsHostingAssetRawEntity parentAsset;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "assignedtoassetuuid") @JoinColumn(name = "assignedtoassetuuid")
private HsHostingAssetBareEntity assignedToAsset; private HsHostingAssetRawEntity assignedToAsset;
@Column(name = "type") @Column(name = "type")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
@ -69,11 +69,11 @@ public class HsHostingAssetBareEntity implements HsHostingAsset {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "alarmcontactuuid") @JoinColumn(name = "alarmcontactuuid")
private HsOfficeContactBareEntity alarmContact; private HsOfficeContactEntity alarmContact;
@OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY)
@JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid") @JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid")
private List<HsHostingAssetBareEntity> subHostingAssets; private List<HsHostingAssetRawEntity> subHostingAssets;
@Column(name = "identifier") @Column(name = "identifier")
private String identifier; // e.g. vm1234, xyz00, example.org, xyz00_abc private String identifier; // e.g. vm1234, xyz00, example.org, xyz00_abc
@ -109,6 +109,6 @@ public class HsHostingAssetBareEntity implements HsHostingAsset {
@Override @Override
public String toString() { public String toString() {
return stringify.using(HsHostingAssetBareEntity.class).apply(this); return stringify.using(HsHostingAssetRawEntity.class).apply(this);
} }
} }

View File

@ -113,13 +113,13 @@ public class ImportHostingAssets extends ImportOfficeData {
static final Integer DBUSER_ID_OFFSET = 7000000; static final Integer DBUSER_ID_OFFSET = 7000000;
static final Integer DB_ID_OFFSET = 8000000; static final Integer DB_ID_OFFSET = 8000000;
record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference<HsHostingAssetBareEntity> serverRef) {} record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference<HsHostingAssetRawEntity> serverRef) {}
static Map<Integer, HsBookingProjectEntity> bookingProjects = new WriteOnceMap<>(); static Map<Integer, HsBookingProjectEntity> bookingProjects = new WriteOnceMap<>();
static Map<Integer, HsBookingItemEntity> bookingItems = new WriteOnceMap<>(); static Map<Integer, HsBookingItemEntity> bookingItems = new WriteOnceMap<>();
static Map<Integer, Hive> hives = new WriteOnceMap<>(); static Map<Integer, Hive> hives = new WriteOnceMap<>();
static Map<Integer, HsHostingAssetBareEntity> hostingAssets = new WriteOnceMap<>(); // TODO.impl: separate maps for each type? static Map<Integer, HsHostingAssetRawEntity> hostingAssets = new WriteOnceMap<>(); // TODO.impl: separate maps for each type?
static Map<String, HsHostingAssetBareEntity> dbUsersByEngineAndName = new WriteOnceMap<>(); static Map<String, HsHostingAssetRawEntity> dbUsersByEngineAndName = new WriteOnceMap<>();
@Test @Test
@Order(11010) @Order(11010)
@ -670,7 +670,7 @@ public class ImportHostingAssets extends ImportOfficeData {
.map(this::trimAll) .map(this::trimAll)
.map(row -> new Record(columns, row)) .map(row -> new Record(columns, row))
.forEach(rec -> { .forEach(rec -> {
final var ipNumber = HsHostingAssetBareEntity.builder() final var ipNumber = HsHostingAssetRawEntity.builder()
.type(IPV4_NUMBER) .type(IPV4_NUMBER)
.identifier(rec.getString("inet_addr")) .identifier(rec.getString("inet_addr"))
.caption(rec.getString("description")) .caption(rec.getString("description"))
@ -734,7 +734,7 @@ public class ImportHostingAssets extends ImportOfficeData {
+ packet_name) + packet_name)
.isTrue()); .isTrue());
final var asset = HsHostingAssetBareEntity.builder() final var asset = HsHostingAssetRawEntity.builder()
// this turns off identifier validation to accept former default prefixes // this turns off identifier validation to accept former default prefixes
.isLoaded(haType == MANAGED_WEBSPACE) .isLoaded(haType == MANAGED_WEBSPACE)
.type(haType) .type(haType)
@ -874,7 +874,7 @@ public class ImportHostingAssets extends ImportOfficeData {
.forEach(rec -> { .forEach(rec -> {
final var unixuser_id = rec.getInteger("unixuser_id"); final var unixuser_id = rec.getInteger("unixuser_id");
final var packet_id = rec.getInteger("packet_id"); final var packet_id = rec.getInteger("packet_id");
final var unixUserAsset = HsHostingAssetBareEntity.builder() final var unixUserAsset = HsHostingAssetRawEntity.builder()
.type(UNIX_USER) .type(UNIX_USER)
.parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id)) .parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id))
.identifier(rec.getString("name")) .identifier(rec.getString("name"))
@ -931,7 +931,7 @@ public class ImportHostingAssets extends ImportOfficeData {
final var unixuser_id = rec.getInteger("emailalias_id"); final var unixuser_id = rec.getInteger("emailalias_id");
final var packet_id = rec.getInteger("pac_id"); final var packet_id = rec.getInteger("pac_id");
final var targets = parseCsvLine(rec.getString("target")); final var targets = parseCsvLine(rec.getString("target"));
final var unixUserAsset = HsHostingAssetBareEntity.builder() final var unixUserAsset = HsHostingAssetRawEntity.builder()
.type(EMAIL_ALIAS) .type(EMAIL_ALIAS)
.parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id)) .parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id))
.identifier(rec.getString("name")) .identifier(rec.getString("name"))
@ -944,14 +944,14 @@ public class ImportHostingAssets extends ImportOfficeData {
}); });
} }
private void createDatabaseInstances(final List<HsHostingAssetBareEntity> parentAssets) { private void createDatabaseInstances(final List<HsHostingAssetRawEntity> parentAssets) {
final var idRef = new AtomicInteger(0); final var idRef = new AtomicInteger(0);
parentAssets.forEach(pa -> { parentAssets.forEach(pa -> {
if (pa.getSubHostingAssets() == null) { if (pa.getSubHostingAssets() == null) {
pa.setSubHostingAssets(new ArrayList<>()); pa.setSubHostingAssets(new ArrayList<>());
} }
final var pgSqlInstanceAsset = HsHostingAssetBareEntity.builder() final var pgSqlInstanceAsset = HsHostingAssetRawEntity.builder()
.type(PGSQL_INSTANCE) .type(PGSQL_INSTANCE)
.parentAsset(pa) .parentAsset(pa)
.identifier(pa.getIdentifier() + "|PgSql.default") .identifier(pa.getIdentifier() + "|PgSql.default")
@ -960,7 +960,7 @@ public class ImportHostingAssets extends ImportOfficeData {
pa.getSubHostingAssets().add(pgSqlInstanceAsset); pa.getSubHostingAssets().add(pgSqlInstanceAsset);
hostingAssets.put(DBINSTANCE_ID_OFFSET + idRef.getAndIncrement(), pgSqlInstanceAsset); hostingAssets.put(DBINSTANCE_ID_OFFSET + idRef.getAndIncrement(), pgSqlInstanceAsset);
final var mariaDbInstanceAsset = HsHostingAssetBareEntity.builder() final var mariaDbInstanceAsset = HsHostingAssetRawEntity.builder()
.type(MARIADB_INSTANCE) .type(MARIADB_INSTANCE)
.parentAsset(pa) .parentAsset(pa)
.identifier(pa.getIdentifier() + "|MariaDB.default") .identifier(pa.getIdentifier() + "|MariaDB.default")
@ -996,7 +996,7 @@ public class ImportHostingAssets extends ImportOfficeData {
.filter(ha -> ha.getType() == dbInstanceAssetType) .filter(ha -> ha.getType() == dbInstanceAssetType)
.findAny().orElseThrow(); // there is exactly one: the default instance for the given type .findAny().orElseThrow(); // there is exactly one: the default instance for the given type
final var dbUserAsset = HsHostingAssetBareEntity.builder() final var dbUserAsset = HsHostingAssetRawEntity.builder()
.type(dbUserAssetType) .type(dbUserAssetType)
.parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id)) .parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id))
.assignedToAsset(dbInstanceAsset) .assignedToAsset(dbInstanceAsset)
@ -1027,7 +1027,7 @@ public class ImportHostingAssets extends ImportOfficeData {
: failWith("unknown DB engine " + engine); : failWith("unknown DB engine " + engine);
final var name = rec.getString("name"); final var name = rec.getString("name");
final var encoding = rec.getString("encoding").replaceAll("[-_]+", ""); final var encoding = rec.getString("encoding").replaceAll("[-_]+", "");
final var dbAsset = HsHostingAssetBareEntity.builder() final var dbAsset = HsHostingAssetRawEntity.builder()
.type(type) .type(type)
.parentAsset(owningDbUserHA) .parentAsset(owningDbUserHA)
.identifier(type.name().substring(0, 2) + "D|" + name) .identifier(type.name().substring(0, 2) + "D|" + name)
@ -1069,7 +1069,7 @@ public class ImportHostingAssets extends ImportOfficeData {
}; };
} }
private static HsHostingAssetBareEntity ipNumber(final Integer inet_addr_id) { private static HsHostingAssetRawEntity ipNumber(final Integer inet_addr_id) {
return inet_addr_id != null ? hostingAssets.get(IP_NUMBER_ID_OFFSET + inet_addr_id) : null; return inet_addr_id != null ? hostingAssets.get(IP_NUMBER_ID_OFFSET + inet_addr_id) : null;
} }
@ -1077,7 +1077,7 @@ public class ImportHostingAssets extends ImportOfficeData {
return hive_id != null ? hives.get(HIVE_ID_OFFSET + hive_id) : null; return hive_id != null ? hives.get(HIVE_ID_OFFSET + hive_id) : null;
} }
private static HsHostingAssetBareEntity pac(final Integer packet_id) { private static HsHostingAssetRawEntity pac(final Integer packet_id) {
return packet_id != null ? hostingAssets.get(PACKET_ID_OFFSET + packet_id) : null; return packet_id != null ? hostingAssets.get(PACKET_ID_OFFSET + packet_id) : null;
} }

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.migration;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionEntity; import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionEntity;
import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType; import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType;
import net.hostsharing.hsadminng.hs.office.coopshares.HsOfficeCoopSharesTransactionEntity; import net.hostsharing.hsadminng.hs.office.coopshares.HsOfficeCoopSharesTransactionEntity;
@ -15,7 +15,6 @@ import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity; import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
@ -121,7 +120,7 @@ public class ImportOfficeData extends CsvDataImport {
-1 -1
); );
static Map<Integer, HsOfficeContactBareEntity> contacts = new WriteOnceMap<>(); static Map<Integer, HsOfficeContactEntity> contacts = new WriteOnceMap<>();
static Map<Integer, HsOfficePersonEntity> persons = new WriteOnceMap<>(); static Map<Integer, HsOfficePersonEntity> persons = new WriteOnceMap<>();
static Map<Integer, HsOfficePartnerEntity> partners = new WriteOnceMap<>(); static Map<Integer, HsOfficePartnerEntity> partners = new WriteOnceMap<>();
static Map<Integer, HsOfficeDebitorEntity> debitors = new WriteOnceMap<>(); static Map<Integer, HsOfficeDebitorEntity> debitors = new WriteOnceMap<>();
@ -979,7 +978,7 @@ public class ImportOfficeData extends CsvDataImport {
contactPerson = addPerson(HsOfficePersonEntity.builder().build(), rec); contactPerson = addPerson(HsOfficePersonEntity.builder().build(), rec);
} }
final var contact = HsOfficeContactBareEntity.builder().build(); final var contact = HsOfficeContactEntity.builder().build();
initContact(contact, rec); initContact(contact, rec);
if (containsPartnerRel(rec)) { if (containsPartnerRel(rec)) {
@ -1057,8 +1056,8 @@ public class ImportOfficeData extends CsvDataImport {
final HsOfficeRelationType type, final HsOfficeRelationType type,
final HsOfficePersonEntity anchor, final HsOfficePersonEntity anchor,
final HsOfficePersonEntity holder, final HsOfficePersonEntity holder,
final HsOfficeContactBareEntity contact) { final HsOfficeContactEntity contact) {
final var rel = HsOfficeRelationBareEntity.builder() final var rel = HsOfficeRelationEntity.builder()
.anchor(anchor) .anchor(anchor)
.holder(holder) .holder(holder)
.contact(contact) .contact(contact)
@ -1118,7 +1117,7 @@ public class ImportOfficeData extends CsvDataImport {
assertThat(unexpectedRolesSet).isEmpty(); assertThat(unexpectedRolesSet).isEmpty();
} }
private HsOfficeContactBareEntity initContact(final HsOfficeContactBareEntity contact, final Record contactRecord) { private HsOfficeContactEntity initContact(final HsOfficeContactEntity contact, final Record contactRecord) {
contact.setCaption(toCaption( contact.setCaption(toCaption(
contactRecord.getString("salut"), contactRecord.getString("salut"),

View File

@ -1,16 +0,0 @@
package net.hostsharing.hsadminng.hs.office.contact;
import java.util.Map;
public class HsOfficeContactBareTestEntity {
public static final HsOfficeContactBareEntity TEST_BARE_CONTACT = hsOfficeContact("some contact", "some-contact@example.com");
static public HsOfficeContactBareEntity hsOfficeContact(final String caption, final String emailAddr) {
return HsOfficeContactBareEntity.builder()
.caption(caption)
.postalAddress("address of " + caption)
.emailAddresses(Map.of("main", emailAddr))
.build();
}
}

View File

@ -45,7 +45,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
Context contextMock; Context contextMock;
@Autowired @Autowired
HsOfficeContactRbacRepository contactRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
JpaAttempt jpaAttempt; JpaAttempt jpaAttempt;
@ -355,10 +355,10 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
} }
} }
private HsOfficeContactRbacEntity givenSomeTemporaryContactCreatedBy(final String creatingUser) { private HsOfficeContactEntity givenSomeTemporaryContactCreatedBy(final String creatingUser) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context.define(creatingUser); context.define(creatingUser);
final var newContact = HsOfficeContactRbacEntity.builder() final var newContact = HsOfficeContactEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.caption("Temp from " + Context.getCallerMethodNameFromStackFrame(1) ) .caption("Temp from " + Context.getCallerMethodNameFromStackFrame(1) )
.emailAddresses(Map.of("main", RandomStringUtils.randomAlphabetic(10) + "@example.org")) .emailAddresses(Map.of("main", RandomStringUtils.randomAlphabetic(10) + "@example.org"))
@ -375,7 +375,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
void cleanup() { void cleanup() {
jpaAttempt.transacted(() -> { jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net", null); context.define("superuser-alex@hostsharing.net", null);
em.createQuery("DELETE FROM HsOfficeContactRbacEntity c WHERE c.caption LIKE 'Temp %'").executeUpdate(); em.createQuery("DELETE FROM HsOfficeContactEntity c WHERE c.caption LIKE 'Temp %'").executeUpdate();
}).assertSuccessful(); }).assertSuccessful();
} }
} }

View File

@ -13,9 +13,9 @@ import static net.hostsharing.hsadminng.mapper.PatchMap.patchMap;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
@TestInstance(PER_CLASS) @TestInstance(PER_CLASS)
class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase< class HsOfficeContactEntityPatcherUnitTest extends PatchUnitTestBase<
HsOfficeContactPatchResource, HsOfficeContactPatchResource,
HsOfficeContactRbacEntity HsOfficeContactEntity
> { > {
private static final UUID INITIAL_CONTACT_UUID = UUID.randomUUID(); private static final UUID INITIAL_CONTACT_UUID = UUID.randomUUID();
@ -42,8 +42,8 @@ class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase<
); );
@Override @Override
protected HsOfficeContactRbacEntity newInitialEntity() { protected HsOfficeContactEntity newInitialEntity() {
final var entity = new HsOfficeContactRbacEntity(); final var entity = new HsOfficeContactEntity();
entity.setUuid(INITIAL_CONTACT_UUID); entity.setUuid(INITIAL_CONTACT_UUID);
entity.setCaption("initial caption"); entity.setCaption("initial caption");
entity.putEmailAddresses(Map.ofEntries( entity.putEmailAddresses(Map.ofEntries(
@ -64,7 +64,7 @@ class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase<
} }
@Override @Override
protected HsOfficeContactEntityPatcher createPatcher(final HsOfficeContactRbacEntity entity) { protected HsOfficeContactEntityPatcher createPatcher(final HsOfficeContactEntity entity) {
return new HsOfficeContactEntityPatcher(entity); return new HsOfficeContactEntityPatcher(entity);
} }
@ -75,26 +75,26 @@ class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase<
"caption", "caption",
HsOfficeContactPatchResource::setCaption, HsOfficeContactPatchResource::setCaption,
"patched caption", "patched caption",
HsOfficeContactRbacEntity::setCaption), HsOfficeContactEntity::setCaption),
new SimpleProperty<>( new SimpleProperty<>(
"resources", "resources",
HsOfficeContactPatchResource::setEmailAddresses, HsOfficeContactPatchResource::setEmailAddresses,
PATCH_EMAIL_ADDRESSES, PATCH_EMAIL_ADDRESSES,
HsOfficeContactRbacEntity::putEmailAddresses, HsOfficeContactEntity::putEmailAddresses,
PATCHED_EMAIL_ADDRESSES) PATCHED_EMAIL_ADDRESSES)
.notNullable(), .notNullable(),
new SimpleProperty<>( new SimpleProperty<>(
"resources", "resources",
HsOfficeContactPatchResource::setPhoneNumbers, HsOfficeContactPatchResource::setPhoneNumbers,
PATCH_PHONE_NUMBERS, PATCH_PHONE_NUMBERS,
HsOfficeContactRbacEntity::putPhoneNumbers, HsOfficeContactEntity::putPhoneNumbers,
PATCHED_PHONE_NUMBERS) PATCHED_PHONE_NUMBERS)
.notNullable(), .notNullable(),
new JsonNullableProperty<>( new JsonNullableProperty<>(
"patched given name", "patched given name",
HsOfficeContactPatchResource::setPostalAddress, HsOfficeContactPatchResource::setPostalAddress,
"patched given name", "patched given name",
HsOfficeContactRbacEntity::setPostalAddress) HsOfficeContactEntity::setPostalAddress)
); );
} }
} }

View File

@ -4,17 +4,17 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
class HsOfficeContactUnitTest { class HsOfficeContactEntityUnitTest {
@Test @Test
void toStringReturnsNullForNullContact() { void toStringReturnsNullForNullContact() {
final HsOfficeContactRbacEntity givenContact = null; final HsOfficeContactEntity givenContact = null;
assertThat("" + givenContact).isEqualTo("null"); assertThat("" + givenContact).isEqualTo("null");
} }
@Test @Test
void toStringReturnsCaption() { void toStringReturnsCaption() {
final var givenContact = HsOfficeContactRbacEntity.builder().caption("given caption").build(); final var givenContact = HsOfficeContactEntity.builder().caption("given caption").build();
assertThat("" + givenContact).isEqualTo("contact(caption='given caption')"); assertThat("" + givenContact).isEqualTo("contact(caption='given caption')");
} }

View File

@ -1,16 +0,0 @@
package net.hostsharing.hsadminng.hs.office.contact;
import java.util.Map;
public class HsOfficeContactRbacTestEntity {
public static final HsOfficeContactRbacEntity TEST_RBAC_CONTACT = hsOfficeContact("some contact", "some-contact@example.com");
static public HsOfficeContactRbacEntity hsOfficeContact(final String caption, final String emailAddr) {
return HsOfficeContactRbacEntity.builder()
.caption(caption)
.postalAddress("address of " + caption)
.emailAddresses(Map.of("main", emailAddr))
.build();
}
}

View File

@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacTestEntity.hsOfficeContact; import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.hsOfficeContact;
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.distinctGrantDisplaysOf; import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.distinctGrantDisplaysOf;
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.distinctRoleNamesOf; import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.distinctRoleNamesOf;
import static net.hostsharing.hsadminng.rbac.test.JpaAttempt.attempt; import static net.hostsharing.hsadminng.rbac.test.JpaAttempt.attempt;
@ -29,10 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import( { Context.class, JpaAttempt.class }) @Import( { Context.class, JpaAttempt.class })
class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
@Autowired @Autowired
HsOfficeContactRbacRepository contactRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
RawRbacRoleRepository rawRoleRepo; RawRbacRoleRepository rawRoleRepo;
@ -65,7 +65,7 @@ class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithC
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactRbacEntity::getUuid).isNotNull(); assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactEntity::getUuid).isNotNull();
assertThatContactIsPersisted(result.returnedValue()); assertThatContactIsPersisted(result.returnedValue());
assertThat(contactRepo.count()).isEqualTo(count + 1); assertThat(contactRepo.count()).isEqualTo(count + 1);
} }
@ -82,7 +82,7 @@ class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithC
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactRbacEntity::getUuid).isNotNull(); assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactEntity::getUuid).isNotNull();
assertThatContactIsPersisted(result.returnedValue()); assertThatContactIsPersisted(result.returnedValue());
assertThat(contactRepo.count()).isEqualTo(count + 1); assertThat(contactRepo.count()).isEqualTo(count + 1);
} }
@ -120,7 +120,7 @@ class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithC
)); ));
} }
private void assertThatContactIsPersisted(final HsOfficeContactRbacEntity saved) { private void assertThatContactIsPersisted(final HsOfficeContactEntity saved) {
final var found = contactRepo.findByUuid(saved.getUuid()); final var found = contactRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString()); assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
} }
@ -270,16 +270,16 @@ class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithC
"[creating contact test-data second contact, hs_office_contact, INSERT]"); "[creating contact test-data second contact, hs_office_contact, INSERT]");
} }
private HsOfficeContactRbacEntity givenSomeTemporaryContact( private HsOfficeContactEntity givenSomeTemporaryContact(
final String createdByUser, final String createdByUser,
Supplier<HsOfficeContactRbacEntity> entitySupplier) { Supplier<HsOfficeContactEntity> entitySupplier) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context(createdByUser); context(createdByUser);
return toCleanup(contactRepo.save(entitySupplier.get())); return toCleanup(contactRepo.save(entitySupplier.get()));
}).assumeSuccessful().returnedValue(); }).assumeSuccessful().returnedValue();
} }
private HsOfficeContactRbacEntity givenSomeTemporaryContact(final String createdByUser) { private HsOfficeContactEntity givenSomeTemporaryContact(final String createdByUser) {
final var random = RandomStringUtils.randomAlphabetic(12); final var random = RandomStringUtils.randomAlphabetic(12);
return givenSomeTemporaryContact(createdByUser, () -> return givenSomeTemporaryContact(createdByUser, () ->
hsOfficeContact( hsOfficeContact(
@ -287,15 +287,15 @@ class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithC
"some-temporary-contact" + random + "@example.com")); "some-temporary-contact" + random + "@example.com"));
} }
void exactlyTheseContactsAreReturned(final List<HsOfficeContactRbacEntity> actualResult, final String... contactCaptions) { void exactlyTheseContactsAreReturned(final List<HsOfficeContactEntity> actualResult, final String... contactCaptions) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsOfficeContactRbacEntity::getCaption) .extracting(HsOfficeContactEntity::getCaption)
.containsExactlyInAnyOrder(contactCaptions); .containsExactlyInAnyOrder(contactCaptions);
} }
void allTheseContactsAreReturned(final List<HsOfficeContactRbacEntity> actualResult, final String... contactCaptions) { void allTheseContactsAreReturned(final List<HsOfficeContactEntity> actualResult, final String... contactCaptions) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsOfficeContactRbacEntity::getCaption) .extracting(HsOfficeContactEntity::getCaption)
.contains(contactCaptions); .contains(contactCaptions);
} }
} }

View File

@ -0,0 +1,16 @@
package net.hostsharing.hsadminng.hs.office.contact;
import java.util.Map;
public class TestHsOfficeContact {
public static final HsOfficeContactEntity TEST_CONTACT = hsOfficeContact("some contact", "some-contact@example.com");
static public HsOfficeContactEntity hsOfficeContact(final String caption, final String emailAddr) {
return HsOfficeContactEntity.builder()
.caption(caption)
.postalAddress("address of " + caption)
.emailAddresses(Map.of("main", emailAddr))
.build();
}
}

View File

@ -5,10 +5,10 @@ import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
@ -55,7 +55,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
HsOfficePartnerRepository partnerRepo; HsOfficePartnerRepository partnerRepo;
@Autowired @Autowired
HsOfficeContactBareRepository contactBareRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
HsOfficeBankAccountRepository bankAccountRepo; HsOfficeBankAccountRepository bankAccountRepo;
@ -268,13 +268,13 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike("Fourth").get(0); final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike("Fourth").get(0);
final var givenBillingPerson = personRepo.findPersonByOptionalNameLike("Fourth").get(0); final var givenBillingPerson = personRepo.findPersonByOptionalNameLike("Fourth").get(0);
final var givenDebitorRelUUid = jpaAttempt.transacted(() -> { final var givenDebitorRelUUid = jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
return relRepo.save(HsOfficeRelationRbacEntity.builder() return relRepo.save(HsOfficeRelationEntity.builder()
.type(DEBITOR) .type(DEBITOR)
.anchor(givenPartner.getPartnerRel().getHolder()) .anchor(givenPartner.getPartnerRel().getHolder())
.holder(givenBillingPerson) .holder(givenBillingPerson)
@ -325,7 +325,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -414,7 +414,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitorRelUuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); final var givenDebitorRelUuid = UUID.fromString("00000000-0000-0000-0000-000000000000");
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -551,7 +551,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitor = givenSomeTemporaryDebitor(); final var givenDebitor = givenSomeTemporaryDebitor();
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -721,12 +721,12 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Fourth").get(0).load(); final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Fourth").get(0).load();
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").get(0);
final var newDebitor = HsOfficeDebitorEntity.builder() final var newDebitor = HsOfficeDebitorEntity.builder()
.debitorNumberSuffix(nextDebitorSuffix()) .debitorNumberSuffix(nextDebitorSuffix())
.billable(true) .billable(true)
.debitorRel( .debitorRel(
HsOfficeRelationRbacEntity.builder() HsOfficeRelationEntity.builder()
.type(DEBITOR) .type(DEBITOR)
.anchor(givenPartner.getPartnerRel().getHolder()) .anchor(givenPartner.getPartnerRel().getHolder())
.holder(givenPartner.getPartnerRel().getHolder()) .holder(givenPartner.getPartnerRel().getHolder())

View File

@ -3,7 +3,6 @@ package net.hostsharing.hsadminng.hs.office.debitor;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance;
@ -45,7 +44,7 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase<
private static final UUID INITIAL_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID(); private static final UUID INITIAL_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID();
private static final UUID PATCHED_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID(); private static final UUID PATCHED_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID();
private final HsOfficeRelationEntity givenInitialDebitorRel = HsOfficeRelationRbacEntity.builder() private final HsOfficeRelationEntity givenInitialDebitorRel = HsOfficeRelationEntity.builder()
.uuid(INITIAL_DEBITOR_REL_UUID) .uuid(INITIAL_DEBITOR_REL_UUID)
.build(); .build();
@ -58,7 +57,7 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase<
@BeforeEach @BeforeEach
void initMocks() { void initMocks() {
lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation ->
HsOfficeRelationRbacEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeRelationEntity.builder().uuid(invocation.getArgument(1)).build());
lenient().when(em.getReference(eq(HsOfficeBankAccountEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeBankAccountEntity.class), any())).thenAnswer(invocation ->
HsOfficeBankAccountEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeBankAccountEntity.builder().uuid(invocation.getArgument(1)).build());
} }
@ -143,7 +142,7 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase<
} }
private HsOfficeRelationEntity newDebitorRel(final UUID uuid) { private HsOfficeRelationEntity newDebitorRel(final UUID uuid) {
return HsOfficeRelationRbacEntity.builder() return HsOfficeRelationEntity.builder()
.uuid(uuid) .uuid(uuid)
.build(); .build();
} }

View File

@ -1,18 +1,17 @@
package net.hostsharing.hsadminng.hs.office.debitor; package net.hostsharing.hsadminng.hs.office.debitor;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
class HsOfficeDebitorEntityUnitTest { class HsOfficeDebitorEntityUnitTest {
private HsOfficeRelationEntity givenDebitorRel = HsOfficeRelationRbacEntity.builder() private HsOfficeRelationEntity givenDebitorRel = HsOfficeRelationEntity.builder()
.anchor(HsOfficePersonEntity.builder() .anchor(HsOfficePersonEntity.builder()
.personType(HsOfficePersonType.LEGAL_PERSON) .personType(HsOfficePersonType.LEGAL_PERSON)
.tradeName("some partner trade name") .tradeName("some partner trade name")
@ -21,7 +20,7 @@ class HsOfficeDebitorEntityUnitTest {
.personType(HsOfficePersonType.LEGAL_PERSON) .personType(HsOfficePersonType.LEGAL_PERSON)
.tradeName("some billing trade name") .tradeName("some billing trade name")
.build()) .build())
.contact(HsOfficeContactBareEntity.builder().caption("some caption").build()) .contact(HsOfficeContactEntity.builder().caption("some caption").build())
.build(); .build();
@Test @Test

View File

@ -2,11 +2,10 @@ package net.hostsharing.hsadminng.hs.office.debitor;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
@ -50,7 +49,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
HsOfficePartnerRepository partnerRepo; HsOfficePartnerRepository partnerRepo;
@Autowired @Autowired
HsOfficeContactBareRepository contactBareRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@ -85,14 +84,14 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var count = debitorRepo.count(); final var count = debitorRepo.count();
final var givenPartner = partnerRepo.findPartnerByPartnerNumber(10001); final var givenPartner = partnerRepo.findPartnerByPartnerNumber(10001);
final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH")); final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH"));
final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike("first contact")); final var givenContact = one(contactRepo.findContactByOptionalCaptionLike("first contact"));
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newDebitor = HsOfficeDebitorEntity.builder() final var newDebitor = HsOfficeDebitorEntity.builder()
.partner(givenPartner) .partner(givenPartner)
.debitorNumberSuffix("21") .debitorNumberSuffix("21")
.debitorRel(HsOfficeRelationRbacEntity.builder() .debitorRel(HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.DEBITOR) .type(HsOfficeRelationType.DEBITOR)
.anchor(givenPartnerPerson) .anchor(givenPartnerPerson)
.holder(givenPartnerPerson) .holder(givenPartnerPerson)
@ -119,13 +118,13 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
// given // given
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH")); final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH"));
final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike("first contact")); final var givenContact = one(contactRepo.findContactByOptionalCaptionLike("first contact"));
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newDebitor = HsOfficeDebitorEntity.builder() final var newDebitor = HsOfficeDebitorEntity.builder()
.debitorNumberSuffix("21") .debitorNumberSuffix("21")
.debitorRel(HsOfficeRelationRbacEntity.builder() .debitorRel(HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.DEBITOR) .type(HsOfficeRelationType.DEBITOR)
.anchor(givenPartnerPerson) .anchor(givenPartnerPerson)
.holder(givenPartnerPerson) .holder(givenPartnerPerson)
@ -157,10 +156,10 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
attempt(em, () -> { attempt(em, () -> {
final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH")); final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH"));
final var givenDebitorPerson = one(personRepo.findPersonByOptionalNameLike("Fourth eG")); final var givenDebitorPerson = one(personRepo.findPersonByOptionalNameLike("Fourth eG"));
final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike("fourth contact")); final var givenContact = one(contactRepo.findContactByOptionalCaptionLike("fourth contact"));
final var newDebitor = HsOfficeDebitorEntity.builder() final var newDebitor = HsOfficeDebitorEntity.builder()
.debitorNumberSuffix("22") .debitorNumberSuffix("22")
.debitorRel(HsOfficeRelationRbacEntity.builder() .debitorRel(HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.DEBITOR) .type(HsOfficeRelationType.DEBITOR)
.anchor(givenPartnerPerson) .anchor(givenPartnerPerson)
.holder(givenDebitorPerson) .holder(givenDebitorPerson)
@ -323,7 +322,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
"hs_office_relation#FourtheG-with-DEBITOR-FourtheG:ADMIN", true); "hs_office_relation#FourtheG-with-DEBITOR-FourtheG:ADMIN", true);
final var givenNewPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First")); final var givenNewPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First"));
final var givenNewBillingPerson = one(personRepo.findPersonByOptionalNameLike("Firby")); final var givenNewBillingPerson = one(personRepo.findPersonByOptionalNameLike("Firby"));
final var givenNewContact = one(contactBareRepo.findContactByOptionalCaptionLike("sixth contact")); final var givenNewContact = one(contactRepo.findContactByOptionalCaptionLike("sixth contact"));
final var givenNewBankAccount = one(bankAccountRepo.findByOptionalHolderLike("first")); final var givenNewBankAccount = one(bankAccountRepo.findByOptionalHolderLike("first"));
final String givenNewVatId = "NEW-VAT-ID"; final String givenNewVatId = "NEW-VAT-ID";
final String givenNewVatCountryCode = "NC"; final String givenNewVatCountryCode = "NC";
@ -332,7 +331,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
givenDebitor.setDebitorRel(HsOfficeRelationRbacEntity.builder() givenDebitor.setDebitorRel(HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.DEBITOR) .type(HsOfficeRelationType.DEBITOR)
.anchor(givenNewPartnerPerson) .anchor(givenNewPartnerPerson)
.holder(givenNewBillingPerson) .holder(givenNewBillingPerson)
@ -611,13 +610,13 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenPartner = one(partnerRepo.findPartnerByOptionalNameLike(partnerName)); final var givenPartner = one(partnerRepo.findPartnerByOptionalNameLike(partnerName));
final var givenPartnerPerson = givenPartner.getPartnerRel().getHolder(); final var givenPartnerPerson = givenPartner.getPartnerRel().getHolder();
final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike(contactCaption)); final var givenContact = one(contactRepo.findContactByOptionalCaptionLike(contactCaption));
final var givenBankAccount = final var givenBankAccount =
bankAccountHolder != null ? one(bankAccountRepo.findByOptionalHolderLike(bankAccountHolder)) : null; bankAccountHolder != null ? one(bankAccountRepo.findByOptionalHolderLike(bankAccountHolder)) : null;
final var newDebitor = HsOfficeDebitorEntity.builder() final var newDebitor = HsOfficeDebitorEntity.builder()
.partner(givenPartner) .partner(givenPartner)
.debitorNumberSuffix("20") .debitorNumberSuffix("20")
.debitorRel(HsOfficeRelationRbacEntity.builder() .debitorRel(HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.DEBITOR) .type(HsOfficeRelationType.DEBITOR)
.anchor(givenPartnerPerson) .anchor(givenPartnerPerson)
.holder(givenPartnerPerson) .holder(givenPartnerPerson)

View File

@ -2,9 +2,9 @@ package net.hostsharing.hsadminng.hs.office.debitor;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareTestEntity.TEST_BARE_CONTACT; import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.TEST_CONTACT;
import static net.hostsharing.hsadminng.hs.office.partner.TestHsOfficePartner.TEST_PARTNER; import static net.hostsharing.hsadminng.hs.office.partner.TestHsOfficePartner.TEST_PARTNER;
@UtilityClass @UtilityClass
@ -14,10 +14,10 @@ public class TestHsOfficeDebitor {
public static final HsOfficeDebitorEntity TEST_DEBITOR = HsOfficeDebitorEntity.builder() public static final HsOfficeDebitorEntity TEST_DEBITOR = HsOfficeDebitorEntity.builder()
.debitorNumberSuffix(DEFAULT_DEBITOR_SUFFIX) .debitorNumberSuffix(DEFAULT_DEBITOR_SUFFIX)
.debitorRel(HsOfficeRelationRbacEntity.builder() .debitorRel(HsOfficeRelationEntity.builder()
.holder(HsOfficePersonEntity.builder().build()) .holder(HsOfficePersonEntity.builder().build())
.anchor(HsOfficePersonEntity.builder().build()) .anchor(HsOfficePersonEntity.builder().build())
.contact(TEST_BARE_CONTACT) .contact(TEST_CONTACT)
.build()) .build())
.partner(TEST_PARTNER) .partner(TEST_PARTNER)
.defaultPrefix("abc") .defaultPrefix("abc")

View File

@ -3,12 +3,11 @@ package net.hostsharing.hsadminng.hs.office.partner;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
@ -48,7 +47,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@Autowired @Autowired
HsOfficeContactBareRepository contactBareRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
JpaAttempt jpaAttempt; JpaAttempt jpaAttempt;
@ -92,7 +91,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow(); final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow();
final var givenPerson = personRepo.findPersonByOptionalNameLike("Third").stream().findFirst().orElseThrow(); final var givenPerson = personRepo.findPersonByOptionalNameLike("Third").stream().findFirst().orElseThrow();
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").stream().findFirst().orElseThrow(); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").stream().findFirst().orElseThrow();
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -180,7 +179,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.post("http://localhost/api/hs/office/partners") .post("http://localhost/api/hs/office/partners")
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(400) .statusCode(400)
.body("message", is("Unable to find " + HsOfficeContactRbacEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID)); .body("message", is("Unable to find " + HsOfficeContactEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID));
// @formatter:on // @formatter:on
} }
@ -189,7 +188,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var mandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); final var mandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -524,9 +523,9 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow(); final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow();
final var givenPerson = personRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow(); final var givenPerson = personRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow();
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow(); final var givenContact = contactRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow();
final var partnerRel = new HsOfficeRelationRbacEntity(); final var partnerRel = new HsOfficeRelationEntity();
partnerRel.setType(HsOfficeRelationType.PARTNER); partnerRel.setType(HsOfficeRelationType.PARTNER);
partnerRel.setAnchor(givenMandantPerson); partnerRel.setAnchor(givenMandantPerson);
partnerRel.setHolder(givenPerson); partnerRel.setHolder(givenPerson);

View File

@ -1,9 +1,9 @@
package net.hostsharing.hsadminng.hs.office.partner; package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
import net.hostsharing.hsadminng.mapper.Mapper; import net.hostsharing.hsadminng.mapper.Mapper;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -69,7 +69,7 @@ class HsOfficePartnerControllerRestTest {
HsOfficePersonEntity personMock; HsOfficePersonEntity personMock;
@Mock @Mock
HsOfficeContactRbacEntity contactMock; HsOfficeContactEntity contactMock;
@Mock @Mock
HsOfficePartnerEntity partnerMock; HsOfficePartnerEntity partnerMock;
@ -83,7 +83,7 @@ class HsOfficePartnerControllerRestTest {
lenient().when(em.getReference(HsOfficePersonEntity.class, GIVEN_MANDANTE_UUID)).thenReturn(mandateMock); lenient().when(em.getReference(HsOfficePersonEntity.class, GIVEN_MANDANTE_UUID)).thenReturn(mandateMock);
lenient().when(em.getReference(HsOfficePersonEntity.class, GIVEN_PERSON_UUID)).thenReturn(personMock); lenient().when(em.getReference(HsOfficePersonEntity.class, GIVEN_PERSON_UUID)).thenReturn(personMock);
lenient().when(em.getReference(HsOfficeContactRbacEntity.class, GIVEN_CONTACT_UUID)).thenReturn(contactMock); lenient().when(em.getReference(HsOfficeContactEntity.class, GIVEN_CONTACT_UUID)).thenReturn(contactMock);
lenient().when(em.getReference(any(), eq(GIVEN_INVALID_UUID))).thenThrow(EntityNotFoundException.class); lenient().when(em.getReference(any(), eq(GIVEN_INVALID_UUID))).thenThrow(EntityNotFoundException.class);
} }
@ -176,7 +176,7 @@ class HsOfficePartnerControllerRestTest {
when(partnerRepo.deleteByUuid(givenPartnerUuid)).thenReturn(0); when(partnerRepo.deleteByUuid(givenPartnerUuid)).thenReturn(0);
final UUID givenRelationUuid = UUID.randomUUID(); final UUID givenRelationUuid = UUID.randomUUID();
when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationRbacEntity.builder() when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationEntity.builder()
.uuid(givenRelationUuid) .uuid(givenRelationUuid)
.build()); .build());
when(relationRepo.deleteByUuid(givenRelationUuid)).thenReturn(0); when(relationRepo.deleteByUuid(givenRelationUuid)).thenReturn(0);

View File

@ -1,6 +1,6 @@
package net.hostsharing.hsadminng.hs.office.partner; package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerDetailsPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerDetailsPatchResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase;
@ -43,8 +43,8 @@ class HsOfficePartnerDetailsEntityPatcherUnitTest extends PatchUnitTestBase<
@BeforeEach @BeforeEach
void initMocks() { void initMocks() {
lenient().when(em.getReference(eq(HsOfficeContactRbacEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation ->
HsOfficeContactRbacEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build());
lenient().when(em.getReference(eq(HsOfficePersonEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficePersonEntity.class), any())).thenAnswer(invocation ->
HsOfficePersonEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficePersonEntity.builder().uuid(invocation.getArgument(1)).build());
} }

View File

@ -1,10 +1,9 @@
package net.hostsharing.hsadminng.hs.office.partner; package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance;
@ -37,7 +36,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
private final HsOfficePersonEntity givenInitialPerson = HsOfficePersonEntity.builder() private final HsOfficePersonEntity givenInitialPerson = HsOfficePersonEntity.builder()
.uuid(INITIAL_PERSON_UUID) .uuid(INITIAL_PERSON_UUID)
.build(); .build();
private final HsOfficeContactBareEntity givenInitialContact = HsOfficeContactBareEntity.builder() private final HsOfficeContactEntity givenInitialContact = HsOfficeContactEntity.builder()
.uuid(INITIAL_CONTACT_UUID) .uuid(INITIAL_CONTACT_UUID)
.build(); .build();
@ -50,7 +49,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
@BeforeEach @BeforeEach
void initMocks() { void initMocks() {
lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation ->
HsOfficeRelationRbacEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeRelationEntity.builder().uuid(invocation.getArgument(1)).build());
} }
@Override @Override
@ -58,7 +57,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
final var entity = HsOfficePartnerEntity.builder() final var entity = HsOfficePartnerEntity.builder()
.uuid(INITIAL_PARTNER_UUID) .uuid(INITIAL_PARTNER_UUID)
.partnerNumber(12345) .partnerNumber(12345)
.partnerRel(HsOfficeRelationRbacEntity.builder() .partnerRel(HsOfficeRelationEntity.builder()
.holder(givenInitialPerson) .holder(givenInitialPerson)
.contact(givenInitialContact) .contact(givenInitialContact)
.build()) .build())
@ -91,7 +90,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
} }
private static HsOfficeRelationEntity newPartnerRel(final UUID uuid) { private static HsOfficeRelationEntity newPartnerRel(final UUID uuid) {
final var newPartnerRel = HsOfficeRelationRbacEntity.builder() final var newPartnerRel = HsOfficeRelationEntity.builder()
.uuid(uuid) .uuid(uuid)
.build(); .build();
return newPartnerRel; return newPartnerRel;

View File

@ -1,9 +1,9 @@
package net.hostsharing.hsadminng.hs.office.partner; package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -13,7 +13,7 @@ class HsOfficePartnerEntityUnitTest {
private final HsOfficePartnerEntity givenPartner = HsOfficePartnerEntity.builder() private final HsOfficePartnerEntity givenPartner = HsOfficePartnerEntity.builder()
.partnerNumber(12345) .partnerNumber(12345)
.partnerRel(HsOfficeRelationRbacEntity.builder() .partnerRel(HsOfficeRelationEntity.builder()
.anchor(HsOfficePersonEntity.builder() .anchor(HsOfficePersonEntity.builder()
.personType(HsOfficePersonType.LEGAL_PERSON) .personType(HsOfficePersonType.LEGAL_PERSON)
.tradeName("Hostsharing eG") .tradeName("Hostsharing eG")
@ -23,7 +23,7 @@ class HsOfficePartnerEntityUnitTest {
.personType(HsOfficePersonType.LEGAL_PERSON) .personType(HsOfficePersonType.LEGAL_PERSON)
.tradeName("some trade name") .tradeName("some trade name")
.build()) .build())
.contact(HsOfficeContactBareEntity.builder().caption("some caption").build()) .contact(HsOfficeContactEntity.builder().caption("some caption").build())
.build()) .build())
.build(); .build();

View File

@ -1,10 +1,9 @@
package net.hostsharing.hsadminng.hs.office.partner; package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
@ -49,7 +48,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@Autowired @Autowired
HsOfficeContactBareRepository contactBareRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
RawRbacObjectRepository rawObjectRepo; RawRbacObjectRepository rawObjectRepo;
@ -110,10 +109,10 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
// when // when
attempt(em, () -> { attempt(em, () -> {
final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").get(0);
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
final var newRelation = HsOfficeRelationRbacEntity.builder() final var newRelation = HsOfficeRelationEntity.builder()
.holder(givenPartnerPerson) .holder(givenPartnerPerson)
.type(HsOfficeRelationType.PARTNER) .type(HsOfficeRelationType.PARTNER)
.anchor(givenMandantPerson) .anchor(givenMandantPerson)
@ -466,9 +465,9 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
private HsOfficeRelationEntity givenSomeTemporaryHostsharingPartnerRel(final String person, final String contact) { private HsOfficeRelationEntity givenSomeTemporaryHostsharingPartnerRel(final String person, final String contact) {
final var givenMandantorPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); final var givenMandantorPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike(person).get(0); final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike(person).get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contact).get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike(contact).get(0);
final var partnerRel = HsOfficeRelationRbacEntity.builder() final var partnerRel = HsOfficeRelationEntity.builder()
.holder(givenPartnerPerson) .holder(givenPartnerPerson)
.type(HsOfficeRelationType.PARTNER) .type(HsOfficeRelationType.PARTNER)
.anchor(givenMandantorPerson) .anchor(givenMandantorPerson)

View File

@ -1,8 +1,8 @@
package net.hostsharing.hsadminng.hs.office.partner; package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGAL_PERSON; import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGAL_PERSON;
@ -15,7 +15,7 @@ public class TestHsOfficePartner {
return HsOfficePartnerEntity.builder() return HsOfficePartnerEntity.builder()
.partnerNumber(10001) .partnerNumber(10001)
.partnerRel( .partnerRel(
HsOfficeRelationRbacEntity.builder() HsOfficeRelationEntity.builder()
.holder(HsOfficePersonEntity.builder() .holder(HsOfficePersonEntity.builder()
.personType(LEGAL_PERSON) .personType(LEGAL_PERSON)
.tradeName("Hostsharing eG") .tradeName("Hostsharing eG")
@ -25,7 +25,7 @@ public class TestHsOfficePartner {
.personType(LEGAL_PERSON) .personType(LEGAL_PERSON)
.tradeName(tradeName) .tradeName(tradeName)
.build()) .build())
.contact(HsOfficeContactBareEntity.builder() .contact(HsOfficeContactEntity.builder()
.caption(tradeName) .caption(tradeName)
.build()) .build())
.build() .build()

View File

@ -2,10 +2,10 @@ package net.hostsharing.hsadminng.hs.office.relation;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationTypeResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationTypeResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
@ -49,7 +49,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@Autowired @Autowired
HsOfficeContactBareRepository contactBareRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
JpaAttempt jpaAttempt; JpaAttempt jpaAttempt;
@ -125,7 +125,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Paul").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Paul").get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("second").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("second").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -172,7 +172,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenAnchorPersonUuid = GIVEN_NON_EXISTING_HOLDER_PERSON_UUID; final var givenAnchorPersonUuid = GIVEN_NON_EXISTING_HOLDER_PERSON_UUID;
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Smith").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Smith").get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -204,7 +204,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -353,7 +353,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenRelation = givenSomeTemporaryRelationBessler(); final var givenRelation = givenSomeTemporaryRelationBessler();
assertThat(givenRelation.getContact().getCaption()).isEqualTo("seventh contact"); assertThat(givenRelation.getContact().getCaption()).isEqualTo("seventh contact");
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
RestAssured // @formatter:off RestAssured // @formatter:off
.given() .given()
@ -455,8 +455,8 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("seventh contact").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("seventh contact").get(0);
final var newRelation = HsOfficeRelationRbacEntity.builder() final var newRelation = HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.REPRESENTATIVE) .type(HsOfficeRelationType.REPRESENTATIVE)
.anchor(givenAnchorPerson) .anchor(givenAnchorPerson)
.holder(givenHolderPerson) .holder(givenHolderPerson)

View File

@ -1,7 +1,6 @@
package net.hostsharing.hsadminng.hs.office.relation; package net.hostsharing.hsadminng.hs.office.relation;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationPatchResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase;
@ -35,8 +34,8 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase<
@BeforeEach @BeforeEach
void initMocks() { void initMocks() {
lenient().when(em.getReference(eq(HsOfficeContactRbacEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation ->
HsOfficeContactRbacEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build());
} }
final HsOfficePersonEntity givenInitialAnchorPerson = HsOfficePersonEntity.builder() final HsOfficePersonEntity givenInitialAnchorPerson = HsOfficePersonEntity.builder()
@ -45,13 +44,13 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase<
final HsOfficePersonEntity givenInitialHolderPerson = HsOfficePersonEntity.builder() final HsOfficePersonEntity givenInitialHolderPerson = HsOfficePersonEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.build(); .build();
final HsOfficeContactBareEntity givenInitialContact = HsOfficeContactBareEntity.builder() final HsOfficeContactEntity givenInitialContact = HsOfficeContactEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.build(); .build();
@Override @Override
protected HsOfficeRelationEntity newInitialEntity() { protected HsOfficeRelationEntity newInitialEntity() {
final var entity = new HsOfficeRelationRbacEntity(); final var entity = new HsOfficeRelationEntity();
entity.setUuid(INITIAL_RELATION_UUID); entity.setUuid(INITIAL_RELATION_UUID);
entity.setType(HsOfficeRelationType.REPRESENTATIVE); entity.setType(HsOfficeRelationType.REPRESENTATIVE);
entity.setAnchor(givenInitialAnchorPerson); entity.setAnchor(givenInitialAnchorPerson);
@ -83,7 +82,9 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase<
); );
} }
static HsOfficeContactBareEntity newContact(final UUID uuid) { static HsOfficeContactEntity newContact(final UUID uuid) {
return HsOfficeContactBareEntity.builder().uuid(uuid).build(); final var newContact = new HsOfficeContactEntity();
newContact.setUuid(uuid);
return newContact;
} }
} }

View File

@ -20,7 +20,7 @@ class HsOfficeRelationEntityUnitTest {
@Test @Test
void toStringReturnsAllProperties() { void toStringReturnsAllProperties() {
final var given = HsOfficeRelationRbacEntity.builder() final var given = HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.SUBSCRIBER) .type(HsOfficeRelationType.SUBSCRIBER)
.mark("members-announce") .mark("members-announce")
.anchor(anchor) .anchor(anchor)
@ -32,7 +32,7 @@ class HsOfficeRelationEntityUnitTest {
@Test @Test
void toShortString() { void toShortString() {
final var given = HsOfficeRelationRbacEntity.builder() final var given = HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.REPRESENTATIVE) .type(HsOfficeRelationType.REPRESENTATIVE)
.anchor(anchor) .anchor(anchor)
.holder(holder) .holder(holder)

View File

@ -1,7 +1,7 @@
package net.hostsharing.hsadminng.hs.office.relation; package net.hostsharing.hsadminng.hs.office.relation;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
@ -40,7 +40,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@Autowired @Autowired
HsOfficeContactBareRepository contactBareRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
RawRbacRoleRepository rawRoleRepo; RawRbacRoleRepository rawRoleRepo;
@ -71,12 +71,12 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Paul").stream() final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Paul").stream()
.filter(p -> p.getPersonType() == NATURAL_PERSON) .filter(p -> p.getPersonType() == NATURAL_PERSON)
.findFirst().orElseThrow(); .findFirst().orElseThrow();
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").stream() final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").stream()
.findFirst().orElseThrow(); .findFirst().orElseThrow();
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newRelation = HsOfficeRelationRbacEntity.builder() final var newRelation = HsOfficeRelationEntity.builder()
.anchor(givenAnchorPerson) .anchor(givenAnchorPerson)
.holder(givenHolderPerson) .holder(givenHolderPerson)
.type(HsOfficeRelationType.SUBSCRIBER) .type(HsOfficeRelationType.SUBSCRIBER)
@ -111,9 +111,9 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Bert").stream() final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Bert").stream()
.filter(p -> p.getPersonType() == NATURAL_PERSON) .filter(p -> p.getPersonType() == NATURAL_PERSON)
.findFirst().orElseThrow(); .findFirst().orElseThrow();
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").stream() final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").stream()
.findFirst().orElseThrow(); .findFirst().orElseThrow();
final var newRelation = HsOfficeRelationRbacEntity.builder() final var newRelation = HsOfficeRelationEntity.builder()
.anchor(givenAnchorPerson) .anchor(givenAnchorPerson)
.holder(givenHolderPerson) .holder(givenHolderPerson)
.type(HsOfficeRelationType.REPRESENTATIVE) .type(HsOfficeRelationType.REPRESENTATIVE)
@ -219,7 +219,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
givenRelation, givenRelation,
"hs_office_person#ErbenBesslerMelBessler:ADMIN"); "hs_office_person#ErbenBesslerMelBessler:ADMIN");
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("sixth contact").stream().findFirst().orElseThrow(); final var givenContact = contactRepo.findContactByOptionalCaptionLike("sixth contact").stream().findFirst().orElseThrow();
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
@ -413,8 +413,8 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike(holderPerson).get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike(holderPerson).get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contact).get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike(contact).get(0);
final var newRelation = HsOfficeRelationRbacEntity.builder() final var newRelation = HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.REPRESENTATIVE) .type(HsOfficeRelationType.REPRESENTATIVE)
.anchor(givenAnchorPerson) .anchor(givenAnchorPerson)
.holder(givenHolderPerson) .holder(givenHolderPerson)