Search in sources :

Example 1 with SetSubmodelElementValueByPathResponse

use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.SetSubmodelElementValueByPathResponse in project FAAAST-Service by FraunhoferIOSB.

the class RequestHandlerManagerTest method testSetSubmodelElementValueByPathRequest.

@Test
public void testSetSubmodelElementValueByPathRequest() throws ResourceNotFoundException, AssetConnectionException {
    when(persistence.get((Reference) any(), any())).thenReturn(environment.getSubmodels().get(0).getSubmodelElements().get(0));
    when(assetConnectionManager.hasValueProvider(any())).thenReturn(true);
    PropertyValue propertyValue = new PropertyValue.Builder().value(new StringValue("Test")).build();
    SetSubmodelElementValueByPathRequest request = new SetSubmodelElementValueByPathRequest.Builder<ElementValue>().id(environment.getSubmodels().get(0).getIdentification()).value(propertyValue).valueParser(new ElementValueParser<ElementValue>() {

        @Override
        public <U extends ElementValue> U parse(ElementValue raw, Class<U> type) {
            return (U) raw;
        }
    }).path(ReferenceHelper.toKeys(SUBMODEL_ELEMENT_REF)).build();
    Response response = manager.execute(request);
    SetSubmodelElementValueByPathResponse expected = new SetSubmodelElementValueByPathResponse.Builder().statusCode(StatusCode.Success).build();
    Assert.assertEquals(expected, response);
    verify(assetValueProvider).setValue(propertyValue);
}
Also used : SetSubmodelElementValueByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.SetSubmodelElementValueByPathRequest) GetAllConceptDescriptionsByDataSpecificationReferenceResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsByDataSpecificationReferenceResponse) PutSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelResponse) GetAllSubmodelsResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelsResponse) PutSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelElementByPathResponse) PostSubmodelElementResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementResponse) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) PostSubmodelReferenceResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelReferenceResponse) DeleteAssetAdministrationShellByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteAssetAdministrationShellByIdResponse) PostSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementByPathResponse) PutAssetAdministrationShellByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutAssetAdministrationShellByIdResponse) PostSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelResponse) GetSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelElementByPathResponse) GetAssetInformationResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAssetInformationResponse) DeleteSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelElementByPathResponse) DeleteConceptDescriptionByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteConceptDescriptionByIdResponse) GetAllSubmodelReferencesResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelReferencesResponse) PutSubmodelByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelByIdResponse) GetSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelResponse) GetAssetAdministrationShellResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAssetAdministrationShellResponse) GetAllConceptDescriptionsByIsCaseOfResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsByIsCaseOfResponse) PutConceptDescriptionByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutConceptDescriptionByIdResponse) Response(de.fraunhofer.iosb.ilt.faaast.service.model.api.Response) GetAllSubmodelsBySemanticIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelsBySemanticIdResponse) PutAssetInformationResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutAssetInformationResponse) DeleteSubmodelByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelByIdResponse) GetConceptDescriptionByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetConceptDescriptionByIdResponse) SetSubmodelElementValueByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.SetSubmodelElementValueByPathResponse) PutAssetAdministrationShellResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutAssetAdministrationShellResponse) PostAssetAdministrationShellResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostAssetAdministrationShellResponse) PostConceptDescriptionResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostConceptDescriptionResponse) GetAllAssetAdministrationShellsResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsResponse) GetSubmodelByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelByIdResponse) InvokeOperationAsyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationAsyncResponse) GetAllAssetAdministrationShellsByIdShortResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByIdShortResponse) GetAssetAdministrationShellByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAssetAdministrationShellByIdResponse) GetAllConceptDescriptionsByIdShortResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsByIdShortResponse) GetAllConceptDescriptionsResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsResponse) GetAllSubmodelElementsResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelElementsResponse) DeleteSubmodelReferenceResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelReferenceResponse) GetAllSubmodelsByIdShortResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelsByIdShortResponse) GetAllAssetAdministrationShellsByAssetIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByAssetIdResponse) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) StringValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.StringValue) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) SetSubmodelElementValueByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.SetSubmodelElementValueByPathResponse) Test(org.junit.Test)

Example 2 with SetSubmodelElementValueByPathResponse

use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.SetSubmodelElementValueByPathResponse in project FAAAST-Service by FraunhoferIOSB.

the class SetSubmodelElementValueByPathRequestHandler method process.

@Override
public SetSubmodelElementValueByPathResponse process(SetSubmodelElementValueByPathRequest request) {
    SetSubmodelElementValueByPathResponse response = new SetSubmodelElementValueByPathResponse();
    try {
        Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
        SubmodelElement submodelElement = persistence.get(reference, new OutputModifier.Builder().extend(Extend.WithBLOBValue).build());
        ElementValue oldValue = ElementValueMapper.toValue(submodelElement);
        if (request.getValueParser() != null) {
            ElementValue newValue = request.getValueParser().parse(request.getRawValue(), oldValue.getClass());
            ElementValueMapper.setValue(submodelElement, newValue);
            writeValueToAssetConnection(reference, newValue);
            persistence.put(null, reference, submodelElement);
            response.setStatusCode(StatusCode.Success);
            publishValueChangeEventMessage(reference, oldValue, newValue);
        } else {
            throw new RuntimeException("Value parser of request must be non-null");
        }
    } 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) OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) Reference(io.adminshell.aas.v3.model.Reference) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) SetSubmodelElementValueByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.SetSubmodelElementValueByPathResponse)

Aggregations

ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)1 Response (de.fraunhofer.iosb.ilt.faaast.service.model.api.Response)1 OutputModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier)1 DeleteAssetAdministrationShellByIdResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteAssetAdministrationShellByIdResponse)1 DeleteConceptDescriptionByIdResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteConceptDescriptionByIdResponse)1 DeleteSubmodelByIdResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelByIdResponse)1 DeleteSubmodelElementByPathResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelElementByPathResponse)1 DeleteSubmodelReferenceResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelReferenceResponse)1 GetAllAssetAdministrationShellsByAssetIdResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByAssetIdResponse)1 GetAllAssetAdministrationShellsByIdShortResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByIdShortResponse)1 GetAllAssetAdministrationShellsResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsResponse)1 GetAllConceptDescriptionsByDataSpecificationReferenceResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsByDataSpecificationReferenceResponse)1 GetAllConceptDescriptionsByIdShortResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsByIdShortResponse)1 GetAllConceptDescriptionsByIsCaseOfResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsByIsCaseOfResponse)1 GetAllConceptDescriptionsResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsResponse)1 GetAllSubmodelElementsResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelElementsResponse)1 GetAllSubmodelReferencesResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelReferencesResponse)1 GetAllSubmodelsByIdShortResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelsByIdShortResponse)1 GetAllSubmodelsBySemanticIdResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelsBySemanticIdResponse)1 GetAllSubmodelsResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelsResponse)1