Commit 854f7013 authored by Ryan Berkheimer's avatar Ryan Berkheimer

implement BaseTransformation so that getconstructor method makes constructor...

implement BaseTransformation so that getconstructor method makes constructor params from map available. Add getconstructor method to IEndpoint and ITransformation
parent 375a4c31
......@@ -26,10 +26,12 @@ public abstract class BaseEndpoint {
public List<String> collectionIds = null;
public List<Map.Entry<String,String>> classifierIds = null;
public List<String> transformationIds = null;
public Map<String,Object> constructorMap = null;
@SuppressWarnings("unchecked")
public BaseEndpoint(Map<String,Object> parameters) {
Map<String,Object> internalParameters = (Map<String,Object>)parameters.get("__internal__");
this.setConstructor(parameters);
this.setFields((List<String>)internalParameters.get("fields"), this.getDefaultFields());
this.setCollectionIds((List<String>)internalParameters.get("collections"));
this.setClassifierIds((List<Map.Entry<String,String>>)internalParameters.get("classifiers"));
......@@ -38,6 +40,10 @@ public abstract class BaseEndpoint {
protected abstract List<IField> getDefaultFields();
public Map<String,Object> getConstructor() {
return this.constructorMap;
}
public IPacket createPacket() {
return new DefaultPacket();
}
......@@ -62,6 +68,10 @@ public abstract class BaseEndpoint {
return this.transformationIds;
}
private void setConstructor(Map<String, Object> constructorMap) {
this.constructorMap = constructorMap;
}
private List<IField> getFields() {
return this.fields;
}
......
package gov.noaa.messageapi.interfaces;
import java.util.List;
import java.util.Map;
//import gov.noaa.messageapi.interfaces.IPacket;
//import gov.noaa.messageapi.interfaces.IProtocolRecord;
......@@ -38,6 +39,13 @@ public interface IEndpoint {
*/
public List<IField> getDefaultFields();
/**
* Returns the constructor map attached to the endpoint. The constructor map
* should be used to retrieve constructor parameters. Note that thread safety
* cannot be guaranteed if these parameters are used as read only.
*/
public Map<String,Object> getConstructor();
/**
* Creates a new packet for returning from the endpoint. As all
* processing for endpoints must return a packet, all endpoints
......
......@@ -8,6 +8,21 @@ import java.util.List;
*/
public interface ITransformation {
/**
* The process method takes in a map of string and record mappings and is
* the main runtime method for the transformation. These mapping
* definitions are contained in the parameter spec. Note that transformations
* are immutable assuming that a getCopy method is provided to any
* custom user types, and this means that individual records may be manipulated
* as desired and returned as needed in the transformation.
*/
public List<IRecord> process(Map<String,List<IRecord>> transformationMap);
/**
* Returns the constructor map attached to the transformation. The constructor map
* can be used to retrieve constructor parameters. Note that thread safety
* cannot be guaranteed if these parameters are used for anything other than read only.
*/
public Map<String, Object> getConstructor();
}
package gov.noaa.messageapi.transformations;
import java.util.Map;
/**
* The abstract base class for user transformations. This class provides extending user
* endpoints the convenience of parsing and provides all possible generic default methods.
* @author Ryan Berkheimer
*/
public abstract class BaseTransformation {
public Map<String,Object> constructorMap = null;
public BaseTransformation(Map<String,Object> parameters) {
this.setConstructor(parameters);
}
public Map<String,Object> getConstructor() {
return this.constructorMap;
}
private void setConstructor(Map<String, Object> constructorMap) {
this.constructorMap = constructorMap;
}
}
\ No newline at end of file
......@@ -6,6 +6,8 @@ import java.util.List;
import gov.noaa.messageapi.interfaces.ITransformation;
import gov.noaa.messageapi.interfaces.IRecord;
import gov.noaa.messageapi.transformations.BaseTransformation;
/**
* <h1>NativeTransformation</h1> This is a wrapper class for transformations that call into
* native code held as binary libs through the <b>JNI (Java Native
......@@ -27,13 +29,14 @@ import gov.noaa.messageapi.interfaces.IRecord;
*
* @author Ryan Berkheimer
*/
public class NativeTransformation implements ITransformation {
public class NativeTransformation extends BaseTransformation implements ITransformation {
private native List<IRecord> process(long nativeInstance);
private synchronized native long create(Map<String,List<IRecord>> recordMap);
private synchronized native void release(long instanceId);
public NativeTransformation(Map<String,Object> params) {
super(params);
this.loadNativeLib((String)params.get("native-library"));
}
......
......@@ -11,6 +11,7 @@ import gov.noaa.messageapi.interfaces.ITransformation;
import gov.noaa.messageapi.fields.DefaultField;
import gov.noaa.messageapi.records.schema.SchemaRecord;
import gov.noaa.messageapi.transformations.BaseTransformation;
/**
......@@ -59,12 +60,13 @@ import gov.noaa.messageapi.records.schema.SchemaRecord;
*<p>
* @author Ryan Berkheimer
*/
public class StringFieldJoin implements ITransformation {
public class StringFieldJoin extends BaseTransformation implements ITransformation {
private IField joinField = null;
private IField collectionField = null;
public StringFieldJoin(Map<String,Object> params) {
super(params);
this.setJoinField((String) params.get("join-field"));
this.setCollectionField((String) params.get("collection-field"));
}
......
......@@ -6,13 +6,17 @@ import java.util.List;
import gov.noaa.messageapi.interfaces.IRecord;
import gov.noaa.messageapi.interfaces.ITransformation;
import gov.noaa.messageapi.transformations.BaseTransformation;
/**
* @author Ryan Berkheimer
*/
public class ReduceTransformation implements ITransformation {
public class ReduceTransformation extends BaseTransformation implements ITransformation {
public ReduceTransformation(Map<String,Object> params) {}
public ReduceTransformation(Map<String,Object> params) {
super(params);
}
public List<IRecord> process(Map<String,List<IRecord>> transformationMap) {
return transformationMap.get("reduce-list");
......
......@@ -10,6 +10,8 @@ import gov.noaa.messageapi.interfaces.ITransformation;
import gov.noaa.messageapi.utils.general.ListUtils;
import gov.noaa.messageapi.utils.general.PathUtils;
import gov.noaa.messageapi.transformations.BaseTransformation;
/**
* <h1>FixRelativePathsTransformation</h1>
......@@ -25,13 +27,14 @@ import gov.noaa.messageapi.utils.general.PathUtils;
*
* @author Ryan Berkheimer
*/
public class FixRelativePathsTransformation implements ITransformation {
public class FixRelativePathsTransformation extends BaseTransformation implements ITransformation {
private List<String> relativePathFields = null;
private String transformKey = null;
@SuppressWarnings("unchecked")
public FixRelativePathsTransformation(Map<String, Object> params) {
super(params);
this.setRelativePathFields((List<String>) params.get("fields"));
this.setTransformKey((String) params.get("transform-key"));
}
......
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