Skip to content

Commit

Permalink
#33 Find missing property by name
Browse files Browse the repository at this point in the history
  • Loading branch information
baardl committed Apr 24, 2023
1 parent 93b09b7 commit 213b197
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class RecObject {
private String realEstate;
private String building;
private String floor;

private String section;
private String placementRoom;
private String servesRoom;
private String climateZone;
Expand Down Expand Up @@ -60,6 +62,14 @@ public void setPlacementRoom(String placementRoom) {
this.placementRoom = placementRoom;
}

public String getSection() {
return section;
}

public void setSection(String section) {
this.section = section;
}

public String getServesRoom() {
return servesRoom;
}
Expand Down Expand Up @@ -91,4 +101,37 @@ public String getSensorType() {
public void setSensorType(String sensorType) {
this.sensorType = sensorType;
}

/**
*
* @param propertyName
* @return
* @throws IllegalArgumentException if propertyName is not a valid property name
*/
public String getProperty(String propertyName) {
switch (propertyName) {
case "recId":
return recId;
case "realEstate":
return realEstate;
case "building":
return building;
case "floor":
return floor;
case "placementRoom":
return placementRoom;
case "servesRoom":
return servesRoom;
case "climateZone":
return climateZone;
case "electricityZone":
return electricityZone;
case "section":
return section;
case "sensorType":
return sensorType;
default:
throw new IllegalArgumentException("Unknown property: " + propertyName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@

public class SensorRecObject extends RecObject {

private String realEstate;
private String building;
private String floor;
private String section;
private String servesRoom;
private String placementRoom;
private String climateZone;
private String electricityZone;

private String name;
private String sensorType;
private String description;
Expand All @@ -26,62 +19,6 @@ public SensorRecObject(String recId) {
super(recId);
}

public String getBuilding() {
return building;
}

public void setBuilding(String building) {
this.building = building;
}

public String getFloor() {
return floor;
}

public void setFloor(String floor) {
this.floor = floor;
}

public String getSection() {
return section;
}

public void setSection(String section) {
this.section = section;
}

public String getServesRoom() {
return servesRoom;
}

public void setServesRoom(String servesRoom) {
this.servesRoom = servesRoom;
}

public String getPlacementRoom() {
return placementRoom;
}

public void setPlacementRoom(String placementRoom) {
this.placementRoom = placementRoom;
}

public String getClimateZone() {
return climateZone;
}

public void setClimateZone(String climateZone) {
this.climateZone = climateZone;
}

public String getElectricityZone() {
return electricityZone;
}

public void setElectricityZone(String electricityZone) {
this.electricityZone = electricityZone;
}

public String getName() {
return name;
}
Expand Down Expand Up @@ -130,13 +67,6 @@ public void setLastUpdatedDate(Instant lastUpdatedDate) {
this.lastUpdatedDate = lastUpdatedDate;
}

public String getRealEstate() {
return realEstate;
}

public void setRealEstate(String realEstate) {
this.realEstate = realEstate;
}

public Tfm getTfm() {
return tfm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public MappedIdQueryBuilder sensorIdClass(Class sensorIdClass) {
return this;
}

public MappedIdQueryBuilder recPropertyIsNull(String propertyName) {
predicates.add(mappedSensorId -> mappedSensorId.getRec() != null);
predicates.add(mappedSensorId -> mappedSensorId.getRec().getProperty(propertyName) == null || mappedSensorId.getRec().getProperty(propertyName).isEmpty());
return this;
}

public MappedIdQueryBuilder missingSensorId() {
predicates.add(mappedSensorId -> mappedSensorId.getSensorId() == null);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ void verifyIdAndTFM() {
assertFalse(tfm.getTfm().equals(recObject.getTfm()));
assertEquals(tfm.getTfm(),recObject.getTfm().getTfm());
}

@Test
void verifyGetProperty() {
recObject.setRealEstate("re1");
assertEquals("recid", recObject.getRecId());
assertEquals("recid", recObject.getProperty("recId"));
assertEquals("re1", recObject.getProperty("realEstate"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,13 @@ void findMissingSensorId() {
query = new MappedIdQueryBuilder().missingSensorId().sensorType("CO2").build();
assertEquals(1, repository.find(query).size());
}

@Test
void whenRecPropertyIsNull() {
MappedIdQuery query = new MappedIdQueryBuilder().recPropertyIsNull("realEstate").build();
List<MappedSensorId> matchingSersorIds = repository.find(query);
assertEquals(0, matchingSersorIds.size());
query = new MappedIdQueryBuilder().recPropertyIsNull("section").build();
assertEquals(9, repository.find(query).size());
}
}

0 comments on commit 213b197

Please sign in to comment.