Skip to content

Commit

Permalink
add designer process
Browse files Browse the repository at this point in the history
  • Loading branch information
SMacOne committed Dec 5, 2019
1 parent 0d3fc9d commit 1b9c40e
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 5 deletions.
72 changes: 72 additions & 0 deletions src/main/java/it/istat/is2/app/util/TreeNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright 2019 ISTAT
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by
* the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence. You may
* obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl5
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* Licence for the specific language governing permissions and limitations under
* the Licence.
*
* @author Francesco Amato <framato @ istat.it>
* @author Mauro Bruno <mbruno @ istat.it>
* @author Paolo Francescangeli <pafrance @ istat.it>
* @author Renzo Iannacone <iannacone @ istat.it>
* @author Stefano Macone <macone @ istat.it>
* @version 1.0
*/
package it.istat.is2.app.util;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class TreeNode<T> implements Iterable<TreeNode<T>> {

T data;
TreeNode<T> parent;
List<TreeNode<T>> children;

public TreeNode(T data) {
this.data = data;
this.children = new LinkedList<TreeNode<T>>();
}

public TreeNode<T> addChild(T child) {
TreeNode<T> childNode = new TreeNode<T>(child);
childNode.parent = this;
this.children.add(childNode);
return childNode;
}

@Override
public Iterator<TreeNode<T>> iterator() {
// TODO Auto-generated method stub
return null;
}

public T getData() {
return data;
}

public List<TreeNode<T>> getChildren() {
return children;
}

public void setChildren(List<TreeNode<T>> children) {
this.children = children;
}

public void setData(T data) {
this.data = data;
}

// other features ...

}
117 changes: 117 additions & 0 deletions src/main/java/it/istat/is2/design/controller/DesignController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* Copyright 2019 ISTAT
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by
* the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence. You may
* obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl5
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* Licence for the specific language governing permissions and limitations under
* the Licence.
*
* @author Francesco Amato <framato @ istat.it>
* @author Mauro Bruno <mbruno @ istat.it>
* @author Paolo Francescangeli <pafrance @ istat.it>
* @author Renzo Iannacone <iannacone @ istat.it>
* @author Stefano Macone <macone @ istat.it>
* @version 1.0
*/
package it.istat.is2.design.controller;


import java.util.ArrayList;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestMapping;
import it.istat.is2.app.service.NotificationService;
import it.istat.is2.app.util.TreeNode;
import it.istat.is2.workflow.dao.BusinessProcessDao;
import it.istat.is2.workflow.domain.BusinessFunction;
import it.istat.is2.workflow.domain.BusinessProcess;
import it.istat.is2.workflow.domain.ProcessStep;
import it.istat.is2.workflow.service.BusinessFunctionService;
import it.istat.is2.workflow.service.ProcessStepService;
import it.istat.is2.workflow.service.BusinessProcessService;



