initial commit
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2016 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.qas.test;
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
||||
import javax.xml.namespace.QName
|
||||
import javax.xml.ws.Service
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import com.qas.web_2005_02.Address
|
||||
import com.qas.web_2005_02.EngineEnumType
|
||||
import com.qas.web_2005_02.EngineType
|
||||
import com.qas.web_2005_02.ProWeb
|
||||
import com.qas.web_2005_02.PromptSetType
|
||||
import com.qas.web_2005_02.QACanSearch
|
||||
import com.qas.web_2005_02.QAData
|
||||
import com.qas.web_2005_02.QADataSet
|
||||
import com.qas.web_2005_02.QAGetAddress
|
||||
import com.qas.web_2005_02.QAGetLayouts
|
||||
import com.qas.web_2005_02.QALayouts
|
||||
import com.qas.web_2005_02.QAPortType
|
||||
import com.qas.web_2005_02.QASearch
|
||||
import com.qas.web_2005_02.QASearchResult
|
||||
|
||||
|
||||
class Client {
|
||||
//stubs generated with:
|
||||
//arye@dm4:~/projects/axelor/axelor-tool/src/main/java$ ~/opt/cxf/bin/wsdl2java -client -frontend jaxws21 http://ip.axelor.com:2021/proweb.wsdl
|
||||
|
||||
//http://cxf.apache.org/docs/how-do-i-develop-a-client.html
|
||||
|
||||
@Test
|
||||
def void WSDL2JavaClient() {
|
||||
ProWeb service = new ProWeb()
|
||||
def serviceName = service.getServiceName()
|
||||
println serviceName
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
def void JAXWSProxy() {
|
||||
QName SERVICE_NAME = new QName("http://www.qas.com/web-2005-02"
|
||||
,"ProWeb")
|
||||
|
||||
QName PORT_NAME = new QName("http://www.qas.com/web-2005-02"
|
||||
,"QAPortType")
|
||||
|
||||
def wsdlURL = new URL("http://ip.axelor.com:2021/proweb.wsdl")
|
||||
println wsdlURL
|
||||
|
||||
Service service = Service.create(wsdlURL, SERVICE_NAME);
|
||||
QAPortType client = service.getPort(QAPortType.class);
|
||||
//QAPortType client = service.getPort(PORT_NAME, QAPortType.class)
|
||||
println client.dump()
|
||||
|
||||
|
||||
|
||||
QAGetLayouts getLayouts = new QAGetLayouts()
|
||||
getLayouts.country = "FRX"
|
||||
|
||||
QALayouts layouts = client.doGetLayouts(getLayouts)
|
||||
println "layouts= "+layouts.layout
|
||||
println layouts.layout*.name
|
||||
|
||||
|
||||
|
||||
|
||||
// 1. Pre-check.
|
||||
print "1. Pre-check."
|
||||
|
||||
QAData qadata = client.doGetData()
|
||||
println qadata
|
||||
println qadata.dataSet
|
||||
QADataSet ds = qadata.dataSet[0]
|
||||
println ds.name
|
||||
println ds.id
|
||||
|
||||
|
||||
QACanSearch canSearch = new QACanSearch()
|
||||
canSearch.country = "FRX"
|
||||
canSearch.layout = "AFNOR INSEE"
|
||||
|
||||
EngineType engType = new EngineType()
|
||||
engType.setFlatten(true)
|
||||
|
||||
engType.value = EngineEnumType.VERIFICATION
|
||||
canSearch.engine = engType
|
||||
def resp = client.doCanSearch(canSearch)
|
||||
println resp.isOk
|
||||
|
||||
|
||||
|
||||
// 2. Initial search.
|
||||
QASearch search = new QASearch()
|
||||
search.country = "FRX"
|
||||
search.layout = "AFNOR INSEE"
|
||||
//search.search = "55 de bercy 75012" //qaPicklist=com.qas.web_2005_02.QAPicklistType@2dd59d3c qaAddress=null verifyLevel=MULTIPLE>
|
||||
//search.search = "55 rue de bercyi 75012" //qaPicklist=null qaAddress=com.qas.web_2005_02.QAAddressType@25c7f37d verifyLevel=INTERACTION_REQUIRED>
|
||||
search.search = "110 rue PETIT 75019 paris" //qaPicklist=null qaAddress=com.qas.web_2005_02.QAAddressType@391da0 verifyLevel=VERIFIED>
|
||||
|
||||
EngineType engTypeT = new EngineType()
|
||||
engTypeT.promptSet = PromptSetType.DEFAULT
|
||||
engTypeT.value = EngineEnumType.VERIFICATION
|
||||
search.engine = engTypeT
|
||||
|
||||
search.engine = engTypeT
|
||||
QASearchResult respSearch = client.doSearch(search)
|
||||
println respSearch.dump()
|
||||
|
||||
|
||||
if (respSearch.qaAddress) {
|
||||
println respSearch.qaAddress.addressLine*.label
|
||||
println respSearch.qaAddress.addressLine*.line
|
||||
//println respSearch.qaAddress.addressLine*.lineContent
|
||||
}
|
||||
|
||||
|
||||
if (respSearch.qaPicklist) {
|
||||
println respSearch.qaPicklist?.total
|
||||
println respSearch.qaPicklist?.picklistEntry*.picklist
|
||||
println respSearch.qaPicklist?.picklistEntry*.postcode
|
||||
println respSearch.qaPicklist?.picklistEntry*.partialAddress
|
||||
println respSearch.qaPicklist?.picklistEntry*.score
|
||||
println respSearch.qaPicklist?.picklistEntry*.moniker
|
||||
|
||||
println respSearch.qaPicklist.dump()
|
||||
|
||||
}
|
||||
|
||||
// 3. OPTIONAL: Refine
|
||||
//DoRefine
|
||||
|
||||
|
||||
// 4. Format the final address.
|
||||
//DoGetAddress
|
||||
QAGetAddress getAddress = new QAGetAddress()
|
||||
if (respSearch.qaPicklist?.picklistEntry) {
|
||||
def moniker = respSearch.qaPicklist?.picklistEntry[0].moniker
|
||||
getAddress.moniker = moniker
|
||||
getAddress.layout = "AFNOR INSEE"
|
||||
|
||||
Address formattedAddress = client.doGetAddress(getAddress)
|
||||
println formattedAddress.dump()
|
||||
println formattedAddress.qaAddress.addressLine*.label
|
||||
println formattedAddress.qaAddress.addressLine*.line
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2016 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.qas.test;
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
||||
import javax.xml.namespace.QName
|
||||
import javax.xml.ws.Service
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import com.qas.web_2005_02.Address
|
||||
import com.qas.web_2005_02.EngineEnumType
|
||||
import com.qas.web_2005_02.EngineType
|
||||
import com.qas.web_2005_02.ProWeb
|
||||
import com.qas.web_2005_02.PromptSetType
|
||||
import com.qas.web_2005_02.QACanSearch
|
||||
import com.qas.web_2005_02.QAData
|
||||
import com.qas.web_2005_02.QADataSet
|
||||
import com.qas.web_2005_02.QAGetAddress
|
||||
import com.qas.web_2005_02.QAGetLayouts
|
||||
import com.qas.web_2005_02.QALayouts
|
||||
import com.qas.web_2005_02.QAPortType
|
||||
import com.qas.web_2005_02.QASearch
|
||||
import com.qas.web_2005_02.QASearchResult
|
||||
|
||||
|
||||
class ClientMonitor {
|
||||
//stubs generated with:
|
||||
//arye@dm4:~/projects/axelor/axelor-tool/src/main/java$ ~/opt/cxf/bin/wsdl2java -client -frontend jaxws21 http://ip.axelor.com:2021/proweb.wsdl
|
||||
|
||||
//http://cxf.apache.org/docs/how-do-i-develop-a-client.html
|
||||
|
||||
// TODO:
|
||||
//http://blog.progs.be/92/cxf-ws-client-dynamic-endpoint-and-loading-wsdl-from-the-classpath
|
||||
|
||||
|
||||
@Test
|
||||
def void JAXWSProxy() {
|
||||
QName SERVICE_NAME = new QName("http://www.qas.com/web-2005-02"
|
||||
,"ProWeb")
|
||||
|
||||
QName PORT_NAME = new QName("http://www.qas.com/web-2005-02"
|
||||
,"QAPortType")
|
||||
|
||||
// set up TCP/IP monitor under Windows | Preferences
|
||||
//http://backup.axelor.com/pub/sftp/proweb.wsdl
|
||||
def wsdlURL = new URL("http://localhost:8001/pub/sftp/proweb.wsdl")
|
||||
println wsdlURL
|
||||
|
||||
Service service = Service.create(wsdlURL, SERVICE_NAME);
|
||||
QAPortType client = service.getPort(QAPortType.class);
|
||||
//QAPortType client = service.getPort(PORT_NAME, QAPortType.class)
|
||||
println client.dump()
|
||||
|
||||
|
||||
|
||||
QAGetLayouts getLayouts = new QAGetLayouts()
|
||||
getLayouts.country = "FRX"
|
||||
|
||||
QALayouts layouts = client.doGetLayouts(getLayouts)
|
||||
println "layouts= "+layouts.layout
|
||||
println layouts.layout*.name
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool;
|
||||
|
||||
import com.axelor.apps.tool.db.Contact;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class InvokationTest {
|
||||
|
||||
protected static final Member INVALID_MEMBER;
|
||||
|
||||
static {
|
||||
Member invalidMember;
|
||||
try {
|
||||
invalidMember = InvokationTest.class.getDeclaredField("INVALID_MEMBER");
|
||||
} catch (NoSuchFieldException ex) {
|
||||
invalidMember = null;
|
||||
} catch (SecurityException ex) {
|
||||
invalidMember = null;
|
||||
}
|
||||
|
||||
INVALID_MEMBER = invalidMember;
|
||||
}
|
||||
|
||||
/** Cache exact attribute class and property reflection Member object */
|
||||
protected static final Map<Class<?>, Map<String, Member>> membersCache =
|
||||
new HashMap<Class<?>, Map<String, Member>>();
|
||||
|
||||
public Contact contact;
|
||||
|
||||
@Before
|
||||
public void prepareTest() {
|
||||
contact = new Contact("Durand", "Pierre");
|
||||
contact.setEmail("@test.com");
|
||||
contact.setFullName(contact.getFullName());
|
||||
contact.setDateOfBirth(LocalDate.now());
|
||||
contact.setPayeurQuality(new BigDecimal("2.2569"));
|
||||
contact.setLanguage("fr");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
ThreadTest thread = new ThreadTest();
|
||||
thread.run();
|
||||
}
|
||||
}
|
||||
|
||||
class ThreadTest extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Object valueEmail = getProperty(contact, "email");
|
||||
Assert.assertEquals(contact.getEmail(), valueEmail);
|
||||
|
||||
Object valueFullName = getProperty(contact, "fullName");
|
||||
Assert.assertEquals(contact.getFullName(), valueFullName);
|
||||
|
||||
Object valueFisrtName = getProperty(contact, "firstName");
|
||||
Assert.assertEquals(contact.getFirstName(), valueFisrtName);
|
||||
|
||||
Object valueLastName = getProperty(contact, "lastName");
|
||||
Assert.assertEquals(contact.getLastName(), valueLastName);
|
||||
|
||||
Object valueDateOfBirth = getProperty(contact, "dateOfBirth");
|
||||
Assert.assertEquals(contact.getDateOfBirth(), valueDateOfBirth);
|
||||
|
||||
Object valuePayeurQuality = getProperty(contact, "payeurQuality");
|
||||
Assert.assertEquals(contact.getPayeurQuality(), valuePayeurQuality);
|
||||
|
||||
Object valueLanguage = getProperty(contact, "language");
|
||||
Assert.assertEquals("fr", valueLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Object getProperty(Object o, String property) {
|
||||
if (o == null) {
|
||||
throw new NullPointerException("o");
|
||||
}
|
||||
|
||||
Class<?> c = o.getClass();
|
||||
|
||||
if (property == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Member member = findMember(c, property);
|
||||
if (member != null) {
|
||||
try {
|
||||
if (member instanceof Method) {
|
||||
return ((Method) member).invoke(o);
|
||||
} else if (member instanceof Field) {
|
||||
return ((Field) member).get(o);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Member findMember(Class<?> clazz, String memberName) {
|
||||
if (clazz == null) {
|
||||
throw new NullPointerException("clazz");
|
||||
}
|
||||
if (memberName == null) {
|
||||
throw new NullPointerException("memberName");
|
||||
}
|
||||
|
||||
synchronized (membersCache) {
|
||||
Map<String, Member> members = membersCache.get(clazz);
|
||||
Member member = null;
|
||||
if (members != null) {
|
||||
member = members.get(memberName);
|
||||
if (member != null) {
|
||||
return member != INVALID_MEMBER ? member : null;
|
||||
}
|
||||
} else {
|
||||
members = new HashMap<String, Member>();
|
||||
membersCache.put(clazz, members);
|
||||
}
|
||||
|
||||
// try getXXX and isXXX properties, look up using reflection
|
||||
String methodSuffix =
|
||||
Character.toUpperCase(memberName.charAt(0))
|
||||
+ memberName.substring(1, memberName.length());
|
||||
|
||||
member = tryGetMethod(clazz, "get" + methodSuffix);
|
||||
if (member == null) {
|
||||
member = tryGetMethod(clazz, "is" + methodSuffix);
|
||||
if (member == null) {
|
||||
member = tryGetMethod(clazz, "has" + methodSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
if (member == null) {
|
||||
// try for a visible field
|
||||
member = tryGetField(clazz, memberName);
|
||||
}
|
||||
|
||||
members.put(memberName, member != null ? member : INVALID_MEMBER);
|
||||
return member;
|
||||
}
|
||||
}
|
||||
|
||||
protected static Method tryGetMethod(Class<?> clazz, String methodName) {
|
||||
try {
|
||||
Method method = clazz.getMethod(methodName);
|
||||
if (method != null) {
|
||||
method.setAccessible(true);
|
||||
}
|
||||
|
||||
return method;
|
||||
} catch (NoSuchMethodException ex) {
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static Field tryGetField(Class<?> clazz, String fieldName) {
|
||||
try {
|
||||
Field field = clazz.getField(fieldName);
|
||||
if (field != null) {
|
||||
field.setAccessible(true);
|
||||
}
|
||||
|
||||
return field;
|
||||
} catch (NoSuchFieldException ex) {
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool;
|
||||
|
||||
import com.axelor.apps.tool.date.DateTool;
|
||||
import java.time.LocalDate;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestDateTool {
|
||||
|
||||
@Test
|
||||
public void testGetNbDay() {
|
||||
Assert.assertEquals(1, DateTool.daysBetween(LocalDate.now(), LocalDate.now(), false));
|
||||
Assert.assertEquals(
|
||||
30, DateTool.daysBetween(LocalDate.of(2011, 9, 1), LocalDate.of(2011, 9, 30), false));
|
||||
Assert.assertEquals(
|
||||
26, DateTool.daysBetween(LocalDate.of(2011, 2, 2), LocalDate.of(2011, 2, 27), true));
|
||||
Assert.assertEquals(
|
||||
26, DateTool.daysBetween(LocalDate.of(2011, 2, 2), LocalDate.of(2011, 2, 27), false));
|
||||
Assert.assertEquals(
|
||||
-26, DateTool.daysBetween(LocalDate.of(2011, 2, 27), LocalDate.of(2011, 2, 2), false));
|
||||
Assert.assertEquals(
|
||||
-26, DateTool.daysBetween(LocalDate.of(2011, 2, 27), LocalDate.of(2011, 2, 2), true));
|
||||
Assert.assertEquals(
|
||||
30, DateTool.daysBetween(LocalDate.of(2011, 2, 1), LocalDate.of(2011, 2, 28), true));
|
||||
Assert.assertEquals(
|
||||
1, DateTool.daysBetween(LocalDate.of(2011, 7, 30), LocalDate.of(2011, 7, 31), true));
|
||||
Assert.assertEquals(
|
||||
54, DateTool.daysBetween(LocalDate.of(2011, 7, 12), LocalDate.of(2011, 9, 5), true));
|
||||
Assert.assertEquals(
|
||||
30, DateTool.daysBetween(LocalDate.of(2011, 7, 15), LocalDate.of(2011, 8, 14), true));
|
||||
Assert.assertEquals(
|
||||
30, DateTool.daysBetween(LocalDate.of(2011, 7, 1), LocalDate.of(2011, 7, 31), true));
|
||||
Assert.assertEquals(
|
||||
31, DateTool.daysBetween(LocalDate.of(2012, 2, 29), LocalDate.of(2012, 3, 30), true));
|
||||
Assert.assertEquals(
|
||||
31, DateTool.daysBetween(LocalDate.of(2011, 2, 28), LocalDate.of(2011, 3, 30), true));
|
||||
Assert.assertEquals(
|
||||
33, DateTool.daysBetween(LocalDate.of(2012, 2, 28), LocalDate.of(2012, 3, 30), true));
|
||||
Assert.assertEquals(
|
||||
181, DateTool.daysBetween(LocalDate.of(2011, 12, 31), LocalDate.of(2012, 6, 30), true));
|
||||
Assert.assertEquals(
|
||||
-68, DateTool.daysBetween(LocalDate.of(2011, 12, 9), LocalDate.of(2011, 10, 2), true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsProrata() {
|
||||
|
||||
// dateFrame1<date1<dateFrame2
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 7, 10),
|
||||
LocalDate.of(2011, 7, 30)));
|
||||
// dateFrame1<date2<dateFrame2
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 6, 1),
|
||||
LocalDate.of(2011, 7, 10)));
|
||||
// date1<dateFrame1 and dateFrame2<date2
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 6, 1),
|
||||
LocalDate.of(2011, 7, 30)));
|
||||
// dateFrame1=date1 and dateFrame2=date2
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15)));
|
||||
// date1=dateFrame1
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 30)));
|
||||
// date1=dateFrame2
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 7, 30)));
|
||||
// date2=dateFrame1
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 6, 1),
|
||||
LocalDate.of(2011, 7, 1)));
|
||||
// date2=dateFrame2
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 6, 1),
|
||||
LocalDate.of(2011, 7, 15)));
|
||||
// date2=null and date1<dateFrame1
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1), LocalDate.of(2011, 7, 15), LocalDate.of(2011, 6, 1), null));
|
||||
// date2=null and date1=dateFrame1
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1), LocalDate.of(2011, 7, 15), LocalDate.of(2011, 7, 1), null));
|
||||
// date2=null and date1>dateFrame1 and date1<dateFrame2
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1), LocalDate.of(2011, 7, 15), LocalDate.of(2011, 7, 10), null));
|
||||
// date2=null and date1=dateFrame2
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1), LocalDate.of(2011, 7, 15), LocalDate.of(2011, 7, 15), null));
|
||||
// date2=null and date1<dateFrame1
|
||||
Assert.assertTrue(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1), LocalDate.of(2011, 7, 15), LocalDate.of(2011, 6, 1), null));
|
||||
// date2=null and date1>dateFrame2
|
||||
Assert.assertFalse(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1), LocalDate.of(2011, 7, 15), LocalDate.of(2011, 8, 1), null));
|
||||
// date2<dateFrame1
|
||||
Assert.assertFalse(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 6, 1),
|
||||
LocalDate.of(2011, 6, 30)));
|
||||
// date1>dateFrame2
|
||||
Assert.assertFalse(
|
||||
DateTool.isProrata(
|
||||
LocalDate.of(2011, 7, 1),
|
||||
LocalDate.of(2011, 7, 15),
|
||||
LocalDate.of(2011, 8, 1),
|
||||
LocalDate.of(2011, 8, 30)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNbFullMonth() {
|
||||
Assert.assertEquals(
|
||||
1, DateTool.days360MonthsBetween(LocalDate.of(2011, 1, 1), LocalDate.of(2011, 2, 5)));
|
||||
Assert.assertEquals(
|
||||
0, DateTool.days360MonthsBetween(LocalDate.of(2011, 1, 1), LocalDate.of(2011, 1, 25)));
|
||||
Assert.assertEquals(
|
||||
1, DateTool.days360MonthsBetween(LocalDate.of(2011, 12, 15), LocalDate.of(2012, 1, 25)));
|
||||
Assert.assertEquals(
|
||||
1, DateTool.days360MonthsBetween(LocalDate.of(2011, 12, 15), LocalDate.of(2012, 1, 15)));
|
||||
Assert.assertEquals(
|
||||
1, DateTool.days360MonthsBetween(LocalDate.of(2011, 12, 15), LocalDate.of(2012, 1, 14)));
|
||||
Assert.assertEquals(
|
||||
0, DateTool.days360MonthsBetween(LocalDate.of(2011, 12, 15), LocalDate.of(2012, 1, 13)));
|
||||
Assert.assertEquals(
|
||||
5, DateTool.days360MonthsBetween(LocalDate.of(2011, 10, 7), LocalDate.of(2012, 3, 9)));
|
||||
Assert.assertEquals(
|
||||
1, DateTool.days360MonthsBetween(LocalDate.of(2011, 1, 31), LocalDate.of(2011, 2, 28)));
|
||||
Assert.assertEquals(
|
||||
1, DateTool.days360MonthsBetween(LocalDate.of(2011, 3, 31), LocalDate.of(2011, 4, 30)));
|
||||
Assert.assertEquals(
|
||||
-5, DateTool.days360MonthsBetween(LocalDate.of(2012, 3, 9), LocalDate.of(2011, 10, 7)));
|
||||
Assert.assertEquals(
|
||||
-1, DateTool.days360MonthsBetween(LocalDate.of(2011, 4, 30), LocalDate.of(2011, 3, 31)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextOccurency() {
|
||||
Assert.assertEquals(
|
||||
LocalDate.of(2010, 11, 9),
|
||||
DateTool.nextOccurency(LocalDate.of(2010, 10, 7), LocalDate.of(2011, 3, 9), 2));
|
||||
Assert.assertEquals(
|
||||
LocalDate.of(2010, 11, 9),
|
||||
DateTool.nextOccurency(LocalDate.of(2010, 10, 7), LocalDate.of(2011, 5, 9), 2));
|
||||
Assert.assertEquals(
|
||||
LocalDate.of(2010, 8, 31),
|
||||
DateTool.nextOccurency(LocalDate.of(2010, 8, 7), LocalDate.of(2011, 4, 30), 1));
|
||||
Assert.assertEquals(
|
||||
LocalDate.of(2010, 5, 9),
|
||||
DateTool.nextOccurency(LocalDate.of(2010, 3, 9), LocalDate.of(2011, 3, 9), 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastOccurency() {
|
||||
Assert.assertEquals(
|
||||
LocalDate.of(2011, 3, 9),
|
||||
DateTool.lastOccurency(LocalDate.of(2010, 11, 9), LocalDate.of(2011, 5, 9), 4));
|
||||
Assert.assertEquals(
|
||||
LocalDate.of(2011, 7, 9),
|
||||
DateTool.lastOccurency(LocalDate.of(2010, 11, 9), LocalDate.of(2011, 9, 9), 4));
|
||||
Assert.assertEquals(
|
||||
LocalDate.of(2011, 7, 9),
|
||||
DateTool.lastOccurency(LocalDate.of(2010, 11, 9), LocalDate.of(2011, 10, 9), 4));
|
||||
Assert.assertEquals(
|
||||
LocalDate.of(2011, 1, 9),
|
||||
DateTool.lastOccurency(LocalDate.of(2010, 11, 9), LocalDate.of(2011, 1, 9), 2));
|
||||
Assert.assertEquals(
|
||||
LocalDate.of(2011, 7, 31),
|
||||
DateTool.lastOccurency(LocalDate.of(2007, 4, 30), LocalDate.of(2011, 8, 6), 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestStringTool {
|
||||
|
||||
@Test
|
||||
public void testToFirstLower() {
|
||||
|
||||
String actual = "Test";
|
||||
String result = "test";
|
||||
|
||||
Assert.assertEquals(StringTool.toFirstLower(actual), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToFirstUpper() {
|
||||
|
||||
String actual = "test";
|
||||
String result = "Test";
|
||||
|
||||
Assert.assertEquals(StringTool.toFirstUpper(actual), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillString() {
|
||||
|
||||
String actual = "test";
|
||||
String resultRight = "test ";
|
||||
String resultLeft = " test";
|
||||
|
||||
Assert.assertEquals(StringTool.fillStringRight(actual, ' ', 8), resultRight);
|
||||
Assert.assertEquals(StringTool.fillStringRight(actual, ' ', 2), "te");
|
||||
|
||||
Assert.assertEquals(StringTool.fillStringLeft(actual, ' ', 8), resultLeft);
|
||||
Assert.assertEquals(StringTool.fillStringLeft(actual, ' ', 2), "st");
|
||||
|
||||
Assert.assertEquals(StringTool.fillStringLeft(resultRight, ' ', 4), " ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.crypto;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* From: http://java.sun.com/developer/technicalArticles/Security/AES/AES_v1.html This program
|
||||
* generates a AES key, retrieves its raw bytes, and then reinstantiates a AES key from the key
|
||||
* bytes. The reinstantiated key is used to initialize a AES cipher for encryption and decryption.
|
||||
*/
|
||||
public class AESTest {
|
||||
|
||||
/**
|
||||
* Turns array of bytes into string
|
||||
*
|
||||
* @param buf Array of bytes to convert to hex string
|
||||
* @return Generated hex string
|
||||
*/
|
||||
public static String asHex(byte buf[]) {
|
||||
StringBuffer strbuf = new StringBuffer(buf.length * 2);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < buf.length; i++) {
|
||||
if (((int) buf[i] & 0xff) < 0x10) strbuf.append("0");
|
||||
|
||||
strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
|
||||
}
|
||||
|
||||
return strbuf.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
|
||||
// Get the KeyGenerator
|
||||
KeyGenerator kgen = KeyGenerator.getInstance("AES");
|
||||
kgen.init(128); // 192 and 256 bits may not be available
|
||||
|
||||
// Generate the secret key specs.
|
||||
SecretKey skey = kgen.generateKey();
|
||||
byte[] raw = skey.getEncoded();
|
||||
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
|
||||
|
||||
// Instantiate the cipher
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES");
|
||||
|
||||
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
|
||||
|
||||
byte[] encrypted = cipher.doFinal("Hello World".getBytes());
|
||||
|
||||
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
|
||||
byte[] original = cipher.doFinal(encrypted);
|
||||
String originalString = new String(original);
|
||||
Assert.assertEquals("Hello World", originalString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.crypto;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/** From: http://stackoverflow.com/questions/587357/rijndael-support-in-java */
|
||||
public class AESTest2 {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
|
||||
String message = "Hello World";
|
||||
|
||||
byte[] CRYPTO_KEY_EXT = {
|
||||
(byte) 0xEF,
|
||||
(byte) 0xA4,
|
||||
(byte) 0xA8,
|
||||
(byte) 0x04,
|
||||
(byte) 0xB6,
|
||||
(byte) 0x14,
|
||||
(byte) 0x3E,
|
||||
(byte) 0xF7,
|
||||
(byte) 0xCE,
|
||||
(byte) 0xD2,
|
||||
(byte) 0xA2,
|
||||
(byte) 0x78,
|
||||
(byte) 0x10,
|
||||
(byte) 0xB2,
|
||||
(byte) 0x2B,
|
||||
(byte) 0x43
|
||||
};
|
||||
|
||||
byte[] CRYPTO_IV_EXT = {
|
||||
(byte) 0xCC,
|
||||
(byte) 0xBA,
|
||||
(byte) 0xAC,
|
||||
(byte) 0x54,
|
||||
(byte) 0xA2,
|
||||
(byte) 0x35,
|
||||
(byte) 0x56,
|
||||
(byte) 0x9E,
|
||||
(byte) 0xEA,
|
||||
(byte) 0x36,
|
||||
(byte) 0xAB,
|
||||
(byte) 0x31,
|
||||
(byte) 0xBC,
|
||||
(byte) 0xB4,
|
||||
(byte) 0x34,
|
||||
(byte) 0x31
|
||||
};
|
||||
|
||||
byte[] sessionKey = CRYPTO_KEY_EXT; // Where you get this from is beyond
|
||||
// the scope of this post
|
||||
byte[] iv = CRYPTO_IV_EXT; // Ditto
|
||||
|
||||
byte[] plaintext = message.getBytes("UTF8"); // Whatever you want to
|
||||
// encrypt/decrypt
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
// You can use ENCRYPT_MODE or DECRYPT_MODE
|
||||
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(sessionKey, "AES"), new IvParameterSpec(iv));
|
||||
byte[] ciphertext = cipher.doFinal(plaintext);
|
||||
|
||||
Cipher cipher2 = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
// You can use DECRYPT_MODE or DECRYPT_MODE
|
||||
cipher2.init(
|
||||
Cipher.DECRYPT_MODE, new SecretKeySpec(sessionKey, "AES"), new IvParameterSpec(iv));
|
||||
byte[] roundTriptext = cipher2.doFinal(ciphertext);
|
||||
String roundTrip = new String(roundTriptext, "UTF8");
|
||||
|
||||
Assert.assertEquals(message, roundTrip);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.db;
|
||||
|
||||
import com.axelor.db.JPA;
|
||||
import com.axelor.db.JpaModel;
|
||||
import com.axelor.db.Query;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "CONTACT_ADDRESS")
|
||||
public class Address extends JpaModel {
|
||||
|
||||
@NotNull private String street;
|
||||
|
||||
private String area;
|
||||
|
||||
@NotNull private String city;
|
||||
|
||||
@NotNull private String zip;
|
||||
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
private Country country;
|
||||
|
||||
@NotNull
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
private Contact contact;
|
||||
|
||||
public Address() {}
|
||||
|
||||
public Address(String street, String area, String city) {
|
||||
this.street = street;
|
||||
this.area = area;
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public void setArea(String area) {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getZip() {
|
||||
return zip;
|
||||
}
|
||||
|
||||
public void setZip(String zip) {
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
public Country getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(Country country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public Contact getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setContact(Contact contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringHelper tsh = MoreObjects.toStringHelper(getClass());
|
||||
|
||||
tsh.add("id", getId());
|
||||
tsh.add("contact", contact);
|
||||
tsh.add("street", street);
|
||||
tsh.add("area", area);
|
||||
tsh.add("city", city);
|
||||
tsh.add("zip", zip);
|
||||
tsh.add("country", country);
|
||||
|
||||
return tsh.omitNullValues().toString();
|
||||
}
|
||||
|
||||
public static Query<Address> all() {
|
||||
return JPA.all(Address.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.db;
|
||||
|
||||
import com.axelor.db.JPA;
|
||||
import com.axelor.db.JpaModel;
|
||||
import com.axelor.db.Query;
|
||||
import com.axelor.db.annotations.NameColumn;
|
||||
import com.axelor.db.annotations.VirtualColumn;
|
||||
import com.axelor.db.annotations.Widget;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "CONTACT_CONTACT")
|
||||
public class Contact extends JpaModel {
|
||||
|
||||
@ManyToOne(
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
fetch = FetchType.LAZY
|
||||
)
|
||||
private Title title;
|
||||
|
||||
@NotNull private String firstName;
|
||||
|
||||
@NotNull private String lastName;
|
||||
|
||||
@Widget(search = {"firstName", "lastName"})
|
||||
@NameColumn
|
||||
@VirtualColumn
|
||||
@Access(AccessType.PROPERTY)
|
||||
private String fullName;
|
||||
|
||||
@NotNull private String email;
|
||||
|
||||
private String phone;
|
||||
|
||||
private LocalDate dateOfBirth;
|
||||
|
||||
@OneToMany(
|
||||
mappedBy = "contact",
|
||||
cascade = CascadeType.ALL,
|
||||
fetch = FetchType.LAZY,
|
||||
orphanRemoval = true
|
||||
)
|
||||
private List<Address> addresses;
|
||||
|
||||
@ManyToMany(
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
fetch = FetchType.LAZY
|
||||
)
|
||||
private Set<Group> groups;
|
||||
|
||||
@Widget(title = "Photo", help = "Max size 4MB.")
|
||||
@Lob
|
||||
@Basic(fetch = FetchType.LAZY)
|
||||
private byte[] image;
|
||||
|
||||
@Widget(multiline = true)
|
||||
private String notes;
|
||||
|
||||
private BigDecimal payeurQuality;
|
||||
|
||||
@Widget(selection = "select.language")
|
||||
private String language;
|
||||
|
||||
public Contact() {}
|
||||
|
||||
public Contact(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public Contact(String firstName, String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Title getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(Title title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return fullName = calculateFullName();
|
||||
}
|
||||
|
||||
protected String calculateFullName() {
|
||||
fullName = firstName + " " + lastName;
|
||||
if (this.title != null) {
|
||||
return this.title.getName() + " " + fullName;
|
||||
}
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public void setFullName(String fullName) {
|
||||
this.fullName = fullName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public LocalDate getDateOfBirth() {
|
||||
return dateOfBirth;
|
||||
}
|
||||
|
||||
public void setDateOfBirth(LocalDate dateOfBirth) {
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
}
|
||||
|
||||
public List<Address> getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public void setAddresses(List<Address> addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
public Group getGroup(int index) {
|
||||
if (groups == null) return null;
|
||||
return Lists.newArrayList(groups).get(index);
|
||||
}
|
||||
|
||||
public Set<Group> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void setGroups(Set<Group> groups) {
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
public byte[] getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(byte[] image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public BigDecimal getPayeurQuality() {
|
||||
return payeurQuality;
|
||||
}
|
||||
|
||||
public void setPayeurQuality(BigDecimal payeurQuality) {
|
||||
this.payeurQuality = payeurQuality;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public String getLanguageTitle() {
|
||||
// MetaSelectItem item = MetaSelectItem
|
||||
// .filter("self.select.name = ?1 AND self.value = ?2",
|
||||
// "select.language", this.language).fetchOne();
|
||||
//
|
||||
// if (item != null) {
|
||||
// return item.getTitle();
|
||||
// }
|
||||
|
||||
return "french";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringHelper tsh = MoreObjects.toStringHelper(getClass());
|
||||
|
||||
tsh.add("id", getId());
|
||||
tsh.add("fullName", getFirstName());
|
||||
tsh.add("email", getEmail());
|
||||
|
||||
return tsh.omitNullValues().toString();
|
||||
}
|
||||
|
||||
public Contact find(Long id) {
|
||||
return JPA.find(Contact.class, id);
|
||||
}
|
||||
|
||||
public static Contact edit(Map<String, Object> values) {
|
||||
return JPA.edit(Contact.class, values);
|
||||
}
|
||||
|
||||
public static Query<Contact> all() {
|
||||
return JPA.all(Contact.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.db;
|
||||
|
||||
import com.axelor.db.JPA;
|
||||
import com.axelor.db.Model;
|
||||
import com.axelor.db.Query;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "CONTACT_COUNTRY")
|
||||
public class Country extends Model {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CONTACT_COUNTRY_SEQ")
|
||||
@SequenceGenerator(
|
||||
name = "CONTACT_COUNTRY_SEQ",
|
||||
sequenceName = "CONTACT_COUNTRY_SEQ",
|
||||
allocationSize = 1
|
||||
)
|
||||
private Long id;
|
||||
|
||||
@NotNull private String code;
|
||||
|
||||
@NotNull private String name;
|
||||
|
||||
public Country() {}
|
||||
|
||||
public Country(String name, String code) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringHelper tsh = MoreObjects.toStringHelper(getClass());
|
||||
|
||||
tsh.add("id", getId());
|
||||
tsh.add("code", code);
|
||||
tsh.add("name", name);
|
||||
|
||||
return tsh.omitNullValues().toString();
|
||||
}
|
||||
|
||||
public static Query<Country> all() {
|
||||
return JPA.all(Country.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.db;
|
||||
|
||||
import com.axelor.db.JPA;
|
||||
import com.axelor.db.Model;
|
||||
import com.axelor.db.Query;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "CONTACT_GROUP")
|
||||
public class Group extends Model {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CONTACT_GROUP_SEQ")
|
||||
@SequenceGenerator(
|
||||
name = "CONTACT_GROUP_SEQ",
|
||||
sequenceName = "CONTACT_GROUP_SEQ",
|
||||
allocationSize = 1
|
||||
)
|
||||
private Long id;
|
||||
|
||||
@NotNull private String name;
|
||||
|
||||
@NotNull private String title;
|
||||
|
||||
public Group() {}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Group(String name, String title) {
|
||||
this.name = name;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringHelper tsh = MoreObjects.toStringHelper(getClass());
|
||||
|
||||
tsh.add("id", getId());
|
||||
tsh.add("name", getName());
|
||||
tsh.add("title", getTitle());
|
||||
|
||||
return tsh.omitNullValues().toString();
|
||||
}
|
||||
|
||||
public static Query<Group> all() {
|
||||
return JPA.all(Group.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.db;
|
||||
|
||||
import com.axelor.db.JPA;
|
||||
import com.axelor.db.JpaModel;
|
||||
import com.axelor.db.Query;
|
||||
import java.time.LocalDate;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TEST_INVOICE")
|
||||
public class Invoice extends JpaModel {
|
||||
|
||||
@ManyToOne(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE}
|
||||
)
|
||||
private Move move;
|
||||
|
||||
@ManyToOne(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE}
|
||||
)
|
||||
private Move oldMove;
|
||||
|
||||
@ManyToOne(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE}
|
||||
)
|
||||
private MoveLine rejectMoveLine;
|
||||
|
||||
private LocalDate date;
|
||||
|
||||
private LocalDate dueDate;
|
||||
|
||||
public Move getMove() {
|
||||
return move;
|
||||
}
|
||||
|
||||
public void setMove(Move move) {
|
||||
this.move = move;
|
||||
}
|
||||
|
||||
public Move getOldMove() {
|
||||
return oldMove;
|
||||
}
|
||||
|
||||
public void setOldMove(Move oldMove) {
|
||||
this.oldMove = oldMove;
|
||||
}
|
||||
|
||||
public MoveLine getRejectMoveLine() {
|
||||
return rejectMoveLine;
|
||||
}
|
||||
|
||||
public void setRejectMoveLine(MoveLine rejectMoveLine) {
|
||||
this.rejectMoveLine = rejectMoveLine;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public LocalDate getDueDate() {
|
||||
return dueDate;
|
||||
}
|
||||
|
||||
public void setDueDate(LocalDate dueDate) {
|
||||
this.dueDate = dueDate;
|
||||
}
|
||||
|
||||
public Invoice persist() {
|
||||
return JPA.persist(this);
|
||||
}
|
||||
|
||||
public Invoice merge() {
|
||||
return JPA.merge(this);
|
||||
}
|
||||
|
||||
public Invoice save() {
|
||||
return JPA.save(this);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
JPA.remove(this);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
JPA.refresh(this);
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
JPA.flush();
|
||||
}
|
||||
|
||||
public static Invoice find(Long id) {
|
||||
return JPA.find(Invoice.class, id);
|
||||
}
|
||||
|
||||
public static Query<Invoice> all() {
|
||||
return JPA.all(Invoice.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.db;
|
||||
|
||||
import com.axelor.db.JPA;
|
||||
import com.axelor.db.JpaModel;
|
||||
import com.axelor.db.Query;
|
||||
import java.util.List;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TEST_MOVE")
|
||||
public class Move extends JpaModel {
|
||||
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
mappedBy = "move",
|
||||
cascade = CascadeType.ALL,
|
||||
orphanRemoval = true
|
||||
)
|
||||
private List<MoveLine> moveLines;
|
||||
|
||||
@ManyToOne(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE}
|
||||
)
|
||||
private Invoice invoice;
|
||||
|
||||
public List<MoveLine> getMoveLines() {
|
||||
return moveLines;
|
||||
}
|
||||
|
||||
public void setMoveLines(List<MoveLine> moveLines) {
|
||||
this.moveLines = moveLines;
|
||||
}
|
||||
|
||||
public Invoice getInvoice() {
|
||||
return invoice;
|
||||
}
|
||||
|
||||
public void setInvoice(Invoice invoice) {
|
||||
this.invoice = invoice;
|
||||
}
|
||||
|
||||
public Move persist() {
|
||||
return JPA.persist(this);
|
||||
}
|
||||
|
||||
public Move merge() {
|
||||
return JPA.merge(this);
|
||||
}
|
||||
|
||||
public Move save() {
|
||||
return JPA.save(this);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
JPA.remove(this);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
JPA.refresh(this);
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
JPA.flush();
|
||||
}
|
||||
|
||||
public static Move find(Long id) {
|
||||
return JPA.find(Move.class, id);
|
||||
}
|
||||
|
||||
public static Query<Move> all() {
|
||||
return JPA.all(Move.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.db;
|
||||
|
||||
import com.axelor.db.JPA;
|
||||
import com.axelor.db.JpaModel;
|
||||
import com.axelor.db.Query;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TEST_MOVE_LINE")
|
||||
public class MoveLine extends JpaModel {
|
||||
|
||||
@ManyToOne(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE}
|
||||
)
|
||||
private Move move;
|
||||
|
||||
@ManyToOne(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE}
|
||||
)
|
||||
private Invoice invoiceReject;
|
||||
|
||||
private LocalDate date;
|
||||
|
||||
private LocalDate dueDate;
|
||||
|
||||
private BigDecimal credit;
|
||||
|
||||
private BigDecimal debit;
|
||||
|
||||
public Move getMove() {
|
||||
return move;
|
||||
}
|
||||
|
||||
public void setMove(Move move) {
|
||||
this.move = move;
|
||||
}
|
||||
|
||||
public Invoice getInvoiceReject() {
|
||||
return invoiceReject;
|
||||
}
|
||||
|
||||
public void setInvoiceReject(Invoice invoiceReject) {
|
||||
this.invoiceReject = invoiceReject;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public LocalDate getDueDate() {
|
||||
return dueDate;
|
||||
}
|
||||
|
||||
public void setDueDate(LocalDate dueDate) {
|
||||
this.dueDate = dueDate;
|
||||
}
|
||||
|
||||
public BigDecimal getCredit() {
|
||||
if (credit == null) return BigDecimal.ZERO;
|
||||
return credit;
|
||||
}
|
||||
|
||||
public void setCredit(BigDecimal credit) {
|
||||
this.credit = credit;
|
||||
}
|
||||
|
||||
public BigDecimal getDebit() {
|
||||
if (debit == null) return BigDecimal.ZERO;
|
||||
return debit;
|
||||
}
|
||||
|
||||
public void setDebit(BigDecimal debit) {
|
||||
this.debit = debit;
|
||||
}
|
||||
|
||||
public MoveLine persist() {
|
||||
return JPA.persist(this);
|
||||
}
|
||||
|
||||
public MoveLine merge() {
|
||||
return JPA.merge(this);
|
||||
}
|
||||
|
||||
public MoveLine save() {
|
||||
return JPA.save(this);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
JPA.remove(this);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
JPA.refresh(this);
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
JPA.flush();
|
||||
}
|
||||
|
||||
public static MoveLine find(Long id) {
|
||||
return JPA.find(MoveLine.class, id);
|
||||
}
|
||||
|
||||
public static Query<MoveLine> all() {
|
||||
return JPA.all(MoveLine.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.db;
|
||||
|
||||
import com.axelor.db.JPA;
|
||||
import com.axelor.db.Model;
|
||||
import com.axelor.db.Query;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.MoreObjects.ToStringHelper;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "CONTACT_TITLE")
|
||||
public class Title extends Model {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CONTACT_TITLE_SEQ")
|
||||
@SequenceGenerator(
|
||||
name = "CONTACT_TITLE_SEQ",
|
||||
sequenceName = "CONTACT_TITLE_SEQ",
|
||||
allocationSize = 1
|
||||
)
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Column(unique = true)
|
||||
private String code;
|
||||
|
||||
@NotNull
|
||||
@Column(unique = true)
|
||||
private String name;
|
||||
|
||||
public Title(String name, String code) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringHelper tsh = MoreObjects.toStringHelper(getClass());
|
||||
|
||||
tsh.add("id", getId());
|
||||
tsh.add("code", getCode());
|
||||
tsh.add("name", getName());
|
||||
|
||||
return tsh.omitNullValues().toString();
|
||||
}
|
||||
|
||||
public static Query<Title> all() {
|
||||
return JPA.all(Title.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestFileTool {
|
||||
|
||||
@Test
|
||||
public void create() throws IOException {
|
||||
|
||||
String destinationFolder =
|
||||
System.getProperty("java.io.tmpdir")
|
||||
+ File.separator
|
||||
+ "tata"
|
||||
+ File.separator
|
||||
+ "titi"
|
||||
+ File.separator
|
||||
+ "toto";
|
||||
String fileName = "toto.txt";
|
||||
|
||||
File file = FileTool.create(destinationFolder, fileName);
|
||||
file.deleteOnExit();
|
||||
|
||||
Assert.assertTrue(file.createNewFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create2() throws IOException {
|
||||
|
||||
String fileName =
|
||||
System.getProperty("java.io.tmpdir")
|
||||
+ File.separator
|
||||
+ "tata2"
|
||||
+ File.separator
|
||||
+ "titi2"
|
||||
+ File.separator
|
||||
+ "toto2"
|
||||
+ File.separator
|
||||
+ "toto.txt";
|
||||
File file = FileTool.create(fileName);
|
||||
file.deleteOnExit();
|
||||
|
||||
Assert.assertTrue(file.createNewFile());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.net;
|
||||
|
||||
import com.axelor.apps.tool.exception.IExceptionMessage;
|
||||
import com.axelor.i18n.I18n;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestURLService {
|
||||
|
||||
@Test
|
||||
public void testNotExist() {
|
||||
|
||||
String url = "http://www.google.com";
|
||||
Assert.assertNull(URLService.notExist(url));
|
||||
|
||||
url = "www.google.com";
|
||||
Assert.assertEquals(
|
||||
String.format(I18n.get(IExceptionMessage.URL_SERVICE_2), url), URLService.notExist(url));
|
||||
|
||||
url = "http://testnotfound.axelor.com/";
|
||||
Assert.assertEquals(
|
||||
String.format(I18n.get(IExceptionMessage.URL_SERVICE_3), url), URLService.notExist(url));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.templating;
|
||||
|
||||
import com.axelor.db.Model;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.stringtemplate.v4.AttributeRenderer;
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
|
||||
public class STSampleTest {
|
||||
|
||||
public String template = "Hi $contact.name;format=\"upper\"$ $contact.lastName$";
|
||||
|
||||
private static List<Contact> data = Lists.newArrayList();
|
||||
|
||||
private static final int MAX_ITER = 5000;
|
||||
|
||||
private static final char CHAR = '$';
|
||||
|
||||
private STGroup stGroup;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
for (int i = 0; i < MAX_ITER; i++) {
|
||||
data.add(new Contact("Name" + i, "LastName" + i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
stGroup = new STGroup(CHAR, CHAR);
|
||||
stGroup.registerRenderer(String.class, new BasicFormatRenderer());
|
||||
|
||||
for (Contact contact : data) {
|
||||
String result = run(contact);
|
||||
|
||||
String expected = "Hi " + contact.getName().toUpperCase() + " " + contact.getLastName();
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
}
|
||||
|
||||
public String run(Contact o) {
|
||||
ST st = new ST(stGroup, template);
|
||||
st.add("contact", o);
|
||||
|
||||
return st.render();
|
||||
}
|
||||
|
||||
class BasicFormatRenderer implements AttributeRenderer {
|
||||
|
||||
public String toString(Object o) {
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
public String toString(Object o, String formatName) {
|
||||
|
||||
if (Strings.isNullOrEmpty(formatName)) {
|
||||
return toString(o);
|
||||
}
|
||||
|
||||
if (formatName.equals("upper")) {
|
||||
return o.toString().toUpperCase();
|
||||
} else if (formatName.equals("toLower")) {
|
||||
return o.toString().toLowerCase();
|
||||
}
|
||||
return toString(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object o, String formatString, Locale locale) {
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
return toString(o, formatString);
|
||||
}
|
||||
}
|
||||
|
||||
class Contact extends Model {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String lastName;
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Contact(String name, String lastName) {
|
||||
this.name = name;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.tool.templating;
|
||||
|
||||
import com.axelor.apps.tool.db.Contact;
|
||||
import com.axelor.apps.tool.db.Title;
|
||||
import com.axelor.tool.template.TemplateMaker;
|
||||
import com.google.common.collect.Maps;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class STTest {
|
||||
|
||||
public Contact contact;
|
||||
public String contentFinal;
|
||||
public Map<String, Object> map = Maps.newHashMap();
|
||||
public String content =
|
||||
""
|
||||
+ "<h1>About Me ($contact.lastName;format=\"upper\"$)</h1>"
|
||||
+ "<hr />"
|
||||
+ "<p><strong>PayeurQuality:</strong> $contact.payeurQuality;format=\"%,2.3f\"$</p>"
|
||||
+ "<p><strong>Title: $contact.title$</p>"
|
||||
+ "<p><strong>First Name:</strong> $contact.firstName$</p>"
|
||||
+ "<p><strong>Last Name:</strong> $contact.lastName;format=\"upper\"$</p>"
|
||||
+ "<p><strong>DateOfBirth:</strong> $contact.dateOfBirth;format=\"dd/MM/YYYY\"$</p>"
|
||||
+ "<p> </p>"
|
||||
+ "<p><em>Contact me:</em> <a href='mailto:$contact.email$' target='_blank'>$contact.fullName$</a></p>"
|
||||
+ "<hr />$__time__;format=\"HH\"$"
|
||||
+ "<ul>$__date__$"
|
||||
+ "<li>Java</li>"
|
||||
+ "<li>JavaScript</li>"
|
||||
+ "<li>Groovy</li>"
|
||||
+ "<li>HTML5</li>"
|
||||
+ "</ul>"
|
||||
+ "<pre>public class Hello {<br /><br />"
|
||||
+ "private String testKey1 = $testKey1$<br />"
|
||||
+ "private String testKey2 = $testKey2$<br />"
|
||||
+ "private String testKey3 = $testKey3$<br />"
|
||||
+ "}</pre>";
|
||||
|
||||
@Before
|
||||
public void prepareTest() {
|
||||
contact = new Contact("Doe", "John");
|
||||
contact.setEmail("john.doe@axelor.com");
|
||||
contact.setFullName(contact.getFullName());
|
||||
contact.setDateOfBirth(LocalDate.now());
|
||||
contact.setPayeurQuality(new BigDecimal("2.2569"));
|
||||
contact.setLanguage("fr");
|
||||
|
||||
Title title = new Title("TitleName", "TitleCode");
|
||||
contact.setTitle(title);
|
||||
|
||||
map.put("testKey1", "This is the key 1");
|
||||
map.put("testKey2", "This is the key 2");
|
||||
map.put("testKey3", "This is the key 3");
|
||||
|
||||
contentFinal =
|
||||
""
|
||||
+ "<h1>About Me (JOHN)</h1>"
|
||||
+ "<hr />"
|
||||
+ "<p><strong>PayeurQuality:</strong> 2,257</p>"
|
||||
+ "<p><strong>Title: "
|
||||
+ title.toString()
|
||||
+ "</p>"
|
||||
+ "<p><strong>First Name:</strong> "
|
||||
+ contact.getFirstName()
|
||||
+ "</p>"
|
||||
+ "<p><strong>Last Name:</strong> "
|
||||
+ contact.getLastName().toUpperCase()
|
||||
+ "</p>"
|
||||
+ "<p><strong>DateOfBirth:</strong> "
|
||||
+ contact.getDateOfBirth().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))
|
||||
+ "</p>"
|
||||
+ "<p> </p>"
|
||||
+ "<p><em>Contact me:</em> <a href='mailto:"
|
||||
+ contact.getEmail()
|
||||
+ "' target='_blank'>"
|
||||
+ contact.getFullName()
|
||||
+ "</a></p>"
|
||||
+ "<hr />"
|
||||
+ java.time.LocalTime.now().format(DateTimeFormatter.ofPattern("HH"))
|
||||
+ "<ul>"
|
||||
+ LocalDate.now()
|
||||
+ "<li>Java</li>"
|
||||
+ "<li>JavaScript</li>"
|
||||
+ "<li>Groovy</li>"
|
||||
+ "<li>HTML5</li>"
|
||||
+ "</ul>"
|
||||
+ "<pre>public class Hello {<br /><br />"
|
||||
+ "private String testKey1 = "
|
||||
+ map.get("testKey1")
|
||||
+ "<br />"
|
||||
+ "private String testKey2 = "
|
||||
+ map.get("testKey2")
|
||||
+ "<br />"
|
||||
+ "private String testKey3 = "
|
||||
+ map.get("testKey3")
|
||||
+ "<br />"
|
||||
+ "}</pre>";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1() {
|
||||
TemplateMaker maker = new TemplateMaker(new Locale("fr"), '$', '$');
|
||||
|
||||
maker.setTemplate(content);
|
||||
maker.setContext(contact, map, "contact");
|
||||
String result = maker.make();
|
||||
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(contentFinal, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
TemplateMaker maker = new TemplateMaker(new Locale("fr"), '$', '$');
|
||||
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
maker.setTemplate(content);
|
||||
maker.setContext(contact, map, "contact");
|
||||
String result = maker.make();
|
||||
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(contentFinal, result);
|
||||
}
|
||||
|
||||
// Assert test total time < 15s
|
||||
Assert.assertTrue(((System.currentTimeMillis() - start) / 1000) < 15);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ThreadTest thread = new ThreadTest();
|
||||
thread.run();
|
||||
}
|
||||
}
|
||||
|
||||
class ThreadTest extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
TemplateMaker maker = new TemplateMaker(new Locale("fr"), '$', '$');
|
||||
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
maker.setTemplate(content);
|
||||
maker.setContext(contact, map, "contact");
|
||||
String result = maker.make();
|
||||
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(contentFinal, result);
|
||||
}
|
||||
|
||||
// Assert test total time < 15s
|
||||
Assert.assertTrue(((System.currentTimeMillis() - start) / 1000) < 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user