diff options
author | Jonathan Bauer | 2015-12-18 16:57:26 +0100 |
---|---|---|
committer | Jonathan Bauer | 2015-12-18 16:57:26 +0100 |
commit | ca397e4a2ca4b4983d6546ce6dfafcf8a4c55b56 (patch) | |
tree | ea03c8adc4cffb5e5a50932f209de03f62c73b94 /dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache | |
parent | [client] don't scroll the pane for the changelog to the bottom, always force ... (diff) | |
download | tutor-module-ca397e4a2ca4b4983d6546ce6dfafcf8a4c55b56.tar.gz tutor-module-ca397e4a2ca4b4983d6546ce6dfafcf8a4c55b56.tar.xz tutor-module-ca397e4a2ca4b4983d6546ce6dfafcf8a4c55b56.zip |
[client] room selection widget [wip]
new wizard page in the lecture wizard
new button "Raumauswahl" LectureDetailsWindow
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java index 0e9f8ea4..6c3d2be5 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java @@ -1,9 +1,11 @@ package org.openslx.dozmod.thrift.cache; +import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.Location; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.Virtualizer; import org.openslx.thrifthelper.ThriftManager; @@ -44,6 +46,26 @@ public class MetaDataCache { return ThriftManager.getMasterClient().getVirtualizers(); } }; + + private static final GenericDataCache<List<Location>> locationCache = new GenericDataCache<List<Location>>( + CACHE_TIME_MS) { + @Override + protected List<Location> update() throws TException { + List<Location> testLocationList = new ArrayList<Location>(); + testLocationList.add(new Location(1, "RZ - Raum 100")); + testLocationList.add(new Location(2, "RZ - Raum 101")); + testLocationList.add(new Location(3, "RZ - Raum 113")); + testLocationList.add(new Location(4, "RZ - Raum 114")); + return testLocationList; + // enable this code when the server call is implemented +// try { +// return ThriftManager.getSatClient().getLocations(); +// } catch (TException e) { +// LOGGER.warn("Could not get location list from satellite, trying master for backup...", e); +// } +// return null; // HACK + } + }; /** * Get all known/valid operating systems an image can be marked as. @@ -117,4 +139,40 @@ public class MetaDataCache { return null; } + /** + * Get all known/valid locations a lecture can be assigned to. + * + * @return + */ + public static List<Location> getLocations() { + return locationCache.get(); + } + + public static Location getLocationById(int id) { + return getLocationById(id, false); + } + + public static Location getLocationById(int id, boolean forceCache) { + // First, try in "always cached" mode + List<Location> list = locationCache.get(CacheMode.FORCE_CACHED); + Location location = getLocationById(id, list); + if (location != null || forceCache) + return location; + // Try again with a potential refresh + List<Location> newList = locationCache.get(CacheMode.DEFAULT); + if (list == newList) // Returned list from cache as it was still recent enough + return null; + return getLocationById(id, newList); + } + + private static Location getLocationById(int id, List<Location> list) { + if (list != null) { + for (Location loc : list) { + if (loc.getLocationId() == id) + return loc; + } + } + return null; + } + }
\ No newline at end of file |