Skip to content

Conversation

@hadijannat
Copy link

@hadijannat hadijannat commented Mar 20, 2024

The procedure is as follows:

  • It first extracts the specific Asset IDs from the request,
  • then transforms the base64url-encoded specificAssetIds into JSON and decodes the JSON via the HTTPApiDecoder to SpecificAssetId instances.
  • Finally, it uses the SpecificAssetId instances to filter the AAS contained in the object store and only returns AAS that match all SpecificAssetIds.

First, it ensures that we have an appropriate method in HTTPApiDecoder to handle decoding base64url-encoded strings into JSON and then into SpecificAssetId instances.

import base64
import json

class HTTPApiDecoder:
    # Existing class content...

    @staticmethod
    def decode_specific_asset_ids(encoded_ids: str):
        # Decoding from base64url and transforming to JSON
        decoded_json = base64.urlsafe_b64decode(encoded_ids + '===').decode('utf-8')
        # Assuming the JSON represents a list of SpecificAssetId objects
        specific_asset_ids = json.loads(decoded_json)
        # Transform the list of dictionaries into SpecificAssetId instances
        return [model.SpecificAssetId(**id_dict) for id_dict in specific_asset_ids]

Finally, the modified get_aas_all function to use this new method for filtering based on SpecificAssetIds is like below:

def get_aas_all(self, request: Request, url_args: Dict, **_kwargs) -> Response:
    response_t = get_response_type(request)
    aas: Iterator[model.AssetAdministrationShell] = self._get_all_obj_of_type(model.AssetAdministrationShell)

    # Filter by 'idShort' if the parameter is provided in the request
    id_short = request.args.get("idShort")
    if id_short is not None:
        aas = filter(lambda shell: shell.id_short == id_short, aas)
    
    # Filtering by base64url encoded SpecificAssetIds if provided
    asset_ids = request.args.get("assetIds")
    if asset_ids is not None:
        # Use the new method to decode and instantiate SpecificAssetIds
        spec_asset_ids = HTTPApiDecoder.decode_specific_asset_ids(asset_ids)
        # Filter the AAS based on these SpecificAssetIds
        aas = filter(lambda shell: all(spec_id in [id_.identifier for id_ in shell.specific_asset_ids] for spec_id in spec_asset_ids), aas)
    
    aas_list = list(aas)
    return response_t(aas_list)

@hadijannat hadijannat changed the base branch from main to feature/http_api March 20, 2024 11:49
@jkhsjdhjs jkhsjdhjs force-pushed the feature/aas_specific_asset_id_filtering branch from 39257db to 3c83221 Compare March 20, 2024 15:26
Copy link

@jkhsjdhjs jkhsjdhjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work, but the idea is correct. The changes required to make it work should be relatively simple.
Furthermore, I already rebased the branch to resolve conflicts that arose due to #22. Before you continue to work on this, you should do the following to remove the commit you have locally and pull the commit I rebased.

git reset --hard HEAD\^
git pull

@s-heppner
Copy link

s-heppner commented Mar 27, 2024

After you did what @jkhsjdhjs suggested, have a look at the StaticAnalysis Test on this page here:

basyx/aas/adapter/http.py:617: error: "AssetInformation" has no attribute "specific_asset_ids"; maybe "specific_asset_id" or "_specific_asset_id"?  [attr-defined]

Other than that, the logic seems fine to me.

@hadijannat hadijannat requested review from jkhsjdhjs and removed request for jkhsjdhjs March 28, 2024 10:41
@hadijannat hadijannat force-pushed the feature/aas_specific_asset_id_filtering branch from 8fddc50 to 5ec7766 Compare April 2, 2024 10:50
@jkhsjdhjs jkhsjdhjs force-pushed the feature/aas_specific_asset_id_filtering branch 2 times, most recently from e817fd3 to a46a296 Compare April 2, 2024 11:45
@jkhsjdhjs jkhsjdhjs force-pushed the feature/aas_specific_asset_id_filtering branch from a46a296 to 216e5b3 Compare April 2, 2024 11:47
@jkhsjdhjs jkhsjdhjs changed the title adapter.http: AAS Specific asset id filtering adapter.http: AAS SpecificAssetId filtering Apr 2, 2024
@jkhsjdhjs jkhsjdhjs force-pushed the feature/aas_specific_asset_id_filtering branch from e8368d5 to a97201c Compare April 2, 2024 12:21
Copy link

@jkhsjdhjs jkhsjdhjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@s-heppner s-heppner merged commit 237aebe into feature/http_api Apr 3, 2024
@s-heppner s-heppner deleted the feature/aas_specific_asset_id_filtering branch April 3, 2024 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants