Index: lams_tool_wookie/db/sql/create_lams_tool_wookie.sql =================================================================== diff -u -re81fdf5aa1e9c04fd0b7a624d8b8419b13cac81a -r08622dbb2e6672584f1cfcb52a239a46b3d667b1 --- lams_tool_wookie/db/sql/create_lams_tool_wookie.sql (.../create_lams_tool_wookie.sql) (revision e81fdf5aa1e9c04fd0b7a624d8b8419b13cac81a) +++ lams_tool_wookie/db/sql/create_lams_tool_wookie.sql (.../create_lams_tool_wookie.sql) (revision 08622dbb2e6672584f1cfcb52a239a46b3d667b1) @@ -49,6 +49,11 @@ session_id bigint, session_name varchar(250), wookie_uid bigint, + widget_shared_data_key varchar(63), + widget_height integer, + widget_width integer, + widget_maximise bit, + widget_identifier varchar(511), primary key (uid) )TYPE=InnoDB; @@ -61,6 +66,7 @@ finishedActivity bit, wookie_session_uid bigint, entry_uid bigint, + user_widget_url varchar(511), primary key (uid) )TYPE=InnoDB; Index: lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/model/Wookie.java =================================================================== diff -u -re81fdf5aa1e9c04fd0b7a624d8b8419b13cac81a -r08622dbb2e6672584f1cfcb52a239a46b3d667b1 --- lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/model/Wookie.java (.../Wookie.java) (revision e81fdf5aa1e9c04fd0b7a624d8b8419b13cac81a) +++ lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/model/Wookie.java (.../Wookie.java) (revision 08622dbb2e6672584f1cfcb52a239a46b3d667b1) @@ -56,7 +56,7 @@ private Date updateDate; - private Long createBy; + private Integer createBy; private String title; @@ -101,7 +101,7 @@ } /** full constructor */ - public Wookie(Date createDate, Date updateDate, Long createBy, String title, String instructions, + public Wookie(Date createDate, Date updateDate, Integer createBy, String title, String instructions, boolean runOffline, boolean lockOnFinished, boolean filteringEnabled, String filterKeywords, String onlineInstructions, String offlineInstructions, boolean contentInUse, boolean defineLater, Long toolContentId, String reflectInstructions, Set wookieAttachments, @@ -168,11 +168,11 @@ * */ - public Long getCreateBy() { + public Integer getCreateBy() { return createBy; } - public void setCreateBy(Long createBy) { + public void setCreateBy(Integer createBy) { this.createBy = createBy; } Index: lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/model/WookieSession.java =================================================================== diff -u -r7c52d117dbe910bd67630b5506346429e25b99a9 -r08622dbb2e6672584f1cfcb52a239a46b3d667b1 --- lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/model/WookieSession.java (.../WookieSession.java) (revision 7c52d117dbe910bd67630b5506346429e25b99a9) +++ lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/model/WookieSession.java (.../WookieSession.java) (revision 08622dbb2e6672584f1cfcb52a239a46b3d667b1) @@ -39,211 +39,273 @@ public class WookieSession implements java.io.Serializable { - private static Logger log = Logger.getLogger(WookieSession.class); - /** + private static Logger log = Logger.getLogger(WookieSession.class); + /** * */ - private static final long serialVersionUID = 4407078136514639026L; + private static final long serialVersionUID = 4407078136514639026L; - // Fields - private Long uid; + // Fields + private Long uid; - private Date sessionEndDate; + private Date sessionEndDate; - private Date sessionStartDate; + private Date sessionStartDate; - private Integer status; + private Integer status; - private Long sessionId; + private Long sessionId; - private String sessionName; + private String sessionName; - private Wookie wookie; + private Wookie wookie; - private Set wookieUsers; + private Set wookieUsers; + + private Long createBy; - // Constructors + // Wookie properties + String widgetSharedDataKey; + Integer widgetHeight; + Integer widgetWidth; + Boolean widgetMaximise; + String widgetIdentifier; - /** default constructor */ - public WookieSession() { - } + // Constructors - /** full constructor */ - public WookieSession(Date sessionEndDate, Date sessionStartDate, - Integer status, Long sessionId, String sessionName, Wookie wookie, - Set wookieUsers) { - this.sessionEndDate = sessionEndDate; - this.sessionStartDate = sessionStartDate; - this.status = status; - this.sessionId = sessionId; - this.sessionName = sessionName; - this.wookie = wookie; - this.wookieUsers = wookieUsers; - } + /** default constructor */ + public WookieSession() { + } - // Property accessors - /** - * @hibernate.id generator-class="native" type="java.lang.Long" column="uid" - * - */ + /** full constructor */ + public WookieSession(Date sessionEndDate, Date sessionStartDate, Integer status, Long sessionId, + String sessionName, Wookie wookie, Set wookieUsers) { + this.sessionEndDate = sessionEndDate; + this.sessionStartDate = sessionStartDate; + this.status = status; + this.sessionId = sessionId; + this.sessionName = sessionName; + this.wookie = wookie; + this.wookieUsers = wookieUsers; + } - public Long getUid() { - return this.uid; - } + // Property accessors + /** + * @hibernate.id generator-class="native" type="java.lang.Long" column="uid" + * + */ - public void setUid(Long uid) { - this.uid = uid; - } + public Long getUid() { + return this.uid; + } - /** - * @hibernate.property column="session_end_date" - * - */ + public void setUid(Long uid) { + this.uid = uid; + } - public Date getSessionEndDate() { - return this.sessionEndDate; - } + /** + * @hibernate.property column="session_end_date" + * + */ - public void setSessionEndDate(Date sessionEndDate) { - this.sessionEndDate = sessionEndDate; - } + public Date getSessionEndDate() { + return this.sessionEndDate; + } - /** - * @hibernate.property column="session_start_date" - * - */ + public void setSessionEndDate(Date sessionEndDate) { + this.sessionEndDate = sessionEndDate; + } - public Date getSessionStartDate() { - return this.sessionStartDate; - } + /** + * @hibernate.property column="session_start_date" + * + */ - public void setSessionStartDate(Date sessionStartDate) { - this.sessionStartDate = sessionStartDate; - } + public Date getSessionStartDate() { + return this.sessionStartDate; + } - /** - * @hibernate.property column="status" length="11" - * - */ + public void setSessionStartDate(Date sessionStartDate) { + this.sessionStartDate = sessionStartDate; + } - public Integer getStatus() { - return this.status; - } + /** + * @hibernate.property column="status" length="11" + * + */ - public void setStatus(Integer status) { - this.status = status; - } + public Integer getStatus() { + return this.status; + } - /** - * @hibernate.property column="session_id" length="20" - * - */ + public void setStatus(Integer status) { + this.status = status; + } - public Long getSessionId() { - return this.sessionId; - } + /** + * @hibernate.property column="session_id" length="20" + * + */ - public void setSessionId(Long sessionId) { - this.sessionId = sessionId; - } + public Long getSessionId() { + return this.sessionId; + } - /** - * @hibernate.property column="session_name" length="250" - * - */ + public void setSessionId(Long sessionId) { + this.sessionId = sessionId; + } - public String getSessionName() { - return this.sessionName; - } + /** + * @hibernate.property column="session_name" length="250" + * + */ - public void setSessionName(String sessionName) { - this.sessionName = sessionName; - } + public String getSessionName() { + return this.sessionName; + } - /** - * @hibernate.many-to-one not-null="true" - * @hibernate.column name="wookie_uid" - * - */ + public void setSessionName(String sessionName) { + this.sessionName = sessionName; + } - public Wookie getWookie() { - return this.wookie; - } + /** + * @hibernate.many-to-one not-null="true" + * @hibernate.column name="wookie_uid" + * + */ - public void setWookie(Wookie wookie) { - this.wookie = wookie; - } + public Wookie getWookie() { + return this.wookie; + } - /** - * @hibernate.set lazy="true" inverse="true" cascade="none" - * @hibernate.collection-key column="wookie_session_uid" - * @hibernate.collection-one-to-many class="org.lamsfoundation.lams.tool.wookie.model.WookieUser" - * - */ + public void setWookie(Wookie wookie) { + this.wookie = wookie; + } - public Set getWookieUsers() { - return this.wookieUsers; - } + /** + * @hibernate.set lazy="true" inverse="true" cascade="none" + * @hibernate.collection-key column="wookie_session_uid" + * @hibernate.collection-one-to-many + * class="org.lamsfoundation.lams.tool.wookie.model.WookieUser" + * + */ - public void setWookieUsers(Set wookieUsers) { - this.wookieUsers = wookieUsers; - } + public Set getWookieUsers() { + return this.wookieUsers; + } - /** - * toString - * - * @return String - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); + public void setWookieUsers(Set wookieUsers) { + this.wookieUsers = wookieUsers; + } + + /** + * @hibernate.property column="widget_shared_data_key" length="63" + * @return + */ + public String getWidgetSharedDataKey() { + return widgetSharedDataKey; + } - buffer.append(getClass().getName()).append("@").append( - Integer.toHexString(hashCode())).append(" ["); - buffer.append("sessionEndDate").append("='") - .append(getSessionEndDate()).append("' "); - buffer.append("sessionStartDate").append("='").append( - getSessionStartDate()).append("' "); - buffer.append("status").append("='").append(getStatus()).append("' "); - buffer.append("sessionID").append("='").append(getSessionId()).append( - "' "); - buffer.append("sessionName").append("='").append(getSessionName()) - .append("' "); - buffer.append("]"); + public void setWidgetSharedDataKey(String widgetSharedDataKey) { + this.widgetSharedDataKey = widgetSharedDataKey; + } - return buffer.toString(); - } + /** + * @hibernate.property column="widget_height" + * @return + */ + public Integer getWidgetHeight() { + return widgetHeight; + } - public boolean equals(Object other) { - if ((this == other)) - return true; - if ((other == null)) - return false; - if (!(other instanceof WookieSession)) - return false; - WookieSession castOther = (WookieSession) other; + public void setWidgetHeight(Integer widgetHeight) { + this.widgetHeight = widgetHeight; + } - return ((this.getUid() == castOther.getUid()) || (this.getUid() != null - && castOther.getUid() != null && this.getUid().equals( - castOther.getUid()))); - } + /** + * @hibernate.property column="widget_width" + * @return + */ + public Integer getWidgetWidth() { + return widgetWidth; + } - public int hashCode() { - int result = 17; - result = 37 * result - + (getUid() == null ? 0 : this.getUid().hashCode()); - return result; - } + public void setWidgetWidth(Integer widgetWidth) { + this.widgetWidth = widgetWidth; + } - public Object clone(){ - - WookieSession session = null; - try{ - session = (WookieSession) super.clone(); - session.wookieUsers = new HashSet(); - } catch (CloneNotSupportedException e) { - log.error("When clone " + WookieSession.class + " failed"); - } - return session; - } + /** + * @hibernate.property column="widget_maximise" + * @return + */ + public Boolean getWidgetMaximise() { + return widgetMaximise; + } + public void setWidgetMaximise(Boolean widgetMaximise) { + this.widgetMaximise = widgetMaximise; + } + + /** + * @hibernate.property column="widget_identifier" length="511" + * @return + */ + public String getWidgetIdentifier() { + return widgetIdentifier; + } + + public void setWidgetIdentifier(String widgetIdentifier) { + this.widgetIdentifier = widgetIdentifier; + } + + /** + * toString + * + * @return String + */ + public String toString() { + StringBuffer buffer = new StringBuffer(); + + buffer.append(getClass().getName()).append("@").append(Integer.toHexString(hashCode())).append(" ["); + buffer.append("sessionEndDate").append("='").append(getSessionEndDate()).append("' "); + buffer.append("sessionStartDate").append("='").append(getSessionStartDate()).append("' "); + buffer.append("status").append("='").append(getStatus()).append("' "); + buffer.append("sessionID").append("='").append(getSessionId()).append("' "); + buffer.append("sessionName").append("='").append(getSessionName()).append("' "); + buffer.append("]"); + + return buffer.toString(); + } + + public boolean equals(Object other) { + if ((this == other)) + return true; + if ((other == null)) + return false; + if (!(other instanceof WookieSession)) + return false; + WookieSession castOther = (WookieSession) other; + + return ((this.getUid() == castOther.getUid()) || (this.getUid() != null && castOther.getUid() != null && this + .getUid().equals(castOther.getUid()))); + } + + public int hashCode() { + int result = 17; + result = 37 * result + (getUid() == null ? 0 : this.getUid().hashCode()); + return result; + } + + public Object clone() { + + WookieSession session = null; + try { + session = (WookieSession) super.clone(); + session.wookieUsers = new HashSet(); + } catch (CloneNotSupportedException e) { + log.error("When clone " + WookieSession.class + " failed"); + } + return session; + } + } Index: lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/model/WookieUser.java =================================================================== diff -u -re81fdf5aa1e9c04fd0b7a624d8b8419b13cac81a -r08622dbb2e6672584f1cfcb52a239a46b3d667b1 --- lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/model/WookieUser.java (.../WookieUser.java) (revision e81fdf5aa1e9c04fd0b7a624d8b8419b13cac81a) +++ lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/model/WookieUser.java (.../WookieUser.java) (revision 08622dbb2e6672584f1cfcb52a239a46b3d667b1) @@ -58,6 +58,8 @@ private boolean finishedActivity; private Long entryUID; + + private String userWidgetURL; // Constructors @@ -176,7 +178,19 @@ public void setEntryUID(Long entryUID) { this.entryUID = entryUID; } + + /** + * @hibernate.property column="user_widget_url" length="511" + * @return + */ + public String getUserWidgetURL() { + return userWidgetURL; + } + public void setUserWidgetURL(String userWidgetURL) { + this.userWidgetURL = userWidgetURL; + } + /** * toString * Index: lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/service/WookieService.java =================================================================== diff -u -r118ef379cba1e25b2de0d5b975e5506097671b8a -r08622dbb2e6672584f1cfcb52a239a46b3d667b1 --- lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/service/WookieService.java (.../WookieService.java) (revision 118ef379cba1e25b2de0d5b975e5506097671b8a) +++ lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/service/WookieService.java (.../WookieService.java) (revision 08622dbb2e6672584f1cfcb52a239a46b3d667b1) @@ -29,14 +29,17 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; +import java.io.StringReader; import java.util.Date; -import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Set; import java.util.SortedMap; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.struts.upload.FormFile; @@ -72,6 +75,7 @@ import org.lamsfoundation.lams.tool.wookie.dao.IWookieDAO; import org.lamsfoundation.lams.tool.wookie.dao.IWookieSessionDAO; import org.lamsfoundation.lams.tool.wookie.dao.IWookieUserDAO; +import org.lamsfoundation.lams.tool.wookie.dto.WidgetData; import org.lamsfoundation.lams.tool.wookie.model.Wookie; import org.lamsfoundation.lams.tool.wookie.model.WookieAttachment; import org.lamsfoundation.lams.tool.wookie.model.WookieConfigItem; @@ -81,23 +85,31 @@ import org.lamsfoundation.lams.tool.wookie.util.WookieException; import org.lamsfoundation.lams.tool.wookie.util.WookieToolContentHandler; import org.lamsfoundation.lams.tool.wookie.util.WookieUtil; +import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.util.audit.IAuditService; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import com.thoughtworks.xstream.XStream; + /** * An implementation of the IWookieService interface. * - * As a requirement, all LAMS tool's service bean must implement ToolContentManager and ToolSessionManager. + * As a requirement, all LAMS tool's service bean must implement + * ToolContentManager and ToolSessionManager. */ -public class WookieService implements ToolSessionManager, ToolContentManager, IWookieService, ToolContentImport102Manager { +public class WookieService implements ToolSessionManager, ToolContentManager, IWookieService, + ToolContentImport102Manager { static Logger logger = Logger.getLogger(WookieService.class.getName()); - public static final String EXPORT_IMAGE_FILE_NAME = "authorImage"; - private IWookieDAO wookieDAO = null; private IWookieSessionDAO wookieSessionDAO = null; @@ -123,8 +135,10 @@ private WookieOutputFactory wookieOutputFactory; private IWookieConfigItemDAO wookieConfigItemDAO; - + private MessageService messageService; + + private IUserManagementService userManagementService; public WookieService() { super(); @@ -145,6 +159,39 @@ // TODO need to also set other fields. Wookie wookie = wookieDAO.getByContentId(toolContentId); session.setWookie(wookie); + + // Create a copy of the widget for the session + // Clone the wookie widget on the external server + String wookieUrl = getWookieURL(); + try { + String newSharedDataKey = toolSessionId.toString() + "_" + toolContentId.toString(); + + if (wookieUrl != null && wookie.getWidgetIdentifier() != null && wookie.getWidgetIdentifier() != "") { + + wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; + + logger.debug("Creating a new clone for session of widget: " + toolContentId.toString()); + boolean success = WookieUtil.cloneWidget(wookieUrl, getWookieAPIKey(), wookie.getWidgetIdentifier(), + toolContentId.toString(), newSharedDataKey, wookie.getCreateBy().toString()); + + if (success) { + session.setWidgetSharedDataKey(newSharedDataKey); + session.setWidgetHeight(wookie.getWidgetHeight()); + session.setWidgetWidth(wookie.getWidgetWidth()); + session.setWidgetMaximise(wookie.getWidgetMaximise()); + session.setWidgetIdentifier(wookie.getWidgetIdentifier()); + } else { + throw new WookieException("Failed to copy widget on wookie server, check log for details."); + } + + } else { + throw new WookieException("Wookie url is not set"); + } + } catch (Exception e) { + logger.error("Problem calling wookie server to clone instance", e); + throw new WookieException("Problem calling wookie server to clone instance", e); + } + wookieSessionDAO.saveOrUpdate(session); } @@ -172,8 +219,9 @@ /** * Get the tool output for the given tool output names. * - * @see org.lamsfoundation.lams.tool.ToolSessionManager#getToolOutput(java.util.List, java.lang.Long, - * java.lang.Long) + * @see + * org.lamsfoundation.lams.tool.ToolSessionManager#getToolOutput(java.util + * .List, java.lang.Long, java.lang.Long) */ public SortedMap getToolOutput(List names, Long toolSessionId, Long learnerId) { return getWookieOutputFactory().getToolOutput(names, this, toolSessionId, learnerId); @@ -182,8 +230,8 @@ /** * Get the tool output for the given tool output name. * - * @see org.lamsfoundation.lams.tool.ToolSessionManager#getToolOutput(java.lang.String, java.lang.Long, - * java.lang.Long) + * @see org.lamsfoundation.lams.tool.ToolSessionManager#getToolOutput(java.lang.String, + * java.lang.Long, java.lang.Long) */ public ToolOutput getToolOutput(String name, Long toolSessionId, Long learnerId) { return getWookieOutputFactory().getToolOutput(name, this, toolSessionId, learnerId); @@ -212,33 +260,48 @@ fromContent = getDefaultContent(); } Wookie toContent = Wookie.newInstance(fromContent, toContentId, wookieToolContentHandler); - + + // Clone the wookie widget on the external server String wookieUrl = getWookieURL(); - try { - if (wookieUrl != null && fromContent.getWidgetIdentifier() != null && fromContent.getWidgetIdentifier() != "") { - - wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; - HashMap params = new HashMap (); - - params.put(WookieConstants.PARAM_KEY_API_KEY, getWookieAPIKey()); - params.put(WookieConstants.PARAM_KEY_WIDGET_ID, fromContent.getWidgetIdentifier()); - params.put(WookieConstants.PARAM_KEY_PROPERTY_TEMPLATE_SHARED_KEY, fromContent.getToolContentId().toString()); - params.put(WookieConstants.PARAM_KEY_PROPERTY_CLONED_SHARED_KEY, toContentId.toString()); - - String xml = WookieUtil.getResponseStringFromExternalServer(wookieUrl, params); - - + if (wookieUrl != null) { + if (fromContent.getWidgetIdentifier() != null && fromContent.getWidgetIdentifier() != "") { + wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; + + logger.debug("Creating a new clone for copycontent for widget: " + fromContentId.toString()); + boolean success = WookieUtil.cloneWidget(wookieUrl, getWookieAPIKey(), fromContent + .getWidgetIdentifier(), fromContentId.toString(), toContentId.toString(), fromContent + .getCreateBy().toString()); + + if (success) { + toContent.setWidgetHeight(fromContent.getWidgetHeight()); + toContent.setWidgetWidth(fromContent.getWidgetWidth()); + toContent.setWidgetAuthorUrl(fromContent.getWidgetAuthorUrl()); + toContent.setWidgetMaximise(fromContent.getWidgetMaximise()); + toContent.setWidgetIdentifier(fromContent.getWidgetIdentifier()); + toContent.setCreateBy(fromContent.getCreateBy()); + + // Need to add the author to the widget so authoring widget url is different in the copy + User user = (User)userManagementService.findById(User.class, fromContent.getCreateBy()); + String returnXML = WookieUtil.getWidget(wookieUrl, getWookieAPIKey(), fromContent.getWidgetIdentifier(), user.getUserDTO(), toContentId.toString(), true); + + toContent.setWidgetAuthorUrl(WookieUtil.getWidgetUrlFromXML(returnXML)); + + } else { + throw new WookieException("Failed to copy widget on wookie server, check log for details."); + } + } } else { - throw new WookieException("Wookie url is not set"); + throw new WookieException("Wookie url is not set"); } } catch (Exception e) { - logger.error("Problem calling wookie server to clone instance"); + logger.error("Problem calling wookie server to clone instance", e); throw new WookieException("Problem calling wookie server to clone instance", e); } wookieDAO.saveOrUpdate(toContent); } + public void copyFile(File srcFile, String destPath) throws Exception { if (srcFile.exists() && srcFile.canRead()) { @@ -278,12 +341,13 @@ } /** - * Export the XML fragment for the tool's content, along with any files needed for the content. + * 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 + * if no tool content matches the toolSessionId * @throws ToolException - * if any other error occurs + * if any other error occurs */ public void exportToolContent(Long toolContentId, String rootPath) throws DataMissingException, ToolException { @@ -315,10 +379,11 @@ } /** - * Import the XML fragment for the tool's content, along with any files needed for the content. + * Import the XML fragment for the tool's content, along with any files + * needed for the content. * * @throws ToolException - * if any other error occurs + * if any other error occurs */ public void importToolContent(Long toolContentId, Integer newUserUid, String toolContentPath, String fromVersion, String toVersion) throws ToolException { @@ -336,7 +401,7 @@ // reset it to new toolContentId wookie.setToolContentId(toolContentId); - wookie.setCreateBy(new Long(newUserUid.longValue())); + wookie.setCreateBy(newUserUid); wookieDAO.saveOrUpdate(wookie); } catch (ImportToolContentException e) { @@ -357,12 +422,14 @@ } /** - * Get the definitions for possible output for an activity, based on the toolContentId. These may be definitions - * that are always available for the tool (e.g. number of marks for Multiple Choice) or a custom definition created - * for a particular activity such as the answer to the third question contains the word Koala and hence the need for - * the toolContentId + * Get the definitions for possible output for an activity, based on the + * toolContentId. These may be definitions that are always available for the + * tool (e.g. number of marks for Multiple Choice) or a custom definition + * created for a particular activity such as the answer to the third + * question contains the word Koala and hence the need for the toolContentId * - * @return SortedMap of ToolOutputDefinitions with the key being the name of each definition + * @return SortedMap of ToolOutputDefinitions with the key being the name of + * each definition */ public SortedMap getToolOutputDefinitions(Long toolContentId, int definitionType) throws ToolException { @@ -372,7 +439,7 @@ } return getWookieOutputFactory().getToolOutputDefinitions(wookie, definitionType); } - + @SuppressWarnings("unchecked") public Class[] getSupportedToolOutputDefinitionClasses(int definitionType) { return getWookieOutputFactory().getSupportedDefinitionClasses(definitionType); @@ -542,11 +609,12 @@ } /** - * This method verifies the credentials of the SubmitFiles Tool and gives it the Ticket to login and - * access the Content Repository. + * 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. + * 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 @@ -573,7 +641,7 @@ public void saveOrUpdateWookieConfigItem(WookieConfigItem item) { wookieConfigItemDAO.saveOrUpdate(item); } - + public String getWookieURL() { String url = null; WookieConfigItem urlItem = wookieConfigItemDAO.getConfigItemByKey(WookieConfigItem.KEY_WOOKIE_URL); @@ -582,7 +650,7 @@ } return url; } - + public String getWookieAPIKey() { String url = null; WookieConfigItem apiItem = wookieConfigItemDAO.getConfigItemByKey(WookieConfigItem.KEY_API); @@ -591,7 +659,7 @@ } return url; } - + public String getMessage(String key) { return messageService.getMessage(key); } @@ -606,11 +674,10 @@ Date now = new Date(); Wookie wookie = new Wookie(); wookie.setContentInUse(Boolean.FALSE); - wookie.setCreateBy(new Long(user.getUserID().longValue())); + wookie.setCreateBy(user.getUserID()); wookie.setCreateDate(now); wookie.setDefineLater(Boolean.FALSE); - wookie.setInstructions(WebUtil.convertNewlines((String) importValues - .get(ToolContentImport102Manager.CONTENT_BODY))); + wookie.setInstructions(WebUtil.convertNewlines((String) importValues.get(ToolContentImport102Manager.CONTENT_BODY))); wookie.setLockOnFinished(Boolean.TRUE); wookie.setOfflineInstructions(null); wookie.setOnlineInstructions(null); @@ -619,14 +686,12 @@ wookie.setToolContentId(toolContentId); wookie.setUpdateDate(now); wookie.setReflectOnActivity(Boolean.FALSE); - // leave as empty, no need to set them to anything. - // setWookieAttachments(Set wookieAttachments); - // setWookieSessions(Set wookieSessions); wookieDAO.saveOrUpdate(wookie); } /** - * Set the description, throws away the title value as this is not supported in 2.0 + * Set the description, throws away the title value as this is not supported + * in 2.0 */ public void setReflectiveData(Long toolContentId, String title, String description) throws ToolException, DataMissingException { @@ -742,12 +807,19 @@ } public MessageService getMessageService() { - return messageService; + return messageService; } public void setMessageService(MessageService messageService) { - this.messageService = messageService; + this.messageService = messageService; } - - + + public IUserManagementService getUserManagementService() { + return userManagementService; + } + + public void setUserManagementService(IUserManagementService userManagementService) { + this.userManagementService = userManagementService; + } + } Index: lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/util/WookieConstants.java =================================================================== diff -u -r118ef379cba1e25b2de0d5b975e5506097671b8a -r08622dbb2e6672584f1cfcb52a239a46b3d667b1 --- lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/util/WookieConstants.java (.../WookieConstants.java) (revision 118ef379cba1e25b2de0d5b975e5506097671b8a) +++ lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/util/WookieConstants.java (.../WookieConstants.java) (revision 08622dbb2e6672584f1cfcb52a239a46b3d667b1) @@ -84,15 +84,14 @@ public static final String PARAM_KEY_PARTICIPANT_THUMBNAIL_URL = "participant_thumbnail_url"; public static final String PARAM_KEY_PROPERTY_NAME = "propertyname"; public static final String PARAM_KEY_PROPERTY_VALUE = "propertyvalue"; - public static final String PARAM_KEY_PROPERTY_TEMPLATE_SHARED_KEY = "templateSharedDataKey"; - public static final String PARAM_KEY_PROPERTY_CLONED_SHARED_KEY = "clonedSharedDataKey"; + public static final String PARAM_KEY_PROPERTY_CLONED_SHARED_KEY = "cloneshareddatakey"; public static final String PARAM_VALUE_GET_WIDGET= "getwidget"; public static final String PARAM_VALUE_ADD_PARTICIPANT = "addparticipant"; public static final String PARAM_VALUE_SET_PERSONAL_PROPERTY = "setpersonalproperty"; public static final String PARAM_VALUE_PROPERTY_NAME_MODERATOR = "moderator"; public static final String PARAM_VALUE_PROPERTY_VALUE_TRUE = "true"; - public static final String PARAM_VALUE_PROPERTY_VALUE_CLONE = "cloneSharedData"; + public static final String PARAM_VALUE_PROPERTY_VALUE_CLONE = "cloneshareddata"; public static final String XML_WIDGETS = "widgets"; public static final String XML_WIDGET = "widget"; @@ -101,7 +100,6 @@ public static final String XML_DESCRIPTION = "description"; public static final String XML_ICON = "icon"; public static final String XML_PARAMETER = "parameter"; - public static final String XML_MESSAGE = "message"; - public static final String XML_COMPLETED = "completed"; + public static final String XML_URL = "url"; } Index: lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/util/WookieUtil.java =================================================================== diff -u -r118ef379cba1e25b2de0d5b975e5506097671b8a -r08622dbb2e6672584f1cfcb52a239a46b3d667b1 --- lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/util/WookieUtil.java (.../WookieUtil.java) (revision 118ef379cba1e25b2de0d5b975e5506097671b8a) +++ lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/util/WookieUtil.java (.../WookieUtil.java) (revision 08622dbb2e6672584f1cfcb52a239a46b3d667b1) @@ -143,8 +143,8 @@ return 0; } - public static String getWidget(String url, String apiKey, String widgetIdentifier, UserDTO user, String sharedDataKey, boolean isModerator) - throws Exception { + public static String getWidget(String url, String apiKey, String widgetIdentifier, UserDTO user, + String sharedDataKey, boolean isModerator) throws Exception { if (url == null || apiKey == null || widgetIdentifier == null || user == null || sharedDataKey == null) { return null; @@ -156,27 +156,31 @@ params.put(WookieConstants.PARAM_KEY_SHARED_DATA_KEY, URLEncoder.encode(sharedDataKey, "UTF8")); params.put(WookieConstants.PARAM_KEY_API_KEY, URLEncoder.encode(apiKey, "UTF8")); - params.put(WookieConstants.PARAM_KEY_REQUEST_ID, URLEncoder.encode(WookieConstants.PARAM_VALUE_GET_WIDGET, "UTF8")); - + params.put(WookieConstants.PARAM_KEY_REQUEST_ID, URLEncoder.encode(WookieConstants.PARAM_VALUE_GET_WIDGET, + "UTF8")); + String widgetXML = getResponseStringFromExternalServer(url, params); String displayName = user.getFirstName() + " " + user.getLastName(); - + // Add the participant - boolean participantAdded = addParticipant(url, apiKey, widgetIdentifier, user.getUserID().toString(), sharedDataKey, user.getUserID().toString(), displayName, null); + boolean participantAdded = addParticipant(url, apiKey, widgetIdentifier, user.getUserID().toString(), + sharedDataKey, user.getUserID().toString(), displayName, null); if (!participantAdded) { throw new WookieException("Attempt to add participant failed, check response code in logs"); } - // If required, set the moderator property if (isModerator) { - boolean propertyAdded = addProperty(url, apiKey, widgetIdentifier, user.getUserID().toString(), sharedDataKey, user.getUserID().toString(), displayName, null, WookieConstants.PARAM_VALUE_PROPERTY_NAME_MODERATOR, WookieConstants.PARAM_VALUE_PROPERTY_VALUE_TRUE); + boolean propertyAdded = addProperty(url, apiKey, widgetIdentifier, user.getUserID().toString(), + sharedDataKey, user.getUserID().toString(), displayName, null, + WookieConstants.PARAM_VALUE_PROPERTY_NAME_MODERATOR, + WookieConstants.PARAM_VALUE_PROPERTY_VALUE_TRUE); if (!propertyAdded) { throw new WookieException("Attempt to add property failed, check response code in logs"); } - + } - + return widgetXML; } @@ -192,12 +196,12 @@ * @param participantDisplayName * @param participantThumbnailURL * @return - * @throws Exception * @throws Exception + * @throws Exception */ public static boolean addParticipant(String url, String apiKey, String widgetIdentifier, String userId, - String sharedDataKey, String participantId, String participantDisplayName, String participantThumbnailURL) throws Exception - { + String sharedDataKey, String participantId, String participantDisplayName, String participantThumbnailURL) + throws Exception { if (url == null || apiKey == null || widgetIdentifier == null || userId == null || sharedDataKey == null) { throw new WookieException("Parameters missing in addParticipant call"); } @@ -211,14 +215,15 @@ .encode(participantDisplayName, "UTF8")); if (participantThumbnailURL != null) { params.put(WookieConstants.PARAM_KEY_PARTICIPANT_THUMBNAIL_URL, URLEncoder.encode(participantThumbnailURL, - "UTF8")); + "UTF8")); } params.put(WookieConstants.PARAM_KEY_API_KEY, URLEncoder.encode(apiKey, "UTF8")); - params.put(WookieConstants.PARAM_KEY_REQUEST_ID, URLEncoder.encode(WookieConstants.PARAM_VALUE_ADD_PARTICIPANT, "UTF8")); - + params.put(WookieConstants.PARAM_KEY_REQUEST_ID, URLEncoder.encode(WookieConstants.PARAM_VALUE_ADD_PARTICIPANT, + "UTF8")); + // Making the request and getting the response code int responseCode = WookieUtil.getResponseCodeExternalServer(url, params); - + // Checking the response code if (responseCode == HttpServletResponse.SC_OK || responseCode == HttpServletResponse.SC_CREATED) { return true; @@ -228,9 +233,8 @@ } /** + * Add a property to the existing initiated widget * - * - * * @param url * @param apiKey * @param widgetIdentifier @@ -240,8 +244,8 @@ * @param participantDisplayName * @param participantThumbnailURL * @return - * @throws Exception * @throws Exception + * @throws Exception */ public static boolean addProperty(String url, String apiKey, String widgetIdentifier, String userId, String sharedDataKey, String participantId, String participantDisplayName, String participantThumbnailURL, @@ -259,16 +263,17 @@ .encode(participantDisplayName, "UTF8")); if (participantThumbnailURL != null) { params.put(WookieConstants.PARAM_KEY_PARTICIPANT_THUMBNAIL_URL, URLEncoder.encode(participantThumbnailURL, - "UTF8")); + "UTF8")); } params.put(WookieConstants.PARAM_KEY_PROPERTY_NAME, URLEncoder.encode(propertyName, "UTF8")); params.put(WookieConstants.PARAM_KEY_PROPERTY_VALUE, URLEncoder.encode(propertyValue, "UTF8")); params.put(WookieConstants.PARAM_KEY_API_KEY, URLEncoder.encode(apiKey, "UTF8")); - params.put(WookieConstants.PARAM_KEY_REQUEST_ID, URLEncoder.encode(WookieConstants.PARAM_VALUE_SET_PERSONAL_PROPERTY, "UTF8")); + params.put(WookieConstants.PARAM_KEY_REQUEST_ID, URLEncoder.encode( + WookieConstants.PARAM_VALUE_SET_PERSONAL_PROPERTY, "UTF8")); // Making the request and getting the response code int responseCode = WookieUtil.getResponseCodeExternalServer(url, params); - + // Checking the response code if (responseCode == HttpServletResponse.SC_OK || responseCode == HttpServletResponse.SC_CREATED) { return true; @@ -277,9 +282,47 @@ } } + /** + * Make a clone of the widget identified by the shared data key + * + * @param url + * @param apiKey + * @param widgetIdentifier + * @param userId + * @param sharedDataKey + * @param participantId + * @param participantDisplayName + * @param participantThumbnailURL + * @return + * @throws Exception + * @throws Exception + */ + public static boolean cloneWidget(String url, String apiKey, String widgetIdentifier, String sharedDataKey, + String newSharedDataKey, String userID) throws Exception { + HashMap params = new HashMap(); + params.put(WookieConstants.PARAM_KEY_WIDGET_ID, URLEncoder.encode(widgetIdentifier, "UTF8")); + params.put(WookieConstants.PARAM_KEY_SHARED_DATA_KEY, URLEncoder.encode(sharedDataKey, "UTF8")); + params.put(WookieConstants.PARAM_KEY_API_KEY, URLEncoder.encode(apiKey, "UTF8")); + params.put(WookieConstants.PARAM_KEY_REQUEST_ID, URLEncoder.encode(WookieConstants.PARAM_VALUE_PROPERTY_VALUE_CLONE, "UTF8")); + params.put(WookieConstants.PARAM_KEY_SHARED_DATA_KEY, URLEncoder.encode(sharedDataKey, "UTF8")); + params.put(WookieConstants.PARAM_KEY_PROPERTY_CLONED_SHARED_KEY, URLEncoder.encode(newSharedDataKey, "UTF8")); + params.put(WookieConstants.PARAM_KEY_USER_ID, URLEncoder.encode(userID, "UTF8")); + + // Making the request and getting the response code + int responseCode = WookieUtil.getResponseCodeExternalServer(url, params); + + // Checking the response code + if (responseCode == HttpServletResponse.SC_OK) { + return true; + } else { + return false; + } + } + /** - * Makes a request to the specified url with the specified parameters and returns the response string + * Makes a request to the specified url with the specified parameters and + * returns the response string * * @param urlStr * @param params @@ -288,7 +331,7 @@ * @throws IOException */ public static String getResponseStringFromExternalServer(String urlStr, HashMap params) - throws Exception { + throws Exception { InputStream is = getResponseInputStreamFromExternalServer(urlStr, params); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); @@ -299,28 +342,27 @@ is.close(); return sb.toString(); } - - + /** - * Makes a request to the specified url. Returns true if the expected status response code is returned + * Makes a request to the specified url. Returns true if the expected status + * response code is returned * * @param urlStr * @param params * @return * @throws ToolException * @throws IOException */ - public static int getResponseCodeExternalServer(String urlStr, HashMap params) - throws Exception { + public static int getResponseCodeExternalServer(String urlStr, HashMap params) throws Exception { URLConnection conn = getResponseUrlConnectionFromExternalServer(urlStr, params); HttpURLConnection httpConn = (HttpURLConnection) conn; - + return httpConn.getResponseCode(); } - - + /** - * Makes a request to the specified url with the specified parameters and returns the response input stream + * Makes a request to the specified url with the specified parameters and + * returns the response input stream * * @param urlStr * @param params @@ -329,15 +371,15 @@ * @throws IOException */ public static InputStream getResponseInputStreamFromExternalServer(String urlStr, HashMap params) - throws Exception { + throws Exception { URLConnection conn = getResponseUrlConnectionFromExternalServer(urlStr, params); InputStream is = conn.getInputStream(); return is; } - - + /** - * Makes a request to the specified url with the specified parameters and returns the response URLConnection + * Makes a request to the specified url with the specified parameters and + * returns the response URLConnection * * @param urlStr * @param params @@ -361,11 +403,33 @@ logger.error("Fail to connect to external server though url: " + urlStr); throw new Exception("Fail to connect to external server though url: " + urlStr); } - + HttpURLConnection httpConn = (HttpURLConnection) conn; logger.info("Response code was " + new Integer(httpConn.getResponseCode()).toString() + " for URL: " + urlStr); - + return conn; } + + /** + * Gets the url response from the getWidget xml + * @param xml + * @return + * @throws ParserConfigurationException + * @throws SAXException + * @throws IOException + */ + public static String getWidgetUrlFromXML(String xml) throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new InputSource(new StringReader(xml))); + NodeList widgetList = document.getElementsByTagName(WookieConstants.XML_URL); + + if (widgetList != null && widgetList.item(0) != null) { + String url = widgetList.item(0).getTextContent(); + return url; + } else { + return null; + } + } } Index: lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/web/actions/AuthoringAction.java =================================================================== diff -u -r118ef379cba1e25b2de0d5b975e5506097671b8a -r08622dbb2e6672584f1cfcb52a239a46b3d667b1 --- lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 118ef379cba1e25b2de0d5b975e5506097671b8a) +++ lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 08622dbb2e6672584f1cfcb52a239a46b3d667b1) @@ -145,8 +145,8 @@ if (wookie == null) { wookie = wookieService.copyDefaultContent(toolContentID); wookie.setCreateDate(new Date()); + wookie.setCreateBy(getUser().getUserID()); wookieService.saveOrUpdateWookie(wookie); - // TODO NOTE: this causes DB orphans when LD not saved. } if (mode != null && mode.isTeacher()) { Index: lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/wookieApplicationContext.xml =================================================================== diff -u -r1b9cc5f77d2ca9a23335fd5dcfc7ee44b87f91b3 -r08622dbb2e6672584f1cfcb52a239a46b3d667b1 --- lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/wookieApplicationContext.xml (.../wookieApplicationContext.xml) (revision 1b9cc5f77d2ca9a23335fd5dcfc7ee44b87f91b3) +++ lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/wookieApplicationContext.xml (.../wookieApplicationContext.xml) (revision 08622dbb2e6672584f1cfcb52a239a46b3d667b1) @@ -39,8 +39,8 @@ - - + +