Skip to content

Commit 3987c2d

Browse files
Implements FileValueAdapting feature (#308)
Signed-off-by: Frank Schnicke <[email protected]>
1 parent f3b9f8d commit 3987c2d

File tree

11 files changed

+715
-18
lines changed

11 files changed

+715
-18
lines changed

basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/AASServerComponent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.eclipse.basyx.components.aas.configuration.AASServerBackend;
7272
import org.eclipse.basyx.components.aas.configuration.BaSyxAASServerConfiguration;
7373
import org.eclipse.basyx.components.aas.delegation.DelegationAASServerFeature;
74+
import org.eclipse.basyx.components.aas.fileadaptation.FileValueAdaptingAASServerFeature;
7475
import org.eclipse.basyx.components.aas.mqtt.MqttAASServerFeature;
7576
import org.eclipse.basyx.components.aas.mqtt.MqttV2AASServerFeature;
7677
import org.eclipse.basyx.components.aas.servlet.AASAggregatorAASXUploadServlet;
@@ -362,6 +363,8 @@ private void loadAASServerFeaturesFromConfig() {
362363

363364
configureSecurity();
364365

366+
addAASServerFeature(new FileValueAdaptingAASServerFeature(getURL()));
367+
365368
if (aasConfig.isAASXUploadEnabled()) {
366369
enableAASXUpload();
367370
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2023 the Eclipse BaSyx Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* SPDX-License-Identifier: MIT
24+
******************************************************************************/
25+
26+
27+
package org.eclipse.basyx.components.aas.fileadaptation;
28+
29+
import org.eclipse.basyx.aas.aggregator.api.IAASAggregatorFactory;
30+
import org.eclipse.basyx.aas.restapi.api.IAASAPIFactory;
31+
import org.eclipse.basyx.components.aas.aascomponent.IAASServerDecorator;
32+
import org.eclipse.basyx.submodel.aggregator.api.ISubmodelAggregatorFactory;
33+
import org.eclipse.basyx.submodel.restapi.api.ISubmodelAPIFactory;
34+
35+
/**
36+
* Decorator for File value adaptation feature
37+
*
38+
* @author schnicke
39+
*
40+
*/
41+
public class FileValueAdaptingAASServerDecorator implements IAASServerDecorator {
42+
43+
private String serverUrl;
44+
45+
public FileValueAdaptingAASServerDecorator(String serverUrl) {
46+
this.serverUrl = serverUrl;
47+
}
48+
49+
@Override
50+
public ISubmodelAPIFactory decorateSubmodelAPIFactory(ISubmodelAPIFactory submodelAPIFactory) {
51+
return new FileValueAdaptingSubmodelAPIFactory(submodelAPIFactory, serverUrl);
52+
}
53+
54+
@Override
55+
public ISubmodelAggregatorFactory decorateSubmodelAggregatorFactory(ISubmodelAggregatorFactory submodelAggregatorFactory) {
56+
return new ParentSettingSubmodelAggregatorFactory(submodelAggregatorFactory);
57+
}
58+
59+
@Override
60+
public IAASAPIFactory decorateAASAPIFactory(IAASAPIFactory aasAPIFactory) {
61+
return aasAPIFactory;
62+
}
63+
64+
@Override
65+
public IAASAggregatorFactory decorateAASAggregatorFactory(IAASAggregatorFactory aasAggregatorFactory) {
66+
return aasAggregatorFactory;
67+
}
68+
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2023 the Eclipse BaSyx Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* SPDX-License-Identifier: MIT
24+
******************************************************************************/
25+
26+
27+
package org.eclipse.basyx.components.aas.fileadaptation;
28+
29+
import org.eclipse.basyx.components.aas.aascomponent.IAASServerDecorator;
30+
import org.eclipse.basyx.components.aas.aascomponent.IAASServerFeature;
31+
32+
/**
33+
* Feature for File value adaptation feature
34+
*
35+
* @author schnicke
36+
*
37+
*/
38+
public class FileValueAdaptingAASServerFeature implements IAASServerFeature {
39+
40+
private String serverUrl;
41+
42+
public FileValueAdaptingAASServerFeature(String serverUrl) {
43+
this.serverUrl = serverUrl;
44+
}
45+
46+
@Override
47+
public void initialize() {
48+
}
49+
50+
@Override
51+
public void cleanUp() {
52+
}
53+
54+
@Override
55+
public IAASServerDecorator getDecorator() {
56+
return new FileValueAdaptingAASServerDecorator(serverUrl);
57+
}
58+
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2023 the Eclipse BaSyx Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* SPDX-License-Identifier: MIT
24+
******************************************************************************/
25+
26+
27+
package org.eclipse.basyx.components.aas.fileadaptation;
28+
29+
import java.io.InputStream;
30+
import java.util.Collection;
31+
32+
import org.eclipse.basyx.submodel.metamodel.api.ISubmodel;
33+
import org.eclipse.basyx.submodel.metamodel.api.submodelelement.ISubmodelElement;
34+
import org.eclipse.basyx.submodel.metamodel.api.submodelelement.operation.IOperation;
35+
import org.eclipse.basyx.submodel.restapi.MultiSubmodelElementProvider;
36+
import org.eclipse.basyx.submodel.restapi.SubmodelProvider;
37+
import org.eclipse.basyx.submodel.restapi.api.ISubmodelAPI;
38+
import org.eclipse.basyx.vab.modelprovider.VABPathTools;
39+
40+
/**
41+
* Submodel API that adapts a File's value after uploading a new file to point
42+
* to the download endpoint
43+
*
44+
* @author schnicke
45+
*
46+
*/
47+
public class FileValueAdaptingSubmodelAPI implements ISubmodelAPI {
48+
private ISubmodelAPI decorated;
49+
50+
private String submodelURL;
51+
52+
public FileValueAdaptingSubmodelAPI(ISubmodelAPI decorated, String submodelUrl) {
53+
this.decorated = decorated;
54+
this.submodelURL = submodelUrl;
55+
}
56+
57+
@Override
58+
public ISubmodel getSubmodel() {
59+
return decorated.getSubmodel();
60+
}
61+
62+
@Override
63+
public void addSubmodelElement(ISubmodelElement elem) {
64+
decorated.addSubmodelElement(elem);
65+
}
66+
67+
@Override
68+
public void addSubmodelElement(String idShortPath, ISubmodelElement elem) {
69+
decorated.addSubmodelElement(idShortPath, elem);
70+
}
71+
72+
@Override
73+
public ISubmodelElement getSubmodelElement(String idShortPath) {
74+
return decorated.getSubmodelElement(idShortPath);
75+
}
76+
77+
@Override
78+
public void deleteSubmodelElement(String idShortPath) {
79+
decorated.deleteSubmodelElement(idShortPath);
80+
}
81+
82+
@Override
83+
public Collection<IOperation> getOperations() {
84+
return decorated.getOperations();
85+
}
86+
87+
@Override
88+
public Collection<ISubmodelElement> getSubmodelElements() {
89+
return decorated.getSubmodelElements();
90+
}
91+
92+
@Override
93+
public void updateSubmodelElement(String idShortPath, Object newValue) {
94+
decorated.updateSubmodelElement(idShortPath, newValue);
95+
}
96+
97+
@Override
98+
public Object getSubmodelElementValue(String idShortPath) {
99+
return decorated.getSubmodelElementValue(idShortPath);
100+
}
101+
102+
@Override
103+
public Object invokeOperation(String idShortPath, Object... params) {
104+
return decorated.invokeOperation(idShortPath, params);
105+
}
106+
107+
@Override
108+
public Object invokeAsync(String idShortPath, Object... params) {
109+
return decorated.invokeAsync(idShortPath, params);
110+
}
111+
112+
@Override
113+
public Object getOperationResult(String idShort, String requestId) {
114+
return decorated.getOperationResult(idShort, requestId);
115+
}
116+
117+
@Override
118+
public java.io.File getSubmodelElementFile(String idShortPath) {
119+
return decorated.getSubmodelElementFile(idShortPath);
120+
}
121+
122+
@Override
123+
public void uploadSubmodelElementFile(String idShortPath, InputStream fileStream) {
124+
decorated.uploadSubmodelElementFile(idShortPath, fileStream);
125+
decorated.updateSubmodelElement(idShortPath, getURL(idShortPath));
126+
}
127+
128+
private Object getURL(String idShortPath) {
129+
return VABPathTools.concatenatePaths(submodelURL, MultiSubmodelElementProvider.ELEMENTS, idShortPath, SubmodelProvider.FILE);
130+
}
131+
132+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2023 the Eclipse BaSyx Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* SPDX-License-Identifier: MIT
24+
******************************************************************************/
25+
26+
27+
package org.eclipse.basyx.components.aas.fileadaptation;
28+
29+
import java.util.List;
30+
import java.util.Optional;
31+
32+
import org.eclipse.basyx.aas.aggregator.AASAggregatorAPIHelper;
33+
import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
34+
import org.eclipse.basyx.aas.metamodel.map.descriptor.CustomId;
35+
import org.eclipse.basyx.submodel.metamodel.api.reference.IKey;
36+
import org.eclipse.basyx.submodel.metamodel.api.reference.IReference;
37+
import org.eclipse.basyx.submodel.metamodel.api.reference.enums.KeyElements;
38+
import org.eclipse.basyx.submodel.metamodel.map.Submodel;
39+
import org.eclipse.basyx.submodel.restapi.SubmodelProvider;
40+
import org.eclipse.basyx.submodel.restapi.api.ISubmodelAPI;
41+
import org.eclipse.basyx.submodel.restapi.api.ISubmodelAPIFactory;
42+
import org.eclipse.basyx.vab.modelprovider.VABPathTools;
43+
import org.slf4j.Logger;
44+
import org.slf4j.LoggerFactory;
45+
46+
/**
47+
* Factory for creating a {@link FileValueAdaptingSubmodelAPI}
48+
*
49+
* @author schnicke
50+
*
51+
*/
52+
public class FileValueAdaptingSubmodelAPIFactory implements ISubmodelAPIFactory {
53+
54+
private static Logger logger = LoggerFactory.getLogger(FileValueAdaptingSubmodelAPIFactory.class);
55+
56+
private String serverUrl;
57+
private ISubmodelAPIFactory submodelApiFactory;
58+
59+
public FileValueAdaptingSubmodelAPIFactory(ISubmodelAPIFactory submodelApiFactory, String serverUrl) {
60+
this.serverUrl = serverUrl;
61+
this.submodelApiFactory = submodelApiFactory;
62+
}
63+
64+
@Override
65+
public ISubmodelAPI getSubmodelAPI(Submodel submodel) {
66+
String aasId = getAasIdentifier(submodel);
67+
return new FileValueAdaptingSubmodelAPI(submodelApiFactory.create(submodel), getSubmodelUrl(serverUrl, aasId, submodel.getIdShort()));
68+
}
69+
70+
private String getAasIdentifier(Submodel submodel) {
71+
IReference reference = submodel.getParent();
72+
73+
if (reference != null && reference.getKeys() != null && reference.getKeys().size() > 0) {
74+
List<IKey> keys = reference.getKeys();
75+
Optional<IKey> aasKey = keys.stream().filter(k -> k.getType().equals(KeyElements.ASSETADMINISTRATIONSHELL)).findAny();
76+
if (aasKey.isPresent()) {
77+
return aasKey.get().getValue();
78+
}
79+
}
80+
81+
logger.error("Submodel with id " + submodel.getIdentification() + " does not have a parent. The automatic setting of FileValues may lead to unexpected results.");
82+
83+
return "";
84+
}
85+
86+
private static String getSubmodelUrl(String serverUrl, String aasId, String submodelIdShort) {
87+
String aasAccessPath = AASAggregatorAPIHelper.getAASAccessPath(new CustomId(aasId));
88+
return VABPathTools.concatenatePaths(serverUrl, aasAccessPath, AssetAdministrationShell.SUBMODELS, submodelIdShort, SubmodelProvider.SUBMODEL);
89+
}
90+
91+
}

0 commit comments

Comments
 (0)