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 00000000..833e607d Binary files /dev/null and b/src/main/webapp/img/settings.png differ 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 @@ + + + + + + + + + + + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + +