Advertisement
Guest User

Untitled

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