Skip to content

Commit

Permalink
feat: finalized dpp-verification backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Brunkow Moser committed Jun 21, 2024
1 parent 5816453 commit 4eda84c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,19 @@ public Response endpoint(@RequestBody Object body, @PathVariable String processI
if(!verificationConfig.getEnabled() || !verificationConfig.getAutoVerify()){
return this.savePassport(processId, endpointData, passport);
}
verificationManager.setVerificationStarted(processId);

VerificationInfo verificationInfo = status.getVerification();
if(verificationInfo.vc){

verificationInfo = verificationManager.buildVerification(passport, verificationInfo);
// If is not enabled to be verified
if(!verificationInfo.vc){
return this.savePassport(processId, endpointData, passport);
}

// Verify aspect
verificationManager.setVerificationStarted(processId);
verificationInfo = verificationManager.buildVerification(passport, verificationInfo);
verificationInfo = verificationManager.setupVerification(verificationInfo, passport);
verificationManager.setVerificationInfo(processId, verificationInfo);

return this.savePassport(processId, endpointData, passport);
} catch (Exception e) {
LogUtil.printException(e, "This request is not allowed! It must contain the valid attributes from an EDC endpoint");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ public Response getDataCall (HttpServletRequest httpRequest, HttpServletResponse
if(verificationConfig.getEnabled()) {
responseData.put(
"verification",
verificationManager.setupVerification(status.getVerification(), passport)
status.getVerification()
);
}
response.data = responseData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.commons.logging.Log;
import org.eclipse.tractusx.digitalproductpass.core.config.ProcessConfig;
import org.eclipse.tractusx.digitalproductpass.core.exceptions.ManagerException;
import org.eclipse.tractusx.digitalproductpass.core.managers.ProcessManager;
Expand Down Expand Up @@ -92,6 +93,9 @@ public String setVerificationStatus(String processId, SubModel subModel, String
if(vc == null){
throw new ManagerException(this.getClass().getName(), "No configuration available for the verification process!");
}
if(vc){
LogUtil.printMessage("[DPP VERIFICATION ADD-ON] [PROCESS "+processId+"] Verifiable Credential Aspect Found in subModel ["+ subModel.getIdentification()+"]!");
}
String path = processManager.getProcessFilePath(processId, processManager.metaFileName);
Status statusFile = null;
if (!fileUtil.pathExists(path)) {
Expand Down Expand Up @@ -134,6 +138,8 @@ public String setVerificationStarted(String processId) {
if (!fileUtil.pathExists(path)) {
throw new ManagerException(this.getClass().getName(), "Process file does not exists for id ["+processId+"]!");
}

LogUtil.printMessage("[DPP VERIFICATION ADD-ON] [PROCESS "+ processId+"] Verification Started for Data Aspect Received from EDC!");
History history = new History(
processId,
"VERIFYING",
Expand Down Expand Up @@ -172,6 +178,12 @@ public String setVerificationInfo(String processId, VerificationInfo verificatio
if (!fileUtil.pathExists(path)) {
throw new ManagerException(this.getClass().getName(), "Process file does not exists for id ["+processId+"]!");
}

if(verificationInfo.verified){
LogUtil.printMessage("[DPP VERIFICATION ADD-ON] [PROCESS "+ processId+"] [VERIFIED] The Data Aspect was verified Successfully!");
}else{
LogUtil.printMessage("[DPP VERIFICATION ADD-ON] [PROCESS "+ processId+"] [VERIFICATION FAILED] The Data Aspect was not able to be verified!");
}
History history = new History(
processId,
verificationInfo.verified?"VERIFIED":"UNVERIFIED",
Expand Down Expand Up @@ -205,11 +217,11 @@ public Boolean isVerifiableCredential(SubModel subModel){

List<SubModel.SemanticId.Key> semanticIds = semanticId.getKeys();

return semanticIds.stream().parallel().allMatch(key -> this.isKeyInKeys(key, keys));
return keys.stream().parallel().allMatch(semanticKey -> this.isKeyInKeys(semanticKey, semanticIds));
}

public Boolean isKeyInKeys(SubModel.SemanticId.Key key, List<CDCConfig.SemanticKey> keys){
return keys.stream().parallel().anyMatch(semanticKey -> key.getType().equals(semanticKey.getKey()) && key.getValue().equals(semanticKey.getValue()));
public Boolean isKeyInKeys(CDCConfig.SemanticKey key, List<SubModel.SemanticId.Key> keys){
return keys.stream().parallel().anyMatch(semanticKey -> key.getKey().equals(semanticKey.getType()) && key.getValue().equals(semanticKey.getValue()));
}

public VerificationInfo setupVerification(VerificationInfo verificationInfo, JsonNode passport){
Expand Down

0 comments on commit 4eda84c

Please sign in to comment.