001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/integration/api-impl/src/java/org/theospi/portfolio/admin/service/SakaiIntegrationServiceImpl.java $
003: * $Id: SakaiIntegrationServiceImpl.java 17650 2006-10-31 20:05:53Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.admin.service;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.sakaiproject.api.app.scheduler.SchedulerManager;
025: import org.sakaiproject.component.cover.ComponentManager;
026: import org.sakaiproject.content.api.ContentCollectionEdit;
027: import org.sakaiproject.content.api.ContentHostingService;
028: import org.sakaiproject.entity.api.ResourceProperties;
029: import org.sakaiproject.exception.IdUsedException;
030: import org.sakaiproject.tool.api.Session;
031: import org.sakaiproject.tool.cover.SessionManager;
032: import org.springframework.beans.factory.InitializingBean;
033: import org.theospi.portfolio.admin.intf.SakaiIntegrationPlugin;
034: import org.theospi.portfolio.admin.intf.SakaiIntegrationService;
035: import org.theospi.portfolio.admin.model.IntegrationOption;
036:
037: import java.util.ArrayList;
038: import java.util.Iterator;
039: import java.util.List;
040:
041: public class SakaiIntegrationServiceImpl implements
042: SakaiIntegrationService, InitializingBean {
043: protected final transient Log logger = LogFactory
044: .getLog(getClass());
045:
046: private List integrationPlugins;
047: private List dependantBeans;
048: private long pollingInterval;
049: private SchedulerManager schedulerManager;
050: private ContentHostingService contentHostingService;
051: private List initUsers = new ArrayList();
052:
053: protected void executePlugin(SakaiIntegrationPlugin plugin) {
054: for (Iterator i = plugin.getPotentialIntegrations().iterator(); i
055: .hasNext();) {
056: if (!plugin.executeOption((IntegrationOption) i.next())) {
057: break;
058: }
059: }
060: }
061:
062: public void afterPropertiesSet() throws Exception {
063: logger.info("afterPropertiesSet()");
064: // go through each integration plugin and execute it...
065: Session sakaiSession = SessionManager.getCurrentSession();
066: String userId = sakaiSession.getUserId();
067:
068: try {
069: sakaiSession.setUserId("admin");
070: sakaiSession.setUserEid("admin");
071: createUserResourceDir();
072: for (Iterator i = getIntegrationPlugins().iterator(); i
073: .hasNext();) {
074: String pluginId = (String) i.next();
075: SakaiIntegrationPlugin plugin = (SakaiIntegrationPlugin) ComponentManager
076: .get(pluginId);
077: executePlugin(plugin);
078: }
079: } catch (Exception e) {
080: logger
081: .warn(
082: "Temporarily catching all exceptions in osp.SakaiIntegrationServiceImpl.afterPropertiesSet()",
083: e);
084: } finally {
085: sakaiSession.setUserEid(userId);
086: sakaiSession.setUserId(userId);
087: }
088: }
089:
090: protected void createUserResourceDir() {
091: for (Iterator iter = getInitUsers().iterator(); iter.hasNext();) {
092: String userId = (String) iter.next();
093: try {
094: ContentCollectionEdit userCollection = getContentHostingService()
095: .addCollection("/user/" + userId + "/");
096: userCollection.getPropertiesEdit().addProperty(
097: ResourceProperties.PROP_DISPLAY_NAME, userId);
098: getContentHostingService().commitCollection(
099: userCollection);
100: } catch (IdUsedException e) {
101: // ignore... it is already there.
102: } catch (Exception e) {
103: throw new RuntimeException(e);
104: }
105: }
106: }
107:
108: public List getIntegrationPlugins() {
109: return integrationPlugins;
110: }
111:
112: public void setIntegrationPlugins(List integrationPlugins) {
113: this .integrationPlugins = integrationPlugins;
114: }
115:
116: public List getDependantBeans() {
117: return dependantBeans;
118: }
119:
120: public void setDependantBeans(List dependantBeans) {
121: this .dependantBeans = dependantBeans;
122: }
123:
124: public long getPollingInterval() {
125: return pollingInterval;
126: }
127:
128: public void setPollingInterval(long pollingInterval) {
129: this .pollingInterval = pollingInterval;
130: }
131:
132: public SchedulerManager getSchedulerManager() {
133: return schedulerManager;
134: }
135:
136: public void setSchedulerManager(SchedulerManager schedulerManager) {
137: this .schedulerManager = schedulerManager;
138: }
139:
140: public ContentHostingService getContentHostingService() {
141: return contentHostingService;
142: }
143:
144: public void setContentHostingService(
145: ContentHostingService contentHostingService) {
146: this .contentHostingService = contentHostingService;
147: }
148:
149: public List getInitUsers() {
150: return initUsers;
151: }
152:
153: public void setInitUsers(List initUsers) {
154: this.initUsers = initUsers;
155: }
156:
157: }
|