Merge pull request #4 from getrebuild/dev

dev
This commit is contained in:
getrebuild 2019-01-30 17:28:38 +08:00 committed by GitHub
commit 99a72b7378
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 82 additions and 77 deletions

View file

@ -1,12 +1,14 @@
-- Init db/user
-- #1 database/user
-- NOTE : UNCOMMENT IF NEEDED
/*
CREATE DATABASE `rebuild10` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
CREATE USER 'rebuild'@'127.0.0.1' IDENTIFIED BY 'rebuild';
GRANT ALL PRIVILEGES ON `rebuild10`.* TO 'rebuild'@'127.0.0.1';
FLUSH PRIVILEGES;
USE `rebuild10`;
*/
-- Init schemas
-- #2 schemas
-- Generated by SchemaGen.java
-- ************ Entity [User] DDL ************
@ -286,7 +288,7 @@ create table if not exists `attachment_folder` (
)Engine=InnoDB;
-- Init data
-- #3 datas
-- User
INSERT INTO `user` (`USER_ID`, `LOGIN_NAME`, `PASSWORD`, `FULL_NAME`, `DEPT_ID`, `ROLE_ID`, `IS_DISABLED`, `CREATED_ON`, `CREATED_BY`, `MODIFIED_ON`, `MODIFIED_BY`, `QUICK_CODE`)

View file

@ -1,13 +1,15 @@
language: java
sudo: false
script: mvn install -DskipTests=true -Denv=travis-ci -B -V
script: mvn clean install -DskipTests=false -B -V
services:
- mysql
- redis
before_install:
# - mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
- mysql -e "CREATE DATABASE `rebuild10` DEFAULT CHARSET utf8 COLLATE utf8_general_ci; CREATE USER 'rebuild'@'127.0.0.1' IDENTIFIED BY 'rebuild'; GRANT ALL PRIVILEGES ON `rebuild10`.* TO 'rebuild'@'127.0.0.1';"
- mysql -e "CREATE DATABASE rebuild10 DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"
- mysql -e "CREATE USER 'rebuild'@'127.0.0.1' IDENTIFIED BY 'rebuild'; GRANT ALL PRIVILEGES ON rebuild10.* TO 'rebuild'@'127.0.0.1'; FLUSH PRIVILEGES;"
- mysql -D rebuild10 < .setup/mysql-init.sql
#script: "mvn cobertura:cobertura"
#after_success:

View file

@ -6,7 +6,7 @@
<groupId>com.rebuild</groupId>
<artifactId>rebuild</artifactId>
<packaging>war</packaging>
<version>1.0.0-PREVIEW</version>
<version>1.0.0-SNAPSHOT</version>
<name>rebuild</name>
<description>Building your system free!</description>
<url>https://getrebuild.com/</url>

View file

