2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.cacher.injestion.parser.strategy;
22 import com.google.gson.JsonArray;
23 import com.google.gson.JsonElement;
24 import com.google.gson.JsonObject;
25 import org.onap.aai.cacher.injestion.parser.AAIResourcesUriTemplates;
26 import org.onap.aai.cacher.model.CacheEntry;
27 import org.onap.aai.cacher.model.DBAction;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
30 import org.springframework.context.annotation.Scope;
31 import org.springframework.stereotype.Component;
33 import java.util.ArrayList;
34 import java.util.List;
37 * AAI resource get all parser strategy
39 @Component(value = "aai-resource-get-all")
40 @Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON)
41 public class AAIResourceGetAllPayloadParserStrategy implements PayloadParserStrategy {
43 AAIResourcesUriTemplates aaiResourcesUriTemplates;
46 public AAIResourceGetAllPayloadParserStrategy(AAIResourcesUriTemplates aaiResourcesUriTemplates) {
47 this.aaiResourcesUriTemplates = aaiResourcesUriTemplates;
51 * Parses aai resources specific payloads generating the details for .
58 public List<CacheEntry> process(String originalKey, JsonObject jsonObject) {
59 final List<CacheEntry> cacheEntries = new ArrayList<>();
61 String type = jsonObject.entrySet().iterator().next().getKey();
63 JsonArray ja = jsonObject.getAsJsonArray(type);
64 CacheEntry cacheEntry;
67 for (JsonElement jsonElement : ja) {
68 jo = jsonElement.getAsJsonObject();
69 uri = aaiResourcesUriTemplates.getUri(type, jo);
70 jsonObject.addProperty("_id", uri);
71 cacheEntry = CacheEntry.CacheEntryBuilder.createCacheEntry().withId(uri).inCollection(originalKey)
72 .withFindQuery(getFindQuery(uri)).withPayload(jo).withDbAction(DBAction.INSERT_REPLACE).build();
73 cacheEntries.add(cacheEntry);
79 protected JsonObject getFindQuery(String uri) {
80 JsonObject jo = new JsonObject();
81 jo.addProperty("_id", uri);