View Javadoc
1   package org.argeo.people.core;
2   
3   import java.util.EnumSet;
4   import java.util.List;
5   
6   import javax.jcr.RepositoryException;
7   import javax.jcr.Session;
8   import javax.jcr.security.Privilege;
9   
10  import org.argeo.connect.ConnectException;
11  import org.argeo.connect.core.AbstractMaintenanceService;
12  import org.argeo.jcr.JcrUtils;
13  import org.argeo.people.PeopleConstants;
14  import org.argeo.people.PeopleRole;
15  
16  /**
17   * Default implementation of the AppMaintenanceService for the People App
18   */
19  public class PeopleMaintenanceService extends AbstractMaintenanceService {
20  	@Override
21  	public List<String> getRequiredRoles() {
22  		return enumToDns(EnumSet.allOf(PeopleRole.class));
23  	}
24  
25  	@Override
26  	protected void addOfficeGroups() {
27  		addManagersToGroup(PeopleRole.editor.dn());
28  		addCoworkersToGroup(PeopleRole.reader.dn());
29  	}
30  
31  	@Override
32  	public boolean prepareJcrTree(Session session) {
33  		try {
34  			boolean hasChanged = false;
35  			JcrUtils.mkdirs(session, getDefaultBasePath());
36  			if (session.hasPendingChanges()) {
37  				session.save();
38  				hasChanged = true;
39  			}
40  			return hasChanged;
41  		} catch (RepositoryException e) {
42  			JcrUtils.discardQuietly(session);
43  			throw new ConnectException("Cannot create base nodes for Activities app", e);
44  		}
45  	}
46  
47  	@Override
48  	public void configurePrivileges(Session session) {
49  		try {
50  			JcrUtils.addPrivilege(session, getDefaultBasePath(), PeopleRole.editor.dn(), Privilege.JCR_ALL);
51  			JcrUtils.addPrivilege(session, getDefaultBasePath(), PeopleRole.reader.dn(), Privilege.JCR_READ);
52  			session.save();
53  		} catch (RepositoryException e) {
54  			JcrUtils.discardQuietly(session);
55  			throw new ConnectException("Cannot configure JCR privileges for Resources app", e);
56  		}
57  	}
58  
59  	public String getDefaultBasePath() {
60  		return "/" + PeopleConstants.PEOPLE_APP_BASE_NAME;
61  	}
62  
63  	// legacy. kept for the pattern
64  	// private String pathToRepository = System.getProperty("user.dir");
65  	//
66  	// private String getMonitoringLogFolderPath(){
67  	// return pathToRepository + "/log/monitoring";
68  	// }
69  
70  	// protected InputStream getStreamFromUrl(String url) throws IOException {
71  	// InputStream inputStream = null;
72  	// if (url.startsWith("classpath:")) {
73  	// url = url.substring("classpath:".length());
74  	// Resource resultbasepath = new ClassPathResource(url);
75  	// if (resultbasepath.exists())
76  	// inputStream = resultbasepath.getInputStream();
77  	// } else if (url.startsWith("file:")) {
78  	// url = url.substring("file:".length());
79  	// File file = new File(url);
80  	// // String tmpPath = file.getAbsolutePath();
81  	// if (file.exists())
82  	// inputStream = new FileInputStream(url);
83  	// }
84  	// return inputStream;
85  	// }
86  
87  	// public long publishAll(Session session, JcrMonitor monitor) {
88  	// Query query;
89  	// long nodeNb = 0;
90  	// try {
91  	// query = session.getWorkspace().getQueryManager().createQuery("SELECT *
92  	// FROM [" + NodeType.MIX_VERSIONABLE
93  	// + "] ORDER BY [" + Property.JCR_LAST_MODIFIED + "] DESC ",
94  	// Query.JCR_SQL2);
95  	// if (monitor != null && !monitor.isCanceled())
96  	// monitor.beginTask("Gathering versionnable items", -1);
97  	// NodeIterator nit = query.execute().getNodes();
98  	//
99  	// if (nit.hasNext() && monitor != null && !monitor.isCanceled()) {
100 	// nodeNb = nit.getSize();
101 	// int shortNb = (int) nodeNb / 100;
102 	// monitor.beginTask("Committing " + nodeNb + " nodes", shortNb);
103 	//
104 	// }
105 	// long i = 0;
106 	// VersionManager vm = session.getWorkspace().getVersionManager();
107 	// while (nit.hasNext()) {
108 	// String currPath = nit.nextNode().getPath();
109 	// vm.checkpoint(currPath);
110 	// if (i % 100 == 0 && monitor != null && !monitor.isCanceled())
111 	// monitor.worked(1);
112 	// i++;
113 	// }
114 	// return nodeNb;
115 	// } catch (RepositoryException e) {
116 	// throw new PeopleException("Unable to publish the workspace for " +
117 	// session, e);
118 	// }
119 	//
120 	// }
121 }