Index: lams_tool_notebook/db/sql/tool_insert.sql =================================================================== diff -u -r5948e17402e1ad574aeddbe55f93dca2f58bbbec -r38b91d278128cd1c5e22eb93a1631d1494f7405e --- lams_tool_notebook/db/sql/tool_insert.sql (.../tool_insert.sql) (revision 5948e17402e1ad574aeddbe55f93dca2f58bbbec) +++ lams_tool_notebook/db/sql/tool_insert.sql (.../tool_insert.sql) (revision 38b91d278128cd1c5e22eb93a1631d1494f7405e) @@ -29,7 +29,7 @@ VALUES ( 'lantbk11', -'notebookToolService', +'notebookService', 'Notebook', 'Notebook', 'notebook', Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/model/Notebook.java =================================================================== diff -u -r5948e17402e1ad574aeddbe55f93dca2f58bbbec -r38b91d278128cd1c5e22eb93a1631d1494f7405e --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/model/Notebook.java (.../Notebook.java) (revision 5948e17402e1ad574aeddbe55f93dca2f58bbbec) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/model/Notebook.java (.../Notebook.java) (revision 38b91d278128cd1c5e22eb93a1631d1494f7405e) @@ -34,7 +34,7 @@ import org.lamsfoundation.lams.contentrepository.NodeKey; import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; -import org.lamsfoundation.lams.tool.notebook.service.NotebookToolService; +import org.lamsfoundation.lams.tool.notebook.service.NotebookService; /** * @hibernate.class table="tl_lantbk11_notebook" @@ -47,7 +47,7 @@ */ private static final long serialVersionUID = 579733009969321015L; - static Logger log = Logger.getLogger(NotebookToolService.class.getName()); + static Logger log = Logger.getLogger(NotebookService.class.getName()); // Fields /** Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/notebookApplicationContext.xml =================================================================== diff -u -r5948e17402e1ad574aeddbe55f93dca2f58bbbec -r38b91d278128cd1c5e22eb93a1631d1494f7405e --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/notebookApplicationContext.xml (.../notebookApplicationContext.xml) (revision 5948e17402e1ad574aeddbe55f93dca2f58bbbec) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/notebookApplicationContext.xml (.../notebookApplicationContext.xml) (revision 38b91d278128cd1c5e22eb93a1631d1494f7405e) @@ -25,10 +25,10 @@ - + - + @@ -38,6 +38,7 @@ + Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/INotebookService.java =================================================================== diff -u --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/INotebookService.java (revision 0) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/INotebookService.java (revision 38b91d278128cd1c5e22eb93a1631d1494f7405e) @@ -0,0 +1,138 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +/* $$Id$$ */ + +package org.lamsfoundation.lams.tool.notebook.service; + +import org.apache.struts.upload.FormFile; +import org.lamsfoundation.lams.tool.notebook.model.Notebook; +import org.lamsfoundation.lams.tool.notebook.model.NotebookAttachment; +import org.lamsfoundation.lams.tool.notebook.model.NotebookSession; +import org.lamsfoundation.lams.tool.notebook.model.NotebookUser; +import org.lamsfoundation.lams.tool.notebook.util.NotebookException; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; + +/** + * Defines the services available to the web layer from the Notebook Service + */ +public interface INotebookService { + /** + * Makes a copy of the default content and assigns it a newContentID + * + * @params newContentID + * @return + */ + public Notebook copyDefaultContent(Long newContentID); + + /** + * Returns an instance of the Notebook tools default content. + * + * @return + */ + public Notebook getDefaultContent(); + + /** + * @param toolSignature + * @return + */ + public Long getDefaultContentIdBySignature(String toolSignature); + + /** + * @param toolContentID + * @return + */ + public Notebook getNotebookByContentId(Long toolContentID); + + /** + * @param toolContentId + * @param file + * @param type + * @return + */ + public NotebookAttachment uploadFileToContent(Long toolContentId, + FormFile file, String type); + + /** + * @param uuid + * @param versionID + */ + public void deleteFromRepository(Long uuid, Long versionID) + throws NotebookException; + + /** + * @param contentID + * @param uuid + * @param versionID + * @param type + */ + public void deleteInstructionFile(Long contentID, Long uuid, + Long versionID, String type); + + /** + * @param notebook + */ + public void saveOrUpdateNotebook(Notebook notebook); + + /** + * @param toolSessionId + * @return + */ + public NotebookSession getSessionBySessionId(Long toolSessionId); + + /** + * @param notebookSession + */ + public void saveOrUpdateNotebookSession(NotebookSession notebookSession); + + /** + * + * @param userId + * @param toolSessionId + * @return + */ + public NotebookUser getUserByUserIdAndSessionId(Long userId, + Long toolSessionId); + + /** + * + * @param uid + * @return + */ + public NotebookUser getUserByUID(Long uid); + + /** + * + * @param notebookUser + */ + public void saveOrUpdateNotebookUser(NotebookUser notebookUser); + + /** + * + * @param user + * @param notebookSession + * @return + */ + public NotebookUser createNotebookUser(UserDTO user, + NotebookSession notebookSession); + +} \ No newline at end of file Fisheye: Tag 38b91d278128cd1c5e22eb93a1631d1494f7405e refers to a dead (removed) revision in file `lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/INotebookToolService.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookService.java =================================================================== diff -u --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookService.java (revision 0) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookService.java (revision 38b91d278128cd1c5e22eb93a1631d1494f7405e) @@ -0,0 +1,546 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +/* $$Id$$ */ + +package org.lamsfoundation.lams.tool.notebook.service; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.apache.struts.upload.FormFile; +import org.lamsfoundation.lams.contentrepository.AccessDeniedException; +import org.lamsfoundation.lams.contentrepository.ICredentials; +import org.lamsfoundation.lams.contentrepository.ITicket; +import org.lamsfoundation.lams.contentrepository.InvalidParameterException; +import org.lamsfoundation.lams.contentrepository.LoginException; +import org.lamsfoundation.lams.contentrepository.NodeKey; +import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; +import org.lamsfoundation.lams.contentrepository.WorkspaceNotFoundException; +import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; +import org.lamsfoundation.lams.contentrepository.service.IRepositoryService; +import org.lamsfoundation.lams.contentrepository.service.RepositoryProxy; +import org.lamsfoundation.lams.contentrepository.service.SimpleCredentials; +import org.lamsfoundation.lams.journal.service.IJournalService; +import org.lamsfoundation.lams.learning.service.ILearnerService; +import org.lamsfoundation.lams.learningdesign.service.ExportToolContentException; +import org.lamsfoundation.lams.learningdesign.service.IExportToolContentService; +import org.lamsfoundation.lams.learningdesign.service.ImportToolContentException; +import org.lamsfoundation.lams.tool.ToolContentManager; +import org.lamsfoundation.lams.tool.ToolSessionExportOutputData; +import org.lamsfoundation.lams.tool.ToolSessionManager; +import org.lamsfoundation.lams.tool.exception.DataMissingException; +import org.lamsfoundation.lams.tool.exception.SessionDataExistsException; +import org.lamsfoundation.lams.tool.exception.ToolException; +import org.lamsfoundation.lams.tool.notebook.dao.INotebookAttachmentDAO; +import org.lamsfoundation.lams.tool.notebook.dao.INotebookDAO; +import org.lamsfoundation.lams.tool.notebook.dao.INotebookSessionDAO; +import org.lamsfoundation.lams.tool.notebook.dao.INotebookUserDAO; +import org.lamsfoundation.lams.tool.notebook.model.Notebook; +import org.lamsfoundation.lams.tool.notebook.model.NotebookAttachment; +import org.lamsfoundation.lams.tool.notebook.model.NotebookSession; +import org.lamsfoundation.lams.tool.notebook.model.NotebookUser; +import org.lamsfoundation.lams.tool.notebook.util.NotebookConstants; +import org.lamsfoundation.lams.tool.notebook.util.NotebookException; +import org.lamsfoundation.lams.tool.notebook.util.NotebookToolContentHandler; +import org.lamsfoundation.lams.tool.service.ILamsToolService; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.util.audit.IAuditService; + +/** + * An implementation of the INotebookService interface. + * + * As a requirement, all LAMS tool's service bean must implement + * ToolContentManager and ToolSessionManager. + */ + +public class NotebookService implements ToolSessionManager, ToolContentManager, + INotebookService { + + static Logger logger = Logger.getLogger(NotebookService.class.getName()); + + private INotebookDAO notebookDAO = null; + + private INotebookSessionDAO notebookSessionDAO = null; + + private INotebookUserDAO notebookUserDAO = null; + + private INotebookAttachmentDAO notebookAttachmentDAO = null; + + private ILearnerService learnerService; + + private ILamsToolService toolService; + + private IToolContentHandler notebookToolContentHandler = null; + + private IRepositoryService repositoryService = null; + + private IAuditService auditService = null; + + private IExportToolContentService exportContentService; + + private IJournalService journalService; + + public NotebookService() { + super(); + // TODO Auto-generated constructor stub + } + + /* ************ Methods from ToolSessionManager ************* */ + public void createToolSession(Long toolSessionId, String toolSessionName, + Long toolContentId) throws ToolException { + if (logger.isDebugEnabled()) { + logger.debug("entering method createToolSession:" + + " toolSessionId = " + toolSessionId + + " toolSessionName = " + toolSessionName + + " toolContentId = " + toolContentId); + } + + NotebookSession session = new NotebookSession(); + session.setSessionId(toolSessionId); + session.setSessionName(toolSessionName); + // learner starts + // TODO need to also set other fields. + Notebook notebook = notebookDAO.getByContentId(toolContentId); + session.setNotebook(notebook); + notebookSessionDAO.saveOrUpdate(session); + } + + public String leaveToolSession(Long toolSessionId, Long learnerId) + throws DataMissingException, ToolException { + return learnerService.completeToolSession(toolSessionId, learnerId); + } + + public ToolSessionExportOutputData exportToolSession(Long toolSessionId) + throws DataMissingException, ToolException { + // TODO Auto-generated method stub + return null; + } + + public ToolSessionExportOutputData exportToolSession(List toolSessionIds) + throws DataMissingException, ToolException { + // TODO Auto-generated method stub + return null; + } + + public void removeToolSession(Long toolSessionId) + throws DataMissingException, ToolException { + notebookSessionDAO.deleteBySessionID(toolSessionId); + //TODO check if cascade worked + } + + /* ************ Methods from ToolContentManager ************************* */ + + public void copyToolContent(Long fromContentId, Long toContentId) + throws ToolException { + + if (logger.isDebugEnabled()) { + logger.debug("entering method copyToolContent:" + " fromContentId=" + + fromContentId + " toContentId=" + toContentId); + } + + if (fromContentId == null || toContentId == null) { + String error = "Failed to copy tool content: " + + " fromContentID or toContentID is null"; + throw new ToolException(error); + } + + Notebook fromContent = notebookDAO.getByContentId(fromContentId); + if (fromContent == null) { + // create the fromContent using the default tool content + fromContent = copyDefaultContent(fromContentId); + } + Notebook toContent = Notebook.newInstance(fromContent, toContentId, + notebookToolContentHandler); + notebookDAO.saveOrUpdate(toContent); + } + + public void setAsDefineLater(Long toolContentId) + throws DataMissingException, ToolException { + Notebook notebook = notebookDAO.getByContentId(toolContentId); + if(notebook == null){ + throw new ToolException("Could not find tool with toolContentID: " + toolContentId); + } + notebook.setDefineLater(true); + notebookDAO.saveOrUpdate(notebook); + } + + public void setAsRunOffline(Long toolContentId) + throws DataMissingException, ToolException { + Notebook notebook = notebookDAO.getByContentId(toolContentId); + if(notebook == null){ + throw new ToolException("Could not find tool with toolContentID: " + toolContentId); + } + notebook.setRunOffline(true); + notebookDAO.saveOrUpdate(notebook); + } + + public void removeToolContent(Long toolContentId, boolean removeSessionData) + throws SessionDataExistsException, ToolException { + // TODO Auto-generated method stub + } + + /** + * Export the XML fragment for the tool's content, along with any files + * needed for the content. + * + * @throws DataMissingException + * if no tool content matches the toolSessionId + * @throws ToolException + * if any other error occurs + */ + + public void exportToolContent(Long toolContentId, String rootPath) + throws DataMissingException, ToolException { + Notebook toolContentObj = notebookDAO.getByContentId(toolContentId); + if (toolContentObj == null) + throw new DataMissingException( + "Unable to find tool content by given id :" + toolContentId); + + // set ResourceToolContentHandler as null to avoid copy file node in + // repository again. + toolContentObj = Notebook.newInstance(toolContentObj, toolContentId, null); + toolContentObj.setToolContentHandler(null); + toolContentObj.setNotebookSessions(null); + Set atts = toolContentObj.getNotebookAttachments(); + for (NotebookAttachment att : atts) { + att.setNotebook(null); + } + try { + exportContentService + .registerFileClassForExport(NotebookAttachment.class.getName(), + "fileUuid", "fileVersionId"); + exportContentService.exportToolContent(toolContentId, + toolContentObj, notebookToolContentHandler, rootPath); + } catch (ExportToolContentException e) { + throw new ToolException(e); + } + } + + /** + * Import the XML fragment for the tool's content, along with any files + * needed for the content. + * + * @throws ToolException + * if any other error occurs + */ + public void importToolContent(Long toolContentId, Integer newUserUid, + String toolContentPath) throws ToolException { + try { + exportContentService.registerFileClassForImport( + NotebookAttachment.class.getName(), "fileUuid", + "fileVersionId", "fileName", "fileType", null, null); + + Object toolPOJO = exportContentService.importToolContent( + toolContentPath, notebookToolContentHandler); + if (!(toolPOJO instanceof Notebook)) + throw new ImportToolContentException( + "Import Notebook tool content failed. Deserialized object is " + + toolPOJO); + Notebook toolContentObj = (Notebook) toolPOJO; + + // reset it to new toolContentId + toolContentObj.setToolContentId(toolContentId); + toolContentObj.setCreateBy(new Long(newUserUid.longValue())); + + notebookDAO.saveOrUpdate(toolContentObj); + } catch (ImportToolContentException e) { + throw new ToolException(e); + } + } + + /* ********** INotebookService Methods ************************************** */ + public Long getDefaultContentIdBySignature(String toolSignature) { + Long toolContentId = null; + toolContentId = new Long(toolService + .getToolDefaultContentIdBySignature(toolSignature)); + if (toolContentId == null) { + String error = "Could not retrieve default content id for this tool"; + logger.error(error); + throw new NotebookException(error); + } + return toolContentId; + } + + public Notebook getDefaultContent() { + Long defaultContentID = getDefaultContentIdBySignature(NotebookConstants.TOOL_SIGNATURE); + Notebook defaultContent = getNotebookByContentId(defaultContentID); + if (defaultContent == null) { + String error = "Could not retrieve default content record for this tool"; + logger.error(error); + throw new NotebookException(error); + } + return defaultContent; + } + + public Notebook copyDefaultContent(Long newContentID) { + + if (newContentID == null) { + String error = "Cannot copy the Notebook tools default content: + " + + "newContentID is null"; + logger.error(error); + throw new NotebookException(error); + } + + Notebook defaultContent = getDefaultContent(); + // create new notebook using the newContentID + Notebook newContent = new Notebook(); + newContent = Notebook.newInstance(defaultContent, newContentID, + notebookToolContentHandler); + notebookDAO.saveOrUpdate(newContent); + return newContent; + } + + public Notebook getNotebookByContentId(Long toolContentID) { + Notebook notebook = (Notebook) notebookDAO.getByContentId(toolContentID); + if (notebook == null) { + logger.debug("Could not find the content with toolContentID:" + + toolContentID); + } + return notebook; + } + + public NotebookSession getSessionBySessionId(Long toolSessionId) { + NotebookSession notebookSession = notebookSessionDAO.getBySessionId(toolSessionId); + if (notebookSession == null) { + logger.debug("Could not find the notebook session with toolSessionID:" + + toolSessionId); + } + return notebookSession; + } + + public NotebookUser getUserByUserIdAndSessionId(Long userId, Long toolSessionId) { + return notebookUserDAO.getByUserIdAndSessionId(userId, toolSessionId); + } + + public NotebookUser getUserByLoginNameAndSessionId(String loginName, + Long toolSessionId) { + return notebookUserDAO.getByLoginNameAndSessionId(loginName, toolSessionId); + } + + public NotebookUser getUserByUID(Long uid) { + return notebookUserDAO.getByUID(uid); + } + + public NotebookAttachment uploadFileToContent(Long toolContentId, + FormFile file, String type) { + if (file == null || StringUtils.isEmpty(file.getFileName())) + throw new NotebookException("Could not find upload file: " + file); + + NodeKey nodeKey = processFile(file, type); + + NotebookAttachment attachment = new NotebookAttachment(); + attachment.setFileType(type); + attachment.setFileUuid(nodeKey.getUuid()); + attachment.setFileVersionId(nodeKey.getVersion()); + attachment.setFileName(file.getFileName()); + + return attachment; + } + + public void deleteFromRepository(Long uuid, Long versionID) + throws NotebookException { + ITicket ticket = getRepositoryLoginTicket(); + try { + repositoryService.deleteVersion(ticket, uuid, versionID); + } catch (Exception e) { + throw new NotebookException( + "Exception occured while deleting files from" + + " the repository " + e.getMessage()); + } + } + + public void deleteInstructionFile(Long contentID, Long uuid, + Long versionID, String type) { + notebookDAO.deleteInstructionFile(contentID, uuid, versionID, type); + + } + + public void saveOrUpdateNotebook(Notebook notebook) { + notebookDAO.saveOrUpdate(notebook); + } + + public void saveOrUpdateNotebookSession(NotebookSession notebookSession) { + notebookSessionDAO.saveOrUpdate(notebookSession); + } + + public void saveOrUpdateNotebookUser(NotebookUser notebookUser) { + notebookUserDAO.saveOrUpdate(notebookUser); + } + + public synchronized NotebookUser createNotebookUser(UserDTO user, + NotebookSession notebookSession) { + NotebookUser notebookUser = new NotebookUser(user, notebookSession); + saveOrUpdateNotebookUser(notebookUser); + return notebookUser; + } + + + public IAuditService getAuditService() { + return auditService; + } + + public void setAuditService(IAuditService auditService) { + this.auditService = auditService; + } + + + + private NodeKey processFile(FormFile file, String type) { + NodeKey node = null; + if (file != null && !StringUtils.isEmpty(file.getFileName())) { + String fileName = file.getFileName(); + try { + node = getNotebookToolContentHandler().uploadFile( + file.getInputStream(), fileName, file.getContentType(), + type); + } catch (InvalidParameterException e) { + throw new NotebookException( + "InvalidParameterException occured while trying to upload File" + + e.getMessage()); + } catch (FileNotFoundException e) { + throw new NotebookException( + "FileNotFoundException occured while trying to upload File" + + e.getMessage()); + } catch (RepositoryCheckedException e) { + throw new NotebookException( + "RepositoryCheckedException occured while trying to upload File" + + e.getMessage()); + } catch (IOException e) { + throw new NotebookException( + "IOException occured while trying to upload File" + + e.getMessage()); + } + } + return node; + } + + /** + * This method verifies the credentials of the SubmitFiles Tool and gives it + * the Ticket to login and access the Content Repository. + * + * A valid ticket is needed in order to access the content from the + * repository. This method would be called evertime the tool needs to + * upload/download files from the content repository. + * + * @return ITicket The ticket for repostory access + * @throws SubmitFilesException + */ + private ITicket getRepositoryLoginTicket() throws NotebookException { + repositoryService = RepositoryProxy.getRepositoryService(); + ICredentials credentials = new SimpleCredentials( + NotebookToolContentHandler.repositoryUser, + NotebookToolContentHandler.repositoryId); + try { + ITicket ticket = repositoryService.login(credentials, + NotebookToolContentHandler.repositoryWorkspaceName); + return ticket; + } catch (AccessDeniedException ae) { + throw new NotebookException("Access Denied to repository." + + ae.getMessage()); + } catch (WorkspaceNotFoundException we) { + throw new NotebookException("Workspace not found." + we.getMessage()); + } catch (LoginException e) { + throw new NotebookException("Login failed." + e.getMessage()); + } + } + + /* ********** Used by Spring to "inject" the linked objects ************* */ + + public INotebookAttachmentDAO getNotebookAttachmentDAO() { + return notebookAttachmentDAO; + } + + public void setNotebookAttachmentDAO(INotebookAttachmentDAO attachmentDAO) { + this.notebookAttachmentDAO = attachmentDAO; + } + + public INotebookDAO getNotebookDAO() { + return notebookDAO; + } + + public void setNotebookDAO(INotebookDAO notebookDAO) { + this.notebookDAO = notebookDAO; + } + + public IToolContentHandler getNotebookToolContentHandler() { + return notebookToolContentHandler; + } + + public void setNotebookToolContentHandler( + IToolContentHandler notebookToolContentHandler) { + this.notebookToolContentHandler = notebookToolContentHandler; + } + + public INotebookSessionDAO getNotebookSessionDAO() { + return notebookSessionDAO; + } + + public void setNotebookSessionDAO(INotebookSessionDAO sessionDAO) { + this.notebookSessionDAO = sessionDAO; + } + + public ILamsToolService getToolService() { + return toolService; + } + + public void setToolService(ILamsToolService toolService) { + this.toolService = toolService; + } + + public INotebookUserDAO getNotebookUserDAO() { + return notebookUserDAO; + } + + public void setNotebookUserDAO(INotebookUserDAO userDAO) { + this.notebookUserDAO = userDAO; + } + + public ILearnerService getLearnerService() { + return learnerService; + } + + public void setLearnerService(ILearnerService learnerService) { + this.learnerService = learnerService; + } + + public IExportToolContentService getExportContentService() { + return exportContentService; + } + + public void setExportContentService( + IExportToolContentService exportContentService) { + this.exportContentService = exportContentService; + } + + public IJournalService getJournalService() { + return journalService; + } + + public void setJournalService(IJournalService journalService) { + this.journalService = journalService; + } +} Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookServiceProxy.java =================================================================== diff -u --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookServiceProxy.java (revision 0) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookServiceProxy.java (revision 38b91d278128cd1c5e22eb93a1631d1494f7405e) @@ -0,0 +1,79 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +/* $$Id$$ */ + +package org.lamsfoundation.lams.tool.notebook.service; + +import javax.servlet.ServletContext; + +import org.lamsfoundation.lams.tool.ToolContentManager; +import org.lamsfoundation.lams.tool.ToolSessionManager; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + + +/** + *

This class act as the proxy between web layer and service layer. It is + * designed to decouple the presentation logic and business logic completely. + * In this way, the presentation tier will no longer be aware of the changes in + * service layer. Therefore we can feel free to switch the business logic + * implementation.

+ */ + +public class NotebookServiceProxy { + + public static final INotebookService getNotebookService(ServletContext servletContext) + { + return (INotebookService)getNotebookDomainService(servletContext); + } + + private static Object getNotebookDomainService(ServletContext servletContext) + { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); + return wac.getBean("notebookService"); + } + + /* + * Return the notebook tool version of tool session manager implementation. + * It will delegate to the Spring helper method to retrieve the proper + * bean from Spring bean factory. + * @param servletContext the servletContext for current application + * @return noticeboard service object.*/ + public static final ToolSessionManager getNotebookSessionManager(ServletContext servletContext) + { + return (ToolSessionManager)getNotebookDomainService(servletContext); + } + + + /* + * Return the notebook tool version of tool content manager implementation. + * It will delegate to the Spring helper method to retrieve the proper + * bean from Spring bean factory. + * @param servletContext the servletContext for current application + * @return noticeboard service object. */ + public static final ToolContentManager getNotebookContentManager(ServletContext servletContext) + { + return (ToolContentManager)getNotebookDomainService(servletContext); + } + +} Fisheye: Tag 38b91d278128cd1c5e22eb93a1631d1494f7405e refers to a dead (removed) revision in file `lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookToolService.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 38b91d278128cd1c5e22eb93a1631d1494f7405e refers to a dead (removed) revision in file `lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookToolServiceProxy.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/AuthoringAction.java =================================================================== diff -u -r5948e17402e1ad574aeddbe55f93dca2f58bbbec -r38b91d278128cd1c5e22eb93a1631d1494f7405e --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 5948e17402e1ad574aeddbe55f93dca2f58bbbec) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 38b91d278128cd1c5e22eb93a1631d1494f7405e) @@ -45,8 +45,8 @@ import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.notebook.model.Notebook; import org.lamsfoundation.lams.tool.notebook.model.NotebookAttachment; -import org.lamsfoundation.lams.tool.notebook.service.NotebookToolServiceProxy; -import org.lamsfoundation.lams.tool.notebook.service.INotebookToolService; +import org.lamsfoundation.lams.tool.notebook.service.NotebookServiceProxy; +import org.lamsfoundation.lams.tool.notebook.service.INotebookService; import org.lamsfoundation.lams.tool.notebook.util.NotebookConstants; import org.lamsfoundation.lams.tool.notebook.web.forms.AuthoringForm; import org.lamsfoundation.lams.util.WebUtil; @@ -69,7 +69,7 @@ private static Logger logger = Logger.getLogger(AuthoringAction.class); - public INotebookToolService notebookToolService; + public INotebookService notebookService; // Authoring SessionMap key names private static final String KEY_MODE = "mode"; @@ -97,18 +97,18 @@ Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); - // set up notebookToolService - if (notebookToolService == null) { - notebookToolService = NotebookToolServiceProxy.getNotebookToolService(this.getServlet() + // set up notebookService + if (notebookService == null) { + notebookService = NotebookServiceProxy.getNotebookService(this.getServlet() .getServletContext()); } // retrieving Notebook with given toolContentID - Notebook notebook = notebookToolService.getNotebookByContentId(toolContentID); + Notebook notebook = notebookService.getNotebookByContentId(toolContentID); if (notebook == null) { - notebook = notebookToolService.copyDefaultContent(toolContentID); + notebook = notebookService.copyDefaultContent(toolContentID); notebook.setCreateDate(new Date()); - notebookToolService.saveOrUpdateNotebook(notebook); + notebookService.saveOrUpdateNotebook(notebook); // TODO NOTE: this causes DB orphans when LD not saved. } @@ -123,7 +123,7 @@ // Set the defineLater flag so that learners cannot use content while we // are editing. This flag is released when updateContent is called. notebook.setDefineLater(true); - notebookToolService.saveOrUpdateNotebook(notebook); + notebookService.saveOrUpdateNotebook(notebook); // Set up sessionMap SessionMap map = new SessionMap(); @@ -152,7 +152,7 @@ SessionMap map = getSessionMap(request, authForm); // get notebook content. - Notebook notebook = notebookToolService.getNotebookByContentId(authForm.getToolContentID()); + Notebook notebook = notebookService.getNotebookByContentId(authForm.getToolContentID()); // update notebook content using form inputs. updateNotebook(notebook, authForm); @@ -165,7 +165,7 @@ for (NotebookAttachment att : getAttList(KEY_DELETED_FILES, map)) { // remove from repository and db - notebookToolService.deleteFromRepository(att.getFileUuid(), att + notebookService.deleteFromRepository(att.getFileUuid(), att .getFileVersionId()); attachments.remove(att); } @@ -183,7 +183,7 @@ // releasing defineLater flag so that learner can start using the tool. notebook.setDefineLater(false); - notebookToolService.saveOrUpdateNotebook(notebook); + notebookService.saveOrUpdateNotebook(notebook); request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); @@ -254,7 +254,7 @@ } // upload file to repository - NotebookAttachment newAtt = notebookToolService.uploadFileToContent(authForm + NotebookAttachment newAtt = notebookService.uploadFileToContent(authForm .getToolContentID(), file, type); // Add attachment to unsavedFiles @@ -328,7 +328,7 @@ if (att.getFileUuid().equals(authForm.getDeleteFileUuid())) { // delete from repository and list - notebookToolService.deleteFromRepository(att.getFileUuid(), att + notebookService.deleteFromRepository(att.getFileUuid(), att .getFileVersionId()); iter.remove(); break; Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/LearningAction.java =================================================================== diff -u -r5948e17402e1ad574aeddbe55f93dca2f58bbbec -r38b91d278128cd1c5e22eb93a1631d1494f7405e --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/LearningAction.java (.../LearningAction.java) (revision 5948e17402e1ad574aeddbe55f93dca2f58bbbec) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/LearningAction.java (.../LearningAction.java) (revision 38b91d278128cd1c5e22eb93a1631d1494f7405e) @@ -42,8 +42,8 @@ import org.lamsfoundation.lams.tool.notebook.model.Notebook; import org.lamsfoundation.lams.tool.notebook.model.NotebookSession; import org.lamsfoundation.lams.tool.notebook.model.NotebookUser; -import org.lamsfoundation.lams.tool.notebook.service.INotebookToolService; -import org.lamsfoundation.lams.tool.notebook.service.NotebookToolServiceProxy; +import org.lamsfoundation.lams.tool.notebook.service.INotebookService; +import org.lamsfoundation.lams.tool.notebook.service.NotebookServiceProxy; import org.lamsfoundation.lams.tool.notebook.util.NotebookException; import org.lamsfoundation.lams.tool.notebook.web.forms.LearningForm; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -67,7 +67,7 @@ private static final boolean MODE_OPTIONAL = false; - private INotebookToolService notebookToolService; + private INotebookService notebookService; public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) @@ -82,14 +82,14 @@ Long toolSessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); - // set up notebookToolService - if (notebookToolService == null) { - notebookToolService = NotebookToolServiceProxy.getNotebookToolService(this.getServlet() + // set up notebookService + if (notebookService == null) { + notebookService = NotebookServiceProxy.getNotebookService(this.getServlet() .getServletContext()); } // Retrieve the session and content. - NotebookSession notebookSession = notebookToolService + NotebookSession notebookSession = notebookService .getSessionBySessionId(toolSessionID); if (notebookSession == null) { throw new NotebookException( @@ -126,7 +126,7 @@ // Ensure that the content is use flag is set. if (!notebook.getContentInUse()) { notebook.setContentInUse(new Boolean(true)); - notebookToolService.saveOrUpdateNotebook(notebook); + notebookService.saveOrUpdateNotebook(notebook); } return mapping.findForward("notebook_client"); @@ -137,13 +137,13 @@ AttributeNames.USER); // attempt to retrieve user using userId and toolSessionId - NotebookUser notebookUser = notebookToolService.getUserByUserIdAndSessionId(new Long( + NotebookUser notebookUser = notebookService.getUserByUserIdAndSessionId(new Long( user.getUserID().intValue()), toolSessionId); if (notebookUser == null) { - NotebookSession notebookSession = notebookToolService + NotebookSession notebookSession = notebookService .getSessionBySessionId(toolSessionId); - notebookUser = notebookToolService.createNotebookUser(user, notebookSession); + notebookUser = notebookService.createNotebookUser(user, notebookSession); } return notebookUser; @@ -156,16 +156,16 @@ Long toolSessionID = WebUtil.readLongParam(request, "toolSessionID"); // set the finished flag - NotebookUser notebookUser = notebookToolService.getUserByUID(notebookUserUID); + NotebookUser notebookUser = notebookService.getUserByUID(notebookUserUID); if (notebookUser != null) { notebookUser.setFinishedActivity(true); - notebookToolService.saveOrUpdateNotebookUser(notebookUser); + notebookService.saveOrUpdateNotebookUser(notebookUser); } else { log.error("finishActivity(): couldn't find NotebookUser with uid: " + notebookUserUID); } - ToolSessionManager sessionMgrService = NotebookToolServiceProxy + ToolSessionManager sessionMgrService = NotebookServiceProxy .getNotebookSessionManager(getServlet().getServletContext()); // get back login user DTO Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/MonitoringAction.java =================================================================== diff -u -r5948e17402e1ad574aeddbe55f93dca2f58bbbec -r38b91d278128cd1c5e22eb93a1631d1494f7405e --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/MonitoringAction.java (.../MonitoringAction.java) (revision 5948e17402e1ad574aeddbe55f93dca2f58bbbec) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/MonitoringAction.java (.../MonitoringAction.java) (revision 38b91d278128cd1c5e22eb93a1631d1494f7405e) @@ -41,8 +41,8 @@ import org.lamsfoundation.lams.tool.notebook.model.Notebook; import org.lamsfoundation.lams.tool.notebook.model.NotebookSession; import org.lamsfoundation.lams.tool.notebook.model.NotebookUser; -import org.lamsfoundation.lams.tool.notebook.service.INotebookToolService; -import org.lamsfoundation.lams.tool.notebook.service.NotebookToolServiceProxy; +import org.lamsfoundation.lams.tool.notebook.service.INotebookService; +import org.lamsfoundation.lams.tool.notebook.service.NotebookServiceProxy; import org.lamsfoundation.lams.tool.notebook.util.NotebookConstants; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.action.LamsDispatchAction; @@ -66,7 +66,7 @@ private static Logger log = Logger.getLogger(MonitoringAction.class); - public INotebookToolService notebookToolService; + public INotebookService notebookService; public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { @@ -75,13 +75,13 @@ Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); - // set up notebookToolService - if (notebookToolService == null) { - notebookToolService = NotebookToolServiceProxy.getNotebookToolService(this.getServlet() + // set up notebookService + if (notebookService == null) { + notebookService = NotebookServiceProxy.getNotebookService(this.getServlet() .getServletContext()); } - Notebook notebook = notebookToolService.getNotebookByContentId(toolContentID); + Notebook notebook = notebookService.getNotebookByContentId(toolContentID); // TODO check for null NotebookDTO notebookDT0 = new NotebookDTO(notebook); Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/servlets/ExportServlet.java =================================================================== diff -u -r5948e17402e1ad574aeddbe55f93dca2f58bbbec -r38b91d278128cd1c5e22eb93a1631d1494f7405e --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/servlets/ExportServlet.java (.../ExportServlet.java) (revision 5948e17402e1ad574aeddbe55f93dca2f58bbbec) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/servlets/ExportServlet.java (.../ExportServlet.java) (revision 38b91d278128cd1c5e22eb93a1631d1494f7405e) @@ -41,8 +41,8 @@ import org.lamsfoundation.lams.tool.notebook.model.Notebook; import org.lamsfoundation.lams.tool.notebook.model.NotebookSession; import org.lamsfoundation.lams.tool.notebook.model.NotebookUser; -import org.lamsfoundation.lams.tool.notebook.service.NotebookToolServiceProxy; -import org.lamsfoundation.lams.tool.notebook.service.INotebookToolService; +import org.lamsfoundation.lams.tool.notebook.service.NotebookServiceProxy; +import org.lamsfoundation.lams.tool.notebook.service.INotebookService; import org.lamsfoundation.lams.tool.notebook.util.NotebookException; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.web.servlet.AbstractExportPortfolioServlet; @@ -57,14 +57,14 @@ private final String FILENAME = "notebook_main.html"; - private INotebookToolService notebookToolService; + private INotebookService notebookService; protected String doExport(HttpServletRequest request, HttpServletResponse response, String directoryName, Cookie[] cookies) { - if (notebookToolService == null) { - notebookToolService = NotebookToolServiceProxy - .getNotebookToolService(getServletContext()); + if (notebookService == null) { + notebookService = NotebookServiceProxy + .getNotebookService(getServletContext()); } try { @@ -103,15 +103,15 @@ throw new NotebookException(error); } - NotebookSession notebookSession = notebookToolService + NotebookSession notebookSession = notebookService .getSessionBySessionId(toolSessionID); // get all messages for current user and filter. UserDTO user = (UserDTO) SessionManager.getSession().getAttribute( AttributeNames.USER); // get the notebook user - NotebookUser notebookUser = notebookToolService.getUserByUserIdAndSessionId( + NotebookUser notebookUser = notebookService.getUserByUserIdAndSessionId( new Long(user.getUserID()), toolSessionID); NotebookDTO notebookDTO = new NotebookDTO(notebookSession.getNotebook()); @@ -132,7 +132,7 @@ throw new NotebookException(error); } - Notebook notebook = notebookToolService.getNotebookByContentId(toolContentID); + Notebook notebook = notebookService.getNotebookByContentId(toolContentID); NotebookDTO notebookDTO = new NotebookDTO(notebook);