Throws Exception instead of returning null in MultiAASProvider
Signed-off-by: Ashfaqul Haque <ashfaqul.haque@iese.fraunhofer.de>
Change-Id: Ibbf6535b57cca236f16232a9f693d74405912687
diff --git a/sdks/java/basys.sdk/src/main/java/org/eclipse/basyx/aas/restapi/MultiAASProvider.java b/sdks/java/basys.sdk/src/main/java/org/eclipse/basyx/aas/restapi/MultiAASProvider.java
index 08d69ca..879c230 100644
--- a/sdks/java/basys.sdk/src/main/java/org/eclipse/basyx/aas/restapi/MultiAASProvider.java
+++ b/sdks/java/basys.sdk/src/main/java/org/eclipse/basyx/aas/restapi/MultiAASProvider.java
@@ -45,91 +45,67 @@
@Override
public Object getModelPropertyValue(String path) throws ProviderException {
String aasId = getId(path);
- if (aasId != null) {
- VABMultiSubmodelProvider provider = aas_providers.get(aasId);
- if (provider == null) {
- throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
- }
- String subPath = getSubPath(path, aasId);
- return provider.getModelPropertyValue(subPath);
- } else {
- throw new MalformedRequestException("No AASId specified.");
+ VABMultiSubmodelProvider provider = aas_providers.get(aasId);
+ if (provider == null) {
+ throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
}
+ String subPath = getSubPath(path, aasId);
+ return provider.getModelPropertyValue(subPath);
}
@Override
public void setModelPropertyValue(String path, Object newValue) throws ProviderException {
String aasId = getId(path);
- if (aasId != null) {
- VABMultiSubmodelProvider provider = aas_providers.get(aasId);
- if (provider == null) {
- throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
- }
- String subPath = getSubPath(path, aasId);
- provider.setModelPropertyValue(subPath, newValue);
- } else {
- throw new MalformedRequestException("No AASId specified.");
+ VABMultiSubmodelProvider provider = aas_providers.get(aasId);
+ if (provider == null) {
+ throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
}
+ String subPath = getSubPath(path, aasId);
+ provider.setModelPropertyValue(subPath, newValue);
}
@Override
public void createValue(String path, Object newEntity) throws ProviderException {
String aasId = getId(path);
- if (aasId != null) {
- VABMultiSubmodelProvider provider = aas_providers.get(aasId);
- if (provider == null) {
- throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
- }
- String subPath = getSubPath(path, aasId);
- provider.createValue(subPath, newEntity);
- } else {
- throw new MalformedRequestException("No AASId specified.");
+ VABMultiSubmodelProvider provider = aas_providers.get(aasId);
+ if (provider == null) {
+ throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
}
+ String subPath = getSubPath(path, aasId);
+ provider.createValue(subPath, newEntity);
}
@Override
public void deleteValue(String path) throws ProviderException {
String aasId = getId(path);
- if (aasId != null) {
- VABMultiSubmodelProvider provider = aas_providers.get(aasId);
- if (provider == null) {
- throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
- }
- String subPath = getSubPath(path, aasId);
- provider.deleteValue(subPath);
- } else {
- throw new MalformedRequestException("No AASId specified.");
+ VABMultiSubmodelProvider provider = aas_providers.get(aasId);
+ if (provider == null) {
+ throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
}
+ String subPath = getSubPath(path, aasId);
+ provider.deleteValue(subPath);
}
@Override
public void deleteValue(String path, Object obj) throws ProviderException {
String aasId = getId(path);
- if (aasId != null) {
- VABMultiSubmodelProvider provider = aas_providers.get(aasId);
- if (provider == null) {
- throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
- }
- String subPath = getSubPath(path, aasId);
- provider.deleteValue(subPath, obj);
- } else {
- throw new MalformedRequestException("No AASId specified.");
+ VABMultiSubmodelProvider provider = aas_providers.get(aasId);
+ if (provider == null) {
+ throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
}
+ String subPath = getSubPath(path, aasId);
+ provider.deleteValue(subPath, obj);
}
@Override
public Object invokeOperation(String path, Object... parameter) throws ProviderException {
String aasId = getId(path);
- if (aasId != null) {
- VABMultiSubmodelProvider provider = aas_providers.get(aasId);
- if (provider == null) {
- throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
- }
- String subPath = getSubPath(path, aasId);
- return provider.invokeOperation(subPath, parameter);
- } else {
- throw new MalformedRequestException("No AASId specified.");
+ VABMultiSubmodelProvider provider = aas_providers.get(aasId);
+ if (provider == null) {
+ throw new ResourceNotFoundException("AAS with ID \"" + aasId + "\" does not exist.");
}
+ String subPath = getSubPath(path, aasId);
+ return provider.invokeOperation(subPath, parameter);
}
/**
@@ -143,7 +119,7 @@
*/
private String getId(String path) {
if (path == null) {
- return null;
+ throw new MalformedRequestException("No AASId specified.");
}
String[] elements = VABPathTools.splitPath(path);
@@ -151,7 +127,7 @@
String aasId = elements[0];
return aasId;
} else {
- return null;
+ throw new MalformedRequestException("No AASId specified.");
}
}