daily pastebin goal
26%
SHARE
TWEET

Folder Structure

Gigi95 Apr 21st, 2018 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.sun.org.apache.xalan.internal.xsltc.dom.SimpleResultTreeImpl;
  2. import org.apache.chemistry.opencmis.client.api.CmisObject;
  3. import org.apache.chemistry.opencmis.client.api.Folder;
  4. import org.apache.chemistry.opencmis.client.api.Session;
  5.  
  6.  
  7. import java.util.*;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.function.Consumer;
  12.  
  13.  
  14. public class FolderStructure {
  15.     private static String school;
  16.     private static String repositoryUrl;
  17.     private static Session CmisSession;
  18.     private static Folder schoolFolder;
  19.     private static String userName;
  20.     private static String passWord;
  21.  
  22.     public FolderStructure(String schoolName, String repoUrl, String[] credentials) {
  23.         this.school = schoolName;
  24.         this.repositoryUrl = repoUrl;
  25.         this.userName = credentials[0];
  26.         this.passWord = credentials[1];
  27.  
  28.     }
  29.  
  30.     public FolderStructure() {
  31.     }
  32.  
  33.     /**
  34.      * @param school
  35.      * @param facultyName
  36.      * @param departments
  37.      * @return
  38.      */
  39.     public static Folder createFacultyWithDepartments (String school, String facultyName, List<String> departments){
  40.  
  41.         String connectionName = repositoryUrl; //"http://192.168.1.104:8080/alfresco/cmisatom";
  42.         //String user = userName;
  43.         //String passwd = passWord; //"rockstar";
  44.         Folder schoolFolder;
  45.         Folder facultyFolder = null;
  46.  
  47.         Map<String, Folder> departmentsFolderMap = new HashMap<String, Folder>();
  48.  
  49.         CmisClient cmisClient = new CmisClient();
  50.         Session session = cmisClient.getSession(connectionName,
  51.                 userName, passWord);
  52.         Folder parentFolder = cmisClient.getParentFolder();
  53.  
  54.         if(parentFolder!=null){
  55.             schoolFolder = (Folder) cmisClient.getObject(
  56.                     session, parentFolder, school);
  57.             if (schoolFolder==null){
  58.                 System.out.println("School Folder does not exits, going to create it");
  59.                 if (session != null) {
  60.                     System.out.println("hurray");
  61.                     Folder folder = cmisClient.createFolder(session, school);
  62.                     if (folder != null) {
  63.                         System.out.println("School Folder Created with Name: \t" + folder.getName());
  64.                         schoolFolder = folder;
  65.                     } else {
  66.                         System.out.println("Awwwww");
  67.                     }
  68.  
  69.                 }
  70.             }
  71.  
  72.             if(schoolFolder!=null){
  73.                 facultyFolder = cmisClient.createFolderWithParentFolder(session,
  74.                         facultyName, parentFolder);
  75.                 if(facultyFolder!=null){
  76.                     System.out.println("Faculty Folder Created");
  77.                     for (String department: departments ) {
  78.                         Folder departmentFolder = cmisClient.createFolderWithParentFolder(session,
  79.                                 department, facultyFolder);
  80.                         departmentsFolderMap.put(department, departmentFolder);
  81.                     }
  82.                     if(facultyFolder!=null){
  83.                         return facultyFolder;
  84.                     }
  85.                 }
  86.             }
  87.         }
  88.         return facultyFolder;
  89.     }
  90.  
  91.     /**
  92.      * @param school
  93.      * @param facultyName
  94.      * @param departmentsWithCourses
  95.      * @return
  96.      */
  97.  
  98.     public static Folder createFacultyWithDepartmentsAndCourses (String school, String facultyName, Map<String, List<String>> departmentsWithCourses) {
  99.  
  100.         Set<String> setOfDepartments = departmentsWithCourses.keySet();
  101.         String[] arrayOfDepartments = new String[setOfDepartments.size()+1];
  102.         Session[] session = new Session[2];
  103.         String connectionName = repositoryUrl; //"http://192.168.1.104:8080/alfresco/cmisatom";
  104.  
  105.         setOfDepartments.toArray(arrayOfDepartments);
  106.         List<String> listOfDepartments = Arrays.asList(arrayOfDepartments);
  107.         Folder facultyWithDepartments = createFacultyWithDepartments(school,
  108.                 facultyName, listOfDepartments);
  109.         Set<Map.Entry<String, List<String>>> entriesOfDepartmentsAndCourses =
  110.                 departmentsWithCourses.entrySet();
  111.         if(facultyWithDepartments!=null){
  112.             System.out.println("Faculty Created");
  113.             System.out.println(" Going to create the Courses " +
  114.                     "for Each department");
  115.             CmisClient cmisClient = new CmisClient();
  116.             if(cmisClient==null) {
  117.                 cmisClient = new CmisClient();
  118.                 if(session[0]==null) {
  119.                     session[0] = cmisClient.getSession(connectionName,
  120.                             userName, passWord);
  121.                 }
  122.             }
  123.  
  124.             CmisClient finalCmisClient = cmisClient;
  125.             facultyWithDepartments.getChildren().forEach(new Consumer<CmisObject>() {
  126.                 public void accept(CmisObject cmisObject) {
  127.                     Folder[] deptFolder = new Folder[2];
  128.                     String departmentName = cmisObject.getName();
  129.                     if(cmisObject instanceof Folder){
  130.                         deptFolder[0] = (Folder)cmisObject;
  131.                         List<String> coursesForDepartment = departmentsWithCourses.get(departmentName);
  132.                         coursesForDepartment.forEach(new Consumer<String>() {
  133.                             @Override
  134.                             public void accept(String course) {
  135.                                 if(deptFolder[0]!=null && finalCmisClient !=null){
  136.                                     Folder courseFolder = finalCmisClient.createFolderWithParentFolder(session[0],
  137.                                             course, deptFolder[0]);
  138.                                     if(courseFolder!=null){
  139.                                         System.out.println("Course Folder with name: \t" +
  140.                                                 courseFolder.getName()+"\t Created");
  141.                                     }
  142.                                 }
  143.                             }
  144.                         });
  145.                     }
  146.  
  147.                 }
  148.             });
  149.         }
  150.  
  151.         return facultyWithDepartments;
  152.     }
  153.  
  154.  
  155.     public static Folder createFacultyWithCoursesAndLecturers (String school, String facultyName, Map<String, Map<String, List<String>>> departmentsWithCourses) {
  156.  
  157.         return null;
  158.     }
  159.  
  160.     public static Folder createDepartmentWithCourses (String school, String departmentName, Map<String, Map<String, List<String>>> courseswithlecturers) {
  161.  
  162.         return null;
  163.  
  164.     }
  165.  
  166.     public static Folder createDepartmentWithLecturers (String school, String departmentName, Map<String, Map<String, List<String>>> courseswithlecturers) {
  167.  
  168.         return null;
  169.  
  170.     }
  171.  
  172.     public static Folder createCourseswithLecturers (String school, String courseName, Map<String, Map<String, List<String>>> lecturers) {
  173.  
  174.         return null;
  175.  
  176.     }
  177. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top