Conflicts:
	src/main/resources/hibernate.cfg.xml
	src/main/webapp/WEB-INF/spring/root-context.xml
multitenant
František Přibyl 11 years ago
commit 4e2faa7c2c

@ -239,6 +239,24 @@
<version>2.2</version> <version>2.2</version>
</dependency> </dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>spring-xml</artifactId>
<version>1.2.1</version>
</dependency>
<!-- Test --> <!-- Test -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>

@ -1,10 +1,29 @@
package info.bukova.isspst; package info.bukova.isspst;
import info.bukova.isspst.data.Role;
public class Constants { public class Constants {
public final static String DEF_ADMIN = "admin"; public final static String DEF_ADMIN = "admin";
public final static String DEF_ADMIN_PASSWD = "admin"; public final static String DEF_ADMIN_PASSWD = "admin";
public final static String ROLE_USER = "ROLE_USER"; public final static String ROLE_USER = "ROLE_USER";
public final static String ROLE_ADMIN = "ROLE_ADMIN"; public final static String ROLE_ADMIN = "ROLE_ADMIN";
public final static String ROLES[] = {ROLE_USER, ROLE_ADMIN}; public final static String ROLE_DIRECTOR = "ROLE_DIRECTOR";
public final static String ROLE_MANAGER = "ROLE_MANAGER";
public final static String ROLE_PRINCIPAL = "ROLE_PRINCIPAL";
public final static String ROLE_ACCOUNTANT = "ROLE_ACCOUNTANT";
public final static String ROLE_SUPPLIER = "ROLE_SUPPLIER";
public final static String ROLE_TECHNICIAN = "ROLE_TECHNICIAN";
public final static String ROLE_LEADER = "ROLE_LEADER";
public final static Role ROLES[] = {
new Role(ROLE_ADMIN, "Administrátor"),
new Role(ROLE_DIRECTOR, "Ředitel"),
new Role(ROLE_MANAGER, "Správce"),
new Role(ROLE_PRINCIPAL, "Příkazce"),
new Role(ROLE_ACCOUNTANT, "Účetní"),
new Role(ROLE_SUPPLIER, "Zásobovač"),
new Role(ROLE_TECHNICIAN, "Technik"),
new Role(ROLE_LEADER, "Vedoucí"),
new Role(ROLE_USER, "Uživatel")
};
} }

@ -2,14 +2,15 @@ package info.bukova.isspst;
import info.bukova.isspst.data.Role; import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User; import info.bukova.isspst.data.User;
import info.bukova.isspst.services.RoleService; import info.bukova.isspst.services.users.RoleService;
import info.bukova.isspst.services.UserService; import info.bukova.isspst.services.users.UserService;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.context.support.WebApplicationContextUtils;
@ -37,16 +38,10 @@ public class DbInitListener implements ServletContextListener {
} }
private void checkRoles() { private void checkRoles() {
Role r = null; for (Role role : Constants.ROLES)
for (String auth : Constants.ROLES)
{ {
r = roleService.getRoleByAuthority(auth); if (roleService.getRoleByAuthority(role.getAuthority()) == null) {
if (r == null) { roleService.add(role);
r = new Role();
r.setAuthority(auth);
r.setDescription("---");
roleService.add(r);
} }
} }
} }
@ -62,12 +57,20 @@ public class DbInitListener implements ServletContextListener {
} }
if (!adminExists) { if (!adminExists) {
User u = new User(); User u = null;
u.setUsername(Constants.DEF_ADMIN); try {
u.addAuthority(roleService.getRoleByAuthority(Constants.ROLE_ADMIN)); u = (User) userService.loadUserByUsername(Constants.DEF_ADMIN);
u.setEnabled(true); u.addAuthority(roleService.getRoleByAuthority(Constants.ROLE_ADMIN));
userService.setPassword(u, Constants.DEF_ADMIN_PASSWD); u.setEnabled(true);
userService.add(u); userService.update(u);
} catch(UsernameNotFoundException e) {
u = new User();
u.setUsername(Constants.DEF_ADMIN);
userService.setPassword(u, Constants.DEF_ADMIN_PASSWD);
u.addAuthority(roleService.getRoleByAuthority(Constants.ROLE_ADMIN));
u.setEnabled(true);
userService.add(u);
}
} }
} }

@ -1,7 +1,7 @@
package info.bukova.isspst; package info.bukova.isspst;
import info.bukova.isspst.data.User; import info.bukova.isspst.data.User;
import info.bukova.isspst.services.UserService; import info.bukova.isspst.services.users.UserService;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Date; import java.util.Date;

@ -0,0 +1,13 @@
package info.bukova.isspst;
public class StringUtils {
public static String nullStr(String str) {
return str == null ? "" : str;
}
public static String not0ToStr(long i) {
return i == 0 ? "" : String.valueOf(i);
}
}

@ -0,0 +1,7 @@
package info.bukova.isspst.dao;
import info.bukova.isspst.data.Address;
public interface AddressDao extends BaseDao<Address> {
}

@ -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<Address> implements AddressDao {
@Override
public String getEntityName() {
return Address.class.getSimpleName();
}
}

@ -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;
}
}

@ -0,0 +1,94 @@
package info.bukova.isspst.data;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
@MappedSuperclass
public abstract class BaseData implements OwnedDataModel {
@Id
@Column(name="ID")
@GeneratedValue
private int id;
@Column(name="CREATED")
private Date created;
@Column(name="MODIFIED")
private Date modified;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="OWNED_BY_ID")
private User ownedBy;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="MODIFIED_BY_ID")
private User modifiedBy;
@Transient
private boolean valid;
@Override
public void setId(int id) {
this.id = id;
}
@Override
public int getId() {
return this.id;
}
@Override
public void setCreated(Date created) {
this.created = created;
}
@Override
public Date getCreated() {
return this.created;
}
@Override
public void setModified(Date modified) {
this.modified = modified;
}
@Override
public Date getModified() {
return this.modified;
}
@Override
public boolean isValid() {
return this.valid;
}
@Override
public void setValid(boolean valid) {
this.valid = valid;
}
@Override
public void setOwnedBy(User user) {
this.ownedBy = user;
}
@Override
public User getOwnedBy() {
return this.ownedBy;
}
@Override
public void setModifiedBy(User user) {
this.modifiedBy = user;
}
@Override
public User getModifiedBy() {
return this.modifiedBy;
}
}

@ -0,0 +1,10 @@
package info.bukova.isspst.data;
public interface OwnedDataModel extends DataModel {
public void setOwnedBy(User user);
public User getOwnedBy();
public void setModifiedBy(User user);
public User getModifiedBy();
}

