Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/SubmissionDetails.java
===================================================================
diff -u
--- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/SubmissionDetails.java (revision 0)
+++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/SubmissionDetails.java (revision abacef33c30b9343d8bd503d262256bf4761d887)
@@ -0,0 +1,162 @@
+package org.lamsfoundation.lams.tool.qa;
+
+import java.io.Serializable;
+import java.util.Date;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.log4j.Logger;
+
+public class SubmissionDetails implements Serializable{
+ /** identifier field */
+ private Long submissionID;
+
+ /** persistent field */
+ private String filePath;
+
+ /** persistent field */
+ private String fileDescription;
+
+ /** persistent field */
+ private Date dateOfSubmission;
+
+ /** persistent field */
+ private Long userID;
+
+ /** persistent field */
+ private Long uuid;
+
+ /** persistent field */
+ private Long versionID;
+
+ /** default constructor */
+ public SubmissionDetails() {
+ }
+
+ /** full constructor */
+ public SubmissionDetails(String filePath, String fileDescription, Date dateOfSubmission, Long userID, Long uuid, Long versionID) {
+ this.filePath = filePath;
+ this.fileDescription = fileDescription;
+ this.dateOfSubmission = dateOfSubmission;
+ this.userID = userID;
+ this.uuid = uuid;
+ this.versionID = versionID;
+ }
+
+ /**
+ * @hibernate.id generator-class="identity" type="java.lang.Long"
+ * column="submission_id"
+ */
+ public Long getSubmissionID() {
+ return this.submissionID;
+ }
+
+ public void setSubmissionID(Long submissionID) {
+ this.submissionID = submissionID;
+ }
+
+ /**
+ * @hibernate.property column="filePath" length="250"
+ */
+ public String getFilePath() {
+ return this.filePath;
+ }
+
+ public void setFilePath(String filePath) {
+ this.filePath = filePath;
+ }
+
+ /**
+ * @hibernate.property column="fileDescription" length="250"
+ */
+ public String getFileDescription() {
+ return this.fileDescription;
+ }
+
+ public void setFileDescription(String fileDescription) {
+ this.fileDescription = fileDescription;
+ }
+
+ /**
+ * @hibernate.property column="date_of_submission" length="19"
+ */
+ public Date getDateOfSubmission() {
+ return this.dateOfSubmission;
+ }
+
+ public void setDateOfSubmission(Date dateOfSubmission) {
+ this.dateOfSubmission = dateOfSubmission;
+ }
+
+ /**
+ * @hibernate.property column="uuid" length="20"
+ */
+ public Long getUuid() {
+ return this.uuid;
+ }
+
+ public void setUuid(Long uuid) {
+ this.uuid = uuid;
+ }
+
+ /**
+ * @hibernate.property column="version_id" length="20"
+ */
+ public Long getVersionID() {
+ return this.versionID;
+ }
+
+ public void setVersionID(Long versionID) {
+ this.versionID = versionID;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("submissionID",getSubmissionID()).append("filePath", getFilePath())
+ .append("fileDescription", getFileDescription())
+ .append("dateOfSubmission", getDateOfSubmission())
+ .append("uuid",getUuid())
+ .append("versionID", getVersionID())
+ .append("userID",getUserID())
+ .toString();
+ }
+
+ public boolean equals(Object other) {
+ if ((this == other))
+ return true;
+ if (!(other instanceof SubmissionDetails))
+ return false;
+ SubmissionDetails castOther = (SubmissionDetails) other;
+ return new EqualsBuilder().append(this.getSubmissionID(),
+ castOther.getSubmissionID()).append(this.getFilePath(),
+ castOther.getFilePath()).append(this.getFileDescription(),
+ castOther.getFileDescription()).append(
+ this.getDateOfSubmission(), castOther.getDateOfSubmission())
+ .append(this.getUuid(), castOther.getUuid())
+ .append(this.getVersionID(), castOther.getVersionID())
+ .append(this.getUserID(),castOther.getUserID())
+ .isEquals();
+ }
+
+ public int hashCode() {
+ return new HashCodeBuilder().append(getSubmissionID()).append(
+ getFilePath()).append(getFileDescription()).append(
+ getDateOfSubmission()).append(getUuid()).append(getVersionID())
+ .toHashCode();
+ }
+
+ /**
+ * @hibernate.property column="user_id" length="20"
+ * @return Returns the userID.
+ */
+ public Long getUserID() {
+ return userID;
+ }
+ /**
+ * @param userID
+ * The userID to set.
+ */
+ public void setUserID(Long userID) {
+ this.userID = userID;
+ }
+}
Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java
===================================================================
diff -u -rd231fdf18f3da49f3ca42f543c784f4d09a59332 -rabacef33c30b9343d8bd503d262256bf4761d887
--- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision d231fdf18f3da49f3ca42f543c784f4d09a59332)
+++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision abacef33c30b9343d8bd503d262256bf4761d887)
@@ -20,8 +20,11 @@
*/
package org.lamsfoundation.lams.tool.qa.service;
+import java.io.InputStream;
import java.util.List;
+import org.lamsfoundation.lams.contentrepository.ITicket;
+import org.lamsfoundation.lams.contentrepository.NodeKey;
import org.lamsfoundation.lams.tool.BasicToolVO;
import org.lamsfoundation.lams.tool.exception.DataMissingException;
import org.lamsfoundation.lams.tool.exception.ToolException;
@@ -42,6 +45,12 @@
*/
public interface IQaService
{
+ public static final String QA_LOGIN = "qaLogin";
+
+ public static final String QA_PASSWORD = "qaPassword";
+
+ public static final String QA_WORKSPACE = "qaWorkspace";
+
/**
* Return the qa object according to the requested content id.
* @param toolContentId the tool content id
@@ -195,6 +204,13 @@
public List getToolSessionsForContent(QaContent qa);
public QaQueContent getToolDefaultQuestionContent(long contentId);
+
+ public ITicket getRepositoryLoginTicket() throws QaApplicationException;
+
+ public void deleteFromRepository(Long uuid, Long versionID) throws QaApplicationException;
+
+ public NodeKey uploadFileToRepository(InputStream stream, String fileName, String mimeType) throws QaApplicationException;
+ public InputStream downloadFile(Long uuid, Long versionID)throws QaApplicationException;
}
Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java
===================================================================
diff -u -rd231fdf18f3da49f3ca42f543c784f4d09a59332 -rabacef33c30b9343d8bd503d262256bf4761d887
--- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision d231fdf18f3da49f3ca42f543c784f4d09a59332)
+++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision abacef33c30b9343d8bd503d262256bf4761d887)
@@ -19,12 +19,28 @@
*http://www.gnu.org/licenses/gpl.txt
*/
package org.lamsfoundation.lams.tool.qa.service;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
import org.apache.log4j.Logger;
+import org.lamsfoundation.lams.contentrepository.AccessDeniedException;
+import org.lamsfoundation.lams.contentrepository.FileException;
+import org.lamsfoundation.lams.contentrepository.ICredentials;
+import org.lamsfoundation.lams.contentrepository.ITicket;
+import org.lamsfoundation.lams.contentrepository.IVersionedNode;
+import org.lamsfoundation.lams.contentrepository.ItemNotFoundException;
+import org.lamsfoundation.lams.contentrepository.LoginException;
+import org.lamsfoundation.lams.contentrepository.NodeKey;
+import org.lamsfoundation.lams.contentrepository.WorkspaceNotFoundException;
+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.lesson.Lesson;
import org.lamsfoundation.lams.tool.BasicToolVO;
import org.lamsfoundation.lams.tool.ToolContentManager;
@@ -40,6 +56,7 @@
import org.lamsfoundation.lams.tool.qa.QaQueUsr;
import org.lamsfoundation.lams.tool.qa.QaSession;
import org.lamsfoundation.lams.tool.qa.QaUsrResp;
+import org.lamsfoundation.lams.tool.qa.SubmissionDetails;
import org.lamsfoundation.lams.tool.qa.dao.IQaContentDAO;
import org.lamsfoundation.lams.tool.qa.dao.IQaQueContentDAO;
import org.lamsfoundation.lams.tool.qa.dao.IQaQueUsrDAO;
@@ -51,6 +68,7 @@
import org.springframework.dao.DataAccessException;
+
/**
* The POJO implementation of Survey service. All business logics of survey tool
* are implemented in this class. It translate the request from presentation
@@ -74,6 +92,8 @@
IQaService, ToolContentManager, ToolSessionManager, QaAppConstants
{
+ static Logger logger = Logger.getLogger(QaServicePOJO.class.getName());
+
private IQaContentDAO qaDAO;
private IQaQueContentDAO qaQueContentDAO;
private IQaSessionDAO qaSessionDAO;
@@ -82,8 +102,10 @@
private IUserManagementService userManagementService;
private ILamsToolService toolService;
+
+ private IRepositoryService repositoryService;
- static Logger logger = Logger.getLogger(QaServicePOJO.class.getName());
+
public QaServicePOJO(){}
@@ -112,6 +134,39 @@
{
this.qaUsrRespDAO = qaUsrRespDAO;
}
+
+ /**
+ * @return Returns the qaDAO.
+ */
+ public IQaContentDAO getQaDAO() {
+ return qaDAO;
+ }
+ /**
+ * @return Returns the qaSessionDAO.
+ */
+ public IQaSessionDAO getQaSessionDAO() {
+ return qaSessionDAO;
+ }
+ /**
+ * @return Returns the qaUsrRespDAO.
+ */
+ public IQaUsrRespDAO getQaUsrRespDAO() {
+ return qaUsrRespDAO;
+ }
+
+ /**
+ * @return Returns the repositoryService.
+ */
+ public IRepositoryService getRepositoryService() {
+ return repositoryService;
+ }
+ /**
+ * @param repositoryService The repositoryService to set.
+ */
+ public void setRepositoryService(IRepositoryService repositoryService) {
+ this.repositoryService = repositoryService;
+ }
+
public void setUserManagementService(IUserManagementService userManagementService)
@@ -1238,29 +1293,195 @@
return listToolSessionIds;
}
- /**
- * @return Returns the qaDAO.
+
+
+ /**
+ * 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
*/
- public IQaContentDAO getQaDAO() {
- return qaDAO;
+ public ITicket getRepositoryLoginTicket() throws QaApplicationException {
+ repositoryService = RepositoryProxy.getLocalRepositoryService();
+ logger.debug("retrieved repositoryService : " + repositoryService);
+
+ ICredentials credentials = new SimpleCredentials(
+ IQaService.QA_LOGIN,
+ IQaService.QA_PASSWORD.toCharArray());
+ try {
+ ITicket ticket = repositoryService.login(credentials,
+ IQaService.QA_WORKSPACE);
+ logger.debug("retrieved ticket: " + ticket);
+ return ticket;
+ } catch (AccessDeniedException e) {
+ throw new QaApplicationException("Access Denied to repository."
+ + e.getMessage());
+ } catch (WorkspaceNotFoundException e) {
+ throw new QaApplicationException("Workspace not found."
+ + e.getMessage());
+ } catch (LoginException e) {
+ throw new QaApplicationException("Login failed." + e.getMessage());
+ }
}
+
+
/**
- * @return Returns the qaSessionDAO.
+ * This method deletes the content with the given uuid
and
+ * versionID
from the content repository
+ *
+ * @param uuid
+ * The uuid
of the node to be deleted
+ * @param versionID
+ * The version_id
of the node to be deleted.
+ * @throws SubmitFilesException
*/
- public IQaSessionDAO getQaSessionDAO() {
- return qaSessionDAO;
+ public void deleteFromRepository(Long uuid, Long versionID)
+ throws QaApplicationException {
+ ITicket ticket = getRepositoryLoginTicket();
+ logger.debug("retrieved ticket: " + ticket);
+ try {
+ String files[] = repositoryService.deleteVersion(ticket, uuid,versionID);
+ logger.debug("retrieved files: " + files);
+ } catch (Exception e) {
+ throw new QaApplicationException(
+ "Exception occured while deleting files from"
+ + " the repository " + e.getMessage());
+ }
}
+
+
/**
- * @return Returns the qaUsrRespDAO.
+ * This method is called everytime a new content has to be added to the
+ * repository. In order to do so first of all a valid ticket is obtained
+ * from the Repository hence authenticating the tool(SubmitFiles) and then
+ * the corresponding file is added to the repository.
+ *
+ * @param stream
+ * The InputStream
representing the data to be
+ * added
+ * @param fileName
+ * The name of the file being added
+ * @param mimeType
+ * The MIME type of the file (eg. TXT, DOC, GIF etc)
+ * @return NodeKey Represents the two part key - UUID and Version.
+ * @throws SubmitFilesException
*/
- public IQaUsrRespDAO getQaUsrRespDAO() {
- return qaUsrRespDAO;
+ public NodeKey uploadFileToRepository(InputStream stream, String fileName,
+ String mimeType) throws QaApplicationException {
+ ITicket ticket = getRepositoryLoginTicket();
+ try {
+ NodeKey nodeKey = repositoryService.addFileItem(ticket, stream,
+ fileName, mimeType, null);
+ logger.debug("retrieved nodeKey: " + nodeKey);
+ return nodeKey;
+ } catch (Exception e) {
+ throw new QaApplicationException("Exception occured while trying to"
+ + " upload file into the repository" + e.getMessage());
+ }
}
+ public InputStream downloadFile(Long uuid, Long versionID)throws QaApplicationException{
+ ITicket ticket = getRepositoryLoginTicket();
+ try{
+ IVersionedNode node = repositoryService.getFileItem(ticket,uuid,null);
+ logger.debug("retrieved node: " + node);
+ return node.getFile();
+ }catch(AccessDeniedException e){
+ throw new QaApplicationException("AccessDeniedException occured while trying to download file " + e.getMessage());
+ }catch(FileException e){
+ throw new QaApplicationException("FileException occured while trying to download file " + e.getMessage());
+ }catch(ItemNotFoundException e){
+ throw new QaApplicationException("ItemNotFoundException occured while trying to download file " + e.getMessage());
+ }
+ }
- public void buildLearnerReport()
- {
-
+ public void uploadFile(Long toolContentId, String filePath,
+ String fileDescription, Long userID) throws QaApplicationException{
+ try{
+ File file = new File(filePath);
+ logger.debug("retrieved file: " + file);
+ String fileName = file.getName();
+ logger.debug("retrieved fileName: " + fileName);
+ String mimeType = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
+ FileInputStream stream = new FileInputStream(file);
+ uploadFile(stream,toolContentId,filePath,fileDescription,fileName,mimeType,new Date(),userID);
+ logger.debug("end of uploadFile: " + fileName);
+ }catch(FileNotFoundException e){
+ throw new QaApplicationException("FileNotFoundException occured while trying to upload File" + e.getMessage());
+ }
}
+
+ /**
+ * This method is called when the user requests to upload a file. It's a
+ * three step process.
+ *
NodeKey
object which is a unique indentifier of the file
+ * in the repsoitorytl_lasbmt11_submission_details
tl_lasbmt11_report
InputStream
representing the data to be
+ * uploaded
+ * @param contentID
+ * The contentID
of the file being uploaded
+ * @param filePath
+ * The physical path of the file
+ * @param fileDescription
+ * The description of the file
+ * @param fileName
+ * The name of the file being added
+ * @param mimeType
+ * The MIME type of the file (eg. TXT, DOC, GIF etc)
+ * @param dateOfSubmission
+ * The date this file was uploaded by the user
+ * @param userID
+ * The User
who has uploaded the file.
+ * @throws SubmitFilesException
+ */
+ private void uploadFile(InputStream stream, Long toolContentId, String filePath,
+ String fileDescription, String fileName, String mimeType,
+ Date dateOfSubmission, Long userID) throws QaApplicationException {
+
+ QaContent qaContent = qaDAO.loadQaById(toolContentId.longValue());
+ logger.debug("retrieving qaContent: " + qaContent);
+
+ if (qaContent == null)
+ {
+ logger.debug("no content with toolContentId: " + toolContentId);
+ throw new QaApplicationException(
+ "No such content with a toolContentId of: " + toolContentId
+ + " found.");
+ }
+ else
+ {
+ NodeKey nodeKey = uploadFileToRepository(stream, fileName, mimeType);
+ SubmissionDetails details = new SubmissionDetails(filePath,fileDescription,dateOfSubmission,
+ nodeKey.getUuid(),nodeKey.getVersion(),
+ userID);
+ logger.debug("details: " + details);
+ //submissionDetailsDAO.insert(details);
+ }
+ }
+
+
+
+
+
}