@ -55,7 +55,7 @@ public final class Application {
/** Rebuild Version
*/
public static final String VER = "1.0.0-PREVIEW";
public static final String VER = "1.0.0-SNAPSHOT";
/** Logging for Global
*/

View file

@ -26,6 +26,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert;
import com.alibaba.fastjson.JSONObject;
@ -43,6 +45,8 @@ import cn.devezhao.persist4j.engine.ID;
* @since 01/10/2019
*/
public class ImportEnter {
private static final Log LOG = LogFactory.getLog(ImportEnter.class);
public static final int REPEAT_OPT_UPDATE = 1;
public static final int REPEAT_OPT_SKIP = 2;
@ -103,6 +107,8 @@ public class ImportEnter {
// --
/**
* 解析导入规则
*
* @param rule
* @return
* @throws IllegalArgumentException
@ -114,20 +120,24 @@ public class ImportEnter {
Assert.notNull(rule.getJSONObject("fields_mapping"), "Node `fields_mapping`");
Entity entity = MetadataHelper.getEntity(rule.getString("entity"));
File file = SystemConfiguration.getFileOfTemp(rule.getString("file"));
if (!file.exists()) {
URL classpathFile = ImportEnter.class.getResource(rule.getString("file"));
try {
file = new File(classpathFile.toURI());
} catch (URISyntaxException e) {
throw new IllegalArgumentException("File not found : " + file, e);
// from TestCase
if (file == null || !file.exists()) {
URL testFile = ImportEnter.class.getClassLoader().getResource(rule.getString("file"));
if (testFile != null) {
try {
file = new File(testFile.toURI());
} catch (URISyntaxException e) {
throw new IllegalArgumentException("File not found : " + file, e);
}
}
LOG.warn("Use file from TestCase : " + file);
}
if (!file.exists()) {
if (file == null || !file.exists()) {
throw new IllegalArgumentException("File not found : " + file);
}
int repeatOpt = rule.getIntValue("repeat_opt");
Field[] repeatFields = null;
if (repeatOpt != 3) {

View file

@ -59,6 +59,14 @@ public class AesPreferencesConfigurer extends PreferencesPlaceholderConfigurer {
props.put(cleanKey, valInCL);
}
}
String mysqlPort = System.getProperty("mysql.port");
if (StringUtils.isNotBlank(mysqlPort)) {
String dbUrl = props.getProperty("db.url");
dbUrl = dbUrl.replace("3306", "4653");
props.put("db.url", dbUrl);
}
propsHold = (Properties) props.clone();
}

View file

@ -86,7 +86,8 @@ public class AES {
* @return
*/
public static String getPassKey() {
String key = StringUtils.defaultIfEmpty(System.getProperty("rbpass"), "REBUILD2018");
String key = StringUtils.defaultIfEmpty(System.getenv("rbpass"), System.getProperty("rbpass"));
key = StringUtils.defaultIfEmpty(key, "REBUILD2018");
key = StringUtils.leftPad(key, 16, "0").substring(0, 16);
return key;
}

View file

@ -44,6 +44,7 @@ public class AppUtils {
/**
* @return
* @see Application#devMode()
*/
public static boolean devMode() {
return Application.devMode();

View file

@ -37,7 +37,7 @@
<property name="acquireIncrement" value="${db.acquireIncrement}" />
<property name="acquireRetryAttempts" value="${db.acquireRetryAttempts}" />
<property name="acquireRetryDelay" value="${db.acquireRetryDelay}" />
<property name="checkoutTimeout" value="500" />
<property name="checkoutTimeout" value="2000" />
<property name="numHelperThreads" value="3" />
<property name="idleConnectionTestPeriod" value="1800" />
<property name="testConnectionOnCheckout" value="true" />

View file

@ -1,7 +1,7 @@
#
# DB settings
db.url=jdbc:mysql://127.0.0.1:4653/rebuild10?useUnicode=true&characterEncoding=UTF-8&useSSL=false&zeroDateTimeBehavior=convertToNull
db.url=jdbc:mysql://127.0.0.1:3306/rebuild10?useUnicode=true&characterEncoding=UTF-8&useSSL=false&zeroDateTimeBehavior=convertToNull
db.user=rebuild
db.passwd=rebuild
db.driver=com.mysql.jdbc.Driver

View file

@ -20,6 +20,7 @@ package com.rebuild.server;
import java.util.Date;
import org.junit.Ignore;
import org.junit.Test;
import com.alibaba.fastjson.JSON;
@ -33,9 +34,14 @@ import cn.devezhao.persist4j.engine.ID;
*/
public class MiscTest {
@Ignore
@Test
public void testJson2String() throws Exception {
System.out.println(JSON.toJSONString(ID.newId(0)));
System.out.println(JSON.toJSONString(new Date()));
System.out.println(System.getenv());
System.out.println(System.getProperties());
}
}

View file

@ -39,18 +39,18 @@ import cn.devezhao.persist4j.Entity;
public class TestSupport {
static {
System.setProperty("catalina.home", "/data/");
System.setProperty("catalina.home", System.getProperty("java.io.tmpdir"));
}
protected static final Log LOG = LogFactory.getLog(TestSupport.class);
protected static final String TEST_ENTITY = "TestAllFieldsRB10";
protected static final String TEST_ENTITY = "TestAllFields";
@BeforeClass
public static void startup() throws Exception {
LOG.warn("TESTING Startup ...");
if ("travis-ci".equals(System.getProperty("env"))) {
TravisCI.install();
if ("true".equals(System.getenv("TRAVIS"))) {
LOG.warn("TESTING in TravisCI ...");
}
Application.debug();

View file

@ -1,43 +0,0 @@
/*
rebuild - Building your system freely.
Copyright (C) 2018 devezhao <zhaofang123@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rebuild.server;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
*
* @author devezhao
* @since 01/26/2019
*/
public class TravisCI {
private static final Log LOG = LogFactory.getLog(TravisCI.class);
/**
* travis-ci install
*/
public static void install() throws Exception {
LOG.warn("Preparing travis-ci TODO ...");
// Class.forName(Driver.class.getName());
// Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:4653/test", "root", "");
// Statement stmt = conn.createStatement();
}
}

View file

@ -19,12 +19,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
package com.rebuild.server.business.datas;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import com.rebuild.server.TestSupport;
import cn.devezhao.commons.excel.Cell;
/**
@ -32,12 +35,14 @@ import cn.devezhao.commons.excel.Cell;
* @author devezhao
* @since 01/09/2019
*/
public class DataFileParserTest {
public class DataFileParserTest extends TestSupport {
@Test
public void testExcel() throws Exception {
URL testFile = DataFileParserTest.class.getResource("dataimports-test.xls");
DataFileParser fileParser = new DataFileParser(new File(testFile.toURI()));
DataFileParser fileParser = getDataFileParser("dataimports-test.xls");
if (fileParser == null) {
return;
}
System.out.println(fileParser.getRowsCount());
List<Cell[]> rows = fileParser.parse(10);
@ -49,8 +54,10 @@ public class DataFileParserTest {
@Test
public void testCSV() throws Exception {
URL testFile = DataFileParserTest.class.getResource("dataimports-test.csv");
DataFileParser fileParser = new DataFileParser(new File(testFile.toURI()));
DataFileParser fileParser = getDataFileParser("dataimports-test.csv");
if (fileParser == null) {
return;
}
System.out.println(fileParser.getRowsCount());
List<Cell[]> rows = fileParser.parse(10);
@ -62,8 +69,10 @@ public class DataFileParserTest {
@Test
public void testXExcel() throws Exception {
URL testFile = DataFileParserTest.class.getResource("dataimports-test.xlsx");
DataFileParser fileParser = new DataFileParser(new File(testFile.toURI()));
DataFileParser fileParser = getDataFileParser("dataimports-test.xlsx");
if (fileParser == null) {
return;
}
System.out.println(fileParser.getRowsCount());
List<Cell[]> rows = fileParser.parse(50);
@ -72,4 +81,13 @@ public class DataFileParserTest {
}
fileParser.close();
}
static DataFileParser getDataFileParser(String fileName) throws URISyntaxException {
URL testFile = DataFileParserTest.class.getClassLoader().getResource(fileName);
if (testFile == null) {
LOG.warn("No file found : " + fileName);
return null;
}
return new DataFileParser(new File(testFile.toURI()));
}
}

View file

@ -37,7 +37,7 @@ public class DataImporterTest extends TestSupport {
ImportEnter importsEnter = ImportEnter.parse(rule);
System.out.println("ImportsEnter 1 : " + importsEnter);
rule = JSON.parseObject("{ file:'dataimports-test.csv', entity:'TestAllFields', repeat_opt:1, repeat_fields:['TestAllFieldsName'], fields_mapping:{TestAllFieldsName:5} }");
rule = JSON.parseObject("{ file:'dataimports-test.xls', entity:'TestAllFields', repeat_opt:1, repeat_fields:['TestAllFieldsName'], fields_mapping:{TestAllFieldsName:5} }");
importsEnter = ImportEnter.parse(rule);
System.out.println("ImportsEnter 2 : " + importsEnter);