diff --git a/src/main/java/info/bukova/isspst/data/RequirementBase.java b/src/main/java/info/bukova/isspst/data/RequirementBase.java index 2fcf679f..c8f918fa 100644 --- a/src/main/java/info/bukova/isspst/data/RequirementBase.java +++ b/src/main/java/info/bukova/isspst/data/RequirementBase.java @@ -21,9 +21,13 @@ import org.hibernate.annotations.LazyCollectionOption; @MappedSuperclass public class RequirementBase extends BaseData { - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "TYPE_ID") private RequirementType type; + @OneToMany(cascade = CascadeType.ALL) + @LazyCollection(LazyCollectionOption.TRUE) + @OrderBy("WORDER") + private List workflow; @Column(name = "NUMSER", unique = true) private String numser; @Column(name = "REQ_DATE") @@ -46,6 +50,7 @@ public class RequirementBase extends BaseData { public RequirementBase() { authorization = new ArrayList(); + workflow = new ArrayList(); } public RequirementType getType() { @@ -114,4 +119,12 @@ public class RequirementBase extends BaseData { this.centre = centre; } + public List getWorkflow() { + return workflow; + } + + public void setWorkflow(List workflow) { + this.workflow = workflow; + } + } diff --git a/src/main/java/info/bukova/isspst/data/RequirementType.java b/src/main/java/info/bukova/isspst/data/RequirementType.java index f2d1b9fd..3f35181b 100644 --- a/src/main/java/info/bukova/isspst/data/RequirementType.java +++ b/src/main/java/info/bukova/isspst/data/RequirementType.java @@ -21,7 +21,7 @@ public class RequirementType extends BaseData { private String type; @Column(name = "DESCRIPTION") private String description; - @OneToMany(cascade = CascadeType.ALL) + @OneToMany(cascade = CascadeType.ALL, orphanRemoval=true) @LazyCollection(LazyCollectionOption.FALSE) @OrderBy("WORDER") private List workflow; diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java index e6fe255b..80933537 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java @@ -8,6 +8,8 @@ import java.util.List; public interface RequirementBaseService { public void loadAuthItems(T data); + public void loadType(T data); + public void loadWorkflow(T data); public void approve(T entity); public boolean canApprove(T entity); public List getNextApprover(T entity); diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java index 0f63dc52..15aedb2c 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -19,6 +19,21 @@ import org.springframework.transaction.annotation.Transactional; public abstract class RequirementBaseServiceImpl extends AbstractOwnedService implements RequirementBaseService { + + protected void addWorkflow(T entity) { + if (entity.getType() == null) { + return; + } + + for (Workflow w : entity.getType().getWorkflow()) { + Workflow workflow = new Workflow(); + workflow.setCentre(w.getCentre()); + workflow.setLimit(w.getLimit()); + workflow.setOrder(w.getOrder()); + workflow.setRole(w.getRole()); + entity.getWorkflow().add(workflow); + } + } @Override @Transactional @@ -59,6 +74,23 @@ public abstract class RequirementBaseServiceImpl exte e.getAuthorization().size(); entity.setAuthorization(e.getAuthorization()); } + + + @Override + @Transactional + public void loadType(T data) { + T e = dao.getById(data.getId()); + e.getType().getType(); + data.setType(e.getType()); + } + + @Override + @Transactional + public void loadWorkflow(T data) { + T e = dao.getById(data.getId()); + e.getWorkflow().size(); + data.setWorkflow(e.getWorkflow()); + } @Override @Transactional @@ -103,16 +135,20 @@ public abstract class RequirementBaseServiceImpl exte private Workflow getNextWorkflow(T e) { AuthItem authItem = null; + if (e.getWorkflow() == null) { + return 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); + for (int i = 0; i < e.getWorkflow().size(); i++) { + wf = e.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); + if (i + 1 < e.getWorkflow().size()) { + wf = e.getWorkflow().get(i + 1); break; } else { return null; diff --git a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java index d506a5ca..9651933d 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java @@ -29,6 +29,7 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl extends ListViewModel @Override protected void loadLazyData(T data) { this.getReqService().loadAuthItems(data); + this.getReqService().loadWorkflow(data); + this.getReqService().loadType(data); } @Command diff --git a/src/main/webapp/requirements/approveStatus.zul b/src/main/webapp/requirements/approveStatus.zul index e18761ca..df1a13c7 100644 --- a/src/main/webapp/requirements/approveStatus.zul +++ b/src/main/webapp/requirements/approveStatus.zul @@ -3,7 +3,7 @@