How can I directly display the name of dimensions in Cumulocity / Java

I want to send MeasurementValuesin Cumulocityand visualize data using the specified tools. What values ​​are sent by my software is indicated in JSON and after compilation it needs to be changed.

My problem:

The Java CumulocityFramework does not allow me to specify the name of the dimension fragment that will be displayed on their website. The name is always the name of the class POJOthat I used to create the dimension. Since I want to send many different variables (which will also change over time), it is impractical to just create many POJO classes in advance.

My question is:

How can I - send measurements from the same class - display different values ​​in Cumulocitywith different names using the Java CumulocityFramework?

What I have tried so far:

  • There is no dimension property that allows me to change the display name
  • Unable to change class name at runtime (compiled ^^)
  • Cumulocity Java Framework does not give me direct access to a property
+4
source share
1 answer

I don’t know if I fully understand what dimension name you want to change, but I assume that you mean the name of the dimension fragment.

When you have created your own dimension in the Java project, you have the ability to annotate it using @alias , to include your user name

package c8y.tinkerforge.measurements;

import java.math.BigDecimal;

import org.svenson.AbstractDynamicProperties;
import org.svenson.JSONProperty;

import com.cumulocity.model.measurement.MeasurementValue;
import com.cumulocity.model.util.Alias;

@Alias("c8y_Acceleration")
public class AccelerationCombinedMeasurement extends AbstractDynamicProperties {

    private static final long serialVersionUID = -2491579656609755745L;

    public static final String DEFAULT_UNIT = "g";

    private final String unit;

    private MeasurementValue accelerationX;

    private MeasurementValue accelerationY;

    private MeasurementValue accelerationZ;

    public AccelerationCombinedMeasurement(double accelerationX, double accelerationY, double accelerationZ,
            final String unit) {
        this.unit = unit;
        this.accelerationX = new MeasurementValue(new BigDecimal(accelerationX), unit);
        this.accelerationY = new MeasurementValue(new BigDecimal(accelerationY), unit);
        this.accelerationZ = new MeasurementValue(new BigDecimal(accelerationZ), unit);
    }

    @JSONProperty("accelerationX")
    public MeasurementValue getAccelerationX() {
        return accelerationX;
    }

    public void setAccelerationX(double accelerationX) {
        this.accelerationX = new MeasurementValue(new BigDecimal(accelerationX), unit);
    }

    @JSONProperty("accelerationY")
    public MeasurementValue getAccelerationY() {
        return accelerationY;
    }

    public void setAccelerationY(double accelerationY) {
        this.accelerationY = new MeasurementValue(new BigDecimal(accelerationY), unit);
    }

    @JSONProperty("accelerationZ")
    public MeasurementValue getAccelerationZ() {
        return accelerationZ;
    }

    public void setAccelerationZ(double accelerationZ) {
        this.accelerationZ = new MeasurementValue(new BigDecimal(accelerationZ), unit);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((accelerationX == null) ? 0 : accelerationX.hashCode());
        result = prime * result + ((accelerationY == null) ? 0 : accelerationY.hashCode());
        result = prime * result + ((accelerationZ == null) ? 0 : accelerationZ.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        AccelerationCombinedMeasurement other = (AccelerationCombinedMeasurement) obj;
        if (accelerationX == null) {
            if (other.accelerationX != null)
                return false;
        } else if (!accelerationX.equals(other.accelerationX))
            return false;
        if (accelerationY == null) {
            if (other.accelerationY != null)
                return false;
        } else if (!accelerationY.equals(other.accelerationY))
            return false;
        if (accelerationZ == null) {
            if (other.accelerationZ != null)
                return false;
        } else if (!accelerationZ.equals(other.accelerationZ))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "AccelerationCombinedMeasurement [accelerationX=" + accelerationX + ", accelerationY=" + accelerationY
                + ", accelerationZ=" + accelerationZ + "]";
    }

}

c8y_Acceleration. , , :

name red outlined

.

+3

Source: https://habr.com/ru/post/1693719/


All Articles