Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sun.org.apache.xalan.internal.xsltc.dom.SimpleResultTreeImpl;
- import org.apache.chemistry.opencmis.client.api.CmisObject;
- import org.apache.chemistry.opencmis.client.api.Folder;
- import org.apache.chemistry.opencmis.client.api.Session;
- import java.util.*;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.function.Consumer;
- public class FolderStructure {
- private static String school;
- private static String repositoryUrl;
- private static Session CmisSession;
- private static Folder schoolFolder;
- private static String userName;
- private static String passWord;
- public FolderStructure(String schoolName, String repoUrl, String[] credentials) {
- this.school = schoolName;
- this.repositoryUrl = repoUrl;
- this.userName = credentials[0];
- this.passWord = credentials[1];
- }
- public FolderStructure() {
- }
- /**
- * @param school
- * @param facultyName
- * @param departments
- * @return
- */
- public static Folder createFacultyWithDepartments (String school, String facultyName, List<String> departments){
- String connectionName = repositoryUrl; //"http://192.168.1.104:8080/alfresco/cmisatom";
- //String user = userName;
- //String passwd = passWord; //"rockstar";
- Folder schoolFolder;
- Folder facultyFolder = null;
- Map<String, Folder> departmentsFolderMap = new HashMap<String, Folder>();
- CmisClient cmisClient = new CmisClient();
- Session session = cmisClient.getSession(connectionName,
- userName, passWord);
- Folder parentFolder = cmisClient.getParentFolder();
- if(parentFolder!=null){
- schoolFolder = (Folder) cmisClient.getObject(
- session, parentFolder, school);
- if (schoolFolder==null){
- System.out.println("School Folder does not exits, going to create it");
- if (session != null) {
- System.out.println("hurray");
- Folder folder = cmisClient.createFolder(session, school);
- if (folder != null) {
- System.out.println("School Folder Created with Name: \t" + folder.getName());
- schoolFolder = folder;
- } else {
- System.out.println("Awwwww");
- }
- }
- }
- if(schoolFolder!=null){
- facultyFolder = cmisClient.createFolderWithParentFolder(session,
- facultyName, parentFolder);
- if(facultyFolder!=null){
- System.out.println("Faculty Folder Created");
- for (String department: departments ) {
- Folder departmentFolder = cmisClient.createFolderWithParentFolder(session,
- department, facultyFolder);
- departmentsFolderMap.put(department, departmentFolder);
- }
- if(facultyFolder!=null){
- return facultyFolder;
- }
- }
- }
- }
- return facultyFolder;
- }
- /**
- * @param school
- * @param facultyName
- * @param departmentsWithCourses
- * @return
- */
- public static Folder createFacultyWithDepartmentsAndCourses (String school, String facultyName, Map<String, List<String>> departmentsWithCourses) {
- Set<String> setOfDepartments = departmentsWithCourses.keySet();
- String[] arrayOfDepartments = new String[setOfDepartments.size()+1];
- Session[] session = new Session[2];
- String connectionName = repositoryUrl; //"http://192.168.1.104:8080/alfresco/cmisatom";
- setOfDepartments.toArray(arrayOfDepartments);
- List<String> listOfDepartments = Arrays.asList(arrayOfDepartments);
- Folder facultyWithDepartments = createFacultyWithDepartments(school,
- facultyName, listOfDepartments);
- Set<Map.Entry<String, List<String>>> entriesOfDepartmentsAndCourses =
- departmentsWithCourses.entrySet();
- if(facultyWithDepartments!=null){
- System.out.println("Faculty Created");
- System.out.println(" Going to create the Courses " +
- "for Each department");
- CmisClient cmisClient = new CmisClient();
- if(cmisClient==null) {
- cmisClient = new CmisClient();
- if(session[0]==null) {
- session[0] = cmisClient.getSession(connectionName,
- userName, passWord);
- }
- }
- CmisClient finalCmisClient = cmisClient;
- facultyWithDepartments.getChildren().forEach(new Consumer<CmisObject>() {
- public void accept(CmisObject cmisObject) {
- Folder[] deptFolder = new Folder[2];
- String departmentName = cmisObject.getName();
- if(cmisObject instanceof Folder){
- deptFolder[0] = (Folder)cmisObject;
- List<String> coursesForDepartment = departmentsWithCourses.get(departmentName);
- coursesForDepartment.forEach(new Consumer<String>() {
- @Override
- public void accept(String course) {
- if(deptFolder[0]!=null && finalCmisClient !=null){
- Folder courseFolder = finalCmisClient.createFolderWithParentFolder(session[0],
- course, deptFolder[0]);
- if(courseFolder!=null){
- System.out.println("Course Folder with name: \t" +
- courseFolder.getName()+"\t Created");
- }
- }
- }
- });
- }
- }
- });
- }
- return facultyWithDepartments;
- }
- public static Folder createFacultyWithCoursesAndLecturers (String school, String facultyName, Map<String, Map<String, List<String>>> departmentsWithCourses) {
- return null;
- }
- public static Folder createDepartmentWithCourses (String school, String departmentName, Map<String, Map<String, List<String>>> courseswithlecturers) {
- return null;
- }
- public static Folder createDepartmentWithLecturers (String school, String departmentName, Map<String, Map<String, List<String>>> courseswithlecturers) {
- return null;
- }
- public static Folder createCourseswithLecturers (String school, String courseName, Map<String, Map<String, List<String>>> lecturers) {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement