Search in sources :

Example 21 with Property

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);
}
Also used : DefaultOperationVariable(io.adminshell.aas.v3.model.impl.DefaultOperationVariable) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Reference(io.adminshell.aas.v3.model.Reference) ServiceContext(de.fraunhofer.iosb.ilt.faaast.service.ServiceContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) Property(io.adminshell.aas.v3.model.Property)

Example 22 with Property

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();
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Array(java.lang.reflect.Array) Iterator(java.util.Iterator) AnnotatedRelationshipElement(io.adminshell.aas.v3.model.AnnotatedRelationshipElement) Collection(java.util.Collection) ElementValueMapper(de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) TypeToken(com.google.common.reflect.TypeToken) Property(io.adminshell.aas.v3.model.Property) Type(java.lang.reflect.Type) Range(io.adminshell.aas.v3.model.Range) Map(java.util.Map) Entity(io.adminshell.aas.v3.model.Entity) Submodel(io.adminshell.aas.v3.model.Submodel) Submodel(io.adminshell.aas.v3.model.Submodel) Entity(io.adminshell.aas.v3.model.Entity) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) AnnotatedRelationshipElement(io.adminshell.aas.v3.model.AnnotatedRelationshipElement) Range(io.adminshell.aas.v3.model.Range) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Iterator(java.util.Iterator) Collection(java.util.Collection) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) Property(io.adminshell.aas.v3.model.Property) Map(java.util.Map)

Example 23 with Property

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);
}
Also used : DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) Property(io.adminshell.aas.v3.model.Property) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) Test(org.junit.Test)

Example 24 with 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;
}
Also used : Error(mpern.sap.commerce.ccv2.validation.Error) Property(mpern.sap.commerce.ccv2.model.Property)

Example 25 with Property

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;
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) Error(mpern.sap.commerce.ccv2.validation.Error) IOException(java.io.IOException) Properties(mpern.sap.commerce.ccv2.model.useconfig.Properties) Aspect(mpern.sap.commerce.ccv2.model.Aspect) java.util(java.util) Property(mpern.sap.commerce.ccv2.model.Property)

Aggregations

TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)10 Property (com.adobe.target.delivery.v1.model.Property)9 Test (org.junit.jupiter.api.Test)9 Context (com.adobe.target.delivery.v1.model.Context)8 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)8 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)8 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)8 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)8 TimingTool (com.adobe.target.edge.client.utils.TimingTool)8 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)7 Property (io.adminshell.aas.v3.model.Property)7 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)5 TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse)5 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)5 ArrayList (java.util.ArrayList)5 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)4 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)4 HashMap (java.util.HashMap)4 Property (model.Property)4 Type (model.Type)3