fix fixme's for credentials error messages
This commit is contained in:
		| @@ -5,6 +5,7 @@ import java.util.UUID; | ||||
|  | ||||
| import io.micrometer.core.annotation.Timed; | ||||
| import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||||
| import net.hostsharing.hsadminng.config.MessageTranslator; | ||||
| import net.hostsharing.hsadminng.context.Context; | ||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.api.CredentialsApi; | ||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.CredentialsInsertResource; | ||||
| @@ -17,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.http.ResponseEntity; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
|  | ||||
| import jakarta.persistence.EntityNotFoundException; | ||||
|  | ||||
| @RestController | ||||
| @SecurityRequirement(name = "casTicket") | ||||
| public class HsCredentialsController implements CredentialsApi { | ||||
| @@ -30,6 +33,9 @@ public class HsCredentialsController implements CredentialsApi { | ||||
|     @Autowired | ||||
|     private StrictMapper mapper; | ||||
|  | ||||
|     @Autowired | ||||
|     private MessageTranslator messageTranslator; | ||||
|  | ||||
|     @Autowired | ||||
|     private HsOfficePersonRbacRepository personRepo; | ||||
|  | ||||
| @@ -56,7 +62,12 @@ public class HsCredentialsController implements CredentialsApi { | ||||
|     ) { | ||||
|         context.assumeRoles(assumedRoles); | ||||
|  | ||||
|         final var person = personRepo.findByUuid(personUuid).orElseThrow(); // FIXME: use proper exception | ||||
|         final var person = personRepo.findByUuid(personUuid).orElseThrow( | ||||
|                 () -> new EntityNotFoundException( | ||||
|                         messageTranslator.translate("{0} \"{1}\" not found or not accessible", "personUuid", personUuid) | ||||
|                 ) | ||||
|  | ||||
|         ); // FIXME: use proper exception | ||||
|         final var credentials = credentialsRepo.findByPerson(person); | ||||
|         final var result = mapper.mapList(credentials, CredentialsResource.class); | ||||
|         return ResponseEntity.ok(result); | ||||
| @@ -96,7 +107,7 @@ public class HsCredentialsController implements CredentialsApi { | ||||
|  | ||||
|         final var current = credentialsRepo.findByUuid(credentialsUuid).orElseThrow(); | ||||
|  | ||||
|         new HsCredentialsEntityPatcher(em, current).apply(body); | ||||
|         new HsCredentialsEntityPatcher(em, messageTranslator, current).apply(body); | ||||
|  | ||||
|         final var saved = credentialsRepo.save(current); | ||||
|         final var mapped = mapper.map(saved, CredentialsResource.class); | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package net.hostsharing.hsadminng.credentials; | ||||
|  | ||||
| import net.hostsharing.hsadminng.config.MessageTranslator; | ||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.ContextResource; | ||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.CredentialsPatchResource; | ||||
| import net.hostsharing.hsadminng.mapper.EntityPatcher; | ||||
| @@ -14,10 +15,12 @@ import java.util.stream.Collectors; | ||||
| public class HsCredentialsEntityPatcher implements EntityPatcher<CredentialsPatchResource> { | ||||
|  | ||||
|     private final EntityManager em; | ||||
|     private MessageTranslator messageTranslator; | ||||
|     private final HsCredentialsEntity entity; | ||||
|  | ||||
|     public HsCredentialsEntityPatcher(final EntityManager em, final HsCredentialsEntity entity) { | ||||
|     public HsCredentialsEntityPatcher(final EntityManager em, MessageTranslator messageTranslator, final HsCredentialsEntity entity) { | ||||
|         this.em = em; | ||||
|         this.messageTranslator = messageTranslator; | ||||
|         this.entity = entity; | ||||
|     } | ||||
|  | ||||
| @@ -57,14 +60,15 @@ public class HsCredentialsEntityPatcher implements EntityPatcher<CredentialsPatc | ||||
|             if (!entityUuids.contains(resource.getUuid())) { | ||||
|                 final var existingContextEntity = em.find(HsCredentialsContextRealEntity.class, resource.getUuid()); | ||||
|                 if ( existingContextEntity == null ) { | ||||
|                     // FIXME: i18n | ||||
|                     throw new EntityNotFoundException( | ||||
|                             HsCredentialsContextRealEntity.class.getName() + " with uuid " + resource.getUuid() + " not found."); | ||||
|                             messageTranslator.translate("{0} \"{1}\" not found or not accessible", | ||||
|                                     "credentials uuid", resource.getUuid())); | ||||
|                 } | ||||
|                 if (!existingContextEntity.getType().equals(resource.getType()) && | ||||
|                     !existingContextEntity.getQualifier().equals(resource.getQualifier())) { | ||||
|                     // FIXME: i18n | ||||
|                     throw new EntityNotFoundException("existing " +  existingContextEntity + " does not match given resource " + resource); | ||||
|                     throw new EntityNotFoundException( | ||||
|                             messageTranslator.translate("existing {0} does not match given resource {1}", | ||||
|                                     existingContextEntity, resource)); | ||||
|                 } | ||||
|                 entities.add(existingContextEntity); | ||||
|             } | ||||
|   | ||||
| @@ -12,6 +12,9 @@ unknown\ authorization\ ticket=unbekanntes Autorisierungs-Ticket | ||||
| {0}\ "{1}"\ not\ found\ or\ not\ accessible={0} "{1}" nicht gefunden oder nicht zugänglich | ||||
| but\ is=ist aber | ||||
|  | ||||
| # credentials validations | ||||
| existing\ {0}\ does\ not\ match\ given\ resource\ {1}=existierender Credentials-Context {0} passt nicht zum angegebenen {1} | ||||
|  | ||||
| # office.coop-shares | ||||
| for\ transactionType\={0},\ shareCount\ must\ be\ positive\ but\ is\ {1}=für transactionType={0}, muss shareCount positiv sein, ist aber {1} | ||||
| for\ transactionType\={0},\ shareCount\ must\ be\ negative\ but\ is\ {1}=für transactionType={0}, muss shareCount negativ sein, ist aber {1} | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package net.hostsharing.hsadminng.credentials; | ||||
|  | ||||
| import net.hostsharing.hsadminng.config.MessageTranslator; | ||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.ContextResource; | ||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.CredentialsPatchResource; | ||||
| import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; | ||||
| @@ -19,6 +20,7 @@ import java.util.stream.Stream; | ||||
| import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; | ||||
| import static org.mockito.ArgumentMatchers.eq; | ||||
| import static org.mockito.Mockito.lenient; | ||||
| import static org.mockito.Mockito.mock; | ||||
|  | ||||
| @TestInstance(PER_CLASS) | ||||
| @ExtendWith(MockitoExtension.class) | ||||
| @@ -115,7 +117,7 @@ class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase< | ||||
|  | ||||
|     @Override | ||||
|     protected HsCredentialsEntityPatcher createPatcher(final HsCredentialsEntity entity) { | ||||
|         return new HsCredentialsEntityPatcher(em, entity); | ||||
|         return new HsCredentialsEntityPatcher(em, mock(MessageTranslator.class), entity); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
		Reference in New Issue
	
	Block a user