diff options
author | Simon Rettberg | 2015-07-03 19:13:12 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-03 19:13:12 +0200 |
commit | 808c9b4abf714697011895e093c20938520abb18 (patch) | |
tree | 140b2991bd5f733f9ef2e7caa21fb26f6f10a18f /dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/OrganizationList.java | |
parent | [client] bwIDM Authentication implemented, yet to be finalized. (diff) | |
download | tutor-module-808c9b4abf714697011895e093c20938520abb18.tar.gz tutor-module-808c9b4abf714697011895e093c20938520abb18.tar.xz tutor-module-808c9b4abf714697011895e093c20938520abb18.zip |
[client] Add classes for caching of data fetched via thrift
(could be used for other things too, code is fairly generic)
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/OrganizationList.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/OrganizationList.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/OrganizationList.java b/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/OrganizationList.java new file mode 100644 index 00000000..d13da1b3 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/OrganizationList.java @@ -0,0 +1,69 @@ +package org.openslx.bwlp.dozmod.thrift; + +import java.util.List; + +import org.openslx.bwlp.thrift.iface.Organization; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.thrifthelper.ThriftManager; + +public class OrganizationList extends ACache<List<Organization>> { + + /** + * How long should the list be cached? + */ + private static final int CACHE_TIME_MS = 20 * 60 * 1000; + + private static final OrganizationList instance = new OrganizationList(); + + private OrganizationList() { + super(CACHE_TIME_MS); + } + + @Override + public List<Organization> update() throws Exception { + try { + return ThriftManager.getMasterClient().getOrganizations(); + } catch (Exception e) { + // Swallow exception, then try satellite + } + return ThriftManager.getSatClient().getAllOrganizations(); + // TODO: Sort list by display name? + } + + /** + * Get all known organizations + * + * @return list of organizations + */ + public static List<Organization> getAll() { + return instance.get(); + } + + /** + * Find the organization the given user belongs to + * + * @param user + * @return matching organization, or <code>null</code> if not found + */ + public static Organization find(UserInfo user) { + return find(user.organizationId); + } + + /** + * Find the organization with the given id + * + * @param organization id + * @return matching organization, or <code>null</code> if not found + */ + public static Organization find(String organizationId) { + List<Organization> list = instance.get(); + if (list == null) + return null; + for (Organization org : list) { + if (org.organizationId.equals(organizationId)) + return org; + } + return null; + } + +} |