Okno globálního nastavení.

refs #101
multitenant
Josef Rokos 11 years ago
parent 005c7fa7ef
commit 9905cc769d

@ -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();
@ -174,4 +179,12 @@ public class AppInitListener implements ServletContextListener {
}
}
private void checkGlobalSettings() {
if (gSettingsService.getAll().isEmpty()) {
GlobalSettings gs = new GlobalSettings();
gSettingsService.add(gs);
}
}
}

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

@ -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<GlobalSettings> implements
GlobalSettingsDao {
}

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

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

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

@ -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<GlobalSettings> {
public void updateSettings();
public SettingsData getSettings();
}

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

@ -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<String> 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 + ":");
}
}

@ -21,5 +21,6 @@
<mapping class="info.bukova.isspst.data.Workflow"></mapping>
<mapping class="info.bukova.isspst.data.RequirementType"></mapping>
<mapping class="info.bukova.isspst.data.ServiceItem"></mapping>
<mapping class="info.bukova.isspst.data.GlobalSettings"></mapping>
</session-factory>
</hibernate-configuration>

@ -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:

@ -157,6 +157,10 @@
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="settingsDao" class="info.bukova.isspst.dao.jpa.GlobalSettingsDaoJPA">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Business logic -->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
@ -238,4 +242,27 @@
<property name="dao" ref="serviceItemDao" />
<property name="validator" ref="validator" />
</bean>
<bean id="settingsService" class="info.bukova.isspst.services.settings.GlobalSettingServiceImpl">
<constructor-arg name="marshaller" ref="marshallerSettings"/>
<constructor-arg name="unmarshaller" ref="unmarshallerSettings"/>
<property name="dao" ref="settingsDao"/>
</bean>
<bean id="xmlCtxSettings" class="org.castor.spring.xml.XMLContextFactoryBean">
<property name="castorProperties">
<props>
<prop key="org.exolab.castor.xml.introspector.primitive.nodetype">element</prop>
</props>
</property>
</bean>
<bean id="unmarshallerSettings" class="org.castor.spring.xml.CastorUnmarshallerFactoryBean">
<property name="xmlContext" ref="xmlCtxSettings" />
</bean>
<bean id="marshallerSettings" class="org.castor.spring.xml.CastorMarshallerFactoryBean">
<property name="xmlContext" ref="xmlCtxSettings" />
</bean>
</beans>

@ -41,7 +41,7 @@
<menuitem label="${labels.AgendaWorkflow}" href="/settings/workflow" disabled="${not sec:isAllGranted('PERM_EDIT_WORKFLOW')}"/>
<menuitem label="Číselné řady" onClick="@command('numSeries')"/>
<menuitem label="Limity částek"/>
<menuitem label="E-maily" />
<menuitem label="${labels.GlobalSettings}" onClick="@command('globalSettings')"/>
</menubar>
</tabpanel>
<tabpanel>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@ -0,0 +1,108 @@
<?page title="EMail" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="editWin" border="normal" closable="true" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.settings.GlobalSettingsVM')" width="620px"
binder="@init(queueName='email')">
<caption src="/img/settings.png" zclass="form-caption" label="${labels.GlobalSettings}" />
<tabbox orient="vertical" height="400px">
<tabs width="100px">
<tab label="${labels.Requirements}"/>
<tab label="${labels.EMails}"/>
</tabs>
<tabpanels>
<tabpanel>
<div>
<checkbox label="${labels.EnableRequirements}" checked="@bind(vm.settings.enableRequirements)"/>
</div>
</tabpanel>
<tabpanel>
<tabbox>
<tabs>
<tab label="${labels.NewRequirement}"/>
<tab label="${labels.AuthRequirement}"/>
<tab label="${labels.ConfirmRequirement}"/>
</tabs>
<tabpanels>
<tabpanel>
<grid>
<columns>
<column hflex="min"/>
<column/>
</columns>
<rows>
<row>
<label value="${labels.MailSubject}"/> <textbox value="@bind(vm.settings.newReqTemplate.subject)" width="100%"/>
</row>
<row spans="2">
<vbox>
<ckeditor toolbar="Basic" value="@bind(vm.settings.newReqTemplate.text)" width="460px" height="180px"/>
<button label="${labels.InsertField}" popup="fieldsNew, position=after_start"/>
</vbox>
</row>
</rows>
</grid>
</tabpanel>
<tabpanel>
<grid>
<columns>
<column hflex="min"/>
<column/>
</columns>
<rows>
<row>
<label value="${labels.MailSubject}"/> <textbox value="@bind(vm.settings.authReqTemplate.subject)" width="100%"/>
</row>
<row spans="2">
<vbox>
<ckeditor toolbar="Basic" value="@bind(vm.settings.authReqTemplate.text)" width="460px" height="180px"/>
<button label="${labels.InsertField}" popup="fieldsAuth, position=after_start"/>
</vbox>
</row>
</rows>
</grid>
</tabpanel>
<tabpanel>
<grid>
<columns>
<column hflex="min"/>
<column/>
</columns>
<rows>
<row>
<label value="${labels.MailSubject}"/> <textbox value="@bind(vm.settings.confReqTemplate.subject)" width="100%"/>
</row>
<row spans="2">
<vbox>
<ckeditor toolbar="Basic" value="@bind(vm.settings.confReqTemplate.text)" width="460px" height="180px"/>
<button label="${labels.InsertField}" popup="fieldsConfirm, position=after_start"/>
</vbox>
</row>
</rows>
</grid>
</tabpanel>
</tabpanels>
</tabbox>
<menupopup id="fieldsNew" children="@load(vm.requirementFields)">
<template name="children">
<menuitem label="@load(each) @converter(vm.locConverter)" onClick="@command('insertField', field=each, message=vm.settings.newReqTemplate)"/>
</template>
</menupopup>
<menupopup id="fieldsAuth" children="@load(vm.requirementFields)">
<template name="children">
<menuitem label="@load(each) @converter(vm.locConverter)" onClick="@command('insertField', field=each, message=vm.settings.authReqTemplate)"/>
</template>
</menupopup>
<menupopup id="fieldsConfirm" children="@load(vm.requirementFields)">
<template name="children">
<menuitem label="@load(each) @converter(vm.locConverter)" onClick="@command('insertField', field=each, message=vm.settings.confReqTemplate)"/>
</template>
</menupopup>
</tabpanel>
</tabpanels>
</tabbox>
<include src="/app/formButtons.zul"/>
</window>
</zk>

@ -1,7 +1,8 @@
<?page title="NumberSeriesFormTitle" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="editWin" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.settings.NumberSeriesVM')" closable="true" width="400px">
viewModel="@id('vm') @init('info.bukova.isspst.ui.settings.NumberSeriesVM')" closable="true" width="400px"
binder="@init(queueName='numSeries')">
<caption zclass="form-caption" label="${labels.NumberSeriesFormTitle}" />
<!-- <combobox></combobox> -->
<grid model="@load(vm.numberSeriesList)">

Loading…
Cancel
Save