repo_name
stringlengths 7
104
| file_path
stringlengths 13
198
| context
stringlengths 67
7.15k
| import_statement
stringlengths 16
4.43k
| code
stringlengths 40
6.98k
| prompt
stringlengths 227
8.27k
| next_line
stringlengths 8
795
|
---|---|---|---|---|---|---|
ferstl/pedantic-pom-enforcers | src/main/java/com/github/ferstl/maven/pomenforcers/PedanticDependencyConfigurationEnforcer.java | // Path: src/main/java/com/github/ferstl/maven/pomenforcers/model/DependencyModel.java
// @XmlRootElement(name = "dependency")
// public class DependencyModel extends ArtifactModel {
//
// private static final Joiner TO_STRING_JOINER = Joiner.on(":").skipNulls();
//
// @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
// @XmlJavaTypeAdapter(value = DependencyScopeAdapter.class)
// private DependencyScope scope;
//
// @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
// private String classifier;
//
// @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
// private String type;
//
// @XmlElementWrapper(namespace = "http://maven.apache.org/POM/4.0.0")
// @XmlElement(name = "exclusion", namespace = "http://maven.apache.org/POM/4.0.0")
// private List<ArtifactModel> exclusions;
//
// // Constructor used by JAXB
// DependencyModel() {
// }
//
// public DependencyModel(
// String groupId, String artifactId, String version, String scope, String classifier, String type) {
//
// super(groupId, artifactId, version);
// this.scope = scope != null ? DependencyScope.getByScopeName(scope) : null;
// this.classifier = classifier;
// this.type = type;
// }
//
// public DependencyScope getScope() {
// return this.scope != null ? this.scope : DependencyScope.COMPILE;
// }
//
// public String getClassifier() {
// return this.classifier;
// }
//
// public String getType() {
// return this.type != null ? this.type : "jar";
// }
//
// public List<ArtifactModel> getExclusions() {
// return this.exclusions != null ? this.exclusions : Collections.emptyList();
// }
//
// @Override
// public String toString() {
// return TO_STRING_JOINER.join(
// super.toString(),
// getType(),
// getScope().getScopeName(),
// this.classifier);
// }
//
// // Note that this equals() implementation breaks the symmetry contract!
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (!(obj instanceof DependencyModel)) {
// return false;
// }
//
// DependencyModel other = (DependencyModel) obj;
// return super.equals(other)
// && equal(this.classifier, other.classifier)
// && equal(this.type, other.type)
// && equal(this.scope, other.scope)
// && equal(this.exclusions, other.exclusions);
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(super.hashCode(), this.classifier, this.type, this.scope);
// }
//
// }
//
// Path: src/main/java/com/github/ferstl/maven/pomenforcers/ErrorReport.java
// public static <T> String toList(Collection<T> collection) {
// return toList(collection, Function.identity());
// }
| import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import com.github.ferstl.maven.pomenforcers.model.DependencyModel;
import static com.github.ferstl.maven.pomenforcers.ErrorReport.toList; | */
public void setManageExclusions(boolean manageExclusions) {
this.manageExclusions = manageExclusions;
}
@Override
protected PedanticEnforcerRule getDescription() {
return PedanticEnforcerRule.DEPENDENCY_CONFIGURATION;
}
@Override
protected void accept(PedanticEnforcerVisitor visitor) {
visitor.visit(this);
}
@Override
protected void doEnforce(ErrorReport report) {
if (this.manageVersions) {
enforceManagedVersions(report);
}
if (this.manageExclusions) {
enforceManagedExclusion(report);
}
}
private void enforceManagedVersions(ErrorReport report) {
Collection<DependencyModel> versionedDependencies = searchForDependencies(DependencyPredicate.WITH_VERSION);
// Filter all project versions if allowed
if (this.allowUnmangedProjectVersions) { | // Path: src/main/java/com/github/ferstl/maven/pomenforcers/model/DependencyModel.java
// @XmlRootElement(name = "dependency")
// public class DependencyModel extends ArtifactModel {
//
// private static final Joiner TO_STRING_JOINER = Joiner.on(":").skipNulls();
//
// @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
// @XmlJavaTypeAdapter(value = DependencyScopeAdapter.class)
// private DependencyScope scope;
//
// @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
// private String classifier;
//
// @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
// private String type;
//
// @XmlElementWrapper(namespace = "http://maven.apache.org/POM/4.0.0")
// @XmlElement(name = "exclusion", namespace = "http://maven.apache.org/POM/4.0.0")
// private List<ArtifactModel> exclusions;
//
// // Constructor used by JAXB
// DependencyModel() {
// }
//
// public DependencyModel(
// String groupId, String artifactId, String version, String scope, String classifier, String type) {
//
// super(groupId, artifactId, version);
// this.scope = scope != null ? DependencyScope.getByScopeName(scope) : null;
// this.classifier = classifier;
// this.type = type;
// }
//
// public DependencyScope getScope() {
// return this.scope != null ? this.scope : DependencyScope.COMPILE;
// }
//
// public String getClassifier() {
// return this.classifier;
// }
//
// public String getType() {
// return this.type != null ? this.type : "jar";
// }
//
// public List<ArtifactModel> getExclusions() {
// return this.exclusions != null ? this.exclusions : Collections.emptyList();
// }
//
// @Override
// public String toString() {
// return TO_STRING_JOINER.join(
// super.toString(),
// getType(),
// getScope().getScopeName(),
// this.classifier);
// }
//
// // Note that this equals() implementation breaks the symmetry contract!
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (!(obj instanceof DependencyModel)) {
// return false;
// }
//
// DependencyModel other = (DependencyModel) obj;
// return super.equals(other)
// && equal(this.classifier, other.classifier)
// && equal(this.type, other.type)
// && equal(this.scope, other.scope)
// && equal(this.exclusions, other.exclusions);
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(super.hashCode(), this.classifier, this.type, this.scope);
// }
//
// }
//
// Path: src/main/java/com/github/ferstl/maven/pomenforcers/ErrorReport.java
// public static <T> String toList(Collection<T> collection) {
// return toList(collection, Function.identity());
// }
// Path: src/main/java/com/github/ferstl/maven/pomenforcers/PedanticDependencyConfigurationEnforcer.java
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import com.github.ferstl.maven.pomenforcers.model.DependencyModel;
import static com.github.ferstl.maven.pomenforcers.ErrorReport.toList;
*/
public void setManageExclusions(boolean manageExclusions) {
this.manageExclusions = manageExclusions;
}
@Override
protected PedanticEnforcerRule getDescription() {
return PedanticEnforcerRule.DEPENDENCY_CONFIGURATION;
}
@Override
protected void accept(PedanticEnforcerVisitor visitor) {
visitor.visit(this);
}
@Override
protected void doEnforce(ErrorReport report) {
if (this.manageVersions) {
enforceManagedVersions(report);
}
if (this.manageExclusions) {
enforceManagedExclusion(report);
}
}
private void enforceManagedVersions(ErrorReport report) {
Collection<DependencyModel> versionedDependencies = searchForDependencies(DependencyPredicate.WITH_VERSION);
// Filter all project versions if allowed
if (this.allowUnmangedProjectVersions) { | versionedDependencies = versionedDependencies.stream().filter(DependencyPredicate.WITH_PROJECT_VERSION).collect(Collectors.toList()); |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
| import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package org.apache.flink.batch.neo4j;
public class Neo4JInputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JInputFormatTest.class);
@Test
public void testInputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatTest.java
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.apache.flink.batch.neo4j;
public class Neo4JInputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JInputFormatTest.class);
@Test
public void testInputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
| SerializationMapper<String> serializationMapper = new StringSerializationMapper(); |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
| import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package org.apache.flink.batch.neo4j;
public class Neo4JInputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JInputFormatTest.class);
@Test
public void testInputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatTest.java
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.apache.flink.batch.neo4j;
public class Neo4JInputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JInputFormatTest.class);
@Test
public void testInputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
| SerializationMapper<String> serializationMapper = new StringSerializationMapper(); |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
| import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package org.apache.flink.batch.neo4j;
public class Neo4JInputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JInputFormatTest.class);
@Test
public void testInputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
SerializationMapper<String> serializationMapper = new StringSerializationMapper();
String statement = "MATCH (i:Item) return i.description";
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatTest.java
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.apache.flink.batch.neo4j;
public class Neo4JInputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JInputFormatTest.class);
@Test
public void testInputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
SerializationMapper<String> serializationMapper = new StringSerializationMapper();
String statement = "MATCH (i:Item) return i.description";
| Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> mappingStrategy = new Neo4JSourceMappingStrategyString( |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
| import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package org.apache.flink.batch.neo4j;
public class Neo4JInputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JInputFormatTest.class);
@Test
public void testInputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
SerializationMapper<String> serializationMapper = new StringSerializationMapper();
String statement = "MATCH (i:Item) return i.description";
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatTest.java
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.apache.flink.batch.neo4j;
public class Neo4JInputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JInputFormatTest.class);
@Test
public void testInputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
SerializationMapper<String> serializationMapper = new StringSerializationMapper();
String statement = "MATCH (i:Item) return i.description";
| Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> mappingStrategy = new Neo4JSourceMappingStrategyString( |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategyTest.java | // Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SerializationMapperTest.java
// class TupleSerializationMapper implements SerializationMapper<Tuple2<String, Integer>> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public Tuple2<String, Integer> serialize(Map<String, Object> record) {
// Tuple2<String, Integer> tuple = new Tuple2<String, Integer>();
//
// tuple.f0 = record.get("i.description").toString();
// tuple.f1 = Integer.valueOf(record.get("i.id").toString());
//
// return tuple;
// }
// }
| import java.util.HashMap;
import java.util.Map;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapperTest.TupleSerializationMapper;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.neo4j.driver.v1.Record; | package org.apache.flink.mapping.neo4j;
public class Neo4JSerializationMappingStrategyTest {
final SerializationMapperTest.TupleSerializationMapper serializationMapper = new SerializationMapperTest().new TupleSerializationMapper();
class Neo4JSourceMappingStrategyTuple extends | // Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SerializationMapperTest.java
// class TupleSerializationMapper implements SerializationMapper<Tuple2<String, Integer>> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public Tuple2<String, Integer> serialize(Map<String, Object> record) {
// Tuple2<String, Integer> tuple = new Tuple2<String, Integer>();
//
// tuple.f0 = record.get("i.description").toString();
// tuple.f1 = Integer.valueOf(record.get("i.id").toString());
//
// return tuple;
// }
// }
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategyTest.java
import java.util.HashMap;
import java.util.Map;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapperTest.TupleSerializationMapper;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.neo4j.driver.v1.Record;
package org.apache.flink.mapping.neo4j;
public class Neo4JSerializationMappingStrategyTest {
final SerializationMapperTest.TupleSerializationMapper serializationMapper = new SerializationMapperTest().new TupleSerializationMapper();
class Neo4JSourceMappingStrategyTuple extends | Neo4JSerializationMappingStrategy<Tuple2<String, Integer>, SerializationMapperTest.TupleSerializationMapper> { |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
| import java.io.IOException;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy; | /**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatMock<T> extends Neo4JOutputFormat<T> {
private static final long serialVersionUID = 1L;
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatMock.java
import java.io.IOException;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
/**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatMock<T> extends Neo4JOutputFormat<T> {
private static final long serialVersionUID = 1L;
| public Neo4JOutputFormatMock(Neo4JDeserializationMappingStrategy<T, DeserializationMapper<T>> mappingStrategy, |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
| import java.io.IOException;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy; | /**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatMock<T> extends Neo4JOutputFormat<T> {
private static final long serialVersionUID = 1L;
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatMock.java
import java.io.IOException;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
/**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatMock<T> extends Neo4JOutputFormat<T> {
private static final long serialVersionUID = 1L;
| public Neo4JOutputFormatMock(Neo4JDeserializationMappingStrategy<T, DeserializationMapper<T>> mappingStrategy, |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
| import java.io.IOException;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy; | /**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatMock<T> extends Neo4JOutputFormat<T> {
private static final long serialVersionUID = 1L;
public Neo4JOutputFormatMock(Neo4JDeserializationMappingStrategy<T, DeserializationMapper<T>> mappingStrategy,
Map<String, String> config) {
super(mappingStrategy, config);
}
@Override
public void open(int taskNumber, int numTasks) throws IOException {
super.open(taskNumber, numTasks);
// We use a static driver wrapper with an embedded Neo4J instance | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatMock.java
import java.io.IOException;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
/**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatMock<T> extends Neo4JOutputFormat<T> {
private static final long serialVersionUID = 1L;
public Neo4JOutputFormatMock(Neo4JDeserializationMappingStrategy<T, DeserializationMapper<T>> mappingStrategy,
Map<String, String> config) {
super(mappingStrategy, config);
}
@Override
public void open(int taskNumber, int numTasks) throws IOException {
super.open(taskNumber, numTasks);
// We use a static driver wrapper with an embedded Neo4J instance | driver = Neo4JBaseEmbeddedConfig.driverWrapper; |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
| import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy; | package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkMock<T> extends Neo4JSink<T> {
private static final long serialVersionUID = 1L;
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkMock.java
import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkMock<T> extends Neo4JSink<T> {
private static final long serialVersionUID = 1L;
| public Neo4JSinkMock(Neo4JDeserializationMappingStrategy<T, DeserializationMapper<T>> mappingStrategy, |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
| import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy; | package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkMock<T> extends Neo4JSink<T> {
private static final long serialVersionUID = 1L;
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkMock.java
import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkMock<T> extends Neo4JSink<T> {
private static final long serialVersionUID = 1L;
| public Neo4JSinkMock(Neo4JDeserializationMappingStrategy<T, DeserializationMapper<T>> mappingStrategy, |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
| import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy; | package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkMock<T> extends Neo4JSink<T> {
private static final long serialVersionUID = 1L;
public Neo4JSinkMock(Neo4JDeserializationMappingStrategy<T, DeserializationMapper<T>> mappingStrategy,
Map<String, String> config) {
super(mappingStrategy, config);
}
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
// We use a static driver wrapper with an embedded Neo4J instance | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkMock.java
import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkMock<T> extends Neo4JSink<T> {
private static final long serialVersionUID = 1L;
public Neo4JSinkMock(Neo4JDeserializationMappingStrategy<T, DeserializationMapper<T>> mappingStrategy,
Map<String, String> config) {
super(mappingStrategy, config);
}
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
// We use a static driver wrapper with an embedded Neo4J instance | driver = Neo4JBaseEmbeddedConfig.driverWrapper; |
albertodelazzari/flink-neo4j | src/main/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSource.java | // Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
| import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Statement;
import org.neo4j.driver.v1.StatementResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | /**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSource<T> extends RichSourceFunction<T> {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JSource.class);
protected transient Neo4JDriverWrapper driver;
/**
* The mapping strategy that we use to map data from Flink to Neo4J
*
* @see Neo4JSerializationMappingStrategy
*/ | // Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
// Path: src/main/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSource.java
import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Statement;
import org.neo4j.driver.v1.StatementResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSource<T> extends RichSourceFunction<T> {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JSource.class);
protected transient Neo4JDriverWrapper driver;
/**
* The mapping strategy that we use to map data from Flink to Neo4J
*
* @see Neo4JSerializationMappingStrategy
*/ | private Neo4JSerializationMappingStrategy<T, SerializationMapper<T>> mappingStrategy; |
albertodelazzari/flink-neo4j | src/main/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSource.java | // Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
| import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Statement;
import org.neo4j.driver.v1.StatementResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | /**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSource<T> extends RichSourceFunction<T> {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JSource.class);
protected transient Neo4JDriverWrapper driver;
/**
* The mapping strategy that we use to map data from Flink to Neo4J
*
* @see Neo4JSerializationMappingStrategy
*/ | // Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
// Path: src/main/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSource.java
import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Statement;
import org.neo4j.driver.v1.StatementResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSource<T> extends RichSourceFunction<T> {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JSource.class);
protected transient Neo4JDriverWrapper driver;
/**
* The mapping strategy that we use to map data from Flink to Neo4J
*
* @see Neo4JSerializationMappingStrategy
*/ | private Neo4JSerializationMappingStrategy<T, SerializationMapper<T>> mappingStrategy; |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java | // Path: src/main/java/org/apache/flink/streaming/connectors/neo4j/Neo4JDriverWrapper.java
// public class Neo4JDriverWrapper implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JDriverWrapper.class);
//
// /**
// * The username property key.
// */
// public static final String USERNAME_PARAM = "neo4j.auth.username";
//
// /**
// * The password property key.
// */
// public static final String PASSWORD_PARAM = "neo4j.auth.password";
//
// /**
// * The Neo4J server url property key.
// */
// public static final String URL = "neo4j.url";
//
// /**
// * The session liveness timeout property key.
// */
// public static final String SESSION_LIVENESS_TIMEOUT = "neo4j.session.livetimeout";
//
// /**
// * The default session liveness timeout as it's defined by the ConfigBuilder class.
// * @see org.neo4j.driver.v1.Config.ConfigBuilder
// */
// private static final String DEFAULT_SESSION_LIVENESS_TIMEOUT = "200";
//
// /**
// * The configuration parameters.
// */
// private Map<String, String> parameters;
//
// /**
// * The internal Neo4J Driver.
// *
// * @see org.neo4j.driver.v1.Driver
// */
// protected transient Driver driver;
//
// /**
// * The defaut constructor. Always pass the connection url, username and
// * password
// *
// * @param parameters
// * the connection parameters
// */
// public Neo4JDriverWrapper(final Map<String, String> parameters) {
// // We want to ensure that all the mandatory parameters are defined
// boolean urlDefined = parameters.containsKey(URL);
// Preconditions.checkArgument(urlDefined, "URL connection to Neo4J server must be defined");
//
// boolean usernameDefined = parameters.containsKey(USERNAME_PARAM);
// Preconditions.checkArgument(usernameDefined, "The username must be defined");
//
// boolean passwordDefined = parameters.containsKey(PASSWORD_PARAM);
// Preconditions.checkArgument(passwordDefined, "The password must be defined");
//
// this.parameters = parameters;
// this.initDriver();
// }
//
// /**
// * Init the internal Neo4J driver.
// *
// * @see org.neo4j.driver.v1.Driver
// */
// protected final void initDriver() {
// String url = parameters.get(URL);
// String username = parameters.get(USERNAME_PARAM);
// String password = parameters.get(PASSWORD_PARAM);
// String timeout = parameters.getOrDefault(SESSION_LIVENESS_TIMEOUT, DEFAULT_SESSION_LIVENESS_TIMEOUT);
//
// AuthToken authToken = AuthTokens.basic(username, password);
// LOGGER.debug("Basic authentication token with username {}", username);
//
// Config config = Config.build().withSessionLivenessCheckTimeout(getLongValue(timeout))
// .withEncryptionLevel(EncryptionLevel.NONE).toConfig();
// driver = GraphDatabase.driver(url, authToken, config);
// LOGGER.debug("A driver has been created to {}", url);
// }
//
// /**
// * Get the corresponding long value for the given string.
// *
// * @param longValue
// * a long number as a string
// * @return the long value
// */
// private long getLongValue(final String longValue) {
// return Long.valueOf(longValue);
// }
//
// /**
// * Establish a session.
// *
// * @see org.neo4j.driver.v1.Session
// * @return a Neo4J session
// */
// public final Session session() {
// return driver.session();
// }
//
// /**
// * Close all the resources assigned to the internal Neo4J Driver.
// *
// * @see org.neo4j.driver.v1.Driver
// */
// public final void close() {
// driver.close();
// }
// }
| import java.util.HashMap;
import java.util.Map;
import org.apache.flink.streaming.connectors.neo4j.Neo4JDriverWrapper;
import org.junit.Before;
import org.junit.ClassRule;
import org.neo4j.harness.junit.Neo4jRule; | package org.apache.flink.embedded.neo4j;
/**
*
* @author Alberto De Lazzari
*
*/
public class Neo4JBaseEmbeddedConfig {
public static final String DEFAULT_URL = "bolt://localhost:7687";
public static final String DEFAULT_USERNAME = "neo4j";
public static final String DEFAULT_PASSWORD = "password";
@ClassRule
public static Neo4jRule neo4jRule;
| // Path: src/main/java/org/apache/flink/streaming/connectors/neo4j/Neo4JDriverWrapper.java
// public class Neo4JDriverWrapper implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JDriverWrapper.class);
//
// /**
// * The username property key.
// */
// public static final String USERNAME_PARAM = "neo4j.auth.username";
//
// /**
// * The password property key.
// */
// public static final String PASSWORD_PARAM = "neo4j.auth.password";
//
// /**
// * The Neo4J server url property key.
// */
// public static final String URL = "neo4j.url";
//
// /**
// * The session liveness timeout property key.
// */
// public static final String SESSION_LIVENESS_TIMEOUT = "neo4j.session.livetimeout";
//
// /**
// * The default session liveness timeout as it's defined by the ConfigBuilder class.
// * @see org.neo4j.driver.v1.Config.ConfigBuilder
// */
// private static final String DEFAULT_SESSION_LIVENESS_TIMEOUT = "200";
//
// /**
// * The configuration parameters.
// */
// private Map<String, String> parameters;
//
// /**
// * The internal Neo4J Driver.
// *
// * @see org.neo4j.driver.v1.Driver
// */
// protected transient Driver driver;
//
// /**
// * The defaut constructor. Always pass the connection url, username and
// * password
// *
// * @param parameters
// * the connection parameters
// */
// public Neo4JDriverWrapper(final Map<String, String> parameters) {
// // We want to ensure that all the mandatory parameters are defined
// boolean urlDefined = parameters.containsKey(URL);
// Preconditions.checkArgument(urlDefined, "URL connection to Neo4J server must be defined");
//
// boolean usernameDefined = parameters.containsKey(USERNAME_PARAM);
// Preconditions.checkArgument(usernameDefined, "The username must be defined");
//
// boolean passwordDefined = parameters.containsKey(PASSWORD_PARAM);
// Preconditions.checkArgument(passwordDefined, "The password must be defined");
//
// this.parameters = parameters;
// this.initDriver();
// }
//
// /**
// * Init the internal Neo4J driver.
// *
// * @see org.neo4j.driver.v1.Driver
// */
// protected final void initDriver() {
// String url = parameters.get(URL);
// String username = parameters.get(USERNAME_PARAM);
// String password = parameters.get(PASSWORD_PARAM);
// String timeout = parameters.getOrDefault(SESSION_LIVENESS_TIMEOUT, DEFAULT_SESSION_LIVENESS_TIMEOUT);
//
// AuthToken authToken = AuthTokens.basic(username, password);
// LOGGER.debug("Basic authentication token with username {}", username);
//
// Config config = Config.build().withSessionLivenessCheckTimeout(getLongValue(timeout))
// .withEncryptionLevel(EncryptionLevel.NONE).toConfig();
// driver = GraphDatabase.driver(url, authToken, config);
// LOGGER.debug("A driver has been created to {}", url);
// }
//
// /**
// * Get the corresponding long value for the given string.
// *
// * @param longValue
// * a long number as a string
// * @return the long value
// */
// private long getLongValue(final String longValue) {
// return Long.valueOf(longValue);
// }
//
// /**
// * Establish a session.
// *
// * @see org.neo4j.driver.v1.Session
// * @return a Neo4J session
// */
// public final Session session() {
// return driver.session();
// }
//
// /**
// * Close all the resources assigned to the internal Neo4J Driver.
// *
// * @see org.neo4j.driver.v1.Driver
// */
// public final void close() {
// driver.close();
// }
// }
// Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
import java.util.HashMap;
import java.util.Map;
import org.apache.flink.streaming.connectors.neo4j.Neo4JDriverWrapper;
import org.junit.Before;
import org.junit.ClassRule;
import org.neo4j.harness.junit.Neo4jRule;
package org.apache.flink.embedded.neo4j;
/**
*
* @author Alberto De Lazzari
*
*/
public class Neo4JBaseEmbeddedConfig {
public static final String DEFAULT_URL = "bolt://localhost:7687";
public static final String DEFAULT_USERNAME = "neo4j";
public static final String DEFAULT_PASSWORD = "password";
@ClassRule
public static Neo4jRule neo4jRule;
| public static Neo4JDriverWrapper driverWrapper; |
albertodelazzari/flink-neo4j | src/main/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSink.java | // Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
| import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | /**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSink<T> extends RichSinkFunction<T> {
/**
* The default serial version UID
*/
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JSink.class);
/**
* Neo4J driver should be not serialized
*/
protected transient Neo4JDriverWrapper driver;
/**
* The mapping strategy that we use to map data from Flink to Neo4J
*
* @see Neo4JDeserializationMappingStrategy
*/ | // Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
// Path: src/main/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSink.java
import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSink<T> extends RichSinkFunction<T> {
/**
* The default serial version UID
*/
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JSink.class);
/**
* Neo4J driver should be not serialized
*/
protected transient Neo4JDriverWrapper driver;
/**
* The mapping strategy that we use to map data from Flink to Neo4J
*
* @see Neo4JDeserializationMappingStrategy
*/ | private Neo4JDeserializationMappingStrategy<T, DeserializationMapper<T>> mappingStrategy; |
albertodelazzari/flink-neo4j | src/main/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSink.java | // Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
| import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | /**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSink<T> extends RichSinkFunction<T> {
/**
* The default serial version UID
*/
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JSink.class);
/**
* Neo4J driver should be not serialized
*/
protected transient Neo4JDriverWrapper driver;
/**
* The mapping strategy that we use to map data from Flink to Neo4J
*
* @see Neo4JDeserializationMappingStrategy
*/ | // Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
// Path: src/main/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSink.java
import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSink<T> extends RichSinkFunction<T> {
/**
* The default serial version UID
*/
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JSink.class);
/**
* Neo4J driver should be not serialized
*/
protected transient Neo4JDriverWrapper driver;
/**
* The mapping strategy that we use to map data from Flink to Neo4J
*
* @see Neo4JDeserializationMappingStrategy
*/ | private Neo4JDeserializationMappingStrategy<T, DeserializationMapper<T>> mappingStrategy; |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
| import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper; | /**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSourceMock<T> extends Neo4JSource<T> {
private static final long serialVersionUID = 1L;
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceMock.java
import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
/**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSourceMock<T> extends Neo4JSource<T> {
private static final long serialVersionUID = 1L;
| public Neo4JSourceMock(final Neo4JSerializationMappingStrategy<T, SerializationMapper<T>> mappingStrategy, |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
| import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper; | /**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSourceMock<T> extends Neo4JSource<T> {
private static final long serialVersionUID = 1L;
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceMock.java
import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
/**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSourceMock<T> extends Neo4JSource<T> {
private static final long serialVersionUID = 1L;
| public Neo4JSourceMock(final Neo4JSerializationMappingStrategy<T, SerializationMapper<T>> mappingStrategy, |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
| import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper; | /**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSourceMock<T> extends Neo4JSource<T> {
private static final long serialVersionUID = 1L;
public Neo4JSourceMock(final Neo4JSerializationMappingStrategy<T, SerializationMapper<T>> mappingStrategy,
final Map<String, String> config) {
super(mappingStrategy, config);
}
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
// We use a static driver wrapper with an embedded Neo4J instance | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceMock.java
import java.util.Map;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
/**
*
*/
package org.apache.flink.streaming.connectors.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JSourceMock<T> extends Neo4JSource<T> {
private static final long serialVersionUID = 1L;
public Neo4JSourceMock(final Neo4JSerializationMappingStrategy<T, SerializationMapper<T>> mappingStrategy,
final Map<String, String> config) {
super(mappingStrategy, config);
}
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
// We use a static driver wrapper with an embedded Neo4J instance | driver = Neo4JBaseEmbeddedConfig.driverWrapper; |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
| import java.util.ArrayList;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Test; | package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkTest extends Neo4JBaseEmbeddedConfig {
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testSink() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStreamSource<Tuple2<String, Integer>> source = env.fromCollection(collection);
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple";
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkTest.java
import java.util.ArrayList;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Test;
package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkTest extends Neo4JBaseEmbeddedConfig {
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testSink() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStreamSource<Tuple2<String, Integer>> source = env.fromCollection(collection);
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple";
| DeserializationMapper<Tuple2<String, Integer>> mapper = new SimpleValuesMapper(); |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
| import java.util.ArrayList;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Test; | package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkTest extends Neo4JBaseEmbeddedConfig {
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testSink() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStreamSource<Tuple2<String, Integer>> source = env.fromCollection(collection);
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple";
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkTest.java
import java.util.ArrayList;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Test;
package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkTest extends Neo4JBaseEmbeddedConfig {
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testSink() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStreamSource<Tuple2<String, Integer>> source = env.fromCollection(collection);
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple";
| DeserializationMapper<Tuple2<String, Integer>> mapper = new SimpleValuesMapper(); |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
| import java.util.ArrayList;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Test; | package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkTest extends Neo4JBaseEmbeddedConfig {
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testSink() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStreamSource<Tuple2<String, Integer>> source = env.fromCollection(collection);
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple";
DeserializationMapper<Tuple2<String, Integer>> mapper = new SimpleValuesMapper(); | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSinkTest.java
import java.util.ArrayList;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Test;
package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSinkTest extends Neo4JBaseEmbeddedConfig {
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testSink() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStreamSource<Tuple2<String, Integer>> source = env.fromCollection(collection);
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple";
DeserializationMapper<Tuple2<String, Integer>> mapper = new SimpleValuesMapper(); | Neo4JDeserializationMappingStrategy<Tuple2<String, Integer>, DeserializationMapper<Tuple2<String, Integer>>> mappingStrategy = new Neo4JDeserializationMappingStrategy<Tuple2<String, Integer>, DeserializationMapper<Tuple2<String, Integer>>>( |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
| import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | /**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JOutputFormatTest.class);
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testOutputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple"; | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatTest.java
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JOutputFormatTest.class);
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testOutputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple"; | DeserializationMapper<Tuple2<String, Integer>> mapper = new SimpleValuesMapper(); |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
| import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | /**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JOutputFormatTest.class);
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testOutputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple"; | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatTest.java
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JOutputFormatTest.class);
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testOutputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple"; | DeserializationMapper<Tuple2<String, Integer>> mapper = new SimpleValuesMapper(); |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
| import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | /**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JOutputFormatTest.class);
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testOutputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple";
DeserializationMapper<Tuple2<String, Integer>> mapper = new SimpleValuesMapper(); | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/DeserializationMapper.java
// @FunctionalInterface
// public interface DeserializationMapper<T> extends Mapper {
//
// /**
// * Convert a generic item to a key-value pairs (used by a cypher statement)
// *
// * @param item the data stream item
// * @return a key-value set that will be used in a cypher statement
// */
// public Map<String, Object> deserialize(T item);
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/SimpleValuesMapper.java
// public class SimpleValuesMapper implements DeserializationMapper<Tuple2<String, Integer>> {
//
// /**
// *
// */
// private static final long serialVersionUID = 1681921169214823084L;
//
// public SimpleValuesMapper() {
// super();
// }
//
// @Override
// public Map<String, Object> deserialize(Tuple2<String, Integer> item) {
// HashMap<String, Object> values = new HashMap<String, Object>();
//
// values.put("t1", item.f1);
// values.put("t2", item.f0);
//
// return values;
// }
//
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JOutputFormatTest.java
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.mapping.neo4j.DeserializationMapper;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SimpleValuesMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JOutputFormatTest extends Neo4JBaseEmbeddedConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JOutputFormatTest.class);
private static final ArrayList<Tuple2<String, Integer>> collection = new ArrayList<>(20);
static {
for (int i = 0; i < 20; i++) {
collection.add(new Tuple2<>("neo4j-" + i, i));
}
}
@Test
public void testOutputFormatCount() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
String statementTemplate = "MERGE (tuple:Tuple {name: {t1}, index: {t2}}) RETURN tuple";
DeserializationMapper<Tuple2<String, Integer>> mapper = new SimpleValuesMapper(); | Neo4JDeserializationMappingStrategy<Tuple2<String, Integer>, DeserializationMapper<Tuple2<String, Integer>>> mappingStrategy = new Neo4JDeserializationMappingStrategy<Tuple2<String, Integer>, DeserializationMapper<Tuple2<String, Integer>>>( |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategyTest.java | // Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
| import java.util.Collection;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.junit.Assert;
import org.junit.Test;
import org.neo4j.driver.v1.Statement; | package org.apache.flink.mapping.neo4j;
public class Neo4JDeserializationMappingStrategyTest {
final StringValuesMapper stringValuesMapper = new StringValuesMapper();
@Test
public void testMappingStrategy() {
String templateStatement = "MATCH (n {id:{key}}) return n"; | // Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategy.java
// public class Neo4JDeserializationMappingStrategy<T, M extends DeserializationMapper<T>> implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// * The mapper that will map a item from a Flink datastream/dataset to a set
// * of parameters
// *
// * @see DeserializationMapper
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement
// * the cypher statement template
// * @param mapper
// * an actual DeserializationMapper implementation
// */
// public Neo4JDeserializationMappingStrategy(String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// * Generate a statement with parameters (templated cypher query) for a given
// * item and a convert function.
// *
// * @param item
// * a data stream item
// * @return the executable statement with its text and parameters
// */
// public Statement getStatement(T item) {
// Statement statement = new Statement(templateStatement);
//
// Map<String, Object> parameters = mapper.deserialize(item);
// return statement.withParameters(parameters);
// }
//
// protected void setStatement(String templateStatement) {
// this.templateStatement = templateStatement;
// }
// }
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JDeserializationMappingStrategyTest.java
import java.util.Collection;
import org.apache.flink.mapping.neo4j.Neo4JDeserializationMappingStrategy;
import org.junit.Assert;
import org.junit.Test;
import org.neo4j.driver.v1.Statement;
package org.apache.flink.mapping.neo4j;
public class Neo4JDeserializationMappingStrategyTest {
final StringValuesMapper stringValuesMapper = new StringValuesMapper();
@Test
public void testMappingStrategy() {
String templateStatement = "MATCH (n {id:{key}}) return n"; | Neo4JDeserializationMappingStrategy<String, StringValuesMapper> mappingStrategy = new Neo4JDeserializationMappingStrategy<String, StringValuesMapper>( |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
| import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig; | /**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JInputFormatMock<T> extends Neo4JInputFormat<T> {
private static final long serialVersionUID = 1L;
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatMock.java
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
/**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JInputFormatMock<T> extends Neo4JInputFormat<T> {
private static final long serialVersionUID = 1L;
| public Neo4JInputFormatMock(Neo4JSerializationMappingStrategy<T, SerializationMapper<T>> mappingStrategy, |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
| import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig; | /**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JInputFormatMock<T> extends Neo4JInputFormat<T> {
private static final long serialVersionUID = 1L;
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatMock.java
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
/**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JInputFormatMock<T> extends Neo4JInputFormat<T> {
private static final long serialVersionUID = 1L;
| public Neo4JInputFormatMock(Neo4JSerializationMappingStrategy<T, SerializationMapper<T>> mappingStrategy, |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatMock.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
| import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig; | /**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JInputFormatMock<T> extends Neo4JInputFormat<T> {
private static final long serialVersionUID = 1L;
public Neo4JInputFormatMock(Neo4JSerializationMappingStrategy<T, SerializationMapper<T>> mappingStrategy,
Map<String, String> config) {
super(mappingStrategy, config);
}
@Override
public void openInputFormat() {
super.openInputFormat();
// We use a static driver wrapper with an embedded Neo4J instance | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
// Path: src/test/java/org/apache/flink/batch/neo4j/Neo4JInputFormatMock.java
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import java.util.Map;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
/**
*
*/
package org.apache.flink.batch.neo4j;
/**
* @author Alberto De Lazzari
*
*/
public class Neo4JInputFormatMock<T> extends Neo4JInputFormat<T> {
private static final long serialVersionUID = 1L;
public Neo4JInputFormatMock(Neo4JSerializationMappingStrategy<T, SerializationMapper<T>> mappingStrategy,
Map<String, String> config) {
super(mappingStrategy, config);
}
@Override
public void openInputFormat() {
super.openInputFormat();
// We use a static driver wrapper with an embedded Neo4J instance | driver = Neo4JBaseEmbeddedConfig.driverWrapper; |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
| import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Assert;
import org.junit.Test; | package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSourceTest extends Neo4JBaseEmbeddedConfig {
@Test
public void testSource() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceTest.java
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Assert;
import org.junit.Test;
package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSourceTest extends Neo4JBaseEmbeddedConfig {
@Test
public void testSource() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
| SerializationMapper<String> serializationMapper = new StringSerializationMapper(); |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
| import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Assert;
import org.junit.Test; | package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSourceTest extends Neo4JBaseEmbeddedConfig {
@Test
public void testSource() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceTest.java
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Assert;
import org.junit.Test;
package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSourceTest extends Neo4JBaseEmbeddedConfig {
@Test
public void testSource() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
| SerializationMapper<String> serializationMapper = new StringSerializationMapper(); |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
| import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Assert;
import org.junit.Test; | package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSourceTest extends Neo4JBaseEmbeddedConfig {
@Test
public void testSource() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
SerializationMapper<String> serializationMapper = new StringSerializationMapper();
String statement = "MATCH (i:Item) return i.description";
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceTest.java
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Assert;
import org.junit.Test;
package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSourceTest extends Neo4JBaseEmbeddedConfig {
@Test
public void testSource() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
SerializationMapper<String> serializationMapper = new StringSerializationMapper();
String statement = "MATCH (i:Item) return i.description";
| Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> mappingStrategy = new Neo4JSourceMappingStrategyString( |
albertodelazzari/flink-neo4j | src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceTest.java | // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
| import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Assert;
import org.junit.Test; | package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSourceTest extends Neo4JBaseEmbeddedConfig {
@Test
public void testSource() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
SerializationMapper<String> serializationMapper = new StringSerializationMapper();
String statement = "MATCH (i:Item) return i.description";
| // Path: src/test/java/org/apache/flink/embedded/neo4j/Neo4JBaseEmbeddedConfig.java
// public class Neo4JBaseEmbeddedConfig {
//
// public static final String DEFAULT_URL = "bolt://localhost:7687";
//
// public static final String DEFAULT_USERNAME = "neo4j";
//
// public static final String DEFAULT_PASSWORD = "password";
//
// @ClassRule
// public static Neo4jRule neo4jRule;
//
// public static Neo4JDriverWrapper driverWrapper;
//
// public static Map<String, String> neo4JConfig;
//
// static {
// neo4jRule = new Neo4jRule().withFixture("create (i:Item {description:'an item'})");
// }
//
// @Before
// public void init() {
// neo4JConfig = new HashMap<String, String>();
// neo4JConfig.put(Neo4JDriverWrapper.URL, neo4jRule.boltURI().toString());
// neo4JConfig.put(Neo4JDriverWrapper.USERNAME_PARAM, "neo4j");
// neo4JConfig.put(Neo4JDriverWrapper.PASSWORD_PARAM, "password");
// neo4JConfig.put(Neo4JDriverWrapper.SESSION_LIVENESS_TIMEOUT, "4000");
//
// driverWrapper = new Neo4JDriverWrapper(neo4JConfig);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/Neo4JSerializationMappingStrategy.java
// public class Neo4JSerializationMappingStrategy<T, M extends SerializationMapper<T>> implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// /**
// * The templated cypher query that will be executed on Neo4J
// */
// private String templateStatement;
//
// /**
// *
// */
// private M mapper;
//
// /**
// *
// * @param templateStatement the cypher statement template
// * @param mapper an actual SerializationMapper implementation
// */
// public Neo4JSerializationMappingStrategy(final String templateStatement, M mapper) {
// this.templateStatement = templateStatement;
// this.mapper = mapper;
// }
//
// /**
// *
// * @return the cypher statement template
// */
// public Statement getStatement() {
// return new Statement(templateStatement);
// }
//
// /**
// * Maps a single result record into a T object
// *
// * @param record a record that will be returned by the cypher query
// * @return an object of type T
// */
// public T map(Record record) {
// return this.mapper.serialize(record.asMap());
// }
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/Neo4JSourceMappingStrategyString.java
// public class Neo4JSourceMappingStrategyString extends Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> {
//
// private static final long serialVersionUID = 1L;
//
// public Neo4JSourceMappingStrategyString(String templateStatement, SerializationMapper<String> mapper) {
// super(templateStatement, mapper);
// }
// }
//
// Path: src/main/java/org/apache/flink/mapping/neo4j/SerializationMapper.java
// @FunctionalInterface
// public interface SerializationMapper<T> extends Mapper {
//
// /**
// * Convert a record (that is returned by the cypher query) into an object of
// * type T.
// *
// * Tips: Maybe record should be of type org.neo4j.driver.v1.Record
// *
// * @param record
// * a record (as a Map) that will be returned by the cypher query
// * @return an item of type T that is a transformation of a record into an
// * item T
// */
// public T serialize(Map<String, Object> record);
// }
//
// Path: src/test/java/org/apache/flink/mapping/neo4j/StringSerializationMapper.java
// public class StringSerializationMapper implements SerializationMapper<String> {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public String serialize(Map<String, Object> record) {
// return record.get("i.description").toString();
// }
// }
// Path: src/test/java/org/apache/flink/streaming/connectors/neo4j/Neo4JSourceTest.java
import java.util.List;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.java.io.LocalCollectionOutputFormat;
import org.apache.flink.embedded.neo4j.Neo4JBaseEmbeddedConfig;
import org.apache.flink.hadoop.shaded.com.google.common.collect.Lists;
import org.apache.flink.mapping.neo4j.Neo4JSerializationMappingStrategy;
import org.apache.flink.mapping.neo4j.Neo4JSourceMappingStrategyString;
import org.apache.flink.mapping.neo4j.SerializationMapper;
import org.apache.flink.mapping.neo4j.StringSerializationMapper;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.junit.Assert;
import org.junit.Test;
package org.apache.flink.streaming.connectors.neo4j;
public class Neo4JSourceTest extends Neo4JBaseEmbeddedConfig {
@Test
public void testSource() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
SerializationMapper<String> serializationMapper = new StringSerializationMapper();
String statement = "MATCH (i:Item) return i.description";
| Neo4JSerializationMappingStrategy<String, SerializationMapper<String>> mappingStrategy = new Neo4JSourceMappingStrategyString( |
jrenner/gdx-proto | core/src/org/jrenner/fps/utils/Compression.java | // Path: core/src/org/jrenner/fps/Log.java
// public class Log {
// private static final String TAG = "LOG";
// private static FileHandle logFile;
// private static final String DEBUG_S = "DEBUG";
// private static final String INFO_S = "INFO";
// private static final String ERROR_S = "ERROR";
// private static boolean serverLogToFile = false;
// private static final String serverLogFileName = "fps.log";
//
// public static void init() {
// if (Main.isServer() && serverLogToFile) {
// logFile = Gdx.files.local(serverLogFileName);
// }
// }
//
// public static void debug(String msg) {
// Gdx.app.debug(TAG, msg);
// if (Gdx.app.getLogLevel() <= DEBUG)
// writeToFile(DEBUG_S, TAG, msg);
// }
//
// public static void info(String msg) {
// Gdx.app.log(TAG, msg);
// if (Gdx.app.getLogLevel() <= INFO)
// writeToFile(INFO_S, TAG, msg);
// }
//
// public static void error(String msg) {
// Gdx.app.log(TAG, msg);
// if (Gdx.app.getLogLevel() <= ERROR)
// writeToFile(ERROR_S, TAG, msg);
// }
//
// public static void setLevel(int level) {
// Gdx.app.setLogLevel(level);
// }
//
// private static StringBuilder sb = new StringBuilder();
//
// private static void writeToFile(String level, String tag, String msg) {
// if (logFile != null) {
// sb.delete(0, sb.length());
// sb.append("[").append(level).append("] ").append(tag).append(": ").append(msg).append("\n");
// try {
// logFile.writeString(sb.toString(), true);
// } catch (Exception e) {
// logFile = null;
// //Log.error(e.toString());
// throw new GdxRuntimeException(e);
// }
// }
// }
//
// public static final int DEBUG = Application.LOG_DEBUG;
// public static final int INFO = Application.LOG_INFO;
// public static final int ERROR = Application.LOG_ERROR;
// }
| import com.badlogic.gdx.utils.Array;
import org.jrenner.fps.Log;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; | gzout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
public static String decompressToString(byte[] bytes) {
GZIPInputStream gzin = null;
try {
gzin = new GZIPInputStream(new ByteArrayInputStream(bytes));
byte[] buf = new byte[8192];
byte[] storage = new byte[65536];
int n = 0;
int total = 0;
while (true) {
n = gzin.read(buf);
if (n == -1) break;
// expand to meet needs
if (total + n >= storage.length) {
byte[] expanded = new byte[storage.length * 2];
System.arraycopy(storage, 0, expanded, 0, storage.length);
storage = expanded;
}
System.out.printf("blen: %d, storlen: %d, total: %d, n: %d\n", buf.length, storage.length, total, n);
System.arraycopy(buf, 0, storage, total, n);
total += n;
} | // Path: core/src/org/jrenner/fps/Log.java
// public class Log {
// private static final String TAG = "LOG";
// private static FileHandle logFile;
// private static final String DEBUG_S = "DEBUG";
// private static final String INFO_S = "INFO";
// private static final String ERROR_S = "ERROR";
// private static boolean serverLogToFile = false;
// private static final String serverLogFileName = "fps.log";
//
// public static void init() {
// if (Main.isServer() && serverLogToFile) {
// logFile = Gdx.files.local(serverLogFileName);
// }
// }
//
// public static void debug(String msg) {
// Gdx.app.debug(TAG, msg);
// if (Gdx.app.getLogLevel() <= DEBUG)
// writeToFile(DEBUG_S, TAG, msg);
// }
//
// public static void info(String msg) {
// Gdx.app.log(TAG, msg);
// if (Gdx.app.getLogLevel() <= INFO)
// writeToFile(INFO_S, TAG, msg);
// }
//
// public static void error(String msg) {
// Gdx.app.log(TAG, msg);
// if (Gdx.app.getLogLevel() <= ERROR)
// writeToFile(ERROR_S, TAG, msg);
// }
//
// public static void setLevel(int level) {
// Gdx.app.setLogLevel(level);
// }
//
// private static StringBuilder sb = new StringBuilder();
//
// private static void writeToFile(String level, String tag, String msg) {
// if (logFile != null) {
// sb.delete(0, sb.length());
// sb.append("[").append(level).append("] ").append(tag).append(": ").append(msg).append("\n");
// try {
// logFile.writeString(sb.toString(), true);
// } catch (Exception e) {
// logFile = null;
// //Log.error(e.toString());
// throw new GdxRuntimeException(e);
// }
// }
// }
//
// public static final int DEBUG = Application.LOG_DEBUG;
// public static final int INFO = Application.LOG_INFO;
// public static final int ERROR = Application.LOG_ERROR;
// }
// Path: core/src/org/jrenner/fps/utils/Compression.java
import com.badlogic.gdx.utils.Array;
import org.jrenner.fps.Log;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
gzout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
public static String decompressToString(byte[] bytes) {
GZIPInputStream gzin = null;
try {
gzin = new GZIPInputStream(new ByteArrayInputStream(bytes));
byte[] buf = new byte[8192];
byte[] storage = new byte[65536];
int n = 0;
int total = 0;
while (true) {
n = gzin.read(buf);
if (n == -1) break;
// expand to meet needs
if (total + n >= storage.length) {
byte[] expanded = new byte[storage.length * 2];
System.arraycopy(storage, 0, expanded, 0, storage.length);
storage = expanded;
}
System.out.printf("blen: %d, storlen: %d, total: %d, n: %d\n", buf.length, storage.length, total, n);
System.arraycopy(buf, 0, storage, total, n);
total += n;
} | Log.debug("read " + total + " bytes from compressed files"); |
jrenner/gdx-proto | core/src/org/jrenner/fps/net/client/ClientUpdate.java | // Path: core/src/org/jrenner/fps/net/packages/CommandPackage.java
// public class CommandPackage implements Pool.Poolable {
// public static final int FORWARD = 0x01;
// public static final int BACK = 0x02;
// public static final int STRAFE_LEFT = 0x04;
// public static final int STRAFE_RIGHT = 0x08;
// public static final int UP = 0x10;
// public static final int DOWN = 0x20;
// public static final int JUMP = 0x40;
// public static final int SHOOT = 0x80;
//
// public int commandBits;
// public float yaw;
// public float pitch;
// public float roll;
//
// public void setTranslation(Direction.Translation trans) {
// switch (trans) {
// case Forward:
// set(FORWARD, true);
// break;
// case Back:
// set(BACK, true);
// break;
// case Up:
// set(UP, true);
// break;
// case Down:
// set(DOWN, true);
// break;
// case Left:
// set(STRAFE_LEFT, true);
// break;
// case Right:
// set(STRAFE_RIGHT, true);
// break;
// default:
// throw new GdxRuntimeException("unhandled");
// }
// }
//
// public void setRotation(Quaternion q) {
// yaw = q.getYaw();
// pitch = q.getPitch();
// roll = q.getRoll();
// }
//
// /*public void setRotation(Direction.Rotation rot) {
// switch (rot) {
// case YawLeft:
// set(YAW_LEFT, true);
// break;
// case YawRight:
// set(YAW_RIGHT, true);
// break;
// case PitchUp:
// set(PITCH_UP, true);
// break;
// case PitchDown:
// set(PITCH_DOWN, true);
// break;
// case RollLeft:
// set(ROLL_LEFT, true);
// break;
// case RollRight:
// set(ROLL_RIGHT, true);
// break;
// }
// }*/
//
// public void set(int value, boolean status) {
// if (status) {
// commandBits |= value; // on
// } else {
// commandBits &= ~(value); // off
// }
// }
//
// public boolean get(int value) {
// return (value & commandBits) != 0;
// }
//
// public void set(CommandPackage other) {
// commandBits = other.commandBits;
// }
//
// @Override
// public void reset() {
// commandBits = 0;
// }
// }
| import com.badlogic.gdx.utils.Pool;
import org.jrenner.fps.net.packages.CommandPackage; | package org.jrenner.fps.net.client;
public class ClientUpdate implements Pool.Poolable {
private static Pool<ClientUpdate> clientUpdatePool = new Pool<ClientUpdate>() {
@Override
protected ClientUpdate newObject() {
return new ClientUpdate();
}
};
/** tick number this input was sent at, used for client-side prediction, not related to main server timing tick */
public int inputTick;
public int entityId; | // Path: core/src/org/jrenner/fps/net/packages/CommandPackage.java
// public class CommandPackage implements Pool.Poolable {
// public static final int FORWARD = 0x01;
// public static final int BACK = 0x02;
// public static final int STRAFE_LEFT = 0x04;
// public static final int STRAFE_RIGHT = 0x08;
// public static final int UP = 0x10;
// public static final int DOWN = 0x20;
// public static final int JUMP = 0x40;
// public static final int SHOOT = 0x80;
//
// public int commandBits;
// public float yaw;
// public float pitch;
// public float roll;
//
// public void setTranslation(Direction.Translation trans) {
// switch (trans) {
// case Forward:
// set(FORWARD, true);
// break;
// case Back:
// set(BACK, true);
// break;
// case Up:
// set(UP, true);
// break;
// case Down:
// set(DOWN, true);
// break;
// case Left:
// set(STRAFE_LEFT, true);
// break;
// case Right:
// set(STRAFE_RIGHT, true);
// break;
// default:
// throw new GdxRuntimeException("unhandled");
// }
// }
//
// public void setRotation(Quaternion q) {
// yaw = q.getYaw();
// pitch = q.getPitch();
// roll = q.getRoll();
// }
//
// /*public void setRotation(Direction.Rotation rot) {
// switch (rot) {
// case YawLeft:
// set(YAW_LEFT, true);
// break;
// case YawRight:
// set(YAW_RIGHT, true);
// break;
// case PitchUp:
// set(PITCH_UP, true);
// break;
// case PitchDown:
// set(PITCH_DOWN, true);
// break;
// case RollLeft:
// set(ROLL_LEFT, true);
// break;
// case RollRight:
// set(ROLL_RIGHT, true);
// break;
// }
// }*/
//
// public void set(int value, boolean status) {
// if (status) {
// commandBits |= value; // on
// } else {
// commandBits &= ~(value); // off
// }
// }
//
// public boolean get(int value) {
// return (value & commandBits) != 0;
// }
//
// public void set(CommandPackage other) {
// commandBits = other.commandBits;
// }
//
// @Override
// public void reset() {
// commandBits = 0;
// }
// }
// Path: core/src/org/jrenner/fps/net/client/ClientUpdate.java
import com.badlogic.gdx.utils.Pool;
import org.jrenner.fps.net.packages.CommandPackage;
package org.jrenner.fps.net.client;
public class ClientUpdate implements Pool.Poolable {
private static Pool<ClientUpdate> clientUpdatePool = new Pool<ClientUpdate>() {
@Override
protected ClientUpdate newObject() {
return new ClientUpdate();
}
};
/** tick number this input was sent at, used for client-side prediction, not related to main server timing tick */
public int inputTick;
public int entityId; | public CommandPackage cmdPack = new CommandPackage(); |
jrenner/gdx-proto | core/src/org/jrenner/fps/net/packages/EntityUpdate.java | // Path: core/src/org/jrenner/fps/utils/Pooler.java
// public class Pooler {
// private static Vector3Pool v3Pool;
// private static Matrix4Pool mtxPool;
// private static ServerUpdatePool serverUpdatePool;
// private static EntityUpdatePool entityUpdatePool;
// private static MovementPackagePool movementPackagePool;
//
// public static void init() {
// v3Pool = new Vector3Pool();
// mtxPool = new Matrix4Pool();
// serverUpdatePool = new ServerUpdatePool();
// entityUpdatePool = new EntityUpdatePool();
// movementPackagePool = new MovementPackagePool();
// }
//
//
//
// public static class Vector3Pool extends CountingPool<Vector3> {
// @Override
// protected Vector3 newObject() {
// return new Vector3();
// }
// }
// public static Vector3 v3() {
// return v3Pool.obtain();
// }
//
// public static void free(Vector3 v3) {
// v3Pool.free(v3);
// }
//
// public static void free(Vector3 ...v3) {
// for (int i = 0; i < v3.length; i++) {
// v3Pool.free(v3[i]);
// }
// }
//
//
//
// public static class Matrix4Pool extends CountingPool<Matrix4> {
// @Override
// protected Matrix4 newObject() {
// return new Matrix4();
// }
// }
//
// public static Matrix4 mtx() {
// return mtxPool.obtain();
// }
//
// public static void free(Matrix4 mtx) {
// mtxPool.free(mtx);
// }
//
// public static void free(Matrix4 ...mtx) {
// for (int i = 0; i < mtx.length; i++) {
// mtxPool.free(mtx[i]);
// }
// }
//
//
//
// public static class ServerUpdatePool extends CountingPool<ServerUpdate> {
// @Override
// protected ServerUpdate newObject() {
// return new ServerUpdate();
// }
// }
//
// public static ServerUpdate serverUpdate() {
// return serverUpdatePool.obtain();
// }
//
// public static void free(ServerUpdate upd) {
// serverUpdatePool.free(upd);
// }
//
// public static void free(ServerUpdate ...upd) {
// for (int i = 0; i < upd.length; i++) {
// serverUpdatePool.free(upd[i]);
// }
// }
//
//
//
// public static class EntityUpdatePool extends CountingPool<EntityUpdate> {
// @Override
// protected EntityUpdate newObject() {
// return new EntityUpdate();
// }
// }
//
// public static EntityUpdate entityUpdate() {
// return entityUpdatePool.obtain();
// }
//
// public static void free(EntityUpdate upd) {
// entityUpdatePool.free(upd);
// }
//
// public static void free(EntityUpdate ...upd) {
// for (int i = 0; i < upd.length; i++) {
// entityUpdatePool.free(upd[i]);
// }
// }
//
//
//
// public static class MovementPackagePool extends CountingPool<CommandPackage> {
// @Override
// protected CommandPackage newObject() {
// return new CommandPackage();
// }
// }
//
// public static CommandPackage movementPackage() {
// return movementPackagePool.obtain();
// }
//
// public static void free(CommandPackage upd) {
// movementPackagePool.free(upd);
// }
//
// public static void free(CommandPackage...upd) {
// for (int i = 0; i < upd.length; i++) {
// movementPackagePool.free(upd[i]);
// }
// }
//
//
// }
| import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Pool;
import org.jrenner.fps.utils.Pooler; | package org.jrenner.fps.net.packages;
public class EntityUpdate {
private int entityId; | // Path: core/src/org/jrenner/fps/utils/Pooler.java
// public class Pooler {
// private static Vector3Pool v3Pool;
// private static Matrix4Pool mtxPool;
// private static ServerUpdatePool serverUpdatePool;
// private static EntityUpdatePool entityUpdatePool;
// private static MovementPackagePool movementPackagePool;
//
// public static void init() {
// v3Pool = new Vector3Pool();
// mtxPool = new Matrix4Pool();
// serverUpdatePool = new ServerUpdatePool();
// entityUpdatePool = new EntityUpdatePool();
// movementPackagePool = new MovementPackagePool();
// }
//
//
//
// public static class Vector3Pool extends CountingPool<Vector3> {
// @Override
// protected Vector3 newObject() {
// return new Vector3();
// }
// }
// public static Vector3 v3() {
// return v3Pool.obtain();
// }
//
// public static void free(Vector3 v3) {
// v3Pool.free(v3);
// }
//
// public static void free(Vector3 ...v3) {
// for (int i = 0; i < v3.length; i++) {
// v3Pool.free(v3[i]);
// }
// }
//
//
//
// public static class Matrix4Pool extends CountingPool<Matrix4> {
// @Override
// protected Matrix4 newObject() {
// return new Matrix4();
// }
// }
//
// public static Matrix4 mtx() {
// return mtxPool.obtain();
// }
//
// public static void free(Matrix4 mtx) {
// mtxPool.free(mtx);
// }
//
// public static void free(Matrix4 ...mtx) {
// for (int i = 0; i < mtx.length; i++) {
// mtxPool.free(mtx[i]);
// }
// }
//
//
//
// public static class ServerUpdatePool extends CountingPool<ServerUpdate> {
// @Override
// protected ServerUpdate newObject() {
// return new ServerUpdate();
// }
// }
//
// public static ServerUpdate serverUpdate() {
// return serverUpdatePool.obtain();
// }
//
// public static void free(ServerUpdate upd) {
// serverUpdatePool.free(upd);
// }
//
// public static void free(ServerUpdate ...upd) {
// for (int i = 0; i < upd.length; i++) {
// serverUpdatePool.free(upd[i]);
// }
// }
//
//
//
// public static class EntityUpdatePool extends CountingPool<EntityUpdate> {
// @Override
// protected EntityUpdate newObject() {
// return new EntityUpdate();
// }
// }
//
// public static EntityUpdate entityUpdate() {
// return entityUpdatePool.obtain();
// }
//
// public static void free(EntityUpdate upd) {
// entityUpdatePool.free(upd);
// }
//
// public static void free(EntityUpdate ...upd) {
// for (int i = 0; i < upd.length; i++) {
// entityUpdatePool.free(upd[i]);
// }
// }
//
//
//
// public static class MovementPackagePool extends CountingPool<CommandPackage> {
// @Override
// protected CommandPackage newObject() {
// return new CommandPackage();
// }
// }
//
// public static CommandPackage movementPackage() {
// return movementPackagePool.obtain();
// }
//
// public static void free(CommandPackage upd) {
// movementPackagePool.free(upd);
// }
//
// public static void free(CommandPackage...upd) {
// for (int i = 0; i < upd.length; i++) {
// movementPackagePool.free(upd[i]);
// }
// }
//
//
// }
// Path: core/src/org/jrenner/fps/net/packages/EntityUpdate.java
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Pool;
import org.jrenner.fps.utils.Pooler;
package org.jrenner.fps.net.packages;
public class EntityUpdate {
private int entityId; | private Vector3 position = Pooler.v3(); |
jrenner/gdx-proto | core/src/org/jrenner/fps/net/packages/ServerMessage.java | // Path: core/src/org/jrenner/fps/LevelStatic.java
// public class LevelStatic {
// public String modelName;
// public Matrix4 mtx = new Matrix4();
// }
| import org.jrenner.fps.LevelStatic; | package org.jrenner.fps.net.packages;
public class ServerMessage {
public static class AssignPlayerEntityId {
public int id;
}
public static class DestroyEntity {
public int id;
}
public static class ServerInfo {
public int tickNum;
public float tickInterval;
public String serverName;
public String serverMsg;
}
public static class LevelGeometry { | // Path: core/src/org/jrenner/fps/LevelStatic.java
// public class LevelStatic {
// public String modelName;
// public Matrix4 mtx = new Matrix4();
// }
// Path: core/src/org/jrenner/fps/net/packages/ServerMessage.java
import org.jrenner.fps.LevelStatic;
package org.jrenner.fps.net.packages;
public class ServerMessage {
public static class AssignPlayerEntityId {
public int id;
}
public static class DestroyEntity {
public int id;
}
public static class ServerInfo {
public int tickNum;
public float tickInterval;
public String serverName;
public String serverMsg;
}
public static class LevelGeometry { | public LevelStatic[] staticPieces; |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/module/cache/DataCache.java | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/utils/FileUtils.java
// public class FileUtils {
//
// /**
// * 获取APP的cache
// */
// public static File getDiskCacheDir(Context context, String uniqueName) {
// String cachePath;
// if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
// || !Environment.isExternalStorageRemovable()) {
// cachePath = context.getExternalCacheDir().getPath();
// } else {
// cachePath = context.getCacheDir().getPath();
// }
// return new File(cachePath + File.separator + uniqueName);
// }
//
// /**
// * 保存图片至相册
// */
// public static void saveImageToGallery(Context context, Bitmap bmp) {
// // 首先保存图片
// File appDir = new File(Environment.getExternalStorageDirectory(), "Qvod");
// if (!appDir.exists()) {
// appDir.mkdirs();
// }
// String fileName = System.currentTimeMillis() + ".jpg";
// File file = new File(appDir, fileName);
// try {
// FileOutputStream fos = new FileOutputStream(file);
// bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
// fos.flush();
// fos.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// // 其次把文件插入到系统图库
// try {
// MediaStore.Images.Media.insertImage(context.getContentResolver(),
// file.getAbsolutePath(), fileName, null);
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
// // 最后通知图库更新
// context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getAbsoluteFile())));
// }
// }
| import android.content.Context;
import android.util.LruCache;
import com.zmj.qvod.module.bean.VideoRes;
import com.zmj.qvod.utils.FileUtils;
import java.io.File;
import okhttp3.internal.DiskLruCache; | package com.zmj.qvod.module.cache;
/**
* Created by matt on 2017/3/15.
*/
public class DataCache {
DiskLruCache mDiskLruCache = null;
/**
* 磁盘缓存
* @param context
*/
public void getDiskCache(Context context) { | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/utils/FileUtils.java
// public class FileUtils {
//
// /**
// * 获取APP的cache
// */
// public static File getDiskCacheDir(Context context, String uniqueName) {
// String cachePath;
// if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
// || !Environment.isExternalStorageRemovable()) {
// cachePath = context.getExternalCacheDir().getPath();
// } else {
// cachePath = context.getCacheDir().getPath();
// }
// return new File(cachePath + File.separator + uniqueName);
// }
//
// /**
// * 保存图片至相册
// */
// public static void saveImageToGallery(Context context, Bitmap bmp) {
// // 首先保存图片
// File appDir = new File(Environment.getExternalStorageDirectory(), "Qvod");
// if (!appDir.exists()) {
// appDir.mkdirs();
// }
// String fileName = System.currentTimeMillis() + ".jpg";
// File file = new File(appDir, fileName);
// try {
// FileOutputStream fos = new FileOutputStream(file);
// bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
// fos.flush();
// fos.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// // 其次把文件插入到系统图库
// try {
// MediaStore.Images.Media.insertImage(context.getContentResolver(),
// file.getAbsolutePath(), fileName, null);
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
// // 最后通知图库更新
// context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getAbsoluteFile())));
// }
// }
// Path: app/src/main/java/com/zmj/qvod/module/cache/DataCache.java
import android.content.Context;
import android.util.LruCache;
import com.zmj.qvod.module.bean.VideoRes;
import com.zmj.qvod.utils.FileUtils;
import java.io.File;
import okhttp3.internal.DiskLruCache;
package com.zmj.qvod.module.cache;
/**
* Created by matt on 2017/3/15.
*/
public class DataCache {
DiskLruCache mDiskLruCache = null;
/**
* 磁盘缓存
* @param context
*/
public void getDiskCache(Context context) { | File cacheDir = FileUtils.getDiskCacheDir(context, "object"); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/module/cache/DataCache.java | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/utils/FileUtils.java
// public class FileUtils {
//
// /**
// * 获取APP的cache
// */
// public static File getDiskCacheDir(Context context, String uniqueName) {
// String cachePath;
// if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
// || !Environment.isExternalStorageRemovable()) {
// cachePath = context.getExternalCacheDir().getPath();
// } else {
// cachePath = context.getCacheDir().getPath();
// }
// return new File(cachePath + File.separator + uniqueName);
// }
//
// /**
// * 保存图片至相册
// */
// public static void saveImageToGallery(Context context, Bitmap bmp) {
// // 首先保存图片
// File appDir = new File(Environment.getExternalStorageDirectory(), "Qvod");
// if (!appDir.exists()) {
// appDir.mkdirs();
// }
// String fileName = System.currentTimeMillis() + ".jpg";
// File file = new File(appDir, fileName);
// try {
// FileOutputStream fos = new FileOutputStream(file);
// bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
// fos.flush();
// fos.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// // 其次把文件插入到系统图库
// try {
// MediaStore.Images.Media.insertImage(context.getContentResolver(),
// file.getAbsolutePath(), fileName, null);
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
// // 最后通知图库更新
// context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getAbsoluteFile())));
// }
// }
| import android.content.Context;
import android.util.LruCache;
import com.zmj.qvod.module.bean.VideoRes;
import com.zmj.qvod.utils.FileUtils;
import java.io.File;
import okhttp3.internal.DiskLruCache; | package com.zmj.qvod.module.cache;
/**
* Created by matt on 2017/3/15.
*/
public class DataCache {
DiskLruCache mDiskLruCache = null;
/**
* 磁盘缓存
* @param context
*/
public void getDiskCache(Context context) {
File cacheDir = FileUtils.getDiskCacheDir(context, "object");
if (!cacheDir.exists()) {
cacheDir.mkdirs();
}
//...
}
/**
* 内存缓存
*/ | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/utils/FileUtils.java
// public class FileUtils {
//
// /**
// * 获取APP的cache
// */
// public static File getDiskCacheDir(Context context, String uniqueName) {
// String cachePath;
// if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
// || !Environment.isExternalStorageRemovable()) {
// cachePath = context.getExternalCacheDir().getPath();
// } else {
// cachePath = context.getCacheDir().getPath();
// }
// return new File(cachePath + File.separator + uniqueName);
// }
//
// /**
// * 保存图片至相册
// */
// public static void saveImageToGallery(Context context, Bitmap bmp) {
// // 首先保存图片
// File appDir = new File(Environment.getExternalStorageDirectory(), "Qvod");
// if (!appDir.exists()) {
// appDir.mkdirs();
// }
// String fileName = System.currentTimeMillis() + ".jpg";
// File file = new File(appDir, fileName);
// try {
// FileOutputStream fos = new FileOutputStream(file);
// bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
// fos.flush();
// fos.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// // 其次把文件插入到系统图库
// try {
// MediaStore.Images.Media.insertImage(context.getContentResolver(),
// file.getAbsolutePath(), fileName, null);
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
// // 最后通知图库更新
// context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getAbsoluteFile())));
// }
// }
// Path: app/src/main/java/com/zmj/qvod/module/cache/DataCache.java
import android.content.Context;
import android.util.LruCache;
import com.zmj.qvod.module.bean.VideoRes;
import com.zmj.qvod.utils.FileUtils;
import java.io.File;
import okhttp3.internal.DiskLruCache;
package com.zmj.qvod.module.cache;
/**
* Created by matt on 2017/3/15.
*/
public class DataCache {
DiskLruCache mDiskLruCache = null;
/**
* 磁盘缓存
* @param context
*/
public void getDiskCache(Context context) {
File cacheDir = FileUtils.getDiskCacheDir(context, "object");
if (!cacheDir.exists()) {
cacheDir.mkdirs();
}
//...
}
/**
* 内存缓存
*/ | private LruCache<String, VideoRes> mVideoCache; |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/constant/ImageLoader.java | // Path: app/src/main/java/com/zmj/qvod/app/VideoApplication.java
// public class VideoApplication extends Application {
//
// private static VideoApplication videoApplication;
//
// public static VideoApplication getInstance() {
// if (videoApplication == null) {
// synchronized (VideoApplication.class) {
// if (videoApplication == null) {
// videoApplication = new VideoApplication();
// }
// }
// }
// return videoApplication;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// videoApplication = this;
// HttpUtils.getInstance().setContext(this);
// JUtils.initialize(this);
// JUtils.setDebug(true, "video");
// initLoading();
// }
//
// private void initLoading() {
// LoadingLayout.getConfig()
// .setErrorText("出错啦~请稍后重试!")
// .setEmptyText("抱歉,暂无数据")
// .setNoNetworkText("无网络连接,请检查您的网络···")
// .setErrorImage(R.drawable.ic_empty_icon)
// .setEmptyImage(R.drawable.ic_empty_icon)
// .setNoNetworkImage(R.drawable.ic_no_network)
// .setAllTipTextColor(R.color.colorTabText)
// .setAllTipTextSize(14)
// .setReloadButtonText("点我重试哦")
// .setReloadButtonTextSize(14)
// .setReloadButtonTextColor(R.color.colorTabText)
// .setReloadButtonWidthAndHeight(150, 40)
// .setAllPageBackgroundColor(R.color.colorBackground)
// .setLoadingPageLayout(R.layout.default_loading_page);
// }
//
// private VideoRes videoRes;
//
// public VideoRes getVideoRes() {
// return videoRes;
// }
//
// public void setVideoRes(VideoRes videoRes) {
// this.videoRes = videoRes;
// }
// }
| import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.FutureTarget;
import com.zmj.qvod.R;
import com.zmj.qvod.app.VideoApplication;
import java.io.File;
import java.util.concurrent.ExecutionException; | package com.zmj.qvod.constant;
/**
* Description: ImageLoader
* Creator: zmj
* date: 2017/02/21 9:53
*/
public class ImageLoader {
public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
if (!activity.isDestroyed()) {
Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
}
}
public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
if (!activity.isDestroyed()) {
Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
}
}
public static void load(String url, ImageView iv, int type) { //使用占位图
switch (type) {
case 320: | // Path: app/src/main/java/com/zmj/qvod/app/VideoApplication.java
// public class VideoApplication extends Application {
//
// private static VideoApplication videoApplication;
//
// public static VideoApplication getInstance() {
// if (videoApplication == null) {
// synchronized (VideoApplication.class) {
// if (videoApplication == null) {
// videoApplication = new VideoApplication();
// }
// }
// }
// return videoApplication;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// videoApplication = this;
// HttpUtils.getInstance().setContext(this);
// JUtils.initialize(this);
// JUtils.setDebug(true, "video");
// initLoading();
// }
//
// private void initLoading() {
// LoadingLayout.getConfig()
// .setErrorText("出错啦~请稍后重试!")
// .setEmptyText("抱歉,暂无数据")
// .setNoNetworkText("无网络连接,请检查您的网络···")
// .setErrorImage(R.drawable.ic_empty_icon)
// .setEmptyImage(R.drawable.ic_empty_icon)
// .setNoNetworkImage(R.drawable.ic_no_network)
// .setAllTipTextColor(R.color.colorTabText)
// .setAllTipTextSize(14)
// .setReloadButtonText("点我重试哦")
// .setReloadButtonTextSize(14)
// .setReloadButtonTextColor(R.color.colorTabText)
// .setReloadButtonWidthAndHeight(150, 40)
// .setAllPageBackgroundColor(R.color.colorBackground)
// .setLoadingPageLayout(R.layout.default_loading_page);
// }
//
// private VideoRes videoRes;
//
// public VideoRes getVideoRes() {
// return videoRes;
// }
//
// public void setVideoRes(VideoRes videoRes) {
// this.videoRes = videoRes;
// }
// }
// Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.FutureTarget;
import com.zmj.qvod.R;
import com.zmj.qvod.app.VideoApplication;
import java.io.File;
import java.util.concurrent.ExecutionException;
package com.zmj.qvod.constant;
/**
* Description: ImageLoader
* Creator: zmj
* date: 2017/02/21 9:53
*/
public class ImageLoader {
public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
if (!activity.isDestroyed()) {
Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
}
}
public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
if (!activity.isDestroyed()) {
Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
}
}
public static void load(String url, ImageView iv, int type) { //使用占位图
switch (type) {
case 320: | Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/view/activity/VideoInfoActivity.java | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/presenter/VideoInfoPresenter.java
// public class VideoInfoPresenter extends BeamBasePresenter<VideoInfoActivity> {
//
// private JCVideoPlayerStandard jcVideoPlay;
//
// private VideoRes videoRes;
// private Subscription rxSubscription;
// private VideoMoreAdapter adapter;
// private View headView;
//
// TextViewExpandableAnimation tvExpand;
//
// @Override
// protected void onCreateView(@NonNull VideoInfoActivity view) {
// super.onCreateView(view);
// getView().getSupportActionBar().setTitle(getView().getVideoInfo().title);
//
// initVideoPlay();
//
// setListView();
//
// initData();
//
// }
//
// private void initVideoPlay() {
// jcVideoPlay = getView().getJcVideoPlay();
// //
// jcVideoPlay.thumbImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
// jcVideoPlay.backButton.setVisibility(View.GONE);
// jcVideoPlay.titleTextView.setVisibility(View.GONE);
// jcVideoPlay.tinyBackImageView.setVisibility(View.GONE);
// //设置视频占位图
// ImageLoader.load(getView().getVideoInfo().pic, jcVideoPlay.thumbImageView, 320);
// }
//
// private void playVideo() {
// if (videoRes == null) return;
// //
// jcVideoPlay.setUp(videoRes.getVideoUrl(), JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, videoRes.title);
// //自动播放
// jcVideoPlay.startPlayLogic();
// //点击全屏_禁用重力感应
// JCVideoPlayer.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
// }
//
// private void setIntro() {
// String dir = "导演:" + StringUtils.removeOtherCode(videoRes.director);
// String act = "主演:" + StringUtils.removeOtherCode(videoRes.actors);
// String des = dir + "\n" + act + "\n" + "简介:" + StringUtils.removeOtherCode(videoRes.description);
// tvExpand.setText(des);
// }
//
// private void setListView() {
// adapter = new VideoMoreAdapter(getView());
// getView().getListView().setAdapter(adapter);
// GridLayoutManager manager = new GridLayoutManager(getView(), 3);
// manager.setSpanSizeLookup(adapter.obtainGridSpanSizeLookUp(3));
// getView().getListView().setLayoutManager(manager);
// SpaceDecoration decoration = new SpaceDecoration(JUtils.dip2px(8));
// decoration.setPaddingEdgeSide(true);
// decoration.setPaddingStart(true);
// decoration.setPaddingHeaderFooter(true);
// getView().getListView().addItemDecoration(decoration);
// //
// headView = LayoutInflater.from(getView()).inflate(R.layout.include_intro, null);
// tvExpand = ButterKnife.findById(headView, R.id.tv_expand);
// adapter.addHeader(new RecyclerArrayAdapter.ItemView() {
// @Override
// public View onCreateView(ViewGroup parent) {
// return headView;
// }
//
// @Override
// public void onBindView(View headerView) {
//
// }
// });
// //
// adapter.setOnItemClickListener(position -> {
// VideoInfoActivity.actionStart(getView(), adapter.getItem(position));
// getView().finish();
// });
// }
//
// private void initData() {
// rxSubscription = HttpUtils.getInstance().getVideoServer().getVideoInfo(getView().getVideoInfo().dataId)
// .compose(RxUtil.rxSchedulerHelper())
// .compose(RxUtil.handleResult())
// .subscribe(videoRes -> {
// VideoInfoPresenter.this.videoRes = videoRes;
// //标题
// getView().getSupportActionBar().setTitle(videoRes.title);
// //
// playVideo();
// //
// setIntro();
// //
// if (videoRes.list.size() > 1)
// adapter.addAll(videoRes.list.get(1).childList);
// else
// adapter.addAll(videoRes.list.get(0).childList);
// },
// throwable -> {
// JUtils.Toast("加载失败");
// },
// () -> {
// //加载完成...
// });
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// rxSubscription.unsubscribe();
// }
// }
| import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.BeamBaseActivity;
import com.jude.easyrecyclerview.EasyRecyclerView;
import com.zmj.qvod.R;
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.presenter.VideoInfoPresenter;
import butterknife.BindView;
import butterknife.ButterKnife;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard; | package com.zmj.qvod.view.activity;
/**
* Created by matt on 2017/3/24.
*/
@RequiresPresenter(VideoInfoPresenter.class)
public class VideoInfoActivity extends BeamBaseActivity<VideoInfoPresenter> {
@BindView(R.id.jc_video_play)
JCVideoPlayerStandard jcVideoPlay;
@BindView(R.id.ev_more)
EasyRecyclerView evMore;
| // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/presenter/VideoInfoPresenter.java
// public class VideoInfoPresenter extends BeamBasePresenter<VideoInfoActivity> {
//
// private JCVideoPlayerStandard jcVideoPlay;
//
// private VideoRes videoRes;
// private Subscription rxSubscription;
// private VideoMoreAdapter adapter;
// private View headView;
//
// TextViewExpandableAnimation tvExpand;
//
// @Override
// protected void onCreateView(@NonNull VideoInfoActivity view) {
// super.onCreateView(view);
// getView().getSupportActionBar().setTitle(getView().getVideoInfo().title);
//
// initVideoPlay();
//
// setListView();
//
// initData();
//
// }
//
// private void initVideoPlay() {
// jcVideoPlay = getView().getJcVideoPlay();
// //
// jcVideoPlay.thumbImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
// jcVideoPlay.backButton.setVisibility(View.GONE);
// jcVideoPlay.titleTextView.setVisibility(View.GONE);
// jcVideoPlay.tinyBackImageView.setVisibility(View.GONE);
// //设置视频占位图
// ImageLoader.load(getView().getVideoInfo().pic, jcVideoPlay.thumbImageView, 320);
// }
//
// private void playVideo() {
// if (videoRes == null) return;
// //
// jcVideoPlay.setUp(videoRes.getVideoUrl(), JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, videoRes.title);
// //自动播放
// jcVideoPlay.startPlayLogic();
// //点击全屏_禁用重力感应
// JCVideoPlayer.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
// }
//
// private void setIntro() {
// String dir = "导演:" + StringUtils.removeOtherCode(videoRes.director);
// String act = "主演:" + StringUtils.removeOtherCode(videoRes.actors);
// String des = dir + "\n" + act + "\n" + "简介:" + StringUtils.removeOtherCode(videoRes.description);
// tvExpand.setText(des);
// }
//
// private void setListView() {
// adapter = new VideoMoreAdapter(getView());
// getView().getListView().setAdapter(adapter);
// GridLayoutManager manager = new GridLayoutManager(getView(), 3);
// manager.setSpanSizeLookup(adapter.obtainGridSpanSizeLookUp(3));
// getView().getListView().setLayoutManager(manager);
// SpaceDecoration decoration = new SpaceDecoration(JUtils.dip2px(8));
// decoration.setPaddingEdgeSide(true);
// decoration.setPaddingStart(true);
// decoration.setPaddingHeaderFooter(true);
// getView().getListView().addItemDecoration(decoration);
// //
// headView = LayoutInflater.from(getView()).inflate(R.layout.include_intro, null);
// tvExpand = ButterKnife.findById(headView, R.id.tv_expand);
// adapter.addHeader(new RecyclerArrayAdapter.ItemView() {
// @Override
// public View onCreateView(ViewGroup parent) {
// return headView;
// }
//
// @Override
// public void onBindView(View headerView) {
//
// }
// });
// //
// adapter.setOnItemClickListener(position -> {
// VideoInfoActivity.actionStart(getView(), adapter.getItem(position));
// getView().finish();
// });
// }
//
// private void initData() {
// rxSubscription = HttpUtils.getInstance().getVideoServer().getVideoInfo(getView().getVideoInfo().dataId)
// .compose(RxUtil.rxSchedulerHelper())
// .compose(RxUtil.handleResult())
// .subscribe(videoRes -> {
// VideoInfoPresenter.this.videoRes = videoRes;
// //标题
// getView().getSupportActionBar().setTitle(videoRes.title);
// //
// playVideo();
// //
// setIntro();
// //
// if (videoRes.list.size() > 1)
// adapter.addAll(videoRes.list.get(1).childList);
// else
// adapter.addAll(videoRes.list.get(0).childList);
// },
// throwable -> {
// JUtils.Toast("加载失败");
// },
// () -> {
// //加载完成...
// });
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// rxSubscription.unsubscribe();
// }
// }
// Path: app/src/main/java/com/zmj/qvod/view/activity/VideoInfoActivity.java
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.BeamBaseActivity;
import com.jude.easyrecyclerview.EasyRecyclerView;
import com.zmj.qvod.R;
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.presenter.VideoInfoPresenter;
import butterknife.BindView;
import butterknife.ButterKnife;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;
package com.zmj.qvod.view.activity;
/**
* Created by matt on 2017/3/24.
*/
@RequiresPresenter(VideoInfoPresenter.class)
public class VideoInfoActivity extends BeamBaseActivity<VideoInfoPresenter> {
@BindView(R.id.jc_video_play)
JCVideoPlayerStandard jcVideoPlay;
@BindView(R.id.ev_more)
EasyRecyclerView evMore;
| private VideoInfo videoInfo; |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/VideoMoreAdapter.java | // Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/VideoMoreViewHolder.java
// public class VideoMoreViewHolder extends BaseViewHolder<VideoInfo> {
//
// private ImageView ivVideo;
// private TextView tvTitle;
//
// public VideoMoreViewHolder(ViewGroup parent) {
// super(parent, R.layout.item_video_info);
// ivVideo = $(R.id.iv_video_info);
// tvTitle = $(R.id.tv_title_info);
// }
//
// @Override
// public void setData(VideoInfo data) {
// tvTitle.setText(data.title);
// ImageLoader.load(data.pic, ivVideo, 200);
// }
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
| import android.content.Context;
import android.view.ViewGroup;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zmj.qvod.adapter.viewholder.VideoMoreViewHolder;
import com.zmj.qvod.module.bean.VideoInfo; | package com.zmj.qvod.adapter;
/**
* Created by matt on 2017/3/30.
*/
public class VideoMoreAdapter extends RecyclerArrayAdapter<VideoInfo> {
public VideoMoreAdapter(Context context) {
super(context);
}
@Override
public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { | // Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/VideoMoreViewHolder.java
// public class VideoMoreViewHolder extends BaseViewHolder<VideoInfo> {
//
// private ImageView ivVideo;
// private TextView tvTitle;
//
// public VideoMoreViewHolder(ViewGroup parent) {
// super(parent, R.layout.item_video_info);
// ivVideo = $(R.id.iv_video_info);
// tvTitle = $(R.id.tv_title_info);
// }
//
// @Override
// public void setData(VideoInfo data) {
// tvTitle.setText(data.title);
// ImageLoader.load(data.pic, ivVideo, 200);
// }
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/VideoMoreAdapter.java
import android.content.Context;
import android.view.ViewGroup;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zmj.qvod.adapter.viewholder.VideoMoreViewHolder;
import com.zmj.qvod.module.bean.VideoInfo;
package com.zmj.qvod.adapter;
/**
* Created by matt on 2017/3/30.
*/
public class VideoMoreAdapter extends RecyclerArrayAdapter<VideoInfo> {
public VideoMoreAdapter(Context context) {
super(context);
}
@Override
public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { | return new VideoMoreViewHolder(parent); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/viewholder/VideoListViewHolder.java | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoType.java
// public class VideoType {
// public String title;
// public String moreURL;
// public String pic;
// public String dataId;
// public String airTime;
// public String score;
// public String description;
// public String msg;
// public String phoneNumber;
// public String userPic;
// public String time;
// public String likeNum;
// public
// @SerializedName("childList")
// List<VideoInfo> childList;
// }
| import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.VideoType; | package com.zmj.qvod.adapter.viewholder;
/**
* Created by matt on 2017/3/20.
*/
public class VideoListViewHolder extends BaseViewHolder<VideoType> {
private ImageView ivVideo;
private TextView tvTitle;
public VideoListViewHolder(ViewGroup parent) {
super(parent, R.layout.item_video_info);
ivVideo = $(R.id.iv_video_info);
tvTitle = $(R.id.tv_title_info);
}
@Override
public void setData(VideoType data) {
tvTitle.setText(data.title); | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoType.java
// public class VideoType {
// public String title;
// public String moreURL;
// public String pic;
// public String dataId;
// public String airTime;
// public String score;
// public String description;
// public String msg;
// public String phoneNumber;
// public String userPic;
// public String time;
// public String likeNum;
// public
// @SerializedName("childList")
// List<VideoInfo> childList;
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/VideoListViewHolder.java
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.VideoType;
package com.zmj.qvod.adapter.viewholder;
/**
* Created by matt on 2017/3/20.
*/
public class VideoListViewHolder extends BaseViewHolder<VideoType> {
private ImageView ivVideo;
private TextView tvTitle;
public VideoListViewHolder(ViewGroup parent) {
super(parent, R.layout.item_video_info);
ivVideo = $(R.id.iv_video_info);
tvTitle = $(R.id.tv_title_info);
}
@Override
public void setData(VideoType data) {
tvTitle.setText(data.title); | ImageLoader.load(data.pic, ivVideo, 200); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/utils/RxUtil.java | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoHttpResponse.java
// public class VideoHttpResponse<T> {
//
// private int code;
// private String msg;
// T ret;
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getRet() {
// return ret;
// }
//
// public void setRet(T ret) {
// this.ret = ret;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/service/ApiException.java
// public class ApiException extends Exception {
// public ApiException(String msg)
// {
// super(msg);
// }
// }
| import android.text.TextUtils;
import com.zmj.qvod.module.bean.VideoHttpResponse;
import com.zmj.qvod.module.service.ApiException;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers; | package com.zmj.qvod.utils;
/**
* Description: RxUtil
* Creator: yxc
* date: 2016/9/21 18:47
*/
public class RxUtil {
/**
* 统一线程处理
*
* @param <T>
* @return
*/
public static <T> Observable.Transformer<T, T> rxSchedulerHelper() { //compose简化线程
return new Observable.Transformer<T, T>() {
@Override
public Observable<T> call(Observable<T> observable) {
return observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
};
}
/**
* 统一返回结果处理
*
* @param <T>
* @return
*/ | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoHttpResponse.java
// public class VideoHttpResponse<T> {
//
// private int code;
// private String msg;
// T ret;
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getRet() {
// return ret;
// }
//
// public void setRet(T ret) {
// this.ret = ret;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/service/ApiException.java
// public class ApiException extends Exception {
// public ApiException(String msg)
// {
// super(msg);
// }
// }
// Path: app/src/main/java/com/zmj/qvod/utils/RxUtil.java
import android.text.TextUtils;
import com.zmj.qvod.module.bean.VideoHttpResponse;
import com.zmj.qvod.module.service.ApiException;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
package com.zmj.qvod.utils;
/**
* Description: RxUtil
* Creator: yxc
* date: 2016/9/21 18:47
*/
public class RxUtil {
/**
* 统一线程处理
*
* @param <T>
* @return
*/
public static <T> Observable.Transformer<T, T> rxSchedulerHelper() { //compose简化线程
return new Observable.Transformer<T, T>() {
@Override
public Observable<T> call(Observable<T> observable) {
return observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
};
}
/**
* 统一返回结果处理
*
* @param <T>
* @return
*/ | public static <T> Observable.Transformer<VideoHttpResponse<T>, T> handleResult() { //compose判断结果 |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/utils/RxUtil.java | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoHttpResponse.java
// public class VideoHttpResponse<T> {
//
// private int code;
// private String msg;
// T ret;
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getRet() {
// return ret;
// }
//
// public void setRet(T ret) {
// this.ret = ret;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/service/ApiException.java
// public class ApiException extends Exception {
// public ApiException(String msg)
// {
// super(msg);
// }
// }
| import android.text.TextUtils;
import com.zmj.qvod.module.bean.VideoHttpResponse;
import com.zmj.qvod.module.service.ApiException;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers; | package com.zmj.qvod.utils;
/**
* Description: RxUtil
* Creator: yxc
* date: 2016/9/21 18:47
*/
public class RxUtil {
/**
* 统一线程处理
*
* @param <T>
* @return
*/
public static <T> Observable.Transformer<T, T> rxSchedulerHelper() { //compose简化线程
return new Observable.Transformer<T, T>() {
@Override
public Observable<T> call(Observable<T> observable) {
return observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
};
}
/**
* 统一返回结果处理
*
* @param <T>
* @return
*/
public static <T> Observable.Transformer<VideoHttpResponse<T>, T> handleResult() { //compose判断结果
return new Observable.Transformer<VideoHttpResponse<T>, T>() {
@Override
public Observable<T> call(Observable<VideoHttpResponse<T>> httpResponseObservable) {
return httpResponseObservable.flatMap(new Func1<VideoHttpResponse<T>, Observable<T>>() {
@Override
public Observable<T> call(VideoHttpResponse<T> videoHttpResponse) {
if (videoHttpResponse.getCode() == 200) {
return createData(videoHttpResponse.getRet());
} else if (!TextUtils.isEmpty(videoHttpResponse.getMsg())) { | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoHttpResponse.java
// public class VideoHttpResponse<T> {
//
// private int code;
// private String msg;
// T ret;
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getRet() {
// return ret;
// }
//
// public void setRet(T ret) {
// this.ret = ret;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/service/ApiException.java
// public class ApiException extends Exception {
// public ApiException(String msg)
// {
// super(msg);
// }
// }
// Path: app/src/main/java/com/zmj/qvod/utils/RxUtil.java
import android.text.TextUtils;
import com.zmj.qvod.module.bean.VideoHttpResponse;
import com.zmj.qvod.module.service.ApiException;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
package com.zmj.qvod.utils;
/**
* Description: RxUtil
* Creator: yxc
* date: 2016/9/21 18:47
*/
public class RxUtil {
/**
* 统一线程处理
*
* @param <T>
* @return
*/
public static <T> Observable.Transformer<T, T> rxSchedulerHelper() { //compose简化线程
return new Observable.Transformer<T, T>() {
@Override
public Observable<T> call(Observable<T> observable) {
return observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
};
}
/**
* 统一返回结果处理
*
* @param <T>
* @return
*/
public static <T> Observable.Transformer<VideoHttpResponse<T>, T> handleResult() { //compose判断结果
return new Observable.Transformer<VideoHttpResponse<T>, T>() {
@Override
public Observable<T> call(Observable<VideoHttpResponse<T>> httpResponseObservable) {
return httpResponseObservable.flatMap(new Func1<VideoHttpResponse<T>, Observable<T>>() {
@Override
public Observable<T> call(VideoHttpResponse<T> videoHttpResponse) {
if (videoHttpResponse.getCode() == 200) {
return createData(videoHttpResponse.getRet());
} else if (!TextUtils.isEmpty(videoHttpResponse.getMsg())) { | return Observable.error(new ApiException("*" + videoHttpResponse.getMsg())); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/utils/BeanUtil.java | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoType.java
// public class VideoType {
// public String title;
// public String moreURL;
// public String pic;
// public String dataId;
// public String airTime;
// public String score;
// public String description;
// public String msg;
// public String phoneNumber;
// public String userPic;
// public String time;
// public String likeNum;
// public
// @SerializedName("childList")
// List<VideoInfo> childList;
// }
| import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.module.bean.VideoRes;
import com.zmj.qvod.module.bean.VideoType; | package com.zmj.qvod.utils;
/**
* Description: BeanUtil
* Creator: yxc
* date: 2016/9/21 14:39
*/
public class BeanUtil {
public static VideoInfo VideoType2VideoInfo(VideoType videoType) {
VideoInfo videoInfo = new VideoInfo();
videoInfo.title = videoType.title;
videoInfo.dataId = videoType.dataId;
videoInfo.pic = videoType.pic;
videoInfo.airTime = videoType.airTime;
videoInfo.score = videoType.score;
return videoInfo;
}
| // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoType.java
// public class VideoType {
// public String title;
// public String moreURL;
// public String pic;
// public String dataId;
// public String airTime;
// public String score;
// public String description;
// public String msg;
// public String phoneNumber;
// public String userPic;
// public String time;
// public String likeNum;
// public
// @SerializedName("childList")
// List<VideoInfo> childList;
// }
// Path: app/src/main/java/com/zmj/qvod/utils/BeanUtil.java
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.module.bean.VideoRes;
import com.zmj.qvod.module.bean.VideoType;
package com.zmj.qvod.utils;
/**
* Description: BeanUtil
* Creator: yxc
* date: 2016/9/21 14:39
*/
public class BeanUtil {
public static VideoInfo VideoType2VideoInfo(VideoType videoType) {
VideoInfo videoInfo = new VideoInfo();
videoInfo.title = videoType.title;
videoInfo.dataId = videoType.dataId;
videoInfo.pic = videoType.pic;
videoInfo.airTime = videoType.airTime;
videoInfo.score = videoType.score;
return videoInfo;
}
| public static VideoRes VideoInfo2VideoRes(VideoInfo videoInfo) { |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/presenter/MineFragmentPresenter.java | // Path: app/src/main/java/com/zmj/qvod/adapter/MyFragmentPagerAdapter.java
// public class MyFragmentPagerAdapter<T> extends FragmentPagerAdapter {
//
// private List<T> mFragment;
// private List<String> mTitleList;
//
// /**
// * 普通,主页使用
// */
// public MyFragmentPagerAdapter(FragmentManager fm, List<T> mFragment) {
// super(fm);
// this.mFragment = mFragment;
// }
//
// /**
// * 接收传递的标题
// */
// public MyFragmentPagerAdapter(FragmentManager fm, List<T> mFragment, List<String> mTitleList) {
// super(fm);
// this.mFragment = mFragment;
// this.mTitleList = mTitleList;
// }
//
// @Override
// public Fragment getItem(int position) {
// return (Fragment) mFragment.get(position);
// }
//
// @Override
// public int getCount() {
// return mFragment.size();
// }
//
// @Override
// public void destroyItem(ViewGroup container, int position, Object object) {
// super.destroyItem(container, position, object);
// }
//
// /**
// * 首页显示title,每日推荐等..
// * 若有问题,移到对应单独页面
// */
// @Override
// public CharSequence getPageTitle(int position) {
// if (mTitleList != null) {
// return mTitleList.get(position);
// } else {
// return "";
// }
// }
//
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/fragment/MineFragment.java
// @RequiresPresenter(MineFragmentPresenter.class)
// public class MineFragment extends BeamFragment<MineFragmentPresenter> {
//
// @BindView(R.id.tl_mine)
// public TabLayout tlMine;
// @BindView(R.id.vp_mine)
// public ViewPager vpMine;
//
// private Unbinder unbinder;
//
// public static MineFragment newInstance() {
// return new MineFragment();
// }
//
// @Nullable
// @Override
// public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// View view = inflater.inflate(R.layout.fragment_mine, null);
// unbinder = ButterKnife.bind(this, view);
// return view;
// }
//
// @Override
// public void onDestroyView() {
// super.onDestroyView();
// unbinder.unbind();
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/fragment/PictureFragment.java
// @RequiresPresenter(PictureFragmentPresenter.class)
// public class PictureFragment extends BeamListFragment<PictureFragmentPresenter, PicBean.ItemsBean> {
//
//
// public static PictureFragment newInstance(String tab) {
// PictureFragment pictureFragment = new PictureFragment();
// Bundle bundle = new Bundle();
// bundle.putString("tab", tab);
// pictureFragment.setArguments(bundle);
// return pictureFragment;
// }
//
// @Override
// public ListConfig getConfig() {
// return Constant.getLoadMoreConfig();
// }
//
// @Override
// public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
// return new PictureViewHolder(parent);
// }
// }
| import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import com.jude.beam.expansion.BeamBasePresenter;
import com.zmj.qvod.R;
import com.zmj.qvod.adapter.MyFragmentPagerAdapter;
import com.zmj.qvod.view.fragment.MineFragment;
import com.zmj.qvod.view.fragment.PictureFragment;
import java.util.ArrayList;
import java.util.List; | package com.zmj.qvod.presenter;
/**
* Created by matt on 2017/4/18.
*/
public class MineFragmentPresenter extends BeamBasePresenter<MineFragment> {
@Override
protected void onCreateView(@NonNull MineFragment view) {
super.onCreateView(view);
initView();
}
private void initView() {
List<Fragment> fragments = new ArrayList<>();
List<String> titles = new ArrayList<>();
//
String[] tabs = getView().getResources().getStringArray(R.array.tab);
//titles = Arrays.asList(tabs);
for (String tab : tabs) { | // Path: app/src/main/java/com/zmj/qvod/adapter/MyFragmentPagerAdapter.java
// public class MyFragmentPagerAdapter<T> extends FragmentPagerAdapter {
//
// private List<T> mFragment;
// private List<String> mTitleList;
//
// /**
// * 普通,主页使用
// */
// public MyFragmentPagerAdapter(FragmentManager fm, List<T> mFragment) {
// super(fm);
// this.mFragment = mFragment;
// }
//
// /**
// * 接收传递的标题
// */
// public MyFragmentPagerAdapter(FragmentManager fm, List<T> mFragment, List<String> mTitleList) {
// super(fm);
// this.mFragment = mFragment;
// this.mTitleList = mTitleList;
// }
//
// @Override
// public Fragment getItem(int position) {
// return (Fragment) mFragment.get(position);
// }
//
// @Override
// public int getCount() {
// return mFragment.size();
// }
//
// @Override
// public void destroyItem(ViewGroup container, int position, Object object) {
// super.destroyItem(container, position, object);
// }
//
// /**
// * 首页显示title,每日推荐等..
// * 若有问题,移到对应单独页面
// */
// @Override
// public CharSequence getPageTitle(int position) {
// if (mTitleList != null) {
// return mTitleList.get(position);
// } else {
// return "";
// }
// }
//
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/fragment/MineFragment.java
// @RequiresPresenter(MineFragmentPresenter.class)
// public class MineFragment extends BeamFragment<MineFragmentPresenter> {
//
// @BindView(R.id.tl_mine)
// public TabLayout tlMine;
// @BindView(R.id.vp_mine)
// public ViewPager vpMine;
//
// private Unbinder unbinder;
//
// public static MineFragment newInstance() {
// return new MineFragment();
// }
//
// @Nullable
// @Override
// public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// View view = inflater.inflate(R.layout.fragment_mine, null);
// unbinder = ButterKnife.bind(this, view);
// return view;
// }
//
// @Override
// public void onDestroyView() {
// super.onDestroyView();
// unbinder.unbind();
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/fragment/PictureFragment.java
// @RequiresPresenter(PictureFragmentPresenter.class)
// public class PictureFragment extends BeamListFragment<PictureFragmentPresenter, PicBean.ItemsBean> {
//
//
// public static PictureFragment newInstance(String tab) {
// PictureFragment pictureFragment = new PictureFragment();
// Bundle bundle = new Bundle();
// bundle.putString("tab", tab);
// pictureFragment.setArguments(bundle);
// return pictureFragment;
// }
//
// @Override
// public ListConfig getConfig() {
// return Constant.getLoadMoreConfig();
// }
//
// @Override
// public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
// return new PictureViewHolder(parent);
// }
// }
// Path: app/src/main/java/com/zmj/qvod/presenter/MineFragmentPresenter.java
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import com.jude.beam.expansion.BeamBasePresenter;
import com.zmj.qvod.R;
import com.zmj.qvod.adapter.MyFragmentPagerAdapter;
import com.zmj.qvod.view.fragment.MineFragment;
import com.zmj.qvod.view.fragment.PictureFragment;
import java.util.ArrayList;
import java.util.List;
package com.zmj.qvod.presenter;
/**
* Created by matt on 2017/4/18.
*/
public class MineFragmentPresenter extends BeamBasePresenter<MineFragment> {
@Override
protected void onCreateView(@NonNull MineFragment view) {
super.onCreateView(view);
initView();
}
private void initView() {
List<Fragment> fragments = new ArrayList<>();
List<String> titles = new ArrayList<>();
//
String[] tabs = getView().getResources().getStringArray(R.array.tab);
//titles = Arrays.asList(tabs);
for (String tab : tabs) { | fragments.add(PictureFragment.newInstance(tab)); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/presenter/MineFragmentPresenter.java | // Path: app/src/main/java/com/zmj/qvod/adapter/MyFragmentPagerAdapter.java
// public class MyFragmentPagerAdapter<T> extends FragmentPagerAdapter {
//
// private List<T> mFragment;
// private List<String> mTitleList;
//
// /**
// * 普通,主页使用
// */
// public MyFragmentPagerAdapter(FragmentManager fm, List<T> mFragment) {
// super(fm);
// this.mFragment = mFragment;
// }
//
// /**
// * 接收传递的标题
// */
// public MyFragmentPagerAdapter(FragmentManager fm, List<T> mFragment, List<String> mTitleList) {
// super(fm);
// this.mFragment = mFragment;
// this.mTitleList = mTitleList;
// }
//
// @Override
// public Fragment getItem(int position) {
// return (Fragment) mFragment.get(position);
// }
//
// @Override
// public int getCount() {
// return mFragment.size();
// }
//
// @Override
// public void destroyItem(ViewGroup container, int position, Object object) {
// super.destroyItem(container, position, object);
// }
//
// /**
// * 首页显示title,每日推荐等..
// * 若有问题,移到对应单独页面
// */
// @Override
// public CharSequence getPageTitle(int position) {
// if (mTitleList != null) {
// return mTitleList.get(position);
// } else {
// return "";
// }
// }
//
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/fragment/MineFragment.java
// @RequiresPresenter(MineFragmentPresenter.class)
// public class MineFragment extends BeamFragment<MineFragmentPresenter> {
//
// @BindView(R.id.tl_mine)
// public TabLayout tlMine;
// @BindView(R.id.vp_mine)
// public ViewPager vpMine;
//
// private Unbinder unbinder;
//
// public static MineFragment newInstance() {
// return new MineFragment();
// }
//
// @Nullable
// @Override
// public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// View view = inflater.inflate(R.layout.fragment_mine, null);
// unbinder = ButterKnife.bind(this, view);
// return view;
// }
//
// @Override
// public void onDestroyView() {
// super.onDestroyView();
// unbinder.unbind();
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/fragment/PictureFragment.java
// @RequiresPresenter(PictureFragmentPresenter.class)
// public class PictureFragment extends BeamListFragment<PictureFragmentPresenter, PicBean.ItemsBean> {
//
//
// public static PictureFragment newInstance(String tab) {
// PictureFragment pictureFragment = new PictureFragment();
// Bundle bundle = new Bundle();
// bundle.putString("tab", tab);
// pictureFragment.setArguments(bundle);
// return pictureFragment;
// }
//
// @Override
// public ListConfig getConfig() {
// return Constant.getLoadMoreConfig();
// }
//
// @Override
// public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
// return new PictureViewHolder(parent);
// }
// }
| import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import com.jude.beam.expansion.BeamBasePresenter;
import com.zmj.qvod.R;
import com.zmj.qvod.adapter.MyFragmentPagerAdapter;
import com.zmj.qvod.view.fragment.MineFragment;
import com.zmj.qvod.view.fragment.PictureFragment;
import java.util.ArrayList;
import java.util.List; | package com.zmj.qvod.presenter;
/**
* Created by matt on 2017/4/18.
*/
public class MineFragmentPresenter extends BeamBasePresenter<MineFragment> {
@Override
protected void onCreateView(@NonNull MineFragment view) {
super.onCreateView(view);
initView();
}
private void initView() {
List<Fragment> fragments = new ArrayList<>();
List<String> titles = new ArrayList<>();
//
String[] tabs = getView().getResources().getStringArray(R.array.tab);
//titles = Arrays.asList(tabs);
for (String tab : tabs) {
fragments.add(PictureFragment.newInstance(tab));
titles.add(tab);
} | // Path: app/src/main/java/com/zmj/qvod/adapter/MyFragmentPagerAdapter.java
// public class MyFragmentPagerAdapter<T> extends FragmentPagerAdapter {
//
// private List<T> mFragment;
// private List<String> mTitleList;
//
// /**
// * 普通,主页使用
// */
// public MyFragmentPagerAdapter(FragmentManager fm, List<T> mFragment) {
// super(fm);
// this.mFragment = mFragment;
// }
//
// /**
// * 接收传递的标题
// */
// public MyFragmentPagerAdapter(FragmentManager fm, List<T> mFragment, List<String> mTitleList) {
// super(fm);
// this.mFragment = mFragment;
// this.mTitleList = mTitleList;
// }
//
// @Override
// public Fragment getItem(int position) {
// return (Fragment) mFragment.get(position);
// }
//
// @Override
// public int getCount() {
// return mFragment.size();
// }
//
// @Override
// public void destroyItem(ViewGroup container, int position, Object object) {
// super.destroyItem(container, position, object);
// }
//
// /**
// * 首页显示title,每日推荐等..
// * 若有问题,移到对应单独页面
// */
// @Override
// public CharSequence getPageTitle(int position) {
// if (mTitleList != null) {
// return mTitleList.get(position);
// } else {
// return "";
// }
// }
//
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/fragment/MineFragment.java
// @RequiresPresenter(MineFragmentPresenter.class)
// public class MineFragment extends BeamFragment<MineFragmentPresenter> {
//
// @BindView(R.id.tl_mine)
// public TabLayout tlMine;
// @BindView(R.id.vp_mine)
// public ViewPager vpMine;
//
// private Unbinder unbinder;
//
// public static MineFragment newInstance() {
// return new MineFragment();
// }
//
// @Nullable
// @Override
// public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// View view = inflater.inflate(R.layout.fragment_mine, null);
// unbinder = ButterKnife.bind(this, view);
// return view;
// }
//
// @Override
// public void onDestroyView() {
// super.onDestroyView();
// unbinder.unbind();
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/fragment/PictureFragment.java
// @RequiresPresenter(PictureFragmentPresenter.class)
// public class PictureFragment extends BeamListFragment<PictureFragmentPresenter, PicBean.ItemsBean> {
//
//
// public static PictureFragment newInstance(String tab) {
// PictureFragment pictureFragment = new PictureFragment();
// Bundle bundle = new Bundle();
// bundle.putString("tab", tab);
// pictureFragment.setArguments(bundle);
// return pictureFragment;
// }
//
// @Override
// public ListConfig getConfig() {
// return Constant.getLoadMoreConfig();
// }
//
// @Override
// public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
// return new PictureViewHolder(parent);
// }
// }
// Path: app/src/main/java/com/zmj/qvod/presenter/MineFragmentPresenter.java
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import com.jude.beam.expansion.BeamBasePresenter;
import com.zmj.qvod.R;
import com.zmj.qvod.adapter.MyFragmentPagerAdapter;
import com.zmj.qvod.view.fragment.MineFragment;
import com.zmj.qvod.view.fragment.PictureFragment;
import java.util.ArrayList;
import java.util.List;
package com.zmj.qvod.presenter;
/**
* Created by matt on 2017/4/18.
*/
public class MineFragmentPresenter extends BeamBasePresenter<MineFragment> {
@Override
protected void onCreateView(@NonNull MineFragment view) {
super.onCreateView(view);
initView();
}
private void initView() {
List<Fragment> fragments = new ArrayList<>();
List<String> titles = new ArrayList<>();
//
String[] tabs = getView().getResources().getStringArray(R.array.tab);
//titles = Arrays.asList(tabs);
for (String tab : tabs) {
fragments.add(PictureFragment.newInstance(tab));
titles.add(tab);
} | MyFragmentPagerAdapter pagerAdapter = new MyFragmentPagerAdapter(getView().getFragmentManager(), fragments, titles); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/module/recommend/RollViewPagerItemView.java | // Path: app/src/main/java/com/zmj/qvod/adapter/ImageLoopAdapter.java
// public class ImageLoopAdapter extends LoopPagerAdapter {
//
// List<VideoInfo> banners;
//
// public ImageLoopAdapter(RollPagerView viewPager) {
// super(viewPager);
// }
//
// @Override
// public View getView(ViewGroup container, int position) {
// View views = LayoutInflater.from(container.getContext()).inflate(R.layout.view_roll_viewpager, null);
// ImageView imageView = (ImageView) views.findViewById(R.id.iv_roll_viewpager);
// imageView.setScaleType(ImageView.ScaleType.FIT_XY);
// ImageLoader.load(banners.get(position).pic, imageView, 320);
// imageView.setOnClickListener(view -> {
// VideoInfoActivity.actionStart(container.getContext(), banners.get(position));
// });
// return views;
// }
//
// @Override
// public int getRealCount() {
// if (banners != null) {
// return banners.size();
// } else {
// return 0;
// }
// }
//
// public void setBanners(List<VideoInfo> banners) {
// this.banners = banners;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/app/VideoApplication.java
// public class VideoApplication extends Application {
//
// private static VideoApplication videoApplication;
//
// public static VideoApplication getInstance() {
// if (videoApplication == null) {
// synchronized (VideoApplication.class) {
// if (videoApplication == null) {
// videoApplication = new VideoApplication();
// }
// }
// }
// return videoApplication;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// videoApplication = this;
// HttpUtils.getInstance().setContext(this);
// JUtils.initialize(this);
// JUtils.setDebug(true, "video");
// initLoading();
// }
//
// private void initLoading() {
// LoadingLayout.getConfig()
// .setErrorText("出错啦~请稍后重试!")
// .setEmptyText("抱歉,暂无数据")
// .setNoNetworkText("无网络连接,请检查您的网络···")
// .setErrorImage(R.drawable.ic_empty_icon)
// .setEmptyImage(R.drawable.ic_empty_icon)
// .setNoNetworkImage(R.drawable.ic_no_network)
// .setAllTipTextColor(R.color.colorTabText)
// .setAllTipTextSize(14)
// .setReloadButtonText("点我重试哦")
// .setReloadButtonTextSize(14)
// .setReloadButtonTextColor(R.color.colorTabText)
// .setReloadButtonWidthAndHeight(150, 40)
// .setAllPageBackgroundColor(R.color.colorBackground)
// .setLoadingPageLayout(R.layout.default_loading_page);
// }
//
// private VideoRes videoRes;
//
// public VideoRes getVideoRes() {
// return videoRes;
// }
//
// public void setVideoRes(VideoRes videoRes) {
// this.videoRes = videoRes;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
| import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.jude.easyrecyclerview.swipe.SwipeRefreshLayout;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.hintview.IconHintView;
import com.jude.utils.JUtils;
import com.zmj.qvod.R;
import com.zmj.qvod.adapter.ImageLoopAdapter;
import com.zmj.qvod.app.VideoApplication;
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.module.bean.VideoRes;
import java.util.ArrayList;
import java.util.List; | package com.zmj.qvod.module.recommend;
/**
* Created by matt on 2017/3/15.
*/
public class RollViewPagerItemView implements RecyclerArrayAdapter.ItemView {
private RollPagerView rollPagerView;
private Context mContext; | // Path: app/src/main/java/com/zmj/qvod/adapter/ImageLoopAdapter.java
// public class ImageLoopAdapter extends LoopPagerAdapter {
//
// List<VideoInfo> banners;
//
// public ImageLoopAdapter(RollPagerView viewPager) {
// super(viewPager);
// }
//
// @Override
// public View getView(ViewGroup container, int position) {
// View views = LayoutInflater.from(container.getContext()).inflate(R.layout.view_roll_viewpager, null);
// ImageView imageView = (ImageView) views.findViewById(R.id.iv_roll_viewpager);
// imageView.setScaleType(ImageView.ScaleType.FIT_XY);
// ImageLoader.load(banners.get(position).pic, imageView, 320);
// imageView.setOnClickListener(view -> {
// VideoInfoActivity.actionStart(container.getContext(), banners.get(position));
// });
// return views;
// }
//
// @Override
// public int getRealCount() {
// if (banners != null) {
// return banners.size();
// } else {
// return 0;
// }
// }
//
// public void setBanners(List<VideoInfo> banners) {
// this.banners = banners;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/app/VideoApplication.java
// public class VideoApplication extends Application {
//
// private static VideoApplication videoApplication;
//
// public static VideoApplication getInstance() {
// if (videoApplication == null) {
// synchronized (VideoApplication.class) {
// if (videoApplication == null) {
// videoApplication = new VideoApplication();
// }
// }
// }
// return videoApplication;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// videoApplication = this;
// HttpUtils.getInstance().setContext(this);
// JUtils.initialize(this);
// JUtils.setDebug(true, "video");
// initLoading();
// }
//
// private void initLoading() {
// LoadingLayout.getConfig()
// .setErrorText("出错啦~请稍后重试!")
// .setEmptyText("抱歉,暂无数据")
// .setNoNetworkText("无网络连接,请检查您的网络···")
// .setErrorImage(R.drawable.ic_empty_icon)
// .setEmptyImage(R.drawable.ic_empty_icon)
// .setNoNetworkImage(R.drawable.ic_no_network)
// .setAllTipTextColor(R.color.colorTabText)
// .setAllTipTextSize(14)
// .setReloadButtonText("点我重试哦")
// .setReloadButtonTextSize(14)
// .setReloadButtonTextColor(R.color.colorTabText)
// .setReloadButtonWidthAndHeight(150, 40)
// .setAllPageBackgroundColor(R.color.colorBackground)
// .setLoadingPageLayout(R.layout.default_loading_page);
// }
//
// private VideoRes videoRes;
//
// public VideoRes getVideoRes() {
// return videoRes;
// }
//
// public void setVideoRes(VideoRes videoRes) {
// this.videoRes = videoRes;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
// Path: app/src/main/java/com/zmj/qvod/module/recommend/RollViewPagerItemView.java
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.jude.easyrecyclerview.swipe.SwipeRefreshLayout;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.hintview.IconHintView;
import com.jude.utils.JUtils;
import com.zmj.qvod.R;
import com.zmj.qvod.adapter.ImageLoopAdapter;
import com.zmj.qvod.app.VideoApplication;
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.module.bean.VideoRes;
import java.util.ArrayList;
import java.util.List;
package com.zmj.qvod.module.recommend;
/**
* Created by matt on 2017/3/15.
*/
public class RollViewPagerItemView implements RecyclerArrayAdapter.ItemView {
private RollPagerView rollPagerView;
private Context mContext; | private ImageLoopAdapter adapter; |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/module/recommend/RollViewPagerItemView.java | // Path: app/src/main/java/com/zmj/qvod/adapter/ImageLoopAdapter.java
// public class ImageLoopAdapter extends LoopPagerAdapter {
//
// List<VideoInfo> banners;
//
// public ImageLoopAdapter(RollPagerView viewPager) {
// super(viewPager);
// }
//
// @Override
// public View getView(ViewGroup container, int position) {
// View views = LayoutInflater.from(container.getContext()).inflate(R.layout.view_roll_viewpager, null);
// ImageView imageView = (ImageView) views.findViewById(R.id.iv_roll_viewpager);
// imageView.setScaleType(ImageView.ScaleType.FIT_XY);
// ImageLoader.load(banners.get(position).pic, imageView, 320);
// imageView.setOnClickListener(view -> {
// VideoInfoActivity.actionStart(container.getContext(), banners.get(position));
// });
// return views;
// }
//
// @Override
// public int getRealCount() {
// if (banners != null) {
// return banners.size();
// } else {
// return 0;
// }
// }
//
// public void setBanners(List<VideoInfo> banners) {
// this.banners = banners;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/app/VideoApplication.java
// public class VideoApplication extends Application {
//
// private static VideoApplication videoApplication;
//
// public static VideoApplication getInstance() {
// if (videoApplication == null) {
// synchronized (VideoApplication.class) {
// if (videoApplication == null) {
// videoApplication = new VideoApplication();
// }
// }
// }
// return videoApplication;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// videoApplication = this;
// HttpUtils.getInstance().setContext(this);
// JUtils.initialize(this);
// JUtils.setDebug(true, "video");
// initLoading();
// }
//
// private void initLoading() {
// LoadingLayout.getConfig()
// .setErrorText("出错啦~请稍后重试!")
// .setEmptyText("抱歉,暂无数据")
// .setNoNetworkText("无网络连接,请检查您的网络···")
// .setErrorImage(R.drawable.ic_empty_icon)
// .setEmptyImage(R.drawable.ic_empty_icon)
// .setNoNetworkImage(R.drawable.ic_no_network)
// .setAllTipTextColor(R.color.colorTabText)
// .setAllTipTextSize(14)
// .setReloadButtonText("点我重试哦")
// .setReloadButtonTextSize(14)
// .setReloadButtonTextColor(R.color.colorTabText)
// .setReloadButtonWidthAndHeight(150, 40)
// .setAllPageBackgroundColor(R.color.colorBackground)
// .setLoadingPageLayout(R.layout.default_loading_page);
// }
//
// private VideoRes videoRes;
//
// public VideoRes getVideoRes() {
// return videoRes;
// }
//
// public void setVideoRes(VideoRes videoRes) {
// this.videoRes = videoRes;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
| import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.jude.easyrecyclerview.swipe.SwipeRefreshLayout;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.hintview.IconHintView;
import com.jude.utils.JUtils;
import com.zmj.qvod.R;
import com.zmj.qvod.adapter.ImageLoopAdapter;
import com.zmj.qvod.app.VideoApplication;
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.module.bean.VideoRes;
import java.util.ArrayList;
import java.util.List; | package com.zmj.qvod.module.recommend;
/**
* Created by matt on 2017/3/15.
*/
public class RollViewPagerItemView implements RecyclerArrayAdapter.ItemView {
private RollPagerView rollPagerView;
private Context mContext;
private ImageLoopAdapter adapter;
private SwipeRefreshLayout swipeRefreshLayout;
// | // Path: app/src/main/java/com/zmj/qvod/adapter/ImageLoopAdapter.java
// public class ImageLoopAdapter extends LoopPagerAdapter {
//
// List<VideoInfo> banners;
//
// public ImageLoopAdapter(RollPagerView viewPager) {
// super(viewPager);
// }
//
// @Override
// public View getView(ViewGroup container, int position) {
// View views = LayoutInflater.from(container.getContext()).inflate(R.layout.view_roll_viewpager, null);
// ImageView imageView = (ImageView) views.findViewById(R.id.iv_roll_viewpager);
// imageView.setScaleType(ImageView.ScaleType.FIT_XY);
// ImageLoader.load(banners.get(position).pic, imageView, 320);
// imageView.setOnClickListener(view -> {
// VideoInfoActivity.actionStart(container.getContext(), banners.get(position));
// });
// return views;
// }
//
// @Override
// public int getRealCount() {
// if (banners != null) {
// return banners.size();
// } else {
// return 0;
// }
// }
//
// public void setBanners(List<VideoInfo> banners) {
// this.banners = banners;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/app/VideoApplication.java
// public class VideoApplication extends Application {
//
// private static VideoApplication videoApplication;
//
// public static VideoApplication getInstance() {
// if (videoApplication == null) {
// synchronized (VideoApplication.class) {
// if (videoApplication == null) {
// videoApplication = new VideoApplication();
// }
// }
// }
// return videoApplication;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// videoApplication = this;
// HttpUtils.getInstance().setContext(this);
// JUtils.initialize(this);
// JUtils.setDebug(true, "video");
// initLoading();
// }
//
// private void initLoading() {
// LoadingLayout.getConfig()
// .setErrorText("出错啦~请稍后重试!")
// .setEmptyText("抱歉,暂无数据")
// .setNoNetworkText("无网络连接,请检查您的网络···")
// .setErrorImage(R.drawable.ic_empty_icon)
// .setEmptyImage(R.drawable.ic_empty_icon)
// .setNoNetworkImage(R.drawable.ic_no_network)
// .setAllTipTextColor(R.color.colorTabText)
// .setAllTipTextSize(14)
// .setReloadButtonText("点我重试哦")
// .setReloadButtonTextSize(14)
// .setReloadButtonTextColor(R.color.colorTabText)
// .setReloadButtonWidthAndHeight(150, 40)
// .setAllPageBackgroundColor(R.color.colorBackground)
// .setLoadingPageLayout(R.layout.default_loading_page);
// }
//
// private VideoRes videoRes;
//
// public VideoRes getVideoRes() {
// return videoRes;
// }
//
// public void setVideoRes(VideoRes videoRes) {
// this.videoRes = videoRes;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
// Path: app/src/main/java/com/zmj/qvod/module/recommend/RollViewPagerItemView.java
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.jude.easyrecyclerview.swipe.SwipeRefreshLayout;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.hintview.IconHintView;
import com.jude.utils.JUtils;
import com.zmj.qvod.R;
import com.zmj.qvod.adapter.ImageLoopAdapter;
import com.zmj.qvod.app.VideoApplication;
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.module.bean.VideoRes;
import java.util.ArrayList;
import java.util.List;
package com.zmj.qvod.module.recommend;
/**
* Created by matt on 2017/3/15.
*/
public class RollViewPagerItemView implements RecyclerArrayAdapter.ItemView {
private RollPagerView rollPagerView;
private Context mContext;
private ImageLoopAdapter adapter;
private SwipeRefreshLayout swipeRefreshLayout;
// | private List<VideoInfo> banners; |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/viewholder/RecommendViewHolder.java | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
| import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.VideoInfo; | package com.zmj.qvod.adapter.viewholder;
/**
* Created by matt on 2017/3/17.
*/
public class RecommendViewHolder extends BaseViewHolder<VideoInfo> {
ImageView ivVideo;
TextView tvTitle;
public RecommendViewHolder(ViewGroup group) {
super(group, R.layout.item_video);
ivVideo = $(R.id.iv_video);
tvTitle = $(R.id.tv_title);
}
@Override
public void setData(VideoInfo data) {
tvTitle.setText(data.title); | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/RecommendViewHolder.java
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.VideoInfo;
package com.zmj.qvod.adapter.viewholder;
/**
* Created by matt on 2017/3/17.
*/
public class RecommendViewHolder extends BaseViewHolder<VideoInfo> {
ImageView ivVideo;
TextView tvTitle;
public RecommendViewHolder(ViewGroup group) {
super(group, R.layout.item_video);
ivVideo = $(R.id.iv_video);
tvTitle = $(R.id.tv_title);
}
@Override
public void setData(VideoInfo data) {
tvTitle.setText(data.title); | ImageLoader.load(data.pic, ivVideo, 320); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/ImageLoopAdapter.java | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/activity/VideoInfoActivity.java
// @RequiresPresenter(VideoInfoPresenter.class)
// public class VideoInfoActivity extends BeamBaseActivity<VideoInfoPresenter> {
//
// @BindView(R.id.jc_video_play)
// JCVideoPlayerStandard jcVideoPlay;
// @BindView(R.id.ev_more)
// EasyRecyclerView evMore;
//
//
// private VideoInfo videoInfo;
//
// public static void actionStart(Context context, VideoInfo videoInfo) {
// Intent intent = new Intent(context, VideoInfoActivity.class);
// intent.putExtra("videoInfo", videoInfo);
// context.startActivity(intent);
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.acivity_video_info);
// ButterKnife.bind(this);
//
// initParam();
// }
//
// private void initParam() {
// videoInfo = (VideoInfo) getIntent().getSerializableExtra("videoInfo");
// }
//
// @Override
// protected void onPause() {
// super.onPause();
// JCVideoPlayer.releaseAllVideos();
// }
//
// @Override
// public void onBackPressed() {
// if (JCVideoPlayer.backPress()) return;
// super.onBackPressed();
// }
//
// public JCVideoPlayerStandard getJcVideoPlay() {
// return jcVideoPlay;
// }
//
// public VideoInfo getVideoInfo() {
// return videoInfo;
// }
//
// public EasyRecyclerView getListView() {
// return evMore;
// }
// }
| import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.DynamicPagerAdapter;
import com.jude.rollviewpager.adapter.LoopPagerAdapter;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.view.activity.VideoInfoActivity;
import java.util.List; | package com.zmj.qvod.adapter;
/**
* Created by zmj on 2016/2/6 0006.
*/
public class ImageLoopAdapter extends LoopPagerAdapter {
List<VideoInfo> banners;
public ImageLoopAdapter(RollPagerView viewPager) {
super(viewPager);
}
@Override
public View getView(ViewGroup container, int position) {
View views = LayoutInflater.from(container.getContext()).inflate(R.layout.view_roll_viewpager, null);
ImageView imageView = (ImageView) views.findViewById(R.id.iv_roll_viewpager);
imageView.setScaleType(ImageView.ScaleType.FIT_XY); | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/activity/VideoInfoActivity.java
// @RequiresPresenter(VideoInfoPresenter.class)
// public class VideoInfoActivity extends BeamBaseActivity<VideoInfoPresenter> {
//
// @BindView(R.id.jc_video_play)
// JCVideoPlayerStandard jcVideoPlay;
// @BindView(R.id.ev_more)
// EasyRecyclerView evMore;
//
//
// private VideoInfo videoInfo;
//
// public static void actionStart(Context context, VideoInfo videoInfo) {
// Intent intent = new Intent(context, VideoInfoActivity.class);
// intent.putExtra("videoInfo", videoInfo);
// context.startActivity(intent);
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.acivity_video_info);
// ButterKnife.bind(this);
//
// initParam();
// }
//
// private void initParam() {
// videoInfo = (VideoInfo) getIntent().getSerializableExtra("videoInfo");
// }
//
// @Override
// protected void onPause() {
// super.onPause();
// JCVideoPlayer.releaseAllVideos();
// }
//
// @Override
// public void onBackPressed() {
// if (JCVideoPlayer.backPress()) return;
// super.onBackPressed();
// }
//
// public JCVideoPlayerStandard getJcVideoPlay() {
// return jcVideoPlay;
// }
//
// public VideoInfo getVideoInfo() {
// return videoInfo;
// }
//
// public EasyRecyclerView getListView() {
// return evMore;
// }
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/ImageLoopAdapter.java
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.DynamicPagerAdapter;
import com.jude.rollviewpager.adapter.LoopPagerAdapter;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.view.activity.VideoInfoActivity;
import java.util.List;
package com.zmj.qvod.adapter;
/**
* Created by zmj on 2016/2/6 0006.
*/
public class ImageLoopAdapter extends LoopPagerAdapter {
List<VideoInfo> banners;
public ImageLoopAdapter(RollPagerView viewPager) {
super(viewPager);
}
@Override
public View getView(ViewGroup container, int position) {
View views = LayoutInflater.from(container.getContext()).inflate(R.layout.view_roll_viewpager, null);
ImageView imageView = (ImageView) views.findViewById(R.id.iv_roll_viewpager);
imageView.setScaleType(ImageView.ScaleType.FIT_XY); | ImageLoader.load(banners.get(position).pic, imageView, 320); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/ImageLoopAdapter.java | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/activity/VideoInfoActivity.java
// @RequiresPresenter(VideoInfoPresenter.class)
// public class VideoInfoActivity extends BeamBaseActivity<VideoInfoPresenter> {
//
// @BindView(R.id.jc_video_play)
// JCVideoPlayerStandard jcVideoPlay;
// @BindView(R.id.ev_more)
// EasyRecyclerView evMore;
//
//
// private VideoInfo videoInfo;
//
// public static void actionStart(Context context, VideoInfo videoInfo) {
// Intent intent = new Intent(context, VideoInfoActivity.class);
// intent.putExtra("videoInfo", videoInfo);
// context.startActivity(intent);
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.acivity_video_info);
// ButterKnife.bind(this);
//
// initParam();
// }
//
// private void initParam() {
// videoInfo = (VideoInfo) getIntent().getSerializableExtra("videoInfo");
// }
//
// @Override
// protected void onPause() {
// super.onPause();
// JCVideoPlayer.releaseAllVideos();
// }
//
// @Override
// public void onBackPressed() {
// if (JCVideoPlayer.backPress()) return;
// super.onBackPressed();
// }
//
// public JCVideoPlayerStandard getJcVideoPlay() {
// return jcVideoPlay;
// }
//
// public VideoInfo getVideoInfo() {
// return videoInfo;
// }
//
// public EasyRecyclerView getListView() {
// return evMore;
// }
// }
| import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.DynamicPagerAdapter;
import com.jude.rollviewpager.adapter.LoopPagerAdapter;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.view.activity.VideoInfoActivity;
import java.util.List; | package com.zmj.qvod.adapter;
/**
* Created by zmj on 2016/2/6 0006.
*/
public class ImageLoopAdapter extends LoopPagerAdapter {
List<VideoInfo> banners;
public ImageLoopAdapter(RollPagerView viewPager) {
super(viewPager);
}
@Override
public View getView(ViewGroup container, int position) {
View views = LayoutInflater.from(container.getContext()).inflate(R.layout.view_roll_viewpager, null);
ImageView imageView = (ImageView) views.findViewById(R.id.iv_roll_viewpager);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
ImageLoader.load(banners.get(position).pic, imageView, 320);
imageView.setOnClickListener(view -> { | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/activity/VideoInfoActivity.java
// @RequiresPresenter(VideoInfoPresenter.class)
// public class VideoInfoActivity extends BeamBaseActivity<VideoInfoPresenter> {
//
// @BindView(R.id.jc_video_play)
// JCVideoPlayerStandard jcVideoPlay;
// @BindView(R.id.ev_more)
// EasyRecyclerView evMore;
//
//
// private VideoInfo videoInfo;
//
// public static void actionStart(Context context, VideoInfo videoInfo) {
// Intent intent = new Intent(context, VideoInfoActivity.class);
// intent.putExtra("videoInfo", videoInfo);
// context.startActivity(intent);
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.acivity_video_info);
// ButterKnife.bind(this);
//
// initParam();
// }
//
// private void initParam() {
// videoInfo = (VideoInfo) getIntent().getSerializableExtra("videoInfo");
// }
//
// @Override
// protected void onPause() {
// super.onPause();
// JCVideoPlayer.releaseAllVideos();
// }
//
// @Override
// public void onBackPressed() {
// if (JCVideoPlayer.backPress()) return;
// super.onBackPressed();
// }
//
// public JCVideoPlayerStandard getJcVideoPlay() {
// return jcVideoPlay;
// }
//
// public VideoInfo getVideoInfo() {
// return videoInfo;
// }
//
// public EasyRecyclerView getListView() {
// return evMore;
// }
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/ImageLoopAdapter.java
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.DynamicPagerAdapter;
import com.jude.rollviewpager.adapter.LoopPagerAdapter;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.VideoInfo;
import com.zmj.qvod.view.activity.VideoInfoActivity;
import java.util.List;
package com.zmj.qvod.adapter;
/**
* Created by zmj on 2016/2/6 0006.
*/
public class ImageLoopAdapter extends LoopPagerAdapter {
List<VideoInfo> banners;
public ImageLoopAdapter(RollPagerView viewPager) {
super(viewPager);
}
@Override
public View getView(ViewGroup container, int position) {
View views = LayoutInflater.from(container.getContext()).inflate(R.layout.view_roll_viewpager, null);
ImageView imageView = (ImageView) views.findViewById(R.id.iv_roll_viewpager);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
ImageLoader.load(banners.get(position).pic, imageView, 320);
imageView.setOnClickListener(view -> { | VideoInfoActivity.actionStart(container.getContext(), banners.get(position)); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/ImageBrowseAdapter.java | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/PicBean.java
// public class PicBean implements Serializable {
//
// private List<ItemsBean> items;
//
// public List<ItemsBean> getItems() {
// return items;
// }
//
// public static class ItemsBean implements Serializable {
//
// private String thumbUrl;
// private String pic_url;
// private String height;
// private String width;
//
// public String getHeight() {
// return height;
// }
//
// public void setHeight(String height) {
// this.height = height;
// }
//
// public String getWidth() {
// return width;
// }
//
//
// public String getThumbUrl() {
// return thumbUrl;
// }
//
// public String getPic_url() {
// return pic_url;
// }
//
// }
// }
| import android.app.Activity;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.github.chrisbanes.photoview.PhotoView;
import com.jude.rollviewpager.adapter.DynamicPagerAdapter;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.PicBean;
import java.util.ArrayList;
import butterknife.ButterKnife; | package com.zmj.qvod.adapter;
/**
* Created by zmj on 2016/2/6 0006.
*/
public class ImageBrowseAdapter extends DynamicPagerAdapter {
private ArrayList<PicBean.ItemsBean> items;
private Activity activity;
public ImageBrowseAdapter(Activity activity) {
this.activity = activity;
}
@Override
public View getView(ViewGroup container, int position) {
View contentView = LayoutInflater.from(container.getContext()).inflate(R.layout.view_photo, null);
PhotoView imageView = ButterKnife.findById(contentView, R.id.photo_view);
LinearLayout loadingView = ButterKnife.findById(contentView, R.id.ll_photo);
//手势控件
Glide.with(container.getContext())
.load(items.get(position).getPic_url())
.asBitmap()
.placeholder(R.drawable.pic_default)
.listener(new RequestListener<String, Bitmap>() {
@Override
public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
loadingView.setVisibility(View.GONE); | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/PicBean.java
// public class PicBean implements Serializable {
//
// private List<ItemsBean> items;
//
// public List<ItemsBean> getItems() {
// return items;
// }
//
// public static class ItemsBean implements Serializable {
//
// private String thumbUrl;
// private String pic_url;
// private String height;
// private String width;
//
// public String getHeight() {
// return height;
// }
//
// public void setHeight(String height) {
// this.height = height;
// }
//
// public String getWidth() {
// return width;
// }
//
//
// public String getThumbUrl() {
// return thumbUrl;
// }
//
// public String getPic_url() {
// return pic_url;
// }
//
// }
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/ImageBrowseAdapter.java
import android.app.Activity;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.github.chrisbanes.photoview.PhotoView;
import com.jude.rollviewpager.adapter.DynamicPagerAdapter;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.PicBean;
import java.util.ArrayList;
import butterknife.ButterKnife;
package com.zmj.qvod.adapter;
/**
* Created by zmj on 2016/2/6 0006.
*/
public class ImageBrowseAdapter extends DynamicPagerAdapter {
private ArrayList<PicBean.ItemsBean> items;
private Activity activity;
public ImageBrowseAdapter(Activity activity) {
this.activity = activity;
}
@Override
public View getView(ViewGroup container, int position) {
View contentView = LayoutInflater.from(container.getContext()).inflate(R.layout.view_photo, null);
PhotoView imageView = ButterKnife.findById(contentView, R.id.photo_view);
LinearLayout loadingView = ButterKnife.findById(contentView, R.id.ll_photo);
//手势控件
Glide.with(container.getContext())
.load(items.get(position).getPic_url())
.asBitmap()
.placeholder(R.drawable.pic_default)
.listener(new RequestListener<String, Bitmap>() {
@Override
public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
loadingView.setVisibility(View.GONE); | ImageLoader.load(items.get(position).getThumbUrl(), imageView, 100); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/viewholder/MovieCastsViewHolder.java | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/activity/WebViewActivity.java
// @RequiresPresenter(WebViewPresenter.class)
// public class WebViewActivity extends BeamBaseActivity<WebViewPresenter> {
//
// @BindView(R.id.wv_web)
// public WebView webView;
// @BindView(R.id.tl_toolbar)
// public TitleLayout tlToolbar;
// @BindView(R.id.pb_web_view)
// public ProgressBar progressBar;
//
// public static void startAction(Context context, String url) {
// Intent intent = new Intent(context, WebViewActivity.class);
// intent.putExtra("url", url);
// context.startActivity(intent);
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_web_view);
// ButterKnife.bind(this);
//
// }
//
// @Override
// public void onBackPressed() {
// if (webView.canGoBack()) {
// // 返回前一个页面
// webView.goBack();
// } else {
// super.onBackPressed();
// }
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// if (webView != null) {
// webView.clearCache(true);
// webView.destroy();
// }
// }
// }
| import android.view.ViewGroup;
import android.widget.TextView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.MovieDetailBean;
import com.zmj.qvod.view.activity.WebViewActivity;
import de.hdodenhof.circleimageview.CircleImageView; | package com.zmj.qvod.adapter.viewholder;
/**
* Created by matt on 2017/4/13.
*/
public class MovieCastsViewHolder extends BaseViewHolder<MovieDetailBean.CastsBean> {
private CircleImageView civCastsPic;
private TextView tvCastsName;
private TextView tvCastsType;
public MovieCastsViewHolder(ViewGroup parent) {
super(parent, R.layout.item_movie_casts);
civCastsPic = $(R.id.civ_casts_pic);
tvCastsName = $(R.id.tv_casts_name);
tvCastsType = $(R.id.tv_casts_type);
}
@Override
public void setData(MovieDetailBean.CastsBean data) {
super.setData(data); | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/activity/WebViewActivity.java
// @RequiresPresenter(WebViewPresenter.class)
// public class WebViewActivity extends BeamBaseActivity<WebViewPresenter> {
//
// @BindView(R.id.wv_web)
// public WebView webView;
// @BindView(R.id.tl_toolbar)
// public TitleLayout tlToolbar;
// @BindView(R.id.pb_web_view)
// public ProgressBar progressBar;
//
// public static void startAction(Context context, String url) {
// Intent intent = new Intent(context, WebViewActivity.class);
// intent.putExtra("url", url);
// context.startActivity(intent);
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_web_view);
// ButterKnife.bind(this);
//
// }
//
// @Override
// public void onBackPressed() {
// if (webView.canGoBack()) {
// // 返回前一个页面
// webView.goBack();
// } else {
// super.onBackPressed();
// }
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// if (webView != null) {
// webView.clearCache(true);
// webView.destroy();
// }
// }
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/MovieCastsViewHolder.java
import android.view.ViewGroup;
import android.widget.TextView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.MovieDetailBean;
import com.zmj.qvod.view.activity.WebViewActivity;
import de.hdodenhof.circleimageview.CircleImageView;
package com.zmj.qvod.adapter.viewholder;
/**
* Created by matt on 2017/4/13.
*/
public class MovieCastsViewHolder extends BaseViewHolder<MovieDetailBean.CastsBean> {
private CircleImageView civCastsPic;
private TextView tvCastsName;
private TextView tvCastsType;
public MovieCastsViewHolder(ViewGroup parent) {
super(parent, R.layout.item_movie_casts);
civCastsPic = $(R.id.civ_casts_pic);
tvCastsName = $(R.id.tv_casts_name);
tvCastsType = $(R.id.tv_casts_type);
}
@Override
public void setData(MovieDetailBean.CastsBean data) {
super.setData(data); | ImageLoader.load(getContext(), data.getAvatars().getLarge(), civCastsPic); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/viewholder/MovieCastsViewHolder.java | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/activity/WebViewActivity.java
// @RequiresPresenter(WebViewPresenter.class)
// public class WebViewActivity extends BeamBaseActivity<WebViewPresenter> {
//
// @BindView(R.id.wv_web)
// public WebView webView;
// @BindView(R.id.tl_toolbar)
// public TitleLayout tlToolbar;
// @BindView(R.id.pb_web_view)
// public ProgressBar progressBar;
//
// public static void startAction(Context context, String url) {
// Intent intent = new Intent(context, WebViewActivity.class);
// intent.putExtra("url", url);
// context.startActivity(intent);
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_web_view);
// ButterKnife.bind(this);
//
// }
//
// @Override
// public void onBackPressed() {
// if (webView.canGoBack()) {
// // 返回前一个页面
// webView.goBack();
// } else {
// super.onBackPressed();
// }
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// if (webView != null) {
// webView.clearCache(true);
// webView.destroy();
// }
// }
// }
| import android.view.ViewGroup;
import android.widget.TextView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.MovieDetailBean;
import com.zmj.qvod.view.activity.WebViewActivity;
import de.hdodenhof.circleimageview.CircleImageView; | package com.zmj.qvod.adapter.viewholder;
/**
* Created by matt on 2017/4/13.
*/
public class MovieCastsViewHolder extends BaseViewHolder<MovieDetailBean.CastsBean> {
private CircleImageView civCastsPic;
private TextView tvCastsName;
private TextView tvCastsType;
public MovieCastsViewHolder(ViewGroup parent) {
super(parent, R.layout.item_movie_casts);
civCastsPic = $(R.id.civ_casts_pic);
tvCastsName = $(R.id.tv_casts_name);
tvCastsType = $(R.id.tv_casts_type);
}
@Override
public void setData(MovieDetailBean.CastsBean data) {
super.setData(data);
ImageLoader.load(getContext(), data.getAvatars().getLarge(), civCastsPic);
tvCastsName.setText(data.getName());
//
if ("导演".equals(data.getType()))
tvCastsType.setText("导演");
else
tvCastsType.setText("演员");
//
itemView.setOnClickListener(view -> {
//onClick | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/view/activity/WebViewActivity.java
// @RequiresPresenter(WebViewPresenter.class)
// public class WebViewActivity extends BeamBaseActivity<WebViewPresenter> {
//
// @BindView(R.id.wv_web)
// public WebView webView;
// @BindView(R.id.tl_toolbar)
// public TitleLayout tlToolbar;
// @BindView(R.id.pb_web_view)
// public ProgressBar progressBar;
//
// public static void startAction(Context context, String url) {
// Intent intent = new Intent(context, WebViewActivity.class);
// intent.putExtra("url", url);
// context.startActivity(intent);
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_web_view);
// ButterKnife.bind(this);
//
// }
//
// @Override
// public void onBackPressed() {
// if (webView.canGoBack()) {
// // 返回前一个页面
// webView.goBack();
// } else {
// super.onBackPressed();
// }
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// if (webView != null) {
// webView.clearCache(true);
// webView.destroy();
// }
// }
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/MovieCastsViewHolder.java
import android.view.ViewGroup;
import android.widget.TextView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.MovieDetailBean;
import com.zmj.qvod.view.activity.WebViewActivity;
import de.hdodenhof.circleimageview.CircleImageView;
package com.zmj.qvod.adapter.viewholder;
/**
* Created by matt on 2017/4/13.
*/
public class MovieCastsViewHolder extends BaseViewHolder<MovieDetailBean.CastsBean> {
private CircleImageView civCastsPic;
private TextView tvCastsName;
private TextView tvCastsType;
public MovieCastsViewHolder(ViewGroup parent) {
super(parent, R.layout.item_movie_casts);
civCastsPic = $(R.id.civ_casts_pic);
tvCastsName = $(R.id.tv_casts_name);
tvCastsType = $(R.id.tv_casts_type);
}
@Override
public void setData(MovieDetailBean.CastsBean data) {
super.setData(data);
ImageLoader.load(getContext(), data.getAvatars().getLarge(), civCastsPic);
tvCastsName.setText(data.getName());
//
if ("导演".equals(data.getType()))
tvCastsType.setText("导演");
else
tvCastsType.setText("演员");
//
itemView.setOnClickListener(view -> {
//onClick | WebViewActivity.startAction(getContext(), data.getAlt()); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/MovieCastsAdapter.java | // Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/MovieCastsViewHolder.java
// public class MovieCastsViewHolder extends BaseViewHolder<MovieDetailBean.CastsBean> {
//
//
// private CircleImageView civCastsPic;
// private TextView tvCastsName;
// private TextView tvCastsType;
//
// public MovieCastsViewHolder(ViewGroup parent) {
// super(parent, R.layout.item_movie_casts);
// civCastsPic = $(R.id.civ_casts_pic);
// tvCastsName = $(R.id.tv_casts_name);
// tvCastsType = $(R.id.tv_casts_type);
// }
//
// @Override
// public void setData(MovieDetailBean.CastsBean data) {
// super.setData(data);
// ImageLoader.load(getContext(), data.getAvatars().getLarge(), civCastsPic);
// tvCastsName.setText(data.getName());
// //
// if ("导演".equals(data.getType()))
// tvCastsType.setText("导演");
// else
// tvCastsType.setText("演员");
// //
// itemView.setOnClickListener(view -> {
// //onClick
// WebViewActivity.startAction(getContext(), data.getAlt());
// });
// }
// }
| import android.content.Context;
import android.view.ViewGroup;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zmj.qvod.adapter.viewholder.MovieCastsViewHolder;
import com.zmj.qvod.module.bean.MovieDetailBean; | package com.zmj.qvod.adapter;
/**
* Created by matt on 2017/4/13.
*/
public class MovieCastsAdapter extends RecyclerArrayAdapter<MovieDetailBean.CastsBean> {
public MovieCastsAdapter(Context context) {
super(context);
}
@Override
public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { | // Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/MovieCastsViewHolder.java
// public class MovieCastsViewHolder extends BaseViewHolder<MovieDetailBean.CastsBean> {
//
//
// private CircleImageView civCastsPic;
// private TextView tvCastsName;
// private TextView tvCastsType;
//
// public MovieCastsViewHolder(ViewGroup parent) {
// super(parent, R.layout.item_movie_casts);
// civCastsPic = $(R.id.civ_casts_pic);
// tvCastsName = $(R.id.tv_casts_name);
// tvCastsType = $(R.id.tv_casts_type);
// }
//
// @Override
// public void setData(MovieDetailBean.CastsBean data) {
// super.setData(data);
// ImageLoader.load(getContext(), data.getAvatars().getLarge(), civCastsPic);
// tvCastsName.setText(data.getName());
// //
// if ("导演".equals(data.getType()))
// tvCastsType.setText("导演");
// else
// tvCastsType.setText("演员");
// //
// itemView.setOnClickListener(view -> {
// //onClick
// WebViewActivity.startAction(getContext(), data.getAlt());
// });
// }
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/MovieCastsAdapter.java
import android.content.Context;
import android.view.ViewGroup;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zmj.qvod.adapter.viewholder.MovieCastsViewHolder;
import com.zmj.qvod.module.bean.MovieDetailBean;
package com.zmj.qvod.adapter;
/**
* Created by matt on 2017/4/13.
*/
public class MovieCastsAdapter extends RecyclerArrayAdapter<MovieDetailBean.CastsBean> {
public MovieCastsAdapter(Context context) {
super(context);
}
@Override
public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { | return new MovieCastsViewHolder(parent); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/presenter/WebViewPresenter.java | // Path: app/src/main/java/com/zmj/qvod/view/activity/WebViewActivity.java
// @RequiresPresenter(WebViewPresenter.class)
// public class WebViewActivity extends BeamBaseActivity<WebViewPresenter> {
//
// @BindView(R.id.wv_web)
// public WebView webView;
// @BindView(R.id.tl_toolbar)
// public TitleLayout tlToolbar;
// @BindView(R.id.pb_web_view)
// public ProgressBar progressBar;
//
// public static void startAction(Context context, String url) {
// Intent intent = new Intent(context, WebViewActivity.class);
// intent.putExtra("url", url);
// context.startActivity(intent);
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_web_view);
// ButterKnife.bind(this);
//
// }
//
// @Override
// public void onBackPressed() {
// if (webView.canGoBack()) {
// // 返回前一个页面
// webView.goBack();
// } else {
// super.onBackPressed();
// }
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// if (webView != null) {
// webView.clearCache(true);
// webView.destroy();
// }
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/widght/MyWebViewClient.java
// public class MyWebViewClient extends WebViewClient {
//
// private WebViewActivity mActivity;
//
// public MyWebViewClient(WebViewActivity webViewActivity) {
// this.mActivity = webViewActivity;
// }
//
// @Override
// public void onPageFinished(WebView view, String url) {
// super.onPageFinished(view, url);
// mActivity.getToolbar().setTitle(view.getTitle());
// }
//
// @SuppressWarnings("deprecation")
// @Override
// public boolean shouldOverrideUrlLoading(WebView view, String url) {
// // 优酷视频跳转浏览器播放
// if (url.startsWith("http://v.youku.com/")) {
// Intent intent = new Intent();
// intent.setAction("android.intent.action.VIEW");
// intent.addCategory("android.intent.category.DEFAULT");
// intent.addCategory("android.intent.category.BROWSABLE");
// Uri content_url = Uri.parse(url);
// intent.setData(content_url);
// mActivity.startActivity(intent);
// return true;
// // 电话、短信、邮箱
// } else if (url.startsWith(WebView.SCHEME_TEL) || url.startsWith("sms:") || url.startsWith(WebView.SCHEME_MAILTO)) {
// try {
// Intent intent = new Intent(Intent.ACTION_VIEW);
// intent.setData(Uri.parse(url));
// mActivity.startActivity(intent);
// } catch (ActivityNotFoundException ignored) {
// }
// return true;
// }
// view.loadUrl(url);
// return false;
// }
// }
| import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.NonNull;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.jude.beam.expansion.BeamBasePresenter;
import com.zmj.qvod.view.activity.WebViewActivity;
import com.zmj.qvod.widght.MyWebViewClient; | package com.zmj.qvod.presenter;
/**
* Created by matt on 2017/4/14.
*/
public class WebViewPresenter extends BeamBasePresenter<WebViewActivity> {
@Override
protected void onCreateView(@NonNull WebViewActivity view) {
super.onCreateView(view);
initParam();
}
private void initParam() {
setUpWebViewDefaults(getView().webView); | // Path: app/src/main/java/com/zmj/qvod/view/activity/WebViewActivity.java
// @RequiresPresenter(WebViewPresenter.class)
// public class WebViewActivity extends BeamBaseActivity<WebViewPresenter> {
//
// @BindView(R.id.wv_web)
// public WebView webView;
// @BindView(R.id.tl_toolbar)
// public TitleLayout tlToolbar;
// @BindView(R.id.pb_web_view)
// public ProgressBar progressBar;
//
// public static void startAction(Context context, String url) {
// Intent intent = new Intent(context, WebViewActivity.class);
// intent.putExtra("url", url);
// context.startActivity(intent);
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_web_view);
// ButterKnife.bind(this);
//
// }
//
// @Override
// public void onBackPressed() {
// if (webView.canGoBack()) {
// // 返回前一个页面
// webView.goBack();
// } else {
// super.onBackPressed();
// }
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// if (webView != null) {
// webView.clearCache(true);
// webView.destroy();
// }
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/widght/MyWebViewClient.java
// public class MyWebViewClient extends WebViewClient {
//
// private WebViewActivity mActivity;
//
// public MyWebViewClient(WebViewActivity webViewActivity) {
// this.mActivity = webViewActivity;
// }
//
// @Override
// public void onPageFinished(WebView view, String url) {
// super.onPageFinished(view, url);
// mActivity.getToolbar().setTitle(view.getTitle());
// }
//
// @SuppressWarnings("deprecation")
// @Override
// public boolean shouldOverrideUrlLoading(WebView view, String url) {
// // 优酷视频跳转浏览器播放
// if (url.startsWith("http://v.youku.com/")) {
// Intent intent = new Intent();
// intent.setAction("android.intent.action.VIEW");
// intent.addCategory("android.intent.category.DEFAULT");
// intent.addCategory("android.intent.category.BROWSABLE");
// Uri content_url = Uri.parse(url);
// intent.setData(content_url);
// mActivity.startActivity(intent);
// return true;
// // 电话、短信、邮箱
// } else if (url.startsWith(WebView.SCHEME_TEL) || url.startsWith("sms:") || url.startsWith(WebView.SCHEME_MAILTO)) {
// try {
// Intent intent = new Intent(Intent.ACTION_VIEW);
// intent.setData(Uri.parse(url));
// mActivity.startActivity(intent);
// } catch (ActivityNotFoundException ignored) {
// }
// return true;
// }
// view.loadUrl(url);
// return false;
// }
// }
// Path: app/src/main/java/com/zmj/qvod/presenter/WebViewPresenter.java
import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.NonNull;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.jude.beam.expansion.BeamBasePresenter;
import com.zmj.qvod.view.activity.WebViewActivity;
import com.zmj.qvod.widght.MyWebViewClient;
package com.zmj.qvod.presenter;
/**
* Created by matt on 2017/4/14.
*/
public class WebViewPresenter extends BeamBasePresenter<WebViewActivity> {
@Override
protected void onCreateView(@NonNull WebViewActivity view) {
super.onCreateView(view);
initParam();
}
private void initParam() {
setUpWebViewDefaults(getView().webView); | getView().webView.setWebViewClient(new MyWebViewClient(getView())); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/RecommendAdapter.java | // Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/RecommendViewHolder.java
// public class RecommendViewHolder extends BaseViewHolder<VideoInfo> {
//
//
// ImageView ivVideo;
// TextView tvTitle;
//
// public RecommendViewHolder(ViewGroup group) {
// super(group, R.layout.item_video);
// ivVideo = $(R.id.iv_video);
// tvTitle = $(R.id.tv_title);
// }
//
// @Override
// public void setData(VideoInfo data) {
// tvTitle.setText(data.title);
// ImageLoader.load(data.pic, ivVideo, 320);
// }
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
| import android.content.Context;
import android.view.ViewGroup;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zmj.qvod.adapter.viewholder.RecommendViewHolder;
import com.zmj.qvod.module.bean.VideoInfo; | package com.zmj.qvod.adapter;
/**
* Created by matt on 2017/3/14.
*/
public class RecommendAdapter extends RecyclerArrayAdapter<VideoInfo> {
public RecommendAdapter(Context context) {
super(context);
}
@Override
public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { | // Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/RecommendViewHolder.java
// public class RecommendViewHolder extends BaseViewHolder<VideoInfo> {
//
//
// ImageView ivVideo;
// TextView tvTitle;
//
// public RecommendViewHolder(ViewGroup group) {
// super(group, R.layout.item_video);
// ivVideo = $(R.id.iv_video);
// tvTitle = $(R.id.tv_title);
// }
//
// @Override
// public void setData(VideoInfo data) {
// tvTitle.setText(data.title);
// ImageLoader.load(data.pic, ivVideo, 320);
// }
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/RecommendAdapter.java
import android.content.Context;
import android.view.ViewGroup;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zmj.qvod.adapter.viewholder.RecommendViewHolder;
import com.zmj.qvod.module.bean.VideoInfo;
package com.zmj.qvod.adapter;
/**
* Created by matt on 2017/3/14.
*/
public class RecommendAdapter extends RecyclerArrayAdapter<VideoInfo> {
public RecommendAdapter(Context context) {
super(context);
}
@Override
public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { | return new RecommendViewHolder(parent); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/adapter/viewholder/VideoMoreViewHolder.java | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
| import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.VideoInfo; | package com.zmj.qvod.adapter.viewholder;
/**
* Created by matt on 2017/3/30.
*/
public class VideoMoreViewHolder extends BaseViewHolder<VideoInfo> {
private ImageView ivVideo;
private TextView tvTitle;
public VideoMoreViewHolder(ViewGroup parent) {
super(parent, R.layout.item_video_info);
ivVideo = $(R.id.iv_video_info);
tvTitle = $(R.id.tv_title_info);
}
@Override
public void setData(VideoInfo data) {
tvTitle.setText(data.title); | // Path: app/src/main/java/com/zmj/qvod/constant/ImageLoader.java
// public class ImageLoader {
//
// public static void load(Context context, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// Glide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void load(Activity activity, String url, ImageView iv) { //使用Glide加载ImageView(如头像)时,不要使用占位图
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv);
// }
// }
//
// public static void loadAll(Context context, String url, ImageView iv) { //不缓存,全部从网络加载
// Glide.with(context).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
//
// @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
// public static void loadAll(Activity activity, String url, ImageView iv) { //不缓存,全部从网络加载
// if (!activity.isDestroyed()) {
// Glide.with(activity).load(url).crossFade().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
// }
// }
//
// public static void load(String url, ImageView iv, int type) { //使用占位图
// switch (type) {
// case 320:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_320).into(iv);
// break;
// case 200:
// Glide.with(VideoApplication.getInstance()).load(url).crossFade(1500).placeholder(R.drawable.default_200).into(iv);
// break;
// case 100:
// Glide.with(VideoApplication.getInstance()).load(url).placeholder(R.drawable.pic_default).into(iv);
// break;
// default:
// break;
// }
// }
//
// /**
// * Glide 获得图片缓存路径
// */
// public static String getImagePath(String imgUrl) {
// String path = null;
// FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
// .load(imgUrl)
// .downloadOnly(500, 500);
// try {
// File cacheFile = future.get();
// path = cacheFile.getAbsolutePath();
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
// return path;
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/bean/VideoInfo.java
// public class VideoInfo implements Serializable {
// public String title;
// public String pic;
// public String dataId;
// public String score;
// public String airTime;
// public String moreURL;
// public String loadType;
// // public String description;
//
// }
// Path: app/src/main/java/com/zmj/qvod/adapter/viewholder/VideoMoreViewHolder.java
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zmj.qvod.R;
import com.zmj.qvod.constant.ImageLoader;
import com.zmj.qvod.module.bean.VideoInfo;
package com.zmj.qvod.adapter.viewholder;
/**
* Created by matt on 2017/3/30.
*/
public class VideoMoreViewHolder extends BaseViewHolder<VideoInfo> {
private ImageView ivVideo;
private TextView tvTitle;
public VideoMoreViewHolder(ViewGroup parent) {
super(parent, R.layout.item_video_info);
ivVideo = $(R.id.iv_video_info);
tvTitle = $(R.id.tv_title_info);
}
@Override
public void setData(VideoInfo data) {
tvTitle.setText(data.title); | ImageLoader.load(data.pic, ivVideo, 200); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/view/activity/ImageBrowseActivity.java | // Path: app/src/main/java/com/zmj/qvod/module/bean/PicBean.java
// public class PicBean implements Serializable {
//
// private List<ItemsBean> items;
//
// public List<ItemsBean> getItems() {
// return items;
// }
//
// public static class ItemsBean implements Serializable {
//
// private String thumbUrl;
// private String pic_url;
// private String height;
// private String width;
//
// public String getHeight() {
// return height;
// }
//
// public void setHeight(String height) {
// this.height = height;
// }
//
// public String getWidth() {
// return width;
// }
//
//
// public String getThumbUrl() {
// return thumbUrl;
// }
//
// public String getPic_url() {
// return pic_url;
// }
//
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/presenter/ImageBrowsePresenter.java
// public class ImageBrowsePresenter extends BeamBasePresenter<ImageBrowseActivity> {
//
// private ArrayList<PicBean.ItemsBean> items;
// private int mPosition;
//
// @Override
// protected void onCreateView(@NonNull ImageBrowseActivity view) {
// super.onCreateView(view);
//
// initPrams();
//
// initImageLoader();
// }
//
// private void initPrams() {
// items = (ArrayList<PicBean.ItemsBean>) getView().getIntent().getSerializableExtra("items");
// mPosition = getView().getIntent().getIntExtra("position", 0);
// }
//
// private void initImageLoader() {
// ImageBrowseAdapter browseAdapter = new ImageBrowseAdapter(getView());
// browseAdapter.setItems(items);
// getView().vpImage.setAdapter(browseAdapter);
// getView().vpImage.setCurrentItem(mPosition);
// if (items != null && items.size() != 0) {
// getView().tvImage.setText((mPosition + 1) + "/" + items.size());
// }
// getView().vpImage.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
// @Override
// public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//
// }
//
// @Override
// public void onPageSelected(int position) {
// mPosition = position;
// if (items != null && items.size() != 0) {
// getView().tvImage.setText((position + 1) + "/" + items.size());
// }
// }
//
// @Override
// public void onPageScrollStateChanged(int state) {
//
// }
// });
// }
//
// /**
// * 保存图片至SD卡
// */
// public void saveImageSdCard() {
// JUtils.Toast("正在保存图片···");
// new Thread(() -> {
// BitmapFactory.Options Options = new BitmapFactory.Options();
// String cachePath = ImageLoader.getImagePath(items.get(mPosition).getPic_url());
// if (cachePath == null) {
// cachePath = ImageLoader.getImagePath(items.get(mPosition).getThumbUrl());
// }
// String finalCachePath = cachePath;
// getView().runOnUiThread(() -> {
// Bitmap bitmap = BitmapFactory.decodeFile(finalCachePath, Options);
// if (bitmap == null) return;
// FileUtils.saveImageToGallery(getView(), bitmap);
// JUtils.Toast("图片已保存至" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/Qvod");
// });
// }).start();
//
// }
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/utils/AppUtils.java
// public class AppUtils {
//
// /**
// * 获取状态栏高度
// *
// * @param context context
// * @return 状态栏高度
// */
// public static int getStatusBarHeight(Context context) {
// // 获得状态栏高度
// int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
// return context.getResources().getDimensionPixelSize(resourceId);
// }
//
// /**
// * [沉浸状态栏]
// */
// public static void steepStatusBar(Activity activity) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// // 透明状态栏
// activity.getWindow().addFlags(
// WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// // 透明导航栏
// activity.getWindow().addFlags(
// WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
// }
//
// }
//
// }
| import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.widget.TextView;
import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.BeamBaseActivity;
import com.zmj.qvod.R;
import com.zmj.qvod.module.bean.PicBean;
import com.zmj.qvod.presenter.ImageBrowsePresenter;
import com.zmj.qvod.utils.AppUtils;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick; | package com.zmj.qvod.view.activity;
/**
* Created by matt on 2017/4/18.
*/
@RequiresPresenter(ImageBrowsePresenter.class)
public class ImageBrowseActivity extends BeamBaseActivity<ImageBrowsePresenter> {
@BindView(R.id.vp_image)
public ViewPager vpImage;
@BindView(R.id.tv_image)
public TextView tvImage;
@BindView(R.id.tv_image_save)
TextView tvImageSave;
| // Path: app/src/main/java/com/zmj/qvod/module/bean/PicBean.java
// public class PicBean implements Serializable {
//
// private List<ItemsBean> items;
//
// public List<ItemsBean> getItems() {
// return items;
// }
//
// public static class ItemsBean implements Serializable {
//
// private String thumbUrl;
// private String pic_url;
// private String height;
// private String width;
//
// public String getHeight() {
// return height;
// }
//
// public void setHeight(String height) {
// this.height = height;
// }
//
// public String getWidth() {
// return width;
// }
//
//
// public String getThumbUrl() {
// return thumbUrl;
// }
//
// public String getPic_url() {
// return pic_url;
// }
//
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/presenter/ImageBrowsePresenter.java
// public class ImageBrowsePresenter extends BeamBasePresenter<ImageBrowseActivity> {
//
// private ArrayList<PicBean.ItemsBean> items;
// private int mPosition;
//
// @Override
// protected void onCreateView(@NonNull ImageBrowseActivity view) {
// super.onCreateView(view);
//
// initPrams();
//
// initImageLoader();
// }
//
// private void initPrams() {
// items = (ArrayList<PicBean.ItemsBean>) getView().getIntent().getSerializableExtra("items");
// mPosition = getView().getIntent().getIntExtra("position", 0);
// }
//
// private void initImageLoader() {
// ImageBrowseAdapter browseAdapter = new ImageBrowseAdapter(getView());
// browseAdapter.setItems(items);
// getView().vpImage.setAdapter(browseAdapter);
// getView().vpImage.setCurrentItem(mPosition);
// if (items != null && items.size() != 0) {
// getView().tvImage.setText((mPosition + 1) + "/" + items.size());
// }
// getView().vpImage.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
// @Override
// public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//
// }
//
// @Override
// public void onPageSelected(int position) {
// mPosition = position;
// if (items != null && items.size() != 0) {
// getView().tvImage.setText((position + 1) + "/" + items.size());
// }
// }
//
// @Override
// public void onPageScrollStateChanged(int state) {
//
// }
// });
// }
//
// /**
// * 保存图片至SD卡
// */
// public void saveImageSdCard() {
// JUtils.Toast("正在保存图片···");
// new Thread(() -> {
// BitmapFactory.Options Options = new BitmapFactory.Options();
// String cachePath = ImageLoader.getImagePath(items.get(mPosition).getPic_url());
// if (cachePath == null) {
// cachePath = ImageLoader.getImagePath(items.get(mPosition).getThumbUrl());
// }
// String finalCachePath = cachePath;
// getView().runOnUiThread(() -> {
// Bitmap bitmap = BitmapFactory.decodeFile(finalCachePath, Options);
// if (bitmap == null) return;
// FileUtils.saveImageToGallery(getView(), bitmap);
// JUtils.Toast("图片已保存至" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/Qvod");
// });
// }).start();
//
// }
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/utils/AppUtils.java
// public class AppUtils {
//
// /**
// * 获取状态栏高度
// *
// * @param context context
// * @return 状态栏高度
// */
// public static int getStatusBarHeight(Context context) {
// // 获得状态栏高度
// int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
// return context.getResources().getDimensionPixelSize(resourceId);
// }
//
// /**
// * [沉浸状态栏]
// */
// public static void steepStatusBar(Activity activity) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// // 透明状态栏
// activity.getWindow().addFlags(
// WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// // 透明导航栏
// activity.getWindow().addFlags(
// WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
// }
//
// }
//
// }
// Path: app/src/main/java/com/zmj/qvod/view/activity/ImageBrowseActivity.java
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.widget.TextView;
import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.BeamBaseActivity;
import com.zmj.qvod.R;
import com.zmj.qvod.module.bean.PicBean;
import com.zmj.qvod.presenter.ImageBrowsePresenter;
import com.zmj.qvod.utils.AppUtils;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
package com.zmj.qvod.view.activity;
/**
* Created by matt on 2017/4/18.
*/
@RequiresPresenter(ImageBrowsePresenter.class)
public class ImageBrowseActivity extends BeamBaseActivity<ImageBrowsePresenter> {
@BindView(R.id.vp_image)
public ViewPager vpImage;
@BindView(R.id.tv_image)
public TextView tvImage;
@BindView(R.id.tv_image_save)
TextView tvImageSave;
| public static void startAction(Context context, ArrayList<PicBean.ItemsBean> items, int position) { |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/app/VideoApplication.java | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/service/HttpUtils.java
// public class HttpUtils {
//
// private static final RestAdapter.LogLevel LOG_LEVEL = RestAdapter.LogLevel.NONE;
// //API
// private static final String VIDEO_HOST = "https://api.svipmovie.com/front";
// private static final String MOVIE_HOST = "https://api.douban.com";
// private static final String PIC_HOST = "https://pic.sogou.com";
// //
// private static RetrofitHttpClient mVideoClient;
// private static RetrofitHttpClient mMovieClient;
// private static RetrofitHttpClient mPicClient;
// //
// private Gson gson;
// private Context mContext;
// private static HttpUtils mHttpUtils;
//
// public void setContext(Context context) {
// this.mContext = context;
// }
//
// public static HttpUtils getInstance() {
// if (mHttpUtils == null) {
// mHttpUtils = new HttpUtils();
// }
// return mHttpUtils;
// }
//
// /**
// * 电影
// *
// * @return
// */
// public RetrofitHttpClient getVideoServer() {
// if (mVideoClient == null) {
// mVideoClient = getRestAdapter(VIDEO_HOST).create(RetrofitHttpClient.class);
// }
// return mVideoClient;
// }
//
// /**
// * 豆瓣
// *
// * @return
// */
// public RetrofitHttpClient getMovieServer() {
// if (mMovieClient == null) {
// mMovieClient = getRestAdapter(MOVIE_HOST).create(RetrofitHttpClient.class);
// }
// return mMovieClient;
// }
//
// /**
// * 图片
// *
// * @return
// */
// public RetrofitHttpClient getPicServer() {
// if (mPicClient == null) {
// mPicClient = getRestAdapter(PIC_HOST).create(RetrofitHttpClient.class);
// }
// return mPicClient;
// }
//
// private RestAdapter getRestAdapter(String HOST) {
// File cacheFile = new File(mContext.getApplicationContext().getCacheDir().getAbsolutePath(), "videoCache");
// int cacheSize = 10 * 1024 * 1024;
// Cache cache = new Cache(cacheFile, cacheSize);
// OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
// okBuilder.cache(cache);
// okBuilder.readTimeout(20, TimeUnit.SECONDS);//设置读取新连接超时
// okBuilder.connectTimeout(10, TimeUnit.SECONDS);//设置新连接的默认连接超时
// okBuilder.writeTimeout(20, TimeUnit.SECONDS);//设置默认为新连接编写超时
// OkHttpClient client = okBuilder.build();
// //
// RestAdapter.Builder restBuilder = new RestAdapter.Builder();
// restBuilder.setClient(new Ok3Client(client));
// restBuilder.setEndpoint(HOST);//URL_HOST
// restBuilder.setConverter(new GsonConverter(getGson()));//解析
// //
// RestAdapter videoRestAdapter = restBuilder.build();
// videoRestAdapter.setLogLevel(LOG_LEVEL);
// return videoRestAdapter;
// }
//
// private Gson getGson() {
// if (gson == null) {
// GsonBuilder gsonBuilder = new GsonBuilder();
// gsonBuilder.setFieldNamingStrategy(new AnnotateNaming());
// gsonBuilder.serializeNulls();
// gsonBuilder.excludeFieldsWithModifiers(Modifier.TRANSIENT);
// gson = gsonBuilder.create();
// }
// return gson;
// }
//
// private static class AnnotateNaming implements FieldNamingStrategy {
// @Override
// public String translateName(Field field) {
// ParamNames a = field.getAnnotation(ParamNames.class);
// return a != null ? a.value() : FieldNamingPolicy.IDENTITY.translateName(field);
// }
// }
//
//
// }
| import android.app.Application;
import com.jude.utils.JUtils;
import com.weavey.loading.lib.LoadingLayout;
import com.zmj.qvod.R;
import com.zmj.qvod.module.bean.VideoRes;
import com.zmj.qvod.module.service.HttpUtils; | package com.zmj.qvod.app;
/**
* Created by matt on 2016/11/22.
*/
public class VideoApplication extends Application {
private static VideoApplication videoApplication;
public static VideoApplication getInstance() {
if (videoApplication == null) {
synchronized (VideoApplication.class) {
if (videoApplication == null) {
videoApplication = new VideoApplication();
}
}
}
return videoApplication;
}
@Override
public void onCreate() {
super.onCreate();
videoApplication = this; | // Path: app/src/main/java/com/zmj/qvod/module/bean/VideoRes.java
// public class VideoRes {
//
//
// public
// @SerializedName("list")
// List<VideoType> list;
// public String title;
// public String score;
// public String videoType;
// public String region;
// public String airTime;
// public String director;
// public String actors;
// public String pic;
// public String description;
// public String smoothURL;
// public String SDURL;
// public String HDURL;
//
// public String getVideoUrl() {
// if (!TextUtils.isEmpty(HDURL))
// return HDURL;
// if (!TextUtils.isEmpty(SDURL))
// return SDURL;
// if (!TextUtils.isEmpty(smoothURL))
// return smoothURL;
// else
// return "";
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/module/service/HttpUtils.java
// public class HttpUtils {
//
// private static final RestAdapter.LogLevel LOG_LEVEL = RestAdapter.LogLevel.NONE;
// //API
// private static final String VIDEO_HOST = "https://api.svipmovie.com/front";
// private static final String MOVIE_HOST = "https://api.douban.com";
// private static final String PIC_HOST = "https://pic.sogou.com";
// //
// private static RetrofitHttpClient mVideoClient;
// private static RetrofitHttpClient mMovieClient;
// private static RetrofitHttpClient mPicClient;
// //
// private Gson gson;
// private Context mContext;
// private static HttpUtils mHttpUtils;
//
// public void setContext(Context context) {
// this.mContext = context;
// }
//
// public static HttpUtils getInstance() {
// if (mHttpUtils == null) {
// mHttpUtils = new HttpUtils();
// }
// return mHttpUtils;
// }
//
// /**
// * 电影
// *
// * @return
// */
// public RetrofitHttpClient getVideoServer() {
// if (mVideoClient == null) {
// mVideoClient = getRestAdapter(VIDEO_HOST).create(RetrofitHttpClient.class);
// }
// return mVideoClient;
// }
//
// /**
// * 豆瓣
// *
// * @return
// */
// public RetrofitHttpClient getMovieServer() {
// if (mMovieClient == null) {
// mMovieClient = getRestAdapter(MOVIE_HOST).create(RetrofitHttpClient.class);
// }
// return mMovieClient;
// }
//
// /**
// * 图片
// *
// * @return
// */
// public RetrofitHttpClient getPicServer() {
// if (mPicClient == null) {
// mPicClient = getRestAdapter(PIC_HOST).create(RetrofitHttpClient.class);
// }
// return mPicClient;
// }
//
// private RestAdapter getRestAdapter(String HOST) {
// File cacheFile = new File(mContext.getApplicationContext().getCacheDir().getAbsolutePath(), "videoCache");
// int cacheSize = 10 * 1024 * 1024;
// Cache cache = new Cache(cacheFile, cacheSize);
// OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
// okBuilder.cache(cache);
// okBuilder.readTimeout(20, TimeUnit.SECONDS);//设置读取新连接超时
// okBuilder.connectTimeout(10, TimeUnit.SECONDS);//设置新连接的默认连接超时
// okBuilder.writeTimeout(20, TimeUnit.SECONDS);//设置默认为新连接编写超时
// OkHttpClient client = okBuilder.build();
// //
// RestAdapter.Builder restBuilder = new RestAdapter.Builder();
// restBuilder.setClient(new Ok3Client(client));
// restBuilder.setEndpoint(HOST);//URL_HOST
// restBuilder.setConverter(new GsonConverter(getGson()));//解析
// //
// RestAdapter videoRestAdapter = restBuilder.build();
// videoRestAdapter.setLogLevel(LOG_LEVEL);
// return videoRestAdapter;
// }
//
// private Gson getGson() {
// if (gson == null) {
// GsonBuilder gsonBuilder = new GsonBuilder();
// gsonBuilder.setFieldNamingStrategy(new AnnotateNaming());
// gsonBuilder.serializeNulls();
// gsonBuilder.excludeFieldsWithModifiers(Modifier.TRANSIENT);
// gson = gsonBuilder.create();
// }
// return gson;
// }
//
// private static class AnnotateNaming implements FieldNamingStrategy {
// @Override
// public String translateName(Field field) {
// ParamNames a = field.getAnnotation(ParamNames.class);
// return a != null ? a.value() : FieldNamingPolicy.IDENTITY.translateName(field);
// }
// }
//
//
// }
// Path: app/src/main/java/com/zmj/qvod/app/VideoApplication.java
import android.app.Application;
import com.jude.utils.JUtils;
import com.weavey.loading.lib.LoadingLayout;
import com.zmj.qvod.R;
import com.zmj.qvod.module.bean.VideoRes;
import com.zmj.qvod.module.service.HttpUtils;
package com.zmj.qvod.app;
/**
* Created by matt on 2016/11/22.
*/
public class VideoApplication extends Application {
private static VideoApplication videoApplication;
public static VideoApplication getInstance() {
if (videoApplication == null) {
synchronized (VideoApplication.class) {
if (videoApplication == null) {
videoApplication = new VideoApplication();
}
}
}
return videoApplication;
}
@Override
public void onCreate() {
super.onCreate();
videoApplication = this; | HttpUtils.getInstance().setContext(this); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/view/activity/SplashActivity.java | // Path: app/src/main/java/com/zmj/qvod/presenter/SplashPresenter.java
// public class SplashPresenter extends Presenter<SplashActivity> {
//
// private static final int COUNT_DOWN_TIME = 2000;
// //
// private Subscription rxSubscription;
//
// @Override
// protected void onCreateView(@NonNull SplashActivity view) {
// super.onCreateView(view);
// //图片放大
// int page = StringUtils.getRandomNumber(0, getArrayList().size() - 1);
// ImageLoader.load(getView(), (String) getArrayList().get(page), getView().getImageView());
// getView().getImageView().animate().scaleX(1.12f).scaleY(1.12f).setDuration(2000).setStartDelay(100).start();
// //
// startCountDown();
// }
//
// private void startCountDown() {
// rxSubscription = Observable.timer(COUNT_DOWN_TIME, TimeUnit.MILLISECONDS)
// .compose(RxUtil.<Long>rxSchedulerHelper())
// .subscribe(new Action1<Long>() {
// @Override
// public void call(Long aLong) {
// getView().startMainActivity();
// }
// });
// }
//
// private ArrayList getArrayList() {
// ArrayList arrayList = new ArrayList();
// arrayList.add("file:///android_asset/a.jpg");
// arrayList.add("file:///android_asset/b.jpg");
// arrayList.add("file:///android_asset/c.jpg");
// arrayList.add("file:///android_asset/d.jpg");
// arrayList.add("file:///android_asset/e.jpg");
// arrayList.add("file:///android_asset/f.jpg");
// arrayList.add("file:///android_asset/g.jpg");
// return arrayList;
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// rxSubscription.unsubscribe();
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/utils/AppUtils.java
// public class AppUtils {
//
// /**
// * 获取状态栏高度
// *
// * @param context context
// * @return 状态栏高度
// */
// public static int getStatusBarHeight(Context context) {
// // 获得状态栏高度
// int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
// return context.getResources().getDimensionPixelSize(resourceId);
// }
//
// /**
// * [沉浸状态栏]
// */
// public static void steepStatusBar(Activity activity) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// // 透明状态栏
// activity.getWindow().addFlags(
// WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// // 透明导航栏
// activity.getWindow().addFlags(
// WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
// }
//
// }
//
// }
| import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.widget.ImageView;
import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.BeamBaseActivity;
import com.zmj.qvod.R;
import com.zmj.qvod.presenter.SplashPresenter;
import com.zmj.qvod.utils.AppUtils;
import butterknife.BindView;
import butterknife.ButterKnife; | package com.zmj.qvod.view.activity;
@RequiresPresenter(SplashPresenter.class)
public class SplashActivity extends BeamBaseActivity<SplashPresenter> {
@BindView(R.id.iv_splash_bg)
ImageView ivSplashBg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ButterKnife.bind(this);
| // Path: app/src/main/java/com/zmj/qvod/presenter/SplashPresenter.java
// public class SplashPresenter extends Presenter<SplashActivity> {
//
// private static final int COUNT_DOWN_TIME = 2000;
// //
// private Subscription rxSubscription;
//
// @Override
// protected void onCreateView(@NonNull SplashActivity view) {
// super.onCreateView(view);
// //图片放大
// int page = StringUtils.getRandomNumber(0, getArrayList().size() - 1);
// ImageLoader.load(getView(), (String) getArrayList().get(page), getView().getImageView());
// getView().getImageView().animate().scaleX(1.12f).scaleY(1.12f).setDuration(2000).setStartDelay(100).start();
// //
// startCountDown();
// }
//
// private void startCountDown() {
// rxSubscription = Observable.timer(COUNT_DOWN_TIME, TimeUnit.MILLISECONDS)
// .compose(RxUtil.<Long>rxSchedulerHelper())
// .subscribe(new Action1<Long>() {
// @Override
// public void call(Long aLong) {
// getView().startMainActivity();
// }
// });
// }
//
// private ArrayList getArrayList() {
// ArrayList arrayList = new ArrayList();
// arrayList.add("file:///android_asset/a.jpg");
// arrayList.add("file:///android_asset/b.jpg");
// arrayList.add("file:///android_asset/c.jpg");
// arrayList.add("file:///android_asset/d.jpg");
// arrayList.add("file:///android_asset/e.jpg");
// arrayList.add("file:///android_asset/f.jpg");
// arrayList.add("file:///android_asset/g.jpg");
// return arrayList;
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// rxSubscription.unsubscribe();
// }
// }
//
// Path: app/src/main/java/com/zmj/qvod/utils/AppUtils.java
// public class AppUtils {
//
// /**
// * 获取状态栏高度
// *
// * @param context context
// * @return 状态栏高度
// */
// public static int getStatusBarHeight(Context context) {
// // 获得状态栏高度
// int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
// return context.getResources().getDimensionPixelSize(resourceId);
// }
//
// /**
// * [沉浸状态栏]
// */
// public static void steepStatusBar(Activity activity) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// // 透明状态栏
// activity.getWindow().addFlags(
// WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// // 透明导航栏
// activity.getWindow().addFlags(
// WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
// }
//
// }
//
// }
// Path: app/src/main/java/com/zmj/qvod/view/activity/SplashActivity.java
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.widget.ImageView;
import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.BeamBaseActivity;
import com.zmj.qvod.R;
import com.zmj.qvod.presenter.SplashPresenter;
import com.zmj.qvod.utils.AppUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
package com.zmj.qvod.view.activity;
@RequiresPresenter(SplashPresenter.class)
public class SplashActivity extends BeamBaseActivity<SplashPresenter> {
@BindView(R.id.iv_splash_bg)
ImageView ivSplashBg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ButterKnife.bind(this);
| AppUtils.steepStatusBar(this); |
zhao-mingjian/qvod | app/src/main/java/com/zmj/qvod/view/activity/WebViewActivity.java | // Path: app/src/main/java/com/zmj/qvod/presenter/WebViewPresenter.java
// public class WebViewPresenter extends BeamBasePresenter<WebViewActivity> {
//
// @Override
// protected void onCreateView(@NonNull WebViewActivity view) {
// super.onCreateView(view);
//
// initParam();
// }
//
// private void initParam() {
// setUpWebViewDefaults(getView().webView);
// getView().webView.setWebViewClient(new MyWebViewClient(getView()));
// //设置显示进度条
// getView().webView.setWebChromeClient(new WebChromeClient() {
// @Override
// public void onProgressChanged(WebView view, int newProgress) {
// super.onProgressChanged(view, newProgress);
// if (newProgress == 100)
// getView().progressBar.setVisibility(View.GONE);
// else
// getView().progressBar.setProgress(newProgress);
// }
// });
// getView().webView.loadUrl(getView().getIntent().getStringExtra("url"));
// }
//
//
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// private void setUpWebViewDefaults(WebView webView) {
// WebSettings settings = webView.getSettings();
//
// // 网页内容的宽度是否可大于WebView控件的宽度
// settings.setLoadWithOverviewMode(false);
// // 保存表单数据
// settings.setSaveFormData(true);
// // 是否应该支持使用其屏幕缩放控件和手势缩放
// settings.setSupportZoom(true);
// settings.setBuiltInZoomControls(true);
// settings.setDisplayZoomControls(false);
// // 启动应用缓存
// settings.setAppCacheEnabled(true);
// // 设置缓存模式
// settings.setCacheMode(WebSettings.LOAD_DEFAULT);
// // setDefaultZoom api19被弃用
// // 设置此属性,可任意比例缩放。
// settings.setUseWideViewPort(true);
// // 缩放比例 1
// webView.setInitialScale(1);
// // 告诉WebView启用JavaScript执行。默认的是false。
// settings.setJavaScriptEnabled(true);
// // 页面加载好以后,再放开图片
// settings.setBlockNetworkImage(false);
// // 使用localStorage则必须打开
// settings.setDomStorageEnabled(true);
// // 排版适应屏幕
// settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
// // WebView是否支持多个窗口。
// settings.setSupportMultipleWindows(true);
//
// // webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
// }
//
// /** 设置字体默认缩放大小(改变网页字体大小,setTextSize api14被弃用)*/
// settings.setTextZoom(100);
//
// // Enable remote debugging via chrome://inspect
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// WebView.setWebContentsDebuggingEnabled(true);
// }
//
// // AppRTC requires third party cookies to work
// CookieManager cookieManager = CookieManager.getInstance();
// cookieManager.setAcceptThirdPartyCookies(webView, true);
//
//
// }
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/widght/TitleLayout.java
// public class TitleLayout extends RelativeLayout {
//
// private Toolbar toolbar;
//
// public TitleLayout(Context context, AttributeSet attrs) {
// super(context, attrs);
// LayoutInflater.from(context).inflate(R.layout.include_title_layout, this);
// //
// toolbar = (Toolbar) findViewById(R.id.toolbar);
// //
// ((AppCompatActivity) getContext()).setSupportActionBar(toolbar);
// ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
// if (actionBar != null) {
// //是否显示默认Title
// actionBar.setDisplayShowTitleEnabled(true);
// //是否显示返回键
// actionBar.setDisplayHomeAsUpEnabled(true);
// //监听返回键
// toolbar.setNavigationOnClickListener(view -> ((AppCompatActivity) getContext()).onBackPressed());
// }
// }
//
// public Toolbar getToolbar() {
// return toolbar;
// }
//
// }
| import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.ProgressBar;
import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.BeamBaseActivity;
import com.zmj.qvod.R;
import com.zmj.qvod.presenter.WebViewPresenter;
import com.zmj.qvod.widght.TitleLayout;
import butterknife.BindView;
import butterknife.ButterKnife; | package com.zmj.qvod.view.activity;
/**
* Created by matt on 2017/4/14.
*/
@RequiresPresenter(WebViewPresenter.class)
public class WebViewActivity extends BeamBaseActivity<WebViewPresenter> {
@BindView(R.id.wv_web)
public WebView webView;
@BindView(R.id.tl_toolbar) | // Path: app/src/main/java/com/zmj/qvod/presenter/WebViewPresenter.java
// public class WebViewPresenter extends BeamBasePresenter<WebViewActivity> {
//
// @Override
// protected void onCreateView(@NonNull WebViewActivity view) {
// super.onCreateView(view);
//
// initParam();
// }
//
// private void initParam() {
// setUpWebViewDefaults(getView().webView);
// getView().webView.setWebViewClient(new MyWebViewClient(getView()));
// //设置显示进度条
// getView().webView.setWebChromeClient(new WebChromeClient() {
// @Override
// public void onProgressChanged(WebView view, int newProgress) {
// super.onProgressChanged(view, newProgress);
// if (newProgress == 100)
// getView().progressBar.setVisibility(View.GONE);
// else
// getView().progressBar.setProgress(newProgress);
// }
// });
// getView().webView.loadUrl(getView().getIntent().getStringExtra("url"));
// }
//
//
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// private void setUpWebViewDefaults(WebView webView) {
// WebSettings settings = webView.getSettings();
//
// // 网页内容的宽度是否可大于WebView控件的宽度
// settings.setLoadWithOverviewMode(false);
// // 保存表单数据
// settings.setSaveFormData(true);
// // 是否应该支持使用其屏幕缩放控件和手势缩放
// settings.setSupportZoom(true);
// settings.setBuiltInZoomControls(true);
// settings.setDisplayZoomControls(false);
// // 启动应用缓存
// settings.setAppCacheEnabled(true);
// // 设置缓存模式
// settings.setCacheMode(WebSettings.LOAD_DEFAULT);
// // setDefaultZoom api19被弃用
// // 设置此属性,可任意比例缩放。
// settings.setUseWideViewPort(true);
// // 缩放比例 1
// webView.setInitialScale(1);
// // 告诉WebView启用JavaScript执行。默认的是false。
// settings.setJavaScriptEnabled(true);
// // 页面加载好以后,再放开图片
// settings.setBlockNetworkImage(false);
// // 使用localStorage则必须打开
// settings.setDomStorageEnabled(true);
// // 排版适应屏幕
// settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
// // WebView是否支持多个窗口。
// settings.setSupportMultipleWindows(true);
//
// // webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
// }
//
// /** 设置字体默认缩放大小(改变网页字体大小,setTextSize api14被弃用)*/
// settings.setTextZoom(100);
//
// // Enable remote debugging via chrome://inspect
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// WebView.setWebContentsDebuggingEnabled(true);
// }
//
// // AppRTC requires third party cookies to work
// CookieManager cookieManager = CookieManager.getInstance();
// cookieManager.setAcceptThirdPartyCookies(webView, true);
//
//
// }
//
// }
//
// Path: app/src/main/java/com/zmj/qvod/widght/TitleLayout.java
// public class TitleLayout extends RelativeLayout {
//
// private Toolbar toolbar;
//
// public TitleLayout(Context context, AttributeSet attrs) {
// super(context, attrs);
// LayoutInflater.from(context).inflate(R.layout.include_title_layout, this);
// //
// toolbar = (Toolbar) findViewById(R.id.toolbar);
// //
// ((AppCompatActivity) getContext()).setSupportActionBar(toolbar);
// ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
// if (actionBar != null) {
// //是否显示默认Title
// actionBar.setDisplayShowTitleEnabled(true);
// //是否显示返回键
// actionBar.setDisplayHomeAsUpEnabled(true);
// //监听返回键
// toolbar.setNavigationOnClickListener(view -> ((AppCompatActivity) getContext()).onBackPressed());
// }
// }
//
// public Toolbar getToolbar() {
// return toolbar;
// }
//
// }
// Path: app/src/main/java/com/zmj/qvod/view/activity/WebViewActivity.java
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.ProgressBar;
import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.BeamBaseActivity;
import com.zmj.qvod.R;
import com.zmj.qvod.presenter.WebViewPresenter;
import com.zmj.qvod.widght.TitleLayout;
import butterknife.BindView;
import butterknife.ButterKnife;
package com.zmj.qvod.view.activity;
/**
* Created by matt on 2017/4/14.
*/
@RequiresPresenter(WebViewPresenter.class)
public class WebViewActivity extends BeamBaseActivity<WebViewPresenter> {
@BindView(R.id.wv_web)
public WebView webView;
@BindView(R.id.tl_toolbar) | public TitleLayout tlToolbar; |
h-omer/neo4j-versioner-core | src/test/java/org/homer/versioner/core/builders/InitBuilderTest.java | // Path: src/main/java/org/homer/versioner/core/procedure/Init.java
// public class Init extends CoreProcedure {
//
// @Procedure(value = "graph.versioner.init", mode = Mode.WRITE)
// @Description("graph.versioner.init(entityLabel, {key:value,...}, {key:value,...}, additionalLabel, date) - Create an Entity node with an optional initial State.")
// public Stream<NodeOutput> init(
// @Name("entityLabel") String entityLabel,
// @Name(value = "entityProps", defaultValue = "{}") Map<String, Object> entityProps,
// @Name(value = "stateProps", defaultValue = "{}") Map<String, Object> stateProps,
// @Name(value = "additionalLabel", defaultValue = "") String additionalLabel,
// @Name(value = "date", defaultValue = "null") LocalDateTime date) {
//
// Node entity = createNode(entityProps, singletonList(entityLabel), transaction);
//
// Node state = createNode(stateProps, getStateLabels(additionalLabel), transaction);
//
// connectWithCurrentRelationship(entity, state, date);
//
// log.info(LOGGER_TAG + "Created a new Entity with label {} and id {}", entityLabel, entity.getId());
//
// createRNodeAndAssociateTo(entity, transaction);
//
// return streamOfNodes(entity);
// }
//
// private Node createNode(Map<String, Object> properties, List<String> labels, Transaction transaction) {
//
// return setProperties(transaction.createNode(asLabels(labels)), properties);
// }
//
// private void connectWithCurrentRelationship(Node entity, Node state, LocalDateTime date) {
//
// LocalDateTime instantDate = (date == null) ? convertEpochToLocalDateTime(Calendar.getInstance().getTimeInMillis()) : date;
// addCurrentState(state, entity, instantDate);
// }
//
// private void createRNodeAndAssociateTo(Node entity, Transaction transaction) {
//
// Node rNode = transaction.createNode(Label.label("R"));
// rNode.createRelationshipTo(entity, RelationshipType.withName("FOR"));
// }
// }
| import org.homer.versioner.core.procedure.Init;
import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.logging.Log;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.mock; | package org.homer.versioner.core.builders;
/**
* DiffBuilderTest class, it contains all the method used to test procedure builders
*/
public class InitBuilderTest {
@Test
public void shouldBuildCorrectProcedureInstance() {
Transaction transaction = mock(Transaction.class);
Log log = mock(Log.class);
| // Path: src/main/java/org/homer/versioner/core/procedure/Init.java
// public class Init extends CoreProcedure {
//
// @Procedure(value = "graph.versioner.init", mode = Mode.WRITE)
// @Description("graph.versioner.init(entityLabel, {key:value,...}, {key:value,...}, additionalLabel, date) - Create an Entity node with an optional initial State.")
// public Stream<NodeOutput> init(
// @Name("entityLabel") String entityLabel,
// @Name(value = "entityProps", defaultValue = "{}") Map<String, Object> entityProps,
// @Name(value = "stateProps", defaultValue = "{}") Map<String, Object> stateProps,
// @Name(value = "additionalLabel", defaultValue = "") String additionalLabel,
// @Name(value = "date", defaultValue = "null") LocalDateTime date) {
//
// Node entity = createNode(entityProps, singletonList(entityLabel), transaction);
//
// Node state = createNode(stateProps, getStateLabels(additionalLabel), transaction);
//
// connectWithCurrentRelationship(entity, state, date);
//
// log.info(LOGGER_TAG + "Created a new Entity with label {} and id {}", entityLabel, entity.getId());
//
// createRNodeAndAssociateTo(entity, transaction);
//
// return streamOfNodes(entity);
// }
//
// private Node createNode(Map<String, Object> properties, List<String> labels, Transaction transaction) {
//
// return setProperties(transaction.createNode(asLabels(labels)), properties);
// }
//
// private void connectWithCurrentRelationship(Node entity, Node state, LocalDateTime date) {
//
// LocalDateTime instantDate = (date == null) ? convertEpochToLocalDateTime(Calendar.getInstance().getTimeInMillis()) : date;
// addCurrentState(state, entity, instantDate);
// }
//
// private void createRNodeAndAssociateTo(Node entity, Transaction transaction) {
//
// Node rNode = transaction.createNode(Label.label("R"));
// rNode.createRelationshipTo(entity, RelationshipType.withName("FOR"));
// }
// }
// Path: src/test/java/org/homer/versioner/core/builders/InitBuilderTest.java
import org.homer.versioner.core.procedure.Init;
import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.logging.Log;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.mock;
package org.homer.versioner.core.builders;
/**
* DiffBuilderTest class, it contains all the method used to test procedure builders
*/
public class InitBuilderTest {
@Test
public void shouldBuildCorrectProcedureInstance() {
Transaction transaction = mock(Transaction.class);
Log log = mock(Log.class);
| Optional<Init> result = new InitBuilder().withTransaction(transaction).withLog(log).build(); |
h-omer/neo4j-versioner-core | src/test/java/org/homer/versioner/core/builders/GetBuilderTest.java | // Path: src/main/java/org/homer/versioner/core/procedure/Get.java
// public class Get {
//
// @Procedure(value = "graph.versioner.get.current.path", mode = DEFAULT)
// @Description("graph.versioner.get.current.path(entity) - Get the current Path (Entity, State and rels) for the given Entity.")
// public Stream<PathOutput> getCurrentPath(
// @Name("entity") Node entity) {
//
// PathImpl.Builder builder = new PathImpl.Builder(entity);
//
// builder = Optional.ofNullable(entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
// .map(builder::push)
// .orElse(new PathImpl.Builder(entity));
//
// return Stream.of(builder.build()).map(PathOutput::new);
// }
//
// @Procedure(value = "graph.versioner.get.current.state", mode = DEFAULT)
// @Description("graph.versioner.get.current.state(entity) - Get the current State node for the given Entity.")
// public Stream<NodeOutput> getCurrentState(
// @Name("entity") Node entity) {
//
// return Stream.of(Optional.ofNullable(entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
// .map(Relationship::getEndNode).map(NodeOutput::new).orElse(null));
// }
//
//
// //fix for error Node[xyz] not connected to this relationship[xyz]
// @Procedure(value = "graph.versioner.get.all", mode = DEFAULT)
// @Description("graph.versioner.get.all(entity) - Get all the State nodes for the given Entity.")
// public Stream<PathOutput> getAllState(
// @Name("entity") Node entity) {
//
// PathImpl.Builder builder = new PathImpl.Builder(entity)
// .push(entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING));
// builder = StreamSupport.stream(entity.getRelationships(Direction.OUTGOING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator(), false)
// .reduce(
// builder,
// (build, rel) -> Optional.ofNullable(rel.getEndNode().getSingleRelationship(RelationshipType.withName(Utility.PREVIOUS_TYPE), Direction.OUTGOING))
// .map(build::push)
// .orElse(build),
// (a, b) -> a);
// return Stream.of(new PathOutput(builder.build()));
// }
//
// @Procedure(value = "graph.versioner.get.by.label", mode = DEFAULT)
// @Description("graph.versioner.get.by.label(entity, label) - Get State nodes with the given label, by the given Entity node")
// public Stream<NodeOutput> getAllStateByLabel(
// @Name("entity") Node entity,
// @Name("label") String label) {
//
// return StreamSupport.stream(entity.getRelationships(Direction.OUTGOING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator(), false)
// .map(Relationship::getEndNode)
// .filter(node -> node.hasLabel(Label.label(label)))
// .map(NodeOutput::new);
// }
//
// @Procedure(value = "graph.versioner.get.by.date", mode = DEFAULT)
// @Description("graph.versioner.get.by.date(entity, date) - Get State node by the given Entity node, created at the given date")
// public Stream<NodeOutput> getStateByDate(
// @Name("entity") Node entity,
// @Name("date") LocalDateTime date) {
//
// return StreamSupport.stream(entity.getRelationships(Direction.OUTGOING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator(), false)
// .filter(relationship -> relationship.getProperty(Utility.START_DATE_PROP).equals(date))
// .map(Relationship::getEndNode)
// .map(NodeOutput::new);
// }
//
// @Procedure(value = "graph.versioner.get.nth.state", mode = DEFAULT)
// @Description("graph.versioner.get.nth.state(entity, nth) - Get the nth State node for the given Entity.")
// public Stream<NodeOutput> getNthState(
// @Name("entity") Node entity,
// @Name("nth") long nth) {
//
// return getCurrentState(entity)
// .findFirst()
// .flatMap(currentState -> getNthStateFrom(currentState.node, nth))
// .map(Utility::streamOfNodes)
// .orElse(Stream.empty());
// }
//
// private Optional<Node> getNthStateFrom(Node state, long nth) {
//
// return Stream.iterate(Optional.of(state), s -> s.flatMap(this::jumpToPreviousState))
// .limit(nth + 1)
// .reduce((a, b) -> b) //get only the last value (apply jumpToPreviousState n times
// .orElse(Optional.empty());
// }
//
// private Optional<Node> jumpToPreviousState(Node state) {
//
// return StreamSupport.stream(state.getRelationships(Direction.OUTGOING, RelationshipType.withName(Utility.PREVIOUS_TYPE)).spliterator(), false)
// .findFirst()
// .map(Relationship::getEndNode);
// }
// }
| import org.homer.versioner.core.procedure.Get;
import org.junit.Test;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is; | package org.homer.versioner.core.builders;
/**
* DiffBuilderTest class, it contains all the method used to test procedure builders
*/
public class GetBuilderTest {
@Test
public void shouldBuildCorrectProcedureInstance() { | // Path: src/main/java/org/homer/versioner/core/procedure/Get.java
// public class Get {
//
// @Procedure(value = "graph.versioner.get.current.path", mode = DEFAULT)
// @Description("graph.versioner.get.current.path(entity) - Get the current Path (Entity, State and rels) for the given Entity.")
// public Stream<PathOutput> getCurrentPath(
// @Name("entity") Node entity) {
//
// PathImpl.Builder builder = new PathImpl.Builder(entity);
//
// builder = Optional.ofNullable(entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
// .map(builder::push)
// .orElse(new PathImpl.Builder(entity));
//
// return Stream.of(builder.build()).map(PathOutput::new);
// }
//
// @Procedure(value = "graph.versioner.get.current.state", mode = DEFAULT)
// @Description("graph.versioner.get.current.state(entity) - Get the current State node for the given Entity.")
// public Stream<NodeOutput> getCurrentState(
// @Name("entity") Node entity) {
//
// return Stream.of(Optional.ofNullable(entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
// .map(Relationship::getEndNode).map(NodeOutput::new).orElse(null));
// }
//
//
// //fix for error Node[xyz] not connected to this relationship[xyz]
// @Procedure(value = "graph.versioner.get.all", mode = DEFAULT)
// @Description("graph.versioner.get.all(entity) - Get all the State nodes for the given Entity.")
// public Stream<PathOutput> getAllState(
// @Name("entity") Node entity) {
//
// PathImpl.Builder builder = new PathImpl.Builder(entity)
// .push(entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING));
// builder = StreamSupport.stream(entity.getRelationships(Direction.OUTGOING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator(), false)
// .reduce(
// builder,
// (build, rel) -> Optional.ofNullable(rel.getEndNode().getSingleRelationship(RelationshipType.withName(Utility.PREVIOUS_TYPE), Direction.OUTGOING))
// .map(build::push)
// .orElse(build),
// (a, b) -> a);
// return Stream.of(new PathOutput(builder.build()));
// }
//
// @Procedure(value = "graph.versioner.get.by.label", mode = DEFAULT)
// @Description("graph.versioner.get.by.label(entity, label) - Get State nodes with the given label, by the given Entity node")
// public Stream<NodeOutput> getAllStateByLabel(
// @Name("entity") Node entity,
// @Name("label") String label) {
//
// return StreamSupport.stream(entity.getRelationships(Direction.OUTGOING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator(), false)
// .map(Relationship::getEndNode)
// .filter(node -> node.hasLabel(Label.label(label)))
// .map(NodeOutput::new);
// }
//
// @Procedure(value = "graph.versioner.get.by.date", mode = DEFAULT)
// @Description("graph.versioner.get.by.date(entity, date) - Get State node by the given Entity node, created at the given date")
// public Stream<NodeOutput> getStateByDate(
// @Name("entity") Node entity,
// @Name("date") LocalDateTime date) {
//
// return StreamSupport.stream(entity.getRelationships(Direction.OUTGOING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator(), false)
// .filter(relationship -> relationship.getProperty(Utility.START_DATE_PROP).equals(date))
// .map(Relationship::getEndNode)
// .map(NodeOutput::new);
// }
//
// @Procedure(value = "graph.versioner.get.nth.state", mode = DEFAULT)
// @Description("graph.versioner.get.nth.state(entity, nth) - Get the nth State node for the given Entity.")
// public Stream<NodeOutput> getNthState(
// @Name("entity") Node entity,
// @Name("nth") long nth) {
//
// return getCurrentState(entity)
// .findFirst()
// .flatMap(currentState -> getNthStateFrom(currentState.node, nth))
// .map(Utility::streamOfNodes)
// .orElse(Stream.empty());
// }
//
// private Optional<Node> getNthStateFrom(Node state, long nth) {
//
// return Stream.iterate(Optional.of(state), s -> s.flatMap(this::jumpToPreviousState))
// .limit(nth + 1)
// .reduce((a, b) -> b) //get only the last value (apply jumpToPreviousState n times
// .orElse(Optional.empty());
// }
//
// private Optional<Node> jumpToPreviousState(Node state) {
//
// return StreamSupport.stream(state.getRelationships(Direction.OUTGOING, RelationshipType.withName(Utility.PREVIOUS_TYPE)).spliterator(), false)
// .findFirst()
// .map(Relationship::getEndNode);
// }
// }
// Path: src/test/java/org/homer/versioner/core/builders/GetBuilderTest.java
import org.homer.versioner.core.procedure.Get;
import org.junit.Test;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
package org.homer.versioner.core.builders;
/**
* DiffBuilderTest class, it contains all the method used to test procedure builders
*/
public class GetBuilderTest {
@Test
public void shouldBuildCorrectProcedureInstance() { | Optional<Get> result = new GetBuilder().build(); |
h-omer/neo4j-versioner-core | src/main/java/org/homer/versioner/core/Utility.java | // Path: src/main/java/org/homer/versioner/core/exception/VersionerCoreException.java
// public class VersionerCoreException extends RuntimeException {
//
// public VersionerCoreException(String s) {
// super(s);
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/NodeOutput.java
// public class NodeOutput {
// public Node node;
//
// public NodeOutput(Node node) {
// this.node = node;
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/RelationshipOutput.java
// public class RelationshipOutput {
// public Relationship relationship;
//
// public RelationshipOutput(Relationship relationship) {
// this.relationship = relationship;
// }
// }
| import org.apache.commons.lang3.tuple.Pair;
import org.homer.versioner.core.exception.VersionerCoreException;
import org.homer.versioner.core.output.NodeOutput;
import org.homer.versioner.core.output.RelationshipOutput;
import org.neo4j.graphdb.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport; | addCurrentState(result, entity, instantDate);
return result;
}
/**
* Connects a new State {@link Node} as the Current one, to the given Entity
*
* @param state a {@link Node} representing the new current State
* @param entity a {@link Node} representing the Entity
* @param instantDate the new current State date
*/
public static void addCurrentState(Node state, Node entity, LocalDateTime instantDate) {
entity.createRelationshipTo(state, RelationshipType.withName(CURRENT_TYPE)).setProperty(DATE_PROP, instantDate);
entity.createRelationshipTo(state, RelationshipType.withName(HAS_STATE_TYPE)).setProperty(START_DATE_PROP, instantDate);
}
/**
* Checks if the given entity is related through the HAS_STATE relationship with the given node
*
* @param entity a {@link Node} representing the Entity
* @param state a {@link Node} representing the State
* @return {@link Boolean} result
*/
public static Boolean checkRelationship(Node entity, Node state) {
Spliterator<Relationship> stateRelIterator = state.getRelationships(Direction.INCOMING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator();
return StreamSupport.stream(stateRelIterator, false).map(hasStateRel -> {
Node maybeEntity = hasStateRel.getStartNode();
if (maybeEntity.getId() != entity.getId()) { | // Path: src/main/java/org/homer/versioner/core/exception/VersionerCoreException.java
// public class VersionerCoreException extends RuntimeException {
//
// public VersionerCoreException(String s) {
// super(s);
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/NodeOutput.java
// public class NodeOutput {
// public Node node;
//
// public NodeOutput(Node node) {
// this.node = node;
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/RelationshipOutput.java
// public class RelationshipOutput {
// public Relationship relationship;
//
// public RelationshipOutput(Relationship relationship) {
// this.relationship = relationship;
// }
// }
// Path: src/main/java/org/homer/versioner/core/Utility.java
import org.apache.commons.lang3.tuple.Pair;
import org.homer.versioner.core.exception.VersionerCoreException;
import org.homer.versioner.core.output.NodeOutput;
import org.homer.versioner.core.output.RelationshipOutput;
import org.neo4j.graphdb.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
addCurrentState(result, entity, instantDate);
return result;
}
/**
* Connects a new State {@link Node} as the Current one, to the given Entity
*
* @param state a {@link Node} representing the new current State
* @param entity a {@link Node} representing the Entity
* @param instantDate the new current State date
*/
public static void addCurrentState(Node state, Node entity, LocalDateTime instantDate) {
entity.createRelationshipTo(state, RelationshipType.withName(CURRENT_TYPE)).setProperty(DATE_PROP, instantDate);
entity.createRelationshipTo(state, RelationshipType.withName(HAS_STATE_TYPE)).setProperty(START_DATE_PROP, instantDate);
}
/**
* Checks if the given entity is related through the HAS_STATE relationship with the given node
*
* @param entity a {@link Node} representing the Entity
* @param state a {@link Node} representing the State
* @return {@link Boolean} result
*/
public static Boolean checkRelationship(Node entity, Node state) {
Spliterator<Relationship> stateRelIterator = state.getRelationships(Direction.INCOMING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator();
return StreamSupport.stream(stateRelIterator, false).map(hasStateRel -> {
Node maybeEntity = hasStateRel.getStartNode();
if (maybeEntity.getId() != entity.getId()) { | throw new VersionerCoreException("Can't patch the given entity, because the given State is owned by another entity."); |
h-omer/neo4j-versioner-core | src/main/java/org/homer/versioner/core/Utility.java | // Path: src/main/java/org/homer/versioner/core/exception/VersionerCoreException.java
// public class VersionerCoreException extends RuntimeException {
//
// public VersionerCoreException(String s) {
// super(s);
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/NodeOutput.java
// public class NodeOutput {
// public Node node;
//
// public NodeOutput(Node node) {
// this.node = node;
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/RelationshipOutput.java
// public class RelationshipOutput {
// public Relationship relationship;
//
// public RelationshipOutput(Relationship relationship) {
// this.relationship = relationship;
// }
// }
| import org.apache.commons.lang3.tuple.Pair;
import org.homer.versioner.core.exception.VersionerCoreException;
import org.homer.versioner.core.output.NodeOutput;
import org.homer.versioner.core.output.RelationshipOutput;
import org.neo4j.graphdb.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport; | entity.createRelationshipTo(state, RelationshipType.withName(HAS_STATE_TYPE)).setProperty(START_DATE_PROP, instantDate);
}
/**
* Checks if the given entity is related through the HAS_STATE relationship with the given node
*
* @param entity a {@link Node} representing the Entity
* @param state a {@link Node} representing the State
* @return {@link Boolean} result
*/
public static Boolean checkRelationship(Node entity, Node state) {
Spliterator<Relationship> stateRelIterator = state.getRelationships(Direction.INCOMING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator();
return StreamSupport.stream(stateRelIterator, false).map(hasStateRel -> {
Node maybeEntity = hasStateRel.getStartNode();
if (maybeEntity.getId() != entity.getId()) {
throw new VersionerCoreException("Can't patch the given entity, because the given State is owned by another entity.");
}
return true;
})
.findFirst()
.orElseThrow(() -> new VersionerCoreException("Can't find any entity node relate to the given State."));
}
/**
* Converts the nodes to a stream of {@link NodeOutput}
*
* @param nodes a {@link List} of {@link Node} that will be converted to stream and mapped into {@link NodeOutput}
* @return {@link Stream} streamOfNodes
*/ | // Path: src/main/java/org/homer/versioner/core/exception/VersionerCoreException.java
// public class VersionerCoreException extends RuntimeException {
//
// public VersionerCoreException(String s) {
// super(s);
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/NodeOutput.java
// public class NodeOutput {
// public Node node;
//
// public NodeOutput(Node node) {
// this.node = node;
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/RelationshipOutput.java
// public class RelationshipOutput {
// public Relationship relationship;
//
// public RelationshipOutput(Relationship relationship) {
// this.relationship = relationship;
// }
// }
// Path: src/main/java/org/homer/versioner/core/Utility.java
import org.apache.commons.lang3.tuple.Pair;
import org.homer.versioner.core.exception.VersionerCoreException;
import org.homer.versioner.core.output.NodeOutput;
import org.homer.versioner.core.output.RelationshipOutput;
import org.neo4j.graphdb.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
entity.createRelationshipTo(state, RelationshipType.withName(HAS_STATE_TYPE)).setProperty(START_DATE_PROP, instantDate);
}
/**
* Checks if the given entity is related through the HAS_STATE relationship with the given node
*
* @param entity a {@link Node} representing the Entity
* @param state a {@link Node} representing the State
* @return {@link Boolean} result
*/
public static Boolean checkRelationship(Node entity, Node state) {
Spliterator<Relationship> stateRelIterator = state.getRelationships(Direction.INCOMING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator();
return StreamSupport.stream(stateRelIterator, false).map(hasStateRel -> {
Node maybeEntity = hasStateRel.getStartNode();
if (maybeEntity.getId() != entity.getId()) {
throw new VersionerCoreException("Can't patch the given entity, because the given State is owned by another entity.");
}
return true;
})
.findFirst()
.orElseThrow(() -> new VersionerCoreException("Can't find any entity node relate to the given State."));
}
/**
* Converts the nodes to a stream of {@link NodeOutput}
*
* @param nodes a {@link List} of {@link Node} that will be converted to stream and mapped into {@link NodeOutput}
* @return {@link Stream} streamOfNodes
*/ | public static Stream<NodeOutput> streamOfNodes(Node... nodes) { |
h-omer/neo4j-versioner-core | src/main/java/org/homer/versioner/core/Utility.java | // Path: src/main/java/org/homer/versioner/core/exception/VersionerCoreException.java
// public class VersionerCoreException extends RuntimeException {
//
// public VersionerCoreException(String s) {
// super(s);
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/NodeOutput.java
// public class NodeOutput {
// public Node node;
//
// public NodeOutput(Node node) {
// this.node = node;
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/RelationshipOutput.java
// public class RelationshipOutput {
// public Relationship relationship;
//
// public RelationshipOutput(Relationship relationship) {
// this.relationship = relationship;
// }
// }
| import org.apache.commons.lang3.tuple.Pair;
import org.homer.versioner.core.exception.VersionerCoreException;
import org.homer.versioner.core.output.NodeOutput;
import org.homer.versioner.core.output.RelationshipOutput;
import org.neo4j.graphdb.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport; | public static Boolean checkRelationship(Node entity, Node state) {
Spliterator<Relationship> stateRelIterator = state.getRelationships(Direction.INCOMING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator();
return StreamSupport.stream(stateRelIterator, false).map(hasStateRel -> {
Node maybeEntity = hasStateRel.getStartNode();
if (maybeEntity.getId() != entity.getId()) {
throw new VersionerCoreException("Can't patch the given entity, because the given State is owned by another entity.");
}
return true;
})
.findFirst()
.orElseThrow(() -> new VersionerCoreException("Can't find any entity node relate to the given State."));
}
/**
* Converts the nodes to a stream of {@link NodeOutput}
*
* @param nodes a {@link List} of {@link Node} that will be converted to stream and mapped into {@link NodeOutput}
* @return {@link Stream} streamOfNodes
*/
public static Stream<NodeOutput> streamOfNodes(Node... nodes) {
return Stream.of(nodes).map(NodeOutput::new);
}
/**
* Converts the relationships to a stream of {@link RelationshipOutput}
*
* @param relationships a {@link List} of {@link Relationship} that will be converted to stream and mapped into {@link RelationshipOutput}
* @return
*/ | // Path: src/main/java/org/homer/versioner/core/exception/VersionerCoreException.java
// public class VersionerCoreException extends RuntimeException {
//
// public VersionerCoreException(String s) {
// super(s);
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/NodeOutput.java
// public class NodeOutput {
// public Node node;
//
// public NodeOutput(Node node) {
// this.node = node;
// }
// }
//
// Path: src/main/java/org/homer/versioner/core/output/RelationshipOutput.java
// public class RelationshipOutput {
// public Relationship relationship;
//
// public RelationshipOutput(Relationship relationship) {
// this.relationship = relationship;
// }
// }
// Path: src/main/java/org/homer/versioner/core/Utility.java
import org.apache.commons.lang3.tuple.Pair;
import org.homer.versioner.core.exception.VersionerCoreException;
import org.homer.versioner.core.output.NodeOutput;
import org.homer.versioner.core.output.RelationshipOutput;
import org.neo4j.graphdb.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public static Boolean checkRelationship(Node entity, Node state) {
Spliterator<Relationship> stateRelIterator = state.getRelationships(Direction.INCOMING, RelationshipType.withName(Utility.HAS_STATE_TYPE)).spliterator();
return StreamSupport.stream(stateRelIterator, false).map(hasStateRel -> {
Node maybeEntity = hasStateRel.getStartNode();
if (maybeEntity.getId() != entity.getId()) {
throw new VersionerCoreException("Can't patch the given entity, because the given State is owned by another entity.");
}
return true;
})
.findFirst()
.orElseThrow(() -> new VersionerCoreException("Can't find any entity node relate to the given State."));
}
/**
* Converts the nodes to a stream of {@link NodeOutput}
*
* @param nodes a {@link List} of {@link Node} that will be converted to stream and mapped into {@link NodeOutput}
* @return {@link Stream} streamOfNodes
*/
public static Stream<NodeOutput> streamOfNodes(Node... nodes) {
return Stream.of(nodes).map(NodeOutput::new);
}
/**
* Converts the relationships to a stream of {@link RelationshipOutput}
*
* @param relationships a {@link List} of {@link Relationship} that will be converted to stream and mapped into {@link RelationshipOutput}
* @return
*/ | public static Stream<RelationshipOutput> streamOfRelationships(Relationship... relationships) { |
h-omer/neo4j-versioner-core | src/test/java/org/homer/versioner/core/builders/DiffBuilderTest.java | // Path: src/main/java/org/homer/versioner/core/procedure/Diff.java
// public class Diff {
//
// @Procedure(value = "graph.versioner.diff", mode = DEFAULT)
// @Description("graph.versioner.diff(stateFrom, stateTo) - Get a list of differences that must be applied to stateFrom in order to convert it into stateTo")
// public Stream<DiffOutput> diff(
// @Name("stateFrom") Node stateFrom,
// @Name("stateTo") Node stateTo) {
// return diffBetweenStates(stateFrom, stateTo);
// }
//
// @Procedure(value = "graph.versioner.diff.from.previous", mode = DEFAULT)
// @Description("graph.versioner.diff.from.previous(state) - Get a list of differences that must be applied to the previous statusof the given one in order to become the given state")
// public Stream<DiffOutput> diffFromPrevious(
// @Name("state") Node state) {
//
// return Optional.ofNullable(state.getSingleRelationship(RelationshipType.withName(Utility.PREVIOUS_TYPE), Direction.OUTGOING))
// .map(Relationship::getEndNode)
// .map(sFrom -> diffBetweenStates(sFrom, state))
// .orElse(Stream.empty());
// }
//
// @Procedure(value = "graph.versioner.diff.from.current", mode = DEFAULT)
// @Description("graph.versioner.diff.from.current(state) - Get a list of differences that must be applied to the given state in order to become the current entity state")
// public Stream<DiffOutput> diffFromCurrent(
// @Name("state") Node state) {
//
// return Optional.ofNullable(state.getSingleRelationship(RelationshipType.withName(Utility.HAS_STATE_TYPE), Direction.INCOMING))
// .map(Relationship::getStartNode)
// .map(entity -> entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
// .map(Relationship::getEndNode)
// .filter(current -> !current.equals(state))
// .map(current -> diffBetweenStates(state, current))
// .orElse(Stream.empty());
// }
//
// /**
// * It returns a {@link Stream<DiffOutput>} by the given nodes
// *
// * @param from
// * @param to
// * @return a {@link Stream<DiffOutput>}
// */
// private Stream<DiffOutput> diffBetweenStates(Node from, Node to) {
// List<DiffOutput> diffs = new ArrayList<>();
//
// Map<String, Object> propertiesFrom = Optional.ofNullable(from).map(Node::getAllProperties).orElse(Collections.emptyMap());
// Map<String, Object> propertiesTo = Optional.ofNullable(to).map(Node::getAllProperties).orElse(Collections.emptyMap());
//
// //Getting updated and removed properties
// propertiesFrom.forEach((key, value) -> {
// Optional<Object> foundValue = Optional.ofNullable(propertiesTo.get(key));
// String operation = foundValue.map(val -> compareObj(val, value) ? "" : Utility.DIFF_OPERATION_UPDATE).orElse(Utility.DIFF_OPERATION_REMOVE);
// if(!operation.isEmpty()){
// diffs.add(new DiffOutput(operation, key, value, foundValue.orElse(null)));
// }
// });
//
// //Getting added properties
// propertiesTo.forEach((key, value) -> {
// if(!propertiesFrom.containsKey(key)) {
// diffs.add(new DiffOutput(Utility.DIFF_OPERATION_ADD, key, null, value));
// }
// });
//
// return diffs.stream().sorted((a, b) -> Integer.compare(Utility.DIFF_OPERATIONS_SORTING.indexOf(a.operation), Utility.DIFF_OPERATIONS_SORTING.indexOf(b.operation)));
// }
//
// /**
// * It compares 2 objects and return true if equals, false instead
// *
// * @param val
// * @param value
// * @return true if equals, false instead
// */
// private boolean compareObj(Object val, Object value){
// if(val.getClass().isArray() && value.getClass().isArray()){
// return (val instanceof boolean[] && value instanceof boolean[] && Arrays.equals((boolean[])val, (boolean[])value))
// || (val instanceof byte[] && value instanceof byte[] && Arrays.equals((byte[])val, (byte[])value))
// || (val instanceof short[] && value instanceof short[] && Arrays.equals((short[])val, (short[])value))
// || (val instanceof int[] && value instanceof int[] && Arrays.equals((int[])val, (int[])value))
// || (val instanceof long[] && value instanceof long[] && Arrays.equals((long[])val, (long[])value))
// || (val instanceof float[] && value instanceof float[] && Arrays.equals((float[])val, (float[])value))
// || (val instanceof double[] && value instanceof double[] && Arrays.equals((double[])val, (double[])value))
// || (val instanceof char[] && value instanceof char[] && Arrays.equals((char[])val, (char[])value))
// || (val instanceof String[] && value instanceof String[] && Arrays.equals((String[])val, (String[])value));
// } else {
// return val.equals(value);
// }
// }
// }
| import org.homer.versioner.core.procedure.Diff;
import org.junit.Test;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is; | package org.homer.versioner.core.builders;
/**
* DiffBuilderTest class, it contains all the method used to test procedure builders
*/
public class DiffBuilderTest {
@Test
public void shouldBuildCorrectProcedureInstance() { | // Path: src/main/java/org/homer/versioner/core/procedure/Diff.java
// public class Diff {
//
// @Procedure(value = "graph.versioner.diff", mode = DEFAULT)
// @Description("graph.versioner.diff(stateFrom, stateTo) - Get a list of differences that must be applied to stateFrom in order to convert it into stateTo")
// public Stream<DiffOutput> diff(
// @Name("stateFrom") Node stateFrom,
// @Name("stateTo") Node stateTo) {
// return diffBetweenStates(stateFrom, stateTo);
// }
//
// @Procedure(value = "graph.versioner.diff.from.previous", mode = DEFAULT)
// @Description("graph.versioner.diff.from.previous(state) - Get a list of differences that must be applied to the previous statusof the given one in order to become the given state")
// public Stream<DiffOutput> diffFromPrevious(
// @Name("state") Node state) {
//
// return Optional.ofNullable(state.getSingleRelationship(RelationshipType.withName(Utility.PREVIOUS_TYPE), Direction.OUTGOING))
// .map(Relationship::getEndNode)
// .map(sFrom -> diffBetweenStates(sFrom, state))
// .orElse(Stream.empty());
// }
//
// @Procedure(value = "graph.versioner.diff.from.current", mode = DEFAULT)
// @Description("graph.versioner.diff.from.current(state) - Get a list of differences that must be applied to the given state in order to become the current entity state")
// public Stream<DiffOutput> diffFromCurrent(
// @Name("state") Node state) {
//
// return Optional.ofNullable(state.getSingleRelationship(RelationshipType.withName(Utility.HAS_STATE_TYPE), Direction.INCOMING))
// .map(Relationship::getStartNode)
// .map(entity -> entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
// .map(Relationship::getEndNode)
// .filter(current -> !current.equals(state))
// .map(current -> diffBetweenStates(state, current))
// .orElse(Stream.empty());
// }
//
// /**
// * It returns a {@link Stream<DiffOutput>} by the given nodes
// *
// * @param from
// * @param to
// * @return a {@link Stream<DiffOutput>}
// */
// private Stream<DiffOutput> diffBetweenStates(Node from, Node to) {
// List<DiffOutput> diffs = new ArrayList<>();
//
// Map<String, Object> propertiesFrom = Optional.ofNullable(from).map(Node::getAllProperties).orElse(Collections.emptyMap());
// Map<String, Object> propertiesTo = Optional.ofNullable(to).map(Node::getAllProperties).orElse(Collections.emptyMap());
//
// //Getting updated and removed properties
// propertiesFrom.forEach((key, value) -> {
// Optional<Object> foundValue = Optional.ofNullable(propertiesTo.get(key));
// String operation = foundValue.map(val -> compareObj(val, value) ? "" : Utility.DIFF_OPERATION_UPDATE).orElse(Utility.DIFF_OPERATION_REMOVE);
// if(!operation.isEmpty()){
// diffs.add(new DiffOutput(operation, key, value, foundValue.orElse(null)));
// }
// });
//
// //Getting added properties
// propertiesTo.forEach((key, value) -> {
// if(!propertiesFrom.containsKey(key)) {
// diffs.add(new DiffOutput(Utility.DIFF_OPERATION_ADD, key, null, value));
// }
// });
//
// return diffs.stream().sorted((a, b) -> Integer.compare(Utility.DIFF_OPERATIONS_SORTING.indexOf(a.operation), Utility.DIFF_OPERATIONS_SORTING.indexOf(b.operation)));
// }
//
// /**
// * It compares 2 objects and return true if equals, false instead
// *
// * @param val
// * @param value
// * @return true if equals, false instead
// */
// private boolean compareObj(Object val, Object value){
// if(val.getClass().isArray() && value.getClass().isArray()){
// return (val instanceof boolean[] && value instanceof boolean[] && Arrays.equals((boolean[])val, (boolean[])value))
// || (val instanceof byte[] && value instanceof byte[] && Arrays.equals((byte[])val, (byte[])value))
// || (val instanceof short[] && value instanceof short[] && Arrays.equals((short[])val, (short[])value))
// || (val instanceof int[] && value instanceof int[] && Arrays.equals((int[])val, (int[])value))
// || (val instanceof long[] && value instanceof long[] && Arrays.equals((long[])val, (long[])value))
// || (val instanceof float[] && value instanceof float[] && Arrays.equals((float[])val, (float[])value))
// || (val instanceof double[] && value instanceof double[] && Arrays.equals((double[])val, (double[])value))
// || (val instanceof char[] && value instanceof char[] && Arrays.equals((char[])val, (char[])value))
// || (val instanceof String[] && value instanceof String[] && Arrays.equals((String[])val, (String[])value));
// } else {
// return val.equals(value);
// }
// }
// }
// Path: src/test/java/org/homer/versioner/core/builders/DiffBuilderTest.java
import org.homer.versioner.core.procedure.Diff;
import org.junit.Test;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
package org.homer.versioner.core.builders;
/**
* DiffBuilderTest class, it contains all the method used to test procedure builders
*/
public class DiffBuilderTest {
@Test
public void shouldBuildCorrectProcedureInstance() { | Optional<Diff> result = new DiffBuilder().build(); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/FirstTrueRulesetListExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetListExecutorImpl.java
// public class FirstTrueRulesetListExecutorImpl<T> extends RulesetListExecutor<T> {
// private final List<RulesetExecutor<T>> rulesetList;
// private final String name;
//
// public FirstTrueRulesetListExecutorImpl(String name, List<RulesetExecutor<T>> rulesetList) {
// this.name = name;
// this.rulesetList = rulesetList;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = null;
// /*
// execute all the rules until a response is found -- if all are false,
// return null
// */
// for (RulesetExecutor<T> ruleSet : rulesetList) {
// T ruleResponse = ruleSet.execute(parameters);
// if (ruleResponse != null) {
// result = ruleResponse;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetListExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; | /*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules;
/**
* @author Paul
*/
@RunWith(MockitoJUnitRunner.class)
public class FirstTrueRulesetListExecutorTest {
private RulesetExecutor<String> executor;
private final String responseMock = "mock";
private final String rulesetName = "mockRuleset";
@org.junit.Rule
public ExpectedException exception = ExpectedException.none();
private List<RulesetExecutor<String>> rulesetListMock;
private Map<String, Object> parameters;
@Mock
private RulesetExecutor<String> rulesetExecutorMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
rulesetListMock = new ArrayList<>();
parameters = new HashMap<>();
| // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetListExecutorImpl.java
// public class FirstTrueRulesetListExecutorImpl<T> extends RulesetListExecutor<T> {
// private final List<RulesetExecutor<T>> rulesetList;
// private final String name;
//
// public FirstTrueRulesetListExecutorImpl(String name, List<RulesetExecutor<T>> rulesetList) {
// this.name = name;
// this.rulesetList = rulesetList;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = null;
// /*
// execute all the rules until a response is found -- if all are false,
// return null
// */
// for (RulesetExecutor<T> ruleSet : rulesetList) {
// T ruleResponse = ruleSet.execute(parameters);
// if (ruleResponse != null) {
// result = ruleResponse;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/FirstTrueRulesetListExecutorTest.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetListExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
/*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules;
/**
* @author Paul
*/
@RunWith(MockitoJUnitRunner.class)
public class FirstTrueRulesetListExecutorTest {
private RulesetExecutor<String> executor;
private final String responseMock = "mock";
private final String rulesetName = "mockRuleset";
@org.junit.Rule
public ExpectedException exception = ExpectedException.none();
private List<RulesetExecutor<String>> rulesetListMock;
private Map<String, Object> parameters;
@Mock
private RulesetExecutor<String> rulesetExecutorMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
rulesetListMock = new ArrayList<>();
parameters = new HashMap<>();
| executor = new FirstTrueRulesetListExecutorImpl<>(rulesetName, rulesetListMock); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/FirstTrueRulesetListExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetListExecutorImpl.java
// public class FirstTrueRulesetListExecutorImpl<T> extends RulesetListExecutor<T> {
// private final List<RulesetExecutor<T>> rulesetList;
// private final String name;
//
// public FirstTrueRulesetListExecutorImpl(String name, List<RulesetExecutor<T>> rulesetList) {
// this.name = name;
// this.rulesetList = rulesetList;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = null;
// /*
// execute all the rules until a response is found -- if all are false,
// return null
// */
// for (RulesetExecutor<T> ruleSet : rulesetList) {
// T ruleResponse = ruleSet.execute(parameters);
// if (ruleResponse != null) {
// result = ruleResponse;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetListExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; | @Mock
private RulesetExecutor<String> rulesetExecutorMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
rulesetListMock = new ArrayList<>();
parameters = new HashMap<>();
executor = new FirstTrueRulesetListExecutorImpl<>(rulesetName, rulesetListMock);
}
@After
public void tearDown() {
}
@Test
public void executeFirstTrueRulesetListEmptyTest() throws Exception {
assertNull(executor.execute(parameters));
}
@Test
public void executeFirstTrueRulesetListInvalidParametersTest() throws Exception { | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetListExecutorImpl.java
// public class FirstTrueRulesetListExecutorImpl<T> extends RulesetListExecutor<T> {
// private final List<RulesetExecutor<T>> rulesetList;
// private final String name;
//
// public FirstTrueRulesetListExecutorImpl(String name, List<RulesetExecutor<T>> rulesetList) {
// this.name = name;
// this.rulesetList = rulesetList;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = null;
// /*
// execute all the rules until a response is found -- if all are false,
// return null
// */
// for (RulesetExecutor<T> ruleSet : rulesetList) {
// T ruleResponse = ruleSet.execute(parameters);
// if (ruleResponse != null) {
// result = ruleResponse;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/FirstTrueRulesetListExecutorTest.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetListExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
@Mock
private RulesetExecutor<String> rulesetExecutorMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
rulesetListMock = new ArrayList<>();
parameters = new HashMap<>();
executor = new FirstTrueRulesetListExecutorImpl<>(rulesetName, rulesetListMock);
}
@After
public void tearDown() {
}
@Test
public void executeFirstTrueRulesetListEmptyTest() throws Exception {
assertNull(executor.execute(parameters));
}
@Test
public void executeFirstTrueRulesetListInvalidParametersTest() throws Exception { | exception.expect(InvalidParameterException.class); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/FirstTrueRulesetExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetExecutorImpl.java
// public class FirstTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
// private final List<RuleExecutor<T>> ruleSet;
// private String name;
//
// public FirstTrueRulesetExecutorImpl(String name, List<RuleExecutor<T>> ruleSet) {
// this.name = name;
// this.ruleSet = ruleSet;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = null;
// for (RuleExecutor<T> rule : ruleSet) {
// Parameter left = rule.getLeftParameter();
// String leftName = left.getName();
// Object leftParameter = parameters.get(leftName);
// validateParameter(leftName, leftParameter, left.getKlasse());
//
// Parameter right = rule.getRightParameter();
//
// T ruleResponse;
//
// if (right.getStaticValue() == null) {
// //send both parameters
// String rightName = right.getName();
// Object rightParameter = parameters.get(rightName);
// validateParameter(rightName, rightParameter, right.getKlasse());
//
// ruleResponse = rule.execute(leftParameter, rightParameter);
//
// } else {
// //send left parameter only
// ruleResponse = rule.execute(leftParameter);
// }
//
// // if the rule is true, send its response and stop processing
// if (null != ruleResponse) {
// result = ruleResponse;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
//
// }
| import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock; | /*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules;
/**
* @author Paul
*/
@RunWith(MockitoJUnitRunner.class)
public class FirstTrueRulesetExecutorTest {
private RulesetExecutor<String> executor;
private final String leftName = "left";
private final String rightName = "right";
private final String nameName = "name";
private final String rulesetName = "mockRuleset";
@org.junit.Rule
public ExpectedException exception = ExpectedException.none();
@Mock
RuleExecutor<String> ruleExecutorMock1;
@Mock
RuleExecutor<String> ruleExecutorMock2;
private List<RuleExecutor<String>> ruleListMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
when(ruleExecutorMock1.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
when(ruleExecutorMock1.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));
when(ruleExecutorMock2.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
when(ruleExecutorMock2.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));
ruleListMock = new ArrayList<>();
ruleListMock.add(ruleExecutorMock1);
ruleListMock.add(ruleExecutorMock2);
| // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetExecutorImpl.java
// public class FirstTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
// private final List<RuleExecutor<T>> ruleSet;
// private String name;
//
// public FirstTrueRulesetExecutorImpl(String name, List<RuleExecutor<T>> ruleSet) {
// this.name = name;
// this.ruleSet = ruleSet;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = null;
// for (RuleExecutor<T> rule : ruleSet) {
// Parameter left = rule.getLeftParameter();
// String leftName = left.getName();
// Object leftParameter = parameters.get(leftName);
// validateParameter(leftName, leftParameter, left.getKlasse());
//
// Parameter right = rule.getRightParameter();
//
// T ruleResponse;
//
// if (right.getStaticValue() == null) {
// //send both parameters
// String rightName = right.getName();
// Object rightParameter = parameters.get(rightName);
// validateParameter(rightName, rightParameter, right.getKlasse());
//
// ruleResponse = rule.execute(leftParameter, rightParameter);
//
// } else {
// //send left parameter only
// ruleResponse = rule.execute(leftParameter);
// }
//
// // if the rule is true, send its response and stop processing
// if (null != ruleResponse) {
// result = ruleResponse;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
//
// }
// Path: src/test/java/org/grouchotools/jsrules/FirstTrueRulesetExecutorTest.java
import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
/*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules;
/**
* @author Paul
*/
@RunWith(MockitoJUnitRunner.class)
public class FirstTrueRulesetExecutorTest {
private RulesetExecutor<String> executor;
private final String leftName = "left";
private final String rightName = "right";
private final String nameName = "name";
private final String rulesetName = "mockRuleset";
@org.junit.Rule
public ExpectedException exception = ExpectedException.none();
@Mock
RuleExecutor<String> ruleExecutorMock1;
@Mock
RuleExecutor<String> ruleExecutorMock2;
private List<RuleExecutor<String>> ruleListMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
when(ruleExecutorMock1.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
when(ruleExecutorMock1.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));
when(ruleExecutorMock2.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
when(ruleExecutorMock2.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));
ruleListMock = new ArrayList<>();
ruleListMock.add(ruleExecutorMock1);
ruleListMock.add(ruleExecutorMock2);
| executor = new FirstTrueRulesetExecutorImpl<>(rulesetName, ruleListMock); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/FirstTrueRulesetExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetExecutorImpl.java
// public class FirstTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
// private final List<RuleExecutor<T>> ruleSet;
// private String name;
//
// public FirstTrueRulesetExecutorImpl(String name, List<RuleExecutor<T>> ruleSet) {
// this.name = name;
// this.ruleSet = ruleSet;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = null;
// for (RuleExecutor<T> rule : ruleSet) {
// Parameter left = rule.getLeftParameter();
// String leftName = left.getName();
// Object leftParameter = parameters.get(leftName);
// validateParameter(leftName, leftParameter, left.getKlasse());
//
// Parameter right = rule.getRightParameter();
//
// T ruleResponse;
//
// if (right.getStaticValue() == null) {
// //send both parameters
// String rightName = right.getName();
// Object rightParameter = parameters.get(rightName);
// validateParameter(rightName, rightParameter, right.getKlasse());
//
// ruleResponse = rule.execute(leftParameter, rightParameter);
//
// } else {
// //send left parameter only
// ruleResponse = rule.execute(leftParameter);
// }
//
// // if the rule is true, send its response and stop processing
// if (null != ruleResponse) {
// result = ruleResponse;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
//
// }
| import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock; | @Before
public void setUp() {
when(ruleExecutorMock1.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
when(ruleExecutorMock1.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));
when(ruleExecutorMock2.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
when(ruleExecutorMock2.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));
ruleListMock = new ArrayList<>();
ruleListMock.add(ruleExecutorMock1);
ruleListMock.add(ruleExecutorMock2);
executor = new FirstTrueRulesetExecutorImpl<>(rulesetName, ruleListMock);
}
@After
public void tearDown() {
}
@Test
public void executeEmptyRulesetTest() throws Exception {
ruleListMock.clear();
Map<String, Object> parameters = new HashMap<>();
assertNull(executor.execute(parameters));
}
@Test
public void executeRulesetInvalidLeftParameterTest() throws Exception { | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetExecutorImpl.java
// public class FirstTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
// private final List<RuleExecutor<T>> ruleSet;
// private String name;
//
// public FirstTrueRulesetExecutorImpl(String name, List<RuleExecutor<T>> ruleSet) {
// this.name = name;
// this.ruleSet = ruleSet;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = null;
// for (RuleExecutor<T> rule : ruleSet) {
// Parameter left = rule.getLeftParameter();
// String leftName = left.getName();
// Object leftParameter = parameters.get(leftName);
// validateParameter(leftName, leftParameter, left.getKlasse());
//
// Parameter right = rule.getRightParameter();
//
// T ruleResponse;
//
// if (right.getStaticValue() == null) {
// //send both parameters
// String rightName = right.getName();
// Object rightParameter = parameters.get(rightName);
// validateParameter(rightName, rightParameter, right.getKlasse());
//
// ruleResponse = rule.execute(leftParameter, rightParameter);
//
// } else {
// //send left parameter only
// ruleResponse = rule.execute(leftParameter);
// }
//
// // if the rule is true, send its response and stop processing
// if (null != ruleResponse) {
// result = ruleResponse;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
//
// }
// Path: src/test/java/org/grouchotools/jsrules/FirstTrueRulesetExecutorTest.java
import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@Before
public void setUp() {
when(ruleExecutorMock1.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
when(ruleExecutorMock1.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));
when(ruleExecutorMock2.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
when(ruleExecutorMock2.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));
ruleListMock = new ArrayList<>();
ruleListMock.add(ruleExecutorMock1);
ruleListMock.add(ruleExecutorMock2);
executor = new FirstTrueRulesetExecutorImpl<>(rulesetName, ruleListMock);
}
@After
public void tearDown() {
}
@Test
public void executeEmptyRulesetTest() throws Exception {
ruleListMock.clear();
Map<String, Object> parameters = new HashMap<>();
assertNull(executor.execute(parameters));
}
@Test
public void executeRulesetInvalidLeftParameterTest() throws Exception { | exception.expect(InvalidParameterClassException.class); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/FirstTrueRulesetExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetExecutorImpl.java
// public class FirstTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
// private final List<RuleExecutor<T>> ruleSet;
// private String name;
//
// public FirstTrueRulesetExecutorImpl(String name, List<RuleExecutor<T>> ruleSet) {
// this.name = name;
// this.ruleSet = ruleSet;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = null;
// for (RuleExecutor<T> rule : ruleSet) {
// Parameter left = rule.getLeftParameter();
// String leftName = left.getName();
// Object leftParameter = parameters.get(leftName);
// validateParameter(leftName, leftParameter, left.getKlasse());
//
// Parameter right = rule.getRightParameter();
//
// T ruleResponse;
//
// if (right.getStaticValue() == null) {
// //send both parameters
// String rightName = right.getName();
// Object rightParameter = parameters.get(rightName);
// validateParameter(rightName, rightParameter, right.getKlasse());
//
// ruleResponse = rule.execute(leftParameter, rightParameter);
//
// } else {
// //send left parameter only
// ruleResponse = rule.execute(leftParameter);
// }
//
// // if the rule is true, send its response and stop processing
// if (null != ruleResponse) {
// result = ruleResponse;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
//
// }
| import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock; |
Map<String, Object> parameters = new HashMap<>();
assertNull(executor.execute(parameters));
}
@Test
public void executeRulesetInvalidLeftParameterTest() throws Exception {
exception.expect(InvalidParameterClassException.class);
Map<String, Object> parameters = new HashMap<>();
parameters.put(leftName, "21");
parameters.put(rightName, 10l);
executor.execute(parameters);
}
@Test
public void executeRulesetInvalidRightParameterTest() throws Exception {
exception.expect(InvalidParameterClassException.class);
Map<String, Object> parameters = new HashMap<>();
parameters.put(leftName, 21l);
parameters.put(rightName, "10");
executor.execute(parameters);
}
@Test
public void executeRulesetMissingParametersTest() throws Exception { | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetExecutorImpl.java
// public class FirstTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
// private final List<RuleExecutor<T>> ruleSet;
// private String name;
//
// public FirstTrueRulesetExecutorImpl(String name, List<RuleExecutor<T>> ruleSet) {
// this.name = name;
// this.ruleSet = ruleSet;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = null;
// for (RuleExecutor<T> rule : ruleSet) {
// Parameter left = rule.getLeftParameter();
// String leftName = left.getName();
// Object leftParameter = parameters.get(leftName);
// validateParameter(leftName, leftParameter, left.getKlasse());
//
// Parameter right = rule.getRightParameter();
//
// T ruleResponse;
//
// if (right.getStaticValue() == null) {
// //send both parameters
// String rightName = right.getName();
// Object rightParameter = parameters.get(rightName);
// validateParameter(rightName, rightParameter, right.getKlasse());
//
// ruleResponse = rule.execute(leftParameter, rightParameter);
//
// } else {
// //send left parameter only
// ruleResponse = rule.execute(leftParameter);
// }
//
// // if the rule is true, send its response and stop processing
// if (null != ruleResponse) {
// result = ruleResponse;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
//
// }
// Path: src/test/java/org/grouchotools/jsrules/FirstTrueRulesetExecutorTest.java
import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
Map<String, Object> parameters = new HashMap<>();
assertNull(executor.execute(parameters));
}
@Test
public void executeRulesetInvalidLeftParameterTest() throws Exception {
exception.expect(InvalidParameterClassException.class);
Map<String, Object> parameters = new HashMap<>();
parameters.put(leftName, "21");
parameters.put(rightName, 10l);
executor.execute(parameters);
}
@Test
public void executeRulesetInvalidRightParameterTest() throws Exception {
exception.expect(InvalidParameterClassException.class);
Map<String, Object> parameters = new HashMap<>();
parameters.put(leftName, 21l);
parameters.put(rightName, "10");
executor.execute(parameters);
}
@Test
public void executeRulesetMissingParametersTest() throws Exception { | exception.expect(MissingParameterException.class); |
el-groucho/jsRules | src/main/java/org/grouchotools/jsrules/util/ClassHandler.java | // Path: src/main/java/org/grouchotools/jsrules/exception/ClassHandlerException.java
// public class ClassHandlerException extends JsRulesException {
//
// public ClassHandlerException() {
// }
//
// public ClassHandlerException(String message) {
// super(message);
// }
//
// public ClassHandlerException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public ClassHandlerException(Throwable cause) {
// super(cause);
// }
//
// public ClassHandlerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import com.fasterxml.jackson.databind.ObjectMapper;
import org.grouchotools.jsrules.exception.ClassHandlerException;
import org.joda.time.DateTime;
import java.io.IOException;
import java.util.Set; | public Class getMyClass() {
return Long.class;
}
@Override
@SuppressWarnings("unchecked")
public Long convertString(String string) {
return Long.parseLong(string);
}
},
STRING {
@Override
public Class getMyClass() {
return String.class;
}
@Override
@SuppressWarnings("unchecked")
public String convertString(String string) {
return string;
}
},
NUMBERSET {
@Override
public Class getMyClass() {
return Set.class;
}
@Override
@SuppressWarnings("unchecked") | // Path: src/main/java/org/grouchotools/jsrules/exception/ClassHandlerException.java
// public class ClassHandlerException extends JsRulesException {
//
// public ClassHandlerException() {
// }
//
// public ClassHandlerException(String message) {
// super(message);
// }
//
// public ClassHandlerException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public ClassHandlerException(Throwable cause) {
// super(cause);
// }
//
// public ClassHandlerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/main/java/org/grouchotools/jsrules/util/ClassHandler.java
import com.fasterxml.jackson.databind.ObjectMapper;
import org.grouchotools.jsrules.exception.ClassHandlerException;
import org.joda.time.DateTime;
import java.io.IOException;
import java.util.Set;
public Class getMyClass() {
return Long.class;
}
@Override
@SuppressWarnings("unchecked")
public Long convertString(String string) {
return Long.parseLong(string);
}
},
STRING {
@Override
public Class getMyClass() {
return String.class;
}
@Override
@SuppressWarnings("unchecked")
public String convertString(String string) {
return string;
}
},
NUMBERSET {
@Override
public Class getMyClass() {
return Set.class;
}
@Override
@SuppressWarnings("unchecked") | public Set<Number> convertString(String string) throws ClassHandlerException { |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/JsRulesTest.java | // Path: src/main/java/org/grouchotools/jsrules/config/ResponseConfig.java
// public class ResponseConfig extends JsonBean implements Config {
// private String response;
// private String responseClass;
//
// public ResponseConfig() {
//
// }
//
// public ResponseConfig(String response, String responseClass) {
// this.response = response;
// this.responseClass = responseClass;
// }
//
// public String getResponse() {
// return response;
// }
//
// public void setResponse(String response) {
// this.response = response;
// }
//
// public String getResponseClass() {
// return responseClass;
// }
//
// public void setResponseClass(String responseClass) {
// this.responseClass = responseClass;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/config/RulesetConfig.java
// public class RulesetConfig implements Config {
// private String rulesetName;
// private String rulesetType;
// private ResponseConfig responseConfig;
// private List<String> components;
//
// public RulesetConfig() {
//
// }
//
// public RulesetConfig(String rulesetName, String rulesetType, ResponseConfig responseConfig, List<String> components) {
// this.rulesetName = rulesetName;
// this.rulesetType = rulesetType;
// this.responseConfig = responseConfig;
// this.components = components;
// }
//
// public String getRulesetName() {
// return rulesetName;
// }
//
// public void setRulesetName(String rulesetName) {
// this.rulesetName = rulesetName;
// }
//
// public String getRulesetType() {
// return rulesetType;
// }
//
// public void setRulesetType(String rulesetType) {
// this.rulesetType = rulesetType;
// }
//
// public ResponseConfig getResponseConfig() {
// return responseConfig;
// }
//
// public void setResponseConfig(ResponseConfig responseConfig) {
// this.responseConfig = responseConfig;
// }
//
// public List<String> getComponents() {
// return components;
// }
//
// public void setComponents(List<String> components) {
// this.components = components;
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidConfigException.java
// public class InvalidConfigException extends JsRulesException {
//
// public InvalidConfigException() {
// }
//
// public InvalidConfigException(String message) {
// super(message);
// }
//
// public InvalidConfigException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidConfigException(Throwable cause) {
// super(cause);
// }
//
// public InvalidConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import com.fasterxml.jackson.databind.ObjectMapper;
import org.grouchotools.jsrules.config.ResponseConfig;
import org.grouchotools.jsrules.config.RulesetConfig;
import org.grouchotools.jsrules.exception.InvalidConfigException;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; |
@Test
public void testLoadJsonString() throws Exception {
String ruleName = "mock rule";
String json = "{" +
"\"ruleName\": \"" + ruleName + "\"," +
"\"leftParamConfig\": {" +
"\"parameterName\": \"left\"," +
"\"parameterClass\": \"Long\"" +
"}," +
"\"operator\": \"GT\"," +
"\"rightParamConfig\": {" +
"\"parameterName\": \"right\"," +
"\"parameterClass\": \"Long\"," +
"\"parameterStaticValue\": \"10\"" +
"}," +
"\"responseConfig\": {" +
"\"response\": \"true\"," +
"\"responseClass\": \"Boolean\"" +
"}" +
"}";
Rule rule = jsRules.loadRuleByJson(json);
assertEquals(ruleName, rule.getRuleName());
}
@Test
public void testLoadJsonInvalid() throws Exception { | // Path: src/main/java/org/grouchotools/jsrules/config/ResponseConfig.java
// public class ResponseConfig extends JsonBean implements Config {
// private String response;
// private String responseClass;
//
// public ResponseConfig() {
//
// }
//
// public ResponseConfig(String response, String responseClass) {
// this.response = response;
// this.responseClass = responseClass;
// }
//
// public String getResponse() {
// return response;
// }
//
// public void setResponse(String response) {
// this.response = response;
// }
//
// public String getResponseClass() {
// return responseClass;
// }
//
// public void setResponseClass(String responseClass) {
// this.responseClass = responseClass;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/config/RulesetConfig.java
// public class RulesetConfig implements Config {
// private String rulesetName;
// private String rulesetType;
// private ResponseConfig responseConfig;
// private List<String> components;
//
// public RulesetConfig() {
//
// }
//
// public RulesetConfig(String rulesetName, String rulesetType, ResponseConfig responseConfig, List<String> components) {
// this.rulesetName = rulesetName;
// this.rulesetType = rulesetType;
// this.responseConfig = responseConfig;
// this.components = components;
// }
//
// public String getRulesetName() {
// return rulesetName;
// }
//
// public void setRulesetName(String rulesetName) {
// this.rulesetName = rulesetName;
// }
//
// public String getRulesetType() {
// return rulesetType;
// }
//
// public void setRulesetType(String rulesetType) {
// this.rulesetType = rulesetType;
// }
//
// public ResponseConfig getResponseConfig() {
// return responseConfig;
// }
//
// public void setResponseConfig(ResponseConfig responseConfig) {
// this.responseConfig = responseConfig;
// }
//
// public List<String> getComponents() {
// return components;
// }
//
// public void setComponents(List<String> components) {
// this.components = components;
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidConfigException.java
// public class InvalidConfigException extends JsRulesException {
//
// public InvalidConfigException() {
// }
//
// public InvalidConfigException(String message) {
// super(message);
// }
//
// public InvalidConfigException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidConfigException(Throwable cause) {
// super(cause);
// }
//
// public InvalidConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/JsRulesTest.java
import com.fasterxml.jackson.databind.ObjectMapper;
import org.grouchotools.jsrules.config.ResponseConfig;
import org.grouchotools.jsrules.config.RulesetConfig;
import org.grouchotools.jsrules.exception.InvalidConfigException;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@Test
public void testLoadJsonString() throws Exception {
String ruleName = "mock rule";
String json = "{" +
"\"ruleName\": \"" + ruleName + "\"," +
"\"leftParamConfig\": {" +
"\"parameterName\": \"left\"," +
"\"parameterClass\": \"Long\"" +
"}," +
"\"operator\": \"GT\"," +
"\"rightParamConfig\": {" +
"\"parameterName\": \"right\"," +
"\"parameterClass\": \"Long\"," +
"\"parameterStaticValue\": \"10\"" +
"}," +
"\"responseConfig\": {" +
"\"response\": \"true\"," +
"\"responseClass\": \"Boolean\"" +
"}" +
"}";
Rule rule = jsRules.loadRuleByJson(json);
assertEquals(ruleName, rule.getRuleName());
}
@Test
public void testLoadJsonInvalid() throws Exception { | exception.expect(InvalidConfigException.class); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/JsRulesTest.java | // Path: src/main/java/org/grouchotools/jsrules/config/ResponseConfig.java
// public class ResponseConfig extends JsonBean implements Config {
// private String response;
// private String responseClass;
//
// public ResponseConfig() {
//
// }
//
// public ResponseConfig(String response, String responseClass) {
// this.response = response;
// this.responseClass = responseClass;
// }
//
// public String getResponse() {
// return response;
// }
//
// public void setResponse(String response) {
// this.response = response;
// }
//
// public String getResponseClass() {
// return responseClass;
// }
//
// public void setResponseClass(String responseClass) {
// this.responseClass = responseClass;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/config/RulesetConfig.java
// public class RulesetConfig implements Config {
// private String rulesetName;
// private String rulesetType;
// private ResponseConfig responseConfig;
// private List<String> components;
//
// public RulesetConfig() {
//
// }
//
// public RulesetConfig(String rulesetName, String rulesetType, ResponseConfig responseConfig, List<String> components) {
// this.rulesetName = rulesetName;
// this.rulesetType = rulesetType;
// this.responseConfig = responseConfig;
// this.components = components;
// }
//
// public String getRulesetName() {
// return rulesetName;
// }
//
// public void setRulesetName(String rulesetName) {
// this.rulesetName = rulesetName;
// }
//
// public String getRulesetType() {
// return rulesetType;
// }
//
// public void setRulesetType(String rulesetType) {
// this.rulesetType = rulesetType;
// }
//
// public ResponseConfig getResponseConfig() {
// return responseConfig;
// }
//
// public void setResponseConfig(ResponseConfig responseConfig) {
// this.responseConfig = responseConfig;
// }
//
// public List<String> getComponents() {
// return components;
// }
//
// public void setComponents(List<String> components) {
// this.components = components;
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidConfigException.java
// public class InvalidConfigException extends JsRulesException {
//
// public InvalidConfigException() {
// }
//
// public InvalidConfigException(String message) {
// super(message);
// }
//
// public InvalidConfigException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidConfigException(Throwable cause) {
// super(cause);
// }
//
// public InvalidConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import com.fasterxml.jackson.databind.ObjectMapper;
import org.grouchotools.jsrules.config.ResponseConfig;
import org.grouchotools.jsrules.config.RulesetConfig;
import org.grouchotools.jsrules.exception.InvalidConfigException;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; | public void testLoadRuleByName() throws Exception {
String ruleName = "GreaterThan10";
Rule rule = jsRules.loadRuleByName(ruleName);
assertEquals(ruleName, rule.getRuleName());
}
@Test
public void testLoadRuleByNameFileMissing() throws Exception {
exception.expect(InvalidConfigException.class);
String ruleName = "BogusRuleName";
jsRules.loadRuleByName(ruleName);
}
@Test
public void testLoadRuleByNameIOError() throws Exception {
exception.expect(InvalidConfigException.class);
String ruleName = "EmptyFile";
jsRules.loadRuleByName(ruleName);
}
@Test
public void testLoadRulesetJson() throws Exception {
String rulesetName = "mockRuleset";
| // Path: src/main/java/org/grouchotools/jsrules/config/ResponseConfig.java
// public class ResponseConfig extends JsonBean implements Config {
// private String response;
// private String responseClass;
//
// public ResponseConfig() {
//
// }
//
// public ResponseConfig(String response, String responseClass) {
// this.response = response;
// this.responseClass = responseClass;
// }
//
// public String getResponse() {
// return response;
// }
//
// public void setResponse(String response) {
// this.response = response;
// }
//
// public String getResponseClass() {
// return responseClass;
// }
//
// public void setResponseClass(String responseClass) {
// this.responseClass = responseClass;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/config/RulesetConfig.java
// public class RulesetConfig implements Config {
// private String rulesetName;
// private String rulesetType;
// private ResponseConfig responseConfig;
// private List<String> components;
//
// public RulesetConfig() {
//
// }
//
// public RulesetConfig(String rulesetName, String rulesetType, ResponseConfig responseConfig, List<String> components) {
// this.rulesetName = rulesetName;
// this.rulesetType = rulesetType;
// this.responseConfig = responseConfig;
// this.components = components;
// }
//
// public String getRulesetName() {
// return rulesetName;
// }
//
// public void setRulesetName(String rulesetName) {
// this.rulesetName = rulesetName;
// }
//
// public String getRulesetType() {
// return rulesetType;
// }
//
// public void setRulesetType(String rulesetType) {
// this.rulesetType = rulesetType;
// }
//
// public ResponseConfig getResponseConfig() {
// return responseConfig;
// }
//
// public void setResponseConfig(ResponseConfig responseConfig) {
// this.responseConfig = responseConfig;
// }
//
// public List<String> getComponents() {
// return components;
// }
//
// public void setComponents(List<String> components) {
// this.components = components;
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidConfigException.java
// public class InvalidConfigException extends JsRulesException {
//
// public InvalidConfigException() {
// }
//
// public InvalidConfigException(String message) {
// super(message);
// }
//
// public InvalidConfigException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidConfigException(Throwable cause) {
// super(cause);
// }
//
// public InvalidConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/JsRulesTest.java
import com.fasterxml.jackson.databind.ObjectMapper;
import org.grouchotools.jsrules.config.ResponseConfig;
import org.grouchotools.jsrules.config.RulesetConfig;
import org.grouchotools.jsrules.exception.InvalidConfigException;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public void testLoadRuleByName() throws Exception {
String ruleName = "GreaterThan10";
Rule rule = jsRules.loadRuleByName(ruleName);
assertEquals(ruleName, rule.getRuleName());
}
@Test
public void testLoadRuleByNameFileMissing() throws Exception {
exception.expect(InvalidConfigException.class);
String ruleName = "BogusRuleName";
jsRules.loadRuleByName(ruleName);
}
@Test
public void testLoadRuleByNameIOError() throws Exception {
exception.expect(InvalidConfigException.class);
String ruleName = "EmptyFile";
jsRules.loadRuleByName(ruleName);
}
@Test
public void testLoadRulesetJson() throws Exception {
String rulesetName = "mockRuleset";
| RulesetConfig rulesetConfig = new RulesetConfig(rulesetName, "ALLTRUE", new ResponseConfig("true", "Boolean"), |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/JsRulesTest.java | // Path: src/main/java/org/grouchotools/jsrules/config/ResponseConfig.java
// public class ResponseConfig extends JsonBean implements Config {
// private String response;
// private String responseClass;
//
// public ResponseConfig() {
//
// }
//
// public ResponseConfig(String response, String responseClass) {
// this.response = response;
// this.responseClass = responseClass;
// }
//
// public String getResponse() {
// return response;
// }
//
// public void setResponse(String response) {
// this.response = response;
// }
//
// public String getResponseClass() {
// return responseClass;
// }
//
// public void setResponseClass(String responseClass) {
// this.responseClass = responseClass;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/config/RulesetConfig.java
// public class RulesetConfig implements Config {
// private String rulesetName;
// private String rulesetType;
// private ResponseConfig responseConfig;
// private List<String> components;
//
// public RulesetConfig() {
//
// }
//
// public RulesetConfig(String rulesetName, String rulesetType, ResponseConfig responseConfig, List<String> components) {
// this.rulesetName = rulesetName;
// this.rulesetType = rulesetType;
// this.responseConfig = responseConfig;
// this.components = components;
// }
//
// public String getRulesetName() {
// return rulesetName;
// }
//
// public void setRulesetName(String rulesetName) {
// this.rulesetName = rulesetName;
// }
//
// public String getRulesetType() {
// return rulesetType;
// }
//
// public void setRulesetType(String rulesetType) {
// this.rulesetType = rulesetType;
// }
//
// public ResponseConfig getResponseConfig() {
// return responseConfig;
// }
//
// public void setResponseConfig(ResponseConfig responseConfig) {
// this.responseConfig = responseConfig;
// }
//
// public List<String> getComponents() {
// return components;
// }
//
// public void setComponents(List<String> components) {
// this.components = components;
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidConfigException.java
// public class InvalidConfigException extends JsRulesException {
//
// public InvalidConfigException() {
// }
//
// public InvalidConfigException(String message) {
// super(message);
// }
//
// public InvalidConfigException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidConfigException(Throwable cause) {
// super(cause);
// }
//
// public InvalidConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import com.fasterxml.jackson.databind.ObjectMapper;
import org.grouchotools.jsrules.config.ResponseConfig;
import org.grouchotools.jsrules.config.RulesetConfig;
import org.grouchotools.jsrules.exception.InvalidConfigException;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; | public void testLoadRuleByName() throws Exception {
String ruleName = "GreaterThan10";
Rule rule = jsRules.loadRuleByName(ruleName);
assertEquals(ruleName, rule.getRuleName());
}
@Test
public void testLoadRuleByNameFileMissing() throws Exception {
exception.expect(InvalidConfigException.class);
String ruleName = "BogusRuleName";
jsRules.loadRuleByName(ruleName);
}
@Test
public void testLoadRuleByNameIOError() throws Exception {
exception.expect(InvalidConfigException.class);
String ruleName = "EmptyFile";
jsRules.loadRuleByName(ruleName);
}
@Test
public void testLoadRulesetJson() throws Exception {
String rulesetName = "mockRuleset";
| // Path: src/main/java/org/grouchotools/jsrules/config/ResponseConfig.java
// public class ResponseConfig extends JsonBean implements Config {
// private String response;
// private String responseClass;
//
// public ResponseConfig() {
//
// }
//
// public ResponseConfig(String response, String responseClass) {
// this.response = response;
// this.responseClass = responseClass;
// }
//
// public String getResponse() {
// return response;
// }
//
// public void setResponse(String response) {
// this.response = response;
// }
//
// public String getResponseClass() {
// return responseClass;
// }
//
// public void setResponseClass(String responseClass) {
// this.responseClass = responseClass;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/config/RulesetConfig.java
// public class RulesetConfig implements Config {
// private String rulesetName;
// private String rulesetType;
// private ResponseConfig responseConfig;
// private List<String> components;
//
// public RulesetConfig() {
//
// }
//
// public RulesetConfig(String rulesetName, String rulesetType, ResponseConfig responseConfig, List<String> components) {
// this.rulesetName = rulesetName;
// this.rulesetType = rulesetType;
// this.responseConfig = responseConfig;
// this.components = components;
// }
//
// public String getRulesetName() {
// return rulesetName;
// }
//
// public void setRulesetName(String rulesetName) {
// this.rulesetName = rulesetName;
// }
//
// public String getRulesetType() {
// return rulesetType;
// }
//
// public void setRulesetType(String rulesetType) {
// this.rulesetType = rulesetType;
// }
//
// public ResponseConfig getResponseConfig() {
// return responseConfig;
// }
//
// public void setResponseConfig(ResponseConfig responseConfig) {
// this.responseConfig = responseConfig;
// }
//
// public List<String> getComponents() {
// return components;
// }
//
// public void setComponents(List<String> components) {
// this.components = components;
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidConfigException.java
// public class InvalidConfigException extends JsRulesException {
//
// public InvalidConfigException() {
// }
//
// public InvalidConfigException(String message) {
// super(message);
// }
//
// public InvalidConfigException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidConfigException(Throwable cause) {
// super(cause);
// }
//
// public InvalidConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/JsRulesTest.java
import com.fasterxml.jackson.databind.ObjectMapper;
import org.grouchotools.jsrules.config.ResponseConfig;
import org.grouchotools.jsrules.config.RulesetConfig;
import org.grouchotools.jsrules.exception.InvalidConfigException;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public void testLoadRuleByName() throws Exception {
String ruleName = "GreaterThan10";
Rule rule = jsRules.loadRuleByName(ruleName);
assertEquals(ruleName, rule.getRuleName());
}
@Test
public void testLoadRuleByNameFileMissing() throws Exception {
exception.expect(InvalidConfigException.class);
String ruleName = "BogusRuleName";
jsRules.loadRuleByName(ruleName);
}
@Test
public void testLoadRuleByNameIOError() throws Exception {
exception.expect(InvalidConfigException.class);
String ruleName = "EmptyFile";
jsRules.loadRuleByName(ruleName);
}
@Test
public void testLoadRulesetJson() throws Exception {
String rulesetName = "mockRuleset";
| RulesetConfig rulesetConfig = new RulesetConfig(rulesetName, "ALLTRUE", new ResponseConfig("true", "Boolean"), |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/integration/AllTrueIntegrationTest.java | // Path: src/main/java/org/grouchotools/jsrules/JsRules.java
// public class JsRules {
//
// private static final JsRules INSTANCE = new JsRules();
//
// private final ObjectMapper objectMapper = new ObjectMapper();
// private final RuleLoader ruleLoader = new RuleLoaderImpl();
// private final RulesetLoader rulesetLoader = new RulesetLoaderImpl(this);
//
// // default cache values
// private static final int CACHE_SIZE = 25;
// private static final long TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes
//
// // these maps provide rudimentary caching
// private final Map<String, Rule> ruleMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
// private final Map<String, RulesetExecutor> rulesetExecutorMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
//
// public static JsRules getInstance() {
// return INSTANCE;
// }
//
// public Rule loadRuleByJson(String json) throws InvalidConfigException {
// try {
// RuleConfig ruleConfig = objectMapper.readValue(json, RuleConfig.class);
// return getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public Rule loadRuleByName(String ruleName) throws InvalidConfigException {
// Rule rule = ruleMap.get(ruleName);
//
// if (rule == null) {
// String fileName = ruleName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find rule file: " + fileName);
// }
//
// try {
// RuleConfig ruleConfig = objectMapper.readValue(stream, RuleConfig.class);
// rule = getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse rule file: " + ruleName, ex);
// }
// }
//
// return rule;
// }
//
// public RulesetExecutor loadRulesetByJson(String json) throws InvalidConfigException {
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(json, RulesetConfig.class);
// return getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public RulesetExecutor loadRulesetByName(String rulesetName) throws InvalidConfigException {
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
//
// if (ruleset == null) {
// String fileName = rulesetName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find ruleset file: " + fileName);
// }
//
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(stream, RulesetConfig.class);
// ruleset = getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse ruleset file: " + rulesetName, ex);
// }
// }
//
// return ruleset;
// }
//
// @SuppressWarnings("unchecked")
// public <T> T executeRuleset(String rulesetName, Map<String, Object> parameters) throws JsRulesException {
// RulesetExecutor<T> executor = loadRulesetByName(rulesetName);
//
// return executor.execute(parameters);
// }
//
// private Rule getRule(RuleConfig ruleConfig) throws InvalidConfigException {
// String ruleName = ruleConfig.getRuleName();
// Rule rule = ruleMap.get(ruleName);
// if (rule == null) {
// rule = ruleLoader.load(ruleConfig);
// ruleMap.put(ruleName, rule);
// }
// return rule;
// }
//
// private RulesetExecutor getRulesetExecutor(RulesetConfig rulesetConfig) throws InvalidConfigException {
// String rulesetName = rulesetConfig.getRulesetName();
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
// if (ruleset == null) {
// ruleset = rulesetLoader.load(rulesetConfig);
// rulesetExecutorMap.put(rulesetName, ruleset);
// }
// return ruleset;
// }
//
// private InputStream getFileFromClasspath(String fileName) {
// return this.getClass().getResourceAsStream("/" + fileName);
// }
// }
| import org.grouchotools.jsrules.JsRules;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; | package org.grouchotools.jsrules.integration;
/**
* This integration test executes a simply ruleset that evaluates whether an inventory item is in stock at a particular
* store.
* <p/>
* There are two rules in the set:
* <p/>
* 1. Evaluate that the store is one that carries the item
* 2. Evaluate that the current inventory of the item is greater than zero.
* <p/>
* If both rules evaluate to true, the ruleset will return the text "Item is in stock"
* <p/>
* Stores with the item in stock: 1, 2, 3, 5, 7
* <p/>
* Files:
* InventoryRuleset.json
* CarriesItem.json
* HasInventory.json
* <p/>
* Created by Paul Richardson 5/16/2015
*/
public class AllTrueIntegrationTest {
private final String success = "Item is in stock";
| // Path: src/main/java/org/grouchotools/jsrules/JsRules.java
// public class JsRules {
//
// private static final JsRules INSTANCE = new JsRules();
//
// private final ObjectMapper objectMapper = new ObjectMapper();
// private final RuleLoader ruleLoader = new RuleLoaderImpl();
// private final RulesetLoader rulesetLoader = new RulesetLoaderImpl(this);
//
// // default cache values
// private static final int CACHE_SIZE = 25;
// private static final long TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes
//
// // these maps provide rudimentary caching
// private final Map<String, Rule> ruleMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
// private final Map<String, RulesetExecutor> rulesetExecutorMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
//
// public static JsRules getInstance() {
// return INSTANCE;
// }
//
// public Rule loadRuleByJson(String json) throws InvalidConfigException {
// try {
// RuleConfig ruleConfig = objectMapper.readValue(json, RuleConfig.class);
// return getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public Rule loadRuleByName(String ruleName) throws InvalidConfigException {
// Rule rule = ruleMap.get(ruleName);
//
// if (rule == null) {
// String fileName = ruleName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find rule file: " + fileName);
// }
//
// try {
// RuleConfig ruleConfig = objectMapper.readValue(stream, RuleConfig.class);
// rule = getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse rule file: " + ruleName, ex);
// }
// }
//
// return rule;
// }
//
// public RulesetExecutor loadRulesetByJson(String json) throws InvalidConfigException {
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(json, RulesetConfig.class);
// return getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public RulesetExecutor loadRulesetByName(String rulesetName) throws InvalidConfigException {
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
//
// if (ruleset == null) {
// String fileName = rulesetName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find ruleset file: " + fileName);
// }
//
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(stream, RulesetConfig.class);
// ruleset = getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse ruleset file: " + rulesetName, ex);
// }
// }
//
// return ruleset;
// }
//
// @SuppressWarnings("unchecked")
// public <T> T executeRuleset(String rulesetName, Map<String, Object> parameters) throws JsRulesException {
// RulesetExecutor<T> executor = loadRulesetByName(rulesetName);
//
// return executor.execute(parameters);
// }
//
// private Rule getRule(RuleConfig ruleConfig) throws InvalidConfigException {
// String ruleName = ruleConfig.getRuleName();
// Rule rule = ruleMap.get(ruleName);
// if (rule == null) {
// rule = ruleLoader.load(ruleConfig);
// ruleMap.put(ruleName, rule);
// }
// return rule;
// }
//
// private RulesetExecutor getRulesetExecutor(RulesetConfig rulesetConfig) throws InvalidConfigException {
// String rulesetName = rulesetConfig.getRulesetName();
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
// if (ruleset == null) {
// ruleset = rulesetLoader.load(rulesetConfig);
// rulesetExecutorMap.put(rulesetName, ruleset);
// }
// return ruleset;
// }
//
// private InputStream getFileFromClasspath(String fileName) {
// return this.getClass().getResourceAsStream("/" + fileName);
// }
// }
// Path: src/test/java/org/grouchotools/jsrules/integration/AllTrueIntegrationTest.java
import org.grouchotools.jsrules.JsRules;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
package org.grouchotools.jsrules.integration;
/**
* This integration test executes a simply ruleset that evaluates whether an inventory item is in stock at a particular
* store.
* <p/>
* There are two rules in the set:
* <p/>
* 1. Evaluate that the store is one that carries the item
* 2. Evaluate that the current inventory of the item is greater than zero.
* <p/>
* If both rules evaluate to true, the ruleset will return the text "Item is in stock"
* <p/>
* Stores with the item in stock: 1, 2, 3, 5, 7
* <p/>
* Files:
* InventoryRuleset.json
* CarriesItem.json
* HasInventory.json
* <p/>
* Created by Paul Richardson 5/16/2015
*/
public class AllTrueIntegrationTest {
private final String success = "Item is in stock";
| private JsRules jsRules; |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/RuleExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/RuleExecutorImpl.java
// public class RuleExecutorImpl<T, P> extends RuleExecutor<T> {
// private static final Logger LOG = LoggerFactory.getLogger(RuleExecutorImpl.class);
//
// private final Rule<T, P> rule;
//
// public RuleExecutorImpl(Rule<T, P> rule) {
// this.rule = rule;
// }
//
// @Override
// public T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// Object staticValue = rule.getRightParameter().getStaticValue();
// if (staticValue != null) {
// LOG.error("Right parameter has a static value of {} and should not be specified", staticValue);
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public T execute(Object leftParameter) throws InvalidParameterException {
// Object rightParameter = rule.getRightParameter().getStaticValue();
//
// if (rightParameter == null) {
// LOG.error("Right parameter must be specified");
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public Parameter getLeftParameter() {
// return rule.getLeftParameter();
// }
//
// @Override
// public Parameter getRightParameter() {
// return rule.getRightParameter();
// }
//
// @Override
// public Rule getRule() {
// return rule;
// }
//
// private T executeRule(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// validateParameter(rule.getLeftParameter().getName(), leftParameter, rule.getLeftParameter().getKlasse());
// validateParameter(rule.getRightParameter().getName(), rightParameter, rule.getRightParameter().getKlasse());
//
// T response = null;
//
// if (rule.getOperator().compare(leftParameter, rightParameter)) {
// response = rule.getResponse();
// }
//
// return response;
// }
//
// }
| import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.RuleExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when; | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.grouchotools.jsrules;
/**
*
* @author Paul
*/
@RunWith(MockitoJUnitRunner.class)
public class RuleExecutorTest {
private RuleExecutor<String> executor;
@org.junit.Rule
public ExpectedException exception= ExpectedException.none();
@Mock
Rule<String, Long> ruleMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() { | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/RuleExecutorImpl.java
// public class RuleExecutorImpl<T, P> extends RuleExecutor<T> {
// private static final Logger LOG = LoggerFactory.getLogger(RuleExecutorImpl.class);
//
// private final Rule<T, P> rule;
//
// public RuleExecutorImpl(Rule<T, P> rule) {
// this.rule = rule;
// }
//
// @Override
// public T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// Object staticValue = rule.getRightParameter().getStaticValue();
// if (staticValue != null) {
// LOG.error("Right parameter has a static value of {} and should not be specified", staticValue);
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public T execute(Object leftParameter) throws InvalidParameterException {
// Object rightParameter = rule.getRightParameter().getStaticValue();
//
// if (rightParameter == null) {
// LOG.error("Right parameter must be specified");
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public Parameter getLeftParameter() {
// return rule.getLeftParameter();
// }
//
// @Override
// public Parameter getRightParameter() {
// return rule.getRightParameter();
// }
//
// @Override
// public Rule getRule() {
// return rule;
// }
//
// private T executeRule(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// validateParameter(rule.getLeftParameter().getName(), leftParameter, rule.getLeftParameter().getKlasse());
// validateParameter(rule.getRightParameter().getName(), rightParameter, rule.getRightParameter().getKlasse());
//
// T response = null;
//
// if (rule.getOperator().compare(leftParameter, rightParameter)) {
// response = rule.getResponse();
// }
//
// return response;
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/RuleExecutorTest.java
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.RuleExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.grouchotools.jsrules;
/**
*
* @author Paul
*/
@RunWith(MockitoJUnitRunner.class)
public class RuleExecutorTest {
private RuleExecutor<String> executor;
@org.junit.Rule
public ExpectedException exception= ExpectedException.none();
@Mock
Rule<String, Long> ruleMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() { | executor = new RuleExecutorImpl<>(ruleMock); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/RuleExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/RuleExecutorImpl.java
// public class RuleExecutorImpl<T, P> extends RuleExecutor<T> {
// private static final Logger LOG = LoggerFactory.getLogger(RuleExecutorImpl.class);
//
// private final Rule<T, P> rule;
//
// public RuleExecutorImpl(Rule<T, P> rule) {
// this.rule = rule;
// }
//
// @Override
// public T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// Object staticValue = rule.getRightParameter().getStaticValue();
// if (staticValue != null) {
// LOG.error("Right parameter has a static value of {} and should not be specified", staticValue);
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public T execute(Object leftParameter) throws InvalidParameterException {
// Object rightParameter = rule.getRightParameter().getStaticValue();
//
// if (rightParameter == null) {
// LOG.error("Right parameter must be specified");
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public Parameter getLeftParameter() {
// return rule.getLeftParameter();
// }
//
// @Override
// public Parameter getRightParameter() {
// return rule.getRightParameter();
// }
//
// @Override
// public Rule getRule() {
// return rule;
// }
//
// private T executeRule(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// validateParameter(rule.getLeftParameter().getName(), leftParameter, rule.getLeftParameter().getKlasse());
// validateParameter(rule.getRightParameter().getName(), rightParameter, rule.getRightParameter().getKlasse());
//
// T response = null;
//
// if (rule.getOperator().compare(leftParameter, rightParameter)) {
// response = rule.getResponse();
// }
//
// return response;
// }
//
// }
| import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.RuleExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when; | Parameter<Long> leftParameterMock = new Parameter<>("left", Long.class);
when(ruleMock.getLeftParameter()).thenReturn(leftParameterMock);
Parameter<Long> rightParameterMock = new Parameter<>("right", Long.class);
when(ruleMock.getRightParameter()).thenReturn(rightParameterMock);
}
@After
public void tearDown() {
}
@Test
public void instantiateWithRuleTest() {
assertNotNull(executor);
}
@Test
public void executeRuleBasic() throws Exception {
String responseMock = "Left is greater than right!";
when(ruleMock.getResponse()).thenReturn(responseMock);
when(ruleMock.getOperator()).thenReturn(Operator.GT);
assertEquals(responseMock, executor.execute(10l, 5l));
assertNull(executor.execute(5l, 10l));
assertNull(executor.execute(5l, 5l));
}
@Test
public void executeRuleInvalidLeftParameter() throws Exception { | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/RuleExecutorImpl.java
// public class RuleExecutorImpl<T, P> extends RuleExecutor<T> {
// private static final Logger LOG = LoggerFactory.getLogger(RuleExecutorImpl.class);
//
// private final Rule<T, P> rule;
//
// public RuleExecutorImpl(Rule<T, P> rule) {
// this.rule = rule;
// }
//
// @Override
// public T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// Object staticValue = rule.getRightParameter().getStaticValue();
// if (staticValue != null) {
// LOG.error("Right parameter has a static value of {} and should not be specified", staticValue);
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public T execute(Object leftParameter) throws InvalidParameterException {
// Object rightParameter = rule.getRightParameter().getStaticValue();
//
// if (rightParameter == null) {
// LOG.error("Right parameter must be specified");
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public Parameter getLeftParameter() {
// return rule.getLeftParameter();
// }
//
// @Override
// public Parameter getRightParameter() {
// return rule.getRightParameter();
// }
//
// @Override
// public Rule getRule() {
// return rule;
// }
//
// private T executeRule(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// validateParameter(rule.getLeftParameter().getName(), leftParameter, rule.getLeftParameter().getKlasse());
// validateParameter(rule.getRightParameter().getName(), rightParameter, rule.getRightParameter().getKlasse());
//
// T response = null;
//
// if (rule.getOperator().compare(leftParameter, rightParameter)) {
// response = rule.getResponse();
// }
//
// return response;
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/RuleExecutorTest.java
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.RuleExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;
Parameter<Long> leftParameterMock = new Parameter<>("left", Long.class);
when(ruleMock.getLeftParameter()).thenReturn(leftParameterMock);
Parameter<Long> rightParameterMock = new Parameter<>("right", Long.class);
when(ruleMock.getRightParameter()).thenReturn(rightParameterMock);
}
@After
public void tearDown() {
}
@Test
public void instantiateWithRuleTest() {
assertNotNull(executor);
}
@Test
public void executeRuleBasic() throws Exception {
String responseMock = "Left is greater than right!";
when(ruleMock.getResponse()).thenReturn(responseMock);
when(ruleMock.getOperator()).thenReturn(Operator.GT);
assertEquals(responseMock, executor.execute(10l, 5l));
assertNull(executor.execute(5l, 10l));
assertNull(executor.execute(5l, 5l));
}
@Test
public void executeRuleInvalidLeftParameter() throws Exception { | exception.expect(InvalidParameterException.class); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/AllTrueRulesetListExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetListExecutorImpl.java
// public class AllTrueRulesetListExecutorImpl<T> extends RulesetListExecutor<T> {
// private final List<RulesetExecutor> rulesetList;
// private final T response;
// private final String name;
//
// public AllTrueRulesetListExecutorImpl(String name, List<RulesetExecutor> rulesetList, T response) {
// this.name = name;
// this.rulesetList = rulesetList;
// this.response = response;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = response;
// for (RulesetExecutor ruleSet : rulesetList) {
// if (ruleSet.execute(parameters) == null) {
// result = null;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.AllTrueRulesetListExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; | /*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules;
/**
* @author Paul
*/
@RunWith(MockitoJUnitRunner.class)
public class AllTrueRulesetListExecutorTest {
private RulesetExecutor<String> executor;
private String responseMock = "mock";
private final String rulesetName = "mockRuleset";
@org.junit.Rule
public ExpectedException exception = ExpectedException.none();
private List<RulesetExecutor> rulesetListMock;
private Map<String, Object> parameters;
@Mock
private RulesetExecutor rulesetExecutorMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
rulesetListMock = new ArrayList<>();
parameters = new HashMap<>();
| // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetListExecutorImpl.java
// public class AllTrueRulesetListExecutorImpl<T> extends RulesetListExecutor<T> {
// private final List<RulesetExecutor> rulesetList;
// private final T response;
// private final String name;
//
// public AllTrueRulesetListExecutorImpl(String name, List<RulesetExecutor> rulesetList, T response) {
// this.name = name;
// this.rulesetList = rulesetList;
// this.response = response;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = response;
// for (RulesetExecutor ruleSet : rulesetList) {
// if (ruleSet.execute(parameters) == null) {
// result = null;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/AllTrueRulesetListExecutorTest.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.AllTrueRulesetListExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
/*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules;
/**
* @author Paul
*/
@RunWith(MockitoJUnitRunner.class)
public class AllTrueRulesetListExecutorTest {
private RulesetExecutor<String> executor;
private String responseMock = "mock";
private final String rulesetName = "mockRuleset";
@org.junit.Rule
public ExpectedException exception = ExpectedException.none();
private List<RulesetExecutor> rulesetListMock;
private Map<String, Object> parameters;
@Mock
private RulesetExecutor rulesetExecutorMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
rulesetListMock = new ArrayList<>();
parameters = new HashMap<>();
| executor = new AllTrueRulesetListExecutorImpl<>(rulesetName, rulesetListMock, responseMock); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/AllTrueRulesetListExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetListExecutorImpl.java
// public class AllTrueRulesetListExecutorImpl<T> extends RulesetListExecutor<T> {
// private final List<RulesetExecutor> rulesetList;
// private final T response;
// private final String name;
//
// public AllTrueRulesetListExecutorImpl(String name, List<RulesetExecutor> rulesetList, T response) {
// this.name = name;
// this.rulesetList = rulesetList;
// this.response = response;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = response;
// for (RulesetExecutor ruleSet : rulesetList) {
// if (ruleSet.execute(parameters) == null) {
// result = null;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.AllTrueRulesetListExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; | @Mock
private RulesetExecutor rulesetExecutorMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
rulesetListMock = new ArrayList<>();
parameters = new HashMap<>();
executor = new AllTrueRulesetListExecutorImpl<>(rulesetName, rulesetListMock, responseMock);
}
@After
public void tearDown() {
}
@Test
public void executeAllTrueRulesetListEmptyTest() throws Exception {
assertEquals(responseMock, executor.execute(parameters));
}
@Test
public void executeAllTrueRulesetListInvalidParametersTest() throws Exception { | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetListExecutorImpl.java
// public class AllTrueRulesetListExecutorImpl<T> extends RulesetListExecutor<T> {
// private final List<RulesetExecutor> rulesetList;
// private final T response;
// private final String name;
//
// public AllTrueRulesetListExecutorImpl(String name, List<RulesetExecutor> rulesetList, T response) {
// this.name = name;
// this.rulesetList = rulesetList;
// this.response = response;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = response;
// for (RulesetExecutor ruleSet : rulesetList) {
// if (ruleSet.execute(parameters) == null) {
// result = null;
// break;
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/AllTrueRulesetListExecutorTest.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.AllTrueRulesetListExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
@Mock
private RulesetExecutor rulesetExecutorMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
rulesetListMock = new ArrayList<>();
parameters = new HashMap<>();
executor = new AllTrueRulesetListExecutorImpl<>(rulesetName, rulesetListMock, responseMock);
}
@After
public void tearDown() {
}
@Test
public void executeAllTrueRulesetListEmptyTest() throws Exception {
assertEquals(responseMock, executor.execute(parameters));
}
@Test
public void executeAllTrueRulesetListInvalidParametersTest() throws Exception { | exception.expect(InvalidParameterException.class); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/util/ClassHandlerTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/ClassHandlerException.java
// public class ClassHandlerException extends JsRulesException {
//
// public ClassHandlerException() {
// }
//
// public ClassHandlerException(String message) {
// super(message);
// }
//
// public ClassHandlerException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public ClassHandlerException(Throwable cause) {
// super(cause);
// }
//
// public ClassHandlerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import static org.junit.Assert.assertEquals;
import org.grouchotools.jsrules.exception.ClassHandlerException;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.*;
import org.junit.rules.ExpectedException;
import java.util.Set; | assertEquals(String.class, handler.getMyClass());
}
@Test
public void StringConversionTest() throws Exception {
String string = "string";
ClassHandler handler = ClassHandler.STRING;
assertEquals(string, handler.convertString(string));
}
@Test
public void LongSetClassTest() {
ClassHandler handler = ClassHandler.NUMBERSET;
assertEquals(Set.class, handler.getMyClass());
}
@Test
public void LongSetConversionTest() throws Exception {
String string = "[1,2,3,4,5]";
ClassHandler handler = ClassHandler.NUMBERSET;
Set<Long> set = handler.convertString(string);
assertEquals(5, set.size());
}
@Test
public void LongSetExceptionTest() throws Exception { | // Path: src/main/java/org/grouchotools/jsrules/exception/ClassHandlerException.java
// public class ClassHandlerException extends JsRulesException {
//
// public ClassHandlerException() {
// }
//
// public ClassHandlerException(String message) {
// super(message);
// }
//
// public ClassHandlerException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public ClassHandlerException(Throwable cause) {
// super(cause);
// }
//
// public ClassHandlerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/util/ClassHandlerTest.java
import static org.junit.Assert.assertEquals;
import org.grouchotools.jsrules.exception.ClassHandlerException;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.*;
import org.junit.rules.ExpectedException;
import java.util.Set;
assertEquals(String.class, handler.getMyClass());
}
@Test
public void StringConversionTest() throws Exception {
String string = "string";
ClassHandler handler = ClassHandler.STRING;
assertEquals(string, handler.convertString(string));
}
@Test
public void LongSetClassTest() {
ClassHandler handler = ClassHandler.NUMBERSET;
assertEquals(Set.class, handler.getMyClass());
}
@Test
public void LongSetConversionTest() throws Exception {
String string = "[1,2,3,4,5]";
ClassHandler handler = ClassHandler.NUMBERSET;
Set<Long> set = handler.convertString(string);
assertEquals(5, set.size());
}
@Test
public void LongSetExceptionTest() throws Exception { | exception.expect(ClassHandlerException.class); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/AllTrueRulesetExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetExecutorImpl.java
// public class AllTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
// private final static Logger LOGGER = LoggerFactory.getLogger(AllTrueRulesetExecutorImpl.class);
//
// private final List<RuleExecutor> ruleSet;
// private final T response;
// private String name;
//
// public AllTrueRulesetExecutorImpl(String name, List<RuleExecutor> ruleSet, T response) {
// this.name = name;
// this.ruleSet = ruleSet;
// this.response = response;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = response;
// for(RuleExecutor rule:ruleSet) {
// Parameter ruleParamRight = rule.getRightParameter();
// Object leftParameter = parameters.get(rule.getLeftParameter().getName());
// Object rightParameter = parameters.get(ruleParamRight.getName());
//
// if (ruleParamRight.getStaticValue() == null) {
// // check both parameters --failed rule checks return null
// if (rule.execute(leftParameter, rightParameter) == null) {
// result = null;
// break;
// }
// } else {
// // check left parameter only -- failed rule checks return null
// if (rule.execute(leftParameter) == null) {
// result = null;
// break;
// }
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/RuleExecutorImpl.java
// public class RuleExecutorImpl<T, P> extends RuleExecutor<T> {
// private static final Logger LOG = LoggerFactory.getLogger(RuleExecutorImpl.class);
//
// private final Rule<T, P> rule;
//
// public RuleExecutorImpl(Rule<T, P> rule) {
// this.rule = rule;
// }
//
// @Override
// public T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// Object staticValue = rule.getRightParameter().getStaticValue();
// if (staticValue != null) {
// LOG.error("Right parameter has a static value of {} and should not be specified", staticValue);
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public T execute(Object leftParameter) throws InvalidParameterException {
// Object rightParameter = rule.getRightParameter().getStaticValue();
//
// if (rightParameter == null) {
// LOG.error("Right parameter must be specified");
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public Parameter getLeftParameter() {
// return rule.getLeftParameter();
// }
//
// @Override
// public Parameter getRightParameter() {
// return rule.getRightParameter();
// }
//
// @Override
// public Rule getRule() {
// return rule;
// }
//
// private T executeRule(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// validateParameter(rule.getLeftParameter().getName(), leftParameter, rule.getLeftParameter().getKlasse());
// validateParameter(rule.getRightParameter().getName(), rightParameter, rule.getRightParameter().getKlasse());
//
// T response = null;
//
// if (rule.getOperator().compare(leftParameter, rightParameter)) {
// response = rule.getResponse();
// }
//
// return response;
// }
//
// }
| import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.AllTrueRulesetExecutorImpl;
import org.grouchotools.jsrules.impl.RuleExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock; |
private List<RuleExecutor> ruleListMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
ruleListMock = new ArrayList<>();
executor = new AllTrueRulesetExecutorImpl<>(rulesetName, ruleListMock, responseMock);
}
@After
public void tearDown() {
}
@Test
public void executeRulesetTest() throws Exception {
Map<String, Object> parameters = new HashMap<>();
assertEquals(responseMock, executor.execute(parameters));
}
@Test
public void executeRulesetInvalidParametersTest() throws Exception { | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetExecutorImpl.java
// public class AllTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
// private final static Logger LOGGER = LoggerFactory.getLogger(AllTrueRulesetExecutorImpl.class);
//
// private final List<RuleExecutor> ruleSet;
// private final T response;
// private String name;
//
// public AllTrueRulesetExecutorImpl(String name, List<RuleExecutor> ruleSet, T response) {
// this.name = name;
// this.ruleSet = ruleSet;
// this.response = response;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = response;
// for(RuleExecutor rule:ruleSet) {
// Parameter ruleParamRight = rule.getRightParameter();
// Object leftParameter = parameters.get(rule.getLeftParameter().getName());
// Object rightParameter = parameters.get(ruleParamRight.getName());
//
// if (ruleParamRight.getStaticValue() == null) {
// // check both parameters --failed rule checks return null
// if (rule.execute(leftParameter, rightParameter) == null) {
// result = null;
// break;
// }
// } else {
// // check left parameter only -- failed rule checks return null
// if (rule.execute(leftParameter) == null) {
// result = null;
// break;
// }
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/RuleExecutorImpl.java
// public class RuleExecutorImpl<T, P> extends RuleExecutor<T> {
// private static final Logger LOG = LoggerFactory.getLogger(RuleExecutorImpl.class);
//
// private final Rule<T, P> rule;
//
// public RuleExecutorImpl(Rule<T, P> rule) {
// this.rule = rule;
// }
//
// @Override
// public T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// Object staticValue = rule.getRightParameter().getStaticValue();
// if (staticValue != null) {
// LOG.error("Right parameter has a static value of {} and should not be specified", staticValue);
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public T execute(Object leftParameter) throws InvalidParameterException {
// Object rightParameter = rule.getRightParameter().getStaticValue();
//
// if (rightParameter == null) {
// LOG.error("Right parameter must be specified");
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public Parameter getLeftParameter() {
// return rule.getLeftParameter();
// }
//
// @Override
// public Parameter getRightParameter() {
// return rule.getRightParameter();
// }
//
// @Override
// public Rule getRule() {
// return rule;
// }
//
// private T executeRule(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// validateParameter(rule.getLeftParameter().getName(), leftParameter, rule.getLeftParameter().getKlasse());
// validateParameter(rule.getRightParameter().getName(), rightParameter, rule.getRightParameter().getKlasse());
//
// T response = null;
//
// if (rule.getOperator().compare(leftParameter, rightParameter)) {
// response = rule.getResponse();
// }
//
// return response;
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/AllTrueRulesetExecutorTest.java
import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.AllTrueRulesetExecutorImpl;
import org.grouchotools.jsrules.impl.RuleExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
private List<RuleExecutor> ruleListMock;
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
ruleListMock = new ArrayList<>();
executor = new AllTrueRulesetExecutorImpl<>(rulesetName, ruleListMock, responseMock);
}
@After
public void tearDown() {
}
@Test
public void executeRulesetTest() throws Exception {
Map<String, Object> parameters = new HashMap<>();
assertEquals(responseMock, executor.execute(parameters));
}
@Test
public void executeRulesetInvalidParametersTest() throws Exception { | exception.expect(InvalidParameterException.class); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/AllTrueRulesetExecutorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetExecutorImpl.java
// public class AllTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
// private final static Logger LOGGER = LoggerFactory.getLogger(AllTrueRulesetExecutorImpl.class);
//
// private final List<RuleExecutor> ruleSet;
// private final T response;
// private String name;
//
// public AllTrueRulesetExecutorImpl(String name, List<RuleExecutor> ruleSet, T response) {
// this.name = name;
// this.ruleSet = ruleSet;
// this.response = response;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = response;
// for(RuleExecutor rule:ruleSet) {
// Parameter ruleParamRight = rule.getRightParameter();
// Object leftParameter = parameters.get(rule.getLeftParameter().getName());
// Object rightParameter = parameters.get(ruleParamRight.getName());
//
// if (ruleParamRight.getStaticValue() == null) {
// // check both parameters --failed rule checks return null
// if (rule.execute(leftParameter, rightParameter) == null) {
// result = null;
// break;
// }
// } else {
// // check left parameter only -- failed rule checks return null
// if (rule.execute(leftParameter) == null) {
// result = null;
// break;
// }
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/RuleExecutorImpl.java
// public class RuleExecutorImpl<T, P> extends RuleExecutor<T> {
// private static final Logger LOG = LoggerFactory.getLogger(RuleExecutorImpl.class);
//
// private final Rule<T, P> rule;
//
// public RuleExecutorImpl(Rule<T, P> rule) {
// this.rule = rule;
// }
//
// @Override
// public T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// Object staticValue = rule.getRightParameter().getStaticValue();
// if (staticValue != null) {
// LOG.error("Right parameter has a static value of {} and should not be specified", staticValue);
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public T execute(Object leftParameter) throws InvalidParameterException {
// Object rightParameter = rule.getRightParameter().getStaticValue();
//
// if (rightParameter == null) {
// LOG.error("Right parameter must be specified");
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public Parameter getLeftParameter() {
// return rule.getLeftParameter();
// }
//
// @Override
// public Parameter getRightParameter() {
// return rule.getRightParameter();
// }
//
// @Override
// public Rule getRule() {
// return rule;
// }
//
// private T executeRule(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// validateParameter(rule.getLeftParameter().getName(), leftParameter, rule.getLeftParameter().getKlasse());
// validateParameter(rule.getRightParameter().getName(), rightParameter, rule.getRightParameter().getKlasse());
//
// T response = null;
//
// if (rule.getOperator().compare(leftParameter, rightParameter)) {
// response = rule.getResponse();
// }
//
// return response;
// }
//
// }
| import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.AllTrueRulesetExecutorImpl;
import org.grouchotools.jsrules.impl.RuleExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock; | @AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
ruleListMock = new ArrayList<>();
executor = new AllTrueRulesetExecutorImpl<>(rulesetName, ruleListMock, responseMock);
}
@After
public void tearDown() {
}
@Test
public void executeRulesetTest() throws Exception {
Map<String, Object> parameters = new HashMap<>();
assertEquals(responseMock, executor.execute(parameters));
}
@Test
public void executeRulesetInvalidParametersTest() throws Exception {
exception.expect(InvalidParameterException.class);
when(ruleMock.getLeftParameter()).thenReturn(new Parameter<>("left",
Long.class));
when(ruleMock.getRightParameter()).thenReturn(new Parameter<>("right",
Long.class));
| // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetExecutorImpl.java
// public class AllTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
// private final static Logger LOGGER = LoggerFactory.getLogger(AllTrueRulesetExecutorImpl.class);
//
// private final List<RuleExecutor> ruleSet;
// private final T response;
// private String name;
//
// public AllTrueRulesetExecutorImpl(String name, List<RuleExecutor> ruleSet, T response) {
// this.name = name;
// this.ruleSet = ruleSet;
// this.response = response;
// }
//
// @Override
// public T execute(Map<String, Object> parameters) throws InvalidParameterException {
// T result = response;
// for(RuleExecutor rule:ruleSet) {
// Parameter ruleParamRight = rule.getRightParameter();
// Object leftParameter = parameters.get(rule.getLeftParameter().getName());
// Object rightParameter = parameters.get(ruleParamRight.getName());
//
// if (ruleParamRight.getStaticValue() == null) {
// // check both parameters --failed rule checks return null
// if (rule.execute(leftParameter, rightParameter) == null) {
// result = null;
// break;
// }
// } else {
// // check left parameter only -- failed rule checks return null
// if (rule.execute(leftParameter) == null) {
// result = null;
// break;
// }
// }
// }
// return result;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/impl/RuleExecutorImpl.java
// public class RuleExecutorImpl<T, P> extends RuleExecutor<T> {
// private static final Logger LOG = LoggerFactory.getLogger(RuleExecutorImpl.class);
//
// private final Rule<T, P> rule;
//
// public RuleExecutorImpl(Rule<T, P> rule) {
// this.rule = rule;
// }
//
// @Override
// public T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// Object staticValue = rule.getRightParameter().getStaticValue();
// if (staticValue != null) {
// LOG.error("Right parameter has a static value of {} and should not be specified", staticValue);
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public T execute(Object leftParameter) throws InvalidParameterException {
// Object rightParameter = rule.getRightParameter().getStaticValue();
//
// if (rightParameter == null) {
// LOG.error("Right parameter must be specified");
// throw new InvalidParameterException();
// }
//
// return executeRule(leftParameter, rightParameter);
// }
//
// @Override
// public Parameter getLeftParameter() {
// return rule.getLeftParameter();
// }
//
// @Override
// public Parameter getRightParameter() {
// return rule.getRightParameter();
// }
//
// @Override
// public Rule getRule() {
// return rule;
// }
//
// private T executeRule(Object leftParameter, Object rightParameter) throws InvalidParameterException {
// validateParameter(rule.getLeftParameter().getName(), leftParameter, rule.getLeftParameter().getKlasse());
// validateParameter(rule.getRightParameter().getName(), rightParameter, rule.getRightParameter().getKlasse());
//
// T response = null;
//
// if (rule.getOperator().compare(leftParameter, rightParameter)) {
// response = rule.getResponse();
// }
//
// return response;
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/AllTrueRulesetExecutorTest.java
import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.impl.AllTrueRulesetExecutorImpl;
import org.grouchotools.jsrules.impl.RuleExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
ruleListMock = new ArrayList<>();
executor = new AllTrueRulesetExecutorImpl<>(rulesetName, ruleListMock, responseMock);
}
@After
public void tearDown() {
}
@Test
public void executeRulesetTest() throws Exception {
Map<String, Object> parameters = new HashMap<>();
assertEquals(responseMock, executor.execute(parameters));
}
@Test
public void executeRulesetInvalidParametersTest() throws Exception {
exception.expect(InvalidParameterException.class);
when(ruleMock.getLeftParameter()).thenReturn(new Parameter<>("left",
Long.class));
when(ruleMock.getRightParameter()).thenReturn(new Parameter<>("right",
Long.class));
| RuleExecutor<String> ruleExecutorMock = new RuleExecutorImpl<>(ruleMock); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/integration/FirstTrueRulesetListIntegrationTest.java | // Path: src/main/java/org/grouchotools/jsrules/JsRules.java
// public class JsRules {
//
// private static final JsRules INSTANCE = new JsRules();
//
// private final ObjectMapper objectMapper = new ObjectMapper();
// private final RuleLoader ruleLoader = new RuleLoaderImpl();
// private final RulesetLoader rulesetLoader = new RulesetLoaderImpl(this);
//
// // default cache values
// private static final int CACHE_SIZE = 25;
// private static final long TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes
//
// // these maps provide rudimentary caching
// private final Map<String, Rule> ruleMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
// private final Map<String, RulesetExecutor> rulesetExecutorMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
//
// public static JsRules getInstance() {
// return INSTANCE;
// }
//
// public Rule loadRuleByJson(String json) throws InvalidConfigException {
// try {
// RuleConfig ruleConfig = objectMapper.readValue(json, RuleConfig.class);
// return getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public Rule loadRuleByName(String ruleName) throws InvalidConfigException {
// Rule rule = ruleMap.get(ruleName);
//
// if (rule == null) {
// String fileName = ruleName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find rule file: " + fileName);
// }
//
// try {
// RuleConfig ruleConfig = objectMapper.readValue(stream, RuleConfig.class);
// rule = getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse rule file: " + ruleName, ex);
// }
// }
//
// return rule;
// }
//
// public RulesetExecutor loadRulesetByJson(String json) throws InvalidConfigException {
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(json, RulesetConfig.class);
// return getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public RulesetExecutor loadRulesetByName(String rulesetName) throws InvalidConfigException {
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
//
// if (ruleset == null) {
// String fileName = rulesetName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find ruleset file: " + fileName);
// }
//
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(stream, RulesetConfig.class);
// ruleset = getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse ruleset file: " + rulesetName, ex);
// }
// }
//
// return ruleset;
// }
//
// @SuppressWarnings("unchecked")
// public <T> T executeRuleset(String rulesetName, Map<String, Object> parameters) throws JsRulesException {
// RulesetExecutor<T> executor = loadRulesetByName(rulesetName);
//
// return executor.execute(parameters);
// }
//
// private Rule getRule(RuleConfig ruleConfig) throws InvalidConfigException {
// String ruleName = ruleConfig.getRuleName();
// Rule rule = ruleMap.get(ruleName);
// if (rule == null) {
// rule = ruleLoader.load(ruleConfig);
// ruleMap.put(ruleName, rule);
// }
// return rule;
// }
//
// private RulesetExecutor getRulesetExecutor(RulesetConfig rulesetConfig) throws InvalidConfigException {
// String rulesetName = rulesetConfig.getRulesetName();
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
// if (ruleset == null) {
// ruleset = rulesetLoader.load(rulesetConfig);
// rulesetExecutorMap.put(rulesetName, ruleset);
// }
// return ruleset;
// }
//
// private InputStream getFileFromClasspath(String fileName) {
// return this.getClass().getResourceAsStream("/" + fileName);
// }
// }
| import org.grouchotools.jsrules.JsRules;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; | package org.grouchotools.jsrules.integration;
/**
* This integration test executes a simple "first true" ruleset list
* <p/>
* There are two rulesets in the list:
* <p/>
* 1. Evaluate that the current inventory at that store is greater than zero.
* 2. Evaluate that the customer can afford something in that store
* <p/>
* If the first ruleset returns true, the response will be "Item is in stock"
* If the first ruleset is false but the second ruleset returns true, the response will be "Item is in budget"
* <p/>
* Stores with the item in stock: 1, 2, 3, 5, 7
* Trouser cost: $200.00 / Shirt cost: $100.00
* <p/>
* Files:
* FirstTrueIntegrationRulesetList.json
* InventoryRuleset.json
* InBudgetRuleset.json
* <p/>
* Created by Paul Richardson 5/16/2015
*/
public class FirstTrueRulesetListIntegrationTest {
private final String itemInStock = "Item is in stock";
| // Path: src/main/java/org/grouchotools/jsrules/JsRules.java
// public class JsRules {
//
// private static final JsRules INSTANCE = new JsRules();
//
// private final ObjectMapper objectMapper = new ObjectMapper();
// private final RuleLoader ruleLoader = new RuleLoaderImpl();
// private final RulesetLoader rulesetLoader = new RulesetLoaderImpl(this);
//
// // default cache values
// private static final int CACHE_SIZE = 25;
// private static final long TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes
//
// // these maps provide rudimentary caching
// private final Map<String, Rule> ruleMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
// private final Map<String, RulesetExecutor> rulesetExecutorMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
//
// public static JsRules getInstance() {
// return INSTANCE;
// }
//
// public Rule loadRuleByJson(String json) throws InvalidConfigException {
// try {
// RuleConfig ruleConfig = objectMapper.readValue(json, RuleConfig.class);
// return getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public Rule loadRuleByName(String ruleName) throws InvalidConfigException {
// Rule rule = ruleMap.get(ruleName);
//
// if (rule == null) {
// String fileName = ruleName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find rule file: " + fileName);
// }
//
// try {
// RuleConfig ruleConfig = objectMapper.readValue(stream, RuleConfig.class);
// rule = getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse rule file: " + ruleName, ex);
// }
// }
//
// return rule;
// }
//
// public RulesetExecutor loadRulesetByJson(String json) throws InvalidConfigException {
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(json, RulesetConfig.class);
// return getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public RulesetExecutor loadRulesetByName(String rulesetName) throws InvalidConfigException {
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
//
// if (ruleset == null) {
// String fileName = rulesetName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find ruleset file: " + fileName);
// }
//
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(stream, RulesetConfig.class);
// ruleset = getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse ruleset file: " + rulesetName, ex);
// }
// }
//
// return ruleset;
// }
//
// @SuppressWarnings("unchecked")
// public <T> T executeRuleset(String rulesetName, Map<String, Object> parameters) throws JsRulesException {
// RulesetExecutor<T> executor = loadRulesetByName(rulesetName);
//
// return executor.execute(parameters);
// }
//
// private Rule getRule(RuleConfig ruleConfig) throws InvalidConfigException {
// String ruleName = ruleConfig.getRuleName();
// Rule rule = ruleMap.get(ruleName);
// if (rule == null) {
// rule = ruleLoader.load(ruleConfig);
// ruleMap.put(ruleName, rule);
// }
// return rule;
// }
//
// private RulesetExecutor getRulesetExecutor(RulesetConfig rulesetConfig) throws InvalidConfigException {
// String rulesetName = rulesetConfig.getRulesetName();
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
// if (ruleset == null) {
// ruleset = rulesetLoader.load(rulesetConfig);
// rulesetExecutorMap.put(rulesetName, ruleset);
// }
// return ruleset;
// }
//
// private InputStream getFileFromClasspath(String fileName) {
// return this.getClass().getResourceAsStream("/" + fileName);
// }
// }
// Path: src/test/java/org/grouchotools/jsrules/integration/FirstTrueRulesetListIntegrationTest.java
import org.grouchotools.jsrules.JsRules;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
package org.grouchotools.jsrules.integration;
/**
* This integration test executes a simple "first true" ruleset list
* <p/>
* There are two rulesets in the list:
* <p/>
* 1. Evaluate that the current inventory at that store is greater than zero.
* 2. Evaluate that the customer can afford something in that store
* <p/>
* If the first ruleset returns true, the response will be "Item is in stock"
* If the first ruleset is false but the second ruleset returns true, the response will be "Item is in budget"
* <p/>
* Stores with the item in stock: 1, 2, 3, 5, 7
* Trouser cost: $200.00 / Shirt cost: $100.00
* <p/>
* Files:
* FirstTrueIntegrationRulesetList.json
* InventoryRuleset.json
* InBudgetRuleset.json
* <p/>
* Created by Paul Richardson 5/16/2015
*/
public class FirstTrueRulesetListIntegrationTest {
private final String itemInStock = "Item is in stock";
| private JsRules jsRules; |
el-groucho/jsRules | src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetExecutorImpl.java | // Path: src/main/java/org/grouchotools/jsrules/Parameter.java
// public class Parameter<T> extends JsonBean {
// public Parameter(String name, Class<T> klasse) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = null;
// }
//
// public Parameter(String name, Class<T> klasse, T staticValue) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = staticValue;
// }
//
// private final String name;
// private final Class<T> klasse;
// private final T staticValue;
//
// public String getName() {
// return name;
// }
//
// public Class<T> getKlasse() {
// return klasse;
// }
//
// public T getStaticValue() {
// return staticValue;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RuleExecutor.java
// public abstract class RuleExecutor<T> extends Executor {
// public abstract T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException;
//
// public abstract T execute(Object leftParameter) throws InvalidParameterException;
//
// public abstract Parameter getLeftParameter();
//
// public abstract Parameter getRightParameter();
//
// public abstract Rule getRule();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RulesetExecutor.java
// public abstract class RulesetExecutor<T> extends Executor {
// public abstract T execute(Map<String, Object> parameters) throws InvalidParameterException;
//
// public abstract String getName();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import java.util.List;
import java.util.Map;
import org.grouchotools.jsrules.Parameter;
import org.grouchotools.jsrules.RuleExecutor;
import org.grouchotools.jsrules.RulesetExecutor;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
| /*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.impl;
/**
* This executor evaluates a series of rules in order.
*
* If all rules evaluate as true, it returns the given response. Otherwise, the
* response is null.
*
* @author Paul
* @param <T>
*/
public class AllTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
private final static Logger LOGGER = LoggerFactory.getLogger(AllTrueRulesetExecutorImpl.class);
| // Path: src/main/java/org/grouchotools/jsrules/Parameter.java
// public class Parameter<T> extends JsonBean {
// public Parameter(String name, Class<T> klasse) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = null;
// }
//
// public Parameter(String name, Class<T> klasse, T staticValue) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = staticValue;
// }
//
// private final String name;
// private final Class<T> klasse;
// private final T staticValue;
//
// public String getName() {
// return name;
// }
//
// public Class<T> getKlasse() {
// return klasse;
// }
//
// public T getStaticValue() {
// return staticValue;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RuleExecutor.java
// public abstract class RuleExecutor<T> extends Executor {
// public abstract T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException;
//
// public abstract T execute(Object leftParameter) throws InvalidParameterException;
//
// public abstract Parameter getLeftParameter();
//
// public abstract Parameter getRightParameter();
//
// public abstract Rule getRule();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RulesetExecutor.java
// public abstract class RulesetExecutor<T> extends Executor {
// public abstract T execute(Map<String, Object> parameters) throws InvalidParameterException;
//
// public abstract String getName();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetExecutorImpl.java
import java.util.List;
import java.util.Map;
import org.grouchotools.jsrules.Parameter;
import org.grouchotools.jsrules.RuleExecutor;
import org.grouchotools.jsrules.RulesetExecutor;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.impl;
/**
* This executor evaluates a series of rules in order.
*
* If all rules evaluate as true, it returns the given response. Otherwise, the
* response is null.
*
* @author Paul
* @param <T>
*/
public class AllTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
private final static Logger LOGGER = LoggerFactory.getLogger(AllTrueRulesetExecutorImpl.class);
| private final List<RuleExecutor> ruleSet;
|
el-groucho/jsRules | src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetExecutorImpl.java | // Path: src/main/java/org/grouchotools/jsrules/Parameter.java
// public class Parameter<T> extends JsonBean {
// public Parameter(String name, Class<T> klasse) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = null;
// }
//
// public Parameter(String name, Class<T> klasse, T staticValue) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = staticValue;
// }
//
// private final String name;
// private final Class<T> klasse;
// private final T staticValue;
//
// public String getName() {
// return name;
// }
//
// public Class<T> getKlasse() {
// return klasse;
// }
//
// public T getStaticValue() {
// return staticValue;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RuleExecutor.java
// public abstract class RuleExecutor<T> extends Executor {
// public abstract T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException;
//
// public abstract T execute(Object leftParameter) throws InvalidParameterException;
//
// public abstract Parameter getLeftParameter();
//
// public abstract Parameter getRightParameter();
//
// public abstract Rule getRule();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RulesetExecutor.java
// public abstract class RulesetExecutor<T> extends Executor {
// public abstract T execute(Map<String, Object> parameters) throws InvalidParameterException;
//
// public abstract String getName();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import java.util.List;
import java.util.Map;
import org.grouchotools.jsrules.Parameter;
import org.grouchotools.jsrules.RuleExecutor;
import org.grouchotools.jsrules.RulesetExecutor;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
| /*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.impl;
/**
* This executor evaluates a series of rules in order.
*
* If all rules evaluate as true, it returns the given response. Otherwise, the
* response is null.
*
* @author Paul
* @param <T>
*/
public class AllTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
private final static Logger LOGGER = LoggerFactory.getLogger(AllTrueRulesetExecutorImpl.class);
private final List<RuleExecutor> ruleSet;
private final T response;
private String name;
public AllTrueRulesetExecutorImpl(String name, List<RuleExecutor> ruleSet, T response) {
this.name = name;
this.ruleSet = ruleSet;
this.response = response;
}
@Override
| // Path: src/main/java/org/grouchotools/jsrules/Parameter.java
// public class Parameter<T> extends JsonBean {
// public Parameter(String name, Class<T> klasse) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = null;
// }
//
// public Parameter(String name, Class<T> klasse, T staticValue) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = staticValue;
// }
//
// private final String name;
// private final Class<T> klasse;
// private final T staticValue;
//
// public String getName() {
// return name;
// }
//
// public Class<T> getKlasse() {
// return klasse;
// }
//
// public T getStaticValue() {
// return staticValue;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RuleExecutor.java
// public abstract class RuleExecutor<T> extends Executor {
// public abstract T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException;
//
// public abstract T execute(Object leftParameter) throws InvalidParameterException;
//
// public abstract Parameter getLeftParameter();
//
// public abstract Parameter getRightParameter();
//
// public abstract Rule getRule();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RulesetExecutor.java
// public abstract class RulesetExecutor<T> extends Executor {
// public abstract T execute(Map<String, Object> parameters) throws InvalidParameterException;
//
// public abstract String getName();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetExecutorImpl.java
import java.util.List;
import java.util.Map;
import org.grouchotools.jsrules.Parameter;
import org.grouchotools.jsrules.RuleExecutor;
import org.grouchotools.jsrules.RulesetExecutor;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.impl;
/**
* This executor evaluates a series of rules in order.
*
* If all rules evaluate as true, it returns the given response. Otherwise, the
* response is null.
*
* @author Paul
* @param <T>
*/
public class AllTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
private final static Logger LOGGER = LoggerFactory.getLogger(AllTrueRulesetExecutorImpl.class);
private final List<RuleExecutor> ruleSet;
private final T response;
private String name;
public AllTrueRulesetExecutorImpl(String name, List<RuleExecutor> ruleSet, T response) {
this.name = name;
this.ruleSet = ruleSet;
this.response = response;
}
@Override
| public T execute(Map<String, Object> parameters) throws InvalidParameterException {
|
el-groucho/jsRules | src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetExecutorImpl.java | // Path: src/main/java/org/grouchotools/jsrules/Parameter.java
// public class Parameter<T> extends JsonBean {
// public Parameter(String name, Class<T> klasse) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = null;
// }
//
// public Parameter(String name, Class<T> klasse, T staticValue) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = staticValue;
// }
//
// private final String name;
// private final Class<T> klasse;
// private final T staticValue;
//
// public String getName() {
// return name;
// }
//
// public Class<T> getKlasse() {
// return klasse;
// }
//
// public T getStaticValue() {
// return staticValue;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RuleExecutor.java
// public abstract class RuleExecutor<T> extends Executor {
// public abstract T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException;
//
// public abstract T execute(Object leftParameter) throws InvalidParameterException;
//
// public abstract Parameter getLeftParameter();
//
// public abstract Parameter getRightParameter();
//
// public abstract Rule getRule();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RulesetExecutor.java
// public abstract class RulesetExecutor<T> extends Executor {
// public abstract T execute(Map<String, Object> parameters) throws InvalidParameterException;
//
// public abstract String getName();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import java.util.List;
import java.util.Map;
import org.grouchotools.jsrules.Parameter;
import org.grouchotools.jsrules.RuleExecutor;
import org.grouchotools.jsrules.RulesetExecutor;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
| /*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.impl;
/**
* This executor evaluates a series of rules in order.
*
* If all rules evaluate as true, it returns the given response. Otherwise, the
* response is null.
*
* @author Paul
* @param <T>
*/
public class AllTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
private final static Logger LOGGER = LoggerFactory.getLogger(AllTrueRulesetExecutorImpl.class);
private final List<RuleExecutor> ruleSet;
private final T response;
private String name;
public AllTrueRulesetExecutorImpl(String name, List<RuleExecutor> ruleSet, T response) {
this.name = name;
this.ruleSet = ruleSet;
this.response = response;
}
@Override
public T execute(Map<String, Object> parameters) throws InvalidParameterException {
T result = response;
for(RuleExecutor rule:ruleSet) {
| // Path: src/main/java/org/grouchotools/jsrules/Parameter.java
// public class Parameter<T> extends JsonBean {
// public Parameter(String name, Class<T> klasse) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = null;
// }
//
// public Parameter(String name, Class<T> klasse, T staticValue) {
// this.name = name;
// this.klasse = klasse;
// this.staticValue = staticValue;
// }
//
// private final String name;
// private final Class<T> klasse;
// private final T staticValue;
//
// public String getName() {
// return name;
// }
//
// public Class<T> getKlasse() {
// return klasse;
// }
//
// public T getStaticValue() {
// return staticValue;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RuleExecutor.java
// public abstract class RuleExecutor<T> extends Executor {
// public abstract T execute(Object leftParameter, Object rightParameter) throws InvalidParameterException;
//
// public abstract T execute(Object leftParameter) throws InvalidParameterException;
//
// public abstract Parameter getLeftParameter();
//
// public abstract Parameter getRightParameter();
//
// public abstract Rule getRule();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RulesetExecutor.java
// public abstract class RulesetExecutor<T> extends Executor {
// public abstract T execute(Map<String, Object> parameters) throws InvalidParameterException;
//
// public abstract String getName();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetExecutorImpl.java
import java.util.List;
import java.util.Map;
import org.grouchotools.jsrules.Parameter;
import org.grouchotools.jsrules.RuleExecutor;
import org.grouchotools.jsrules.RulesetExecutor;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.impl;
/**
* This executor evaluates a series of rules in order.
*
* If all rules evaluate as true, it returns the given response. Otherwise, the
* response is null.
*
* @author Paul
* @param <T>
*/
public class AllTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
private final static Logger LOGGER = LoggerFactory.getLogger(AllTrueRulesetExecutorImpl.class);
private final List<RuleExecutor> ruleSet;
private final T response;
private String name;
public AllTrueRulesetExecutorImpl(String name, List<RuleExecutor> ruleSet, T response) {
this.name = name;
this.ruleSet = ruleSet;
this.response = response;
}
@Override
public T execute(Map<String, Object> parameters) throws InvalidParameterException {
T result = response;
for(RuleExecutor rule:ruleSet) {
| Parameter ruleParamRight = rule.getRightParameter();
|
el-groucho/jsRules | src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetListExecutorImpl.java | // Path: src/main/java/org/grouchotools/jsrules/RulesetExecutor.java
// public abstract class RulesetExecutor<T> extends Executor {
// public abstract T execute(Map<String, Object> parameters) throws InvalidParameterException;
//
// public abstract String getName();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RulesetListExecutor.java
// public abstract class RulesetListExecutor<T> extends RulesetExecutor<T> {
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import org.grouchotools.jsrules.RulesetExecutor;
import org.grouchotools.jsrules.RulesetListExecutor;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import java.util.List;
import java.util.Map; | /*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.impl;
/**
* This executor evaluates a series of rulesets in order.
* <p/>
* If all rulesets evaluate as true, it returns the given response. Otherwise, the
* response is null.
*
* @param <T>
* @author Paul
*/
public class AllTrueRulesetListExecutorImpl<T> extends RulesetListExecutor<T> {
private final List<RulesetExecutor> rulesetList;
private final T response;
private final String name;
public AllTrueRulesetListExecutorImpl(String name, List<RulesetExecutor> rulesetList, T response) {
this.name = name;
this.rulesetList = rulesetList;
this.response = response;
}
@Override | // Path: src/main/java/org/grouchotools/jsrules/RulesetExecutor.java
// public abstract class RulesetExecutor<T> extends Executor {
// public abstract T execute(Map<String, Object> parameters) throws InvalidParameterException;
//
// public abstract String getName();
// }
//
// Path: src/main/java/org/grouchotools/jsrules/RulesetListExecutor.java
// public abstract class RulesetListExecutor<T> extends RulesetExecutor<T> {
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/main/java/org/grouchotools/jsrules/impl/AllTrueRulesetListExecutorImpl.java
import org.grouchotools.jsrules.RulesetExecutor;
import org.grouchotools.jsrules.RulesetListExecutor;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import java.util.List;
import java.util.Map;
/*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.impl;
/**
* This executor evaluates a series of rulesets in order.
* <p/>
* If all rulesets evaluate as true, it returns the given response. Otherwise, the
* response is null.
*
* @param <T>
* @author Paul
*/
public class AllTrueRulesetListExecutorImpl<T> extends RulesetListExecutor<T> {
private final List<RulesetExecutor> rulesetList;
private final T response;
private final String name;
public AllTrueRulesetListExecutorImpl(String name, List<RulesetExecutor> rulesetList, T response) {
this.name = name;
this.rulesetList = rulesetList;
this.response = response;
}
@Override | public T execute(Map<String, Object> parameters) throws InvalidParameterException { |
el-groucho/jsRules | src/main/java/org/grouchotools/jsrules/Executor.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package org.grouchotools.jsrules;
/**
* Contains common methods used by various executors
* <p/>
* Created by Paul Richardson 4/30/2015
*/
public abstract class Executor {
private static final Logger LOG = LoggerFactory.getLogger(Executor.class);
/**
* Validate that parameter is present (not null) and is an instance of the correct
* class
*
* @param key the name of the parameter
* @param parameter the parameter object
* @param expectedClass the class we are expecting the parameter to be
*/ | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/org/grouchotools/jsrules/Executor.java
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.grouchotools.jsrules;
/**
* Contains common methods used by various executors
* <p/>
* Created by Paul Richardson 4/30/2015
*/
public abstract class Executor {
private static final Logger LOG = LoggerFactory.getLogger(Executor.class);
/**
* Validate that parameter is present (not null) and is an instance of the correct
* class
*
* @param key the name of the parameter
* @param parameter the parameter object
* @param expectedClass the class we are expecting the parameter to be
*/ | protected void validateParameter(String key, Object parameter, Class expectedClass) throws InvalidParameterException { |
el-groucho/jsRules | src/main/java/org/grouchotools/jsrules/Executor.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package org.grouchotools.jsrules;
/**
* Contains common methods used by various executors
* <p/>
* Created by Paul Richardson 4/30/2015
*/
public abstract class Executor {
private static final Logger LOG = LoggerFactory.getLogger(Executor.class);
/**
* Validate that parameter is present (not null) and is an instance of the correct
* class
*
* @param key the name of the parameter
* @param parameter the parameter object
* @param expectedClass the class we are expecting the parameter to be
*/
protected void validateParameter(String key, Object parameter, Class expectedClass) throws InvalidParameterException {
if (parameter == null) {
LOG.error("Expected Parameter {} is missing", key); | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/org/grouchotools/jsrules/Executor.java
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.grouchotools.jsrules;
/**
* Contains common methods used by various executors
* <p/>
* Created by Paul Richardson 4/30/2015
*/
public abstract class Executor {
private static final Logger LOG = LoggerFactory.getLogger(Executor.class);
/**
* Validate that parameter is present (not null) and is an instance of the correct
* class
*
* @param key the name of the parameter
* @param parameter the parameter object
* @param expectedClass the class we are expecting the parameter to be
*/
protected void validateParameter(String key, Object parameter, Class expectedClass) throws InvalidParameterException {
if (parameter == null) {
LOG.error("Expected Parameter {} is missing", key); | throw new MissingParameterException(); |
el-groucho/jsRules | src/main/java/org/grouchotools/jsrules/Executor.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package org.grouchotools.jsrules;
/**
* Contains common methods used by various executors
* <p/>
* Created by Paul Richardson 4/30/2015
*/
public abstract class Executor {
private static final Logger LOG = LoggerFactory.getLogger(Executor.class);
/**
* Validate that parameter is present (not null) and is an instance of the correct
* class
*
* @param key the name of the parameter
* @param parameter the parameter object
* @param expectedClass the class we are expecting the parameter to be
*/
protected void validateParameter(String key, Object parameter, Class expectedClass) throws InvalidParameterException {
if (parameter == null) {
LOG.error("Expected Parameter {} is missing", key);
throw new MissingParameterException();
} else if (!expectedClass.isInstance(parameter)) {
LOG.error("Parameter {} is invalid | Expected class: {} | Parameter Class: {}",
key, expectedClass, parameter.getClass()); | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
// public InvalidParameterClassException() {
// }
//
// public InvalidParameterClassException(String message) {
// super(message);
// }
//
// public InvalidParameterClassException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterClassException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
// public MissingParameterException() {
// }
//
// public MissingParameterException(String message) {
// super(message);
// }
//
// public MissingParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public MissingParameterException(Throwable cause) {
// super(cause);
// }
//
// public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/org/grouchotools/jsrules/Executor.java
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.grouchotools.jsrules;
/**
* Contains common methods used by various executors
* <p/>
* Created by Paul Richardson 4/30/2015
*/
public abstract class Executor {
private static final Logger LOG = LoggerFactory.getLogger(Executor.class);
/**
* Validate that parameter is present (not null) and is an instance of the correct
* class
*
* @param key the name of the parameter
* @param parameter the parameter object
* @param expectedClass the class we are expecting the parameter to be
*/
protected void validateParameter(String key, Object parameter, Class expectedClass) throws InvalidParameterException {
if (parameter == null) {
LOG.error("Expected Parameter {} is missing", key);
throw new MissingParameterException();
} else if (!expectedClass.isInstance(parameter)) {
LOG.error("Parameter {} is invalid | Expected class: {} | Parameter Class: {}",
key, expectedClass, parameter.getClass()); | throw new InvalidParameterClassException(); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/OperatorTest.java | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.junit.*;
import org.junit.rules.ExpectedException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; |
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void greaterThanTest() throws Exception {
Operator operator = Operator.GT;
Long left = 10l;
Long right = 5l;
assertTrue(operator.compare(left, right));
assertFalse(operator.compare(right, left));
right = left;
assertFalse(operator.compare(left, right));
Integer rightInt = 5;
assertTrue(operator.compare(left, rightInt));
}
@Test
public void greaterThanExceptionTest() throws Exception { | // Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterException.java
// public class InvalidParameterException extends JsRulesException {
//
// public InvalidParameterException() {
// }
//
// public InvalidParameterException(String message) {
// super(message);
// }
//
// public InvalidParameterException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidParameterException(Throwable cause) {
// super(cause);
// }
//
// public InvalidParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/OperatorTest.java
import org.grouchotools.jsrules.exception.InvalidParameterException;
import org.junit.*;
import org.junit.rules.ExpectedException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void greaterThanTest() throws Exception {
Operator operator = Operator.GT;
Long left = 10l;
Long right = 5l;
assertTrue(operator.compare(left, right));
assertFalse(operator.compare(right, left));
right = left;
assertFalse(operator.compare(left, right));
Integer rightInt = 5;
assertTrue(operator.compare(left, rightInt));
}
@Test
public void greaterThanExceptionTest() throws Exception { | exception.expect(InvalidParameterException.class); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/integration/FirstTrueIntegrationTest.java | // Path: src/main/java/org/grouchotools/jsrules/JsRules.java
// public class JsRules {
//
// private static final JsRules INSTANCE = new JsRules();
//
// private final ObjectMapper objectMapper = new ObjectMapper();
// private final RuleLoader ruleLoader = new RuleLoaderImpl();
// private final RulesetLoader rulesetLoader = new RulesetLoaderImpl(this);
//
// // default cache values
// private static final int CACHE_SIZE = 25;
// private static final long TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes
//
// // these maps provide rudimentary caching
// private final Map<String, Rule> ruleMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
// private final Map<String, RulesetExecutor> rulesetExecutorMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
//
// public static JsRules getInstance() {
// return INSTANCE;
// }
//
// public Rule loadRuleByJson(String json) throws InvalidConfigException {
// try {
// RuleConfig ruleConfig = objectMapper.readValue(json, RuleConfig.class);
// return getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public Rule loadRuleByName(String ruleName) throws InvalidConfigException {
// Rule rule = ruleMap.get(ruleName);
//
// if (rule == null) {
// String fileName = ruleName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find rule file: " + fileName);
// }
//
// try {
// RuleConfig ruleConfig = objectMapper.readValue(stream, RuleConfig.class);
// rule = getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse rule file: " + ruleName, ex);
// }
// }
//
// return rule;
// }
//
// public RulesetExecutor loadRulesetByJson(String json) throws InvalidConfigException {
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(json, RulesetConfig.class);
// return getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public RulesetExecutor loadRulesetByName(String rulesetName) throws InvalidConfigException {
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
//
// if (ruleset == null) {
// String fileName = rulesetName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find ruleset file: " + fileName);
// }
//
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(stream, RulesetConfig.class);
// ruleset = getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse ruleset file: " + rulesetName, ex);
// }
// }
//
// return ruleset;
// }
//
// @SuppressWarnings("unchecked")
// public <T> T executeRuleset(String rulesetName, Map<String, Object> parameters) throws JsRulesException {
// RulesetExecutor<T> executor = loadRulesetByName(rulesetName);
//
// return executor.execute(parameters);
// }
//
// private Rule getRule(RuleConfig ruleConfig) throws InvalidConfigException {
// String ruleName = ruleConfig.getRuleName();
// Rule rule = ruleMap.get(ruleName);
// if (rule == null) {
// rule = ruleLoader.load(ruleConfig);
// ruleMap.put(ruleName, rule);
// }
// return rule;
// }
//
// private RulesetExecutor getRulesetExecutor(RulesetConfig rulesetConfig) throws InvalidConfigException {
// String rulesetName = rulesetConfig.getRulesetName();
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
// if (ruleset == null) {
// ruleset = rulesetLoader.load(rulesetConfig);
// rulesetExecutorMap.put(rulesetName, ruleset);
// }
// return ruleset;
// }
//
// private InputStream getFileFromClasspath(String fileName) {
// return this.getClass().getResourceAsStream("/" + fileName);
// }
// }
| import org.grouchotools.jsrules.JsRules;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; | package org.grouchotools.jsrules.integration;
/**
* This integration test executes a simple ruleset that evaluates which inventory item fits in the customer's budget.
* <p/>
* There are two rules in the set:
* <p/>
* 1. Evaluate that the customer can afford trousers.
* 2. Evaluate that the customer can afford a shirt.
* <p/>
* If the first rule evaluates as true, the ruleset will return "Trousers".
* If the second rule evalutes as true, the ruleset will return "Shirt".
* <p/>
* Trousers are $200.00. Shirts are $100.00.
* <p/>
* Files:
* InBudgetRuleset.json
* TrousersInBudget.json
* ShirtInBudget.json
* <p/>
* Created by Paul Richardson 5/16/2015
*/
public class FirstTrueIntegrationTest {
private final String trousers = "Trousers";
private final String shirt = "Shirt";
| // Path: src/main/java/org/grouchotools/jsrules/JsRules.java
// public class JsRules {
//
// private static final JsRules INSTANCE = new JsRules();
//
// private final ObjectMapper objectMapper = new ObjectMapper();
// private final RuleLoader ruleLoader = new RuleLoaderImpl();
// private final RulesetLoader rulesetLoader = new RulesetLoaderImpl(this);
//
// // default cache values
// private static final int CACHE_SIZE = 25;
// private static final long TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes
//
// // these maps provide rudimentary caching
// private final Map<String, Rule> ruleMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
// private final Map<String, RulesetExecutor> rulesetExecutorMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
//
// public static JsRules getInstance() {
// return INSTANCE;
// }
//
// public Rule loadRuleByJson(String json) throws InvalidConfigException {
// try {
// RuleConfig ruleConfig = objectMapper.readValue(json, RuleConfig.class);
// return getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public Rule loadRuleByName(String ruleName) throws InvalidConfigException {
// Rule rule = ruleMap.get(ruleName);
//
// if (rule == null) {
// String fileName = ruleName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find rule file: " + fileName);
// }
//
// try {
// RuleConfig ruleConfig = objectMapper.readValue(stream, RuleConfig.class);
// rule = getRule(ruleConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse rule file: " + ruleName, ex);
// }
// }
//
// return rule;
// }
//
// public RulesetExecutor loadRulesetByJson(String json) throws InvalidConfigException {
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(json, RulesetConfig.class);
// return getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse json: " + json, ex);
// }
// }
//
// public RulesetExecutor loadRulesetByName(String rulesetName) throws InvalidConfigException {
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
//
// if (ruleset == null) {
// String fileName = rulesetName + ".json";
//
// InputStream stream = getFileFromClasspath(fileName);
//
// if (stream == null) {
// throw new InvalidConfigException("Unable to find ruleset file: " + fileName);
// }
//
// try {
// RulesetConfig rulesetConfig = objectMapper.readValue(stream, RulesetConfig.class);
// ruleset = getRulesetExecutor(rulesetConfig);
// } catch (IOException ex) {
// throw new InvalidConfigException("Unable to parse ruleset file: " + rulesetName, ex);
// }
// }
//
// return ruleset;
// }
//
// @SuppressWarnings("unchecked")
// public <T> T executeRuleset(String rulesetName, Map<String, Object> parameters) throws JsRulesException {
// RulesetExecutor<T> executor = loadRulesetByName(rulesetName);
//
// return executor.execute(parameters);
// }
//
// private Rule getRule(RuleConfig ruleConfig) throws InvalidConfigException {
// String ruleName = ruleConfig.getRuleName();
// Rule rule = ruleMap.get(ruleName);
// if (rule == null) {
// rule = ruleLoader.load(ruleConfig);
// ruleMap.put(ruleName, rule);
// }
// return rule;
// }
//
// private RulesetExecutor getRulesetExecutor(RulesetConfig rulesetConfig) throws InvalidConfigException {
// String rulesetName = rulesetConfig.getRulesetName();
// RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
// if (ruleset == null) {
// ruleset = rulesetLoader.load(rulesetConfig);
// rulesetExecutorMap.put(rulesetName, ruleset);
// }
// return ruleset;
// }
//
// private InputStream getFileFromClasspath(String fileName) {
// return this.getClass().getResourceAsStream("/" + fileName);
// }
// }
// Path: src/test/java/org/grouchotools/jsrules/integration/FirstTrueIntegrationTest.java
import org.grouchotools.jsrules.JsRules;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
package org.grouchotools.jsrules.integration;
/**
* This integration test executes a simple ruleset that evaluates which inventory item fits in the customer's budget.
* <p/>
* There are two rules in the set:
* <p/>
* 1. Evaluate that the customer can afford trousers.
* 2. Evaluate that the customer can afford a shirt.
* <p/>
* If the first rule evaluates as true, the ruleset will return "Trousers".
* If the second rule evalutes as true, the ruleset will return "Shirt".
* <p/>
* Trousers are $200.00. Shirts are $100.00.
* <p/>
* Files:
* InBudgetRuleset.json
* TrousersInBudget.json
* ShirtInBudget.json
* <p/>
* Created by Paul Richardson 5/16/2015
*/
public class FirstTrueIntegrationTest {
private final String trousers = "Trousers";
private final String shirt = "Shirt";
| private JsRules jsRules = new JsRules(); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/loader/ResponseLoaderTest.java | // Path: src/main/java/org/grouchotools/jsrules/config/ResponseConfig.java
// public class ResponseConfig extends JsonBean implements Config {
// private String response;
// private String responseClass;
//
// public ResponseConfig() {
//
// }
//
// public ResponseConfig(String response, String responseClass) {
// this.response = response;
// this.responseClass = responseClass;
// }
//
// public String getResponse() {
// return response;
// }
//
// public void setResponse(String response) {
// this.response = response;
// }
//
// public String getResponseClass() {
// return responseClass;
// }
//
// public void setResponseClass(String responseClass) {
// this.responseClass = responseClass;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidConfigException.java
// public class InvalidConfigException extends JsRulesException {
//
// public InvalidConfigException() {
// }
//
// public InvalidConfigException(String message) {
// super(message);
// }
//
// public InvalidConfigException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidConfigException(Throwable cause) {
// super(cause);
// }
//
// public InvalidConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/loader/impl/ResponseLoaderImpl.java
// public class ResponseLoaderImpl<T> implements ResponseLoader<T> {
//
// /**
// *
// * @param config
// * @return
// * @throws org.grouchotools.jsrules.exception.InvalidConfigException
// */
// @Override
// public T load(ResponseConfig config) throws InvalidConfigException {
// if (config == null || config.getResponseClass() == null) {
// throw new InvalidConfigException("Response class must not be null");
// }
// String responseClassName = config.getResponseClass().toUpperCase();
// ClassHandler handler;
// try {
// handler = ClassHandler.valueOf(responseClassName);
// } catch (IllegalArgumentException ex) {
// throw new InvalidConfigException(responseClassName+" is not a supported class", ex);
// }
//
// String responseValue = config.getResponse();
// T response;
// try {
// response = handler.convertString(responseValue);
// } catch (ClassHandlerException|IllegalArgumentException ex) {
// throw new InvalidConfigException(responseValue+" is not a valid "+responseClassName, ex);
// }
//
// return response;
// }
//
// }
| import org.grouchotools.jsrules.config.ResponseConfig;
import org.grouchotools.jsrules.exception.InvalidConfigException;
import org.grouchotools.jsrules.loader.impl.ResponseLoaderImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals; | /*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.loader;
/**
*
* @author Paul
*/
public class ResponseLoaderTest {
@Rule
public ExpectedException exception= ExpectedException.none();
| // Path: src/main/java/org/grouchotools/jsrules/config/ResponseConfig.java
// public class ResponseConfig extends JsonBean implements Config {
// private String response;
// private String responseClass;
//
// public ResponseConfig() {
//
// }
//
// public ResponseConfig(String response, String responseClass) {
// this.response = response;
// this.responseClass = responseClass;
// }
//
// public String getResponse() {
// return response;
// }
//
// public void setResponse(String response) {
// this.response = response;
// }
//
// public String getResponseClass() {
// return responseClass;
// }
//
// public void setResponseClass(String responseClass) {
// this.responseClass = responseClass;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidConfigException.java
// public class InvalidConfigException extends JsRulesException {
//
// public InvalidConfigException() {
// }
//
// public InvalidConfigException(String message) {
// super(message);
// }
//
// public InvalidConfigException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidConfigException(Throwable cause) {
// super(cause);
// }
//
// public InvalidConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/loader/impl/ResponseLoaderImpl.java
// public class ResponseLoaderImpl<T> implements ResponseLoader<T> {
//
// /**
// *
// * @param config
// * @return
// * @throws org.grouchotools.jsrules.exception.InvalidConfigException
// */
// @Override
// public T load(ResponseConfig config) throws InvalidConfigException {
// if (config == null || config.getResponseClass() == null) {
// throw new InvalidConfigException("Response class must not be null");
// }
// String responseClassName = config.getResponseClass().toUpperCase();
// ClassHandler handler;
// try {
// handler = ClassHandler.valueOf(responseClassName);
// } catch (IllegalArgumentException ex) {
// throw new InvalidConfigException(responseClassName+" is not a supported class", ex);
// }
//
// String responseValue = config.getResponse();
// T response;
// try {
// response = handler.convertString(responseValue);
// } catch (ClassHandlerException|IllegalArgumentException ex) {
// throw new InvalidConfigException(responseValue+" is not a valid "+responseClassName, ex);
// }
//
// return response;
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/loader/ResponseLoaderTest.java
import org.grouchotools.jsrules.config.ResponseConfig;
import org.grouchotools.jsrules.exception.InvalidConfigException;
import org.grouchotools.jsrules.loader.impl.ResponseLoaderImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
/*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.loader;
/**
*
* @author Paul
*/
public class ResponseLoaderTest {
@Rule
public ExpectedException exception= ExpectedException.none();
| private final ResponseLoader responseLoader = new ResponseLoaderImpl(); |
el-groucho/jsRules | src/test/java/org/grouchotools/jsrules/loader/ResponseLoaderTest.java | // Path: src/main/java/org/grouchotools/jsrules/config/ResponseConfig.java
// public class ResponseConfig extends JsonBean implements Config {
// private String response;
// private String responseClass;
//
// public ResponseConfig() {
//
// }
//
// public ResponseConfig(String response, String responseClass) {
// this.response = response;
// this.responseClass = responseClass;
// }
//
// public String getResponse() {
// return response;
// }
//
// public void setResponse(String response) {
// this.response = response;
// }
//
// public String getResponseClass() {
// return responseClass;
// }
//
// public void setResponseClass(String responseClass) {
// this.responseClass = responseClass;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidConfigException.java
// public class InvalidConfigException extends JsRulesException {
//
// public InvalidConfigException() {
// }
//
// public InvalidConfigException(String message) {
// super(message);
// }
//
// public InvalidConfigException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidConfigException(Throwable cause) {
// super(cause);
// }
//
// public InvalidConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/loader/impl/ResponseLoaderImpl.java
// public class ResponseLoaderImpl<T> implements ResponseLoader<T> {
//
// /**
// *
// * @param config
// * @return
// * @throws org.grouchotools.jsrules.exception.InvalidConfigException
// */
// @Override
// public T load(ResponseConfig config) throws InvalidConfigException {
// if (config == null || config.getResponseClass() == null) {
// throw new InvalidConfigException("Response class must not be null");
// }
// String responseClassName = config.getResponseClass().toUpperCase();
// ClassHandler handler;
// try {
// handler = ClassHandler.valueOf(responseClassName);
// } catch (IllegalArgumentException ex) {
// throw new InvalidConfigException(responseClassName+" is not a supported class", ex);
// }
//
// String responseValue = config.getResponse();
// T response;
// try {
// response = handler.convertString(responseValue);
// } catch (ClassHandlerException|IllegalArgumentException ex) {
// throw new InvalidConfigException(responseValue+" is not a valid "+responseClassName, ex);
// }
//
// return response;
// }
//
// }
| import org.grouchotools.jsrules.config.ResponseConfig;
import org.grouchotools.jsrules.exception.InvalidConfigException;
import org.grouchotools.jsrules.loader.impl.ResponseLoaderImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals; | /*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.loader;
/**
*
* @author Paul
*/
public class ResponseLoaderTest {
@Rule
public ExpectedException exception= ExpectedException.none();
private final ResponseLoader responseLoader = new ResponseLoaderImpl();
public ResponseLoaderTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void loadResponseTest() throws Exception { | // Path: src/main/java/org/grouchotools/jsrules/config/ResponseConfig.java
// public class ResponseConfig extends JsonBean implements Config {
// private String response;
// private String responseClass;
//
// public ResponseConfig() {
//
// }
//
// public ResponseConfig(String response, String responseClass) {
// this.response = response;
// this.responseClass = responseClass;
// }
//
// public String getResponse() {
// return response;
// }
//
// public void setResponse(String response) {
// this.response = response;
// }
//
// public String getResponseClass() {
// return responseClass;
// }
//
// public void setResponseClass(String responseClass) {
// this.responseClass = responseClass;
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidConfigException.java
// public class InvalidConfigException extends JsRulesException {
//
// public InvalidConfigException() {
// }
//
// public InvalidConfigException(String message) {
// super(message);
// }
//
// public InvalidConfigException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public InvalidConfigException(Throwable cause) {
// super(cause);
// }
//
// public InvalidConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
//
// Path: src/main/java/org/grouchotools/jsrules/loader/impl/ResponseLoaderImpl.java
// public class ResponseLoaderImpl<T> implements ResponseLoader<T> {
//
// /**
// *
// * @param config
// * @return
// * @throws org.grouchotools.jsrules.exception.InvalidConfigException
// */
// @Override
// public T load(ResponseConfig config) throws InvalidConfigException {
// if (config == null || config.getResponseClass() == null) {
// throw new InvalidConfigException("Response class must not be null");
// }
// String responseClassName = config.getResponseClass().toUpperCase();
// ClassHandler handler;
// try {
// handler = ClassHandler.valueOf(responseClassName);
// } catch (IllegalArgumentException ex) {
// throw new InvalidConfigException(responseClassName+" is not a supported class", ex);
// }
//
// String responseValue = config.getResponse();
// T response;
// try {
// response = handler.convertString(responseValue);
// } catch (ClassHandlerException|IllegalArgumentException ex) {
// throw new InvalidConfigException(responseValue+" is not a valid "+responseClassName, ex);
// }
//
// return response;
// }
//
// }
// Path: src/test/java/org/grouchotools/jsrules/loader/ResponseLoaderTest.java
import org.grouchotools.jsrules.config.ResponseConfig;
import org.grouchotools.jsrules.exception.InvalidConfigException;
import org.grouchotools.jsrules.loader.impl.ResponseLoaderImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
/*
* The MIT License
*
* Copyright 2015 Paul.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.grouchotools.jsrules.loader;
/**
*
* @author Paul
*/
public class ResponseLoaderTest {
@Rule
public ExpectedException exception= ExpectedException.none();
private final ResponseLoader responseLoader = new ResponseLoaderImpl();
public ResponseLoaderTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void loadResponseTest() throws Exception { | ResponseConfig responseConfig = new ResponseConfig("25", "long"); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.