Compare commits
68 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b0fedfa3f3 | |||
| dc0607c072 | |||
| 4d74b0a3fe | |||
| 3b3e4b38e6 | |||
| c2ca2e45ec | |||
| aaa89a2653 | |||
| fbc7a02161 | |||
| e5a8e0f0d9 | |||
| 0f169f8be9 | |||
| b6d0546b48 | |||
| a6799064f7 | |||
| 933f5e784b | |||
| 04dc8a5587 | |||
| b63a2c3944 | |||
| 67629cf312 | |||
| cdd2f81cad | |||
| c292c3bcde | |||
| 9d202192ee | |||
| 93a463db69 | |||
| 3a5da06c48 | |||
| 76969a2baf | |||
| 4e6af2ceed | |||
| ef431867e1 | |||
| 25c8405f03 | |||
| ac90b0a2e3 | |||
| 9c5679af2c | |||
| ceac59c8d3 | |||
| 5d9e6226d3 | |||
| b470559cb7 | |||
| 9b8bfe2228 | |||
| 42deec695a | |||
| e01e32f10c | |||
| f13bc6e5c4 | |||
| 021d73bf48 | |||
| 340abb5269 | |||
| 724f6b3559 | |||
| ecd3cf426b | |||
| c6ebf8959b | |||
| 48d2c75d7b | |||
| 1d2810f78d | |||
| c4f5671327 | |||
| 860c7227cd | |||
| f94afbc3ed | |||
| 1df90a41c4 | |||
| 93e1ef1fd3 | |||
| 277ea0f993 | |||
| 884bc8267d | |||
| 678c140a94 | |||
| 566b408ddd | |||
| 9ec15943ed | |||
| ecbc2be47c | |||
| 024f1321ad | |||
| ea64e5a888 | |||
| 08532dcd02 | |||
| c04f74c5a2 | |||
| eed31fe6da | |||
| 61a4b3ba82 | |||
| ee2539000c | |||
| 0f02efbec3 | |||
| b357d0a7ef | |||
| 100889d44a | |||
| 765c56f250 | |||
| f5e69ce80d | |||
| e9cd08c249 | |||
| 34f1bb86de | |||
| ad2a861a7b | |||
| cf6c523698 | |||
| 02311ae5dd |
@@ -215,16 +215,20 @@
|
||||
|
||||
<!-- Hibernate -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>4.2.8.Final</version>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>4.2.8.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>4.3.0.Final</version>
|
||||
</dependency>
|
||||
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>4.3.0.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-search</artifactId>
|
||||
<version>4.4.6.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ZK -->
|
||||
<dependency>
|
||||
@@ -345,6 +349,19 @@
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Text extractors -->
|
||||
<dependency>
|
||||
<groupId>org.apache.odftoolkit</groupId>
|
||||
<artifactId>simple-odf</artifactId>
|
||||
<version>0.7-incubating</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>3.11</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.fulltext.FullTextService;
|
||||
import info.bukova.isspst.services.munits.MUnitService;
|
||||
import info.bukova.isspst.services.numberseries.NumberSeriesService;
|
||||
import info.bukova.isspst.services.requirement.RequirementTypeService;
|
||||
@@ -19,19 +20,17 @@ import info.bukova.isspst.services.settings.GlobalSettingsService;
|
||||
import info.bukova.isspst.services.users.PermissionService;
|
||||
import info.bukova.isspst.services.users.RoleService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public class AppInitListener implements ServletContextListener {
|
||||
|
||||
|
||||
@@ -43,6 +42,7 @@ public class AppInitListener implements ServletContextListener {
|
||||
private NumberSeriesService nsService;
|
||||
private RequirementTypeService reqTypeService;
|
||||
private GlobalSettingsService gSettingsService;
|
||||
private FullTextService ftService;
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent arg0) {
|
||||
@@ -63,6 +63,7 @@ public class AppInitListener implements ServletContextListener {
|
||||
nsService =ctx.getBean(NumberSeriesService.class);
|
||||
gSettingsService = ctx.getBean(GlobalSettingsService.class);
|
||||
reqTypeService = ctx.getBean(RequirementTypeService.class);
|
||||
ftService = ctx.getBean(FullTextService.class);
|
||||
|
||||
userService.grantAdmin();
|
||||
this.checkDbInfo();
|
||||
@@ -74,11 +75,15 @@ public class AppInitListener implements ServletContextListener {
|
||||
this.checkNumberSeries();
|
||||
checkReqTypes();
|
||||
this.checkGlobalSettings();
|
||||
buildFulltext();
|
||||
userService.removeAccess();
|
||||
|
||||
loadModuleReports();
|
||||
}
|
||||
|
||||
private void buildFulltext() {
|
||||
ftService.reindex();
|
||||
}
|
||||
private void checkDbInfo()
|
||||
{
|
||||
List<User> userList = userService.getAll();
|
||||
@@ -223,6 +228,9 @@ public class AppInitListener implements ServletContextListener {
|
||||
|
||||
private void checkPermissions() {
|
||||
for (Module m : Constants.MODULES) {
|
||||
if (!m.isDefaultPermissions()) {
|
||||
continue;
|
||||
}
|
||||
for (Permission p : Constants.DEF_PERMISSIONS) {
|
||||
if (permService.getPermissionByModule(m.getId(), p.getAuthority()) == null) {
|
||||
p.setModule(m.getId());
|
||||
|
||||
@@ -1,13 +1,48 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import org.jfree.util.Log;
|
||||
|
||||
public class BooleanUtils
|
||||
{
|
||||
public static boolean isEqualByBoolean(Boolean b1, Boolean b2)
|
||||
private static final String TAG = BooleanUtils.class.getSimpleName();
|
||||
|
||||
public static boolean isEqualByBooleanValue(Boolean b1, Boolean b2)
|
||||
{
|
||||
boolean bool1 = ((b1 == null) ? false : b1.booleanValue());
|
||||
boolean bool2 = ((b2 == null) ? false : b2.booleanValue());
|
||||
boolean equals = (bool1 == bool2);
|
||||
return equals;
|
||||
}
|
||||
|
||||
public static boolean isEqualByBoolean(Boolean b1, Boolean b2)
|
||||
{
|
||||
if ((b1 == null) && (b2 == null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ((b1 != null) && (b2 != null))
|
||||
{
|
||||
return (b1.booleanValue() == b2.booleanValue());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isEqualFilterByBoolean(Boolean value, Boolean filterValue)
|
||||
{
|
||||
if (filterValue == null)
|
||||
{
|
||||
// Show all records
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
// Fuck!!! Tri-state data (null, false, true)... We need new solution for selecting ALL data
|
||||
Log.warn(TAG + "\nVelky Boolean v databazi... Pozor na filtrovani.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return (value.booleanValue() == filterValue.booleanValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import info.bukova.isspst.data.Order;
|
||||
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.TripBill;
|
||||
import info.bukova.isspst.data.TripBillApproval;
|
||||
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.buildings.BuildingService;
|
||||
import info.bukova.isspst.services.fulltext.FullTextService;
|
||||
import info.bukova.isspst.services.invoicing.InvoicingService;
|
||||
import info.bukova.isspst.services.munits.MUnitService;
|
||||
import info.bukova.isspst.services.orders.ApprovedService;
|
||||
@@ -30,7 +34,7 @@ import java.util.Map;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public final static long DB_VERSION = 2;
|
||||
public final static long DB_VERSION = 5;
|
||||
|
||||
public final static String DEF_ADMIN = "admin";
|
||||
public final static String DEF_ADMIN_PASSWD = "admin";
|
||||
@@ -81,6 +85,7 @@ public class Constants {
|
||||
public final static String MOD_APPROVED = "APPROVED";
|
||||
public final static String MOD_ORDER = "ORDER";
|
||||
public final static String MOD_INVOICING = "INVOICING";
|
||||
public final static String MOD_SEARCH = "SEARCH";
|
||||
public final static Module MODULES[] = {
|
||||
new Module(MOD_USERS, "Uživatelé", UserService.class),
|
||||
new Module(MOD_PERMISSIONS, "Práva", RoleService.class),
|
||||
@@ -96,7 +101,9 @@ public class Constants {
|
||||
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_INVOICING, "Fakturace požadavků", InvoicingService.class) };
|
||||
new Module(MOD_INVOICING, "Fakturace požadavků", InvoicingService.class),
|
||||
new Module(MOD_SEARCH, "Fulltextové vyhledávání", FullTextService.class, true, false),
|
||||
};
|
||||
|
||||
public final static String PERM_APPROVE = "PERM_APPROVE";
|
||||
public final static String PERM_SHOW_WORKGROUP_REQ = "PERM_SHOW_WORKGROUP_REQ";
|
||||
@@ -105,6 +112,7 @@ public class Constants {
|
||||
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 String PERM_SEARCH = "PERM_SEARCH";
|
||||
|
||||
public final static Permission SPECIAL_PERMISSIONS[] = {
|
||||
new Permission(PERM_EDIT_NEW, "Upravit neschválené", MOD_REQUIREMENTS, PermissionType.GLOBAL),
|
||||
@@ -120,6 +128,8 @@ public class Constants {
|
||||
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),
|
||||
new Permission(PERM_APPROVE, "Schválení", MOD_TRIPREQUIREMENTS, PermissionType.WORKGROUP),
|
||||
|
||||
new Permission(PERM_SEARCH, "Vyhledávat", MOD_SEARCH, PermissionType.GLOBAL),
|
||||
};
|
||||
|
||||
public final static String DYNAMIC_REPORT_NAME = "Tabulková sestava";
|
||||
@@ -127,7 +137,7 @@ public class Constants {
|
||||
new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresní karty", "address")),
|
||||
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_TRIPBILL, new Report("Vyúčtování", "tripBill", false, true, true)),
|
||||
new ReportMapping(MOD_ORDER, new Report("Objednávka", "order", true, true)),
|
||||
new ReportMapping(MOD_REQUIREMENTS, new Report("Požadavky", "requirements"))
|
||||
};
|
||||
@@ -146,8 +156,12 @@ public class Constants {
|
||||
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/");
|
||||
put(TripBillApproval.class, "/main/trips/requirements/");
|
||||
put(Order.class, "/main/orders/created/");
|
||||
put(TripBill.class, "/main/trips/bill/");
|
||||
}} );
|
||||
|
||||
public final static int LEN_TEXT = 255;
|
||||
public final static int LEN_DESCRIPTION = 8192;
|
||||
public final static int LEN_RESULT_MESSAGE = 8192;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import info.bukova.isspst.reporting.Report;
|
||||
import info.bukova.isspst.services.AbstractService;
|
||||
import info.bukova.isspst.services.ModuleNotActiveException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*
|
||||
* Třída reprezentuje informace o modulu (agendě).
|
||||
*
|
||||
*/
|
||||
public class Module {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private Class<?> serviceClass;
|
||||
private List<Report> reports;
|
||||
private boolean defaultPermissions;
|
||||
private boolean active;
|
||||
|
||||
public Class<?> getServiceClass() {
|
||||
return serviceClass;
|
||||
@@ -20,11 +30,42 @@ public class Module {
|
||||
this.serviceClass = serviceClass;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id identifikátor modulu
|
||||
* @param name jméno zobrazované v aplikaci
|
||||
* @param serviceClass servisní třída
|
||||
*/
|
||||
public Module(String id, String name, Class<?> serviceClass) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.serviceClass = serviceClass;
|
||||
reports = new ArrayList<Report>();
|
||||
defaultPermissions = true;
|
||||
active = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id identifikátor modulu
|
||||
* @param name jméno zobrazované v aplikaci
|
||||
* @param serviceClass servisní třída
|
||||
* @param active příznak, jestli je modul aktivní
|
||||
*/
|
||||
public Module(String id, String name, Class<?> serviceClass, boolean active) {
|
||||
this(id, name, serviceClass);
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id identifikátor modulu
|
||||
* @param name jméno zobrazované v aplikaci
|
||||
* @param serviceClass servisní třída
|
||||
* @param active příznak, jestli je modul aktivní.
|
||||
* @param defaultPermissions příznak určující jestli modul kontroluje výchozí práva (čtení, zápis, modifikace, mazání)
|
||||
*/
|
||||
public Module(String id, String name, Class<?> serviceClass, boolean active, boolean defaultPermissions) {
|
||||
this(id, name, serviceClass, active);
|
||||
this.defaultPermissions = defaultPermissions;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@@ -51,4 +92,33 @@ public class Module {
|
||||
this.reports.add(report);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pokud je true, modul kontroluje výchozí práva (čtení, zápis, modifikace, mazání). Má vliv
|
||||
* na generování formulářů v nastavení práv.
|
||||
*
|
||||
* @return výchozí práva. Default true
|
||||
*/
|
||||
public boolean isDefaultPermissions() {
|
||||
return defaultPermissions;
|
||||
}
|
||||
|
||||
public void setDefaultPermissions(boolean defaultPermissions) {
|
||||
this.defaultPermissions = defaultPermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Určuje, zda je modul aktivní. Neaktivní moduly nejsou viditelné v UI. Při pokusu o přístup přímo přes URL
|
||||
* se generuje výjimka {@link ModuleNotActiveException}. Pokud servisní třída modulu nedědí z {@link AbstractService},
|
||||
* musí se implementovat kontrola aktivity do příslušné třídy.
|
||||
*
|
||||
* @return aktivita. Default true
|
||||
*/
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleUtils {
|
||||
|
||||
public static List<Module> getActiveModules() {
|
||||
List<Module> modules = new ArrayList<Module>();
|
||||
|
||||
for (Module m : Arrays.asList(Constants.MODULES)) {
|
||||
if (m.isActive()) {
|
||||
modules.add(m);
|
||||
}
|
||||
}
|
||||
|
||||
return modules;
|
||||
}
|
||||
|
||||
public static Module getModule(Class<?> serviceClass) {
|
||||
for (Module m : Constants.MODULES) {
|
||||
if (Arrays.asList(serviceClass.getInterfaces()).contains(m.getServiceClass())) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Module getModule(String id) {
|
||||
for (Module m : Constants.MODULES) {
|
||||
if (m.getId().equals(id)) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isActive(String id) {
|
||||
return getModule(id).isActive();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class RequirementUrlResolver implements EntityUrlResolver {
|
||||
|
||||
Requirement req = (Requirement)entity;
|
||||
|
||||
if (req.getKind() == Constants.REQ_TYPE_MATERIAL) {
|
||||
if (req.getKind() != null && 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());
|
||||
|
||||
@@ -7,6 +7,15 @@ import org.zkoss.util.resource.Labels;
|
||||
|
||||
public class StringUtils
|
||||
{
|
||||
public static boolean isNullOrEmpty(String str)
|
||||
{
|
||||
return ((str == null) || (str.isEmpty()));
|
||||
}
|
||||
|
||||
public static boolean isNullOrTrimmedEmpty(String str)
|
||||
{
|
||||
return ((str == null) || (str.trim().isEmpty()));
|
||||
}
|
||||
|
||||
public static String nullToEmptyString(String str)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import info.bukova.isspst.data.TripBillApproval;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class TripBillAprovalUrlResolver implements EntityUrlResolver {
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Override
|
||||
public String entityUrl(Object entity) {
|
||||
String defUrl = request.getRequestURL().toString();
|
||||
defUrl = defUrl.substring(0, defUrl.indexOf(request.getServletPath()));
|
||||
|
||||
if (entity instanceof TripBillApproval) {
|
||||
String url = Constants.URL_MAP.get(entity.getClass());
|
||||
|
||||
return defUrl + url + "?select=" + String.valueOf(((TripBillApproval)entity).getBill().getRequirement().getId());
|
||||
}
|
||||
|
||||
return defUrl + "/app";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package info.bukova.isspst.dao;
|
||||
|
||||
import info.bukova.isspst.data.TripBillApproval;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public interface TripBillApprovalDao extends BaseDao<TripBillApproval> {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package info.bukova.isspst.dao.jpa;
|
||||
|
||||
import info.bukova.isspst.dao.TripBillApprovalDao;
|
||||
import info.bukova.isspst.data.TripBillApproval;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class TripBillApprovalDaoJPA extends BaseDaoJPA<TripBillApproval> implements TripBillApprovalDao {
|
||||
|
||||
}
|
||||
@@ -7,11 +7,18 @@ import java.util.List;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
import org.hibernate.search.annotations.Analyze;
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Index;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
|
||||
@Embeddable
|
||||
@Indexed
|
||||
public class AddressEmb
|
||||
{
|
||||
|
||||
private int id;
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String company;
|
||||
private String department;
|
||||
private String contactName;
|
||||
|
||||
@@ -11,7 +11,11 @@ import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
import org.hibernate.search.annotations.IndexedEmbedded;
|
||||
|
||||
@MappedSuperclass
|
||||
@Indexed
|
||||
public abstract class BaseData implements OwnedDataModel {
|
||||
|
||||
@Id
|
||||
@@ -24,9 +28,11 @@ public abstract class BaseData implements OwnedDataModel {
|
||||
private Date modified;
|
||||
@ManyToOne(fetch=FetchType.LAZY)
|
||||
@JoinColumn(name="OWNED_BY_ID")
|
||||
@IndexedEmbedded
|
||||
private User ownedBy;
|
||||
@ManyToOne(fetch=FetchType.LAZY)
|
||||
@JoinColumn(name="MODIFIED_BY_ID")
|
||||
@IndexedEmbedded
|
||||
private User modifiedBy;
|
||||
@Transient
|
||||
private boolean valid;
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.hibernate.search.annotations.Analyze;
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Index;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "FILE_CONTENTS")
|
||||
@Indexed
|
||||
public class FileContent {
|
||||
|
||||
@Id
|
||||
@Column(name = "ID")
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@Column(name = "CONTENT")
|
||||
@Type(type = "text")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String plainText;
|
||||
|
||||
@Column(name = "CONTENT_TYPE")
|
||||
private String contentType;
|
||||
|
||||
@Column(name = "PATH_IN_FILESYSTEM")
|
||||
private String pathInFilesystem;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPlainText() {
|
||||
return plainText;
|
||||
|
||||
}
|
||||
|
||||
public void setPlainText(String content) {
|
||||
this.plainText = content;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getPathInFilesystem() {
|
||||
return pathInFilesystem;
|
||||
}
|
||||
|
||||
public void setPathInFilesystem(String pathInFilesystem) {
|
||||
this.pathInFilesystem = pathInFilesystem;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof FileContent)) return false;
|
||||
|
||||
FileContent that = (FileContent) o;
|
||||
|
||||
if (id != that.id) return false;
|
||||
if (plainText != null ? !plainText.equals(that.plainText) : that.plainText != null) return false;
|
||||
if (contentType != null ? !contentType.equals(that.contentType) : that.contentType != null) return false;
|
||||
if (pathInFilesystem != null ? !pathInFilesystem.equals(that.pathInFilesystem) : that.pathInFilesystem != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id;
|
||||
result = 31 * result + (plainText != null ? plainText.hashCode() : 0);
|
||||
result = 31 * result + (contentType != null ? contentType.hashCode() : 0);
|
||||
result = 31 * result + (pathInFilesystem != null ? pathInFilesystem.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.search.annotations.Analyze;
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Index;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
import org.hibernate.search.annotations.IndexedEmbedded;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "FILE_METAINFO")
|
||||
@Indexed
|
||||
public class FileMetainfo extends BaseData {
|
||||
|
||||
@Column(name = "FILE_NAME")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String fileName;
|
||||
|
||||
@Column(name = "MODULE_ID")
|
||||
private String moduleId;
|
||||
|
||||
@Column(name = "RECORD_ID")
|
||||
private int recordId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "CONTENT_ID")
|
||||
@Cascade(CascadeType.SAVE_UPDATE)
|
||||
@IndexedEmbedded
|
||||
private FileContent content;
|
||||
|
||||
@Column(name = "MD5")
|
||||
private String md5;
|
||||
|
||||
@Column(name = "DESCRIPTION")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String description;
|
||||
|
||||
private void ensureContentExists() {
|
||||
if (content == null) {
|
||||
content = new FileContent();
|
||||
}
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getPathInFilesystem() {
|
||||
if (content != null) {
|
||||
return content.getPathInFilesystem();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPathInFilesystem(String pathInFilesystem) {
|
||||
ensureContentExists();
|
||||
content.setPathInFilesystem(pathInFilesystem);
|
||||
}
|
||||
|
||||
public String getModuleId() {
|
||||
return moduleId;
|
||||
}
|
||||
|
||||
public void setModuleId(String moduleId) {
|
||||
this.moduleId = moduleId;
|
||||
}
|
||||
|
||||
public int getRecordId() {
|
||||
return recordId;
|
||||
}
|
||||
|
||||
public void setRecordId(int recordId) {
|
||||
this.recordId = recordId;
|
||||
}
|
||||
|
||||
public FileContent getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(FileContent content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return md5;
|
||||
}
|
||||
|
||||
public void setMd5(String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
if (content != null) {
|
||||
return content.getContentType();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
ensureContentExists();
|
||||
content.setContentType(contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof FileMetainfo)) return false;
|
||||
|
||||
FileMetainfo that = (FileMetainfo) o;
|
||||
|
||||
if (recordId != that.recordId) return false;
|
||||
if (content != null ? !content.equals(that.content) : that.content != null) return false;
|
||||
if (description != null ? !description.equals(that.description) : that.description != null) return false;
|
||||
if (fileName != null ? !fileName.equals(that.fileName) : that.fileName != null) return false;
|
||||
if (md5 != null ? !md5.equals(that.md5) : that.md5 != null) return false;
|
||||
if (moduleId != null ? !moduleId.equals(that.moduleId) : that.moduleId != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = fileName != null ? fileName.hashCode() : 0;
|
||||
result = 31 * result + (moduleId != null ? moduleId.hashCode() : 0);
|
||||
result = 31 * result + recordId;
|
||||
result = 31 * result + (content != null ? content.hashCode() : 0);
|
||||
result = 31 * result + (md5 != null ? md5.hashCode() : 0);
|
||||
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,8 @@ import org.hibernate.annotations.LazyCollectionOption;
|
||||
|
||||
@Entity
|
||||
@Table(name = "INVOICING")
|
||||
public class Invoicing extends BaseData {
|
||||
public class Invoicing extends BaseData implements Cloneable
|
||||
{
|
||||
|
||||
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "REQUIREMENT_ID")
|
||||
@@ -31,6 +32,9 @@ public class Invoicing extends BaseData {
|
||||
@Column(name = "TOTAL_INVOICED", precision = 15, scale = 4)
|
||||
private BigDecimal totalInvoiced;
|
||||
|
||||
@Column(name = "COMPLETED")
|
||||
private boolean completed;
|
||||
|
||||
public Requirement getRequirement() {
|
||||
return requirement;
|
||||
}
|
||||
@@ -55,4 +59,20 @@ public class Invoicing extends BaseData {
|
||||
this.totalInvoiced = totalInvoiced;
|
||||
}
|
||||
|
||||
public boolean isCompleted()
|
||||
{
|
||||
return completed;
|
||||
}
|
||||
|
||||
public void setCompleted(boolean completed)
|
||||
{
|
||||
this.completed = completed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException
|
||||
{
|
||||
Invoicing cloned = (Invoicing) super.clone();
|
||||
return cloned;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -220,6 +222,23 @@ public class JoinedItem implements DataModel, FilterableRequirement
|
||||
this.ownedBy = owner;
|
||||
}
|
||||
|
||||
protected Boolean itemMaterial;
|
||||
|
||||
public boolean isItemMaterialReal()
|
||||
{
|
||||
return ((this.requirement != null) && (this.requirement.getKind() == Constants.REQ_TYPE_MATERIAL));
|
||||
}
|
||||
|
||||
public Boolean getItemMaterial()
|
||||
{
|
||||
return this.itemMaterial;
|
||||
}
|
||||
|
||||
public void setItemMaterial(Boolean value)
|
||||
{
|
||||
this.itemMaterial = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
|
||||
@@ -18,9 +18,15 @@ import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.search.annotations.Analyze;
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Index;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
import org.hibernate.search.annotations.IndexedEmbedded;
|
||||
|
||||
@Entity
|
||||
@Table(name = "ORDERS")
|
||||
@Indexed
|
||||
public class Order extends BaseData implements Cloneable
|
||||
{
|
||||
|
||||
@@ -47,6 +53,7 @@ public class Order extends BaseData implements Cloneable
|
||||
@AttributeOverride(name = "street", column = @Column(name = "SUPPLIER_STREET")),
|
||||
@AttributeOverride(name = "web", column = @Column(name = "SUPPLIER_WEB")),
|
||||
@AttributeOverride(name = "zipCode", column = @Column(name = "SUPPLIER_ZIP_CODE")) })
|
||||
@IndexedEmbedded
|
||||
private AddressEmb suplier;
|
||||
|
||||
@Embedded
|
||||
@@ -97,10 +104,12 @@ public class Order extends BaseData implements Cloneable
|
||||
private String deliveryType;
|
||||
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String description;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "order", orphanRemoval = true)
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
@IndexedEmbedded
|
||||
private List<OrderItem> items;
|
||||
|
||||
@Column(name = "TOTAL", precision = 15, scale = 4)
|
||||
|
||||
@@ -14,8 +14,14 @@ import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.search.annotations.Analyze;
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Index;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
|
||||
@Entity
|
||||
@Table(name = "ORDER_ITEM")
|
||||
@Indexed
|
||||
public class OrderItem
|
||||
{
|
||||
|
||||
@@ -28,9 +34,11 @@ public class OrderItem
|
||||
private String code;
|
||||
|
||||
@Column(name = "NAME")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String name;
|
||||
|
||||
@Column(name = "TEXTITEM")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String textItem;
|
||||
|
||||
@Column(name = "QUANTITY", precision = 15, scale = 4)
|
||||
@@ -46,6 +54,7 @@ public class OrderItem
|
||||
private BigDecimal total;
|
||||
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String description;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
|
||||
@@ -12,11 +12,16 @@ import javax.persistence.FetchType;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
import org.hibernate.search.annotations.IndexedEmbedded;
|
||||
|
||||
@Entity
|
||||
@Table(name = "REQUIREMENT")
|
||||
@Indexed
|
||||
public class Requirement extends RequirementBase
|
||||
{
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "requirement", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@IndexedEmbedded
|
||||
private List<RequirementItem> items;
|
||||
|
||||
@Column(name = "DELIVERYDATE")
|
||||
|
||||
@@ -19,8 +19,13 @@ import javax.persistence.OrderBy;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.search.annotations.Analyze;
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Index;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
|
||||
@MappedSuperclass
|
||||
@Indexed
|
||||
public class RequirementBase extends BaseData implements FilterableRequirement {
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@@ -31,10 +36,12 @@ public class RequirementBase extends BaseData implements FilterableRequirement {
|
||||
@OrderBy("CENTRE, WORDER")
|
||||
private List<Workflow> workflow;
|
||||
@Column(name = "NUMSER", unique = true)
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String numser;
|
||||
@Column(name = "REQ_DATE")
|
||||
private Date reqDate;
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String description;
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "CENTRE_ID")
|
||||
|
||||
@@ -14,8 +14,15 @@ import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.search.annotations.Analyze;
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Index;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
import org.hibernate.search.annotations.IndexedEmbedded;
|
||||
|
||||
@Entity
|
||||
@Table(name = "REQUIREMENT_ITEMS")
|
||||
@Indexed
|
||||
public class RequirementItem
|
||||
{
|
||||
@Id
|
||||
@@ -35,9 +42,11 @@ public class RequirementItem
|
||||
private String code;
|
||||
|
||||
@Column(name = "NAME")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String name;
|
||||
|
||||
@Column(name = "TEXTITEM")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String textItem;
|
||||
|
||||
@Column(name = "QUANTITY", precision=15, scale=4)
|
||||
@@ -53,6 +62,7 @@ public class RequirementItem
|
||||
private BigDecimal total;
|
||||
|
||||
@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String description;
|
||||
|
||||
@Column(name = "DELIVERED")
|
||||
|
||||
@@ -14,6 +14,8 @@ public class SettingsData {
|
||||
private MailMessage newReqTemplate;
|
||||
private MailMessage authReqTemplate;
|
||||
private MailMessage confReqTemplate;
|
||||
private MailMessage confReqTripPassenger;
|
||||
private MailMessage reqPassenger;
|
||||
private Address mainAddress;
|
||||
private List<Address> shippingAddrs;
|
||||
private String bankName;
|
||||
@@ -22,11 +24,14 @@ public class SettingsData {
|
||||
private List<Vehicle> vehicles;
|
||||
private Map<Integer, BigDecimal[]> refunds;
|
||||
private String stampFile;
|
||||
private String logoFile;
|
||||
|
||||
public SettingsData() {
|
||||
newReqTemplate = new MailMessage();
|
||||
authReqTemplate = new MailMessage();
|
||||
confReqTemplate = new MailMessage();
|
||||
confReqTripPassenger = new MailMessage();
|
||||
reqPassenger = new MailMessage();
|
||||
mainAddress = new Address();
|
||||
shippingAddrs = new ArrayList<Address>();
|
||||
vehicles = new ArrayList<Vehicle>();
|
||||
@@ -140,4 +145,29 @@ public class SettingsData {
|
||||
this.stampFile = stampFile;
|
||||
}
|
||||
|
||||
public String getLogoFile()
|
||||
{
|
||||
return logoFile;
|
||||
}
|
||||
|
||||
public void setLogoFile(String logoFile)
|
||||
{
|
||||
this.logoFile = logoFile;
|
||||
}
|
||||
|
||||
public MailMessage getConfReqTripPassenger() {
|
||||
return confReqTripPassenger;
|
||||
}
|
||||
|
||||
public void setConfReqTripPassenger(MailMessage confReqTripPassenger) {
|
||||
this.confReqTripPassenger = confReqTripPassenger;
|
||||
}
|
||||
|
||||
public MailMessage getReqPassenger() {
|
||||
return reqPassenger;
|
||||
}
|
||||
|
||||
public void setReqPassenger(MailMessage reqPassenger) {
|
||||
this.reqPassenger = reqPassenger;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.storage.EntityWithAttachment;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -16,10 +19,16 @@ import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.search.annotations.Analyze;
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Index;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
import org.hibernate.search.annotations.IndexedEmbedded;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TRIP_BILL")
|
||||
public class TripBill extends BaseData {
|
||||
@Indexed
|
||||
public class TripBill extends BaseData implements EntityWithAttachment {
|
||||
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "REQUIREMENT_ID")
|
||||
@@ -28,6 +37,11 @@ public class TripBill extends BaseData {
|
||||
private Date resultMessageDate;
|
||||
@Column(name = "SIGN_DATE")
|
||||
private Date signDate;
|
||||
|
||||
@Column(name = "RESULT_MESSAGE", length = Constants.LEN_RESULT_MESSAGE)
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String resultMessage;
|
||||
|
||||
@Column(name = "FREE_MEALS")
|
||||
private boolean freeMeals;
|
||||
@Column(name = "FREE_HOUSING")
|
||||
@@ -44,9 +58,19 @@ public class TripBill extends BaseData {
|
||||
private BigDecimal downPayment;
|
||||
@Column(name = "TOTAL", precision = 15, scale = 4)
|
||||
private BigDecimal total;
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
@IndexedEmbedded
|
||||
private List<FileMetainfo> attachedFiles;
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "APPROVAL_ID")
|
||||
private TripBillApproval approval;
|
||||
@Column(name = "SAVED")
|
||||
private Boolean saved;
|
||||
|
||||
public TripBill() {
|
||||
billItems = new ArrayList<TripBillItem>();
|
||||
attachedFiles = new ArrayList<FileMetainfo>();
|
||||
}
|
||||
|
||||
public TripRequirement getRequirement() {
|
||||
@@ -73,6 +97,16 @@ public class TripBill extends BaseData {
|
||||
this.signDate = signDate;
|
||||
}
|
||||
|
||||
public String getResultMessage()
|
||||
{
|
||||
return resultMessage;
|
||||
}
|
||||
|
||||
public void setResultMessage(String resultMessage)
|
||||
{
|
||||
this.resultMessage = resultMessage;
|
||||
}
|
||||
|
||||
public boolean isFreeMeals() {
|
||||
return freeMeals;
|
||||
}
|
||||
@@ -121,4 +155,37 @@ public class TripBill extends BaseData {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<FileMetainfo> getAttachedFiles() {
|
||||
return attachedFiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAttachment(FileMetainfo metaInfo) {
|
||||
attachedFiles.add(metaInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(FileMetainfo metainfo) {
|
||||
attachedFiles.remove(metainfo);
|
||||
}
|
||||
|
||||
public void setAttachedFiles(List<FileMetainfo> attachedFiles) {
|
||||
this.attachedFiles = attachedFiles;
|
||||
}
|
||||
|
||||
public TripBillApproval getApproval() {
|
||||
return approval;
|
||||
}
|
||||
|
||||
public void setApproval(TripBillApproval approval) {
|
||||
this.approval = approval;
|
||||
}
|
||||
|
||||
public Boolean getSaved() {
|
||||
return saved;
|
||||
}
|
||||
|
||||
public void setSaved(Boolean saved) {
|
||||
this.saved = saved;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
|
||||
@Entity
|
||||
@Table(name = "TRIP_BILL_APPROVAL")
|
||||
public class TripBillApproval extends RequirementBase {
|
||||
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "TRIPBILL_ID")
|
||||
private TripBill bill;
|
||||
|
||||
@Override
|
||||
public String getNumser() {
|
||||
|
||||
if (bill == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
TripRequirement tr = bill.getRequirement();
|
||||
|
||||
if (tr == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return tr.getNumser();
|
||||
}
|
||||
|
||||
public TripBill getBill() {
|
||||
return bill;
|
||||
}
|
||||
|
||||
public void setBill(TripBill bill) {
|
||||
this.bill = bill;
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,14 @@ package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TRIP_BILL_ITEMS")
|
||||
@@ -65,6 +64,35 @@ public class TripBillItem extends BaseData {
|
||||
@Column(name = "ADJUSTED_TOTAL", precision = 15, scale = 4)
|
||||
private BigDecimal adjustedTotal;
|
||||
|
||||
public TripBillItem() {
|
||||
|
||||
}
|
||||
|
||||
public TripBillItem(TripBillItem src) {
|
||||
date = src.getDate();
|
||||
to = src.getTo();
|
||||
back = src.getBack();
|
||||
toDeparture = src.getToDeparture();
|
||||
toArrival = src.getToArrival();
|
||||
backDeparture = src.getBackDeparture();
|
||||
backArrival = src.getBackArrival();
|
||||
toVehicle = src.getToVehicle();
|
||||
backVehicle = src.getBackVehicle();
|
||||
beginWork = src.getBeginWork();
|
||||
endWork = src.getEndWork();
|
||||
freeMealsCount = src.getFreeMealsCount();
|
||||
distance = src.getDistance();
|
||||
fuelConsumption = src.getFuelConsumption();
|
||||
distanceAmount = src.getDistanceAmount();
|
||||
fuelAmount = src.getFuelAmount();
|
||||
carefare = src.getCarefare();
|
||||
housing = src.getHousing();
|
||||
meals = src.getMeals();
|
||||
otherExpenses = src.getOtherExpenses();
|
||||
total = src.getTotal();
|
||||
adjustedTotal = src.getAdjustedTotal();
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
@@ -1,28 +1,40 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.storage.EntityWithAttachment;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.search.annotations.Analyze;
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Index;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
import org.hibernate.search.annotations.IndexedEmbedded;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TRIPREQUIREMENT")
|
||||
public class TripRequirement extends RequirementBase {
|
||||
@Indexed
|
||||
public class TripRequirement extends RequirementBase implements EntityWithAttachment {
|
||||
|
||||
@Column(name = "TRIP_FROM")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String from;
|
||||
@Column(name = "TRIP_TO")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String to;
|
||||
@Column(name = "TRIP_DATE")
|
||||
private Date tripDate;
|
||||
@@ -34,16 +46,28 @@ public class TripRequirement extends RequirementBase {
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
@JoinTable(name="TRIPREQUIREMENT_PASSANGER", joinColumns={@JoinColumn(name="TRIPREQUIREMENT_ID")}, inverseJoinColumns={@JoinColumn(name="USER_ID")})
|
||||
private List<User> passengers;
|
||||
|
||||
@Column(name = "FOREIGN_PERSONS")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String foreignPersons;
|
||||
|
||||
@Embedded
|
||||
private Vehicle vehicle;
|
||||
@Column(name = "REQUIRE_DOWN_PAYMENT")
|
||||
private Boolean requireDownPayment;
|
||||
@Column(name = "DOWN_PAYMENT", precision = 15, scale = 4)
|
||||
private BigDecimal downPayment;
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
@IndexedEmbedded
|
||||
private List<FileMetainfo> attachedFiles;
|
||||
@Column(name = "BILL_FOR_PASSENGERS")
|
||||
private Boolean billForPassengers;
|
||||
|
||||
public TripRequirement() {
|
||||
this.setOwnedBy(new User());
|
||||
passengers = new ArrayList<User>();
|
||||
attachedFiles = new ArrayList<FileMetainfo>();
|
||||
}
|
||||
|
||||
public String getFrom() {
|
||||
@@ -94,6 +118,16 @@ public class TripRequirement extends RequirementBase {
|
||||
this.passengers = passengers;
|
||||
}
|
||||
|
||||
public String getForeignPersons()
|
||||
{
|
||||
return foreignPersons;
|
||||
}
|
||||
|
||||
public void setForeignPersons(String foreignPersons)
|
||||
{
|
||||
this.foreignPersons = foreignPersons;
|
||||
}
|
||||
|
||||
public Vehicle getVehicle() {
|
||||
return vehicle;
|
||||
}
|
||||
@@ -118,4 +152,30 @@ public class TripRequirement extends RequirementBase {
|
||||
this.downPayment = downPayment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileMetainfo> getAttachedFiles() {
|
||||
return attachedFiles;
|
||||
}
|
||||
|
||||
public void setAttachedFiles(List<FileMetainfo> attachedFiles) {
|
||||
this.attachedFiles = attachedFiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAttachment(FileMetainfo metaInfo) {
|
||||
attachedFiles.add(metaInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(FileMetainfo metainfo) {
|
||||
attachedFiles.remove(metainfo);
|
||||
}
|
||||
|
||||
public Boolean getBillForPassengers() {
|
||||
return billForPassengers;
|
||||
}
|
||||
|
||||
public void setBillForPassengers(Boolean billForPassengers) {
|
||||
this.billForPassengers = billForPassengers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,15 @@ import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.search.annotations.Analyze;
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Index;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
@Entity
|
||||
@Table(name="USER")
|
||||
@Indexed
|
||||
public class User extends Member implements UserDetails, DataModel {
|
||||
|
||||
/**
|
||||
@@ -32,8 +37,10 @@ public class User extends Member implements UserDetails, DataModel {
|
||||
@Column(name="ENABLED")
|
||||
private boolean enabled;
|
||||
@Column(name="FIRST_NAME")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String firstName;
|
||||
@Column(name="LAST_NAME")
|
||||
@Field(index = Index.YES, analyze = Analyze.YES)
|
||||
private String lastName;
|
||||
@Column(name="PERSONAL_NUMBER")
|
||||
private String personalNumber;
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import info.bukova.isspst.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@@ -47,4 +52,22 @@ public class UsersAddress {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add(this.street);
|
||||
list.add(this.houseNumber);
|
||||
final String s1 = StringUtils.joinNotEmpty(list, " ");
|
||||
|
||||
list.clear();
|
||||
list.add(this.zipCode);
|
||||
list.add(this.city);
|
||||
final String s2 = StringUtils.joinNotEmpty(list, " ");
|
||||
|
||||
list.clear();
|
||||
list.add(s1);
|
||||
list.add(s2);
|
||||
final String s = StringUtils.joinNotEmpty(list, ", ");
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package info.bukova.isspst.filters;
|
||||
|
||||
import info.bukova.isspst.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.zul.Listbox;
|
||||
import org.zkoss.zul.Listitem;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class BooleanFilterListbox extends Listbox
|
||||
{
|
||||
class TristateBooleanListItem extends TristateBoolean
|
||||
{
|
||||
public TristateBooleanListItem(String text, int value)
|
||||
{
|
||||
this.setText(text);
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
private String text;
|
||||
|
||||
public String getText()
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text)
|
||||
{
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
|
||||
public BooleanFilterListbox()
|
||||
{
|
||||
super();
|
||||
|
||||
List<TristateBooleanListItem> list = new ArrayList<TristateBooleanListItem>();
|
||||
list.add(new TristateBooleanListItem(StringUtils.localize("LabelAll"), TristateBoolean.NULL));
|
||||
list.add(new TristateBooleanListItem(StringUtils.localize("LabelNo"), TristateBoolean.FALSE));
|
||||
list.add(new TristateBooleanListItem(StringUtils.localize("LabelYes"), TristateBoolean.TRUE));
|
||||
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
{
|
||||
TristateBooleanListItem triStateItem = (TristateBooleanListItem) list.get(i);
|
||||
this.appendItem(triStateItem.getText(), "");
|
||||
|
||||
Listitem item = this.getItemAtIndex(i);
|
||||
item.setValue((TristateBoolean) triStateItem);
|
||||
}
|
||||
|
||||
this.setSelectedIndex(0);
|
||||
// this.setHflex("1");
|
||||
this.setMold("select");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.bukova.isspst.filters;
|
||||
|
||||
import info.bukova.isspst.BooleanUtils;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.data.MUnitEmb;
|
||||
@@ -42,6 +43,7 @@ public class JoinedItemFilter implements Filter<JoinedItem>
|
||||
@Override
|
||||
public boolean matchesSafely(JoinedItem item)
|
||||
{
|
||||
boolean foundItemMaterial = BooleanUtils.isEqualFilterByBoolean(item.isItemMaterialReal(), condition.getItemMaterial());
|
||||
boolean foundCode = StringUtils.isEqualForFilter(item.getCode(), condition.getCode());
|
||||
boolean foundName = StringUtils.isEqualForFilter(item.getName(), condition.getName());
|
||||
boolean foundTextItem = StringUtils.isEqualForFilter(item.getTextItem(), condition.getTextItem());
|
||||
@@ -56,7 +58,18 @@ public class JoinedItemFilter implements Filter<JoinedItem>
|
||||
boolean foundCenter = Workgroup.isEqualByWorkgroupForFilter(item.getCentre(), condition.getCentre());
|
||||
boolean foundOwner = User.isEqualByUserForFilter(item.getOwnedBy(), condition.getOwnedBy());
|
||||
boolean foundDescription = StringUtils.isEqualForFilter(item.getDescription(), condition.getDescription());
|
||||
return (foundCode && foundName && foundTextItem && foundDescription && foundQuantity && foundUnitPrice && foundMUnit && foundTotal && foundWorkgroup && foundCenter && foundOwner && foundDescription);
|
||||
return (foundItemMaterial
|
||||
&& foundCode
|
||||
&& foundName
|
||||
&& foundTextItem
|
||||
&& foundDescription
|
||||
&& foundQuantity
|
||||
&& foundUnitPrice
|
||||
&& foundMUnit
|
||||
&& foundTotal
|
||||
&& foundWorkgroup
|
||||
&& foundCenter
|
||||
&& foundOwner && foundDescription);
|
||||
}
|
||||
|
||||
@Factory
|
||||
|
||||
@@ -47,7 +47,7 @@ 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());
|
||||
boolean foundProject = BooleanUtils.isEqualByBoolean(item.getProject(), condition.getProject());
|
||||
boolean foundProject = BooleanUtils.isEqualByBooleanValue(item.getProject(), condition.getProject());
|
||||
return (foundNumser && foundReqDate && foundCenter && foundDescription && foundDeliveryDate && foundUser && foundProject);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package info.bukova.isspst.filters;
|
||||
|
||||
import org.jfree.util.Log;
|
||||
|
||||
public class TristateBoolean
|
||||
{
|
||||
private static final String TAG = TristateBoolean.class.getSimpleName();
|
||||
|
||||
public static final int NULL = -1;
|
||||
public static final int FALSE = 0;
|
||||
public static final int TRUE = 1;
|
||||
|
||||
public static final int getValidValue(final int value)
|
||||
{
|
||||
if ((value != TristateBoolean.NULL) && (value != TristateBoolean.FALSE) && (value != TristateBoolean.TRUE))
|
||||
{
|
||||
Log.warn(TAG + "\nBad tristate boolean value.");
|
||||
return TristateBoolean.NULL;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public TristateBoolean()
|
||||
{
|
||||
this.setValue(TristateBoolean.NULL);
|
||||
}
|
||||
|
||||
public TristateBoolean(boolean value)
|
||||
{
|
||||
this.setValue(value ? TristateBoolean.TRUE : TristateBoolean.FALSE);
|
||||
}
|
||||
|
||||
public TristateBoolean(int value)
|
||||
{
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
protected int value;
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value)
|
||||
{
|
||||
this.value = TristateBoolean.getValidValue(value);
|
||||
}
|
||||
|
||||
public Boolean getBoolean()
|
||||
{
|
||||
switch (this.value)
|
||||
{
|
||||
case TristateBoolean.FALSE:
|
||||
return new Boolean(false);
|
||||
|
||||
case TristateBoolean.TRUE:
|
||||
return new Boolean(true);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
if (obj instanceof TristateBoolean)
|
||||
{
|
||||
TristateBoolean item = (TristateBoolean) obj;
|
||||
int thisValue = this.getValue();
|
||||
int itemValue = item.getValue();
|
||||
return (thisValue == itemValue);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(int value)
|
||||
{
|
||||
return (this.getValue() == value);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package info.bukova.isspst.reporting;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mysql.jdbc.StringUtils;
|
||||
import info.bukova.isspst.data.Address;
|
||||
import info.bukova.isspst.data.AuthItem;
|
||||
import info.bukova.isspst.data.Order;
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
@@ -10,11 +9,14 @@ import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.UserSettingsData;
|
||||
import info.bukova.isspst.services.requirement.TripRequirementService;
|
||||
import info.bukova.isspst.services.settings.GlobalSettingsService;
|
||||
import info.bukova.isspst.services.tripbill.TripBillApprovalService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.storage.FileStorage;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ParamFiller {
|
||||
|
||||
@Autowired
|
||||
@@ -27,6 +29,8 @@ public class ParamFiller {
|
||||
private TripRequirementService tripReqService;
|
||||
@Autowired
|
||||
private GlobalSettingsService settingService;
|
||||
@Autowired
|
||||
private TripBillApprovalService tripBillApprovalService;
|
||||
|
||||
public void fill() {
|
||||
if (definition.getDataSet() == null || definition.getDataSet().isEmpty()) {
|
||||
@@ -45,6 +49,7 @@ public class ParamFiller {
|
||||
|
||||
if ((definition.getDataSet().get(0) instanceof TripBill)
|
||||
&& definition.getReport().isSingleRecord()) {
|
||||
|
||||
if (userService.getUserSettings().getSignatureFile() != null
|
||||
&& !userService.getUserSettings().getSignatureFile().isEmpty()) {
|
||||
definition.setParam("P_USER_SIGNATURE", storage.serverPath(userService.getUserSettings().getSignatureFile()));
|
||||
@@ -52,18 +57,32 @@ public class ParamFiller {
|
||||
|
||||
TripBill tb = (TripBill)definition.getDataSet().get(0);
|
||||
tripReqService.loadAuthItems(tb.getRequirement());
|
||||
AuthItem lastAuth = tb.getRequirement().getAuthorization().get(tb.getRequirement().getAuthorization().size() - 1);
|
||||
|
||||
definition.setParam("P_APPROVE_DATE", lastAuth.getAuthDate());
|
||||
if (tb.getApproval() != null) {
|
||||
tripBillApprovalService.loadAuthItems(tb.getApproval());
|
||||
}
|
||||
|
||||
User u = lastAuth.getApprover();
|
||||
if (tb.getApproval() != null && tb.getApproval().getAuthorization() != null && !tb.getApproval().getAuthorization().isEmpty()) {
|
||||
|
||||
UserSettingsData approverSettings = userService.getUserSettings(u);
|
||||
AuthItem lastButOneAuth = tb.getApproval().getAuthorization().get(0);
|
||||
definition.setParam("P_PREV_APPROVE_DATE", lastButOneAuth.getAuthDate());
|
||||
|
||||
if (approverSettings != null
|
||||
&& approverSettings.getSignatureFile() != null
|
||||
&& !approverSettings.getSignatureFile().isEmpty()) {
|
||||
definition.setParam("P_APPROVER_SIGNATURE", storage.serverPath(approverSettings.getSignatureFile()));
|
||||
User lastButOneUser = lastButOneAuth.getApprover();
|
||||
UserSettingsData prevApproverSettings = userService.getUserSettings(lastButOneUser);
|
||||
|
||||
if (prevApproverSettings != null && !StringUtils.isNullOrEmpty(prevApproverSettings.getSignatureFile())) {
|
||||
definition.setParam("P_PREV_APPROVER_SIGNATURE", storage.serverPath(prevApproverSettings.getSignatureFile()));
|
||||
}
|
||||
|
||||
AuthItem lastAuth = tb.getApproval().getAuthorization().get(tb.getRequirement().getAuthorization().size() - 1);
|
||||
definition.setParam("P_APPROVE_DATE", lastAuth.getAuthDate());
|
||||
|
||||
User u = lastAuth.getApprover();
|
||||
UserSettingsData approverSettings = userService.getUserSettings(u);
|
||||
|
||||
if (approverSettings != null && !StringUtils.isNullOrEmpty(approverSettings.getSignatureFile())) {
|
||||
definition.setParam("P_APPROVER_SIGNATURE", storage.serverPath(approverSettings.getSignatureFile()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +93,15 @@ public class ParamFiller {
|
||||
definition.setParam("P_STAMP", storage.serverPath(settingService.getSettings().getStampFile()));
|
||||
}
|
||||
}
|
||||
|
||||
definition.setParam("P_LOGO", storage.serverPath(settingService.getSettings().getLogoFile()));
|
||||
|
||||
Address mainAddress = settingService.getSettings().getMainAddress();
|
||||
|
||||
if (mainAddress != null) {
|
||||
String addr = (StringUtils.isNullOrEmpty(mainAddress.getCompany()) ? "" : mainAddress.getCompany());
|
||||
definition.setParam("P_MAIN_ADDRESS", addr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,10 +8,12 @@ public class Report {
|
||||
private String jasperFile;
|
||||
private boolean hasSettings;
|
||||
private boolean singleRecord;
|
||||
private boolean hasCondition;
|
||||
|
||||
public Report() {
|
||||
hasSettings = false;
|
||||
singleRecord = false;
|
||||
hasCondition = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +48,19 @@ public class Report {
|
||||
this.singleRecord = singleRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param jasperFile
|
||||
* @param hasSettings
|
||||
* @param singleRecord
|
||||
* @param hasCondition
|
||||
*/
|
||||
public Report(String name, String jasperFile, boolean hasSettings, boolean singleRecord, boolean hasCondition) {
|
||||
this(name, jasperFile, hasSettings, singleRecord);
|
||||
this.hasCondition = hasCondition;
|
||||
}
|
||||
|
||||
public ReportType getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -86,4 +101,11 @@ public class Report {
|
||||
this.singleRecord = singleRecord;
|
||||
}
|
||||
|
||||
public boolean isHasCondition() {
|
||||
return hasCondition;
|
||||
}
|
||||
|
||||
public void setHasCondition(boolean hasCondition) {
|
||||
this.hasCondition = hasCondition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,16 @@ public abstract class AbstractRequirementEvaluator extends AbstractModuleEvaluat
|
||||
return false;
|
||||
}
|
||||
|
||||
RequirementBase req = (RequirementBase) targetDomainObject;
|
||||
if (targetDomainObject instanceof RequirementBase) {
|
||||
RequirementBase req = (RequirementBase) targetDomainObject;
|
||||
|
||||
if (permission.equals(Constants.PERM_EDIT_NEW)) {
|
||||
return req.getState() == RequirementState.NEW;
|
||||
}
|
||||
if (permission.equals(Constants.PERM_EDIT_NEW)) {
|
||||
return req.getState() == RequirementState.NEW;
|
||||
}
|
||||
|
||||
if (permission.equals(Constants.PERM_DELETE_NEW)) {
|
||||
return req.getState() == RequirementState.NEW;
|
||||
if (permission.equals(Constants.PERM_DELETE_NEW)) {
|
||||
return req.getState() == RequirementState.NEW;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package info.bukova.isspst.services;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import info.bukova.isspst.data.OwnedDataModel;
|
||||
import info.bukova.isspst.data.User;
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -9,8 +9,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import info.bukova.isspst.data.OwnedDataModel;
|
||||
import info.bukova.isspst.data.User;
|
||||
import java.util.Date;
|
||||
|
||||
public class AbstractOwnedService<T extends OwnedDataModel> extends AbstractService<T> {
|
||||
|
||||
@@ -32,6 +31,7 @@ public class AbstractOwnedService<T extends OwnedDataModel> extends AbstractServ
|
||||
entity.setModifiedBy(getLoggedInUser());
|
||||
entity.setModified(new Date());
|
||||
dao.modify(entity);
|
||||
maintainStorrage();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package info.bukova.isspst.services;
|
||||
|
||||
import static ch.lambdaj.Lambda.filter;
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.Module;
|
||||
import info.bukova.isspst.ModuleUtils;
|
||||
import info.bukova.isspst.SessionData;
|
||||
import info.bukova.isspst.dao.BaseDao;
|
||||
import info.bukova.isspst.dao.QueryDao;
|
||||
@@ -11,7 +10,15 @@ import info.bukova.isspst.data.NumberSeries;
|
||||
import info.bukova.isspst.filters.Filter;
|
||||
import info.bukova.isspst.reporting.Report;
|
||||
import info.bukova.isspst.services.numberseries.NumberSeriesService;
|
||||
import info.bukova.isspst.storage.DocumentFileStorage;
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
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 javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validator;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -20,14 +27,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
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 static ch.lambdaj.Lambda.filter;
|
||||
|
||||
public abstract class AbstractService<T extends DataModel> implements Service<T> {
|
||||
|
||||
@@ -37,10 +37,15 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
protected SessionData sessionData;
|
||||
@Autowired
|
||||
protected QueryDao queryDao;
|
||||
private DocumentFileStorage documentFileStorage;
|
||||
|
||||
private NumberSeriesService numberSeriesService;
|
||||
|
||||
|
||||
public void setDocumentFileStorage(DocumentFileStorage storage) {
|
||||
this.documentFileStorage = storage;
|
||||
}
|
||||
|
||||
public NumberSeriesService getNumberSeriesService()
|
||||
{
|
||||
return numberSeriesService;
|
||||
@@ -63,6 +68,12 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
return "";
|
||||
}
|
||||
|
||||
protected void maintainStorrage() {
|
||||
if (documentFileStorage != null) {
|
||||
documentFileStorage.purge();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasPermission(this, 'PERM_ADD')")
|
||||
public final T create() {
|
||||
@@ -77,6 +88,10 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
throw new IsspstException("DAO is null");
|
||||
}
|
||||
|
||||
if (getModule() != null && !getModule().isActive()) {
|
||||
throw new ModuleNotActiveException();
|
||||
}
|
||||
|
||||
validate(entity);
|
||||
entity.setCreated(new Date());
|
||||
dao.add(entity);
|
||||
@@ -90,9 +105,14 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
throw new IsspstException("DAO is null");
|
||||
}
|
||||
|
||||
if (getModule() != null && !getModule().isActive()) {
|
||||
throw new ModuleNotActiveException();
|
||||
}
|
||||
|
||||
validate(entity);
|
||||
entity.setModified(new Date());
|
||||
dao.modify(entity);
|
||||
maintainStorrage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,7 +123,13 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
throw new IsspstException("DAO is null");
|
||||
}
|
||||
|
||||
if (getModule() != null && !getModule().isActive()) {
|
||||
throw new ModuleNotActiveException();
|
||||
}
|
||||
|
||||
dao.delete(entity);
|
||||
|
||||
maintainStorrage(); // poklidit přiložené soubory
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,6 +167,10 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
throw new IsspstException("DAO is null");
|
||||
}
|
||||
|
||||
if (getModule() != null && !getModule().isActive()) {
|
||||
throw new ModuleNotActiveException();
|
||||
}
|
||||
|
||||
return dao.getById(id);
|
||||
}
|
||||
|
||||
@@ -152,6 +182,10 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
throw new IsspstException("DAO is null");
|
||||
}
|
||||
|
||||
if (getModule() != null && !getModule().isActive()) {
|
||||
throw new ModuleNotActiveException();
|
||||
}
|
||||
|
||||
return dao.getAll();
|
||||
}
|
||||
|
||||
@@ -163,6 +197,10 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
throw new IsspstException("DAO is null");
|
||||
}
|
||||
|
||||
if (getModule() != null && !getModule().isActive()) {
|
||||
throw new ModuleNotActiveException();
|
||||
}
|
||||
|
||||
return dao.execQuery(query);
|
||||
}
|
||||
|
||||
@@ -175,6 +213,10 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
throw new IsspstException("DAO is null");
|
||||
}
|
||||
|
||||
if (getModule() != null && !getModule().isActive()) {
|
||||
throw new ModuleNotActiveException();
|
||||
}
|
||||
|
||||
try {
|
||||
Query q = dao.getQuery(query);
|
||||
return (T) q.uniqueResult();
|
||||
@@ -193,13 +235,7 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
|
||||
@Override
|
||||
public Module getModule() {
|
||||
for (Module m : Constants.MODULES) {
|
||||
if (Arrays.asList(this.getClass().getInterfaces()).contains(m.getServiceClass())) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return ModuleUtils.getModule(this.getClass());
|
||||
}
|
||||
|
||||
public List<Report> getReports() {
|
||||
@@ -238,6 +274,10 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
@Override
|
||||
@Transactional
|
||||
public void loadLazyData(String group, T entity) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Method[] methods = this.getClass().getMethods();
|
||||
|
||||
for (Method m : methods) {
|
||||
@@ -260,4 +300,9 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPrintRecord(T entity) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package info.bukova.isspst.services;
|
||||
|
||||
public class ModuleNotActiveException extends IsspstException {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1219763294556500698L;
|
||||
|
||||
public ModuleNotActiveException() {
|
||||
super("Module deactivated");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,5 +22,6 @@ public interface Service<T> {
|
||||
public List<T> filterList(List<T> sourceList, Filter<T> filter);
|
||||
public Module getModule();
|
||||
public List<Report> getReports();
|
||||
public boolean canPrintRecord(T entity);
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ public class DbInfoServiceImpl extends AbstractService<DbInfo> implements DbInfo
|
||||
}
|
||||
}
|
||||
|
||||
// String source = UserCountUtils.encryptUserCount(1000);
|
||||
// long users = UserCountUtils.decryptUserCount(source);
|
||||
|
||||
long dbVersion = this.getDbInfo().getVersion();
|
||||
|
||||
if (Constants.DB_VERSION > dbVersion)
|
||||
@@ -71,29 +74,29 @@ public class DbInfoServiceImpl extends AbstractService<DbInfo> implements DbInfo
|
||||
{
|
||||
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("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"));
|
||||
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)
|
||||
{
|
||||
@@ -107,9 +110,9 @@ public class DbInfoServiceImpl extends AbstractService<DbInfo> implements DbInfo
|
||||
{
|
||||
List<String> tables = new ArrayList<String>();
|
||||
|
||||
tables.add("material");
|
||||
tables.add("order_item");
|
||||
tables.add("requirement_items");
|
||||
tables.add("MATERIAL");
|
||||
tables.add("ORDER_ITEM");
|
||||
tables.add("REQUIREMENT_ITEMS");
|
||||
|
||||
for (String item : tables)
|
||||
{
|
||||
@@ -119,6 +122,26 @@ public class DbInfoServiceImpl extends AbstractService<DbInfo> implements DbInfo
|
||||
}
|
||||
}
|
||||
|
||||
if (dbVersion < 3)
|
||||
{
|
||||
sql = "UPDATE INVOICING SET COMPLETED = false WHERE (COMPLETED Is NULL) ";
|
||||
sq = this.dao.getSession().createSQLQuery(sql);
|
||||
sq.executeUpdate();
|
||||
}
|
||||
|
||||
if (dbVersion < 4)
|
||||
{
|
||||
sql = "UPDATE TRIP_BILL SET RESULT_MESSAGE = 'Zpráva z pracovní cesty' WHERE (RESULT_MESSAGE Is NULL) ";
|
||||
sq = this.dao.getSession().createSQLQuery(sql);
|
||||
sq.executeUpdate();
|
||||
}
|
||||
|
||||
if (dbVersion < 5) {
|
||||
sql = "ALTER TABLE TRIP_BILL MODIFY RESULT_MESSAGE VARCHAR(" + String.valueOf(Constants.LEN_RESULT_MESSAGE) + ")";
|
||||
sq = this.dao.getSession().createSQLQuery(sql);
|
||||
sq.executeUpdate();
|
||||
}
|
||||
|
||||
this.updateDatabaseVersion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public abstract class AbstractExtractor implements Extractor {
|
||||
|
||||
public String extract(byte[] data) {
|
||||
return extract(new ByteArrayInputStream(data));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import org.apache.poi.POIXMLTextExtractor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public abstract class AbstractOfficeExtractor extends AbstractExtractor {
|
||||
|
||||
@Override
|
||||
public String extract(InputStream is) throws ExtractorException {
|
||||
try {
|
||||
POIXMLTextExtractor extractor = createExtractor(is);
|
||||
return extractor.getText();
|
||||
} catch (IOException e) {
|
||||
throw new ExtractorException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract POIXMLTextExtractor createExtractor(InputStream is) throws IOException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import org.apache.poi.POIXMLTextExtractor;
|
||||
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class ExcelExtractor extends AbstractOfficeExtractor implements Extractor {
|
||||
|
||||
@Override
|
||||
protected POIXMLTextExtractor createExtractor(InputStream is) throws IOException {
|
||||
return new XSSFExcelExtractor(new XSSFWorkbook(is));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*
|
||||
* Rozhraní extractoru čistého textu z formátů Office a PDF
|
||||
*/
|
||||
public interface Extractor {
|
||||
|
||||
/**
|
||||
* Extrahuje text z předaného pole bytů
|
||||
*
|
||||
* @param data zdrajová data
|
||||
* @return čistý text
|
||||
* @throws ExtractorException
|
||||
*/
|
||||
public String extract(byte[] data) throws ExtractorException;
|
||||
|
||||
/**
|
||||
* Extrahuje text z předaného InputStream objektu
|
||||
*
|
||||
* @param is zdrojový InputStream
|
||||
* @return čistý text
|
||||
* @throws ExtractorException
|
||||
*/
|
||||
public String extract(InputStream is) throws ExtractorException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import info.bukova.isspst.services.IsspstException;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*
|
||||
* Výjimka extrakce textu
|
||||
*/
|
||||
public class ExtractorException extends IsspstException {
|
||||
|
||||
public ExtractorException(Throwable cause) {
|
||||
super("Extractor exception: ", cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*
|
||||
* Factory pro konkrétní extractor
|
||||
*/
|
||||
public class ExtractorFactory {
|
||||
|
||||
/**
|
||||
* Vytvoří extractor podle předaného content typu
|
||||
*
|
||||
* @param contentType
|
||||
* @return Extractor
|
||||
*/
|
||||
public static Extractor createExtractor(String contentType) {
|
||||
if (contentType.equals("application/vnd.oasis.opendocument.text")
|
||||
|| contentType.equals("application/vnd.oasis.opendocument.spreadsheet")
|
||||
|| contentType.equals("application/vnd.oasis.opendocument.presentation")) {
|
||||
return new OdfExtractor();
|
||||
}
|
||||
|
||||
if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
|
||||
return new WordExtractor();
|
||||
}
|
||||
|
||||
if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
|
||||
return new ExcelExtractor();
|
||||
}
|
||||
|
||||
if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.slideshow")) {
|
||||
return new PowerPointExtractor();
|
||||
}
|
||||
|
||||
if (contentType.equals("application/pdf")) {
|
||||
return new PdfExtractor();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import org.hibernate.search.annotations.Field;
|
||||
import org.hibernate.search.annotations.Indexed;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*
|
||||
* Rozhraní služby fulltextového vyhledávání
|
||||
*
|
||||
*/
|
||||
public interface FullTextService {
|
||||
|
||||
/**
|
||||
* Přegeneruje fulltextový index.
|
||||
*/
|
||||
public void reindex();
|
||||
|
||||
|
||||
/**
|
||||
* Vyhledává entity zadané třídy. Třída entity musí být anotovaná {@link Indexed}
|
||||
*
|
||||
* @param entityClass třída entity k vyhledání
|
||||
* @param fields property entity kde se bude vyhledávat. Musí být anotované {@link Field}
|
||||
* @param word vyhledávaný výraz
|
||||
* @return list odpovídajících entit
|
||||
*/
|
||||
public List<?> search(Class<?> entityClass, String[] fields, String word);
|
||||
|
||||
|
||||
/**
|
||||
* Globální vyhledávání ve všech entitách, jejichš třídy jsou anotované {@link Indexed} a
|
||||
* property {@link Field}
|
||||
*
|
||||
* @param word vyhledávaný výraz
|
||||
* @return list odpovídajících entit
|
||||
*/
|
||||
public List<?> globalSearch(String word);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import info.bukova.isspst.ModuleUtils;
|
||||
import info.bukova.isspst.dao.QueryDao;
|
||||
import info.bukova.isspst.data.BaseData;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.services.ModuleNotActiveException;
|
||||
import info.bukova.isspst.sort.ReflectionTools;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.Sort;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.search.FullTextQuery;
|
||||
import org.hibernate.search.FullTextSession;
|
||||
import org.hibernate.search.Search;
|
||||
import org.hibernate.search.annotations.IndexedEmbedded;
|
||||
import org.hibernate.search.query.dsl.QueryBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FullTextServiceImpl implements FullTextService {
|
||||
|
||||
@Autowired
|
||||
private QueryDao queryDao;
|
||||
private List<Class<?>> classesForSearch;
|
||||
private Map<Class<?>, String[]> fields;
|
||||
private List<Class<?>> nestedClasses;
|
||||
|
||||
public FullTextServiceImpl() {
|
||||
nestedClasses = new ArrayList<Class<?>>();
|
||||
nestedClasses.add(User.class);
|
||||
nestedClasses.add(BaseData.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void reindex() {
|
||||
Logger logger = LoggerFactory.getLogger(FullTextServiceImpl.class);
|
||||
logger.info("Indexing database for fulltext search");
|
||||
FullTextSession ftSession = Search.getFullTextSession(queryDao.getSession());
|
||||
ftSession.createIndexer().start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_SEARCH')")
|
||||
public List<?> search(Class<?> entityClass, String[] fields, String word) {
|
||||
checkActivity();
|
||||
FullTextSession session = Search.getFullTextSession(queryDao.getSession());
|
||||
QueryBuilder qb = session.getSearchFactory().buildQueryBuilder().forEntity(entityClass).get();
|
||||
|
||||
Query luceneQuery = qb.keyword().onFields(fields).matching(word).createQuery();
|
||||
FullTextQuery hiberQuery = session.createFullTextQuery(luceneQuery, entityClass);
|
||||
hiberQuery.setSort(Sort.RELEVANCE);
|
||||
|
||||
return hiberQuery.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_SEARCH')")
|
||||
public List<?> globalSearch(String word) {
|
||||
checkActivity();
|
||||
List<Object> result = new ArrayList<Object>();
|
||||
|
||||
for (Class<?> clazz : classesForSearch()) {
|
||||
result.addAll(search(clazz, fields.get(clazz), word));
|
||||
}
|
||||
|
||||
for (Object o : result) {
|
||||
BaseData data = (BaseData) o;
|
||||
Hibernate.initialize(data.getModifiedBy());
|
||||
Hibernate.initialize(data.getOwnedBy());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void checkActivity() {
|
||||
if (!ModuleUtils.getModule(this.getClass()).isActive()) {
|
||||
throw new ModuleNotActiveException();
|
||||
}
|
||||
}
|
||||
|
||||
private List<Class<?>> classesForSearch() {
|
||||
if (classesForSearch != null) {
|
||||
return classesForSearch;
|
||||
}
|
||||
|
||||
classesForSearch = new ArrayList<Class<?>>();
|
||||
fields = new HashMap<Class<?>, String[]>();
|
||||
FullTextSession session = Search.getFullTextSession(queryDao.getSession());
|
||||
|
||||
for (Class<?> clazz : session.getSearchFactory().getIndexedTypes()) {
|
||||
if (nestedClasses.contains(clazz)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
classesForSearch.add(clazz);
|
||||
fields.put(clazz, fields(clazz, ""));
|
||||
}
|
||||
|
||||
return classesForSearch;
|
||||
}
|
||||
|
||||
private String[] fields(Class<?> clazz, String prefix) {
|
||||
List<String> res = new ArrayList<String>();
|
||||
|
||||
for (Field field : ReflectionTools.getFields(clazz)) {
|
||||
for (Annotation a : field.getDeclaredAnnotations()) {
|
||||
if (a instanceof org.hibernate.search.annotations.Field) {
|
||||
res.add(prefix + field.getName());
|
||||
}
|
||||
|
||||
if (a instanceof IndexedEmbedded) {
|
||||
Class<?> fieldClass;
|
||||
|
||||
fieldClass = field.getType();
|
||||
if (fieldClass.isAssignableFrom(List.class)) {
|
||||
ParameterizedType type = (ParameterizedType) field.getGenericType();
|
||||
Type[] types = type.getActualTypeArguments();
|
||||
if (types.length == 1) {
|
||||
fieldClass = (Class<?>)types[0];
|
||||
}
|
||||
}
|
||||
|
||||
classesForSearch.remove(fieldClass);
|
||||
fields.remove(fieldClass);
|
||||
nestedClasses.add(fieldClass);
|
||||
|
||||
String nestedPrefix = prefix + field.getName() + ".";
|
||||
res.addAll(Arrays.asList(fields(fieldClass, nestedPrefix)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String resArray[] = new String[res.size()];
|
||||
resArray = res.toArray(resArray);
|
||||
return resArray;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import org.odftoolkit.simple.Document;
|
||||
import org.odftoolkit.simple.common.TextExtractor;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class OdfExtractor extends AbstractExtractor implements Extractor {
|
||||
|
||||
@Override
|
||||
public String extract(InputStream is) throws ExtractorException {
|
||||
try {
|
||||
Document odfDocument = Document.loadDocument(is);
|
||||
TextExtractor extractor = TextExtractor.newOdfTextExtractor(odfDocument.getContentRoot());
|
||||
|
||||
return extractor.getText();
|
||||
} catch (Exception e) {
|
||||
throw new ExtractorException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import com.lowagie.text.pdf.PdfReader;
|
||||
import com.lowagie.text.pdf.parser.PdfTextExtractor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class PdfExtractor extends AbstractExtractor implements Extractor {
|
||||
|
||||
@Override
|
||||
public String extract(InputStream is) throws ExtractorException {
|
||||
try {
|
||||
PdfReader reader = new PdfReader(is);
|
||||
PdfTextExtractor extractor = new PdfTextExtractor(reader);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
|
||||
sb.append(extractor.getTextFromPage(i));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new ExtractorException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import org.apache.poi.POIXMLTextExtractor;
|
||||
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
|
||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class PowerPointExtractor extends AbstractOfficeExtractor implements Extractor {
|
||||
|
||||
@Override
|
||||
protected POIXMLTextExtractor createExtractor(InputStream is) throws IOException {
|
||||
return new XSLFPowerPointExtractor(new XMLSlideShow(is));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package info.bukova.isspst.services.fulltext;
|
||||
|
||||
import org.apache.poi.POIXMLTextExtractor;
|
||||
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class WordExtractor extends AbstractOfficeExtractor implements Extractor {
|
||||
|
||||
@Override
|
||||
protected POIXMLTextExtractor createExtractor(InputStream is) throws IOException {
|
||||
return new XWPFWordExtractor(new XWPFDocument(is));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
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;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public interface InvoicingService extends Service<Invoicing> {
|
||||
|
||||
public BigDecimal totalInvoicedForWorkgroup(Workgroup workgroup);
|
||||
@@ -16,4 +17,7 @@ public interface InvoicingService extends Service<Invoicing> {
|
||||
|
||||
public void calculate(Invoicing invoicing);
|
||||
|
||||
public List<Invoicing> getPendingList();
|
||||
|
||||
public List<Invoicing> getArchiveList();
|
||||
}
|
||||
|
||||
@@ -65,4 +65,31 @@ public class InvoicingServiceImpl extends AbstractOwnedService<Invoicing> implem
|
||||
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());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_READ')")
|
||||
public List<Invoicing> getPendingList()
|
||||
{
|
||||
Query q = dao.getQuery("select inv from Invoicing as inv join fetch inv.requirement rq join fetch rq.ownedBy where (inv.completed Is Null or inv.completed = false) order by rq.numser");
|
||||
return q.list();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_READ')")
|
||||
public List<Invoicing> getArchiveList()
|
||||
{
|
||||
Query q = dao.getQuery("select inv from Invoicing as inv join fetch inv.requirement rq join fetch rq.ownedBy where inv.completed = true order by rq.numser");
|
||||
return q.list();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,5 +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);
|
||||
}
|
||||
|
||||
@@ -180,9 +180,7 @@ public class OrderServiceImpl extends AbstractOwnedService<Order> implements
|
||||
return sumTotal;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())")
|
||||
public void updateApprovedItems(Order order, boolean orderedChanged)
|
||||
protected void setApprovedItems(Order order, boolean orderedChanged)
|
||||
{
|
||||
if (orderedChanged)
|
||||
{
|
||||
@@ -197,7 +195,23 @@ public class OrderServiceImpl extends AbstractOwnedService<Order> implements
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package info.bukova.isspst.services.requirement;
|
||||
|
||||
import info.bukova.isspst.services.IsspstException;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class ApproveException extends IsspstException {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3794779381621324848L;
|
||||
|
||||
public ApproveException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ApproveException(String message) {
|
||||
super(message);
|
||||
this.setReason(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import info.bukova.isspst.data.RequirementBase;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -21,6 +22,7 @@ public interface RequirementBaseService<T extends RequirementBase> extends Servi
|
||||
public void loadType(T data);
|
||||
public void loadWorkflow(T data);
|
||||
public void approve(T entity);
|
||||
public void approve(T entity, Date approveDate);
|
||||
public boolean canApprove(T entity);
|
||||
public List<User> getNextApprover(T entity);
|
||||
|
||||
|
||||
+37
-14
@@ -18,11 +18,6 @@ import info.bukova.isspst.services.LazyLoader;
|
||||
import info.bukova.isspst.services.settings.GlobalSettingsService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.LazyInitializationException;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,6 +25,10 @@ import org.springframework.security.access.prepost.PostFilter;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
* @author Franta Přibyl
|
||||
@@ -76,11 +75,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
|
||||
super.add(entity);
|
||||
|
||||
if (canApprove(entity)) {
|
||||
approve(entity);
|
||||
} else {
|
||||
this.sendToApprovers(entity);
|
||||
}
|
||||
this.postAdd(entity);
|
||||
}
|
||||
|
||||
private void checkEnable() {
|
||||
@@ -104,6 +99,14 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
}
|
||||
}
|
||||
|
||||
protected void postAdd(T entity) {
|
||||
if (canApprove(entity)) {
|
||||
approve(entity);
|
||||
} else {
|
||||
this.sendToApprovers(entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addWorkflow(T entity) {
|
||||
if (entity.getType() == null) {
|
||||
return;
|
||||
@@ -211,9 +214,17 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
}
|
||||
}
|
||||
|
||||
protected void approve(T entity, User user) {
|
||||
protected void approve(T entity, User user, Date approveDate) {
|
||||
T e = (T) dao.getById(entity.getId());
|
||||
|
||||
if (e.getReqDate().getTime() > approveDate.getTime()) {
|
||||
throw new ApproveException("ErrApproveBeforeRequirement");
|
||||
}
|
||||
|
||||
if (e.getLastApproveDate() != null && e.getLastApproveDate().getTime() > approveDate.getTime()) {
|
||||
throw new ApproveException("ErrAppreveBeforeLastApprove");
|
||||
}
|
||||
|
||||
Workflow wf = getNextWorkflow(e);
|
||||
if (wf == null) {
|
||||
return;
|
||||
@@ -223,7 +234,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
AuthItem auth = new AuthItem();
|
||||
auth.setApprover(user);
|
||||
auth.setRole(role);
|
||||
auth.setAuthDate(new Date());
|
||||
auth.setAuthDate(approveDate);
|
||||
|
||||
e.getAuthorization().add(auth);
|
||||
|
||||
@@ -235,7 +246,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
|
||||
super.update(e);
|
||||
|
||||
if (!autoApprove(e)) {
|
||||
if (!autoApprove(e, approveDate)) {
|
||||
this.sendToApprovers(e);
|
||||
|
||||
SettingsData settings = settingsService.getSettings();
|
||||
@@ -261,6 +272,10 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
postApprove(e);
|
||||
}
|
||||
|
||||
protected void approve(T entity, User user) {
|
||||
approve(entity, user, new Date());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("this.canApprove(#entity)")
|
||||
@@ -268,13 +283,21 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
approve(entity, getLoggedInUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("this.canApprove(#entity)")
|
||||
public void approve(T entity, Date approveDate) {
|
||||
approve(entity, getLoggedInUser(), approveDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param approveDate
|
||||
* @return true pokud se provedlo automatické schválení.
|
||||
*/
|
||||
protected boolean autoApprove(T entity) {
|
||||
protected boolean autoApprove(T entity, Date approveDate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,16 +10,15 @@ import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.Workflow;
|
||||
import info.bukova.isspst.services.LazyLoader;
|
||||
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;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
* @author Franta Přibyl
|
||||
@@ -48,7 +47,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean autoApprove(Requirement entity)
|
||||
protected boolean autoApprove(Requirement entity, Date approveDate)
|
||||
{
|
||||
List<User> approvers = this.getNextApprover(entity);
|
||||
Workflow nextWf = this.getNextWorkflow(entity);
|
||||
@@ -61,7 +60,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
|
||||
if ((entity.getSumTotal() != null)
|
||||
&& (entity.getSumTotal().compareTo(nextWf.getLimit()) == -1))
|
||||
{
|
||||
approve(entity, approvers.get(0));
|
||||
approve(entity, approvers.get(0), approveDate);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
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);
|
||||
|
||||
public TripBill getTripBill(TripRequirement requirement);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
}
|
||||
|
||||
+103
-13
@@ -4,17 +4,26 @@ import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.data.NumberSeries;
|
||||
import info.bukova.isspst.data.RequirementState;
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
import info.bukova.isspst.data.TripBillApproval;
|
||||
import info.bukova.isspst.data.TripRequirement;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.mail.MailMessage;
|
||||
import info.bukova.isspst.mail.Mailer;
|
||||
import info.bukova.isspst.mail.MessageBuilder;
|
||||
import info.bukova.isspst.services.LazyLoader;
|
||||
import info.bukova.isspst.services.settings.GlobalSettingsService;
|
||||
import info.bukova.isspst.services.tripbill.TripBillApprovalService;
|
||||
import info.bukova.isspst.services.tripbill.TripBillService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import org.hibernate.Hibernate;
|
||||
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 org.hibernate.LazyInitializationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.List;
|
||||
|
||||
public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripRequirement>
|
||||
implements TripRequirementService, RequirementBaseService<TripRequirement> {
|
||||
@@ -22,9 +31,17 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
||||
@Autowired
|
||||
private RequirementTypeService reqTypeService;
|
||||
@Autowired
|
||||
private WorkgroupService workgroupService;
|
||||
@Autowired
|
||||
private TripBillService tripBillService;
|
||||
@Autowired
|
||||
private TripBillApprovalService tripBillApprovalService;
|
||||
@Autowired
|
||||
private Mailer mailer;
|
||||
@Autowired
|
||||
private MessageBuilder messageBuilder;
|
||||
@Autowired
|
||||
private GlobalSettingsService settingsService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
protected TripRequirement createEntity() {
|
||||
@@ -36,6 +53,45 @@ 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());
|
||||
TripBillApproval approval = bill.getApproval();
|
||||
|
||||
if (approval != null) {
|
||||
tripBillApprovalService.delete(approval);
|
||||
}
|
||||
|
||||
bill.setApproval(null);
|
||||
tripBillService.calculate(bill);
|
||||
tripBillService.update(bill);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postAdd(TripRequirement entity) {
|
||||
super.postAdd(entity);
|
||||
sendMailToPassengers(entity, settingsService.getSettings().getReqPassenger());
|
||||
}
|
||||
|
||||
private void sendMailToPassengers(TripRequirement entity, MailMessage messageTemplate) {
|
||||
if (entity.getBillForPassengers() != null && !entity.getPassengers().isEmpty() && messageTemplate != null) {
|
||||
MailMessage message = messageBuilder.buildMessage(messageTemplate, entity);
|
||||
message.setFrom(userService.getCurrent().getEmail());
|
||||
message.setTo(userService.getEmailsForSend(entity.getPassengers()));
|
||||
mailer.send(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@LazyLoader("form")
|
||||
@@ -53,6 +109,36 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public TripBill getTripBill(TripRequirement requirement) {
|
||||
Query q = dao.getQuery("from TripBill tb where tb.requirement = :req");
|
||||
q.setParameter("req", requirement);
|
||||
List<TripBill> result = q.list();
|
||||
|
||||
if (result.size() > 0) {
|
||||
return result.get(0);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<TripBill> getBills(TripRequirement entity) {
|
||||
Query q = queryDao.getQuery("from TripBill bill where bill.requirement = :req");
|
||||
q.setParameter("req", entity);
|
||||
return q.list();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@LazyLoader("form")
|
||||
public void loadAttachments(TripRequirement entity) {
|
||||
TripRequirement e = dao.getById(entity.getId());
|
||||
Hibernate.initialize(e.getAttachedFiles());
|
||||
entity.setAttachedFiles(e.getAttachedFiles());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postApprove(TripRequirement entity) {
|
||||
if (entity.getState() == RequirementState.APPROVED) {
|
||||
@@ -61,13 +147,17 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
||||
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);
|
||||
if (entity.getBillForPassengers() != null && entity.getBillForPassengers()) {
|
||||
for (User u : entity.getPassengers()) {
|
||||
if (!u.equals(entity.getOwnedBy())) {
|
||||
TripBill passBill = tripBillService.createPassengersBill(entity);
|
||||
tripBillService.add(passBill);
|
||||
passBill.setOwnedBy(u);
|
||||
tripBillService.update(passBill);
|
||||
}
|
||||
}
|
||||
|
||||
sendMailToPassengers(entity, settingsService.getSettings().getConfReqTripPassenger());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package info.bukova.isspst.services.tripbill;
|
||||
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
import info.bukova.isspst.data.TripBillApproval;
|
||||
import info.bukova.isspst.services.requirement.RequirementBaseService;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public interface TripBillApprovalService extends RequirementBaseService<TripBillApproval> {
|
||||
|
||||
public TripBillApproval createApproval(TripBill bill);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package info.bukova.isspst.services.tripbill;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.RequirementState;
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
import info.bukova.isspst.data.TripBillApproval;
|
||||
import info.bukova.isspst.services.IsspstException;
|
||||
import info.bukova.isspst.services.requirement.RequirementBaseServiceImpl;
|
||||
import info.bukova.isspst.services.requirement.RequirementTypeService;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class TripBillApprovalServiceImpl extends RequirementBaseServiceImpl<TripBillApproval> implements TripBillApprovalService {
|
||||
|
||||
@Autowired
|
||||
private RequirementTypeService reqTypeService;
|
||||
|
||||
@Override
|
||||
public TripBillApproval createApproval(TripBill bill) {
|
||||
if (bill.getApproval() != null) {
|
||||
throw new IsspstException("Approval already exists");
|
||||
}
|
||||
|
||||
TripBillApproval approval = new TripBillApproval();
|
||||
approval.setCentre(bill.getRequirement().getCentre());
|
||||
approval.setWorkgroup(bill.getRequirement().getWorkgroup());
|
||||
approval.setReqDate(new Date());
|
||||
approval.setType(reqTypeService.getTypeById(Constants.REQTYPE_BUSINESSTRIP));
|
||||
approval.setState(RequirementState.NEW);
|
||||
// approval.setNumser(bill.getRequirement().getNumser());
|
||||
approval.setDescription(StringUtils.localize("TravelOrdersFormTitle") + " \"" + bill.getOwnedBy() + "\" - " + bill.getRequirement().getDescription());
|
||||
approval.setBill(bill);
|
||||
bill.setApproval(approval);
|
||||
return approval;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_ADD')")
|
||||
public void add(TripBillApproval entity) {
|
||||
entity.setCreated(new Date());
|
||||
entity.setOwnedBy(getLoggedInUser());
|
||||
addWorkflow(entity);
|
||||
dao.add(entity);
|
||||
|
||||
postAdd(entity);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,26 @@
|
||||
package info.bukova.isspst.services.tripbill;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
import info.bukova.isspst.data.TripRequirement;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TripBillService extends Service<TripBill> {
|
||||
|
||||
public TripBill createTripBill(TripRequirement requirement);
|
||||
public TripBill createPassengersBill(TripRequirement requirement);
|
||||
public void loadItems(TripBill bill);
|
||||
public void calculate(TripBill bill);
|
||||
public List<TripBill> getMy();
|
||||
public void loadOwner(TripBill bill);
|
||||
public void loadPassengers(TripBill bill);
|
||||
|
||||
/**
|
||||
* Uloží vyúčtování a nastaví příznak přenosu vyúčtování od žadatele
|
||||
*
|
||||
* @param bill
|
||||
*/
|
||||
public void updateOwned(TripBill bill);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.bukova.isspst.services.tripbill;
|
||||
|
||||
import info.bukova.isspst.data.RequirementState;
|
||||
import info.bukova.isspst.data.SettingsData;
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
import info.bukova.isspst.data.TripBillItem;
|
||||
@@ -7,13 +8,7 @@ import info.bukova.isspst.data.TripRequirement;
|
||||
import info.bukova.isspst.services.AbstractOwnedService;
|
||||
import info.bukova.isspst.services.LazyLoader;
|
||||
import info.bukova.isspst.services.settings.GlobalSettingsService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.LazyInitializationException;
|
||||
import org.hibernate.Query;
|
||||
import org.joda.time.DateTime;
|
||||
@@ -24,6 +19,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TripBillServiceImpl extends AbstractOwnedService<TripBill> implements
|
||||
TripBillService {
|
||||
|
||||
@@ -32,10 +33,23 @@ public class TripBillServiceImpl extends AbstractOwnedService<TripBill> implemen
|
||||
|
||||
@Override
|
||||
public TripBill createTripBill(TripRequirement requirement) {
|
||||
return createBill(requirement, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TripBill createPassengersBill(TripRequirement requirement) {
|
||||
return createBill(requirement, true);
|
||||
}
|
||||
|
||||
private TripBill createBill(TripRequirement requirement, boolean passengers) {
|
||||
TripBill bill = new TripBill();
|
||||
|
||||
bill.setRequirement(requirement);
|
||||
|
||||
if (!passengers) {
|
||||
bill.setDownPayment(requirement.getDownPayment());
|
||||
}
|
||||
|
||||
int daysCount = Days.daysBetween((new DateTime(requirement.getTripDate())).withTimeAtStartOfDay(),
|
||||
(new DateTime(requirement.getEndDate())).withTimeAtStartOfDay()).getDays() + 1;
|
||||
|
||||
@@ -80,6 +94,14 @@ public class TripBillServiceImpl extends AbstractOwnedService<TripBill> implemen
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@LazyLoader("form")
|
||||
public void loadAttachments(TripBill entity) {
|
||||
TripBill e = dao.getById(entity.getId());
|
||||
Hibernate.initialize(e.getAttachedFiles());
|
||||
entity.setAttachedFiles(e.getAttachedFiles());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate(TripBill bill) {
|
||||
bill.setTotal(BigDecimal.ZERO);
|
||||
@@ -93,8 +115,8 @@ public class TripBillServiceImpl extends AbstractOwnedService<TripBill> implemen
|
||||
bill.setTotal(bill.getTotal().add(item.getTotal()));
|
||||
}
|
||||
|
||||
if (bill.getRequirement().getDownPayment() != null) {
|
||||
bill.setTotal(bill.getTotal().subtract(bill.getRequirement().getDownPayment()));
|
||||
if (bill.getDownPayment() != null) {
|
||||
bill.setTotal(bill.getTotal().subtract(bill.getDownPayment()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,11 +192,13 @@ public class TripBillServiceImpl extends AbstractOwnedService<TripBill> implemen
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@LazyLoader("print")
|
||||
@LazyLoader({"print", "form"})
|
||||
public void loadOwner(TripBill bill) {
|
||||
TripBill tb = dao.getById(bill.getId());
|
||||
tb.getOwnedBy().getFirstName();
|
||||
tb.getRequirement().getOwnedBy().getFirstName();
|
||||
bill.setOwnedBy(tb.getOwnedBy());
|
||||
bill.getRequirement().setOwnedBy(tb.getRequirement().getOwnedBy());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,4 +212,50 @@ public class TripBillServiceImpl extends AbstractOwnedService<TripBill> implemen
|
||||
bill.getRequirement().setPassengers(tr.getPassengers());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())")
|
||||
public void updateOwned(TripBill bill) {
|
||||
bill.setSaved(true);
|
||||
update(bill);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())")
|
||||
public void update(TripBill entity) {
|
||||
super.update(entity);
|
||||
|
||||
TripRequirement req = entity.getRequirement();
|
||||
|
||||
if (req.getOwnedBy().equals(entity.getOwnedBy())) {
|
||||
Query q = dao.getQuery("from TripBill where requirement = :req and id != :id and (saved = false or saved is null)");
|
||||
q.setParameter("req", req);
|
||||
q.setParameter("id", entity.getId());
|
||||
|
||||
List<TripBill> bills = q.list();
|
||||
for (TripBill tb : bills) {
|
||||
tb.getBillItems().clear();
|
||||
|
||||
for (TripBillItem item : entity.getBillItems()) {
|
||||
tb.getBillItems().add(new TripBillItem(item));
|
||||
}
|
||||
|
||||
tb.setFreeCarfare(entity.isFreeCarfare());
|
||||
tb.setFreeHousing(entity.isFreeHousing());
|
||||
tb.setFreeMeals(entity.isFreeMeals());
|
||||
calculate(tb);
|
||||
super.update(tb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPrintRecord(TripBill entity) {
|
||||
if (entity.getApproval() != null && entity.getApproval().getState() == RequirementState.APPROVED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ReflectionTools {
|
||||
@@ -78,4 +80,23 @@ public class ReflectionTools {
|
||||
|
||||
return getEntityFields(entity.getClass());
|
||||
}
|
||||
|
||||
public static List<Field> getFields(Object entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getFields(entity.getClass());
|
||||
}
|
||||
|
||||
public static List<Field> getFields(Class<?> clazz) {
|
||||
List<Field> ret = new ArrayList<Field>();
|
||||
|
||||
ret.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
||||
if (!clazz.getSuperclass().equals(Object.class)) {
|
||||
ret.addAll(getFields(clazz.getSuperclass()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package info.bukova.isspst.storage;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Abstraktni třída pro práci se soubory.
|
||||
*
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public abstract class AbstractFileStorage<T> implements FileStorage<T> {
|
||||
|
||||
protected void saveFileDataToPath(byte[] data, String path) {
|
||||
|
||||
File file = new File(path);
|
||||
FileOutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(file);
|
||||
os.write(data);
|
||||
os.flush();
|
||||
os.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (os != null) {
|
||||
os.flush();
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new StorageException("Cannot close stream", e.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveFileToPtah(File file, String path) {
|
||||
File dest = new File(path + File.pathSeparator + file.getName());
|
||||
FileOutputStream fos = null;
|
||||
|
||||
try {
|
||||
fos = new FileOutputStream(dest);
|
||||
fos.write(readFile(file));
|
||||
fos.flush();
|
||||
fos.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new StorageException("Cannot move file: " + file.getName(), e.getCause());
|
||||
} catch (IOException e) {
|
||||
throw new StorageException("Cannot move file: " + file.getName(), e.getCause());
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.flush();
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
throw new StorageException("Cannot close stream", e.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeFileByPath(String path) {
|
||||
File f = new File(path);
|
||||
if (!f.delete()) {
|
||||
throw new StorageException("Cannot delete file: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
protected byte[] fileDataFromPath(String path) {
|
||||
File f = new File(path);
|
||||
return readFile(f);
|
||||
}
|
||||
|
||||
protected byte[] readFile(File file) {
|
||||
byte[] out = new byte[(int) file.length()];
|
||||
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
fis.read(out);
|
||||
fis.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new StorageException("File cannot be found: " + file.getName(), e.getCause());
|
||||
} catch (IOException e) {
|
||||
throw new StorageException("Cannot read file: " + file.getName(), e.getCause());
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
throw new StorageException("Cannot close stream", e.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
protected File fileFromPath(String path) {
|
||||
return new File(path);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package info.bukova.isspst.storage;
|
||||
|
||||
import info.bukova.isspst.data.FileMetainfo;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Rozhraní servisního objektu pro práci s přílohami u záznamů. Přílohy jsou reprezentovány objektem FileMetainfo,
|
||||
* kde je zobrazované jméno souboru, vygenerovaný GUID, pod kterým je soubor fyzicky uložen a MD5 součet používaný
|
||||
* pro deduplikaci.
|
||||
*
|
||||
* @see info.bukova.isspst.data.FileMetainfo
|
||||
*
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public interface DocumentFileStorage extends FileStorage<FileMetainfo> {
|
||||
|
||||
/**
|
||||
* Uloží data předaná jako byte[] do uložiště příloh a vrátí metainformace.
|
||||
* Metoda řeší deduplikaci souborů, takže v uložišti je fyzicky vždy jen jedna kopie.
|
||||
*
|
||||
* @see info.bukova.isspst.data.FileMetainfo
|
||||
*
|
||||
* @param data Data souboru
|
||||
* @param name Zobrazovaný název souboru
|
||||
* @return Metainformace o souboru
|
||||
*/
|
||||
public FileMetainfo saveAndCreateInfo(byte[] data, String name);
|
||||
|
||||
/**
|
||||
* Uloží data předaná jako File do uložiště příloh a vrátí metainformace.
|
||||
* Metoda řeší deduplikaci souborů, takže v uložišti je fyzicky vždy jen jedna kopie.
|
||||
*
|
||||
* @see info.bukova.isspst.data.FileMetainfo
|
||||
*
|
||||
* @param file Objekt reprezentující soubor
|
||||
* @param name Zobrazovaný název souboru
|
||||
* @return Metainformace o souboru
|
||||
*/
|
||||
public FileMetainfo saveAndCreateInfo(File file, String name);
|
||||
|
||||
/**
|
||||
* Vrátí metainformace podle fyzické cesty v uložišti.
|
||||
*
|
||||
* @param path Cesta k souboru v uložišti
|
||||
* @return Metainformace o souboru
|
||||
*/
|
||||
public FileMetainfo getMetainfoForPath(String path);
|
||||
|
||||
/**
|
||||
* Bezpečně odstraní přílohu ze záznamu. Záznam o příloze odstraní z kolekce příloh a následně zavolá metodu
|
||||
* removeFile(FileMetainfo info), která soubor fyzicky smaže, pokud už není nikam linkovaný.
|
||||
*
|
||||
* @param entity Entita s přílohami
|
||||
* @param metaInfo Příloha k odstranění
|
||||
*/
|
||||
public void removeAttachment(EntityWithAttachment entity, FileMetainfo metaInfo);
|
||||
|
||||
/**
|
||||
* Bezpečně odstraní všechny přílohy ze záznamu.
|
||||
*
|
||||
* @param entity Entita s přílohami
|
||||
*/
|
||||
public void removeAllAttachments(EntityWithAttachment entity);
|
||||
|
||||
/**
|
||||
* Uklidí soubory, na které neexistuje reference v databázi a z tabulky FILE_CONTENTS vymaže záznamy, na které
|
||||
* neexistuje refernece z FILE_METAINFO
|
||||
*/
|
||||
public void purge();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
package info.bukova.isspst.storage;
|
||||
|
||||
import info.bukova.isspst.dao.QueryDao;
|
||||
import info.bukova.isspst.data.FileContent;
|
||||
import info.bukova.isspst.data.FileMetainfo;
|
||||
import info.bukova.isspst.services.fulltext.Extractor;
|
||||
import info.bukova.isspst.services.fulltext.ExtractorFactory;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SQLQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*
|
||||
* Třída pro práci s uložištěm příloh u záznamů. Na soubory příloh se odkazuje pomocí objektů FileMetainfo.
|
||||
*
|
||||
* @see info.bukova.isspst.data.FileMetainfo
|
||||
*/
|
||||
public class DocumentFileStorageImpl extends AbstractFileStorage<FileMetainfo> implements DocumentFileStorage {
|
||||
|
||||
private String rootPath;
|
||||
@Autowired
|
||||
private QueryDao queryDao;
|
||||
|
||||
/**
|
||||
* Nastavuje kořenová adresář pro ukládání příloh. Nastavuje se absolutní cesta na filesystému serveru.
|
||||
*
|
||||
* @param rootPath kořenový adresář pro přílohy
|
||||
*/
|
||||
public void setRootPath(String rootPath) {
|
||||
this.rootPath = rootPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFile(byte[] data, FileMetainfo fileID) {
|
||||
String fileName = generateFileName(fileID.getFileName());
|
||||
|
||||
saveFileDataToPath(data, rootPath + File.separator + fileName);
|
||||
fileID.setPathInFilesystem(fileName);
|
||||
fileID.setContentType(MimeTypes.getContentType(data, fileName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFile(File file, FileMetainfo fileID) {
|
||||
String fileName = generateFileName(fileID.getFileName());
|
||||
|
||||
saveFileToPtah(file, rootPath + File.separator + fileName);
|
||||
fileID.setPathInFilesystem(fileName);
|
||||
fileID.setContentType(MimeTypes.getContentType(readFile(file), fileName));
|
||||
}
|
||||
|
||||
private String generateFileName(String originalName) {
|
||||
String extension = null;
|
||||
String fileName = UUID.randomUUID().toString();
|
||||
|
||||
if (originalName != null && !originalName.isEmpty()) {
|
||||
extension = MimeTypes.fileExtension(originalName);
|
||||
}
|
||||
|
||||
if (extension != null) {
|
||||
fileName = fileName + "." + extension;
|
||||
}
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
private void extractContent(InputStream is, FileMetainfo fileID) {
|
||||
Extractor extractor = ExtractorFactory.createExtractor(fileID.getContentType());
|
||||
|
||||
if (extractor != null) {
|
||||
fileID.getContent().setPlainText(extractor.extract(is));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeFile(FileMetainfo fileID) {
|
||||
if (fileID.getPathInFilesystem() == null || fileID.getPathInFilesystem().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (infosForPath(fileID.getPathInFilesystem()).size() <= 1) {
|
||||
removeFileByPath(rootPath + File.separator + fileID.getPathInFilesystem());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveFile(String source, String destination) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDirectory(String dir) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] fileData(FileMetainfo fileID) {
|
||||
if (fileID.getPathInFilesystem() != null && !fileID.getPathInFilesystem().isEmpty()) {
|
||||
return fileDataFromPath(rootPath + File.separator + fileID.getPathInFilesystem());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File file(FileMetainfo fileID) {
|
||||
if (fileID.getPathInFilesystem() != null && !fileID.getPathInFilesystem().isEmpty()) {
|
||||
return fileFromPath(rootPath + File.separator + fileID.getPathInFilesystem());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dirExists(String path) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serverPath(FileMetainfo fileID) {
|
||||
return "/api/dl/" + fileID.getPathInFilesystem() + "/" + fileID.getFileName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public FileMetainfo saveAndCreateInfo(byte[] data, String name) {
|
||||
FileMetainfo metaInfo = new FileMetainfo();
|
||||
metaInfo.setFileName(name);
|
||||
|
||||
if (!checkForDuplicate(new ByteArrayInputStream(data), metaInfo)) {
|
||||
saveFile(data, metaInfo);
|
||||
extractContent(new ByteArrayInputStream(data), metaInfo);
|
||||
}
|
||||
|
||||
return metaInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public FileMetainfo saveAndCreateInfo(File file, String name) {
|
||||
FileMetainfo metaInfo = new FileMetainfo();
|
||||
metaInfo.setFileName(name);
|
||||
|
||||
try {
|
||||
if (!checkForDuplicate(new FileInputStream(file), metaInfo)) {
|
||||
saveFile(file, metaInfo);
|
||||
extractContent(new FileInputStream(file), metaInfo);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
//TODO: ošetřit
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return metaInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public FileMetainfo getMetainfoForPath(String path) {
|
||||
if (infosForPath(path).isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return infosForPath(path).get(0);
|
||||
}
|
||||
|
||||
private List<FileMetainfo> infosForPath(String path) {
|
||||
Query q = queryDao.getQuery("from FileMetainfo info where info.content.pathInFilesystem = :path");
|
||||
q.setString("path", path);
|
||||
|
||||
return q.list();
|
||||
}
|
||||
|
||||
private boolean checkForDuplicate(InputStream is, FileMetainfo info) {
|
||||
String md5 = null;
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] dataBytes = new byte[1024];
|
||||
int nread = 0;
|
||||
|
||||
while ((nread = is.read(dataBytes)) != -1) {
|
||||
md.update(dataBytes, 0, nread);
|
||||
}
|
||||
|
||||
md5 = new String(Hex.encodeHex(md.digest()));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
//TODO: ošetřit
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Query q = queryDao.getQuery("select info from FileMetainfo info where info.md5 = :md5");
|
||||
q.setString("md5", md5);
|
||||
List<FileMetainfo> found = (List<FileMetainfo>) q.list();
|
||||
|
||||
if (!found.isEmpty()) {
|
||||
FileMetainfo foundInfo = found.get(0);
|
||||
info.setMd5(foundInfo.getMd5());
|
||||
info.setContent(foundInfo.getContent());
|
||||
|
||||
return true;
|
||||
} else {
|
||||
info.setMd5(md5);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeAttachment(EntityWithAttachment entity, FileMetainfo metaInfo) {
|
||||
entity.removeAttachment(metaInfo);
|
||||
removeFile(metaInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeAllAttachments(EntityWithAttachment entity) {
|
||||
for (FileMetainfo metaInfo : entity.getAttachedFiles()) {
|
||||
removeFile(metaInfo);
|
||||
}
|
||||
|
||||
entity.getAttachedFiles().clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void purge() {
|
||||
File folder = new File(rootPath);
|
||||
File[] allFiles = folder.listFiles();
|
||||
Query q = queryDao.getQuery("from FileMetainfo");
|
||||
List<FileMetainfo> infos = q.list();
|
||||
|
||||
for (File f : allFiles) {
|
||||
boolean fileExists = false;
|
||||
|
||||
for (FileMetainfo info : infos) {
|
||||
FileContent fileContent = info.getContent();
|
||||
|
||||
if ((fileContent != null) && f.isFile() && fileContent.getPathInFilesystem().equals(f.getName()))
|
||||
{
|
||||
fileExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fileExists && f.isFile())
|
||||
{
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
|
||||
SQLQuery sql = queryDao.getSession().createSQLQuery("delete from FILE_CONTENTS where ID not in(select CONTENT_ID from FILE_METAINFO)");
|
||||
sql.executeUpdate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package info.bukova.isspst.storage;
|
||||
|
||||
import info.bukova.isspst.data.FileMetainfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Rozhraní datových entit s přílohami.
|
||||
*
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public interface EntityWithAttachment {
|
||||
|
||||
public List<FileMetainfo> getAttachedFiles();
|
||||
public void addAttachment(FileMetainfo metaInfo);
|
||||
public void removeAttachment(FileMetainfo metainfo);
|
||||
|
||||
}
|
||||
@@ -2,17 +2,22 @@ package info.bukova.isspst.storage;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface FileStorage {
|
||||
/**
|
||||
* Rozhraní pro uložiště souborů
|
||||
*
|
||||
* @param <T> typ objektu, kterým se odkazuje na soubory
|
||||
*/
|
||||
public interface FileStorage<T> {
|
||||
|
||||
// public String getRootPath();
|
||||
public void saveFile(byte[] data, String fileName);
|
||||
public void saveFile(File file, String path);
|
||||
public void removeFile(String fileName);
|
||||
public void saveFile(byte[] data, T fileID);
|
||||
public void saveFile(File file, T fileId);
|
||||
public void removeFile(T fileID);
|
||||
public void moveFile(String source, String destination);
|
||||
public void createDirectory(String dir);
|
||||
public byte[] fileData(String fileName);
|
||||
public File file(String fileName);
|
||||
public byte[] fileData(T fileID);
|
||||
public File file(T fileID);
|
||||
public boolean dirExists(String path);
|
||||
public String serverPath(String fileName);
|
||||
public String serverPath(T fileID);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
package info.bukova.isspst.storage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.*;
|
||||
|
||||
public class LocalFileStorage implements FileStorage {
|
||||
public class LocalFileStorage extends AbstractFileStorage<String> {
|
||||
|
||||
private String rootPath;
|
||||
private ServletContext context;
|
||||
@@ -26,96 +21,27 @@ public class LocalFileStorage implements FileStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFile(byte[] data, String fileName) {
|
||||
public void saveFile(byte[] data, String fileID) {
|
||||
saveFileDataToPath(data, getFullPath() + fileID);
|
||||
}
|
||||
|
||||
File file = new File(getFullPath() + fileName);
|
||||
FileOutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(file);
|
||||
os.write(data);
|
||||
os.flush();
|
||||
os.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (os != null) {
|
||||
os.flush();
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new StorageException("Cannot close stream", e.getCause());
|
||||
}
|
||||
}
|
||||
public void saveFile(File file, String fileID) {
|
||||
saveFileToPtah(file, getFullPath() + fileID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFile(File file, String path) {
|
||||
File dest = new File(getFullPath() + path + File.pathSeparator + file.getName());
|
||||
FileOutputStream fos = null;
|
||||
|
||||
try {
|
||||
fos = new FileOutputStream(dest);
|
||||
fos.write(fileData(file.getName()));
|
||||
fos.flush();
|
||||
fos.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new StorageException("Cannot move file: " + file.getName(), e.getCause());
|
||||
} catch (IOException e) {
|
||||
throw new StorageException("Cannot move file: " + file.getName(), e.getCause());
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.flush();
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
throw new StorageException("Cannot close stream", e.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
public void removeFile(String fileID) {
|
||||
removeFileByPath(getFullPath() + fileID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFile(String fileName) {
|
||||
File f = new File(getFullPath() + fileName);
|
||||
if (!f.delete()) {
|
||||
throw new StorageException("Cannot delete file: " + getFullPath()
|
||||
+ fileName);
|
||||
}
|
||||
public byte[] fileData(String fileID) {
|
||||
return fileDataFromPath(getFullPath() + fileID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] fileData(String fileName) {
|
||||
File f = new File(getFullPath() + fileName);
|
||||
byte[] out = new byte[(int) f.length()];
|
||||
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(f);
|
||||
fis.read(out);
|
||||
fis.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new StorageException("File cannot be found: " + fileName, e.getCause());
|
||||
} catch (IOException e) {
|
||||
throw new StorageException("Cannot read file: " + fileName, e.getCause());
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
throw new StorageException("Cannot close stream", e.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File file(String fileName) {
|
||||
return new File(getFullPath() + fileName);
|
||||
public File file(String fileID) {
|
||||
return fileFromPath(getFullPath() + fileID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,8 +65,8 @@ public class LocalFileStorage implements FileStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serverPath(String fileName) {
|
||||
return context.getRealPath(rootPath + File.separator + fileName);
|
||||
public String serverPath(String fileID) {
|
||||
return context.getRealPath(rootPath + File.separator + fileID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
package info.bukova.isspst.storage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Created by pepa on 30.1.15.
|
||||
*/
|
||||
public class MimeTypes {
|
||||
|
||||
public static String getContentType(byte[] data)
|
||||
{
|
||||
return getContentType(data, null);
|
||||
}
|
||||
|
||||
public static String getContentType(byte[] data, String name)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
byte[] header = new byte[11];
|
||||
System.arraycopy(data, 0, header, 0, Math.min(data.length, header.length));
|
||||
int c1 = header[0] & 0xff;
|
||||
int c2 = header[1] & 0xff;
|
||||
int c3 = header[2] & 0xff;
|
||||
int c4 = header[3] & 0xff;
|
||||
int c5 = header[4] & 0xff;
|
||||
int c6 = header[5] & 0xff;
|
||||
int c7 = header[6] & 0xff;
|
||||
int c8 = header[7] & 0xff;
|
||||
int c9 = header[8] & 0xff;
|
||||
int c10 = header[9] & 0xff;
|
||||
int c11 = header[10] & 0xff;
|
||||
|
||||
if (c1 == 0xCA && c2 == 0xFE && c3 == 0xBA && c4 == 0xBE)
|
||||
{
|
||||
return "application/java-vm";
|
||||
}
|
||||
|
||||
if (c1 == 0xD0 && c2 == 0xCF && c3 == 0x11 && c4 == 0xE0 && c5 == 0xA1 && c6 == 0xB1 && c7 == 0x1A && c8 == 0xE1)
|
||||
{
|
||||
// if the name is set then check if it can be validated by name, because it could be a xls or powerpoint
|
||||
String contentType = guessContentTypeFromName(name);
|
||||
if (contentType != null)
|
||||
{
|
||||
return contentType;
|
||||
}
|
||||
return "application/msword";
|
||||
}
|
||||
if (c1 == 0x25 && c2 == 0x50 && c3 == 0x44 && c4 == 0x46 && c5 == 0x2d && c6 == 0x31 && c7 == 0x2e)
|
||||
{
|
||||
return "application/pdf";
|
||||
}
|
||||
|
||||
if (c1 == 0x38 && c2 == 0x42 && c3 == 0x50 && c4 == 0x53 && c5 == 0x00 && c6 == 0x01)
|
||||
{
|
||||
return "image/photoshop";
|
||||
}
|
||||
|
||||
if (c1 == 0x25 && c2 == 0x21 && c3 == 0x50 && c4 == 0x53)
|
||||
{
|
||||
return "application/postscript";
|
||||
}
|
||||
|
||||
if (c1 == 0xff && c2 == 0xfb && c3 == 0x30)
|
||||
{
|
||||
return "audio/mp3";
|
||||
}
|
||||
|
||||
if (c1 == 0x49 && c2 == 0x44 && c3 == 0x33)
|
||||
{
|
||||
return "audio/mp3";
|
||||
}
|
||||
|
||||
if (c1 == 0xAC && c2 == 0xED)
|
||||
{
|
||||
// next two bytes are version number, currently 0x00 0x05
|
||||
return "application/x-java-serialized-object";
|
||||
}
|
||||
|
||||
if (c1 == '<')
|
||||
{
|
||||
if (c2 == '!' ||
|
||||
((c2 == 'h' && (c3 == 't' && c4 == 'm' && c5 == 'l' || c3 == 'e' && c4 == 'a' && c5 == 'd') || (c2 == 'b' && c3 == 'o' && c4 == 'd' && c5 == 'y'))) ||
|
||||
((c2 == 'H' && (c3 == 'T' && c4 == 'M' && c5 == 'L' || c3 == 'E' && c4 == 'A' && c5 == 'D') || (c2 == 'B' && c3 == 'O' && c4 == 'D' && c5 == 'Y'))))
|
||||
{
|
||||
return "text/html";
|
||||
}
|
||||
|
||||
if (c2 == '?' && c3 == 'x' && c4 == 'm' && c5 == 'l' && c6 == ' ')
|
||||
{
|
||||
return "application/xml";
|
||||
}
|
||||
}
|
||||
|
||||
// big and little endian UTF-16 encodings, with byte order mark
|
||||
if (c1 == 0xfe && c2 == 0xff)
|
||||
{
|
||||
if (c3 == 0 && c4 == '<' && c5 == 0 && c6 == '?' && c7 == 0 && c8 == 'x')
|
||||
{
|
||||
return "application/xml";
|
||||
}
|
||||
}
|
||||
|
||||
if (c1 == 0xff && c2 == 0xfe)
|
||||
{
|
||||
if (c3 == '<' && c4 == 0 && c5 == '?' && c6 == 0 && c7 == 'x' && c8 == 0)
|
||||
{
|
||||
return "application/xml";
|
||||
}
|
||||
}
|
||||
|
||||
if (c1 == 'B' && c2 == 'M')
|
||||
{
|
||||
return "image/bmp";
|
||||
}
|
||||
|
||||
if (c1 == 0x49 && c2 == 0x49 && c3 == 0x2a && c4 == 0x00)
|
||||
{
|
||||
return "image/tiff";
|
||||
}
|
||||
|
||||
if (c1 == 0x4D && c2 == 0x4D && c3 == 0x00 && c4 == 0x2a)
|
||||
{
|
||||
return "image/tiff";
|
||||
}
|
||||
|
||||
if (c1 == 'G' && c2 == 'I' && c3 == 'F' && c4 == '8')
|
||||
{
|
||||
return "image/gif";
|
||||
}
|
||||
|
||||
if (c1 == '#' && c2 == 'd' && c3 == 'e' && c4 == 'f')
|
||||
{
|
||||
return "image/x-bitmap";
|
||||
}
|
||||
|
||||
if (c1 == '!' && c2 == ' ' && c3 == 'X' && c4 == 'P' && c5 == 'M' && c6 == '2')
|
||||
{
|
||||
return "image/x-pixmap";
|
||||
}
|
||||
|
||||
if (c1 == 137 && c2 == 80 && c3 == 78 && c4 == 71 && c5 == 13 && c6 == 10 && c7 == 26 && c8 == 10)
|
||||
{
|
||||
return "image/png";
|
||||
}
|
||||
|
||||
if (c1 == 0xFF && c2 == 0xD8 && c3 == 0xFF)
|
||||
{
|
||||
if (c4 == 0xE0)
|
||||
{
|
||||
return "image/jpeg";
|
||||
}
|
||||
|
||||
/**
|
||||
* File format used by digital cameras to store images. Exif Format can be read by any application supporting JPEG. Exif Spec can be found at:
|
||||
* http://www.pima.net/standards/it10/PIMA15740/Exif_2-1.PDF
|
||||
*/
|
||||
if ((c4 == 0xE1) && (c7 == 'E' && c8 == 'x' && c9 == 'i' && c10 == 'f' && c11 == 0))
|
||||
{
|
||||
return "image/jpeg";
|
||||
}
|
||||
|
||||
if (c4 == 0xEE)
|
||||
{
|
||||
return "image/jpg";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* According to http://www.opendesign.com/files/guestdownloads/OpenDesign_Specification_for_.dwg_files.pdf
|
||||
* first 6 bytes are of type "AC1018" (for example) and the next 5 bytes are 0x00.
|
||||
*/
|
||||
if ((c1 == 0x41 && c2 == 0x43) && (c7 == 0x00 && c8 == 0x00 && c9 == 0x00 && c10 == 0x00 && c11 == 0x00))
|
||||
{
|
||||
return "application/acad";
|
||||
}
|
||||
|
||||
if (c1 == 0x2E && c2 == 0x73 && c3 == 0x6E && c4 == 0x64)
|
||||
{
|
||||
return "audio/basic"; // .au
|
||||
// format,
|
||||
// big
|
||||
// endian
|
||||
}
|
||||
|
||||
if (c1 == 0x64 && c2 == 0x6E && c3 == 0x73 && c4 == 0x2E)
|
||||
{
|
||||
return "audio/basic"; // .au
|
||||
// format,
|
||||
// little
|
||||
// endian
|
||||
}
|
||||
|
||||
if (c1 == 'R' && c2 == 'I' && c3 == 'F' && c4 == 'F')
|
||||
{
|
||||
/*
|
||||
* I don't know if this is official but evidence suggests that .wav files start with "RIFF" - brown
|
||||
*/
|
||||
return "audio/x-wav";
|
||||
}
|
||||
|
||||
if (c1 == 'P' && c2 == 'K')
|
||||
{
|
||||
// its application/zip but this could be a open office thing if name is given
|
||||
String contentType = guessContentTypeFromName(name);
|
||||
if (contentType != null)
|
||||
{
|
||||
return contentType;
|
||||
}
|
||||
return "application/zip";
|
||||
}
|
||||
return guessContentTypeFromName(name);
|
||||
}
|
||||
|
||||
private static final Map<String, String> mimeTypes = new HashMap<String, String>();
|
||||
|
||||
public static String guessContentTypeFromName(String name)
|
||||
{
|
||||
if (name == null) return null;
|
||||
|
||||
int lastIndex = name.lastIndexOf('.');
|
||||
if (lastIndex != -1)
|
||||
{
|
||||
String extention = name.substring(lastIndex + 1).toLowerCase();
|
||||
if (mimeTypes.size() == 0)
|
||||
{
|
||||
HashMap<String, String> tempMap = new HashMap<String, String>();
|
||||
InputStream is = MimeTypes.class.getResourceAsStream("/mime.types.properties");
|
||||
try
|
||||
{
|
||||
Properties properties = new Properties();
|
||||
properties.load(is);
|
||||
for (Object key : properties.keySet())
|
||||
{
|
||||
String property = properties.getProperty((String)key);
|
||||
StringTokenizer st = new StringTokenizer(property, " ");
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
tempMap.put(st.nextToken(), (String)key);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
//ToDo: ošetřit
|
||||
//Debug.error(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
is.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
//ToDo: ošetřit
|
||||
//Debug.error(e);
|
||||
}
|
||||
}
|
||||
synchronized (mimeTypes)
|
||||
{
|
||||
mimeTypes.putAll(tempMap);
|
||||
}
|
||||
}
|
||||
return mimeTypes.get(extention);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String fileExtension(String fileName) {
|
||||
int index = fileName.lastIndexOf(".");
|
||||
|
||||
if (index > -1) {
|
||||
return fileName.substring(index + 1);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package info.bukova.isspst.storage;
|
||||
|
||||
import info.bukova.isspst.data.FileMetainfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by pepa on 2.2.15.
|
||||
*/
|
||||
|
||||
@Controller
|
||||
public class StorageController {
|
||||
|
||||
@Autowired
|
||||
private DocumentFileStorage documentStorage;
|
||||
private static final Logger logger = LoggerFactory.getLogger(StorageController.class);
|
||||
|
||||
@RequestMapping(value = "dl/{path}/{name}")
|
||||
public void viewFile(HttpServletResponse response, @PathVariable("path") String path,
|
||||
@PathVariable("name") String name) {
|
||||
ServletOutputStream os = null;
|
||||
|
||||
try {
|
||||
os = response.getOutputStream();
|
||||
FileMetainfo metainfo = new FileMetainfo();
|
||||
metainfo.setPathInFilesystem(path);
|
||||
byte[] data = null;
|
||||
|
||||
try {
|
||||
data = documentStorage.fileData(metainfo);
|
||||
metainfo.setContentType(MimeTypes.getContentType(data, path));
|
||||
} catch (StorageException e) {
|
||||
response.sendError(404);
|
||||
}
|
||||
|
||||
if (data != null) {
|
||||
response.setContentType(metainfo.getContentType());
|
||||
response.setContentLength(data.length);
|
||||
|
||||
os.write(data, 0, data.length);
|
||||
os.flush();
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("I/O error: " + e.getMessage());
|
||||
} finally {
|
||||
if (os != null) {
|
||||
try {
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package info.bukova.isspst.ui;
|
||||
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.services.ModuleNotActiveException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
|
||||
public class ErrorVM {
|
||||
|
||||
private String message;
|
||||
private final Logger logger = LoggerFactory.getLogger(ErrorVM.class);
|
||||
|
||||
@Init
|
||||
public void init() {
|
||||
HttpServletRequest request = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
|
||||
Throwable ex = (Throwable) request.getAttribute("javax.servlet.error.exception");
|
||||
Throwable root = ex;
|
||||
|
||||
if (root != null) {
|
||||
while (root.getCause() != null) {
|
||||
root = root.getCause();
|
||||
}
|
||||
|
||||
if (root instanceof ModuleNotActiveException) {
|
||||
message = StringUtils.localize("ModuleNotActive");
|
||||
} else {
|
||||
logger.error("Unhandled exception", ex);
|
||||
message = ex.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package info.bukova.isspst.ui;
|
||||
|
||||
import info.bukova.isspst.data.DataModel;
|
||||
import info.bukova.isspst.data.FileMetainfo;
|
||||
import info.bukova.isspst.storage.DocumentFileStorage;
|
||||
import info.bukova.isspst.storage.EntityWithAttachment;
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.ContextParam;
|
||||
import org.zkoss.bind.annotation.ContextType;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zk.ui.event.UploadEvent;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
import org.zkoss.zul.Filedownload;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class FormWithUpload<T extends DataModel> extends FormViewModel<T> {
|
||||
|
||||
private List<FileMetainfo> attachments;
|
||||
private List<FileMetainfo> forDelete;
|
||||
@WireVariable
|
||||
private DocumentFileStorage documentStorage;
|
||||
|
||||
@Init(superclass = true)
|
||||
public void initFormWithUpload() {
|
||||
if (getDataBean() instanceof EntityWithAttachment) {
|
||||
attachments = ((EntityWithAttachment)getDataBean()).getAttachedFiles();
|
||||
}
|
||||
forDelete = new ArrayList<FileMetainfo>(); // kolekce příloh na smazání v případě uložení záznamu
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange("attachments")
|
||||
public void uploadAttachment(@ContextParam(ContextType.TRIGGER_EVENT) UploadEvent upEvent) {
|
||||
FileMetainfo metaInfo = documentStorage.saveAndCreateInfo(upEvent.getMedia().getByteData(),
|
||||
upEvent.getMedia().getName());
|
||||
|
||||
((EntityWithAttachment)getDataBean()).addAttachment(metaInfo);
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange("attachments")
|
||||
public void deleteAttachment(@BindingParam("attachment") FileMetainfo metaInfo) {
|
||||
((EntityWithAttachment)getDataBean()).removeAttachment(metaInfo);
|
||||
forDelete.add(metaInfo); // smazat až v případě uložení záznamu
|
||||
}
|
||||
|
||||
@Command
|
||||
public void downloadAttachment(@BindingParam("attachment") FileMetainfo metaInfo) {
|
||||
Filedownload.save(documentStorage.fileData(metaInfo), metaInfo.getContentType(), metaInfo.getFileName());
|
||||
}
|
||||
|
||||
public List<FileMetainfo> getAttachments() {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSave() {
|
||||
maintainAttachment();
|
||||
super.doSave();
|
||||
}
|
||||
|
||||
protected void maintainAttachment() {
|
||||
for (FileMetainfo info : forDelete) {
|
||||
documentStorage.removeFile(info);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -258,7 +258,10 @@ public class ListViewModel<T extends DataModel> extends DocumentViewModel
|
||||
}
|
||||
dataBean = editBean;
|
||||
if (!newRec && editBean != null) {
|
||||
dataList.set(selIndex, editBean);
|
||||
if (selIndex < dataList.size())
|
||||
{
|
||||
dataList.set(selIndex, editBean);
|
||||
}
|
||||
}
|
||||
|
||||
BindUtils.postGlobalCommand(null, null, "reloadRelated", null);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package info.bukova.isspst.ui.main;
|
||||
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.RequirementBase;
|
||||
import info.bukova.isspst.services.requirement.ApproveException;
|
||||
import info.bukova.isspst.services.requirement.RequirementBaseService;
|
||||
import info.bukova.isspst.ui.ListViewModel;
|
||||
import org.zkoss.bind.BindUtils;
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.ExecutionArgParam;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class ApproveDialogVM {
|
||||
|
||||
private RequirementBaseService service;
|
||||
private RequirementBase requirement;
|
||||
private ListViewModel grid;
|
||||
private Date approveDate;
|
||||
|
||||
public Date getApproveDate() {
|
||||
return approveDate;
|
||||
}
|
||||
|
||||
public void setApproveDate(Date approveDate) {
|
||||
this.approveDate = approveDate;
|
||||
}
|
||||
|
||||
@Init
|
||||
public void init(@ExecutionArgParam("service") RequirementBaseService service,
|
||||
@ExecutionArgParam("requirement") RequirementBase requirement,
|
||||
@ExecutionArgParam("grid") ListViewModel grid) {
|
||||
this.service = service;
|
||||
this.requirement = requirement;
|
||||
this.grid = grid;
|
||||
this.approveDate = new Date();
|
||||
}
|
||||
|
||||
@Command
|
||||
public void approve(@BindingParam("window") Window window) {
|
||||
try {
|
||||
service.approve(requirement, approveDate);
|
||||
BindUtils.postNotifyChange(null, null, grid, "dataBean");
|
||||
BindUtils.postNotifyChange(null, null, grid, "canApprove");
|
||||
BindUtils.postGlobalCommand(null, null, "reload", null);
|
||||
window.detach();
|
||||
} catch (ApproveException ex) {
|
||||
Messagebox.show(StringUtils.localize(ex.getReason()), StringUtils.localize("Error"), Messagebox.OK,
|
||||
Messagebox.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,11 +5,11 @@ 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.filters.TristateBoolean;
|
||||
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;
|
||||
import info.bukova.isspst.ui.ListViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -38,24 +38,17 @@ public class ApprovedList extends ListViewModel<JoinedItem>
|
||||
@WireVariable
|
||||
protected OrderService orderService;
|
||||
|
||||
private BigDecimalConverter bigDecimalConverter;
|
||||
|
||||
protected List<JoinedItem> selectedItems;
|
||||
|
||||
@Init
|
||||
@Init(superclass = true)
|
||||
public void initApprovedList()
|
||||
{
|
||||
service = approvedService;
|
||||
dataClass = JoinedItem.class;
|
||||
// formZul = "form.zul";
|
||||
dataFilter = new JoinedItemFilter(getFilterTemplate());
|
||||
bigDecimalConverter = new BigDecimalConverter();
|
||||
selectedItems = new ArrayList<JoinedItem>();
|
||||
}
|
||||
|
||||
public BigDecimalConverter getBigDecimalConverter()
|
||||
{
|
||||
return bigDecimalConverter;
|
||||
this.itemMaterial = new TristateBoolean();
|
||||
}
|
||||
|
||||
public List<JoinedItem> getItems()
|
||||
@@ -123,4 +116,17 @@ public class ApprovedList extends ListViewModel<JoinedItem>
|
||||
return new ArrayList<JoinedItem>();
|
||||
}
|
||||
}
|
||||
|
||||
protected TristateBoolean itemMaterial;
|
||||
|
||||
public TristateBoolean getItemMaterial()
|
||||
{
|
||||
return this.itemMaterial;
|
||||
}
|
||||
|
||||
public void setItemMaterial(TristateBoolean tristate)
|
||||
{
|
||||
this.itemMaterial = tristate;
|
||||
this.getFilterTemplate().setItemMaterial(tristate.getBoolean());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package info.bukova.isspst.ui.main.invoicing;
|
||||
|
||||
import info.bukova.isspst.data.Invoicing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
|
||||
public class InvoicingArchiveList extends InvoicingList
|
||||
{
|
||||
@Init(superclass = true)
|
||||
public void initInvoicingArchiveList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Invoicing> getListFromService()
|
||||
{
|
||||
try
|
||||
{
|
||||
return invoicingService.getArchiveList();
|
||||
}
|
||||
catch (AccessDeniedException e)
|
||||
{
|
||||
// BindUtils.postGlobalCommand(null, null, "disableCentre", null);
|
||||
// e.printStackTrace();
|
||||
return new ArrayList<Invoicing>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import info.bukova.isspst.data.InvoicingItem;
|
||||
import info.bukova.isspst.services.invoicing.InvoicingService;
|
||||
import info.bukova.isspst.ui.FormViewModel;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.zkoss.bind.BindUtils;
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
@@ -13,14 +16,44 @@ import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
|
||||
public class InvoicingForm extends FormViewModel<Invoicing> {
|
||||
|
||||
public final static String TAG = InvoicingForm.class.getSimpleName();
|
||||
private final static Logger log = LoggerFactory.getLogger(InvoicingForm.class.getSimpleName());
|
||||
|
||||
private InvoicingItem selectedItem;
|
||||
private int selectedIndex;
|
||||
@WireVariable
|
||||
private InvoicingService invoicingService;
|
||||
|
||||
protected Invoicing invoicingBeforeEdit;
|
||||
|
||||
@Init(superclass = true)
|
||||
public void init() {
|
||||
public void initInvoicingForm()
|
||||
{
|
||||
selectedIndex = -1;
|
||||
|
||||
try
|
||||
{
|
||||
this.invoicingBeforeEdit = (Invoicing) this.getDataBean().clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
log.error("Nelze provést hlubokou kopii fakturace!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSave()
|
||||
{
|
||||
// Zjisti, zda se změnil příznak Vyřízeno
|
||||
boolean competedChanged = (this.invoicingBeforeEdit.isCompleted() != this.getDataBean().isCompleted());
|
||||
|
||||
super.doSave();
|
||||
|
||||
if (competedChanged)
|
||||
{
|
||||
BindUtils.postGlobalCommand(null, null, "refreshTabs", null);
|
||||
}
|
||||
}
|
||||
|
||||
private void selectItem(InvoicingItem item) {
|
||||
@@ -77,4 +110,13 @@ public class InvoicingForm extends FormViewModel<Invoicing> {
|
||||
this.selectedIndex = selectedIndex;
|
||||
}
|
||||
|
||||
public Invoicing getInvoicingBeforeEdit()
|
||||
{
|
||||
return invoicingBeforeEdit;
|
||||
}
|
||||
|
||||
public void setInvoicingBeforeEdit(Invoicing invoicingBeforeEdit)
|
||||
{
|
||||
this.invoicingBeforeEdit = invoicingBeforeEdit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
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;
|
||||
@@ -11,13 +9,17 @@ import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.ui.ListViewModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.bind.annotation.GlobalCommand;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
|
||||
public class InvoicingList extends ListViewModel<Invoicing> {
|
||||
|
||||
@WireVariable
|
||||
private InvoicingService invoicingService;
|
||||
protected InvoicingService invoicingService;
|
||||
@WireVariable
|
||||
private WorkgroupService workgroupService;
|
||||
@WireVariable
|
||||
@@ -53,4 +55,15 @@ public class InvoicingList extends ListViewModel<Invoicing> {
|
||||
return userService.getUsersForCombo();
|
||||
}
|
||||
|
||||
@GlobalCommand
|
||||
@NotifyChange({ "dataList", "dataBean", "ableToDelete" })
|
||||
public void refreshTabs()
|
||||
{
|
||||
// Změnou hodnoty Vyřízeno se záznam přesunul do jiné záložky
|
||||
// Aby se editovaný záznam nerefreshoval, protože tam už nebude, nastaví
|
||||
// se na null
|
||||
this.setEditBean(null);
|
||||
// Provede přenačtení všech záložek
|
||||
this.reload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package info.bukova.isspst.ui.main.invoicing;
|
||||
|
||||
import info.bukova.isspst.data.Invoicing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
|
||||
public class InvoicingPendingList extends InvoicingList
|
||||
{
|
||||
@Init(superclass = true)
|
||||
public void initInvoicingPendingList()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Invoicing> getListFromService()
|
||||
{
|
||||
try
|
||||
{
|
||||
return invoicingService.getPendingList();
|
||||
}
|
||||
catch (AccessDeniedException e)
|
||||
{
|
||||
// BindUtils.postGlobalCommand(null, null, "disableCentre", null);
|
||||
// e.printStackTrace();
|
||||
return new ArrayList<Invoicing>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -297,6 +297,17 @@ public class OrderForm extends FormViewModel<Order>
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -5,9 +5,6 @@ import info.bukova.isspst.reporting.ReportDefinition;
|
||||
import info.bukova.isspst.reporting.ReportType;
|
||||
import info.bukova.isspst.services.Service;
|
||||
import info.bukova.isspst.ui.DocumentViewModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.ExecutionArgParam;
|
||||
@@ -17,6 +14,8 @@ import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReportDialogVM extends DocumentViewModel
|
||||
{
|
||||
|
||||
@@ -94,4 +93,12 @@ public class ReportDialogVM extends DocumentViewModel
|
||||
this.reportDefinition = reportDefinition;
|
||||
}
|
||||
|
||||
public boolean isCanPrint() {
|
||||
if (singleObject != null) {
|
||||
return reportDefinition.getService().canPrintRecord(singleObject);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,14 +7,17 @@ import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.ui.BigDecimalConverter;
|
||||
import info.bukova.isspst.ui.ListViewModel;
|
||||
import info.bukova.isspst.ui.renderers.RequirementsItemRenderer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.bind.BindUtils;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
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.Window;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RequirementSubpage<T extends RequirementBase> extends ListViewModel<T> {
|
||||
|
||||
@@ -55,8 +58,12 @@ public class RequirementSubpage<T extends RequirementBase> extends ListViewModel
|
||||
@Command
|
||||
@NotifyChange({"dataBean", "canApprove"})
|
||||
public void approve() {
|
||||
this.getReqService().approve(getDataBean());
|
||||
BindUtils.postGlobalCommand(null, null, "reload", null);
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("service", getReqService());
|
||||
params.put("requirement", getDataBean());
|
||||
params.put("grid", this);
|
||||
Window window = (Window) Executions.createComponents("/main/approveDialog.zul", null, params);
|
||||
window.doModal();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
package info.bukova.isspst.ui.requirement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.RequirementState;
|
||||
import info.bukova.isspst.data.SettingsData;
|
||||
import info.bukova.isspst.data.TripRequirement;
|
||||
import info.bukova.isspst.data.User;
|
||||
@@ -17,10 +11,22 @@ import info.bukova.isspst.services.requirement.TripRequirementService;
|
||||
import info.bukova.isspst.services.settings.GlobalSettingsService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.ui.FormViewModel;
|
||||
import info.bukova.isspst.storage.DocumentFileStorage;
|
||||
import info.bukova.isspst.ui.FormWithUpload;
|
||||
import info.bukova.isspst.validators.TripRequirementFormValidator;
|
||||
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.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
public class TripRequirementForm extends FormViewModel<TripRequirement> {
|
||||
import java.util.List;
|
||||
|
||||
public class TripRequirementForm extends FormWithUpload<TripRequirement> {
|
||||
|
||||
@WireVariable
|
||||
private UserService userService;
|
||||
@@ -32,7 +38,33 @@ public class TripRequirementForm extends FormViewModel<TripRequirement> {
|
||||
private RequirementTypeService reqTypeService;
|
||||
@WireVariable
|
||||
private TripRequirementService tripRequirementService;
|
||||
@WireVariable
|
||||
private DocumentFileStorage documentStorage;
|
||||
private List<Workgroup> centres;
|
||||
|
||||
@Override
|
||||
@NotifyChange("errMessages")
|
||||
@Command
|
||||
public void save(@BindingParam("window") Window win) {
|
||||
final Window editWin = win;
|
||||
|
||||
if (getDataBean().getState() == RequirementState.APPROVED) {
|
||||
Messagebox.show(StringUtils.localize("TripRequirementChangeWarn"), StringUtils.localize("TripRequirementSave"), Messagebox.YES
|
||||
| Messagebox.NO, Messagebox.QUESTION, new EventListener<Event>() {
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (((Integer) event.getData()).intValue() == Messagebox.YES) {
|
||||
TripRequirementForm.super.save(editWin);
|
||||
} else {
|
||||
editWin.detach();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
super.save(win);
|
||||
}
|
||||
}
|
||||
|
||||
private List<User> users;
|
||||
private List<User> passengers;
|
||||
private User selUser;
|
||||
|
||||
@@ -7,10 +7,6 @@ import info.bukova.isspst.services.requirement.TripRequirementService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
import info.bukova.isspst.ui.ListViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.zkoss.bind.BindUtils;
|
||||
import org.zkoss.bind.annotation.GlobalCommand;
|
||||
@@ -18,6 +14,9 @@ import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TripRequirementList extends ListViewModel<TripRequirement> {
|
||||
|
||||
@WireVariable
|
||||
@@ -79,11 +78,6 @@ public class TripRequirementList extends ListViewModel<TripRequirement> {
|
||||
return myCentres;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadLazyDataForEdit(TripRequirement data) {
|
||||
tripRequirementService.loadPassangers(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TripRequirement> getListFromService()
|
||||
{
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
package info.bukova.isspst.ui.requirement;
|
||||
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
import info.bukova.isspst.data.TripRequirement;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.filters.TripRequirementFilter;
|
||||
import info.bukova.isspst.services.requirement.TripRequirementService;
|
||||
import info.bukova.isspst.services.tripbill.TripBillService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.zkoss.bind.BindUtils;
|
||||
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.Window;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TripRequirementListAll extends RequirementSubpage<TripRequirement> {
|
||||
|
||||
@@ -22,6 +28,8 @@ public class TripRequirementListAll extends RequirementSubpage<TripRequirement>
|
||||
private TripRequirementService tripRequirementService;
|
||||
@WireVariable
|
||||
private WorkgroupService workgroupService;
|
||||
@WireVariable
|
||||
private TripBillService tripBillService;
|
||||
private List<Workgroup> allCentres;
|
||||
private List<Workgroup> allWorkgroups;
|
||||
|
||||
@@ -65,4 +73,18 @@ public class TripRequirementListAll extends RequirementSubpage<TripRequirement>
|
||||
BindUtils.postGlobalCommand(null, null, "selectAll", null);
|
||||
}
|
||||
|
||||
@Command
|
||||
public void showTripBill() {
|
||||
if (getDataBean() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TripBill tb = tripRequirementService.getTripBill(getDataBean());
|
||||
tripBillService.loadLazyData(tb);
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("bill", tb);
|
||||
Window win = (Window) Executions.createComponents("tripBillSummaryMaster.zul", null, params);
|
||||
win.doModal();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
package info.bukova.isspst.ui.requirement;
|
||||
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
import info.bukova.isspst.data.TripRequirement;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.filters.TripRequirementFilter;
|
||||
import info.bukova.isspst.services.requirement.TripRequirementService;
|
||||
import info.bukova.isspst.services.tripbill.TripBillService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.zkoss.bind.BindUtils;
|
||||
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.Window;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TripRequirementListCentre extends RequirementSubpage<TripRequirement> {
|
||||
|
||||
@@ -24,6 +30,9 @@ public class TripRequirementListCentre extends RequirementSubpage<TripRequiremen
|
||||
@WireVariable
|
||||
private WorkgroupService workgroupService;
|
||||
|
||||
@WireVariable
|
||||
private TripBillService tripBillService;
|
||||
|
||||
private List<Workgroup> myCentres;
|
||||
|
||||
@Init
|
||||
@@ -61,4 +70,18 @@ public class TripRequirementListCentre extends RequirementSubpage<TripRequiremen
|
||||
BindUtils.postGlobalCommand(null, null, "selectCentre", null);
|
||||
}
|
||||
|
||||
@Command
|
||||
public void showTripBill() {
|
||||
if (getDataBean() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TripBill tb = tripRequirementService.getTripBill(getDataBean());
|
||||
tripBillService.loadLazyData(tb);
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("bill", tb);
|
||||
Window win = (Window) Executions.createComponents("tripBillSummaryMaster.zul", null, params);
|
||||
win.doModal();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
package info.bukova.isspst.ui.requirement;
|
||||
|
||||
import info.bukova.isspst.data.TripBill;
|
||||
import info.bukova.isspst.data.TripRequirement;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.filters.TripRequirementFilter;
|
||||
import info.bukova.isspst.services.requirement.TripRequirementService;
|
||||
import info.bukova.isspst.services.tripbill.TripBillService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.zkoss.bind.BindUtils;
|
||||
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.Window;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TripRequirementListWorkgroup extends RequirementSubpage<TripRequirement> {
|
||||
|
||||
@@ -24,6 +30,9 @@ public class TripRequirementListWorkgroup extends RequirementSubpage<TripRequire
|
||||
@WireVariable
|
||||
private WorkgroupService workgroupService;
|
||||
|
||||
@WireVariable
|
||||
private TripBillService tripBillService;
|
||||
|
||||
private List<Workgroup> myCentres;
|
||||
|
||||
private List<Workgroup> myWorkgroups;
|
||||
@@ -68,4 +77,18 @@ public class TripRequirementListWorkgroup extends RequirementSubpage<TripRequire
|
||||
BindUtils.postGlobalCommand(null, null, "selectWorkgroup", null);
|
||||
}
|
||||
|
||||
@Command
|
||||
public void showTripBill() {
|
||||
if (getDataBean() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TripBill tb = tripRequirementService.getTripBill(getDataBean());
|
||||
tripBillService.loadLazyData(tb);
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("bill", tb);
|
||||
Window win = (Window) Executions.createComponents("tripBillSummaryMaster.zul", null, params);
|
||||
win.doModal();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package info.bukova.isspst.ui.search;
|
||||
|
||||
import info.bukova.isspst.EntityUrlResolver;
|
||||
import info.bukova.isspst.data.BaseData;
|
||||
import info.bukova.isspst.data.DataModel;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*
|
||||
* Třída obecného transformačního objektu. Do výsledku nastaví property z rozhraní {@link DataModel}, které implementují všechny entity.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractResultTransformer implements ResultTransformer {
|
||||
|
||||
protected EntityUrlResolver urlResolver;
|
||||
|
||||
@Override
|
||||
public SearchResult transformObject(Object object) {
|
||||
BaseData data = (BaseData)object;
|
||||
SearchResult result = new SearchResult();
|
||||
|
||||
result.setCreated(data.getCreated());
|
||||
result.setModified(data.getModified());
|
||||
result.setOwnedBy(data.getOwnedBy());
|
||||
result.setModifiedBy(data.getModifiedBy());
|
||||
|
||||
if (urlResolver != null) {
|
||||
result.setUrl(urlResolver.entityUrl(data));
|
||||
}
|
||||
|
||||
|
||||
transform(object, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Další transformace v závislosti na konkrétní třídě přdané entity
|
||||
*
|
||||
* @param object entita k transformaci
|
||||
* @param result výsledný transformovaný objekt
|
||||
*/
|
||||
protected abstract void transform(Object object, SearchResult result);
|
||||
|
||||
@Override
|
||||
public void setUrlResolver(EntityUrlResolver resolver) {
|
||||
this.urlResolver = resolver;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package info.bukova.isspst.ui.search;
|
||||
|
||||
|
||||
public class CommonResultTransformer extends AbstractResultTransformer implements ResultTransformer {
|
||||
|
||||
@Override
|
||||
protected void transform(Object object, SearchResult result) {
|
||||
result.setRecordName("Neznámá entita");
|
||||
result.setDescription(object.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package info.bukova.isspst.ui.search;
|
||||
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.Order;
|
||||
|
||||
public class OrderResultTransformer extends AbstractResultTransformer implements ResultTransformer {
|
||||
|
||||
@Override
|
||||
protected void transform(Object object, SearchResult result) {
|
||||
Order order = (Order)object;
|
||||
result.setRecordName(StringUtils.localize("Order") + ": " + order.getNumser());
|
||||
result.setDescription(order.getDescription() + ", " + StringUtils.localize("Supplier") + ": " + order.getSuplier().getCompany());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package info.bukova.isspst.ui.search;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.Requirement;
|
||||
|
||||
public class RequirementResultTransformer extends AbstractResultTransformer implements ResultTransformer {
|
||||
|
||||
@Override
|
||||
protected void transform(Object object, SearchResult result) {
|
||||
Requirement req = (Requirement)object;
|
||||
String moduleName;
|
||||
|
||||
if (req.getKind() != null && req.getKind().equals(Constants.REQ_TYPE_SERVICES)) {
|
||||
moduleName = StringUtils.localize("ServiceRequirement");
|
||||
} else {
|
||||
moduleName = StringUtils.localize("MaterialRequirement");
|
||||
}
|
||||
|
||||
result.setRecordName(moduleName + ": " + req.getNumser());
|
||||
result.setDescription(req.getDescription());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package info.bukova.isspst.ui.search;
|
||||
|
||||
import info.bukova.isspst.EntityUrlResolver;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*
|
||||
* Rozhraní transformačního objektu výsledků fulltextového vyhledávání. Z vyhledaných entit potřebujeme na UI
|
||||
* objekty třídy {@link SearchResult}.
|
||||
*
|
||||
*/
|
||||
public interface ResultTransformer {
|
||||
|
||||
/**
|
||||
* Transformuje entitu na {@link SearchResult}
|
||||
*
|
||||
* @param object entita k transformaci
|
||||
* @return objekt {@link SearchResult}
|
||||
*/
|
||||
public SearchResult transformObject(Object object);
|
||||
|
||||
|
||||
/**
|
||||
* Nastaví objekt vyhodnocovače URL záznamu, aby bylo možné generovat URL pro přímý přístup do příslušné agendy a vystavení kurzoru v gridu.
|
||||
*
|
||||
* @param resolver vyhodnocovač URL
|
||||
*/
|
||||
public void setUrlResolver(EntityUrlResolver resolver);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package info.bukova.isspst.ui.search;
|
||||
|
||||
import info.bukova.isspst.UrlResolverHolder;
|
||||
import info.bukova.isspst.services.fulltext.FullTextService;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SearchForm {
|
||||
|
||||
@WireVariable
|
||||
private FullTextService fulltextService;
|
||||
@WireVariable
|
||||
private UrlResolverHolder urlResolverHolder;
|
||||
private List<SearchResult> results;
|
||||
|
||||
private String keyWord;
|
||||
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange("results")
|
||||
public void doSearch() {
|
||||
if (keyWord == null || keyWord.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<?> result = fulltextService.globalSearch(keyWord);
|
||||
|
||||
SearchListTransformer srt = new SearchListTransformer(urlResolverHolder);
|
||||
results = srt.transform(result);
|
||||
|
||||
System.out.println(result.size());
|
||||
}
|
||||
|
||||
public String getKeyWord() {
|
||||
return keyWord;
|
||||
}
|
||||
|
||||
public void setKeyWord(String keyWord) {
|
||||
this.keyWord = keyWord;
|
||||
}
|
||||
|
||||
public List<SearchResult> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package info.bukova.isspst.ui.search;
|
||||
|
||||
import info.bukova.isspst.UrlResolverHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*
|
||||
* Transformuje list různých entit na list objektů třídy {@link SearchResult}
|
||||
*
|
||||
*/
|
||||
public class SearchListTransformer {
|
||||
|
||||
private UrlResolverHolder urlResolverHolder;
|
||||
|
||||
public SearchListTransformer() {
|
||||
urlResolverHolder = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param urlResolverHolder kontajner vyhodnocovačů URL (objekt se konfiguruje přes Spring context)
|
||||
*/
|
||||
public SearchListTransformer(UrlResolverHolder urlResolverHolder) {
|
||||
super();
|
||||
this.urlResolverHolder = urlResolverHolder;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<SearchResult> transform(List<?> source) {
|
||||
List<SearchResult> ret = new ArrayList<SearchResult>();
|
||||
|
||||
for (int i = 0; i < source.size(); i++) {
|
||||
ResultTransformer transformer = TransformerFactory.transformerFor(source.get(i));
|
||||
if (urlResolverHolder != null) {
|
||||
transformer.setUrlResolver(urlResolverHolder.resolverFor(source.get(i).getClass()));
|
||||
}
|
||||
ret.add(transformer.transformObject(source.get(i)));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user