From 3f411eadd268d935b8de1f628e75cddfc363b44e Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sun, 11 May 2014 21:18:46 +0200 Subject: [PATCH] =?UTF-8?q?Agenda=20Dodavatel=C3=A9=20-=20adres=C3=A1?= =?UTF-8?q?=C5=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 18 ++ .../info/bukova/isspst/dao/AddressDao.java | 7 + .../bukova/isspst/dao/jpa/AddressDaoJPA.java | 13 ++ .../java/info/bukova/isspst/data/Address.java | 135 +++++++++++++ .../bukova/isspst/filters/AddressFilter.java | 60 ++++++ .../isspst/services/IsspstException.java | 25 +++ .../services/addressbook/AdbService.java | 17 ++ .../services/addressbook/AdbServiceImpl.java | 70 +++++++ .../services/addressbook/AddressFinder.java | 11 ++ .../addressbook/AddressFinderAres.java | 178 ++++++++++++++++++ .../addressbook/AddressFinderTaxID.java | 137 ++++++++++++++ .../services/addressbook/AresOdpoved.java | 30 +++ .../services/addressbook/AresZaznam.java | 56 ++++++ .../isspst/services/addressbook/ares.xsl | 28 +++ .../services/addressbook/mappingAres.xml | 42 +++++ src/main/java/info/bukova/isspst/ui/Mapa.java | 37 ++++ .../ui/addressbook/AddressFindResult.java | 38 ++++ .../isspst/ui/addressbook/AddressForm.java | 77 ++++++++ .../isspst/ui/addressbook/AddressList.java | 25 +++ .../java/web/js/info/bukova/isspst/ui/Mapa.js | 43 +++++ .../java/web/js/info/bukova/isspst/ui/zk.wpd | 4 + src/main/resources/hibernate.cfg.xml | 2 + .../webapp/WEB-INF/ckez-bind-lang-addon.xml | 35 ++++ src/main/webapp/WEB-INF/mapa-lang-addon.xml | 11 ++ .../webapp/WEB-INF/spring/root-context.xml | 32 ++++ src/main/webapp/WEB-INF/zk.xml | 30 +++ .../admin/addressbook/addrFindResult.zul | 30 +++ src/main/webapp/admin/addressbook/address.zul | 78 ++++++++ .../webapp/admin/addressbook/addressbook.zul | 89 +++++++++ src/main/webapp/admin/addressbook/index.zul | 11 ++ src/main/webapp/app/form.css | 4 + src/main/webapp/app/formButtons.zul | 4 + src/main/webapp/app/navigation.zul | 1 + src/main/webapp/app/template.zhtml | 39 ++++ src/main/webapp/img/search.png | Bin 0 -> 778 bytes 35 files changed, 1417 insertions(+) create mode 100644 src/main/java/info/bukova/isspst/dao/AddressDao.java create mode 100644 src/main/java/info/bukova/isspst/dao/jpa/AddressDaoJPA.java create mode 100644 src/main/java/info/bukova/isspst/data/Address.java create mode 100644 src/main/java/info/bukova/isspst/filters/AddressFilter.java create mode 100644 src/main/java/info/bukova/isspst/services/IsspstException.java create mode 100644 src/main/java/info/bukova/isspst/services/addressbook/AdbService.java create mode 100644 src/main/java/info/bukova/isspst/services/addressbook/AdbServiceImpl.java create mode 100644 src/main/java/info/bukova/isspst/services/addressbook/AddressFinder.java create mode 100644 src/main/java/info/bukova/isspst/services/addressbook/AddressFinderAres.java create mode 100644 src/main/java/info/bukova/isspst/services/addressbook/AddressFinderTaxID.java create mode 100644 src/main/java/info/bukova/isspst/services/addressbook/AresOdpoved.java create mode 100644 src/main/java/info/bukova/isspst/services/addressbook/AresZaznam.java create mode 100644 src/main/java/info/bukova/isspst/services/addressbook/ares.xsl create mode 100644 src/main/java/info/bukova/isspst/services/addressbook/mappingAres.xml create mode 100644 src/main/java/info/bukova/isspst/ui/Mapa.java create mode 100644 src/main/java/info/bukova/isspst/ui/addressbook/AddressFindResult.java create mode 100644 src/main/java/info/bukova/isspst/ui/addressbook/AddressForm.java create mode 100644 src/main/java/info/bukova/isspst/ui/addressbook/AddressList.java create mode 100644 src/main/java/web/js/info/bukova/isspst/ui/Mapa.js create mode 100644 src/main/java/web/js/info/bukova/isspst/ui/zk.wpd create mode 100644 src/main/webapp/WEB-INF/ckez-bind-lang-addon.xml create mode 100644 src/main/webapp/WEB-INF/mapa-lang-addon.xml create mode 100644 src/main/webapp/WEB-INF/zk.xml create mode 100644 src/main/webapp/admin/addressbook/addrFindResult.zul create mode 100644 src/main/webapp/admin/addressbook/address.zul create mode 100644 src/main/webapp/admin/addressbook/addressbook.zul create mode 100644 src/main/webapp/admin/addressbook/index.zul create mode 100644 src/main/webapp/app/formButtons.zul create mode 100644 src/main/webapp/img/search.png diff --git a/pom.xml b/pom.xml index 2bb7e3ab..e5e408c5 100644 --- a/pom.xml +++ b/pom.xml @@ -238,6 +238,24 @@ lambdaj 2.2 + + + commons-collections + commons-collections + 3.2.1 + + + + commons-httpclient + commons-httpclient + 3.1 + + + + org.codehaus.castor + spring-xml + 1.2.1 + diff --git a/src/main/java/info/bukova/isspst/dao/AddressDao.java b/src/main/java/info/bukova/isspst/dao/AddressDao.java new file mode 100644 index 00000000..04ae626a --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/AddressDao.java @@ -0,0 +1,7 @@ +package info.bukova.isspst.dao; + +import info.bukova.isspst.data.Address; + +public interface AddressDao extends BaseDao
{ + +} diff --git a/src/main/java/info/bukova/isspst/dao/jpa/AddressDaoJPA.java b/src/main/java/info/bukova/isspst/dao/jpa/AddressDaoJPA.java new file mode 100644 index 00000000..92f605b5 --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/jpa/AddressDaoJPA.java @@ -0,0 +1,13 @@ +package info.bukova.isspst.dao.jpa; + +import info.bukova.isspst.dao.AddressDao; +import info.bukova.isspst.data.Address; + +public class AddressDaoJPA extends BaseDaoJPA
implements AddressDao { + + @Override + public String getEntityName() { + return Address.class.getSimpleName(); + } + +} diff --git a/src/main/java/info/bukova/isspst/data/Address.java b/src/main/java/info/bukova/isspst/data/Address.java new file mode 100644 index 00000000..d263970f --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/Address.java @@ -0,0 +1,135 @@ +package info.bukova.isspst.data; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; + +import org.hibernate.validator.constraints.Email; +import org.hibernate.validator.constraints.NotEmpty; +import org.hibernate.validator.constraints.URL; + +@Entity +@Table(name="ADDRESS") +public class Address extends BaseData { + + @Column(name="COMPANY") + private String company; + @Column(name="DEPARTMENT") + private String department; + @Column(name="CONTACT_NAME") + private String contactName; + @Column(name="STREET") + private String street; + @Column(name="HOUSE_NUMBER") + private String houseNumber; + @Column(name="ZIP_CODE") + private String zipCode; + @Column(name="CITY") + private String city; + @Column(name="STATE") + private String state; + @Column(name="IC") + private long ic; + @Column(name="DIC") + private String dic; + @Column(name="PHONE") + private String phone; + @Column(name="EMAIL") + private String email; + @Column(name="WEB") + private String web; + @Column(name="DESCRIPTION") + private String description; + + @NotNull(message = "Zadejte firmu") + @NotEmpty(message = "Zadejte firmu") + public String getCompany() { + return company; + } + public void setCompany(String company) { + this.company = company; + } + public String getDepartment() { + return department; + } + public void setDepartment(String department) { + this.department = department; + } + public String getContactName() { + return contactName; + } + public void setContactName(String contactName) { + this.contactName = contactName; + } + public String getStreet() { + return street; + } + public void setStreet(String street) { + this.street = street; + } + public String getHouseNumber() { + return houseNumber; + } + public void setHouseNumber(String houseNumber) { + this.houseNumber = houseNumber; + } + public String getZipCode() { + return zipCode; + } + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } + @NotNull(message = "Zadejte město") + @NotEmpty(message = "Zadejte město") + public String getCity() { + return city; + } + public void setCity(String city) { + this.city = city; + } + public String getState() { + return state; + } + public void setState(String state) { + this.state = state; + } + public long getIc() { + return ic; + } + public void setIc(long ic) { + this.ic = ic; + } + public String getDic() { + return dic; + } + public void setDic(String dic) { + this.dic = dic; + } + public String getPhone() { + return phone; + } + public void setPhone(String phone) { + this.phone = phone; + } + @Email(message = "Špatný formát adresy") + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + @URL(message = "Špatný formát adresy") + public String getWeb() { + return web; + } + public void setWeb(String web) { + this.web = web; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } +} diff --git a/src/main/java/info/bukova/isspst/filters/AddressFilter.java b/src/main/java/info/bukova/isspst/filters/AddressFilter.java new file mode 100644 index 00000000..468b59ea --- /dev/null +++ b/src/main/java/info/bukova/isspst/filters/AddressFilter.java @@ -0,0 +1,60 @@ +package info.bukova.isspst.filters; + +import static info.bukova.isspst.StringUtils.not0ToStr; +import static info.bukova.isspst.StringUtils.nullStr; +import info.bukova.isspst.data.Address; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class AddressFilter implements Filter
{ + + private Address condAddr; + + public AddressFilter(Address condAddr) { + this.condAddr = condAddr; + } + + private static class AddrMatcher extends TypeSafeMatcher
{ + + private Address condAddress; + + public AddrMatcher(Address cond) { + this.condAddress = cond; + } + + @Override + public void describeTo(Description desc) { + desc.appendText("address matches"); + } + + @Override + public boolean matchesSafely(Address item) { + return nullStr(item.getCompany()).toLowerCase().contains(nullStr(condAddress.getCompany()).toLowerCase()) + && nullStr(item.getCity()).toLowerCase().contains(nullStr(condAddress.getCity()).toLowerCase()) + && nullStr(item.getContactName()).toLowerCase().contains(nullStr(condAddress.getContactName()).toLowerCase()) + && nullStr(item.getStreet()).toLowerCase().contains(nullStr(condAddress.getStreet()).toLowerCase()) + && not0ToStr(item.getIc()).startsWith(not0ToStr(condAddress.getIc())) + && nullStr(item.getHouseNumber()).startsWith(nullStr(condAddress.getHouseNumber())); + } + + @Factory + public static Matcher
matchAddr(Address addr) { + return new AddrMatcher(addr); + } + } + + @Override + public AddrMatcher matcher() { + return new AddrMatcher(condAddr); + } + + @Override + public String queryString() { + // TODO query string + return ""; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/IsspstException.java b/src/main/java/info/bukova/isspst/services/IsspstException.java new file mode 100644 index 00000000..b0a89439 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/IsspstException.java @@ -0,0 +1,25 @@ +package info.bukova.isspst.services; + +public class IsspstException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + private final static String MSG = "RsFaktura Exception. "; + + public IsspstException() { + super(MSG); + } + + public IsspstException(String message) { + super(MSG + message); + } + + public IsspstException(Throwable cause) { + super(cause); + } + + public IsspstException(String message, Throwable cause) { + super(MSG + message, cause); + } + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/AdbService.java b/src/main/java/info/bukova/isspst/services/addressbook/AdbService.java new file mode 100644 index 00000000..e14c0165 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/addressbook/AdbService.java @@ -0,0 +1,17 @@ +package info.bukova.isspst.services.addressbook; + +import info.bukova.isspst.data.Address; +import info.bukova.isspst.services.Service; + +import java.util.List; + +public interface AdbService extends Service
{ + + public List
lookForAddr(AddressFinder finder, Address condAdr); + public void fillFoundData(AddressFinder finder, Address address); + public void mergeAddress(Address destination, Address source, boolean overwrite); + public List
queryToArrayList(String filter); + + public int count(); + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/AdbServiceImpl.java b/src/main/java/info/bukova/isspst/services/addressbook/AdbServiceImpl.java new file mode 100644 index 00000000..3abb9d95 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/addressbook/AdbServiceImpl.java @@ -0,0 +1,70 @@ +package info.bukova.isspst.services.addressbook; + +import info.bukova.isspst.data.Address; +import info.bukova.isspst.services.AbstractOwnedService; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.transaction.annotation.Transactional; + +public class AdbServiceImpl extends AbstractOwnedService
implements AdbService { + + @Override + public List
lookForAddr(AddressFinder finder, Address condAddr) { + return finder.findAddress(condAddr); + } + + @Override + public void mergeAddress(Address destination, Address source, boolean overwrite) { + if (destination.getIc() == 0) + destination.setIc(source.getIc()); + if (destination.getCompany() == null || destination.getCompany().isEmpty() || overwrite) + destination.setCompany(source.getCompany()); + if (destination.getDic() == null || destination.getDic().isEmpty() || overwrite) + destination.setDic(source.getDic()); + if (destination.getDepartment() == null || destination.getDepartment().isEmpty() || overwrite) + destination.setDepartment(source.getDepartment()); + if (destination.getContactName() == null || destination.getContactName().isEmpty() || overwrite) + destination.setContactName(source.getContactName()); + if (destination.getStreet() == null || destination.getStreet().isEmpty() || overwrite) + destination.setStreet(source.getStreet()); + if (destination.getHouseNumber() == null || destination.getHouseNumber().isEmpty() || overwrite) + destination.setHouseNumber(source.getHouseNumber()); + if (destination.getCity() == null || destination.getCity().isEmpty() || overwrite) + destination.setCity(source.getCity()); + if (destination.getZipCode() == null || destination.getZipCode().isEmpty() || overwrite) + destination.setZipCode(source.getZipCode()); + if (destination.getPhone() == null || destination.getPhone().isEmpty() || overwrite) + destination.setPhone(source.getPhone()); + if (destination.getEmail() == null || destination.getEmail().isEmpty() || overwrite) + destination.setEmail(source.getEmail()); + } + + @Override + public void fillFoundData(AddressFinder finder, Address address) { + List
found = finder.findAddress(address); + + if (found.size() > 0) { + this.mergeAddress(address, found.get(0), false); + } + } + + + @Override + public List
queryToArrayList(String filter) { + return new ArrayList
(execQuery(filter)); + } + + @Override + @Transactional + public int count() { +// Query q = queryDefaultFilter(); +// q.setResult("count(id)"); +// Object result = q.execute(); +// +// return ((Long)result).intValue(); + return 0; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/AddressFinder.java b/src/main/java/info/bukova/isspst/services/addressbook/AddressFinder.java new file mode 100644 index 00000000..119d7911 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/addressbook/AddressFinder.java @@ -0,0 +1,11 @@ +package info.bukova.isspst.services.addressbook; + +import info.bukova.isspst.data.Address; + +import java.util.List; + +public interface AddressFinder { + + public List
findAddress(Address condAddress); + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/AddressFinderAres.java b/src/main/java/info/bukova/isspst/services/addressbook/AddressFinderAres.java new file mode 100644 index 00000000..cda7bd6f --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/addressbook/AddressFinderAres.java @@ -0,0 +1,178 @@ +package info.bukova.isspst.services.addressbook; + +import info.bukova.isspst.data.Address; +import info.bukova.isspst.services.IsspstException; + +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.httpclient.methods.GetMethod; +import org.exolab.castor.xml.MarshalException; +import org.exolab.castor.xml.Unmarshaller; +import org.exolab.castor.xml.ValidationException; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; + +public class AddressFinderAres implements AddressFinder { + + private Map conditions; + private String aresUrl; + private Unmarshaller unmarsheller; + + private NameValuePair[] buildQueryString() { + List resList = new ArrayList(); + + for (String key : conditions.keySet()) { + resList.add(new NameValuePair(key, conditions.get(key))); + } + + return resList.toArray(new NameValuePair[resList.size()]); + } + + private InputStream getAresResponse() throws HttpException, IOException, IsspstException { + GetMethod httpGet = new GetMethod(aresUrl); + HttpClient httpCli = new HttpClient(); + + httpGet.setQueryString(buildQueryString()); + int res = httpCli.executeMethod(httpGet); + + if (res != 200) { + throw new IsspstException("Server returned error code " + String.valueOf(res)); + } + + return httpGet.getResponseBodyAsStream(); + } + + private StringReader transformOut(InputStream inXml) throws IsspstException { + TransformerFactory tf = TransformerFactory.newInstance(); + + Resource resource = new ClassPathResource("info/bukova/isspst/services/addressbook/ares.xsl"); + + Transformer transformer; + StringWriter sWriter = null; + InputStream is = null; + try { + sWriter = new StringWriter(); + is = resource.getInputStream(); + StreamSource src = new StreamSource(is); + transformer = tf.newTransformer(src); + is.close(); + + StreamSource source = new StreamSource(inXml); + StreamResult result = new StreamResult(sWriter); + transformer.transform(source, result); + sWriter.flush(); + sWriter.close(); + + return new StringReader(sWriter.getBuffer().toString()); + } catch (TransformerException e) { + throw new IsspstException("ARES transformation error", e.getCause()); + } catch (IOException e) { + throw new IsspstException("Transformation file \"ares.xsl\" not found.", e.getCause()); + } finally { + try { + if (sWriter != null) { + sWriter.flush(); + sWriter.close(); + } + } catch (IOException e) { + throw new IsspstException("Cannot close stream", e.getCause()); + } + try { + if (is != null) { + is.close(); + } + } catch (IOException e) { + throw new IsspstException("Cannot close stream", e.getCause()); + } + } + } + + private List
convertToAddrList(AresOdpoved odpoved) { + List
resList = new ArrayList
(); + + if (odpoved == null || odpoved.getPocetZaznamu() <= 0) + return resList; + + for (AresZaznam zaznam : odpoved.getAresZaznam()) { + Address addr = new Address(); + addr.setCompany(zaznam.getFirma()); + addr.setIc(zaznam.getIco()); + addr.setStreet(zaznam.getUlice()); + addr.setHouseNumber(zaznam.getCp()); + addr.setCity(zaznam.getObec()); + addr.setZipCode(zaznam.getPsc()); + resList.add(addr); + } + return resList; + } + + private void setConditionAddr(Address condAddress) { + if (conditions == null) + conditions = new HashMap(); + else + conditions.clear(); + + if (condAddress.getCompany() != null && !condAddress.getCompany().isEmpty()) + conditions.put("obchodni_firma", condAddress.getCompany()); + if (condAddress.getIc() != 0) + conditions.put("ico", String.valueOf(condAddress.getIc())); + if (condAddress.getCity() != null && !condAddress.getCity().isEmpty()) + conditions.put("nazev_obce", condAddress.getCity()); + conditions.put("max_pocet", "200"); + conditions.put("czk", "utf"); + } + + @Override + public synchronized List
findAddress(Address condAddress) throws IsspstException { + setConditionAddr(condAddress); + AresOdpoved odpoved; + InputStream is = null; + try { + is = getAresResponse(); + odpoved = (AresOdpoved) unmarsheller.unmarshal(transformOut(is)); + is.close(); + return convertToAddrList(odpoved); + } catch (MarshalException e) { + throw new IsspstException("Can't create ARES answer object", e.getCause()); + } catch (ValidationException e) { + throw new IsspstException("ARES answer is not valid", e.getCause()); + } catch (HttpException e) { + throw new IsspstException("Error while comunication with ARES server", e.getCause()); + } catch (IOException e) { + throw new IsspstException("ARES find error", e.getCause()); + } finally { + try { + if (is != null) + is.close(); + } catch (IOException e) { + throw new IsspstException("Cannot close stream", e.getCause()); + } + } + + } + + public void setAresUrl(String aresUrl) { + this.aresUrl = aresUrl; + } + + public void setUnmarsheller(Unmarshaller unmarsheller) { + this.unmarsheller = unmarsheller; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/AddressFinderTaxID.java b/src/main/java/info/bukova/isspst/services/addressbook/AddressFinderTaxID.java new file mode 100644 index 00000000..0b9bbc08 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/addressbook/AddressFinderTaxID.java @@ -0,0 +1,137 @@ +package info.bukova.isspst.services.addressbook; + +import info.bukova.isspst.data.Address; +import info.bukova.isspst.services.IsspstException; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.methods.GetMethod; +import org.springframework.util.xml.SimpleNamespaceContext; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +public class AddressFinderTaxID implements AddressFinder { + + private String aresDicUrl; + private Address resAddr; + + @Override + public synchronized List
findAddress(Address condAddress) throws IsspstException { + ArrayList
resList = new ArrayList
(); + resAddr = new Address(); + resAddr.setIc(condAddress.getIc()); + InputStream is = null; + try { + is = getAresResponse(condAddress); + parseDic(is); + is.close(); + } catch (HttpException e) { + throw new IsspstException(); + } catch (IOException e) { + throw new IsspstException(); + } finally { + try { + is.close(); + } catch (IOException e) { + throw new IsspstException("Cannot close stream", e.getCause()); + } + } + resList.add(resAddr); + return resList; + } + + private InputStream getAresResponse(Address condAddress) throws IsspstException, HttpException, IOException { + GetMethod httpGet = new GetMethod(aresDicUrl); + HttpClient httpCli = new HttpClient(); + + httpGet.setQueryString("ico=" + String.valueOf(condAddress.getIc())); + int res = httpCli.executeMethod(httpGet); + + if (res != 200) { + throw new IsspstException("Server returned error code " + String.valueOf(res)); + } + + return httpGet.getResponseBodyAsStream(); + } + + private void parseDic(InputStream is) throws IsspstException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + try { + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + Document doc = docBuilder.parse(is); + + Map xmlNs = new HashMap(); + xmlNs.put("are", "http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer_basic/v_1.0.3"); + xmlNs.put("D", "http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_datatypes/v_1.0.3"); + xmlNs.put("U", "http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.3"); + SimpleNamespaceContext nsCtx = new SimpleNamespaceContext(); + nsCtx.setBindings(xmlNs); + + XPathFactory factory = XPathFactory.newInstance(); + XPath xpath = factory.newXPath(); + xpath.setNamespaceContext(nsCtx); + XPathExpression exp = xpath.compile("/are:Ares_odpovedi/are:Odpoved/D:VBAS/D:DIC"); + String dic = (String) exp.evaluate(doc, XPathConstants.STRING); + exp = xpath.compile("/are:Ares_odpovedi/are:Odpoved/D:VBAS/D:OF"); + String company = (String) exp.evaluate(doc, XPathConstants.STRING); + exp = xpath.compile("/are:Ares_odpovedi/are:Odpoved/D:VBAS/D:AA/D:NU"); + String street = (String) exp.evaluate(doc, XPathConstants.STRING); + exp = xpath.compile("/are:Ares_odpovedi/are:Odpoved/D:VBAS/D:AA/D:CD"); + String num = (String) exp.evaluate(doc, XPathConstants.STRING); + exp = xpath.compile("/are:Ares_odpovedi/are:Odpoved/D:VBAS/D:AA/D:CO"); + String numOr = (String) exp.evaluate(doc, XPathConstants.STRING); + exp = xpath.compile("/are:Ares_odpovedi/are:Odpoved/D:VBAS/D:AA/D:N"); + String city = (String) exp.evaluate(doc, XPathConstants.STRING); + exp = xpath.compile("/are:Ares_odpovedi/are:Odpoved/D:VBAS/D:AA/D:PSC"); + String zip = (String) exp.evaluate(doc, XPathConstants.STRING); + exp = xpath.compile("/are:Ares_odpovedi/are:Odpoved/D:VBAS/D:AA/D:NS"); + String state = (String) exp.evaluate(doc, XPathConstants.STRING); + + resAddr.setDic(dic); + resAddr.setCompany(company); + resAddr.setStreet(street); + if (numOr != null && !numOr.isEmpty()) + num = num + "/" + numOr; + resAddr.setHouseNumber(num); + resAddr.setCity(city); + resAddr.setZipCode(zip); + resAddr.setState(state); + + } catch (ParserConfigurationException e) { + throw new IsspstException("ARES: parese error while finding Tax ID", e.getCause()); + } catch (SAXException e) { + throw new IsspstException("ARES: SAX error while finding Tax ID", e.getCause()); + } catch (IOException e) { + throw new IsspstException("ARES: IO error while finding Tax ID", e.getCause()); + } catch (XPathExpressionException e) { + throw new IsspstException("ARES: xpath compile error", e.getCause()); + } + + } + + public String getAresDicUrl() { + return aresDicUrl; + } + + public void setAresDicUrl(String aresDicUrl) { + this.aresDicUrl = aresDicUrl; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/AresOdpoved.java b/src/main/java/info/bukova/isspst/services/addressbook/AresOdpoved.java new file mode 100644 index 00000000..53027819 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/addressbook/AresOdpoved.java @@ -0,0 +1,30 @@ +package info.bukova.isspst.services.addressbook; + +import java.util.List; + +public class AresOdpoved { + + private long pocetZaznamu; + private String typVyhledani; + private List aresZaznam; + + public long getPocetZaznamu() { + return pocetZaznamu; + } + public void setPocetZaznamu(long pocetZaznamu) { + this.pocetZaznamu = pocetZaznamu; + } + public String getTypVyhledani() { + return typVyhledani; + } + public void setTypVyhledani(String typVyhledani) { + this.typVyhledani = typVyhledani; + } + public List getAresZaznam() { + return aresZaznam; + } + public void setAresZaznam(List aresZaznam) { + this.aresZaznam = aresZaznam; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/AresZaznam.java b/src/main/java/info/bukova/isspst/services/addressbook/AresZaznam.java new file mode 100644 index 00000000..12e697b8 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/addressbook/AresZaznam.java @@ -0,0 +1,56 @@ +package info.bukova.isspst.services.addressbook; + +public class AresZaznam { + + private String firma; + private long ico; + private String obec; + private String mestskaCast; + private String ulice; + private String cp; + private String psc; + + public String getFirma() { + return firma; + } + public void setFirma(String firma) { + this.firma = firma; + } + public long getIco() { + return ico; + } + public void setIco(long ico) { + this.ico = ico; + } + public String getObec() { + return obec; + } + public void setObec(String obec) { + this.obec = obec; + } + public String getMestskaCast() { + return mestskaCast; + } + public void setMestskaCast(String mestskaCast) { + this.mestskaCast = mestskaCast; + } + public String getUlice() { + return ulice; + } + public void setUlice(String ulice) { + this.ulice = ulice; + } + public String getCp() { + return cp; + } + public void setCp(String cp) { + this.cp = cp; + } + public String getPsc() { + return psc; + } + public void setPsc(String psc) { + this.psc = psc; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/ares.xsl b/src/main/java/info/bukova/isspst/services/addressbook/ares.xsl new file mode 100644 index 00000000..c77d0d9a --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/addressbook/ares.xsl @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + / + + + + + + + + + + diff --git a/src/main/java/info/bukova/isspst/services/addressbook/mappingAres.xml b/src/main/java/info/bukova/isspst/services/addressbook/mappingAres.xml new file mode 100644 index 00000000..0bd50b69 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/addressbook/mappingAres.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/info/bukova/isspst/ui/Mapa.java b/src/main/java/info/bukova/isspst/ui/Mapa.java new file mode 100644 index 00000000..3002afd1 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/Mapa.java @@ -0,0 +1,37 @@ +package info.bukova.isspst.ui; + +import org.zkoss.zk.ui.HtmlBasedComponent; + +public class Mapa extends HtmlBasedComponent { + + private static final long serialVersionUID = 6856577544897548586L; + + private String address = ""; + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + if (this.address != null && this.address.equals(address)) + return; + + this.address = address; + this.smartUpdate("address", this.address); + } + + public void setValue(String val) { + setAddress(val); + } + + public String getValue() { + return address; + } + + protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) + throws java.io.IOException { + super.renderProperties(renderer); + render(renderer, "address", this.address); + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/addressbook/AddressFindResult.java b/src/main/java/info/bukova/isspst/ui/addressbook/AddressFindResult.java new file mode 100644 index 00000000..a9c79058 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/addressbook/AddressFindResult.java @@ -0,0 +1,38 @@ +package info.bukova.isspst.ui.addressbook; + +import info.bukova.isspst.data.Address; + +import java.util.List; + +import org.zkoss.bind.annotation.ExecutionArgParam; +import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; + +public class AddressFindResult { + + private List
listResult; + private Address selectedAddr; + + @Init + public void init(@ExecutionArgParam("result") List
result) { + listResult = result; + } + + public List
getListResult() { + return listResult; + } + + public Address getSelectedAddr() { + return selectedAddr; + } + + @NotifyChange("selected") + public void setSelectedAddr(Address selectedAddr) { + this.selectedAddr = selectedAddr; + } + + public boolean getSelected() { + return selectedAddr == null; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/addressbook/AddressForm.java b/src/main/java/info/bukova/isspst/ui/addressbook/AddressForm.java new file mode 100644 index 00000000..e3cdb3e7 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/addressbook/AddressForm.java @@ -0,0 +1,77 @@ +package info.bukova.isspst.ui.addressbook; + +import info.bukova.isspst.data.Address; +import info.bukova.isspst.services.IsspstException; +import info.bukova.isspst.services.addressbook.AdbService; +import info.bukova.isspst.services.addressbook.AddressFinder; +import info.bukova.isspst.ui.FormViewModel; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.zkoss.bind.annotation.BindingParam; +import org.zkoss.bind.annotation.Command; +import org.zkoss.bind.annotation.GlobalCommand; +import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; +import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.select.annotation.WireVariable; +import org.zkoss.zul.Messagebox; +import org.zkoss.zul.Window; + +public class AddressForm extends FormViewModel
{ + + @WireVariable + private AdbService adbService; + @WireVariable + private AddressFinder addressFinderAres; + @WireVariable + private AddressFinder addressFinderTaxID; + + @Init(superclass = true) + public void init() { + + } + + @Command + @NotifyChange("dataBean") + public void searchAres() { + if (getDataBean().getIc() != 0) { + try { + adbService.fillFoundData(addressFinderTaxID, getDataBean()); + } catch (IsspstException e) { + e.printStackTrace(); + } + return; + } + + Map> arg = new HashMap>(); + try { + arg.put("result", adbService.lookForAddr(addressFinderAres, getDataBean())); + } catch (IsspstException e) { + e.printStackTrace(); + Messagebox.show("Chyba při hledání adresy", "Chyba", Messagebox.OK, Messagebox.ERROR); + return; + } + Window resWin = (Window) Executions.createComponents("addrFindResult.zul", null, arg); + resWin.doModal(); + + } + + @GlobalCommand("selectAddress") + @NotifyChange("dataBean") + public void selectAddress(@BindingParam("selected") Address selected, @BindingParam("window") Window window) { + try { + adbService.fillFoundData(addressFinderTaxID, selected); + } catch (IsspstException e) { + e.printStackTrace(); + } + + adbService.mergeAddress(getDataBean(), selected, true); + + if (window != null) + window.detach(); + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/addressbook/AddressList.java b/src/main/java/info/bukova/isspst/ui/addressbook/AddressList.java new file mode 100644 index 00000000..a314fea6 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/addressbook/AddressList.java @@ -0,0 +1,25 @@ +package info.bukova.isspst.ui.addressbook; + +import info.bukova.isspst.data.Address; +import info.bukova.isspst.filters.AddressFilter; +import info.bukova.isspst.services.addressbook.AdbService; +import info.bukova.isspst.ui.ListViewModel; + +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +public class AddressList extends ListViewModel
{ + + @WireVariable + private AdbService adbService; + + @Init + public void init() { + service = adbService; + dataClass = Address.class; + formZul = "address.zul"; + dataFilter = new AddressFilter(getFilterTemplate()); + + } + +} diff --git a/src/main/java/web/js/info/bukova/isspst/ui/Mapa.js b/src/main/java/web/js/info/bukova/isspst/ui/Mapa.js new file mode 100644 index 00000000..ce95476f --- /dev/null +++ b/src/main/java/web/js/info/bukova/isspst/ui/Mapa.js @@ -0,0 +1,43 @@ +info.bukova.isspst.ui.Mapa = zk.$extends(zk.Widget, { + address : '', // default value + + getAddress : function() { + return this.address; + }, + + setAddress : function(value) { + if (this.address != value) { + this.address = value; + if (this.desktop) { + var myOptions = { + zoom: 12, + center: new google.maps.LatLng(-34.397, 150.644), + mapTypeId: google.maps.MapTypeId.ROADMAP + }; + + var map = new google.maps.Map(this.$n(), myOptions); + var geocoder = new google.maps.Geocoder(); + + var request = { + address: this.address + }; + geocoder.geocode(request, function(results, status) { + if (status == google.maps.GeocoderStatus.OK) { + var marker = new google.maps.Marker({ + map: map, + position: results[0].geometry.location + }); + map.panTo(marker.getPosition()); + } else { + window.console.log('failed to geocode address: ' + status); + } + }); + } + } + }, + + redraw: function (out) { + out.push('
', this.getAddress(), '
'); + } + +}); \ No newline at end of file diff --git a/src/main/java/web/js/info/bukova/isspst/ui/zk.wpd b/src/main/java/web/js/info/bukova/isspst/ui/zk.wpd new file mode 100644 index 00000000..dfa706ce --- /dev/null +++ b/src/main/java/web/js/info/bukova/isspst/ui/zk.wpd @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index 76d3d2d2..100b96d9 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/ckez-bind-lang-addon.xml b/src/main/webapp/WEB-INF/ckez-bind-lang-addon.xml new file mode 100644 index 00000000..44ea3165 --- /dev/null +++ b/src/main/webapp/WEB-INF/ckez-bind-lang-addon.xml @@ -0,0 +1,35 @@ + + + + ckezbind + + + xul/html + + + ckeditor + ckeditor + + ZKBIND + value + + ACCESS + both + + + SAVE_EVENT + onChange + + + LOAD_REPLACEMENT + value + + + LOAD_TYPE + java.lang.String + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/mapa-lang-addon.xml b/src/main/webapp/WEB-INF/mapa-lang-addon.xml new file mode 100644 index 00000000..dede21d7 --- /dev/null +++ b/src/main/webapp/WEB-INF/mapa-lang-addon.xml @@ -0,0 +1,11 @@ + + + mapa + xul/html + + + mapa + info.bukova.isspst.ui.Mapa + info.bukova.isspst.ui.Mapa + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index 2e95a6b7..c3a8e678 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -88,7 +88,13 @@ + + + + + + @@ -97,5 +103,31 @@ + + + + + + + + + + + + + + + + + + + info/bukova/isspst/services/addressbook/mappingAres.xml + + + + + + + diff --git a/src/main/webapp/WEB-INF/zk.xml b/src/main/webapp/WEB-INF/zk.xml new file mode 100644 index 00000000..3eec7dba --- /dev/null +++ b/src/main/webapp/WEB-INF/zk.xml @@ -0,0 +1,30 @@ + + + + + + + true + + + org.zkoss.web.classWebResource.cache + false + + + + /WEB-INF/mapa-lang-addon.xml + /WEB-INF/ckez-bind-lang-addon.xml + + + + diff --git a/src/main/webapp/admin/addressbook/addrFindResult.zul b/src/main/webapp/admin/addressbook/addrFindResult.zul new file mode 100644 index 00000000..e4c30525 --- /dev/null +++ b/src/main/webapp/admin/addressbook/addrFindResult.zul @@ -0,0 +1,30 @@ + + + + + +