Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better-duplicated-schema-error-msg #324

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ public <T> ResponseEntity<T> executeMediaRequest(String url, HttpMethod method,
responseType);
} catch (RestClientException e) {
e.printStackTrace();

// TODO: imporve hack (implemented only due to time issues and for the demo day)
if (e.getMessage() != null && e.getMessage().contains("Schema already exists on ledger")
&& responseType.equals(String.class)) {
try {
String msg = e.getMessage().split("\"message\":")[1]; // = "error msg", "details": "..."}
msg = msg.split("\"")[1];// = error msg
return (ResponseEntity<T>) ResponseEntity.status(400).body(msg);
} catch (Exception exception) {
exception.printStackTrace();
return null;
}
}
return null;
}
// log response
Expand Down Expand Up @@ -119,6 +132,7 @@ public <T> ResponseEntity<T> executeJsonRequest(String url, HttpMethod method, C
responseType);
} catch (RestClientException e) {
e.printStackTrace();

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.util.Pair;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
Expand All @@ -38,21 +39,20 @@ public class LissiApiService {
public ResponseEntity<ConnectionsResponse> provideExistingConnections() {
String url = baseUrl + "/ctrl/api/v1.0/connections";


ResponseEntity<ConnectionsResponse> response = httpService.executeUriRequest(url, HttpMethod.GET,
ConnectionsResponse.class, Pair.of("size", "100"));

if (handleResponse(response) == null) {
return null;
return null;
}

int pages = response.getBody().getTotalPages();
for (int i = 1; i < pages; i++) {
ResponseEntity<ConnectionsResponse> furtherResponse = httpService.executeUriRequest(url, HttpMethod.GET,
ConnectionsResponse.class, Pair.of("page", Integer.toString(i)), Pair.of("size", "100"));
List<ConnectionContent> content = response.getBody().getContent();
content.addAll(furtherResponse.getBody().getContent());
response.getBody().setContent(content);
ResponseEntity<ConnectionsResponse> furtherResponse = httpService.executeUriRequest(url, HttpMethod.GET,
ConnectionsResponse.class, Pair.of("page", Integer.toString(i)), Pair.of("size", "100"));
List<ConnectionContent> content = response.getBody().getContent();
content.addAll(furtherResponse.getBody().getContent());
response.getBody().setContent(content);
}

return response;
Expand Down Expand Up @@ -104,6 +104,12 @@ public ResponseEntity<String> createSchema(String alias, String imageUri, String
Pair.of("version", version),
Pair.of("attributes", attributes));

// handle duplicated schema error
if (response.getStatusCode().equals(HttpStatus.BAD_REQUEST)
&& response.getBody().contains("Schema already exists on ledger")) {
return response;
}

// check response status code
return handleResponse(response);
}
Expand Down Expand Up @@ -171,15 +177,15 @@ public ResponseEntity<PagedCredentialAnswer> getAllCredentials(String credential

String onlyIssuedString = "false";
if (onlyIssued) {
onlyIssuedString = "true";
onlyIssuedString = "true";
}

if (credentialDefinitionId == "") {
ResponseEntity<PagedCredentialAnswer> response = httpService.executeUriRequest(url, HttpMethod.GET,
PagedCredentialAnswer.class,
Pair.of("page", page),
Pair.of("size", size),
Pair.of("issued", onlyIssuedString));
Pair.of("page", page),
Pair.of("size", size),
Pair.of("issued", onlyIssuedString));
return handleResponse(response);
}

Expand Down Expand Up @@ -324,7 +330,8 @@ public ResponseEntity<String> getAllProofs(String proofTemplateId, String page,
return handleResponse(response);
}

public ResponseEntity<PagedProofAnswer> getAllOpenProofsByConnectionId(String connectionId, String page, String size) {
public ResponseEntity<PagedProofAnswer> getAllOpenProofsByConnectionId(String connectionId, String page,
String size) {
String url = baseUrl + "/ctrl/api/v1.0/presentation-proof";

ResponseEntity<PagedProofAnswer> response = httpService.executeUriRequest(url, HttpMethod.GET,
Expand Down Expand Up @@ -358,32 +365,29 @@ private <T> ResponseEntity<T> handleResponse(ResponseEntity<T> response) {
}
}

public ResponseEntity<String> getCredentialDiOverview(String connectionId,
public ResponseEntity<String> getCredentialDiOverview(String connectionId,
String page, String size) {
String url = baseUrl + "/ctrl/api/v1.0/credentials";
String url = baseUrl + "/ctrl/api/v1.0/credentials";

ResponseEntity<String> response = httpService.executeUriRequest(url, HttpMethod.GET,
String.class,
Pair.of("connectionId", connectionId),
Pair.of("page", page),
Pair.of("size", size));
ResponseEntity<String> response = httpService.executeUriRequest(url, HttpMethod.GET,
String.class,
Pair.of("connectionId", connectionId),
Pair.of("page", page),
Pair.of("size", size));

return handleResponse(response);
return handleResponse(response);
}

public ResponseEntity<String> getProofDiOverview(String connectionId,
public ResponseEntity<String> getProofDiOverview(String connectionId,
String page, String size) {
String url = baseUrl + "/ctrl/api/v1.0/presentation-proof";
String url = baseUrl + "/ctrl/api/v1.0/presentation-proof";

ResponseEntity<String> response = httpService.executeUriRequest(url, HttpMethod.GET,
String.class,
Pair.of("connectionId", connectionId),
Pair.of("page", page),
Pair.of("size", size));
ResponseEntity<String> response = httpService.executeUriRequest(url, HttpMethod.GET,
String.class,
Pair.of("connectionId", connectionId),
Pair.of("page", page),
Pair.of("size", size));

return handleResponse(response);
return handleResponse(response);
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public ResponseEntity<String> createSchema(String alias,

if (response == null) {
return ResponseEntity.status(500).body("Could not create a new schema.");
} else if (!response.getStatusCode().is2xxSuccessful()) {
return response;
}
return ResponseEntity.status(201).body(response.getBody());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ErrorMessageService {
openHttpErrorDialog(error: HttpErrorResponse) {
let data = {
header: 'Process failed!',
text: 'Error ' + error.status + ' \n' + error.error,
text: 'Error ' + error.status + ':\n' + error.error,
};

if (error.status == 401) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
.container{
.container {
color: #3D474F;
min-width: 600px;
min-height: 300px
}

div .close-button{
div .close-button {
display: flex;
justify-content: flex-end;
}

div .head-modal{
div .head-modal {
display: flex;
justify-content: center;
text-align: center;
}

div .head-modal h2{
div .head-modal h2 {
font-size: 1.8em !important;
}

div .body-modal{
div .body-modal {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
text-align: center;
}

div .body-modal .fail, div .body-modal .check{
div .body-modal .fail, div .body-modal .check {
transform: scale(2.5);
margin-top: 30px;
}

div .body-modal .fail{
div .body-modal .fail {
color: #ff6b6b;
}

div .body-modal .check{
div .body-modal .check {
color: #1dd1a1;
}

pre {
white-space: inherit;
white-space: break-spaces;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ <h2 mat-header>{{ header }}</h2>

<div class="body-modal">
<pre mat-content>{{ text }}</pre>

<button mat-icon-button (click)="close()">
<mat-icon class="check" *ngIf="isSuccessData">check_circle</mat-icon>
<mat-icon class="fail" *ngIf="!isSuccessData">cancel</mat-icon>
</button>
<p>
<button mat-icon-button (click)="close()">
<mat-icon class="check" *ngIf="isSuccessData">check_circle</mat-icon>
<mat-icon class="fail" *ngIf="!isSuccessData">cancel</mat-icon>
</button>
</p>
</div>
</div>