Skip to content

Commit

Permalink
feat: change the passport api to data
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Brunkow Moser committed Oct 16, 2023
1 parent 4a9baf8 commit 82cc2be
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ Response index() throws Exception {
* @return this {@code Response} HTTP response with status.
*
*/
@RequestMapping(value = "/passport", method = {RequestMethod.POST})
@Operation(summary = "Returns versioned product passport by id", responses = {
@RequestMapping(value = "/data", method = {RequestMethod.POST})
@Operation(summary = "Returns the data negotiated and transferred", responses = {
@ApiResponse(description = "Default Response Structure", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Response.class))),
@ApiResponse(description = "Content of Data Field in Response", responseCode = "200", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = PassportResponse.class))),
})
public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) {
public Response getData(@Valid @RequestBody TokenRequest tokenRequestBody) {
Response response = httpUtil.getInternalError();

// Check for authentication
Expand Down Expand Up @@ -169,13 +169,13 @@ public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) {
return httpUtil.buildResponse(response, httpResponse);
}

if (!status.historyExists("passport-received")) {
response = httpUtil.getNotFound("The passport is not available!");
if (!status.historyExists("data-received")) {
response = httpUtil.getNotFound("The data is not available!");
return httpUtil.buildResponse(response, httpResponse);
}

if (status.historyExists("passport-retrieved")) {
response = httpUtil.getNotFound("The passport was already retrieved and is no longer available!");
if (status.historyExists("data-retrieved")) {
response = httpUtil.getNotFound("The data was already retrieved and is no longer available!");
return httpUtil.buildResponse(response, httpResponse);
}
String semanticId = status.getSemanticId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public Response cancel(@Valid @RequestBody TokenRequest tokenRequestBody) {
return httpUtil.buildResponse(response, httpResponse);
}

if (status.getStatus().equals("COMPLETED") || status.getStatus().equals("RETRIEVED") || status.historyExists("transfer-request") || status.historyExists("transfer-completed") || status.historyExists("passport-received") || status.historyExists("passport-retrieved")) {
if (status.getStatus().equals("COMPLETED") || status.getStatus().equals("RETRIEVED") || status.historyExists("transfer-request") || status.historyExists("transfer-completed") || status.historyExists("data-received") || status.historyExists("data-retrieved")) {
response = httpUtil.getForbiddenResponse("This negotiation can not be canceled! It was already transferred!");
return httpUtil.buildResponse(response, httpResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ public String saveProcessPayload(String processId, Object payload, String fileNa
this.setStatus(processId, eventKey, history);
String path = this.getProcessFilePath(processId, fileName);
String returnPath = "";
if(eventKey.equals("passport-received") && encrypt) {
if(eventKey.equals("data-received") && encrypt) {
returnPath = fileUtil.toFile(path, payload.toString(), false);
}else {
returnPath = jsonUtil.toJsonFile(path, payload, processConfig.getIndent());
Expand Down Expand Up @@ -1239,7 +1239,7 @@ public JsonNode loadPassport(String processId){
LogUtil.printStatus("[PROCESS " + processId +"] Failed to delete passport file!");
}

this.setStatus(processId,"passport-retrieved", history);
this.setStatus(processId,"data-retrieved", history);
return passport;
} catch (Exception e) {
throw new ManagerException(this.getClass().getName(), e, "It was not possible to load the passport!");
Expand Down Expand Up @@ -1285,7 +1285,7 @@ public String savePassport(String processId, DataPlaneEndpoint endpointData, Jso
this.passportFileName,
endpointData.getId(),
"RECEIVED",
"passport-received");
"data-received");
} catch (Exception e) {
throw new ManagerException(this.getClass().getName(), e, "It was not possible to save the digital product passport!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,9 @@ public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin) {
SubModel3 subModel = null;
// Search for first subModel with matching semanticId, if it fails gives null
for (String semanticId: passportConfig.getAspects()) {
subModel = subModels.stream().filter(s -> s.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase(submodelTypeKey) && k.getValue().equalsIgnoreCase(semanticId)) != null).findFirst().orElse(null);
subModel = subModels.stream().filter(s -> s.getSemanticId().getKeys().stream().anyMatch(
k -> (k.getType().equalsIgnoreCase(submodelTypeKey) && k.getValue().equalsIgnoreCase(semanticId))
)).findFirst().orElse(null);
if (subModel != null) {
return subModel; // Return subModel if found
}
Expand All @@ -627,15 +629,15 @@ public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin) {
* <p>
* @param digitalTwin
* the {@code DigitalTwin3} object with its submodels.
* @param semanticId
* @param aspectSemanticId
* the {@code String} semantic id of the intended submodel.
*
* @return a {@code Submodel3} object with the submodel found, if exists.
*
* @throws ServiceException
* if unable to find a the {@code Submodel3} for the given semantic id.
*/
public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin, String semanticId) {
public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin, String aspectSemanticId) {
try {
ArrayList<SubModel3> subModels = digitalTwin.getSubmodelDescriptors();
if (subModels.size() < 1) {
Expand All @@ -644,7 +646,10 @@ public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin, String seman
}
SubModel3 subModel = null;
// Search for first subModel with matching semanticId, if it fails gives null
subModel = subModels.stream().filter(s -> s.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase(submodelTypeKey) && k.getValue().equalsIgnoreCase(semanticId)) != null).findFirst().orElse(null);
subModel = subModels.stream().filter(
s -> s.getSemanticId().getKeys().stream().anyMatch(
k -> (k.getType().equalsIgnoreCase(submodelTypeKey) && k.getValue().equalsIgnoreCase(aspectSemanticId))
)).findFirst().orElse(null);
if (subModel != null) {
return subModel; // Return subModel if found
}
Expand Down Expand Up @@ -1000,9 +1005,12 @@ public DecentralDigitalTwinRegistryQueryById(Search search, DataPlaneEndpoint ed
@Override
public void run() {
this.setDigitalTwin(searchDigitalTwin3(this.getIdType(), this.getAssetId(), this.getDtIndex(), this.getEdr().getEndpoint(), this.getEdr()));
LogUtil.printMessage("SemanticId = ["+this.semanticId+"] and " +this.getSemanticId());
if(this.semanticId == null || this.semanticId.isEmpty()){
LogUtil.printMessage("Searching with Defaults Params");
this.setSubModel(searchSubModel3BySemanticId(this.getDigitalTwin()));
}else {
LogUtil.printMessage("Searching with Semantic ID");
this.setSubModel(searchSubModel3BySemanticId(this.getDigitalTwin(), this.semanticId));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/general/LoadingComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
(statusData.data.history['transfer-request']
? this.stepsNames.contractTransfer.progressValue
: 0) +
(statusData.data.history['passport-received']
(statusData.data.history['data-received']
? this.stepsNames.passportRetrieval.progressValue
: 0)
"
Expand Down Expand Up @@ -116,7 +116,7 @@
/>
<!-- Passport Retrieval step -->
<StepperItem
:condition="statusData.data.history['passport-received']"
:condition="statusData.data.history['data-received']"
:stepTitle="this.stepsNames.passportRetrieval.stepTitle"
:successStepSubTitle="
this.stepsNames.passportRetrieval.successStepSubtitle
Expand Down

0 comments on commit 82cc2be

Please sign in to comment.