Search in sources :

Example 1 with SubmodelElement

use of io.adminshell.aas.v3.model.SubmodelElement in project FAAAST-Service by FraunhoferIOSB.

the class RequestHandlerManagerTest method testReadValueFromAssetConnectionAndUpdatePersistence.

@Test
public void testReadValueFromAssetConnectionAndUpdatePersistence() throws AssetConnectionException, ResourceNotFoundException {
    RequestHandler requestHandler = new DeleteSubmodelByIdRequestHandler(persistence, messageBus, assetConnectionManager);
    Reference parentRef = new DefaultReference.Builder().key(new DefaultKey.Builder().value("sub").idType(KeyType.IRI).type(KeyElements.SUBMODEL).build()).build();
    SubmodelElement prop1 = new DefaultProperty.Builder().idShort("prop1").value("test").valueType("string").build();
    SubmodelElement range = new DefaultRange.Builder().idShort("range1").max("1.0").min("0").valueType("double").build();
    SubmodelElement prop2 = new DefaultProperty.Builder().idShort("prop2").value("test").valueType("string").build();
    SubmodelElementCollection collection = new DefaultSubmodelElementCollection.Builder().idShort("col1").value(prop2).build();
    SubmodelElement prop1_new = new DefaultProperty.Builder().idShort("prop1").value("testNew").valueType("string").build();
    SubmodelElement range_new = new DefaultRange.Builder().idShort("range1").max("1.0").min("0").valueType("double").build();
    SubmodelElement prop2_new = new DefaultProperty.Builder().idShort("prop2").value("testNew").valueType("string").build();
    List<SubmodelElement> submodelElements = List.of(prop1, range, collection);
    AssetValueProvider provider_prop1 = mock(AssetValueProvider.class);
    AssetValueProvider provider_prop2 = mock(AssetValueProvider.class);
    AssetValueProvider provider_range1 = mock(AssetValueProvider.class);
    when(assetConnectionManager.hasValueProvider(any())).thenReturn(true);
    // mock value prop1
    when(assetConnectionManager.getValueProvider(AasUtils.toReference(parentRef, prop1))).thenReturn(provider_prop1);
    when(provider_prop1.getValue()).thenReturn(ElementValueMapper.toValue(prop1_new));
    // mock value prop2
    when(assetConnectionManager.getValueProvider(AasUtils.toReference(AasUtils.toReference(parentRef, collection), prop2))).thenReturn(provider_prop2);
    when(provider_prop2.getValue()).thenReturn(ElementValueMapper.toValue(prop2_new));
    // mock value range
    when(assetConnectionManager.getValueProvider(AasUtils.toReference(parentRef, range))).thenReturn(provider_range1);
    when(provider_range1.getValue()).thenReturn(ElementValueMapper.toValue(range_new));
    requestHandler.readValueFromAssetConnectionAndUpdatePersistence(parentRef, submodelElements);
    verify(persistence).put(null, AasUtils.toReference(parentRef, prop1), prop1_new);
    verify(persistence).put(null, AasUtils.toReference(AasUtils.toReference(parentRef, collection), prop2), prop2_new);
    Assert.assertEquals(prop1_new, prop1);
    Assert.assertEquals(prop2_new, prop2);
    Assert.assertEquals(range_new, range);
}
Also used : DeleteSubmodelByIdRequestHandler(de.fraunhofer.iosb.ilt.faaast.service.request.handler.DeleteSubmodelByIdRequestHandler) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) RequestHandler(de.fraunhofer.iosb.ilt.faaast.service.request.handler.RequestHandler) DeleteSubmodelByIdRequestHandler(de.fraunhofer.iosb.ilt.faaast.service.request.handler.DeleteSubmodelByIdRequestHandler) DefaultRange(io.adminshell.aas.v3.model.impl.DefaultRange) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultSubmodelElementCollection(io.adminshell.aas.v3.model.impl.DefaultSubmodelElementCollection) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) DefaultSubmodelElementCollection(io.adminshell.aas.v3.model.impl.DefaultSubmodelElementCollection) AssetValueProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetValueProvider) Test(org.junit.Test)

Example 2 with SubmodelElement

use of io.adminshell.aas.v3.model.SubmodelElement in project FAAAST-Service by FraunhoferIOSB.

the class RequestHandlerManagerTest method testPostSubmodelElementRequest.