@Controller
public class DesignController {


@Autowired
private NotificationService notificationService;

@Autowired
private BusinessFunctionService businessFunctionService;
@Autowired
private BusinessProcessService businessProcessService;

@Autowired
private ProcessStepService processStepService;




@RequestMapping("/settings")
public String viewSettings(Model model) {
notificationService.removeAllMessages();
List<BusinessFunction> listaFunzioni = businessFunctionService.findBFunctions();
//List<BusinessProcess> listaBp = businessProcessService.findBProcessByIdFunction(new Long(1));
List<BusinessProcess> listaBp = businessProcessService.findAll();

List<ProcessStep> listaBs = processStepService.findAll();


List<BusinessProcess> listaAllBp = businessProcessService.findAllProcesses();
List<BusinessProcess> listaAllSubBp = businessProcessService.findAllSubProcesses();


List<TreeNode> albero = new ArrayList<TreeNode>();
BusinessProcessDao temp = null;


listaFunzioni.forEach((n) -> {albero.add(new TreeNode<String>(n.getName())); n.getBusinessProcesses().forEach((m) ->{ if(m.getBusinessProcessParent()==null){albero.get(albero.size()- 1).addChild(m.getName()); listaBp.forEach((s) ->
{if(s.getBusinessProcessParent()!=null && s.getBusinessProcessParent().getId()== m.getId()){TreeNode tempNode = ((TreeNode) albero.get(albero.size()- 1).getChildren().get(albero.get(albero.size()- 1).getChildren().size() - 1)).addChild(s.getName());
listaBs.forEach((p)->{p.getBusinessProcesses().forEach((k)->{if(k.getId().equals(s.getId())){tempNode.addChild(p.getDescr()); }; }); }); }; });}}); });


// listaFunzioni.forEach((n) -> {albero.add(new TreeNode<String>(n.getNome())); n.getBusinessProcesses().forEach((m) ->{ if(m.getSxBProcessParent()==null){albero.get(albero.size()- 1).addChild(m.getNome()); listaBp.forEach((s) ->
// {if(s.getSxBProcessParent()!=null && s.getSxBProcessParent().getId()== m.getId()){TreeNode tempNode = ((TreeNode) albero.get(albero.size()- 1).getChildren().get(albero.get(albero.size()- 1).getChildren().size() - 1)).addChild(s.getNome());
// listaBs.forEach((p)->{p.getBusinessProcesses().forEach((k)->{if(k.getId().equals(s.getId())){tempNode.addChild(p.getNome()); }; }); }); }; });}}); });
//

model.addAttribute("albero", albero);






model.addAttribute("listaBp", listaBp);
model.addAttribute("listaAllBp", listaAllBp);
model.addAttribute("listaAllSubBp", listaAllSubBp);
model.addAttribute("listaFunzioni", listaFunzioni);
model.addAttribute("listaBusinessStep", listaBs);



return "workflow/settings";

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package it.istat.is2.workflow.dao;
import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
Expand All @@ -32,6 +34,10 @@
@Repository
public interface BusinessProcessDao extends CrudRepository<BusinessProcess,Long> {

@Query("SELECT bp FROM BusinessProcess bp WHERE bp.businessProcessParent IS NULL ORDER BY bp.order ASC ")
List<BusinessProcess> findAllProcesses();
@Query("SELECT bp FROM BusinessProcess bp WHERE bp.businessProcessParent IS NOT NULL ORDER BY bp.order ASC")
List<BusinessProcess> findAllSubProcesses();
List<BusinessProcess> findAll();
@SuppressWarnings("rawtypes")
List<BusinessProcess> findByBusinessFunctions( @Param("idfunction")List businessFunctions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
import it.istat.is2.workflow.domain.ProcessStep;

@Repository
public interface BusinessStepDao extends CrudRepository<ProcessStep,Long> {
public interface ProcessStepDao extends CrudRepository<ProcessStep,Long> {

List<ProcessStep> findAll();
@SuppressWarnings("rawtypes")
List<ProcessStep> findByBusinessProcesses(@Param("idprocess")List businessProcess);

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.fasterxml.jackson.annotation.JsonManagedReference;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -52,6 +53,7 @@ public class BusinessProcess implements Serializable {
private String label;
@Column(name="ORDER")
private Short order;


@JsonBackReference
@ManyToMany(mappedBy = "businessProcesses")
Expand All @@ -70,6 +72,9 @@ public class BusinessProcess implements Serializable {
@OneToMany(mappedBy = "businessProcessParent")
private List<BusinessProcess> businessSubProcesses = new ArrayList<>();




public BusinessProcess() {
}

Expand All @@ -79,3 +84,6 @@ public BusinessProcess(Long idFunction) {
}

}



6 changes: 6 additions & 0 deletions src/main/java/it/istat/is2/workflow/domain/ProcessStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,11 @@ public ProcessStep(Long id) {
super();
this.id = id;
}







}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ public class StepInstance implements Serializable {
public StepInstance() {
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@ public List<BusinessProcess> findBProcessByIdFunction(Long idfunction) {
public BusinessProcess findBProcessById(long idprocess) {
return businessProcessDao.findById(idprocess).orElse(null);
}
public List<BusinessProcess> findAllProcesses() {
return businessProcessDao.findAllProcesses();
}

public List<BusinessProcess> findAllSubProcesses() {
return businessProcessDao.findAllSubProcesses();
}
public List<BusinessProcess> findAll() {
// TODO Auto-generated method stub
return businessProcessDao.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,29 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import it.istat.is2.workflow.dao.BusinessStepDao;
import it.istat.is2.workflow.dao.ProcessStepDao;
import it.istat.is2.workflow.domain.BusinessProcess;
import it.istat.is2.workflow.domain.ProcessStep;
import it.istat.is2.workflow.domain.StepInstance;

@Service
public class BusinessStepService {

@Autowired
BusinessStepDao businessStepDao;
ProcessStepDao processStepDao;

public List<ProcessStep> findBStepByIdProcess(Long idprocess) {
List<BusinessProcess> businessProcesses = new ArrayList<>();
businessProcesses.add(new BusinessProcess(idprocess));
return businessStepDao.findByBusinessProcesses(businessProcesses);
return processStepDao.findByBusinessProcesses(businessProcesses);
}

public Optional<ProcessStep> findBusinessStep(Long idbstep) {
return businessStepDao.findById(idbstep);
return processStepDao.findById(idbstep);
}

public List<StepInstance> findAll() {
// TODO Auto-generated method stub
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package it.istat.is2.workflow.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import it.istat.is2.workflow.dao.ProcessStepDao;

import it.istat.is2.workflow.domain.BusinessProcess;
import it.istat.is2.workflow.domain.ProcessStep;


@Service
public class ProcessStepService {


@Autowired
ProcessStepDao ProcessStepDao;

public List<ProcessStep> findBStepByIdProcess(Long idprocess) {
List<BusinessProcess> businessProcesses = new ArrayList<>();
businessProcesses.add(new BusinessProcess(idprocess));
return ProcessStepDao.findByBusinessProcesses(businessProcesses);
}
public List<ProcessStep> findAll() {
return ProcessStepDao.findAll();
}

public Optional<ProcessStep> findProcessStep(Long idbstep) {
return ProcessStepDao.findById(idbstep);
}

}

0 comments on commit 1b9c40e

Please sign in to comment.