Skip to content

Commit 4a55eeb

Browse files
committed
Allow property type overrides from CSDL
1 parent 1dcd231 commit 4a55eeb

4 files changed

Lines changed: 47 additions & 12 deletions

File tree

src/main/java/de/fraunhofer/iosb/ilt/frostclient/model/PropertyType.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import de.fraunhofer.iosb.ilt.frostclient.utils.ParserUtils;
3030
import java.util.ArrayList;
3131
import java.util.List;
32+
import java.util.Objects;
3233
import tools.jackson.databind.ValueDeserializer;
3334
import tools.jackson.databind.ValueSerializer;
3435

@@ -134,4 +135,30 @@ public String toString() {
134135
return getFullName();
135136
}
136137

138+
@Override
139+
public int hashCode() {
140+
int hash = 7;
141+
hash = 53 * hash + Objects.hashCode(this.name);
142+
hash = 53 * hash + Objects.hashCode(this.namespace);
143+
return hash;
144+
}
145+
146+
@Override
147+
public boolean equals(Object obj) {
148+
if (this == obj) {
149+
return true;
150+
}
151+
if (obj == null) {
152+
return false;
153+
}
154+
if (getClass() != obj.getClass()) {
155+
return false;
156+
}
157+
final PropertyType other = (PropertyType) obj;
158+
if (!Objects.equals(this.name, other.name)) {
159+
return false;
160+
}
161+
return Objects.equals(this.namespace, other.namespace);
162+
}
163+
137164
}

src/main/java/de/fraunhofer/iosb/ilt/frostclient/model/csdl/CsdlPropertyEntity.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,14 @@ public void applyTo(ModelRegistry mr, EntityType entityType, String name) {
102102
EntityPropertyMain ep = createProperty(mr, name);
103103
entityType.registerProperty(ep);
104104
} else {
105-
LOGGER.debug(" EntityType {} already has property {}", entityType, name);
105+
final PropertyType newType = createPropertyType(mr);
106+
final PropertyType oldType = existingProp.getType();
107+
if (oldType.equals(newType)) {
108+
LOGGER.debug(" EntityType {} already has property {}", entityType, name);
109+
} else {
110+
existingProp.setType(newType);
111+
LOGGER.info(" Replaced type of {}/{} from {} to {}", entityType, existingProp, oldType, newType);
112+
}
106113
}
107114
}
108115

@@ -113,6 +120,13 @@ public void applyTo(ModelRegistry mr, TypeComplex tc, String name) {
113120
}
114121

115122
private EntityPropertyMain createProperty(ModelRegistry mr, String name) throws IllegalArgumentException {
123+
PropertyType propertyType = createPropertyType(mr);
124+
EntityPropertyMain ep = new EntityPropertyMain(name, propertyType);
125+
ep.setNullable(nullable);
126+
return ep;
127+
}
128+
129+
public PropertyType createPropertyType(ModelRegistry mr) throws IllegalArgumentException {
116130
PropertyType propertyType = mr.getPropertyType(type);
117131
if (collection) {
118132
if (propertyType instanceof TypePrimitive ptp) {
@@ -123,9 +137,7 @@ private EntityPropertyMain createProperty(ModelRegistry mr, String name) throws
123137
throw new IllegalArgumentException("Can't create Type for Set of " + propertyType.getName());
124138
}
125139
}
126-
EntityPropertyMain ep = new EntityPropertyMain(name, propertyType);
127-
ep.setNullable(nullable);
128-
return ep;
140+
return propertyType;
129141
}
130142

131143
@JsonAnyGetter

src/main/java/de/fraunhofer/iosb/ilt/frostclient/model/property/type/TypeComplex.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public class TypeComplex extends PropertyType implements ContainerType<TypeCompl
5757

5858
public static final String STA_MAP_NAME = "Object";
5959
public static final String STA_OBJECT_NAME = "ANY";
60-
public static final String STA_TIMEINTERVAL_NAME = "TimeInterval";
61-
public static final String STA_TIMEVALUE_NAME = "TimeValue";
60+
public static final String STA_TIMEINTERVAL_NAME = "TM_Period";
61+
public static final String STA_TIMEVALUE_NAME = "TM_Object";
6262
public static final String NAME_INTERVAL_START = "start";
6363
public static final String NAME_INTERVAL_END = "end";
6464

@@ -95,6 +95,7 @@ public class TypeComplex extends PropertyType implements ContainerType<TypeCompl
9595
}
9696
try {
9797
final TypeComplex type = (TypeComplex) FieldUtils.readStaticField(field, false);
98+
type.setNamespace("org.OGC.STA");
9899
final String name = type.getName();
99100
TYPES.put(name, type);
100101
LOGGER.debug("Registered type: {}", name);
@@ -190,9 +191,4 @@ public static interface Instantiator {
190191
public ComplexValue instantiate(TypeComplex type);
191192
}
192193

193-
@Override
194-
public String toString() {
195-
return "TypeComplex: " + getName();
196-
}
197-
198194
}

src/main/java/de/fraunhofer/iosb/ilt/frostclient/models/SensorThingsV20Core.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public class SensorThingsV20Core implements DataModel {
135135
public final EntityType etLocation = new EntityType(NAME_LOCATION, NAME_LOCATIONS).setNamespace(NAMESPACE);
136136
public final EntityType etObservedProperty = new EntityType(NAME_OBSERVEDPROPERTY, NAME_OBSERVEDPROPERTIES).setNamespace(NAMESPACE);
137137
public final EntityType etObservation = new EntityType(NAME_OBSERVATION, NAME_OBSERVATIONS)
138-
.setToStringMethod(e -> e.getType().toString() + ": " + e.getPrimaryKeyValues() + " " + e.getProperty(EP_PHENOMENONTIME) + " " + e.getProperty(EP_RESULT))
138+
.setToStringMethod(e -> e.getPrimaryKeyValues() + " " + e.getProperty(EP_PHENOMENONTIME) + " " + e.getProperty(EP_RESULT))
139139
.setNamespace(NAMESPACE);
140140
public final EntityType etSensor = new EntityType(NAME_SENSOR, NAME_SENSORS).setNamespace(NAMESPACE);
141141
public final EntityType etThing = new EntityType(NAME_THING, NAME_THINGS).setNamespace(NAMESPACE);

0 commit comments

Comments
 (0)