use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByAssetIdResponse in project FAAAST-Service by FraunhoferIOSB.
the class GetAllAssetAdministrationShellsByAssetIdRequestHandler method process.
@Override
public GetAllAssetAdministrationShellsByAssetIdResponse process(GetAllAssetAdministrationShellsByAssetIdRequest request) {
GetAllAssetAdministrationShellsByAssetIdResponse response = new GetAllAssetAdministrationShellsByAssetIdResponse();
try {
List<AssetIdentification> assetIdentifications = new ArrayList<>();
List<IdentifierKeyValuePair> identifierKeyValuePairs = request.getAssetIds();
for (IdentifierKeyValuePair pair : identifierKeyValuePairs) {
AssetIdentification id = null;
if (pair.getKey().equalsIgnoreCase("globalAssetId")) {
id = new GlobalAssetIdentification.Builder().reference(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.GLOBAL_REFERENCE).value(pair.getValue()).build()).build()).build();
} else {
id = new SpecificAssetIdentification.Builder().value(pair.getValue()).key(pair.getKey()).build();
}
assetIdentifications.add(id);
}
List<AssetAdministrationShell> shells = new ArrayList<>(persistence.get(null, assetIdentifications, request.getOutputModifier()));
response.setPayload(shells);
response.setStatusCode(StatusCode.Success);
shells.forEach(x -> publishElementReadEventMessage(AasUtils.toReference(x), x));
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByAssetIdResponse in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testGetAllAssetAdministrationShellsByAssetIdRequest.
@Test
public void testGetAllAssetAdministrationShellsByAssetIdRequest() {
GlobalAssetIdentification globalAssetIdentification = new GlobalAssetIdentification.Builder().reference(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.GLOBAL_REFERENCE).value("TestValue").build()).build()).build();
SpecificAssetIdentification specificAssetIdentification = new SpecificAssetIdentification.Builder().value("TestValue").key("TestKey").build();
when(persistence.get(eq(null), eq(List.of(globalAssetIdentification, specificAssetIdentification)), any())).thenReturn(List.of(environment.getAssetAdministrationShells().get(0), environment.getAssetAdministrationShells().get(1)));
List<IdentifierKeyValuePair> assetIds = List.of(new DefaultIdentifierKeyValuePair.Builder().key("globalAssetId").value("TestValue").externalSubjectId(new DefaultReference.Builder().build()).build(), new DefaultIdentifierKeyValuePair.Builder().key("TestKey").value("TestValue").build());
GetAllAssetAdministrationShellsByAssetIdRequest request = new GetAllAssetAdministrationShellsByAssetIdRequest.Builder().assetIds(assetIds).build();
GetAllAssetAdministrationShellsByAssetIdResponse response = manager.execute(request);
GetAllAssetAdministrationShellsByAssetIdResponse expected = new GetAllAssetAdministrationShellsByAssetIdResponse.Builder().payload(List.of(environment.getAssetAdministrationShells().get(0), environment.getAssetAdministrationShells().get(1))).statusCode(StatusCode.Success).build();
Assert.assertEquals(expected, response);
}
Aggregations