Skip to content

Commit d28857c

Browse files
REMReM generate to be able to control the ER lookups (#159)
* REMReM generate able to control the ER lookups of shallow and pagesize * Added the documentaion of pageSize and shallow parameters of ER lookup handled in REMReM * Change the name of the parameteres from shallow, pagesize to connectToExternalErs and limit * Changed the description of of ER lookups content in documentaion * Added the description about local and external ER's * Changed the ER lookup parameters names connectToExternalERs to lookupInExternalERs and limit to lookupLimit * Changed the default value of lookupInExternalERs to false * Changed the description of lookupLimit Co-authored-by: Sudharshan Bandaru <sudharshan.bandaru@ericsson.com>
1 parent 4496618 commit d28857c

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.0.13
2+
- Added the lookupInExternalERs and lookupLimit parameters to ER lookup.
3+
14
## 2.0.12
25
- Uplifted eiffel-remrem-parent version from 2.0.2 to 2.0.4.
36
- Uplifted eiffel-remrem-shared version from 2.0.2 to 2.0.4.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<properties>
13-
<eiffel-remrem-generate.version>2.0.12</eiffel-remrem-generate.version>
13+
<eiffel-remrem-generate.version>2.0.13</eiffel-remrem-generate.version>
1414
<eiffel-remrem-shared.version>2.0.4</eiffel-remrem-shared.version>
1515
<eiffel-remrem-semantics.version>2.0.12</eiffel-remrem-semantics.version>
1616
</properties>

service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,11 @@ public final class RemremGenerateServiceConstants {
3535
public static final String UNAVAILABLE_FOR_FAILIFNONEFOUND = "{\"status_code\": 406, \"result\": \"FAIL\", "
3636
+ "\"message\":\"No event id found with ERLookup properties\"}";
3737

38+
public static final String LOOKUP_LIMIT = "The maximum number of events returned from a lookup. If more events "
39+
+ "are found they will be disregarded. The order of the events is undefined, which means that what events are "
40+
+ "disregarded is also undefined.";
41+
42+
public static final String LOOKUP_IN_EXTERNAL_ERS = "Determines if external ER's should be used to compile the results of query."
43+
+ "Use true to use External ER's.";
44+
3845
}

service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import org.slf4j.LoggerFactory;
3333
import org.springframework.beans.factory.annotation.Autowired;
34+
import org.springframework.beans.factory.annotation.Value;
3435
import org.springframework.http.HttpStatus;
3536
import org.springframework.http.MediaType;
3637
import org.springframework.http.RequestEntity;
@@ -97,10 +98,12 @@ public ResponseEntity<?> generate(
9798
@ApiParam(value = "message type", required = true) @RequestParam("msgType") final String msgType,
9899
@ApiParam(value = "ER lookup result multiple found, Generate will fail") @RequestParam(value = "failIfMultipleFound", required = false, defaultValue = "false") final Boolean failIfMultipleFound,
99100
@ApiParam(value = "ER lookup result none found, Generate will fail") @RequestParam(value = "failIfNoneFound", required = false, defaultValue = "false") final Boolean failIfNoneFound,
101+
@ApiParam(value = RemremGenerateServiceConstants.LOOKUP_IN_EXTERNAL_ERS) @RequestParam(value = "lookupInExternalERs", required = false, defaultValue = "false") final Boolean lookupInExternalERs,
102+
@ApiParam(value = RemremGenerateServiceConstants.LOOKUP_LIMIT) @RequestParam(value = "lookupLimit", required = false, defaultValue = "1") final int lookupLimit,
100103
@ApiParam(value = "JSON message", required = true) @RequestBody JsonObject bodyJson) {
101104

102105
try {
103-
bodyJson = erLookup(bodyJson, failIfMultipleFound, failIfNoneFound);
106+
bodyJson = erLookup(bodyJson, failIfMultipleFound, failIfNoneFound, lookupInExternalERs, lookupLimit);
104107
MsgService msgService = getMessageService(msgProtocol);
105108
String response;
106109
if (msgService != null) {
@@ -128,7 +131,8 @@ public ResponseEntity<?> generate(
128131
}
129132
}
130133

131-
private JsonObject erLookup(final JsonObject bodyJson, Boolean failIfMultipleFound, Boolean failIfNoneFound)
134+
private JsonObject erLookup(final JsonObject bodyJson, Boolean failIfMultipleFound, Boolean failIfNoneFound,
135+
final Boolean lookupInExternalERs, final int lookupLimit)
132136
throws REMGenerateException {
133137

134138
// Checking ER lookup enabled or not
@@ -141,7 +145,7 @@ private JsonObject erLookup(final JsonObject bodyJson, Boolean failIfMultipleFou
141145

142146
// prepare ER Query
143147
String Query = ERLookupController.getQueryfromLookup(lookupLinks.get(i).getAsJsonObject());
144-
String url = erlookupConfig.getErURL() + Query;
148+
String url = erlookupConfig.getErURL() + Query + String.format("&shallow=%s&pageSize=%d", !lookupInExternalERs, lookupLimit);
145149

146150
// Execute ER Query
147151
int j = 0;

service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void testErlookupSuccesswithMultipleIds() throws Exception {
167167
JsonParser parser = new JsonParser();
168168
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();
169169

170-
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelconfidencelevel", false, false, json);
170+
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelconfidencelevel", false, false, true, 1, json);
171171
assertEquals(elem.getStatusCode(), HttpStatus.OK);
172172
}
173173

@@ -178,7 +178,7 @@ public void testErlookupMultipleFound() throws Exception {
178178
JsonParser parser = new JsonParser();
179179
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();
180180

181-
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelcompositiondefined", true, false, json);
181+
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelcompositiondefined", true, false, true, 1, json);
182182
assertEquals(elem.getStatusCode(), HttpStatus.EXPECTATION_FAILED);
183183
}
184184

@@ -188,7 +188,7 @@ public void testErlookupMultipleTraces() throws Exception {
188188
JsonParser parser = new JsonParser();
189189
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();
190190

191-
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelartifactpublished", false, true, json);
191+
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelartifactpublished", false, true, true, 1, json);
192192
assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST);
193193
}
194194

@@ -198,7 +198,7 @@ public void testErlookupSuccesswithOneId() throws Exception {
198198
JsonParser parser = new JsonParser();
199199
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();
200200

201-
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelCompositionDefined", true, true, json);
201+
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelCompositionDefined", true, true, true, 1, json);
202202
assertEquals(elem.getStatusCode(), HttpStatus.OK);
203203
}
204204

@@ -208,7 +208,7 @@ public void testErlookupNoneFound() throws Exception {
208208
JsonParser parser = new JsonParser();
209209
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();
210210

211-
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEvent", true, true, json);
211+
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEvent", true, true, true, 1, json);
212212
assertEquals(elem.getStatusCode(), HttpStatus.NOT_ACCEPTABLE);
213213
}
214214

@@ -218,7 +218,7 @@ public void testErlookupMultipleTrace() throws Exception {
218218
JsonParser parser = new JsonParser();
219219
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();
220220

221-
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelSCSubmitted", false, true, json);
221+
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelSCSubmitted", false, true, true, 1, json);
222222
assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST);
223223
}
224224
}

service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,31 +102,31 @@ public void setUp() throws Exception {
102102

103103
@Test
104104
public void testSemanticsSuccessEvent() throws Exception {
105-
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelactivityfinished", false, false, body.getAsJsonObject());
105+
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelactivityfinished", false, false, true, 1, body.getAsJsonObject());
106106
assertEquals(elem.getStatusCode(), HttpStatus.OK);
107107
}
108108

109109
@Test
110110
public void testSemanticsFailureEvent() throws Exception {
111-
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "EiffelActivityFinished", false, false, body.getAsJsonObject());
111+
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "EiffelActivityFinished", false, false, true, 1, body.getAsJsonObject());
112112
assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST);
113113
}
114114

