Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make MongDb stateless, add create(Identifier aasIdentifier) into IAASAPIFactory to prevent that MongoDb creates new AAS every time whenn fetching the provider #343

Merged
merged 5 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.basyx.aas.restapi.api.IAASAPI;
import org.eclipse.basyx.aas.restapi.api.IAASAPIFactory;
import org.eclipse.basyx.aas.restapi.vab.VABAASAPIFactory;
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;

/**
* AAS API provider that provides the default AAS API
Expand All @@ -50,4 +51,9 @@ public IAASAPI getAASApi(AssetAdministrationShell aas) {
return aasAPIFactory.create(aas);
}

@Override
public IAASAPI create(IIdentifier aasId) {
return aasAPIFactory.create(aasId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
package org.eclipse.basyx.aas.restapi.api;

import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
import org.eclipse.basyx.vab.exception.FeatureNotImplementedException;

/**
* Interface for providing an AAS API
Expand All @@ -44,7 +46,12 @@ public interface IAASAPIFactory {
@Deprecated
public IAASAPI getAASApi(AssetAdministrationShell aas);


public default IAASAPI create(AssetAdministrationShell aas) {
return getAASApi(aas);
}

public default IAASAPI create(IIdentifier aasId) {
throw new FeatureNotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
import org.eclipse.basyx.aas.restapi.api.IAASAPI;
import org.eclipse.basyx.aas.restapi.api.IAASAPIFactory;
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
import org.eclipse.basyx.vab.exception.FeatureNotImplementedException;
import org.eclipse.basyx.vab.modelprovider.lambda.VABLambdaProvider;

/**
Expand All @@ -39,4 +41,10 @@ public class VABAASAPIFactory implements IAASAPIFactory {
public IAASAPI getAASApi(AssetAdministrationShell aas) {
return new VABAASAPI(new VABLambdaProvider(aas));
}

@Override
public IAASAPI create(IIdentifier aasId) {
// This should not be used for VABAASAPI
throw new FeatureNotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
import org.eclipse.basyx.aas.restapi.api.IAASAPI;
import org.eclipse.basyx.aas.restapi.api.IAASAPIFactory;
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;

/**
* Api provider for constructing a new AAS API that is authorized
Expand All @@ -29,4 +30,9 @@ public AuthorizedDecoratingAASAPIFactory(IAASAPIFactory factoryToBeDecorated) {
public IAASAPI getAASApi(AssetAdministrationShell aas) {
return new AuthorizedAASAPI(apiFactory.create(aas));
}

@Override
public IAASAPI create(IIdentifier aasId) {
return new AuthorizedAASAPI(apiFactory.create(aasId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.basyx.aas.restapi.api.IAASAPI;
import org.eclipse.basyx.aas.restapi.api.IAASAPIFactory;
import org.eclipse.basyx.extensions.shared.authorization.internal.ISubjectInformationProvider;
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;

/**
* Api provider for constructing a new AAS API that is authorized
Expand All @@ -50,4 +51,9 @@ public AuthorizedDecoratingAASAPIFactory(final IAASAPIFactory factoryToBeDecorat
public IAASAPI getAASApi(final AssetAdministrationShell aas) {
return new AuthorizedAASAPI<>(apiFactory.create(aas), aasAPIAuthorizer, subjectInformationProvider);
}

@Override
public IAASAPI create(IIdentifier aasId) {
return new AuthorizedAASAPI<>(apiFactory.create(aasId), aasAPIAuthorizer, subjectInformationProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.basyx.aas.restapi.api.IAASAPI;
import org.eclipse.basyx.aas.restapi.api.IAASAPIFactory;
import org.eclipse.basyx.aas.restapi.observing.ObservableAASAPI;
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
import org.eclipse.basyx.vab.exception.provider.ProviderException;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
Expand All @@ -33,13 +34,22 @@ public MqttDecoratingAASAPIFactory(IAASAPIFactory factoryToBeDecorated, MqttClie

@Override
public IAASAPI getAASApi(AssetAdministrationShell aas) {
return createMqttDecoratingAASAPI(apiFactory.create(aas));
}

private IAASAPI createMqttDecoratingAASAPI(IAASAPI aasAPI) {
try {
ObservableAASAPI observedAPI = new ObservableAASAPI(apiFactory.create(aas));
ObservableAASAPI observedAPI = new ObservableAASAPI(aasAPI);
MqttAASAPIObserver mqttAASAPIObserver = new MqttAASAPIObserver(client, MqttAASAPIHelper.getAASIdShort(observedAPI));
observedAPI.addObserver(mqttAASAPIObserver);
return observedAPI;
} catch (MqttException e) {
throw new ProviderException(e);
}
}

@Override
public IAASAPI create(IIdentifier aasId) {
return createMqttDecoratingAASAPI(apiFactory.create(aasId));
}
}