001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/migration/api-impl/src/java/org/theospi/portfolio/migration/UpdateFormPropsJob.java $
003: * $Id: UpdateFormPropsJob.java 10879 2006-06-19 19:41:40Z 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.migration;
021:
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.quartz.Job;
028: import org.quartz.JobExecutionContext;
029: import org.quartz.JobExecutionException;
030: import org.sakaiproject.content.api.ContentHostingService;
031: import org.sakaiproject.content.api.ContentResource;
032: import org.sakaiproject.exception.IdUnusedException;
033: import org.sakaiproject.exception.InUseException;
034: import org.sakaiproject.exception.PermissionException;
035: import org.sakaiproject.exception.ServerOverloadException;
036: import org.sakaiproject.exception.TypeException;
037: import org.sakaiproject.metaobj.shared.mgt.MetaobjEntityManager;
038: import org.sakaiproject.tool.cover.SessionManager;
039:
040: public class UpdateFormPropsJob implements Job {
041:
042: private ContentHostingService contentHosting;
043: protected final transient Log logger = LogFactory
044: .getLog(getClass());
045:
046: public void execute(JobExecutionContext arg0)
047: throws JobExecutionException {
048: logger.info("Quartz job started: " + this .getClass().getName());
049:
050: org.sakaiproject.tool.api.Session sakaiSession = SessionManager
051: .getCurrentSession();
052: String userId = sakaiSession.getUserId();
053: sakaiSession.setUserId("admin");
054: sakaiSession.setUserEid("admin");
055: List resources = getContentHosting().getAllResources("/");
056: logger.debug("Total Resources Found " + resources.size());
057:
058: int formCount = 0;
059: for (Iterator i = resources.iterator(); i.hasNext();) {
060: ContentResource resource = (ContentResource) i.next();
061: try {
062: if (resource.getContentType().equalsIgnoreCase(
063: "application/x-osp")) {
064:
065: getContentHosting()
066: .addProperty(
067: resource.getId(),
068: ContentHostingService.PROP_ALTERNATE_REFERENCE,
069: MetaobjEntityManager.METAOBJ_ENTITY_PREFIX);
070: formCount += 1;
071: }
072: } catch (PermissionException e) {
073: logger.warn(
074: "Failed to update properties for resource: "
075: + resource.getId(), e);
076: } catch (IdUnusedException e) {
077: logger.warn(
078: "Failed to update properties for resource: "
079: + resource.getId(), e);
080: } catch (TypeException e) {
081: logger.warn(
082: "Failed to update properties for resource: "
083: + resource.getId(), e);
084: } catch (InUseException e) {
085: logger.warn(
086: "Failed to update properties for resource: "
087: + resource.getId(), e);
088: } catch (ServerOverloadException e) {
089: logger.warn(
090: "Failed to update properties for resource: "
091: + resource.getId(), e);
092: }
093: }
094: logger.debug("Forms found " + formCount);
095: sakaiSession.setUserEid(userId);
096: sakaiSession.setUserId(userId);
097: logger
098: .info("Quartz job finished: "
099: + this .getClass().getName());
100: }
101:
102: public ContentHostingService getContentHosting() {
103: return contentHosting;
104: }
105:
106: public void setContentHosting(ContentHostingService contentHosting) {
107: this.contentHosting = contentHosting;
108: }
109:
110: }
|