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
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/protocol/storage/DeleteFileCommand.java
// Path: src/main/java/org/cleverframe/fastdfs/protocol/BaseResponse.java // public abstract class BaseResponse<T> { // /** // * 报文头 // */ // private ProtocolHead head; // // /** // * 返回值泛型类型 // */ // private final Class<T> genericType; // // /** // * 构造函数 // */ // public BaseResponse() { // this.genericType = ReflectionsUtils.getClassGenricType(getClass()); // } // // /** // * 获取报文长度 // */ // protected long getContentLength() { // return head.getContentLength(); // } // // /** // * 解析反馈结果 请求头报文使用 {@link ProtocolHead#createFromInputStream(InputStream)} 解析 // */ // T decode(ProtocolHead head, InputStream in, Charset charset) throws IOException { // this.head = head; // return decodeContent(in, charset); // } // // /** // * 解析反馈内容 // */ // public T decodeContent(InputStream in, Charset charset) throws IOException { // // 如果有内容 // if (getContentLength() > 0) { // byte[] bytes = new byte[(int) getContentLength()]; // int contentSize = in.read(bytes); // // 获取数据 // if (contentSize != getContentLength()) { // throw new IOException("读取到的数据长度与协议长度不符"); // } // return FastDfsParamMapperUtils.map(bytes, genericType, charset); // } // return null; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/request/DeleteFileRequest.java // public class DeleteFileRequest extends BaseRequest { // /** // * 组名 // */ // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // /** // * 路径名 // */ // @FastDFSColumn(index = 1, dynamicField = DynamicFieldType.allRestByte) // private String path; // // /** // * 删除文件命令 // * // * @param groupName 组名 // * @param path 文件路径 // */ // public DeleteFileRequest(String groupName, String path) { // super(); // this.groupName = groupName; // this.path = path; // this.head = new ProtocolHead(CmdConstants.STORAGE_PROTO_CMD_DELETE_FILE); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // }
import org.cleverframe.fastdfs.protocol.BaseResponse; import org.cleverframe.fastdfs.protocol.storage.request.DeleteFileRequest;
package org.cleverframe.fastdfs.protocol.storage; /** * 删除文件爱你命令 * 作者:LiZW <br/> * 创建时间:2016/11/20 17:03 <br/> */ public class DeleteFileCommand extends StorageCommand<Void> { /** * 文件删除命令 * * @param groupName 组名 * @param path 文件路径 */ public DeleteFileCommand(String groupName, String path) { super(); this.request = new DeleteFileRequest(groupName, path); // 输出响应
// Path: src/main/java/org/cleverframe/fastdfs/protocol/BaseResponse.java // public abstract class BaseResponse<T> { // /** // * 报文头 // */ // private ProtocolHead head; // // /** // * 返回值泛型类型 // */ // private final Class<T> genericType; // // /** // * 构造函数 // */ // public BaseResponse() { // this.genericType = ReflectionsUtils.getClassGenricType(getClass()); // } // // /** // * 获取报文长度 // */ // protected long getContentLength() { // return head.getContentLength(); // } // // /** // * 解析反馈结果 请求头报文使用 {@link ProtocolHead#createFromInputStream(InputStream)} 解析 // */ // T decode(ProtocolHead head, InputStream in, Charset charset) throws IOException { // this.head = head; // return decodeContent(in, charset); // } // // /** // * 解析反馈内容 // */ // public T decodeContent(InputStream in, Charset charset) throws IOException { // // 如果有内容 // if (getContentLength() > 0) { // byte[] bytes = new byte[(int) getContentLength()]; // int contentSize = in.read(bytes); // // 获取数据 // if (contentSize != getContentLength()) { // throw new IOException("读取到的数据长度与协议长度不符"); // } // return FastDfsParamMapperUtils.map(bytes, genericType, charset); // } // return null; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/request/DeleteFileRequest.java // public class DeleteFileRequest extends BaseRequest { // /** // * 组名 // */ // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // /** // * 路径名 // */ // @FastDFSColumn(index = 1, dynamicField = DynamicFieldType.allRestByte) // private String path; // // /** // * 删除文件命令 // * // * @param groupName 组名 // * @param path 文件路径 // */ // public DeleteFileRequest(String groupName, String path) { // super(); // this.groupName = groupName; // this.path = path; // this.head = new ProtocolHead(CmdConstants.STORAGE_PROTO_CMD_DELETE_FILE); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // } // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/DeleteFileCommand.java import org.cleverframe.fastdfs.protocol.BaseResponse; import org.cleverframe.fastdfs.protocol.storage.request.DeleteFileRequest; package org.cleverframe.fastdfs.protocol.storage; /** * 删除文件爱你命令 * 作者:LiZW <br/> * 创建时间:2016/11/20 17:03 <br/> */ public class DeleteFileCommand extends StorageCommand<Void> { /** * 文件删除命令 * * @param groupName 组名 * @param path 文件路径 */ public DeleteFileCommand(String groupName, String path) { super(); this.request = new DeleteFileRequest(groupName, path); // 输出响应
this.response = new BaseResponse<Void>() {
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/mapper/ObjectMateData.java
// Path: src/main/java/org/cleverframe/fastdfs/exception/FastDfsColumnMapException.java // public class FastDfsColumnMapException extends RuntimeException { // public FastDfsColumnMapException() { // } // // // public FastDfsColumnMapException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { // // super(message, cause, enableSuppression, writableStackTrace); // // } // // public FastDfsColumnMapException(String message, Throwable cause) { // super(message, cause); // } // // public FastDfsColumnMapException(String message) { // super(message); // } // // public FastDfsColumnMapException(Throwable cause) { // super(cause); // } // }
import org.cleverframe.fastdfs.exception.FastDfsColumnMapException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.List;
} /** * 是否有动态数据列 */ private boolean hasDynamicField() { for (FieldMateData field : fieldList) { if (field.isDynamicField()) { return true; } } return false; } /** * 获取动态数据列长度 */ private int getDynamicFieldSize(Object obj, Charset charset) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { int size = 0; for (FieldMateData field : dynamicFieldList) { size = size + field.getDynamicFieldByteSize(obj, charset); } return size; } /** * 获取固定参数对象总长度 */ public int getFieldsFixTotalSize() { if (hasDynamicField()) {
// Path: src/main/java/org/cleverframe/fastdfs/exception/FastDfsColumnMapException.java // public class FastDfsColumnMapException extends RuntimeException { // public FastDfsColumnMapException() { // } // // // public FastDfsColumnMapException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { // // super(message, cause, enableSuppression, writableStackTrace); // // } // // public FastDfsColumnMapException(String message, Throwable cause) { // super(message, cause); // } // // public FastDfsColumnMapException(String message) { // super(message); // } // // public FastDfsColumnMapException(Throwable cause) { // super(cause); // } // } // Path: src/main/java/org/cleverframe/fastdfs/mapper/ObjectMateData.java import org.cleverframe.fastdfs.exception.FastDfsColumnMapException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.List; } /** * 是否有动态数据列 */ private boolean hasDynamicField() { for (FieldMateData field : fieldList) { if (field.isDynamicField()) { return true; } } return false; } /** * 获取动态数据列长度 */ private int getDynamicFieldSize(Object obj, Charset charset) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { int size = 0; for (FieldMateData field : dynamicFieldList) { size = size + field.getDynamicFieldByteSize(obj, charset); } return size; } /** * 获取固定参数对象总长度 */ public int getFieldsFixTotalSize() { if (hasDynamicField()) {
throw new FastDfsColumnMapException(className + "类中有Dynamic字段, 不支持操作getFieldsTotalSize");
Lzw2016/fastdfs-java-client
src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetStorageNodeCommandTest.java
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNode.java // public class StorageNode implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // @FastDFSColumn(index = 3) // private byte storeIndex; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // * @param storeIndex 存储服务器顺序 // */ // public StorageNode(String ip, int port, byte storeIndex) { // super(); // this.ip = ip; // this.port = port; // this.storeIndex = storeIndex; // } // // public StorageNode() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // public byte getStoreIndex() { // return storeIndex; // } // // public void setStoreIndex(byte storeIndex) { // this.storeIndex = storeIndex; // } // // @Override // public String toString() { // return "StorageNode{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // ", storeIndex=" + storeIndex + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // }
import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNode; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:16 <br/> */ public class GetStorageNodeCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetListStorageCommandTest.class); @Test public void test01() {
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNode.java // public class StorageNode implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // @FastDFSColumn(index = 3) // private byte storeIndex; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // * @param storeIndex 存储服务器顺序 // */ // public StorageNode(String ip, int port, byte storeIndex) { // super(); // this.ip = ip; // this.port = port; // this.storeIndex = storeIndex; // } // // public StorageNode() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // public byte getStoreIndex() { // return storeIndex; // } // // public void setStoreIndex(byte storeIndex) { // this.storeIndex = storeIndex; // } // // @Override // public String toString() { // return "StorageNode{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // ", storeIndex=" + storeIndex + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // } // Path: src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetStorageNodeCommandTest.java import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNode; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:16 <br/> */ public class GetStorageNodeCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetListStorageCommandTest.class); @Test public void test01() {
Connection connection = GetTrackerConnection.getDefaultConnection();
Lzw2016/fastdfs-java-client
src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetStorageNodeCommandTest.java
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNode.java // public class StorageNode implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // @FastDFSColumn(index = 3) // private byte storeIndex; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // * @param storeIndex 存储服务器顺序 // */ // public StorageNode(String ip, int port, byte storeIndex) { // super(); // this.ip = ip; // this.port = port; // this.storeIndex = storeIndex; // } // // public StorageNode() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // public byte getStoreIndex() { // return storeIndex; // } // // public void setStoreIndex(byte storeIndex) { // this.storeIndex = storeIndex; // } // // @Override // public String toString() { // return "StorageNode{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // ", storeIndex=" + storeIndex + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // }
import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNode; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:16 <br/> */ public class GetStorageNodeCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetListStorageCommandTest.class); @Test public void test01() {
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNode.java // public class StorageNode implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // @FastDFSColumn(index = 3) // private byte storeIndex; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // * @param storeIndex 存储服务器顺序 // */ // public StorageNode(String ip, int port, byte storeIndex) { // super(); // this.ip = ip; // this.port = port; // this.storeIndex = storeIndex; // } // // public StorageNode() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // public byte getStoreIndex() { // return storeIndex; // } // // public void setStoreIndex(byte storeIndex) { // this.storeIndex = storeIndex; // } // // @Override // public String toString() { // return "StorageNode{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // ", storeIndex=" + storeIndex + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // } // Path: src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetStorageNodeCommandTest.java import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNode; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:16 <br/> */ public class GetStorageNodeCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetListStorageCommandTest.class); @Test public void test01() {
Connection connection = GetTrackerConnection.getDefaultConnection();
Lzw2016/fastdfs-java-client
src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetStorageNodeCommandTest.java
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNode.java // public class StorageNode implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // @FastDFSColumn(index = 3) // private byte storeIndex; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // * @param storeIndex 存储服务器顺序 // */ // public StorageNode(String ip, int port, byte storeIndex) { // super(); // this.ip = ip; // this.port = port; // this.storeIndex = storeIndex; // } // // public StorageNode() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // public byte getStoreIndex() { // return storeIndex; // } // // public void setStoreIndex(byte storeIndex) { // this.storeIndex = storeIndex; // } // // @Override // public String toString() { // return "StorageNode{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // ", storeIndex=" + storeIndex + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // }
import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNode; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:16 <br/> */ public class GetStorageNodeCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetListStorageCommandTest.class); @Test public void test01() { Connection connection = GetTrackerConnection.getDefaultConnection(); try { GetStorageNodeCommand command = new GetStorageNodeCommand();
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNode.java // public class StorageNode implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // @FastDFSColumn(index = 3) // private byte storeIndex; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // * @param storeIndex 存储服务器顺序 // */ // public StorageNode(String ip, int port, byte storeIndex) { // super(); // this.ip = ip; // this.port = port; // this.storeIndex = storeIndex; // } // // public StorageNode() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // public byte getStoreIndex() { // return storeIndex; // } // // public void setStoreIndex(byte storeIndex) { // this.storeIndex = storeIndex; // } // // @Override // public String toString() { // return "StorageNode{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // ", storeIndex=" + storeIndex + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // } // Path: src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetStorageNodeCommandTest.java import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNode; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:16 <br/> */ public class GetStorageNodeCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetListStorageCommandTest.class); @Test public void test01() { Connection connection = GetTrackerConnection.getDefaultConnection(); try { GetStorageNodeCommand command = new GetStorageNodeCommand();
StorageNode storageNode = command.execute(connection);
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/protocol/storage/DownloadFileCommand.java
// Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/callback/DownloadCallback.java // public interface DownloadCallback<T> { // // /** // * 注意不能直接返回入参的InputStream,因为此方法返回后将关闭原输入流<br/> // * 不能关闭inputStream? TODO 验证是否可以关闭 // * // * @param inputStream 返回数据输入流 // */ // T receive(InputStream inputStream) throws IOException; // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/request/DownloadFileRequest.java // public class DownloadFileRequest extends BaseRequest { // // /** // * 开始位置 // */ // @FastDFSColumn(index = 0) // private long fileOffset; // /** // * 读取文件长度 // */ // @FastDFSColumn(index = 1) // private long fileSize; // /** // * 组名 // */ // @FastDFSColumn(index = 2, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // /** // * 文件路径 // */ // @FastDFSColumn(index = 3, dynamicField = DynamicFieldType.allRestByte) // private String path; // // /** // * 文件下载请求 // * // * @param groupName 组名称 // * @param path 文件路径 // * @param fileOffset 开始位置 // * @param fileSize 读取文件长度 // */ // public DownloadFileRequest(String groupName, String path, long fileOffset, long fileSize) { // super(); // this.groupName = groupName; // this.fileSize = fileSize; // this.path = path; // this.fileOffset = fileOffset; // head = new ProtocolHead(CmdConstants.STORAGE_PROTO_CMD_DOWNLOAD_FILE); // } // // public long getFileOffset() { // return fileOffset; // } // // public String getGroupName() { // return groupName; // } // // public String getPath() { // return path; // } // // @Override // public long getFileSize() { // return fileSize; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/response/DownloadFileResponse.java // public class DownloadFileResponse<T> extends BaseResponse<T> { // // private DownloadCallback<T> callback; // // public DownloadFileResponse(DownloadCallback<T> callback) { // super(); // this.callback = callback; // } // // /** // * 解析反馈内容 // */ // @Override // public T decodeContent(InputStream in, Charset charset) throws IOException { // // 解析报文内容 // FastDFSInputStream input = new FastDFSInputStream(in, getContentLength()); // return callback.receive(input); // } // }
import org.cleverframe.fastdfs.protocol.storage.callback.DownloadCallback; import org.cleverframe.fastdfs.protocol.storage.request.DownloadFileRequest; import org.cleverframe.fastdfs.protocol.storage.response.DownloadFileResponse;
package org.cleverframe.fastdfs.protocol.storage; /** * 下载文件 * 作者:LiZW <br/> * 创建时间:2016/11/20 16:02 <br/> */ public class DownloadFileCommand<T> extends StorageCommand<T> { /** * 下载文件 * * @param groupName 组名称 * @param path 文件路径 * @param fileOffset 开始位置 * @param fileSize 读取文件长度 * @param callback 文件下载回调 */ public DownloadFileCommand(String groupName, String path, long fileOffset, long fileSize, DownloadCallback<T> callback) { super();
// Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/callback/DownloadCallback.java // public interface DownloadCallback<T> { // // /** // * 注意不能直接返回入参的InputStream,因为此方法返回后将关闭原输入流<br/> // * 不能关闭inputStream? TODO 验证是否可以关闭 // * // * @param inputStream 返回数据输入流 // */ // T receive(InputStream inputStream) throws IOException; // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/request/DownloadFileRequest.java // public class DownloadFileRequest extends BaseRequest { // // /** // * 开始位置 // */ // @FastDFSColumn(index = 0) // private long fileOffset; // /** // * 读取文件长度 // */ // @FastDFSColumn(index = 1) // private long fileSize; // /** // * 组名 // */ // @FastDFSColumn(index = 2, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // /** // * 文件路径 // */ // @FastDFSColumn(index = 3, dynamicField = DynamicFieldType.allRestByte) // private String path; // // /** // * 文件下载请求 // * // * @param groupName 组名称 // * @param path 文件路径 // * @param fileOffset 开始位置 // * @param fileSize 读取文件长度 // */ // public DownloadFileRequest(String groupName, String path, long fileOffset, long fileSize) { // super(); // this.groupName = groupName; // this.fileSize = fileSize; // this.path = path; // this.fileOffset = fileOffset; // head = new ProtocolHead(CmdConstants.STORAGE_PROTO_CMD_DOWNLOAD_FILE); // } // // public long getFileOffset() { // return fileOffset; // } // // public String getGroupName() { // return groupName; // } // // public String getPath() { // return path; // } // // @Override // public long getFileSize() { // return fileSize; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/response/DownloadFileResponse.java // public class DownloadFileResponse<T> extends BaseResponse<T> { // // private DownloadCallback<T> callback; // // public DownloadFileResponse(DownloadCallback<T> callback) { // super(); // this.callback = callback; // } // // /** // * 解析反馈内容 // */ // @Override // public T decodeContent(InputStream in, Charset charset) throws IOException { // // 解析报文内容 // FastDFSInputStream input = new FastDFSInputStream(in, getContentLength()); // return callback.receive(input); // } // } // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/DownloadFileCommand.java import org.cleverframe.fastdfs.protocol.storage.callback.DownloadCallback; import org.cleverframe.fastdfs.protocol.storage.request.DownloadFileRequest; import org.cleverframe.fastdfs.protocol.storage.response.DownloadFileResponse; package org.cleverframe.fastdfs.protocol.storage; /** * 下载文件 * 作者:LiZW <br/> * 创建时间:2016/11/20 16:02 <br/> */ public class DownloadFileCommand<T> extends StorageCommand<T> { /** * 下载文件 * * @param groupName 组名称 * @param path 文件路径 * @param fileOffset 开始位置 * @param fileSize 读取文件长度 * @param callback 文件下载回调 */ public DownloadFileCommand(String groupName, String path, long fileOffset, long fileSize, DownloadCallback<T> callback) { super();
this.request = new DownloadFileRequest(groupName, path, fileOffset, fileSize);
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/protocol/storage/DownloadFileCommand.java
// Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/callback/DownloadCallback.java // public interface DownloadCallback<T> { // // /** // * 注意不能直接返回入参的InputStream,因为此方法返回后将关闭原输入流<br/> // * 不能关闭inputStream? TODO 验证是否可以关闭 // * // * @param inputStream 返回数据输入流 // */ // T receive(InputStream inputStream) throws IOException; // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/request/DownloadFileRequest.java // public class DownloadFileRequest extends BaseRequest { // // /** // * 开始位置 // */ // @FastDFSColumn(index = 0) // private long fileOffset; // /** // * 读取文件长度 // */ // @FastDFSColumn(index = 1) // private long fileSize; // /** // * 组名 // */ // @FastDFSColumn(index = 2, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // /** // * 文件路径 // */ // @FastDFSColumn(index = 3, dynamicField = DynamicFieldType.allRestByte) // private String path; // // /** // * 文件下载请求 // * // * @param groupName 组名称 // * @param path 文件路径 // * @param fileOffset 开始位置 // * @param fileSize 读取文件长度 // */ // public DownloadFileRequest(String groupName, String path, long fileOffset, long fileSize) { // super(); // this.groupName = groupName; // this.fileSize = fileSize; // this.path = path; // this.fileOffset = fileOffset; // head = new ProtocolHead(CmdConstants.STORAGE_PROTO_CMD_DOWNLOAD_FILE); // } // // public long getFileOffset() { // return fileOffset; // } // // public String getGroupName() { // return groupName; // } // // public String getPath() { // return path; // } // // @Override // public long getFileSize() { // return fileSize; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/response/DownloadFileResponse.java // public class DownloadFileResponse<T> extends BaseResponse<T> { // // private DownloadCallback<T> callback; // // public DownloadFileResponse(DownloadCallback<T> callback) { // super(); // this.callback = callback; // } // // /** // * 解析反馈内容 // */ // @Override // public T decodeContent(InputStream in, Charset charset) throws IOException { // // 解析报文内容 // FastDFSInputStream input = new FastDFSInputStream(in, getContentLength()); // return callback.receive(input); // } // }
import org.cleverframe.fastdfs.protocol.storage.callback.DownloadCallback; import org.cleverframe.fastdfs.protocol.storage.request.DownloadFileRequest; import org.cleverframe.fastdfs.protocol.storage.response.DownloadFileResponse;
package org.cleverframe.fastdfs.protocol.storage; /** * 下载文件 * 作者:LiZW <br/> * 创建时间:2016/11/20 16:02 <br/> */ public class DownloadFileCommand<T> extends StorageCommand<T> { /** * 下载文件 * * @param groupName 组名称 * @param path 文件路径 * @param fileOffset 开始位置 * @param fileSize 读取文件长度 * @param callback 文件下载回调 */ public DownloadFileCommand(String groupName, String path, long fileOffset, long fileSize, DownloadCallback<T> callback) { super(); this.request = new DownloadFileRequest(groupName, path, fileOffset, fileSize); // 输出响应
// Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/callback/DownloadCallback.java // public interface DownloadCallback<T> { // // /** // * 注意不能直接返回入参的InputStream,因为此方法返回后将关闭原输入流<br/> // * 不能关闭inputStream? TODO 验证是否可以关闭 // * // * @param inputStream 返回数据输入流 // */ // T receive(InputStream inputStream) throws IOException; // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/request/DownloadFileRequest.java // public class DownloadFileRequest extends BaseRequest { // // /** // * 开始位置 // */ // @FastDFSColumn(index = 0) // private long fileOffset; // /** // * 读取文件长度 // */ // @FastDFSColumn(index = 1) // private long fileSize; // /** // * 组名 // */ // @FastDFSColumn(index = 2, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // /** // * 文件路径 // */ // @FastDFSColumn(index = 3, dynamicField = DynamicFieldType.allRestByte) // private String path; // // /** // * 文件下载请求 // * // * @param groupName 组名称 // * @param path 文件路径 // * @param fileOffset 开始位置 // * @param fileSize 读取文件长度 // */ // public DownloadFileRequest(String groupName, String path, long fileOffset, long fileSize) { // super(); // this.groupName = groupName; // this.fileSize = fileSize; // this.path = path; // this.fileOffset = fileOffset; // head = new ProtocolHead(CmdConstants.STORAGE_PROTO_CMD_DOWNLOAD_FILE); // } // // public long getFileOffset() { // return fileOffset; // } // // public String getGroupName() { // return groupName; // } // // public String getPath() { // return path; // } // // @Override // public long getFileSize() { // return fileSize; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/response/DownloadFileResponse.java // public class DownloadFileResponse<T> extends BaseResponse<T> { // // private DownloadCallback<T> callback; // // public DownloadFileResponse(DownloadCallback<T> callback) { // super(); // this.callback = callback; // } // // /** // * 解析反馈内容 // */ // @Override // public T decodeContent(InputStream in, Charset charset) throws IOException { // // 解析报文内容 // FastDFSInputStream input = new FastDFSInputStream(in, getContentLength()); // return callback.receive(input); // } // } // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/DownloadFileCommand.java import org.cleverframe.fastdfs.protocol.storage.callback.DownloadCallback; import org.cleverframe.fastdfs.protocol.storage.request.DownloadFileRequest; import org.cleverframe.fastdfs.protocol.storage.response.DownloadFileResponse; package org.cleverframe.fastdfs.protocol.storage; /** * 下载文件 * 作者:LiZW <br/> * 创建时间:2016/11/20 16:02 <br/> */ public class DownloadFileCommand<T> extends StorageCommand<T> { /** * 下载文件 * * @param groupName 组名称 * @param path 文件路径 * @param fileOffset 开始位置 * @param fileSize 读取文件长度 * @param callback 文件下载回调 */ public DownloadFileCommand(String groupName, String path, long fileOffset, long fileSize, DownloadCallback<T> callback) { super(); this.request = new DownloadFileRequest(groupName, path, fileOffset, fileSize); // 输出响应
this.response = new DownloadFileResponse<T>(callback);
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/exception/FastDfsServerException.java
// Path: src/main/java/org/cleverframe/fastdfs/constant/ErrorCodeConstants.java // public final class ErrorCodeConstants { // public static final byte SUCCESS = 0; // public static final byte ERR_NO_ENOENT = 2; // public static final byte ERR_NO_EIO = 5; // public static final byte ERR_NO_EBUSY = 16; // public static final byte ERR_NO_EINVAL = 22; // public static final byte ERR_NO_ENOSPC = 28; // public static final byte ERR_NO_CONNREFUSED = 61; // public static final byte ERR_NO_EALREADY = 114; // }
import org.cleverframe.fastdfs.constant.ErrorCodeConstants; import java.util.Collections; import java.util.HashMap; import java.util.Map;
package org.cleverframe.fastdfs.exception; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 1:22 <br/> */ public class FastDfsServerException extends FastDfsException { /** * 错误对照表 */ private static final Map<Integer, String> CODE_MESSAGE_MAPPING; static { Map<Integer, String> mapping = new HashMap<Integer, String>();
// Path: src/main/java/org/cleverframe/fastdfs/constant/ErrorCodeConstants.java // public final class ErrorCodeConstants { // public static final byte SUCCESS = 0; // public static final byte ERR_NO_ENOENT = 2; // public static final byte ERR_NO_EIO = 5; // public static final byte ERR_NO_EBUSY = 16; // public static final byte ERR_NO_EINVAL = 22; // public static final byte ERR_NO_ENOSPC = 28; // public static final byte ERR_NO_CONNREFUSED = 61; // public static final byte ERR_NO_EALREADY = 114; // } // Path: src/main/java/org/cleverframe/fastdfs/exception/FastDfsServerException.java import org.cleverframe.fastdfs.constant.ErrorCodeConstants; import java.util.Collections; import java.util.HashMap; import java.util.Map; package org.cleverframe.fastdfs.exception; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 1:22 <br/> */ public class FastDfsServerException extends FastDfsException { /** * 错误对照表 */ private static final Map<Integer, String> CODE_MESSAGE_MAPPING; static { Map<Integer, String> mapping = new HashMap<Integer, String>();
mapping.put((int) ErrorCodeConstants.ERR_NO_ENOENT, "找不到节点或文件");
Lzw2016/fastdfs-java-client
src/test/java/org/cleverframe/fastdfs/protocol/tracker/DeleteStorageCommandTest.java
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // }
import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:46 <br/> */ public class DeleteStorageCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class); @Test public void test01() {
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // } // Path: src/test/java/org/cleverframe/fastdfs/protocol/tracker/DeleteStorageCommandTest.java import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:46 <br/> */ public class DeleteStorageCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class); @Test public void test01() {
Connection connection = GetTrackerConnection.getDefaultConnection();
Lzw2016/fastdfs-java-client
src/test/java/org/cleverframe/fastdfs/protocol/tracker/DeleteStorageCommandTest.java
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // }
import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:46 <br/> */ public class DeleteStorageCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class); @Test public void test01() {
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // } // Path: src/test/java/org/cleverframe/fastdfs/protocol/tracker/DeleteStorageCommandTest.java import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:46 <br/> */ public class DeleteStorageCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class); @Test public void test01() {
Connection connection = GetTrackerConnection.getDefaultConnection();
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/protocol/storage/callback/DownloadFileWriter.java
// Path: src/main/java/org/cleverframe/fastdfs/utils/IOUtils.java // public class IOUtils { // /** // * 日志 // */ // private static final Logger logger = LoggerFactory.getLogger(IOUtils.class); // // private static final int EOF = -1; // // private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; // // public static void closeQuietly(final Closeable closeable) { // try { // if (closeable != null) { // closeable.close(); // } // } catch (final IOException ioe) { // logger.error("数据流关闭异常", ioe); // } // } // // public static void closeQuietly(final Closeable... closeables) { // if (closeables == null) { // return; // } // for (final Closeable closeable : closeables) { // closeQuietly(closeable); // } // } // // private static long copyLarge(final InputStream input, final OutputStream output, final byte[] buffer) // throws IOException { // long count = 0; // int n; // while (EOF != (n = input.read(buffer))) { // output.write(buffer, 0, n); // count += n; // } // return count; // } // // private static long copyLarge(final InputStream input, final OutputStream output) // throws IOException { // return copy(input, output, DEFAULT_BUFFER_SIZE); // } // // private static long copy(final InputStream input, final OutputStream output, final int bufferSize) // throws IOException { // return copyLarge(input, output, new byte[bufferSize]); // } // // public static int copy(final InputStream input, final OutputStream output) throws IOException { // final long count = copyLarge(input, output); // if (count > Integer.MAX_VALUE) { // return -1; // } // return (int) count; // } // // public static byte[] toByteArray(final InputStream input) throws IOException { // final ByteArrayOutputStream output = new ByteArrayOutputStream(); // copy(input, output); // return output.toByteArray(); // } // }
import org.cleverframe.fastdfs.utils.IOUtils; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream;
package org.cleverframe.fastdfs.protocol.storage.callback; /** * 直接把文件下载到本地文件系统 * 作者:LiZW <br/> * 创建时间:2016/11/20 15:57 <br/> */ public class DownloadFileWriter implements DownloadCallback<String> { /** * 文件名称 */ private String fileName; public DownloadFileWriter(String fileName) { this.fileName = fileName; } /** * 文件下载处理 * * @return 返回文件名称 */ @Override public String receive(InputStream inputStream) throws IOException { FileOutputStream out = null; InputStream in = null; try { out = new FileOutputStream(fileName); in = new BufferedInputStream(inputStream); // 通过ioutil 对接输入输出流,实现文件下载
// Path: src/main/java/org/cleverframe/fastdfs/utils/IOUtils.java // public class IOUtils { // /** // * 日志 // */ // private static final Logger logger = LoggerFactory.getLogger(IOUtils.class); // // private static final int EOF = -1; // // private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; // // public static void closeQuietly(final Closeable closeable) { // try { // if (closeable != null) { // closeable.close(); // } // } catch (final IOException ioe) { // logger.error("数据流关闭异常", ioe); // } // } // // public static void closeQuietly(final Closeable... closeables) { // if (closeables == null) { // return; // } // for (final Closeable closeable : closeables) { // closeQuietly(closeable); // } // } // // private static long copyLarge(final InputStream input, final OutputStream output, final byte[] buffer) // throws IOException { // long count = 0; // int n; // while (EOF != (n = input.read(buffer))) { // output.write(buffer, 0, n); // count += n; // } // return count; // } // // private static long copyLarge(final InputStream input, final OutputStream output) // throws IOException { // return copy(input, output, DEFAULT_BUFFER_SIZE); // } // // private static long copy(final InputStream input, final OutputStream output, final int bufferSize) // throws IOException { // return copyLarge(input, output, new byte[bufferSize]); // } // // public static int copy(final InputStream input, final OutputStream output) throws IOException { // final long count = copyLarge(input, output); // if (count > Integer.MAX_VALUE) { // return -1; // } // return (int) count; // } // // public static byte[] toByteArray(final InputStream input) throws IOException { // final ByteArrayOutputStream output = new ByteArrayOutputStream(); // copy(input, output); // return output.toByteArray(); // } // } // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/callback/DownloadFileWriter.java import org.cleverframe.fastdfs.utils.IOUtils; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; package org.cleverframe.fastdfs.protocol.storage.callback; /** * 直接把文件下载到本地文件系统 * 作者:LiZW <br/> * 创建时间:2016/11/20 15:57 <br/> */ public class DownloadFileWriter implements DownloadCallback<String> { /** * 文件名称 */ private String fileName; public DownloadFileWriter(String fileName) { this.fileName = fileName; } /** * 文件下载处理 * * @return 返回文件名称 */ @Override public String receive(InputStream inputStream) throws IOException { FileOutputStream out = null; InputStream in = null; try { out = new FileOutputStream(fileName); in = new BufferedInputStream(inputStream); // 通过ioutil 对接输入输出流,实现文件下载
IOUtils.copy(in, out);
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/model/StorageState.java
// Path: src/main/java/org/cleverframe/fastdfs/constant/OtherConstants.java // public final class OtherConstants { // /** // * for overwrite all old metadata // */ // public static final byte STORAGE_SET_METADATA_FLAG_OVERWRITE = 'O'; // // /** // * for replace, insert when the meta item not exist, otherwise update it // */ // public static final byte STORAGE_SET_METADATA_FLAG_MERGE = 'M'; // public static final int FDFS_PROTO_PKG_LEN_SIZE = 8; // public static final int FDFS_PROTO_CMD_SIZE = 1; // public static final int FDFS_PROTO_CONNECTION_LEN = 4; // public static final int FDFS_GROUP_NAME_MAX_LEN = 16; // public static final int FDFS_IPADDR_SIZE = 16; // public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128; // public static final int FDFS_VERSION_SIZE = 6; // public static final int FDFS_STORAGE_ID_MAX_SIZE = 16; // // public static final String FDFS_RECORD_SEPERATOR = "\u0001"; // public static final String FDFS_FIELD_SEPERATOR = "\u0002"; // // public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE; // public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中命令位置 // */ // public static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中状态码位置 // */ // public static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1; // // public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6; // public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16; // public static final byte FDFS_FILE_PATH_LEN = 10; // public static final byte FDFS_FILENAME_BASE64_LENGTH = 27; // public static final byte FDFS_TRUNK_FILE_INFO_LEN = 16; // // public static final long INFINITE_FILE_SIZE = 256 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long APPENDER_FILE_SIZE = INFINITE_FILE_SIZE; // public static final long TRUNK_FILE_MARK_SIZE = 512 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long NORMAL_LOGIC_FILENAME_LENGTH = FDFS_FILE_PATH_LEN + FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1; // public static final long TRUNK_LOGIC_FILENAME_LENGTH = NORMAL_LOGIC_FILENAME_LENGTH + FDFS_TRUNK_FILE_INFO_LEN; // }
import org.cleverframe.fastdfs.constant.OtherConstants; import org.cleverframe.fastdfs.mapper.FastDFSColumn; import java.io.Serializable; import java.util.Date;
package org.cleverframe.fastdfs.model; /** * FastDFS中storage节点的状态信息 * <p> * 作者:LiZW <br/> * 创建时间:2016/11/20 11:24 <br/> */ public class StorageState implements Serializable { /** * 状态代码 */ @FastDFSColumn(index = 0) private byte status; /** * id */
// Path: src/main/java/org/cleverframe/fastdfs/constant/OtherConstants.java // public final class OtherConstants { // /** // * for overwrite all old metadata // */ // public static final byte STORAGE_SET_METADATA_FLAG_OVERWRITE = 'O'; // // /** // * for replace, insert when the meta item not exist, otherwise update it // */ // public static final byte STORAGE_SET_METADATA_FLAG_MERGE = 'M'; // public static final int FDFS_PROTO_PKG_LEN_SIZE = 8; // public static final int FDFS_PROTO_CMD_SIZE = 1; // public static final int FDFS_PROTO_CONNECTION_LEN = 4; // public static final int FDFS_GROUP_NAME_MAX_LEN = 16; // public static final int FDFS_IPADDR_SIZE = 16; // public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128; // public static final int FDFS_VERSION_SIZE = 6; // public static final int FDFS_STORAGE_ID_MAX_SIZE = 16; // // public static final String FDFS_RECORD_SEPERATOR = "\u0001"; // public static final String FDFS_FIELD_SEPERATOR = "\u0002"; // // public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE; // public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中命令位置 // */ // public static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中状态码位置 // */ // public static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1; // // public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6; // public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16; // public static final byte FDFS_FILE_PATH_LEN = 10; // public static final byte FDFS_FILENAME_BASE64_LENGTH = 27; // public static final byte FDFS_TRUNK_FILE_INFO_LEN = 16; // // public static final long INFINITE_FILE_SIZE = 256 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long APPENDER_FILE_SIZE = INFINITE_FILE_SIZE; // public static final long TRUNK_FILE_MARK_SIZE = 512 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long NORMAL_LOGIC_FILENAME_LENGTH = FDFS_FILE_PATH_LEN + FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1; // public static final long TRUNK_LOGIC_FILENAME_LENGTH = NORMAL_LOGIC_FILENAME_LENGTH + FDFS_TRUNK_FILE_INFO_LEN; // } // Path: src/main/java/org/cleverframe/fastdfs/model/StorageState.java import org.cleverframe.fastdfs.constant.OtherConstants; import org.cleverframe.fastdfs.mapper.FastDFSColumn; import java.io.Serializable; import java.util.Date; package org.cleverframe.fastdfs.model; /** * FastDFS中storage节点的状态信息 * <p> * 作者:LiZW <br/> * 创建时间:2016/11/20 11:24 <br/> */ public class StorageState implements Serializable { /** * 状态代码 */ @FastDFSColumn(index = 0) private byte status; /** * id */
@FastDFSColumn(index = 1, max = OtherConstants.FDFS_STORAGE_ID_MAX_SIZE)
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/utils/MetadataMapperUtils.java
// Path: src/main/java/org/cleverframe/fastdfs/constant/OtherConstants.java // public final class OtherConstants { // /** // * for overwrite all old metadata // */ // public static final byte STORAGE_SET_METADATA_FLAG_OVERWRITE = 'O'; // // /** // * for replace, insert when the meta item not exist, otherwise update it // */ // public static final byte STORAGE_SET_METADATA_FLAG_MERGE = 'M'; // public static final int FDFS_PROTO_PKG_LEN_SIZE = 8; // public static final int FDFS_PROTO_CMD_SIZE = 1; // public static final int FDFS_PROTO_CONNECTION_LEN = 4; // public static final int FDFS_GROUP_NAME_MAX_LEN = 16; // public static final int FDFS_IPADDR_SIZE = 16; // public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128; // public static final int FDFS_VERSION_SIZE = 6; // public static final int FDFS_STORAGE_ID_MAX_SIZE = 16; // // public static final String FDFS_RECORD_SEPERATOR = "\u0001"; // public static final String FDFS_FIELD_SEPERATOR = "\u0002"; // // public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE; // public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中命令位置 // */ // public static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中状态码位置 // */ // public static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1; // // public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6; // public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16; // public static final byte FDFS_FILE_PATH_LEN = 10; // public static final byte FDFS_FILENAME_BASE64_LENGTH = 27; // public static final byte FDFS_TRUNK_FILE_INFO_LEN = 16; // // public static final long INFINITE_FILE_SIZE = 256 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long APPENDER_FILE_SIZE = INFINITE_FILE_SIZE; // public static final long TRUNK_FILE_MARK_SIZE = 512 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long NORMAL_LOGIC_FILENAME_LENGTH = FDFS_FILE_PATH_LEN + FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1; // public static final long TRUNK_LOGIC_FILENAME_LENGTH = NORMAL_LOGIC_FILENAME_LENGTH + FDFS_TRUNK_FILE_INFO_LEN; // } // // Path: src/main/java/org/cleverframe/fastdfs/model/MateData.java // public class MateData implements Serializable { // // private String name; // // private String value; // // public MateData() { // } // // public MateData(String name) { // this.name = name; // } // // public MateData(String name, String value) { // this.name = name; // this.value = value; // } // // public String getName() { // return this.name; // } // // public String getValue() { // return this.value; // } // // public void setName(String name) { // this.name = name; // } // // public void setValue(String value) { // this.value = value; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((value == null) ? 0 : value.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // MateData other = (MateData) obj; // if (name == null) { // if (other.name != null) // return false; // } else if (!name.equals(other.name)) // return false; // if (value == null) { // if (other.value != null) // return false; // } else if (!value.equals(other.value)) // return false; // return true; // } // // @Override // public String toString() { // return "NameValuePair [name=" + name + ", value=" + value + "]"; // } // }
import org.cleverframe.fastdfs.constant.OtherConstants; import org.cleverframe.fastdfs.model.MateData; import java.nio.charset.Charset; import java.util.HashSet; import java.util.Set;
package org.cleverframe.fastdfs.utils; /** * 文件标签(元数据)映射对象 * 作者:LiZW <br/> * 创建时间:2016/11/20 1:52 <br/> */ public class MetadataMapperUtils { private MetadataMapperUtils() { } /** * 将元数据映射为byte */
// Path: src/main/java/org/cleverframe/fastdfs/constant/OtherConstants.java // public final class OtherConstants { // /** // * for overwrite all old metadata // */ // public static final byte STORAGE_SET_METADATA_FLAG_OVERWRITE = 'O'; // // /** // * for replace, insert when the meta item not exist, otherwise update it // */ // public static final byte STORAGE_SET_METADATA_FLAG_MERGE = 'M'; // public static final int FDFS_PROTO_PKG_LEN_SIZE = 8; // public static final int FDFS_PROTO_CMD_SIZE = 1; // public static final int FDFS_PROTO_CONNECTION_LEN = 4; // public static final int FDFS_GROUP_NAME_MAX_LEN = 16; // public static final int FDFS_IPADDR_SIZE = 16; // public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128; // public static final int FDFS_VERSION_SIZE = 6; // public static final int FDFS_STORAGE_ID_MAX_SIZE = 16; // // public static final String FDFS_RECORD_SEPERATOR = "\u0001"; // public static final String FDFS_FIELD_SEPERATOR = "\u0002"; // // public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE; // public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中命令位置 // */ // public static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中状态码位置 // */ // public static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1; // // public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6; // public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16; // public static final byte FDFS_FILE_PATH_LEN = 10; // public static final byte FDFS_FILENAME_BASE64_LENGTH = 27; // public static final byte FDFS_TRUNK_FILE_INFO_LEN = 16; // // public static final long INFINITE_FILE_SIZE = 256 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long APPENDER_FILE_SIZE = INFINITE_FILE_SIZE; // public static final long TRUNK_FILE_MARK_SIZE = 512 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long NORMAL_LOGIC_FILENAME_LENGTH = FDFS_FILE_PATH_LEN + FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1; // public static final long TRUNK_LOGIC_FILENAME_LENGTH = NORMAL_LOGIC_FILENAME_LENGTH + FDFS_TRUNK_FILE_INFO_LEN; // } // // Path: src/main/java/org/cleverframe/fastdfs/model/MateData.java // public class MateData implements Serializable { // // private String name; // // private String value; // // public MateData() { // } // // public MateData(String name) { // this.name = name; // } // // public MateData(String name, String value) { // this.name = name; // this.value = value; // } // // public String getName() { // return this.name; // } // // public String getValue() { // return this.value; // } // // public void setName(String name) { // this.name = name; // } // // public void setValue(String value) { // this.value = value; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((value == null) ? 0 : value.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // MateData other = (MateData) obj; // if (name == null) { // if (other.name != null) // return false; // } else if (!name.equals(other.name)) // return false; // if (value == null) { // if (other.value != null) // return false; // } else if (!value.equals(other.value)) // return false; // return true; // } // // @Override // public String toString() { // return "NameValuePair [name=" + name + ", value=" + value + "]"; // } // } // Path: src/main/java/org/cleverframe/fastdfs/utils/MetadataMapperUtils.java import org.cleverframe.fastdfs.constant.OtherConstants; import org.cleverframe.fastdfs.model.MateData; import java.nio.charset.Charset; import java.util.HashSet; import java.util.Set; package org.cleverframe.fastdfs.utils; /** * 文件标签(元数据)映射对象 * 作者:LiZW <br/> * 创建时间:2016/11/20 1:52 <br/> */ public class MetadataMapperUtils { private MetadataMapperUtils() { } /** * 将元数据映射为byte */
public static byte[] toByte(Set<MateData> metadataSet, Charset charset) {
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/utils/MetadataMapperUtils.java
// Path: src/main/java/org/cleverframe/fastdfs/constant/OtherConstants.java // public final class OtherConstants { // /** // * for overwrite all old metadata // */ // public static final byte STORAGE_SET_METADATA_FLAG_OVERWRITE = 'O'; // // /** // * for replace, insert when the meta item not exist, otherwise update it // */ // public static final byte STORAGE_SET_METADATA_FLAG_MERGE = 'M'; // public static final int FDFS_PROTO_PKG_LEN_SIZE = 8; // public static final int FDFS_PROTO_CMD_SIZE = 1; // public static final int FDFS_PROTO_CONNECTION_LEN = 4; // public static final int FDFS_GROUP_NAME_MAX_LEN = 16; // public static final int FDFS_IPADDR_SIZE = 16; // public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128; // public static final int FDFS_VERSION_SIZE = 6; // public static final int FDFS_STORAGE_ID_MAX_SIZE = 16; // // public static final String FDFS_RECORD_SEPERATOR = "\u0001"; // public static final String FDFS_FIELD_SEPERATOR = "\u0002"; // // public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE; // public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中命令位置 // */ // public static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中状态码位置 // */ // public static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1; // // public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6; // public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16; // public static final byte FDFS_FILE_PATH_LEN = 10; // public static final byte FDFS_FILENAME_BASE64_LENGTH = 27; // public static final byte FDFS_TRUNK_FILE_INFO_LEN = 16; // // public static final long INFINITE_FILE_SIZE = 256 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long APPENDER_FILE_SIZE = INFINITE_FILE_SIZE; // public static final long TRUNK_FILE_MARK_SIZE = 512 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long NORMAL_LOGIC_FILENAME_LENGTH = FDFS_FILE_PATH_LEN + FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1; // public static final long TRUNK_LOGIC_FILENAME_LENGTH = NORMAL_LOGIC_FILENAME_LENGTH + FDFS_TRUNK_FILE_INFO_LEN; // } // // Path: src/main/java/org/cleverframe/fastdfs/model/MateData.java // public class MateData implements Serializable { // // private String name; // // private String value; // // public MateData() { // } // // public MateData(String name) { // this.name = name; // } // // public MateData(String name, String value) { // this.name = name; // this.value = value; // } // // public String getName() { // return this.name; // } // // public String getValue() { // return this.value; // } // // public void setName(String name) { // this.name = name; // } // // public void setValue(String value) { // this.value = value; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((value == null) ? 0 : value.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // MateData other = (MateData) obj; // if (name == null) { // if (other.name != null) // return false; // } else if (!name.equals(other.name)) // return false; // if (value == null) { // if (other.value != null) // return false; // } else if (!value.equals(other.value)) // return false; // return true; // } // // @Override // public String toString() { // return "NameValuePair [name=" + name + ", value=" + value + "]"; // } // }
import org.cleverframe.fastdfs.constant.OtherConstants; import org.cleverframe.fastdfs.model.MateData; import java.nio.charset.Charset; import java.util.HashSet; import java.util.Set;
package org.cleverframe.fastdfs.utils; /** * 文件标签(元数据)映射对象 * 作者:LiZW <br/> * 创建时间:2016/11/20 1:52 <br/> */ public class MetadataMapperUtils { private MetadataMapperUtils() { } /** * 将元数据映射为byte */ public static byte[] toByte(Set<MateData> metadataSet, Charset charset) { if (null == metadataSet || metadataSet.isEmpty()) { return new byte[0]; } StringBuilder sb = new StringBuilder(32 * metadataSet.size()); for (MateData md : metadataSet) {
// Path: src/main/java/org/cleverframe/fastdfs/constant/OtherConstants.java // public final class OtherConstants { // /** // * for overwrite all old metadata // */ // public static final byte STORAGE_SET_METADATA_FLAG_OVERWRITE = 'O'; // // /** // * for replace, insert when the meta item not exist, otherwise update it // */ // public static final byte STORAGE_SET_METADATA_FLAG_MERGE = 'M'; // public static final int FDFS_PROTO_PKG_LEN_SIZE = 8; // public static final int FDFS_PROTO_CMD_SIZE = 1; // public static final int FDFS_PROTO_CONNECTION_LEN = 4; // public static final int FDFS_GROUP_NAME_MAX_LEN = 16; // public static final int FDFS_IPADDR_SIZE = 16; // public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128; // public static final int FDFS_VERSION_SIZE = 6; // public static final int FDFS_STORAGE_ID_MAX_SIZE = 16; // // public static final String FDFS_RECORD_SEPERATOR = "\u0001"; // public static final String FDFS_FIELD_SEPERATOR = "\u0002"; // // public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE; // public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中命令位置 // */ // public static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中状态码位置 // */ // public static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1; // // public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6; // public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16; // public static final byte FDFS_FILE_PATH_LEN = 10; // public static final byte FDFS_FILENAME_BASE64_LENGTH = 27; // public static final byte FDFS_TRUNK_FILE_INFO_LEN = 16; // // public static final long INFINITE_FILE_SIZE = 256 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long APPENDER_FILE_SIZE = INFINITE_FILE_SIZE; // public static final long TRUNK_FILE_MARK_SIZE = 512 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long NORMAL_LOGIC_FILENAME_LENGTH = FDFS_FILE_PATH_LEN + FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1; // public static final long TRUNK_LOGIC_FILENAME_LENGTH = NORMAL_LOGIC_FILENAME_LENGTH + FDFS_TRUNK_FILE_INFO_LEN; // } // // Path: src/main/java/org/cleverframe/fastdfs/model/MateData.java // public class MateData implements Serializable { // // private String name; // // private String value; // // public MateData() { // } // // public MateData(String name) { // this.name = name; // } // // public MateData(String name, String value) { // this.name = name; // this.value = value; // } // // public String getName() { // return this.name; // } // // public String getValue() { // return this.value; // } // // public void setName(String name) { // this.name = name; // } // // public void setValue(String value) { // this.value = value; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((value == null) ? 0 : value.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // MateData other = (MateData) obj; // if (name == null) { // if (other.name != null) // return false; // } else if (!name.equals(other.name)) // return false; // if (value == null) { // if (other.value != null) // return false; // } else if (!value.equals(other.value)) // return false; // return true; // } // // @Override // public String toString() { // return "NameValuePair [name=" + name + ", value=" + value + "]"; // } // } // Path: src/main/java/org/cleverframe/fastdfs/utils/MetadataMapperUtils.java import org.cleverframe.fastdfs.constant.OtherConstants; import org.cleverframe.fastdfs.model.MateData; import java.nio.charset.Charset; import java.util.HashSet; import java.util.Set; package org.cleverframe.fastdfs.utils; /** * 文件标签(元数据)映射对象 * 作者:LiZW <br/> * 创建时间:2016/11/20 1:52 <br/> */ public class MetadataMapperUtils { private MetadataMapperUtils() { } /** * 将元数据映射为byte */ public static byte[] toByte(Set<MateData> metadataSet, Charset charset) { if (null == metadataSet || metadataSet.isEmpty()) { return new byte[0]; } StringBuilder sb = new StringBuilder(32 * metadataSet.size()); for (MateData md : metadataSet) {
sb.append(md.getName()).append(OtherConstants.FDFS_FIELD_SEPERATOR).append(md.getValue());
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/protocol/storage/callback/DownloadByteArray.java
// Path: src/main/java/org/cleverframe/fastdfs/utils/IOUtils.java // public class IOUtils { // /** // * 日志 // */ // private static final Logger logger = LoggerFactory.getLogger(IOUtils.class); // // private static final int EOF = -1; // // private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; // // public static void closeQuietly(final Closeable closeable) { // try { // if (closeable != null) { // closeable.close(); // } // } catch (final IOException ioe) { // logger.error("数据流关闭异常", ioe); // } // } // // public static void closeQuietly(final Closeable... closeables) { // if (closeables == null) { // return; // } // for (final Closeable closeable : closeables) { // closeQuietly(closeable); // } // } // // private static long copyLarge(final InputStream input, final OutputStream output, final byte[] buffer) // throws IOException { // long count = 0; // int n; // while (EOF != (n = input.read(buffer))) { // output.write(buffer, 0, n); // count += n; // } // return count; // } // // private static long copyLarge(final InputStream input, final OutputStream output) // throws IOException { // return copy(input, output, DEFAULT_BUFFER_SIZE); // } // // private static long copy(final InputStream input, final OutputStream output, final int bufferSize) // throws IOException { // return copyLarge(input, output, new byte[bufferSize]); // } // // public static int copy(final InputStream input, final OutputStream output) throws IOException { // final long count = copyLarge(input, output); // if (count > Integer.MAX_VALUE) { // return -1; // } // return (int) count; // } // // public static byte[] toByteArray(final InputStream input) throws IOException { // final ByteArrayOutputStream output = new ByteArrayOutputStream(); // copy(input, output); // return output.toByteArray(); // } // }
import org.cleverframe.fastdfs.utils.IOUtils; import java.io.IOException; import java.io.InputStream;
package org.cleverframe.fastdfs.protocol.storage.callback; /** * 直接返回Byte[]数据 * 作者:LiZW <br/> * 创建时间:2016/11/20 15:56 <br/> */ public class DownloadByteArray implements DownloadCallback<byte[]> { @Override public byte[] receive(InputStream inputStream) throws IOException {
// Path: src/main/java/org/cleverframe/fastdfs/utils/IOUtils.java // public class IOUtils { // /** // * 日志 // */ // private static final Logger logger = LoggerFactory.getLogger(IOUtils.class); // // private static final int EOF = -1; // // private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; // // public static void closeQuietly(final Closeable closeable) { // try { // if (closeable != null) { // closeable.close(); // } // } catch (final IOException ioe) { // logger.error("数据流关闭异常", ioe); // } // } // // public static void closeQuietly(final Closeable... closeables) { // if (closeables == null) { // return; // } // for (final Closeable closeable : closeables) { // closeQuietly(closeable); // } // } // // private static long copyLarge(final InputStream input, final OutputStream output, final byte[] buffer) // throws IOException { // long count = 0; // int n; // while (EOF != (n = input.read(buffer))) { // output.write(buffer, 0, n); // count += n; // } // return count; // } // // private static long copyLarge(final InputStream input, final OutputStream output) // throws IOException { // return copy(input, output, DEFAULT_BUFFER_SIZE); // } // // private static long copy(final InputStream input, final OutputStream output, final int bufferSize) // throws IOException { // return copyLarge(input, output, new byte[bufferSize]); // } // // public static int copy(final InputStream input, final OutputStream output) throws IOException { // final long count = copyLarge(input, output); // if (count > Integer.MAX_VALUE) { // return -1; // } // return (int) count; // } // // public static byte[] toByteArray(final InputStream input) throws IOException { // final ByteArrayOutputStream output = new ByteArrayOutputStream(); // copy(input, output); // return output.toByteArray(); // } // } // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/callback/DownloadByteArray.java import org.cleverframe.fastdfs.utils.IOUtils; import java.io.IOException; import java.io.InputStream; package org.cleverframe.fastdfs.protocol.storage.callback; /** * 直接返回Byte[]数据 * 作者:LiZW <br/> * 创建时间:2016/11/20 15:56 <br/> */ public class DownloadByteArray implements DownloadCallback<byte[]> { @Override public byte[] receive(InputStream inputStream) throws IOException {
return IOUtils.toByteArray(inputStream);
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/model/FileInfo.java
// Path: src/main/java/org/cleverframe/fastdfs/constant/OtherConstants.java // public final class OtherConstants { // /** // * for overwrite all old metadata // */ // public static final byte STORAGE_SET_METADATA_FLAG_OVERWRITE = 'O'; // // /** // * for replace, insert when the meta item not exist, otherwise update it // */ // public static final byte STORAGE_SET_METADATA_FLAG_MERGE = 'M'; // public static final int FDFS_PROTO_PKG_LEN_SIZE = 8; // public static final int FDFS_PROTO_CMD_SIZE = 1; // public static final int FDFS_PROTO_CONNECTION_LEN = 4; // public static final int FDFS_GROUP_NAME_MAX_LEN = 16; // public static final int FDFS_IPADDR_SIZE = 16; // public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128; // public static final int FDFS_VERSION_SIZE = 6; // public static final int FDFS_STORAGE_ID_MAX_SIZE = 16; // // public static final String FDFS_RECORD_SEPERATOR = "\u0001"; // public static final String FDFS_FIELD_SEPERATOR = "\u0002"; // // public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE; // public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中命令位置 // */ // public static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中状态码位置 // */ // public static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1; // // public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6; // public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16; // public static final byte FDFS_FILE_PATH_LEN = 10; // public static final byte FDFS_FILENAME_BASE64_LENGTH = 27; // public static final byte FDFS_TRUNK_FILE_INFO_LEN = 16; // // public static final long INFINITE_FILE_SIZE = 256 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long APPENDER_FILE_SIZE = INFINITE_FILE_SIZE; // public static final long TRUNK_FILE_MARK_SIZE = 512 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long NORMAL_LOGIC_FILENAME_LENGTH = FDFS_FILE_PATH_LEN + FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1; // public static final long TRUNK_LOGIC_FILENAME_LENGTH = NORMAL_LOGIC_FILENAME_LENGTH + FDFS_TRUNK_FILE_INFO_LEN; // }
import org.cleverframe.fastdfs.constant.OtherConstants; import org.cleverframe.fastdfs.mapper.FastDFSColumn; import java.io.Serializable; import java.text.SimpleDateFormat;
package org.cleverframe.fastdfs.model; /** * 上传文件信息 * 作者:LiZW <br/> * 创建时间:2016/11/20 11:05 <br/> */ public class FileInfo implements Serializable{ /** * 长度 */ @FastDFSColumn(index = 0) private long fileSize; /** * 创建时间 */ @FastDFSColumn(index = 1) private int createTime; /** * 校验码 */ @FastDFSColumn(index = 2) private int crc32; /** * ip地址 */
// Path: src/main/java/org/cleverframe/fastdfs/constant/OtherConstants.java // public final class OtherConstants { // /** // * for overwrite all old metadata // */ // public static final byte STORAGE_SET_METADATA_FLAG_OVERWRITE = 'O'; // // /** // * for replace, insert when the meta item not exist, otherwise update it // */ // public static final byte STORAGE_SET_METADATA_FLAG_MERGE = 'M'; // public static final int FDFS_PROTO_PKG_LEN_SIZE = 8; // public static final int FDFS_PROTO_CMD_SIZE = 1; // public static final int FDFS_PROTO_CONNECTION_LEN = 4; // public static final int FDFS_GROUP_NAME_MAX_LEN = 16; // public static final int FDFS_IPADDR_SIZE = 16; // public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128; // public static final int FDFS_VERSION_SIZE = 6; // public static final int FDFS_STORAGE_ID_MAX_SIZE = 16; // // public static final String FDFS_RECORD_SEPERATOR = "\u0001"; // public static final String FDFS_FIELD_SEPERATOR = "\u0002"; // // public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE; // public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN + FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中命令位置 // */ // public static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE; // // /** // * 报文头中状态码位置 // */ // public static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1; // // public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6; // public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16; // public static final byte FDFS_FILE_PATH_LEN = 10; // public static final byte FDFS_FILENAME_BASE64_LENGTH = 27; // public static final byte FDFS_TRUNK_FILE_INFO_LEN = 16; // // public static final long INFINITE_FILE_SIZE = 256 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long APPENDER_FILE_SIZE = INFINITE_FILE_SIZE; // public static final long TRUNK_FILE_MARK_SIZE = 512 * 1024L * 1024 * 1024 * 1024 * 1024L; // public static final long NORMAL_LOGIC_FILENAME_LENGTH = FDFS_FILE_PATH_LEN + FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1; // public static final long TRUNK_LOGIC_FILENAME_LENGTH = NORMAL_LOGIC_FILENAME_LENGTH + FDFS_TRUNK_FILE_INFO_LEN; // } // Path: src/main/java/org/cleverframe/fastdfs/model/FileInfo.java import org.cleverframe.fastdfs.constant.OtherConstants; import org.cleverframe.fastdfs.mapper.FastDFSColumn; import java.io.Serializable; import java.text.SimpleDateFormat; package org.cleverframe.fastdfs.model; /** * 上传文件信息 * 作者:LiZW <br/> * 创建时间:2016/11/20 11:05 <br/> */ public class FileInfo implements Serializable{ /** * 长度 */ @FastDFSColumn(index = 0) private long fileSize; /** * 创建时间 */ @FastDFSColumn(index = 1) private int createTime; /** * 校验码 */ @FastDFSColumn(index = 2) private int crc32; /** * ip地址 */
@FastDFSColumn(index = 3, max = OtherConstants.FDFS_IPADDR_SIZE)
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/protocol/storage/GetMetadataCommand.java
// Path: src/main/java/org/cleverframe/fastdfs/model/MateData.java // public class MateData implements Serializable { // // private String name; // // private String value; // // public MateData() { // } // // public MateData(String name) { // this.name = name; // } // // public MateData(String name, String value) { // this.name = name; // this.value = value; // } // // public String getName() { // return this.name; // } // // public String getValue() { // return this.value; // } // // public void setName(String name) { // this.name = name; // } // // public void setValue(String value) { // this.value = value; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((value == null) ? 0 : value.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // MateData other = (MateData) obj; // if (name == null) { // if (other.name != null) // return false; // } else if (!name.equals(other.name)) // return false; // if (value == null) { // if (other.value != null) // return false; // } else if (!value.equals(other.value)) // return false; // return true; // } // // @Override // public String toString() { // return "NameValuePair [name=" + name + ", value=" + value + "]"; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/request/GetMetadataRequest.java // public class GetMetadataRequest extends BaseRequest { // /** // * 组名 // */ // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // /** // * 路径名 // */ // @FastDFSColumn(index = 1, dynamicField = DynamicFieldType.allRestByte) // private String path; // // /** // * 删除文件命令 // * // * @param groupName 组名 // * @param path 文件路径 // */ // public GetMetadataRequest(String groupName, String path) { // super(); // this.groupName = groupName; // this.path = path; // this.head = new ProtocolHead(CmdConstants.STORAGE_PROTO_CMD_GET_METADATA); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/response/GetMetadataResponse.java // public class GetMetadataResponse extends BaseResponse<Set<MateData>> { // // /** // * 解析反馈内容 // */ // @Override // public Set<MateData> decodeContent(InputStream in, Charset charset) throws IOException { // // 解析报文内容 // byte[] bytes = new byte[(int) getContentLength()]; // int contentSize = in.read(bytes); // if (contentSize != getContentLength()) { // throw new IOException("读取到的数据长度与协议长度不符"); // } // return MetadataMapperUtils.fromByte(bytes, charset); // } // }
import org.cleverframe.fastdfs.model.MateData; import org.cleverframe.fastdfs.protocol.storage.request.GetMetadataRequest; import org.cleverframe.fastdfs.protocol.storage.response.GetMetadataResponse; import java.util.Set;
package org.cleverframe.fastdfs.protocol.storage; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 17:07 <br/> */ public class GetMetadataCommand extends StorageCommand<Set<MateData>> { /** * 设置文件标签(元数据) * * @param groupName 组名 * @param path 文件路径 */ public GetMetadataCommand(String groupName, String path) {
// Path: src/main/java/org/cleverframe/fastdfs/model/MateData.java // public class MateData implements Serializable { // // private String name; // // private String value; // // public MateData() { // } // // public MateData(String name) { // this.name = name; // } // // public MateData(String name, String value) { // this.name = name; // this.value = value; // } // // public String getName() { // return this.name; // } // // public String getValue() { // return this.value; // } // // public void setName(String name) { // this.name = name; // } // // public void setValue(String value) { // this.value = value; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((value == null) ? 0 : value.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // MateData other = (MateData) obj; // if (name == null) { // if (other.name != null) // return false; // } else if (!name.equals(other.name)) // return false; // if (value == null) { // if (other.value != null) // return false; // } else if (!value.equals(other.value)) // return false; // return true; // } // // @Override // public String toString() { // return "NameValuePair [name=" + name + ", value=" + value + "]"; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/request/GetMetadataRequest.java // public class GetMetadataRequest extends BaseRequest { // /** // * 组名 // */ // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // /** // * 路径名 // */ // @FastDFSColumn(index = 1, dynamicField = DynamicFieldType.allRestByte) // private String path; // // /** // * 删除文件命令 // * // * @param groupName 组名 // * @param path 文件路径 // */ // public GetMetadataRequest(String groupName, String path) { // super(); // this.groupName = groupName; // this.path = path; // this.head = new ProtocolHead(CmdConstants.STORAGE_PROTO_CMD_GET_METADATA); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/response/GetMetadataResponse.java // public class GetMetadataResponse extends BaseResponse<Set<MateData>> { // // /** // * 解析反馈内容 // */ // @Override // public Set<MateData> decodeContent(InputStream in, Charset charset) throws IOException { // // 解析报文内容 // byte[] bytes = new byte[(int) getContentLength()]; // int contentSize = in.read(bytes); // if (contentSize != getContentLength()) { // throw new IOException("读取到的数据长度与协议长度不符"); // } // return MetadataMapperUtils.fromByte(bytes, charset); // } // } // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/GetMetadataCommand.java import org.cleverframe.fastdfs.model.MateData; import org.cleverframe.fastdfs.protocol.storage.request.GetMetadataRequest; import org.cleverframe.fastdfs.protocol.storage.response.GetMetadataResponse; import java.util.Set; package org.cleverframe.fastdfs.protocol.storage; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 17:07 <br/> */ public class GetMetadataCommand extends StorageCommand<Set<MateData>> { /** * 设置文件标签(元数据) * * @param groupName 组名 * @param path 文件路径 */ public GetMetadataCommand(String groupName, String path) {
this.request = new GetMetadataRequest(groupName, path);
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/protocol/storage/GetMetadataCommand.java
// Path: src/main/java/org/cleverframe/fastdfs/model/MateData.java // public class MateData implements Serializable { // // private String name; // // private String value; // // public MateData() { // } // // public MateData(String name) { // this.name = name; // } // // public MateData(String name, String value) { // this.name = name; // this.value = value; // } // // public String getName() { // return this.name; // } // // public String getValue() { // return this.value; // } // // public void setName(String name) { // this.name = name; // } // // public void setValue(String value) { // this.value = value; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((value == null) ? 0 : value.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // MateData other = (MateData) obj; // if (name == null) { // if (other.name != null) // return false; // } else if (!name.equals(other.name)) // return false; // if (value == null) { // if (other.value != null) // return false; // } else if (!value.equals(other.value)) // return false; // return true; // } // // @Override // public String toString() { // return "NameValuePair [name=" + name + ", value=" + value + "]"; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/request/GetMetadataRequest.java // public class GetMetadataRequest extends BaseRequest { // /** // * 组名 // */ // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // /** // * 路径名 // */ // @FastDFSColumn(index = 1, dynamicField = DynamicFieldType.allRestByte) // private String path; // // /** // * 删除文件命令 // * // * @param groupName 组名 // * @param path 文件路径 // */ // public GetMetadataRequest(String groupName, String path) { // super(); // this.groupName = groupName; // this.path = path; // this.head = new ProtocolHead(CmdConstants.STORAGE_PROTO_CMD_GET_METADATA); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/response/GetMetadataResponse.java // public class GetMetadataResponse extends BaseResponse<Set<MateData>> { // // /** // * 解析反馈内容 // */ // @Override // public Set<MateData> decodeContent(InputStream in, Charset charset) throws IOException { // // 解析报文内容 // byte[] bytes = new byte[(int) getContentLength()]; // int contentSize = in.read(bytes); // if (contentSize != getContentLength()) { // throw new IOException("读取到的数据长度与协议长度不符"); // } // return MetadataMapperUtils.fromByte(bytes, charset); // } // }
import org.cleverframe.fastdfs.model.MateData; import org.cleverframe.fastdfs.protocol.storage.request.GetMetadataRequest; import org.cleverframe.fastdfs.protocol.storage.response.GetMetadataResponse; import java.util.Set;
package org.cleverframe.fastdfs.protocol.storage; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 17:07 <br/> */ public class GetMetadataCommand extends StorageCommand<Set<MateData>> { /** * 设置文件标签(元数据) * * @param groupName 组名 * @param path 文件路径 */ public GetMetadataCommand(String groupName, String path) { this.request = new GetMetadataRequest(groupName, path); // 输出响应
// Path: src/main/java/org/cleverframe/fastdfs/model/MateData.java // public class MateData implements Serializable { // // private String name; // // private String value; // // public MateData() { // } // // public MateData(String name) { // this.name = name; // } // // public MateData(String name, String value) { // this.name = name; // this.value = value; // } // // public String getName() { // return this.name; // } // // public String getValue() { // return this.value; // } // // public void setName(String name) { // this.name = name; // } // // public void setValue(String value) { // this.value = value; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((value == null) ? 0 : value.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // MateData other = (MateData) obj; // if (name == null) { // if (other.name != null) // return false; // } else if (!name.equals(other.name)) // return false; // if (value == null) { // if (other.value != null) // return false; // } else if (!value.equals(other.value)) // return false; // return true; // } // // @Override // public String toString() { // return "NameValuePair [name=" + name + ", value=" + value + "]"; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/request/GetMetadataRequest.java // public class GetMetadataRequest extends BaseRequest { // /** // * 组名 // */ // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // /** // * 路径名 // */ // @FastDFSColumn(index = 1, dynamicField = DynamicFieldType.allRestByte) // private String path; // // /** // * 删除文件命令 // * // * @param groupName 组名 // * @param path 文件路径 // */ // public GetMetadataRequest(String groupName, String path) { // super(); // this.groupName = groupName; // this.path = path; // this.head = new ProtocolHead(CmdConstants.STORAGE_PROTO_CMD_GET_METADATA); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/response/GetMetadataResponse.java // public class GetMetadataResponse extends BaseResponse<Set<MateData>> { // // /** // * 解析反馈内容 // */ // @Override // public Set<MateData> decodeContent(InputStream in, Charset charset) throws IOException { // // 解析报文内容 // byte[] bytes = new byte[(int) getContentLength()]; // int contentSize = in.read(bytes); // if (contentSize != getContentLength()) { // throw new IOException("读取到的数据长度与协议长度不符"); // } // return MetadataMapperUtils.fromByte(bytes, charset); // } // } // Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/GetMetadataCommand.java import org.cleverframe.fastdfs.model.MateData; import org.cleverframe.fastdfs.protocol.storage.request.GetMetadataRequest; import org.cleverframe.fastdfs.protocol.storage.response.GetMetadataResponse; import java.util.Set; package org.cleverframe.fastdfs.protocol.storage; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 17:07 <br/> */ public class GetMetadataCommand extends StorageCommand<Set<MateData>> { /** * 设置文件标签(元数据) * * @param groupName 组名 * @param path 文件路径 */ public GetMetadataCommand(String groupName, String path) { this.request = new GetMetadataRequest(groupName, path); // 输出响应
this.response = new GetMetadataResponse();
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/protocol/AbstractCommand.java
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/exception/FastDfsIOException.java // public class FastDfsIOException extends FastDfsException { // public FastDfsIOException(Throwable cause) { // super("客户端连接服务端出现了io异常", cause); // } // // public FastDfsIOException(String messge, Throwable cause) { // super("客户端连接服务端出现了io异常:" + messge, cause); // } // // public FastDfsIOException(String message) { // super(message); // } // }
import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.exception.FastDfsIOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset;
package org.cleverframe.fastdfs.protocol; /** * FastDFS命令操执行抽象类 * 作者:LiZW <br/> * 创建时间:2016/11/20 12:23 <br/> */ public abstract class AbstractCommand<T> implements BaseCommand<T> { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(AbstractCommand.class); /** * 请求对象 */ protected BaseRequest request; /** * 响应对象 */ protected BaseResponse<T> response; /** * 对服务端发出请求然后接收反馈 */
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/exception/FastDfsIOException.java // public class FastDfsIOException extends FastDfsException { // public FastDfsIOException(Throwable cause) { // super("客户端连接服务端出现了io异常", cause); // } // // public FastDfsIOException(String messge, Throwable cause) { // super("客户端连接服务端出现了io异常:" + messge, cause); // } // // public FastDfsIOException(String message) { // super(message); // } // } // Path: src/main/java/org/cleverframe/fastdfs/protocol/AbstractCommand.java import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.exception.FastDfsIOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; package org.cleverframe.fastdfs.protocol; /** * FastDFS命令操执行抽象类 * 作者:LiZW <br/> * 创建时间:2016/11/20 12:23 <br/> */ public abstract class AbstractCommand<T> implements BaseCommand<T> { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(AbstractCommand.class); /** * 请求对象 */ protected BaseRequest request; /** * 响应对象 */ protected BaseResponse<T> response; /** * 对服务端发出请求然后接收反馈 */
public T execute(Connection conn) {
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/protocol/AbstractCommand.java
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/exception/FastDfsIOException.java // public class FastDfsIOException extends FastDfsException { // public FastDfsIOException(Throwable cause) { // super("客户端连接服务端出现了io异常", cause); // } // // public FastDfsIOException(String messge, Throwable cause) { // super("客户端连接服务端出现了io异常:" + messge, cause); // } // // public FastDfsIOException(String message) { // super(message); // } // }
import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.exception.FastDfsIOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset;
package org.cleverframe.fastdfs.protocol; /** * FastDFS命令操执行抽象类 * 作者:LiZW <br/> * 创建时间:2016/11/20 12:23 <br/> */ public abstract class AbstractCommand<T> implements BaseCommand<T> { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(AbstractCommand.class); /** * 请求对象 */ protected BaseRequest request; /** * 响应对象 */ protected BaseResponse<T> response; /** * 对服务端发出请求然后接收反馈 */ public T execute(Connection conn) { // 封装socket交易 send try { send(conn.getOutputStream(), conn.getCharset()); } catch (IOException e) {
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/exception/FastDfsIOException.java // public class FastDfsIOException extends FastDfsException { // public FastDfsIOException(Throwable cause) { // super("客户端连接服务端出现了io异常", cause); // } // // public FastDfsIOException(String messge, Throwable cause) { // super("客户端连接服务端出现了io异常:" + messge, cause); // } // // public FastDfsIOException(String message) { // super(message); // } // } // Path: src/main/java/org/cleverframe/fastdfs/protocol/AbstractCommand.java import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.exception.FastDfsIOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; package org.cleverframe.fastdfs.protocol; /** * FastDFS命令操执行抽象类 * 作者:LiZW <br/> * 创建时间:2016/11/20 12:23 <br/> */ public abstract class AbstractCommand<T> implements BaseCommand<T> { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(AbstractCommand.class); /** * 请求对象 */ protected BaseRequest request; /** * 响应对象 */ protected BaseResponse<T> response; /** * 对服务端发出请求然后接收反馈 */ public T execute(Connection conn) { // 封装socket交易 send try { send(conn.getOutputStream(), conn.getCharset()); } catch (IOException e) {
throw new FastDfsIOException("Socket IO异常 发送消息异常", e);
Lzw2016/fastdfs-java-client
src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetFetchStorageCommandTest.java
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNodeInfo.java // public class StorageNodeInfo implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // */ // public StorageNodeInfo(String ip, int port) { // super(); // this.ip = ip; // this.port = port; // } // // public StorageNodeInfo() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // @Override // public String toString() { // return "StorageNodeInfo{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // }
import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNodeInfo; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:37 <br/> */ public class GetFetchStorageCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class); @Test public void test01() {
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNodeInfo.java // public class StorageNodeInfo implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // */ // public StorageNodeInfo(String ip, int port) { // super(); // this.ip = ip; // this.port = port; // } // // public StorageNodeInfo() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // @Override // public String toString() { // return "StorageNodeInfo{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // } // Path: src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetFetchStorageCommandTest.java import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNodeInfo; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:37 <br/> */ public class GetFetchStorageCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class); @Test public void test01() {
Connection connection = GetTrackerConnection.getDefaultConnection();
Lzw2016/fastdfs-java-client
src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetFetchStorageCommandTest.java
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNodeInfo.java // public class StorageNodeInfo implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // */ // public StorageNodeInfo(String ip, int port) { // super(); // this.ip = ip; // this.port = port; // } // // public StorageNodeInfo() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // @Override // public String toString() { // return "StorageNodeInfo{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // }
import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNodeInfo; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:37 <br/> */ public class GetFetchStorageCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class); @Test public void test01() {
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNodeInfo.java // public class StorageNodeInfo implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // */ // public StorageNodeInfo(String ip, int port) { // super(); // this.ip = ip; // this.port = port; // } // // public StorageNodeInfo() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // @Override // public String toString() { // return "StorageNodeInfo{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // } // Path: src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetFetchStorageCommandTest.java import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNodeInfo; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:37 <br/> */ public class GetFetchStorageCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class); @Test public void test01() {
Connection connection = GetTrackerConnection.getDefaultConnection();
Lzw2016/fastdfs-java-client
src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetFetchStorageCommandTest.java
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNodeInfo.java // public class StorageNodeInfo implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // */ // public StorageNodeInfo(String ip, int port) { // super(); // this.ip = ip; // this.port = port; // } // // public StorageNodeInfo() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // @Override // public String toString() { // return "StorageNodeInfo{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // }
import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNodeInfo; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:37 <br/> */ public class GetFetchStorageCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class); @Test public void test01() { Connection connection = GetTrackerConnection.getDefaultConnection(); try { GetFetchStorageCommand command = new GetFetchStorageCommand("group1", "/00/00/wKg4i1gw1JWALQsHAATA4WNjQT4937.jpg", false);
// Path: src/main/java/org/cleverframe/fastdfs/conn/Connection.java // public interface Connection extends Closeable { // /** // * 关闭连接 // */ // @Override // void close(); // // /** // * 连接是否关闭 // * // * @return 返回true表示连接关闭 // */ // boolean isClosed(); // // /** // * 测试连接是否有效 // * // * @return 返回true表示连接无效 // */ // boolean isValid(); // // /** // * 获取输出流 // * // * @return 输出流 // * @throws IOException 操作异常 // */ // OutputStream getOutputStream() throws IOException; // // /** // * 获取输入流 // * // * @return 输入流 // * @throws IOException 获取输入流错误 // */ // InputStream getInputStream() throws IOException; // // /** // * 获取字符集 // * // * @return 字符集 // */ // Charset getCharset(); // } // // Path: src/main/java/org/cleverframe/fastdfs/model/StorageNodeInfo.java // public class StorageNodeInfo implements Serializable { // @FastDFSColumn(index = 0, max = OtherConstants.FDFS_GROUP_NAME_MAX_LEN) // private String groupName; // // @FastDFSColumn(index = 1, max = OtherConstants.FDFS_IPADDR_SIZE - 1) // private String ip; // // @FastDFSColumn(index = 2) // private int port; // // /** // * 存储节点 // * // * @param ip 存储服务器IP地址 // * @param port 存储服务器端口号 // */ // public StorageNodeInfo(String ip, int port) { // super(); // this.ip = ip; // this.port = port; // } // // public StorageNodeInfo() { // super(); // } // // /** // * @return 根据IP和端口 返回 InetSocketAddress 对象 // */ // public InetSocketAddress getInetSocketAddress() { // return new InetSocketAddress(ip, port); // } // // public String getGroupName() { // return groupName; // } // // public void setGroupName(String groupName) { // this.groupName = groupName; // } // // public String getIp() { // return ip; // } // // public void setIp(String ip) { // this.ip = ip; // } // // public int getPort() { // return port; // } // // public void setPort(int port) { // this.port = port; // } // // @Override // public String toString() { // return "StorageNodeInfo{" + // "groupName='" + groupName + '\'' + // ", ip='" + ip + '\'' + // ", port=" + port + // '}'; // } // } // // Path: src/test/java/org/cleverframe/fastdfs/testbase/GetTrackerConnection.java // public final class GetTrackerConnection { // private static final InetSocketAddress address = new InetSocketAddress("192.168.10.128", 22122); // private static final int soTimeout = 1500; // private static final int connectTimeout = 600; // private static final Charset charset = Charset.forName("UTF-8"); // // public static Connection getDefaultConnection() { // return new SocketConnection(address, soTimeout, connectTimeout, charset); // } // } // Path: src/test/java/org/cleverframe/fastdfs/protocol/tracker/GetFetchStorageCommandTest.java import org.cleverframe.fastdfs.conn.Connection; import org.cleverframe.fastdfs.model.StorageNodeInfo; import org.cleverframe.fastdfs.testbase.GetTrackerConnection; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package org.cleverframe.fastdfs.protocol.tracker; /** * 作者:LiZW <br/> * 创建时间:2016/11/20 15:37 <br/> */ public class GetFetchStorageCommandTest { /** * 日志 */ private static final Logger logger = LoggerFactory.getLogger(GetGroupListCommandTest.class); @Test public void test01() { Connection connection = GetTrackerConnection.getDefaultConnection(); try { GetFetchStorageCommand command = new GetFetchStorageCommand("group1", "/00/00/wKg4i1gw1JWALQsHAATA4WNjQT4937.jpg", false);
StorageNodeInfo storageNodeInfo = command.execute(connection);
Lzw2016/fastdfs-java-client
src/main/java/org/cleverframe/fastdfs/conn/CommandExecutor.java
// Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/StorageCommand.java // public abstract class StorageCommand<T> extends AbstractCommand<T> { // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/tracker/TrackerCommand.java // public abstract class TrackerCommand<T> extends AbstractCommand<T> { // }
import org.cleverframe.fastdfs.protocol.storage.StorageCommand; import org.cleverframe.fastdfs.protocol.tracker.TrackerCommand; import java.net.InetSocketAddress;
package org.cleverframe.fastdfs.conn; /** * FastDFS命令执行器 * <p> * 命令执行器 * 作者:LiZW <br/> * 创建时间:2016/11/21 15:22 <br/> */ public interface CommandExecutor { /** * 在Tracker Server上执行命令 * * @param command Tracker Server命令 * @param <T> 返回数据类型 * @return 返回数据 */ <T> T execute(TrackerCommand<T> command); /** * 在Storage Server上执行命令 * * @param address Storage Server地址 * @param command Storage Server命令 * @param <T> 返回数据类型 * @return 返回数据 */
// Path: src/main/java/org/cleverframe/fastdfs/protocol/storage/StorageCommand.java // public abstract class StorageCommand<T> extends AbstractCommand<T> { // } // // Path: src/main/java/org/cleverframe/fastdfs/protocol/tracker/TrackerCommand.java // public abstract class TrackerCommand<T> extends AbstractCommand<T> { // } // Path: src/main/java/org/cleverframe/fastdfs/conn/CommandExecutor.java import org.cleverframe.fastdfs.protocol.storage.StorageCommand; import org.cleverframe.fastdfs.protocol.tracker.TrackerCommand; import java.net.InetSocketAddress; package org.cleverframe.fastdfs.conn; /** * FastDFS命令执行器 * <p> * 命令执行器 * 作者:LiZW <br/> * 创建时间:2016/11/21 15:22 <br/> */ public interface CommandExecutor { /** * 在Tracker Server上执行命令 * * @param command Tracker Server命令 * @param <T> 返回数据类型 * @return 返回数据 */ <T> T execute(TrackerCommand<T> command); /** * 在Storage Server上执行命令 * * @param address Storage Server地址 * @param command Storage Server命令 * @param <T> 返回数据类型 * @return 返回数据 */
<T> T execute(InetSocketAddress address, StorageCommand<T> command);
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/core/NodeDao.java
// Path: modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java // public interface ItemDao<T extends Item> { // // T create(T item) throws GroundException; // // DbStatements insert(T item) throws GroundException; // // T retrieveFromDatabase(long id) throws GroundException; // // T retrieveFromDatabase(String sourceKey) throws GroundException; // // Class<T> getType(); // // List<Long> getLeaves(long itemId) throws GroundException; // // Map<Long, Long> getHistory(long itemId) throws GroundException; // // /** // * Add a new Version to this Item. The provided parentIds will be the parents of this particular // * version. What's provided in the default case varies based on which database we are writing // * into. // * // * @param itemId the id of the Item we're updating // * @param childId the new version's id // * @param parentIds the ids of the parents of the child // */ // DbStatements update(long itemId, long childId, List<Long> parentIds) throws GroundException; // // /** // * Truncate the item to only have the most recent levels. // * // * @param numLevels the levels to keep // * @throws GroundException an error while removing versions // */ // void truncate(long itemId, int numLevels) throws GroundException; // // default boolean checkIfItemExists(String sourceKey) { // try { // this.retrieveFromDatabase(sourceKey); // // return true; // } catch (GroundException e) { // return false; // } // } // // default void verifyItemNotExists(String sourceKey) throws GroundException { // if (checkIfItemExists(sourceKey)) { // throw new GroundException(ExceptionType.ITEM_ALREADY_EXISTS, this.getType().getSimpleName(), sourceKey); // } // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/core/Node.java // public class Node extends Item { // // // the name of this Node // @JsonProperty("name") // private final String name; // // // the source key for this Node // @JsonProperty("sourceKey") // private final String sourceKey; // // /** // * Create a new node. // * // * @param id the id of the node // * @param name the name of the node // * @param sourceKey the user-generated source key of the node // * @param tags the tags associated with the node // */ // @JsonCreator // public Node(@JsonProperty("itemId") long id, // @JsonProperty("name") String name, // @JsonProperty("sourceKey") String sourceKey, // @JsonProperty("tags") Map<String, Tag> tags) { // // super(id, tags); // // this.name = name; // this.sourceKey = sourceKey; // } // // public Node(long id, Node other) { // super(id, other.getTags()); // // this.name = other.name; // this.sourceKey = other.sourceKey; // } // // public long getItemId() { // return super.getId(); // } // // public String getName() { // return this.name; // } // // public String getSourceKey() { // return this.sourceKey; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Node)) { // return false; // } // // Node otherNode = (Node) other; // // return this.name.equals(otherNode.name) // && this.getId() == otherNode.getId() // && this.sourceKey.equals(otherNode.sourceKey) // && this.getTags().equals(otherNode.getTags()); // } // }
import edu.berkeley.ground.common.dao.version.ItemDao; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.Node; import java.util.List; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface NodeDao extends ItemDao<Node> { @Override default Class<Node> getType() { return Node.class; } @Override
// Path: modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java // public interface ItemDao<T extends Item> { // // T create(T item) throws GroundException; // // DbStatements insert(T item) throws GroundException; // // T retrieveFromDatabase(long id) throws GroundException; // // T retrieveFromDatabase(String sourceKey) throws GroundException; // // Class<T> getType(); // // List<Long> getLeaves(long itemId) throws GroundException; // // Map<Long, Long> getHistory(long itemId) throws GroundException; // // /** // * Add a new Version to this Item. The provided parentIds will be the parents of this particular // * version. What's provided in the default case varies based on which database we are writing // * into. // * // * @param itemId the id of the Item we're updating // * @param childId the new version's id // * @param parentIds the ids of the parents of the child // */ // DbStatements update(long itemId, long childId, List<Long> parentIds) throws GroundException; // // /** // * Truncate the item to only have the most recent levels. // * // * @param numLevels the levels to keep // * @throws GroundException an error while removing versions // */ // void truncate(long itemId, int numLevels) throws GroundException; // // default boolean checkIfItemExists(String sourceKey) { // try { // this.retrieveFromDatabase(sourceKey); // // return true; // } catch (GroundException e) { // return false; // } // } // // default void verifyItemNotExists(String sourceKey) throws GroundException { // if (checkIfItemExists(sourceKey)) { // throw new GroundException(ExceptionType.ITEM_ALREADY_EXISTS, this.getType().getSimpleName(), sourceKey); // } // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/core/Node.java // public class Node extends Item { // // // the name of this Node // @JsonProperty("name") // private final String name; // // // the source key for this Node // @JsonProperty("sourceKey") // private final String sourceKey; // // /** // * Create a new node. // * // * @param id the id of the node // * @param name the name of the node // * @param sourceKey the user-generated source key of the node // * @param tags the tags associated with the node // */ // @JsonCreator // public Node(@JsonProperty("itemId") long id, // @JsonProperty("name") String name, // @JsonProperty("sourceKey") String sourceKey, // @JsonProperty("tags") Map<String, Tag> tags) { // // super(id, tags); // // this.name = name; // this.sourceKey = sourceKey; // } // // public Node(long id, Node other) { // super(id, other.getTags()); // // this.name = other.name; // this.sourceKey = other.sourceKey; // } // // public long getItemId() { // return super.getId(); // } // // public String getName() { // return this.name; // } // // public String getSourceKey() { // return this.sourceKey; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Node)) { // return false; // } // // Node otherNode = (Node) other; // // return this.name.equals(otherNode.name) // && this.getId() == otherNode.getId() // && this.sourceKey.equals(otherNode.sourceKey) // && this.getTags().equals(otherNode.getTags()); // } // } // Path: modules/common/app/edu/berkeley/ground/common/dao/core/NodeDao.java import edu.berkeley.ground.common.dao.version.ItemDao; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.Node; import java.util.List; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface NodeDao extends ItemDao<Node> { @Override default Class<Node> getType() { return Node.class; } @Override
Node retrieveFromDatabase(String sourceKey) throws GroundException;
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/usage/LineageEdgeDao.java
// Path: modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java // public interface ItemDao<T extends Item> { // // T create(T item) throws GroundException; // // DbStatements insert(T item) throws GroundException; // // T retrieveFromDatabase(long id) throws GroundException; // // T retrieveFromDatabase(String sourceKey) throws GroundException; // // Class<T> getType(); // // List<Long> getLeaves(long itemId) throws GroundException; // // Map<Long, Long> getHistory(long itemId) throws GroundException; // // /** // * Add a new Version to this Item. The provided parentIds will be the parents of this particular // * version. What's provided in the default case varies based on which database we are writing // * into. // * // * @param itemId the id of the Item we're updating // * @param childId the new version's id // * @param parentIds the ids of the parents of the child // */ // DbStatements update(long itemId, long childId, List<Long> parentIds) throws GroundException; // // /** // * Truncate the item to only have the most recent levels. // * // * @param numLevels the levels to keep // * @throws GroundException an error while removing versions // */ // void truncate(long itemId, int numLevels) throws GroundException; // // default boolean checkIfItemExists(String sourceKey) { // try { // this.retrieveFromDatabase(sourceKey); // // return true; // } catch (GroundException e) { // return false; // } // } // // default void verifyItemNotExists(String sourceKey) throws GroundException { // if (checkIfItemExists(sourceKey)) { // throw new GroundException(ExceptionType.ITEM_ALREADY_EXISTS, this.getType().getSimpleName(), sourceKey); // } // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/usage/LineageEdge.java // public class LineageEdge extends Item { // // // the name of this LineageEdge // @JsonProperty("name") // private final String name; // // // the source key for this Node // @JsonProperty("sourceKey") // private final String sourceKey; // // /** // * Create a new lineage edge. // * // * @param id the id of the lineage edge // * @param name the name of the lineage edge // * @param sourceKey the user-generated unique key for the lineage edge // * @param tags the tags associated with this lineage edge // */ // // @JsonCreator // public LineageEdge(@JsonProperty("itemId") long id, @JsonProperty("name") String name, // @JsonProperty("sourceKey") String sourceKey, @JsonProperty("tags") Map<String, Tag> tags) { // super(id, tags); // // this.name = name; // this.sourceKey = sourceKey; // } // // public LineageEdge(long id, LineageEdge other) { // super(id, other.getTags()); // // this.name = other.name; // this.sourceKey = other.sourceKey; // } // // public String getName() { // return this.name; // } // // public String getSourceKey() { // return this.sourceKey; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof LineageEdge)) { // return false; // } // // LineageEdge otherLineageEdge = (LineageEdge) other; // // return this.name.equals(otherLineageEdge.name) // && this.getId() == otherLineageEdge.getId() // && this.sourceKey.equals(otherLineageEdge.sourceKey) // && this.getTags().equals(otherLineageEdge.getTags()); // } // }
import edu.berkeley.ground.common.dao.version.ItemDao; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.usage.LineageEdge; import java.util.List; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.usage; public interface LineageEdgeDao extends ItemDao<LineageEdge> { @Override
// Path: modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java // public interface ItemDao<T extends Item> { // // T create(T item) throws GroundException; // // DbStatements insert(T item) throws GroundException; // // T retrieveFromDatabase(long id) throws GroundException; // // T retrieveFromDatabase(String sourceKey) throws GroundException; // // Class<T> getType(); // // List<Long> getLeaves(long itemId) throws GroundException; // // Map<Long, Long> getHistory(long itemId) throws GroundException; // // /** // * Add a new Version to this Item. The provided parentIds will be the parents of this particular // * version. What's provided in the default case varies based on which database we are writing // * into. // * // * @param itemId the id of the Item we're updating // * @param childId the new version's id // * @param parentIds the ids of the parents of the child // */ // DbStatements update(long itemId, long childId, List<Long> parentIds) throws GroundException; // // /** // * Truncate the item to only have the most recent levels. // * // * @param numLevels the levels to keep // * @throws GroundException an error while removing versions // */ // void truncate(long itemId, int numLevels) throws GroundException; // // default boolean checkIfItemExists(String sourceKey) { // try { // this.retrieveFromDatabase(sourceKey); // // return true; // } catch (GroundException e) { // return false; // } // } // // default void verifyItemNotExists(String sourceKey) throws GroundException { // if (checkIfItemExists(sourceKey)) { // throw new GroundException(ExceptionType.ITEM_ALREADY_EXISTS, this.getType().getSimpleName(), sourceKey); // } // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/usage/LineageEdge.java // public class LineageEdge extends Item { // // // the name of this LineageEdge // @JsonProperty("name") // private final String name; // // // the source key for this Node // @JsonProperty("sourceKey") // private final String sourceKey; // // /** // * Create a new lineage edge. // * // * @param id the id of the lineage edge // * @param name the name of the lineage edge // * @param sourceKey the user-generated unique key for the lineage edge // * @param tags the tags associated with this lineage edge // */ // // @JsonCreator // public LineageEdge(@JsonProperty("itemId") long id, @JsonProperty("name") String name, // @JsonProperty("sourceKey") String sourceKey, @JsonProperty("tags") Map<String, Tag> tags) { // super(id, tags); // // this.name = name; // this.sourceKey = sourceKey; // } // // public LineageEdge(long id, LineageEdge other) { // super(id, other.getTags()); // // this.name = other.name; // this.sourceKey = other.sourceKey; // } // // public String getName() { // return this.name; // } // // public String getSourceKey() { // return this.sourceKey; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof LineageEdge)) { // return false; // } // // LineageEdge otherLineageEdge = (LineageEdge) other; // // return this.name.equals(otherLineageEdge.name) // && this.getId() == otherLineageEdge.getId() // && this.sourceKey.equals(otherLineageEdge.sourceKey) // && this.getTags().equals(otherLineageEdge.getTags()); // } // } // Path: modules/common/app/edu/berkeley/ground/common/dao/usage/LineageEdgeDao.java import edu.berkeley.ground.common.dao.version.ItemDao; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.usage.LineageEdge; import java.util.List; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.usage; public interface LineageEdgeDao extends ItemDao<LineageEdge> { @Override
LineageEdge create(LineageEdge lineageEdge) throws GroundException;
ground-context/ground
modules/postgres/app/Module.java
// Path: modules/postgres/app/edu/berkeley/ground/postgres/start/ApplicationStart.java // @Singleton // public class ApplicationStart { // // private final Instant start; // // @Inject // public ApplicationStart(Clock clock, ApplicationLifecycle appLifecycle, final Configuration configuration, final Database dbSource) // throws GroundException { // // this.start = clock.instant(); // Logger.info("Ground Postgres: Starting application at " + this.start); // // Logger.info("Queries will Cache for {} seconds.", configuration.underlying().getString("ground.cache.expire.secs")); // System.setProperty("ground.cache.expire.secs", configuration.underlying().getString("ground.cache.expire.secs")); // // appLifecycle.addStopHook( // () -> { // Instant stop = clock.instant(); // Long runningTime = stop.getEpochSecond() - this.start.getEpochSecond(); // Logger.info("Ground Postgres: Stopping application at " + clock.instant() + " after " + runningTime + "s."); // return CompletableFuture.completedFuture(null); // }); // } // }
import com.google.inject.AbstractModule; import edu.berkeley.ground.postgres.start.ApplicationStart; import java.time.Clock;
public class Module extends AbstractModule { @Override public void configure() { bind(Clock.class).toInstance(Clock.systemDefaultZone());
// Path: modules/postgres/app/edu/berkeley/ground/postgres/start/ApplicationStart.java // @Singleton // public class ApplicationStart { // // private final Instant start; // // @Inject // public ApplicationStart(Clock clock, ApplicationLifecycle appLifecycle, final Configuration configuration, final Database dbSource) // throws GroundException { // // this.start = clock.instant(); // Logger.info("Ground Postgres: Starting application at " + this.start); // // Logger.info("Queries will Cache for {} seconds.", configuration.underlying().getString("ground.cache.expire.secs")); // System.setProperty("ground.cache.expire.secs", configuration.underlying().getString("ground.cache.expire.secs")); // // appLifecycle.addStopHook( // () -> { // Instant stop = clock.instant(); // Long runningTime = stop.getEpochSecond() - this.start.getEpochSecond(); // Logger.info("Ground Postgres: Stopping application at " + clock.instant() + " after " + runningTime + "s."); // return CompletableFuture.completedFuture(null); // }); // } // } // Path: modules/postgres/app/Module.java import com.google.inject.AbstractModule; import edu.berkeley.ground.postgres.start.ApplicationStart; import java.time.Clock; public class Module extends AbstractModule { @Override public void configure() { bind(Clock.class).toInstance(Clock.systemDefaultZone());
bind(ApplicationStart.class).asEagerSingleton();
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/core/GraphVersion.java
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Tag; import java.util.ArrayList; import java.util.List; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class GraphVersion extends RichVersion { @JsonProperty("graphId") private final long graphId; @JsonProperty("edgeVersionIds") private final List<Long> edgeVersionIds; /** * Create a new graph version. * * @param id the id of this graph version * @param tags the tags associated with this graph version * @param structureVersionId the id of the StructureVersion associated with this graph version * @param reference an optional external reference * @param referenceParameters the access parameters of the reference * @param graphId the id of the graph containing this version * @param edgeVersionIds the list of edge versions in this graph version */ @JsonCreator public GraphVersion( @JsonProperty("id") long id,
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/core/GraphVersion.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Tag; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class GraphVersion extends RichVersion { @JsonProperty("graphId") private final long graphId; @JsonProperty("edgeVersionIds") private final List<Long> edgeVersionIds; /** * Create a new graph version. * * @param id the id of this graph version * @param tags the tags associated with this graph version * @param structureVersionId the id of the StructureVersion associated with this graph version * @param reference an optional external reference * @param referenceParameters the access parameters of the reference * @param graphId the id of the graph containing this version * @param edgeVersionIds the list of edge versions in this graph version */ @JsonCreator public GraphVersion( @JsonProperty("id") long id,
@JsonProperty("tags") Map<String, Tag> tags,
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/core/StructureDao.java
// Path: modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java // public interface ItemDao<T extends Item> { // // T create(T item) throws GroundException; // // DbStatements insert(T item) throws GroundException; // // T retrieveFromDatabase(long id) throws GroundException; // // T retrieveFromDatabase(String sourceKey) throws GroundException; // // Class<T> getType(); // // List<Long> getLeaves(long itemId) throws GroundException; // // Map<Long, Long> getHistory(long itemId) throws GroundException; // // /** // * Add a new Version to this Item. The provided parentIds will be the parents of this particular // * version. What's provided in the default case varies based on which database we are writing // * into. // * // * @param itemId the id of the Item we're updating // * @param childId the new version's id // * @param parentIds the ids of the parents of the child // */ // DbStatements update(long itemId, long childId, List<Long> parentIds) throws GroundException; // // /** // * Truncate the item to only have the most recent levels. // * // * @param numLevels the levels to keep // * @throws GroundException an error while removing versions // */ // void truncate(long itemId, int numLevels) throws GroundException; // // default boolean checkIfItemExists(String sourceKey) { // try { // this.retrieveFromDatabase(sourceKey); // // return true; // } catch (GroundException e) { // return false; // } // } // // default void verifyItemNotExists(String sourceKey) throws GroundException { // if (checkIfItemExists(sourceKey)) { // throw new GroundException(ExceptionType.ITEM_ALREADY_EXISTS, this.getType().getSimpleName(), sourceKey); // } // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/core/Structure.java // public class Structure extends Item { // // // the name of this Structure // @JsonProperty("name") // private final String name; // // // the source key for this Node // @JsonProperty("sourceKey") // private final String sourceKey; // // /** // * Create a new structure. // * // * @param id the id of the structure // * @param name the name of the structure // * @param sourceKey the user-generated unique key for the structure // * @param tags the tags associated with this structure // */ // @JsonCreator // public Structure( // @JsonProperty("itemId") long id, // @JsonProperty("name") String name, // @JsonProperty("sourceKey") String sourceKey, // @JsonProperty("tags") Map<String, Tag> tags) { // super(id, tags); // // this.name = name; // this.sourceKey = sourceKey; // } // // public Structure(long id, Structure other) { // super(id, other.getTags()); // // this.name = other.name; // this.sourceKey = other.sourceKey; // } // // public String getName() { // return this.name; // } // // public String getSourceKey() { // return this.sourceKey; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Structure)) { // return false; // } // // Structure otherStructure = (Structure) other; // // return this.name.equals(otherStructure.name) // && this.getId() == otherStructure.getId() // && this.sourceKey.equals(otherStructure.sourceKey) // && this.getTags().equals(otherStructure.getTags()); // } // }
import edu.berkeley.ground.common.dao.version.ItemDao; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.Structure; import java.util.List; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface StructureDao extends ItemDao<Structure> { @Override default Class<Structure> getType() { return Structure.class; } @Override
// Path: modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java // public interface ItemDao<T extends Item> { // // T create(T item) throws GroundException; // // DbStatements insert(T item) throws GroundException; // // T retrieveFromDatabase(long id) throws GroundException; // // T retrieveFromDatabase(String sourceKey) throws GroundException; // // Class<T> getType(); // // List<Long> getLeaves(long itemId) throws GroundException; // // Map<Long, Long> getHistory(long itemId) throws GroundException; // // /** // * Add a new Version to this Item. The provided parentIds will be the parents of this particular // * version. What's provided in the default case varies based on which database we are writing // * into. // * // * @param itemId the id of the Item we're updating // * @param childId the new version's id // * @param parentIds the ids of the parents of the child // */ // DbStatements update(long itemId, long childId, List<Long> parentIds) throws GroundException; // // /** // * Truncate the item to only have the most recent levels. // * // * @param numLevels the levels to keep // * @throws GroundException an error while removing versions // */ // void truncate(long itemId, int numLevels) throws GroundException; // // default boolean checkIfItemExists(String sourceKey) { // try { // this.retrieveFromDatabase(sourceKey); // // return true; // } catch (GroundException e) { // return false; // } // } // // default void verifyItemNotExists(String sourceKey) throws GroundException { // if (checkIfItemExists(sourceKey)) { // throw new GroundException(ExceptionType.ITEM_ALREADY_EXISTS, this.getType().getSimpleName(), sourceKey); // } // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/core/Structure.java // public class Structure extends Item { // // // the name of this Structure // @JsonProperty("name") // private final String name; // // // the source key for this Node // @JsonProperty("sourceKey") // private final String sourceKey; // // /** // * Create a new structure. // * // * @param id the id of the structure // * @param name the name of the structure // * @param sourceKey the user-generated unique key for the structure // * @param tags the tags associated with this structure // */ // @JsonCreator // public Structure( // @JsonProperty("itemId") long id, // @JsonProperty("name") String name, // @JsonProperty("sourceKey") String sourceKey, // @JsonProperty("tags") Map<String, Tag> tags) { // super(id, tags); // // this.name = name; // this.sourceKey = sourceKey; // } // // public Structure(long id, Structure other) { // super(id, other.getTags()); // // this.name = other.name; // this.sourceKey = other.sourceKey; // } // // public String getName() { // return this.name; // } // // public String getSourceKey() { // return this.sourceKey; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Structure)) { // return false; // } // // Structure otherStructure = (Structure) other; // // return this.name.equals(otherStructure.name) // && this.getId() == otherStructure.getId() // && this.sourceKey.equals(otherStructure.sourceKey) // && this.getTags().equals(otherStructure.getTags()); // } // } // Path: modules/common/app/edu/berkeley/ground/common/dao/core/StructureDao.java import edu.berkeley.ground.common.dao.version.ItemDao; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.Structure; import java.util.List; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface StructureDao extends ItemDao<Structure> { @Override default Class<Structure> getType() { return Structure.class; } @Override
Structure retrieveFromDatabase(final String sourceKey) throws GroundException;
ground-context/ground
modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // }
import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import play.libs.Json;
package edu.berkeley.ground.common.util; public class ModelTestUtils { public static String readFromFile(String filename) throws GroundException { try { String content = new Scanner(new File(filename)).useDelimiter("\\Z").next(); return content; } catch (FileNotFoundException e) {
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import play.libs.Json; package edu.berkeley.ground.common.util; public class ModelTestUtils { public static String readFromFile(String filename) throws GroundException { try { String content = new Scanner(new File(filename)).useDelimiter("\\Z").next(); return content; } catch (FileNotFoundException e) {
throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename));
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/core/Node.java
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.model.version.Tag; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class Node extends Item { // the name of this Node @JsonProperty("name") private final String name; // the source key for this Node @JsonProperty("sourceKey") private final String sourceKey; /** * Create a new node. * * @param id the id of the node * @param name the name of the node * @param sourceKey the user-generated source key of the node * @param tags the tags associated with the node */ @JsonCreator public Node(@JsonProperty("itemId") long id, @JsonProperty("name") String name, @JsonProperty("sourceKey") String sourceKey,
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/core/Node.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.model.version.Tag; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class Node extends Item { // the name of this Node @JsonProperty("name") private final String name; // the source key for this Node @JsonProperty("sourceKey") private final String sourceKey; /** * Create a new node. * * @param id the id of the node * @param name the name of the node * @param sourceKey the user-generated source key of the node * @param tags the tags associated with the node */ @JsonCreator public Node(@JsonProperty("itemId") long id, @JsonProperty("name") String name, @JsonProperty("sourceKey") String sourceKey,
@JsonProperty("tags") Map<String, Tag> tags) {
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/core/NodeVersion.java
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // }
import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Tag;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * <p> * <p>http://www.apache.org/licenses/LICENSE-2.0 * <p> * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class NodeVersion extends RichVersion { // the id of the Node containing this Version @JsonProperty("nodeId") private final long nodeId; /** * Create a new node version. * * @param id the id of the version * @param tags the tags associated with the version * @param structureVersionId the id of the StructureVersion associated with this version * @param reference an optional external reference * @param referenceParameters the parameters associated with the reference * @param nodeId the id of the node containing this version */ @JsonCreator
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/core/NodeVersion.java import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Tag; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * <p> * <p>http://www.apache.org/licenses/LICENSE-2.0 * <p> * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class NodeVersion extends RichVersion { // the id of the Node containing this Version @JsonProperty("nodeId") private final long nodeId; /** * Create a new node version. * * @param id the id of the version * @param tags the tags associated with the version * @param structureVersionId the id of the StructureVersion associated with this version * @param reference an optional external reference * @param referenceParameters the parameters associated with the reference * @param nodeId the id of the node containing this version */ @JsonCreator
public NodeVersion(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags,
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/core/Graph.java
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.model.version.Tag; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class Graph extends Item { // the name of this Graph @JsonProperty("name") private final String name; // the source key for this Graph @JsonProperty("sourceKey") private final String sourceKey; /** * Create a new Graph. * * @param id the id of the graph * @param name the name of the graph * @param sourceKey the user-generated unique key for the graph * @param tags the tags associated with the graph */ @JsonCreator public Graph(@JsonProperty("itemId") long id, @JsonProperty("name") String name, @JsonProperty("sourceKey") String sourceKey,
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/core/Graph.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.model.version.Tag; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class Graph extends Item { // the name of this Graph @JsonProperty("name") private final String name; // the source key for this Graph @JsonProperty("sourceKey") private final String sourceKey; /** * Create a new Graph. * * @param id the id of the graph * @param name the name of the graph * @param sourceKey the user-generated unique key for the graph * @param tags the tags associated with the graph */ @JsonCreator public Graph(@JsonProperty("itemId") long id, @JsonProperty("name") String name, @JsonProperty("sourceKey") String sourceKey,
@JsonProperty("tags") Map<String, Tag> tags) {
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/core/Edge.java
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.model.version.Tag; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class Edge extends Item { // the name of this Edge @JsonProperty("name") private final String name; // the id of the Node that this EdgeVersion originates from @JsonProperty("fromNodeId") private final long fromNodeId; // the id of the Node that this EdgeVersion points to @JsonProperty("toNodeId") private final long toNodeId; // the source key for this Edge @JsonProperty("sourceKey") private final String sourceKey; /** * Construct a new Edge. * * @param id the edge id * @param name the edge name * @param sourceKey the user-generated unique key for the edge * @param fromNodeId the source node of this edge * @param toNodeId the destination node of this edge * @param tags the tags associated with this edge */ @JsonCreator public Edge(@JsonProperty("itemId") long id, @JsonProperty("name") String name, @JsonProperty("sourceKey") String sourceKey, @JsonProperty("fromNodeId") long fromNodeId, @JsonProperty("toNodeId") long toNodeId,
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/core/Edge.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.model.version.Tag; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class Edge extends Item { // the name of this Edge @JsonProperty("name") private final String name; // the id of the Node that this EdgeVersion originates from @JsonProperty("fromNodeId") private final long fromNodeId; // the id of the Node that this EdgeVersion points to @JsonProperty("toNodeId") private final long toNodeId; // the source key for this Edge @JsonProperty("sourceKey") private final String sourceKey; /** * Construct a new Edge. * * @param id the edge id * @param name the edge name * @param sourceKey the user-generated unique key for the edge * @param fromNodeId the source node of this edge * @param toNodeId the destination node of this edge * @param tags the tags associated with this edge */ @JsonCreator public Edge(@JsonProperty("itemId") long id, @JsonProperty("name") String name, @JsonProperty("sourceKey") String sourceKey, @JsonProperty("fromNodeId") long fromNodeId, @JsonProperty("toNodeId") long toNodeId,
@JsonProperty("tags") Map<String, Tag> tags) {
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/core/RichVersion.java
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Version.java // public class Version { // private final long id; // // public Version(long id) { // this.id = id; // } // // public long getId() { // return this.id; // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Tag; import edu.berkeley.ground.common.model.version.Version; import java.util.HashMap; import java.util.Map; import java.util.Objects;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * <p> * <p>http://www.apache.org/licenses/LICENSE-2.0 * <p> * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class RichVersion extends Version { // the map of Keys to Tags associated with this RichVersion @JsonProperty("tags")
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Version.java // public class Version { // private final long id; // // public Version(long id) { // this.id = id; // } // // public long getId() { // return this.id; // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/core/RichVersion.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Tag; import edu.berkeley.ground.common.model.version.Version; import java.util.HashMap; import java.util.Map; import java.util.Objects; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * <p> * <p>http://www.apache.org/licenses/LICENSE-2.0 * <p> * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class RichVersion extends Version { // the map of Keys to Tags associated with this RichVersion @JsonProperty("tags")
private final Map<String, Tag> tags;
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/core/StructureVersion.java
// Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Version.java // public class Version { // private final long id; // // public Version(long id) { // this.id = id; // } // // public long getId() { // return this.id; // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.GroundType; import edu.berkeley.ground.common.model.version.Version; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class StructureVersion extends Version { // the id of the Structure containing this Version @JsonProperty("structureId") private final long structureId; // the map of attribute names to types @JsonProperty("attributes")
// Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Version.java // public class Version { // private final long id; // // public Version(long id) { // this.id = id; // } // // public long getId() { // return this.id; // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/core/StructureVersion.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.GroundType; import edu.berkeley.ground.common.model.version.Version; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class StructureVersion extends Version { // the id of the Structure containing this Version @JsonProperty("structureId") private final long structureId; // the map of attribute names to types @JsonProperty("attributes")
private final Map<String, GroundType> attributes;
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/core/NodeVersionDao.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/core/NodeVersion.java // public class NodeVersion extends RichVersion { // // // the id of the Node containing this Version // @JsonProperty("nodeId") // private final long nodeId; // // /** // * Create a new node version. // * // * @param id the id of the version // * @param tags the tags associated with the version // * @param structureVersionId the id of the StructureVersion associated with this version // * @param reference an optional external reference // * @param referenceParameters the parameters associated with the reference // * @param nodeId the id of the node containing this version // */ // // @JsonCreator // public NodeVersion(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags, // @JsonProperty("structureVersionId") long structureVersionId, // @JsonProperty("reference") String reference, // @JsonProperty("referenceParameters") Map<String, String> referenceParameters, // @JsonProperty("nodeId") long nodeId) { // // super(id, tags, structureVersionId, reference, referenceParameters); // // this.nodeId = nodeId; // } // // public NodeVersion(long id, NodeVersion other) { // this(id, other, other); // } // // public NodeVersion(long id, RichVersion otherRichVersion, NodeVersion other) { // super(id, otherRichVersion); // // this.nodeId = other.nodeId; // } // // public long getNodeId() { // return this.nodeId; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof NodeVersion)) { // return false; // } // // NodeVersion otherNodeVersion = (NodeVersion) other; // // return this.nodeId == otherNodeVersion.nodeId && super.equals(other); // } // }
import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.NodeVersion; import java.util.List;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface NodeVersionDao extends RichVersionDao<NodeVersion> { @Override
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/core/NodeVersion.java // public class NodeVersion extends RichVersion { // // // the id of the Node containing this Version // @JsonProperty("nodeId") // private final long nodeId; // // /** // * Create a new node version. // * // * @param id the id of the version // * @param tags the tags associated with the version // * @param structureVersionId the id of the StructureVersion associated with this version // * @param reference an optional external reference // * @param referenceParameters the parameters associated with the reference // * @param nodeId the id of the node containing this version // */ // // @JsonCreator // public NodeVersion(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags, // @JsonProperty("structureVersionId") long structureVersionId, // @JsonProperty("reference") String reference, // @JsonProperty("referenceParameters") Map<String, String> referenceParameters, // @JsonProperty("nodeId") long nodeId) { // // super(id, tags, structureVersionId, reference, referenceParameters); // // this.nodeId = nodeId; // } // // public NodeVersion(long id, NodeVersion other) { // this(id, other, other); // } // // public NodeVersion(long id, RichVersion otherRichVersion, NodeVersion other) { // super(id, otherRichVersion); // // this.nodeId = other.nodeId; // } // // public long getNodeId() { // return this.nodeId; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof NodeVersion)) { // return false; // } // // NodeVersion otherNodeVersion = (NodeVersion) other; // // return this.nodeId == otherNodeVersion.nodeId && super.equals(other); // } // } // Path: modules/common/app/edu/berkeley/ground/common/dao/core/NodeVersionDao.java import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.NodeVersion; import java.util.List; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface NodeVersionDao extends RichVersionDao<NodeVersion> { @Override
NodeVersion create(NodeVersion nodeVersion, List<Long> parentIds) throws GroundException;
ground-context/ground
modules/postgres/app/edu/berkeley/ground/postgres/start/ApplicationStart.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // }
import edu.berkeley.ground.common.exception.GroundException; import java.time.Clock; import java.time.Instant; import java.util.concurrent.CompletableFuture; import javax.inject.Inject; import javax.inject.Singleton; import play.Logger; import play.api.Configuration; import play.db.Database; import play.inject.ApplicationLifecycle;
package edu.berkeley.ground.postgres.start; @Singleton public class ApplicationStart { private final Instant start; @Inject public ApplicationStart(Clock clock, ApplicationLifecycle appLifecycle, final Configuration configuration, final Database dbSource)
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // Path: modules/postgres/app/edu/berkeley/ground/postgres/start/ApplicationStart.java import edu.berkeley.ground.common.exception.GroundException; import java.time.Clock; import java.time.Instant; import java.util.concurrent.CompletableFuture; import javax.inject.Inject; import javax.inject.Singleton; import play.Logger; import play.api.Configuration; import play.db.Database; import play.inject.ApplicationLifecycle; package edu.berkeley.ground.postgres.start; @Singleton public class ApplicationStart { private final Instant start; @Inject public ApplicationStart(Clock clock, ApplicationLifecycle appLifecycle, final Configuration configuration, final Database dbSource)
throws GroundException {
ground-context/ground
modules/common/test/edu/berkeley/ground/common/model/versions/GroundTypeTest.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // }
import static org.junit.Assert.assertEquals; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.GroundType; import org.junit.Test;
package edu.berkeley.ground.common.model.versions; public class GroundTypeTest { @Test
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // } // Path: modules/common/test/edu/berkeley/ground/common/model/versions/GroundTypeTest.java import static org.junit.Assert.assertEquals; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.GroundType; import org.junit.Test; package edu.berkeley.ground.common.model.versions; public class GroundTypeTest { @Test
public void testGetTypeFromString() throws GroundException {
ground-context/ground
modules/common/test/edu/berkeley/ground/common/model/versions/GroundTypeTest.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // }
import static org.junit.Assert.assertEquals; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.GroundType; import org.junit.Test;
package edu.berkeley.ground.common.model.versions; public class GroundTypeTest { @Test public void testGetTypeFromString() throws GroundException {
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // } // Path: modules/common/test/edu/berkeley/ground/common/model/versions/GroundTypeTest.java import static org.junit.Assert.assertEquals; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.GroundType; import org.junit.Test; package edu.berkeley.ground.common.model.versions; public class GroundTypeTest { @Test public void testGetTypeFromString() throws GroundException {
assertEquals(GroundType.BOOLEAN, GroundType.fromString("boolean"));
ground-context/ground
modules/postgres/test/edu/berkeley/ground/postgres/dao/version/PostgresVersionHistoryDagDaoTest.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/VersionHistoryDag.java // public class VersionHistoryDag { // // // the id of the Version that's at the rootId of this DAG // private final long itemId; // // // list of VersionSuccessors that make up this DAG // private final List<Long> edgeIds; // // // map of parents to children // private final Map<Long, List<Long>> parentChildMap; // // /** // * Create a new version history DAG. // * // * @param itemId the id of the item of this DAG // * @param edges the version successors in this DAG // */ // public VersionHistoryDag(long itemId, List<VersionSuccessor> edges) { // this.itemId = itemId; // this.edgeIds = edges.stream().map(VersionSuccessor::getId).collect(Collectors.toList()); // this.parentChildMap = new HashMap<>(); // // edges.forEach(edge -> this.addToParentChildMap(edge.getFromId(), edge.getToId())); // } // // public long getItemId() { // return this.itemId; // } // // public List<Long> getEdgeIds() { // return this.edgeIds; // } // // /** // * Checks if a given ID is in the DAG. // * // * @param id the ID to be checked // * @return true if id is in the DAG, false otherwise // */ // public boolean checkItemInDag(long id) { // return this.parentChildMap.keySet().contains(id) || this.getLeaves().contains(id); // } // // /** // * Adds an edge to this DAG. // * // * @param parentId the id of the "from" of the edge // * @param childId the id of the "to" of the edge // */ // public void addEdge(long parentId, long childId, long successorId) { // this.edgeIds.add(successorId); // this.addToParentChildMap(parentId, childId); // } // // /** // * Return the parent(s) of a particular version. // * // * @param childId the query id // * @return the list of parent version(s) // */ // public List<Long> getParent(long childId) { // return this.parentChildMap // .entrySet() // .stream() // .filter(entry -> entry.getValue().contains(childId)) // .map(Map.Entry::getKey) // .collect(Collectors.toList()); // } // // public Map<Long, Long> getParentChildPairs() { // Map<Long, Long> result = new HashMap<>(); // // for (Long parent : this.parentChildMap.keySet()) { // List<Long> children = this.parentChildMap.get(parent); // // for (Long child : children) { // result.put(parent, child); // } // } // // return result; // } // // /** // * Returns the leaves of the DAG (i.e., any version id that is not a parent of another version // * id). // * // * @return the list of the IDs of the leaves of this DAG // */ // public List<Long> getLeaves() { // Set<Long> leaves = new HashSet<>(); // this.parentChildMap.values().forEach(leaves::addAll); // leaves.removeAll(this.parentChildMap.keySet()); // // return new ArrayList<>(leaves); // } // // private void addToParentChildMap(long parent, long child) { // List<Long> childList = this.parentChildMap.computeIfAbsent(parent, key -> new ArrayList<>()); // childList.add(child); // } // }
import static org.junit.Assert.assertEquals; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.VersionHistoryDag; import edu.berkeley.ground.postgres.dao.PostgresTest; import org.junit.Test;
package edu.berkeley.ground.postgres.dao.version; /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class PostgresVersionHistoryDagDaoTest extends PostgresTest { public PostgresVersionHistoryDagDaoTest() throws GroundException { super(); } @Test public void testVersionHistoryDAGCreation() throws GroundException { long testId = 1; PostgresTest.versionHistoryDagDao.create(testId);
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/VersionHistoryDag.java // public class VersionHistoryDag { // // // the id of the Version that's at the rootId of this DAG // private final long itemId; // // // list of VersionSuccessors that make up this DAG // private final List<Long> edgeIds; // // // map of parents to children // private final Map<Long, List<Long>> parentChildMap; // // /** // * Create a new version history DAG. // * // * @param itemId the id of the item of this DAG // * @param edges the version successors in this DAG // */ // public VersionHistoryDag(long itemId, List<VersionSuccessor> edges) { // this.itemId = itemId; // this.edgeIds = edges.stream().map(VersionSuccessor::getId).collect(Collectors.toList()); // this.parentChildMap = new HashMap<>(); // // edges.forEach(edge -> this.addToParentChildMap(edge.getFromId(), edge.getToId())); // } // // public long getItemId() { // return this.itemId; // } // // public List<Long> getEdgeIds() { // return this.edgeIds; // } // // /** // * Checks if a given ID is in the DAG. // * // * @param id the ID to be checked // * @return true if id is in the DAG, false otherwise // */ // public boolean checkItemInDag(long id) { // return this.parentChildMap.keySet().contains(id) || this.getLeaves().contains(id); // } // // /** // * Adds an edge to this DAG. // * // * @param parentId the id of the "from" of the edge // * @param childId the id of the "to" of the edge // */ // public void addEdge(long parentId, long childId, long successorId) { // this.edgeIds.add(successorId); // this.addToParentChildMap(parentId, childId); // } // // /** // * Return the parent(s) of a particular version. // * // * @param childId the query id // * @return the list of parent version(s) // */ // public List<Long> getParent(long childId) { // return this.parentChildMap // .entrySet() // .stream() // .filter(entry -> entry.getValue().contains(childId)) // .map(Map.Entry::getKey) // .collect(Collectors.toList()); // } // // public Map<Long, Long> getParentChildPairs() { // Map<Long, Long> result = new HashMap<>(); // // for (Long parent : this.parentChildMap.keySet()) { // List<Long> children = this.parentChildMap.get(parent); // // for (Long child : children) { // result.put(parent, child); // } // } // // return result; // } // // /** // * Returns the leaves of the DAG (i.e., any version id that is not a parent of another version // * id). // * // * @return the list of the IDs of the leaves of this DAG // */ // public List<Long> getLeaves() { // Set<Long> leaves = new HashSet<>(); // this.parentChildMap.values().forEach(leaves::addAll); // leaves.removeAll(this.parentChildMap.keySet()); // // return new ArrayList<>(leaves); // } // // private void addToParentChildMap(long parent, long child) { // List<Long> childList = this.parentChildMap.computeIfAbsent(parent, key -> new ArrayList<>()); // childList.add(child); // } // } // Path: modules/postgres/test/edu/berkeley/ground/postgres/dao/version/PostgresVersionHistoryDagDaoTest.java import static org.junit.Assert.assertEquals; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.VersionHistoryDag; import edu.berkeley.ground.postgres.dao.PostgresTest; import org.junit.Test; package edu.berkeley.ground.postgres.dao.version; /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class PostgresVersionHistoryDagDaoTest extends PostgresTest { public PostgresVersionHistoryDagDaoTest() throws GroundException { super(); } @Test public void testVersionHistoryDAGCreation() throws GroundException { long testId = 1; PostgresTest.versionHistoryDagDao.create(testId);
VersionHistoryDag dag = PostgresTest.versionHistoryDagDao.retrieveFromDatabase(testId);
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/version/VersionSuccessorDao.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/VersionSuccessor.java // public class VersionSuccessor { // // private final long id; // // private final long fromId; // // private final long toId; // // /** // * Create a version successor. // * // * @param id the id of the successor // * @param fromId the source id // * @param toId the destination id // */ // public VersionSuccessor(long id, long fromId, long toId) { // this.id = id; // this.fromId = fromId; // this.toId = toId; // } // // public long getId() { // return this.id; // } // // public long getFromId() { // return this.fromId; // } // // public long getToId() { // return this.toId; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/util/DbStatements.java // public interface DbStatements<T> { // // void append(T statement); // // void merge(DbStatements other); // // List<T> getAllStatements(); // // }
import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.VersionSuccessor; import edu.berkeley.ground.common.util.DbStatements;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.version; public interface VersionSuccessorDao { DbStatements insert(VersionSuccessor successor);
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/VersionSuccessor.java // public class VersionSuccessor { // // private final long id; // // private final long fromId; // // private final long toId; // // /** // * Create a version successor. // * // * @param id the id of the successor // * @param fromId the source id // * @param toId the destination id // */ // public VersionSuccessor(long id, long fromId, long toId) { // this.id = id; // this.fromId = fromId; // this.toId = toId; // } // // public long getId() { // return this.id; // } // // public long getFromId() { // return this.fromId; // } // // public long getToId() { // return this.toId; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/util/DbStatements.java // public interface DbStatements<T> { // // void append(T statement); // // void merge(DbStatements other); // // List<T> getAllStatements(); // // } // Path: modules/common/app/edu/berkeley/ground/common/dao/version/VersionSuccessorDao.java import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.VersionSuccessor; import edu.berkeley.ground.common.util.DbStatements; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.version; public interface VersionSuccessorDao { DbStatements insert(VersionSuccessor successor);
VersionSuccessor retrieveFromDatabase(long dbId) throws GroundException;
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/version/TagDao.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/util/DbStatements.java // public interface DbStatements<T> { // // void append(T statement); // // void merge(DbStatements other); // // List<T> getAllStatements(); // // }
import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.Tag; import edu.berkeley.ground.common.util.DbStatements; import java.util.List; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.version; public interface TagDao { List<Long> getVersionIdsByTag(String tag) throws GroundException; List<Long> getItemIdsByTag(String tag) throws GroundException;
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/util/DbStatements.java // public interface DbStatements<T> { // // void append(T statement); // // void merge(DbStatements other); // // List<T> getAllStatements(); // // } // Path: modules/common/app/edu/berkeley/ground/common/dao/version/TagDao.java import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.Tag; import edu.berkeley.ground.common.util.DbStatements; import java.util.List; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.version; public interface TagDao { List<Long> getVersionIdsByTag(String tag) throws GroundException; List<Long> getItemIdsByTag(String tag) throws GroundException;
Map<String, Tag> retrieveFromDatabaseByVersionId(long id) throws GroundException;
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/version/TagDao.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/util/DbStatements.java // public interface DbStatements<T> { // // void append(T statement); // // void merge(DbStatements other); // // List<T> getAllStatements(); // // }
import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.Tag; import edu.berkeley.ground.common.util.DbStatements; import java.util.List; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.version; public interface TagDao { List<Long> getVersionIdsByTag(String tag) throws GroundException; List<Long> getItemIdsByTag(String tag) throws GroundException; Map<String, Tag> retrieveFromDatabaseByVersionId(long id) throws GroundException; Map<String, Tag> retrieveFromDatabaseByItemId(long id) throws GroundException;
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/util/DbStatements.java // public interface DbStatements<T> { // // void append(T statement); // // void merge(DbStatements other); // // List<T> getAllStatements(); // // } // Path: modules/common/app/edu/berkeley/ground/common/dao/version/TagDao.java import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.version.Tag; import edu.berkeley.ground.common.util.DbStatements; import java.util.List; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.version; public interface TagDao { List<Long> getVersionIdsByTag(String tag) throws GroundException; List<Long> getItemIdsByTag(String tag) throws GroundException; Map<String, Tag> retrieveFromDatabaseByVersionId(long id) throws GroundException; Map<String, Tag> retrieveFromDatabaseByItemId(long id) throws GroundException;
DbStatements insertItemTag(final Tag tag);
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/core/EdgeVersionDao.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // }
import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.EdgeVersion; import java.util.List;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface EdgeVersionDao extends RichVersionDao<EdgeVersion> { @Override
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // Path: modules/common/app/edu/berkeley/ground/common/dao/core/EdgeVersionDao.java import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.EdgeVersion; import java.util.List; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface EdgeVersionDao extends RichVersionDao<EdgeVersion> { @Override
EdgeVersion create(EdgeVersion nodeVersion, List<Long> parentIds) throws GroundException;
ground-context/ground
modules/common/test/edu/berkeley/ground/common/model/core/StructureVersionTest.java
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String convertFromClassToString(Object object) { // return Json.stringify(Json.toJson(object)); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static Object convertFromStringToClass(String body, Class<?> klass) { // return Json.fromJson(Json.parse(body), klass); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String readFromFile(String filename) throws GroundException { // try { // String content = new Scanner(new File(filename)).useDelimiter("\\Z").next(); // // return content; // } catch (FileNotFoundException e) { // throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename)); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // }
import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromClassToString; import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromStringToClass; import static edu.berkeley.ground.common.util.ModelTestUtils.readFromFile; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import edu.berkeley.ground.common.model.version.GroundType; import java.util.HashMap; import java.util.Map; import org.junit.Test;
/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class StructureVersionTest { @Test public void serializesToJSON() throws Exception {
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String convertFromClassToString(Object object) { // return Json.stringify(Json.toJson(object)); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static Object convertFromStringToClass(String body, Class<?> klass) { // return Json.fromJson(Json.parse(body), klass); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String readFromFile(String filename) throws GroundException { // try { // String content = new Scanner(new File(filename)).useDelimiter("\\Z").next(); // // return content; // } catch (FileNotFoundException e) { // throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename)); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // } // Path: modules/common/test/edu/berkeley/ground/common/model/core/StructureVersionTest.java import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromClassToString; import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromStringToClass; import static edu.berkeley.ground.common.util.ModelTestUtils.readFromFile; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import edu.berkeley.ground.common.model.version.GroundType; import java.util.HashMap; import java.util.Map; import org.junit.Test; /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class StructureVersionTest { @Test public void serializesToJSON() throws Exception {
Map<String, GroundType> attributes = new HashMap<>();
ground-context/ground
modules/common/test/edu/berkeley/ground/common/model/core/StructureVersionTest.java
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String convertFromClassToString(Object object) { // return Json.stringify(Json.toJson(object)); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static Object convertFromStringToClass(String body, Class<?> klass) { // return Json.fromJson(Json.parse(body), klass); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String readFromFile(String filename) throws GroundException { // try { // String content = new Scanner(new File(filename)).useDelimiter("\\Z").next(); // // return content; // } catch (FileNotFoundException e) { // throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename)); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // }
import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromClassToString; import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromStringToClass; import static edu.berkeley.ground.common.util.ModelTestUtils.readFromFile; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import edu.berkeley.ground.common.model.version.GroundType; import java.util.HashMap; import java.util.Map; import org.junit.Test;
/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class StructureVersionTest { @Test public void serializesToJSON() throws Exception { Map<String, GroundType> attributes = new HashMap<>(); attributes.put("tag1", GroundType.INTEGER); attributes.put("tag2", GroundType.STRING); StructureVersion structureVersion = new StructureVersion(1, 1, attributes);
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String convertFromClassToString(Object object) { // return Json.stringify(Json.toJson(object)); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static Object convertFromStringToClass(String body, Class<?> klass) { // return Json.fromJson(Json.parse(body), klass); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String readFromFile(String filename) throws GroundException { // try { // String content = new Scanner(new File(filename)).useDelimiter("\\Z").next(); // // return content; // } catch (FileNotFoundException e) { // throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename)); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // } // Path: modules/common/test/edu/berkeley/ground/common/model/core/StructureVersionTest.java import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromClassToString; import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromStringToClass; import static edu.berkeley.ground.common.util.ModelTestUtils.readFromFile; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import edu.berkeley.ground.common.model.version.GroundType; import java.util.HashMap; import java.util.Map; import org.junit.Test; /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class StructureVersionTest { @Test public void serializesToJSON() throws Exception { Map<String, GroundType> attributes = new HashMap<>(); attributes.put("tag1", GroundType.INTEGER); attributes.put("tag2", GroundType.STRING); StructureVersion structureVersion = new StructureVersion(1, 1, attributes);
final String expected = convertFromClassToString(convertFromStringToClass(readFromFile
ground-context/ground
modules/common/test/edu/berkeley/ground/common/model/core/StructureVersionTest.java
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String convertFromClassToString(Object object) { // return Json.stringify(Json.toJson(object)); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static Object convertFromStringToClass(String body, Class<?> klass) { // return Json.fromJson(Json.parse(body), klass); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String readFromFile(String filename) throws GroundException { // try { // String content = new Scanner(new File(filename)).useDelimiter("\\Z").next(); // // return content; // } catch (FileNotFoundException e) { // throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename)); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // }
import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromClassToString; import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromStringToClass; import static edu.berkeley.ground.common.util.ModelTestUtils.readFromFile; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import edu.berkeley.ground.common.model.version.GroundType; import java.util.HashMap; import java.util.Map; import org.junit.Test;
/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class StructureVersionTest { @Test public void serializesToJSON() throws Exception { Map<String, GroundType> attributes = new HashMap<>(); attributes.put("tag1", GroundType.INTEGER); attributes.put("tag2", GroundType.STRING); StructureVersion structureVersion = new StructureVersion(1, 1, attributes);
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String convertFromClassToString(Object object) { // return Json.stringify(Json.toJson(object)); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static Object convertFromStringToClass(String body, Class<?> klass) { // return Json.fromJson(Json.parse(body), klass); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String readFromFile(String filename) throws GroundException { // try { // String content = new Scanner(new File(filename)).useDelimiter("\\Z").next(); // // return content; // } catch (FileNotFoundException e) { // throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename)); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // } // Path: modules/common/test/edu/berkeley/ground/common/model/core/StructureVersionTest.java import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromClassToString; import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromStringToClass; import static edu.berkeley.ground.common.util.ModelTestUtils.readFromFile; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import edu.berkeley.ground.common.model.version.GroundType; import java.util.HashMap; import java.util.Map; import org.junit.Test; /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class StructureVersionTest { @Test public void serializesToJSON() throws Exception { Map<String, GroundType> attributes = new HashMap<>(); attributes.put("tag1", GroundType.INTEGER); attributes.put("tag2", GroundType.STRING); StructureVersion structureVersion = new StructureVersion(1, 1, attributes);
final String expected = convertFromClassToString(convertFromStringToClass(readFromFile
ground-context/ground
modules/common/test/edu/berkeley/ground/common/model/core/StructureVersionTest.java
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String convertFromClassToString(Object object) { // return Json.stringify(Json.toJson(object)); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static Object convertFromStringToClass(String body, Class<?> klass) { // return Json.fromJson(Json.parse(body), klass); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String readFromFile(String filename) throws GroundException { // try { // String content = new Scanner(new File(filename)).useDelimiter("\\Z").next(); // // return content; // } catch (FileNotFoundException e) { // throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename)); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // }
import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromClassToString; import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromStringToClass; import static edu.berkeley.ground.common.util.ModelTestUtils.readFromFile; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import edu.berkeley.ground.common.model.version.GroundType; import java.util.HashMap; import java.util.Map; import org.junit.Test;
/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class StructureVersionTest { @Test public void serializesToJSON() throws Exception { Map<String, GroundType> attributes = new HashMap<>(); attributes.put("tag1", GroundType.INTEGER); attributes.put("tag2", GroundType.STRING); StructureVersion structureVersion = new StructureVersion(1, 1, attributes);
// Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String convertFromClassToString(Object object) { // return Json.stringify(Json.toJson(object)); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static Object convertFromStringToClass(String body, Class<?> klass) { // return Json.fromJson(Json.parse(body), klass); // } // // Path: modules/common/test/edu/berkeley/ground/common/util/ModelTestUtils.java // public static String readFromFile(String filename) throws GroundException { // try { // String content = new Scanner(new File(filename)).useDelimiter("\\Z").next(); // // return content; // } catch (FileNotFoundException e) { // throw new GroundException(ExceptionType.OTHER, String.format("File %s not found", filename)); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java // public enum GroundType { // STRING(String.class, "string", Types.VARCHAR) { // @Override // public Object parse(String str) { // return str; // } // }, // INTEGER(Integer.class, "integer", Types.INTEGER) { // @Override // public Object parse(String str) { // return Integer.parseInt(str); // } // }, // BOOLEAN(Boolean.class, "boolean", Types.BOOLEAN) { // @Override // public Object parse(String str) { // return Boolean.parseBoolean(str); // } // }, // LONG(Long.class, "long", Types.BIGINT) { // @Override // public Object parse(String str) { // return Long.parseLong(str); // } // }; // // private final Class<?> klass; // private final String name; // private final int sqlType; // // GroundType(Class<?> klass, String name, int sqlType) { // this.klass = klass; // this.name = name; // this.sqlType = sqlType; // } // // /** // * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType // * // * @return an integer the corresponding SQL Type // */ // public int getSqlType() { // return sqlType; // } // // public abstract Object parse(String str); // // public Class<?> getTypeClass() { // return this.klass; // } // // /** // * Return a type based on the string name. // * // * @param str the name of the type // * @return the corresponding GroundType // * @throws GroundException no such type // */ // @JsonCreator // public static GroundType fromString(String str) throws GroundException { // if (str == null) { // return null; // } // try { // return GroundType.valueOf(str.toUpperCase()); // } catch (IllegalArgumentException iae) { // throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str)); // } // } // // @Override // public String toString() { // return this.name; // } // } // Path: modules/common/test/edu/berkeley/ground/common/model/core/StructureVersionTest.java import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromClassToString; import static edu.berkeley.ground.common.util.ModelTestUtils.convertFromStringToClass; import static edu.berkeley.ground.common.util.ModelTestUtils.readFromFile; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import edu.berkeley.ground.common.model.version.GroundType; import java.util.HashMap; import java.util.Map; import org.junit.Test; /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class StructureVersionTest { @Test public void serializesToJSON() throws Exception { Map<String, GroundType> attributes = new HashMap<>(); attributes.put("tag1", GroundType.INTEGER); attributes.put("tag2", GroundType.STRING); StructureVersion structureVersion = new StructureVersion(1, 1, attributes);
final String expected = convertFromClassToString(convertFromStringToClass(readFromFile
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // }
import java.sql.Types; import com.fasterxml.jackson.annotation.JsonCreator; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType;
GroundType(Class<?> klass, String name, int sqlType) { this.klass = klass; this.name = name; this.sqlType = sqlType; } /** * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType * * @return an integer the corresponding SQL Type */ public int getSqlType() { return sqlType; } public abstract Object parse(String str); public Class<?> getTypeClass() { return this.klass; } /** * Return a type based on the string name. * * @param str the name of the type * @return the corresponding GroundType * @throws GroundException no such type */ @JsonCreator
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java import java.sql.Types; import com.fasterxml.jackson.annotation.JsonCreator; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; GroundType(Class<?> klass, String name, int sqlType) { this.klass = klass; this.name = name; this.sqlType = sqlType; } /** * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType * * @return an integer the corresponding SQL Type */ public int getSqlType() { return sqlType; } public abstract Object parse(String str); public Class<?> getTypeClass() { return this.klass; } /** * Return a type based on the string name. * * @param str the name of the type * @return the corresponding GroundType * @throws GroundException no such type */ @JsonCreator
public static GroundType fromString(String str) throws GroundException {
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // }
import java.sql.Types; import com.fasterxml.jackson.annotation.JsonCreator; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType;
/** * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType * * @return an integer the corresponding SQL Type */ public int getSqlType() { return sqlType; } public abstract Object parse(String str); public Class<?> getTypeClass() { return this.klass; } /** * Return a type based on the string name. * * @param str the name of the type * @return the corresponding GroundType * @throws GroundException no such type */ @JsonCreator public static GroundType fromString(String str) throws GroundException { if (str == null) { return null; } try { return GroundType.valueOf(str.toUpperCase()); } catch (IllegalArgumentException iae) {
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/version/GroundType.java import java.sql.Types; import com.fasterxml.jackson.annotation.JsonCreator; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; /** * Returns the SQL type as defined in java.sql.Types corresponding to this GroundType * * @return an integer the corresponding SQL Type */ public int getSqlType() { return sqlType; } public abstract Object parse(String str); public Class<?> getTypeClass() { return this.klass; } /** * Return a type based on the string name. * * @param str the name of the type * @return the corresponding GroundType * @throws GroundException no such type */ @JsonCreator public static GroundType fromString(String str) throws GroundException { if (str == null) { return null; } try { return GroundType.valueOf(str.toUpperCase()); } catch (IllegalArgumentException iae) {
throw new GroundException(ExceptionType.OTHER, String.format("Invalid type: %s.", str));
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/util/DbStatements.java // public interface DbStatements<T> { // // void append(T statement); // // void merge(DbStatements other); // // List<T> getAllStatements(); // // }
import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.util.DbStatements; import java.util.List; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.version; public interface ItemDao<T extends Item> { T create(T item) throws GroundException;
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/util/DbStatements.java // public interface DbStatements<T> { // // void append(T statement); // // void merge(DbStatements other); // // List<T> getAllStatements(); // // } // Path: modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.util.DbStatements; import java.util.List; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.version; public interface ItemDao<T extends Item> { T create(T item) throws GroundException;
DbStatements insert(T item) throws GroundException;
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/util/DbStatements.java // public interface DbStatements<T> { // // void append(T statement); // // void merge(DbStatements other); // // List<T> getAllStatements(); // // }
import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.util.DbStatements; import java.util.List; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.version; public interface ItemDao<T extends Item> { T create(T item) throws GroundException; DbStatements insert(T item) throws GroundException; T retrieveFromDatabase(long id) throws GroundException; T retrieveFromDatabase(String sourceKey) throws GroundException; Class<T> getType(); List<Long> getLeaves(long itemId) throws GroundException; Map<Long, Long> getHistory(long itemId) throws GroundException; /** * Add a new Version to this Item. The provided parentIds will be the parents of this particular * version. What's provided in the default case varies based on which database we are writing * into. * * @param itemId the id of the Item we're updating * @param childId the new version's id * @param parentIds the ids of the parents of the child */ DbStatements update(long itemId, long childId, List<Long> parentIds) throws GroundException; /** * Truncate the item to only have the most recent levels. * * @param numLevels the levels to keep * @throws GroundException an error while removing versions */ void truncate(long itemId, int numLevels) throws GroundException; default boolean checkIfItemExists(String sourceKey) { try { this.retrieveFromDatabase(sourceKey); return true; } catch (GroundException e) { return false; } } default void verifyItemNotExists(String sourceKey) throws GroundException { if (checkIfItemExists(sourceKey)) {
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/util/DbStatements.java // public interface DbStatements<T> { // // void append(T statement); // // void merge(DbStatements other); // // List<T> getAllStatements(); // // } // Path: modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.util.DbStatements; import java.util.List; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.version; public interface ItemDao<T extends Item> { T create(T item) throws GroundException; DbStatements insert(T item) throws GroundException; T retrieveFromDatabase(long id) throws GroundException; T retrieveFromDatabase(String sourceKey) throws GroundException; Class<T> getType(); List<Long> getLeaves(long itemId) throws GroundException; Map<Long, Long> getHistory(long itemId) throws GroundException; /** * Add a new Version to this Item. The provided parentIds will be the parents of this particular * version. What's provided in the default case varies based on which database we are writing * into. * * @param itemId the id of the Item we're updating * @param childId the new version's id * @param parentIds the ids of the parents of the child */ DbStatements update(long itemId, long childId, List<Long> parentIds) throws GroundException; /** * Truncate the item to only have the most recent levels. * * @param numLevels the levels to keep * @throws GroundException an error while removing versions */ void truncate(long itemId, int numLevels) throws GroundException; default boolean checkIfItemExists(String sourceKey) { try { this.retrieveFromDatabase(sourceKey); return true; } catch (GroundException e) { return false; } } default void verifyItemNotExists(String sourceKey) throws GroundException { if (checkIfItemExists(sourceKey)) {
throw new GroundException(ExceptionType.ITEM_ALREADY_EXISTS, this.getType().getSimpleName(), sourceKey);
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/core/Structure.java
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.model.version.Tag; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class Structure extends Item { // the name of this Structure @JsonProperty("name") private final String name; // the source key for this Node @JsonProperty("sourceKey") private final String sourceKey; /** * Create a new structure. * * @param id the id of the structure * @param name the name of the structure * @param sourceKey the user-generated unique key for the structure * @param tags the tags associated with this structure */ @JsonCreator public Structure( @JsonProperty("itemId") long id, @JsonProperty("name") String name, @JsonProperty("sourceKey") String sourceKey,
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/core/Structure.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.model.version.Tag; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.core; public class Structure extends Item { // the name of this Structure @JsonProperty("name") private final String name; // the source key for this Node @JsonProperty("sourceKey") private final String sourceKey; /** * Create a new structure. * * @param id the id of the structure * @param name the name of the structure * @param sourceKey the user-generated unique key for the structure * @param tags the tags associated with this structure */ @JsonCreator public Structure( @JsonProperty("itemId") long id, @JsonProperty("name") String name, @JsonProperty("sourceKey") String sourceKey,
@JsonProperty("tags") Map<String, Tag> tags) {
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/core/GraphDao.java
// Path: modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java // public interface ItemDao<T extends Item> { // // T create(T item) throws GroundException; // // DbStatements insert(T item) throws GroundException; // // T retrieveFromDatabase(long id) throws GroundException; // // T retrieveFromDatabase(String sourceKey) throws GroundException; // // Class<T> getType(); // // List<Long> getLeaves(long itemId) throws GroundException; // // Map<Long, Long> getHistory(long itemId) throws GroundException; // // /** // * Add a new Version to this Item. The provided parentIds will be the parents of this particular // * version. What's provided in the default case varies based on which database we are writing // * into. // * // * @param itemId the id of the Item we're updating // * @param childId the new version's id // * @param parentIds the ids of the parents of the child // */ // DbStatements update(long itemId, long childId, List<Long> parentIds) throws GroundException; // // /** // * Truncate the item to only have the most recent levels. // * // * @param numLevels the levels to keep // * @throws GroundException an error while removing versions // */ // void truncate(long itemId, int numLevels) throws GroundException; // // default boolean checkIfItemExists(String sourceKey) { // try { // this.retrieveFromDatabase(sourceKey); // // return true; // } catch (GroundException e) { // return false; // } // } // // default void verifyItemNotExists(String sourceKey) throws GroundException { // if (checkIfItemExists(sourceKey)) { // throw new GroundException(ExceptionType.ITEM_ALREADY_EXISTS, this.getType().getSimpleName(), sourceKey); // } // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/core/Graph.java // public class Graph extends Item { // // // the name of this Graph // @JsonProperty("name") // private final String name; // // // the source key for this Graph // @JsonProperty("sourceKey") // private final String sourceKey; // // /** // * Create a new Graph. // * // * @param id the id of the graph // * @param name the name of the graph // * @param sourceKey the user-generated unique key for the graph // * @param tags the tags associated with the graph // */ // @JsonCreator // public Graph(@JsonProperty("itemId") long id, // @JsonProperty("name") String name, // @JsonProperty("sourceKey") String sourceKey, // @JsonProperty("tags") Map<String, Tag> tags) { // super(id, tags); // // this.name = name; // this.sourceKey = sourceKey; // } // // public Graph(long id, Graph other) { // super(id, other.getTags()); // // this.name = other.name; // this.sourceKey = other.sourceKey; // } // // public String getName() { // return this.name; // } // // public String getSourceKey() { // return this.sourceKey; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Graph)) { // return false; // } // // Graph otherGraph = (Graph) other; // // return this.name.equals(otherGraph.name) // && this.getId() == otherGraph.getId() // && this.sourceKey.equals(otherGraph.sourceKey) // && this.getTags().equals(otherGraph.getTags()); // } // }
import edu.berkeley.ground.common.dao.version.ItemDao; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.Graph; import java.util.List; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface GraphDao extends ItemDao<Graph> { @Override default Class<Graph> getType() { return Graph.class; } @Override
// Path: modules/common/app/edu/berkeley/ground/common/dao/version/ItemDao.java // public interface ItemDao<T extends Item> { // // T create(T item) throws GroundException; // // DbStatements insert(T item) throws GroundException; // // T retrieveFromDatabase(long id) throws GroundException; // // T retrieveFromDatabase(String sourceKey) throws GroundException; // // Class<T> getType(); // // List<Long> getLeaves(long itemId) throws GroundException; // // Map<Long, Long> getHistory(long itemId) throws GroundException; // // /** // * Add a new Version to this Item. The provided parentIds will be the parents of this particular // * version. What's provided in the default case varies based on which database we are writing // * into. // * // * @param itemId the id of the Item we're updating // * @param childId the new version's id // * @param parentIds the ids of the parents of the child // */ // DbStatements update(long itemId, long childId, List<Long> parentIds) throws GroundException; // // /** // * Truncate the item to only have the most recent levels. // * // * @param numLevels the levels to keep // * @throws GroundException an error while removing versions // */ // void truncate(long itemId, int numLevels) throws GroundException; // // default boolean checkIfItemExists(String sourceKey) { // try { // this.retrieveFromDatabase(sourceKey); // // return true; // } catch (GroundException e) { // return false; // } // } // // default void verifyItemNotExists(String sourceKey) throws GroundException { // if (checkIfItemExists(sourceKey)) { // throw new GroundException(ExceptionType.ITEM_ALREADY_EXISTS, this.getType().getSimpleName(), sourceKey); // } // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/core/Graph.java // public class Graph extends Item { // // // the name of this Graph // @JsonProperty("name") // private final String name; // // // the source key for this Graph // @JsonProperty("sourceKey") // private final String sourceKey; // // /** // * Create a new Graph. // * // * @param id the id of the graph // * @param name the name of the graph // * @param sourceKey the user-generated unique key for the graph // * @param tags the tags associated with the graph // */ // @JsonCreator // public Graph(@JsonProperty("itemId") long id, // @JsonProperty("name") String name, // @JsonProperty("sourceKey") String sourceKey, // @JsonProperty("tags") Map<String, Tag> tags) { // super(id, tags); // // this.name = name; // this.sourceKey = sourceKey; // } // // public Graph(long id, Graph other) { // super(id, other.getTags()); // // this.name = other.name; // this.sourceKey = other.sourceKey; // } // // public String getName() { // return this.name; // } // // public String getSourceKey() { // return this.sourceKey; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Graph)) { // return false; // } // // Graph otherGraph = (Graph) other; // // return this.name.equals(otherGraph.name) // && this.getId() == otherGraph.getId() // && this.sourceKey.equals(otherGraph.sourceKey) // && this.getTags().equals(otherGraph.getTags()); // } // } // Path: modules/common/app/edu/berkeley/ground/common/dao/core/GraphDao.java import edu.berkeley.ground.common.dao.version.ItemDao; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.Graph; import java.util.List; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface GraphDao extends ItemDao<Graph> { @Override default Class<Graph> getType() { return Graph.class; } @Override
Graph retrieveFromDatabase(final String sourceKey) throws GroundException;
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/version/Tag.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; import java.util.Objects;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.version; public class Tag { @JsonProperty("id") private long id; @JsonProperty("key") private final String key; @JsonProperty("value") private final Object value; @JsonProperty("type") private final GroundType valueType; /** * Create a new tag. * * @param id the id of the version containing this tag * @param key the key of the tag * @param value the value of the tag * @param valueType the type of the value */ @JsonCreator public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, @JsonProperty("type") GroundType valueType)
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; import java.util.Objects; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.version; public class Tag { @JsonProperty("id") private long id; @JsonProperty("key") private final String key; @JsonProperty("value") private final Object value; @JsonProperty("type") private final GroundType valueType; /** * Create a new tag. * * @param id the id of the version containing this tag * @param key the key of the tag * @param value the value of the tag * @param valueType the type of the value */ @JsonCreator public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, @JsonProperty("type") GroundType valueType)
throws edu.berkeley.ground.common.exception.GroundException {
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/version/Tag.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; import java.util.Objects;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.version; public class Tag { @JsonProperty("id") private long id; @JsonProperty("key") private final String key; @JsonProperty("value") private final Object value; @JsonProperty("type") private final GroundType valueType; /** * Create a new tag. * * @param id the id of the version containing this tag * @param key the key of the tag * @param value the value of the tag * @param valueType the type of the value */ @JsonCreator public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, @JsonProperty("type") GroundType valueType) throws edu.berkeley.ground.common.exception.GroundException { if (!((value != null) == (valueType != null)) || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) {
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.exception.GroundException.ExceptionType; import java.util.Objects; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.version; public class Tag { @JsonProperty("id") private long id; @JsonProperty("key") private final String key; @JsonProperty("value") private final Object value; @JsonProperty("type") private final GroundType valueType; /** * Create a new tag. * * @param id the id of the version containing this tag * @param key the key of the tag * @param value the value of the tag * @param valueType the type of the value */ @JsonCreator public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, @JsonProperty("type") GroundType valueType) throws edu.berkeley.ground.common.exception.GroundException { if (!((value != null) == (valueType != null)) || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) {
throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ").");
ground-context/ground
modules/postgres/test/edu/berkeley/ground/postgres/dao/core/PostgresEdgeVersionDaoTest.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // }
import static org.junit.Assert.assertEquals; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.EdgeVersion; import edu.berkeley.ground.common.model.version.Tag; import edu.berkeley.ground.postgres.dao.PostgresTest; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.Test;
package edu.berkeley.ground.postgres.dao.core; /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class PostgresEdgeVersionDaoTest extends PostgresTest { public PostgresEdgeVersionDaoTest() throws GroundException { super(); } @Test public void testEdgeVersionCreation() throws GroundException { String firstTestNode = "firstTestNode"; long firstTestNodeId = PostgresTest.createNode(firstTestNode).getId(); long firstNodeVersionId = PostgresTest.createNodeVersion(firstTestNodeId).getId(); String secondTestNode = "secondTestNode"; long secondTestNodeId = PostgresTest.createNode(secondTestNode).getId(); long secondNodeVersionId = PostgresTest.createNodeVersion(secondTestNodeId).getId(); String edgeName = "testEdge"; long edgeId = PostgresTest.createEdge(edgeName, firstTestNode, secondTestNode).getId(); String structureName = "testStructure"; long structureId = PostgresTest.createStructure(structureName).getId(); long structureVersionId = PostgresTest.createStructureVersion(structureId).getId();
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // Path: modules/postgres/test/edu/berkeley/ground/postgres/dao/core/PostgresEdgeVersionDaoTest.java import static org.junit.Assert.assertEquals; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.EdgeVersion; import edu.berkeley.ground.common.model.version.Tag; import edu.berkeley.ground.postgres.dao.PostgresTest; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.Test; package edu.berkeley.ground.postgres.dao.core; /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class PostgresEdgeVersionDaoTest extends PostgresTest { public PostgresEdgeVersionDaoTest() throws GroundException { super(); } @Test public void testEdgeVersionCreation() throws GroundException { String firstTestNode = "firstTestNode"; long firstTestNodeId = PostgresTest.createNode(firstTestNode).getId(); long firstNodeVersionId = PostgresTest.createNodeVersion(firstTestNodeId).getId(); String secondTestNode = "secondTestNode"; long secondTestNodeId = PostgresTest.createNode(secondTestNode).getId(); long secondNodeVersionId = PostgresTest.createNodeVersion(secondTestNodeId).getId(); String edgeName = "testEdge"; long edgeId = PostgresTest.createEdge(edgeName, firstTestNode, secondTestNode).getId(); String structureName = "testStructure"; long structureId = PostgresTest.createStructure(structureName).getId(); long structureVersionId = PostgresTest.createStructureVersion(structureId).getId();
Map<String, Tag> tags = PostgresTest.createTags();
ground-context/ground
modules/postgres/app/edu/berkeley/ground/postgres/util/PostgresUtils.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // }
import akka.actor.ActorSystem; import com.google.common.base.CaseFormat; import edu.berkeley.ground.common.exception.GroundException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Executor; import play.Logger; import play.db.Database; import play.libs.concurrent.HttpExecution;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.postgres.util; public final class PostgresUtils { private PostgresUtils() { } public static Executor getDbSourceHttpContext(final ActorSystem actorSystem) { return HttpExecution.fromThread((Executor) actorSystem.dispatchers().lookup("ground.db.context")); }
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // Path: modules/postgres/app/edu/berkeley/ground/postgres/util/PostgresUtils.java import akka.actor.ActorSystem; import com.google.common.base.CaseFormat; import edu.berkeley.ground.common.exception.GroundException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Executor; import play.Logger; import play.db.Database; import play.libs.concurrent.HttpExecution; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.postgres.util; public final class PostgresUtils { private PostgresUtils() { } public static Executor getDbSourceHttpContext(final ActorSystem actorSystem) { return HttpExecution.fromThread((Executor) actorSystem.dispatchers().lookup("ground.db.context")); }
public static String executeQueryToJson(Database dbSource, String sql) throws GroundException {
ground-context/ground
modules/common/app/edu/berkeley/ground/common/model/usage/LineageEdge.java
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.model.version.Tag; import java.util.Map;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.usage; public class LineageEdge extends Item { // the name of this LineageEdge @JsonProperty("name") private final String name; // the source key for this Node @JsonProperty("sourceKey") private final String sourceKey; /** * Create a new lineage edge. * * @param id the id of the lineage edge * @param name the name of the lineage edge * @param sourceKey the user-generated unique key for the lineage edge * @param tags the tags associated with this lineage edge */ @JsonCreator public LineageEdge(@JsonProperty("itemId") long id, @JsonProperty("name") String name,
// Path: modules/common/app/edu/berkeley/ground/common/model/version/Item.java // public class Item { // // @JsonProperty("id") // private final long id; // // @JsonProperty("tags") // private final Map<String, Tag> tags; // // @JsonCreator // public Item(@JsonProperty("id") long id, @JsonProperty("tags") Map<String, Tag> tags) { // this.id = id; // // if (tags == null) { // this.tags = new HashMap<>(); // } else { // this.tags = tags; // } // } // // public long getId() { // return this.id; // } // // public Map<String, Tag> getTags() { // return this.tags; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/version/Tag.java // public class Tag { // // @JsonProperty("id") // private long id; // // @JsonProperty("key") // private final String key; // // @JsonProperty("value") // private final Object value; // // @JsonProperty("type") // private final GroundType valueType; // // /** // * Create a new tag. // * // * @param id the id of the version containing this tag // * @param key the key of the tag // * @param value the value of the tag // * @param valueType the type of the value // */ // @JsonCreator // public Tag(@JsonProperty("item_id") long id, @JsonProperty("key") String key, @JsonProperty("value") Object value, // @JsonProperty("type") GroundType valueType) // throws edu.berkeley.ground.common.exception.GroundException { // // if (!((value != null) == (valueType != null)) // || (value != null && !(value.getClass().equals(valueType.getTypeClass())))) { // // throw new GroundException(ExceptionType.OTHER, "Mismatch between value (" + value + ") and given type (" + valueType.toString() + ")."); // } // // if (value != null) { // assert (value.getClass().equals(valueType.getTypeClass())); // } // // this.id = id; // this.key = key; // this.value = value; // this.valueType = valueType; // } // // public long getId() { // return this.id; // } // // public String getKey() { // return this.key; // } // // public Object getValue() { // return this.value; // } // // public GroundType getValueType() { // return this.valueType; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof Tag)) { // return false; // } // // Tag otherTag = (Tag) other; // // return this.key.equals(otherTag.key) // && Objects.equals(this.value, otherTag.value) // && Objects.equals(this.valueType, otherTag.valueType); // } // } // Path: modules/common/app/edu/berkeley/ground/common/model/usage/LineageEdge.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import edu.berkeley.ground.common.model.version.Item; import edu.berkeley.ground.common.model.version.Tag; import java.util.Map; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.model.usage; public class LineageEdge extends Item { // the name of this LineageEdge @JsonProperty("name") private final String name; // the source key for this Node @JsonProperty("sourceKey") private final String sourceKey; /** * Create a new lineage edge. * * @param id the id of the lineage edge * @param name the name of the lineage edge * @param sourceKey the user-generated unique key for the lineage edge * @param tags the tags associated with this lineage edge */ @JsonCreator public LineageEdge(@JsonProperty("itemId") long id, @JsonProperty("name") String name,
@JsonProperty("sourceKey") String sourceKey, @JsonProperty("tags") Map<String, Tag> tags) {
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/core/GraphVersionDao.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/core/GraphVersion.java // public class GraphVersion extends RichVersion { // // @JsonProperty("graphId") // private final long graphId; // // @JsonProperty("edgeVersionIds") // private final List<Long> edgeVersionIds; // // /** // * Create a new graph version. // * // * @param id the id of this graph version // * @param tags the tags associated with this graph version // * @param structureVersionId the id of the StructureVersion associated with this graph version // * @param reference an optional external reference // * @param referenceParameters the access parameters of the reference // * @param graphId the id of the graph containing this version // * @param edgeVersionIds the list of edge versions in this graph version // */ // @JsonCreator // public GraphVersion( // @JsonProperty("id") long id, // @JsonProperty("tags") Map<String, Tag> tags, // @JsonProperty("structureVersionId") long structureVersionId, // @JsonProperty("reference") String reference, // @JsonProperty("referenceParameters") Map<String, String> referenceParameters, // @JsonProperty("graphId") long graphId, // @JsonProperty("edgeVersionIds") List<Long> edgeVersionIds) { // // super(id, tags, structureVersionId, reference, referenceParameters); // // this.graphId = graphId; // if (edgeVersionIds == null) { // this.edgeVersionIds = new ArrayList<>(); // } else { // this.edgeVersionIds = edgeVersionIds; // } // } // // public GraphVersion(long id, GraphVersion other) { // this(id, other, other); // // } // // public GraphVersion(long id, RichVersion otherRichVersion, GraphVersion other) { // super(id, otherRichVersion); // // this.graphId = other.graphId; // this.edgeVersionIds = other.edgeVersionIds; // } // // public long getGraphId() { // return this.graphId; // } // // public List<Long> getEdgeVersionIds() { // return this.edgeVersionIds; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof GraphVersion)) { // return false; // } // // GraphVersion otherGraphVersion = (GraphVersion) other; // // return this.graphId == otherGraphVersion.graphId // && this.edgeVersionIds.equals(otherGraphVersion.edgeVersionIds) // && super.equals(other); // } // }
import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.GraphVersion;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface GraphVersionDao extends RichVersionDao<GraphVersion> { @Override
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/core/GraphVersion.java // public class GraphVersion extends RichVersion { // // @JsonProperty("graphId") // private final long graphId; // // @JsonProperty("edgeVersionIds") // private final List<Long> edgeVersionIds; // // /** // * Create a new graph version. // * // * @param id the id of this graph version // * @param tags the tags associated with this graph version // * @param structureVersionId the id of the StructureVersion associated with this graph version // * @param reference an optional external reference // * @param referenceParameters the access parameters of the reference // * @param graphId the id of the graph containing this version // * @param edgeVersionIds the list of edge versions in this graph version // */ // @JsonCreator // public GraphVersion( // @JsonProperty("id") long id, // @JsonProperty("tags") Map<String, Tag> tags, // @JsonProperty("structureVersionId") long structureVersionId, // @JsonProperty("reference") String reference, // @JsonProperty("referenceParameters") Map<String, String> referenceParameters, // @JsonProperty("graphId") long graphId, // @JsonProperty("edgeVersionIds") List<Long> edgeVersionIds) { // // super(id, tags, structureVersionId, reference, referenceParameters); // // this.graphId = graphId; // if (edgeVersionIds == null) { // this.edgeVersionIds = new ArrayList<>(); // } else { // this.edgeVersionIds = edgeVersionIds; // } // } // // public GraphVersion(long id, GraphVersion other) { // this(id, other, other); // // } // // public GraphVersion(long id, RichVersion otherRichVersion, GraphVersion other) { // super(id, otherRichVersion); // // this.graphId = other.graphId; // this.edgeVersionIds = other.edgeVersionIds; // } // // public long getGraphId() { // return this.graphId; // } // // public List<Long> getEdgeVersionIds() { // return this.edgeVersionIds; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof GraphVersion)) { // return false; // } // // GraphVersion otherGraphVersion = (GraphVersion) other; // // return this.graphId == otherGraphVersion.graphId // && this.edgeVersionIds.equals(otherGraphVersion.edgeVersionIds) // && super.equals(other); // } // } // Path: modules/common/app/edu/berkeley/ground/common/dao/core/GraphVersionDao.java import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.core.GraphVersion; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.core; public interface GraphVersionDao extends RichVersionDao<GraphVersion> { @Override
GraphVersion retrieveFromDatabase(long id) throws GroundException;
ground-context/ground
modules/common/app/edu/berkeley/ground/common/dao/usage/LineageEdgeVersionDao.java
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/usage/LineageEdgeVersion.java // public class LineageEdgeVersion extends RichVersion { // // // the id of the LineageEdge containing this Version // @JsonProperty("lineageEdgeId") // private final long lineageEdgeId; // // // the id of the RichVersion that this LineageEdgeVersion originates from // @JsonProperty("fromRichVersionId") // private final long fromId; // // // the id of the RichVersion that this LineageEdgeVersion points to // @JsonProperty("toRichVersionId") // private final long toId; // // /** // * Create a lineage edge version. // * // * @param id the id of this version // * @param tags the tags associated with this version // * @param structureVersionId the id of the StructureVersion associated with this version // * @param reference an optional external reference // * @param referenceParameters the access parameters for the reference // * @param fromId the source rich version id // * @param toId the destination rich version id // * @param lineageEdgeId the id of the lineage edge containing this version // */ // // @JsonCreator // public LineageEdgeVersion(@JsonProperty("id") long id, // @JsonProperty("tags") Map<String, Tag> tags, // @JsonProperty("structureVersionId") Long structureVersionId, // @JsonProperty("reference") String reference, // @JsonProperty("referenceParameters") Map<String, String> referenceParameters, // @JsonProperty("fromRichVersionId") long fromId, // @JsonProperty("toRichVersionId") long toId, // @JsonProperty("lineageEdgeId") long lineageEdgeId) { // super(id, tags, structureVersionId, reference, referenceParameters); // // this.lineageEdgeId = lineageEdgeId; // this.fromId = fromId; // this.toId = toId; // } // // public LineageEdgeVersion(long id, LineageEdgeVersion other) { // this(id, other, other); // } // // public LineageEdgeVersion(long id, RichVersion otherRichVersion, LineageEdgeVersion other) { // super(id, otherRichVersion); // // this.lineageEdgeId = other.lineageEdgeId; // this.fromId = other.fromId; // this.toId = other.toId; // } // // public long getLineageEdgeId() { // return this.lineageEdgeId; // } // // public long getFromId() { // return this.fromId; // } // // public long getToId() { // return this.toId; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof LineageEdgeVersion)) { // return false; // } // // LineageEdgeVersion otherLineageEdgeVersion = (LineageEdgeVersion) other; // // return this.lineageEdgeId == otherLineageEdgeVersion.lineageEdgeId // && this.fromId == otherLineageEdgeVersion.fromId // && this.toId == otherLineageEdgeVersion.toId // && this.getId() == otherLineageEdgeVersion.getId() // && super.equals(other); // } // }
import java.util.List; import edu.berkeley.ground.common.dao.core.RichVersionDao; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.usage.LineageEdgeVersion;
/** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.usage; public interface LineageEdgeVersionDao extends RichVersionDao<LineageEdgeVersion> { @Override
// Path: modules/common/app/edu/berkeley/ground/common/exception/GroundException.java // public class GroundException extends Exception { // // private static final long serialVersionUID = 1L; // // private final String message; // private final ExceptionType exceptionType; // // public enum ExceptionType { // DB("Database Exception:", "%s"), // ITEM_NOT_FOUND("GroundItemNotFoundException", "No %s \'%s\' found."), // VERSION_NOT_FOUND("GroundVersionNotFoundException", "No %s \'%s\' found."), // ITEM_ALREADY_EXISTS("GroundItemAlreadyExistsException", "%s %s already exists."), // OTHER("GroundException", "%s"); // // String name; // String description; // // ExceptionType(String name, String description) { // this.name = name; // this.description = description; // } // // public String format(String... values) { // return String.format(this.description, values); // } // } // // public GroundException(ExceptionType exceptionType, String... values) { // this.exceptionType = exceptionType; // this.message = this.exceptionType.format(values); // } // // public GroundException(Exception exception) { // this.exceptionType = ExceptionType.OTHER; // this.message = this.exceptionType.format(exception.getMessage()); // } // // @Override // public String getMessage() { // return this.message; // } // // public ExceptionType getExceptionType() { // return this.exceptionType; // } // } // // Path: modules/common/app/edu/berkeley/ground/common/model/usage/LineageEdgeVersion.java // public class LineageEdgeVersion extends RichVersion { // // // the id of the LineageEdge containing this Version // @JsonProperty("lineageEdgeId") // private final long lineageEdgeId; // // // the id of the RichVersion that this LineageEdgeVersion originates from // @JsonProperty("fromRichVersionId") // private final long fromId; // // // the id of the RichVersion that this LineageEdgeVersion points to // @JsonProperty("toRichVersionId") // private final long toId; // // /** // * Create a lineage edge version. // * // * @param id the id of this version // * @param tags the tags associated with this version // * @param structureVersionId the id of the StructureVersion associated with this version // * @param reference an optional external reference // * @param referenceParameters the access parameters for the reference // * @param fromId the source rich version id // * @param toId the destination rich version id // * @param lineageEdgeId the id of the lineage edge containing this version // */ // // @JsonCreator // public LineageEdgeVersion(@JsonProperty("id") long id, // @JsonProperty("tags") Map<String, Tag> tags, // @JsonProperty("structureVersionId") Long structureVersionId, // @JsonProperty("reference") String reference, // @JsonProperty("referenceParameters") Map<String, String> referenceParameters, // @JsonProperty("fromRichVersionId") long fromId, // @JsonProperty("toRichVersionId") long toId, // @JsonProperty("lineageEdgeId") long lineageEdgeId) { // super(id, tags, structureVersionId, reference, referenceParameters); // // this.lineageEdgeId = lineageEdgeId; // this.fromId = fromId; // this.toId = toId; // } // // public LineageEdgeVersion(long id, LineageEdgeVersion other) { // this(id, other, other); // } // // public LineageEdgeVersion(long id, RichVersion otherRichVersion, LineageEdgeVersion other) { // super(id, otherRichVersion); // // this.lineageEdgeId = other.lineageEdgeId; // this.fromId = other.fromId; // this.toId = other.toId; // } // // public long getLineageEdgeId() { // return this.lineageEdgeId; // } // // public long getFromId() { // return this.fromId; // } // // public long getToId() { // return this.toId; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof LineageEdgeVersion)) { // return false; // } // // LineageEdgeVersion otherLineageEdgeVersion = (LineageEdgeVersion) other; // // return this.lineageEdgeId == otherLineageEdgeVersion.lineageEdgeId // && this.fromId == otherLineageEdgeVersion.fromId // && this.toId == otherLineageEdgeVersion.toId // && this.getId() == otherLineageEdgeVersion.getId() // && super.equals(other); // } // } // Path: modules/common/app/edu/berkeley/ground/common/dao/usage/LineageEdgeVersionDao.java import java.util.List; import edu.berkeley.ground.common.dao.core.RichVersionDao; import edu.berkeley.ground.common.exception.GroundException; import edu.berkeley.ground.common.model.usage.LineageEdgeVersion; /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * <p>http://www.apache.org/licenses/LICENSE-2.0 * * <p>Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package edu.berkeley.ground.common.dao.usage; public interface LineageEdgeVersionDao extends RichVersionDao<LineageEdgeVersion> { @Override
LineageEdgeVersion create(LineageEdgeVersion lineageEdgeVersion, List<Long> parentIds) throws GroundException;
codelibs/fess-suggest
test-site/app/controllers/Suggest.java
// Path: src/main/java/org/codelibs/fess/suggest/request/suggest/SuggestResponse.java // public class SuggestResponse implements Response { // protected final String index; // // protected final long tookMs; // // protected final List<String> words; // // protected final int num; // // protected final long total; // // protected final List<SuggestItem> items; // // public SuggestResponse(final String index, final long tookMs, final List<String> words, final long total, // final List<SuggestItem> items) { // this.index = index; // this.tookMs = tookMs; // this.words = words; // this.num = words.size(); // this.total = total; // this.items = items; // } // // public String getIndex() { // return index; // } // // public long getTookMs() { // return tookMs; // } // // public List<String> getWords() { // return words; // } // // public int getNum() { // return num; // } // // public long getTotal() { // return total; // } // // public List<SuggestItem> getItems() { // return items; // } // }
import models.*; import org.codelibs.fess.suggest.request.suggest.SuggestResponse; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; import play.Logger; import play.mvc.Controller; import play.mvc.Result; import java.util.Map;
package controllers; public class Suggest extends Controller { public static Result get() { Map<String, String[]> params = request().queryString(); String[] callback = params.get("callback"); String[] query = params.get("query"); try { SuggestIndex suggestIndex = new SuggestIndex();
// Path: src/main/java/org/codelibs/fess/suggest/request/suggest/SuggestResponse.java // public class SuggestResponse implements Response { // protected final String index; // // protected final long tookMs; // // protected final List<String> words; // // protected final int num; // // protected final long total; // // protected final List<SuggestItem> items; // // public SuggestResponse(final String index, final long tookMs, final List<String> words, final long total, // final List<SuggestItem> items) { // this.index = index; // this.tookMs = tookMs; // this.words = words; // this.num = words.size(); // this.total = total; // this.items = items; // } // // public String getIndex() { // return index; // } // // public long getTookMs() { // return tookMs; // } // // public List<String> getWords() { // return words; // } // // public int getNum() { // return num; // } // // public long getTotal() { // return total; // } // // public List<SuggestItem> getItems() { // return items; // } // } // Path: test-site/app/controllers/Suggest.java import models.*; import org.codelibs.fess.suggest.request.suggest.SuggestResponse; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; import play.Logger; import play.mvc.Controller; import play.mvc.Result; import java.util.Map; package controllers; public class Suggest extends Controller { public static Result get() { Map<String, String[]> params = request().queryString(); String[] callback = params.get("callback"); String[] query = params.get("query"); try { SuggestIndex suggestIndex = new SuggestIndex();
SuggestResponse response = suggestIndex.suggest(query[0]);
codelibs/fess-suggest
src/main/java/org/codelibs/fess/suggest/settings/ElevateWordSettings.java
// Path: src/main/java/org/codelibs/fess/suggest/constants/FieldNames.java // public final class FieldNames { // public static final String ID = "_id"; // public static final String TEXT = "text"; // public static final String READING_PREFIX = "reading_"; // public static final String SCORE = "score"; // public static final String QUERY_FREQ = "queryFreq"; // public static final String DOC_FREQ = "docFreq"; // public static final String USER_BOOST = "userBoost"; // public static final String KINDS = "kinds"; // public static final String TIMESTAMP = "@timestamp"; // public static final String TAGS = "tags"; // public static final String ROLES = "roles"; // public static final String FIELDS = "fields"; // public static final String LANGUAGES = "languages"; // // public static final String ARRAY_KEY = "key"; // public static final String ARRAY_VALUE = "value"; // // public static final String ANALYZER_SETTINGS_TYPE = "settingsType"; // public static final String ANALYZER_SETTINGS_FIELD_NAME = "fieldName"; // public static final String ANALYZER_SETTINGS_READING_ANALYZER = "readingAnalyzer"; // public static final String ANALYZER_SETTINGS_READING_TERM_ANALYZER = "readingTermAnalyzer"; // public static final String ANALYZER_SETTINGS_NORMALIZE_ANALYZER = "normalizeAnalyzer"; // public static final String ANALYZER_SETTINGS_CONTENTS_ANALYZER = "contentsAnalyzer"; // public static final String ANALYZER_SETTINGS_CONTENTS_READING_ANALYZER = "contentsReadingAnalyzer"; // // private FieldNames() { // } // } // // Path: src/main/java/org/codelibs/fess/suggest/entity/ElevateWord.java // public class ElevateWord { // // protected final String elevateWord; // protected final float boost; // protected final List<String> readings; // protected final List<String> fields; // protected final List<String> tags; // protected final List<String> roles; // // public ElevateWord(final String elevateWord, final float boost, final List<String> readings, final List<String> fields, // final List<String> tags, final List<String> roles) { // this.elevateWord = elevateWord; // this.boost = boost; // this.readings = readings; // this.fields = fields; // if (tags == null) { // this.tags = Collections.emptyList(); // } else { // this.tags = tags; // } // if (roles == null) { // this.roles = Collections.emptyList(); // } else { // this.roles = roles; // } // } // // public String getElevateWord() { // return elevateWord; // } // // public float getBoost() { // return boost; // } // // public List<String> getReadings() { // return readings; // } // // public List<String> getFields() { // return fields; // } // // public List<String> getTags() { // return tags; // } // // public List<String> getRoles() { // return roles; // } // // public SuggestItem toSuggestItem() { // final String[][] readingArray = // this.getReadings().stream().map(reading -> new String[] { reading }).toArray(count -> new String[count][]); // return new SuggestItem(new String[] { this.getElevateWord() }, readingArray, fields.toArray(new String[fields.size()]), 1, 0, // this.getBoost(), this.getTags().toArray(new String[this.getTags().size()]), // this.getRoles().toArray(new String[this.getRoles().size()]), null, SuggestItem.Kind.USER); // } // }
import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.codelibs.fess.suggest.constants.FieldNames; import org.codelibs.fess.suggest.entity.ElevateWord; import org.opensearch.client.Client;
/* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.settings; public class ElevateWordSettings { private static final Logger logger = Logger.getLogger(ElevateWordSettings.class.getName()); public static final String ELEVATE_WORD_SETTINGD_KEY = "elevateword"; public static final String ELEVATE_WORD_BOOST = "boost"; public static final String ELEVATE_WORD_READING = "reading"; public static final String ELEVATE_WORD_FIELDS = "fields"; public static final String ELEVATE_WORD_TAGS = "tags"; public static final String ELEVATE_WORD_ROLES = "roles"; protected ArraySettings arraySettings; protected ElevateWordSettings(final SuggestSettings settings, final Client client, final String settingsIndexName, final String settingsId) { this.arraySettings = new ArraySettings(settings, client, settingsIndexName, settingsId) { @Override protected String createArraySettingsIndexName(final String settingsIndexName) { return settingsIndexName + "_elevate"; } }; }
// Path: src/main/java/org/codelibs/fess/suggest/constants/FieldNames.java // public final class FieldNames { // public static final String ID = "_id"; // public static final String TEXT = "text"; // public static final String READING_PREFIX = "reading_"; // public static final String SCORE = "score"; // public static final String QUERY_FREQ = "queryFreq"; // public static final String DOC_FREQ = "docFreq"; // public static final String USER_BOOST = "userBoost"; // public static final String KINDS = "kinds"; // public static final String TIMESTAMP = "@timestamp"; // public static final String TAGS = "tags"; // public static final String ROLES = "roles"; // public static final String FIELDS = "fields"; // public static final String LANGUAGES = "languages"; // // public static final String ARRAY_KEY = "key"; // public static final String ARRAY_VALUE = "value"; // // public static final String ANALYZER_SETTINGS_TYPE = "settingsType"; // public static final String ANALYZER_SETTINGS_FIELD_NAME = "fieldName"; // public static final String ANALYZER_SETTINGS_READING_ANALYZER = "readingAnalyzer"; // public static final String ANALYZER_SETTINGS_READING_TERM_ANALYZER = "readingTermAnalyzer"; // public static final String ANALYZER_SETTINGS_NORMALIZE_ANALYZER = "normalizeAnalyzer"; // public static final String ANALYZER_SETTINGS_CONTENTS_ANALYZER = "contentsAnalyzer"; // public static final String ANALYZER_SETTINGS_CONTENTS_READING_ANALYZER = "contentsReadingAnalyzer"; // // private FieldNames() { // } // } // // Path: src/main/java/org/codelibs/fess/suggest/entity/ElevateWord.java // public class ElevateWord { // // protected final String elevateWord; // protected final float boost; // protected final List<String> readings; // protected final List<String> fields; // protected final List<String> tags; // protected final List<String> roles; // // public ElevateWord(final String elevateWord, final float boost, final List<String> readings, final List<String> fields, // final List<String> tags, final List<String> roles) { // this.elevateWord = elevateWord; // this.boost = boost; // this.readings = readings; // this.fields = fields; // if (tags == null) { // this.tags = Collections.emptyList(); // } else { // this.tags = tags; // } // if (roles == null) { // this.roles = Collections.emptyList(); // } else { // this.roles = roles; // } // } // // public String getElevateWord() { // return elevateWord; // } // // public float getBoost() { // return boost; // } // // public List<String> getReadings() { // return readings; // } // // public List<String> getFields() { // return fields; // } // // public List<String> getTags() { // return tags; // } // // public List<String> getRoles() { // return roles; // } // // public SuggestItem toSuggestItem() { // final String[][] readingArray = // this.getReadings().stream().map(reading -> new String[] { reading }).toArray(count -> new String[count][]); // return new SuggestItem(new String[] { this.getElevateWord() }, readingArray, fields.toArray(new String[fields.size()]), 1, 0, // this.getBoost(), this.getTags().toArray(new String[this.getTags().size()]), // this.getRoles().toArray(new String[this.getRoles().size()]), null, SuggestItem.Kind.USER); // } // } // Path: src/main/java/org/codelibs/fess/suggest/settings/ElevateWordSettings.java import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.codelibs.fess.suggest.constants.FieldNames; import org.codelibs.fess.suggest.entity.ElevateWord; import org.opensearch.client.Client; /* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.settings; public class ElevateWordSettings { private static final Logger logger = Logger.getLogger(ElevateWordSettings.class.getName()); public static final String ELEVATE_WORD_SETTINGD_KEY = "elevateword"; public static final String ELEVATE_WORD_BOOST = "boost"; public static final String ELEVATE_WORD_READING = "reading"; public static final String ELEVATE_WORD_FIELDS = "fields"; public static final String ELEVATE_WORD_TAGS = "tags"; public static final String ELEVATE_WORD_ROLES = "roles"; protected ArraySettings arraySettings; protected ElevateWordSettings(final SuggestSettings settings, final Client client, final String settingsIndexName, final String settingsId) { this.arraySettings = new ArraySettings(settings, client, settingsIndexName, settingsId) { @Override protected String createArraySettingsIndexName(final String settingsIndexName) { return settingsIndexName + "_elevate"; } }; }
public ElevateWord[] get() {
codelibs/fess-suggest
src/main/java/org/codelibs/fess/suggest/settings/ElevateWordSettings.java
// Path: src/main/java/org/codelibs/fess/suggest/constants/FieldNames.java // public final class FieldNames { // public static final String ID = "_id"; // public static final String TEXT = "text"; // public static final String READING_PREFIX = "reading_"; // public static final String SCORE = "score"; // public static final String QUERY_FREQ = "queryFreq"; // public static final String DOC_FREQ = "docFreq"; // public static final String USER_BOOST = "userBoost"; // public static final String KINDS = "kinds"; // public static final String TIMESTAMP = "@timestamp"; // public static final String TAGS = "tags"; // public static final String ROLES = "roles"; // public static final String FIELDS = "fields"; // public static final String LANGUAGES = "languages"; // // public static final String ARRAY_KEY = "key"; // public static final String ARRAY_VALUE = "value"; // // public static final String ANALYZER_SETTINGS_TYPE = "settingsType"; // public static final String ANALYZER_SETTINGS_FIELD_NAME = "fieldName"; // public static final String ANALYZER_SETTINGS_READING_ANALYZER = "readingAnalyzer"; // public static final String ANALYZER_SETTINGS_READING_TERM_ANALYZER = "readingTermAnalyzer"; // public static final String ANALYZER_SETTINGS_NORMALIZE_ANALYZER = "normalizeAnalyzer"; // public static final String ANALYZER_SETTINGS_CONTENTS_ANALYZER = "contentsAnalyzer"; // public static final String ANALYZER_SETTINGS_CONTENTS_READING_ANALYZER = "contentsReadingAnalyzer"; // // private FieldNames() { // } // } // // Path: src/main/java/org/codelibs/fess/suggest/entity/ElevateWord.java // public class ElevateWord { // // protected final String elevateWord; // protected final float boost; // protected final List<String> readings; // protected final List<String> fields; // protected final List<String> tags; // protected final List<String> roles; // // public ElevateWord(final String elevateWord, final float boost, final List<String> readings, final List<String> fields, // final List<String> tags, final List<String> roles) { // this.elevateWord = elevateWord; // this.boost = boost; // this.readings = readings; // this.fields = fields; // if (tags == null) { // this.tags = Collections.emptyList(); // } else { // this.tags = tags; // } // if (roles == null) { // this.roles = Collections.emptyList(); // } else { // this.roles = roles; // } // } // // public String getElevateWord() { // return elevateWord; // } // // public float getBoost() { // return boost; // } // // public List<String> getReadings() { // return readings; // } // // public List<String> getFields() { // return fields; // } // // public List<String> getTags() { // return tags; // } // // public List<String> getRoles() { // return roles; // } // // public SuggestItem toSuggestItem() { // final String[][] readingArray = // this.getReadings().stream().map(reading -> new String[] { reading }).toArray(count -> new String[count][]); // return new SuggestItem(new String[] { this.getElevateWord() }, readingArray, fields.toArray(new String[fields.size()]), 1, 0, // this.getBoost(), this.getTags().toArray(new String[this.getTags().size()]), // this.getRoles().toArray(new String[this.getRoles().size()]), null, SuggestItem.Kind.USER); // } // }
import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.codelibs.fess.suggest.constants.FieldNames; import org.codelibs.fess.suggest.entity.ElevateWord; import org.opensearch.client.Client;
/* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.settings; public class ElevateWordSettings { private static final Logger logger = Logger.getLogger(ElevateWordSettings.class.getName()); public static final String ELEVATE_WORD_SETTINGD_KEY = "elevateword"; public static final String ELEVATE_WORD_BOOST = "boost"; public static final String ELEVATE_WORD_READING = "reading"; public static final String ELEVATE_WORD_FIELDS = "fields"; public static final String ELEVATE_WORD_TAGS = "tags"; public static final String ELEVATE_WORD_ROLES = "roles"; protected ArraySettings arraySettings; protected ElevateWordSettings(final SuggestSettings settings, final Client client, final String settingsIndexName, final String settingsId) { this.arraySettings = new ArraySettings(settings, client, settingsIndexName, settingsId) { @Override protected String createArraySettingsIndexName(final String settingsIndexName) { return settingsIndexName + "_elevate"; } }; } public ElevateWord[] get() { final Map<String, Object>[] sourceArray = arraySettings.getFromArrayIndex(arraySettings.arraySettingsIndexName, arraySettings.settingsId, ELEVATE_WORD_SETTINGD_KEY); final ElevateWord[] elevateWords = new ElevateWord[sourceArray.length]; for (int i = 0; i < elevateWords.length; i++) {
// Path: src/main/java/org/codelibs/fess/suggest/constants/FieldNames.java // public final class FieldNames { // public static final String ID = "_id"; // public static final String TEXT = "text"; // public static final String READING_PREFIX = "reading_"; // public static final String SCORE = "score"; // public static final String QUERY_FREQ = "queryFreq"; // public static final String DOC_FREQ = "docFreq"; // public static final String USER_BOOST = "userBoost"; // public static final String KINDS = "kinds"; // public static final String TIMESTAMP = "@timestamp"; // public static final String TAGS = "tags"; // public static final String ROLES = "roles"; // public static final String FIELDS = "fields"; // public static final String LANGUAGES = "languages"; // // public static final String ARRAY_KEY = "key"; // public static final String ARRAY_VALUE = "value"; // // public static final String ANALYZER_SETTINGS_TYPE = "settingsType"; // public static final String ANALYZER_SETTINGS_FIELD_NAME = "fieldName"; // public static final String ANALYZER_SETTINGS_READING_ANALYZER = "readingAnalyzer"; // public static final String ANALYZER_SETTINGS_READING_TERM_ANALYZER = "readingTermAnalyzer"; // public static final String ANALYZER_SETTINGS_NORMALIZE_ANALYZER = "normalizeAnalyzer"; // public static final String ANALYZER_SETTINGS_CONTENTS_ANALYZER = "contentsAnalyzer"; // public static final String ANALYZER_SETTINGS_CONTENTS_READING_ANALYZER = "contentsReadingAnalyzer"; // // private FieldNames() { // } // } // // Path: src/main/java/org/codelibs/fess/suggest/entity/ElevateWord.java // public class ElevateWord { // // protected final String elevateWord; // protected final float boost; // protected final List<String> readings; // protected final List<String> fields; // protected final List<String> tags; // protected final List<String> roles; // // public ElevateWord(final String elevateWord, final float boost, final List<String> readings, final List<String> fields, // final List<String> tags, final List<String> roles) { // this.elevateWord = elevateWord; // this.boost = boost; // this.readings = readings; // this.fields = fields; // if (tags == null) { // this.tags = Collections.emptyList(); // } else { // this.tags = tags; // } // if (roles == null) { // this.roles = Collections.emptyList(); // } else { // this.roles = roles; // } // } // // public String getElevateWord() { // return elevateWord; // } // // public float getBoost() { // return boost; // } // // public List<String> getReadings() { // return readings; // } // // public List<String> getFields() { // return fields; // } // // public List<String> getTags() { // return tags; // } // // public List<String> getRoles() { // return roles; // } // // public SuggestItem toSuggestItem() { // final String[][] readingArray = // this.getReadings().stream().map(reading -> new String[] { reading }).toArray(count -> new String[count][]); // return new SuggestItem(new String[] { this.getElevateWord() }, readingArray, fields.toArray(new String[fields.size()]), 1, 0, // this.getBoost(), this.getTags().toArray(new String[this.getTags().size()]), // this.getRoles().toArray(new String[this.getRoles().size()]), null, SuggestItem.Kind.USER); // } // } // Path: src/main/java/org/codelibs/fess/suggest/settings/ElevateWordSettings.java import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.codelibs.fess.suggest.constants.FieldNames; import org.codelibs.fess.suggest.entity.ElevateWord; import org.opensearch.client.Client; /* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.settings; public class ElevateWordSettings { private static final Logger logger = Logger.getLogger(ElevateWordSettings.class.getName()); public static final String ELEVATE_WORD_SETTINGD_KEY = "elevateword"; public static final String ELEVATE_WORD_BOOST = "boost"; public static final String ELEVATE_WORD_READING = "reading"; public static final String ELEVATE_WORD_FIELDS = "fields"; public static final String ELEVATE_WORD_TAGS = "tags"; public static final String ELEVATE_WORD_ROLES = "roles"; protected ArraySettings arraySettings; protected ElevateWordSettings(final SuggestSettings settings, final Client client, final String settingsIndexName, final String settingsId) { this.arraySettings = new ArraySettings(settings, client, settingsIndexName, settingsId) { @Override protected String createArraySettingsIndexName(final String settingsIndexName) { return settingsIndexName + "_elevate"; } }; } public ElevateWord[] get() { final Map<String, Object>[] sourceArray = arraySettings.getFromArrayIndex(arraySettings.arraySettingsIndexName, arraySettings.settingsId, ELEVATE_WORD_SETTINGD_KEY); final ElevateWord[] elevateWords = new ElevateWord[sourceArray.length]; for (int i = 0; i < elevateWords.length; i++) {
final Object elevateWord = sourceArray[i].get(FieldNames.ARRAY_VALUE);
codelibs/fess-suggest
src/test/java/org/codelibs/opensearch/extension/analysis/ReloadableKuromojiTokenizerFactory.java
// Path: src/test/java/org/codelibs/opensearch/extension/kuromoji/index/analysis/KuromojiTokenizerFactory.java // public class KuromojiTokenizerFactory extends AbstractTokenizerFactory { // // private static final String USER_DICT_PATH_OPTION = "user_dictionary"; // private static final String USER_DICT_RULES_OPTION = "user_dictionary_rules"; // private static final String NBEST_COST = "nbest_cost"; // private static final String NBEST_EXAMPLES = "nbest_examples"; // // private final UserDictionary userDictionary; // private final Mode mode; // private final String nBestExamples; // private final int nBestCost; // // private boolean discartPunctuation; // // public KuromojiTokenizerFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) { // super(indexSettings, settings, name); // mode = getMode(settings); // userDictionary = getUserDictionary(env, settings); // discartPunctuation = settings.getAsBoolean("discard_punctuation", true); // nBestCost = settings.getAsInt(NBEST_COST, -1); // nBestExamples = settings.get(NBEST_EXAMPLES); // } // // public static UserDictionary getUserDictionary(Environment env, Settings settings) { // if (settings.get(USER_DICT_PATH_OPTION) != null && settings.get(USER_DICT_RULES_OPTION) != null) { // throw new IllegalArgumentException( // "It is not allowed to use [" + USER_DICT_PATH_OPTION + "] in conjunction" + " with [" + USER_DICT_RULES_OPTION + "]"); // } // try { // List<String> ruleList = Analysis.getWordList(env, settings, USER_DICT_PATH_OPTION, USER_DICT_RULES_OPTION, false); // if (ruleList == null || ruleList.isEmpty()) { // return null; // } // Set<String> dup = new HashSet<>(); // int lineNum = 0; // for (String line : ruleList) { // // ignore comments // if (line.startsWith("#") == false) { // String[] values = CSVUtil.parse(line); // if (dup.add(values[0]) == false) { // throw new IllegalArgumentException( // "Found duplicate term [" + values[0] + "] in user dictionary " + "at line [" + lineNum + "]"); // } // } // ++lineNum; // } // StringBuilder sb = new StringBuilder(); // for (String line : ruleList) { // sb.append(line).append(System.lineSeparator()); // } // return UserDictionary.open(new StringReader(sb.toString())); // } catch (IOException e) { // throw new OpenSearchException("failed to load kuromoji user dictionary", e); // } // } // // public static JapaneseTokenizer.Mode getMode(Settings settings) { // JapaneseTokenizer.Mode mode = JapaneseTokenizer.DEFAULT_MODE; // String modeSetting = settings.get("mode", null); // if (modeSetting != null) { // if ("search".equalsIgnoreCase(modeSetting)) { // mode = JapaneseTokenizer.Mode.SEARCH; // } else if ("normal".equalsIgnoreCase(modeSetting)) { // mode = JapaneseTokenizer.Mode.NORMAL; // } else if ("extended".equalsIgnoreCase(modeSetting)) { // mode = JapaneseTokenizer.Mode.EXTENDED; // } // } // return mode; // } // // @Override // public Tokenizer create() { // JapaneseTokenizer t = new JapaneseTokenizer(userDictionary, discartPunctuation, mode); // int nBestCost = this.nBestCost; // if (nBestExamples != null) { // nBestCost = Math.max(nBestCost, t.calcNBestCost(nBestExamples)); // } // t.setNBestCost(nBestCost); // return t; // } // // }
import java.io.File; import java.io.IOException; import java.io.Reader; import java.lang.reflect.Field; import java.nio.file.Path; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.EnumMap; import org.apache.lucene.analysis.Tokenizer; import org.apache.lucene.analysis.ja.JapaneseTokenizer; import org.apache.lucene.analysis.ja.JapaneseTokenizer.Mode; import org.apache.lucene.analysis.ja.JapaneseTokenizer.Type; import org.apache.lucene.analysis.ja.dict.Dictionary; import org.apache.lucene.analysis.ja.dict.TokenInfoFST; import org.apache.lucene.analysis.ja.dict.UserDictionary; import org.apache.lucene.util.AttributeSource; import org.codelibs.opensearch.extension.kuromoji.index.analysis.KuromojiTokenizerFactory; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.env.Environment; import org.opensearch.index.IndexSettings; import org.opensearch.index.analysis.AbstractTokenizerFactory;
protected final Field userFSTField; protected final Field userFSTReaderField; protected final Field dictionaryMapField; private final Environment env; private final Settings settings; private File reloadableFile = null; protected volatile long dictionaryTimestamp; private volatile long lastChecked; private long reloadInterval; private volatile UserDictionary userDictionary; private final Mode mode; private final boolean discartPunctuation; public ReloadableKuromojiTokenizerFactory(final IndexSettings indexSettings, final Environment env, final String name, final Settings settings) { super(indexSettings, settings, name); this.env = env; this.settings = settings;
// Path: src/test/java/org/codelibs/opensearch/extension/kuromoji/index/analysis/KuromojiTokenizerFactory.java // public class KuromojiTokenizerFactory extends AbstractTokenizerFactory { // // private static final String USER_DICT_PATH_OPTION = "user_dictionary"; // private static final String USER_DICT_RULES_OPTION = "user_dictionary_rules"; // private static final String NBEST_COST = "nbest_cost"; // private static final String NBEST_EXAMPLES = "nbest_examples"; // // private final UserDictionary userDictionary; // private final Mode mode; // private final String nBestExamples; // private final int nBestCost; // // private boolean discartPunctuation; // // public KuromojiTokenizerFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) { // super(indexSettings, settings, name); // mode = getMode(settings); // userDictionary = getUserDictionary(env, settings); // discartPunctuation = settings.getAsBoolean("discard_punctuation", true); // nBestCost = settings.getAsInt(NBEST_COST, -1); // nBestExamples = settings.get(NBEST_EXAMPLES); // } // // public static UserDictionary getUserDictionary(Environment env, Settings settings) { // if (settings.get(USER_DICT_PATH_OPTION) != null && settings.get(USER_DICT_RULES_OPTION) != null) { // throw new IllegalArgumentException( // "It is not allowed to use [" + USER_DICT_PATH_OPTION + "] in conjunction" + " with [" + USER_DICT_RULES_OPTION + "]"); // } // try { // List<String> ruleList = Analysis.getWordList(env, settings, USER_DICT_PATH_OPTION, USER_DICT_RULES_OPTION, false); // if (ruleList == null || ruleList.isEmpty()) { // return null; // } // Set<String> dup = new HashSet<>(); // int lineNum = 0; // for (String line : ruleList) { // // ignore comments // if (line.startsWith("#") == false) { // String[] values = CSVUtil.parse(line); // if (dup.add(values[0]) == false) { // throw new IllegalArgumentException( // "Found duplicate term [" + values[0] + "] in user dictionary " + "at line [" + lineNum + "]"); // } // } // ++lineNum; // } // StringBuilder sb = new StringBuilder(); // for (String line : ruleList) { // sb.append(line).append(System.lineSeparator()); // } // return UserDictionary.open(new StringReader(sb.toString())); // } catch (IOException e) { // throw new OpenSearchException("failed to load kuromoji user dictionary", e); // } // } // // public static JapaneseTokenizer.Mode getMode(Settings settings) { // JapaneseTokenizer.Mode mode = JapaneseTokenizer.DEFAULT_MODE; // String modeSetting = settings.get("mode", null); // if (modeSetting != null) { // if ("search".equalsIgnoreCase(modeSetting)) { // mode = JapaneseTokenizer.Mode.SEARCH; // } else if ("normal".equalsIgnoreCase(modeSetting)) { // mode = JapaneseTokenizer.Mode.NORMAL; // } else if ("extended".equalsIgnoreCase(modeSetting)) { // mode = JapaneseTokenizer.Mode.EXTENDED; // } // } // return mode; // } // // @Override // public Tokenizer create() { // JapaneseTokenizer t = new JapaneseTokenizer(userDictionary, discartPunctuation, mode); // int nBestCost = this.nBestCost; // if (nBestExamples != null) { // nBestCost = Math.max(nBestCost, t.calcNBestCost(nBestExamples)); // } // t.setNBestCost(nBestCost); // return t; // } // // } // Path: src/test/java/org/codelibs/opensearch/extension/analysis/ReloadableKuromojiTokenizerFactory.java import java.io.File; import java.io.IOException; import java.io.Reader; import java.lang.reflect.Field; import java.nio.file.Path; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.EnumMap; import org.apache.lucene.analysis.Tokenizer; import org.apache.lucene.analysis.ja.JapaneseTokenizer; import org.apache.lucene.analysis.ja.JapaneseTokenizer.Mode; import org.apache.lucene.analysis.ja.JapaneseTokenizer.Type; import org.apache.lucene.analysis.ja.dict.Dictionary; import org.apache.lucene.analysis.ja.dict.TokenInfoFST; import org.apache.lucene.analysis.ja.dict.UserDictionary; import org.apache.lucene.util.AttributeSource; import org.codelibs.opensearch.extension.kuromoji.index.analysis.KuromojiTokenizerFactory; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.env.Environment; import org.opensearch.index.IndexSettings; import org.opensearch.index.analysis.AbstractTokenizerFactory; protected final Field userFSTField; protected final Field userFSTReaderField; protected final Field dictionaryMapField; private final Environment env; private final Settings settings; private File reloadableFile = null; protected volatile long dictionaryTimestamp; private volatile long lastChecked; private long reloadInterval; private volatile UserDictionary userDictionary; private final Mode mode; private final boolean discartPunctuation; public ReloadableKuromojiTokenizerFactory(final IndexSettings indexSettings, final Environment env, final String name, final Settings settings) { super(indexSettings, settings, name); this.env = env; this.settings = settings;
mode = KuromojiTokenizerFactory.getMode(settings);
codelibs/fess-suggest
src/main/java/org/codelibs/fess/suggest/settings/BadWordSettings.java
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggestSettingsException.java // public class SuggestSettingsException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggestSettingsException(final String msg) { // super(msg); // } // // public SuggestSettingsException(final Throwable cause) { // super(cause); // } // // public SuggestSettingsException(final String msg, final Throwable cause) { // super(msg, cause); // } // }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import org.codelibs.fess.suggest.exception.SuggestSettingsException; import org.opensearch.client.Client; import org.opensearch.common.Strings;
} arraySettings.delete(BAD_WORD_SETTINGD_KEY); } protected String getValidationError(final String badWord) { if (Strings.isNullOrEmpty(badWord)) { return "badWord was empty."; } if (badWord.contains(" ") || badWord.contains(" ")) { return "badWord contains space."; } return null; } protected static void updateDefaultBadwords() { if (defaultWords != null) { return; } final List<String> list = new ArrayList<>(); try (BufferedReader br = new BufferedReader(new InputStreamReader( Thread.currentThread().getContextClassLoader().getResourceAsStream("suggest_settings/default-badwords.txt")))) { String line; while ((line = br.readLine()) != null) { if (line.length() > 0 && !line.startsWith("#")) { list.add(line.trim()); } } } catch (final Exception e) {
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggestSettingsException.java // public class SuggestSettingsException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggestSettingsException(final String msg) { // super(msg); // } // // public SuggestSettingsException(final Throwable cause) { // super(cause); // } // // public SuggestSettingsException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // Path: src/main/java/org/codelibs/fess/suggest/settings/BadWordSettings.java import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import org.codelibs.fess.suggest.exception.SuggestSettingsException; import org.opensearch.client.Client; import org.opensearch.common.Strings; } arraySettings.delete(BAD_WORD_SETTINGD_KEY); } protected String getValidationError(final String badWord) { if (Strings.isNullOrEmpty(badWord)) { return "badWord was empty."; } if (badWord.contains(" ") || badWord.contains(" ")) { return "badWord contains space."; } return null; } protected static void updateDefaultBadwords() { if (defaultWords != null) { return; } final List<String> list = new ArrayList<>(); try (BufferedReader br = new BufferedReader(new InputStreamReader( Thread.currentThread().getContextClassLoader().getResourceAsStream("suggest_settings/default-badwords.txt")))) { String line; while ((line = br.readLine()) != null) { if (line.length() > 0 && !line.startsWith("#")) { list.add(line.trim()); } } } catch (final Exception e) {
throw new SuggestSettingsException("Failed to load default badwords.", e);
codelibs/fess-suggest
src/main/java/org/codelibs/fess/suggest/request/RequestBuilder.java
// Path: src/main/java/org/codelibs/fess/suggest/concurrent/Deferred.java // public class Deferred<RESPONSE extends Response> { // private RESPONSE response = null; // // private Throwable error = null; // // private final Promise promise = new Promise(); // // private final Queue<Consumer<RESPONSE>> doneCallbacks = new LinkedBlockingQueue<>(); // // private final Queue<Consumer<Throwable>> errorCallbacks = new LinkedBlockingQueue<>(); // // private final CountDownLatch latch = new CountDownLatch(1); // // public void resolve(final RESPONSE r) { // final ArrayList<Consumer<RESPONSE>> executeCallbacks; // synchronized (Deferred.this) { // if (response != null || error != null) { // return; // } // response = r; // // executeCallbacks = new ArrayList<>(doneCallbacks.size()); // Consumer<RESPONSE> callback; // while ((callback = doneCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // if (executeCallbacks.size() > 0) { // try { // executeCallbacks.stream().forEach(callback -> callback.accept(response)); // } catch (final Exception ignore) {} // } // latch.countDown(); // } // // public void reject(final Throwable t) { // final ArrayList<Consumer<Throwable>> executeCallbacks; // synchronized (Deferred.this) { // if (response != null || error != null) { // return; // } // error = t; // // executeCallbacks = new ArrayList<>(errorCallbacks.size()); // Consumer<Throwable> callback; // while ((callback = errorCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // if (executeCallbacks.size() > 0) { // try { // executeCallbacks.stream().forEach(callback -> callback.accept(error)); // } catch (final Exception ignore) {} // } // latch.countDown(); // } // // public Promise then(final Consumer<RESPONSE> consumer) { // return promise.then(consumer); // } // // public Promise error(final Consumer<Throwable> consumer) { // return promise.error(consumer); // } // // public Promise promise() { // return promise; // } // // public class Promise { // public Promise then(final Consumer<RESPONSE> consumer) { // final ArrayList<Consumer<RESPONSE>> executeCallbacks; // synchronized (Deferred.this) { // doneCallbacks.add(consumer); // executeCallbacks = new ArrayList<>(doneCallbacks.size()); // if (response != null) { // Consumer<RESPONSE> callback; // while ((callback = doneCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // } // if (executeCallbacks.size() > 0) { // executeCallbacks.stream().forEach(callback -> callback.accept(response)); // } // return this; // } // // public Promise error(final Consumer<Throwable> consumer) { // final ArrayList<Consumer<Throwable>> executeCallbacks; // synchronized (Deferred.this) { // errorCallbacks.add(consumer); // executeCallbacks = new ArrayList<>(errorCallbacks.size()); // if (error != null) { // Consumer<Throwable> callback; // while ((callback = errorCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // } // if (executeCallbacks.size() > 0) { // executeCallbacks.stream().forEach(callback -> callback.accept(error)); // } // return this; // } // // public RESPONSE getResponse() { // return getResponse(1, TimeUnit.MINUTES); // } // // public RESPONSE getResponse(final long time, final TimeUnit unit) { // try { // final boolean isTimeout = !latch.await(time, unit); // if (isTimeout) { // throw new SuggesterException("Request timeout. time:" + time + " unit:" + unit.name()); // } // if (error != null) { // throw new SuggesterException(error); // } // return response; // } catch (final InterruptedException e) { // throw new SuggesterException(e); // } // } // } // }
import org.codelibs.fess.suggest.concurrent.Deferred; import org.opensearch.client.Client;
/* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.request; public abstract class RequestBuilder<Req extends Request<Res>, Res extends Response> { protected Client client; protected Req request; public RequestBuilder(final Client client, final Req request) { this.client = client; this.request = request; }
// Path: src/main/java/org/codelibs/fess/suggest/concurrent/Deferred.java // public class Deferred<RESPONSE extends Response> { // private RESPONSE response = null; // // private Throwable error = null; // // private final Promise promise = new Promise(); // // private final Queue<Consumer<RESPONSE>> doneCallbacks = new LinkedBlockingQueue<>(); // // private final Queue<Consumer<Throwable>> errorCallbacks = new LinkedBlockingQueue<>(); // // private final CountDownLatch latch = new CountDownLatch(1); // // public void resolve(final RESPONSE r) { // final ArrayList<Consumer<RESPONSE>> executeCallbacks; // synchronized (Deferred.this) { // if (response != null || error != null) { // return; // } // response = r; // // executeCallbacks = new ArrayList<>(doneCallbacks.size()); // Consumer<RESPONSE> callback; // while ((callback = doneCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // if (executeCallbacks.size() > 0) { // try { // executeCallbacks.stream().forEach(callback -> callback.accept(response)); // } catch (final Exception ignore) {} // } // latch.countDown(); // } // // public void reject(final Throwable t) { // final ArrayList<Consumer<Throwable>> executeCallbacks; // synchronized (Deferred.this) { // if (response != null || error != null) { // return; // } // error = t; // // executeCallbacks = new ArrayList<>(errorCallbacks.size()); // Consumer<Throwable> callback; // while ((callback = errorCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // if (executeCallbacks.size() > 0) { // try { // executeCallbacks.stream().forEach(callback -> callback.accept(error)); // } catch (final Exception ignore) {} // } // latch.countDown(); // } // // public Promise then(final Consumer<RESPONSE> consumer) { // return promise.then(consumer); // } // // public Promise error(final Consumer<Throwable> consumer) { // return promise.error(consumer); // } // // public Promise promise() { // return promise; // } // // public class Promise { // public Promise then(final Consumer<RESPONSE> consumer) { // final ArrayList<Consumer<RESPONSE>> executeCallbacks; // synchronized (Deferred.this) { // doneCallbacks.add(consumer); // executeCallbacks = new ArrayList<>(doneCallbacks.size()); // if (response != null) { // Consumer<RESPONSE> callback; // while ((callback = doneCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // } // if (executeCallbacks.size() > 0) { // executeCallbacks.stream().forEach(callback -> callback.accept(response)); // } // return this; // } // // public Promise error(final Consumer<Throwable> consumer) { // final ArrayList<Consumer<Throwable>> executeCallbacks; // synchronized (Deferred.this) { // errorCallbacks.add(consumer); // executeCallbacks = new ArrayList<>(errorCallbacks.size()); // if (error != null) { // Consumer<Throwable> callback; // while ((callback = errorCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // } // if (executeCallbacks.size() > 0) { // executeCallbacks.stream().forEach(callback -> callback.accept(error)); // } // return this; // } // // public RESPONSE getResponse() { // return getResponse(1, TimeUnit.MINUTES); // } // // public RESPONSE getResponse(final long time, final TimeUnit unit) { // try { // final boolean isTimeout = !latch.await(time, unit); // if (isTimeout) { // throw new SuggesterException("Request timeout. time:" + time + " unit:" + unit.name()); // } // if (error != null) { // throw new SuggesterException(error); // } // return response; // } catch (final InterruptedException e) { // throw new SuggesterException(e); // } // } // } // } // Path: src/main/java/org/codelibs/fess/suggest/request/RequestBuilder.java import org.codelibs.fess.suggest.concurrent.Deferred; import org.opensearch.client.Client; /* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.request; public abstract class RequestBuilder<Req extends Request<Res>, Res extends Response> { protected Client client; protected Req request; public RequestBuilder(final Client client, final Req request) { this.client = client; this.request = request; }
public Deferred<Res>.Promise execute() {
codelibs/fess-suggest
src/main/java/org/codelibs/fess/suggest/request/Request.java
// Path: src/main/java/org/codelibs/fess/suggest/concurrent/Deferred.java // public class Deferred<RESPONSE extends Response> { // private RESPONSE response = null; // // private Throwable error = null; // // private final Promise promise = new Promise(); // // private final Queue<Consumer<RESPONSE>> doneCallbacks = new LinkedBlockingQueue<>(); // // private final Queue<Consumer<Throwable>> errorCallbacks = new LinkedBlockingQueue<>(); // // private final CountDownLatch latch = new CountDownLatch(1); // // public void resolve(final RESPONSE r) { // final ArrayList<Consumer<RESPONSE>> executeCallbacks; // synchronized (Deferred.this) { // if (response != null || error != null) { // return; // } // response = r; // // executeCallbacks = new ArrayList<>(doneCallbacks.size()); // Consumer<RESPONSE> callback; // while ((callback = doneCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // if (executeCallbacks.size() > 0) { // try { // executeCallbacks.stream().forEach(callback -> callback.accept(response)); // } catch (final Exception ignore) {} // } // latch.countDown(); // } // // public void reject(final Throwable t) { // final ArrayList<Consumer<Throwable>> executeCallbacks; // synchronized (Deferred.this) { // if (response != null || error != null) { // return; // } // error = t; // // executeCallbacks = new ArrayList<>(errorCallbacks.size()); // Consumer<Throwable> callback; // while ((callback = errorCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // if (executeCallbacks.size() > 0) { // try { // executeCallbacks.stream().forEach(callback -> callback.accept(error)); // } catch (final Exception ignore) {} // } // latch.countDown(); // } // // public Promise then(final Consumer<RESPONSE> consumer) { // return promise.then(consumer); // } // // public Promise error(final Consumer<Throwable> consumer) { // return promise.error(consumer); // } // // public Promise promise() { // return promise; // } // // public class Promise { // public Promise then(final Consumer<RESPONSE> consumer) { // final ArrayList<Consumer<RESPONSE>> executeCallbacks; // synchronized (Deferred.this) { // doneCallbacks.add(consumer); // executeCallbacks = new ArrayList<>(doneCallbacks.size()); // if (response != null) { // Consumer<RESPONSE> callback; // while ((callback = doneCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // } // if (executeCallbacks.size() > 0) { // executeCallbacks.stream().forEach(callback -> callback.accept(response)); // } // return this; // } // // public Promise error(final Consumer<Throwable> consumer) { // final ArrayList<Consumer<Throwable>> executeCallbacks; // synchronized (Deferred.this) { // errorCallbacks.add(consumer); // executeCallbacks = new ArrayList<>(errorCallbacks.size()); // if (error != null) { // Consumer<Throwable> callback; // while ((callback = errorCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // } // if (executeCallbacks.size() > 0) { // executeCallbacks.stream().forEach(callback -> callback.accept(error)); // } // return this; // } // // public RESPONSE getResponse() { // return getResponse(1, TimeUnit.MINUTES); // } // // public RESPONSE getResponse(final long time, final TimeUnit unit) { // try { // final boolean isTimeout = !latch.await(time, unit); // if (isTimeout) { // throw new SuggesterException("Request timeout. time:" + time + " unit:" + unit.name()); // } // if (error != null) { // throw new SuggesterException(error); // } // return response; // } catch (final InterruptedException e) { // throw new SuggesterException(e); // } // } // } // } // // Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // }
import org.codelibs.fess.suggest.concurrent.Deferred; import org.codelibs.fess.suggest.exception.SuggesterException; import org.opensearch.client.Client; import org.opensearch.common.Strings;
/* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.request; public abstract class Request<T extends Response> { public Deferred<T>.Promise execute(final Client client) { final String error = getValidationError(); if (!Strings.isNullOrEmpty(error)) { throw new IllegalArgumentException(error); } final Deferred<T> deferred = new Deferred<>(); try { processRequest(client, deferred); } catch (final Exception e) {
// Path: src/main/java/org/codelibs/fess/suggest/concurrent/Deferred.java // public class Deferred<RESPONSE extends Response> { // private RESPONSE response = null; // // private Throwable error = null; // // private final Promise promise = new Promise(); // // private final Queue<Consumer<RESPONSE>> doneCallbacks = new LinkedBlockingQueue<>(); // // private final Queue<Consumer<Throwable>> errorCallbacks = new LinkedBlockingQueue<>(); // // private final CountDownLatch latch = new CountDownLatch(1); // // public void resolve(final RESPONSE r) { // final ArrayList<Consumer<RESPONSE>> executeCallbacks; // synchronized (Deferred.this) { // if (response != null || error != null) { // return; // } // response = r; // // executeCallbacks = new ArrayList<>(doneCallbacks.size()); // Consumer<RESPONSE> callback; // while ((callback = doneCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // if (executeCallbacks.size() > 0) { // try { // executeCallbacks.stream().forEach(callback -> callback.accept(response)); // } catch (final Exception ignore) {} // } // latch.countDown(); // } // // public void reject(final Throwable t) { // final ArrayList<Consumer<Throwable>> executeCallbacks; // synchronized (Deferred.this) { // if (response != null || error != null) { // return; // } // error = t; // // executeCallbacks = new ArrayList<>(errorCallbacks.size()); // Consumer<Throwable> callback; // while ((callback = errorCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // if (executeCallbacks.size() > 0) { // try { // executeCallbacks.stream().forEach(callback -> callback.accept(error)); // } catch (final Exception ignore) {} // } // latch.countDown(); // } // // public Promise then(final Consumer<RESPONSE> consumer) { // return promise.then(consumer); // } // // public Promise error(final Consumer<Throwable> consumer) { // return promise.error(consumer); // } // // public Promise promise() { // return promise; // } // // public class Promise { // public Promise then(final Consumer<RESPONSE> consumer) { // final ArrayList<Consumer<RESPONSE>> executeCallbacks; // synchronized (Deferred.this) { // doneCallbacks.add(consumer); // executeCallbacks = new ArrayList<>(doneCallbacks.size()); // if (response != null) { // Consumer<RESPONSE> callback; // while ((callback = doneCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // } // if (executeCallbacks.size() > 0) { // executeCallbacks.stream().forEach(callback -> callback.accept(response)); // } // return this; // } // // public Promise error(final Consumer<Throwable> consumer) { // final ArrayList<Consumer<Throwable>> executeCallbacks; // synchronized (Deferred.this) { // errorCallbacks.add(consumer); // executeCallbacks = new ArrayList<>(errorCallbacks.size()); // if (error != null) { // Consumer<Throwable> callback; // while ((callback = errorCallbacks.poll()) != null) { // executeCallbacks.add(callback); // } // } // } // if (executeCallbacks.size() > 0) { // executeCallbacks.stream().forEach(callback -> callback.accept(error)); // } // return this; // } // // public RESPONSE getResponse() { // return getResponse(1, TimeUnit.MINUTES); // } // // public RESPONSE getResponse(final long time, final TimeUnit unit) { // try { // final boolean isTimeout = !latch.await(time, unit); // if (isTimeout) { // throw new SuggesterException("Request timeout. time:" + time + " unit:" + unit.name()); // } // if (error != null) { // throw new SuggesterException(error); // } // return response; // } catch (final InterruptedException e) { // throw new SuggesterException(e); // } // } // } // } // // Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // Path: src/main/java/org/codelibs/fess/suggest/request/Request.java import org.codelibs.fess.suggest.concurrent.Deferred; import org.codelibs.fess.suggest.exception.SuggesterException; import org.opensearch.client.Client; import org.opensearch.common.Strings; /* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.request; public abstract class Request<T extends Response> { public Deferred<T>.Promise execute(final Client client) { final String error = getValidationError(); if (!Strings.isNullOrEmpty(error)) { throw new IllegalArgumentException(error); } final Deferred<T> deferred = new Deferred<>(); try { processRequest(client, deferred); } catch (final Exception e) {
throw new SuggesterException(e);
codelibs/fess-suggest
src/main/java/org/codelibs/fess/suggest/concurrent/Deferred.java
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // // Path: src/main/java/org/codelibs/fess/suggest/request/Response.java // public interface Response { // }
import java.util.ArrayList; import java.util.Queue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import org.codelibs.fess.suggest.exception.SuggesterException; import org.codelibs.fess.suggest.request.Response;
} return this; } public Promise error(final Consumer<Throwable> consumer) { final ArrayList<Consumer<Throwable>> executeCallbacks; synchronized (Deferred.this) { errorCallbacks.add(consumer); executeCallbacks = new ArrayList<>(errorCallbacks.size()); if (error != null) { Consumer<Throwable> callback; while ((callback = errorCallbacks.poll()) != null) { executeCallbacks.add(callback); } } } if (executeCallbacks.size() > 0) { executeCallbacks.stream().forEach(callback -> callback.accept(error)); } return this; } public RESPONSE getResponse() { return getResponse(1, TimeUnit.MINUTES); } public RESPONSE getResponse(final long time, final TimeUnit unit) { try { final boolean isTimeout = !latch.await(time, unit); if (isTimeout) {
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // // Path: src/main/java/org/codelibs/fess/suggest/request/Response.java // public interface Response { // } // Path: src/main/java/org/codelibs/fess/suggest/concurrent/Deferred.java import java.util.ArrayList; import java.util.Queue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import org.codelibs.fess.suggest.exception.SuggesterException; import org.codelibs.fess.suggest.request.Response; } return this; } public Promise error(final Consumer<Throwable> consumer) { final ArrayList<Consumer<Throwable>> executeCallbacks; synchronized (Deferred.this) { errorCallbacks.add(consumer); executeCallbacks = new ArrayList<>(errorCallbacks.size()); if (error != null) { Consumer<Throwable> callback; while ((callback = errorCallbacks.poll()) != null) { executeCallbacks.add(callback); } } } if (executeCallbacks.size() > 0) { executeCallbacks.stream().forEach(callback -> callback.accept(error)); } return this; } public RESPONSE getResponse() { return getResponse(1, TimeUnit.MINUTES); } public RESPONSE getResponse(final long time, final TimeUnit unit) { try { final boolean isTimeout = !latch.await(time, unit); if (isTimeout) {
throw new SuggesterException("Request timeout. time:" + time + " unit:" + unit.name());
codelibs/fess-suggest
src/main/java/org/codelibs/fess/suggest/settings/SuggestSettingsBuilder.java
// Path: src/main/java/org/codelibs/fess/suggest/settings/SuggestSettings.java // public static class TimeoutSettings { // protected String searchTimeout = "15s"; // protected String indexTimeout = "1m"; // protected String bulkTimeout = "1m"; // protected String indicesTimeout = "1m"; // protected String clusterTimeout = "1m"; // protected String scrollTimeout = "1m"; // }
import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.codelibs.fess.suggest.settings.SuggestSettings.TimeoutSettings; import org.opensearch.client.Client;
/* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.settings; public class SuggestSettingsBuilder { protected String settingsIndexName = "fess_suggest";
// Path: src/main/java/org/codelibs/fess/suggest/settings/SuggestSettings.java // public static class TimeoutSettings { // protected String searchTimeout = "15s"; // protected String indexTimeout = "1m"; // protected String bulkTimeout = "1m"; // protected String indicesTimeout = "1m"; // protected String clusterTimeout = "1m"; // protected String scrollTimeout = "1m"; // } // Path: src/main/java/org/codelibs/fess/suggest/settings/SuggestSettingsBuilder.java import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.codelibs.fess.suggest.settings.SuggestSettings.TimeoutSettings; import org.opensearch.client.Client; /* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.settings; public class SuggestSettingsBuilder { protected String settingsIndexName = "fess_suggest";
protected TimeoutSettings timeoutSettings = new TimeoutSettings();
codelibs/fess-suggest
src/main/java/org/codelibs/fess/suggest/settings/SuggestSettings.java
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggestSettingsException.java // public class SuggestSettingsException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggestSettingsException(final String msg) { // super(msg); // } // // public SuggestSettingsException(final Throwable cause) { // super(cause); // } // // public SuggestSettingsException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // // Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import org.codelibs.core.lang.StringUtil; import org.codelibs.fess.suggest.exception.SuggestSettingsException; import org.codelibs.fess.suggest.exception.SuggesterException; import org.opensearch.action.get.GetResponse; import org.opensearch.client.Client; import org.opensearch.common.collect.Tuple; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.index.IndexNotFoundException;
public void init() { if (initialized) { return; } initialized = true; initialize(initialSettings); new AnalyzerSettings(client, this, settingsIndexName).init(); } private void initialize(final Map<String, Object> initialSettings) { boolean doIndexCreate = false; boolean doCreate = false; try { final GetResponse getResponse = client.prepareGet().setIndex(settingsIndexName).setId(settingsId).execute().actionGet(getSearchTimeout()); if (!getResponse.isExists()) { doCreate = true; } } catch (final IndexNotFoundException e) { doIndexCreate = true; doCreate = true; } if (doCreate) { if (doIndexCreate) { try { client.admin().indices().prepareCreate(settingsIndexName).setSettings(loadIndexSettings(), XContentType.JSON).execute() .actionGet(getIndicesTimeout()); } catch (final IOException e) {
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggestSettingsException.java // public class SuggestSettingsException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggestSettingsException(final String msg) { // super(msg); // } // // public SuggestSettingsException(final Throwable cause) { // super(cause); // } // // public SuggestSettingsException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // // Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // Path: src/main/java/org/codelibs/fess/suggest/settings/SuggestSettings.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import org.codelibs.core.lang.StringUtil; import org.codelibs.fess.suggest.exception.SuggestSettingsException; import org.codelibs.fess.suggest.exception.SuggesterException; import org.opensearch.action.get.GetResponse; import org.opensearch.client.Client; import org.opensearch.common.collect.Tuple; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.index.IndexNotFoundException; public void init() { if (initialized) { return; } initialized = true; initialize(initialSettings); new AnalyzerSettings(client, this, settingsIndexName).init(); } private void initialize(final Map<String, Object> initialSettings) { boolean doIndexCreate = false; boolean doCreate = false; try { final GetResponse getResponse = client.prepareGet().setIndex(settingsIndexName).setId(settingsId).execute().actionGet(getSearchTimeout()); if (!getResponse.isExists()) { doCreate = true; } } catch (final IndexNotFoundException e) { doIndexCreate = true; doCreate = true; } if (doCreate) { if (doIndexCreate) { try { client.admin().indices().prepareCreate(settingsIndexName).setSettings(loadIndexSettings(), XContentType.JSON).execute() .actionGet(getIndicesTimeout()); } catch (final IOException e) {
throw new SuggesterException(e);
codelibs/fess-suggest
src/main/java/org/codelibs/fess/suggest/settings/SuggestSettings.java
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggestSettingsException.java // public class SuggestSettingsException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggestSettingsException(final String msg) { // super(msg); // } // // public SuggestSettingsException(final Throwable cause) { // super(cause); // } // // public SuggestSettingsException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // // Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import org.codelibs.core.lang.StringUtil; import org.codelibs.fess.suggest.exception.SuggestSettingsException; import org.codelibs.fess.suggest.exception.SuggesterException; import org.opensearch.action.get.GetResponse; import org.opensearch.client.Client; import org.opensearch.common.collect.Tuple; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.index.IndexNotFoundException;
value = defaultValue; } else { value = Float.parseFloat(obj.toString()); } return value; } public boolean getAsBoolean(final String key, final boolean defaultValue) { final Object obj = get(key); final boolean value; if (obj == null) { value = defaultValue; } else { value = Boolean.parseBoolean(obj.toString()); } return value; } public void set(final String key, final Object value) { if (logger.isLoggable(Level.FINER)) { logger.finer(() -> String.format("Set suggest settings. %s key: %s value: %s", settingsIndexName, key, value)); } try { client.prepareUpdate().setIndex(settingsIndexName).setId(settingsId).setDocAsUpsert(true).setDoc(key, value) .setRetryOnConflict(5).execute().actionGet(getIndexTimeout()); client.admin().indices().prepareRefresh().setIndices(settingsIndexName).execute().actionGet(getIndicesTimeout()); } catch (final Exception e) {
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggestSettingsException.java // public class SuggestSettingsException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggestSettingsException(final String msg) { // super(msg); // } // // public SuggestSettingsException(final Throwable cause) { // super(cause); // } // // public SuggestSettingsException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // // Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // Path: src/main/java/org/codelibs/fess/suggest/settings/SuggestSettings.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import org.codelibs.core.lang.StringUtil; import org.codelibs.fess.suggest.exception.SuggestSettingsException; import org.codelibs.fess.suggest.exception.SuggesterException; import org.opensearch.action.get.GetResponse; import org.opensearch.client.Client; import org.opensearch.common.collect.Tuple; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.index.IndexNotFoundException; value = defaultValue; } else { value = Float.parseFloat(obj.toString()); } return value; } public boolean getAsBoolean(final String key, final boolean defaultValue) { final Object obj = get(key); final boolean value; if (obj == null) { value = defaultValue; } else { value = Boolean.parseBoolean(obj.toString()); } return value; } public void set(final String key, final Object value) { if (logger.isLoggable(Level.FINER)) { logger.finer(() -> String.format("Set suggest settings. %s key: %s value: %s", settingsIndexName, key, value)); } try { client.prepareUpdate().setIndex(settingsIndexName).setId(settingsId).setDocAsUpsert(true).setDoc(key, value) .setRetryOnConflict(5).execute().actionGet(getIndexTimeout()); client.admin().indices().prepareRefresh().setIndices(settingsIndexName).execute().actionGet(getIndicesTimeout()); } catch (final Exception e) {
throw new SuggestSettingsException("Failed to update suggestSettings.", e);
codelibs/fess-suggest
src/test/java/org/codelibs/fess/suggest/concurrent/DeferredTest.java
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // // Path: src/main/java/org/codelibs/fess/suggest/request/suggest/SuggestResponse.java // public class SuggestResponse implements Response { // protected final String index; // // protected final long tookMs; // // protected final List<String> words; // // protected final int num; // // protected final long total; // // protected final List<SuggestItem> items; // // public SuggestResponse(final String index, final long tookMs, final List<String> words, final long total, // final List<SuggestItem> items) { // this.index = index; // this.tookMs = tookMs; // this.words = words; // this.num = words.size(); // this.total = total; // this.items = items; // } // // public String getIndex() { // return index; // } // // public long getTookMs() { // return tookMs; // } // // public List<String> getWords() { // return words; // } // // public int getNum() { // return num; // } // // public long getTotal() { // return total; // } // // public List<SuggestItem> getItems() { // return items; // } // }
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.Collections; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.codelibs.fess.suggest.exception.SuggesterException; import org.codelibs.fess.suggest.request.suggest.SuggestResponse; import org.junit.Test;
/* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.concurrent; public class DeferredTest { @Test public void test_doneBeforeResolve() throws Exception {
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // // Path: src/main/java/org/codelibs/fess/suggest/request/suggest/SuggestResponse.java // public class SuggestResponse implements Response { // protected final String index; // // protected final long tookMs; // // protected final List<String> words; // // protected final int num; // // protected final long total; // // protected final List<SuggestItem> items; // // public SuggestResponse(final String index, final long tookMs, final List<String> words, final long total, // final List<SuggestItem> items) { // this.index = index; // this.tookMs = tookMs; // this.words = words; // this.num = words.size(); // this.total = total; // this.items = items; // } // // public String getIndex() { // return index; // } // // public long getTookMs() { // return tookMs; // } // // public List<String> getWords() { // return words; // } // // public int getNum() { // return num; // } // // public long getTotal() { // return total; // } // // public List<SuggestItem> getItems() { // return items; // } // } // Path: src/test/java/org/codelibs/fess/suggest/concurrent/DeferredTest.java import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.Collections; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.codelibs.fess.suggest.exception.SuggesterException; import org.codelibs.fess.suggest.request.suggest.SuggestResponse; import org.junit.Test; /* * Copyright 2012-2022 CodeLibs Project and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.codelibs.fess.suggest.concurrent; public class DeferredTest { @Test public void test_doneBeforeResolve() throws Exception {
final Deferred<SuggestResponse> deferred = new Deferred<>();
codelibs/fess-suggest
src/test/java/org/codelibs/fess/suggest/concurrent/DeferredTest.java
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // // Path: src/main/java/org/codelibs/fess/suggest/request/suggest/SuggestResponse.java // public class SuggestResponse implements Response { // protected final String index; // // protected final long tookMs; // // protected final List<String> words; // // protected final int num; // // protected final long total; // // protected final List<SuggestItem> items; // // public SuggestResponse(final String index, final long tookMs, final List<String> words, final long total, // final List<SuggestItem> items) { // this.index = index; // this.tookMs = tookMs; // this.words = words; // this.num = words.size(); // this.total = total; // this.items = items; // } // // public String getIndex() { // return index; // } // // public long getTookMs() { // return tookMs; // } // // public List<String> getWords() { // return words; // } // // public int getNum() { // return num; // } // // public long getTotal() { // return total; // } // // public List<SuggestItem> getItems() { // return items; // } // }
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.Collections; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.codelibs.fess.suggest.exception.SuggesterException; import org.codelibs.fess.suggest.request.suggest.SuggestResponse; import org.junit.Test;
deferred.resolve(new SuggestResponse("", 0, Collections.emptyList(), 0, null)); }); th.start(); SuggestResponse response = deferred.promise().getResponse(10, TimeUnit.SECONDS); assertEquals(0, response.getNum()); } @Test public void test_getResponseAfterResolve() throws Exception { final Deferred<SuggestResponse> deferred = new Deferred<>(); Thread th = new Thread(() -> { deferred.resolve(new SuggestResponse("", 0, Collections.emptyList(), 0, null)); }); th.start(); Thread.sleep(1000); SuggestResponse response = deferred.promise().getResponse(10, TimeUnit.SECONDS); assertEquals(0, response.getNum()); } @Test public void test_getResponseWithException() throws Exception { final Deferred<SuggestResponse> deferred = new Deferred<>(); Thread th = new Thread(() -> { try { Thread.sleep(1000); } catch (InterruptedException ignore) {}
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java // public class SuggesterException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public SuggesterException(final String msg) { // super(msg); // } // // public SuggesterException(final Throwable cause) { // super(cause); // } // // public SuggesterException(final String msg, final Throwable cause) { // super(msg, cause); // } // } // // Path: src/main/java/org/codelibs/fess/suggest/request/suggest/SuggestResponse.java // public class SuggestResponse implements Response { // protected final String index; // // protected final long tookMs; // // protected final List<String> words; // // protected final int num; // // protected final long total; // // protected final List<SuggestItem> items; // // public SuggestResponse(final String index, final long tookMs, final List<String> words, final long total, // final List<SuggestItem> items) { // this.index = index; // this.tookMs = tookMs; // this.words = words; // this.num = words.size(); // this.total = total; // this.items = items; // } // // public String getIndex() { // return index; // } // // public long getTookMs() { // return tookMs; // } // // public List<String> getWords() { // return words; // } // // public int getNum() { // return num; // } // // public long getTotal() { // return total; // } // // public List<SuggestItem> getItems() { // return items; // } // } // Path: src/test/java/org/codelibs/fess/suggest/concurrent/DeferredTest.java import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.Collections; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.codelibs.fess.suggest.exception.SuggesterException; import org.codelibs.fess.suggest.request.suggest.SuggestResponse; import org.junit.Test; deferred.resolve(new SuggestResponse("", 0, Collections.emptyList(), 0, null)); }); th.start(); SuggestResponse response = deferred.promise().getResponse(10, TimeUnit.SECONDS); assertEquals(0, response.getNum()); } @Test public void test_getResponseAfterResolve() throws Exception { final Deferred<SuggestResponse> deferred = new Deferred<>(); Thread th = new Thread(() -> { deferred.resolve(new SuggestResponse("", 0, Collections.emptyList(), 0, null)); }); th.start(); Thread.sleep(1000); SuggestResponse response = deferred.promise().getResponse(10, TimeUnit.SECONDS); assertEquals(0, response.getNum()); } @Test public void test_getResponseWithException() throws Exception { final Deferred<SuggestResponse> deferred = new Deferred<>(); Thread th = new Thread(() -> { try { Thread.sleep(1000); } catch (InterruptedException ignore) {}
deferred.reject(new SuggesterException("test"));
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/BaseView.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/ENUM_SNACKBAR_ACTIONS.java // public enum ENUM_SNACKBAR_ACTIONS { // // NONE, REFRESH, SELECT_DEPARTURE, SELECT_ARRIVAL, SELECT_TRAIN_NUMBER, ACCEPT // // }
import android.content.Context; import com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.ENUM_SNACKBAR_ACTIONS;
package com.jaus.albertogiunta.justintrain_oraritreni; public interface BaseView { /* public void onCreate(Bundle savedInstanceState) public void onResume() public void onDestroy() protected void onSaveInstanceState(Bundle outState) */ /** * Getter for the view context. (Needed when dealing with shared prefs and such). */ Context getViewContext(); /** * Because everybody might need a snackbar at some point. * @param message The message to display * @param intent use it to understand what to do. It also should determine the action string. * @param duration */
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/ENUM_SNACKBAR_ACTIONS.java // public enum ENUM_SNACKBAR_ACTIONS { // // NONE, REFRESH, SELECT_DEPARTURE, SELECT_ARRIVAL, SELECT_TRAIN_NUMBER, ACCEPT // // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/BaseView.java import android.content.Context; import com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.ENUM_SNACKBAR_ACTIONS; package com.jaus.albertogiunta.justintrain_oraritreni; public interface BaseView { /* public void onCreate(Bundle savedInstanceState) public void onResume() public void onDestroy() protected void onSaveInstanceState(Bundle outState) */ /** * Getter for the view context. (Needed when dealing with shared prefs and such). */ Context getViewContext(); /** * Because everybody might need a snackbar at some point. * @param message The message to display * @param intent use it to understand what to do. It also should determine the action string. * @param duration */
void showSnackbar(String message, ENUM_SNACKBAR_ACTIONS intent, int duration);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/networking/APINetworkingFactory.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/ServerConfigsHelper.java // public class ServerConfigsHelper { // // public static String getAPIEndpoint() { // return FirebaseRemoteConfig.getInstance().getString(FIREBASE_SERVER_CONFIG); // } // // public static void removeAPIEndpoint(Context context) { // SharedPreferencesHelper.removeSharedPreferenceObject(context, SP_SP_SERVER_CONFIG); // } // // public static int getProUsersNumberFromSharedPreferences(Context context) { // return SharedPreferencesHelper.getSharedPreferenceInt(context, SP_SP_PRO_USERS_NUMBER, 2); // } // // public static void setProUsersInSharedPreferences(Context context, int number) { // SharedPreferencesHelper.setSharedPreferenceInt(context, SP_SP_PRO_USERS_NUMBER, number); // } // // }
import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.jaus.albertogiunta.justintrain_oraritreni.BuildConfig; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.ServerConfigsHelper; import org.joda.time.DateTime; import io.reactivex.schedulers.Schedulers; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory;
package com.jaus.albertogiunta.justintrain_oraritreni.networking; public class APINetworkingFactory { /** * Creates a retrofit service from an arbitrary class (clazz) * * @param clazz Java interface of the retrofit service * @return retrofit service with defined endpoint */ public static <T> T createRetrofitService(final Class<T> clazz) { HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .addInterceptor(chain -> { Request original = chain.request(); // Request customization: add request headers Request.Builder requestBuilder = original.newBuilder() .header(BuildConfig.AUTH_FIELD_NAME, BuildConfig.AUTH_TOKEN) .method(original.method(), original.body()); Request request = requestBuilder.build(); return chain.proceed(request); }) .build(); Gson gson = new GsonBuilder() .registerTypeAdapter(DateTime.class, new DateTimeAdapter()) .registerTypeAdapterFactory(new PostProcessingEnabler()) .create(); final Retrofit restAdapter = new Retrofit.Builder()
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/ServerConfigsHelper.java // public class ServerConfigsHelper { // // public static String getAPIEndpoint() { // return FirebaseRemoteConfig.getInstance().getString(FIREBASE_SERVER_CONFIG); // } // // public static void removeAPIEndpoint(Context context) { // SharedPreferencesHelper.removeSharedPreferenceObject(context, SP_SP_SERVER_CONFIG); // } // // public static int getProUsersNumberFromSharedPreferences(Context context) { // return SharedPreferencesHelper.getSharedPreferenceInt(context, SP_SP_PRO_USERS_NUMBER, 2); // } // // public static void setProUsersInSharedPreferences(Context context, int number) { // SharedPreferencesHelper.setSharedPreferenceInt(context, SP_SP_PRO_USERS_NUMBER, number); // } // // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/networking/APINetworkingFactory.java import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.jaus.albertogiunta.justintrain_oraritreni.BuildConfig; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.ServerConfigsHelper; import org.joda.time.DateTime; import io.reactivex.schedulers.Schedulers; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; package com.jaus.albertogiunta.justintrain_oraritreni.networking; public class APINetworkingFactory { /** * Creates a retrofit service from an arbitrary class (clazz) * * @param clazz Java interface of the retrofit service * @return retrofit service with defined endpoint */ public static <T> T createRetrofitService(final Class<T> clazz) { HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .addInterceptor(chain -> { Request original = chain.request(); // Request customization: add request headers Request.Builder requestBuilder = original.newBuilder() .header(BuildConfig.AUTH_FIELD_NAME, BuildConfig.AUTH_TOKEN) .method(original.method(), original.body()); Request request = requestBuilder.build(); return chain.proceed(request); }) .build(); Gson gson = new GsonBuilder() .registerTypeAdapter(DateTime.class, new DateTimeAdapter()) .registerTypeAdapterFactory(new PostProcessingEnabler()) .create(); final Retrofit restAdapter = new Retrofit.Builder()
.baseUrl(ServerConfigsHelper.getAPIEndpoint())
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // }
import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting;
package com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences; public class ProPreferences { public static void enableAllPro(Context context) { ProPreferences.enablePro(context); ProPreferences.enableLiveNotification(context); ProPreferences.enableInstantDelay(context); ProPreferences.enableCompactNotification(context); ProPreferences.enableAutoRemoveNotification(context); } public static void disableAllPro(Context context) { ProPreferences.disablePro(context); ProPreferences.disableLiveNotification(context); ProPreferences.disableInstantDelay(context); ProPreferences.disableCompactNotification(context); ProPreferences.disableAutoRemoveNotification(context); } // instant delay public static boolean isPro(Context context) {
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting; package com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences; public class ProPreferences { public static void enableAllPro(Context context) { ProPreferences.enablePro(context); ProPreferences.enableLiveNotification(context); ProPreferences.enableInstantDelay(context); ProPreferences.enableCompactNotification(context); ProPreferences.enableAutoRemoveNotification(context); } public static void disableAllPro(Context context) { ProPreferences.disablePro(context); ProPreferences.disableLiveNotification(context); ProPreferences.disableInstantDelay(context); ProPreferences.disableCompactNotification(context); ProPreferences.disableAutoRemoveNotification(context); } // instant delay public static boolean isPro(Context context) {
return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SP_IS_PRO, false);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // }
import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting;
package com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences; public class ProPreferences { public static void enableAllPro(Context context) { ProPreferences.enablePro(context); ProPreferences.enableLiveNotification(context); ProPreferences.enableInstantDelay(context); ProPreferences.enableCompactNotification(context); ProPreferences.enableAutoRemoveNotification(context); } public static void disableAllPro(Context context) { ProPreferences.disablePro(context); ProPreferences.disableLiveNotification(context); ProPreferences.disableInstantDelay(context); ProPreferences.disableCompactNotification(context); ProPreferences.disableAutoRemoveNotification(context); } // instant delay public static boolean isPro(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SP_IS_PRO, false); } public static void enablePro(Context context) {
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting; package com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences; public class ProPreferences { public static void enableAllPro(Context context) { ProPreferences.enablePro(context); ProPreferences.enableLiveNotification(context); ProPreferences.enableInstantDelay(context); ProPreferences.enableCompactNotification(context); ProPreferences.enableAutoRemoveNotification(context); } public static void disableAllPro(Context context) { ProPreferences.disablePro(context); ProPreferences.disableLiveNotification(context); ProPreferences.disableInstantDelay(context); ProPreferences.disableCompactNotification(context); ProPreferences.disableAutoRemoveNotification(context); } // instant delay public static boolean isPro(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SP_IS_PRO, false); } public static void enablePro(Context context) {
enableGenericSetting(context, SP_SP_IS_PRO);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // }
import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting;
package com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences; public class ProPreferences { public static void enableAllPro(Context context) { ProPreferences.enablePro(context); ProPreferences.enableLiveNotification(context); ProPreferences.enableInstantDelay(context); ProPreferences.enableCompactNotification(context); ProPreferences.enableAutoRemoveNotification(context); } public static void disableAllPro(Context context) { ProPreferences.disablePro(context); ProPreferences.disableLiveNotification(context); ProPreferences.disableInstantDelay(context); ProPreferences.disableCompactNotification(context); ProPreferences.disableAutoRemoveNotification(context); } // instant delay public static boolean isPro(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SP_IS_PRO, false); } public static void enablePro(Context context) { enableGenericSetting(context, SP_SP_IS_PRO); } public static void disablePro(Context context) {
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting; package com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences; public class ProPreferences { public static void enableAllPro(Context context) { ProPreferences.enablePro(context); ProPreferences.enableLiveNotification(context); ProPreferences.enableInstantDelay(context); ProPreferences.enableCompactNotification(context); ProPreferences.enableAutoRemoveNotification(context); } public static void disableAllPro(Context context) { ProPreferences.disablePro(context); ProPreferences.disableLiveNotification(context); ProPreferences.disableInstantDelay(context); ProPreferences.disableCompactNotification(context); ProPreferences.disableAutoRemoveNotification(context); } // instant delay public static boolean isPro(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SP_IS_PRO, false); } public static void enablePro(Context context) { enableGenericSetting(context, SP_SP_IS_PRO); } public static void disablePro(Context context) {
disableGenericSetting(context, SP_SP_IS_PRO);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // }
import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting;
package com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences; public class ProPreferences { public static void enableAllPro(Context context) { ProPreferences.enablePro(context); ProPreferences.enableLiveNotification(context); ProPreferences.enableInstantDelay(context); ProPreferences.enableCompactNotification(context); ProPreferences.enableAutoRemoveNotification(context); } public static void disableAllPro(Context context) { ProPreferences.disablePro(context); ProPreferences.disableLiveNotification(context); ProPreferences.disableInstantDelay(context); ProPreferences.disableCompactNotification(context); ProPreferences.disableAutoRemoveNotification(context); } // instant delay public static boolean isPro(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SP_IS_PRO, false); } public static void enablePro(Context context) { enableGenericSetting(context, SP_SP_IS_PRO); } public static void disablePro(Context context) { disableGenericSetting(context, SP_SP_IS_PRO); } // instant delay public static boolean isInstantDelayEnabled(Context context) {
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting; package com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences; public class ProPreferences { public static void enableAllPro(Context context) { ProPreferences.enablePro(context); ProPreferences.enableLiveNotification(context); ProPreferences.enableInstantDelay(context); ProPreferences.enableCompactNotification(context); ProPreferences.enableAutoRemoveNotification(context); } public static void disableAllPro(Context context) { ProPreferences.disablePro(context); ProPreferences.disableLiveNotification(context); ProPreferences.disableInstantDelay(context); ProPreferences.disableCompactNotification(context); ProPreferences.disableAutoRemoveNotification(context); } // instant delay public static boolean isPro(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SP_IS_PRO, false); } public static void enablePro(Context context) { enableGenericSetting(context, SP_SP_IS_PRO); } public static void disablePro(Context context) { disableGenericSetting(context, SP_SP_IS_PRO); } // instant delay public static boolean isInstantDelayEnabled(Context context) {
return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_INSTANT_DELAY, true);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // }
import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting;
} // instant delay public static boolean isPro(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SP_IS_PRO, false); } public static void enablePro(Context context) { enableGenericSetting(context, SP_SP_IS_PRO); } public static void disablePro(Context context) { disableGenericSetting(context, SP_SP_IS_PRO); } // instant delay public static boolean isInstantDelayEnabled(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_INSTANT_DELAY, true); } public static void enableInstantDelay(Context context) { enableGenericSetting(context, SP_SETT_INSTANT_DELAY); } public static void disableInstantDelay(Context context) { disableGenericSetting(context, SP_SETT_INSTANT_DELAY); } // live notification public static boolean isLiveNotificationEnabled(Context context) {
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting; } // instant delay public static boolean isPro(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SP_IS_PRO, false); } public static void enablePro(Context context) { enableGenericSetting(context, SP_SP_IS_PRO); } public static void disablePro(Context context) { disableGenericSetting(context, SP_SP_IS_PRO); } // instant delay public static boolean isInstantDelayEnabled(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_INSTANT_DELAY, true); } public static void enableInstantDelay(Context context) { enableGenericSetting(context, SP_SETT_INSTANT_DELAY); } public static void disableInstantDelay(Context context) { disableGenericSetting(context, SP_SETT_INSTANT_DELAY); } // live notification public static boolean isLiveNotificationEnabled(Context context) {
return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_NOTIF_LIVE, true);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // }
import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting;
} // instant delay public static boolean isInstantDelayEnabled(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_INSTANT_DELAY, true); } public static void enableInstantDelay(Context context) { enableGenericSetting(context, SP_SETT_INSTANT_DELAY); } public static void disableInstantDelay(Context context) { disableGenericSetting(context, SP_SETT_INSTANT_DELAY); } // live notification public static boolean isLiveNotificationEnabled(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_NOTIF_LIVE, true); } public static void enableLiveNotification(Context context) { enableGenericSetting(context, SP_SETT_NOTIF_LIVE); } public static void disableLiveNotification(Context context) { disableGenericSetting(context, SP_SETT_NOTIF_LIVE); } // live notification public static boolean isCompactNotificationEnabled(Context context) {
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting; } // instant delay public static boolean isInstantDelayEnabled(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_INSTANT_DELAY, true); } public static void enableInstantDelay(Context context) { enableGenericSetting(context, SP_SETT_INSTANT_DELAY); } public static void disableInstantDelay(Context context) { disableGenericSetting(context, SP_SETT_INSTANT_DELAY); } // live notification public static boolean isLiveNotificationEnabled(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_NOTIF_LIVE, true); } public static void enableLiveNotification(Context context) { enableGenericSetting(context, SP_SETT_NOTIF_LIVE); } public static void disableLiveNotification(Context context) { disableGenericSetting(context, SP_SETT_NOTIF_LIVE); } // live notification public static boolean isCompactNotificationEnabled(Context context) {
return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_NOTIF_COMPACT, true);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // }
import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting;
} // live notification public static boolean isLiveNotificationEnabled(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_NOTIF_LIVE, true); } public static void enableLiveNotification(Context context) { enableGenericSetting(context, SP_SETT_NOTIF_LIVE); } public static void disableLiveNotification(Context context) { disableGenericSetting(context, SP_SETT_NOTIF_LIVE); } // live notification public static boolean isCompactNotificationEnabled(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_NOTIF_COMPACT, true); } public static void enableCompactNotification(Context context) { enableGenericSetting(context, SP_SETT_NOTIF_COMPACT); } public static void disableCompactNotification(Context context) { disableGenericSetting(context, SP_SETT_NOTIF_COMPACT); } // auto removing notification public static boolean isAutoRemoveNotificationEnabled(Context context) {
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_INSTANT_DELAY = "settings>isInstantDelayEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_AUTO_REMOVE = "settings>isNotifAutoRemoveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_COMPACT = "settings>isNotifCompactEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SETT_NOTIF_LIVE = "settings>isNotifLiveEnabled"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String SP_SP_IS_PRO = "prefs>isPro"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void disableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, false); // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/SettingsPreferences.java // public static void enableGenericSetting(Context context, String CONST) { // SharedPreferencesHelper.setSharedPreferenceBoolean(context, CONST, true); // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/sharedPreferences/ProPreferences.java import android.content.Context; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_INSTANT_DELAY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_AUTO_REMOVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_COMPACT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SETT_NOTIF_LIVE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.SP_SP_IS_PRO; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.disableGenericSetting; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.sharedPreferences.SettingsPreferences.enableGenericSetting; } // live notification public static boolean isLiveNotificationEnabled(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_NOTIF_LIVE, true); } public static void enableLiveNotification(Context context) { enableGenericSetting(context, SP_SETT_NOTIF_LIVE); } public static void disableLiveNotification(Context context) { disableGenericSetting(context, SP_SETT_NOTIF_LIVE); } // live notification public static boolean isCompactNotificationEnabled(Context context) { return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_NOTIF_COMPACT, true); } public static void enableCompactNotification(Context context) { enableGenericSetting(context, SP_SETT_NOTIF_COMPACT); } public static void disableCompactNotification(Context context) { disableGenericSetting(context, SP_SETT_NOTIF_COMPACT); } // auto removing notification public static boolean isAutoRemoveNotificationEnabled(Context context) {
return SharedPreferencesHelper.getSharedPreferenceBoolean(context, SP_SETT_NOTIF_AUTO_REMOVE, true);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/ENUM_HOME_HEADER.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String PREFIX_PREF_JOURNEY = "prefJourney>"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String PREFIX_REC_JOURNEY = "recJourney>";
import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.PREFIX_PREF_JOURNEY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.PREFIX_REC_JOURNEY;
package com.jaus.albertogiunta.justintrain_oraritreni.utils.constants; public enum ENUM_HOME_HEADER { FAVOURITES("Preferiti", PREFIX_PREF_JOURNEY),
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String PREFIX_PREF_JOURNEY = "prefJourney>"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_SP_V0.java // public static final String PREFIX_REC_JOURNEY = "recJourney>"; // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/ENUM_HOME_HEADER.java import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.PREFIX_PREF_JOURNEY; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_SP_V0.PREFIX_REC_JOURNEY; package com.jaus.albertogiunta.justintrain_oraritreni.utils.constants; public enum ENUM_HOME_HEADER { FAVOURITES("Preferiti", PREFIX_PREF_JOURNEY),
RECENT("Recenti", PREFIX_REC_JOURNEY);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/aboutAndSettings/AboutActivity.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/tutorial/IntroActivity.java // public class IntroActivity extends AppIntro2 { // // AnalyticsHelper analyticsHelper; // // @Override // protected void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // analyticsHelper = AnalyticsHelper.getInstance(this); // addSlide(AppIntro2Fragment.newInstance("Percorri sempre la stessa tratta?", // "Aggiungi le tue tratte e i tuoi treni abituali ai preferiti, per averli sempre a portata di mano!", R.drawable.tut1, Color.parseColor("#717C8D"))); // addSlide(AppIntro2Fragment.newInstance("Andata? Ritorno?", "No problem. Trascina la tratta preferita verso dove vuoi andare. Proprio come ti verrebbe naturale fare.", R.drawable.tut2, Color.parseColor("#717C8D"))); // addSlide(AppIntro2Fragment.newInstance("Treno poco affidabile?", "Tienilo sempre sotto controllo tramite la notifica!", R.drawable.tut3, Color.parseColor("#717C8D"))); // } // // @Override // public void onDonePressed(Fragment currentFragment) { // super.onDonePressed(currentFragment); // analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_DONE); // finish(); // } // // @Override // public void onSkipPressed(Fragment currentFragment) { // super.onSkipPressed(currentFragment); // analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_SKIP); // finish(); // } // // @Override // public void onSlideChanged(@Nullable Fragment oldFragment, @Nullable Fragment newFragment) { // super.onSlideChanged(oldFragment, newFragment); // analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_NEXT); // } // // // @Override // protected void attachBaseContext(Context newBase) { // super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase)); // } // }
import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.widget.LinearLayout; import android.widget.Toast; import com.jaus.albertogiunta.justintrain_oraritreni.BuildConfig; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.tutorial.IntroActivity; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
startActivity(Intent.createChooser(sendIntent, "Consiglia l'app via...")); }) .build()) .addSeparator() //-----------------------------------------// .addItem(new ItemBuilder(this, linearLayout) .addItemWithTitleSubtitle("Iscriviti al canale Telegram!", "Per anticipazioni e per votare nuove feature") .addOnClickListener(view -> { if (AboutPageUtils.isAppInstalled(this, "org.telegram.messenger")) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setData(Uri.parse("https://telegram.me/justintrain")); startActivity(intent); } else { Toast.makeText(this, "Telegram non sembra essere installato sul tuo dispositivo!", Toast.LENGTH_LONG).show(); } }) .build()) .addItem(new ItemBuilder(this, linearLayout).addItemGroupHeader("Info sull'app").build()) .addItem(new ItemBuilder(this, linearLayout) .addItemWithTitleSubtitle("Changelog", "Versione " + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")") .addOnClickListener(view -> { handler.sendEmptyMessage(1); }) .build()) .addSeparator() //-----------------------------------------// .addItem(new ItemBuilder(this, linearLayout) .addItemWithTitleSubtitle("Tutorial", "Clicca per visualizzare il Tutorial") .addOnClickListener(view -> {
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/tutorial/IntroActivity.java // public class IntroActivity extends AppIntro2 { // // AnalyticsHelper analyticsHelper; // // @Override // protected void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // analyticsHelper = AnalyticsHelper.getInstance(this); // addSlide(AppIntro2Fragment.newInstance("Percorri sempre la stessa tratta?", // "Aggiungi le tue tratte e i tuoi treni abituali ai preferiti, per averli sempre a portata di mano!", R.drawable.tut1, Color.parseColor("#717C8D"))); // addSlide(AppIntro2Fragment.newInstance("Andata? Ritorno?", "No problem. Trascina la tratta preferita verso dove vuoi andare. Proprio come ti verrebbe naturale fare.", R.drawable.tut2, Color.parseColor("#717C8D"))); // addSlide(AppIntro2Fragment.newInstance("Treno poco affidabile?", "Tienilo sempre sotto controllo tramite la notifica!", R.drawable.tut3, Color.parseColor("#717C8D"))); // } // // @Override // public void onDonePressed(Fragment currentFragment) { // super.onDonePressed(currentFragment); // analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_DONE); // finish(); // } // // @Override // public void onSkipPressed(Fragment currentFragment) { // super.onSkipPressed(currentFragment); // analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_SKIP); // finish(); // } // // @Override // public void onSlideChanged(@Nullable Fragment oldFragment, @Nullable Fragment newFragment) { // super.onSlideChanged(oldFragment, newFragment); // analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_NEXT); // } // // // @Override // protected void attachBaseContext(Context newBase) { // super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase)); // } // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/aboutAndSettings/AboutActivity.java import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.widget.LinearLayout; import android.widget.Toast; import com.jaus.albertogiunta.justintrain_oraritreni.BuildConfig; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.tutorial.IntroActivity; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; startActivity(Intent.createChooser(sendIntent, "Consiglia l'app via...")); }) .build()) .addSeparator() //-----------------------------------------// .addItem(new ItemBuilder(this, linearLayout) .addItemWithTitleSubtitle("Iscriviti al canale Telegram!", "Per anticipazioni e per votare nuove feature") .addOnClickListener(view -> { if (AboutPageUtils.isAppInstalled(this, "org.telegram.messenger")) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setData(Uri.parse("https://telegram.me/justintrain")); startActivity(intent); } else { Toast.makeText(this, "Telegram non sembra essere installato sul tuo dispositivo!", Toast.LENGTH_LONG).show(); } }) .build()) .addItem(new ItemBuilder(this, linearLayout).addItemGroupHeader("Info sull'app").build()) .addItem(new ItemBuilder(this, linearLayout) .addItemWithTitleSubtitle("Changelog", "Versione " + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")") .addOnClickListener(view -> { handler.sendEmptyMessage(1); }) .build()) .addSeparator() //-----------------------------------------// .addItem(new ItemBuilder(this, linearLayout) .addItemWithTitleSubtitle("Tutorial", "Clicca per visualizzare il Tutorial") .addOnClickListener(view -> {
Intent i = new Intent(AboutActivity.this, IntroActivity.class);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/tutorial/IntroActivity.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/AnalyticsHelper.java // public class AnalyticsHelper { // // /* // // adb shell setprop log.tag.FA VERBOSE // adb shell setprop log.tag.FA-SVC VERBOSE // adb logcat -v time -s FA FA-SVC // // */ // // private FirebaseAnalytics firebase = null; // // private static AnalyticsHelper analyticsHelper; // // public static AnalyticsHelper getInstance(Context context) { // if (analyticsHelper == null) { // analyticsHelper = new AnalyticsHelper(context); // } // return analyticsHelper; // } // // private AnalyticsHelper(Context context) { // firebase = FirebaseAnalytics.getInstance(context); // firebase.setMinimumSessionDuration(3000); // // firebase.setUserId(); // // firebase.setUserProperty(); // } // // public void logScreenEvent(String screen, String action) { // Bundle bundle = new Bundle(); // bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, screen); // bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, action); // bundle.putString(FirebaseAnalytics.Param.ITEM_ID, action); // firebase.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); // } // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_DONE = " Done Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_NEXT = " Next slide"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_SKIP = " Skip Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String SCREEN_TUTORIAL = "TUT";
import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import com.github.paolorotolo.appintro.AppIntro2; import com.github.paolorotolo.appintro.AppIntro2Fragment; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.AnalyticsHelper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_DONE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_NEXT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_SKIP; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.SCREEN_TUTORIAL;
package com.jaus.albertogiunta.justintrain_oraritreni.tutorial; public class IntroActivity extends AppIntro2 { AnalyticsHelper analyticsHelper; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); analyticsHelper = AnalyticsHelper.getInstance(this); addSlide(AppIntro2Fragment.newInstance("Percorri sempre la stessa tratta?", "Aggiungi le tue tratte e i tuoi treni abituali ai preferiti, per averli sempre a portata di mano!", R.drawable.tut1, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Andata? Ritorno?", "No problem. Trascina la tratta preferita verso dove vuoi andare. Proprio come ti verrebbe naturale fare.", R.drawable.tut2, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Treno poco affidabile?", "Tienilo sempre sotto controllo tramite la notifica!", R.drawable.tut3, Color.parseColor("#717C8D"))); } @Override public void onDonePressed(Fragment currentFragment) { super.onDonePressed(currentFragment);
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/AnalyticsHelper.java // public class AnalyticsHelper { // // /* // // adb shell setprop log.tag.FA VERBOSE // adb shell setprop log.tag.FA-SVC VERBOSE // adb logcat -v time -s FA FA-SVC // // */ // // private FirebaseAnalytics firebase = null; // // private static AnalyticsHelper analyticsHelper; // // public static AnalyticsHelper getInstance(Context context) { // if (analyticsHelper == null) { // analyticsHelper = new AnalyticsHelper(context); // } // return analyticsHelper; // } // // private AnalyticsHelper(Context context) { // firebase = FirebaseAnalytics.getInstance(context); // firebase.setMinimumSessionDuration(3000); // // firebase.setUserId(); // // firebase.setUserProperty(); // } // // public void logScreenEvent(String screen, String action) { // Bundle bundle = new Bundle(); // bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, screen); // bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, action); // bundle.putString(FirebaseAnalytics.Param.ITEM_ID, action); // firebase.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); // } // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_DONE = " Done Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_NEXT = " Next slide"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_SKIP = " Skip Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String SCREEN_TUTORIAL = "TUT"; // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/tutorial/IntroActivity.java import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import com.github.paolorotolo.appintro.AppIntro2; import com.github.paolorotolo.appintro.AppIntro2Fragment; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.AnalyticsHelper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_DONE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_NEXT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_SKIP; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.SCREEN_TUTORIAL; package com.jaus.albertogiunta.justintrain_oraritreni.tutorial; public class IntroActivity extends AppIntro2 { AnalyticsHelper analyticsHelper; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); analyticsHelper = AnalyticsHelper.getInstance(this); addSlide(AppIntro2Fragment.newInstance("Percorri sempre la stessa tratta?", "Aggiungi le tue tratte e i tuoi treni abituali ai preferiti, per averli sempre a portata di mano!", R.drawable.tut1, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Andata? Ritorno?", "No problem. Trascina la tratta preferita verso dove vuoi andare. Proprio come ti verrebbe naturale fare.", R.drawable.tut2, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Treno poco affidabile?", "Tienilo sempre sotto controllo tramite la notifica!", R.drawable.tut3, Color.parseColor("#717C8D"))); } @Override public void onDonePressed(Fragment currentFragment) { super.onDonePressed(currentFragment);
analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_DONE);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/tutorial/IntroActivity.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/AnalyticsHelper.java // public class AnalyticsHelper { // // /* // // adb shell setprop log.tag.FA VERBOSE // adb shell setprop log.tag.FA-SVC VERBOSE // adb logcat -v time -s FA FA-SVC // // */ // // private FirebaseAnalytics firebase = null; // // private static AnalyticsHelper analyticsHelper; // // public static AnalyticsHelper getInstance(Context context) { // if (analyticsHelper == null) { // analyticsHelper = new AnalyticsHelper(context); // } // return analyticsHelper; // } // // private AnalyticsHelper(Context context) { // firebase = FirebaseAnalytics.getInstance(context); // firebase.setMinimumSessionDuration(3000); // // firebase.setUserId(); // // firebase.setUserProperty(); // } // // public void logScreenEvent(String screen, String action) { // Bundle bundle = new Bundle(); // bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, screen); // bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, action); // bundle.putString(FirebaseAnalytics.Param.ITEM_ID, action); // firebase.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); // } // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_DONE = " Done Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_NEXT = " Next slide"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_SKIP = " Skip Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String SCREEN_TUTORIAL = "TUT";
import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import com.github.paolorotolo.appintro.AppIntro2; import com.github.paolorotolo.appintro.AppIntro2Fragment; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.AnalyticsHelper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_DONE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_NEXT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_SKIP; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.SCREEN_TUTORIAL;
package com.jaus.albertogiunta.justintrain_oraritreni.tutorial; public class IntroActivity extends AppIntro2 { AnalyticsHelper analyticsHelper; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); analyticsHelper = AnalyticsHelper.getInstance(this); addSlide(AppIntro2Fragment.newInstance("Percorri sempre la stessa tratta?", "Aggiungi le tue tratte e i tuoi treni abituali ai preferiti, per averli sempre a portata di mano!", R.drawable.tut1, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Andata? Ritorno?", "No problem. Trascina la tratta preferita verso dove vuoi andare. Proprio come ti verrebbe naturale fare.", R.drawable.tut2, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Treno poco affidabile?", "Tienilo sempre sotto controllo tramite la notifica!", R.drawable.tut3, Color.parseColor("#717C8D"))); } @Override public void onDonePressed(Fragment currentFragment) { super.onDonePressed(currentFragment);
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/AnalyticsHelper.java // public class AnalyticsHelper { // // /* // // adb shell setprop log.tag.FA VERBOSE // adb shell setprop log.tag.FA-SVC VERBOSE // adb logcat -v time -s FA FA-SVC // // */ // // private FirebaseAnalytics firebase = null; // // private static AnalyticsHelper analyticsHelper; // // public static AnalyticsHelper getInstance(Context context) { // if (analyticsHelper == null) { // analyticsHelper = new AnalyticsHelper(context); // } // return analyticsHelper; // } // // private AnalyticsHelper(Context context) { // firebase = FirebaseAnalytics.getInstance(context); // firebase.setMinimumSessionDuration(3000); // // firebase.setUserId(); // // firebase.setUserProperty(); // } // // public void logScreenEvent(String screen, String action) { // Bundle bundle = new Bundle(); // bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, screen); // bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, action); // bundle.putString(FirebaseAnalytics.Param.ITEM_ID, action); // firebase.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); // } // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_DONE = " Done Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_NEXT = " Next slide"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_SKIP = " Skip Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String SCREEN_TUTORIAL = "TUT"; // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/tutorial/IntroActivity.java import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import com.github.paolorotolo.appintro.AppIntro2; import com.github.paolorotolo.appintro.AppIntro2Fragment; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.AnalyticsHelper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_DONE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_NEXT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_SKIP; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.SCREEN_TUTORIAL; package com.jaus.albertogiunta.justintrain_oraritreni.tutorial; public class IntroActivity extends AppIntro2 { AnalyticsHelper analyticsHelper; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); analyticsHelper = AnalyticsHelper.getInstance(this); addSlide(AppIntro2Fragment.newInstance("Percorri sempre la stessa tratta?", "Aggiungi le tue tratte e i tuoi treni abituali ai preferiti, per averli sempre a portata di mano!", R.drawable.tut1, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Andata? Ritorno?", "No problem. Trascina la tratta preferita verso dove vuoi andare. Proprio come ti verrebbe naturale fare.", R.drawable.tut2, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Treno poco affidabile?", "Tienilo sempre sotto controllo tramite la notifica!", R.drawable.tut3, Color.parseColor("#717C8D"))); } @Override public void onDonePressed(Fragment currentFragment) { super.onDonePressed(currentFragment);
analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_DONE);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/tutorial/IntroActivity.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/AnalyticsHelper.java // public class AnalyticsHelper { // // /* // // adb shell setprop log.tag.FA VERBOSE // adb shell setprop log.tag.FA-SVC VERBOSE // adb logcat -v time -s FA FA-SVC // // */ // // private FirebaseAnalytics firebase = null; // // private static AnalyticsHelper analyticsHelper; // // public static AnalyticsHelper getInstance(Context context) { // if (analyticsHelper == null) { // analyticsHelper = new AnalyticsHelper(context); // } // return analyticsHelper; // } // // private AnalyticsHelper(Context context) { // firebase = FirebaseAnalytics.getInstance(context); // firebase.setMinimumSessionDuration(3000); // // firebase.setUserId(); // // firebase.setUserProperty(); // } // // public void logScreenEvent(String screen, String action) { // Bundle bundle = new Bundle(); // bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, screen); // bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, action); // bundle.putString(FirebaseAnalytics.Param.ITEM_ID, action); // firebase.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); // } // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_DONE = " Done Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_NEXT = " Next slide"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_SKIP = " Skip Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String SCREEN_TUTORIAL = "TUT";
import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import com.github.paolorotolo.appintro.AppIntro2; import com.github.paolorotolo.appintro.AppIntro2Fragment; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.AnalyticsHelper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_DONE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_NEXT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_SKIP; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.SCREEN_TUTORIAL;
package com.jaus.albertogiunta.justintrain_oraritreni.tutorial; public class IntroActivity extends AppIntro2 { AnalyticsHelper analyticsHelper; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); analyticsHelper = AnalyticsHelper.getInstance(this); addSlide(AppIntro2Fragment.newInstance("Percorri sempre la stessa tratta?", "Aggiungi le tue tratte e i tuoi treni abituali ai preferiti, per averli sempre a portata di mano!", R.drawable.tut1, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Andata? Ritorno?", "No problem. Trascina la tratta preferita verso dove vuoi andare. Proprio come ti verrebbe naturale fare.", R.drawable.tut2, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Treno poco affidabile?", "Tienilo sempre sotto controllo tramite la notifica!", R.drawable.tut3, Color.parseColor("#717C8D"))); } @Override public void onDonePressed(Fragment currentFragment) { super.onDonePressed(currentFragment); analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_DONE); finish(); } @Override public void onSkipPressed(Fragment currentFragment) { super.onSkipPressed(currentFragment);
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/AnalyticsHelper.java // public class AnalyticsHelper { // // /* // // adb shell setprop log.tag.FA VERBOSE // adb shell setprop log.tag.FA-SVC VERBOSE // adb logcat -v time -s FA FA-SVC // // */ // // private FirebaseAnalytics firebase = null; // // private static AnalyticsHelper analyticsHelper; // // public static AnalyticsHelper getInstance(Context context) { // if (analyticsHelper == null) { // analyticsHelper = new AnalyticsHelper(context); // } // return analyticsHelper; // } // // private AnalyticsHelper(Context context) { // firebase = FirebaseAnalytics.getInstance(context); // firebase.setMinimumSessionDuration(3000); // // firebase.setUserId(); // // firebase.setUserProperty(); // } // // public void logScreenEvent(String screen, String action) { // Bundle bundle = new Bundle(); // bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, screen); // bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, action); // bundle.putString(FirebaseAnalytics.Param.ITEM_ID, action); // firebase.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); // } // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_DONE = " Done Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_NEXT = " Next slide"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_SKIP = " Skip Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String SCREEN_TUTORIAL = "TUT"; // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/tutorial/IntroActivity.java import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import com.github.paolorotolo.appintro.AppIntro2; import com.github.paolorotolo.appintro.AppIntro2Fragment; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.AnalyticsHelper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_DONE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_NEXT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_SKIP; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.SCREEN_TUTORIAL; package com.jaus.albertogiunta.justintrain_oraritreni.tutorial; public class IntroActivity extends AppIntro2 { AnalyticsHelper analyticsHelper; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); analyticsHelper = AnalyticsHelper.getInstance(this); addSlide(AppIntro2Fragment.newInstance("Percorri sempre la stessa tratta?", "Aggiungi le tue tratte e i tuoi treni abituali ai preferiti, per averli sempre a portata di mano!", R.drawable.tut1, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Andata? Ritorno?", "No problem. Trascina la tratta preferita verso dove vuoi andare. Proprio come ti verrebbe naturale fare.", R.drawable.tut2, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Treno poco affidabile?", "Tienilo sempre sotto controllo tramite la notifica!", R.drawable.tut3, Color.parseColor("#717C8D"))); } @Override public void onDonePressed(Fragment currentFragment) { super.onDonePressed(currentFragment); analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_DONE); finish(); } @Override public void onSkipPressed(Fragment currentFragment) { super.onSkipPressed(currentFragment);
analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_SKIP);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/tutorial/IntroActivity.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/AnalyticsHelper.java // public class AnalyticsHelper { // // /* // // adb shell setprop log.tag.FA VERBOSE // adb shell setprop log.tag.FA-SVC VERBOSE // adb logcat -v time -s FA FA-SVC // // */ // // private FirebaseAnalytics firebase = null; // // private static AnalyticsHelper analyticsHelper; // // public static AnalyticsHelper getInstance(Context context) { // if (analyticsHelper == null) { // analyticsHelper = new AnalyticsHelper(context); // } // return analyticsHelper; // } // // private AnalyticsHelper(Context context) { // firebase = FirebaseAnalytics.getInstance(context); // firebase.setMinimumSessionDuration(3000); // // firebase.setUserId(); // // firebase.setUserProperty(); // } // // public void logScreenEvent(String screen, String action) { // Bundle bundle = new Bundle(); // bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, screen); // bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, action); // bundle.putString(FirebaseAnalytics.Param.ITEM_ID, action); // firebase.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); // } // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_DONE = " Done Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_NEXT = " Next slide"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_SKIP = " Skip Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String SCREEN_TUTORIAL = "TUT";
import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import com.github.paolorotolo.appintro.AppIntro2; import com.github.paolorotolo.appintro.AppIntro2Fragment; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.AnalyticsHelper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_DONE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_NEXT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_SKIP; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.SCREEN_TUTORIAL;
package com.jaus.albertogiunta.justintrain_oraritreni.tutorial; public class IntroActivity extends AppIntro2 { AnalyticsHelper analyticsHelper; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); analyticsHelper = AnalyticsHelper.getInstance(this); addSlide(AppIntro2Fragment.newInstance("Percorri sempre la stessa tratta?", "Aggiungi le tue tratte e i tuoi treni abituali ai preferiti, per averli sempre a portata di mano!", R.drawable.tut1, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Andata? Ritorno?", "No problem. Trascina la tratta preferita verso dove vuoi andare. Proprio come ti verrebbe naturale fare.", R.drawable.tut2, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Treno poco affidabile?", "Tienilo sempre sotto controllo tramite la notifica!", R.drawable.tut3, Color.parseColor("#717C8D"))); } @Override public void onDonePressed(Fragment currentFragment) { super.onDonePressed(currentFragment); analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_DONE); finish(); } @Override public void onSkipPressed(Fragment currentFragment) { super.onSkipPressed(currentFragment); analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_SKIP); finish(); } @Override public void onSlideChanged(@Nullable Fragment oldFragment, @Nullable Fragment newFragment) { super.onSlideChanged(oldFragment, newFragment);
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/AnalyticsHelper.java // public class AnalyticsHelper { // // /* // // adb shell setprop log.tag.FA VERBOSE // adb shell setprop log.tag.FA-SVC VERBOSE // adb logcat -v time -s FA FA-SVC // // */ // // private FirebaseAnalytics firebase = null; // // private static AnalyticsHelper analyticsHelper; // // public static AnalyticsHelper getInstance(Context context) { // if (analyticsHelper == null) { // analyticsHelper = new AnalyticsHelper(context); // } // return analyticsHelper; // } // // private AnalyticsHelper(Context context) { // firebase = FirebaseAnalytics.getInstance(context); // firebase.setMinimumSessionDuration(3000); // // firebase.setUserId(); // // firebase.setUserProperty(); // } // // public void logScreenEvent(String screen, String action) { // Bundle bundle = new Bundle(); // bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, screen); // bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, action); // bundle.putString(FirebaseAnalytics.Param.ITEM_ID, action); // firebase.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); // } // } // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_DONE = " Done Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_NEXT = " Next slide"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String ACTION_TUTORIAL_SKIP = " Skip Tutorial"; // // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/constants/CONST_ANALYTICS.java // public static final String SCREEN_TUTORIAL = "TUT"; // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/tutorial/IntroActivity.java import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import com.github.paolorotolo.appintro.AppIntro2; import com.github.paolorotolo.appintro.AppIntro2Fragment; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.AnalyticsHelper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_DONE; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_NEXT; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.ACTION_TUTORIAL_SKIP; import static com.jaus.albertogiunta.justintrain_oraritreni.utils.constants.CONST_ANALYTICS.SCREEN_TUTORIAL; package com.jaus.albertogiunta.justintrain_oraritreni.tutorial; public class IntroActivity extends AppIntro2 { AnalyticsHelper analyticsHelper; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); analyticsHelper = AnalyticsHelper.getInstance(this); addSlide(AppIntro2Fragment.newInstance("Percorri sempre la stessa tratta?", "Aggiungi le tue tratte e i tuoi treni abituali ai preferiti, per averli sempre a portata di mano!", R.drawable.tut1, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Andata? Ritorno?", "No problem. Trascina la tratta preferita verso dove vuoi andare. Proprio come ti verrebbe naturale fare.", R.drawable.tut2, Color.parseColor("#717C8D"))); addSlide(AppIntro2Fragment.newInstance("Treno poco affidabile?", "Tienilo sempre sotto controllo tramite la notifica!", R.drawable.tut3, Color.parseColor("#717C8D"))); } @Override public void onDonePressed(Fragment currentFragment) { super.onDonePressed(currentFragment); analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_DONE); finish(); } @Override public void onSkipPressed(Fragment currentFragment) { super.onSkipPressed(currentFragment); analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_SKIP); finish(); } @Override public void onSlideChanged(@Nullable Fragment oldFragment, @Nullable Fragment newFragment) { super.onSlideChanged(oldFragment, newFragment);
analyticsHelper.logScreenEvent(SCREEN_TUTORIAL, ACTION_TUTORIAL_NEXT);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/notification/ScreenOnReceiver.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/notification/NotificationService.java // public static final String ACTION_UPDATE_NOTIFICATION = "com.jaus.albertogiunta.justintrain_oraripendolaritrenitalia.action.UPDATE_NOTIFICATION";
import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import java.util.Objects; import static com.jaus.albertogiunta.justintrain_oraritreni.notification.NotificationService.ACTION_UPDATE_NOTIFICATION;
package com.jaus.albertogiunta.justintrain_oraritreni.notification; public class ScreenOnReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (Objects.equals(intent.getAction(), Intent.ACTION_SCREEN_ON)) { Intent i = new Intent(context, NotificationService.class);
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/notification/NotificationService.java // public static final String ACTION_UPDATE_NOTIFICATION = "com.jaus.albertogiunta.justintrain_oraripendolaritrenitalia.action.UPDATE_NOTIFICATION"; // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/notification/ScreenOnReceiver.java import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import java.util.Objects; import static com.jaus.albertogiunta.justintrain_oraritreni.notification.NotificationService.ACTION_UPDATE_NOTIFICATION; package com.jaus.albertogiunta.justintrain_oraritreni.notification; public class ScreenOnReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (Objects.equals(intent.getAction(), Intent.ACTION_SCREEN_ON)) { Intent i = new Intent(context, NotificationService.class);
i.setAction(ACTION_UPDATE_NOTIFICATION);
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/data/PreferredStation.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/db/Station.java // @Entity(tableName = "station") // public class Station { // // @PrimaryKey // private Integer sid; // // @ColumnInfo(name = "name_short") // private String nameShort; // // @ColumnInfo(name = "name_long") // private String nameLong; // // @ColumnInfo(name = "name_fancy") // private String nameFancy; // // @ColumnInfo(name = "id_short") // private String stationShortId; // // @ColumnInfo(name = "id_long") // private String stationLongId; // // public Integer getSid() { // return sid; // } // // public void setSid(Integer sid) { // this.sid = sid; // } // // public String getStationShortId() { // return stationShortId; // } // // public void setStationShortId(String stationShortId) { // this.stationShortId = stationShortId; // } // // public String getStationLongId() { // return stationLongId; // } // // public void setStationLongId(String stationLongId) { // this.stationLongId = stationLongId; // } // // public String getNameFancy() { // return nameFancy; // } // // public void setNameFancy(String nameFancy) { // this.nameFancy = nameFancy; // } // // public String getNameShort() { // return nameShort; // } // // public void setNameShort(String nameShort) { // this.nameShort = nameShort; // } // // public String getNameLong() { // return nameLong; // } // // public void setNameLong(String nameLong) { // this.nameLong = nameLong; // } // // @Override // public String toString() { // return "Station{" + // "stationShortId='" + stationShortId + '\'' + // ", stationLongId='" + stationLongId + '\'' + // ", nameLong='" + nameLong + '\'' + // ", nameShort='" + nameShort + '\'' + // '}'; // } // }
import com.jaus.albertogiunta.justintrain_oraritreni.db.Station; import java.util.HashMap; import java.util.Map;
package com.jaus.albertogiunta.justintrain_oraritreni.data; @SuppressWarnings("unused") public class PreferredStation { private String stationShortId; private String stationLongId; private String nameShort; private String nameLong; private Map<String, Journey.Solution> preferredSolutions; public PreferredStation() { preferredSolutions = new HashMap<>(); }
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/db/Station.java // @Entity(tableName = "station") // public class Station { // // @PrimaryKey // private Integer sid; // // @ColumnInfo(name = "name_short") // private String nameShort; // // @ColumnInfo(name = "name_long") // private String nameLong; // // @ColumnInfo(name = "name_fancy") // private String nameFancy; // // @ColumnInfo(name = "id_short") // private String stationShortId; // // @ColumnInfo(name = "id_long") // private String stationLongId; // // public Integer getSid() { // return sid; // } // // public void setSid(Integer sid) { // this.sid = sid; // } // // public String getStationShortId() { // return stationShortId; // } // // public void setStationShortId(String stationShortId) { // this.stationShortId = stationShortId; // } // // public String getStationLongId() { // return stationLongId; // } // // public void setStationLongId(String stationLongId) { // this.stationLongId = stationLongId; // } // // public String getNameFancy() { // return nameFancy; // } // // public void setNameFancy(String nameFancy) { // this.nameFancy = nameFancy; // } // // public String getNameShort() { // return nameShort; // } // // public void setNameShort(String nameShort) { // this.nameShort = nameShort; // } // // public String getNameLong() { // return nameLong; // } // // public void setNameLong(String nameLong) { // this.nameLong = nameLong; // } // // @Override // public String toString() { // return "Station{" + // "stationShortId='" + stationShortId + '\'' + // ", stationLongId='" + stationLongId + '\'' + // ", nameLong='" + nameLong + '\'' + // ", nameShort='" + nameShort + '\'' + // '}'; // } // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/data/PreferredStation.java import com.jaus.albertogiunta.justintrain_oraritreni.db.Station; import java.util.HashMap; import java.util.Map; package com.jaus.albertogiunta.justintrain_oraritreni.data; @SuppressWarnings("unused") public class PreferredStation { private String stationShortId; private String stationLongId; private String nameShort; private String nameLong; private Map<String, Journey.Solution> preferredSolutions; public PreferredStation() { preferredSolutions = new HashMap<>(); }
public PreferredStation(Station station) {
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/db/AppDatabase.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/db/sqliteAsset/AssetSQLiteOpenHelperFactory.java // @SuppressWarnings("unused") // public class AssetSQLiteOpenHelperFactory implements SupportSQLiteOpenHelper.Factory { // @Override // public SupportSQLiteOpenHelper create(SupportSQLiteOpenHelper.Configuration configuration) { // return new AssetSQLiteOpenHelper( // configuration.context, configuration.name, null, // configuration.version, configuration.errorHandler, configuration.callback // ); // } // }
import android.arch.persistence.room.Database; import android.arch.persistence.room.Room; import android.arch.persistence.room.RoomDatabase; import android.content.Context; import com.jaus.albertogiunta.justintrain_oraritreni.db.sqliteAsset.AssetSQLiteOpenHelperFactory;
package com.jaus.albertogiunta.justintrain_oraritreni.db; @Database(entities = {Station.class}, version = 3) public abstract class AppDatabase extends RoomDatabase { private static AppDatabase INSTANCE; public abstract StationDaoRoom stationDao(); public static AppDatabase getAppDatabase(Context context, boolean force) { if (INSTANCE == null || force) { INSTANCE = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "justintrain.db") // allow queries on the main thread. // Don't do\ this on a real app! See PersistenceBasicSample for an example.
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/db/sqliteAsset/AssetSQLiteOpenHelperFactory.java // @SuppressWarnings("unused") // public class AssetSQLiteOpenHelperFactory implements SupportSQLiteOpenHelper.Factory { // @Override // public SupportSQLiteOpenHelper create(SupportSQLiteOpenHelper.Configuration configuration) { // return new AssetSQLiteOpenHelper( // configuration.context, configuration.name, null, // configuration.version, configuration.errorHandler, configuration.callback // ); // } // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/db/AppDatabase.java import android.arch.persistence.room.Database; import android.arch.persistence.room.Room; import android.arch.persistence.room.RoomDatabase; import android.content.Context; import com.jaus.albertogiunta.justintrain_oraritreni.db.sqliteAsset.AssetSQLiteOpenHelperFactory; package com.jaus.albertogiunta.justintrain_oraritreni.db; @Database(entities = {Station.class}, version = 3) public abstract class AppDatabase extends RoomDatabase { private static AppDatabase INSTANCE; public abstract StationDaoRoom stationDao(); public static AppDatabase getAppDatabase(Context context, boolean force) { if (INSTANCE == null || force) { INSTANCE = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "justintrain.db") // allow queries on the main thread. // Don't do\ this on a real app! See PersistenceBasicSample for an example.
.openHelperFactory(new AssetSQLiteOpenHelperFactory())
albertogiunta/justintrain-client-android
app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/journeySearch/StationSearchActivity.java
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/DatabaseHelper.java // public class DatabaseHelper { // // public static List<String> getAll() { // return Stream // .of(MyApplication.database.stationDao().getAll()) // .map(Station::getNameFancy).collect(Collectors.toList()); // } // // // public static List<String> getElementByNameFancy(String stationName) { // return Stream // .of(MyApplication.database.stationDao().getAllByNameFancy("" + stationName + "%", "%_" + stationName + "%")) // .map(Station::getNameFancy).collect(Collectors.toList()); // } // // public static List<String> getElementByNameShort(String stationName) { // return Stream // .of(MyApplication.database.stationDao().getAllByNameShort(stationName)) // .map(Station::getNameLong).collect(Collectors.toList()); // } // // public static boolean isThisJourneyPreferred(PreferredStation departureStation, PreferredStation arrivalStation, Context context) { // return departureStation != null && // arrivalStation != null && // PreferredStationsPreferences.isJourneyAlreadyPreferred( // context, // departureStation, // arrivalStation); // } // // public static boolean isStationNameValid(String stationName) { // return MyApplication.database.stationDao().isStationNameValid(stationName); // } // // public static Station getStation4DatabaseObject(String stationName) { // return MyApplication.database.stationDao().getByWhateverName(stationName); // } // }
import com.google.firebase.crash.FirebaseCrash; import android.app.SearchManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SearchView; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.DatabaseHelper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import java.util.LinkedList; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife;
package com.jaus.albertogiunta.justintrain_oraritreni.journeySearch; public class StationSearchActivity extends AppCompatActivity implements SearchedStationsAdapter.OnClickListener { @BindView(R.id.rv_searched_stations) RecyclerView rvSearchedStations; SearchedStationsAdapter adapter;
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/DatabaseHelper.java // public class DatabaseHelper { // // public static List<String> getAll() { // return Stream // .of(MyApplication.database.stationDao().getAll()) // .map(Station::getNameFancy).collect(Collectors.toList()); // } // // // public static List<String> getElementByNameFancy(String stationName) { // return Stream // .of(MyApplication.database.stationDao().getAllByNameFancy("" + stationName + "%", "%_" + stationName + "%")) // .map(Station::getNameFancy).collect(Collectors.toList()); // } // // public static List<String> getElementByNameShort(String stationName) { // return Stream // .of(MyApplication.database.stationDao().getAllByNameShort(stationName)) // .map(Station::getNameLong).collect(Collectors.toList()); // } // // public static boolean isThisJourneyPreferred(PreferredStation departureStation, PreferredStation arrivalStation, Context context) { // return departureStation != null && // arrivalStation != null && // PreferredStationsPreferences.isJourneyAlreadyPreferred( // context, // departureStation, // arrivalStation); // } // // public static boolean isStationNameValid(String stationName) { // return MyApplication.database.stationDao().isStationNameValid(stationName); // } // // public static Station getStation4DatabaseObject(String stationName) { // return MyApplication.database.stationDao().getByWhateverName(stationName); // } // } // Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/journeySearch/StationSearchActivity.java import com.google.firebase.crash.FirebaseCrash; import android.app.SearchManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SearchView; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import com.jaus.albertogiunta.justintrain_oraritreni.R; import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.DatabaseHelper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import java.util.LinkedList; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; package com.jaus.albertogiunta.justintrain_oraritreni.journeySearch; public class StationSearchActivity extends AppCompatActivity implements SearchedStationsAdapter.OnClickListener { @BindView(R.id.rv_searched_stations) RecyclerView rvSearchedStations; SearchedStationsAdapter adapter;
List<String> stationNames = new LinkedList<>(DatabaseHelper.getAll());
EnderiumSmith/CharcoalPit
src/main/java/charcoalPit/blocks/BlockCeramicPot.java
// Path: src/main/java/charcoalPit/CharcoalPit.java // @Mod(modid=Constants.MODID, name=Constants.MODNAME, version=Constants.MODVERSION, acceptedMinecraftVersions="[1.12, 1.13)", dependencies="before:quark;before:jei;after:thaumcraft") // public class CharcoalPit { // // static{ // FluidRegistry.enableUniversalBucket(); // } // // @Mod.Instance // public static CharcoalPit instance; // // @SidedProxy(clientSide="charcoalPit.core.ClientProxy", // serverSide="charcoalPit.core.ServerProxy") // public static CommonProxy proxy; // // @EventHandler // public void preInit(FMLPreInitializationEvent e){ // proxy.preInit(e); // } // @EventHandler // public void init(FMLInitializationEvent e){ // proxy.init(e); // } // @EventHandler // public void postInit(FMLPostInitializationEvent e){ // proxy.postInit(e); // } // } // // Path: src/main/java/charcoalPit/tile/TileCeramicPot.java // public class TileCeramicPot extends TileEntity{ // // @CapabilityInject(IItemHandler.class) // public static Capability<IItemHandler> ITEM=null; // public CeramicItemHandler items; // public TileCeramicPot() { // items=new CeramicItemHandler(9); // } // // @Override // public NBTTagCompound writeToNBT(NBTTagCompound compound) { // super.writeToNBT(compound); // compound.setTag("items", items.serializeNBT()); // return compound; // } // // @Override // public void readFromNBT(NBTTagCompound compound) { // super.readFromNBT(compound); // items.deserializeNBT(compound.getCompoundTag("items")); // } // // @Override // public boolean hasCapability(Capability<?> capability, EnumFacing facing) { // if(capability==ITEM){ // return true; // } // return super.hasCapability(capability, facing); // } // // @SuppressWarnings("unchecked") // @Override // public <T> T getCapability(Capability<T> capability, EnumFacing facing) { // if(capability==ITEM){ // return (T) items; // } // return super.getCapability(capability, facing); // } // // public static class CeramicItemHandler extends FilteredItemHandler{ // // public CeramicItemHandler(int size) { // super(size); // } // // @Override // public boolean isItemValid(int slot, ItemStack stack) { // if(stack.getItem() instanceof ItemBlock){ // if(((ItemBlock)stack.getItem()).getBlock() instanceof BlockCeramicPot|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockShulkerBox|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockClayPot|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockSmeltedPot){ // return false; // } // } // return !MethodHelper.isItemBlackListed(stack); // } // // } // }
import java.util.List; import charcoalPit.CharcoalPit; import charcoalPit.tile.TileCeramicPot; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.EnumPushReaction; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.items.ItemStackHandler;
} @Override public boolean isFullCube(IBlockState state) { return false; } @Override public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) { return false; } @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return AABB_POT; } @Override public EnumPushReaction getMobilityFlag(IBlockState state) { return EnumPushReaction.DESTROY; } @Override public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) { } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tileentity = worldIn.getTileEntity(pos);
// Path: src/main/java/charcoalPit/CharcoalPit.java // @Mod(modid=Constants.MODID, name=Constants.MODNAME, version=Constants.MODVERSION, acceptedMinecraftVersions="[1.12, 1.13)", dependencies="before:quark;before:jei;after:thaumcraft") // public class CharcoalPit { // // static{ // FluidRegistry.enableUniversalBucket(); // } // // @Mod.Instance // public static CharcoalPit instance; // // @SidedProxy(clientSide="charcoalPit.core.ClientProxy", // serverSide="charcoalPit.core.ServerProxy") // public static CommonProxy proxy; // // @EventHandler // public void preInit(FMLPreInitializationEvent e){ // proxy.preInit(e); // } // @EventHandler // public void init(FMLInitializationEvent e){ // proxy.init(e); // } // @EventHandler // public void postInit(FMLPostInitializationEvent e){ // proxy.postInit(e); // } // } // // Path: src/main/java/charcoalPit/tile/TileCeramicPot.java // public class TileCeramicPot extends TileEntity{ // // @CapabilityInject(IItemHandler.class) // public static Capability<IItemHandler> ITEM=null; // public CeramicItemHandler items; // public TileCeramicPot() { // items=new CeramicItemHandler(9); // } // // @Override // public NBTTagCompound writeToNBT(NBTTagCompound compound) { // super.writeToNBT(compound); // compound.setTag("items", items.serializeNBT()); // return compound; // } // // @Override // public void readFromNBT(NBTTagCompound compound) { // super.readFromNBT(compound); // items.deserializeNBT(compound.getCompoundTag("items")); // } // // @Override // public boolean hasCapability(Capability<?> capability, EnumFacing facing) { // if(capability==ITEM){ // return true; // } // return super.hasCapability(capability, facing); // } // // @SuppressWarnings("unchecked") // @Override // public <T> T getCapability(Capability<T> capability, EnumFacing facing) { // if(capability==ITEM){ // return (T) items; // } // return super.getCapability(capability, facing); // } // // public static class CeramicItemHandler extends FilteredItemHandler{ // // public CeramicItemHandler(int size) { // super(size); // } // // @Override // public boolean isItemValid(int slot, ItemStack stack) { // if(stack.getItem() instanceof ItemBlock){ // if(((ItemBlock)stack.getItem()).getBlock() instanceof BlockCeramicPot|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockShulkerBox|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockClayPot|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockSmeltedPot){ // return false; // } // } // return !MethodHelper.isItemBlackListed(stack); // } // // } // } // Path: src/main/java/charcoalPit/blocks/BlockCeramicPot.java import java.util.List; import charcoalPit.CharcoalPit; import charcoalPit.tile.TileCeramicPot; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.EnumPushReaction; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.items.ItemStackHandler; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) { return false; } @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return AABB_POT; } @Override public EnumPushReaction getMobilityFlag(IBlockState state) { return EnumPushReaction.DESTROY; } @Override public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) { } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileCeramicPot)
EnderiumSmith/CharcoalPit
src/main/java/charcoalPit/blocks/BlockCeramicPot.java
// Path: src/main/java/charcoalPit/CharcoalPit.java // @Mod(modid=Constants.MODID, name=Constants.MODNAME, version=Constants.MODVERSION, acceptedMinecraftVersions="[1.12, 1.13)", dependencies="before:quark;before:jei;after:thaumcraft") // public class CharcoalPit { // // static{ // FluidRegistry.enableUniversalBucket(); // } // // @Mod.Instance // public static CharcoalPit instance; // // @SidedProxy(clientSide="charcoalPit.core.ClientProxy", // serverSide="charcoalPit.core.ServerProxy") // public static CommonProxy proxy; // // @EventHandler // public void preInit(FMLPreInitializationEvent e){ // proxy.preInit(e); // } // @EventHandler // public void init(FMLInitializationEvent e){ // proxy.init(e); // } // @EventHandler // public void postInit(FMLPostInitializationEvent e){ // proxy.postInit(e); // } // } // // Path: src/main/java/charcoalPit/tile/TileCeramicPot.java // public class TileCeramicPot extends TileEntity{ // // @CapabilityInject(IItemHandler.class) // public static Capability<IItemHandler> ITEM=null; // public CeramicItemHandler items; // public TileCeramicPot() { // items=new CeramicItemHandler(9); // } // // @Override // public NBTTagCompound writeToNBT(NBTTagCompound compound) { // super.writeToNBT(compound); // compound.setTag("items", items.serializeNBT()); // return compound; // } // // @Override // public void readFromNBT(NBTTagCompound compound) { // super.readFromNBT(compound); // items.deserializeNBT(compound.getCompoundTag("items")); // } // // @Override // public boolean hasCapability(Capability<?> capability, EnumFacing facing) { // if(capability==ITEM){ // return true; // } // return super.hasCapability(capability, facing); // } // // @SuppressWarnings("unchecked") // @Override // public <T> T getCapability(Capability<T> capability, EnumFacing facing) { // if(capability==ITEM){ // return (T) items; // } // return super.getCapability(capability, facing); // } // // public static class CeramicItemHandler extends FilteredItemHandler{ // // public CeramicItemHandler(int size) { // super(size); // } // // @Override // public boolean isItemValid(int slot, ItemStack stack) { // if(stack.getItem() instanceof ItemBlock){ // if(((ItemBlock)stack.getItem()).getBlock() instanceof BlockCeramicPot|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockShulkerBox|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockClayPot|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockSmeltedPot){ // return false; // } // } // return !MethodHelper.isItemBlackListed(stack); // } // // } // }
import java.util.List; import charcoalPit.CharcoalPit; import charcoalPit.tile.TileCeramicPot; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.EnumPushReaction; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.items.ItemStackHandler;
public boolean hasComparatorInputOverride(IBlockState state) { return true; } @Override public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) { TileCeramicPot tile=(TileCeramicPot)worldIn.getTileEntity(pos); int i = 0; float f = 0.0F; for (int j = 0; j < tile.items.getSlots(); ++j) { ItemStack itemstack = tile.items.getStackInSlot(j); if (!itemstack.isEmpty()) { f += (float)itemstack.getCount() / (float)Math.min(tile.items.getSlotLimit(j), itemstack.getMaxStackSize()); ++i; } } f = f / (float)tile.items.getSlots(); return MathHelper.floor(f * 14.0F) + (i > 0 ? 1 : 0); }*/ @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if(worldIn.isRemote){ return true; }else{
// Path: src/main/java/charcoalPit/CharcoalPit.java // @Mod(modid=Constants.MODID, name=Constants.MODNAME, version=Constants.MODVERSION, acceptedMinecraftVersions="[1.12, 1.13)", dependencies="before:quark;before:jei;after:thaumcraft") // public class CharcoalPit { // // static{ // FluidRegistry.enableUniversalBucket(); // } // // @Mod.Instance // public static CharcoalPit instance; // // @SidedProxy(clientSide="charcoalPit.core.ClientProxy", // serverSide="charcoalPit.core.ServerProxy") // public static CommonProxy proxy; // // @EventHandler // public void preInit(FMLPreInitializationEvent e){ // proxy.preInit(e); // } // @EventHandler // public void init(FMLInitializationEvent e){ // proxy.init(e); // } // @EventHandler // public void postInit(FMLPostInitializationEvent e){ // proxy.postInit(e); // } // } // // Path: src/main/java/charcoalPit/tile/TileCeramicPot.java // public class TileCeramicPot extends TileEntity{ // // @CapabilityInject(IItemHandler.class) // public static Capability<IItemHandler> ITEM=null; // public CeramicItemHandler items; // public TileCeramicPot() { // items=new CeramicItemHandler(9); // } // // @Override // public NBTTagCompound writeToNBT(NBTTagCompound compound) { // super.writeToNBT(compound); // compound.setTag("items", items.serializeNBT()); // return compound; // } // // @Override // public void readFromNBT(NBTTagCompound compound) { // super.readFromNBT(compound); // items.deserializeNBT(compound.getCompoundTag("items")); // } // // @Override // public boolean hasCapability(Capability<?> capability, EnumFacing facing) { // if(capability==ITEM){ // return true; // } // return super.hasCapability(capability, facing); // } // // @SuppressWarnings("unchecked") // @Override // public <T> T getCapability(Capability<T> capability, EnumFacing facing) { // if(capability==ITEM){ // return (T) items; // } // return super.getCapability(capability, facing); // } // // public static class CeramicItemHandler extends FilteredItemHandler{ // // public CeramicItemHandler(int size) { // super(size); // } // // @Override // public boolean isItemValid(int slot, ItemStack stack) { // if(stack.getItem() instanceof ItemBlock){ // if(((ItemBlock)stack.getItem()).getBlock() instanceof BlockCeramicPot|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockShulkerBox|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockClayPot|| // ((ItemBlock)stack.getItem()).getBlock() instanceof BlockSmeltedPot){ // return false; // } // } // return !MethodHelper.isItemBlackListed(stack); // } // // } // } // Path: src/main/java/charcoalPit/blocks/BlockCeramicPot.java import java.util.List; import charcoalPit.CharcoalPit; import charcoalPit.tile.TileCeramicPot; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.EnumPushReaction; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.items.ItemStackHandler; public boolean hasComparatorInputOverride(IBlockState state) { return true; } @Override public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) { TileCeramicPot tile=(TileCeramicPot)worldIn.getTileEntity(pos); int i = 0; float f = 0.0F; for (int j = 0; j < tile.items.getSlots(); ++j) { ItemStack itemstack = tile.items.getStackInSlot(j); if (!itemstack.isEmpty()) { f += (float)itemstack.getCount() / (float)Math.min(tile.items.getSlotLimit(j), itemstack.getMaxStackSize()); ++i; } } f = f / (float)tile.items.getSlots(); return MathHelper.floor(f * 14.0F) + (i > 0 ? 1 : 0); }*/ @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if(worldIn.isRemote){ return true; }else{
playerIn.openGui(CharcoalPit.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
EnderiumSmith/CharcoalPit
src/main/java/charcoalPit/crafting/MineTweaker.java
// Path: src/main/java/charcoalPit/crafting/OreSmeltingRecipes.java // public static class AlloyRecipe{ // public Object[] recipe; // public Object output; // public int outAmount; // public boolean usePrefix; // public boolean isAdvanced; // // public AlloyRecipe(Object output, int amount, boolean advanced, boolean usePrefix, Object...recipe) { // this.output=output; // this.outAmount=amount; // this.usePrefix=usePrefix; // this.isAdvanced=advanced; // this.recipe=recipe; // } // // public boolean isInputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // for(int i=0;i<recipe.length;i++){ // if(recipe[i] instanceof ItemStack){ // if(((ItemStack)recipe[i]).isItemEqual(in)) // return true; // } // if(recipe[i] instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(usePrefix){ // String ore=OreDictionary.getOreName(id); // for(int j=0;j<orePrefixes.size();j++){ // if(ore.equals(orePrefixes.get(j)+recipe[i])) // return true; // } // }else{ // if(OreDictionary.getOreName(id).equals(recipe[i])) // return true; // } // } // } // } // return false; // } // // public boolean isInputEqual(ItemStack in, int slot){ // if(in.isEmpty()) // return false; // if(slot>=recipe.length) // return false; // if(recipe[slot] instanceof ItemStack){ // if(((ItemStack)recipe[slot]).isItemEqual(in)) // return true; // } // if(recipe[slot] instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(usePrefix){ // String ore=OreDictionary.getOreName(id); // for(int j=0;j<orePrefixes.size();j++){ // if(ore.equals(orePrefixes.get(j)+recipe[slot])) // return true; // } // }else{ // if(OreDictionary.getOreName(id).equals(recipe[slot])) // return true; // } // } // } // return false; // } // // public boolean isOutputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // if(output instanceof ItemStack){ // if(((ItemStack)output).isItemEqual(in)) // return true; // } // if(output instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(OreDictionary.getOreName(id).equals(output)) // return true; // } // } // return false; // } // } // // Path: src/main/java/charcoalPit/crafting/OreSmeltingRecipes.java // public static class SmeltingFuel{ // // public String ore; // public ItemStack item; // public int value; // public SmeltingFuel(String ore,ItemStack item, int value) { // this.ore=ore; // this.item=item; // this.value=value; // } // // public boolean isInputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // if(!item.isEmpty()){ // if(item.isItemEqual(in)) // return true; // } // if(ore!=null){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(OreDictionary.getOreName(id).equals(ore)) // return true; // } // } // return false; // } // // }
import java.util.ArrayList; import charcoalPit.crafting.OreSmeltingRecipes.AlloyRecipe; import charcoalPit.crafting.OreSmeltingRecipes.SmeltingFuel; import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.minecraft.CraftTweakerMC; import crafttweaker.api.oredict.IOreDictEntry; import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod;
package charcoalPit.crafting; @ZenClass("mods.charcoalpit") @ZenRegister public class MineTweaker { @ZenMethod public static void addKilnRecipe(IItemStack in, IItemStack out){ PotteryKilnRecipe.recipes.add(new PotteryKilnRecipe(CraftTweakerMC.getItemStack(in), CraftTweakerMC.getItemStack(out))); } @ZenMethod public static void flushKilnRecipes(){ PotteryKilnRecipe.recipes=new ArrayList<>(); } @ZenMethod public static void addSmeltingFuel(IOreDictEntry in, int value){
// Path: src/main/java/charcoalPit/crafting/OreSmeltingRecipes.java // public static class AlloyRecipe{ // public Object[] recipe; // public Object output; // public int outAmount; // public boolean usePrefix; // public boolean isAdvanced; // // public AlloyRecipe(Object output, int amount, boolean advanced, boolean usePrefix, Object...recipe) { // this.output=output; // this.outAmount=amount; // this.usePrefix=usePrefix; // this.isAdvanced=advanced; // this.recipe=recipe; // } // // public boolean isInputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // for(int i=0;i<recipe.length;i++){ // if(recipe[i] instanceof ItemStack){ // if(((ItemStack)recipe[i]).isItemEqual(in)) // return true; // } // if(recipe[i] instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(usePrefix){ // String ore=OreDictionary.getOreName(id); // for(int j=0;j<orePrefixes.size();j++){ // if(ore.equals(orePrefixes.get(j)+recipe[i])) // return true; // } // }else{ // if(OreDictionary.getOreName(id).equals(recipe[i])) // return true; // } // } // } // } // return false; // } // // public boolean isInputEqual(ItemStack in, int slot){ // if(in.isEmpty()) // return false; // if(slot>=recipe.length) // return false; // if(recipe[slot] instanceof ItemStack){ // if(((ItemStack)recipe[slot]).isItemEqual(in)) // return true; // } // if(recipe[slot] instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(usePrefix){ // String ore=OreDictionary.getOreName(id); // for(int j=0;j<orePrefixes.size();j++){ // if(ore.equals(orePrefixes.get(j)+recipe[slot])) // return true; // } // }else{ // if(OreDictionary.getOreName(id).equals(recipe[slot])) // return true; // } // } // } // return false; // } // // public boolean isOutputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // if(output instanceof ItemStack){ // if(((ItemStack)output).isItemEqual(in)) // return true; // } // if(output instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(OreDictionary.getOreName(id).equals(output)) // return true; // } // } // return false; // } // } // // Path: src/main/java/charcoalPit/crafting/OreSmeltingRecipes.java // public static class SmeltingFuel{ // // public String ore; // public ItemStack item; // public int value; // public SmeltingFuel(String ore,ItemStack item, int value) { // this.ore=ore; // this.item=item; // this.value=value; // } // // public boolean isInputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // if(!item.isEmpty()){ // if(item.isItemEqual(in)) // return true; // } // if(ore!=null){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(OreDictionary.getOreName(id).equals(ore)) // return true; // } // } // return false; // } // // } // Path: src/main/java/charcoalPit/crafting/MineTweaker.java import java.util.ArrayList; import charcoalPit.crafting.OreSmeltingRecipes.AlloyRecipe; import charcoalPit.crafting.OreSmeltingRecipes.SmeltingFuel; import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.minecraft.CraftTweakerMC; import crafttweaker.api.oredict.IOreDictEntry; import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; package charcoalPit.crafting; @ZenClass("mods.charcoalpit") @ZenRegister public class MineTweaker { @ZenMethod public static void addKilnRecipe(IItemStack in, IItemStack out){ PotteryKilnRecipe.recipes.add(new PotteryKilnRecipe(CraftTweakerMC.getItemStack(in), CraftTweakerMC.getItemStack(out))); } @ZenMethod public static void flushKilnRecipes(){ PotteryKilnRecipe.recipes=new ArrayList<>(); } @ZenMethod public static void addSmeltingFuel(IOreDictEntry in, int value){
OreSmeltingRecipes.smeltingFuels.add(new SmeltingFuel(in.getName(), ItemStack.EMPTY, value));
EnderiumSmith/CharcoalPit
src/main/java/charcoalPit/crafting/MineTweaker.java
// Path: src/main/java/charcoalPit/crafting/OreSmeltingRecipes.java // public static class AlloyRecipe{ // public Object[] recipe; // public Object output; // public int outAmount; // public boolean usePrefix; // public boolean isAdvanced; // // public AlloyRecipe(Object output, int amount, boolean advanced, boolean usePrefix, Object...recipe) { // this.output=output; // this.outAmount=amount; // this.usePrefix=usePrefix; // this.isAdvanced=advanced; // this.recipe=recipe; // } // // public boolean isInputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // for(int i=0;i<recipe.length;i++){ // if(recipe[i] instanceof ItemStack){ // if(((ItemStack)recipe[i]).isItemEqual(in)) // return true; // } // if(recipe[i] instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(usePrefix){ // String ore=OreDictionary.getOreName(id); // for(int j=0;j<orePrefixes.size();j++){ // if(ore.equals(orePrefixes.get(j)+recipe[i])) // return true; // } // }else{ // if(OreDictionary.getOreName(id).equals(recipe[i])) // return true; // } // } // } // } // return false; // } // // public boolean isInputEqual(ItemStack in, int slot){ // if(in.isEmpty()) // return false; // if(slot>=recipe.length) // return false; // if(recipe[slot] instanceof ItemStack){ // if(((ItemStack)recipe[slot]).isItemEqual(in)) // return true; // } // if(recipe[slot] instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(usePrefix){ // String ore=OreDictionary.getOreName(id); // for(int j=0;j<orePrefixes.size();j++){ // if(ore.equals(orePrefixes.get(j)+recipe[slot])) // return true; // } // }else{ // if(OreDictionary.getOreName(id).equals(recipe[slot])) // return true; // } // } // } // return false; // } // // public boolean isOutputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // if(output instanceof ItemStack){ // if(((ItemStack)output).isItemEqual(in)) // return true; // } // if(output instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(OreDictionary.getOreName(id).equals(output)) // return true; // } // } // return false; // } // } // // Path: src/main/java/charcoalPit/crafting/OreSmeltingRecipes.java // public static class SmeltingFuel{ // // public String ore; // public ItemStack item; // public int value; // public SmeltingFuel(String ore,ItemStack item, int value) { // this.ore=ore; // this.item=item; // this.value=value; // } // // public boolean isInputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // if(!item.isEmpty()){ // if(item.isItemEqual(in)) // return true; // } // if(ore!=null){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(OreDictionary.getOreName(id).equals(ore)) // return true; // } // } // return false; // } // // }
import java.util.ArrayList; import charcoalPit.crafting.OreSmeltingRecipes.AlloyRecipe; import charcoalPit.crafting.OreSmeltingRecipes.SmeltingFuel; import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.minecraft.CraftTweakerMC; import crafttweaker.api.oredict.IOreDictEntry; import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod;
OreSmeltingRecipes.smeltingFuels.add(new SmeltingFuel(null, CraftTweakerMC.getItemStack(in), value)); } @ZenMethod public static void flushSmeltingFuels(){ OreSmeltingRecipes.smeltingFuels=new ArrayList<>(); } @ZenMethod public static void addAlloyRecipe(IIngredient result, int amount, boolean advanced, boolean usePrefix, IIngredient[] recipe){ Object out; Object[] in=new Object[recipe.length]; if(result instanceof IItemStack) out=CraftTweakerMC.getItemStack(result); else if(result instanceof IOreDictEntry) out=((IOreDictEntry) result).getName(); else{ CraftTweakerAPI.logError("Unknown input"); return; } for(int i=0;i<recipe.length;i++){ if(recipe[i] instanceof IItemStack) in[i]=CraftTweakerMC.getItemStack(recipe[i]); else if(recipe[i] instanceof IOreDictEntry) in[i]=((IOreDictEntry) recipe[i]).getName(); else{ CraftTweakerAPI.logError("Unknown input"); return; } }
// Path: src/main/java/charcoalPit/crafting/OreSmeltingRecipes.java // public static class AlloyRecipe{ // public Object[] recipe; // public Object output; // public int outAmount; // public boolean usePrefix; // public boolean isAdvanced; // // public AlloyRecipe(Object output, int amount, boolean advanced, boolean usePrefix, Object...recipe) { // this.output=output; // this.outAmount=amount; // this.usePrefix=usePrefix; // this.isAdvanced=advanced; // this.recipe=recipe; // } // // public boolean isInputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // for(int i=0;i<recipe.length;i++){ // if(recipe[i] instanceof ItemStack){ // if(((ItemStack)recipe[i]).isItemEqual(in)) // return true; // } // if(recipe[i] instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(usePrefix){ // String ore=OreDictionary.getOreName(id); // for(int j=0;j<orePrefixes.size();j++){ // if(ore.equals(orePrefixes.get(j)+recipe[i])) // return true; // } // }else{ // if(OreDictionary.getOreName(id).equals(recipe[i])) // return true; // } // } // } // } // return false; // } // // public boolean isInputEqual(ItemStack in, int slot){ // if(in.isEmpty()) // return false; // if(slot>=recipe.length) // return false; // if(recipe[slot] instanceof ItemStack){ // if(((ItemStack)recipe[slot]).isItemEqual(in)) // return true; // } // if(recipe[slot] instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(usePrefix){ // String ore=OreDictionary.getOreName(id); // for(int j=0;j<orePrefixes.size();j++){ // if(ore.equals(orePrefixes.get(j)+recipe[slot])) // return true; // } // }else{ // if(OreDictionary.getOreName(id).equals(recipe[slot])) // return true; // } // } // } // return false; // } // // public boolean isOutputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // if(output instanceof ItemStack){ // if(((ItemStack)output).isItemEqual(in)) // return true; // } // if(output instanceof String){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(OreDictionary.getOreName(id).equals(output)) // return true; // } // } // return false; // } // } // // Path: src/main/java/charcoalPit/crafting/OreSmeltingRecipes.java // public static class SmeltingFuel{ // // public String ore; // public ItemStack item; // public int value; // public SmeltingFuel(String ore,ItemStack item, int value) { // this.ore=ore; // this.item=item; // this.value=value; // } // // public boolean isInputEqual(ItemStack in){ // if(in.isEmpty()) // return false; // if(!item.isEmpty()){ // if(item.isItemEqual(in)) // return true; // } // if(ore!=null){ // int[] ids=OreDictionary.getOreIDs(in); // for(int id:ids){ // if(OreDictionary.getOreName(id).equals(ore)) // return true; // } // } // return false; // } // // } // Path: src/main/java/charcoalPit/crafting/MineTweaker.java import java.util.ArrayList; import charcoalPit.crafting.OreSmeltingRecipes.AlloyRecipe; import charcoalPit.crafting.OreSmeltingRecipes.SmeltingFuel; import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.minecraft.CraftTweakerMC; import crafttweaker.api.oredict.IOreDictEntry; import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; OreSmeltingRecipes.smeltingFuels.add(new SmeltingFuel(null, CraftTweakerMC.getItemStack(in), value)); } @ZenMethod public static void flushSmeltingFuels(){ OreSmeltingRecipes.smeltingFuels=new ArrayList<>(); } @ZenMethod public static void addAlloyRecipe(IIngredient result, int amount, boolean advanced, boolean usePrefix, IIngredient[] recipe){ Object out; Object[] in=new Object[recipe.length]; if(result instanceof IItemStack) out=CraftTweakerMC.getItemStack(result); else if(result instanceof IOreDictEntry) out=((IOreDictEntry) result).getName(); else{ CraftTweakerAPI.logError("Unknown input"); return; } for(int i=0;i<recipe.length;i++){ if(recipe[i] instanceof IItemStack) in[i]=CraftTweakerMC.getItemStack(recipe[i]); else if(recipe[i] instanceof IOreDictEntry) in[i]=((IOreDictEntry) recipe[i]).getName(); else{ CraftTweakerAPI.logError("Unknown input"); return; } }
OreSmeltingRecipes.addAlloyRecipe(new AlloyRecipe(out, amount, advanced, usePrefix, in));
EnderiumSmith/CharcoalPit
src/main/java/charcoalPit/blocks/BlocksRegistry.java
// Path: src/main/java/charcoalPit/core/Constants.java // public class Constants { // // public static final String MODID="charcoal_pit"; // public static final String MODNAME="Charcoal Pit"; // public static final String MODVERSION="1.20"; // } // // Path: src/main/java/charcoalPit/fluids/FluidsRegistry.java // public class FluidsRegistry { // // public static Fluid Creosote; // public static BlockFluidCreosote BlockCreosote; // // public static void registerFluids(){ // if(!FluidRegistry.isFluidRegistered("creosote")){ // Creosote=new FluidCreosote("creosote", new ResourceLocation(Constants.MODID, "blocks/creosote_still"), new ResourceLocation(Constants.MODID, "blocks/creosote_flow")); // Creosote.setViscosity(2000); // FluidRegistry.registerFluid(Creosote); // FluidRegistry.addBucketForFluid(Creosote); // BlockCreosote=new BlockFluidCreosote(); // Creosote.setBlock(BlockCreosote); // }else{ // Creosote=FluidRegistry.getFluid("creosote"); // if(Creosote.getBlock()==null){ // BlockCreosote=new BlockFluidCreosote(); // Creosote.setBlock(BlockCreosote); // } // } // } // }
import charcoalPit.core.Constants; import charcoalPit.fluids.FluidsRegistry; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.statemap.StateMapperBase; import net.minecraft.item.EnumDyeColor; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly;
public static BlockActivePile activeCoalPile=new BlockActivePile(Material.ROCK, "active_coal_pile", true); public static BlockAshPile charcoalPile=new BlockAshPile("charcoal_pile", false); public static BlockAshPile cokePile=new BlockAshPile("coke_pile", true); public static BlockCreosoteCollector stoneCollector=new BlockCreosoteCollector("stone_creosote_collector", false); public static BlockCreosoteCollector brickCollector=new BlockCreosoteCollector("brick_creosote_collector", true); public static BlockCreosoteCollector netherCollector=new BlockCreosoteCollector("nether_creosote_collector", true); public static BlockPotteryKiln potteryKiln=new BlockPotteryKiln("pottery_kiln"); public static BlockCeramicPot ceramicPot=new BlockCeramicPot("ceramic_pot"); public static BlockClayPot clayPot=new BlockClayPot(); public static BlockSmeltedPot brokenPot=new BlockSmeltedPot(); public static BlockDyedPot[] dyedPot=new BlockDyedPot[16]; public static BlockThatch thatch=new BlockThatch(); public static BlockBloomeryHatch hatch=new BlockBloomeryHatch(); public static BlockBronzeReinforcedBrick reinforcedBrick=new BlockBronzeReinforcedBrick(); public static BlockBloomeryOreLayer oreLayer=new BlockBloomeryOreLayer(); public static BlockBloom bloom=new BlockBloom(); public static BlockCustomFurnace furnace=new BlockCustomFurnace(); static{ for(int i=0;i<16;i++){ dyedPot[i]=new BlockDyedPot("dyed_pot", EnumDyeColor.byMetadata(i)); } } @SubscribeEvent public static void registerBlocks(RegistryEvent.Register<Block> event){ event.getRegistry().registerAll(logPile, cokeBlock, activeLogPile, activeCoalPile, charcoalPile, cokePile, stoneCollector, brickCollector, netherCollector, potteryKiln, ceramicPot, clayPot, brokenPot, thatch, hatch, reinforcedBrick, oreLayer, bloom, furnace); event.getRegistry().registerAll(dyedPot);
// Path: src/main/java/charcoalPit/core/Constants.java // public class Constants { // // public static final String MODID="charcoal_pit"; // public static final String MODNAME="Charcoal Pit"; // public static final String MODVERSION="1.20"; // } // // Path: src/main/java/charcoalPit/fluids/FluidsRegistry.java // public class FluidsRegistry { // // public static Fluid Creosote; // public static BlockFluidCreosote BlockCreosote; // // public static void registerFluids(){ // if(!FluidRegistry.isFluidRegistered("creosote")){ // Creosote=new FluidCreosote("creosote", new ResourceLocation(Constants.MODID, "blocks/creosote_still"), new ResourceLocation(Constants.MODID, "blocks/creosote_flow")); // Creosote.setViscosity(2000); // FluidRegistry.registerFluid(Creosote); // FluidRegistry.addBucketForFluid(Creosote); // BlockCreosote=new BlockFluidCreosote(); // Creosote.setBlock(BlockCreosote); // }else{ // Creosote=FluidRegistry.getFluid("creosote"); // if(Creosote.getBlock()==null){ // BlockCreosote=new BlockFluidCreosote(); // Creosote.setBlock(BlockCreosote); // } // } // } // } // Path: src/main/java/charcoalPit/blocks/BlocksRegistry.java import charcoalPit.core.Constants; import charcoalPit.fluids.FluidsRegistry; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.statemap.StateMapperBase; import net.minecraft.item.EnumDyeColor; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public static BlockActivePile activeCoalPile=new BlockActivePile(Material.ROCK, "active_coal_pile", true); public static BlockAshPile charcoalPile=new BlockAshPile("charcoal_pile", false); public static BlockAshPile cokePile=new BlockAshPile("coke_pile", true); public static BlockCreosoteCollector stoneCollector=new BlockCreosoteCollector("stone_creosote_collector", false); public static BlockCreosoteCollector brickCollector=new BlockCreosoteCollector("brick_creosote_collector", true); public static BlockCreosoteCollector netherCollector=new BlockCreosoteCollector("nether_creosote_collector", true); public static BlockPotteryKiln potteryKiln=new BlockPotteryKiln("pottery_kiln"); public static BlockCeramicPot ceramicPot=new BlockCeramicPot("ceramic_pot"); public static BlockClayPot clayPot=new BlockClayPot(); public static BlockSmeltedPot brokenPot=new BlockSmeltedPot(); public static BlockDyedPot[] dyedPot=new BlockDyedPot[16]; public static BlockThatch thatch=new BlockThatch(); public static BlockBloomeryHatch hatch=new BlockBloomeryHatch(); public static BlockBronzeReinforcedBrick reinforcedBrick=new BlockBronzeReinforcedBrick(); public static BlockBloomeryOreLayer oreLayer=new BlockBloomeryOreLayer(); public static BlockBloom bloom=new BlockBloom(); public static BlockCustomFurnace furnace=new BlockCustomFurnace(); static{ for(int i=0;i<16;i++){ dyedPot[i]=new BlockDyedPot("dyed_pot", EnumDyeColor.byMetadata(i)); } } @SubscribeEvent public static void registerBlocks(RegistryEvent.Register<Block> event){ event.getRegistry().registerAll(logPile, cokeBlock, activeLogPile, activeCoalPile, charcoalPile, cokePile, stoneCollector, brickCollector, netherCollector, potteryKiln, ceramicPot, clayPot, brokenPot, thatch, hatch, reinforcedBrick, oreLayer, bloom, furnace); event.getRegistry().registerAll(dyedPot);
if(FluidsRegistry.BlockCreosote!=null){
EnderiumSmith/CharcoalPit
src/main/java/charcoalPit/blocks/BlocksRegistry.java
// Path: src/main/java/charcoalPit/core/Constants.java // public class Constants { // // public static final String MODID="charcoal_pit"; // public static final String MODNAME="Charcoal Pit"; // public static final String MODVERSION="1.20"; // } // // Path: src/main/java/charcoalPit/fluids/FluidsRegistry.java // public class FluidsRegistry { // // public static Fluid Creosote; // public static BlockFluidCreosote BlockCreosote; // // public static void registerFluids(){ // if(!FluidRegistry.isFluidRegistered("creosote")){ // Creosote=new FluidCreosote("creosote", new ResourceLocation(Constants.MODID, "blocks/creosote_still"), new ResourceLocation(Constants.MODID, "blocks/creosote_flow")); // Creosote.setViscosity(2000); // FluidRegistry.registerFluid(Creosote); // FluidRegistry.addBucketForFluid(Creosote); // BlockCreosote=new BlockFluidCreosote(); // Creosote.setBlock(BlockCreosote); // }else{ // Creosote=FluidRegistry.getFluid("creosote"); // if(Creosote.getBlock()==null){ // BlockCreosote=new BlockFluidCreosote(); // Creosote.setBlock(BlockCreosote); // } // } // } // }
import charcoalPit.core.Constants; import charcoalPit.fluids.FluidsRegistry; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.statemap.StateMapperBase; import net.minecraft.item.EnumDyeColor; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly;
public static BlockThatch thatch=new BlockThatch(); public static BlockBloomeryHatch hatch=new BlockBloomeryHatch(); public static BlockBronzeReinforcedBrick reinforcedBrick=new BlockBronzeReinforcedBrick(); public static BlockBloomeryOreLayer oreLayer=new BlockBloomeryOreLayer(); public static BlockBloom bloom=new BlockBloom(); public static BlockCustomFurnace furnace=new BlockCustomFurnace(); static{ for(int i=0;i<16;i++){ dyedPot[i]=new BlockDyedPot("dyed_pot", EnumDyeColor.byMetadata(i)); } } @SubscribeEvent public static void registerBlocks(RegistryEvent.Register<Block> event){ event.getRegistry().registerAll(logPile, cokeBlock, activeLogPile, activeCoalPile, charcoalPile, cokePile, stoneCollector, brickCollector, netherCollector, potteryKiln, ceramicPot, clayPot, brokenPot, thatch, hatch, reinforcedBrick, oreLayer, bloom, furnace); event.getRegistry().registerAll(dyedPot); if(FluidsRegistry.BlockCreosote!=null){ event.getRegistry().register(FluidsRegistry.BlockCreosote); } } @SubscribeEvent @SideOnly(Side.CLIENT) public static void registerModels(ModelRegistryEvent event){ StateMapperBase mapper=new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
// Path: src/main/java/charcoalPit/core/Constants.java // public class Constants { // // public static final String MODID="charcoal_pit"; // public static final String MODNAME="Charcoal Pit"; // public static final String MODVERSION="1.20"; // } // // Path: src/main/java/charcoalPit/fluids/FluidsRegistry.java // public class FluidsRegistry { // // public static Fluid Creosote; // public static BlockFluidCreosote BlockCreosote; // // public static void registerFluids(){ // if(!FluidRegistry.isFluidRegistered("creosote")){ // Creosote=new FluidCreosote("creosote", new ResourceLocation(Constants.MODID, "blocks/creosote_still"), new ResourceLocation(Constants.MODID, "blocks/creosote_flow")); // Creosote.setViscosity(2000); // FluidRegistry.registerFluid(Creosote); // FluidRegistry.addBucketForFluid(Creosote); // BlockCreosote=new BlockFluidCreosote(); // Creosote.setBlock(BlockCreosote); // }else{ // Creosote=FluidRegistry.getFluid("creosote"); // if(Creosote.getBlock()==null){ // BlockCreosote=new BlockFluidCreosote(); // Creosote.setBlock(BlockCreosote); // } // } // } // } // Path: src/main/java/charcoalPit/blocks/BlocksRegistry.java import charcoalPit.core.Constants; import charcoalPit.fluids.FluidsRegistry; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.statemap.StateMapperBase; import net.minecraft.item.EnumDyeColor; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public static BlockThatch thatch=new BlockThatch(); public static BlockBloomeryHatch hatch=new BlockBloomeryHatch(); public static BlockBronzeReinforcedBrick reinforcedBrick=new BlockBronzeReinforcedBrick(); public static BlockBloomeryOreLayer oreLayer=new BlockBloomeryOreLayer(); public static BlockBloom bloom=new BlockBloom(); public static BlockCustomFurnace furnace=new BlockCustomFurnace(); static{ for(int i=0;i<16;i++){ dyedPot[i]=new BlockDyedPot("dyed_pot", EnumDyeColor.byMetadata(i)); } } @SubscribeEvent public static void registerBlocks(RegistryEvent.Register<Block> event){ event.getRegistry().registerAll(logPile, cokeBlock, activeLogPile, activeCoalPile, charcoalPile, cokePile, stoneCollector, brickCollector, netherCollector, potteryKiln, ceramicPot, clayPot, brokenPot, thatch, hatch, reinforcedBrick, oreLayer, bloom, furnace); event.getRegistry().registerAll(dyedPot); if(FluidsRegistry.BlockCreosote!=null){ event.getRegistry().register(FluidsRegistry.BlockCreosote); } } @SubscribeEvent @SideOnly(Side.CLIENT) public static void registerModels(ModelRegistryEvent event){ StateMapperBase mapper=new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return new ModelResourceLocation(new ResourceLocation(Constants.MODID, "creosote"), "creosote");