@ -35,6 +35,15 @@ public class Role implements GrantedAuthority, DataModel {
@Transient @Transient
private boolean valid; private boolean valid;
public Role(String authority, String description) {
this.authority = authority;
this.description = description;
}
public Role() {
}
@Override @Override
public String getAuthority() { public String getAuthority() {
return authority; return authority;
@ -84,4 +93,13 @@ public class Role implements GrantedAuthority, DataModel {
this.valid = valid; this.valid = valid;
} }
@Override
public boolean equals(Object o) {
if ((o instanceof Role) && ((Role)o).getId() == this.id) {
return true;
} else {
return false;
}
}
} }

@ -9,9 +9,9 @@ import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.MapKeyColumn; import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
@ -36,9 +36,18 @@ public class User implements UserDetails, DataModel {
private String password; private String password;
@Column(name="ENABLED") @Column(name="ENABLED")
private boolean enabled; private boolean enabled;
private String fullName; @Column(name="FIRST_NAME")
@OneToMany(fetch=FetchType.EAGER) @JoinTable(name="USER_ROLE") private String firstName;
@MapKeyColumn(name="ROLE_ID") @Column(name="LAST_NAME")
private String lastName;
@Column(name="PERSONAL_NUMBER")
private String personalNumber;
@Column(name="EMAIL")
private String email;
@Column(name="NOTIFY")
private boolean notify;
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="USER_ROLE", joinColumns={@JoinColumn(name="USER_ID")}, inverseJoinColumns={@JoinColumn(name="ROLE_ID")})
private List<Role> authorities; private List<Role> authorities;
@Column(name="CREATED") @Column(name="CREATED")
private Date created; private Date created;
@ -139,11 +148,51 @@ public class User implements UserDetails, DataModel {
} }
public String getFullName() { public String getFullName() {
return fullName; String ret = "";
if (firstName != null && !firstName.isEmpty()) {
ret = firstName + " ";
}
return ret + lastName == null ? "" : lastName;
} }
public void setFullName(String fullName) { public String getFirstName() {
this.fullName = fullName; 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 getPersonalNumber() {
return personalNumber;
}
public void setPersonalNumber(String personalNumber) {
this.personalNumber = personalNumber;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean isNotify() {
return notify;
}
public void setNotify(boolean notify) {
this.notify = notify;
} }
} }

@ -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<Address> {
private Address condAddr;
public AddressFilter(Address condAddr) {
this.condAddr = condAddr;
}
private static class AddrMatcher extends TypeSafeMatcher<Address> {
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<Address> matchAddr(Address addr) {
return new AddrMatcher(addr);
}
}
@Override
public AddrMatcher matcher() {
return new AddrMatcher(condAddr);
}
@Override
public String queryString() {
// TODO query string
return "";
}
}

@ -0,0 +1,57 @@
package info.bukova.isspst.filters;
import info.bukova.isspst.data.User;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.TypeSafeMatcher;
import static info.bukova.isspst.StringUtils.nullStr;
public class UserFilter implements Filter<User> {
private User condUser;
public UserFilter(User condition) {
this.condUser = condition;
}
private static class UserMatcher extends TypeSafeMatcher<User> {
private User condUser;
public UserMatcher(User condition) {
this.condUser = condition;
}
@Override
public void describeTo(Description description) {
description.appendText("user matcher");
}
@Override
public boolean matchesSafely(User item) {
return nullStr(item.getUsername()).toLowerCase().contains(nullStr(condUser.getUsername()).toLowerCase())
&& nullStr(item.getFirstName()).toLowerCase().contains(nullStr(condUser.getFirstName()).toLowerCase())
&& nullStr(item.getLastName()).toLowerCase().contains(nullStr(condUser.getLastName()).toLowerCase())
&& nullStr(item.getPersonalNumber()).toLowerCase().contains(nullStr(condUser.getPersonalNumber()).toLowerCase());
}
@Factory
public UserMatcher matchUser(User cond) {
return new UserMatcher(cond);
}
}
@Override
public TypeSafeMatcher<User> matcher() {
return new UserMatcher(condUser);
}
@Override
public String queryString() {
return null;
}
}

@ -0,0 +1,39 @@
package info.bukova.isspst.services;
import java.util.Date;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.transaction.annotation.Transactional;
import info.bukova.isspst.data.OwnedDataModel;
import info.bukova.isspst.data.User;
public class AbstractOwnedService<T extends OwnedDataModel> extends AbstractService<T> {
@Override
@Transactional
public void add(T entity) {
validate(entity);
entity.setCreated(new Date());
entity.setOwnedBy(getLoggedInUser());
dao.add(entity);
}
@Override
@Transactional
public void update(T entity) {
if (entity.getCreated() == null) {
add(entity);
} else {
validate(entity);
entity.setModifiedBy(getLoggedInUser());
entity.setModified(new Date());
dao.modify(entity);
}
}
protected User getLoggedInUser() {
return (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
}
}

@ -1,6 +1,9 @@
package info.bukova.isspst.services; package info.bukova.isspst.services;
import static ch.lambdaj.Lambda.filter; import static ch.lambdaj.Lambda.filter;
import info.bukova.isspst.dao.BaseDao;
import info.bukova.isspst.data.DataModel;
import info.bukova.isspst.filters.Filter;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -9,16 +12,10 @@ import java.util.Set;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.Validator; import javax.validation.Validator;
import org.hibernate.HibernateException;
import org.hibernate.NonUniqueResultException; import org.hibernate.NonUniqueResultException;
import org.hibernate.Query; import org.hibernate.Query;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import info.bukova.isspst.dao.BaseDao;
import info.bukova.isspst.dao.IntegrityException;
import info.bukova.isspst.data.DataModel;
import info.bukova.isspst.filters.Filter;
public abstract class AbstractService<T extends DataModel> implements Service<T> { public abstract class AbstractService<T extends DataModel> implements Service<T> {
protected BaseDao<T> dao; protected BaseDao<T> dao;
@ -31,6 +28,7 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
@Override @Override
@Transactional @Transactional
public void add(T entity) { public void add(T entity) {
validate(entity);
entity.setCreated(new Date()); entity.setCreated(new Date());
dao.add(entity); dao.add(entity);
} }
@ -38,18 +36,19 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
@Override @Override
@Transactional @Transactional
public void update(T entity) { public void update(T entity) {
entity.setModified(new Date()); if (entity.getCreated() == null) {
dao.modify(entity); add(entity);
} else {
validate(entity);
entity.setModified(new Date());
dao.modify(entity);
}
} }
@Override @Override
@Transactional @Transactional
public void delete(T entity) { public void delete(T entity) {
try { dao.delete(entity);
dao.delete(entity);
} catch (HibernateException e) {
throw new IntegrityException(e);
}
} }
@Override @Override

@ -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);
}
}

@ -1,11 +0,0 @@
package info.bukova.isspst.services;
import info.bukova.isspst.data.User;
public interface UserService extends Service<User> {
public void setPassword(User user, String password);
public boolean hasRole(User user, String authority);
public void test();
}

@ -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<Address>{
public List<Address> lookForAddr(AddressFinder finder, Address condAdr);
public void fillFoundData(AddressFinder finder, Address address);
public void mergeAddress(Address destination, Address source, boolean overwrite);
public List<Address> queryToArrayList(String filter);
public int count();
}

