Skip to content

Commit

Permalink
Merge pull request #7 from smartSenseSolutions/chore/CGD-445-remove-d…
Browse files Browse the repository at this point in the history
…elete-vc-endpoint

feat: CGD-445: Delete VC api removed
  • Loading branch information
nitin-vavdiya authored Aug 17, 2023
2 parents 477759b + 4a8b870 commit d614510
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,61 +345,4 @@ public ResponseEntity<PageImpl<VerifiableCredential>> getCredentials(@Parameter(
public ResponseEntity<VerifiableCredential> issueCredential(@RequestBody Map<String, Object> data, Principal principal) {
return ResponseEntity.status(HttpStatus.CREATED).body(holdersCredentialService.issueCredential(data, getBPNFromToken(principal)));
}

/**
* Delete credential response entity.
*
* @param credentialId the credential id
* @param principal the principal
* @return the response entity
*/
@ApiResponse(responseCode = "404", description = "Wallet not found with caller BPN or Credential id not found", content = {@Content(examples = {
@ExampleObject(name = "Wallet not found with caller BPN", value = """
{
"type": "about:blank",
"title": "Wallet not found for identifier did:web:localhost:BPNL0000000501",
"status": 404,
"detail": "Wallet not found for identifier did:web:localhost:BPNL0000000501",
"instance": "/api/wallets/did%3Aweb%3Alocalhost%3ABPNL0000000501",
"properties": {
"timestamp": 1689764377224
}
}
"""),
@ExampleObject(name = "Credential id not found", value = """
{
"type": "about:blank",
"title": "Credential ID: did:web:localhost:BPNL000000000000#319a2641-9407-4c39-bf51-a4a109b59604 is not exists ",
"status": 404,
"detail": "Credential ID: did:web:localhost:BPNL000000000000#319a2641-9407-4c39-bf51-a4a109b59604 is not exists ",
"instance": "/api/credentials",
"properties": {
"timestamp": 1689774732385
}
}
""")
})})
@ApiResponse(responseCode = "204", description = "Credential deleted", content = {@Content(examples = {})})
@ApiResponse(responseCode = "401", description = "The request could not be completed due to a failed authorization.", content = {@Content(examples = {})})
@ApiResponse(responseCode = "403", description = "The request could not be completed due to a forbidden access", content = {@Content(examples = {})})
@ApiResponse(responseCode = "500", description = "Any other internal server error", content = {@Content(examples = {
@ExampleObject(name = "Internal server error", value = """
{
"type": "about:blank",
"title": "Error Title",
"status": 500,
"detail": "Error Details",
"instance": "API endpoint",
"properties": {
"timestamp": 1689762476720
}
}
""")
})})
@Operation(description = "Permission: **update_wallet** (The BPN of holderIdentifier must equal BPN of caller)\n\n Delete a verifiable credential by its ID", summary = "Delete a verifiable credential by its ID")
@DeleteMapping(path = RestURI.CREDENTIALS, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> deleteCredential(@Parameter(name = "id", description = "Credential Id", examples = {@ExampleObject(name = "Credential Id", value = "did:web:localhost:BPNL000000000000#319a2641-9407-4c39-bf51-a4a109b59604")}) @RequestParam(name = "id") String credentialId, Principal principal) {
holdersCredentialService.deleteCredential(credentialId, getBPNFromToken(principal));
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.smartsensesolutions.java.commons.base.repository.BaseRepository;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.HoldersCredential;
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

Expand Down Expand Up @@ -71,15 +70,6 @@ public interface HoldersCredentialRepository extends BaseRepository<HoldersCrede
*/
boolean existsByHolderDidAndType(String holderDid, String type);

/**
* Delete by credential id.
*
* @param credentialId the credential id
*/
@Modifying
@Query("delete from HoldersCredential where credentialId=:credentialId")
void deleteByCredentialId(@Param("credentialId") String credentialId);

/**
* Exists by holder did and credential id boolean.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -170,25 +167,6 @@ public VerifiableCredential issueCredential(Map<String, Object> data, String cal
return credential.getData();
}

/**
* Delete credential.
*
* @param credentialId the credential id
* @param bpnFromToken the bpn from token
*/
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED)
public void deleteCredential(String credentialId, String bpnFromToken) {
//Fetch Holder Wallet
Wallet holderWallet = commonService.getWalletByIdentifier(bpnFromToken);

//check credential exp
isCredentialExistWithId(holderWallet.getDid(), credentialId);

//remove credential
holdersCredentialRepository.deleteByCredentialId(credentialId);
log.debug("VC deleted with id ->{} of bpn ->{}", StringEscapeUtils.escapeJava(credentialId), StringEscapeUtils.escapeJava(holderWallet.getBpn()));
}

private void isCredentialExistWithId(String holderDid, String credentialId) {
Validate.isFalse(holdersCredentialRepository.existsByHolderDidAndCredentialId(holderDid, credentialId)).launch(new CredentialNotFoundProblem("Credential ID: " + credentialId + " is not exists "));
}
Expand Down

This file was deleted.

0 comments on commit d614510

Please sign in to comment.