use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testEntityToValueMapping.
@Test
public void testEntityToValueMapping() throws ValueFormatException {
EntityValue expected = 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 input = new DefaultEntity.Builder().statement(new DefaultProperty.Builder().category("Test").idShort(expected.getStatements().keySet().iterator().next()).valueType(Datatype.String.getName()).value("foo").build()).entityType(expected.getEntityType()).globalAssetId(new DefaultReference.Builder().keys(expected.getGlobalAssetId()).build()).build();
ElementValue actual = ElementValueMapper.toValue(input);
Assert.assertEquals(expected, actual);
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testReferenceElementSetValueMapping.
@Test
public void testReferenceElementSetValueMapping() {
SubmodelElement actual = new DefaultReferenceElement.Builder().value(new DefaultReference.Builder().build()).build();
ReferenceElementValue value = ReferenceElementValue.builder().key(KeyType.IRI, KeyElements.SUBMODEL, "http://example.org/submodel/1").key(KeyType.ID_SHORT, KeyElements.PROPERTY, "property1").build();
SubmodelElement expected = new DefaultReferenceElement.Builder().value(new DefaultReference.Builder().keys(value.getKeys()).build()).build();
ElementValueMapper.setValue(actual, value);
Assert.assertEquals(expected, actual);
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class PutSubmodelRequestHandler method process.
@Override
public PutSubmodelResponse process(PutSubmodelRequest request) {
PutSubmodelResponse response = new PutSubmodelResponse();
try {
// check if resource does exist
Submodel submodel = (Submodel) persistence.get(request.getSubmodel().getIdentification(), new QueryModifier.Builder().extend(Extend.WithoutBLOBValue).level(Level.Core).build());
submodel = (Submodel) persistence.put(request.getSubmodel());
response.setPayload(submodel);
response.setStatusCode(StatusCode.Success);
Reference reference = AasUtils.toReference(submodel);
readValueFromAssetConnectionAndUpdatePersistence(reference, submodel.getSubmodelElements());
publishElementUpdateEventMessage(reference, submodel);
} catch (ResourceNotFoundException ex) {
response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
use of io.adminshell.aas.v3.model.Submodel 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;
}
use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpoint method callOperation.
/**
* Calls the desired operation in the service.
*
* @param operation The desired operation
* @param inputVariables The input arguments
* @param submodel The corresponding submodel
* @param refElement The reference to the SubmodelElement
* @return The OutputArguments The output arguments returned from the operation call
* @throws StatusException If the operation fails
*/
public List<OperationVariable> callOperation(Operation operation, List<OperationVariable> inputVariables, Submodel submodel, Reference refElement) throws StatusException {
List<OperationVariable> outputArguments;
try {
InvokeOperationSyncRequest request = new InvokeOperationSyncRequest();
List<Key> path = new ArrayList<>();
path.addAll(refElement.getKeys());
request.setId(submodel.getIdentification());
request.setPath(path);
request.setInputArguments(inputVariables);
request.setContent(Content.Normal);
requestCounter++;
request.setRequestId(Integer.toString(requestCounter));
// execute method
InvokeOperationSyncResponse response = (InvokeOperationSyncResponse) service.execute(request);
if (isSuccess(response.getStatusCode())) {
logger.info("callOperation: Operation " + operation.getIdShort() + " executed successfully");
} else if (response.getStatusCode() == StatusCode.ClientMethodNotAllowed) {
logger.warn("callOperation: Operation " + operation.getIdShort() + " error executing operation: " + response.getStatusCode());
throw new StatusException(StatusCodes.Bad_NotExecutable);
} else {
logger.warn("callOperation: Operation " + operation.getIdShort() + " error executing operation: " + response.getStatusCode());
throw new StatusException(StatusCodes.Bad_UnexpectedError);
}
outputArguments = response.getPayload().getOutputArguments();
} catch (Exception ex) {
logger.error("callOperation error", ex);
throw ex;
}
return outputArguments;
}
Aggregations