From 9905cc769d8b3a06dd5a366276fced8cfc03ec73 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sun, 6 Jul 2014 11:50:03 +0200 Subject: [PATCH] =?UTF-8?q?Okno=20glob=C3=A1ln=C3=ADho=20nastaven=C3=AD.?= =?UTF-8?q?=20refs=20#101?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../info/bukova/isspst/AppInitListener.java | 17 ++- .../bukova/isspst/dao/GlobalSettingsDao.java | 7 ++ .../isspst/dao/jpa/GlobalSettingsDaoJPA.java | 9 ++ .../bukova/isspst/data/GlobalSettings.java | 22 ++++ .../info/bukova/isspst/data/SettingsData.java | 50 ++++++++ .../settings/GlobalSettingServiceImpl.java | 110 ++++++++++++++++++ .../settings/GlobalSettingsService.java | 12 ++ .../info/bukova/isspst/ui/NavigationVM.java | 6 + .../isspst/ui/settings/GlobalSettingsVM.java | 60 ++++++++++ src/main/resources/hibernate.cfg.xml | 1 + .../WEB-INF/locales/zk-label.properties | 9 ++ .../webapp/WEB-INF/spring/root-context.xml | 27 +++++ src/main/webapp/app/navigation.zul | 2 +- src/main/webapp/img/settings.png | Bin 0 -> 3188 bytes src/main/webapp/settings/globalSettings.zul | 108 +++++++++++++++++ src/main/webapp/settings/numberSeries.zul | 3 +- 16 files changed, 439 insertions(+), 4 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/dao/GlobalSettingsDao.java create mode 100644 src/main/java/info/bukova/isspst/dao/jpa/GlobalSettingsDaoJPA.java create mode 100644 src/main/java/info/bukova/isspst/data/GlobalSettings.java create mode 100644 src/main/java/info/bukova/isspst/data/SettingsData.java create mode 100644 src/main/java/info/bukova/isspst/services/settings/GlobalSettingServiceImpl.java create mode 100644 src/main/java/info/bukova/isspst/services/settings/GlobalSettingsService.java create mode 100644 src/main/java/info/bukova/isspst/ui/settings/GlobalSettingsVM.java create mode 100644 src/main/webapp/img/settings.png create mode 100644 src/main/webapp/settings/globalSettings.zul diff --git a/src/main/java/info/bukova/isspst/AppInitListener.java b/src/main/java/info/bukova/isspst/AppInitListener.java index 361938c0..b2645840 100644 --- a/src/main/java/info/bukova/isspst/AppInitListener.java +++ b/src/main/java/info/bukova/isspst/AppInitListener.java @@ -1,8 +1,7 @@ package info.bukova.isspst; +import info.bukova.isspst.data.GlobalSettings; import info.bukova.isspst.data.NumberSeries; -import java.util.List; - import info.bukova.isspst.data.Permission; import info.bukova.isspst.data.RequirementType; import info.bukova.isspst.data.Role; @@ -12,10 +11,13 @@ import info.bukova.isspst.reporting.ReportMapping; import info.bukova.isspst.reporting.ReportType; import info.bukova.isspst.services.numberseries.NumberSeriesService; import info.bukova.isspst.services.requirements.RequirementTypeService; +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.util.List; + import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; @@ -32,6 +34,7 @@ public class AppInitListener implements ServletContextListener { private PermissionService permService; private NumberSeriesService nsService; private RequirementTypeService reqTypeService; + private GlobalSettingsService gSettingsService; @Override public void contextDestroyed(ServletContextEvent arg0) { @@ -48,6 +51,7 @@ public class AppInitListener implements ServletContextListener { userService = ctx.getBean(UserService.class); permService = ctx.getBean(PermissionService.class); nsService =ctx.getBean(NumberSeriesService.class); + gSettingsService = ctx.getBean(GlobalSettingsService.class); reqTypeService = ctx.getBean(RequirementTypeService.class); userService.grantAdmin(); @@ -57,6 +61,7 @@ public class AppInitListener implements ServletContextListener { checkAllAdminRights(); this.checkNumberSeries(); checkReqTypes(); + this.checkGlobalSettings(); userService.removeAccess(); loadModuleReports(); @@ -173,5 +178,13 @@ public class AppInitListener implements ServletContextListener { nsService.add(ns); } } + + private void checkGlobalSettings() { + if (gSettingsService.getAll().isEmpty()) { + GlobalSettings gs = new GlobalSettings(); + gSettingsService.add(gs); + } + + } } diff --git a/src/main/java/info/bukova/isspst/dao/GlobalSettingsDao.java b/src/main/java/info/bukova/isspst/dao/GlobalSettingsDao.java new file mode 100644 index 00000000..4b960b8e --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/GlobalSettingsDao.java @@ -0,0 +1,7 @@ +package info.bukova.isspst.dao; + +import info.bukova.isspst.data.GlobalSettings; + +public interface GlobalSettingsDao extends BaseDao { + +} diff --git a/src/main/java/info/bukova/isspst/dao/jpa/GlobalSettingsDaoJPA.java b/src/main/java/info/bukova/isspst/dao/jpa/GlobalSettingsDaoJPA.java new file mode 100644 index 00000000..78e7365d --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/jpa/GlobalSettingsDaoJPA.java @@ -0,0 +1,9 @@ +package info.bukova.isspst.dao.jpa; + +import info.bukova.isspst.dao.GlobalSettingsDao; +import info.bukova.isspst.data.GlobalSettings; + +public class GlobalSettingsDaoJPA extends BaseDaoJPA implements + GlobalSettingsDao { + +} diff --git a/src/main/java/info/bukova/isspst/data/GlobalSettings.java b/src/main/java/info/bukova/isspst/data/GlobalSettings.java new file mode 100644 index 00000000..5ce9aecb --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/GlobalSettings.java @@ -0,0 +1,22 @@ +package info.bukova.isspst.data; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Entity +@Table(name = "GLOBALSETTINGS") +public class GlobalSettings extends BaseData { + + @Column(name = "DATA", length = 1048576) + private String data; + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + +} diff --git a/src/main/java/info/bukova/isspst/data/SettingsData.java b/src/main/java/info/bukova/isspst/data/SettingsData.java new file mode 100644 index 00000000..89434b41 --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/SettingsData.java @@ -0,0 +1,50 @@ +package info.bukova.isspst.data; + +import info.bukova.isspst.mail.MailMessage; + +public class SettingsData { + + private boolean enableRequirements; + private MailMessage newReqTemplate; + private MailMessage authReqTemplate; + private MailMessage confReqTemplate; + + public SettingsData() { + newReqTemplate = new MailMessage(); + authReqTemplate = new MailMessage(); + confReqTemplate = new MailMessage(); + } + + public boolean isEnableRequirements() { + return enableRequirements; + } + + public void setEnableRequirements(boolean enableRequirements) { + this.enableRequirements = enableRequirements; + } + + public MailMessage getNewReqTemplate() { + return newReqTemplate; + } + + public void setNewReqTemplate(MailMessage newReqTemplate) { + this.newReqTemplate = newReqTemplate; + } + + public MailMessage getAuthReqTemplate() { + return authReqTemplate; + } + + public void setAuthReqTemplate(MailMessage authReqTemplate) { + this.authReqTemplate = authReqTemplate; + } + + public MailMessage getConfReqTemplate() { + return confReqTemplate; + } + + public void setConfReqTemplate(MailMessage confReqTemplate) { + this.confReqTemplate = confReqTemplate; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/settings/GlobalSettingServiceImpl.java b/src/main/java/info/bukova/isspst/services/settings/GlobalSettingServiceImpl.java new file mode 100644 index 00000000..a06a322f --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/settings/GlobalSettingServiceImpl.java @@ -0,0 +1,110 @@ +package info.bukova.isspst.services.settings; + +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; + +import org.exolab.castor.xml.MarshalException; +import org.exolab.castor.xml.Marshaller; +import org.exolab.castor.xml.Unmarshaller; +import org.exolab.castor.xml.ValidationException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; + +import info.bukova.isspst.data.GlobalSettings; +import info.bukova.isspst.data.SettingsData; +import info.bukova.isspst.services.AbstractOwnedService; +import info.bukova.isspst.services.IsspstException; + +public class GlobalSettingServiceImpl extends AbstractOwnedService implements + GlobalSettingsService { + + private final static Logger log = LoggerFactory.getLogger(GlobalSettingsService.class); + private final static String MARSHAL_ERROR = "Cannot marshal settings data: "; + private final static String UNMARSHAL_ERROR = "Cannot unmarshal settings data: "; + + private Marshaller marshaller; + private Unmarshaller unmarshaller; + private SettingsData settings; + + public GlobalSettingServiceImpl(Marshaller marshaller, Unmarshaller unmarshaller) { + this.marshaller = marshaller; + this.unmarshaller = unmarshaller; + } + + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_ADD')") + public void add(GlobalSettings entity) { + if (!this.getAll().isEmpty()) { + throw new IsspstException("Global settings allready exists"); + } + + if (entity.getData() == null || entity.getData().isEmpty()) { + SettingsData data = new SettingsData(); + entity.setData(marshalData(data)); + } + + super.add(entity); + } + + private String marshalData(SettingsData data) { + StringWriter wr = new StringWriter(); + try { + marshaller.setWriter(wr); + marshaller. marshal(data); + } catch (MarshalException e) { + log.error(MARSHAL_ERROR + e.getMessage()); + } catch (ValidationException e) { + log.error(MARSHAL_ERROR + e.getMessage()); + } catch (IOException e) { + log.error(MARSHAL_ERROR + e.getMessage()); + } + + return wr.toString(); + + } + + private SettingsData unmarshalData(String data) { + StringReader sr = new StringReader(data); + try { + unmarshaller.setClass(SettingsData.class); + return (SettingsData) unmarshaller.unmarshal(sr); + } catch (MarshalException e) { + log.error(UNMARSHAL_ERROR + e.getMessage()); + } catch (ValidationException e) { + log.error(UNMARSHAL_ERROR + e.getMessage()); + } + + return null; + } + + @Override + @Transactional + public SettingsData getSettings() { + if (settings == null) { + GlobalSettings gs = this.getAll().get(0); + settings = unmarshalData(gs.getData()); + } + return settings; + } + + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_EDIT')") + public void updateSettings() { + if (this.getAll().isEmpty()) { + throw new IsspstException("Global settings does not exists"); + } + + GlobalSettings gs = this.getAll().get(0); + gs.setData(marshalData(settings)); + + super.update(gs); + } + + + +} diff --git a/src/main/java/info/bukova/isspst/services/settings/GlobalSettingsService.java b/src/main/java/info/bukova/isspst/services/settings/GlobalSettingsService.java new file mode 100644 index 00000000..e15cba77 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/settings/GlobalSettingsService.java @@ -0,0 +1,12 @@ +package info.bukova.isspst.services.settings; + +import info.bukova.isspst.data.GlobalSettings; +import info.bukova.isspst.data.SettingsData; +import info.bukova.isspst.services.Service; + +public interface GlobalSettingsService extends Service { + + public void updateSettings(); + public SettingsData getSettings(); + +} diff --git a/src/main/java/info/bukova/isspst/ui/NavigationVM.java b/src/main/java/info/bukova/isspst/ui/NavigationVM.java index 0f6ae109..72d9a205 100644 --- a/src/main/java/info/bukova/isspst/ui/NavigationVM.java +++ b/src/main/java/info/bukova/isspst/ui/NavigationVM.java @@ -28,6 +28,12 @@ public class NavigationVM { window.doModal(); } + @Command + public void globalSettings() { + Window window = (Window)Executions.createComponents("/settings/globalSettings.zul", null, null); + window.doModal(); + } + public String getContextPath() { return contextPath; } diff --git a/src/main/java/info/bukova/isspst/ui/settings/GlobalSettingsVM.java b/src/main/java/info/bukova/isspst/ui/settings/GlobalSettingsVM.java new file mode 100644 index 00000000..6def8eaa --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/settings/GlobalSettingsVM.java @@ -0,0 +1,60 @@ +package info.bukova.isspst.ui.settings; + +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 org.zkoss.zul.Window; + +import info.bukova.isspst.data.Requirement; +import info.bukova.isspst.data.SettingsData; +import info.bukova.isspst.mail.MailMessage; +import info.bukova.isspst.services.settings.GlobalSettingsService; +import info.bukova.isspst.sort.ReflectionTools; +import info.bukova.isspst.ui.LocaleConverter; + +public class GlobalSettingsVM { + + @WireVariable + private GlobalSettingsService settingsService; + private SettingsData settings; + private LocaleConverter locConverter; + + @Init + public void init() { + settings = settingsService.getSettings(); + locConverter = new LocaleConverter(); + } + + public SettingsData getSettings() { + return settings; + } + + @Command + public void save(@BindingParam("window") Window window) { + settingsService.updateSettings(); + window.detach(); + } + + public List getRequirementFields() { + return ReflectionTools.getEntityFields(Requirement.class); + } + + public boolean isCanSave() { + return true; + } + + public LocaleConverter getLocConverter() { + return locConverter; + } + + @Command + @NotifyChange("settings") + public void insertField(@BindingParam("field") String field, @BindingParam("message") MailMessage message) { + message.setText(message.getText() + ":" + field + ":"); + } + +} diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index 5b798d77..115c5d51 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -21,5 +21,6 @@ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 24e07edf..acae1cc4 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -112,6 +112,15 @@ NumberSeriesFormTitle=Číselné řady Number=Číslo: Prefix=Prefix: +GlobalSettings=Globální nastavení +Requirements=Požadavky +EMails=E-maily +NewRequirement=Nový požadavek +AuthRequirement=Dílčí schválení +ConfirmRequirement=Schválení +InsertField=Vložit pole +EnableRequirements=Povolit zadávání požadavků + CentresForRequirements=Střediska, pro která lze vkládat požadavky WorkgroupMembership=Členství v komisích LogedInUser=Přihlášený uživatel: diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index cef73c09..9c2d7ec2 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -157,6 +157,10 @@ + + + + @@ -238,4 +242,27 @@ + + + + + + + + + + + element + + + + + + + + + + + + diff --git a/src/main/webapp/app/navigation.zul b/src/main/webapp/app/navigation.zul index a01cd11f..6418c5d7 100644 --- a/src/main/webapp/app/navigation.zul +++ b/src/main/webapp/app/navigation.zul @@ -41,7 +41,7 @@ - + diff --git a/src/main/webapp/img/settings.png b/src/main/webapp/img/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..833e607d58bed5c85838b6c9cb440f977837ac85 GIT binary patch literal 3188 zcmV-)42$!LP)R>%dT%}J_4U=()M~oA zy6;c&RjXFrJWfqbopk)R*Q&5=^*Zg&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O7@{DA=%rG~DK)on z!X7DrH~`lG{9LV8LoSySi^T$i!2qdLdeac!)Yfl;9B+3oFZ{_E46o0foo#eE-82*k z6G~y_LS@_;*E+3xL8nMfJ&t@a_;!4 z3*Y_S8&3m(J<8uXET~kfbd$-nZ)j*}Go@4nK>s&>%eDYhRswZ%y#jH2KK#G`H{h$j`3iF9 a>i+;!$hT3O%}*}?0000 literal 0 HcmV?d00001 diff --git a/src/main/webapp/settings/globalSettings.zul b/src/main/webapp/settings/globalSettings.zul new file mode 100644 index 00000000..9d693e92 --- /dev/null +++ b/src/main/webapp/settings/globalSettings.zul @@ -0,0 +1,108 @@ + + + + + + + + + + + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + +