Společné báze pro práci s požadavky- rozpracovaná verze.
parent
eade2dd793
commit
1c8b294f36
@ -1,5 +1,15 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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>
|
Loading…
Reference in New Issue