Advertisement
cmptrwz

Untitled

Mar 26th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. In a library system you want to check circulation rules. As inputs you have a user object, an item object, and some basic circ information. As outputs you want duration and fine information.
  2.  
  3. Thus, lets go with the following basics:
  4.  
  5. Users have a permission group and home library. Both are references to trees, and we want to include when these values are descendants of the selected value. Users also have an optional date of birth, from which we can get their age, if it is set.
  6. Items have an owning library, a circ modifier, and we can get the item's age based on our own criteria.
  7. The circulation information includes where the item is circulating and if it is a renewal.
  8.  
  9. Our current method of accomplishing this is to use a table with a number of "check" and "result" columns. Simplified for the above:
  10. Check columns:
  11. user_home_library FK
  12. user_permission_group FK
  13. user_age_min INTERVAL
  14. user_age_max INTERVAL
  15. item_owning_library FK
  16. item_circ_modifier FK
  17. item_age_max INTERVAL
  18. circ_library FK
  19. is_renewal BOOL
  20.  
  21. Result columns:
  22. duration_rule FK
  23. fine_rule FK
  24.  
  25. All of the check columns can be null to represent "no data" - This serves as a wildcard. Only non-null check columns contribute to our ordering of rows, however. To avoid two rows with the same checks but different results we have a unique index across all check columns, coalesced to non-null values. The actual result is returned by a plpgsql stored procedure that takes the basic data in and returns the final result.
  26.  
  27. When all check columns are null the duration and fine rules would be the "default" rules, for when no more specific rules exist. Otherwise we filter and order based on the non-null check columns in any given row.
  28.  
  29. Because this is a user configurable area we allow users to set (or not set) any combination of check columns. They may decide that they only care about the item_circ_modifier, or perhaps they care about the combination of the user_permission_group and item_circ_modifier.
  30.  
  31. I have been told that the use of nulls in this situation may be a horrible idea, and as I am planning on working on this area of our system in the near future I will be in a position to do this in a more "correct" manner. I just need to know what that manner is so that I can weigh the pros and cons compared to how things are currently implemented.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement