NEW DATA MODEL: Migration Guide
How to migrate client code to use the new data model and methods
Avi
Blackmore
Head Programmer/Administrator
2013
Agri ImaGIS Technologies, Inc.
Table of Contents
The new data modelWith the 2013 update to the Services API, we introduced a significant reorganization of the data model for grouping users and geospatial objects, such as fields. The
old, hierarchical model of dealers, consultants, growers, farms, and fields is gone. In its place, we have provided a much more flexible and fine-grained mechanism for
grouping together users and controlling their capabilities, and a similar, parallel mechanism for grouping boundaries and other geospatial objects and controlling access
to them.
In the new scheme, users are grouped together into entities called groups, and boundaries and other geospatial objects are grouped together
into groupings called regions. Groups represent business entities, or subgroupings within those business entities, in a simple but
flexible one-to-many parent-child relationship. Groups can have subgroups, which can themselves have subgroups, and so on, nested to whatever depth a customer finds
useful; the system does not need to know or care what a particular group represents within an organization. The old "master dealer" and "subdealer" relationships, for
instance, are easily represented with groups, as well as the "consultant" and "grower" relationships. Those entities can all be represented using one basic mechanism,
the group.
Similarly, boundariess and other objects exist in regions. Regions, unlike groups, are many-to-many: a given region can of course contain multiple objects, but a given
object can also exist in multiple regions. Regions can, similar to groups, represent groupings of geospatial objects of whatever type the users find meaningful: farms,
for instance, are naturally represented by regions, but so are crop insurance units, seed or fertilizer company sales regions, sets of farms owned by a particular
grower, or any other "area of interest".
Further, the way in which user actions are controlled on the system has changed a great deal. No longer are users given a static "user level" number, which governs
their capabilities in a hard-coded, poorly-documented fashion. Instead, users have privileges, flags which explicitly control which operations they can perform. Groups
also have privileges, which governs what privileges the users in that group, and in child groups, can possess. Similarly, access to field boundaries and other
geospatial objects is no longer controlled by what "grower entity" they are grouped under, but by explicit access control lists, which can flexibly grant varying levels
of access to groups or to specific users.
Why the change?Obviously, all of this represented a big change, with a great deal of work going into changing the database, server-side code, and client-visible API methods. It
requires that client programmers learn new methods and data structures, and deprecate old ways of doing things. And it requires that users of the clients relearn, to
some extent, how the system works. This is a lot of effort, so why did we bother?
Simply put, the reasons for the change are threefold: flexibility, ease of use, and maintainability.
FlexibilityThe old hierarchy model, with its strict levels and predefined roles of entities, was not very flexible. It enforced a particular organizational scheme on the
customers, and their fields, which often did not reflect the realities of the customers' needs. The levels of hierarchy were fixed, even if the customer didn't need
any subdivisions, for instance if they were an independent grower. The positioning of "consultant" users in between the dealer and grower entities was a further
complication, because it meant that user names would show up in surprising places; sharing growers and their farms and fields between consultants required that the
grower's consultant be set to "none (shared)", which could result in the given fields being shared between more people than was necessary. If a given customer's
company had divisions which were not easily mapped to the master dealer -> dealer -> consultant -> grower hierarchy, the mismatch between their own organization and
the Satshot model created headaches. In particular, if they had more levels of organization than the old model accounted for, it was difficult to model this within
the old system. Groups solve this problem by using one entity type, allowing unlimited nesting, and supporting flexible descriptions so that customers can arrange
their users according to their own organizational needs.
Additionally, the hard-coded "user levels" created a system of privileges that was difficult to explain to users, and could not be changed by customers to suit their
needs. If they needed a mechanism for controlling, say, which users could use certain operations, and the user levels didn't provide it, they were out of luck. There
was no easily-understood mechanism for controlling user privileges. With privilege flags, this problem disappears: users in upper-level groups can easily see and
control what the users in their child groups are allowed to do.
This was also an issue for controlling visibility of fields and other geospatial objects; the only determinant of who could see what boundaries, was that person's
position in the hierarchy with respect to the grower that "owned" those boundaries. With access controls, the question of who can see what is made explicit, and is
under the direct control of the users. Customers now have the ability to define how their field boundaries and other objects are visible within their overall
organization, and further, can define "read-only" versus "read-write" accessibility.
Finally, farms were an acceptable, but not very flexible, grouping mechanism for fields. A field could belong to one and only one farm, and this membership was
globally visible and could not be customized. By contrast, the flexibility of regions is unparalleled: every user can define for themselves what is the most logical
grouping for the geospatial objects they can access, and do this without impinging on how other users might view the same objects. Regions can represent more than
just farms, and can overlap without difficulty.
Ease of UseThe old hierarchy model was difficult to use, for both end users and for client programmers. Clients had to keep track of whether an entity was a dealer or a grower,
with consultant users wedged in between the two entity types to boot. The process of navigating the hierarchy to get to the right list of fields was time-consuming
and tedious, and adding new entities required separate method calls, separate entry forms, and separate data structures. This also meant that users always needed to
know what dealer, consultant, and grower they had to select in order to get to what they really wanted to see: the fields.
By contrast, the new model is much simpler to understand and use: a group may or may not have subgroups, which may in turn have subgroups of their own, but
fundamentally they are all the same type of entity. And because access to geospatial objects is not controlled by the user's position in a hierarchy, but by an
explicit access control list, users don't necessarily even need to know, day to day, where they are positioned in their customer organization's group hierarchy. All
they have to do is look at their regions, and the objects within them, to see what they need to work with.
Client programmers should also find the new model easier to work with, because fewer methods need to be called to get the necessary information, there are fewer types
of entities to keep track of, and fewer special cases to work around. In particular, the only hierarchy is the parent-child relationship between groups: users are
always "leaf nodes" in this tree; and the relationship between regions and geospatial objects is a single-level, many-to-many mapping.
MaintainabilityFinally, the old hierarchy model was a maintenance burden on our end. Details of this are not particularly important, but it is worth noting that the amount of code
required to handle the new model is a third of that required for the old. This significantly decreases the burden on maintaining the code, and enables us to write new
features more quickly, as needed.
What's ChangedNew Object TypesThe first obvious change is the system's support of more objects than just boundaries (which we used to call "fields"). To wit, we now support locations (points), and
paths (lines or multilines), as well. With only a few exceptions, which are being worked on, all operations that work for boundaries will work for locations and paths as
well. This includes image extraction and analysis, so it's quite possible to analyze an area around a point, or around the sides of a linear path. This addition has made
it necessary to include new parameters for a few methods, to specify the object type, but a number of methods are essentially unchanged.
Removed MethodsThese methods have been removed, for the given reasons:
- create_hilite_boundary_from_map_coordinates, create_hilite_boundary_from_pixel_points: Replaced with create_hilite_objects_from_wkt(), which is more
standard and more flexible. Also, it can create multiple new hilites in one call.
- paint_image_pixels_with_map_coordinates, paint_image_pixels_with_pixel_points: Painting pixels is deprecated, and never worked well. Use the polygon painting
methods instead.
- activate_field, activate_fields: Field activation is no longer a part of the business model.
- activate_grower: Grower activation is no longer relevant, since growers no longer exist.
- create_dealer, create_grower: Dealers and growers no longer exist.
- create_farm: Farms have been replaced with regions.
- delete_basic_field_attributes,set_basic_field_attributes: "Basic field attributes" were never used by anyone, and are completely supplanted by the new fielddata
facility.
- delete_farm, delete_farms: Farms have been replaced with regions.
- delete_field, delete_fields: Hard deletion of objects is no longer supported, and we don't call them "fields" anymore.
- get_customer_special_scene_purchase_records: This information is now returned with the regular transaction history, so no need for a separate method.
- get_dealers_balances, get_growers_balances: These methods were deprecated long ago, and even the method that replaced them is gone.
- get_field_info,get_multiple_fields_info: Object info is now returned in get_accessible_regions_and_objects(), so no need for separate
methods.
- get_grower_farms_and_fields: Growers no longer exist, and get_accessible_regions_and_objects() does what this does, and better.
- get_saved_datasets_for_multiple_fields: The new method, get_saved_datasets_for_objects(), can already handle multiple objects at once.
- get_transaction_history: Replaced with get_customer_transaction_history().
- get_visible_dealers,get_visible_consultants_for_dealer,get_visible_growers_for_dealer_consultant: Hierarchy navigating methods, no longer needed.
- migrate_fields_to_new_farms,rename_and_save_hilites_as_fields_with_multiple_farms: Farms no longer exist. Objects can exist in multiple regions, so there is no
need to "migrate" them between regions, and save_hilited_objects() handles dispatching to multiple regions already.
- process_grower_creditcard_payment: This was deprecated long ago in favor of process_creditcard_payment().
- query_geotagged_photos_at_coordinate_point, query_geotagged_photos_at_pixel_point: Unnecessary, since we have the generic layer query methods.
- rename_farm,rename_field: This can be handled with the "update" parameter to save_hilited_objects().
- save_hilites_as_fields: Replaced with save_hilited_objects(), which handles all object types.
- select_by_fieldid: They aren't called "fields" anymore, and we needed a new method that could select on different object types.
- update_dealer_info,update_grower_info: Dealers and growers no longer exist.
New MethodsThese are the new methods written for the new data model:
These new methods work with geospatial objects:
Renamed MethodsA number of methods were simply renamed, but otherwise have few semantic changes:
Semantic ChangesThese are miscellaneous semantic changes, other than the obvious ones implied by the new data model.
- All methods which changed the map extents, and had a "returnextents" parameter, have had that parameter removed. The behavior of returning the new extents is
now universal.
- The get_hilites() method, and other methods which return hilites (such as the SELECT methods), have some minor changes in the returned structure. Also, there
is now a parameter for get_hilites() to retrieve the WKT of the objects.
- The method get_customers_balances() now takes an array of groupids. There is no "idtype" parameter. This reflects the new model in which groups are the
"customer" entities.
- The "user level" of users is no longer relevant. Privileges have replaced this facility entirely.
- Privilege checks are now applied to most methods. The methods' documentation will note the required privilege. Access controls are also checked for operations that access
objects. This is pervasive, and applies to almost all methods.
- The layer formerly known as "fields" is now called "boundaries".
- There are now three layers to represent hilites, "hilites", "hilite_lines", and "hilite_points", for (multi)polygon, (multi)line, and point hilites, respectively. This
is necessary for technical reasons: no known GIS software can display multiple object types on the same layer. The different layers are only an issue if using them via
WMS or WFS for display purposes; otherwise, this distinction can be ignored (but client software will likely need to use different layers to display different object
types, anyway).
| Prev |
Up |
Next |
| Attributed CLUs |
Understanding and Using the Satshot Services API, Version 2 |
|
|
|