Search in sources :

Example 1 with GetAllAssetAdministrationShellIdsByAssetLinkRequest

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;
}
Also used : MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) Objects(java.util.Objects) Identifiable(io.adminshell.aas.v3.model.Identifiable) List(java.util.List) StatusCode(de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode) FaaastConstants(de.fraunhofer.iosb.ilt.faaast.service.util.FaaastConstants) GetAllAssetAdministrationShellIdsByAssetLinkRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.GetAllAssetAdministrationShellIdsByAssetLinkRequest) GetAllAssetAdministrationShellIdsByAssetLinkResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellIdsByAssetLinkResponse) AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) Collectors(java.util.stream.Collectors) IdentifierKeyValuePair(io.adminshell.aas.v3.model.IdentifierKeyValuePair) IdentifierKeyValuePair(io.adminshell.aas.v3.model.IdentifierKeyValuePair) GetAllAssetAdministrationShellIdsByAssetLinkResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellIdsByAssetLinkResponse) Identifiable(io.adminshell.aas.v3.model.Identifiable)

Aggregations

AssetConnectionManager (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager)1 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)1 StatusCode (de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode)1 GetAllAssetAdministrationShellIdsByAssetLinkResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellIdsByAssetLinkResponse)1 GetAllAssetAdministrationShellIdsByAssetLinkRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.GetAllAssetAdministrationShellIdsByAssetLinkRequest)1 Persistence (de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence)1 FaaastConstants (de.fraunhofer.iosb.ilt.faaast.service.util.FaaastConstants)1 Identifiable (io.adminshell.aas.v3.model.Identifiable)1 IdentifierKeyValuePair (io.adminshell.aas.v3.model.IdentifierKeyValuePair)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1