Skip to content

Commit

Permalink
Fix #177: Internal server error when deleting documents (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanstrobl authored Jun 24, 2024
1 parent 6f04756 commit 15c407a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.wultra.security.userdatastore.client.model.request.EmbeddedAttachmentCreateRequest;
import com.wultra.security.userdatastore.client.model.request.EmbeddedPhotoCreateRequest;
import com.wultra.security.userdatastore.model.error.RequestValidationException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.net.MalformedURLException;
Expand All @@ -35,6 +36,7 @@
*
* @author Roman Strobl, [email protected]
*/
@Slf4j
public class DocumentRequestValidator {

final ObjectMapper mapper = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public Response updateDocument(final String documentId, final DocumentUpdateRequ

@Transactional
public void deleteDocuments(final String userId, final Optional<String> documentId) {
photoService.deletePhotos(userId, documentId);
attachmentService.deleteAttachments(userId, documentId);
if (documentId.isPresent()) {
int count = documentRepository.deleteAllByUserIdAndId(userId, documentId.get());
if (count == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ void testPostComposite() throws Exception {
assertEquals(1, response.attachments().size());
}

@Test
void testDeleteComposite() throws Exception {
final List<EmbeddedPhotoCreateRequest> photos = List.of(new EmbeddedPhotoCreateRequest("test_type", "dGVzdF9kYXRh", null));
List<EmbeddedAttachmentCreateRequest> attachments = new ArrayList<>();
attachments.add(new EmbeddedAttachmentCreateRequest("test_type", "test_data", null));
DocumentCreateRequest request = new DocumentCreateRequest("alice", "test", "test_type", "1", null, "test_data", Collections.emptyMap(), photos, attachments);
DocumentCreateResponse response = restClient.createDocument(request);

DocumentResponse documentResponse = restClient.fetchDocuments("alice", response.id());
assertEquals(1, documentResponse.documents().size());

restClient.deleteDocuments("alice", response.id());
assertThrows(UserDataStoreClientException.class, () -> restClient.fetchDocuments("alice", response.id()));
}

@Test
void testLifeCycle() throws Exception {
DocumentCreateRequest request = new DocumentCreateRequest("alice", "test_type", "test_data_type", "1", null, "test_data", Collections.emptyMap(), Collections.emptyList(), Collections.emptyList());
Expand Down

0 comments on commit 15c407a

Please sign in to comment.