115115
@Test
116116
public void testEiffel3SuccessEvent() throws Exception {
117-
ResponseEntity<?> elem = unit.generate("eiffel3", "eiffelartifactnew", false, false, body.getAsJsonObject());
117+
ResponseEntity<?> elem = unit.generate("eiffel3", "eiffelartifactnew", false, false, true, 1, body.getAsJsonObject());
118118
assertEquals(elem.getStatusCode(), HttpStatus.OK);
119119
}
120120

121121
@Test
122122
public void testEiffel3FailureEvent() throws Exception {
123-
ResponseEntity<?> elem = unit.generate("eiffel3", "eiffelartifactnewevent", false, false, body.getAsJsonObject());
123+
ResponseEntity<?> elem = unit.generate("eiffel3", "eiffelartifactnewevent", false, false, true, 1, body.getAsJsonObject());
124124
assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST);
125125
}
126126

127127
@Test
128128
public void testMessageServiceUnavailableEvent() throws Exception {
129-
ResponseEntity<?> elem = unit.generate("other", "EiffelActivityFinishedEvent", false, false, body.getAsJsonObject());
129+
ResponseEntity<?> elem = unit.generate("other", "EiffelActivityFinishedEvent", false, false, true, 1, body.getAsJsonObject());
130130
assertEquals(elem.getStatusCode(), HttpStatus.SERVICE_UNAVAILABLE);
131131
}
132132

