diff --git a/src/digitalIdentity-backend/src/main/java/didentity/amos/digitalIdentity/services/DIConnectionService.java b/src/digitalIdentity-backend/src/main/java/didentity/amos/digitalIdentity/services/DIConnectionService.java index 984e13da..b70348f3 100644 --- a/src/digitalIdentity-backend/src/main/java/didentity/amos/digitalIdentity/services/DIConnectionService.java +++ b/src/digitalIdentity-backend/src/main/java/didentity/amos/digitalIdentity/services/DIConnectionService.java @@ -226,7 +226,7 @@ public ResponseEntity remove(Integer id) { if (user.isPresent()) { return remove(user.get()); } else { - return ResponseEntity.status(200).body("Successfully removed connection."); + return ResponseEntity.status(200).body("Nothing to do. Connection was not found"); } } @@ -238,10 +238,17 @@ public ResponseEntity remove(User user) { } private ResponseEntity remove(User user, boolean removeCreds, boolean removeProofs) { + if (userRepository.findById(user.getId()).isPresent() == false) { + return ResponseEntity.status(200).body("Nothing to do. Connection was not found"); + } userRepository.delete(user); - // TODO: - lissiApiService.removeConnection(user.getConnectionId(), removeCreds, + + String response = lissiApiService.removeConnection(user.getConnectionId(), removeCreds, removeProofs); + if (response == null) { + userRepository.save(user); + return ResponseEntity.status(500).body("Could not remove the connection on the lissi legder."); + } return ResponseEntity.status(200).body("Successfully removed connection."); } diff --git a/src/digitalIdentity-backend/src/main/java/didentity/amos/digitalIdentity/services/LissiApiService.java b/src/digitalIdentity-backend/src/main/java/didentity/amos/digitalIdentity/services/LissiApiService.java index 320fa30a..bc61226a 100644 --- a/src/digitalIdentity-backend/src/main/java/didentity/amos/digitalIdentity/services/LissiApiService.java +++ b/src/digitalIdentity-backend/src/main/java/didentity/amos/digitalIdentity/services/LissiApiService.java @@ -89,23 +89,23 @@ public CreateConnectionResponse createConnectionInvitation(String alias) throws @SuppressWarnings("unchecked") // TODO: if someone wants to bother with generic arrays, feel free :) public String removeConnection(String connectionID, boolean removeCreds, boolean removeProofs) { - String url = baseUrl + "/" + connectionID + "/remove"; - String rmCreds = removeCreds ? "true" : "false"; - String rmProofs = removeProofs ? "true" : "false"; + String url = baseUrl + "/ctrl/api/v1.0/connections/" + connectionID + "/remove"; - HttpHeaders headers = httpService.createHttpHeader(MediaType.APPLICATION_JSON); + // build headers + HttpHeaders headers = httpService.createHttpHeader(MediaType.MULTIPART_FORM_DATA); // build body LinkedMultiValueMap body = httpService.createHttpBody( - Pair.of("removeCreds", rmCreds), - Pair.of("removeProofs", rmProofs)); + Pair.of("removeCreds", "false"), + Pair.of("removeProofs", "false")); if (body == null) { return null; } - - // build the request - - return httpService.postForObject(url, new HttpEntity<>(body, headers), String.class); + ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(body, headers), + String.class); + return response.getStatusCode().toString(); + // return httpService.postForObject(url, new HttpEntity<>(body, headers), + // String.class); } /** @@ -159,7 +159,7 @@ public ResponseEntity provideExistingSchemas(String activeState, String String.class); // check response status code - if (response.getStatusCode() == HttpStatus.OK) { + if (response.getStatusCode().is2xxSuccessful()) { return response; } else { return null; @@ -197,7 +197,6 @@ public ResponseEntity provideExistingCredDefs(String activeState, String activeState = activeState != null ? activeState : ""; searchText = searchText != null ? searchText : ""; - // build headers // build headers HttpHeaders headers = httpService.createHttpHeader( MediaType.APPLICATION_JSON,