Skip to content
Open
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
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Eclipse BaSyx Java Components [![Docker Pulls](https://img.shields.io/docker/pulls/eclipsebasyx/aas-server?style=plastic)](https://hub.docker.com/search?q=eclipsebasyx)
[![BaSyx Logo](https://www.eclipse.org/basyx/img/basyxlogo.png)](https://www.eclipse.org/basyx/)

[![AAS Server javadoc](https://javadoc.io/badge2/org.eclipse.basyx/basyx.components.AASServer/javadoc.svg)](https://javadoc.io/doc/org.eclipse.basyx/basyx.components.AASServer) AAS Server

[![AAS Registry javadoc](https://javadoc.io/badge2/org.eclipse.basyx/basyx.components.registry/javadoc.svg)](https://javadoc.io/doc/org.eclipse.basyx/basyx.components.registry) AAS Registry
Expand Down
8 changes: 8 additions & 0 deletions basyx.aasrepository-backend-inmemory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasservice-core</artifactId>
<version>2.0.0-SNAPSHOT</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.stream.Collectors;

import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.basyx.aasservice.AasService;
import org.eclipse.digitaltwin.basyx.aasservice.AasServiceFactory;
Expand Down Expand Up @@ -121,4 +122,16 @@ public void removeSubmodelReference(String aasId, String submodelId) {
aasServices.get(aasId).removeSubmodelReference(submodelId);
}

@Override
public void setAssetInformation(String aasId, AssetInformation aasInfo) throws ElementDoesNotExistException {
throwIfAasDoesNotExist(aasId);
aasServices.get(aasId).getAAS().setAssetInformation(aasInfo);
}

@Override
public AssetInformation getAssetInformation(String aasId) throws ElementDoesNotExistException{
throwIfAasDoesNotExist(aasId);
return aasServices.get(aasId).getAAS().getAssetInformation();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;

import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.basyx.aasservice.backend.InMemoryAasService;
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException;
Expand Down Expand Up @@ -125,4 +126,18 @@ public void removeSubmodelReference(String aasId, String submodelId) {

updateAas(aasId, service.getAAS());
}

@Override
public void setAssetInformation(String aasId, AssetInformation aasInfo) throws ElementDoesNotExistException {
InMemoryAasService service = new InMemoryAasService(getAas(aasId));
service.setAssetInformation(aasInfo);

updateAas(aasId, service.getAAS());
}

@Override
public AssetInformation getAssetInformation(String aasId) throws ElementDoesNotExistException{
return this.getAas(aasId).getAssetInformation();
}

}
8 changes: 8 additions & 0 deletions basyx.aasrepository-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
<artifactId>basyx.aasservice-core</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasservice-core</artifactId>
<version>2.0.0-SNAPSHOT</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>


<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.List;

import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException;
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException;
Expand Down Expand Up @@ -100,6 +101,26 @@ public interface AasRepository {
*/
public void removeSubmodelReference(String aasId, String submodelId);

/**
* Sets the asset-information of a specific AAS
*
* @param aasId
* the id of the AAS
*
* @return the requested Asset-Information of the specified AAS
*/
public void setAssetInformation(String aasId, AssetInformation aasInfo) throws ElementDoesNotExistException;

/**
* Retrieves the asset-information of a specific AAS
*
* @param aasId
* the id of the AAS
*
* @return the requested AAS
*/
public AssetInformation getAssetInformation(String aasId) throws ElementDoesNotExistException;

public default String getName() {
return "aasRepository-default-name";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
import java.util.List;

import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind;
import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference;
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException;
Expand All @@ -56,6 +59,7 @@ public abstract class AasRepositorySuite {
private static final String AAS_1_ID = "aas1/s";
private AssetAdministrationShell aas1;
private AssetAdministrationShell aas2;
private AssetAdministrationShell aas3;
private List<AssetAdministrationShell> preconfiguredShells = new ArrayList<>();

private static final String DUMMY_SUBMODEL_ID = "dummySubmodelId";
Expand All @@ -71,8 +75,9 @@ public void createAasRepoWithDummyAas() {
aas1 = new DefaultAssetAdministrationShell.Builder().id(AAS_1_ID).submodels(createDummyReference(DUMMY_SUBMODEL_ID))
.build();

aas2 = new DefaultAssetAdministrationShell.Builder().id("aas2")
.build();
aas2 = new DefaultAssetAdministrationShell.Builder().id("aas2").build();
AssetInformation assetInfo = createDummyAssetInformation();
aas2.setAssetInformation(assetInfo);

preconfiguredShells.add(aas1);
preconfiguredShells.add(aas2);
Expand Down Expand Up @@ -182,9 +187,36 @@ public void updateNonExistingAas() {
aasRepo.updateAas("nonExisting", aas1);
}

@Test
public void getAssetInformation() {
assertEquals(aas2.getAssetInformation(), aasRepo.getAssetInformation(aas2.getId()));
}

@Test(expected = ElementDoesNotExistException.class)
public void getAssetInformationOfNonExistingAas() {
aasRepo.getAssetInformation("nonExisting");
}

@Test
public void setAssetInformation() {
AssetInformation assetInfo = createDummyAssetInformation();
aasRepo.setAssetInformation(aas2.getId(), assetInfo);
assertEquals(assetInfo, aasRepo.getAssetInformation(aas2.getId()));
}

@Test(expected = ElementDoesNotExistException.class)
public void setAssetInformationOfNonExistingAas() {
aasRepo.setAssetInformation("nonExisting", createDummyAssetInformation());
}

public static Reference createDummyReference(String submodelId) {
return new DefaultReference.Builder()
.keys(new DefaultKey.Builder().type(KeyTypes.SUBMODEL).value(submodelId).build()).build();
}

private AssetInformation createDummyAssetInformation() {
return new DefaultAssetInformation.Builder().assetKind(AssetKind.INSTANCE).globalAssetId(
new DefaultReference.Builder().keys(new DefaultKey.Builder().value("assetIDTestKey").build()).build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonSerializer;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository;
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException;
Expand Down Expand Up @@ -111,6 +112,16 @@ public void removeSubmodelReference(String aasId, String submodelId) {
decorated.removeSubmodelReference(aasId, submodelId);
}

@Override
public void setAssetInformation(String aasId, AssetInformation aasInfo) throws ElementDoesNotExistException {
decorated.setAssetInformation(aasId, aasInfo);
}

@Override
public AssetInformation getAssetInformation(String aasId) throws ElementDoesNotExistException{
return decorated.getAssetInformation(aasId);
}

private void aasCreated(AssetAdministrationShell shell, String repoId) {
sendMqttMessage(topicFactory.createCreateAASTopic(repoId), serializePayload(shell));
}
Expand Down Expand Up @@ -159,4 +170,5 @@ private MqttMessage createMqttMessage(String payload) {
return new MqttMessage(payload.getBytes());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository;
import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier;
Expand All @@ -59,15 +59,12 @@ public class AasRepositoryApiHTTPController implements AasRepositoryHTTPApi {
private static final Logger log = LoggerFactory.getLogger(AasRepositoryApiHTTPController.class);

private final ObjectMapper objectMapper;

private final HttpServletRequest request;

private final AasRepository aasRepository;

@Autowired
public AasRepositoryApiHTTPController(ObjectMapper objectMapper, HttpServletRequest request, AasRepository aasRepository) {
public AasRepositoryApiHTTPController(ObjectMapper objectMapper, AasRepository aasRepository) {
this.objectMapper = objectMapper;
this.request = request;
this.aasRepository = aasRepository;
}

Expand Down Expand Up @@ -140,4 +137,19 @@ public ResponseEntity<List<AssetAdministrationShell>> getAllAssetAdministrationS
@Parameter(in = ParameterIn.QUERY, description = "The Asset Administration Shell’s IdShort", schema = @Schema()) @Valid @RequestParam(value = "idShort", required = false) String idShort) {
return new ResponseEntity<List<AssetAdministrationShell>>(new ArrayList<>(aasRepository.getAllAas()), HttpStatus.OK);
}

@Override
public ResponseEntity<Void> postAssetInformationByAasId(
@Parameter(in = ParameterIn.PATH, description = "The Asset Administration Shell’s unique id (BASE64-URL-encoded)", required = true, schema = @Schema()) @PathVariable("aasIdentifier") Base64UrlEncodedIdentifier aasIdentifier,
@Parameter(in = ParameterIn.DEFAULT, description = "Asset Information object", required = true, schema = @Schema()) @Valid @RequestBody AssetInformation body) {
aasRepository.setAssetInformation(aasIdentifier.getIdentifier(), body);
return new ResponseEntity<Void>(HttpStatus.OK);
}

@Override
public ResponseEntity<AssetInformation> getAssetInformationByAasId(
@Parameter(in = ParameterIn.PATH, description = "The Asset Administration Shell’s unique id (BASE64-URL-encoded)", required = true, schema = @Schema()) @PathVariable("aasIdentifier") Base64UrlEncodedIdentifier aasIdentifier) {
return new ResponseEntity<AssetInformation>(aasRepository.getAssetInformation(aasIdentifier.getIdentifier()), HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javax.validation.Valid;

import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -121,4 +122,20 @@ ResponseEntity<Reference> postSubmodelReference(
ResponseEntity<Void> putAssetAdministrationShellById(
@Parameter(in = ParameterIn.PATH, description = "The Asset Administration Shell’s unique id (BASE64-URL-encoded)", required = true, schema = @Schema()) @PathVariable("aasIdentifier") Base64UrlEncodedIdentifier aasIdentifier,
@Parameter(in = ParameterIn.DEFAULT, description = "Asset Administration Shell object", required = true, schema = @Schema()) @Valid @RequestBody AssetAdministrationShell body);

@Operation(summary = "Updates the Asset Information of an existing Asset Administration Shell", description = "", tags = { "Asset Administration Shell Repository" })
@ApiResponses(value = { @ApiResponse(responseCode = "204", description = "Asset Information updated successfully") })
@RequestMapping(value = "/shells/{aasIdentifier}/asset-information", consumes = { "application/json" }, method = RequestMethod.POST)
ResponseEntity<Void> postAssetInformationByAasId(
@Parameter(in = ParameterIn.PATH, description = "The Asset Administration Shell’s unique id (BASE64-URL-encoded)", required = true, schema = @Schema()) @PathVariable("aasIdentifier") Base64UrlEncodedIdentifier aasIdentifier,
@Parameter(in = ParameterIn.DEFAULT, description = "Asset Information object", required = true, schema = @Schema()) @Valid @RequestBody AssetInformation body);

@Operation(summary = "Returns the Asset Information of a specific Asset Administration Shell", description = "", tags = { "Asset Administration Shell Repository" })
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Requested Asset Information of Asset Administration Shell", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AssetInformation.class))) })
@RequestMapping(value = "/shells/{aasIdentifier}/asset-information", produces = {
"application/json" }, method = RequestMethod.GET)
ResponseEntity<AssetInformation> getAssetInformationByAasId(
@Parameter(in = ParameterIn.PATH, description = "The Asset Administration Shell’s unique id (BASE64-URL-encoded)", required = true, schema = @Schema()) @PathVariable("aasIdentifier") Base64UrlEncodedIdentifier aasIdentifier);


}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,58 @@ public void removeNonExistingSubmodelReference() throws FileNotFoundException, I
createDummyAasOnServer();
String url = getSpecificSubmodelReferenceUrl();
CloseableHttpResponse deleteResponse = BaSyxHttpTestUtils.executeDeleteOnURL(url);
assertEquals(404, deleteResponse.getCode());
assertEquals(HttpStatus.NOT_FOUND.value(), deleteResponse.getCode());
}

@Test
public void getAssetInformationByIdentifier() throws FileNotFoundException, IOException, ParseException {
createDummyAasOnServer();
String url = getSpecificAssetInformationAccessURL(dummyAasId);
CloseableHttpResponse response = BaSyxHttpTestUtils.executeGetOnURL(url);

String expected = BaSyxHttpTestUtils.readJSONStringFromFile("classpath:assetInfoSimple.json");

BaSyxHttpTestUtils.assertSameJSONContent(expected, BaSyxHttpTestUtils.getResponseAsString(response));
}


@Test
public void getNonExistingAssetInformationByIdentifier() throws FileNotFoundException, IOException, ParseException {
String url = getSpecificAasAccessURL("nonExisting") + "/asset-information";
CloseableHttpResponse response = BaSyxHttpTestUtils.executeGetOnURL(url);

assertEquals(HttpStatus.NOT_FOUND.value(), response.getCode());
}

@Test
public void postAssetInformationByIdentifier() throws FileNotFoundException, IOException, ParseException {
createDummyAasOnServer();

String json = BaSyxHttpTestUtils.readJSONStringFromFile("classpath:exampleAssetInfo.json");

BaSyxHttpTestUtils.executePostOnServer(getSpecificAssetInformationAccessURL(dummyAasId), json);

CloseableHttpResponse response = BaSyxHttpTestUtils
.executeGetOnURL(getSpecificAssetInformationAccessURL(dummyAasId));

BaSyxHttpTestUtils.assertSameJSONContent(json, BaSyxHttpTestUtils.getResponseAsString(response));
}

@Test
public void postAssetInformationToNonExistingAasByIdentifier()
throws FileNotFoundException, IOException, ParseException {

String json = BaSyxHttpTestUtils.readJSONStringFromFile("classpath:exampleAssetInfo.json");

CloseableHttpResponse response = BaSyxHttpTestUtils
.executeGetOnURL(getSpecificAssetInformationAccessURL("nonExisting"));

assertEquals(HttpStatus.NOT_FOUND.value(), response.getCode());
}


private String getSpecificAssetInformationAccessURL(String aasID) {
return getSpecificAasAccessURL(aasID) + "/asset-information";
}

@Test
Expand Down
Loading