Skip to content

Commit

Permalink
#166 finished backend for diconnection.remove (might contain buggs if…
Browse files Browse the repository at this point in the history
… remove fails due to lissi api)

Signed-off-by: Karol Bakas <karol.bakas@fau.de>
  • Loading branch information
Idontker committed Jun 24, 2022
1 parent 2669109 commit fc9e10f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public ResponseEntity<String> 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");
}
}

Expand All @@ -238,10 +238,17 @@ public ResponseEntity<String> remove(User user) {
}

private ResponseEntity<String> 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.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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<String> 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);
}

/**
Expand Down Expand Up @@ -159,7 +159,7 @@ public ResponseEntity<String> provideExistingSchemas(String activeState, String
String.class);

// check response status code
if (response.getStatusCode() == HttpStatus.OK) {
if (response.getStatusCode().is2xxSuccessful()) {
return response;
} else {
return null;
Expand Down Expand Up @@ -197,7 +197,6 @@ public ResponseEntity<String> provideExistingCredDefs(String activeState, String
activeState = activeState != null ? activeState : "";
searchText = searchText != null ? searchText : "";

// build headers
// build headers
HttpHeaders headers = httpService.createHttpHeader(
MediaType.APPLICATION_JSON,
Expand Down

0 comments on commit fc9e10f

Please sign in to comment.