Skip to content

Commit

Permalink
fix: Update File Value events
Browse files Browse the repository at this point in the history
  • Loading branch information
ShehriyarShariq-Fraunhofer committed Dec 3, 2024
1 parent 86ffb23 commit c84de43
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This feature provides hierarchical MQTT eventing for a multitude of events:
| SubmodelElement Updated | sm-repository/$repoId/submodels/$submodelIdBase64URLEncoded/submodelElements/$idShortPath/updated | Updated SubmodelElement JSON |
| SubmodelElement Deleted | sm-repository/$repoId/submodels/$submodelIdBase64URLEncoded/submodelElements/$idShortPath/deleted | Deleted SubmodelElement JSON |
| SubmodelElements Patched | sm-repository/$repoId/submodels/$submodelIdBase64URLEncoded/submodelElements/patched | Patched SubmodelElements JSON |
| FileValue Updated | sm-repository/$repoId/submodels/$submodelIdBase64URLEncoded/submodelElements/$idShortPath/fileValue/$fileName/updated | Updated SubmodelElement JSON |
| FileValue Deleted | sm-repository/$repoId/submodels/$submodelIdBase64URLEncoded/submodelElements/$idShortPath/fileValue/deleted | Deleted SubmodelElement JSON |
| FileValue Updated | sm-repository/$repoId/submodels/$submodelIdBase64URLEncoded/submodelElements/$idShortPath/attachment/updated | Updated SubmodelElement JSON |
| FileValue Deleted | sm-repository/$repoId/submodels/$submodelIdBase64URLEncoded/submodelElements/$idShortPath/attachment/deleted | Deleted SubmodelElement JSON |

Per default, the SubmodelElement topic payloads include the SubmodelElement's value. If this is not desired, the SubmodelElement can be annotated with a Qualifier of type *emptyValueUpdateEvent* and value *true*
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void deleteFileValue(String identifier, String idShortPath) {
public void setFileValue(String submodelId, String idShortPath, String fileName, InputStream inputStream){
decorated.setFileValue(submodelId, idShortPath, fileName, inputStream);
SubmodelElement submodelElement = decorated.getSubmodelElement(submodelId, idShortPath);
fileValueUpdated(submodelElement, getName(), submodelId, idShortPath, fileName);
fileValueUpdated(submodelElement, getName(), submodelId, idShortPath);
}

@Override
Expand Down Expand Up @@ -210,8 +210,8 @@ private void fileValueDeleted(SubmodelElement submodelElement, String repoId, St
sendMqttMessage(topicFactory.createDeleteFileValueTopic(repoId, submodelId, submodelElementId), SubmodelElementSerializer.serializeSubmodelElement(submodelElement));
}

private void fileValueUpdated(SubmodelElement submodelElement, String repoId, String submodelId, String submodelElementId, String fileName) {
sendMqttMessage(topicFactory.createUpdateFileValueTopic(repoId, submodelId, submodelElementId, fileName), SubmodelElementSerializer.serializeSubmodelElement(submodelElement));
private void fileValueUpdated(SubmodelElement submodelElement, String repoId, String submodelId, String submodelElementId) {
sendMqttMessage(topicFactory.createUpdateFileValueTopic(repoId, submodelId, submodelElementId), SubmodelElementSerializer.serializeSubmodelElement(submodelElement));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class MqttSubmodelRepositoryTopicFactory extends AbstractMqttTopicFactory
private static final String DELETED = "deleted";
private static final String PATCHED = "patched";
private static final String SUBMODELELEMENTS = "submodelElements";
private static final String FILEVALUE = "fileValue";
private static final String ATTACHMENT = "attachment";

/**
* @param encoder
Expand Down Expand Up @@ -124,7 +124,7 @@ public String createPatchSubmodelElementsTopic(String repoId, String submodelId)
*
*/
public String createDeleteFileValueTopic(String repoId, String submodelId, String submodelElementId) {
return new StringJoiner("/", "", "").add(SUBMODELREPOSITORY).add(repoId).add(SUBMODELS).add(encodeId(submodelId)).add(SUBMODELELEMENTS).add(submodelElementId).add(FILEVALUE).add(DELETED).toString();
return new StringJoiner("/", "", "").add(SUBMODELREPOSITORY).add(repoId).add(SUBMODELS).add(encodeId(submodelId)).add(SUBMODELELEMENTS).add(submodelElementId).add(ATTACHMENT).add(DELETED).toString();
}

/**
Expand All @@ -133,7 +133,7 @@ public String createDeleteFileValueTopic(String repoId, String submodelId, Strin
* @param repoId
*
*/
public String createUpdateFileValueTopic(String repoId, String submodelId, String submodelElementId, String fileName) {
return new StringJoiner("/", "", "").add(SUBMODELREPOSITORY).add(repoId).add(SUBMODELS).add(encodeId(submodelId)).add(SUBMODELELEMENTS).add(submodelElementId).add(FILEVALUE).add(fileName).add(UPDATED).toString();
public String createUpdateFileValueTopic(String repoId, String submodelId, String submodelElementId) {
return new StringJoiner("/", "", "").add(SUBMODELREPOSITORY).add(repoId).add(SUBMODELS).add(encodeId(submodelId)).add(SUBMODELELEMENTS).add(submodelElementId).add(ATTACHMENT).add(UPDATED).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void setFileValueEvent() throws DeserializationException, IOException {

submodelRepository.setFileValue(submodel.getId(), submodelElement.getIdShort(), FILE_SUBMODEL_ELEMENT_NAME, getInputStreamOfDummyFile(FILE_SUBMODEL_ELEMENT_CONTENT));

assertEquals(topicFactory.createUpdateFileValueTopic(submodelRepository.getName(), submodel.getId(), submodelElement.getIdShort(), FILE_SUBMODEL_ELEMENT_NAME), listener.lastTopic);
assertEquals(topicFactory.createUpdateFileValueTopic(submodelRepository.getName(), submodel.getId(), submodelElement.getIdShort()), listener.lastTopic);
assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload));
}

Expand Down

0 comments on commit c84de43

Please sign in to comment.