parent
005c7fa7ef
commit
9905cc769d
@ -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();
|
||||
|
||||
}
|
@ -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 + ":");
|
||||
}
|
||||
|
||||
}
|
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>
|
Loading…
Reference in New Issue