improve-performance-of-office-data-import #83
@ -46,6 +46,6 @@ public class CustomErrorResponse {
|
||||
this.path = path;
|
||||
this.statusCode = status.value();
|
||||
this.statusPhrase = status.getReasonPhrase();
|
||||
this.message = message;
|
||||
this.message = message.startsWith("ERROR: [") ? message : "ERROR: [" + statusCode + "] " + message;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package net.hostsharing.hsadminng.errors;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DisplayAs {
|
||||
class DisplayName {
|
||||
public static String of(final Class<?> clazz) {
|
||||
final var displayNameAnnot = clazz.getAnnotation(DisplayAs.class);
|
||||
return displayNameAnnot != null ? displayNameAnnot.value() : clazz.getSimpleName();
|
||||
}
|
||||
|
||||
public static String of(@NotNull final Object instance) {
|
||||
return of(instance.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
String value() default "";
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package net.hostsharing.hsadminng.errors;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DisplayName {
|
||||
String value() default "";
|
||||
}
|
@ -152,8 +152,8 @@ public class RestResponseEntityExceptionHandler
|
||||
final var entityName = matcher.group(1);
|
||||
final var entityClass = resolveClass(entityName);
|
||||
if (entityClass.isPresent()) {
|
||||
return (entityClass.get().isAnnotationPresent(DisplayName.class)
|
||||
? exceptionMessage.replace(entityName, entityClass.get().getAnnotation(DisplayName.class).value())
|
||||
return (entityClass.get().isAnnotationPresent(DisplayAs.class)
|
||||
? exceptionMessage.replace(entityName, entityClass.get().getAnnotation(DisplayAs.class).value())
|
||||
: exceptionMessage.replace(entityName, entityClass.get().getSimpleName()))
|
||||
.replace(" with id ", " with uuid ");
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.stringify.Stringify;
|
||||
import net.hostsharing.hsadminng.stringify.Stringifyable;
|
||||
|
||||
@ -23,7 +23,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("BookingDebitor")
|
||||
@DisplayAs("BookingDebitor")
|
||||
public class HsBookingDebitorEntity implements Stringifyable {
|
||||
|
||||
public static final String DEBITOR_NUMBER_TAG = "D-";
|
||||
|
@ -55,7 +55,6 @@ 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;
|
||||
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
|
||||
@Builder
|
||||
@Entity
|
||||
|
@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.bankaccount;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
import net.hostsharing.hsadminng.stringify.Stringify;
|
||||
@ -26,7 +26,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@FieldNameConstants
|
||||
@DisplayName("BankAccount")
|
||||
@DisplayAs("BankAccount")
|
||||
public class HsOfficeBankAccountEntity implements BaseEntity<HsOfficeBankAccountEntity>, Stringifyable {
|
||||
|
||||
private static Stringify<HsOfficeBankAccountEntity> toString = stringify(HsOfficeBankAccountEntity.class, "bankAccount")
|
||||
|
@ -9,7 +9,7 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.mapper.PatchableMapWrapper;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity;
|
||||
import net.hostsharing.hsadminng.stringify.Stringify;
|
||||
@ -36,7 +36,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@AllArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@FieldNameConstants
|
||||
@DisplayName("Contact")
|
||||
@DisplayAs("Contact")
|
||||
public class HsOfficeContact implements Stringifyable, BaseEntity<HsOfficeContact> {
|
||||
|
||||
private static Stringify<HsOfficeContact> toString = stringify(HsOfficeContact.class, "contact")
|
||||
|
@ -3,9 +3,8 @@ 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 net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
@ -16,7 +15,7 @@ import jakarta.persistence.Table;
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@DisplayName("BareContact")
|
||||
@DisplayAs("BareContact")
|
||||
public class HsOfficeContactBareEntity extends HsOfficeContact {
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
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.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
|
||||
|
||||
@ -22,7 +21,7 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor;
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@DisplayName("RbacContact")
|
||||
@DisplayAs("RbacContact")
|
||||
public class HsOfficeContactRbacEntity extends HsOfficeContact {
|
||||
|
||||
public static RbacView rbac() {
|
||||
|
@ -6,7 +6,7 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
@ -40,7 +40,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("CoopAssetsTransaction")
|
||||
@DisplayAs("CoopAssetsTransaction")
|
||||
public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseEntity<HsOfficeCoopAssetsTransactionEntity> {
|
||||
|
||||
private static Stringify<HsOfficeCoopAssetsTransactionEntity> stringify = stringify(HsOfficeCoopAssetsTransactionEntity.class)
|
||||
|
@ -5,7 +5,7 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity;
|
||||
@ -38,7 +38,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("CoopShareTransaction")
|
||||
@DisplayAs("CoopShareTransaction")
|
||||
public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, BaseEntity<HsOfficeCoopSharesTransactionEntity> {
|
||||
|
||||
private static Stringify<HsOfficeCoopSharesTransactionEntity> stringify = stringify(HsOfficeCoopSharesTransactionEntity.class)
|
||||
|
@ -18,11 +18,12 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.validation.ValidationException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.errors.DisplayAs.DisplayName;
|
||||
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.DEBITOR;
|
||||
|
||||
@RestController
|
||||
@ -92,7 +93,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
||||
final var debitorRelOptional = relBareRepo.findByUuid(body.getDebitorRelUuid());
|
||||
debitorRelOptional.ifPresentOrElse(
|
||||
debitorRel -> {entityToSave.setDebitorRel(relBareRepo.save(debitorRel));},
|
||||
() -> { throw new EntityNotFoundException("ERROR: [400] debitorRelUuid not found: " + body.getDebitorRelUuid());});
|
||||
() -> { throw new ValidationException("Unable to find BareRelation by debitorRelUuid: " + body.getDebitorRelUuid());});
|
||||
}
|
||||
|
||||
final var savedEntity = debitorRepo.save(entityToSave);
|
||||
@ -164,7 +165,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
||||
private <T extends BaseEntity<T>> T validateEntityExists(final String property, final T entitySkeleton) {
|
||||
final var foundEntity = em.find(entitySkeleton.getClass(), entitySkeleton.getUuid());
|
||||
if ( foundEntity == null) {
|
||||
throw new EntityNotFoundException("ERROR: [400] " + property + " not found: " + entitySkeleton.getUuid());
|
||||
throw new ValidationException("Unable to find " + DisplayName.of(entitySkeleton) + " by " + property + ": " + entitySkeleton.getUuid());
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
|
@ -5,7 +5,7 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
|
||||
@ -59,7 +59,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@Builder(toBuilder = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("Debitor")
|
||||
@DisplayAs("Debitor")
|
||||
public class HsOfficeDebitorEntity implements BaseEntity<HsOfficeDebitorEntity>, Stringifyable {
|
||||
|
||||
public static final String DEBITOR_NUMBER_TAG = "D-";
|
||||
|
@ -7,7 +7,7 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
|
||||
@ -61,7 +61,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("Membership")
|
||||
@DisplayAs("Membership")
|
||||
public class HsOfficeMembershipEntity implements BaseEntity<HsOfficeMembershipEntity>, Stringifyable {
|
||||
|
||||
public static final String MEMBER_NUMBER_TAG = "M-";
|
||||
|
@ -9,7 +9,6 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartne
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerResource;
|
||||
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.relation.HsOfficeRelation;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.office.partner;
|
||||
|
||||
import lombok.*;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
|
||||
@ -25,7 +25,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("PartnerDetails")
|
||||
@DisplayAs("PartnerDetails")
|
||||
public class HsOfficePartnerDetailsEntity implements BaseEntity<HsOfficePartnerDetailsEntity>, Stringifyable {
|
||||
|
||||
private static Stringify<HsOfficePartnerDetailsEntity> stringify = stringify(
|
||||
|
@ -5,7 +5,7 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContact;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
|
||||
@ -41,7 +41,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("Partner")
|
||||
@DisplayAs("Partner")
|
||||
public class HsOfficePartnerEntity implements Stringifyable, BaseEntity<HsOfficePartnerEntity> {
|
||||
|
||||
public static final String PARTNER_NUMBER_TAG = "P-";
|
||||
|
@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.person;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
|
||||
@ -29,7 +29,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@FieldNameConstants
|
||||
@DisplayName("Person")
|
||||
@DisplayAs("Person")
|
||||
public class HsOfficePersonEntity implements BaseEntity<HsOfficePersonEntity>, Stringifyable {
|
||||
|
||||
private static Stringify<HsOfficePersonEntity> toString = stringify(HsOfficePersonEntity.class, "person")
|
||||
|
@ -4,7 +4,7 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
@ -16,6 +16,6 @@ import jakarta.persistence.Table;
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@DisplayName("BareRelation")
|
||||
@DisplayAs("BareRelation")
|
||||
public class HsOfficeRelationBareEntity extends HsOfficeRelation {
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
@ -39,7 +39,7 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor;
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@DisplayName("RbacRelation")
|
||||
@DisplayAs("RbacRelation")
|
||||
public class HsOfficeRelationRbacEntity extends HsOfficeRelation {
|
||||
|
||||
public static RbacView rbac() {
|
||||
|
@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.sepamandate;
|
||||
import io.hypersistence.utils.hibernate.type.range.PostgreSQLRangeType;
|
||||
import io.hypersistence.utils.hibernate.type.range.Range;
|
||||
import lombok.*;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
|
||||
@ -39,7 +39,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("SEPA-Mandate")
|
||||
@DisplayAs("SEPA-Mandate")
|
||||
public class HsOfficeSepaMandateEntity implements Stringifyable, BaseEntity<HsOfficeSepaMandateEntity> {
|
||||
|
||||
private static Stringify<HsOfficeSepaMandateEntity> stringify = stringify(HsOfficeSepaMandateEntity.class)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.hostsharing.hsadminng.mapper;
|
||||
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@ -13,6 +12,8 @@ import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.hostsharing.hsadminng.errors.DisplayAs.DisplayName;
|
||||
|
||||
/**
|
||||
* A nicer API for ModelMapper.
|
||||
*/
|
||||
@ -74,9 +75,7 @@ public class Mapper extends ModelMapper {
|
||||
if (entity != null) {
|
||||
return entity;
|
||||
}
|
||||
final var displayNameAnnot = entityClass.getAnnotation(DisplayName.class);
|
||||
final var displayName = displayNameAnnot != null ? displayNameAnnot.value() : entityClass.getSimpleName();
|
||||
throw new ValidationException(displayName + " not found: " + subEntityUuid);
|
||||
throw new ValidationException("Unable to find " + DisplayName.of(entityClass) + " by uuid: " + subEntityUuid);
|
||||
}
|
||||
|
||||
public <S, T> T map(final S source, final Class<T> targetClass, final BiConsumer<S, T> postMapper) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.stringify;
|
||||
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
@ -46,7 +46,7 @@ public final class Stringify<B> {
|
||||
if (name != null) {
|
||||
this.name = name;
|
||||
} else {
|
||||
final var displayName = clazz.getAnnotation(DisplayName.class);
|
||||
final var displayName = clazz.getAnnotation(DisplayAs.class);
|
||||
if (displayName != null) {
|
||||
this.name = displayName.value();
|
||||
} else {
|
||||
|
@ -84,6 +84,7 @@ public class ArchitectureTest {
|
||||
@ArchTest
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule dontUseImplSuffix = noClasses()
|
||||
.that().areNotPrivate() // e.g. Lombok SuperBuilder generated classes
|
||||
.should().haveSimpleNameEndingWith("Impl");
|
||||
|
||||
@ArchTest
|
||||
|
@ -40,7 +40,7 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(409);
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("First Line");
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("ERROR: [409] First Line");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -59,7 +59,7 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(400);
|
||||
assertThat(errorResponse.getBody()).isNotNull()
|
||||
.extracting(CustomErrorResponse::getMessage).isEqualTo("Second Line");
|
||||
.extracting(CustomErrorResponse::getMessage).isEqualTo("ERROR: [400] Second Line");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -91,7 +91,7 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(400);
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("Unable to find Partner with uuid 12345-123454");
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("ERROR: [400] Unable to find Partner with uuid 12345-123454");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -109,7 +109,7 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(400);
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo(
|
||||
"Unable to find net.hostsharing.hsadminng.WhateverEntity with id 12345-123454");
|
||||
"ERROR: [400] Unable to find net.hostsharing.hsadminng.WhateverEntity with id 12345-123454");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -125,7 +125,7 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(400);
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("whatever error message");
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("ERROR: [400] whatever error message");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -143,7 +143,7 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(400);
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("Unable to find NoDisplayNameEntity with uuid 12345-123454");
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("ERROR: [400] Unable to find NoDisplayNameEntity with uuid 12345-123454");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -172,7 +172,7 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(404);
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("some error message");
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("ERROR: [404] some error message");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ -191,7 +191,7 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(400);
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("given error message");
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("ERROR: [400] given error message");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -218,7 +218,8 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
.extracting("statusCode").isEqualTo(400);
|
||||
assertThat(errorResponse.getBody())
|
||||
.extracting("message")
|
||||
.isEqualTo("[someField expected to be something but is \"someRejectedValue\"]");
|
||||
// FYI: the brackets around the message are here because it's actually an array, in this case of size 1
|
||||
.isEqualTo("ERROR: [400] [someField expected to be something but is \"someRejectedValue\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -232,7 +233,7 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(500);
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("First Line");
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("ERROR: [500] First Line");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -120,7 +120,7 @@ class HsOfficeCoopSharesTransactionControllerRestTest {
|
||||
.andExpect(status().is4xxClientError())
|
||||
.andExpect(jsonPath("statusCode", is(400)))
|
||||
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
||||
.andExpect(jsonPath("message", is(testCase.expectedErrorMessage)));
|
||||
.andExpect(jsonPath("message", is("ERROR: [400] " + testCase.expectedErrorMessage)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.post("http://localhost/api/hs/office/debitors")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(400)
|
||||
.body("message", is("ERROR: [400] debitorRel.contactUuid not found: 00000000-0000-0000-0000-000000000000"));
|
||||
.body("message", is("ERROR: [400] Unable to find BareContact by debitorRel.contactUuid: 00000000-0000-0000-0000-000000000000"));
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@ -433,7 +433,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.post("http://localhost/api/hs/office/debitors")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(400)
|
||||
.body("message", is("BareRelation not found: 00000000-0000-0000-0000-000000000000"));
|
||||
.body("message", is("ERROR: [400] Unable to find BareRelation by uuid: 00000000-0000-0000-0000-000000000000"));
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,8 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
.andExpect(status().is4xxClientError())
|
||||
.andExpect(jsonPath("statusCode", is(400)))
|
||||
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
||||
.andExpect(jsonPath("message", is("[partnerUuid must not be null but is \"null\"]")));
|
||||
// FYI: the brackets around the message are here because it's actually an array, in this case of size 1
|
||||
.andExpect(jsonPath("message", is("ERROR: [400] [partnerUuid must not be null but is \"null\"]")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -114,7 +115,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
.andExpect(status().is4xxClientError())
|
||||
.andExpect(jsonPath("statusCode", is(400)))
|
||||
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
||||
.andExpect(jsonPath("message", is("Partner not found: " + givenPartnerUuid)));
|
||||
.andExpect(jsonPath("message", is("ERROR: [400] Unable to find Partner by uuid: " + givenPartnerUuid)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
@ -180,7 +180,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.post("http://localhost/api/hs/office/partners")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(400)
|
||||
.body("message", is("Unable to find " + HsOfficeContactBareEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID));
|
||||
.body("message", is("ERROR: [400] Unable to find " + HsOfficeContactBareEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID));
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@ -218,7 +218,10 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.post("http://localhost/api/hs/office/partners")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(400)
|
||||
.body("message", is("Unable to find " + HsOfficePersonEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID));
|
||||
// TODO.impl: we want this error message:
|
||||
// .body("message", is("ERROR: [400] Unable to find Person by uuid: " + GIVEN_NON_EXISTING_UUID));
|
||||
// but ModelMapper creates this error message:
|
||||
.body("message", is("ERROR: [400] Unable to find " + HsOfficePersonEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID));
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
.post("http://localhost/api/hs/office/sepamandates")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(400)
|
||||
.body("message", is("BankAccount not found: 00000000-0000-0000-0000-000000000000"));
|
||||
.body("message", is("ERROR: [400] Unable to find BankAccount by uuid: 00000000-0000-0000-0000-000000000000"));
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
.post("http://localhost/api/hs/office/sepamandates")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(400)
|
||||
.body("message", is("Debitor not found: 00000000-0000-0000-0000-000000000000"));
|
||||
.body("message", is("ERROR: [400] Unable to find Debitor by uuid: 00000000-0000-0000-0000-000000000000"));
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.hostsharing.hsadminng.rbac.test;
|
||||
|
||||
import lombok.*;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.mapper.Mapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@ -88,7 +88,7 @@ class MapperUnitTest {
|
||||
);
|
||||
|
||||
assertThat(exception).isInstanceOf(ValidationException.class)
|
||||
.hasMessage("Unable to find SubTargetBean1 with uuid " + GIVEN_UUID);
|
||||
.hasMessage("Unable to find SubTargetBean1 by uuid: " + GIVEN_UUID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -101,7 +101,7 @@ class MapperUnitTest {
|
||||
);
|
||||
|
||||
assertThat(exception).isInstanceOf(ValidationException.class)
|
||||
.hasMessage("Unable to find SomeDisplayName with uuid " + GIVEN_UUID);
|
||||
.hasMessage("Unable to find SomeDisplayName by uuid: " + GIVEN_UUID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -217,7 +217,7 @@ class MapperUnitTest {
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("SomeDisplayName")
|
||||
@DisplayAs("SomeDisplayName")
|
||||
public static class SubTargetBean2 {
|
||||
|
||||
private UUID uuid;
|
||||
|
@ -175,7 +175,8 @@ class TestCustomerControllerAcceptanceTest {
|
||||
.statusCode(403)
|
||||
.contentType(ContentType.JSON)
|
||||
.statusCode(403)
|
||||
.body("message", containsString("insert into test_customer not allowed for current subjects {test_customer#xxx:ADMIN}"));
|
||||
.body("message", containsString("ERROR: [403] insert into test_customer "))
|
||||
.body("message", containsString(" not allowed for current subjects {test_customer#xxx:ADMIN}"));
|
||||
// @formatter:on
|
||||
|
||||
// finally, the new customer was not created
|
||||
@ -204,7 +205,8 @@ class TestCustomerControllerAcceptanceTest {
|
||||
.statusCode(403)
|
||||
.contentType(ContentType.JSON)
|
||||
.statusCode(403)
|
||||
.body("message", containsString("ERROR: [403] insert into test_customer not allowed for current subjects {customer-admin@yyy.example.com}"));
|
||||
.body("message", containsString("ERROR: [403] insert into test_customer "))
|
||||
.body("message", containsString(" not allowed for current subjects"));
|
||||
// @formatter:on
|
||||
|
||||
// finally, the new customer was not created
|
||||
|
Loading…
Reference in New Issue
Block a user