use of de.fraunhofer.iosb.ilt.faaast.service.model.request.GetAllAssetAdministrationShellIdsByAssetLinkRequest in project FAAAST-Service by FraunhoferIOSB.
the class GetAllAssetAdministrationShellIdsByAssetLinkRequestHandler method process.
@Override
public GetAllAssetAdministrationShellIdsByAssetLinkResponse process(GetAllAssetAdministrationShellIdsByAssetLinkRequest request) {
GetAllAssetAdministrationShellIdsByAssetLinkResponse response = new GetAllAssetAdministrationShellIdsByAssetLinkResponse();
// TODO update Persistence interface to forward query; specification does not say whether to use AND or OR on global/specific assetIds
List<String> globalAssetIds = request.getAssetIdentifierPairs().stream().filter(x -> Objects.equals(FaaastConstants.KEY_GLOBAL_ASSET_ID, x.getKey())).map(IdentifierKeyValuePair::getValue).collect(Collectors.toList());
List<IdentifierKeyValuePair> specificAssetIds = request.getAssetIdentifierPairs().stream().filter(x -> !Objects.equals(FaaastConstants.KEY_GLOBAL_ASSET_ID, x.getKey())).collect(Collectors.toList());
response.setPayload(persistence.getEnvironment().getAssetAdministrationShells().stream().filter(aas -> {
boolean globalMatch = aas.getAssetInformation().getGlobalAssetId() != null && aas.getAssetInformation().getGlobalAssetId().getKeys() != null && !aas.getAssetInformation().getGlobalAssetId().getKeys().isEmpty() && globalAssetIds.contains(aas.getAssetInformation().getGlobalAssetId().getKeys().get(aas.getAssetInformation().getGlobalAssetId().getKeys().size() - 1).getValue());
boolean specificMatch = specificAssetIds.stream().allMatch(x -> aas.getAssetInformation().getSpecificAssetIds().contains(x));
if (!globalAssetIds.isEmpty() && specificAssetIds.isEmpty()) {
return globalMatch;
}
if (globalAssetIds.isEmpty() && !specificAssetIds.isEmpty()) {
return specificMatch;
}
if (!globalAssetIds.isEmpty() && !specificAssetIds.isEmpty()) {
return globalMatch || specificMatch;
}
return true;
}).map(Identifiable::getIdentification).collect(Collectors.toList()));
response.setStatusCode(StatusCode.SUCCESS);
return response;
}
Aggregations