Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.1.3
- REST API parameter `domainId` added.

## 2.1.2
- Added external parameters to send username, password and/or uri to connect to Messagebus.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
*/
package com.ericsson.eiffel.remrem.publish.controller;

import java.net.URISyntaxException;
import java.util.EnumSet;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.URIBuilder;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -180,6 +183,7 @@ public ResponseEntity send(
@ResponseBody
public ResponseEntity generateAndPublish(@ApiParam(value = "message protocol", required = true) @RequestParam(value = "mp") final String msgProtocol,
@ApiParam(value = "message type", required = true) @RequestParam("msgType") final String msgType,
@ApiParam(value = "domain ID") @RequestParam(value = "domainId", required = false) final String domainId,
@ApiParam(value = "user domain") @RequestParam(value = "ud", required = false) final String userDomain,
@ApiParam(value = "tag") @RequestParam(value = "tag", required = false) final String tag,
@ApiParam(value = "routing key") @RequestParam(value = "rk", required = false) final String routingKey,
Expand Down Expand Up @@ -215,10 +219,22 @@ public ResponseEntity generateAndPublish(@ApiParam(value = "message protocol", r
EnumSet<HttpStatus> getStatus = EnumSet.of(HttpStatus.SERVICE_UNAVAILABLE, HttpStatus.UNAUTHORIZED, HttpStatus.NOT_ACCEPTABLE, HttpStatus.EXPECTATION_FAILED, HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.UNPROCESSABLE_ENTITY);

try {
String generateUrl = generateURLTemplate.getUrl() + "&failIfMultipleFound=" + failIfMultipleFound
+ "&failIfNoneFound=" + failIfNoneFound + "&lookupInExternalERs=" + lookupInExternalERs
+ "&lookupLimit=" + lookupLimit + "&okToLeaveOutInvalidOptionalFields=" + okToLeaveOutInvalidOptionalFields;
ResponseEntity<String> response = restTemplate.postForEntity(generateUrl,
URIBuilder builder = null;
try {
builder = new URIBuilder(generateURLTemplate.getUrl());
builder.addParameter("failIfMultipleFound", failIfMultipleFound.toString());
builder.addParameter("failIfNoneFound", failIfNoneFound.toString());
builder.addParameter("lookupInExternalERs", lookupInExternalERs.toString());
builder.addParameter("lookupLimit", String.valueOf(lookupLimit));
builder.addParameter("okToLeaveOutInvalidOptionalFields", okToLeaveOutInvalidOptionalFields.toString());
if (StringUtils.isNotBlank(domainId))
builder.addParameter("domainId", domainId);
} catch (URISyntaxException e) {
return new ResponseEntity("Cannot build URL of generate service: " + e.getMessage(),
HttpStatus.INTERNAL_SERVER_ERROR);
}

ResponseEntity<String> response = restTemplate.postForEntity(builder.toString(),
entity, String.class, generateURLTemplate.getMap(msgProtocol, msgType));

if (response.getStatusCode() == HttpStatus.OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void testRestTemplateCallSuccess() throws Exception {
when(restTemplate.postForEntity(Mockito.contains(correctURL), Mockito.<HttpEntity<String>>any(),
Mockito.eq(String.class), Mockito.anyMap())).thenReturn(responseOK);

ResponseEntity<?> elem = unit.generateAndPublish("eiffelsemantics", "eiffelactivityfinished", "", "", "",false,
ResponseEntity<?> elem = unit.generateAndPublish("eiffelsemantics", "eiffelactivityfinished", null, "", "", "",false,
null, null, true, 1, false, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.OK);

Expand All @@ -140,7 +140,7 @@ public void testRestTemplateCallFail() throws Exception {
when(restTemplate.postForEntity(Mockito.contains(inCorrectURL), Mockito.<HttpEntity<String>>any(),
Mockito.eq(String.class), Mockito.anyMap())).thenReturn(responseBad);

ResponseEntity<?> elem = unit.generateAndPublish("eiffel3", "eiffelactivityfinished", "", "", "",false,
ResponseEntity<?> elem = unit.generateAndPublish("eiffel3", "eiffelactivityfinished", null, "", "", "",false,
null, null, true, 1, false, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST);

Expand Down Expand Up @@ -176,7 +176,7 @@ public void testErLookupFailedWithOptions() throws Exception {
when(restTemplate.postForEntity(Mockito.contains(correctURL), Mockito.<HttpEntity<String>> any(),
Mockito.eq(String.class), Mockito.anyMap())).thenReturn(responseOptionsFailed);

ResponseEntity<?> elem = unit.generateAndPublish("eiffelsemantics", "eiffelactivityfinished", "", "", "", false,
ResponseEntity<?> elem = unit.generateAndPublish("eiffelsemantics", "eiffelactivityfinished", null, "", "", "", false,
false, false, true, 1, false, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY);

Expand All @@ -189,7 +189,7 @@ public void testErLookupFailedWithMultipleFound() throws Exception {
when(restTemplate.postForEntity(Mockito.contains(correctURL), Mockito.<HttpEntity<String>> any(),
Mockito.eq(String.class), Mockito.anyMap())).thenReturn(responseMultipleFound);

ResponseEntity<?> elem = unit.generateAndPublish("eiffelsemantics", "eiffelactivityfinished", "", "", "", false,
ResponseEntity<?> elem = unit.generateAndPublish("eiffelsemantics", "eiffelactivityfinished", null, "", "", "", false,
false, false, true, 1, false, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.EXPECTATION_FAILED);

Expand All @@ -202,7 +202,7 @@ public void testErLookupFailedWithNoneFound() throws Exception {
when(restTemplate.postForEntity(Mockito.contains(correctURL), Mockito.<HttpEntity<String>> any(),
Mockito.eq(String.class), Mockito.anyMap())).thenReturn(responseNoneFound);

ResponseEntity<?> elem = unit.generateAndPublish("eiffelsemantics", "eiffelactivityfinished", "", "", "", false,
ResponseEntity<?> elem = unit.generateAndPublish("eiffelsemantics", "eiffelactivityfinished", null, "", "", "", false,
false, false, true, 1, false, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.NOT_ACCEPTABLE);

Expand Down
21 changes: 11 additions & 10 deletions wiki/markdown/usage/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,17 @@ application or `/publish/generateAndPublish` if run as Tomcat app.
POST

##### Parameters
| Name | Description | Required | Default value |
|------|------------------------------------------|----------|---------------|
| `mp` | Message protocol. | yes |
| `ud` | User domain .| no |
| `tag` | | no |
| `rk` | Routing key .| no |
| `failIfMultipleFound` | If value is set to `truea and multiple event ids are found through any of the provided lookup definitions, then no event will be generated .| no | `false` |
| `failIfNoneFound` | 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 .| no | `false` |
| `lookupInExternalERs` | 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. | no | `false` |
| `lookupLimit` | The number of events returned, through any lookup definition given, is limited to this number. | no |`1` |
| Name | Description | Required | Default value |
|------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------------|
| `mp` | Message protocol. | yes |
| `domainId` | Eiffel domain identifier is passed to underlying `generate` service, see [Configuration of Default Domain Identifier](https://github.com/eiffel-community/eiffel-remrem-generate/blob/master/wiki/markdown/usage/configuration.md#configuration-of-default-domain-identifier) of `generate` service. | no | |
| `ud` | User domain. | no |
| `tag` | | no |
| `rk` | Routing key. | no |
| `failIfMultipleFound` | 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. | no | `false` |
| `failIfNoneFound` | 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. | no | `false` |
| `lookupInExternalERs` | 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. | no | `false` |
| `lookupLimit` | The number of events returned, through any lookup definition given, is limited to this number. | no |`1` |

##### Request
```
Expand Down