X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportalapp%2Fportal%2Fservice%2FAppsCacheServiceImple.java;h=3a70da84bd1f768f45b1dc1a39c0c52c06b19b7f;hb=a3a04c5887779e9ca8024a3e87ece109b8d9b0c1;hp=06adb7f50968b0f87ea5cf7c9d406ecf5c5e39fd;hpb=24608a9e1450c409dc3870440d29e91cc3a26bb9;p=portal.git diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java index 06adb7f5..3a70da84 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -37,9 +37,11 @@ */ package org.onap.portalapp.portal.service; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.annotation.PostConstruct; @@ -51,6 +53,8 @@ import org.onap.portalapp.portal.logging.aop.EPMetricsLog; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalapp.portal.service.AppsCacheService; import org.onap.portalapp.portal.service.AppsCacheServiceImple; +import org.onap.portalapp.portal.transport.OnboardingApp; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; @Service("appsCacheService") @org.springframework.context.annotation.Configuration @@ -73,47 +77,46 @@ public class AppsCacheServiceImple implements AppsCacheService { } } - CacheConfiguration appConf = null; - CacheConfiguration analyticsAppConf = null; + CacheConfiguration quickRefreshCacheConf = null; + CacheConfiguration slowRefreshCacheConf = null; private static volatile Map appsMap; - private static volatile Map anlyticsAppsMap; + private static volatile Map uebAppsMap; @PostConstruct public void init() { - appConf = new CacheConfiguration(0, 10); - analyticsAppConf = new CacheConfiguration(0, 3600); + quickRefreshCacheConf = new CacheConfiguration(0, 120); + slowRefreshCacheConf = new CacheConfiguration(0, 3600); - this.refreshAppsMap(appConf); + this.refreshAppsMap(quickRefreshCacheConf); } - private Map refreshAppsMap(CacheConfiguration conf) { + private void refreshAppsMap(CacheConfiguration conf) { long now = System.currentTimeMillis(); if(noNeedToUpdate(now, conf)) - return null; + return; synchronized (this) { if(noNeedToUpdate(now, conf)) - return null; + return; List allApps = appsService.getAppsFullList(); Map newAppsMap = new HashMap(); for (EPApp app : allApps) { newAppsMap.put(app.getId(), app); } - Map newAnalyticsAppsMap = new HashMap(); + Map newUebAppsMap = new HashMap(); for (EPApp app : allApps) { - newAnalyticsAppsMap.put(app.getUebKey(), app); + newUebAppsMap.put(app.getUebKey(), app); } // Switch cache with the new one. appsMap = newAppsMap; - anlyticsAppsMap = newAnalyticsAppsMap; + uebAppsMap = newUebAppsMap; conf.updateTime = now; } - return appsMap; } private boolean noNeedToUpdate(long now, CacheConfiguration conf) { @@ -127,16 +130,34 @@ public class AppsCacheServiceImple implements AppsCacheService { @Override public String getAppEndpoint(Long appId) { - refreshAppsMap(appConf); + refreshAppsMap(quickRefreshCacheConf); EPApp app = appsMap.get(appId); if(app != null) return app.getAppRestEndpoint(); return null; } + @SuppressWarnings("unchecked") + @Override + public List getAppsFullList() { + refreshAppsMap(quickRefreshCacheConf); + List appList = new ArrayList (appsMap.values()); + appList.removeIf(app -> app.getId() == 1); + List appsFinalList = appList.stream() + .filter(app -> app.getEnabled() == true && app.getOpen() == false).collect(Collectors.toList()); + + List onboardingAppsList = new ArrayList(); + for (EPApp app : appsFinalList) { + OnboardingApp onboardingApp = new OnboardingApp(); + appsService.createOnboardingFromApp(app, onboardingApp); + onboardingAppsList.add(onboardingApp); + } + return onboardingAppsList; + } + @Override public EPApp getApp(Long appId) { - refreshAppsMap(appConf); + refreshAppsMap(quickRefreshCacheConf); EPApp app = appsMap.get(appId); if(app != null) return app; @@ -144,9 +165,14 @@ public class AppsCacheServiceImple implements AppsCacheService { } @Override - public EPApp getAppForAnalytics(String appKey) { - refreshAppsMap(analyticsAppConf); - EPApp app = anlyticsAppsMap.get(appKey); + public EPApp getAppFromUeb(String appKey) { + return getAppFromUeb(appKey,0); + } + + @Override + public EPApp getAppFromUeb(String appKey, Integer quickCacheRefresh) { + refreshAppsMap(quickCacheRefresh == 1 ? quickRefreshCacheConf:slowRefreshCacheConf); + EPApp app = uebAppsMap.get(appKey); if(app != null) return app; return null;