@ -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<Address> implements AdbService {
@Override
public List<Address> 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<Address> found = finder.findAddress(address);
if (found.size() > 0) {
this.mergeAddress(address, found.get(0), false);
}
}
@Override
public List<Address> queryToArrayList(String filter) {
return new ArrayList<Address>(execQuery(filter));
}
@Override
@Transactional
public int count() {
// Query q = queryDefaultFilter();
// q.setResult("count(id)");
// Object result = q.execute();
//
// return ((Long)result).intValue();
return 0;
}
}

@ -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<Address> findAddress(Address condAddress);
}

@ -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<String, String> conditions;
private String aresUrl;
private Unmarshaller unmarsheller;
private NameValuePair[] buildQueryString() {
List<NameValuePair> resList = new ArrayList<NameValuePair>();
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<Address> convertToAddrList(AresOdpoved odpoved) {
List<Address> resList = new ArrayList<Address>();
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<String, String>();
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<Address> 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;
}
}

@ -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<Address> findAddress(Address condAddress) throws IsspstException {
ArrayList<Address> resList = new ArrayList<Address>();
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<String, String> xmlNs = new HashMap<String, String>();
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;
}
}

@ -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> 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<AresZaznam> getAresZaznam() {
return aresZaznam;
}
public void setAresZaznam(List<AresZaznam> aresZaznam) {
this.aresZaznam = aresZaznam;
}
}

@ -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;
}
}

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:are="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer/v_1.0.1"
xmlns:dtt="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_datatypes/v_1.0.4"
xmlns:udt="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.1" >
<xsl:template match="are:Odpoved">
<AresOdpoved>
<PocetZaznamu><xsl:value-of select="are:Pocet_zaznamu" /></PocetZaznamu>
<TypVyhledani><xsl:value-of select="are:Typ_vyhledani" /></TypVyhledani>
<xsl:for-each select="are:Zaznam">
<AresZaznam>
<Firma><xsl:value-of select="are:Obchodni_firma" /></Firma>
<Ico><xsl:value-of select="are:ICO" /></Ico>
<Obec><xsl:value-of select="are:Identifikace/are:Adresa_ARES/dtt:Nazev_obce" /></Obec>
<MestskaCast><xsl:value-of select="are:Identifikace/are:Adresa_ARES/dtt:Nazev_mestske_casti" /></MestskaCast>
<Ulice><xsl:value-of select="are:Identifikace/are:Adresa_ARES/dtt:Nazev_ulice" /></Ulice>
<Cp><xsl:value-of select="are:Identifikace/are:Adresa_ARES/dtt:Cislo_domovni" /><xsl:if test="are:Identifikace/are:Adresa_ARES/dtt:Cislo_orientacni">/<xsl:value-of select="are:Identifikace/are:Adresa_ARES/dtt:Cislo_orientacni" />
</xsl:if>
</Cp>
<Psc><xsl:value-of select="are:Identifikace/are:Adresa_ARES/dtt:PSC" /></Psc>
</AresZaznam>
</xsl:for-each>
</AresOdpoved>
</xsl:template>
</xsl:stylesheet>

@ -0,0 +1,42 @@
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.codehaus.org/mapping.dtd">
<mapping>
<class name="info.bukova.isspst.services.addressbook.AresOdpoved">
<map-to xml="AresOdpoved"/>
<field name="PocetZaznamu" type="long">
<bind-xml name="PocetZaznamu" node="element"/>
</field>
<field name="TypVyhledani" type="string">
<bind-xml name="TypVyhledani" node="element"/>
</field>
<field name="AresZaznam" type="info.bukova.isspst.services.addressbook.AresZaznam" collection="arraylist">
<bind-xml name="AresZaznam" node="element"/>
</field>
</class>
<class name="info.bukova.isspst.services.addressbook.AresZaznam">
<field name="Firma" type="string">
<bind-xml name="Firma" node="element"/>
</field>
<field name="Ico" type="long">
<bind-xml name="Ico" node="element"/>
</field>
<field name="Ulice" type="string">
<bind-xml name="Ulice" node="element"/>
</field>
<field name="Cp" type="string">
<bind-xml name="Cp" node="element"/>
</field>
<field name="Obec" type="string">
<bind-xml name="Obec" node="element"/>
</field>
<field name="MestskaCast" type="string">
<bind-xml name="MestskaCast" node="element"/>
</field>
<field name="Psc" type="string">
<bind-xml name="Psc" node="element"/>
</field>
</class>
</mapping>

