Repository: incubator-unomi Updated Branches: refs/heads/master 9bf0ebf90 -> f84401a7a
UNOMI-159 Fix for property types not properly initialized on startup. Signed-off-by: Serge Huber <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/f84401a7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/f84401a7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/f84401a7 Branch: refs/heads/master Commit: f84401a7a64d25c18faf5fc8c4c0eaafde34d0fe Parents: 9bf0ebf Author: Serge Huber <[email protected]> Authored: Wed Feb 21 14:49:18 2018 +0100 Committer: Serge Huber <[email protected]> Committed: Wed Feb 21 14:49:18 2018 +0100 ---------------------------------------------------------------------- .../services/services/ProfileServiceImpl.java | 53 +++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f84401a7/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java index fedc3e9..b42d8e7 100644 --- a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java @@ -99,6 +99,7 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList public void postConstruct() { logger.debug("postConstruct {" + bundleContext.getBundle() + "}"); + loadPropertyTypesFromPersistence(); processBundleStartup(bundleContext); for (Bundle bundle : bundleContext.getBundles()) { if (bundle.getBundleContext() != null) { @@ -154,35 +155,39 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList TimerTask task = new TimerTask() { @Override public void run() { - try { - allPropertyTypes = persistenceService.getAllItems(PropertyType.class, 0, -1, "rank").getList(); - Map<String,PropertyType> newPropertyTypesById = new HashMap<>(); - Map<String,List<PropertyType>> newPropertyTypesByTags = new HashMap<>(); - Map<String,List<PropertyType>> newPropertyTypesBySystemTags = new HashMap<>(); - Map<String,List<PropertyType>> newPropertyTypesByTarget = new HashMap<>(); - for (PropertyType propertyType : allPropertyTypes) { - newPropertyTypesById.put(propertyType.getItemId(), propertyType); - for (String propertyTypeTag : propertyType.getMetadata().getTags()) { - updateListMap(newPropertyTypesByTags, propertyType, propertyTypeTag); - } - for (String propertyTypeSystemTag : propertyType.getMetadata().getSystemTags()) { - updateListMap(newPropertyTypesBySystemTags, propertyType, propertyTypeSystemTag); - } - updateListMap(newPropertyTypesByTarget, propertyType, propertyType.getTarget()); - } - propertyTypesById = newPropertyTypesById; - propertyTypesByTags = newPropertyTypesByTags; - propertyTypesBySystemTags = newPropertyTypesBySystemTags; - propertyTypesByTarget = newPropertyTypesByTarget; - } catch (Exception e) { - logger.error("Error loading property types from persistence service", e); - } + loadPropertyTypesFromPersistence(); } }; - allPropertyTypesTimer.scheduleAtFixedRate(task, 0, 5000); + allPropertyTypesTimer.scheduleAtFixedRate(task, 5000, 5000); logger.info("Scheduled task for property type loading each 5s"); } + private void loadPropertyTypesFromPersistence() { + try { + allPropertyTypes = persistenceService.getAllItems(PropertyType.class, 0, -1, "rank").getList(); + Map<String,PropertyType> newPropertyTypesById = new HashMap<>(); + Map<String,List<PropertyType>> newPropertyTypesByTags = new HashMap<>(); + Map<String,List<PropertyType>> newPropertyTypesBySystemTags = new HashMap<>(); + Map<String,List<PropertyType>> newPropertyTypesByTarget = new HashMap<>(); + for (PropertyType propertyType : allPropertyTypes) { + newPropertyTypesById.put(propertyType.getItemId(), propertyType); + for (String propertyTypeTag : propertyType.getMetadata().getTags()) { + updateListMap(newPropertyTypesByTags, propertyType, propertyTypeTag); + } + for (String propertyTypeSystemTag : propertyType.getMetadata().getSystemTags()) { + updateListMap(newPropertyTypesBySystemTags, propertyType, propertyTypeSystemTag); + } + updateListMap(newPropertyTypesByTarget, propertyType, propertyType.getTarget()); + } + propertyTypesById = newPropertyTypesById; + propertyTypesByTags = newPropertyTypesByTags; + propertyTypesBySystemTags = newPropertyTypesBySystemTags; + propertyTypesByTarget = newPropertyTypesByTarget; + } catch (Exception e) { + logger.error("Error loading property types from persistence service", e); + } + } + private void updateListMap(Map<String, List<PropertyType>> listMap, PropertyType propertyType, String key) { List<PropertyType> propertyTypes = listMap.get(key); if (propertyTypes == null) {
