Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:knightliao/disconf into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
knightliao committed Jun 13, 2016
2 parents 7cef395 + 0a834e0 commit bee9e92
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 120 deletions.
1 change: 1 addition & 0 deletions disconf-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public interface ConfigDao extends BaseDao<Long, Config> {
/**
* @param appId
* @param envId
* @param env
* @param version
* @param key
* @param disConfigTypeEnum
*
* @return
*/
Config getByParameter(Long appId, Long envId, String env, String key, DisConfigTypeEnum disConfigTypeEnum);
Config getByParameter(Long appId, Long envId, String version, String key, DisConfigTypeEnum disConfigTypeEnum);

/**
* @param
Expand Down Expand Up @@ -57,10 +57,11 @@ public interface ConfigDao extends BaseDao<Long, Config> {
* @param appId
* @param envId
* @param version
*
* @param hasValue
* @return
*/
List<Config> getConfigList(Long appId, Long envId, String version);
List<Config> getConfigList(Long appId, Long envId, String version, Boolean hasValue);


/**
* @param configId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public Config getByParameter(Long appId, Long envId, String version, String key,
*/
@Override
public List<Config> getConfByAppEnv(Long appId, Long envId) {

if (envId == null) {
return find(new Match(Columns.APP_ID, appId), new Match(Columns.STATUS, Constants.STATUS_NORMAL));
} else {
Expand Down Expand Up @@ -81,15 +80,18 @@ public DaoPageResult<Config> getConfigList(Long appId, Long envId, String versio
*
*/
@Override
public List<Config> getConfigList(Long appId, Long envId, String version) {
public List<Config> getConfigList(Long appId, Long envId, String version, Boolean hasValue) {

List<Match> matchs = new ArrayList<Match>();
matchs.add(new Match(Columns.APP_ID, appId));
matchs.add(new Match(Columns.ENV_ID, envId));
matchs.add(new Match(Columns.VERSION, version));
matchs.add(new Match(Columns.STATUS, Constants.STATUS_NORMAL));

return find(matchs, new ArrayList<Order>());
if (hasValue)
return find(matchs, new ArrayList<Order>());
else
return findColumns(matchs,new String[]{Columns.CONFIG_ID,Columns.TYPE,Columns.NAME,Columns.CREATE_TIME
,Columns.UPDATE_TIME,Columns.STATUS,Columns.APP_ID,Columns.ENV_ID,Columns.VERSION});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.baidu.disconf.core.common.json.ValueVo;
import com.baidu.disconf.web.service.config.bo.Config;

import java.util.List;

/**
* @author knightliao
*/
Expand All @@ -12,9 +14,8 @@ public interface ConfigFetchMgr {
/**
* @param appId
* @param envId
* @param env
* @param envId
* @param key
* @param disConfigTypeEnum
*
* @return
*/
Expand All @@ -23,12 +24,22 @@ public interface ConfigFetchMgr {
/**
* @param appId
* @param envId
* @param env
* @param version
* @param key
* @param disConfigTypeEnum
*
* @return
*/
Config getConfByParameter(Long appId, Long envId, String env, String key, DisConfigTypeEnum disConfigTypeEnum);
Config getConfByParameter(Long appId, Long envId, String version, String key, DisConfigTypeEnum disConfigTypeEnum);


/**
* @param appId
* @param envId
* @param env
*
* @return
*/
List<Config> getConfListByParameter(Long appId, Long envId, String env, Boolean hasValue);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.baidu.disconf.web.service.config.service.ConfigFetchMgr;
import com.baidu.disconf.web.service.config.utils.ConfigUtils;

import java.util.List;

/**
* @author knightliao
*/
Expand All @@ -28,10 +30,10 @@ public class ConfigFetchMgrImpl implements ConfigFetchMgr {
* 根据详细参数获取配置
*/
@Override
public Config getConfByParameter(Long appId, Long envId, String env, String key,
public Config getConfByParameter(Long appId, Long envId, String version, String key,
DisConfigTypeEnum disConfigTypeEnum) {

return configDao.getByParameter(appId, envId, env, key, disConfigTypeEnum);
return configDao.getByParameter(appId, envId, version, key, disConfigTypeEnum);
}

/**
Expand All @@ -50,4 +52,12 @@ public ValueVo getConfItemByParameter(Long appId, Long envId, String version, St

return valueVo;
}

/**
* 根据详细参数获取配置列表返回
*/
public List<Config> getConfListByParameter(Long appId, Long envId, String version, Boolean hasValue){
return configDao.getConfigList(appId, envId, version, hasValue);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public List<String> getVersionListByAppEnv(Long appId, Long envId) {
public List<File> getDisconfFileList(ConfListForm confListForm) {

List<Config> configList =
configDao.getConfigList(confListForm.getAppId(), confListForm.getEnvId(), confListForm.getVersion());
configDao.getConfigList(confListForm.getAppId(), confListForm.getEnvId(), confListForm.getVersion(),true);

// 时间作为当前文件夹
String curTime = DateUtils.format(new Date(), DataFormatConstants.COMMON_TIME_FORMAT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.baidu.disconf.web.utils;

import org.apache.commons.lang3.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,101 +14,14 @@ public class CodeUtils {
/**
* utf-8 转换成 unicode
*/
public static String utf8ToUnicode(String inStr) {

char[] myBuffer = inStr.toCharArray();

StringBuffer sb = new StringBuffer();
for (int i = 0; i < inStr.length(); i++) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(myBuffer[i]);
if (ub == Character.UnicodeBlock.BASIC_LATIN) {
sb.append(myBuffer[i]);
} else if (ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
int j = (int) myBuffer[i] - 65248;
sb.append((char) j);
} else {
int chr1 = (char) myBuffer[i];
String hexS = Integer.toHexString(chr1);
String unicode = "\\u" + hexS;
sb.append(unicode.toLowerCase());
}
}
return sb.toString();

public static String utf8ToUnicode(String theStr) {
return StringEscapeUtils.escapeJava(theStr);
}

/**
* unicode 转换成 utf-8
*/
public static String unicodeToUtf8(String theString) {
if (theString == null) {
return null;
}
char aChar;
int len = theString.length();
StringBuffer outBuffer = new StringBuffer(len);
for (int x = 0; x < len; ) {
aChar = theString.charAt(x++);
if (aChar == '\\') {
aChar = theString.charAt(x++);
if (aChar == 'u') {
// Read the xxxx
int value = 0;
for (int i = 0; i < 4; i++) {
aChar = theString.charAt(x++);
switch (aChar) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
value = (value << 4) + aChar - '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
value = (value << 4) + 10 + aChar - 'a';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
value = (value << 4) + 10 + aChar - 'A';
break;
default:
//throw new IllegalArgumentException("Malformed \\uxxxx encoding." + value);
// filter this bad case
value = 0;
break;
}
}
outBuffer.append((char) value);
} else {
if (aChar == 't') {
aChar = '\t';
} else if (aChar == 'r') {
aChar = '\r';
} else if (aChar == 'n') {
aChar = '\n';
} else if (aChar == 'f') {
aChar = '\f';
}
outBuffer.append(aChar);
}
} else {
outBuffer.append(aChar);
}
}
return outBuffer.toString();
public static String unicodeToUtf8(String theStr) {
return StringEscapeUtils.unescapeJava(theStr);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package com.baidu.disconf.web.utils;

import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.input.BOMInputStream;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
* Created by knightliao on 15/1/26.
*/
public class MyStringUtils {


public static boolean isDouble(String str) {
try {
Double.parseDouble(str);
Expand All @@ -13,4 +22,26 @@ public static boolean isDouble(String str) {
return false;
}
}
}

private final static int BUFFER_SIZE = 4096;
private final static String DEFAULT_ENCODING = "UTF-8" ;
/**
* 将InputStream转换成指定编码的String
*/
public static String inputStreamToString(InputStream in, String encoding) throws IOException {

ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[BUFFER_SIZE];
int count = -1;
while((count = in.read(data,0,BUFFER_SIZE)) != -1) {
outStream.write(data, 0, count);
}
return new String(outStream.toByteArray(),encoding);
}
public static String multipartFileToString(MultipartFile file) throws IOException {
BOMInputStream bomInputStream = new BOMInputStream(file.getInputStream());
ByteOrderMark bom = bomInputStream.getBOM();
String charsetName = bom == null ? DEFAULT_ENCODING : bom.getCharsetName();
return inputStreamToString(bomInputStream,charsetName);
}
}
Loading

0 comments on commit bee9e92

Please sign in to comment.