Commit 7642048a authored by Ryan Berkheimer's avatar Ryan Berkheimer
Browse files

FEATURE ADDITION - Added new Standard Session and associated test for creation...

FEATURE ADDITION - Added new Standard Session and associated test for creation of sessions directly from parameter map
parent 951fc29c
Pipeline #5982 failed with stage
in 0 seconds
......@@ -29,6 +29,10 @@ JAR_INSTALL_SCRIPT=$(PROJECT_ROOT)/scripts/install/java/main/install.sh
DOCS_SRC_DIR=$(PROJECT_ROOT)/build/docs/groovydoc
API_DOCS_DIR=$(PROJECT_ROOT)/dist/docs/api
TEMPLATE_SRC_DIR=$(PROJECT_ROOT)/resources/main/templates
SESSION_TEMPLATE_SRC_DIR=$(TEMPLATE_SRC_DIR)/sessions
METADATA_TEMPLATE_SRC_DIR=$(TEMPLATE_SRC_DIR)/metadata
#C/C++ Related Paths
C_MAIN_BUILD_DIR=$(PROJECT_ROOT)/scripts/build/c/main
C_TEST_BUILD_DIR=$(PROJECT_ROOT)/scripts/build/c/test
......@@ -74,8 +78,10 @@ dist-java:
@echo "Creating distributable Java artifacts."
@cp $(JAR_SRC_DIR)/$(SRC_JAR) $(JAR_SRC_DIR)/$(TARGET_JAR)
@cp $(JAR_INSTALL_SCRIPT) $(JAR_SRC_DIR)
@cp $(SESSION_TEMPLATE_SRC_DIR)/*.json $(JAR_SRC_DIR)
@cp $(METADATA_TEMPLATE_SRC_DIR)/*.json $(JAR_SRC_DIR)
@mkdir -p $(JAVA_ARTIFACT_DIR)
@-cd $(JAR_SRC_DIR) && tar -cf $(LIBRARY_NAME).tar $(TARGET_JAR) install.sh
@-cd $(JAR_SRC_DIR) && tar -cf $(LIBRARY_NAME).tar $(TARGET_JAR) install.sh *.json
@-cd $(JAR_SRC_DIR) && mv $(LIBRARY_NAME).tar $(JAVA_ARTIFACT_DIR)
copy-docs:
......
......@@ -64,6 +64,7 @@ test {
testLogging {
showStandardStreams = true
}
environment "MESSAGEAPI_SESSION_TEMPLATE_DIR", "/workspaces/messageapi/resources/test/standard_session"
}
......
{
"metadata": {
"id": "DefaultContainer",
"version": "1.0.0",
"classifiers": {"class": "container",
"author": "Ryan Berkheimer",
"components": ["collection", "classifier", "transformation"]},
"description": "DefaultContainer ships with MessageAPI core. Contains collections, classifiers, and transformations that 'bin' fields and conditions in a schema. Fields can be repeatedly binned, classifiers apply to collections, and transformations consume collections, classifiers, UUID bins, or other transformations immutably."
}
}
\ No newline at end of file
{
"metadata": {
"id": "DefaultProtocol",
"version": "1.0.0",
"classifiers": {"class": "protocol",
"author": "Ryan Berkheimer",
"components": ["endpoint", "connection"]},
"description": "DefaultProtocol ships with MessageAPI core. Contains endpoints and associated connections. Connections are assigned arbitrary container lists of transformations, collections, or classifiers."
}
}
{
"metadata": {
"id": "DefaultSchema",
"version": "1.0.0",
"classifiers": {"class": "schema",
"author": "Ryan Berkheimer",
"components":["field", "condition"]},
"description": "DefaultSchema ships with MessageAPI core. Contains fields and conditions per-record and per-request. Initial values set on conditions are nullified for individual records but not requests."
}
}
\ No newline at end of file
......@@ -4,27 +4,24 @@
"schema": {
"plugin": "gov.noaa.messageapi.schemas.DefaultSchema",
"constructor": {
"metadata": "{_standard_}",
"fields": "{_standard_}"
"metadata": "{_schema_metadata_}",
"fields": "{_standard_}",
"conditions": "{_standard_}"
}
},
"container": {
"plugin": "gov.noaa.messageapi.containers.DefaultContainer",
"constructor": {
"metadata": "{_standard_}",
"collections": "{_standard_}"
"metadata": "{_container_metadata_}",
"collections": "{_standard_}",
"transformations": "{_standard_}"
}
},
"protocol": {
"plugin": "gov.noaa.messageapi.protocols.DefaultProtocol",
"constructor": {
"metadata": "{_standard_}",
"endpoints": [
{
"plugin": "gov.noaa.messageapi.endpoints.NativeEndpoint",
"connections": "{_standard_}"
}
]
"metadata": "{_protocol_metadata_}",
"endpoints": "{_standard_}"
}
}
}
......
{
"metadata": {
"id": "DefaultContainer",
"version": "1.0.0",
"classifiers": {"class": "container",
"author": "Ryan Berkheimer",
"components": ["collection", "classifier", "transformation"]},
"description": "DefaultContainer ships with MessageAPI core. Contains collections, classifiers, and transformations that 'bin' fields and conditions in a schema. Fields can be repeatedly binned, classifiers apply to collections, and transformations consume collections, classifiers, UUID bins, or other transformations immutably."
}
}
\ No newline at end of file
{
"fields": [{"id": "file-path",
"type": "string",
"required": true}],
"conditions": [{"id": "is-relative-path",
"type": "comparison",
"operator": "gov.noaa.messageapi.operators.StringConditionOperator",
"constructor": {"comparison": "contains"},
"field": "file-path",
"value": "{}"}],
"collections": [{"id": "coll-1",
"classifiers": {},
"fields": ["file-path"],
"conditions": ["is-relative-path"]}],
"transformations": [{"id": "trans-1",
"operator": "gov.noaa.messageapi.test.transformations.FixRelativePathsTransformation",
"constructor": {"transform-key": "file-collection",
"fields": ["file-path"]},
"records": {"file-collection": {"COLLECTION": "coll-1"}}}],
"endpoints": [{"plugin": "gov.noaa.messageapi.test.endpoints.InMemoryFileReader",
"connections": [{"id": "conn-1",
"transformations": ["trans-1"],
"constructor": {"file-fields": "file-path"},
"fields": ["value","number","length"]}]}]
}
\ No newline at end of file
{
"metadata": {
"id": "DefaultProtocol",
"version": "1.0.0",
"classifiers": {"class": "protocol",
"author": "Ryan Berkheimer",
"components": ["endpoint", "connection"]},
"description": "DefaultProtocol ships with MessageAPI core. Contains endpoints and associated connections. Connections are assigned arbitrary container lists of transformations, collections, or classifiers."
}
}
{
"metadata": {
"id": "DefaultSchema",
"version": "1.0.0",
"classifiers": {"class": "schema",
"author": "Ryan Berkheimer",
"components":["field", "condition"]},
"description": "DefaultSchema ships with MessageAPI core. Contains fields and conditions per-record and per-request. Initial values set on conditions are nullified for individual records but not requests."
}
}
\ No newline at end of file
{
"plugin": "gov.noaa.messageapi.sessions.DefaultSession",
"constructor": {
"schema": {
"plugin": "gov.noaa.messageapi.schemas.DefaultSchema",
"constructor": {
"metadata": "{_schema_metadata_}",
"fields": "{_standard_}",
"conditions": "{_standard_}"
}
},
"container": {
"plugin": "gov.noaa.messageapi.containers.DefaultContainer",
"constructor": {
"metadata": "{_container_metadata_}",
"collections": "{_standard_}",
"transformations": "{_standard_}"
}
},
"protocol": {
"plugin": "gov.noaa.messageapi.protocols.DefaultProtocol",
"constructor": {
"metadata": "{_protocol_metadata_}",
"endpoints": "{_standard_}"
}
}
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ update_headers_var () {
echo "export MESSAGEAPI_HEADERS=${HEADERS_INSTALL_DIR} #messageapi_c_cpp_set_headers" >> "${BASHRC}"
echo "Added a 'MESSAGEAPI_HEADERS' environment variable to ${BASHRC} for convenient inclusion of library headers."
echo "When creating a C/C++ session, endpoint, condition, or transformation, you can use the MESSAGEAPI_HEADERS as the include location."
echo "Build file templates for each of these is provided in the templates directory, accessible via the MESSAGEAPI_TEMPLATES environment variable."
echo "Build file templates for each of these is provided in the templates directory, accessible via the MESSAGEAPI_C_TEMPLATES environment variable."
echo ""
}
......@@ -71,17 +71,17 @@ update_src_var () {
echo "export MESSAGEAPI_SRC=${SRC_INSTALL_DIR} #messageapi_c_cpp_set_src" >> "${BASHRC}"
echo "Added a 'MESSAGEAPI_SRC' environment variable to ${BASHRC} for convenient inclusion of the C/C++ source files."
echo "When creating a C/C++ session, endpoint, condition, or transformation, you can use the MESSAGEAPI_SRC for base source paths during build."
echo "Build file templates for each of these is provided in the templates directory, accessible via the MESSAGEAPI_TEMPLATES environment variable."
echo "Build file templates for each of these is provided in the templates directory, accessible via the MESSAGEAPI_C_TEMPLATES environment variable."
echo ""
}
update_template_var () {
echo ""
echo "Updating the MESSAGEAPI_TEMPLATES environment variable in $(whoami)'s ~/.bashrc."
echo "Updating the MESSAGEAPI_C_TEMPLATES environment variable in $(whoami)'s ~/.bashrc."
sed '/#messageapi_c_cpp_build_templates/d' "${BASHRC}" > "${BASHRC_TMP}"
mv "${BASHRC_TMP}" "${BASHRC}"
echo "export MESSAGEAPI_TEMPLATES=${TEMPLATE_INSTALL_DIR} #messageapi_c_cpp_build_templates" >> "${BASHRC}"
echo "Added a 'MESSAGEAPI_TEMPLATES' environment variable to ${BASHRC} for convenient access to the C/C++ build templates."
echo "export MESSAGEAPI_C_TEMPLATES=${TEMPLATE_INSTALL_DIR} #messageapi_c_cpp_build_templates" >> "${BASHRC}"
echo "Added a 'MESSAGEAPI_C_TEMPLATES' environment variable to ${BASHRC} for convenient access to the C/C++ build templates."
echo "These templates are set up to use the installation paths for messageapi source code, libraries, and headers."
echo "To use them, copy the template to your desired build location, fill out the fields with USER FIELD comments, and run 'make'."
echo ""
......
......@@ -9,6 +9,15 @@ update_classpath_var () {
echo ""
}
update_template_var () {
echo ""
echo "Updating the MESSAGEAPI_SESSION_TEMPLATE_DIR environment variable in $(whoami)'s ~/.bashrc."
sed '/#messageapi_core_set_template_dir/d' "${BASHRC}" > "${BASHRC_TMP}"
mv "${BASHRC_TMP}" "${BASHRC}"
echo "export MESSAGEAPI_SESSION_TEMPLATE_DIR=${SESSION_TEMPLATE_INSTALL_DIR} #messageapi_core_set_template_dir" >> "${BASHRC}"
echo ""
}
install_core_jar () {
echo ""
echo "Installing messageapi core jar to ${CORE_INSTALL_DIR}."
......@@ -19,8 +28,19 @@ install_core_jar () {
echo ""
}
install_standard_session_template_resources () {
echo ""
echo "Installing messageapi standard session template resources to ${SESSION_TEMPLATE_INSTALL_DIR}."
rm -rf "${SESSION_TEMPLATE_INSTALL_DIR}"
mkdir -p "${SESSION_TEMPLATE_INSTALL_DIR}"
cp *.json "${SESSION_TEMPLATE_INSTALL_DIR}"
echo "Finished installing messageapi standard session template resources to ${SESSION_TEMPLATE_INSTALL_DIR}."
echo ""
}
refresh_shell () {
unset CLASSPATH
unset MESSAGEAPI_SESSION_TEMPLATE_DIR
}
......@@ -28,6 +48,7 @@ BASHRC=${HOME}/.bashrc
BASHRC_TMP=${HOME}/.bashrc_tmp
CORE_INSTALL_DIR=${HOME}/.messageapi/java/jars
SESSION_TEMPLATE_INSTALL_DIR=${HOME}/.messageapi/java/templates
MAJOR_VERSION=1
MINOR_VERSION=0
......@@ -38,7 +59,9 @@ JAR_NAME=messageapi-core-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.jar
echo ""
echo "Installing the MessageAPI-Core Jar for the current user $(whoami)"
install_core_jar
install_standard_session_template_resources
update_classpath_var
update_template_var
refresh_shell
echo "Finished installing the MessageAPI-Core Jar for user $(whoami)."
echo ""
\ No newline at end of file
......@@ -10,6 +10,8 @@
import gov.noaa.messageapi.factories.SessionFactory;
import gov.noaa.messageapi.sessions.DefaultSession;
import gov.noaa.messageapi.sessions.StandardSession;
class SessionUnitTests extends spock.lang.Specification {
def "Test session creation from a json spec using factory."() {
......@@ -38,4 +40,14 @@ class SessionUnitTests extends spock.lang.Specification {
then: "An ISession instance is created without error."
session in gov.noaa.messageapi.interfaces.ISession
}
def "Test a standard session creation." () {
given: "we pass a session parameter spec path."
def sessionSpec = this.getClass().getResource('standard_session/parameters.json').getPath()
when: "We create a standard session"
ISession session = new StandardSession(sessionSpec)
then: "An ISession instance is created without error."
session in gov.noaa.messageapi.interfaces.ISession
}
}
......@@ -22,6 +22,10 @@ public class SessionPluginParser extends BasePluginParser implements IPluginPars
super(spec);
}
public SessionPluginParser(final Object parserMap) throws Exception {
super(parserMap);
}
@SuppressWarnings("unchecked")
public ISession build() throws Exception {
try {
......
......@@ -3,6 +3,9 @@ package gov.noaa.messageapi.sessions;
import gov.noaa.messageapi.interfaces.ISession;
import gov.noaa.messageapi.interfaces.ISchema;
import gov.noaa.messageapi.interfaces.IProtocol;
import java.util.Map;
import gov.noaa.messageapi.interfaces.IContainer;
import gov.noaa.messageapi.parsers.plugins.SessionPluginParser;
......@@ -24,6 +27,19 @@ public class BaseSession {
this.initialize(c, p, s);
}
public BaseSession(final ISession session) {
this.setContainer(session.getContainer());
this.setProtocol(session.getProtocol());
this.setSchema(session.getSchema());
}
public BaseSession(final Map<String,Object> sessionMap) throws Exception {
final ISession session = new SessionPluginParser(sessionMap).build();
this.setContainer(session.getContainer());
this.setProtocol(session.getProtocol());
this.setSchema(session.getSchema());
}
public BaseSession(final String spec) throws Exception {
final ISession session = new SessionPluginParser(spec).build();
this.setContainer(session.getContainer());
......
package gov.noaa.messageapi.sessions;
import java.util.Map;
import gov.noaa.messageapi.interfaces.ISession;
import gov.noaa.messageapi.interfaces.ISchema;
import gov.noaa.messageapi.interfaces.IProtocol;
......@@ -24,10 +26,22 @@ public class DefaultSession extends BaseSession implements ISession {
* @param p An IProtocol object
* @param s An ISchema object
*/
public DefaultSession(final IContainer c, final IProtocol p, final ISchema s) {
public DefaultSession(final IContainer c, final IProtocol p, final ISchema s) throws Exception {
super(c, p, s);
}
/**
* Constructs a new publish session from existing session.
* @param session A preexisting ISession object
*/
public DefaultSession(final ISession session) throws Exception {
super(session);
}
public DefaultSession(final Map<String,Object> sessionMap) throws Exception {
super(sessionMap);
}
/**
* Constructs a new publish session directly from a text map. The text map
* should contain all the properties needed for Session Construction.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment