Search in sources :

Example 1 with GetAllAssetAdministrationShellsByAssetIdResponse

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;
}
Also used : AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) IdentifierKeyValuePair(io.adminshell.aas.v3.model.IdentifierKeyValuePair) GetAllAssetAdministrationShellsByAssetIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByAssetIdResponse) GlobalAssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.GlobalAssetIdentification) SpecificAssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.SpecificAssetIdentification) AssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification) ArrayList(java.util.ArrayList) GlobalAssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.GlobalAssetIdentification) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference)

Example 2 with GetAllAssetAdministrationShellsByAssetIdResponse

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);
}
Also used : GetAllAssetAdministrationShellsByAssetIdRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.GetAllAssetAdministrationShellsByAssetIdRequest) DefaultIdentifierKeyValuePair(io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair) IdentifierKeyValuePair(io.adminshell.aas.v3.model.IdentifierKeyValuePair) SpecificAssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.SpecificAssetIdentification) DefaultIdentifierKeyValuePair(io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair) GetAllAssetAdministrationShellsByAssetIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByAssetIdResponse) GlobalAssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.GlobalAssetIdentification) Test(org.junit.Test)

Aggregations

GetAllAssetAdministrationShellsByAssetIdResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByAssetIdResponse)2 GlobalAssetIdentification (de.fraunhofer.iosb.ilt.faaast.service.model.asset.GlobalAssetIdentification)2 SpecificAssetIdentification (de.fraunhofer.iosb.ilt.faaast.service.model.asset.SpecificAssetIdentification)2 IdentifierKeyValuePair (io.adminshell.aas.v3.model.IdentifierKeyValuePair)2 AssetIdentification (de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification)1 GetAllAssetAdministrationShellsByAssetIdRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.GetAllAssetAdministrationShellsByAssetIdRequest)1 AssetAdministrationShell (io.adminshell.aas.v3.model.AssetAdministrationShell)1 DefaultIdentifierKeyValuePair (io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair)1 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)1 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1