use of de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testGetAllAssetAdministrationShellRequest.
@Test
public void testGetAllAssetAdministrationShellRequest() {
when(persistence.get(any(), argThat((List<AssetIdentification> t) -> true), any())).thenReturn(environment.getAssetAdministrationShells());
GetAllAssetAdministrationShellsRequest request = new GetAllAssetAdministrationShellsRequest();
GetAllAssetAdministrationShellsResponse response = manager.execute(request);
GetAllAssetAdministrationShellsResponse expected = new GetAllAssetAdministrationShellsResponse.Builder().payload(environment.getAssetAdministrationShells()).statusCode(StatusCode.Success).build();
Assert.assertEquals(expected, response);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testGetAllAssetAdministrationShellRequestAsync.
@Test
public void testGetAllAssetAdministrationShellRequestAsync() throws InterruptedException {
when(persistence.get(any(), argThat((List<AssetIdentification> t) -> true), any())).thenReturn(environment.getAssetAdministrationShells());
GetAllAssetAdministrationShellsRequest request = new GetAllAssetAdministrationShellsRequest();
final AtomicReference<GetAllAssetAdministrationShellsResponse> response = new AtomicReference<>();
CountDownLatch condition = new CountDownLatch(1);
manager.executeAsync(request, x -> response.set(x));
condition.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertEquals(environment.getAssetAdministrationShells(), response.get().getPayload());
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification in project FAAAST-Service by FraunhoferIOSB.
the class GetAllAssetAdministrationShellsByIdShortRequestHandler method process.
@Override
public GetAllAssetAdministrationShellsByIdShortResponse process(GetAllAssetAdministrationShellsByIdShortRequest request) {
GetAllAssetAdministrationShellsByIdShortResponse response = new GetAllAssetAdministrationShellsByIdShortResponse();
try {
List<AssetAdministrationShell> shells = persistence.get(request.getIdShort(), (List<AssetIdentification>) null, request.getOutputModifier());
response.setPayload(shells);
response.setStatusCode(StatusCode.Success);
if (shells != null) {
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.asset.AssetIdentification in project FAAAST-Service by FraunhoferIOSB.
the class GetAllAssetAdministrationShellsRequestHandler method process.
@Override
public GetAllAssetAdministrationShellsResponse process(GetAllAssetAdministrationShellsRequest request) {
GetAllAssetAdministrationShellsResponse response = new GetAllAssetAdministrationShellsResponse();
try {
List<AssetAdministrationShell> shells = persistence.get(null, (List<AssetIdentification>) null, request.getOutputModifier());
response.setPayload(shells);
response.setStatusCode(StatusCode.Success);
if (shells != null) {
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.asset.AssetIdentification 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;
}
Aggregations