Společné báze pro práci s požadavky- rozpracovaná verze.

multitenant
Josef Rokos 11 years ago
parent eade2dd793
commit 1c8b294f36

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

@ -8,7 +8,7 @@ import java.util.Date;
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 AbstractOwnedService<Requirement> implements RequirementService, RequirementBaseService<Requirement>
{ {
@Override @Override
protected Requirement createEntity() protected Requirement createEntity()

@ -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,42 @@
package info.bukova.isspst.ui.requirement;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import info.bukova.isspst.data.RequirementBase;
import info.bukova.isspst.data.TripRequirement;
import info.bukova.isspst.services.requirement.RequirementBaseService;
import info.bukova.isspst.ui.ListViewModel;
public class RequirementSubpage<T extends RequirementBase> extends ListViewModel<T> {
private RequirementBaseService<T> reqService;
@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;
}
}

@ -56,4 +56,8 @@ public class TripRequirementListAll extends ListViewModel<TripRequirement> {
return allWorkgroups; return allWorkgroups;
} }
public boolean isCanApprove() {
return false;
}
} }

@ -1,13 +1,5 @@
package info.bukova.isspst.ui.requirement; package info.bukova.isspst.ui.requirement;
import java.util.ArrayList;
import java.util.List;
import org.springframework.security.access.AccessDeniedException;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.select.annotation.WireVariable;
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.filters.TripRequirementFilter; import info.bukova.isspst.filters.TripRequirementFilter;
@ -16,6 +8,16 @@ import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.services.workgroups.WorkgroupService;
import info.bukova.isspst.ui.ListViewModel; import info.bukova.isspst.ui.ListViewModel;
import java.util.ArrayList;
import java.util.List;
import org.springframework.security.access.AccessDeniedException;
import org.zkoss.bind.BindUtils;
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;
public class TripRequirementListCentre extends ListViewModel<TripRequirement> { public class TripRequirementListCentre extends ListViewModel<TripRequirement> {
@WireVariable @WireVariable
@ -50,4 +52,6 @@ public class TripRequirementListCentre extends ListViewModel<TripRequirement> {
return myCentres; return myCentres;
} }
} }

@ -56,4 +56,8 @@ public class TripRequirementListWorkgroup extends ListViewModel<TripRequirement>
return myWorkgroups; return myWorkgroups;
} }
public boolean isCanApprove() {
return false;
}
} }

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