Skip to content

Commit

Permalink
Change existing code to use NotifyAll Call
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusmolina-iese committed Dec 5, 2023
1 parent 47712e5 commit 69a3f9a
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ public IModelProvider getAASProvider(IIdentifier aasId) throws ResourceNotFoundE
@Override
public void createAAS(AssetAdministrationShell aas) {
aasAggregator.createAAS(aas);
observers.stream().forEach(o -> o.aasCreated(aas.getIdentification().getId()));
notifyAll(o -> o.aasCreated(aas.getIdentification().getId()));
}

@Override
public void updateAAS(AssetAdministrationShell aas) throws ResourceNotFoundException {
aasAggregator.updateAAS(aas);
observers.stream().forEach(o -> o.aasUpdated(aas.getIdentification().getId()));
notifyAll(o -> o.aasUpdated(aas.getIdentification().getId()));
}

@Override
public void deleteAAS(IIdentifier aasId) {
aasAggregator.deleteAAS(aasId);
observers.stream().forEach(o -> o.aasDeleted(aasId.getId()));
notifyAll(o -> o.aasDeleted(aasId.getId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ public IModelProvider getAASProvider(IIdentifier aasId) throws ResourceNotFoundE
@Override
public void createAAS(AssetAdministrationShell aas) {
aasAggregator.createAAS(aas);
observers.stream().forEach(o -> o.aasCreated(aas, this.aasServerId));
notifyAll(o -> o.aasCreated(aas, this.aasServerId));
}

@Override
public void updateAAS(AssetAdministrationShell aas) throws ResourceNotFoundException {
aasAggregator.updateAAS(aas);
observers.stream().forEach(o -> o.aasUpdated(aas, this.aasServerId));
notifyAll(o -> o.aasUpdated(aas, this.aasServerId));
}

@Override
public void deleteAAS(IIdentifier aasId) {
IAssetAdministrationShell aas = aasAggregator.getAAS(aasId);
aasAggregator.deleteAAS(aasId);
observers.stream().forEach(o -> o.aasDeleted(aas, this.aasServerId));
notifyAll(o -> o.aasDeleted(aas, this.aasServerId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ public ObservableAASRegistryService(IAASRegistry registry) {
@Override
public void register(AASDescriptor deviceAASDescriptor) throws ProviderException {
aasRegistry.register(deviceAASDescriptor);
observers.stream().forEach(o -> o.aasRegistered(deviceAASDescriptor.getIdentifier().getId()));
notifyAll(o -> o.aasRegistered(deviceAASDescriptor.getIdentifier().getId()));
}

@Override
public void register(IIdentifier aas, SubmodelDescriptor smDescriptor) throws ProviderException {
aasRegistry.register(aas, smDescriptor);
observers.stream().forEach(o -> o.submodelRegistered(aas, smDescriptor.getIdentifier()));
notifyAll(o -> o.submodelRegistered(aas, smDescriptor.getIdentifier()));
}

@Override
public void delete(IIdentifier aasId) throws ProviderException {
aasRegistry.delete(aasId);
observers.stream().forEach(o -> o.aasDeleted(aasId.getId()));
notifyAll(o -> o.aasDeleted(aasId.getId()));
}

@Override
public void delete(IIdentifier aasId, IIdentifier smId) throws ProviderException {
aasRegistry.delete(aasId, smId);
observers.stream().forEach(o -> o.submodelDeleted(aasId, smId));
notifyAll(o -> o.submodelDeleted(aasId, smId));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public void register(AASDescriptor deviceAASDescriptor) throws ProviderException
try {
aasRegistry.lookupAAS(deviceAASDescriptor.getIdentifier());
aasRegistry.register(deviceAASDescriptor);
observers.stream().forEach(o -> o.aasUpdated(deviceAASDescriptor, this.registryId));
notifyAll(o -> o.aasUpdated(deviceAASDescriptor, this.registryId));
} catch(ResourceNotFoundException e) {
aasRegistry.register(deviceAASDescriptor);
observers.stream().forEach(o -> o.aasRegistered(deviceAASDescriptor, this.registryId));
notifyAll(o -> o.aasRegistered(deviceAASDescriptor, this.registryId));
}
}

Expand All @@ -76,25 +76,25 @@ public void register(IIdentifier aas, SubmodelDescriptor smDescriptor) throws Pr
try {
aasRegistry.lookupSubmodel(aas, smDescriptor.getIdentifier());
aasRegistry.register(aas, smDescriptor);
observers.stream().forEach(o -> o.submodelUpdated(aas, smDescriptor, this.registryId));
notifyAll(o -> o.submodelUpdated(aas, smDescriptor, this.registryId));
} catch(ResourceNotFoundException e) {
aasRegistry.register(aas, smDescriptor);
observers.stream().forEach(o -> o.submodelRegistered(aas, smDescriptor, this.registryId));
notifyAll(o -> o.submodelRegistered(aas, smDescriptor, this.registryId));
}
}

@Override
public void delete(IIdentifier aasId) throws ProviderException {
AASDescriptor aasDescriptor = lookupAAS(aasId);
aasRegistry.delete(aasId);
observers.stream().forEach(o -> o.aasDeleted(aasDescriptor, this.registryId));
notifyAll(o -> o.aasDeleted(aasDescriptor, this.registryId));
}

@Override
public void delete(IIdentifier aasId, IIdentifier smId) throws ProviderException {
SubmodelDescriptor smDescriptor = lookupSubmodel(aasId, smId);
aasRegistry.delete(aasId, smId);
observers.stream().forEach(o -> o.submodelDeleted(aasId, smDescriptor, this.registryId));
notifyAll(o -> o.submodelDeleted(aasId, smDescriptor, this.registryId));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public void addSubmodel(IReference submodel) {
throw new MalformedRequestException("Reference has to contain a submodel");

aasAPI.addSubmodel(submodel);
observers.stream().forEach(o -> o.submodelAdded(submodel));
notifyAll(o -> o.submodelAdded(submodel));
}

@Override
public void removeSubmodel(String id) {
aasAPI.removeSubmodel(id);
observers.stream().forEach(o -> o.submodelRemoved(id));
notifyAll(o -> o.submodelRemoved(id));
}

private boolean containsSubmodelReference(IReference submodel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public void register(TaggedAASDescriptor descriptor) {
try {
taggedDirectory.lookupAAS(descriptor.getIdentifier());
taggedDirectory.register(descriptor);
observers.stream().forEach(o -> o.aasUpdated(descriptor, super.getRegistryId()));
notifyAll(o -> o.aasUpdated(descriptor, super.getRegistryId()));
} catch(ResourceNotFoundException e) {
taggedDirectory.register(descriptor);
observers.stream().forEach(o -> o.aasRegistered(descriptor, super.getRegistryId()));
notifyAll(o -> o.aasRegistered(descriptor, super.getRegistryId()));
}
}

Expand All @@ -68,10 +68,10 @@ public void registerSubmodel(IIdentifier aas, TaggedSubmodelDescriptor descripto
try {
taggedDirectory.lookupSubmodel(aas, descriptor.getIdentifier());
taggedDirectory.register(aas, descriptor);
observers.stream().forEach(o -> o.submodelUpdated(aas, descriptor, super.getRegistryId()));
notifyAll(o -> o.submodelUpdated(aas, descriptor, super.getRegistryId()));
} catch (ResourceNotFoundException e) {
taggedDirectory.register(aas, descriptor);
observers.stream().forEach(o -> o.submodelRegistered(aas, descriptor, super.getRegistryId()));
notifyAll(o -> o.submodelRegistered(aas, descriptor, super.getRegistryId()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,34 @@ public ISubmodelAPI getSubmodelAPIByIdShort(String submodelIdShort) throws Resou
@Override
public void createSubmodel(Submodel submodel) {
submodelAggregator.createSubmodel(submodel);
observers.stream().forEach(observer -> observer.submodelCreated(getParentAASId(submodel), submodel.getIdentification().getId()));
notifyAll(observer -> observer.submodelCreated(getParentAASId(submodel), submodel.getIdentification().getId()));
}

@Override
public void createSubmodel(ISubmodelAPI submodelAPI) {
submodelAggregator.createSubmodel(submodelAPI);
observers.stream().forEach(observer -> observer.submodelCreated(getParentAASId(submodelAPI.getSubmodel()), submodelAPI.getSubmodel().getIdentification().getId()));
notifyAll(observer -> observer.submodelCreated(getParentAASId(submodelAPI.getSubmodel()), submodelAPI.getSubmodel().getIdentification().getId()));
}

@Override
public void updateSubmodel(Submodel submodel) throws ResourceNotFoundException {
submodelAggregator.updateSubmodel(submodel);
observers.stream().forEach(observer -> observer.submodelUpdated(getParentAASId(submodel), submodel.getIdentification().getId()));
notifyAll(observer -> observer.submodelUpdated(getParentAASId(submodel), submodel.getIdentification().getId()));
}

@Override
public void deleteSubmodelByIdentifier(IIdentifier submodelIdentifier) {
String parentAASId = getParentAASId(submodelAggregator.getSubmodel(submodelIdentifier));
submodelAggregator.deleteSubmodelByIdentifier(submodelIdentifier);
observers.stream().forEach(observer -> observer.submodelDeleted(parentAASId, submodelIdentifier.getId()));
notifyAll(observer -> observer.submodelDeleted(parentAASId, submodelIdentifier.getId()));
}

@Override
public void deleteSubmodelByIdShort(String submodelIdShort) {
ISubmodel submodel = submodelAggregator.getSubmodelbyIdShort(submodelIdShort);
String parentAASId = getParentAASId(submodel);
submodelAggregator.deleteSubmodelByIdShort(submodelIdShort);
observers.stream().forEach(observer -> observer.submodelDeleted(parentAASId, submodel.getIdentification().getId()));
notifyAll(observer -> observer.submodelDeleted(parentAASId, submodel.getIdentification().getId()));
}

private String getParentAASId(ISubmodel submodel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,35 @@ public ISubmodelAPI getSubmodelAPIByIdShort(String submodelIdShort) throws Resou
@Override
public void createSubmodel(Submodel submodel) {
submodelAggregator.createSubmodel(submodel);
observers.stream().forEach(observer -> observer.submodelCreated(getParentAASId(submodel), submodel, this.aasServerId));
notifyAll(observer -> observer.submodelCreated(getParentAASId(submodel), submodel, this.aasServerId));
}

@Override
public void createSubmodel(ISubmodelAPI submodelAPI) {
submodelAggregator.createSubmodel(submodelAPI);
observers.stream().forEach(observer -> observer.submodelCreated(getParentAASId(submodelAPI.getSubmodel()), submodelAPI.getSubmodel(), this.aasServerId));
notifyAll(observer -> observer.submodelCreated(getParentAASId(submodelAPI.getSubmodel()), submodelAPI.getSubmodel(), this.aasServerId));
}

@Override
public void updateSubmodel(Submodel submodel) throws ResourceNotFoundException {
submodelAggregator.updateSubmodel(submodel);
observers.stream().forEach(observer -> observer.submodelUpdated(getParentAASId(submodel), submodel, this.aasServerId));
notifyAll(observer -> observer.submodelUpdated(getParentAASId(submodel), submodel, this.aasServerId));
}

@Override
public void deleteSubmodelByIdentifier(IIdentifier submodelIdentifier) {
ISubmodel submodel = submodelAggregator.getSubmodel(submodelIdentifier);
String parentAASId = getParentAASId(submodel);
submodelAggregator.deleteSubmodelByIdentifier(submodelIdentifier);
observers.stream().forEach(observer -> observer.submodelDeleted(parentAASId, submodel, this.aasServerId));
notifyAll(observer -> observer.submodelDeleted(parentAASId, submodel, this.aasServerId));
}

@Override
public void deleteSubmodelByIdShort(String submodelIdShort) {
ISubmodel submodel = submodelAggregator.getSubmodelbyIdShort(submodelIdShort);
String parentAASId = getParentAASId(submodel);
submodelAggregator.deleteSubmodelByIdShort(submodelIdShort);
observers.stream().forEach(observer -> observer.submodelDeleted(parentAASId, submodel, this.aasServerId));
notifyAll(observer -> observer.submodelDeleted(parentAASId, submodel, this.aasServerId));
}

private String getParentAASId(ISubmodel submodel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public ISubmodel getSubmodel() {
@Override
public void addSubmodelElement(ISubmodelElement elem) {
submodelAPI.addSubmodelElement(elem);
observers.stream().forEach(o -> o.elementAdded(elem.getIdShort(), elem.getValue()));
notifyAll(o -> o.elementAdded(elem.getIdShort(), elem.getValue()));
}

@Override
public void addSubmodelElement(String idShortPath, ISubmodelElement elem) {
submodelAPI.addSubmodelElement(idShortPath, elem);
observers.stream().forEach(o -> o.elementAdded(idShortPath, elem.getValue()));
notifyAll(o -> o.elementAdded(idShortPath, elem.getValue()));
}

@Override
Expand All @@ -74,7 +74,7 @@ public ISubmodelElement getSubmodelElement(String idShortPath) {
@Override
public void deleteSubmodelElement(String idShortPath) {
submodelAPI.deleteSubmodelElement(idShortPath);
observers.stream().forEach(o -> o.elementDeleted(idShortPath));
notifyAll(o -> o.elementDeleted(idShortPath));
}

@Override
Expand All @@ -90,7 +90,7 @@ public Collection<ISubmodelElement> getSubmodelElements() {
@Override
public void updateSubmodelElement(String idShortPath, Object newValue) {
submodelAPI.updateSubmodelElement(idShortPath, newValue);
observers.stream().forEach(o -> o.elementUpdated(idShortPath, newValue));
notifyAll(o -> o.elementUpdated(idShortPath, newValue));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ private void addOrReplaceSubmodelElement(String idShortPath, ISubmodelElement el
try {
submodelAPI.getSubmodelElement(idShortPath);
submodelAPI.addSubmodelElement(idShortPath, elem);
observers.stream().forEach(o -> o.elementUpdated(idShortPath, elem, getParentAASId(getSubmodel()), getSubmodel().getIdentification().getId(), this.aasServerId));
notifyAll(o -> o.elementUpdated(idShortPath, elem, getParentAASId(getSubmodel()), getSubmodel().getIdentification().getId(), this.aasServerId));
} catch (ResourceNotFoundException e) {
submodelAPI.addSubmodelElement(idShortPath, elem);
observers.stream().forEach(o -> o.elementAdded(idShortPath, elem, getParentAASId(getSubmodel()), getSubmodel().getIdentification().getId(), this.aasServerId));
notifyAll(o -> o.elementAdded(idShortPath, elem, getParentAASId(getSubmodel()), getSubmodel().getIdentification().getId(), this.aasServerId));
}
}

Expand All @@ -101,7 +101,7 @@ public ISubmodelElement getSubmodelElement(String idShortPath) {
public void deleteSubmodelElement(String idShortPath) {
ISubmodelElement submodelElement = submodelAPI.getSubmodelElement(idShortPath);
submodelAPI.deleteSubmodelElement(idShortPath);
observers.stream().forEach(o -> o.elementDeleted(idShortPath, submodelElement, getParentAASId(getSubmodel()), getSubmodel().getIdentification().getId(), this.aasServerId));
notifyAll(o -> o.elementDeleted(idShortPath, submodelElement, getParentAASId(getSubmodel()), getSubmodel().getIdentification().getId(), this.aasServerId));
}

@Override
Expand All @@ -127,7 +127,7 @@ public void updateSubmodelElement(String idShortPath, Object newValue) {
valueToSend = newValue;
}

observers.stream().forEach(o -> o.elementValue(idShortPath, valueToSend, getParentAASId(getSubmodel()), getSubmodel().getIdentification().getId(), this.aasServerId));
notifyAll(o -> o.elementValue(idShortPath, valueToSend, getParentAASId(getSubmodel()), getSubmodel().getIdentification().getId(), this.aasServerId));
}


Expand Down

0 comments on commit 69a3f9a

Please sign in to comment.