Skip to content

Commit

Permalink
Implement endpoint to get event templates given the type and protocol (
Browse files Browse the repository at this point in the history
#87)

implement endpoint to get event templates given the type and protocol
  • Loading branch information
Christoffer-Cortes authored and vasile-baluta committed Jan 17, 2018
1 parent 4af6ed1 commit c28df4a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

## 0.9.3
- Added endpoint to get event templates
- Uplifted remrem-semantics to 0.3.5
- Uplifted remrem-protocol-interface to 0.0.7

## 0.9.2
- Uplifted remrem-semantics version to 0.3.2 to support continuous operation events

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ subprojects {
targetCompatibility = 1.8

//Latest version for generate
version = "0.9.2"
version = "0.9.3"

repositories {
mavenCentral()
Expand All @@ -64,8 +64,8 @@ subprojects {
dependencies {
//Injectable Message Library and its Implementation
compile ('com.github.Ericsson:eiffel-remrem-shared:0.3.4')
compile ('com.github.Ericsson:eiffel-remrem-semantics:0.3.2')
compile ('com.github.Ericsson:eiffel-remrem-protocol-interface:0.0.5')
compile ('com.github.Ericsson:eiffel-remrem-semantics:0.3.5')
compile ('com.github.Ericsson:eiffel-remrem-protocol-interface:0.0.7')

//Authentication
compile("org.springframework.boot:spring-boot-starter-security:$sprintBootVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,37 @@ public void testDuplicateKeyInBody() throws IOException {
.then()
.statusCode(HttpStatus.SC_BAD_REQUEST);
}


@Test
public void testGetEventTypes() throws Exception {
given()
.header("Authorization", credentials)
.when()
.get("/event_types/eiffelsemantics")
.then()
.statusCode(HttpStatus.SC_OK)
.body(Matchers.containsString("EiffelArtifactPublishedEvent"))
.body(Matchers.containsString("EiffelActivityFinishedEvent"))
.body(Matchers.containsString("EiffelActivityStartedEvent"));
}

@Test
public void testGetEventTypeTemplateFileExists() {
given()
.header("Authorization", credentials)
.when()
.get("/template/EiffelArtifactPublishedEvent/eiffelsemantics")
.then()
.statusCode(HttpStatus.SC_OK);
}

@Test
public void testGetEventTypeTemplateNoFileExists() {
given()
.header("Authorization", credentials)
.when()
.get("/template/EiffelNotAnEvent/eiffelsemantics")
.then()
.statusCode(HttpStatus.SC_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -30,6 +31,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -87,7 +89,32 @@ public JsonElement getVersions() {
Map<String, Map<String, String>> versions = new VersionService().getMessagingVersions();
return parser.parse(versions.toString());
}


/**
* this method returns available Eiffel event types as listed in EiffelEventType enum.
*
* @return string collection with event types.
*/
@RequestMapping(value = "/event_types/{mp}", method = RequestMethod.GET)
public ResponseEntity<Collection<String>> getEventTypes(@PathVariable("mp") String mp) {
MsgService msgService = getMessageService(mp);
return new ResponseEntity<Collection<String>>(msgService.getSupportedEventTypes(), HttpStatus.OK);
}

/**
* Returns an eiffel event template matching the type specified in the path.
*
* @return json containing eiffel event template.
*/
@RequestMapping(value = "/template/{type}/{mp}", method = RequestMethod.GET)
public ResponseEntity<JsonElement> getEventTypeTemplate(@PathVariable("type") String type, @PathVariable("mp") String mp) {
MsgService msgService = getMessageService(mp);
JsonElement template = msgService.getEventTemplate(type);
if(template != null)
return new ResponseEntity<JsonElement>(template, HttpStatus.OK);
else
return new ResponseEntity<JsonElement>(template, HttpStatus.NOT_FOUND);
}

private MsgService getMessageService(String messageProtocol) {
for (MsgService service : msgServices) {
Expand Down

0 comments on commit c28df4a

Please sign in to comment.