Skip to content

Commit

Permalink
feat: updated credential get api
Browse files Browse the repository at this point in the history
  • Loading branch information
thackerronak committed Jun 5, 2023
1 parent 813ce33 commit c6e2af4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation "org.springdoc:springdoc-openapi-starter-common:${openApiVersion}"
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${openApiVersion}"
implementation group: 'com.smartsensesolutions', name: 'commons-dao', version: '0.0.2'
implementation group: 'com.smartsensesolutions', name: 'commons-dao', version: '0.0.5'
implementation 'org.liquibase:liquibase-core'
implementation 'org.eclipse.tractusx.ssi.lib:cx-ssi-lib:0.0.4'
runtimeOnly 'org.postgresql:postgresql'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public ResponseEntity<VerifiableCredential> issueFrameworkCredential(@Valid @Req
"issuanceDate": "2019-06-16T18:56:59Z",
"expirationDate": "2019-06-17T18:56:59Z",
"credentialSubject": {
"college": "Test-University"
"college": "org.eclipse.tractusx.managedidentitywallets.Test-University"
},
"proof": {
"type": "Ed25519Signature2018",
Expand Down Expand Up @@ -171,14 +171,7 @@ public ResponseEntity<Map<String, Object>> credentialsValidation(@RequestBody Ma
"issuanceDate": "2019-06-16T18:56:59Z",
"expirationDate": "2019-06-17T18:56:59Z",
"credentialSubject": {
"college": "Test-University"
},
"proof": {
"type": "Ed25519Signature2018",
"created": "2021-11-17T22:20:27Z",
"proofPurpose": "assertionMethod",
"verificationMethod": "did:example:76e12ec712ebc6f1c221ebfeb1f#keys-1",
"jws": "eyJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCJdLCJhbGciOiJFZERTQSJ9..JNerzfrK46Mq4XxYZEnY9xOK80xsEaWCLAHuZsFie1-NTJD17wWWENn_DAlA_OwxGF5dhxUJ05P6Dm8lcmF5Cg"
"college": "org.eclipse.tractusx.managedidentitywallets.Test-University"
}
}
"""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.smartsensesolutions.java.commons.FilterRequest;
import com.smartsensesolutions.java.commons.base.repository.BaseRepository;
import com.smartsensesolutions.java.commons.base.service.BaseService;
import com.smartsensesolutions.java.commons.criteria.CriteriaOperator;
import com.smartsensesolutions.java.commons.operator.Operator;
import com.smartsensesolutions.java.commons.sort.Sort;
import com.smartsensesolutions.java.commons.sort.SortType;
Expand All @@ -51,8 +52,6 @@
import org.eclipse.tractusx.ssi.lib.proof.LinkedDataProofValidation;
import org.eclipse.tractusx.ssi.lib.resolver.DidDocumentResolverRegistryImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -122,34 +121,38 @@ protected SpecificationUtil<Credential> getSpecificationUtil() {
*/
public List<VerifiableCredential> getCredentials(String credentialId, String issuerIdentifier, List<String> type, String sortColumn, String sortType, String callerBPN) {
FilterRequest filterRequest = new FilterRequest();

filterRequest.setPage(0);
filterRequest.setSize(1000);

Wallet holderWallet = walletService.getWalletByIdentifier(callerBPN);
filterRequest.appendNewCriteria("holderDid", Operator.EQUALS, holderWallet.getDid());
filterRequest.appendCriteria("holderDid", Operator.EQUALS, holderWallet.getDid());

if (StringUtils.hasText(issuerIdentifier)) {
Wallet issuerWallet = walletService.getWalletByIdentifier(issuerIdentifier);
filterRequest.appendNewCriteria("issuerDid", Operator.EQUALS, issuerWallet.getDid());
filterRequest.appendCriteria("issuerDid", Operator.EQUALS, issuerWallet.getDid());
}

if (StringUtils.hasText(credentialId)) {
filterRequest.appendNewCriteria("credentialId", Operator.EQUALS, credentialId);
filterRequest.appendCriteria("credentialId", Operator.EQUALS, credentialId);
}
Specification<Credential> sps = getSpecificationUtil().generateSpecification(filterRequest.getCriteria());
// Specification<Credential> sps = getSpecificationUtil().generateSpecification(filterRequest.getCriteria());
FilterRequest request = new FilterRequest();
if (!CollectionUtils.isEmpty(type)) {
request.setPage(filterRequest.getPage());
request.setSize(filterRequest.getSize());
request.setCriteriaOperator(CriteriaOperator.OR);
for (String str : type) {
request.appendNewCriteria("type", Operator.CONTAIN, str);
request.appendCriteria("type", Operator.CONTAIN, str);
}
Specification<Credential> sp = getSpecificationUtil().generateOrSpecification(request.getCriteria());
sps = sp.and(sps);
// Specification<Credential> sp = getSpecificationUtil().generateOrSpecification(request.getCriteria());
// sps = sp.and(sps);
}

Sort sort = new Sort();
sort.setColumn(sortColumn);
sort.setSortType(SortType.valueOf(sortType.toUpperCase()));
filterRequest.setSort(sort);
Page<Credential> filter = getRepository().findAll(sps, PageRequest.of(0, 1000));
Page<Credential> filter = filter(filterRequest, request, CriteriaOperator.AND);

List<VerifiableCredential> list = new ArrayList<>(filter.getContent().size());
for (Credential credential : filter.getContent()) {
Expand Down

0 comments on commit c6e2af4

Please sign in to comment.