@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 + ":");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user