replace HsHostingContactEntity with HsOfficeContactEntity
This commit is contained in:
parent
cb29730810
commit
1ba760e9a9
@ -8,7 +8,6 @@ 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.hosting.contact.HsHostingContactEntity;
|
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||||
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;
|
||||||
@ -100,7 +99,7 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject {
|
|||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "alarmcontactuuid")
|
@JoinColumn(name = "alarmcontactuuid")
|
||||||
private HsHostingContactEntity 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")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||||
|
|
||||||
import net.hostsharing.hsadminng.hs.hosting.contact.HsHostingContactEntity;
|
|
||||||
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.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;
|
||||||
@ -28,7 +28,7 @@ public class HsHostingAssetEntityPatcher implements EntityPatcher<HsHostingAsset
|
|||||||
.ifPresent(r -> entity.getConfig().patch(KeyValueMap.from(resource.getConfig())));
|
.ifPresent(r -> entity.getConfig().patch(KeyValueMap.from(resource.getConfig())));
|
||||||
OptionalFromJson.of(resource.getAlarmContactUuid()).ifPresent(newValue -> {
|
OptionalFromJson.of(resource.getAlarmContactUuid()).ifPresent(newValue -> {
|
||||||
verifyNotNull(newValue, "alarmContact");
|
verifyNotNull(newValue, "alarmContact");
|
||||||
entity.setAlarmContact(em.getReference(HsHostingContactEntity.class, newValue));
|
entity.setAlarmContact(em.getReference(HsOfficeContactEntity.class, newValue));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
package net.hostsharing.hsadminng.hs.hosting.contact;
|
|
||||||
|
|
||||||
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
|
||||||
import lombok.*;
|
|
||||||
import lombok.experimental.FieldNameConstants;
|
|
||||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
|
||||||
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
|
|
||||||
import net.hostsharing.hsadminng.stringify.Stringify;
|
|
||||||
import net.hostsharing.hsadminng.stringify.Stringifyable;
|
|
||||||
import org.hibernate.annotations.Type;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "hs_office_contact_rv")
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@FieldNameConstants
|
|
||||||
@DisplayName("Contact")
|
|
||||||
public class HsHostingContactEntity implements Stringifyable, RbacObject {
|
|
||||||
|
|
||||||
private static Stringify<HsHostingContactEntity> toString = stringify(HsHostingContactEntity.class, "contact")
|
|
||||||
.withProp(HsHostingContactEntity.Fields.caption, HsHostingContactEntity::getCaption)
|
|
||||||
.withProp(HsHostingContactEntity.Fields.emailAddresses, HsHostingContactEntity::getEmailAddresses);
|
|
||||||
|
|
||||||
@Id
|
|
||||||
private UUID uuid;
|
|
||||||
|
|
||||||
@Version
|
|
||||||
private int version;
|
|
||||||
|
|
||||||
@Column(name = "caption")
|
|
||||||
private String caption;
|
|
||||||
|
|
||||||
@Builder.Default
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
@Type(JsonType.class)
|
|
||||||
@Column(name = "emailaddresses")
|
|
||||||
private Map<String, String> emailAddresses = new HashMap<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return toString.apply(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toShortString() {
|
|
||||||
return caption;
|
|
||||||
}
|
|
||||||
}
|
|
@ -477,7 +477,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
|||||||
assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isPresent().get()
|
assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isPresent().get()
|
||||||
.matches(asset -> {
|
.matches(asset -> {
|
||||||
assertThat(asset.getAlarmContact().toString()).isEqualTo(
|
assertThat(asset.getAlarmContact().toString()).isEqualTo(
|
||||||
"contact(caption='second contact', emailAddresses='{main=contact-admin@secondcontact.example.com}')");
|
"contact(caption='second contact', emailAddresses='{ main: contact-admin@secondcontact.example.com }')");
|
||||||
assertThat(asset.getConfig().toString()).isEqualTo(
|
assertThat(asset.getConfig().toString()).isEqualTo(
|
||||||
"{ monit_max_cpu_usage: 90, monit_max_ram_usage: 70, monit_max_ssd_usage: 85, monit_min_free_ssd: 5 }");
|
"{ monit_max_cpu_usage: 90, monit_max_ram_usage: 70, monit_max_ssd_usage: 85, monit_min_free_ssd: 5 }");
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||||
|
|
||||||
import net.hostsharing.hsadminng.hs.hosting.contact.HsHostingContactEntity;
|
|
||||||
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.HsOfficeContactEntity;
|
||||||
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;
|
||||||
@ -48,7 +48,7 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
|
|||||||
entry("SSD", 256),
|
entry("SSD", 256),
|
||||||
entry("MEM", 64)
|
entry("MEM", 64)
|
||||||
);
|
);
|
||||||
final HsHostingContactEntity givenInitialContact = HsHostingContactEntity.builder()
|
final HsOfficeContactEntity givenInitialContact = HsOfficeContactEntity.builder()
|
||||||
.uuid(UUID.randomUUID())
|
.uuid(UUID.randomUUID())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@ -60,12 +60,10 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void initMocks() {
|
void initMocks() {
|
||||||
// lenient().when(em.getReference(eq(HsOfficeDebitorEntity.class), any())).thenAnswer(invocation ->
|
|
||||||
// HsOfficeDebitorEntity.builder().uuid(invocation.getArgument(1)).build());
|
|
||||||
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(HsHostingContactEntity.class), any())).thenAnswer(invocation ->
|
lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation ->
|
||||||
HsHostingContactEntity.builder().uuid(invocation.getArgument(1)).build());
|
HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -114,7 +112,7 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static HsHostingContactEntity newContact(final UUID uuid) {
|
static HsOfficeContactEntity newContact(final UUID uuid) {
|
||||||
return HsHostingContactEntity.builder().uuid(uuid).build();
|
return HsOfficeContactEntity.builder().uuid(uuid).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package net.hostsharing.hsadminng.hs.hosting.contact;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
class HsHostingContactEntityUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toStringReturnsNullForNullContact() {
|
|
||||||
final HsHostingContactEntity givenContact = null;
|
|
||||||
assertThat("" + givenContact).isEqualTo("null");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toStringReturnsCaption() {
|
|
||||||
final var givenContact = HsHostingContactEntity.builder().caption("given caption").build();
|
|
||||||
assertThat("" + givenContact).isEqualTo("contact(caption='given caption')");
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user