@ -1,6 +1,7 @@
package info.bukova.isspst.services; package info.bukova.isspst.services.users;
import info.bukova.isspst.data.Role; import info.bukova.isspst.data.Role;
import info.bukova.isspst.services.Service;
public interface RoleService extends Service<Role> { public interface RoleService extends Service<Role> {

@ -1,8 +1,9 @@
package info.bukova.isspst.services; package info.bukova.isspst.services.users;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import info.bukova.isspst.data.Role; import info.bukova.isspst.data.Role;
import info.bukova.isspst.services.AbstractService;
public class RoleServiceImpl extends AbstractService<Role> implements RoleService { public class RoleServiceImpl extends AbstractService<Role> implements RoleService {

@ -0,0 +1,14 @@
package info.bukova.isspst.services.users;
import org.springframework.security.core.userdetails.UserDetailsService;
import info.bukova.isspst.data.User;
import info.bukova.isspst.services.Service;
public interface UserService extends UserDetailsService, Service<User> {
public void setPassword(User user, String password);
public boolean hasRole(User user, String authority);
public void saveWithPwd(User user, String password);
}

@ -1,18 +1,16 @@
package info.bukova.isspst.services; package info.bukova.isspst.services.users;
import org.hibernate.Query; import org.hibernate.Query;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.authentication.encoding.PasswordEncoder; import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import info.bukova.isspst.Constants;
import info.bukova.isspst.data.Role; import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User; import info.bukova.isspst.data.User;
import info.bukova.isspst.services.AbstractService;
public class UserServiceImpl extends AbstractService<User> implements UserService, UserDetailsService { public class UserServiceImpl extends AbstractService<User> implements UserService {
private PasswordEncoder encoder; private PasswordEncoder encoder;
@ -51,9 +49,10 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
} }
@Override @Override
@Secured(Constants.ROLE_ADMIN) @Transactional
public void test() { public void saveWithPwd(User user, String password) {
System.out.println("pokus secured"); this.setPassword(user, password);
this.update(user);
} }

@ -1,6 +1,6 @@
package info.bukova.isspst.ui; package info.bukova.isspst.ui;
import info.bukova.isspst.dao.IntegrityException; import info.bukova.isspst.data.DataModel;
import info.bukova.isspst.services.Service; import info.bukova.isspst.services.Service;
import info.bukova.isspst.services.ValidationException; import info.bukova.isspst.services.ValidationException;
@ -14,7 +14,7 @@ import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zul.Messagebox; import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Window; import org.zkoss.zul.Window;
public class FormViewModel<T> { public class FormViewModel<T extends DataModel> {
private T dataBean; private T dataBean;
private Map<String, String> errMessages; private Map<String, String> errMessages;
@ -34,7 +34,7 @@ public class FormViewModel<T> {
@NotifyChange("errMessages") @NotifyChange("errMessages")
public void save(@BindingParam("window") Window win) { public void save(@BindingParam("window") Window win) {
try { try {
service.update(dataBean); doSave();
win.detach(); win.detach();
} catch (ValidationException e) { } catch (ValidationException e) {
errMessages = e.getMessages(); errMessages = e.getMessages();
@ -44,9 +44,11 @@ public class FormViewModel<T> {
classErr = ""; classErr = "";
} }
Messagebox.show("Chyba validace", "Error", Messagebox.OK, Messagebox.ERROR); Messagebox.show("Chyba validace", "Chyba", Messagebox.OK, Messagebox.ERROR);
} catch (IntegrityException e) { } catch (Exception e) {
dataBean.setCreated(null);
e.printStackTrace(); e.printStackTrace();
Messagebox.show("Chyba při ukládání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);
} }
} }
@ -58,4 +60,12 @@ public class FormViewModel<T> {
this.errMessages = msgs; this.errMessages = msgs;
} }
protected void doSave() {
service.update(dataBean);
}
public boolean isCanSave() {
return true;
}
} }

@ -1,6 +1,5 @@
package info.bukova.isspst.ui; package info.bukova.isspst.ui;
import info.bukova.isspst.dao.IntegrityException;
import info.bukova.isspst.data.DataModel; import info.bukova.isspst.data.DataModel;
import info.bukova.isspst.filters.Filter; import info.bukova.isspst.filters.Filter;
import info.bukova.isspst.services.Service; import info.bukova.isspst.services.Service;
@ -10,11 +9,15 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.dao.DataIntegrityViolationException;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.GlobalCommand; import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Messagebox; import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Window; import org.zkoss.zul.Window;
@ -24,8 +27,7 @@ public class ListViewModel<T extends DataModel> {
private boolean filter = false; private boolean filter = false;
private Window editWin; private Window editWin;
private T dataBean; private T dataBean;
//private T filterTemplate; private T filterTemplate;
private Filter<T> dataFilter;
private T editBean; private T editBean;
private List<T> dataList; private List<T> dataList;
private List<T> fullList; private List<T> fullList;
@ -39,6 +41,7 @@ public class ListViewModel<T extends DataModel> {
protected Service<T> service; protected Service<T> service;
protected Class<T> dataClass; protected Class<T> dataClass;
protected String formZul; protected String formZul;
protected Filter<T> dataFilter;
public List<T> getDataList() { public List<T> getDataList() {
if (dataList == null) { if (dataList == null) {
@ -57,6 +60,20 @@ public class ListViewModel<T extends DataModel> {
this.dataFilter = dataFilter; this.dataFilter = dataFilter;
} }
public T getFilterTemplate() {
if (filterTemplate == null) {
try {
filterTemplate = dataClass.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return filterTemplate;
}
public T getDataBean() { public T getDataBean() {
return dataBean; return dataBean;
} }
@ -125,6 +142,7 @@ public class ListViewModel<T extends DataModel> {
@Command @Command
public void edit() { public void edit() {
int index = dataList.indexOf(dataBean); int index = dataList.indexOf(dataBean);
newRec = false;
if (index != -1) { if (index != -1) {
selIndex = index; selIndex = index;
} }
@ -141,20 +159,46 @@ public class ListViewModel<T extends DataModel> {
@Command @Command
@NotifyChange({"dataList", "dataBean"}) @NotifyChange({"dataList", "dataBean"})
public void delete() { public void delete() {
Messagebox.show("Opravdu smazat?", "Smazat záznam", Messagebox.YES|Messagebox.NO,
Messagebox.QUESTION, new EventListener<Event>() {
@Override
public void onEvent(Event evt) throws Exception {
if (((Integer)evt.getData()).intValue() == Messagebox.YES) {
try {
service.delete(dataBean);
dataList.remove(dataBean);
dataBean = null;
BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataList");
BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataBean");
} catch (DataIntegrityViolationException e) {
Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);
}
}
}
});
confirmDelete = false;
}
@NotifyChange({"dataList", "dataBean"})
private void onDelete() {
try { try {
service.delete(dataBean); service.delete(dataBean);
dataList.remove(dataBean); dataList.remove(dataBean);
dataBean = null; dataBean = null;
} catch (IntegrityException e) { } catch (DataIntegrityViolationException e) {
Messagebox.show("Error while deleting object", "Error", Messagebox.OK, Messagebox.ERROR); Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);
} }
confirmDelete = false;
} }
@GlobalCommand @GlobalCommand
@NotifyChange({"dataList", "dataBean"}) @NotifyChange({"dataList", "dataBean"})
public void refresh() { public void refresh() {
if (editBean != null && !editBean.isValid()) { /*if (editBean != null && !editBean.isValid()) {
return;
}*/
if (editBean.getCreated() == null) {
return; return;
} }
if (!filter && newRec) { if (!filter && newRec) {
@ -220,28 +264,29 @@ public class ListViewModel<T extends DataModel> {
} }
} }
private void loadFromDb() { // private void loadFromDb() {
Thread fillThread = new Thread(new Runnable() { // Thread fillThread = new Thread(new Runnable() {
//
@Override // @Override
public void run() { // public void run() {
tmpList = service.getAll(); // tmpList = service.getAll();
//
try { // try {
Thread.sleep(200); // Thread.sleep(200);
} catch (InterruptedException e) { // } catch (InterruptedException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
//
fullFill = true; // fullFill = true;
} // }
}); // });
//
fillThread.start(); // fillThread.start();
} // }
private void loadFromDbSync() { private void loadFromDbSync() {
dataList.addAll(service.getAll()); dataList.addAll(service.getAll());
fullList = dataList;
} }
protected void showForm() { protected void showForm() {

@ -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);
}
}

@ -1,14 +0,0 @@
package info.bukova.isspst.ui;
import org.zkoss.bind.annotation.Init;
import info.bukova.isspst.data.User;
public class UserForm extends FormViewModel<User> {
@Init(superclass = true)
public void init() {
}
}

@ -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<Address> listResult;
private Address selectedAddr;
@Init
public void init(@ExecutionArgParam("result") List<Address> result) {
listResult = result;
}
public List<Address> getListResult() {
return listResult;
}
public Address getSelectedAddr() {
return selectedAddr;
}
@NotifyChange("selected")
public void setSelectedAddr(Address selectedAddr) {
this.selectedAddr = selectedAddr;
}
public boolean getSelected() {
return selectedAddr == null;
}
}

@ -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<Address> {
@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<String, List<Address>> arg = new HashMap<String, List<Address>>();
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();
}
}

@ -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<Address> {
@WireVariable
private AdbService adbService;
@Init
public void init() {
service = adbService;
dataClass = Address.class;
formZul = "address.zul";
dataFilter = new AddressFilter(getFilterTemplate());
}
}

@ -0,0 +1,43 @@
package info.bukova.isspst.ui.users;
import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User;
public class RoleCheck {
private Role role;
private User user;
private boolean checked;
public RoleCheck(User user, Role role) {
this.user = user;
this.role = role;
if (user.getAuthorities().contains(role)) {
checked = true;
} else {
checked = false;
}
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
if (checked && !user.getAuthorities().contains(role)) {
user.addAuthority(role);
} else {
user.getAuthorities().remove(role);
}
}
}

@ -0,0 +1,90 @@
package info.bukova.isspst.ui.users;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import info.bukova.isspst.data.User;
import info.bukova.isspst.services.users.RoleService;
import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.ui.FormViewModel;
public class UserForm extends FormViewModel<User> {
@WireVariable
private RoleService roleService;
@WireVariable
private UserService userService;
private String retPasswd = "";
private String password = "";
private UserRoles userRoles;
private boolean loginFree;
@Init(superclass = true)
public void init() {
userRoles = new UserRoles(getDataBean(), roleService.getAll());
loginFree = true;
}
public UserRoles getUserRoles() {
return userRoles;
}
public String getRetPasswd() {
return retPasswd;
}
@NotifyChange({"canSave", "pwMatches"})
public void setRetPasswd(String retPasswd) {
this.retPasswd = retPasswd;
}
public String getPassword() {
return password;
}
@NotifyChange({"canSave", "pwMatches"})
public void setPassword(String password) {
this.password = password;
}
@Command
@NotifyChange({"loginFree", "canSave"})
public void checkLogin() {
try {
userService.loadUserByUsername(getDataBean().getUsername());
loginFree = false;
} catch(UsernameNotFoundException e) {
loginFree = true;
}
}
public boolean isPwMatches() {
return password.equals(retPasswd);
}
public boolean isLoginFree() {
return loginFree || isEdit();
}
public boolean isEdit() {
return getDataBean().getCreated() != null;
}
@Override
protected void doSave() {
if (!password.isEmpty()) {
userService.saveWithPwd(getDataBean(), this.password);
} else {
super.doSave();
}
}
@Override
public boolean isCanSave() {
return password.equals(retPasswd) && isLoginFree() && getDataBean().getUsername() != null && !getDataBean().getUsername().isEmpty();
}
}

@ -0,0 +1,24 @@
package info.bukova.isspst.ui.users;
import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User;
import java.util.ArrayList;
import java.util.List;
public class UserRoles {
private List<RoleCheck> roleChecks;
public UserRoles(User user, List<Role> roles) {
roleChecks = new ArrayList<RoleCheck>();
for (Role r : roles) {
roleChecks.add(new RoleCheck(user, r));
}
}
public List<RoleCheck> getRoleChecks() {
return roleChecks;
}
}

@ -1,10 +1,12 @@
package info.bukova.isspst.ui; package info.bukova.isspst.ui.users;
import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zk.ui.select.annotation.WireVariable;
import info.bukova.isspst.data.User; import info.bukova.isspst.data.User;
import info.bukova.isspst.services.UserService; import info.bukova.isspst.filters.UserFilter;
import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.ui.ListViewModel;
public class UsersList extends ListViewModel<User> { public class UsersList extends ListViewModel<User> {
@ -16,6 +18,7 @@ public class UsersList extends ListViewModel<User> {
service = userService; service = userService;
dataClass = User.class; dataClass = User.class;
formZul = "userForm.zul"; formZul = "userForm.zul";
dataFilter = new UserFilter(getFilterTemplate());
} }
} }

@ -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('<div', this.domAttrs_(), '><div id="map_canvas">', this.getAddress(), '</div></span>');
}
});

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<package name="info.bukova.isspst.ui" language="xul/html" depends="zul">
<widget name="Mapa"/>
</package>

@ -7,6 +7,8 @@
<session-factory> <session-factory>
<mapping class="info.bukova.isspst.data.User"></mapping> <mapping class="info.bukova.isspst.data.User"></mapping>
<mapping class="info.bukova.isspst.data.Role"></mapping> <mapping class="info.bukova.isspst.data.Role"></mapping>
<mapping class="info.bukova.isspst.data.BaseData"></mapping>
<mapping class="info.bukova.isspst.data.Address"></mapping>
<mapping class="info.bukova.isspst.data.Building"></mapping> <mapping class="info.bukova.isspst.data.Building"></mapping>
</session-factory> </session-factory>
</hibernate-configuration> </hibernate-configuration>

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<language-addon>
<!-- The name of this addon. It must be unique -->
<addon-name>ckezbind</addon-name>
<!-- Specifies what other addon this depends
<depends></depends>
-->
<!-- Which language this addon will be added to -->
<language-name>xul/html</language-name>
<component>
<component-name>ckeditor</component-name>
<extends>ckeditor</extends>
<annotation>
<annotation-name>ZKBIND</annotation-name>
<property-name>value</property-name>
<attribute>
<attribute-name>ACCESS</attribute-name>
<attribute-value>both</attribute-value>
</attribute>
<attribute>
<attribute-name>SAVE_EVENT</attribute-name>
<attribute-value>onChange</attribute-value>
</attribute>
<attribute>
<attribute-name>LOAD_REPLACEMENT</attribute-name>
<attribute-value>value</attribute-value>
</attribute>
<attribute>
<attribute-name>LOAD_TYPE</attribute-name>
<attribute-value>java.lang.String</attribute-value>
</attribute>
</annotation>
</component>
</language-addon>

@ -1,5 +1,5 @@
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.dialect=org.hibernate.dialect.MySQLDialect jdbc.dialect=org.hibernate.dialect.MySQLDialect
jdbc.databaseurl=jdbc:mysql://127.0.0.1:3306/isspst jdbc.databaseurl=jdbc:mysql://127.0.0.1:3306/isspst?characterEncoding=utf8
jdbc.username=root jdbc.username=root
jdbc.password=xsacfgd jdbc.password=xsacfgd

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<language-addon>
<addon-name>mapa</addon-name>
<language-name>xul/html</language-name>
<component>
<component-name>mapa</component-name>
<component-class>info.bukova.isspst.ui.Mapa</component-class>
<widget-class>info.bukova.isspst.ui.Mapa</widget-class>
</component>
</language-addon>

@ -88,7 +88,13 @@
<property name="sessionFactory" ref="sessionFactory"/> <property name="sessionFactory" ref="sessionFactory"/>
</bean> </bean>
<bean id="addressDao" class="info.bukova.isspst.dao.jpa.AddressDaoJPA">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Business logic --> <!-- Business logic -->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
<bean id="userService" class="info.bukova.isspst.services.users.UserServiceImpl"> <bean id="userService" class="info.bukova.isspst.services.users.UserServiceImpl">
<property name="dao" ref="userDao"/> <property name="dao" ref="userDao"/>
<property name="encoder" ref="passwordEncoder"/> <property name="encoder" ref="passwordEncoder"/>
@ -98,4 +104,30 @@
<property name="dao" ref="roleDao"/> <property name="dao" ref="roleDao"/>
</bean> </bean>
<bean id="adbService" class="info.bukova.isspst.services.addressbook.AdbServiceImpl">
<property name="dao" ref="addressDao"/>
<property name="validator" ref="validator"/>
</bean>
<bean id="addressFinderAres" class="info.bukova.isspst.services.addressbook.AddressFinderAres">
<property name="aresUrl" value="http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi"/>
<property name="unmarsheller" ref="unmarshallerAres"/>
</bean>
<bean id="addressFinderTaxID" class="info.bukova.isspst.services.addressbook.AddressFinderTaxID">
<property name="aresDicUrl" value="http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_bas.cgi"/>
</bean>
<bean id="xmlCtxAres" class="org.castor.spring.xml.XMLContextFactoryBean">
<property name="mappingLocations">
<list>
<value>info/bukova/isspst/services/addressbook/mappingAres.xml</value>
</list>
</property>
</bean>
<bean id="unmarshallerAres" class="org.castor.spring.xml.CastorUnmarshallerFactoryBean">
<property name="xmlContext" ref="xmlCtxAres"/>
</bean>
</beans> </beans>

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<zk>
<!-- [Optional]
Uncomment if you want to defines the application's name
<preference>
<name>org.zkoss.zk.ui.WebApp.name</name>
<value>rsfaktura</value>
</preference>
-->
<client-config>
<debug-js>true</debug-js>
</client-config>
<library-property>
<name>org.zkoss.web.classWebResource.cache</name>
<value>false</value>
</library-property>
<language-config>
<addon-uri>/WEB-INF/mapa-lang-addon.xml</addon-uri>
<addon-uri>/WEB-INF/ckez-bind-lang-addon.xml</addon-uri>
</language-config>
<!-- <library-property>
<name>org.zkoss.zul.progressbox.position</name>
<value>center</value>
</library-property> -->
</zk>

@ -0,0 +1,30 @@
<?page title="${labels.FindResult}" contentType="text/html;charset=UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk>
<window id="findResult" title="Výsledek hledání" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.addressbook.AddressFindResult')"
closable="true" width="700px">
<style src="/app/form.css"/>
<listbox model="@load(vm.listResult)" height="300px" selectedItem="@bind(vm.selectedAddr)">
<listhead>
<listheader label="Firma" sort="auto(company)"/>
<listheader label="IČ"/>
<listheader label="Ulice"/>
<listheader label="Číslo domu" width="80px"/>
<listheader label="Město"/>
</listhead>
<template name="model">
<listitem>
<listcell label="@load(each.company)"/>
<listcell label="@load(each.ic)"/>
<listcell label="@load(each.street)"/>
<listcell label="@load(each.houseNumber)"/>
<listcell label="@load(each.city)"/>
</listitem>
</template>
</listbox>
<button label="Zvolit" onClick="@global-command('selectAddress', selected=vm.selectedAddr, window=findResult)" disabled="@bind(vm.selected)" sclass="nicebutton"/> <button label="Zavřít" onClick="findResult.detach()" sclass="nicebutton"/>
</window>
</zk>

@ -0,0 +1,78 @@
<?page title="Adresa" contentType="text/html;charset=UTF-8"?>
<zk>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window id="editWin" title="Adresa" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.addressbook.AddressForm')"
closable="true" width="600px">
<style src="/app/form.css"/>
<grid width="580px">
<columns>
<column label="" hflex="min"/>
<column label="" hflex="min"/>
<column label=""/>
<column label=""/>
</columns>
<rows>
<row>
<label value="Firma" /> <textbox value="@bind(vm.dataBean.company)" instant="true"/>
<label visible="true" value="@load(vm.errMessages['company'])" style="color:red"/>
<button image="/img/search.png" label="Hledat v ARESu" onClick="@command('searchAres')" sclass="nicebutton" disabled="@load((vm.dataBean.ic == 0) &amp;&amp; (empty vm.dataBean.company))" />
</row>
<row>
<label value="IČ" /> <textbox value="@bind(vm.dataBean.ic)"/>
</row>
<row>
<label value="DIČ" /> <textbox value="@bind(vm.dataBean.dic)"/>
</row>
<row>
<label value="Oddělení" /> <textbox value="@bind(vm.dataBean.department)"/>
</row>
<row>
<label value="Kontaktní osoba" /> <textbox value="@bind(vm.dataBean.contactName)"/>
</row>
<row>
<label value="Ulice" /> <textbox value="@bind(vm.dataBean.street)"/>
</row>
<row>
<label value="Číslo domu" /> <textbox value="@bind(vm.dataBean.houseNumber)"/>
</row>
<row>
<label value="Město" /> <textbox value="@bind(vm.dataBean.city)"/>
<label visible="true" value="@load(vm.errMessages['city'])" style="color:red"/>
</row>
<row>
<label value="PSČ" /> <textbox value="@bind(vm.dataBean.zipCode)"/>
</row>
<row>
<label value="Telefon" /> <textbox value="@bind(vm.dataBean.phone)"/>
</row>
<row>
<label value="E-mail" /> <textbox value="@bind(vm.dataBean.email)"/>
<label visible="true" value="@load(vm.errMessages['email'])" style="color:red"/>
</row>
<row>
<label value="Web" /> <textbox value="@bind(vm.dataBean.web)"/>
<label visible="true" value="@load(vm.errMessages['web'])" style="color:red"/>
</row>
</rows>
</grid>
<hlayout>
<panel>
<panelchildren>
<vlayout>
<panel>
<panelchildren><label value="Poznámka"/> </panelchildren>
</panel>
<panel>
<panelchildren><ckeditor height="65px" width="330px" toolbar="Basic" value="@bind(vm.dataBean.description)"/>
</panelchildren>
</panel>
</vlayout>
</panelchildren>
</panel>
</hlayout>
<include src="/app/formButtons.zul"/>
</window>
</zk>

@ -0,0 +1,89 @@
<?page title="Dodavatelé" contentType="text/html;charset=UTF-8"?>
<zk>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window title="Dodavatelé" border="normal"
apply="org.zkoss.bind.BindComposer" height="570px"
viewModel="@id('vm') @init('info.bukova.isspst.ui.addressbook.AddressList')">
<include src="/app/toolbar.zul"/>
<style src="/app/form.css"/>
<hbox width="100%">
<listbox id="dataGrid" model="@load(vm.dataList)" selectedItem="@bind(vm.dataBean)"
onAfterRender="@command('afterRender')" selectedIndex="@load(vm.selIndex)" hflex="6" height="480px">
<auxhead sclass="category-center" visible="@load(vm.filter)">
<auxheader>
<image src="/img/funnel.png" />
<textbox instant="true" width="85%"
value="@bind(vm.filterTemplate.company)" onChange="@command('doFilter')" />
</auxheader>
<auxheader>
<image src="/img/funnel.png" />
<textbox instant="true" width="85%"
value="@bind(vm.filterTemplate.ic)" onChange="@command('doFilter')" />
</auxheader>
<auxheader>
<image src="/img/funnel.png" />
<textbox instant="true" width="85%"
value="@bind(vm.filterTemplate.contactName)" onChange="@command('doFilter')"/>
</auxheader>
<auxheader>
<image src="/img/funnel.png" />
<textbox instant="true" width="85%"
value="@bind(vm.filterTemplate.street)" onChange="@command('doFilter')"/>
</auxheader>
<auxheader>
<image src="/img/funnel.png" />
<textbox instant="true" width="85%"
value="@bind(vm.filterTemplate.houseNumber)" onChange="@command('doFilter')"/>
</auxheader>
<auxheader>
<image src="/img/funnel.png" />
<textbox instant="true" width="85%"
value="@bind(vm.filterTemplate.city)" onChange="@command('doFilter')"/>
</auxheader>
</auxhead>
<listhead vflex="true">
<listheader label="Firma" sort="auto(company)" onSort="@command('onSort', column='company')" />
<listheader label="IČ" width="100px"/>
<listheader label="Kontaktní osoba"/>
<listheader label="Ulice"/>
<listheader label="Číslo domu" width="80px"/>
<listheader label="Město" sort="auto(city)" onSort="@command('onSort', column='city')"/>
</listhead>
<template name="model">
<listitem>
<listcell label="@load(each.company)"/>
<listcell label="@load(each.ic)"/>
<listcell label="@load(each.contactName)"/>
<listcell label="@load(each.street)"/>
<listcell label="@load(each.houseNumber)"/>
<listcell label="@load(each.city)"/>
</listitem>
</template>
</listbox>
<div hflex="4">
<label value="Detail:" sclass="bold"/>
<grid visible="@load(vm.dataBean ne null)" hflex="1">
<columns>
<column hflex="min"/>
<column/>
</columns>
<rows>
<row><label value="Oddělení"/><label value="@load(vm.dataBean.department)"/></row>
<row><label value="Telefon"/><label value="@load(vm.dataBean.phone)"/></row>
<row><label value="Email"/><label value="@load(vm.dataBean.email)"/></row>
<row><label value="Web"/><label value="@load(vm.dataBean.web)"/></row>
</rows>
</grid>
<label value="Poznámka:" visible="@load(not empty vm.dataBean.description)" sclass="bold"/>
<html style="font-family:arial,sans-serif;font-size:12px;" content="@load(vm.dataBean.description)"/>
<mapa address="@load((empty vm.dataBean.street ? vm.dataBean.city : vm.dataBean.street).concat(' ').concat(vm.dataBean.houseNumber).concat(', ').concat(vm.dataBean.city))" width="360px" height="180px" visible="@load(vm.dataBean ne null)"/>
</div>
</hbox>
</window>
</zk>

@ -0,0 +1,11 @@
<?page title="Dodavatelé" contentType="text/html;charset=UTF-8"?>
<?script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB6sVWLvFMvbK994Pa418XDhbDUZ6Xr4CQ&amp;sensor=false"?>
<zk>
<zscript>
String gridZul = "addressbook.zul";
</zscript>
<include src="/app/template.zhtml"/>
</zk>

@ -1,6 +1,34 @@
<?page title="Uživatel" contentType="text/html;charset=UTF-8"?> <?page title="Uživatel" contentType="text/html;charset=UTF-8"?>
<zk> <zk>
<window title="Uživatel" border="normal"> <window id="editWin" title="Uživatel" border="normal" closable="true" width="450px" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.users.UserForm')">
<style src="/app/form.css"/>
<grid width="440px">
<columns>
<column hflex="min"></column>
<column></column>
<column></column>
</columns>
<rows>
<row><label value="Login"/><textbox value="@bind(vm.dataBean.username)" instant="true" disabled="@load(vm.edit)" onChange="@command('checkLogin')"/><label value="Login je obsazený" sclass="error" visible="@load(not vm.loginFree)"/></row>
<row><label value="Jméno"/><textbox value="@bind(vm.dataBean.firstName)"/></row>
<row><label value="Příjmení"/><textbox value="@bind(vm.dataBean.lastName)"/></row>
<row><label value="Osobní číslo"/><textbox value="@bind(vm.dataBean.personalNumber)" width="90px"/></row>
<row><label value="E-mail"/><textbox value="@bind(vm.dataBean.email)"/></row>
<row><label value=""/><checkbox label="Zasílat upozornění" checked="@bind(vm.dataBean.notify)"/></row>
<row><label value="Heslo"/><textbox value="@bind(vm.password)" type="password" instant="true"/></row>
<row><label value="Znova heslo"/><textbox value="@bind(vm.retPasswd)" type="password" instant="true"/><label value="Hesla nesouhlasí" sclass="error" visible="@load(not vm.pwMatches)"/></row>
<row><label value=""/><checkbox label="Aktivní" checked="@bind(vm.dataBean.enabled)"/></row>
</rows>
</grid>
<groupbox mold="3d">
<caption label="Role"/>
<vbox children="@load(vm.userRoles.roleChecks)">
<template name="children">
<checkbox label="@load(each.role.description)" checked="@bind(each.checked)"/>
</template>
</vbox>
</groupbox>
<button image="/img/save.png" label="Uložit" onClick="@command('save', window=editWin) @global-command('refresh')" disabled="@load(not vm.canSave)" sclass="nicebutton" /><button image="~./zul/img/misc/drag-disallow.png" label="Zavřít" onClick="editWin.detach()" sclass="nicebutton"/>
</window> </window>
</zk> </zk>

@ -2,25 +2,41 @@
<zk> <zk>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window title="Uživatelé" border="normal" apply="org.zkoss.bind.BindComposer" <window title="Uživatelé" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.UsersList')"> viewModel="@id('vm') @init('info.bukova.isspst.ui.users.UsersList')" height="570px">
<toolbar>
<toolbarbutton image="/img/add.png" tooltiptext="${labels.New}" id="btnNew" onClick="@command('addNew')" disabled="@load(vm.filter)" />
<toolbarbutton image="/img/edit.png" tooltiptext="${labels.Edit}" id="btnEdit" onClick="@command('edit')" disabled="@load(empty vm.dataBean ? 'true' : 'false')"/>
<toolbarbutton image="/img/delete.png" tooltiptext="${labels.Delete}" id="btnDelete" onClick="@command('delObject')" disabled="@load(empty vm.dataBean ? 'true' : 'false')"/>
<toolbarbutton image="/img/funnel.png" tooltiptext="${labels.Filter}" id="btnFilter" onClick="@command('filter')" />
</toolbar>
<include src="/app/toolbar.zul"/>
<listbox model="@load(vm.dataList)" selectedItem="@bind(vm.dataBean)"> <listbox model="@load(vm.dataList)" selectedItem="@bind(vm.dataBean)">
<auxhead sclass="category-center" visible="@load(vm.filter)">
<auxheader>
<image src="/img/funnel.png" />
<textbox value="@bind(vm.filterTemplate.username)" instant="true" onChange="@command('doFilter')"/>
</auxheader>
<auxheader>
<image src="/img/funnel.png" />
<textbox value="@bind(vm.filterTemplate.personalNumber)" instant="true" onChange="@command('doFilter')"/>
</auxheader>
<auxheader>
<image src="/img/funnel.png" />
<textbox value="@bind(vm.filterTemplate.firstName)" instant="true" onChange="@command('doFilter')"/>
</auxheader>
<auxheader>
<image src="/img/funnel.png" />
<textbox value="@bind(vm.filterTemplate.lastName)" instant="true" onChange="@command('doFilter')"/>
</auxheader>
</auxhead>
<listhead> <listhead>
<listheader label="Login"/> <listheader label="Login"/>
<listheader label="Celé jméno"/> <listheader label="Osobní číslo"/>
<listheader label="Jméno"/>
<listheader label="Příjmení"/>
</listhead> </listhead>
<template name="model"> <template name="model">
<listitem> <listitem>
<listcell label="@load(each.username)"/> <listcell label="@load(each.username)"/>
<listcell label="@load(each.fullName)"/> <listcell label="@load(each.personalNumber)"/>
<listcell label="@load(each.firstName)"/>
<listcell label="@load(each.lastName)"/>
</listitem> </listitem>
</template> </template>
</listbox> </listbox>

@ -0,0 +1,55 @@
.nicebutton {
font-family: Arial;
color: #050005;
font-size: 12px;
padding-top: 3px;
padding-right: 10px;
padding-bottom: 3px;
padding-left: 10px;
margin: 4px;
text-decoration: none;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0px 1px 3px #666666;
-moz-box-shadow: 0px 1px 3px #666666;
box-shadow: 0px 1px 3px #666666;
text-shadow: 1px 1px 2px #666666;
border: solid #8abaed 1px;
background: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#efefef));
background: -moz-linear-gradient(top, #ffffff, #efefef);
-ms-filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#ffffff, endColorStr=#efefef);
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#ffffff, endColorStr=#efefef);
display:inline-block; /* IE is so silly */
}
.nicebutton:hover {
background: #c5e8fa;
}
.nicebutton:disabled {
font-family: Arial;
color: #c4c4c4;
font-size: 12px;
padding-top: 3px;
padding-right: 10px;
padding-bottom: 3px;
padding-left: 10px;
margin: 5px;
text-decoration: none;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0px 1px 3px #666666;
-moz-box-shadow: 0px 1px 3px #666666;
text-shadow: 0px 0px 0px #9e9e9e;
box-shadow: 0px 1px 3px #666666;
border: solid #d91c71 0px;
background: #ebebeb;
}
.error {
color: red;
}
.bold {
font-weight: bold;
}

@ -0,0 +1,4 @@
<?page title="buttons" contentType="text/html;charset=UTF-8"?>
<zk>
<button image="/img/save.png" label="Uložit" onClick="@command('save', window=editWin) @global-command('refresh')" sclass="nicebutton" /><button image="~./zul/img/misc/drag-disallow.png" label="Zrušit" onClick="editWin.detach()" sclass="nicebutton"/>
</zk>

@ -31,6 +31,7 @@
<menuitem label="Střediska" href="/admin/users" disabled="${not sec:isAllGranted('ROLE_ADMIN')}"/> <menuitem label="Střediska" href="/admin/users" disabled="${not sec:isAllGranted('ROLE_ADMIN')}"/>
<menuitem label="${labels.AgendaBuildings}" href="/buildings"/> <menuitem label="${labels.AgendaBuildings}" href="/buildings"/>
<menuitem label="Místnosti" href="/admin/users"/> <menuitem label="Místnosti" href="/admin/users"/>
<menuitem label="Dodavatelé" href="/admin/addressbook"/>
</menubar> </menubar>
</tabpanel> </tabpanel>
<tabpanel> <tabpanel>

@ -2,6 +2,46 @@
<html xmlns="native" xmlns:u="zul" xmlns:zk="zk"> <html xmlns="native" xmlns:u="zul" xmlns:zk="zk">
<u:style src="/app/page.css"/> <u:style src="/app/page.css"/>
<script type="text/javascript">
zk.afterLoad("zk", function () {
var oldProgressbox = zUtl.progressbox;
zUtl.progressbox = function () {
oldProgressbox.apply(this, arguments);
var $mask = jq('.z-loading');
if ($mask) {
var $img = jq('.z-loading-indicator'),
$body = jq(document.body),
body = $body[0],
bw = $body.width() + body.scrollLeft - 10,
bh = $body.height() + body.scrollTop - 10;
// update mask and image's style
$mask.width(bw);
$mask.height(bh);
$mask.css('opacity', .75);
$img.width('150px');
$img.css('margin-left', (bw - $img.width()) / 2 + 'px');
$img.css('margin-top', (bh - $img.height()) / 2 + 'px');
// update mask size when window scroll
if (!window.eventBinded) {
var $win = jq(window);
$win.scroll(function () {
var $maskInst = jq('.z-loading');
if ($maskInst[0]) {
$maskInst.width(bw + $win.scrollLeft());
$maskInst.height(bh + $win.scrollTop());
}
});
window.eventBinded = true;
}
}
}
});
</script>
<div id="container">
<div id="header"> <div id="header">
hlavicka hlavicka
</div> </div>
@ -11,11 +51,13 @@
</div> </div>
<div id="maincolumn"> <div id="maincolumn">
<u:include src="${gridZul}"/> <u:include src="${gridZul}"/>
</div> </div>
<div id="footer">Footer <div id="footer">Footer
</div> </div>
</div>
</html> </html>

@ -0,0 +1,9 @@
<?page title="toolbar" contentType="text/html;charset=UTF-8"?>
<zk>
<toolbar>
<toolbarbutton image="/img/add.png" tooltiptext="Nový" id="btnNew" onClick="@command('addNew')" disabled="@load(vm.filter)" />
<toolbarbutton image="/img/edit.png" tooltiptext="Upravit" id="btnEdit" onClick="@command('edit')" disabled="@load(empty vm.dataBean ? 'true' : 'false')"/>
<toolbarbutton image="/img/delete.png" tooltiptext="Smazat" id="btnDelete" onClick="@command('delete')" disabled="@load(empty vm.dataBean ? 'true' : 'false')"/>
<toolbarbutton image="/img/funnel.png" tooltiptext="Filtr" id="btnFilter" onClick="@command('filter')" />
</toolbar>
</zk>

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Loading…
Cancel
Save