Conflicts:
	src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java
multitenant
František Přibyl 11 years ago
commit dd4b7a2166

@ -13,6 +13,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption; import org.hibernate.annotations.LazyCollectionOption;
@ -29,7 +30,7 @@ public class RequirementBase extends BaseData {
private Date reqDate; private Date reqDate;
@Column(name = "DESCRIPTION") @Column(name = "DESCRIPTION")
private String description; private String description;
@ManyToOne(fetch = FetchType.EAGER) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CENTRE_ID") @JoinColumn(name = "CENTRE_ID")
private Workgroup centre; private Workgroup centre;
@ManyToOne(fetch = FetchType.EAGER) @ManyToOne(fetch = FetchType.EAGER)
@ -37,6 +38,7 @@ public class RequirementBase extends BaseData {
private Workgroup workgroup; private Workgroup workgroup;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@LazyCollection(LazyCollectionOption.TRUE) @LazyCollection(LazyCollectionOption.TRUE)
@OrderBy("ID")
private List<AuthItem> authorization; private List<AuthItem> authorization;
@Column(name = "STATE") @Column(name = "STATE")
@Enumerated(EnumType.ORDINAL) @Enumerated(EnumType.ORDINAL)

@ -1,5 +1,15 @@
package info.bukova.isspst.services.requirement; package info.bukova.isspst.services.requirement;
public interface RequirementBaseService { import info.bukova.isspst.data.RequirementBase;
import info.bukova.isspst.data.User;
import java.util.List;
public interface RequirementBaseService<T extends RequirementBase> {
public void loadAuthItems(T data);
public void approve(T entity);
public boolean canApprove(T entity);
public List<User> getNextApprover(T entity);
} }

@ -0,0 +1,130 @@
package info.bukova.isspst.services.requirement;
import info.bukova.isspst.data.AuthItem;
import info.bukova.isspst.data.JobMapping;
import info.bukova.isspst.data.RequirementBase;
import info.bukova.isspst.data.RequirementState;
import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workflow;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.AbstractOwnedService;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
public abstract class RequirementBaseServiceImpl<T extends RequirementBase> extends
AbstractOwnedService<T> implements RequirementBaseService<T> {
@Override
@Transactional
public List<User> getNextApprover(T entity) {
T e = (T) dao.getById(entity.getId());
List<User> users = new ArrayList<User>();
Workgroup wg;
Workflow wf = getNextWorkflow(e);
Role nextRole;
if (wf == null) {
return null;
} else {
nextRole = wf.getRole();
}
if (wf.getCentre() || e.getWorkgroup() == null) {
wg = e.getCentre();
} else {
wg = e.getWorkgroup();
}
for (JobMapping jm : wg.getMembers()) {
if (jm.getRole().equals(nextRole) && jm.getMember().isPerson()) {
users.add((User) jm.getMember());
}
}
return users;
}
@Override
@Transactional
public void loadAuthItems(T entity) {
T e = dao.getById(entity.getId());
e.getAuthorization().size();
entity.setAuthorization(e.getAuthorization());
}
@Override
@Transactional
@PreAuthorize("this.canApprove(#entity)")
public void approve(T entity) {
T e = (T) dao.getById(entity.getId());
Workflow wf = getNextWorkflow(e);
if (wf == null) {
return;
}
Role role = wf.getRole();
AuthItem auth = new AuthItem();
auth.setApprover(getLoggedInUser());
auth.setRole(role);
auth.setAuthDate(new Date());
e.getAuthorization().add(auth);
if (getNextWorkflow(e) == null) {
e.setState(RequirementState.APPROVED);
} else {
e.setState(RequirementState.PARTIALLY);
}
entity.setState(e.getState());
entity.getAuthorization().add(auth);
this.update(e);
}
@Override
@Transactional
public boolean canApprove(T entity) {
List<User> nextApprovers = getNextApprover(entity);
if (nextApprovers != null && nextApprovers.contains(getLoggedInUser())) {
return true;
}
return false;
}
private Workflow getNextWorkflow(T e) {
AuthItem authItem = null;
if (e.getAuthorization().size() > 0) {
authItem = e.getAuthorization().get(e.getAuthorization().size() - 1);
}
Workflow wf = null;
for (int i = 0; i < e.getType().getWorkflow().size(); i++) {
wf = e.getType().getWorkflow().get(i);
if (authItem != null && wf.getRole().equals(authItem.getRole())) {
if (i + 1 < e.getType().getWorkflow().size()) {
wf = e.getType().getWorkflow().get(i + 1);
break;
} else {
return null;
}
}
if (authItem == null) {
break;
}
}
return wf;
}
}

@ -3,7 +3,6 @@ package info.bukova.isspst.services.requirement;
import info.bukova.isspst.Constants; import info.bukova.isspst.Constants;
import info.bukova.isspst.data.Requirement; import info.bukova.isspst.data.Requirement;
import info.bukova.isspst.data.RequirementState; import info.bukova.isspst.data.RequirementState;
import info.bukova.isspst.services.AbstractOwnedService;
import java.util.Date; import java.util.Date;
@ -11,14 +10,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
public class RequirementServiceImpl extends AbstractOwnedService<Requirement> implements RequirementService, RequirementBaseService public class RequirementServiceImpl extends
{ RequirementBaseServiceImpl<Requirement> implements RequirementService,
RequirementBaseService<Requirement> {
@Autowired @Autowired
private RequirementTypeService reqTypeService; private RequirementTypeService reqTypeService;
@Override @Override
protected Requirement createEntity() protected Requirement createEntity() {
{
Requirement entity = new Requirement(); Requirement entity = new Requirement();
entity.setReqDate(new Date()); entity.setReqDate(new Date());
@ -31,8 +31,7 @@ public class RequirementServiceImpl extends AbstractOwnedService<Requirement> im
@Override @Override
@Transactional @Transactional
@PreAuthorize("hasPermission(this, 'PERM_ADD')") @PreAuthorize("hasPermission(this, 'PERM_ADD')")
public void add(Requirement entity) public void add(Requirement entity) {
{
entity.setNumser(this.getNumberSerie()); entity.setNumser(this.getNumberSerie());
super.add(entity); super.add(entity);
} }

@ -3,6 +3,7 @@ package info.bukova.isspst.services.requirement;
import java.util.List; import java.util.List;
import info.bukova.isspst.data.TripRequirement; import info.bukova.isspst.data.TripRequirement;
import info.bukova.isspst.data.User;
import info.bukova.isspst.services.Service; import info.bukova.isspst.services.Service;
public interface TripRequirementService extends Service<TripRequirement> { public interface TripRequirementService extends Service<TripRequirement> {
@ -10,5 +11,9 @@ public interface TripRequirementService extends Service<TripRequirement> {
public List<TripRequirement> getCentreReq(); public List<TripRequirement> getCentreReq();
public List<TripRequirement> getWorkgroupReq(); public List<TripRequirement> getWorkgroupReq();
public List<TripRequirement> getFromAll(); public List<TripRequirement> getFromAll();
public void loadAuthItems(TripRequirement entity);
public List<User> getNextApprover(TripRequirement entity);
public boolean canApprove(TripRequirement entity);
public void approve(TripRequirement entity);
} }

@ -4,7 +4,6 @@ import info.bukova.isspst.Constants;
import info.bukova.isspst.data.RequirementState; import info.bukova.isspst.data.RequirementState;
import info.bukova.isspst.data.TripRequirement; import info.bukova.isspst.data.TripRequirement;
import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.AbstractOwnedService;
import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.services.workgroups.WorkgroupService;
import java.util.Date; import java.util.Date;
@ -16,8 +15,8 @@ import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
public class TripRequirementServiceImpl extends AbstractOwnedService<TripRequirement> public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripRequirement>
implements TripRequirementService, RequirementBaseService { implements TripRequirementService, RequirementBaseService<TripRequirement> {
@Autowired @Autowired
private RequirementTypeService reqTypeService; private RequirementTypeService reqTypeService;
@ -89,4 +88,5 @@ public class TripRequirementServiceImpl extends AbstractOwnedService<TripRequire
return super.getAll(); return super.getAll();
} }
} }

@ -56,9 +56,14 @@ public class ListViewModel<T extends DataModel> {
@NotifyChange({"dataBean","ableToDelete"}) @NotifyChange({"dataBean","ableToDelete"})
public void setDataBean(T data) { public void setDataBean(T data) {
loadLazyData(data);
this.dataBean = data; this.dataBean = data;
} }
protected void loadLazyData(T data) {
}
public void setDataFilter(Filter<T> dataFilter) { public void setDataFilter(Filter<T> dataFilter) {
this.dataFilter = dataFilter; this.dataFilter = dataFilter;
} }

@ -0,0 +1,45 @@
package info.bukova.isspst.ui.requirement;
import info.bukova.isspst.data.RequirementBase;
import info.bukova.isspst.services.requirement.RequirementBaseService;
import info.bukova.isspst.ui.ListViewModel;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
public class RequirementSubpage<T extends RequirementBase> extends ListViewModel<T> {
protected RequirementBaseService<T> reqService;
@SuppressWarnings("unchecked")
public void init() {
reqService = (RequirementBaseService<T>) service;
}
@Override
protected void loadLazyData(T data) {
reqService.loadAuthItems(data);
}
@Command
@NotifyChange("dataBean")
public void approve() {
reqService.approve(getDataBean());
}
@Override
@NotifyChange({ "dataBean", "ableToDelete", "canApprove" })
public void setDataBean(T data) {
super.setDataBean(data);
}
public boolean isCanApprove() {
if (getDataBean() != null) {
return reqService.canApprove(getDataBean());
}
return false;
}
}

@ -1,5 +1,11 @@
package info.bukova.isspst.ui.requirement; package info.bukova.isspst.ui.requirement;
import info.bukova.isspst.data.TripRequirement;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.filters.TripRequirementFilter;
import info.bukova.isspst.services.requirement.TripRequirementService;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -8,22 +14,12 @@ import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zk.ui.select.annotation.WireVariable;
import info.bukova.isspst.data.TripRequirement; public class TripRequirementListAll extends RequirementSubpage<TripRequirement> {
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.filters.TripRequirementFilter;
import info.bukova.isspst.services.requirement.TripRequirementService;
import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import info.bukova.isspst.ui.ListViewModel;
public class TripRequirementListAll extends ListViewModel<TripRequirement> {
@WireVariable @WireVariable
private TripRequirementService tripRequirementService; private TripRequirementService tripRequirementService;
@WireVariable @WireVariable
private WorkgroupService workgroupService; private WorkgroupService workgroupService;
@WireVariable
private UserService userService;
private List<Workgroup> allCentres; private List<Workgroup> allCentres;
private List<Workgroup> allWorkgroups; private List<Workgroup> allWorkgroups;
@ -36,6 +32,7 @@ public class TripRequirementListAll extends ListViewModel<TripRequirement> {
allCentres = workgroupService.getCentres(); allCentres = workgroupService.getCentres();
allWorkgroups = workgroupService.getWorkgroups(); allWorkgroups = workgroupService.getWorkgroups();
super.init();
} }
@Override @Override

@ -1,5 +1,12 @@
package info.bukova.isspst.ui.requirement; package info.bukova.isspst.ui.requirement;
import info.bukova.isspst.data.TripRequirement;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.filters.TripRequirementFilter;
import info.bukova.isspst.services.requirement.TripRequirementService;
import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -8,15 +15,7 @@ import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zk.ui.select.annotation.WireVariable;
import info.bukova.isspst.data.TripRequirement; public class TripRequirementListCentre extends RequirementSubpage<TripRequirement> {
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.filters.TripRequirementFilter;
import info.bukova.isspst.services.requirement.TripRequirementService;
import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import info.bukova.isspst.ui.ListViewModel;
public class TripRequirementListCentre extends ListViewModel<TripRequirement> {
@WireVariable @WireVariable
private TripRequirementService tripRequirementService; private TripRequirementService tripRequirementService;
@ -34,6 +33,7 @@ public class TripRequirementListCentre extends ListViewModel<TripRequirement> {
dataFilter = new TripRequirementFilter(getFilterTemplate()); dataFilter = new TripRequirementFilter(getFilterTemplate());
myCentres = workgroupService.getUserCentres(userService.getCurrent()); myCentres = workgroupService.getUserCentres(userService.getCurrent());
super.init();
} }
@Override @Override
@ -50,4 +50,6 @@ public class TripRequirementListCentre extends ListViewModel<TripRequirement> {
return myCentres; return myCentres;
} }
} }

@ -1,5 +1,12 @@
package info.bukova.isspst.ui.requirement; package info.bukova.isspst.ui.requirement;
import info.bukova.isspst.data.TripRequirement;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.filters.TripRequirementFilter;
import info.bukova.isspst.services.requirement.TripRequirementService;
import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -8,15 +15,7 @@ import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zk.ui.select.annotation.WireVariable;
import info.bukova.isspst.data.TripRequirement; public class TripRequirementListWorkgroup extends RequirementSubpage<TripRequirement> {
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.filters.TripRequirementFilter;
import info.bukova.isspst.services.requirement.TripRequirementService;
import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import info.bukova.isspst.ui.ListViewModel;
public class TripRequirementListWorkgroup extends ListViewModel<TripRequirement> {
@WireVariable @WireVariable
private TripRequirementService tripRequirementService; private TripRequirementService tripRequirementService;
@ -36,6 +35,7 @@ public class TripRequirementListWorkgroup extends ListViewModel<TripRequirement>
myCentres = workgroupService.getUserCentres(userService.getCurrent()); myCentres = workgroupService.getUserCentres(userService.getCurrent());
myWorkgroups = workgroupService.getUserWorkgroups(userService.getCurrent()); myWorkgroups = workgroupService.getUserWorkgroups(userService.getCurrent());
super.init();
} }
@Override @Override

@ -0,0 +1,25 @@
<?page title="approve status" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="Stav schválení: "/>
<button label="Schválit" onClick="@command('approve')" disabled="@load(not vmSub.canApprove)"/>
<vbox children="@load(vmSub.dataBean.type.workflow)">
<template name="children">
<grid model="@load(vmSub.dataBean.authorization)">
<columns>
<column label="@load(each.role.description)"/>
<column label="Datum"/>
</columns>
<rows>
<template name="model" var="auth">
<row visible="@load(auth.role eq each.role)">
<label value="@load(auth.approver.fullName)"/>
<label value="@load(auth.authDate)"/>
</row>
</template>
</rows>
</grid>
</template>
</vbox>
</zk>

@ -141,9 +141,11 @@
viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListCentre')"> viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListCentre')">
<include src="/requirements/toolbar.zul"/> <include src="/requirements/toolbar.zul"/>
<hbox width="100%">
<listbox <listbox
model="@load(vmSub.dataList)" model="@load(vmSub.dataList)"
selectedItem="@bind(vmSub.dataBean)"> selectedItem="@bind(vmSub.dataBean)"
hflex="7">
<listhead menupopup="auto"> <listhead menupopup="auto">
<listheader <listheader
label="${labels.RequirementsGridNumberSerie}" label="${labels.RequirementsGridNumberSerie}"
@ -266,7 +268,7 @@
</auxheader> </auxheader>
</auxhead> </auxhead>
<template name="model"> <template name="model">
<listitem> <listitem style="@load((each.state eq 'PARTIALLY') ? 'background-color: #fffb90' : ((each.state eq 'APPROVED') ? 'background-color: #afffb5' : ''))">
<listcell label="@load(each.numser)" /> <listcell label="@load(each.numser)" />
<listcell label="@load(each.reqDate) @converter('formatedDate', format=labels.DateFormat)" /> <listcell label="@load(each.reqDate) @converter('formatedDate', format=labels.DateFormat)" />
<listcell label="@load(each.centre.fullName)" /> <listcell label="@load(each.centre.fullName)" />
@ -276,14 +278,22 @@
</listitem> </listitem>
</template> </template>
</listbox> </listbox>
<div hflex="3">
<include src="/requirements/approveStatus.zul"/>
</div>
</hbox>
</tabpanel> </tabpanel>
<tabpanel apply="org.zkoss.bind.BindComposer" <tabpanel apply="org.zkoss.bind.BindComposer"
viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListWorkgroup')"> viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListWorkgroup')">
<include src="/requirements/toolbar.zul"/> <include src="/requirements/toolbar.zul"/>
<hbox width="100%">
<listbox <listbox
model="@load(vmSub.dataList)" model="@load(vmSub.dataList)"
selectedItem="@bind(vmSub.dataBean)"> selectedItem="@bind(vmSub.dataBean)"
hflex="7">
<listhead menupopup="auto"> <listhead menupopup="auto">
<listheader <listheader
label="${labels.RequirementsGridNumberSerie}" label="${labels.RequirementsGridNumberSerie}"
@ -438,14 +448,22 @@
</listitem> </listitem>
</template> </template>
</listbox> </listbox>
<div hflex="3">
<include src="/requirements/approveStatus.zul"/>
</div>
</hbox>
</tabpanel> </tabpanel>
<tabpanel apply="org.zkoss.bind.BindComposer" <tabpanel apply="org.zkoss.bind.BindComposer"
viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListAll')"> viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListAll')">
<include src="/requirements/toolbar.zul"/> <include src="/requirements/toolbar.zul"/>
<hbox width="100%">
<listbox <listbox
model="@load(vmSub.dataList)" model="@load(vmSub.dataList)"
selectedItem="@bind(vmSub.dataBean)"> selectedItem="@bind(vmSub.dataBean)"
hflex="7">
<listhead menupopup="auto"> <listhead menupopup="auto">
<listheader <listheader
label="${labels.RequirementsGridNumberSerie}" label="${labels.RequirementsGridNumberSerie}"
@ -600,6 +618,12 @@
</listitem> </listitem>
</template> </template>
</listbox> </listbox>
<div hflex="3">
<include src="/requirements/approveStatus.zul"/>
</div>
</hbox>
</tabpanel> </tabpanel>
</tabpanels> </tabpanels>
</tabbox> </tabbox>

Loading…
Cancel
Save