diff --git a/endpoint/opcua/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/opcua/AasServiceNodeManager.java b/endpoint/opcua/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/opcua/AasServiceNodeManager.java index 826c8d592..b2030a3e3 100644 --- a/endpoint/opcua/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/opcua/AasServiceNodeManager.java +++ b/endpoint/opcua/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/opcua/AasServiceNodeManager.java @@ -43,6 +43,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus; import de.fraunhofer.iosb.ilt.faaast.service.model.SubmodelElementIdentifier; import de.fraunhofer.iosb.ilt.faaast.service.model.exception.AmbiguousElementException; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.PersistenceException; import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueFormatException; import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId; import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo; @@ -388,9 +389,10 @@ private void subscribeMessageBus() throws MessageBusException { * @throws AddressSpaceException If the operation fails * @throws ValueFormatException The data format of the value is invalid * @throws AmbiguousElementException if there are multiple matching elements in the environment + * @throws PersistenceException if accessing the environment fails */ private void elementCreated(Reference element, Referable value) - throws StatusException, ServiceResultException, ServiceException, AddressSpaceException, ValueFormatException, AmbiguousElementException { + throws StatusException, ServiceResultException, ServiceException, AddressSpaceException, ValueFormatException, AmbiguousElementException, PersistenceException { Ensure.requireNonNull(element, ELEMENT_NULL); Ensure.requireNonNull(value, VALUE_NULL); @@ -472,9 +474,10 @@ private void elementDeleted(Reference element) throws StatusException { * @throws AddressSpaceException If the operation fails * @throws ValueFormatException The data format of the value is invalid * @throws AmbiguousElementException if there are multiple matching elements in the environment + * @throws PersistenceException if accessing the environment fails */ private void elementUpdated(Reference element, Referable value) - throws StatusException, ServiceResultException, ServiceException, AddressSpaceException, ValueFormatException, AmbiguousElementException { + throws StatusException, ServiceResultException, ServiceException, AddressSpaceException, ValueFormatException, AmbiguousElementException, PersistenceException { Ensure.requireNonNull(element, ELEMENT_NULL); Ensure.requireNonNull(value, VALUE_NULL); diff --git a/endpoint/opcua/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/opcua/OpcUaEndpoint.java b/endpoint/opcua/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/opcua/OpcUaEndpoint.java index ea633db50..359cc711f 100644 --- a/endpoint/opcua/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/opcua/OpcUaEndpoint.java +++ b/endpoint/opcua/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/opcua/OpcUaEndpoint.java @@ -29,6 +29,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.submodel.InvokeOperationSyncRequest; import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.submodel.GetSubmodelElementByPathResponse; import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.submodel.InvokeOperationSyncResponse; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.PersistenceException; import de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValueParser; import de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper; @@ -101,10 +102,9 @@ public void start() throws EndpointException { return; } - aasEnvironment = service.getAASEnvironment(); - Ensure.requireNonNull(aasEnvironment, "aasEnvironment must not be null"); - try { + aasEnvironment = service.getAASEnvironment(); + Ensure.requireNonNull(aasEnvironment, "aasEnvironment must not be null"); server = new Server(currentConfig.getTcpPort(), aasEnvironment, this); server.startup(); LOGGER.debug("server started"); @@ -270,8 +270,9 @@ else if (response.getStatusCode() == StatusCode.CLIENT_METHOD_NOT_ALLOWED) { * Read the current environment from the service. * * @return The current environment. + * @throws PersistenceException if accessing the environment fails */ - public Environment getAASEnvironment() { + public Environment getAASEnvironment() throws PersistenceException { return service.getAASEnvironment(); } } diff --git a/persistence/mongo/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/persistence/mongo/PersistenceMongo.java b/persistence/mongo/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/persistence/mongo/PersistenceMongo.java index 5a6c3ed3a..8474fa882 100644 --- a/persistence/mongo/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/persistence/mongo/PersistenceMongo.java +++ b/persistence/mongo/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/persistence/mongo/PersistenceMongo.java @@ -91,6 +91,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -98,14 +99,12 @@ * Persistence implementation for a mongo database. */ public class PersistenceMongo implements Persistence { - private static final String ID_KEY = "id"; - private static final String ID_SHORT_KEY = "idShort"; - private static final String SUBMODEL_ELEMENTS_KEY = "submodelElements"; - private static final String VALUE_KEY = "value"; + + private static final Logger LOGGER = LoggerFactory.getLogger(PersistenceMongo.class); + + private static final int RANDOM_VALUE_LENGTH = 100; private static final String SERIALIZATION_ERROR = "Serialization of document with id %s failed!"; - private static final String DESERIALIZATION_ERROR = "Deserialization of document with id %s failed!"; - private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(PersistenceMongo.class); private static final String MSG_RESOURCE_NOT_FOUND_BY_ID = "resource not found (id %s)"; private static final String MSG_MODIFIER_NOT_NULL = "modifier must be non-null"; private static final String MSG_CRITERIA_NOT_NULL = "criteria must be non-null"; @@ -117,6 +116,11 @@ public class PersistenceMongo implements Persistence { private static final String SUBMODEL_COLLECTION_NAME = "submodels"; private static final String OPERATION_COLLECTION_NAME = "operationResults"; + private static final String ID_KEY = "id"; + private static final String ID_SHORT_KEY = "idShort"; + private static final String SUBMODEL_ELEMENTS_KEY = "submodelElements"; + private static final String VALUE_KEY = "value"; + private static final Pattern INDEX_REGEX = Pattern.compile("\\[\\d+\\]"); private final JsonApiSerializer serializer = new JsonApiSerializer(); @@ -612,7 +616,6 @@ public void deleteConceptDescription(String id) throws ResourceNotFoundException deleteElementById(cdCollection, id); } - private static final int RANDOM_VALUE_LENGTH = 100; private static String generateRandomValue() { byte[] data = new byte[RANDOM_VALUE_LENGTH];