Skip to content

Commit

Permalink
fix bugs & cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
mjacoby committed Oct 17, 2024
1 parent 02c06ac commit fc1f977
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,20 @@
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;


/**
* Persistence implementation for a mongo database.
*/
public class PersistenceMongo implements Persistence<PersistenceMongoConfig> {
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";
Expand All @@ -117,6 +116,11 @@ public class PersistenceMongo implements Persistence<PersistenceMongoConfig> {
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();
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit fc1f977

Please sign in to comment.