diff options
-rw-r--r-- | INFO.yaml | 16 | ||||
-rw-r--r-- | pom.xml | 16 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/cacher/common/MongoConfig.java | 7 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/cacher/common/MongoHelperSingleton.java | 67 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/cacher/service/tasks/ScheduledTaskConfig.java | 25 |
5 files changed, 62 insertions, 69 deletions
@@ -4,11 +4,11 @@ project_creation_date: '2018-07-09' project_category: '' lifecycle_state: 'Incubation' project_lead: &onap_aai_ptl - name: 'James Forsyth' - email: 'jf2512@att.com' - id: 'jimmydot' + name: 'William Reehil' + email: 'william.reehil@att.com' company: 'ATT' - timezone: 'America/Detroit' + id: 'wreehil' + timezone: 'America/New_York' primary_contact: *onap_aai_ptl issue_tracking: type: 'jira' @@ -46,11 +46,11 @@ committers: company: 'ATT' id: 'vk250x' timezone: 'America/New_York' - - name: 'William Reehil' - email: 'william.reehil@att.com' + - name: 'James Forsyth' + email: 'jf2512@att.com' + id: 'jimmydot' company: 'ATT' - id: 'wreehil' - timezone: 'America/New_York' + timezone: 'America/Detroit' tsc: approval: 'https://lists.onap.org/g/onap-tsc' changes: @@ -279,11 +279,6 @@ <version>1.18</version> </dependency> <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-compress</artifactId> - <version>1.18</version> - </dependency> - <dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver</artifactId> <version>3.6.2</version> @@ -364,10 +359,6 @@ <version>2.24</version> </dependency> <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - </dependency> - <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> @@ -555,12 +546,9 @@ <artifactId>maven-dependency-plugin</artifactId> </plugin> <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - <plugin> <artifactId>exec-maven-plugin</artifactId> <groupId>org.codehaus.mojo</groupId> + <version>3.0.0</version> </plugin> <plugin> <groupId>org.springframework.boot</groupId> @@ -603,10 +591,12 @@ <plugin> <groupId>com.github.kongchen</groupId> <artifactId>swagger-maven-plugin</artifactId> + <version>3.1.8</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> + <version>3.2.0</version> <configuration> <additionalparam>-Xdoclint:none</additionalparam> </configuration> diff --git a/src/main/java/org/onap/aai/cacher/common/MongoConfig.java b/src/main/java/org/onap/aai/cacher/common/MongoConfig.java index 5c1a541..ca063a7 100644 --- a/src/main/java/org/onap/aai/cacher/common/MongoConfig.java +++ b/src/main/java/org/onap/aai/cacher/common/MongoConfig.java @@ -48,7 +48,7 @@ import java.io.IOException; @Configuration public class MongoConfig { - private final static EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(MongoConfig.class); + private static final EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(MongoConfig.class); @Value("${mongodb.host}") private String MONGO_DB_HOST; @@ -61,9 +61,8 @@ public class MongoConfig { @Bean public MongoClient mongoClient(MongodProcess mongodProcess) { - try { - // To connect to mongodb server - MongoClient mongoC = new MongoClient(MONGO_DB_HOST, MONGO_DB_PORT); + // To connect to mongodb server + try (MongoClient mongoC = new MongoClient(MONGO_DB_HOST, MONGO_DB_PORT)) { // Now connect to your databases EELF_LOGGER.info("Connect to database successfully"); diff --git a/src/main/java/org/onap/aai/cacher/common/MongoHelperSingleton.java b/src/main/java/org/onap/aai/cacher/common/MongoHelperSingleton.java index a94f36a..3b52a00 100644 --- a/src/main/java/org/onap/aai/cacher/common/MongoHelperSingleton.java +++ b/src/main/java/org/onap/aai/cacher/common/MongoHelperSingleton.java @@ -57,7 +57,11 @@ import java.util.stream.Collectors; @Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON) public class MongoHelperSingleton { - private final static EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(MongoHelperSingleton.class); + public static final String AAI_4000_LBL = "AAI_4000"; + + public static final String AAI_5105_LBL = "AAI_5105"; + + private static final EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(MongoHelperSingleton.class); private DB db; @@ -80,7 +84,7 @@ public class MongoHelperSingleton { db.getCollection(name); EELF_LOGGER.info("Collection " + name + " created successfully"); } catch (Exception e) { - AAIException aaiException = new AAIException("AAI_4000"); + AAIException aaiException = new AAIException(AAI_4000_LBL); ErrorLogHelper.logException(aaiException); } } @@ -100,11 +104,11 @@ public class MongoHelperSingleton { return false; } } catch (MongoException ex) { - AAIException aaiException = new AAIException("AAI_5105"); + AAIException aaiException = new AAIException(AAI_5105_LBL); ErrorLogHelper.logException(aaiException); return false; } catch (Exception e) { - AAIException aaiException = new AAIException("AAI_4000"); + AAIException aaiException = new AAIException(AAI_4000_LBL); ErrorLogHelper.logException(aaiException); return false; } @@ -118,11 +122,11 @@ public class MongoHelperSingleton { result = collection.update(searchQuery, (BasicDBObject) document, updateOptions); return result.wasAcknowledged(); } catch (MongoException ex) { - AAIException aaiException = new AAIException("AAI_5105"); + AAIException aaiException = new AAIException(AAI_5105_LBL); ErrorLogHelper.logException(aaiException); return false; } catch (Exception e) { - AAIException aaiException = new AAIException("AAI_4000"); + AAIException aaiException = new AAIException(AAI_4000_LBL); ErrorLogHelper.logException(aaiException); return false; } @@ -144,7 +148,7 @@ public class MongoHelperSingleton { return "NOT_FOUND"; } } catch (MongoException ex) { - AAIException aaiException = new AAIException("AAI_5105"); + AAIException aaiException = new AAIException(AAI_5105_LBL); ErrorLogHelper.logException(aaiException); return "EXCEPTION_THROWN"; } @@ -266,7 +270,6 @@ public class MongoHelperSingleton { protected void mongoPull(CacheEntry cacheEntry, MongoCollection<Document> collection, Document nestedFind) { CacheEntry localCacheEntry = CacheEntry.CacheEntryBuilder.createCacheEntry().deepCopy(cacheEntry).build(); - ArrayList<Document> filters = this.getFiltersAndUpdateNestedField(localCacheEntry); Document pullObj = new Document(); pullObj.put(localCacheEntry.getNestedField(), @@ -275,42 +278,46 @@ public class MongoHelperSingleton { pull.put("$pull", pullObj); collection.findOneAndUpdate(nestedFind, pull, new FindOneAndUpdateOptions().upsert(true)); // TODO remove wrapping if there are no entries in array. - } private ArrayList<Document> getFiltersAndUpdateNestedField(CacheEntry cacheEntry) { - - if (StringUtils.countMatches(cacheEntry.getNestedField(), ".$.") < 2) { - return new ArrayList<>(); - } - ArrayList<Document> filters = new ArrayList<>(); - List<String> keys = cacheEntry.getNestedFind().entrySet().stream().map(Map.Entry::getKey) - .filter(s -> !s.equals("_id")).sorted((s, t1) -> { - if (StringUtils.countMatches(s, ".") > StringUtils.countMatches(t1, ".")) { - return 1; - } - return s.compareTo(t1); - }).collect(Collectors.toList()); String filterKey; String filterValue; String key; char filterIndex = 'a'; StringBuilder newNestedField = new StringBuilder(); + + if (StringUtils.countMatches(cacheEntry.getNestedField(), ".$.") < 2) { + return new ArrayList<>(); + } + + List<String> keys = cacheEntry.getNestedFind().entrySet().stream() + .map(Map.Entry::getKey) + .filter(s -> !s.equals("_id")).sorted((s, t1) -> { + if (StringUtils.countMatches(s, ".") > StringUtils.countMatches(t1, ".")) { + return 1; + } + return s.compareTo(t1); + }).collect(Collectors.toList()); List<String> fieldSplit = Arrays.asList(cacheEntry.getNestedField().split("\\.\\$")); + for (int i = 0; i < fieldSplit.size(); i++) { final String subSplit = StringUtils.join(fieldSplit.subList(0, i + 1), ""); - key = keys.stream().filter(s -> s.startsWith(subSplit)).findFirst().get(); - filterIndex += i; - filterKey = filterIndex + "." + key.substring(key.lastIndexOf(".") + 1); - filterValue = cacheEntry.getNestedFind().get(key).getAsString(); - newNestedField.append(fieldSplit.get(i)); - if (i + 1 != fieldSplit.size()) { - newNestedField.append(".$[").append(filterIndex).append("]"); - filters.add(new Document().append(filterKey, filterValue)); + Optional<String> keyOpt = keys.stream().filter(s -> s.startsWith(subSplit)).findFirst(); + if (keyOpt.isPresent()) { + key = keyOpt.get(); + filterIndex += i; + filterKey = filterIndex + "." + key.substring(key.lastIndexOf(".") + 1); + filterValue = cacheEntry.getNestedFind().get(key).getAsString(); + newNestedField.append(fieldSplit.get(i)); + if (i + 1 != fieldSplit.size()) { + newNestedField.append(".$[").append(filterIndex).append("]"); + filters.add(new Document().append(filterKey, filterValue)); + } } - } + cacheEntry.setNestedField(newNestedField.toString()); return filters; diff --git a/src/main/java/org/onap/aai/cacher/service/tasks/ScheduledTaskConfig.java b/src/main/java/org/onap/aai/cacher/service/tasks/ScheduledTaskConfig.java index 2a9a403..cdd9a2c 100644 --- a/src/main/java/org/onap/aai/cacher/service/tasks/ScheduledTaskConfig.java +++ b/src/main/java/org/onap/aai/cacher/service/tasks/ScheduledTaskConfig.java @@ -31,18 +31,18 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.config.IntervalTask; import org.springframework.scheduling.config.ScheduledTaskRegistrar; -import java.text.SimpleDateFormat; import java.util.Date; @Configuration public class ScheduledTaskConfig { - private final static EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(ScheduledTaskConfig.class); - private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); - private final static int THREAD_POOL_SIZE = 10; - private final static String THREAD_POOL_PREFIX = "poolScheduler"; - private final static int TASK_INTERVAL_TIME = 30000; - private final static int TASK_DELAY_TIME = 0; + private static final EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(ScheduledTaskConfig.class); + private static final int THREAD_POOL_SIZE = 10; + private static final String THREAD_POOL_PREFIX = "poolScheduler"; + private static final int TASK_INTERVAL_TIME = 30000; + private static final int TASK_DELAY_TIME = 0; + + private ScheduledTaskConfig(){} @Configuration static class RegisterTaskSchedulerViaSchedulingConfigurer implements SchedulingConfigurer { @@ -53,13 +53,10 @@ public class ScheduledTaskConfig { @Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { taskRegistrar.setTaskScheduler(poolScheduler()); - taskRegistrar.addFixedRateTask(new IntervalTask(new Runnable() { - @Override - public void run() { - EELF_LOGGER.info( - "Job @ fixed rate " + new Date() + ", Thread name is " + Thread.currentThread().getName()); - chs.checkAndInitTasks(); - } + taskRegistrar.addFixedRateTask(new IntervalTask(() -> { + EELF_LOGGER.info( + "Job @ fixed rate " + new Date() + ", Thread name is " + Thread.currentThread().getName()); + chs.checkAndInitTasks(); }, TASK_INTERVAL_TIME, TASK_DELAY_TIME)); } |