Skip to content

Commit

Permalink
Code to handle the lookup towards Event Repository when generating ev…
Browse files Browse the repository at this point in the history
…ents using REMReM. (#135)

Added code to handle the Event Repository lookups and generate the links.
  • Loading branch information
durga-vasaadi authored and SantoshNC68 committed Oct 15, 2019
1 parent 816a90b commit 9037412
Show file tree
Hide file tree
Showing 26 changed files with 1,069 additions and 54 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 2.0.6
- Added ER Lookup configurations for a link when generating events
- Uplifted eiffel-remrem-generate cersion from 2.0.5 to 2.0.6
- Added ER Lookup configurations for a link and code to handle the lookup towards ER when generating events.
- Uplifted eiffel-remrem-generate version from 2.0.5 to 2.0.6

## 2.0.5
- Uplifted eiffel-remrem-parent version from 2.0.1 to 2.0.2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package com.ericsson.eiffel.remrem.generate.config;

import javax.annotation.PostConstruct;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import ch.qos.logback.classic.Logger;

Expand All @@ -29,7 +31,6 @@
*
*/

@Profile("!integration-test")
@Configuration
@Component("event-repository")
public class ErLookUpConfig {
Expand All @@ -47,19 +48,10 @@ public String getErURL() {
return erURL;
}

public void setErURL(String erURL) {
this.erURL = erURL;
}

public String getEventRepositoryEnabled() {
return eventRepositoryEnabled;
public Boolean getEventRepositoryEnabled() {
return eventRepositoryCheck;
}

public void setEventRepositoryEnabled(String eventRepositoryEnabled) {
this.eventRepositoryEnabled = eventRepositoryEnabled;
}


/**
* This method is used to check whether to enable Event-Repository lookup .
* If event-repository.enabled is false, it didn't perform lookup functionality while fetching events.
Expand All @@ -76,7 +68,6 @@ public void checkAndLoadEventRepositoryConfiguration() throws InterruptedExcepti
if (eventRepositoryCheck) {
if (!erURL.isEmpty()) {
log.info("Event Repository configurations for lookup are enabled");
setErURL(erURL);
log.info("Configured Event Repository URL for lookup : " + getErURL());
} else {
log.error("Enabled Event Repository configurations for lookUp but not provided Event Repository URL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ public final class RemremGenerateServiceConstants {

public static final String DOCUMENTATION_URL = "https://eiffel-community.github.io/eiffel-remrem-generate/index.html";

public static final String UNAVAILABLE_FOR_FAILIFMULTIPLEFOUND = "{\"status_code\": 417, \"result\": \"FAIL\", "
+ "\"message\":\"Muliple event ids found with ERLookup properties\"}";

public static final String UNAVAILABLE_FOR_FAILIFNONEFOUND = "{\"status_code\": 406, \"result\": \"FAIL\", "
+ "\"message\":\"No event id found with ERLookup properties\"}";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2019 Ericsson AB.
For a full list of individual contributors, please see the commit history.
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.
*/
package com.ericsson.eiffel.remrem.generate.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.StreamSupport;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class ERLookupController {

public static String getQueryfromLookup(JsonObject link) {
String query = null;
if (link.toString().contains("%lookup%")) {
final JsonObject lookup = link.get("%lookup%").getAsJsonObject();
final String eventType = lookup.get("eventType").getAsString();
final JsonArray lookUpParams = lookup.get("properties").getAsJsonArray();
final StringBuilder queryBuilder = new StringBuilder("/eventrepository/events?meta.type=" + eventType);
StreamSupport.stream(lookUpParams.spliterator(), false)
.forEach(jsonArray -> {
for (Entry<String, JsonElement> entry : jsonArray.getAsJsonObject().entrySet()) {
final String propertyKey = entry.getKey();
final String propertyValue = entry.getValue().getAsString();
final String str = "&" + propertyKey + "=" + propertyValue;
queryBuilder.append(str);
}
});
query = queryBuilder.toString();
}
return query;
}

public static String[] getIdsfromResponseBody(String responseBody) {

final JsonObject jsonObject = new JsonParser().parse(responseBody).getAsJsonObject();
final JsonArray asJsonArray = jsonObject.get("items").getAsJsonArray();
final int length = asJsonArray.size();
if (length == 0) {
return new String[0];
} else {
final List<String> list = new ArrayList<>();
asJsonArray.forEach(
item -> list.add(item.getAsJsonObject().get("meta").getAsJsonObject().get("id").getAsString()));
return list.toArray(new String[0]);
}
}

public static void convertbodyJsontoLookupJson(String[] ids, JsonObject link, JsonArray links) {
final String type = link.get("type").getAsString();
for (int j = 0; j < ids.length; j++) {
final JsonObject newJsonObject = new JsonObject();
newJsonObject.addProperty("type", type);
newJsonObject.addProperty("target", ids[j]);
links.add(newJsonObject);
}
}
}
Loading

0 comments on commit 9037412

Please sign in to comment.