wiki/markdown/usage/service.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Available REST resources for REMReM Generate Service are described below:
2929

3030
| Resource | Method | Parameters | Request body | Description |
3131
|-----------------------|--------|---------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
32-
| /mp | POST | mp - message protocol, required msgType - Eiffel event type, required failIfMultipleFound - default: false failIfNoneFound - default: false | { "msgParams": {"meta": {# Matches the meta object }},"eventParams": {"data": {# Matches the data object},"links": { # Matches the links object } }} | This endpoint is used to generate Eiffel events and then the obtained event could be published by [Eiffel REMReM Publish](https://github.com/eiffel-community/eiffel-remrem-publish). |
32+
| /mp | POST | mp - message protocol, required msgType - Eiffel event type, required failIfMultipleFound - default: false failIfNoneFound - default: false, lookupInExternalERs - default: false, lookupLimit - default: 1| { "msgParams": {"meta": {# Matches the meta object }},"eventParams": {"data": {# Matches the data object},"links": { # Matches the links object } }} | This endpoint is used to generate Eiffel events and then the obtained event could be published by [Eiffel REMReM Publish](https://github.com/eiffel-community/eiffel-remrem-publish). |
3333
| /event_types/{mp} | GET | mp - message protocol, required | | This endpoint is used to obtain Eiffel event types implemented in [Eiffel REMReM Semantics](https://github.com/eiffel-community/eiffel-remrem-semantics). |
3434
| /template/{type}/{mp} | GET | type - Eiffel event type mp - message protocol, required | | This endpoint is used to obtain Eiffel event templates implemented in [Eiffel REMReM Semantics](https://github.com/eiffel-community/eiffel-remrem-semantics). |
3535
| /versions | GET | | | This endpoint is used to get versions of generate service and all loaded protocols versions in JSON format. |
@@ -204,9 +204,11 @@ https://localhost:8080/eventrepository/events/?meta.type=EiffelArtifactCreatedEv
204204
}]
205205
```
206206

207-
#### Lookups are provided with two options:
207+
#### Lookups are provided with four options:
208208

209209
| Options | Default Value | Description |
210210
|----------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
211-
| failIfMultipleFound: | False | If value is set to false, REMReM generates event if multiple event ids found or no event id fetched from the event repository configured in generate and adds them in links section of the target field. If value is set to true, if only one event is found then REMReM generates the event successfully and if multiple event ids are found then REMReM fails to generate any event and displays relevant error message to the user. |
212-
| failIfNoneFound: | False | If value is set to true, no event ids fetched from event repository , REMReM fails to generate any event and displays relevant error message to the user. If value is set to false,REMReM generates event if no event found or atleast one event fetched from the event repository configured in configuration file. |
211+
| failIfMultipleFound: | False | If value is set to True and multiple event ids are found through any of the provided lookup definitions, then no event will be generated. |
212+
| failIfNoneFound: | False | If value is set to True and no event id is found through (at least one of) the provided lookup definitions, then no event will be generated.|
213+
| lookupInExternalERs: | False | If value is set to True then REMReM will query external ERs and not just the locally used ER. The reason for the default value to be False is to decrease the load on external ERs. Here local ER means Single ER which is using REMReM generate. External ER means multiple ER's which are configured in Local ER.|
214+
| lookupLimit: | 1 | The number of events returned, through any lookup definition given, is limited to this number. |

0 commit comments

Comments
 (0)