parent
d2aa1cbd9a
commit
012ad06358
@ -0,0 +1,10 @@
|
||||
package info.bukova.isspst.dao;
|
||||
|
||||
import info.bukova.isspst.data.Season;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public interface SeasonDao extends BaseDao<Season> {
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package info.bukova.isspst.dao.jpa;
|
||||
|
||||
import info.bukova.isspst.dao.SeasonDao;
|
||||
import info.bukova.isspst.data.Season;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class SeasonDaoJPA extends BaseDaoJPA<Season> implements SeasonDao {
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "SEASON")
|
||||
public class Season extends BaseData {
|
||||
@Column(name = "DESCRIPTION")
|
||||
private String description;
|
||||
@Column(name = "VALID_FROM")
|
||||
private Date validFrom;
|
||||
@Column(name = "VALID_TO")
|
||||
private Date validTo;
|
||||
@Column(name = "ACTIVE")
|
||||
private boolean active;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Season)) return false;
|
||||
|
||||
Season season = (Season) o;
|
||||
|
||||
if (getId() != season.getId()) return false;
|
||||
if (active != season.active) return false;
|
||||
if (description != null ? !description.equals(season.description) : season.description != null) return false;
|
||||
if (validFrom != null ? !validFrom.equals(season.validFrom) : season.validFrom != null) return false;
|
||||
if (validTo != null ? !validTo.equals(season.validTo) : season.validTo != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = description != null ? description.hashCode() : 0;
|
||||
result = 31 * result + (validFrom != null ? validFrom.hashCode() : 0);
|
||||
result = 31 * result + (validTo != null ? validTo.hashCode() : 0);
|
||||
result = 31 * result + (active ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Date getValidFrom() {
|
||||
return validFrom;
|
||||
}
|
||||
|
||||
public void setValidFrom(Date validFrom) {
|
||||
this.validFrom = validFrom;
|
||||
}
|
||||
|
||||
public Date getValidTo() {
|
||||
return validTo;
|
||||
}
|
||||
|
||||
public void setValidTo(Date validTo) {
|
||||
this.validTo = validTo;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public interface SeasonsAware {
|
||||
public Season getSeason();
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package info.bukova.isspst.services;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class HqlDataFilter {
|
||||
private String where;
|
||||
private String orderBy;
|
||||
private Map<String, Object> params;
|
||||
private Class<?> dataClass;
|
||||
|
||||
public HqlDataFilter() {
|
||||
params = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
public HqlDataFilter(String where) {
|
||||
this();
|
||||
this.where = where;
|
||||
}
|
||||
|
||||
public HqlDataFilter(String where, String orderBy) {
|
||||
this(where);
|
||||
this.orderBy = orderBy;
|
||||
}
|
||||
|
||||
public String getWhere() {
|
||||
return where;
|
||||
}
|
||||
|
||||
public void setWhere(String where) {
|
||||
this.where = where;
|
||||
}
|
||||
|
||||
public String getOrderBy() {
|
||||
return orderBy;
|
||||
}
|
||||
|
||||
public void setOrderBy(String orderBy) {
|
||||
this.orderBy = orderBy;
|
||||
}
|
||||
|
||||
public void setParam(String key, Object value) {
|
||||
params.put(key, value);
|
||||
}
|
||||
|
||||
public Object getParam(String key) {
|
||||
return params.get(key);
|
||||
}
|
||||
|
||||
public Set<String> getParamKeys() {
|
||||
return params.keySet();
|
||||
}
|
||||
|
||||
public void andFilter(String filter) {
|
||||
if (where == null || where.isEmpty()) {
|
||||
where = filter;
|
||||
} else {
|
||||
where += " and (" + filter + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public void orFilter(String filter) {
|
||||
if (where == null ||where.isEmpty()) {
|
||||
where = filter;
|
||||
} else {
|
||||
where += " or (" + filter + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
where = "";
|
||||
orderBy = "";
|
||||
params.clear();
|
||||
}
|
||||
|
||||
public Class<?> getDataClass() {
|
||||
return dataClass;
|
||||
}
|
||||
|
||||
public void setDataClass(Class<?> dataClass) {
|
||||
this.dataClass = dataClass;
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package info.bukova.isspst.services;
|
||||
|
||||
import org.hibernate.Query;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class HqlUtils {
|
||||
|
||||
public static String buildHql(String select, HqlDataFilter filter) {
|
||||
if (select.toLowerCase().contains("where")
|
||||
|| select.toLowerCase().contains("order by")) {
|
||||
throw new IsspstException("Use add*() methods instead.");
|
||||
}
|
||||
|
||||
String hql = addWhere(select, filter, "");
|
||||
return addOrderBy(hql, filter);
|
||||
}
|
||||
|
||||
public static String addAndWhere(String hql, HqlDataFilter filter) {
|
||||
if (!checkWhere(filter)) {
|
||||
return hql;
|
||||
}
|
||||
|
||||
return addWhere(hql, filter, "and");
|
||||
}
|
||||
|
||||
public static String addOrWhere(String hql, HqlDataFilter filter) {
|
||||
if (!checkWhere(filter)) {
|
||||
return hql;
|
||||
}
|
||||
|
||||
return addWhere(hql, filter, "or");
|
||||
}
|
||||
|
||||
public static String addOrderBy(String hql, HqlDataFilter filter) {
|
||||
if (filter == null || filter.getOrderBy() == null || filter.getOrderBy().isEmpty()) {
|
||||
return hql;
|
||||
}
|
||||
|
||||
if (!hql.contains("order by")) {
|
||||
hql += " order by ";
|
||||
}
|
||||
|
||||
hql += filter.getOrderBy();
|
||||
return hql;
|
||||
}
|
||||
|
||||
public static void addParameters(Query query, HqlDataFilter filter) {
|
||||
if (filter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String key : filter.getParamKeys()) {
|
||||
if (filter.getParam(key) instanceof Collection<?>) {
|
||||
query.setParameterList(key, (Collection) filter.getParam(key));
|
||||
} else {
|
||||
query.setParameter(key, filter.getParam(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkWhere(HqlDataFilter filter) {
|
||||
return filter != null && filter.getWhere() != null && !filter.getWhere().isEmpty();
|
||||
}
|
||||
|
||||
private static String addWhere(String hql, HqlDataFilter filter, String operator) {
|
||||
if (hql.toLowerCase().contains("where") && hql.toLowerCase().contains("order by")) {
|
||||
String[] split = hql.split("order by");
|
||||
hql = split[0] + " " + operator + " (" + filter.getWhere() + ") order by " + split[1];
|
||||
return hql;
|
||||
}
|
||||
|
||||
if (hql.toLowerCase().contains("where")) {
|
||||
hql += " " + operator + " (" + filter.getWhere() + ")";
|
||||
return hql;
|
||||
}
|
||||
|
||||
if (hql.toLowerCase().contains("order by")) {
|
||||
String[] split = hql.split("order by");
|
||||
hql = split[0] + " where (" + filter.getWhere() + ") order by " + split[1];
|
||||
return hql;
|
||||
}
|
||||
|
||||
hql += " where (" + filter.getWhere() + ")";
|
||||
return hql;
|
||||
}
|
||||
}
|
@ -1,11 +1,18 @@
|
||||
package info.bukova.isspst.services.numberseries;
|
||||
|
||||
import info.bukova.isspst.data.NumberSeries;
|
||||
import info.bukova.isspst.data.Season;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface NumberSeriesService extends Service<NumberSeries>
|
||||
{
|
||||
public NumberSeries getNumberSerie(String module);
|
||||
|
||||
public NumberSeries getNumberSerieForSeason(String module, Season season);
|
||||
|
||||
public void increase(NumberSeries ns);
|
||||
|
||||
public List<NumberSeries> getSeriesForSeason(Season season);
|
||||
}
|
||||
|
@ -1,24 +1,48 @@
|
||||
package info.bukova.isspst.services.numberseries;
|
||||
|
||||
import info.bukova.isspst.data.NumberSeries;
|
||||
import info.bukova.isspst.data.Season;
|
||||
import info.bukova.isspst.services.AbstractService;
|
||||
|
||||
import info.bukova.isspst.services.settings.SeasonService;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NumberSeriesServiceImpl extends AbstractService<NumberSeries> implements NumberSeriesService
|
||||
{
|
||||
@Autowired
|
||||
private SeasonService seasonService;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public NumberSeries getNumberSerie(String module) {
|
||||
return getNumberSerieForSeason(module, seasonService.getActive());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public NumberSeries getNumberSerie(String module)
|
||||
{
|
||||
return this.selectSingle("from NumberSeries where MODULE = '" + module + "'");
|
||||
public NumberSeries getNumberSerieForSeason(String module, Season season) {
|
||||
Query q = dao.getQuery("from NumberSeries where module = :m and season = :s");
|
||||
q.setParameter("m", module);
|
||||
q.setParameter("s", season);
|
||||
return (NumberSeries) q.uniqueResult();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void increase(NumberSeries ns)
|
||||
{
|
||||
public void increase(NumberSeries ns) {
|
||||
ns.setNumber(ns.getNumber() + 1);
|
||||
this.update(ns);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public List<NumberSeries> getSeriesForSeason(Season season) {
|
||||
Query q = dao.getQuery("from NumberSeries where season = :s");
|
||||
q.setParameter("s", season);
|
||||
return q.list();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package info.bukova.isspst.services.settings;
|
||||
|
||||
import info.bukova.isspst.services.IsspstException;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class SeasonException extends IsspstException {
|
||||
|
||||
SeasonException() {
|
||||
super();
|
||||
}
|
||||
|
||||
SeasonException(String msg) {
|
||||
super(msg);
|
||||
setReason(msg);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package info.bukova.isspst.services.settings;
|
||||
|
||||
import info.bukova.isspst.data.Season;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public interface SeasonService extends Service<Season> {
|
||||
Season addSeason();
|
||||
Season getActive();
|
||||
List<Season> getAllSeasons();
|
||||
void setActive(Season season);
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package info.bukova.isspst.services.settings;
|
||||
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.NumberSeries;
|
||||
import info.bukova.isspst.data.Season;
|
||||
import info.bukova.isspst.services.AbstractOwnedService;
|
||||
import info.bukova.isspst.services.numberseries.NumberSeriesService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class SeasonServiceImpl extends AbstractOwnedService<Season> implements SeasonService {
|
||||
private Season activeSeason;
|
||||
@Autowired
|
||||
private NumberSeriesService numberSeriesService;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Season addSeason() {
|
||||
Season season = new Season();
|
||||
season.setDescription(StringUtils.localize("SeasonsNewSeason"));
|
||||
season.setValidFrom(new Date());
|
||||
season.setActive(true);
|
||||
|
||||
Season last = selectSingle("from Season where validTo Is Null");
|
||||
add(season);
|
||||
|
||||
last.setValidTo(new Date());
|
||||
last.setActive(false);
|
||||
update(last);
|
||||
|
||||
|
||||
activeSeason = null;
|
||||
|
||||
List<NumberSeries> numSeries = numberSeriesService.getSeriesForSeason(last);
|
||||
for (NumberSeries ns: numSeries) {
|
||||
String txt = ns.getPrefix().replaceAll("[0-9]+", "");
|
||||
String numTxt = ns.getPrefix().replaceAll("[a-zA-Z]+", "");
|
||||
|
||||
int num = 0;
|
||||
try {
|
||||
num = Integer.valueOf(numTxt);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String newPrefix = txt + String.valueOf(num + 1);
|
||||
|
||||
NumberSeries newNumSer = new NumberSeries();
|
||||
newNumSer.setPrefix(newPrefix);
|
||||
newNumSer.setModule(ns.getModule());
|
||||
newNumSer.setNumber(1);
|
||||
newNumSer.setSeason(season);
|
||||
numberSeriesService.add(newNumSer);
|
||||
}
|
||||
return season;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Season getActive() {
|
||||
if (activeSeason == null) {
|
||||
activeSeason = selectSingle("from Season where active = true");
|
||||
}
|
||||
|
||||
if (activeSeason == null) {
|
||||
throw new SeasonException("Active_season_not_set");
|
||||
}
|
||||
return activeSeason;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<Season> getAllSeasons() {
|
||||
return getAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void setActive(Season season) {
|
||||
for (Season s: getAll()) {
|
||||
s.setActive(false);
|
||||
update(s);
|
||||
}
|
||||
|
||||
Season s = dao.getById(season.getId());
|
||||
|
||||
if (s == null) {
|
||||
throw new SeasonException("Season_not_in_database");
|
||||
}
|
||||
|
||||
s.setActive(true);
|
||||
activeSeason = s;
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package info.bukova.isspst.ui.settings;
|
||||
|
||||
import info.bukova.isspst.Module;
|
||||
import info.bukova.isspst.ModuleUtils;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.NumberSeries;
|
||||
import info.bukova.isspst.data.Season;
|
||||
import info.bukova.isspst.services.numberseries.NumberSeriesService;
|
||||
import info.bukova.isspst.services.settings.SeasonService;
|
||||
import org.zkoss.bind.BindUtils;
|
||||
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.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class SeasonsVM {
|
||||
@WireVariable
|
||||
private SeasonService seasonService;
|
||||
@WireVariable
|
||||
private NumberSeriesService numericSeriesService;
|
||||
private List<Season> seasons;
|
||||
private List<NumberSeries> numSeries;
|
||||
private Map<String, Module> moduleMap;
|
||||
|
||||
@Init
|
||||
public void init() {
|
||||
seasons = seasonService.getAll();
|
||||
numSeries = numericSeriesService.getSeriesForSeason(seasonService.getActive());
|
||||
moduleMap = new HashMap<String, Module>();
|
||||
for (Module m : ModuleUtils.getActiveModules()) {
|
||||
moduleMap.put(m.getId(), m);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Module> getModuleMap() {
|
||||
return moduleMap;
|
||||
}
|
||||
|
||||
@Command
|
||||
//@NotifyChange({"seasons", "numSeries"})
|
||||
public void addSeason() {
|
||||
Messagebox.show(StringUtils.localize("SeasonsNewSeasonDialog"), StringUtils.localize("SeasonsNewSeason"), Messagebox.YES | Messagebox.NO, Messagebox.QUESTION,
|
||||
new EventListener<Event>() {
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (((Integer)event.getData()).intValue() == Messagebox.YES) {
|
||||
Season newSeason = seasonService.addSeason();
|
||||
seasons = seasonService.getAll();
|
||||
numSeries = numericSeriesService.getSeriesForSeason(seasonService.getActive());
|
||||
BindUtils.postNotifyChange(null, null, SeasonsVM.this, "seasons");
|
||||
BindUtils.postNotifyChange(null, null, SeasonsVM.this, "numSeries");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Command
|
||||
public void save(@BindingParam("window") Window win) {
|
||||
for(Season s: seasons) {
|
||||
seasonService.update(s);
|
||||
}
|
||||
|
||||
for(NumberSeries n: numSeries) {
|
||||
numericSeriesService.update(n);
|
||||
}
|
||||
|
||||
win.detach();
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({"numSeries", "seasons"})
|
||||
public void activate(@BindingParam("season") Season season) {
|
||||
seasonService.setActive(season);
|
||||
seasons = seasonService.getAll();
|
||||
numSeries = numericSeriesService.getSeriesForSeason(season);
|
||||
}
|
||||
|
||||
public List<Season> getSeasons() {
|
||||
return seasons;
|
||||
}
|
||||
|
||||
public List<NumberSeries> getNumSeries() {
|
||||
return numSeries;
|
||||
}
|
||||
|
||||
public boolean isCanSave() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?page title="${labels.TravelOrdersFormTitle}" contentType="text/html;charset=UTF-8"?>
|
||||
|
||||
<zk xmlns="http://www.zkoss.org/2005/zul"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
|
||||
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
|
||||
|
||||
<window id="editWin"
|
||||
border="normal"
|
||||
closable="true"
|
||||
apply="org.zkoss.bind.BindComposer"
|
||||
viewModel="@id('vm') @init('info.bukova.isspst.ui.settings.SeasonsVM')"
|
||||
width="750px"
|
||||
height="600px">
|
||||
<caption
|
||||
src="/img/global-setting-032.png"
|
||||
zclass="form-caption"
|
||||
label="${labels.SeasonsSeason}" />
|
||||
<vbox>
|
||||
<button label="${labels.SeasonsNewSeason}" onClick="@command('addSeason')" sclass="nicebutton"/>
|
||||
<listbox model="@load(vm.seasons)">
|
||||
<listhead>
|
||||
<listheader label="${labels.SeasonsDescription}"/>
|
||||
<listheader label="${labels.SeasonsValidFrom}"/>
|
||||
<listheader label="${labels.SeasonsValidTo}"/>
|
||||
<listheader label="${labels.SeasonsActive}"/>
|
||||
</listhead>
|
||||
<template name="model">
|
||||
<listitem>
|
||||
<listcell>
|
||||
<textbox value="@bind(each.description)" inplace="true"/>
|
||||
</listcell>
|
||||
<listcell label="@load(each.validFrom)"/>
|
||||
<listcell label="@load(each.validTo)"/>
|
||||
<listcell>
|
||||
<button label="${labels.SeasonsActivate}" onClick="@command('activate', season=each)" disabled="@load(each.active)" sclass="nicebutton"/>
|
||||
</listcell>
|
||||
</listitem>
|
||||
</template>
|
||||
</listbox>
|
||||
<label value="${labels.SeasonsActiveNumSeries}"/>
|
||||
<listbox model="@load(vm.numSeries)">
|
||||
<listhead>
|
||||
<listheader label="${labels.SeasonsAgenda}"/>
|
||||
<listheader label="${labels.SeasonsPrefix}"/>
|
||||
<listheader/>
|
||||
</listhead>
|
||||
<template name="model">
|
||||
<listitem>
|
||||
<listcell label="@load(vm.moduleMap[each.module].name)"/>
|
||||
<listcell>
|
||||
<textbox value="@bind(each.prefix)" inplace="true"/>
|
||||
</listcell>
|
||||
<listcell label="@load(each.number)"/>
|
||||
</listitem>
|
||||
</template>
|
||||
</listbox>
|
||||
<include src="/app/formButtons.zul" />
|
||||
</vbox>
|
||||
</window>
|
||||
|
||||
</zk>
|
Loading…
Reference in New Issue