use of com.adobe.target.delivery.v1.model.Property in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaAssetConnectionTest method testInvokeOperation.
private void testInvokeOperation(String nodeId, boolean sync, Map<String, PropertyValue> input, Map<String, PropertyValue> inoutput, Map<String, PropertyValue> expectedInoutput, Map<String, PropertyValue> expectedOutput) throws AssetConnectionException, InterruptedException, ConfigurationInitializationException {
Reference reference = AasUtils.parseReference("(Property)[ID_SHORT]Temperature");
OpcUaAssetConnectionConfig config = OpcUaAssetConnectionConfig.builder().host(serverUrl).operationProvider(reference, OpcUaOperationProviderConfig.builder().nodeId(nodeId).build()).build();
OperationVariable[] inputVariables = input == null ? new OperationVariable[0] : input.entrySet().stream().map(x -> {
Property property = new DefaultProperty.Builder().idShort(x.getKey()).build();
ElementValueMapper.setValue(property, x.getValue());
return new DefaultOperationVariable.Builder().value(property).build();
}).toArray(OperationVariable[]::new);
OperationVariable[] inoutputVariables = inoutput == null ? new OperationVariable[0] : inoutput.entrySet().stream().map(x -> {
Property property = new DefaultProperty.Builder().idShort(x.getKey()).build();
ElementValueMapper.setValue(property, x.getValue());
return new DefaultOperationVariable.Builder().value(property).build();
}).toArray(OperationVariable[]::new);
OperationVariable[] expectedInOut = expectedInoutput == null ? new OperationVariable[0] : expectedInoutput.entrySet().stream().map(x -> {
Property property = new DefaultProperty.Builder().idShort(x.getKey()).build();
ElementValueMapper.setValue(property, x.getValue());
return new DefaultOperationVariable.Builder().value(property).build();
}).toArray(OperationVariable[]::new);
OperationVariable[] expectedOut = expectedOutput == null ? new OperationVariable[0] : expectedOutput.entrySet().stream().map(x -> {
Property property = new DefaultProperty.Builder().idShort(x.getKey()).build();
ElementValueMapper.setValue(property, x.getValue());
return new DefaultOperationVariable.Builder().value(property).build();
}).toArray(OperationVariable[]::new);
ServiceContext serviceContext = mock(ServiceContext.class);
doReturn(expectedOut).when(serviceContext).getOperationOutputVariables(reference);
OpcUaAssetConnection connection = new OpcUaAssetConnection(CoreConfig.builder().build(), config, serviceContext);
OperationVariable[] actual;
if (sync) {
actual = connection.getOperationProviders().get(reference).invoke(inputVariables, inoutputVariables);
} else {
final AtomicReference<OperationVariable[]> operationResult = new AtomicReference<>();
final AtomicReference<OperationVariable[]> operationInout = new AtomicReference<>();
CountDownLatch condition = new CountDownLatch(1);
connection.getOperationProviders().get(reference).invokeAsync(inputVariables, inoutputVariables, (res, inout) -> {
operationResult.set(res);
operationInout.set(inout);
condition.countDown();
});
condition.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
actual = operationResult.get();
inoutputVariables = operationInout.get();
}
connection.close();
Assert.assertArrayEquals(expectedOut, actual);
Assert.assertArrayEquals(expectedInOut, inoutputVariables);
}
use of com.adobe.target.delivery.v1.model.Property in project FAAAST-Service by FraunhoferIOSB.
the class TypeExtractor method extractTypeInfo.
public static TypeInfo extractTypeInfo(Object obj) {
if (obj == null) {
return null;
}
Class<?> type = obj.getClass();
if (SubmodelElement.class.isAssignableFrom(type)) {
ElementValueTypeInfo.Builder builder = ElementValueTypeInfo.builder();
SubmodelElement submodelElement = (SubmodelElement) obj;
builder.type(ElementValueMapper.getValueClass(submodelElement.getClass()));
if (AnnotatedRelationshipElement.class.isAssignableFrom(type)) {
AnnotatedRelationshipElement annotatedRelationshipElement = (AnnotatedRelationshipElement) obj;
annotatedRelationshipElement.getAnnotations().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
} else if (SubmodelElementCollection.class.isAssignableFrom(type)) {
SubmodelElementCollection submodelElementCollection = (SubmodelElementCollection) obj;
submodelElementCollection.getValues().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
} else if (Entity.class.isAssignableFrom(type)) {
Entity entity = (Entity) obj;
entity.getStatements().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
} else if (Property.class.isAssignableFrom(obj.getClass())) {
Property property = (Property) obj;
builder.datatype(Datatype.fromName(property.getValueType()));
} else if (Range.class.isAssignableFrom(obj.getClass())) {
Range range = (Range) obj;
builder.datatype(Datatype.fromName(range.getValueType()));
}
return builder.build();
}
if (Submodel.class.isAssignableFrom(type)) {
Submodel submodel = (Submodel) obj;
ContainerTypeInfo.Builder<Object> builder = ContainerTypeInfo.<Object>builder();
builder.type(Submodel.class);
submodel.getSubmodelElements().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
return builder.build();
}
if (Collection.class.isAssignableFrom(type)) {
Collection collection = (Collection) obj;
ContainerTypeInfo.Builder<Integer> builder = ContainerTypeInfo.<Integer>builder();
builder.type(Collection.class);
builder.contentType(TypeToken.of(type).resolveType(COLLECTION_GENERIC_TOKEN).getRawType());
Iterator iterator = collection.iterator();
int i = 0;
while (iterator.hasNext()) {
builder.element(i, extractTypeInfo(iterator.next()));
i++;
}
return builder.build();
}
if (Map.class.isAssignableFrom(type)) {
Map map = (Map) obj;
ContainerTypeInfo.Builder<String> builder = ContainerTypeInfo.<String>builder();
builder.type(Map.class);
builder.contentType(TypeToken.of(type).resolveType(MAP_GENERIC_TOKEN).getRawType());
map.forEach((key, value) -> builder.element(key.toString(), extractTypeInfo(value)));
return builder.build();
}
if (type.isArray()) {
Object[] array = (Object[]) obj;
ContainerTypeInfo.Builder<Integer> builder = ContainerTypeInfo.<Integer>builder();
builder.type(Array.class);
builder.contentType(type.getComponentType());
for (int i = 0; i < array.length; i++) {
builder.element(i, extractTypeInfo(array[i]));
}
return builder.build();
}
return ContainerTypeInfo.<Object>builder().build();
}
use of com.adobe.target.delivery.v1.model.Property in project FAAAST-Service by FraunhoferIOSB.
the class JsonSerializerTest method testReferableSerialization.
@Test
public void testReferableSerialization() throws Exception {
Property property = new DefaultProperty.Builder().idShort("testShell").value("Test").build();
compareToAdminShellIoSerialization(property);
}
use of com.adobe.target.delivery.v1.model.Property in project commerce-gradle-plugin by SAP.
the class SharedPropertyValidator method validateProperties.
public List<Error> validateProperties(Collection<Property> properties) {
int index = 0;
List<Error> errors = new ArrayList<>();
for (Property property : properties) {
String location = String.format(locationPrefix + "properties[%d]", index);
if (!ALLOWED_PERSONAS.contains(property.persona)) {
errors.add(new Error.Builder().setLocation(location).setMessage("Persona `%s` not supported", property.persona).setCode("E-008").createError());
}
if (MANAGED_PROPERTIES.contains(property.key) || (location.contains("backoffice") && BACKOFFICE_MANAGED_PROPERTIES.contains(property.key))) {
errors.add(new Error.Builder().setLevel(Level.WARNING).setLocation(location).setMessage("Property `%s` is a managed property. Are you sure you need to modify it?", property.key).setCode("W-001").createError());
}
index += 1;
}
return errors;
}
use of com.adobe.target.delivery.v1.model.Property in project commerce-gradle-plugin by SAP.
the class WebrootValidator method validate.
@Override
public List<Error> validate(Manifest manifest) throws Exception {
Map<String, Set<String>> occurences = new HashMap<>();
for (int i = 0; i < manifest.properties.size(); i++) {
Property p = manifest.properties.get(i);
String location = String.format("properties[%d]", i);
checkProperty(p.key, location, occurences);
}
for (int i = 0; i < manifest.useConfig.properties.size(); i++) {
Properties properties = manifest.useConfig.properties.get(i);
Tuple2<Path, List<Error>> result = ValidationUtils.validateAndNormalizePath(this.projectRoot, "", properties.location);
if (result.getFirst() != null) {
try (InputStream stream = Files.newInputStream(result.getFirst())) {
java.util.Properties props = new java.util.Properties();
props.load(stream);
String location = String.format("useConfig.properties[%d].location (%s)", i, properties.location);
for (Map.Entry<Object, Object> entry : props.entrySet()) {
checkProperty((String) entry.getKey(), location, occurences);
}
} catch (IOException e) {
// ignore
}
}
}
for (Aspect aspect : manifest.aspects) {
for (int i = 0; i < aspect.properties.size(); i++) {
Property p = aspect.properties.get(i);
String location = String.format("aspects[?name == '%s'].properties[%d]", aspect.name, i);
checkProperty(p.key, location, occurences);
}
}
if (occurences.isEmpty()) {
return Collections.emptyList();
} else {
List<Error> errors = new ArrayList<>();
for (Map.Entry<String, Set<String>> errorEntry : occurences.entrySet()) {
errors.add(new Error.Builder().setLocation(errorEntry.getKey()).setCode("E-017").setMessage("Do not configure webroots in properties.\nFaulty properties:\n- " + String.join("\n -", errorEntry.getValue())).createError());
}
return errors;
}
}
Aggregations