Add bulid.gradle setting
repositories {
...
maven { url 'https://jitpack.io' } //add repositories
}
dependencies {
...
implementation 'com.github.renuevo:drcode_library:1.3' //add releases current version
...
}
Example Sample Vo Class
class SampleVo{
private String key;
private String value;
public SampleVo(String key, String value){
}
public SampleVo(String key, String value){
this.key = key;
this.value = value;
}
public void setKey(String key){
this.key = key;
}
public void setValue(String value){
this.value = value;
}
public String getKey(){
return key;
}
public String getValue(){
return value;
}
}
CsvUtils useful csv library! ✔️
This library need for getter/setter on VoClass
1. Default Write
void writeCsv(List<String[]> list, String path, String charsetName)
String[] header = {"name", "deokhwa"}; List<String[]> saveList = new ArrayList<>(); saveList.add(header); //create sample list csvUtils.writeCsv(saveList, path, "utf-8"); //write csvCsv Out Result
name deokhwa
2. List Model Write
void writeCsv(List list, String path, String charsetName, Class<T> classType)
SampleVo sampleVo = new SampleVo("name","deokhwa"); List<SampleVo> saveList = new ArrayList<>(); saveList.add(sampleVo); //create sample list csvUtils.writeCsv(saveList, path, "utf-8", SampleVo.class); //write csvCsv Out Result
key value name deokhwa Csv Header Is Model Member Variable Name
3. Map Model Write
void writeCsv(Map<String, List> writeMap, String path, String charsetName, Class<T> classType)
SampleVo sampleVo1 = new SampleVo("name1","deokhwa"); SampleVo sampleVo2 = new SampleVo("name2","renuevo"); Map<String, List<SampleVo>> saveMap = new HashMap<>(); saveMap.put("one", Arrays.asList(sampleVo1)); //create sample list saveMap.put("two", Arrays.asList(sampleVo2)); //create sample list csvUtils.writeCsv(saveMap, path, "utf-8", SampleVo.class); //write csvCsv Out Result
key value name1 deokhwa name2 renuevo Csv Header Is Model Member Variable Name
1. Default Read
List<String[]> readCsv(String path, String charsetName, int line)List<String[]> csvList = csvUtils.readCsv(path, "utf-8", 1); //write csv
2. Model Read
List<T> readModelCsv(String path, String charsetName, Class<T> classType)List<SampleVo> csvList = csvUtils.readModelCsv(path, "utf-8", SampleVo.class); //write csvIf you have different csv header then add header name setter
Csv Out Result
title value name deokhwa class SampleVo{ private String key; ... //add header setter public void setTitle(String title){ this.key = title; } ... }
VoMapperUtils useful java reflection library! ✔️
VoMapperUtils default use in static method
Key Type
- default : setKeyValue() -> keyValue
- lower : setKeyValue() -> keyvalue
- upper : setKeyValue() -> KEYVALUE
- underUpper : setKey_value() -> keyValue
- upperUnder : setKeyValue() -> key_value
- all : all key type 1 ~ 5 pleases check duplication ❗
This utils return type 👉 Map<String, Method>
Map<String, Method> getFieldMehtods(Class<T> classType, String methodType)
Map<String, Method> setSampleVoMap = VoMapperUtils.getFieldMehtods(SampleVo.class, "set"); //keytype default String[] memberArray = {"key","value"}; SampleVo sampleVo = new SampleVo(); for(String key : memberArray){ //key is key/value if(setSampleVoMap.containsKey(key)) setSampleVoMap.get(key).invoke(sampleVo, key); //set SampleVo value }SampleVo Result
key value key value
Example keyType All
Map<String, Method> getFieldMehtods(Class classType, String methodType, String keyType)//setSampleVoMap key -> value/Value key/Key Map<String, Method> setSampleVoMap = VoMapperUtils.getFieldMehtods(SampleVo.class, "set", "all");
This utils return type 👉 Map<String, Method>
Map<String, Method> getFieldMehtods(Class<T> classType, String methodType)
Map<String, Method> getSampleVoMap = VoMapperUtils.getFieldMehtods(SampleVo.class, "get"); //keytype default SampleVo sampleVo = new SampleVo("name", "deokhwa kim"); System.out.println(getSampleVoMap.get("value").invoke(sampleVo)); //return Object TypePrintln Result
deokhwa kimkey type parameter same Set
EsQueryBuilder useful DSL query build library! ✔️
QueryTemplate read json query file
String getQueryTemplate(File qyFile)
String query = EsQueryBuilder.getQueryTemplate(new File(..)); //Json Query File Read
getQuery
json query file value change keyword : keyword is $
{
"size" : "$size", /*parameter1*/
"query" : {
"term": {
"search": {"value": "$value"} /*parameter2*/
}
}
}
String getQuery(String query, Object... variables)
String dslQuery = EsQueryBuilder.getQuery(query, 10, "java"); //return to Json DSL Query
Csv Out Result
{
"size" : 10,
"query" : {
"term": {
"search": {"value": "java"}
}
}
}
EsMapper useful Elastic Response Parsing library! ✔️
1. getSearchCount
int getSearchCount(String response)
EsMapper esMapper = new EsMapper(); esMapper.getSourceCount(response); //elastic search response string type
2. getSearchSource
List getSearchSource(String response, Class classType)
EsMapper esMapper = new EsMapper(); List<SampleVo> sampleVoList = esMapper.getSearchSource(response, SampleVo.class); //elastic response List<Object> return