sensorconfig model

This commit is contained in:
insanity 2018-07-04 17:42:01 +09:00
parent ffb9d69a1e
commit 7837981781
14 changed files with 12 additions and 571 deletions

View File

@ -13,7 +13,7 @@
<groupId>com.loafle.overflow</groupId>
<artifactId>commons-java</artifactId>
<packaging>jar</packaging>
<version>1.0.118-SNAPSHOT</version>
<version>1.0.119-SNAPSHOT</version>
<name>com.loafle.overflow.commons-java</name>
<properties>

View File

@ -1,5 +1,9 @@
package com.loafle.overflow.model.sensorconfig;
import java.util.List;
import com.loafle.overflow.model.meta.MetaCollectionItem;
public class SensorConfig {
private Long sensorID;
@ -7,7 +11,8 @@ public class SensorConfig {
private SensorConfigSchedule schedule;
private SensorConfigCrawler crawler;
private SensorConfigConnection connection;
private SensorConfigItems items;
private List<MetaCollectionItem> metaCollectionItems;
public Long getSensorID() {
return sensorID;
@ -41,11 +46,12 @@ public class SensorConfig {
this.connection = connection;
}
public SensorConfigItems getItems() {
return items;
public List<MetaCollectionItem> getMetaCollectionItems() {
return metaCollectionItems;
}
public void setItems(SensorConfigItems items) {
this.items = items;
public void setMetaCollectionItems(List<MetaCollectionItem> metaCollectionItems) {
this.metaCollectionItems = metaCollectionItems;
}
}

View File

@ -1,17 +0,0 @@
package com.loafle.overflow.model.sensorconfig;
import java.util.List;
import com.loafle.overflow.model.meta.MetaCollectionItem;
public class SensorConfigItems {
private List<MetaCollectionItem> metaCollectionItems;
public List<MetaCollectionItem> getMetaCollectionItems() {
return metaCollectionItems;
}
public void setMetaCollectionItems(List<MetaCollectionItem> metaCollectionItems) {
this.metaCollectionItems = metaCollectionItems;
}
}

View File

@ -1,74 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
import com.loafle.overflow.model.meta.MetaCryptoType;
import com.loafle.overflow.model.meta.MetaIPType;
import com.loafle.overflow.model.meta.MetaPortType;
/**
* Connection
*/
public class Connection {
private MetaIPType metaIPType;
private String ip;
private MetaPortType metaPortType;
private Integer port;
private MetaCryptoType metaCryptoType;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
/**
* @return the metaPortType
*/
public MetaPortType getMetaPortType() {
return metaPortType;
}
/**
* @param metaPortType the metaPortType to set
*/
public void setMetaPortType(MetaPortType metaPortType) {
this.metaPortType = metaPortType;
}
/**
* @return the metaIPType
*/
public MetaIPType getMetaIPType() {
return metaIPType;
}
/**
* @param metaIPType the metaIPType to set
*/
public void setMetaIPType(MetaIPType metaIPType) {
this.metaIPType = metaIPType;
}
/**
* @return the metaCryptoType
*/
public MetaCryptoType getMetaCryptoType() {
return metaCryptoType;
}
/**
* @param metaCryptoType the metaCryptoType to set
*/
public void setMetaCryptoType(MetaCryptoType metaCryptoType) {
this.metaCryptoType = metaCryptoType;
}
}

View File

@ -1,25 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
/**
* Crawler
*/
public class Crawler {
private String name;
private String container;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContainer() {
return container;
}
public void setContainer(String container) {
this.container = container;
}
}

View File

@ -1,37 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
import java.util.List;
/**
* Item
*/
public class Item {
private List<Keys> keys;
private QueryInfo queryInfo;
private MappingInfo mappingInfo;
public List<Keys> getKeys() {
return keys;
}
public void setKeys(List<Keys> keys) {
this.keys = keys;
}
public QueryInfo getQueryInfo() {
return queryInfo;
}
public void setQueryInfo(QueryInfo queryInfo) {
this.queryInfo = queryInfo;
}
public MappingInfo getMappingInfo() {
return mappingInfo;
}
public void setMappingInfo(MappingInfo mappingInfo) {
this.mappingInfo = mappingInfo;
}
}

View File

@ -1,36 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
import java.util.HashMap;
import java.util.Map;
/**
* Keys
*/
public class Keys {
private String metric;
private String key;
public String getMetric() {
return metric;
}
public void setMetric(String metric) {
this.metric = metric;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public static Map<String, String> keysToMap(Keys[] keys) {
Map<String, String> map = new HashMap<>();
for (Keys k : keys) {
map.put(k.key, k.metric);
}
return map;
}
}

View File

@ -1,45 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
import java.util.List;
/**
* MappingInfo
*/
public class MappingInfo {
private String parseDirection;
private List<String> arrayColumns;
private List<String> keyColumns;
private String valueColumn;
public String getParseDirection() {
return parseDirection;
}
public void setParseDirection(String parseDirection) {
this.parseDirection = parseDirection;
}
public List<String> getArrayColumns() {
return arrayColumns;
}
public void setArrayColumns(List<String> arrayColumns) {
this.arrayColumns = arrayColumns;
}
public List<String> getKeyColumns() {
return keyColumns;
}
public void setKeyColumns(List<String> keyColumns) {
this.keyColumns = keyColumns;
}
public String getValueColumn() {
return valueColumn;
}
public void setValueColumn(String valueColumn) {
this.valueColumn = valueColumn;
}
}

View File

@ -1,27 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
import java.util.Map;
/**
* QueryInfo
*/
public class QueryInfo {
private String query;
private Map<String, Object> extend;
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
public Map<String, Object> getExtend() {
return extend;
}
public void setExtend(Map<String, Object> extend) {
this.extend = extend;
}
}

View File

@ -1,71 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* ResultSet
*/
public abstract class ResultSet {
protected Item item;
protected List<List<String>> rows;
protected Map<String, Integer> meta;
// methods
public static ResultSet newInstance(Item item) {
if (item.getMappingInfo() == null) {
item.setMappingInfo(new MappingInfo());
}
String type = (String) item.getMappingInfo().getParseDirection();
if (type != null && type.equals("row")) {
return new ResultSetRow(item);
} else {
return new ResultSetCol(item);
}
}
public ResultSet(Item item) {
this.item = item;
this.rows = new ArrayList<>();
this.setMeta();
}
public void addRow(List<String> row) {
rows.add(row);
}
public List<List<String>> getRows() {
return rows;
}
public void setRows(List<List<String>> rows) {
this.rows = rows;
}
public Map<String, Integer> getMeta() {
return meta;
}
public void setMeta(Map<String, Integer> meta) {
this.meta = meta;
}
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
public Map<String, String> getData() {
return parse();
}
// abstracts
public abstract void setMeta();
public abstract Map<String, String> parse();
}

View File

@ -1,102 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* ResultSetCol
*/
public class ResultSetCol extends ResultSet {
public ResultSetCol(Item item) {
super(item);
}
public void setMeta() {
List<Keys> meta = this.item.getKeys();
List<String> arrayColumns = this.item.getMappingInfo().getArrayColumns();
if (this.meta == null) {
this.meta = new HashMap<>();
}
for (int indexI = 0; indexI < meta.size(); ++indexI) {
this.meta.put(meta.get(indexI).getKey(), indexI);
}
if (arrayColumns != null) {
for (int indexI = 0; indexI < arrayColumns.size(); ++indexI) {
if (this.meta.containsKey(arrayColumns.get(indexI))) {
continue;
}
this.meta.put(arrayColumns.get(indexI), indexI + meta.size());
}
}
}
public Map<String, String> parse() {
List<Keys> metrics = this.item.getKeys();
List<String> arrayColumns = this.item.getMappingInfo().getArrayColumns();
Map<String, String> resultMap = new HashMap<>();
List<String> row = null;
String metric = null;
List<String> arrayValue = new ArrayList<>();
int columnIdx = 0;
for (int indexI = 0; indexI < this.rows.size(); ++indexI) {
row = this.rows.get(indexI);
for (int indexJ = 0; indexJ < row.size(); ++indexJ) {
arrayValue.clear();
if (arrayColumns != null) {
for (int indexL = 0; indexL < arrayColumns.size(); ++indexL) {
columnIdx = this.meta.get(arrayColumns.get(indexL));
arrayValue.add(row.get(columnIdx));
}
}
for (int indexK = 0; indexK < metrics.size(); ++indexK) {
metric = metrics.get(indexK).getMetric();
metric = convertMetric(metric, arrayValue);
resultMap.put(metric, row.get(indexK));
}
}
}
return resultMap;
}
private String convertMetric(String metric, List<String> arrayValue) {
if (arrayValue == null || arrayValue.size() <= 0) {
return metric;
}
String convertChar = "$";
String convertStr = null;
for (int indexI = 0; indexI < arrayValue.size(); ++indexI) {
convertStr = convertChar + String.valueOf(indexI);
metric = metric.replace(convertStr, arrayValue.get(indexI));
}
return metric;
}
}

View File

@ -1,107 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* ResultSetRow
*/
public class ResultSetRow extends ResultSet {
public ResultSetRow(Item item) {
super(item);
}
public void setMeta() {
List<String> meta = new ArrayList<>();
List<String> arrayColumns = (List<String>) this.item.getMappingInfo().getArrayColumns();
List<String> keyColumns = (List<String>) this.item.getMappingInfo().getKeyColumns();
String valueColumn = (String) this.item.getMappingInfo().getValueColumn();
if (arrayColumns != null) {
for (String c : arrayColumns) {
meta.add(c);
}
}
if (keyColumns != null) {
for (String c : keyColumns) {
meta.add(c);
}
}
if (valueColumn != null && !valueColumn.equals(""))
meta.add(valueColumn);
if (this.meta == null) {
this.meta = new HashMap<>();
}
for (int indexI = 0; indexI < meta.size(); ++indexI) {
this.meta.put(meta.get(indexI), indexI);
}
}
public Map<String, String> parse() {
Map<String, String> returnMap = new HashMap<>();
String valueColumn = (String) this.item.getMappingInfo().getValueColumn();
for (List<String> row : this.rows) {
String key = makeKey(row);
if (key == null)
continue;
returnMap.put(key, row.get(this.meta.get(valueColumn)));
}
return returnMap;
}
private String makeKey(List<String> data) {
List<Keys> metrics = this.item.getKeys();
List<String> arrayColumns = (List<String>) this.item.getMappingInfo().getArrayColumns();
List<String> keyColumns = (List<String>) this.item.getMappingInfo().getKeyColumns();
List<Keys> keys = this.item.getKeys();
boolean find = false;
int findIndex = -1;
for (String keyColumn : keyColumns) {
String row = data.get(this.meta.get(keyColumn));
for (int i = 0; i < keys.size(); ++i) {
if (row.equals(keys.get(i).getKey())) {
findIndex = i;
find = true;
break;
}
}
if (find == true) {
break;
}
}
if (findIndex < 0) {
return null;
}
String metric = metrics.get(findIndex).getMetric();
if (arrayColumns != null) {
for (int i = 0; i < arrayColumns.size(); ++i) {
// replace
String k = "$" + i;
int dataIndex = this.meta.get(arrayColumns.get(i));
String replaceString = data.get(dataIndex);
metric = metric.replace(k, "'" + replaceString + "'");
}
}
return metric;
}
}

View File

@ -1,16 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
/**
* Schedule
*/
public class Schedule {
private String interval;
public String getInterval() {
return interval;
}
public void setInterval(String interval) {
this.interval = interval;
}
}

View File

@ -1,8 +0,0 @@
package com.loafle.overflow.model.sensorconfig.old;
public class Target {
// private Map<String, Object> auth;
// private Connection connection;
// private Map<String, Object> meta;
}