Search in sources :

Example 1 with Property

use of com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Property in project azure-maven-plugins by microsoft.

the class AzureTelemeter method getParameterProperties.

private static Map<String, String> getParameterProperties(AzureOperationRef ref) {
    final HashMap<String, String> properties = new HashMap<>();
    final Object[] paramValues = ref.getParamValues();
    final Parameter[] parameters = ref.getMethod().getParameters();
    for (int i = 0; i < parameters.length; i++) {
        final Parameter param = parameters[i];
        final Object value = paramValues[i];
        Optional.ofNullable(param.getAnnotation(Property.class)).map(Property::value).map(n -> Property.PARAM_NAME.equals(n) ? param.getName() : n).ifPresent((name) -> properties.put(name, Optional.ofNullable(value).map(Object::toString).orElse("")));
        Optional.ofNullable(param.getAnnotation(Properties.class)).map(Properties::value).map(AzureTelemeter::instantiate).map(converter -> converter.convert(value)).ifPresent(properties::putAll);
    }
    return properties;
}
Also used : Setter(lombok.Setter) Getter(lombok.Getter) SneakyThrows(lombok.SneakyThrows) HashMap(java.util.HashMap) Instant(java.time.Instant) Property(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Property) Objects(java.util.Objects) AzureOperationRef(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef) Parameter(java.lang.reflect.Parameter) Properties(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Properties) Map(java.util.Map) Optional(java.util.Optional) IAzureOperation(com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) HashMap(java.util.HashMap) Properties(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Properties) Parameter(java.lang.reflect.Parameter) Property(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Property)

Aggregations

AzureOperationRef (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef)1 IAzureOperation (com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation)1 Properties (com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Properties)1 Property (com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Property)1 Parameter (java.lang.reflect.Parameter)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Getter (lombok.Getter)1 Setter (lombok.Setter)1 SneakyThrows (lombok.SneakyThrows)1 ExceptionUtils (org.apache.commons.lang3.exception.ExceptionUtils)1