Compare commits
60 Commits
multitenant
..
1.5
| Author | SHA1 | Date | |
|---|---|---|---|
| b470559cb7 | |||
| f13bc6e5c4 | |||
| 884bc8267d | |||
| ecbc2be47c | |||
| 4e2b00a957 | |||
| d9fd26bbad | |||
| e461afd611 | |||
| ba99079a85 | |||
| a0447318e6 | |||
| 8e33bb8ef7 | |||
| d37076cd27 | |||
| 780edd5678 | |||
| e51955f86a | |||
| 26699fd3a9 | |||
| ce17f5b626 | |||
| 2a6ce7e4d3 | |||
| f4fe974931 | |||
| 537cc563ac | |||
| 4cd2f5b5e6 | |||
| 6ff69c932c | |||
| 908b214a93 | |||
| cd2214c7ef | |||
| 66133dce1a | |||
| b1818546c0 | |||
| bc5a7a7c4c | |||
| 966c9033ef | |||
| 08dfb177ef | |||
| 3c3cf5d46f | |||
| 26e733a537 | |||
| c521fc3c87 | |||
| 9f07c52f2c | |||
| 6737d44d62 | |||
| 9ca4908ce4 | |||
| 4c033deffb | |||
| 9088a88b9a | |||
| a9a98cfd63 | |||
| babb9f8312 | |||
| 7c6a43baf6 | |||
| d2bcfc727d | |||
| fc2fa76402 | |||
| ab9a5577d9 | |||
| bd37a7081a | |||
| 8f248de094 | |||
| 6ccd2a91a3 | |||
| 9175a7911f | |||
| b2d141e52b | |||
| a1c400aa27 | |||
| f1ca2d11c8 | |||
| 3558d1bd50 | |||
| eaf37147dc | |||
| 13f35611fd | |||
| 3725e9473d | |||
| 412db2a394 | |||
| b8a734f817 | |||
| b932d390ca | |||
| 882993ef17 | |||
| 44178c52e6 | |||
| a10abe6961 | |||
| 18920701a7 | |||
| 5b380386bd |
@@ -202,12 +202,6 @@
|
||||
</dependency>
|
||||
|
||||
<!-- DB -->
|
||||
<dependency>
|
||||
<groupId>postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>9.1-901-1.jdbc4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
|
||||
@@ -11,6 +11,7 @@ import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.reporting.Report;
|
||||
import info.bukova.isspst.reporting.ReportMapping;
|
||||
import info.bukova.isspst.reporting.ReportType;
|
||||
import info.bukova.isspst.services.dbinfo.DbInfoService;
|
||||
import info.bukova.isspst.services.munits.MUnitService;
|
||||
import info.bukova.isspst.services.numberseries.NumberSeriesService;
|
||||
import info.bukova.isspst.services.requirement.RequirementTypeService;
|
||||
@@ -33,6 +34,8 @@ import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
public class AppInitListener implements ServletContextListener {
|
||||
|
||||
|
||||
private DbInfoService dbInfoService;
|
||||
private MUnitService mUnitsService;
|
||||
private RoleService roleService;
|
||||
private UserService userService;
|
||||
@@ -48,10 +51,11 @@ public class AppInitListener implements ServletContextListener {
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent evt) {
|
||||
/*Logger logger = LoggerFactory.getLogger(AppInitListener.class);
|
||||
Logger logger = LoggerFactory.getLogger(AppInitListener.class);
|
||||
logger.info("Initializing database");
|
||||
|
||||
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(evt.getServletContext());
|
||||
dbInfoService = ctx.getBean(DbInfoService.class);
|
||||
mUnitsService = ctx.getBean(MUnitService.class);
|
||||
roleService = ctx.getBean(RoleService.class);
|
||||
userService = ctx.getBean(UserService.class);
|
||||
@@ -61,6 +65,7 @@ public class AppInitListener implements ServletContextListener {
|
||||
reqTypeService = ctx.getBean(RequirementTypeService.class);
|
||||
|
||||
userService.grantAdmin();
|
||||
this.checkDbInfo();
|
||||
checkMUnits();
|
||||
checkRoles();
|
||||
checkUsers();
|
||||
@@ -71,7 +76,25 @@ public class AppInitListener implements ServletContextListener {
|
||||
this.checkGlobalSettings();
|
||||
userService.removeAccess();
|
||||
|
||||
loadModuleReports();*/
|
||||
loadModuleReports();
|
||||
}
|
||||
|
||||
private void checkDbInfo()
|
||||
{
|
||||
List<User> userList = userService.getAll();
|
||||
|
||||
if (userList.isEmpty())
|
||||
{
|
||||
// Database is new/empty, column definition is anotated - set actual
|
||||
// database version
|
||||
dbInfoService.updateDatabaseVersion();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Existing database - try change structure and set actual database
|
||||
// version...
|
||||
dbInfoService.changeDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkMUnits()
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
|
||||
public class BooleanUtils
|
||||
{
|
||||
public static boolean isEqualByBoolean(Boolean b1, Boolean b2)
|
||||
{
|
||||
boolean bool1 = ((b1 == null) ? false : b1.booleanValue());
|
||||
boolean bool2 = ((b2 == null) ? false : b2.booleanValue());
|
||||
boolean equals = (bool1 == bool2);
|
||||
return equals;
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider;
|
||||
|
||||
public class ClientConnectionPrivider implements MultiTenantConnectionProvider {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2142963179208004018L;
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
public ClientConnectionPrivider(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean isUnwrappableAs(Class unwrapType) {
|
||||
return ConnectionProvider.class.equals( unwrapType ) || MultiTenantConnectionProvider.class.equals( unwrapType ) || ClientConnectionPrivider.class.isAssignableFrom( unwrapType );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> unwrapType) {
|
||||
if ( isUnwrappableAs( unwrapType ) ) {
|
||||
return (T) this;
|
||||
}
|
||||
else {
|
||||
throw new UnknownUnwrapTypeException( unwrapType );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getAnyConnection() throws SQLException {
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseAnyConnection(Connection connection) throws SQLException {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection(String tenantIdentifier)
|
||||
throws SQLException {
|
||||
|
||||
Connection con = getAnyConnection();
|
||||
try {
|
||||
con.createStatement().execute("SET schema '" + tenantIdentifier + "'");
|
||||
} catch ( SQLException e ) {
|
||||
throw new HibernateException("Could not alter JDBC connection to specified schema [" + tenantIdentifier + "]", e);
|
||||
}
|
||||
|
||||
return con;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseConnection(String tenantIdentifier, Connection connection)
|
||||
throws SQLException {
|
||||
releaseAnyConnection(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsAggressiveRelease() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class ClientResolver implements CurrentTenantIdentifierResolver {
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
private static final String TOP_DOMAIN = "localhost"; // Bude se tahat z konfigurace...
|
||||
|
||||
@Override
|
||||
public String resolveCurrentTenantIdentifier() {
|
||||
String hostName = request.getServerName();
|
||||
String tenant = "";
|
||||
|
||||
if (hostName.contains(".")) {
|
||||
tenant = hostName.substring(0, hostName.indexOf("." + TOP_DOMAIN));
|
||||
}
|
||||
|
||||
if (tenant.isEmpty()) {
|
||||
tenant = "public";
|
||||
}
|
||||
|
||||
return tenant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateExistingCurrentSessions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import info.bukova.isspst.data.DataModel;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class CommonUrlResolver implements EntityUrlResolver {
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
protected String defaultUrl;
|
||||
|
||||
public CommonUrlResolver() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String entityUrl(Object entity) {
|
||||
if (defaultUrl == null) {
|
||||
this.defaultUrl = request.getRequestURL().toString();
|
||||
this.defaultUrl = defaultUrl.substring(0, defaultUrl.indexOf(request.getServletPath()));
|
||||
}
|
||||
|
||||
if (!DataModel.class.isAssignableFrom(entity.getClass())) {
|
||||
return defaultUrl + "/app";
|
||||
}
|
||||
|
||||
String url = Constants.URL_MAP.get(entity.getClass());
|
||||
|
||||
if (url == null) {
|
||||
return defaultUrl + "/app";
|
||||
}
|
||||
|
||||
return defaultUrl + url + "?select=" + String.valueOf(((DataModel)entity).getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,15 +2,18 @@ package info.bukova.isspst;
|
||||
|
||||
import info.bukova.isspst.data.Permission;
|
||||
import info.bukova.isspst.data.PermissionType;
|
||||
import info.bukova.isspst.data.Requirement;
|
||||
import info.bukova.isspst.data.RequirementType;
|
||||
import info.bukova.isspst.data.Role;
|
||||
import info.bukova.isspst.data.TripRequirement;
|
||||
import info.bukova.isspst.reporting.Report;
|
||||
import info.bukova.isspst.reporting.ReportMapping;
|
||||
import info.bukova.isspst.services.addressbook.AdbService;
|
||||
import info.bukova.isspst.services.approved.ApprovedService;
|
||||
import info.bukova.isspst.services.approved.OrderService;
|
||||
import info.bukova.isspst.services.buildings.BuildingService;
|
||||
import info.bukova.isspst.services.invoicing.InvoicingService;
|
||||
import info.bukova.isspst.services.munits.MUnitService;
|
||||
import info.bukova.isspst.services.orders.ApprovedService;
|
||||
import info.bukova.isspst.services.orders.OrderService;
|
||||
import info.bukova.isspst.services.reqsubjects.MaterialService;
|
||||
import info.bukova.isspst.services.reqsubjects.ServiceItemService;
|
||||
import info.bukova.isspst.services.requirement.RequirementService;
|
||||
@@ -21,8 +24,14 @@ import info.bukova.isspst.services.users.RoleService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public final static long DB_VERSION = 2;
|
||||
|
||||
public final static String DEF_ADMIN = "admin";
|
||||
public final static String DEF_ADMIN_PASSWD = "admin";
|
||||
public final static String ROLE_USER = "ROLE_USER";
|
||||
@@ -71,6 +80,7 @@ public class Constants {
|
||||
public final static String MOD_TRIPBILL = "TRIPBILL";
|
||||
public final static String MOD_APPROVED = "APPROVED";
|
||||
public final static String MOD_ORDER = "ORDER";
|
||||
public final static String MOD_INVOICING = "INVOICING";
|
||||
public final static Module MODULES[] = {
|
||||
new Module(MOD_USERS, "Uživatelé", UserService.class),
|
||||
new Module(MOD_PERMISSIONS, "Práva", RoleService.class),
|
||||
@@ -85,7 +95,8 @@ public class Constants {
|
||||
new Module(MOD_WORKFLOW, "Procesy schválení", RequirementTypeService.class),
|
||||
new Module(MOD_TRIPBILL, "Cestovní příkazy", TripBillService.class),
|
||||
new Module(MOD_APPROVED, "Schválené položky požadavků", ApprovedService.class),
|
||||
new Module(MOD_ORDER, "Objednávky", OrderService.class) };
|
||||
new Module(MOD_ORDER, "Objednávky", OrderService.class),
|
||||
new Module(MOD_INVOICING, "Fakturace požadavků", InvoicingService.class) };
|
||||
|
||||
public final static String PERM_APPROVE = "PERM_APPROVE";
|
||||
public final static String PERM_SHOW_WORKGROUP_REQ = "PERM_SHOW_WORKGROUP_REQ";
|
||||
@@ -93,15 +104,18 @@ public class Constants {
|
||||
public final static String PERM_SHOW_ALL_REQ = "PERM_SHOW_ALL_REQ";
|
||||
public final static String PERM_EDIT_NEW = "PERM_EDIT_NEW";
|
||||
public final static String PERM_EDIT_OWN = "PERM_EDIT_OWN";
|
||||
public final static String PERM_DELETE_NEW = "PERM_DELETE_NEW";
|
||||
|
||||
public final static Permission SPECIAL_PERMISSIONS[] = {
|
||||
new Permission(PERM_EDIT_NEW, "Upravit neschválené", MOD_REQUIREMENTS, PermissionType.GLOBAL),
|
||||
new Permission(PERM_DELETE_NEW, "Mazat neschválené", MOD_REQUIREMENTS, PermissionType.GLOBAL),
|
||||
new Permission(PERM_SHOW_WORKGROUP_REQ, "Zobrazení požadavků komise", MOD_REQUIREMENTS, PermissionType.WORKGROUP),
|
||||
new Permission(PERM_SHOW_CENTRE_REQ, "Zobrazení požadavků střediska", MOD_REQUIREMENTS, PermissionType.CENTRE),
|
||||
new Permission(PERM_SHOW_ALL_REQ, "Zobrazení všech požadavků", MOD_REQUIREMENTS, PermissionType.GLOBAL),
|
||||
new Permission(PERM_APPROVE, "Schválení", MOD_REQUIREMENTS, PermissionType.WORKGROUP),
|
||||
|
||||
new Permission(PERM_EDIT_NEW, "Upravit neschválené", MOD_TRIPREQUIREMENTS, PermissionType.GLOBAL),
|
||||
new Permission(PERM_DELETE_NEW, "Mazat neschválené", MOD_TRIPREQUIREMENTS, PermissionType.GLOBAL),
|
||||
new Permission(PERM_SHOW_WORKGROUP_REQ, "Zobrazení požadavků komise", MOD_TRIPREQUIREMENTS, PermissionType.WORKGROUP),
|
||||
new Permission(PERM_SHOW_CENTRE_REQ, "Zobrazení požadavků střediska", MOD_TRIPREQUIREMENTS, PermissionType.CENTRE),
|
||||
new Permission(PERM_SHOW_ALL_REQ, "Zobrazení všech požadavků", MOD_TRIPREQUIREMENTS, PermissionType.GLOBAL),
|
||||
@@ -114,7 +128,8 @@ public class Constants {
|
||||
new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresa", "address", false, true)),
|
||||
new ReportMapping(MOD_TRIPBILL, new Report("Žádost", "tripRequirement", false, true)),
|
||||
new ReportMapping(MOD_TRIPBILL, new Report("Vyúčtování", "tripBill", false, true)),
|
||||
new ReportMapping(MOD_ORDER, new Report("Objednávka", "order", true, true))
|
||||
new ReportMapping(MOD_ORDER, new Report("Objednávka", "order", true, true)),
|
||||
new ReportMapping(MOD_REQUIREMENTS, new Report("Požadavky", "requirements"))
|
||||
};
|
||||
|
||||
public final static String REQTYPE_ORDER = "ORDER";
|
||||
@@ -126,4 +141,13 @@ public class Constants {
|
||||
|
||||
public final static long REQ_TYPE_MATERIAL = 1;
|
||||
public final static long REQ_TYPE_SERVICES = 2;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public final static Map<Class<?>, String> URL_MAP = Collections.unmodifiableMap(new HashMap<Class<?>, String>() {{
|
||||
put(Requirement.class, "/main/orders/");
|
||||
put(TripRequirement.class, "/main/trips/requirements/");
|
||||
}} );
|
||||
|
||||
public final static int LEN_TEXT = 255;
|
||||
public final static int LEN_DESCRIPTION = 8192;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
public interface EntityUrlResolver {
|
||||
|
||||
public String entityUrl(Object entity);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import info.bukova.isspst.data.Requirement;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class RequirementUrlResolver implements EntityUrlResolver {
|
||||
|
||||
private String defaultUrl;
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public RequirementUrlResolver() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String entityUrl(Object entity) {
|
||||
if (!(entity instanceof Requirement)) {
|
||||
return defaultUrl + "/app";
|
||||
}
|
||||
|
||||
if (defaultUrl == null) {
|
||||
this.defaultUrl = request.getRequestURL().toString();
|
||||
this.defaultUrl = defaultUrl.substring(0, defaultUrl.indexOf(request.getServletPath()));
|
||||
}
|
||||
|
||||
Requirement req = (Requirement)entity;
|
||||
|
||||
if (req.getKind() == Constants.REQ_TYPE_MATERIAL) {
|
||||
return defaultUrl + Constants.URL_MAP.get(req.getClass()) + "material/?select=" + String.valueOf(req.getId());
|
||||
} else {
|
||||
return defaultUrl + Constants.URL_MAP.get(req.getClass()) + "services/?select=" + String.valueOf(req.getId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.util.resource.Labels;
|
||||
@@ -7,12 +8,12 @@ import org.zkoss.util.resource.Labels;
|
||||
public class StringUtils
|
||||
{
|
||||
|
||||
private static String nullStr(String str)
|
||||
public static String nullToEmptyString(String str)
|
||||
{
|
||||
return str == null ? "" : str;
|
||||
}
|
||||
|
||||
private static String not0ToStr(long i)
|
||||
private static String zeroToEmptyString(long i)
|
||||
{
|
||||
return i == 0 ? "" : String.valueOf(i);
|
||||
}
|
||||
@@ -60,8 +61,8 @@ public class StringUtils
|
||||
|
||||
public static boolean isEqualForFilter(String value, String search)
|
||||
{
|
||||
value = StringUtils.nullStr(value).toLowerCase();
|
||||
search = StringUtils.nullStr(search).toLowerCase();
|
||||
value = StringUtils.nullToEmptyString(value).toLowerCase();
|
||||
search = StringUtils.nullToEmptyString(search).toLowerCase();
|
||||
|
||||
if (search.isEmpty())
|
||||
{
|
||||
@@ -73,8 +74,8 @@ public class StringUtils
|
||||
|
||||
public static boolean isIcEqualForFilter(long value, long search)
|
||||
{
|
||||
String compareValue = StringUtils.not0ToStr(value);
|
||||
String searchValue = StringUtils.not0ToStr(search);
|
||||
String compareValue = StringUtils.zeroToEmptyString(value);
|
||||
String searchValue = StringUtils.zeroToEmptyString(search);
|
||||
return compareValue.startsWith(searchValue);
|
||||
}
|
||||
|
||||
@@ -124,7 +125,7 @@ public class StringUtils
|
||||
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
{
|
||||
String item = StringUtils.nullStr(list.get(i));
|
||||
String item = StringUtils.nullToEmptyString(list.get(i));
|
||||
result = StringUtils.addSeparator(result, separator);
|
||||
result += item;
|
||||
}
|
||||
@@ -138,7 +139,7 @@ public class StringUtils
|
||||
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
{
|
||||
String item = StringUtils.nullStr(list.get(i));
|
||||
String item = StringUtils.nullToEmptyString(list.get(i));
|
||||
|
||||
if (!item.isEmpty())
|
||||
{
|
||||
@@ -149,4 +150,47 @@ public class StringUtils
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> split(String value, String separator)
|
||||
{
|
||||
String tmp = value;
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
if (tmp != null)
|
||||
{
|
||||
if ((separator == null) || separator.isEmpty() || tmp.isEmpty())
|
||||
{
|
||||
list.add(tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
int separatorLength = separator.length();
|
||||
|
||||
while (!tmp.isEmpty())
|
||||
{
|
||||
String part = "";
|
||||
int idx = tmp.indexOf(separator);
|
||||
|
||||
if (idx > -1)
|
||||
{
|
||||
part = tmp.substring(0, idx);
|
||||
list.add(part);
|
||||
tmp = tmp.substring(idx + separatorLength);
|
||||
|
||||
if (tmp.isEmpty())
|
||||
{
|
||||
list.add("");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list.add(tmp);
|
||||
tmp = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class UrlResolverHolder {
|
||||
|
||||
private EntityUrlResolver commonResolver;
|
||||
private Map<Class<?>, EntityUrlResolver> resolvers;
|
||||
|
||||
public UrlResolverHolder(EntityUrlResolver common) {
|
||||
this.commonResolver = common;
|
||||
resolvers = new HashMap<Class<?>, EntityUrlResolver>();
|
||||
}
|
||||
|
||||
public void setResolvers(Map<Class<?>, EntityUrlResolver> resolvers) {
|
||||
this.resolvers = resolvers;
|
||||
}
|
||||
|
||||
public EntityUrlResolver resolverFor(Class<?> clazz) {
|
||||
EntityUrlResolver res = resolvers.get(clazz);
|
||||
|
||||
if (res == null) {
|
||||
return commonResolver;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package info.bukova.isspst.dao;
|
||||
|
||||
import info.bukova.isspst.data.DbInfo;
|
||||
|
||||
public interface DbInfoDao extends BaseDao<DbInfo>
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package info.bukova.isspst.dao;
|
||||
|
||||
import info.bukova.isspst.data.Invoicing;
|
||||
|
||||
public interface InvoicingDao extends BaseDao<Invoicing> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package info.bukova.isspst.dao;
|
||||
|
||||
import info.bukova.isspst.data.RequirementItem;
|
||||
|
||||
public interface RequirementItemDao extends BaseDao<RequirementItem>
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package info.bukova.isspst.dao.jpa;
|
||||
|
||||
import info.bukova.isspst.dao.DbInfoDao;
|
||||
import info.bukova.isspst.data.DbInfo;
|
||||
|
||||
public class DbInfoDaoJPA extends BaseDaoJPA<DbInfo> implements DbInfoDao
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package info.bukova.isspst.dao.jpa;
|
||||
|
||||
import info.bukova.isspst.dao.InvoicingDao;
|
||||
import info.bukova.isspst.data.Invoicing;
|
||||
|
||||
public class InvoicingDaoJPA extends BaseDaoJPA<Invoicing> implements InvoicingDao {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package info.bukova.isspst.dao.jpa;
|
||||
|
||||
import info.bukova.isspst.dao.RequirementItemDao;
|
||||
import info.bukova.isspst.data.RequirementItem;
|
||||
|
||||
public class RequirementItemDaoJPA extends BaseDaoJPA<RequirementItem> implements RequirementItemDao
|
||||
{
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -45,7 +46,7 @@ public class Address extends BaseData
|
||||
private String email;
|
||||
@Column(name = "WEB")
|
||||
private String web;
|
||||
@Column(name = "DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
|
||||
@NotNull(message = "Zadejte firmu")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -23,7 +25,7 @@ public class Building extends BaseData implements DataModel {
|
||||
@Column(name = "NAME")
|
||||
private String name;
|
||||
|
||||
@Column(name = "DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "building", orphanRemoval = true)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "DBINFO")
|
||||
public class DbInfo extends BaseSimpleData
|
||||
{
|
||||
@Column(name = "VERSION")
|
||||
private long version;
|
||||
|
||||
public DbInfo()
|
||||
{
|
||||
this.version = 0;
|
||||
}
|
||||
|
||||
public long getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(long version)
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
|
||||
@Entity
|
||||
@Table(name = "INVOICING")
|
||||
public class Invoicing extends BaseData {
|
||||
|
||||
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "REQUIREMENT_ID")
|
||||
private Requirement requirement;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
@JoinColumn(name = "INVOICING_ID")
|
||||
private List<InvoicingItem> items;
|
||||
|
||||
@Column(name = "TOTAL_INVOICED", precision = 15, scale = 4)
|
||||
private BigDecimal totalInvoiced;
|
||||
|
||||
public Requirement getRequirement() {
|
||||
return requirement;
|
||||
}
|
||||
|
||||
public void setRequirement(Requirement requirement) {
|
||||
this.requirement = requirement;
|
||||
}
|
||||
|
||||
public List<InvoicingItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<InvoicingItem> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalInvoiced() {
|
||||
return totalInvoiced;
|
||||
}
|
||||
|
||||
public void setTotalInvoiced(BigDecimal totalInvoiced) {
|
||||
this.totalInvoiced = totalInvoiced;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "INVOICING_ITEM")
|
||||
public class InvoicingItem {
|
||||
|
||||
@Id
|
||||
@Column(name = "ID")
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@Column(name = "INVOICE_DATE")
|
||||
private Date invoiceDate;
|
||||
|
||||
@Column(name = "INVOICE_NUMBER")
|
||||
private String invoiceNumber;
|
||||
|
||||
@Column(name = "AMOUNT", precision = 15, scale = 4)
|
||||
private BigDecimal amount;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getInvoiceDate() {
|
||||
return invoiceDate;
|
||||
}
|
||||
|
||||
public void setInvoiceDate(Date invoiceDate) {
|
||||
this.invoiceDate = invoiceDate;
|
||||
}
|
||||
|
||||
public String getInvoiceNumber() {
|
||||
return invoiceNumber;
|
||||
}
|
||||
|
||||
public void setInvoiceNumber(String invoiceNumber) {
|
||||
this.invoiceNumber = invoiceNumber;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
if (obj instanceof InvoicingItem)
|
||||
{
|
||||
InvoicingItem item = (InvoicingItem)obj;
|
||||
|
||||
int thisId = this.getId();
|
||||
int itemId = item.getId();
|
||||
boolean equalsId = (thisId == itemId);
|
||||
|
||||
if (equalsId && (thisId == 0))
|
||||
{
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
return equalsId;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
|
||||
import javax.persistence.Column;
|
||||
@@ -13,7 +14,7 @@ public class MUnit extends BaseData
|
||||
@Column(name = "NAME")
|
||||
private String name;
|
||||
|
||||
@Column(name = "DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
|
||||
public String getName()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
|
||||
import javax.persistence.Column;
|
||||
@@ -14,11 +15,14 @@ public class MUnitEmb
|
||||
@Column(name = "MUNIT_NAME")
|
||||
private String name;
|
||||
|
||||
@Column(name = "MUNIT_DESCRIPTION")
|
||||
@Column(name = "MUNIT_DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
|
||||
public MUnitEmb()
|
||||
{
|
||||
// Embeddable object is loaded by hibernate like NULL, if all properties
|
||||
// are NULL. So, we set ID.
|
||||
this.id = 0;
|
||||
}
|
||||
|
||||
public MUnitEmb(MUnit munit)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -19,7 +21,7 @@ import org.hibernate.annotations.LazyCollectionOption;
|
||||
|
||||
@Entity
|
||||
@Table(name = "ORDERS")
|
||||
public class Order extends BaseData
|
||||
public class Order extends BaseData implements Cloneable
|
||||
{
|
||||
|
||||
@Column(name = "NUMSER")
|
||||
@@ -35,7 +37,7 @@ public class Order extends BaseData
|
||||
@AttributeOverride(name = "company", column = @Column(name = "SUPPLIER_COMPANY")),
|
||||
@AttributeOverride(name = "contactName", column = @Column(name = "SUPPLIER_CONTACT_NAME")),
|
||||
@AttributeOverride(name = "department", column = @Column(name = "SUPPLIER_DEPARTMENT")),
|
||||
@AttributeOverride(name = "description", column = @Column(name = "SUPPLIER_DESCRIPTION")),
|
||||
@AttributeOverride(name = "description", column = @Column(name = "SUPPLIER_DESCRIPTION", length = Constants.LEN_DESCRIPTION)),
|
||||
@AttributeOverride(name = "dic", column = @Column(name = "SUPPLIER_DIC")),
|
||||
@AttributeOverride(name = "email", column = @Column(name = "SUPPLIER_EMAIL")),
|
||||
@AttributeOverride(name = "houseNumber", column = @Column(name = "SUPPLIER_HOUSENUMBER")),
|
||||
@@ -54,7 +56,7 @@ public class Order extends BaseData
|
||||
@AttributeOverride(name = "company", column = @Column(name = "INVOICE_COMPANY")),
|
||||
@AttributeOverride(name = "contactName", column = @Column(name = "INVOICE_CONTACT_NAME")),
|
||||
@AttributeOverride(name = "department", column = @Column(name = "INVOICE_DEPARTMENT")),
|
||||
@AttributeOverride(name = "description", column = @Column(name = "INVOICE_DESCRIPTION")),
|
||||
@AttributeOverride(name = "description", column = @Column(name = "INVOICE_DESCRIPTION", length = Constants.LEN_DESCRIPTION)),
|
||||
@AttributeOverride(name = "dic", column = @Column(name = "INVOICE_DIC")),
|
||||
@AttributeOverride(name = "email", column = @Column(name = "INVOICE_EMAIL")),
|
||||
@AttributeOverride(name = "houseNumber", column = @Column(name = "INVOICE_HOUSENUMBER")),
|
||||
@@ -73,7 +75,7 @@ public class Order extends BaseData
|
||||
@AttributeOverride(name = "company", column = @Column(name = "DELIVERY_COMPANY")),
|
||||
@AttributeOverride(name = "contactName", column = @Column(name = "DELIVERY_CONTACT_NAME")),
|
||||
@AttributeOverride(name = "department", column = @Column(name = "DELIVERY_DEPARTMENT")),
|
||||
@AttributeOverride(name = "description", column = @Column(name = "DELIVERY_DESCRIPTION")),
|
||||
@AttributeOverride(name = "description", column = @Column(name = "DELIVERY_DESCRIPTION", length = Constants.LEN_DESCRIPTION)),
|
||||
@AttributeOverride(name = "dic", column = @Column(name = "DELIVERY_DIC")),
|
||||
@AttributeOverride(name = "email", column = @Column(name = "DELIVERY_EMAIL")),
|
||||
@AttributeOverride(name = "houseNumber", column = @Column(name = "DELIVERY_HOUSENUMBER")),
|
||||
@@ -94,7 +96,7 @@ public class Order extends BaseData
|
||||
@Column(name = "DELIVERY_TYPE")
|
||||
private String deliveryType;
|
||||
|
||||
@Column(name = "DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "order", orphanRemoval = true)
|
||||
@@ -110,20 +112,10 @@ public class Order extends BaseData
|
||||
@Column(name = "DELIVERED")
|
||||
private boolean delivered;
|
||||
|
||||
@Column(name = "INVOICED")
|
||||
private boolean invoiced;
|
||||
|
||||
@Column(name = "INVOICE_NUMBER")
|
||||
private String invoiceNumber;
|
||||
|
||||
@Column(name = "INVOICE_TOTAL", precision = 15, scale = 4)
|
||||
private BigDecimal invoiceTotal;
|
||||
|
||||
public Order()
|
||||
{
|
||||
this.items = new ArrayList<OrderItem>();
|
||||
this.total = BigDecimal.ZERO;
|
||||
this.invoiceTotal = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
public String getNumser()
|
||||
@@ -232,26 +224,6 @@ public class Order extends BaseData
|
||||
this.delivered = delivered;
|
||||
}
|
||||
|
||||
public boolean isInvoiced()
|
||||
{
|
||||
return invoiced;
|
||||
}
|
||||
|
||||
public void setInvoiced(boolean invoiced)
|
||||
{
|
||||
this.invoiced = invoiced;
|
||||
}
|
||||
|
||||
public String getInvoiceNumber()
|
||||
{
|
||||
return invoiceNumber;
|
||||
}
|
||||
|
||||
public void setInvoiceNumber(String invoiceNumber)
|
||||
{
|
||||
this.invoiceNumber = invoiceNumber;
|
||||
}
|
||||
|
||||
public boolean isOrdered()
|
||||
{
|
||||
return ordered;
|
||||
@@ -282,14 +254,29 @@ public class Order extends BaseData
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public BigDecimal getInvoiceTotal()
|
||||
public boolean isIcludedRequirementItemFromAnotherOrder()
|
||||
{
|
||||
return invoiceTotal;
|
||||
for (OrderItem oItem : this.getItems())
|
||||
{
|
||||
RequirementItem rItem = oItem.getReqItem();
|
||||
|
||||
if (rItem != null)
|
||||
{
|
||||
String orderNum = rItem.getOrderNum();
|
||||
boolean isIncluded = ((orderNum != null) && !orderNum.isEmpty());
|
||||
boolean isFromAnotherOrder = (isIncluded && !this.numser.equals(orderNum));
|
||||
return isFromAnotherOrder;
|
||||
}
|
||||
}
|
||||
|
||||
public void setInvoiceTotal(BigDecimal invoiceTotal)
|
||||
{
|
||||
this.invoiceTotal = invoiceTotal;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException
|
||||
{
|
||||
Order cloned = (Order) super.clone();
|
||||
cloned.setTotal(new BigDecimal(this.getTotal().toString()));
|
||||
return cloned;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.persistence.Column;
|
||||
@@ -14,7 +16,8 @@ import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "ORDER_ITEM")
|
||||
public class OrderItem {
|
||||
public class OrderItem
|
||||
{
|
||||
|
||||
@Id
|
||||
@Column(name = "ID")
|
||||
@@ -42,7 +45,7 @@ public class OrderItem {
|
||||
@Column(name = "TOTAL", precision = 15, scale = 4)
|
||||
private BigDecimal total;
|
||||
|
||||
@Column(name = "DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@@ -53,11 +56,13 @@ public class OrderItem {
|
||||
@JoinColumn(name = "ORDER_ID")
|
||||
private Order order;
|
||||
|
||||
public OrderItem() {
|
||||
public OrderItem()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public OrderItem(RequirementItem reqItem) {
|
||||
public OrderItem(RequirementItem reqItem)
|
||||
{
|
||||
super();
|
||||
this.reqItem = reqItem;
|
||||
this.code = reqItem.getCode();
|
||||
@@ -70,91 +75,113 @@ public class OrderItem {
|
||||
this.description = reqItem.getDescription();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
public int getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
public void setId(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
public void setCode(String code)
|
||||
{
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTextItem() {
|
||||
public String getTextItem()
|
||||
{
|
||||
return textItem;
|
||||
}
|
||||
|
||||
public void setTextItem(String textItem) {
|
||||
public void setTextItem(String textItem)
|
||||
{
|
||||
this.textItem = textItem;
|
||||
}
|
||||
|
||||
public BigDecimal getQuantity() {
|
||||
public BigDecimal getQuantity()
|
||||
{
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(BigDecimal quantity) {
|
||||
public void setQuantity(BigDecimal quantity)
|
||||
{
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public MUnitEmb getMunit() {
|
||||
public MUnitEmb getMunit()
|
||||
{
|
||||
return munit;
|
||||
}
|
||||
|
||||
public void setMunit(MUnitEmb munit) {
|
||||
public void setMunit(MUnitEmb munit)
|
||||
{
|
||||
this.munit = munit;
|
||||
}
|
||||
|
||||
public BigDecimal getUnitPrice() {
|
||||
public BigDecimal getUnitPrice()
|
||||
{
|
||||
return unitPrice;
|
||||
}
|
||||
|
||||
public void setUnitPrice(BigDecimal unitPrice) {
|
||||
public void setUnitPrice(BigDecimal unitPrice)
|
||||
{
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
|
||||
public BigDecimal getTotal() {
|
||||
public BigDecimal getTotal()
|
||||
{
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(BigDecimal total) {
|
||||
public void setTotal(BigDecimal total)
|
||||
{
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public RequirementItem getReqItem() {
|
||||
public RequirementItem getReqItem()
|
||||
{
|
||||
return reqItem;
|
||||
}
|
||||
|
||||
public void setReqItem(RequirementItem reqItem) {
|
||||
public void setReqItem(RequirementItem reqItem)
|
||||
{
|
||||
this.reqItem = reqItem;
|
||||
}
|
||||
|
||||
public Order getOrder() {
|
||||
public Order getOrder()
|
||||
{
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Order order) {
|
||||
public void setOrder(Order order)
|
||||
{
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
@@ -19,7 +21,7 @@ public class Permission extends BaseSimpleData implements GrantedAuthority {
|
||||
|
||||
@Column(name="AUTHORITY")
|
||||
private String authority;
|
||||
@Column(name="DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
@Column(name="MODULE")
|
||||
private String module;
|
||||
|
||||
@@ -16,7 +16,7 @@ import javax.persistence.Table;
|
||||
@Table(name = "REQUIREMENT")
|
||||
public class Requirement extends RequirementBase
|
||||
{
|
||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "requirement", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "requirement", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<RequirementItem> items;
|
||||
|
||||
@Column(name = "DELIVERYDATE")
|
||||
@@ -28,6 +28,9 @@ public class Requirement extends RequirementBase
|
||||
@Column(name = "KIND")
|
||||
private Long kind;
|
||||
|
||||
@Column(name = "PROJECT")
|
||||
private Boolean project;
|
||||
|
||||
public Requirement()
|
||||
{
|
||||
this.setItems(new ArrayList<RequirementItem>());
|
||||
@@ -78,4 +81,39 @@ public class Requirement extends RequirementBase
|
||||
{
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public Boolean getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(Boolean project)
|
||||
{
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
if (obj instanceof Requirement)
|
||||
{
|
||||
Requirement item = (Requirement) obj;
|
||||
|
||||
int thisId = this.getId();
|
||||
int itemId = item.getId();
|
||||
boolean equalsId = (thisId == itemId);
|
||||
|
||||
if (equalsId && (thisId == 0))
|
||||
{
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
return equalsId;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -32,7 +34,7 @@ public class RequirementBase extends BaseData implements FilterableRequirement {
|
||||
private String numser;
|
||||
@Column(name = "REQ_DATE")
|
||||
private Date reqDate;
|
||||
@Column(name = "DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "CENTRE_ID")
|
||||
@@ -127,4 +129,20 @@ public class RequirementBase extends BaseData implements FilterableRequirement {
|
||||
this.workflow = workflow;
|
||||
}
|
||||
|
||||
public User getLastApprover() {
|
||||
if (authorization.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return authorization.get(authorization.size() - 1).getApprover();
|
||||
}
|
||||
|
||||
public Date getLastApproveDate() {
|
||||
if (authorization.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return authorization.get(authorization.size() - 1).getAuthDate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.persistence.Column;
|
||||
@@ -50,12 +52,18 @@ public class RequirementItem
|
||||
@Column(name = "TOTAL", precision=15, scale=4)
|
||||
private BigDecimal total;
|
||||
|
||||
@Column(name = "DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
|
||||
@Column(name = "DELIVERED")
|
||||
private Boolean delivered;
|
||||
|
||||
@Column(name = "ORDERNUM")
|
||||
private String orderNum;
|
||||
|
||||
@Column(name = "PAID")
|
||||
private Boolean paid;
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return id;
|
||||
@@ -163,7 +171,22 @@ public class RequirementItem
|
||||
{
|
||||
RequirementItem item = (RequirementItem)obj;
|
||||
|
||||
return (this.getId() == item.getId());
|
||||
int thisId = this.getId();
|
||||
int itemId = item.getId();
|
||||
boolean equalsId = (thisId == itemId);
|
||||
|
||||
if (equalsId && (thisId == 0))
|
||||
{
|
||||
// Při zadávání položek do gridu zatím nové položky nemají
|
||||
// přiřazeno ID, takže se rozlišují podle reference
|
||||
// Při hledání položky v seznamu nebo zjišťování indexu pak
|
||||
// byly veškeré položky s ID = 0 a grid nevybíral aktivní
|
||||
// položku správně, stejně tak nepřekresloval ani scrollbar
|
||||
// a pod.
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
return equalsId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,4 +210,22 @@ public class RequirementItem
|
||||
public void setDelivered(Boolean delivered) {
|
||||
this.delivered = delivered;
|
||||
}
|
||||
|
||||
public String getOrderNum()
|
||||
{
|
||||
return orderNum;
|
||||
}
|
||||
|
||||
public void setOrderNum(String orderNum)
|
||||
{
|
||||
this.orderNum = orderNum;
|
||||
}
|
||||
|
||||
public Boolean getPaid() {
|
||||
return paid;
|
||||
}
|
||||
|
||||
public void setPaid(Boolean paid) {
|
||||
this.paid = paid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
@@ -42,10 +44,9 @@ public abstract class RequirementSubject implements OwnedDataModel {
|
||||
private String code;
|
||||
@Column(name = "NAME")
|
||||
private String name;
|
||||
@Column(name = "DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
|
||||
|
||||
@NotEmpty(message = "{MaterialFormCodeConstr}")
|
||||
public String getCode() {
|
||||
return code;
|
||||
@@ -140,7 +141,16 @@ public abstract class RequirementSubject implements OwnedDataModel {
|
||||
{
|
||||
RequirementSubject item = (RequirementSubject) obj;
|
||||
|
||||
return (this.getId() == item.getId());
|
||||
int thisId = this.getId();
|
||||
int itemId = item.getId();
|
||||
boolean equalsId = (thisId == itemId);
|
||||
|
||||
if (equalsId && (thisId == 0))
|
||||
{
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
return equalsId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OrderBy;
|
||||
@@ -22,7 +24,7 @@ public class RequirementType extends BaseData {
|
||||
|
||||
@Column(name = "TYPE")
|
||||
private String type;
|
||||
@Column(name = "DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval=true)
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -25,7 +27,7 @@ public class Role extends BaseSimpleData implements GrantedAuthority, DataModel
|
||||
|
||||
@Column(name="AUTHORITY", unique=true)
|
||||
private String authority;
|
||||
@Column(name="DESCRIPTION")
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
@ManyToMany
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -33,7 +35,7 @@ public class TripBillItem extends BaseData {
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "code", column = @Column(name = "BACK_VEHICLE_CODE")),
|
||||
@AttributeOverride(name = "description", column = @Column(name = "BACK_VEHICLE_DESCRIPTION"))
|
||||
@AttributeOverride(name = "description", column = @Column(name = "BACK_VEHICLE_DESCRIPTION", length = Constants.LEN_DESCRIPTION))
|
||||
})
|
||||
private Vehicle backVehicle;
|
||||
@Column(name = "BEGIN_WORK")
|
||||
|
||||
@@ -26,7 +26,7 @@ public class TripRequirement extends RequirementBase {
|
||||
private String to;
|
||||
@Column(name = "TRIP_DATE")
|
||||
private Date tripDate;
|
||||
@Column(name = "TRIP_END")
|
||||
@Column(name = "END")
|
||||
private String end;
|
||||
@Column(name = "END_DATE")
|
||||
private Date endDate;
|
||||
|
||||
@@ -17,7 +17,7 @@ import javax.persistence.Table;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
@Entity
|
||||
@Table(name="USER_LOGIN")
|
||||
@Table(name="USER")
|
||||
public class User extends Member implements UserDetails, DataModel {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@@ -8,7 +10,7 @@ public class Vehicle {
|
||||
|
||||
@Column(name = "VEHICLE_CODE")
|
||||
private String code;
|
||||
@Column(name = "VEHICLE_DESCRIPTION")
|
||||
@Column(name = "VEHICLE_DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
private String description;
|
||||
|
||||
public String getCode() {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package info.bukova.isspst.filters;
|
||||
|
||||
import info.bukova.isspst.DateTimeUtils;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.Invoicing;
|
||||
import info.bukova.isspst.data.Requirement;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Factory;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
|
||||
public class InvoicingFilter implements Filter<Invoicing>
|
||||
{
|
||||
|
||||
private Invoicing condition;
|
||||
|
||||
public InvoicingFilter(Invoicing cond)
|
||||
{
|
||||
this.condition = cond;
|
||||
}
|
||||
|
||||
private static class InvoicingMatcher extends TypeSafeMatcher<Invoicing>
|
||||
{
|
||||
|
||||
private Invoicing condition;
|
||||
|
||||
public InvoicingMatcher(Invoicing cond)
|
||||
{
|
||||
this.condition = cond;
|
||||
|
||||
if (condition.getRequirement() == null) {
|
||||
condition.setRequirement(new Requirement());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description desc)
|
||||
{
|
||||
desc.appendText("Invoicing matches");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesSafely(Invoicing item)
|
||||
{
|
||||
boolean foundNumser = StringUtils.isEqualForFilter(item.getRequirement().getNumser(), condition.getRequirement().getNumser());
|
||||
boolean foundReqDate = DateTimeUtils.isEqualByDateForFilter(item.getRequirement().getReqDate(), condition.getRequirement().getReqDate());
|
||||
boolean foundCenter = Workgroup.isEqualByWorkgroupForFilter(item.getRequirement().getCentre(), condition.getRequirement().getCentre());
|
||||
boolean foundWorkgroup = Workgroup.isEqualByWorkgroupForFilter(item.getRequirement().getWorkgroup(), condition.getRequirement().getWorkgroup());
|
||||
boolean foundUser = User.isEqualByUserForFilter(item.getRequirement().getOwnedBy(), condition.getRequirement().getOwnedBy());
|
||||
boolean foundDescription = StringUtils.isEqualForFilter(item.getRequirement().getDescription(), condition.getRequirement().getDescription());
|
||||
return (foundNumser && foundReqDate && foundCenter && foundDescription && foundWorkgroup && foundUser);
|
||||
}
|
||||
|
||||
@Factory
|
||||
public static Matcher<Invoicing> matchBuilding(Invoicing building)
|
||||
{
|
||||
return new InvoicingMatcher(building);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InvoicingMatcher matcher()
|
||||
{
|
||||
return new InvoicingMatcher(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String queryString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,27 +42,24 @@ public class OrderFilter implements Filter<Order>
|
||||
@Override
|
||||
public boolean matchesSafely(Order item)
|
||||
{
|
||||
boolean foundOrdered = (item.isOrdered() == condition.isOrdered());
|
||||
boolean foundNumSer = StringUtils.isEqualForFilter(item.getNumser(), condition.getNumser());
|
||||
boolean foundOrderDate = DateTimeUtils.isEqualByDateForFilter(item.getOrderDate(), condition.getOrderDate());
|
||||
boolean foundTotal = true;// BigDecimalUtils.isEqualByDecimalForFilter(item.getTotal(),
|
||||
// condition.getTotal());
|
||||
boolean foundDeliveryDate = DateTimeUtils.isEqualByDateForFilter(item.getDeliveryDate(), condition.getDeliveryDate());
|
||||
boolean foundDeliveredDate = DateTimeUtils.isEqualByDateForFilter(item.getDeliveredDate(), condition.getDeliveredDate());
|
||||
boolean foundInvoiceNumber = StringUtils.isEqualForFilter(item.getInvoiceNumber(), condition.getInvoiceNumber());
|
||||
boolean foundInvoiceTotal = true;// BigDecimalUtils.isEqualByDecimalForFilter(item.getInvoiceTotal(),
|
||||
// condition.getInvoiceTotal());
|
||||
boolean foundSupplierAddr = AddressEmb.isEqualByAddressEmbForFilter(item.getSuplier(), condition.getSuplier());
|
||||
boolean foundDeliveryAddr = AddressEmb.isEqualByAddressEmbForFilter(item.getDeliveryAddress(), condition.getDeliveryAddress());
|
||||
boolean foundInvoiceAddr = AddressEmb.isEqualByAddressEmbForFilter(item.getAddress(), condition.getAddress());
|
||||
boolean foundOwnedBy = User.isEqualByUserForFilter(item.getOwnedBy(), condition.getOwnedBy());
|
||||
boolean foundDescription = StringUtils.isEqualForFilter(item.getDescription(), condition.getDescription());
|
||||
return (foundNumSer
|
||||
return (foundOrdered
|
||||
&& foundNumSer
|
||||
&& foundOrderDate
|
||||
&& foundTotal
|
||||
&& foundDeliveryDate
|
||||
&& foundDeliveredDate
|
||||
&& foundInvoiceNumber
|
||||
&& foundInvoiceTotal
|
||||
&& foundSupplierAddr
|
||||
&& foundDeliveryAddr
|
||||
&& foundInvoiceAddr
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.bukova.isspst.filters;
|
||||
|
||||
import info.bukova.isspst.BooleanUtils;
|
||||
import info.bukova.isspst.DateTimeUtils;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.Requirement;
|
||||
@@ -46,7 +47,8 @@ public class RequirementFilter implements Filter<Requirement>
|
||||
boolean foundDescription = StringUtils.isEqualForFilter(item.getDescription(), condition.getDescription());
|
||||
boolean foundDeliveryDate = DateTimeUtils.isEqualByDateForFilter(item.getDeliveryDate(), condition.getDeliveryDate());
|
||||
boolean foundUser = User.isEqualByUserForFilter(item.getOwnedBy(), condition.getOwnedBy());
|
||||
return (foundNumser && foundReqDate && foundCenter && foundDescription && foundDeliveryDate && foundUser);
|
||||
boolean foundProject = BooleanUtils.isEqualByBoolean(item.getProject(), condition.getProject());
|
||||
return (foundNumser && foundReqDate && foundCenter && foundDescription && foundDeliveryDate && foundUser && foundProject);
|
||||
}
|
||||
|
||||
@Factory
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.bukova.isspst.filters;
|
||||
import info.bukova.isspst.DateTimeUtils;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.TripRequirement;
|
||||
import info.bukova.isspst.data.User;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Factory;
|
||||
@@ -45,7 +46,7 @@ public class TripRequirementFilter implements Filter<TripRequirement>
|
||||
boolean foundTo = StringUtils.isEqualForFilter(item.getTo(), condition.getTo());
|
||||
boolean foundWorkgroup = (condition.getWorkgroup() == null ||(item.getWorkgroup() != null && item.getWorkgroup().equals(condition.getWorkgroup())));
|
||||
boolean foundCentre = (condition.getCentre() == null || (item.getCentre() != null && item.getCentre().equals(condition.getCentre())));
|
||||
boolean foundOwner = StringUtils.isEqualForFilter(item.getOwnedBy().getLastName(), condition.getOwnedBy().getLastName());
|
||||
boolean foundOwner = User.isEqualByUserForFilter(item.getOwnedBy(), condition.getOwnedBy());
|
||||
return foundNumser && foundReqDate && foundDescription && foundFrom && foundTo && foundWorkgroup && foundCentre && foundOwner;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package info.bukova.isspst.mail;
|
||||
|
||||
import info.bukova.isspst.EntityUrlResolver;
|
||||
import info.bukova.isspst.UrlResolverHolder;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -12,6 +15,7 @@ public class EntityMessageBuilder implements MessageBuilder {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(EntityMessageBuilder.class);
|
||||
private boolean html;
|
||||
private UrlResolverHolder urlResolverHolder;
|
||||
|
||||
public void setHtml(boolean html) {
|
||||
this.html = html;
|
||||
@@ -53,7 +57,11 @@ public class EntityMessageBuilder implements MessageBuilder {
|
||||
|
||||
for (String p : properties) {
|
||||
try {
|
||||
if (p.equals("-url-")) {
|
||||
ret = ret.replaceAll("\\[" + p + "\\]", getUrl(data));
|
||||
} else {
|
||||
ret = ret.replaceAll("\\[" + p + "\\]", BeanUtils.getProperty(data, p));
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.error(e.getMessage());
|
||||
} catch (InvocationTargetException e) {
|
||||
@@ -68,4 +76,17 @@ public class EntityMessageBuilder implements MessageBuilder {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private String getUrl(Object data) {
|
||||
if (urlResolverHolder == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
EntityUrlResolver res = urlResolverHolder.resolverFor(data.getClass());
|
||||
return res.entityUrl(data);
|
||||
}
|
||||
|
||||
public void setUrlResolverHolder(UrlResolverHolder urlResolverHolder) {
|
||||
this.urlResolverHolder = urlResolverHolder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +43,10 @@ public class MailerWithAttachement implements Mailer {
|
||||
}
|
||||
}
|
||||
|
||||
if (message.getReplyTo() == null) {
|
||||
message.setReplyTo(message.getFrom());
|
||||
}
|
||||
|
||||
helper.setFrom(message.getFrom());
|
||||
helper.setReplyTo(message.getReplyTo());
|
||||
helper.setTo(message.getTo());
|
||||
@@ -63,6 +67,7 @@ public class MailerWithAttachement implements Mailer {
|
||||
}
|
||||
try {
|
||||
sender.send(mimeMessage);
|
||||
logger.info("Mail queued for send");
|
||||
} catch (MailAuthenticationException e) {
|
||||
logger.error("Authentication error");
|
||||
} catch (MailSendException e) {
|
||||
|
||||
@@ -30,6 +30,10 @@ public abstract class AbstractRequirementEvaluator extends AbstractModuleEvaluat
|
||||
return req.getState() == RequirementState.NEW;
|
||||
}
|
||||
|
||||
if (permission.equals(Constants.PERM_DELETE_NEW)) {
|
||||
return req.getState() == RequirementState.NEW;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package info.bukova.isspst.security;
|
||||
|
||||
public enum AuthMethod {
|
||||
|
||||
DATABASE,
|
||||
LDAP,
|
||||
AD
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ public class AuthPopulator implements LdapAuthoritiesPopulator {
|
||||
public AuthPopulator(UserService userService, RoleService roleService) {
|
||||
this.userService = userService;
|
||||
this.roleService = roleService;
|
||||
userService.setAuthMethod(AuthMethod.LDAP);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package info.bukova.isspst.security;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.Module;
|
||||
import info.bukova.isspst.data.Permission;
|
||||
import info.bukova.isspst.data.PermissionType;
|
||||
import info.bukova.isspst.data.Role;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.services.Service;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -39,11 +41,31 @@ public class WorkgroupAwareServiceEvaluator implements Evaluator {
|
||||
}
|
||||
|
||||
User user = (User)authentication.getPrincipal();
|
||||
String moduleId = "";
|
||||
|
||||
if (targetDomainObject instanceof Service<?>) {
|
||||
Service<?> service = (Service<?>)targetDomainObject;
|
||||
Module mod = service.getModule();
|
||||
|
||||
if (mod != null) {
|
||||
moduleId = mod.getId();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - v master větvi je na toto pomocná třída
|
||||
/*for (Module m : Constants.MODULES) {
|
||||
if (m.getServiceClass() != null && m.getServiceClass().isAssignableFrom(targetDomainObject.getClass())) {
|
||||
moduleId = m.getId();
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
Permission appPermission = null;
|
||||
for (Permission p : Constants.SPECIAL_PERMISSIONS) {
|
||||
if (p.getAuthority().equals(permission)) {
|
||||
if (p.getAuthority().equals(permission)
|
||||
&& p.getModule().equals(moduleId)) {
|
||||
appPermission = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +88,8 @@ public class WorkgroupAwareServiceEvaluator implements Evaluator {
|
||||
|
||||
for (Role r : wgRoles) {
|
||||
for (Permission p : r.getPermissions()) {
|
||||
if (p.getAuthority().equals(appPermission.getAuthority())) {
|
||||
if (p.getAuthority().equals(appPermission.getAuthority())
|
||||
&& p.getModule().equals(appPermission.getModule())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getDeleteEntityPermission() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasPermission(this, 'PERM_ADD')")
|
||||
public final T create() {
|
||||
@@ -93,7 +97,7 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_DELETE')")
|
||||
@PreAuthorize("hasPermission(this, 'PERM_DELETE') or hasPermission(#entity, this.getDeleteEntityPermission())")
|
||||
public void delete(T entity) {
|
||||
if (dao == null) {
|
||||
throw new IsspstException("DAO is null");
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package info.bukova.isspst.services.dbinfo;
|
||||
|
||||
import info.bukova.isspst.data.DbInfo;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
public interface DbInfoService extends Service<DbInfo>
|
||||
{
|
||||
public void changeDatabase();
|
||||
|
||||
public void updateDatabaseVersion();
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package info.bukova.isspst.services.dbinfo;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.data.DbInfo;
|
||||
import info.bukova.isspst.services.AbstractService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.SQLQuery;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class DbInfoServiceImpl extends AbstractService<DbInfo> implements DbInfoService
|
||||
{
|
||||
private DbInfo getDbInfo()
|
||||
{
|
||||
DbInfo dbInfo = null;
|
||||
|
||||
List<DbInfo> list = this.getAll();
|
||||
|
||||
if (list.isEmpty())
|
||||
{
|
||||
dbInfo = new DbInfo();
|
||||
this.add(dbInfo);
|
||||
list = this.getAll();
|
||||
}
|
||||
|
||||
for (DbInfo item : list)
|
||||
{
|
||||
dbInfo = item;
|
||||
break;
|
||||
}
|
||||
|
||||
return dbInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void changeDatabase()
|
||||
{
|
||||
class Str2Str
|
||||
{
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public Str2Str(String key, String value)
|
||||
{
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
long dbVersion = this.getDbInfo().getVersion();
|
||||
|
||||
if (Constants.DB_VERSION > dbVersion)
|
||||
{
|
||||
SQLQuery sq = null;
|
||||
String sql = "";
|
||||
|
||||
if (dbVersion < 1)
|
||||
{
|
||||
List<Str2Str> tables = new ArrayList<Str2Str>();
|
||||
|
||||
tables.add(new Str2Str("address", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("building", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("material", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("munit", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("orders", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("order_item", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("permission", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("requirement", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("requirementtype", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("requirement_items", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("role", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("service", "DESCRIPTION"));
|
||||
tables.add(new Str2Str("triprequirement", "DESCRIPTION"));
|
||||
|
||||
tables.add(new Str2Str("material", "MUNIT_DESCRIPTION"));
|
||||
tables.add(new Str2Str("orders", "INVOICE_DESCRIPTION"));
|
||||
tables.add(new Str2Str("orders", "DELIVERY_DESCRIPTION"));
|
||||
tables.add(new Str2Str("orders", "SUPPLIER_DESCRIPTION"));
|
||||
tables.add(new Str2Str("order_item", "MUNIT_DESCRIPTION"));
|
||||
tables.add(new Str2Str("requirement_items", "MUNIT_DESCRIPTION"));
|
||||
tables.add(new Str2Str("triprequirement", "VEHICLE_DESCRIPTION"));
|
||||
tables.add(new Str2Str("trip_bill_items", "BACK_VEHICLE_DESCRIPTION"));
|
||||
tables.add(new Str2Str("trip_bill_items", "VEHICLE_DESCRIPTION"));
|
||||
|
||||
for (Str2Str item : tables)
|
||||
{
|
||||
sql = "ALTER TABLE " + item.getKey() + " MODIFY " + item.getValue() + " VARCHAR(" + String.valueOf(Constants.LEN_DESCRIPTION) + ")";
|
||||
sq = this.dao.getSession().createSQLQuery(sql);
|
||||
sq.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
if (dbVersion < 2)
|
||||
{
|
||||
List<String> tables = new ArrayList<String>();
|
||||
|
||||
tables.add("material");
|
||||
tables.add("order_item");
|
||||
tables.add("requirement_items");
|
||||
|
||||
for (String item : tables)
|
||||
{
|
||||
sql = "UPDATE " + item + " SET MUNIT_ID = 0 WHERE (MUNIT_ID Is NULL) ";
|
||||
sq = this.dao.getSession().createSQLQuery(sql);
|
||||
sq.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
this.updateDatabaseVersion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateDatabaseVersion()
|
||||
{
|
||||
DbInfo dbInfo = this.getDbInfo();
|
||||
dbInfo.setVersion(Constants.DB_VERSION);
|
||||
this.update(dbInfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package info.bukova.isspst.services.invoicing;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import info.bukova.isspst.data.Invoicing;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
public interface InvoicingService extends Service<Invoicing> {
|
||||
|
||||
public BigDecimal totalInvoicedForWorkgroup(Workgroup workgroup);
|
||||
|
||||
public void loadReqItems(Invoicing invoicing);
|
||||
|
||||
public void loadItems(Invoicing invoicing);
|
||||
|
||||
public void calculate(Invoicing invoicing);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package info.bukova.isspst.services.invoicing;
|
||||
|
||||
import info.bukova.isspst.data.Invoicing;
|
||||
import info.bukova.isspst.data.InvoicingItem;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.services.AbstractOwnedService;
|
||||
import info.bukova.isspst.services.LazyLoader;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class InvoicingServiceImpl extends AbstractOwnedService<Invoicing> implements
|
||||
InvoicingService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public BigDecimal totalInvoicedForWorkgroup(Workgroup workgroup) {
|
||||
Query q = dao.getQuery("select sum(inv.totalInvoiced) "
|
||||
+ "from Invoicing inv join inv.requirement rq join rq.workgroup w "
|
||||
+ "where w = :workgroup ");
|
||||
q.setParameter("workgroup", workgroup);
|
||||
return (BigDecimal) q.uniqueResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@LazyLoader("form")
|
||||
public void loadReqItems(Invoicing invoicing) {
|
||||
Invoicing inv = getById(invoicing.getId());
|
||||
Hibernate.initialize(inv.getRequirement().getItems());
|
||||
invoicing.getRequirement().setItems(inv.getRequirement().getItems());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@LazyLoader({"form", "grid"})
|
||||
public void loadItems(Invoicing invoicing) {
|
||||
Invoicing inv = getById(invoicing.getId());
|
||||
Hibernate.initialize(inv.getItems());
|
||||
invoicing.setItems(inv.getItems());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate(Invoicing invoicing) {
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
|
||||
for (InvoicingItem item : invoicing.getItems()) {
|
||||
total = total.add(item.getAmount());
|
||||
}
|
||||
|
||||
invoicing.setTotalInvoiced(total);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_READ')")
|
||||
public List<Invoicing> getAll() {
|
||||
Query q = dao.getQuery("select inv from Invoicing as inv join fetch inv.requirement rq join fetch rq.ownedBy order by rq.numser");
|
||||
return q.list();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@LazyLoader("form")
|
||||
public void loadOwnedBy(Invoicing invoice) {
|
||||
Invoicing inv = getById(invoice.getId());
|
||||
Hibernate.initialize(inv.getRequirement().getOwnedBy());
|
||||
invoice.getRequirement().setOwnedBy(inv.getRequirement().getOwnedBy());
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package info.bukova.isspst.services.approved;
|
||||
package info.bukova.isspst.services.orders;
|
||||
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.services.Service;
|
||||
+35
-3
@@ -1,9 +1,13 @@
|
||||
package info.bukova.isspst.services.approved;
|
||||
package info.bukova.isspst.services.orders;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.Module;
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.data.RequirementItem;
|
||||
import info.bukova.isspst.data.RequirementState;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.reporting.Report;
|
||||
import info.bukova.isspst.reporting.ReportType;
|
||||
import info.bukova.isspst.services.AbstractService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
@@ -34,8 +38,13 @@ public class ApprovedServiceImpl extends AbstractService<JoinedItem> implements
|
||||
public List<JoinedItem> getAll()
|
||||
{
|
||||
List<Workgroup> wgList = workgroupService.getUserCentres(userService.getCurrent());
|
||||
Query q = queryDao
|
||||
.getQuery("select item from RequirementItem item left join item.requirement rq join rq.centre c where rq.kind is not null and rq.state = :state and c in (:wgList)");
|
||||
Query q = queryDao.getQuery("select item "
|
||||
+ "from RequirementItem item left join item.requirement rq join rq.centre c "
|
||||
+ "where rq.kind is not null "
|
||||
+ "and rq.state = :state "
|
||||
+ "and (rq.project Is Null or rq.project = false) "
|
||||
+ "and c in (:wgList) "
|
||||
+ "and (item.orderNum Is Null or item.orderNum = '')");
|
||||
q.setParameterList("wgList", wgList);
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
List<JoinedItem> items = new ArrayList<JoinedItem>();
|
||||
@@ -50,4 +59,27 @@ public class ApprovedServiceImpl extends AbstractService<JoinedItem> implements
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module getModule() {
|
||||
for (Module m : Constants.MODULES) {
|
||||
if (m.getId() == Constants.MOD_REQUIREMENTS) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Report> getReports() {
|
||||
Report rep = new Report();
|
||||
rep.setType(ReportType.DYNAMIC);
|
||||
rep.setName(Constants.DYNAMIC_REPORT_NAME);
|
||||
|
||||
List<Report> ret = new ArrayList<Report>();
|
||||
ret.add(rep);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -1,4 +1,4 @@
|
||||
package info.bukova.isspst.services.approved;
|
||||
package info.bukova.isspst.services.orders;
|
||||
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.data.Order;
|
||||
@@ -22,4 +22,7 @@ public interface OrderService extends Service<Order> {
|
||||
|
||||
public BigDecimal calcSumTotalFromItems(List<OrderItem> items);
|
||||
|
||||
public void addApprovedItems(Order order, boolean orderedChanged);
|
||||
|
||||
public void updateApprovedItems(Order order, boolean orderedChanged);
|
||||
}
|
||||
+64
-3
@@ -1,9 +1,11 @@
|
||||
package info.bukova.isspst.services.approved;
|
||||
package info.bukova.isspst.services.orders;
|
||||
|
||||
import info.bukova.isspst.dao.RequirementItemDao;
|
||||
import info.bukova.isspst.data.AddressEmb;
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.data.Order;
|
||||
import info.bukova.isspst.data.OrderItem;
|
||||
import info.bukova.isspst.data.RequirementItem;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.services.AbstractOwnedService;
|
||||
import info.bukova.isspst.services.LazyLoader;
|
||||
@@ -24,6 +26,9 @@ public class OrderServiceImpl extends AbstractOwnedService<Order> implements
|
||||
@Autowired
|
||||
private GlobalSettingsService globalSettings;
|
||||
|
||||
@Autowired
|
||||
private RequirementItemDao requirementItemDao;
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasPermission(this, 'PERM_ADD')")
|
||||
public Order createOrder(List<JoinedItem> items) {
|
||||
@@ -47,8 +52,11 @@ public class OrderServiceImpl extends AbstractOwnedService<Order> implements
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public BigDecimal totalOrderedForWorkgroup(Workgroup workgroup) {
|
||||
Query q = dao.getQuery("select sum(oi.total) from OrderItem oi join oi.reqItem ri join ri.requirement rq join rq.workgroup w where ri.delivered = true and w = :workgroup");
|
||||
public BigDecimal totalOrderedForWorkgroup(Workgroup workgroup)
|
||||
{
|
||||
Query q = dao.getQuery("select sum(oi.total) "
|
||||
+ "from OrderItem oi join oi.reqItem ri join ri.requirement rq join rq.workgroup w "
|
||||
+ "where (ri.orderNum is not null or ri.orderNum = '') and w = :workgroup ");
|
||||
q.setParameter("workgroup", workgroup);
|
||||
return (BigDecimal) q.uniqueResult();
|
||||
}
|
||||
@@ -171,4 +179,57 @@ public class OrderServiceImpl extends AbstractOwnedService<Order> implements
|
||||
|
||||
return sumTotal;
|
||||
}
|
||||
|
||||
protected void setApprovedItems(Order order, boolean orderedChanged)
|
||||
{
|
||||
if (orderedChanged)
|
||||
{
|
||||
for (OrderItem item : order.getItems())
|
||||
{
|
||||
RequirementItem rItem = item.getReqItem();
|
||||
|
||||
if (rItem != null)
|
||||
{
|
||||
rItem.setOrderNum(order.isOrdered() ? order.getNumser() : null);
|
||||
requirementItemDao.modify(rItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_ADD')")
|
||||
public void addApprovedItems(Order order, boolean orderedChanged)
|
||||
{
|
||||
this.add(order);
|
||||
this.setApprovedItems(order, orderedChanged);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())")
|
||||
public void updateApprovedItems(Order order, boolean orderedChanged)
|
||||
{
|
||||
this.setApprovedItems(order, orderedChanged);
|
||||
super.update(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_DELETE') or hasPermission(#entity, this.getDeleteEntityPermission())")
|
||||
public void delete(Order order) {
|
||||
for (OrderItem item : order.getItems())
|
||||
{
|
||||
RequirementItem rItem = item.getReqItem();
|
||||
|
||||
if (rItem != null)
|
||||
{
|
||||
rItem.setOrderNum(null);
|
||||
requirementItemDao.modify(rItem);
|
||||
}
|
||||
}
|
||||
|
||||
super.delete(order);
|
||||
}
|
||||
}
|
||||
@@ -38,9 +38,8 @@ public class ReqMaterialServiceImpl extends RequirementServiceImpl implements Re
|
||||
@PreAuthorize("hasPermission(this, 'PERM_READ')")
|
||||
public List<Requirement> getMy()
|
||||
{
|
||||
Query q = dao.getQuery("from " + dao.getEntityName() + " where ownedBy = :owner and state != :state and kind = :kind");
|
||||
Query q = dao.getQuery("from " + dao.getEntityName() + " where ownedBy = :owner and kind = :kind");
|
||||
q.setParameter("owner", getLoggedInUser());
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
q.setParameter("kind", Constants.REQ_TYPE_MATERIAL);
|
||||
return q.list();
|
||||
}
|
||||
@@ -53,9 +52,8 @@ public class ReqMaterialServiceImpl extends RequirementServiceImpl implements Re
|
||||
public List<Requirement> getCentreReq()
|
||||
{
|
||||
List<Workgroup> wgList = workgroupService.getUserCentres(getLoggedInUser());
|
||||
Query q = dao.getQuery("select tr from " + dao.getEntityName() + " tr join fetch tr.ownedBy join tr.centre c where tr.state != :state and c in (:wgList) and kind = :kind order by tr.numser");
|
||||
Query q = dao.getQuery("select tr from " + dao.getEntityName() + " tr join fetch tr.ownedBy join tr.centre c where c in (:wgList) and kind = :kind order by tr.numser");
|
||||
q.setParameterList("wgList", wgList);
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
q.setParameter("kind", Constants.REQ_TYPE_MATERIAL);
|
||||
return q.list();
|
||||
}
|
||||
@@ -70,9 +68,8 @@ public class ReqMaterialServiceImpl extends RequirementServiceImpl implements Re
|
||||
List<Workgroup> wgList = workgroupService.getUserWorkgroups(getLoggedInUser());
|
||||
Query q = dao.getQuery("select tr from "
|
||||
+ dao.getEntityName()
|
||||
+ " tr join fetch tr.ownedBy join tr.workgroup w where tr.state != :state and w in (:wgList) and kind = :kind order by tr.numser");
|
||||
+ " tr join fetch tr.ownedBy join tr.workgroup w where w in (:wgList) and kind = :kind order by tr.numser");
|
||||
q.setParameterList("wgList", wgList);
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
q.setParameter("kind", Constants.REQ_TYPE_MATERIAL);
|
||||
return q.list();
|
||||
}
|
||||
|
||||
@@ -38,9 +38,8 @@ public class ReqServicesServiceImpl extends RequirementServiceImpl implements Re
|
||||
@PreAuthorize("hasPermission(this, 'PERM_READ')")
|
||||
public List<Requirement> getMy()
|
||||
{
|
||||
Query q = dao.getQuery("from " + dao.getEntityName() + " where ownedBy = :owner and state != :state and kind = :kind");
|
||||
Query q = dao.getQuery("from " + dao.getEntityName() + " where ownedBy = :owner and kind = :kind");
|
||||
q.setParameter("owner", getLoggedInUser());
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
q.setParameter("kind", Constants.REQ_TYPE_SERVICES);
|
||||
return q.list();
|
||||
}
|
||||
@@ -53,9 +52,8 @@ public class ReqServicesServiceImpl extends RequirementServiceImpl implements Re
|
||||
public List<Requirement> getCentreReq()
|
||||
{
|
||||
List<Workgroup> wgList = workgroupService.getUserCentres(getLoggedInUser());
|
||||
Query q = dao.getQuery("select tr from " + dao.getEntityName() + " tr join fetch tr.ownedBy join tr.centre c where tr.state != :state and c in (:wgList) and kind = :kind order by tr.numser");
|
||||
Query q = dao.getQuery("select tr from " + dao.getEntityName() + " tr join fetch tr.ownedBy join tr.centre c where c in (:wgList) and kind = :kind order by tr.numser");
|
||||
q.setParameterList("wgList", wgList);
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
q.setParameter("kind", Constants.REQ_TYPE_SERVICES);
|
||||
return q.list();
|
||||
}
|
||||
@@ -70,9 +68,8 @@ public class ReqServicesServiceImpl extends RequirementServiceImpl implements Re
|
||||
List<Workgroup> wgList = workgroupService.getUserWorkgroups(getLoggedInUser());
|
||||
Query q = dao.getQuery("select tr from "
|
||||
+ dao.getEntityName()
|
||||
+ " tr join fetch tr.ownedBy join tr.workgroup w where tr.state != :state and w in (:wgList) and kind = :kind order by tr.numser");
|
||||
+ " tr join fetch tr.ownedBy join tr.workgroup w where w in (:wgList) and kind = :kind order by tr.numser");
|
||||
q.setParameterList("wgList", wgList);
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
q.setParameter("kind", Constants.REQ_TYPE_SERVICES);
|
||||
return q.list();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,14 @@ import info.bukova.isspst.services.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
* @author Franta Přibyl
|
||||
*
|
||||
* Základní rozhraní všech požadavků.
|
||||
*
|
||||
* @param <T> Třída požadavku.
|
||||
*/
|
||||
public interface RequirementBaseService<T extends RequirementBase> extends Service<T>
|
||||
{
|
||||
|
||||
|
||||
+38
-9
@@ -30,6 +30,14 @@ import org.springframework.security.access.prepost.PostFilter;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
* @author Franta Přibyl
|
||||
*
|
||||
* Abstraktní bázová třída všech požadavků
|
||||
*
|
||||
* @param <T> Třída požadavku
|
||||
*/
|
||||
public abstract class RequirementBaseServiceImpl<T extends RequirementBase> extends
|
||||
AbstractOwnedService<T> implements RequirementBaseService<T> {
|
||||
|
||||
@@ -68,8 +76,12 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
|
||||
super.add(entity);
|
||||
|
||||
if (canApprove(entity)) {
|
||||
approve(entity);
|
||||
} else {
|
||||
this.sendToApprovers(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEnable() {
|
||||
if (!settingsService.getSettings().isEnableRequirements()) {
|
||||
@@ -220,12 +232,10 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
} else {
|
||||
e.setState(RequirementState.PARTIALLY);
|
||||
}
|
||||
entity.setState(e.getState());
|
||||
entity.getAuthorization().add(auth);
|
||||
|
||||
super.update(e);
|
||||
|
||||
if (!autoApprove(entity)) {
|
||||
if (!autoApprove(e)) {
|
||||
this.sendToApprovers(e);
|
||||
|
||||
SettingsData settings = settingsService.getSettings();
|
||||
@@ -247,6 +257,8 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
postApprove(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -256,10 +268,25 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
approve(entity, getLoggedInUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* Volá se z metody approve pro automatické schválení dalším schvalovatelem v pořadí. Metoda z báze nedělá nic.
|
||||
*
|
||||
* @param entity Požadavek
|
||||
* @return true pokud se provedlo automatické schválení.
|
||||
*/
|
||||
protected boolean autoApprove(T entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Činnost prováděná po schválení požadavku (i dílčím schválení).
|
||||
*
|
||||
* @param entity Požadavek
|
||||
*/
|
||||
protected void postApprove(T entity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean canApprove(T entity) {
|
||||
@@ -307,9 +334,8 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
@PreAuthorize("hasPermission(this, 'PERM_READ')")
|
||||
public List<T> getMy()
|
||||
{
|
||||
Query q = dao.getQuery("from " + dao.getEntityName() + " where ownedBy = :owner and state != :state");
|
||||
Query q = dao.getQuery("from " + dao.getEntityName() + " where ownedBy = :owner");
|
||||
q.setParameter("owner", getLoggedInUser());
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
return q.list();
|
||||
}
|
||||
|
||||
@@ -321,9 +347,8 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
public List<T> getCentreReq()
|
||||
{
|
||||
List<Workgroup> wgList = workgroupService.getUserCentres(getLoggedInUser());
|
||||
Query q = dao.getQuery("select tr from " + dao.getEntityName() + " tr join fetch tr.ownedBy join tr.centre c where tr.state != :state and c in (:wgList) order by tr.numser");
|
||||
Query q = dao.getQuery("select tr from " + dao.getEntityName() + " tr join fetch tr.ownedBy join tr.centre c where c in (:wgList) order by tr.numser");
|
||||
q.setParameterList("wgList", wgList);
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
return q.list();
|
||||
}
|
||||
|
||||
@@ -335,9 +360,8 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
public List<T> getWorkgroupReq()
|
||||
{
|
||||
List<Workgroup> wgList = workgroupService.getUserWorkgroups(getLoggedInUser());
|
||||
Query q = dao.getQuery("select tr from " + dao.getEntityName() + " tr join fetch tr.ownedBy join tr.workgroup w where tr.state != :state and w in (:wgList) order by tr.numser");
|
||||
Query q = dao.getQuery("select tr from " + dao.getEntityName() + " tr join fetch tr.ownedBy join tr.workgroup w where w in (:wgList) order by tr.numser");
|
||||
q.setParameterList("wgList", wgList);
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
return q.list();
|
||||
}
|
||||
|
||||
@@ -356,4 +380,9 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
return Constants.PERM_EDIT_NEW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeleteEntityPermission() {
|
||||
return Constants.PERM_DELETE_NEW;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,10 +6,19 @@ import info.bukova.isspst.data.RequirementItem;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
* @author Franta Přibyl
|
||||
*
|
||||
* Základní rozhraní požadavků na služby a materiál.
|
||||
*
|
||||
*/
|
||||
public interface RequirementService extends RequirementBaseService<Requirement>
|
||||
{
|
||||
public void loadGroups(Requirement req);
|
||||
|
||||
public void loadItems(Requirement req);
|
||||
|
||||
public BigDecimal calcTotalFromItem(RequirementItem item);
|
||||
|
||||
public RequirementItem calcTotalInItem(RequirementItem item);
|
||||
@@ -17,4 +26,6 @@ public interface RequirementService extends RequirementBaseService<Requirement>
|
||||
public RequirementItem calcItemValuesFromItemTotal(RequirementItem item);
|
||||
|
||||
public BigDecimal calcSumTotalFromItems(List<RequirementItem> items);
|
||||
|
||||
public BigDecimal getInvoicedAmount(Requirement req);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package info.bukova.isspst.services.requirement;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.data.Invoicing;
|
||||
import info.bukova.isspst.data.Requirement;
|
||||
import info.bukova.isspst.data.RequirementItem;
|
||||
import info.bukova.isspst.data.RequirementState;
|
||||
@@ -8,22 +9,31 @@ import info.bukova.isspst.data.RequirementSubject;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.Workflow;
|
||||
import info.bukova.isspst.services.LazyLoader;
|
||||
import info.bukova.isspst.services.approved.OrderService;
|
||||
import info.bukova.isspst.services.invoicing.InvoicingService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
* @author Franta Přibyl
|
||||
*
|
||||
* Bázová třída požadavků na materiál a služby.
|
||||
*
|
||||
*/
|
||||
public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requirement> implements RequirementService, RequirementBaseService<Requirement>
|
||||
{
|
||||
|
||||
@Autowired
|
||||
private RequirementTypeService reqTypeService;
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
private InvoicingService invoicingService;
|
||||
|
||||
@Override
|
||||
protected Requirement createEntity()
|
||||
@@ -48,7 +58,8 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity.getSumTotal().compareTo(nextWf.getLimit()) == -1)
|
||||
if ((entity.getSumTotal() != null)
|
||||
&& (entity.getSumTotal().compareTo(nextWf.getLimit()) == -1))
|
||||
{
|
||||
approve(entity, approvers.get(0));
|
||||
return true;
|
||||
@@ -63,7 +74,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
|
||||
if (entity.getWorkgroup() != null && entity.getWorkgroup().getLimit() != null && entity.getWorkgroup().getLimit().compareTo(BigDecimal.ZERO) != 0)
|
||||
{
|
||||
|
||||
BigDecimal total = orderService.totalOrderedForWorkgroup(entity.getWorkgroup());
|
||||
BigDecimal total = invoicingService.totalInvoicedForWorkgroup(entity.getWorkgroup());
|
||||
|
||||
if (total == null)
|
||||
{
|
||||
@@ -136,6 +147,19 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
|
||||
req.setItems(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@LazyLoader("form")
|
||||
public void loadItems(Requirement req) {
|
||||
if (req == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Requirement r = getById(req.getId());
|
||||
Hibernate.initialize(r.getItems());
|
||||
req.setItems(r.getItems());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal calcTotalFromItem(RequirementItem item)
|
||||
{
|
||||
@@ -208,4 +232,24 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
|
||||
|
||||
return sumTotal;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postApprove(Requirement entity) {
|
||||
if (entity.getState() == RequirementState.APPROVED) {
|
||||
Invoicing inv = new Invoicing();
|
||||
inv.setRequirement(entity);
|
||||
invoicingService.add(inv);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public BigDecimal getInvoicedAmount(Requirement req) {
|
||||
Query query = dao.getQuery("select invoice from Invoicing invoice join invoice.requirement rq where rq.id = :reqId");
|
||||
query.setParameter("reqId", req.getId());
|
||||
|
||||
Invoicing inv = (Invoicing) query.uniqueResult();
|
||||
|
||||
return inv != null ? inv.getTotalInvoiced() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
package info.bukova.isspst.services.requirement;
|
||||
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
import info.bukova.isspst.data.TripRequirement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TripRequirementService extends RequirementBaseService<TripRequirement>
|
||||
{
|
||||
|
||||
public void loadPassangers(TripRequirement entity);
|
||||
|
||||
/**
|
||||
* Vrátí seznam vyúčtování, která josu vázána k požadavku
|
||||
*
|
||||
* @param entity požadavek
|
||||
* @return seznam vyúčtování
|
||||
*/
|
||||
public List<TripBill> getBills(TripRequirement entity);
|
||||
|
||||
}
|
||||
|
||||
+38
-6
@@ -5,17 +5,19 @@ import info.bukova.isspst.data.NumberSeries;
|
||||
import info.bukova.isspst.data.RequirementState;
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
import info.bukova.isspst.data.TripRequirement;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.services.LazyLoader;
|
||||
import info.bukova.isspst.services.tripbill.TripBillService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.hibernate.LazyInitializationException;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripRequirement>
|
||||
implements TripRequirementService, RequirementBaseService<TripRequirement> {
|
||||
|
||||
@@ -36,6 +38,23 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
||||
return tr;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())")
|
||||
public void update(TripRequirement entity) {
|
||||
super.update(entity);
|
||||
|
||||
if (entity.getState() == RequirementState.APPROVED) {
|
||||
for (TripBill bill : getBills(entity)) {
|
||||
TripBill newBill = tripBillService.createTripBill(entity);
|
||||
bill.getBillItems().clear();
|
||||
bill.getBillItems().addAll(newBill.getBillItems());
|
||||
tripBillService.calculate(bill);
|
||||
tripBillService.update(bill);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@LazyLoader("form")
|
||||
@@ -55,15 +74,28 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("this.canApprove(#entity)")
|
||||
public void approve(TripRequirement entity) {
|
||||
super.approve(entity);
|
||||
public List<TripBill> getBills(TripRequirement entity) {
|
||||
Query q = queryDao.getQuery("from TripBill bill where bill.requirement = :req");
|
||||
q.setParameter("req", entity);
|
||||
return q.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postApprove(TripRequirement entity) {
|
||||
if (entity.getState() == RequirementState.APPROVED) {
|
||||
TripBill bill = tripBillService.createTripBill(entity);
|
||||
tripBillService.add(bill);
|
||||
bill.setOwnedBy(entity.getOwnedBy());
|
||||
tripBillService.update(bill);
|
||||
|
||||
for (User u : entity.getPassengers()) {
|
||||
if (!u.equals(entity.getOwnedBy())) {
|
||||
TripBill passBill = tripBillService.createTripBill(entity);
|
||||
tripBillService.add(passBill);
|
||||
passBill.setOwnedBy(u);
|
||||
tripBillService.update(passBill);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package info.bukova.isspst.services.users;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.security.AuthMethod;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -26,12 +27,14 @@ public class AdUserCtxMapper implements UserDetailsContextMapper {
|
||||
|
||||
private UserService userService;
|
||||
private RoleService roleService;
|
||||
private String allowedGroup;
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(AdUserCtxMapper.class);
|
||||
|
||||
public AdUserCtxMapper(UserService userService, RoleService roleService) {
|
||||
this.userService = userService;
|
||||
this.roleService = roleService;
|
||||
userService.setAuthMethod(AuthMethod.AD);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,7 +46,7 @@ public class AdUserCtxMapper implements UserDetailsContextMapper {
|
||||
return user;
|
||||
} catch (UsernameNotFoundException e) {
|
||||
logger.info("Importing user from Active Directory");
|
||||
LdapUserImporter importer = new LdapUserImporter(userService);
|
||||
LdapUserImporter importer = new LdapUserImporter(userService, allowedGroup);
|
||||
importer.importUser(username, userData, roleService.getRoleByAuthority(Constants.ROLE_USER));
|
||||
|
||||
return userService.loadUserByUsername(username);
|
||||
@@ -56,4 +59,8 @@ public class AdUserCtxMapper implements UserDetailsContextMapper {
|
||||
"use a subclass if mapUserToContext() is required.");
|
||||
}
|
||||
|
||||
public void setAllowedGroup(String allowedGroup) {
|
||||
this.allowedGroup = allowedGroup;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package info.bukova.isspst.services.users;
|
||||
|
||||
import info.bukova.isspst.services.IsspstException;
|
||||
|
||||
public class DeleteUserException extends IsspstException {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5326664758639660224L;
|
||||
|
||||
public DeleteUserException(String message) {
|
||||
super(message);
|
||||
setReason(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import javax.naming.NamingException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
/**
|
||||
* Pomocná třída pro import uživatele z LDAP serveru (nebo Active Directory) do databáze aplikace
|
||||
@@ -19,12 +20,18 @@ import org.springframework.ldap.core.DirContextOperations;
|
||||
public class LdapUserImporter {
|
||||
|
||||
private UserService userService;
|
||||
private String allowedGroup;
|
||||
private final static Logger logger = LoggerFactory.getLogger(LdapUserImporter.class);
|
||||
|
||||
public LdapUserImporter(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public LdapUserImporter(UserService userService, String group) {
|
||||
this.userService = userService;
|
||||
this.allowedGroup = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provede import uživatele z LDAP do aplikační databáze
|
||||
*
|
||||
@@ -37,6 +44,21 @@ public class LdapUserImporter {
|
||||
user.setUsername(login);
|
||||
user.addAuthority(defaultRole);
|
||||
|
||||
if (allowedGroup != null && !allowedGroup.isEmpty()) {
|
||||
boolean isAllowed = false;
|
||||
|
||||
for (Object atr : userData.getObjectAttributes("memberOf")) {
|
||||
if (atr.toString().startsWith("CN="+allowedGroup)) {
|
||||
isAllowed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAllowed) {
|
||||
throw new UsernameNotFoundException("User is not member of group '" + allowedGroup + "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (userData.attributeExists("givenName")) {
|
||||
try {
|
||||
user.setFirstName(userData.getAttributes().get("givenName").get().toString());
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package info.bukova.isspst.services.users;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import info.bukova.isspst.data.Permission;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
public interface PermissionService extends Service<Permission> {
|
||||
|
||||
public Permission getPermissionByModule(String moduleId, String permission);
|
||||
public List<Permission> getAllPermissions();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package info.bukova.isspst.services.users;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import info.bukova.isspst.data.Permission;
|
||||
import info.bukova.isspst.services.AbstractService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class PermissionServiceImpl extends AbstractService<Permission> implements PermissionService {
|
||||
|
||||
@Override
|
||||
@@ -13,5 +15,10 @@ public class PermissionServiceImpl extends AbstractService<Permission> implement
|
||||
return selectSingle("from Permission where MODULE = '" + moduleId + "' and AUTHORITY = '" + permission + "'");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<Permission> getAllPermissions() {
|
||||
return dao.getAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
import info.bukova.isspst.data.Role;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.UserSettingsData;
|
||||
import info.bukova.isspst.security.AuthMethod;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
@@ -24,4 +25,8 @@ public interface UserService extends UserDetailsService, Service<User> {
|
||||
public UserSettingsData getUserSettings(User user);
|
||||
public UserSettingsData getUserSettings();
|
||||
public void setUserSettings(UserSettingsData settings);
|
||||
public void setAuthMethod(AuthMethod method);
|
||||
public AuthMethod getAuthMethod();
|
||||
public List<User> getUsersForCombo();
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,13 @@ import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.data.Role;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.UserSettingsData;
|
||||
import info.bukova.isspst.security.AuthMethod;
|
||||
import info.bukova.isspst.services.AbstractService;
|
||||
import info.bukova.isspst.services.StringXmlMarshaller;
|
||||
//import info.bukova.isspst.services.LazyLoader;
|
||||
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -33,10 +36,14 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
||||
private PasswordEncoder encoder;
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
@Autowired
|
||||
private WorkgroupService workgroupService;
|
||||
private StringXmlMarshaller<UserSettingsData> marshaller;
|
||||
private AuthMethod authMethod;
|
||||
|
||||
public UserServiceImpl(Marshaller marshaller, Unmarshaller unmarshaller) {
|
||||
this.marshaller = new StringXmlMarshaller<UserSettingsData>(marshaller, unmarshaller, UserSettingsData.class);
|
||||
authMethod = AuthMethod.DATABASE;
|
||||
}
|
||||
|
||||
public void setEncoder(PasswordEncoder encoder) {
|
||||
@@ -202,4 +209,33 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
||||
return Constants.PERM_EDIT_OWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAuthMethod(AuthMethod method) {
|
||||
this.authMethod = method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthMethod getAuthMethod() {
|
||||
return authMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(User entity) {
|
||||
workgroupService.loadParents(entity);
|
||||
|
||||
if (entity.getParents().isEmpty()) {
|
||||
super.delete(entity);
|
||||
} else {
|
||||
throw new DeleteUserException("UserIsInWorkgroup");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Transactional
|
||||
public List<User> getUsersForCombo() {
|
||||
Query q = dao.getQuery("from User u order by u.lastName");
|
||||
return q.list();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,9 +13,11 @@ public class WorkgroupException extends IsspstException {
|
||||
public final static String MSUT_HAS_CENTER = "RoleMustHasCentre";
|
||||
public final static String MUST_HAS_WORKGROUP = "WorkgroupMustHasCentre";
|
||||
public final static String CYCLIC_MEMBER = "CyclicMembership";
|
||||
public final static String HAS_PARENT = "WorkgroupIsInWorkgroup";
|
||||
|
||||
public WorkgroupException(String message) {
|
||||
super(message);
|
||||
setReason(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -248,6 +248,11 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_DELETE')")
|
||||
public void delete(Workgroup entity) {
|
||||
Workgroup dbWg = dao.getById(entity.getId());
|
||||
if (!dbWg.getParents().isEmpty()) {
|
||||
throw new WorkgroupException(WorkgroupException.HAS_PARENT);
|
||||
}
|
||||
|
||||
loadMembers(entity);
|
||||
for (JobMapping m : entity.getMembers()) {
|
||||
loadParents(m.getMember());
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
package info.bukova.isspst.sort;
|
||||
|
||||
import info.bukova.isspst.StringUtils;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.Collator;
|
||||
import java.text.ParseException;
|
||||
import java.text.RuleBasedCollator;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.zk.ui.util.Clients;
|
||||
|
||||
public class CzechStringComparator implements Comparator<Object> {
|
||||
private String m_rule;
|
||||
private final String m_property;
|
||||
private final List<String> m_propertyPath;
|
||||
private final boolean m_ascending;
|
||||
private Method m_getter;
|
||||
private Comparator<Object> m_comparator;
|
||||
|
||||
public CzechStringComparator(String property, boolean ascending) {
|
||||
@@ -47,7 +49,7 @@ public class CzechStringComparator implements Comparator<Object> {
|
||||
m_rule += "< Y,y < Ý,ý ";
|
||||
m_rule += "< Z,z < Ź,ź < Ž,ž ";
|
||||
|
||||
m_property = property;
|
||||
m_propertyPath = StringUtils.split(property, ".");
|
||||
m_ascending = ascending;
|
||||
}
|
||||
|
||||
@@ -72,21 +74,56 @@ public class CzechStringComparator implements Comparator<Object> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private Object getValue(Object caller)
|
||||
{
|
||||
Object obj = caller;
|
||||
|
||||
for (String property : m_propertyPath)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Method method = ReflectionTools.getGetterMethod(obj, property);
|
||||
|
||||
try
|
||||
{
|
||||
obj = method.invoke(obj);
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
private int internalCompare(Object argL, Object argR)
|
||||
throws ParseException, IllegalAccessException,
|
||||
IllegalArgumentException, InvocationTargetException {
|
||||
if (m_getter == null) {
|
||||
m_getter = ReflectionTools.getGetterMethod(argL, m_property);
|
||||
}
|
||||
|
||||
if (m_comparator == null) {
|
||||
if (m_comparator == null)
|
||||
{
|
||||
Collator c = new RuleBasedCollator(m_rule);
|
||||
c.setStrength(Collator.TERTIARY);
|
||||
m_comparator = c;
|
||||
}
|
||||
|
||||
Object valL = m_getter.invoke(argL);
|
||||
Object valR = m_getter.invoke(argR);
|
||||
Object valL = this.getValue(argL);
|
||||
Object valR = this.getValue(argR);
|
||||
boolean isNullValL = (valL == null);
|
||||
boolean isNullValR = (valR == null);
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@ package info.bukova.isspst.ui;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.zkoss.bind.BindContext;
|
||||
import org.zkoss.bind.Converter;
|
||||
import org.zkoss.util.Locales;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
|
||||
public class BigDecimalConverter implements Converter<String, BigDecimal, Component>
|
||||
@@ -23,7 +25,8 @@ public class BigDecimalConverter implements Converter<String, BigDecimal, Compon
|
||||
{
|
||||
try
|
||||
{
|
||||
DecimalFormat format = new DecimalFormat();
|
||||
Locale loc = Locales.getCurrent();
|
||||
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(loc);
|
||||
format.setParseBigDecimal(true);
|
||||
val = (BigDecimal) format.parse(str);
|
||||
}
|
||||
@@ -43,6 +46,9 @@ public class BigDecimalConverter implements Converter<String, BigDecimal, Compon
|
||||
@Override
|
||||
public String coerceToUi(BigDecimal val, Component component, BindContext cx)
|
||||
{
|
||||
// String lang = Executions.getCurrent().getHeader("accept-language");
|
||||
Locale loc = Locales.getCurrent();
|
||||
|
||||
if (val == null)
|
||||
{
|
||||
val = BigDecimal.ZERO;
|
||||
@@ -50,13 +56,13 @@ public class BigDecimalConverter implements Converter<String, BigDecimal, Compon
|
||||
|
||||
val = val.setScale(2, BigDecimal.ROUND_DOWN);
|
||||
|
||||
DecimalFormat format = new DecimalFormat();
|
||||
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(loc);
|
||||
format.setMaximumFractionDigits(2);
|
||||
format.setMinimumFractionDigits(2);
|
||||
format.setGroupingUsed(true);
|
||||
format.setGroupingSize(3);
|
||||
|
||||
return format.format(val);
|
||||
String formatted = format.format(val);
|
||||
return formatted;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package info.bukova.isspst.ui;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.zkoss.bind.SimpleForm;
|
||||
@@ -34,12 +34,40 @@ public class BindingForm<T> extends SimpleForm {
|
||||
*/
|
||||
public void bindTo(T object) {
|
||||
for (String key : getFieldNames()) {
|
||||
try {
|
||||
BeanUtils.setProperty(object, key, getField(key));
|
||||
} catch (IllegalAccessException e) {
|
||||
// try {
|
||||
// BeanUtils.setProperty(object, key, getField(key));
|
||||
//
|
||||
// } catch (IllegalAccessException e) {
|
||||
// logger.warn("Cannot bind value", e);
|
||||
// } catch (InvocationTargetException e) {
|
||||
// logger.warn("Cannot bind value", e);
|
||||
// }
|
||||
try
|
||||
{
|
||||
if (PropertyUtils.getPropertyType(object, key).isPrimitive()
|
||||
&& (getField(key) == null))
|
||||
{
|
||||
PropertyUtils.setProperty(object, key, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
PropertyUtils.setProperty(object, key, getField(key));
|
||||
}
|
||||
}
|
||||
catch (NoSuchMethodException e)
|
||||
{
|
||||
logger.warn("Cannot bind value " + key + " (" + e.getMessage() + ")");
|
||||
// e.printStackTrace();
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
logger.warn("Cannot bind value", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
logger.warn("Cannot bind value", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,22 @@ import org.zkoss.bind.BindContext;
|
||||
import org.zkoss.bind.Converter;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
|
||||
public class BoolConverter implements Converter<String, Boolean, Component> {
|
||||
|
||||
public class BoolConverter implements Converter<String, Boolean, Component>
|
||||
{
|
||||
@Override
|
||||
public Boolean coerceToBean(String str, Component component, BindContext cx) {
|
||||
public Boolean coerceToBean(String str, Component component, BindContext cx)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String coerceToUi(Boolean val, Component component, BindContext cx) {
|
||||
return StringUtils.localize(val.toString());
|
||||
public String coerceToUi(Boolean val, Component component, BindContext cx)
|
||||
{
|
||||
if (val == null)
|
||||
{
|
||||
val = new Boolean(false);
|
||||
}
|
||||
|
||||
return StringUtils.localize(val.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.bukova.isspst.ui;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -17,6 +18,8 @@ public class DocumentViewModel
|
||||
{
|
||||
protected BigDecimalConverter standardBigDecimalConverter;
|
||||
|
||||
protected BoolConverter standardBoolConverter;
|
||||
|
||||
public BigDecimalConverter getStandardBigDecimalConverter()
|
||||
{
|
||||
return standardBigDecimalConverter;
|
||||
@@ -27,10 +30,31 @@ public class DocumentViewModel
|
||||
this.standardBigDecimalConverter = standardBigDecimalConverter;
|
||||
}
|
||||
|
||||
public BoolConverter getStandardBoolConverter()
|
||||
{
|
||||
return standardBoolConverter;
|
||||
}
|
||||
|
||||
public void setStandardBoolConverter(BoolConverter standardBoolConverter)
|
||||
{
|
||||
this.standardBoolConverter = standardBoolConverter;
|
||||
}
|
||||
|
||||
final public int getLengthText()
|
||||
{
|
||||
return Constants.LEN_TEXT;
|
||||
}
|
||||
|
||||
final public int getLengthDescription()
|
||||
{
|
||||
return Constants.LEN_DESCRIPTION;
|
||||
}
|
||||
|
||||
@Init
|
||||
public void initDocumentViewModel()
|
||||
{
|
||||
this.standardBigDecimalConverter = new BigDecimalConverter();
|
||||
this.standardBoolConverter = new BoolConverter();
|
||||
}
|
||||
|
||||
@Command
|
||||
|
||||
@@ -3,6 +3,7 @@ package info.bukova.isspst.ui;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.DataModel;
|
||||
import info.bukova.isspst.filters.Filter;
|
||||
import info.bukova.isspst.services.IsspstException;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -202,6 +203,18 @@ public class ListViewModel<T extends DataModel> extends DocumentViewModel
|
||||
BindUtils.postNotifyChange(null, null,
|
||||
ListViewModel.this, "dataBean");
|
||||
BindUtils.postGlobalCommand(null, null, "reloadRelated", null);
|
||||
} catch (IsspstException e) {
|
||||
if (e.getReason() != null) {
|
||||
Messagebox.show(
|
||||
StringUtils.localize(e.getReason()),
|
||||
StringUtils.localize("Error"),
|
||||
Messagebox.OK, Messagebox.ERROR);
|
||||
} else {
|
||||
Messagebox.show(
|
||||
StringUtils.localize("DbSaveError"),
|
||||
StringUtils.localize("Error"),
|
||||
Messagebox.OK, Messagebox.ERROR);
|
||||
}
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
Messagebox.show(StringUtils.localize("DbCannotDelete"), StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR);
|
||||
} catch (AccessDeniedException e) {
|
||||
@@ -300,6 +313,7 @@ public class ListViewModel<T extends DataModel> extends DocumentViewModel
|
||||
|
||||
if (selIndex > -1) {
|
||||
this.setDataBean(dataList.get(selIndex));
|
||||
afterSelect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,6 +321,10 @@ public class ListViewModel<T extends DataModel> extends DocumentViewModel
|
||||
|
||||
}
|
||||
|
||||
protected void afterSelect() {
|
||||
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange("dataBean")
|
||||
public void onSort(@BindingParam("column") String column) {
|
||||
@@ -335,26 +353,6 @@ public class ListViewModel<T extends DataModel> extends DocumentViewModel
|
||||
}
|
||||
}
|
||||
|
||||
// private void loadFromDb() {
|
||||
// Thread fillThread = new Thread(new Runnable() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// tmpList = service.getAll();
|
||||
//
|
||||
// try {
|
||||
// Thread.sleep(200);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// fullFill = true;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// fillThread.start();
|
||||
// }
|
||||
|
||||
@Command
|
||||
public void onPrint() {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
@@ -400,4 +398,9 @@ public class ListViewModel<T extends DataModel> extends DocumentViewModel
|
||||
{
|
||||
return this.isRecordSelected();
|
||||
}
|
||||
|
||||
public boolean isAbleToAdd()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package info.bukova.isspst.ui;
|
||||
|
||||
import info.bukova.isspst.security.AuthMethod;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
public class MainMenu
|
||||
@@ -10,6 +14,8 @@ public class MainMenu
|
||||
private String contextPath;
|
||||
|
||||
private String moduleUrl;
|
||||
@WireVariable
|
||||
private UserService userService;
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@@ -55,4 +61,8 @@ public class MainMenu
|
||||
Window window = (Window) Executions.createComponents("/settings/userSettings.zul", null, null);
|
||||
window.doModal();
|
||||
}
|
||||
|
||||
public boolean isCanChangePassword() {
|
||||
return userService.getAuthMethod() == AuthMethod.DATABASE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package info.bukova.isspst.ui.dashboard;
|
||||
import info.bukova.isspst.data.Role;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.services.approved.OrderService;
|
||||
import info.bukova.isspst.services.invoicing.InvoicingService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.ui.DocumentViewModel;
|
||||
@@ -24,7 +24,7 @@ public class DashBoardVM extends DocumentViewModel {
|
||||
@WireVariable
|
||||
private UserService userService;
|
||||
@WireVariable
|
||||
private OrderService orderService;
|
||||
private InvoicingService invoicingService;
|
||||
private User user;
|
||||
private Map<Workgroup, List<Role>> groupRoles;
|
||||
private Map<Workgroup, BigDecimal> workgroupSpent;
|
||||
@@ -47,7 +47,7 @@ public class DashBoardVM extends DocumentViewModel {
|
||||
for (Workgroup w : wg) {
|
||||
List<Role> r = workgroupService.getUserWorkgroupRoles(w, user);
|
||||
groupRoles.put(w, r);
|
||||
workgroupSpent.put(w, orderService.totalOrderedForWorkgroup(w));
|
||||
workgroupSpent.put(w, invoicingService.totalInvoicedForWorkgroup(w));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import info.bukova.isspst.reporting.GeneratorFactory;
|
||||
import info.bukova.isspst.reporting.ReportDefinition;
|
||||
import info.bukova.isspst.services.addressbook.AdbService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.ui.DocumentViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -27,7 +28,8 @@ import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
public class MailForm {
|
||||
public class MailForm extends DocumentViewModel
|
||||
{
|
||||
|
||||
@WireVariable
|
||||
private Mailer mailer;
|
||||
@@ -52,7 +54,7 @@ public class MailForm {
|
||||
private int adbType;
|
||||
private String findAddress;
|
||||
|
||||
@Init
|
||||
@Init(superclass = true)
|
||||
public void init(@ExecutionArgParam("report") Boolean report) {
|
||||
message = new MailMessage();
|
||||
message.setHtml(true);
|
||||
|
||||
@@ -5,8 +5,8 @@ import info.bukova.isspst.data.Order;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.filters.JoinedItemFilter;
|
||||
import info.bukova.isspst.services.approved.ApprovedService;
|
||||
import info.bukova.isspst.services.approved.OrderService;
|
||||
import info.bukova.isspst.services.orders.ApprovedService;
|
||||
import info.bukova.isspst.services.orders.OrderService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.ui.BigDecimalConverter;
|
||||
@@ -85,7 +85,7 @@ public class ApprovedList extends ListViewModel<JoinedItem>
|
||||
|
||||
public List<User> getUsers()
|
||||
{
|
||||
return this.userService.getAll();
|
||||
return this.userService.getUsersForCombo();
|
||||
}
|
||||
|
||||
@Command
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package info.bukova.isspst.ui.main.invoicing;
|
||||
|
||||
import info.bukova.isspst.data.Invoicing;
|
||||
import info.bukova.isspst.data.InvoicingItem;
|
||||
import info.bukova.isspst.services.invoicing.InvoicingService;
|
||||
import info.bukova.isspst.ui.FormViewModel;
|
||||
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
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;
|
||||
|
||||
public class InvoicingForm extends FormViewModel<Invoicing> {
|
||||
|
||||
private InvoicingItem selectedItem;
|
||||
private int selectedIndex;
|
||||
@WireVariable
|
||||
private InvoicingService invoicingService;
|
||||
|
||||
@Init(superclass = true)
|
||||
public void init() {
|
||||
selectedIndex = -1;
|
||||
}
|
||||
|
||||
private void selectItem(InvoicingItem item) {
|
||||
if (item != null) {
|
||||
selectedItem = item;
|
||||
selectedIndex = getDataBean().getItems().indexOf(item);
|
||||
} else {
|
||||
selectedItem = null;
|
||||
selectedIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({"dataBean", "selectedItem", "selectedIndex"})
|
||||
public void addItem() {
|
||||
InvoicingItem item = new InvoicingItem();
|
||||
getDataBean().getItems().add(item);
|
||||
selectItem(item);
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({"dataBean", "selectedItem", "selectedIndex"})
|
||||
public void removeItem(@BindingParam("item") InvoicingItem item) {
|
||||
getDataBean().getItems().remove(item);
|
||||
selectItem(null);
|
||||
calculate();
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({"selectedItem", "selectedIndex"})
|
||||
public void onFocus(@BindingParam("item") InvoicingItem item) {
|
||||
selectItem(item);
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange("dataBean")
|
||||
public void calculate() {
|
||||
invoicingService.calculate(getDataBean());
|
||||
}
|
||||
|
||||
public InvoicingItem getSelectedItem() {
|
||||
return selectedItem;
|
||||
}
|
||||
|
||||
public void setSelectedItem(InvoicingItem selectedItem) {
|
||||
this.selectedItem = selectedItem;
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return selectedIndex;
|
||||
}
|
||||
|
||||
public void setSelectedIndex(int selectedIndex) {
|
||||
this.selectedIndex = selectedIndex;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package info.bukova.isspst.ui.main.invoicing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import info.bukova.isspst.data.Invoicing;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.filters.InvoicingFilter;
|
||||
import info.bukova.isspst.services.invoicing.InvoicingService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.ui.ListViewModel;
|
||||
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
|
||||
public class InvoicingList extends ListViewModel<Invoicing> {
|
||||
|
||||
@WireVariable
|
||||
private InvoicingService invoicingService;
|
||||
@WireVariable
|
||||
private WorkgroupService workgroupService;
|
||||
@WireVariable
|
||||
private UserService userService;
|
||||
|
||||
@Init(superclass = true)
|
||||
public void initInvoicing() {
|
||||
service = invoicingService;
|
||||
dataClass = Invoicing.class;
|
||||
formZul = "invoicingForm.zul";
|
||||
dataFilter = new InvoicingFilter(getFilterTemplate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbleToAdd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbleToDelete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Workgroup> getCentres() {
|
||||
return workgroupService.getCentres();
|
||||
}
|
||||
|
||||
public List<Workgroup> getWorkgroups() {
|
||||
return workgroupService.getWorkgroups();
|
||||
}
|
||||
|
||||
public List<User> getUsers() {
|
||||
return userService.getUsersForCombo();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,14 +4,18 @@ import info.bukova.isspst.data.Address;
|
||||
import info.bukova.isspst.data.AddressEmb;
|
||||
import info.bukova.isspst.data.Order;
|
||||
import info.bukova.isspst.data.OrderItem;
|
||||
import info.bukova.isspst.services.IsspstException;
|
||||
import info.bukova.isspst.services.addressbook.AdbService;
|
||||
import info.bukova.isspst.services.approved.OrderService;
|
||||
import info.bukova.isspst.services.addressbook.AddressFinder;
|
||||
import info.bukova.isspst.services.orders.OrderService;
|
||||
import info.bukova.isspst.services.settings.GlobalSettingsService;
|
||||
import info.bukova.isspst.ui.FormViewModel;
|
||||
import info.bukova.isspst.validators.OrderFormValidator;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -19,9 +23,13 @@ import org.zkoss.bind.BindUtils;
|
||||
import org.zkoss.bind.SimpleForm;
|
||||
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;
|
||||
import org.zkoss.zul.impl.InputElement;
|
||||
|
||||
public class OrderForm extends FormViewModel<Order>
|
||||
@@ -29,7 +37,11 @@ public class OrderForm extends FormViewModel<Order>
|
||||
private final static Logger log = LoggerFactory.getLogger(OrderForm.class.getName());
|
||||
|
||||
@WireVariable
|
||||
protected AdbService adbService;
|
||||
private AdbService adbService;
|
||||
@WireVariable
|
||||
private AddressFinder addressFinderAres;
|
||||
@WireVariable
|
||||
private AddressFinder addressFinderTaxID;
|
||||
|
||||
@WireVariable
|
||||
protected GlobalSettingsService settingsService;
|
||||
@@ -51,19 +63,29 @@ public class OrderForm extends FormViewModel<Order>
|
||||
|
||||
protected List<OrderItem> syncOrderItems;
|
||||
|
||||
/**
|
||||
* Obsah záznamu před editací
|
||||
*/
|
||||
protected Order recordBeforeEdit;
|
||||
|
||||
@Init(superclass = true)
|
||||
public void initOrderForm()
|
||||
{
|
||||
this.orderFormValidator = new OrderFormValidator();
|
||||
|
||||
if (this.getDataBean().getSuplier() == null)
|
||||
if (getDataBean().getSuplier() != null)
|
||||
{
|
||||
if (getDataBean().getSuplier().getAddress().getId() != 0)
|
||||
{
|
||||
this.selectedSuppAddrItem = this.getDataBean().getSuplier().getAddress();
|
||||
}
|
||||
this.suppCompany = getDataBean().getSuplier().getCompany();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getDataBean().setSuplier(new AddressEmb());
|
||||
}
|
||||
|
||||
this.selectedSuppAddrItem = this.getDataBean().getSuplier().getAddress();
|
||||
this.suppCompany = this.selectedSuppAddrItem.getCompany();
|
||||
|
||||
if (this.getDataBean().getDeliveryAddress() == null)
|
||||
{
|
||||
this.getDataBean().setDeliveryAddress(new AddressEmb());
|
||||
@@ -78,6 +100,16 @@ public class OrderForm extends FormViewModel<Order>
|
||||
}
|
||||
|
||||
this.syncOrderItems = this.getDataBean().getItems();
|
||||
|
||||
try
|
||||
{
|
||||
this.recordBeforeEdit = (Order) this.getDataBean().clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
log.error("Nelze provést hlubokou kopii objednávky!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public OrderFormValidator getOrderFormValidator()
|
||||
@@ -165,10 +197,21 @@ public class OrderForm extends FormViewModel<Order>
|
||||
this.syncOrderItems = syncOrderItems;
|
||||
}
|
||||
|
||||
public Order getRecordBeforeEdit()
|
||||
{
|
||||
return recordBeforeEdit;
|
||||
}
|
||||
|
||||
public void setRecordBeforeEdit(Order recordBeforeEdit)
|
||||
{
|
||||
this.recordBeforeEdit = recordBeforeEdit;
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange("dataBean")
|
||||
public void doFillSuppAddress()
|
||||
{
|
||||
this.getDataForm().bind();
|
||||
AddressEmb addr;
|
||||
|
||||
if (this.selectedSuppAddrItem == null)
|
||||
@@ -190,6 +233,7 @@ public class OrderForm extends FormViewModel<Order>
|
||||
@NotifyChange("dataBean")
|
||||
public void doFillDeliveryAddress()
|
||||
{
|
||||
this.getDataForm().bind();
|
||||
AddressEmb addr;
|
||||
|
||||
if (this.selectedDeliveryAddrItem == null)
|
||||
@@ -252,4 +296,81 @@ public class OrderForm extends FormViewModel<Order>
|
||||
// Calculate total price at form
|
||||
this.calcAndUpdateFormTotalPrice(form);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doAdd()
|
||||
{
|
||||
// Zjisti, zda se změnil příznak objednávky (objednáno/neobjednáno)
|
||||
boolean orderedChanged = (this.recordBeforeEdit.isOrdered() != this.getDataBean().isOrdered());
|
||||
// Aktualizovat příznak schválených položek, aby se nemohli vložit do
|
||||
// jiných objednávek
|
||||
orderService.addApprovedItems(this.getDataBean(), orderedChanged);
|
||||
BindUtils.postGlobalCommand(null, null, "reload", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSave()
|
||||
{
|
||||
// Zjisti, zda se změnil příznak objednávky (objednáno/neobjednáno)
|
||||
boolean orderedChanged = (this.recordBeforeEdit.isOrdered() != this.getDataBean().isOrdered());
|
||||
// Aktualizovat příznak schválených položek, aby se nemohli vložit do
|
||||
// jiných objednávek
|
||||
orderService.updateApprovedItems(this.getDataBean(), orderedChanged);
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({"dataBean", "suppCompany"})
|
||||
public void searchAddress()
|
||||
{
|
||||
getDataForm().bind();
|
||||
|
||||
Address adr = getDataBean().getSuplier().getAddress();
|
||||
|
||||
if (adr.getIc() != 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
adbService.fillFoundData(addressFinderTaxID, adr);
|
||||
getDataBean().setSuplier(new AddressEmb(adr));
|
||||
suppCompany = adr.getCompany();
|
||||
}
|
||||
catch (IsspstException e)
|
||||
{
|
||||
Messagebox.show("Chyba při hledání adresy", "Chyba", Messagebox.OK, Messagebox.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Map<String, List<Address>> arg = new HashMap<String, List<Address>>();
|
||||
try {
|
||||
arg.put("result", adbService.lookForAddr(addressFinderAres, adr));
|
||||
} catch (IsspstException e) {
|
||||
Messagebox.show("Chyba při hledání adresy", "Chyba", Messagebox.OK, Messagebox.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
Window resWin = (Window) Executions.createComponents("/lists/addressbook/addrFindResult.zul", null, arg);
|
||||
resWin.doModal();
|
||||
}
|
||||
}
|
||||
|
||||
@GlobalCommand
|
||||
@NotifyChange({"dataBean", "suppCompany"})
|
||||
public void selectAddress(@BindingParam("selected") Address selected, @BindingParam("window") Window window) {
|
||||
try {
|
||||
adbService.fillFoundData(addressFinderTaxID, selected);
|
||||
} catch (IsspstException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Address adr = getDataBean().getSuplier().getAddress();
|
||||
adbService.mergeAddress(adr, selected, true);
|
||||
getDataBean().setSuplier(new AddressEmb(adr));
|
||||
suppCompany = adr.getCompany();
|
||||
|
||||
if (window != null)
|
||||
window.detach();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,11 @@ import info.bukova.isspst.data.SettingsData;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.filters.OrderFilter;
|
||||
import info.bukova.isspst.services.addressbook.AdbService;
|
||||
import info.bukova.isspst.services.approved.OrderService;
|
||||
import info.bukova.isspst.services.orders.OrderService;
|
||||
import info.bukova.isspst.services.settings.GlobalSettingsService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.ui.ListViewModel;
|
||||
import info.bukova.isspst.ui.renderers.OrderCreatedItemRenderer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -47,6 +48,8 @@ public class OrderList extends ListViewModel<Order>
|
||||
|
||||
protected List<OrderItem> orderItems;
|
||||
|
||||
protected OrderCreatedItemRenderer orderCreatedItemRenderer;
|
||||
|
||||
@Init(superclass = true)
|
||||
public void initOrderList()
|
||||
{
|
||||
@@ -55,6 +58,7 @@ public class OrderList extends ListViewModel<Order>
|
||||
formZul = "orderForm.zul";
|
||||
dataFilter = new OrderFilter(getFilterTemplate());
|
||||
this.orderItems = new ArrayList<OrderItem>();
|
||||
this.orderCreatedItemRenderer = new OrderCreatedItemRenderer();
|
||||
}
|
||||
|
||||
public List<AddressEmb> getSuppAddresses()
|
||||
@@ -117,6 +121,16 @@ public class OrderList extends ListViewModel<Order>
|
||||
this.orderItems = orderItems;
|
||||
}
|
||||
|
||||
public OrderCreatedItemRenderer getOrderCreatedItemRenderer()
|
||||
{
|
||||
return orderCreatedItemRenderer;
|
||||
}
|
||||
|
||||
public void setOrderCreatedItemRenderer(OrderCreatedItemRenderer orderCreatedItemRenderer)
|
||||
{
|
||||
this.orderCreatedItemRenderer = orderCreatedItemRenderer;
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange("orderItems")
|
||||
public void onChangeSelectOrder(@BindingParam("ctrl") Listbox lb)
|
||||
|
||||
@@ -17,10 +17,9 @@ public class ReqMaterialListMy extends ReqListMy
|
||||
@WireVariable
|
||||
protected RequirementService reqMaterialService;
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initReqMaterialListMy()
|
||||
{
|
||||
super.init();
|
||||
service = reqMaterialService;
|
||||
formZul = "/main/orders/material/reqHeadForm.zul";
|
||||
}
|
||||
|
||||
@@ -17,10 +17,9 @@ public class ReqMaterialListMyAll extends ReqListMyAll
|
||||
@WireVariable
|
||||
protected RequirementService reqMaterialService;
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initReqMaterialListMyAll()
|
||||
{
|
||||
super.init();
|
||||
service = reqMaterialService;
|
||||
formZul = "/main/orders/material/reqHeadForm.zul";
|
||||
}
|
||||
|
||||
+2
-3
@@ -17,10 +17,9 @@ public class ReqMaterialListMyCenters extends ReqListMyCenters
|
||||
@WireVariable
|
||||
protected RequirementService reqMaterialService;
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initReqMaterialListMyCenters()
|
||||
{
|
||||
super.init();
|
||||
service = reqMaterialService;
|
||||
formZul = "/main/orders/material/reqHeadForm.zul";
|
||||
}
|
||||
|
||||
+2
-3
@@ -17,10 +17,9 @@ public class ReqMaterialListMyWorkgroups extends ReqListMyWorkgroups
|
||||
@WireVariable
|
||||
protected RequirementService reqMaterialService;
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initReqMaterialListMyWorkgroups()
|
||||
{
|
||||
super.init();
|
||||
service = reqMaterialService;
|
||||
formZul = "/main/orders/material/reqHeadForm.zul";
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ public class SelectMaterialItems extends SelectItems
|
||||
private MaterialFilter dataFilterMaterial;
|
||||
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initSelectMaterialItems()
|
||||
{
|
||||
super.init();
|
||||
// super.init();
|
||||
|
||||
this.setFullMaterialList(materialService.getAll());
|
||||
this.setMaterialList(this.getFullMaterialList());
|
||||
|
||||
@@ -28,10 +28,9 @@ public class ReqListMy extends RequirementSubpage<Requirement>
|
||||
return workgroupService.getCentres();
|
||||
}
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initReqListMy()
|
||||
{
|
||||
super.init();
|
||||
service = requirementService;
|
||||
dataClass = Requirement.class;
|
||||
formZul = "/main/orders/requirements/reqForm.zul";
|
||||
|
||||
@@ -7,6 +7,7 @@ import info.bukova.isspst.services.requirement.RequirementService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.ui.requirement.RequirementSubpage;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,10 +31,9 @@ public class ReqListMyAll extends RequirementSubpage<Requirement>
|
||||
return workgroupService.getCentres();
|
||||
}
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initReqListMyAll()
|
||||
{
|
||||
super.init();
|
||||
service = requirementService;
|
||||
dataClass = Requirement.class;
|
||||
formZul = "/main/orders/requirements/reqForm.zul";
|
||||
@@ -65,4 +65,18 @@ public class ReqListMyAll extends RequirementSubpage<Requirement>
|
||||
protected void beforeSelectViaUrl() {
|
||||
BindUtils.postGlobalCommand(null, null, "selectAll", null);
|
||||
}
|
||||
|
||||
public BigDecimal getInvoicedAmount() {
|
||||
if (getDataBean() != null) {
|
||||
return requirementService.getInvoicedAmount(getDataBean());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotifyChange({ "dataBean", "ableToDelete", "canApprove", "invoicedAmount" })
|
||||
public void setDataBean(Requirement data) {
|
||||
super.setDataBean(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import info.bukova.isspst.services.requirement.RequirementService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.ui.requirement.RequirementSubpage;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,10 +31,9 @@ public class ReqListMyCenters extends RequirementSubpage<Requirement>
|
||||
return workgroupService.getUserCentres(userService.getCurrent());
|
||||
}
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initReqListMyCenters()
|
||||
{
|
||||
super.init();
|
||||
service = requirementService;
|
||||
dataClass = Requirement.class;
|
||||
formZul = "/main/orders/requirements/reqForm.zul";
|
||||
@@ -65,4 +65,18 @@ public class ReqListMyCenters extends RequirementSubpage<Requirement>
|
||||
protected void beforeSelectViaUrl() {
|
||||
BindUtils.postGlobalCommand(null, null, "selectCentre", null);
|
||||
}
|
||||
|
||||
public BigDecimal getInvoicedAmount() {
|
||||
if (getDataBean() != null) {
|
||||
return requirementService.getInvoicedAmount(getDataBean());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotifyChange({ "dataBean", "ableToDelete", "canApprove", "invoicedAmount" })
|
||||
public void setDataBean(Requirement data) {
|
||||
super.setDataBean(data);
|
||||
}
|
||||
}
|
||||
|
||||
+17
-3
@@ -7,6 +7,7 @@ import info.bukova.isspst.services.requirement.RequirementService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.ui.requirement.RequirementSubpage;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,10 +31,9 @@ public class ReqListMyWorkgroups extends RequirementSubpage<Requirement>
|
||||
return workgroupService.getCentres();
|
||||
}
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initReqListMyWorkgroups()
|
||||
{
|
||||
super.init();
|
||||
service = requirementService;
|
||||
dataClass = Requirement.class;
|
||||
formZul = "/main/orders/requirements/reqForm.zul";
|
||||
@@ -65,4 +65,18 @@ public class ReqListMyWorkgroups extends RequirementSubpage<Requirement>
|
||||
protected void beforeSelectViaUrl() {
|
||||
BindUtils.postGlobalCommand(null, null, "selectWorkgroup", null);
|
||||
}
|
||||
|
||||
public BigDecimal getInvoicedAmount() {
|
||||
if (getDataBean() != null) {
|
||||
return requirementService.getInvoicedAmount(getDataBean());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotifyChange({ "dataBean", "ableToDelete", "canApprove", "invoicedAmount" })
|
||||
public void setDataBean(Requirement data) {
|
||||
super.setDataBean(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.bukova.isspst.ui.main.orders.requirements;
|
||||
|
||||
import info.bukova.isspst.data.MUnitEmb;
|
||||
import info.bukova.isspst.data.Material;
|
||||
import info.bukova.isspst.data.Requirement;
|
||||
import info.bukova.isspst.data.RequirementItem;
|
||||
@@ -125,6 +126,7 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({ "selItemIndex", "selectedItem" })
|
||||
public void onFocusItem(@BindingParam("item") RequirementItem item, @BindingParam("ctrl") InputElement ctrl)
|
||||
{
|
||||
this.selItemIndex = this.getDataBean().getItems().indexOf(item);
|
||||
@@ -147,19 +149,20 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({ "syncItems", "selItemIndex" })
|
||||
@NotifyChange({ "syncItems", "selItemIndex", "selectedItem" })
|
||||
public void removeItem(@BindingParam("form") SimpleForm form, @BindingParam("item") RequirementItem item)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
this.getDataBean().getItems().remove(item);
|
||||
this.setSelItemIndex(-1);
|
||||
this.selItemIndex = -1;
|
||||
this.selectedItem = null;
|
||||
this.calcAndUpdateFormTotalPrice(form);
|
||||
}
|
||||
}
|
||||
|
||||
@GlobalCommand("insertSelectedItem")
|
||||
@NotifyChange({ "syncItems", "selItemIndex" })
|
||||
@NotifyChange({ "syncItems", "selItemIndex", "selectedItem" })
|
||||
public void insertSelectedItem(@BindingParam("selected") RequirementSubject selected, @BindingParam("window") Window window)
|
||||
{
|
||||
if (selected != null)
|
||||
@@ -180,7 +183,14 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
if (isMaterial)
|
||||
{
|
||||
Material materialItem = (Material) selected;
|
||||
item.setMunit(materialItem.getMunit());
|
||||
MUnitEmb unit = materialItem.getMunit();
|
||||
|
||||
// if (unit == null)
|
||||
// {
|
||||
// unit = new MUnitEmb();
|
||||
// }
|
||||
|
||||
item.setMunit(unit);
|
||||
}
|
||||
|
||||
this.setSelectedItem(item);
|
||||
@@ -195,7 +205,7 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({ "selectedItem", "syncItems" })
|
||||
@NotifyChange({ "selectedItem" })
|
||||
public void recalculate(@BindingParam("form") SimpleForm form, @BindingParam("changed") String source)
|
||||
{
|
||||
if (this.selectedItem == null)
|
||||
@@ -219,7 +229,7 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({ "selectedItem", "syncItems" })
|
||||
@NotifyChange({ "selectedItem" })
|
||||
public void onChangeGroup()
|
||||
{
|
||||
// Někdo změnil skupinu materiálu nebo služby
|
||||
@@ -234,6 +244,15 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
|
||||
if (subject != null)
|
||||
{
|
||||
boolean isMaterial = (subject instanceof Material);
|
||||
|
||||
if (isMaterial)
|
||||
{
|
||||
Material materialItem = (Material) subject;
|
||||
MUnitEmb munit = materialItem.getMunit();
|
||||
this.selectedItem.setMunit(munit);
|
||||
}
|
||||
|
||||
// Skupina materiálu nebo služeb je propojená, nastavit k zadanému
|
||||
// kódu i správný název skupiny materiálu nebo služby
|
||||
this.selectedItem.setName(subject.getName());
|
||||
@@ -241,7 +260,7 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({ "selectedItem", "syncItems" })
|
||||
@NotifyChange({ "syncItems", "selectedItem", "selItemIndex" })
|
||||
public void addNewItem()
|
||||
{
|
||||
RequirementItem item = new RequirementItem();
|
||||
@@ -254,10 +273,11 @@ public class RequirementForm extends FormViewModel<Requirement>
|
||||
item.setUnitPrice(BigDecimal.valueOf(0));
|
||||
item.setTotal(BigDecimal.valueOf(0));
|
||||
item.setDescription("");
|
||||
item.setMunit(null);
|
||||
item.setMunit(new MUnitEmb());
|
||||
|
||||
this.setSelectedItem(item);
|
||||
this.getDataBean().addItem(item);
|
||||
this.setSelItemIndex(this.getDataBean().getItems().indexOf(item));
|
||||
|
||||
this.selItemIndex = this.getDataBean().getItems().indexOf(item);
|
||||
this.selectedItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,14 @@ package info.bukova.isspst.ui.main.orders.requirements;
|
||||
import info.bukova.isspst.data.MUnitEmb;
|
||||
import info.bukova.isspst.data.RequirementSubject;
|
||||
import info.bukova.isspst.services.munits.MUnitService;
|
||||
import info.bukova.isspst.ui.DocumentViewModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
|
||||
public class SelectItems
|
||||
public class SelectItems extends DocumentViewModel
|
||||
{
|
||||
protected RequirementSubject selectedItem;
|
||||
|
||||
@@ -19,8 +20,8 @@ public class SelectItems
|
||||
protected List<MUnitEmb> munitList;
|
||||
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initSelectItems()
|
||||
{
|
||||
this.setMunitList(munitService.getEmbAll());
|
||||
}
|
||||
|
||||
@@ -17,10 +17,9 @@ public class ReqServicesListMy extends ReqListMy
|
||||
@WireVariable
|
||||
protected RequirementService reqServicesService;
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initReqServicesListMy()
|
||||
{
|
||||
super.init();
|
||||
service = reqServicesService;
|
||||
formZul = "/main/orders/services/reqHeadForm.zul";
|
||||
}
|
||||
|
||||
@@ -17,10 +17,9 @@ public class ReqServicesListMyAll extends ReqListMyAll
|
||||
@WireVariable
|
||||
protected RequirementService reqServicesService;
|
||||
|
||||
@Init
|
||||
public void init()
|
||||
@Init(superclass = true)
|
||||
public void initReqServicesListMyAll()
|
||||
{
|
||||
super.init();
|
||||
service = reqServicesService;
|
||||
formZul = "/main/orders/services/reqHeadForm.zul";
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user