1 package net.sourceforge.formview.usecases.service; 2 3 import java.util.ArrayList ; 4 import java.util.Collection ; 5 import java.util.HashMap ; 6 import java.util.Map ; 7 8 import net.sourceforge.formview.usecases.dto.DeveloperDTO; 9 import net.sourceforge.formview.usecases.dto.ManagerDTO; 10 import net.sourceforge.formview.usecases.dto.ProjectDTO; 11 12 public class ProjectService { 13 14 private static int projectIdIncrement = 0; 15 private static Map projectsDTOMap = new HashMap (); 16 private static Map managersDTOMap = new HashMap (); 17 18 static { 19 for (int i=0; i< 10; i++) { 21 projectIdIncrement++; 22 ManagerDTO manager = new ManagerDTO(String.valueOf(projectIdIncrement), "Manager name " + String.valueOf(projectIdIncrement)); 24 25 Collection developers = new ArrayList (); 27 for(int j=0; j< 5; j++) { 28 developers.add(new DeveloperDTO(String.valueOf(j), "Developer name " + String.valueOf(j))); 29 } 30 31 managersDTOMap.put(String.valueOf(projectIdIncrement), manager); 32 createProject(new ProjectDTO(String.valueOf(projectIdIncrement), 33 "Project name" + String.valueOf(projectIdIncrement), 34 "01/01/2006" , 35 manager, developers)); 36 } 37 38 } 39 40 41 public static ProjectDTO findProjectById(String projectId) { 42 return (ProjectDTO)projectsDTOMap.get(projectId); 43 } 44 45 public static Collection findAllProject() { 46 return projectsDTOMap.values(); 47 } 48 49 public static void createProject(ProjectDTO projectDTO) { 50 String projectId = String.valueOf(projectIdIncrement++); 51 projectDTO.setId(String.valueOf(projectId)); 52 projectsDTOMap.put(projectId, projectDTO); 53 } 54 55 public static ProjectDTO updateProject(ProjectDTO projectDTO) { 56 String projectId = projectDTO.getId(); 57 return (ProjectDTO)projectsDTOMap.put(projectId, projectDTO); 58 } 59 60 64 public static Collection findAllManager() { 65 return managersDTOMap.values(); 66 } 67 68 public static ManagerDTO findManagerById(String managerId) { 69 return (ManagerDTO)managersDTOMap.get(managerId); 70 } 71 72 73 } 74 75 | Popular Tags |