Search in sources :

Example 1 with Response

use of de.fraunhofer.iosb.ilt.faaast.service.model.api.Response 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 Response

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

the class OpcUaEndpoint method writeValue.

/**
 * Writes the Value of the given SubmodelElement into the service.
 *
 * @param element The desired SubmodelElement including the new value
 * @param submodel The corresponding submodel
 * @param refElement The reference to the SubmodelElement
 * @return True if the write succeeded, false otherwise
 */
public boolean writeValue(SubmodelElement element, Submodel submodel, Reference refElement) {
    boolean retval = false;
    if (element == null) {
        throw new IllegalArgumentException("element == null");
    } else if (submodel == null) {
        throw new IllegalArgumentException("submodel == null");
    }
    try {
        SetSubmodelElementValueByPathRequest request = new SetSubmodelElementValueByPathRequest();
        List<Key> path = new ArrayList<>();
        path.addAll(refElement.getKeys());
        request.setId(submodel.getIdentification());
        request.setPath(path);
        request.setValueParser(new OpcUaElementValueParser());
        if (element instanceof MultiLanguageProperty) {
            MultiLanguageProperty mlp = (MultiLanguageProperty) element;
            if ((mlp.getValues() != null) && (mlp.getValues().size() > 1)) {
                for (int i = 0; i < mlp.getValues().size(); i++) {
                    logger.info("writeValue: MLP " + i + ": " + mlp.getValues().get(i).getValue());
                }
            }
        }
        request.setRawValue(ElementValueMapper.toValue(element));
        if (request.getRawValue() instanceof MultiLanguagePropertyValue) {
            MultiLanguagePropertyValue mlpv = (MultiLanguagePropertyValue) request.getRawValue();
            if ((mlpv.getLangStringSet() != null) && (mlpv.getLangStringSet().size() > 1)) {
                for (int i = 0; i < mlpv.getLangStringSet().size(); i++) {
                    logger.info("writeValue: MLPV " + i + ": " + mlpv.getLangStringSet().toArray()[i]);
                }
            }
        }
        Response response = service.execute(request);
        logger.info("writeValue: Submodel " + submodel.getIdentification().getIdentifier() + "; Element " + element.getIdShort() + "; Status: " + response.getStatusCode());
        if (isSuccess(response.getStatusCode())) {
            retval = true;
        }
    } catch (Exception ex) {
        logger.error("writeValue error", ex);
    }
    return retval;
}
Also used : SetSubmodelElementValueByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.SetSubmodelElementValueByPathRequest) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) Response(de.fraunhofer.iosb.ilt.faaast.service.model.api.Response) MultiLanguageProperty(io.adminshell.aas.v3.model.MultiLanguageProperty) ArrayList(java.util.ArrayList) Key(io.adminshell.aas.v3.model.Key) Endpoint(de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint) StatusException(com.prosysopc.ua.StatusException) MultiLanguagePropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue)

Example 3 with Response

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

the class HttpEndpointTest method testGetAllSubmodelElements_ValueOnly.

@Test
public void testGetAllSubmodelElements_ValueOnly() throws Exception {
    List<SubmodelElement> submodelElements = List.of(new DefaultProperty.Builder().idShort("property1").value("hello world").valueType("string").build(), new DefaultRange.Builder().idShort("range1").min("1.1").max("2.0").valueType("double").build());
    when(serviceContext.execute(any())).thenReturn(GetAllSubmodelElementsResponse.builder().statusCode(StatusCode.Success).payload(submodelElements).build());
    ContentResponse response = execute(HttpMethod.GET, "/submodels/foo/submodel/submodel-elements", new OutputModifier.Builder().content(Content.Value).build());
    Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
    List<ElementValue> actual = deserializer.readValueList(new String(response.getContent()), TypeExtractor.extractTypeInfo(submodelElements));
    List<ElementValue> expected = submodelElements.stream().map(x -> (ElementValue) ElementValueMapper.toValue(x)).collect(Collectors.toList());
    Assert.assertEquals(expected, actual);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) TypeExtractor(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeExtractor) BeforeClass(org.junit.BeforeClass) Date(java.util.Date) DefaultRange(io.adminshell.aas.v3.model.impl.DefaultRange) OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) LoggerFactory(org.slf4j.LoggerFactory) ServiceContext(de.fraunhofer.iosb.ilt.faaast.service.ServiceContext) AASFull(de.fraunhofer.iosb.ilt.faaast.service.model.AASFull) HttpJsonDeserializer(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.serialization.HttpJsonDeserializer) Request(org.eclipse.jetty.client.api.Request) Identifier(io.adminshell.aas.v3.model.Identifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) ServerSocket(java.net.ServerSocket) HttpClient(org.eclipse.jetty.client.HttpClient) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Message(de.fraunhofer.iosb.ilt.faaast.service.model.api.Message) StatusCode(de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode) StringRequestContent(org.eclipse.jetty.client.util.StringRequestContent) Map(java.util.Map) HttpStatus(org.eclipse.jetty.http.HttpStatus) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) EncodingHelper(de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper) ElementValueMapper(de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) de.fraunhofer.iosb.ilt.faaast.service.model.api.response(de.fraunhofer.iosb.ilt.faaast.service.model.api.response) Collectors(java.util.stream.Collectors) Result(de.fraunhofer.iosb.ilt.faaast.service.model.api.Result) List(java.util.List) HttpMethod(org.eclipse.jetty.http.HttpMethod) Ignore(org.junit.Ignore) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) Assert(org.junit.Assert) MessageType(de.fraunhofer.iosb.ilt.faaast.service.model.api.MessageType) Content(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content) Mockito.mock(org.mockito.Mockito.mock) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) Test(org.junit.Test)

Aggregations

Response (de.fraunhofer.iosb.ilt.faaast.service.model.api.Response)2 InvokeOperationSyncResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse)2 SetSubmodelElementValueByPathRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.SetSubmodelElementValueByPathRequest)2 ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)2 Test (org.junit.Test)2 StatusException (com.prosysopc.ua.StatusException)1 ServiceContext (de.fraunhofer.iosb.ilt.faaast.service.ServiceContext)1 CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)1 Endpoint (de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint)1 HttpJsonDeserializer (de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.serialization.HttpJsonDeserializer)1 AASFull (de.fraunhofer.iosb.ilt.faaast.service.model.AASFull)1 Message (de.fraunhofer.iosb.ilt.faaast.service.model.api.Message)1 MessageType (de.fraunhofer.iosb.ilt.faaast.service.model.api.MessageType)1 Result (de.fraunhofer.iosb.ilt.faaast.service.model.api.Result)1 StatusCode (de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode)1 Content (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content)1 OutputModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier)1 de.fraunhofer.iosb.ilt.faaast.service.model.api.response (de.fraunhofer.iosb.ilt.faaast.service.model.api.response)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