@Test
public void testPostSubmodelElementRequest() throws ResourceNotFoundException {
    Reference reference = ReferenceHelper.toReference(environment.getSubmodels().get(0).getIdentification(), Submodel.class);
    when(persistence.put(reference, (Reference) null, environment.getSubmodels().get(0).getSubmodelElements().get(0))).thenReturn(environment.getSubmodels().get(0).getSubmodelElements().get(0));
    PostSubmodelElementRequest request = new PostSubmodelElementRequest.Builder().id(environment.getSubmodels().get(0).getIdentification()).submodelElement(environment.getSubmodels().get(0).getSubmodelElements().get(0)).build();
    PostSubmodelElementResponse response = manager.execute(request);
    PostSubmodelElementResponse expected = new PostSubmodelElementResponse.Builder().statusCode(StatusCode.SuccessCreated).payload(environment.getSubmodels().get(0).getSubmodelElements().get(0)).build();
    Assert.assertEquals(expected, response);
}
Also used : Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) PostSubmodelElementRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.PostSubmodelElementRequest) PostSubmodelElementResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementResponse) Test(org.junit.Test)

Example 3 with SubmodelElement

use of io.adminshell.aas.v3.model.SubmodelElement in project FAAAST-Service by FraunhoferIOSB.

the class InvokeOperationSyncRequestHandler method process.

@Override
public InvokeOperationSyncResponse process(InvokeOperationSyncRequest request) {
    Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
    InvokeOperationSyncResponse response = new InvokeOperationSyncResponse();
    try {
        // Check if submodelelement does exist
        Operation operation = (Operation) persistence.get(reference, new OutputModifier());
        publishOperationInvokeEventMessage(reference, toValues(request.getInputArguments()), toValues(request.getInoutputArguments()));
        OperationResult operationResult = executeOperationSync(reference, request);
        response.setPayload(operationResult);
        response.setStatusCode(StatusCode.Success);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    publishOperationFinishEventMessage(reference, toValues(response.getPayload().getOutputArguments()), toValues(response.getPayload().getInoutputArguments()));
    return response;
}
Also used : OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) Reference(io.adminshell.aas.v3.model.Reference) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Operation(io.adminshell.aas.v3.model.Operation) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) TimeoutException(java.util.concurrent.TimeoutException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 4 with SubmodelElement

use of io.adminshell.aas.v3.model.SubmodelElement in project FAAAST-Service by FraunhoferIOSB.

the class PostSubmodelElementRequestHandler method process.

@Override
public PostSubmodelElementResponse process(PostSubmodelElementRequest request) {
    PostSubmodelElementResponse response = new PostSubmodelElementResponse();
    try {
        Reference parentReference = ReferenceHelper.toReference(request.getId(), Submodel.class);
        Reference childReference = AasUtils.toReference(parentReference, request.getSubmodelElement());
        SubmodelElement submodelElement = persistence.put(parentReference, null, request.getSubmodelElement());
        response.setPayload(submodelElement);
        response.setStatusCode(StatusCode.SuccessCreated);
        writeValueToAssetConnection(childReference, ElementValueMapper.toValue(submodelElement));
        publishElementCreateEventMessage(parentReference, submodelElement);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) PostSubmodelElementResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementResponse) Reference(io.adminshell.aas.v3.model.Reference) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 5 with SubmodelElement

use of io.adminshell.aas.v3.model.SubmodelElement in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testEntitySetValueMapping.

@Test
public void testEntitySetValueMapping() throws ValueFormatException {
    SubmodelElement actual = new DefaultEntity.Builder().statement(new DefaultProperty.Builder().idShort("property").build()).build();
    EntityValue value = EntityValue.builder().statement("property", PropertyValue.of(Datatype.String, "foo")).entityType(EntityType.SELF_MANAGED_ENTITY).globalAssetId(List.of(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("http://example.org/submodel/1").build(), new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.PROPERTY).value("property1").build())).build();
    SubmodelElement expected = new DefaultEntity.Builder().statement(new DefaultProperty.Builder().idShort(value.getStatements().keySet().iterator().next()).valueType(Datatype.String.getName()).value("foo").build()).entityType(value.getEntityType()).globalAssetId(new DefaultReference.Builder().keys(value.getGlobalAssetId()).build()).build();
    ElementValueMapper.setValue(actual, value);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) EntityValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.EntityValue) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Test(org.junit.Test)

Aggregations

SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)63 Test (org.junit.Test)47 Reference (io.adminshell.aas.v3.model.Reference)31 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)28 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)21 ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)20 OutputModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier)17 QueryModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier)16 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)16 Submodel (io.adminshell.aas.v3.model.Submodel)15 SubmodelElementCollection (io.adminshell.aas.v3.model.SubmodelElementCollection)15 List (java.util.List)15 Collectors (java.util.stream.Collectors)15 Assert (org.junit.Assert)13 AnnotatedRelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)12 DefaultIdentifier (io.adminshell.aas.v3.model.impl.DefaultIdentifier)12 ReferenceElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue)11 RelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue)11 AssetAdministrationShell (io.adminshell.aas.v3.model.AssetAdministrationShell)11 Identifier (io.adminshell.aas.v3.model.Identifier)11