diff options
8 files changed, 170 insertions, 136 deletions
@@ -4,11 +4,11 @@ project_creation_date: '2018-07-09' project_category: '' lifecycle_state: 'Mature' 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,6 +46,11 @@ committers: company: 'ATT' id: 'vk250x' timezone: 'America/New_York' + - name: 'James Forsyth' + email: 'jf2512@att.com' + id: 'jimmydot' + company: 'ATT' + timezone: 'America/Detroit' tsc: approval: 'https://lists.onap.org/g/onap-tsc' changes: @@ -55,3 +60,6 @@ tsc: - type: 'removal' name: 'Tian Lee' link: 'https://lists.onap.org/g/onap-tsc/message/6227' + - type: 'Addition' + name: 'William Reehil' + link: 'https://lists.onap.org/g/onap-tsc/message/6506' @@ -265,7 +265,7 @@ <dependency> <groupId>de.flapdoodle.embed</groupId> <artifactId>de.flapdoodle.embed.mongo</artifactId> - <version>2.0.3</version> + <version>2.2.0</version> <exclusions> <exclusion> <groupId>org.apache.commons</groupId> @@ -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> @@ -631,7 +621,7 @@ <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> - <version>0.7.7.201606060606</version> + <version>0.8.5</version> <configuration> <dumpOnExit>true</dumpOnExit> </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/exceptions/MissingTemplateException.java b/src/main/java/org/onap/aai/cacher/exceptions/MissingTemplateException.java new file mode 100644 index 0000000..d47541b --- /dev/null +++ b/src/main/java/org/onap/aai/cacher/exceptions/MissingTemplateException.java @@ -0,0 +1,29 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2020 Bell Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.cacher.exceptions; + +public class MissingTemplateException extends RuntimeException { + + public static final String DEFAULT_EXCEPTION_MESSAGE = "Failed in uriToTemplates for truncatedUri '%s'"; + + public MissingTemplateException(String uri) { + super(String.format(DEFAULT_EXCEPTION_MESSAGE, uri)); + } +} diff --git a/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/AAIResourcesUriTemplates.java b/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/AAIResourcesUriTemplates.java index 887e4d3..819a7a6 100644 --- a/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/AAIResourcesUriTemplates.java +++ b/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/AAIResourcesUriTemplates.java @@ -24,6 +24,7 @@ import com.att.eelf.configuration.EELFManager; import com.google.gson.JsonObject; import org.apache.commons.lang3.StringUtils; import org.onap.aai.annotations.Metadata; +import org.onap.aai.cacher.exceptions.MissingTemplateException; import org.onap.aai.cacher.util.AAIConstants; import org.reflections.Reflections; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -44,7 +45,7 @@ import java.util.*; @Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON) public class AAIResourcesUriTemplates { - private final static EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIResourcesUriTemplates.class); + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIResourcesUriTemplates.class); private final Map<String, String> typeToUriTemplate; @@ -63,13 +64,13 @@ public class AAIResourcesUriTemplates { Reflections reflections = new Reflections("org.onap.aai.domain.yang"); reflections.getTypesAnnotatedWith(Metadata.class) - .stream() - .filter(aClass -> "org.onap.aai.domain.yang".equals(aClass.getPackage().getName())) - .filter(aClass -> !aClass.getAnnotation(Metadata.class).uriTemplate().isEmpty()) - .forEach(aClass -> typeToUriTemplate.put( - aClass.getAnnotation(XmlRootElement.class).name(), - aClass.getAnnotation(Metadata.class).uriTemplate()) - ); + .stream() + .filter(aClass -> "org.onap.aai.domain.yang".equals(aClass.getPackage().getName())) + .filter(aClass -> !aClass.getAnnotation(Metadata.class).uriTemplate().isEmpty()) + .forEach(aClass -> typeToUriTemplate.put( + aClass.getAnnotation(XmlRootElement.class).name(), + aClass.getAnnotation(Metadata.class).uriTemplate()) + ); LOGGER.info("AAI uri templates: " + typeToUriTemplate); } @@ -80,7 +81,7 @@ public class AAIResourcesUriTemplates { /** * Get templated aai uri segment by type. - * + * * @param type * @return */ @@ -90,6 +91,7 @@ public class AAIResourcesUriTemplates { /** * For the given template and uri get the variable key value pairs + * * @param uri * @param template * @return @@ -106,7 +108,7 @@ public class AAIResourcesUriTemplates { /** * For a given uri get an ordered list of templates. - * + * * @param uri * @return */ @@ -118,19 +120,20 @@ public class AAIResourcesUriTemplates { while (truncatedUri.contains("/")) { matchingStartingTemplate = this.getMatchingStartingTemplate(truncatedUri); - if ( !matchingStartingTemplate.isPresent()) { + if (!matchingStartingTemplate.isPresent()) { LOGGER.error("failed in uriToTemplates for truncatedUri " + truncatedUri); - // exception expected for missing template - } - template = matchingStartingTemplate.get(); - uriTemplateList.add(template); - int count = StringUtils.countMatches(template, "/"); - if (count < StringUtils.countMatches(truncatedUri, "/")) { - truncatedUri = StringUtils.substring( + throw new MissingTemplateException(truncatedUri); + } else { + template = matchingStartingTemplate.get(); + uriTemplateList.add(template); + int count = StringUtils.countMatches(template, "/"); + if (count < StringUtils.countMatches(truncatedUri, "/")) { + truncatedUri = StringUtils.substring( truncatedUri, StringUtils.ordinalIndexOf(truncatedUri, "/", count + 1)); - } else { - truncatedUri = ""; + } else { + truncatedUri = ""; + } } } @@ -139,7 +142,7 @@ public class AAIResourcesUriTemplates { /** * For a given uri get an ordered list of templates. - * + * * @param uri * @return */ @@ -149,14 +152,17 @@ public class AAIResourcesUriTemplates { String truncatedUri = uri; while (truncatedUri.contains("/")) { - template = this.getMatchingStartingTemplate(truncatedUri).get(); - int count = StringUtils.countMatches(template, "/"); - int cutIndex = truncatedUri.length(); - if (count != StringUtils.countMatches(truncatedUri, "/")) { - cutIndex = StringUtils.ordinalIndexOf(truncatedUri, "/", count + 1); + Optional<String> templateOpt = this.getMatchingStartingTemplate(truncatedUri); + if (templateOpt.isPresent()) { + template = templateOpt.get(); + int count = StringUtils.countMatches(template, "/"); + int cutIndex = truncatedUri.length(); + if (count != StringUtils.countMatches(truncatedUri, "/")) { + cutIndex = StringUtils.ordinalIndexOf(truncatedUri, "/", count + 1); + } + uriList.add(StringUtils.substring(truncatedUri, 0, cutIndex)); + truncatedUri = StringUtils.substring(truncatedUri, cutIndex); } - uriList.add(StringUtils.substring(truncatedUri, 0, cutIndex)); - truncatedUri = StringUtils.substring(truncatedUri, cutIndex); } return uriList; @@ -164,7 +170,7 @@ public class AAIResourcesUriTemplates { /** * returns the template matching the start of the uri. - * + * * @param uri * @return @see java.util.Optional */ @@ -174,7 +180,7 @@ public class AAIResourcesUriTemplates { /** * Given aai type and json object generate the uri for it. - * + * * @param type * @param jo * @return @@ -190,7 +196,7 @@ public class AAIResourcesUriTemplates { /** * Get encoded values from json object for each key in keys - * + * * @param keys * @param jo * @return @@ -204,7 +210,7 @@ public class AAIResourcesUriTemplates { /** * extract uri keys from the templated uri - * + * * @param template * @return */ @@ -216,7 +222,7 @@ public class AAIResourcesUriTemplates { /** * UTF-8 encoding of @param string - * + * * @param string string to be encoded * @return */ @@ -230,7 +236,7 @@ public class AAIResourcesUriTemplates { /** * UTF-8 decoding of @param string - * + * * @param string string to be encoded * @return */ @@ -260,7 +266,7 @@ public class AAIResourcesUriTemplates { for (int i = 0; i < uriSegments.size(); i++) { aus = new AAIUriSegment(uriSegments.get(i), uriSegmentTemplates.get(i)); aus.setSegmentKeyValues( - getUriTemplateMappings(aus.getSegment(), aus.getSegmentTemplate())); + getUriTemplateMappings(aus.getSegment(), aus.getSegmentTemplate())); uriSegmentList.add(aus); } return uriSegmentList; diff --git a/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/dmaap/AAIResourceDmaapParserStrategy.java b/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/dmaap/AAIResourceDmaapParserStrategy.java index 8d88a4a..d879314 100644 --- a/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/dmaap/AAIResourceDmaapParserStrategy.java +++ b/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/dmaap/AAIResourceDmaapParserStrategy.java @@ -48,7 +48,9 @@ import java.util.stream.Collectors; @Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON) public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadParserStrategy { - private final static EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIResourceDmaapParserStrategy.class); + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIResourceDmaapParserStrategy.class); + + public static final String RELATED_LINK_PROPERTY_KEY = "related-link"; @Autowired public AAIResourceDmaapParserStrategy(AAIResourcesUriTemplates aaiResourcesUriTemplates) { @@ -133,7 +135,7 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars private CacheEntry getParentUpdateCacheEntry(String topEntityType, String entityUri, DmaapAction actionType, List<AAIUriSegment> uriSegments) { String parentUri = String.join( "", - uriSegments.stream().limit(uriSegments.size()-1).map(AAIUriSegment::getSegment).collect(Collectors.toList())); + uriSegments.stream().limit(uriSegments.size()-1L).map(AAIUriSegment::getSegment).collect(Collectors.toList())); JsonObject findQuery = new JsonObject(); findQuery.addProperty("_id", parentUri); JsonObject nestedFindQuery = new JsonObject(); @@ -181,10 +183,10 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars findQuery.addProperty("_id", uri); JsonObject nestedFindQuery = new JsonObject(); nestedFindQuery.addProperty("_id", uri); - nestedFindQuery.addProperty("relationship-list.relationship.related-link", entity.get("related-link").getAsString()); + nestedFindQuery.addProperty("relationship-list.relationship.related-link", entity.get(RELATED_LINK_PROPERTY_KEY).getAsString()); String nestedField = "relationship-list.relationship"; JsonObject nestedIdentifier = new JsonObject(); - nestedIdentifier.addProperty("related-link", entity.get("related-link").getAsString()); + nestedIdentifier.addProperty(RELATED_LINK_PROPERTY_KEY, entity.get(RELATED_LINK_PROPERTY_KEY).getAsString()); return CacheEntry.CacheEntryBuilder.createCacheEntry().inCollection(collection).withDbAction(actionType.getDbAction()) .withId(uri).isNested(true).withPayload(entity).withFindQuery(findQuery) @@ -197,18 +199,17 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars existingCacheEntriesRelationships.forEach((k, v) -> { if (cacheEntriesRelationships.containsKey(k)) { v.forEach(oldA -> { - int found = -1; - for (int i = 0; i < cacheEntriesRelationships.get(k).size(); i++) { - if (cacheEntriesRelationships.get(k).get(i).getFullUri().equals(oldA.getFullUri())) { - found = i; - break; - } - } - if (found != -1) { - cacheEntriesRelationships.get(k).remove(cacheEntriesRelationships.get(k).get(found)); + List<AAIRelatedToDetails> cacheEntriesRelationshipsForK = cacheEntriesRelationships.get(k); + + Optional<AAIRelatedToDetails> foundEntryOpt = cacheEntriesRelationshipsForK.stream() + .filter(entry -> entry.getFullUri().equals(oldA.getFullUri())) + .findFirst(); + + if (foundEntryOpt.isPresent()) { + cacheEntriesRelationshipsForK.remove(foundEntryOpt.get()); } else { oldA.setActionType(DmaapAction.DELETE); - cacheEntriesRelationships.get(k).add(oldA); + cacheEntriesRelationshipsForK.add(oldA); } }); } else { @@ -231,7 +232,7 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars JsonArray relationships = e.getValue().getAsJsonObject().getAsJsonArray("relationship"); for (JsonElement relationship : relationships) { relationshipMapping.add(fullUriPrefix + cacheEntry.getId(), new AAIRelatedToDetails( - relationship.getAsJsonObject().get("related-link").getAsString(), + relationship.getAsJsonObject().get(RELATED_LINK_PROPERTY_KEY).getAsString(), relationship.getAsJsonObject().get("relationship-label").getAsString(), actionType)); } } @@ -256,7 +257,7 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars if (label != null) { relObj.addProperty("relationship-label", label); } - relObj.addProperty("related-link", fullUri); + relObj.addProperty(RELATED_LINK_PROPERTY_KEY, fullUri); for (AAIUriSegment aaiUriSegment : uriSegmentList) { aaiUriSegment.getSegmentKeyValues().forEach((k, v) -> { @@ -281,35 +282,35 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars if (uriSegments.size() > 1) { Optional<String> segmentPlural; String segmentSingular; - String jsonStr; JsonObject jsonObj; JsonArray jsonArray; - JsonElement jsonElement; for (int i = 1; i < uriSegments.size(); i++) { + segmentPlural = uriSegments.get(i).getSegmentPlural(); + segmentSingular = uriSegments.get(i).getSegmentSingular(); - if (uriSegments.get(i).getSegmentPlural().isPresent()) { - segmentPlural = uriSegments.get(i).getSegmentPlural(); - segmentSingular = uriSegments.get(i).getSegmentSingular(); - if ( segmentSingular.equals("cvlan-tag")) { - // map to what is in the entity + if (segmentPlural.isPresent()) { + if (segmentSingular.equals("cvlan-tag")) { + // map to what is in the entity segmentSingular = "cvlan-tag-entry"; } - jsonObj = entityBody.getAsJsonObject(uriSegments.get(i).getSegmentPlural().get()); + jsonObj = entityBody.getAsJsonObject(segmentPlural.get()); jsonArray = jsonObj.getAsJsonArray(segmentSingular); - if ( jsonArray == null ) { - LOGGER.error("failed in getWrappedEntityObject " + segmentSingular + " not found in " + jsonObj ); + if (jsonArray == null) { + LOGGER + .error("failed in getWrappedEntityObject " + segmentSingular + " not found in " + jsonObj); // exception expected for missing template + } else { + entityBody = jsonArray.get(0).getAsJsonObject(); + arrayKey = segmentSingular; } - entityBody = jsonArray.get(0).getAsJsonObject(); - arrayKey = uriSegments.get(i).getSegmentSingular(); } else { - entityBody = entityBody.getAsJsonArray(uriSegments.get(i).getSegmentSingular()).get(0).getAsJsonObject(); - arrayKey = uriSegments.get(i).getSegmentSingular(); + entityBody = entityBody.getAsJsonArray(segmentSingular).get(0).getAsJsonObject(); + arrayKey = segmentSingular; } - } } + arrayWrapper.add(entityBody); objectWrapper.add(arrayKey, arrayWrapper); return objectWrapper; @@ -321,7 +322,4 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars } return String.join("", uriSegments.subList(0, uriSegments.size()-1).stream().map(AAIUriSegment::getSegment).collect(Collectors.toList())); } - - - }
\ No newline at end of file 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)); } |