Wednesday, April 22, 2009

Don't have a create operation inside failed lookup


GeoTrackedEntity te = null;
try {
te = geoTrackedEntityApi.findTrackedEntity(vehicle.getGuid(), false);
} catch (UnknownFeatureException e2) {
te = addTrackedEntity(vehicle, buGuid);
}


This code is awful because it makes it hard to know when something is created. Plus you would have to have this kind of thing everywhere a find was performed.

This is truly awful. The above method addTrackedEntity then repeats this anti-pattern to add a dataset (which is required if you need to add a tracked entity).


GeoDataSet ds;
try {
ds = geoDatasetApi.findDataSetByBusUnitAndName(buGuid,
vehicle.getVehicleType().getName());

} catch (UnknownDataSetException e1) {
ds =addTrackedEntityDataSet(vehicle.getVehicleType().getName(),
vehicle.getVehicleType().getGuid(), buGuid);
}

No comments: