Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
java
java
public void exportToolContent(Long toolContentId, String rootPath)
		throws DataMissingException, ToolException {
	Scribe scribe = scribeDAO.getByContentId(toolContentId);
	if (scribe == null) {
		scribe = getDefaultContent();
	}
	if (scribe == null)
		throw new DataMissingException("Unable to find default content for the scribe tool");

	// set ResourceToolContentHandler as null to avoid copy file node in
	// repository again.
	scribe = Scribe.newInstance(scribe, toolContentId, null);
	scribe.setToolContentHandler(null);
	scribe.setScribeSessions(null);
	// wipe out the links from ScribeAttachments, ScribeHeading back to Scribe, or it will try to 
	// include the hibernate object version of the Scribe within the XML
	Set<ScribeAttachment> atts = scribe.getScribeAttachments();
	for (ScribeAttachment att : atts) {
		att.setScribe(null);
	}
	Set<ScribeHeading> headings = scribe.getScribeHeadings();
	for (ScribeHeading heading : headings) {
		heading.setScribe(null);
	}
	try {
		exportContentService.registerFileClassForExport(ScribeAttachment.class.getName(),
						"fileUuid", "fileVersionId");
		exportContentService.exportToolContent(toolContentId,
				scribe, scribeToolContentHandler, rootPath);
	} catch (ExportToolContentException e) {
		throw new ToolException(e);
	}

Import tool content.

It is a reverse process with export content.

...

Code Block
java
java
public void importToolContent(Long toolContentId, Integer newUserUid, String toolContentPath, String fromVersion, String toVersion) 
    throws ToolException 
{

	try {
		exportContentService.registerFileClassForImport(ResourceAttachment.class.getName()
				,"fileUuid","fileVersionId","fileName","fileType",null,null);
		exportContentService.registerFileClassForImport(ResourceItem.class.getName()
				,"fileUuid","fileVersionId","fileName","fileType",null,"initialItem");
		   exportContentService.registerImportVersionFilterClass(RsrcImportContentVersionFilter.class);

		Object toolPOJO =  exportContentService.importToolContent(toolContentPath,resourceToolContentHandler,fromVersion,toVersion);
		if(\!(toolPOJO instanceof Resource))
			throw new ImportToolContentException("Import Share resources tool content failed. Deserialized object is " + toolPOJO);
		Resource toolContentObj = (Resource) toolPOJO;

	//			reset it to new toolContentId
		toolContentObj.setContentId(toolContentId);

	//			Refresh user information for tool content object
		ResourceUser user = resourceUserDao.getUserByUserID(new Long(newUserUid.longValue()));
		if(user == null){
			user = new ResourceUser();
			UserDTO sysUser = userManagementService.getUserById(newUserUid).getUserDTO();
			user.setFirstName(sysUser.getFirstName());
			user.setLastName(sysUser.getLastName());
			user.setLoginName(sysUser.getLogin());
			user.setUserId(new Long(newUserUid.longValue()));
		}
		toolContentObj.setCreatedBy(user);

	//			refresh all resourceItem createBy user
		Set<ResourceItem> items = toolContentObj.getResourceItems();
		for(ResourceItem item:items){
			item.setCreateBy(user);
		}
		resourceDao.saveObject(toolContentObj);
	} catch (ImportToolContentException e) {
		throw new ToolException(e);
	}
}

...

In the example below, Scribe contains a set of ScribeHeadings. The ScribeHeading contains a reference to its Scribe, so if it is converted to XML as is, we end up with a Scribe, containing ScribeHeadings, which in turn contain the Hibernate version of Scribe. When the file is imported then the ScribeHeadings try to point to the wrong Scribe. This was fixed by first creating a new instance of Scribe and then going through the ScribeHeadings and setting their reference to Scribe to null.

Bad tool.xml

Code Block
  <createDate>2006-10-25 15:28:05.765 EST</createDate>
  <title>LAMS Scribe</title>
  <instructions>Scribe Instruction</instructions>
  <runOffline>false</runOffline>
  <lockOnFinished>true</lockOnFinished>
  <reflectOnActivity>false</reflectOnActivity>
  <onlineInstructions>Online instructions</onlineInstructions>
  <offlineInstructions>Offline instructions</offlineInstructions>
  <contentInUse>false</contentInUse>
  <defineLater>false</defineLater>
  <autoSelectScribe>true</autoSelectScribe>
  <toolContentId>60</toolContentId>
  <scribeAttachments/>
  <scribeHeadings>
    <org.lamsfoundation.lams.tool.scribe.model.ScribeHeading>
      <scribe>
        <uid>1</uid>
        <title>LAMS Scribe</title>
        <instructions>Scribe Instruction</instructions>
        <runOffline>false</runOffline>
        <lockOnFinished>true</lockOnFinished>
        <reflectOnActivity>false</reflectOnActivity>
        <onlineInstructions>Online instructions</onlineInstructions>
        <offlineInstructions>Offline instructions</offlineInstructions>
        <contentInUse>false</contentInUse>
        <defineLater>false</defineLater>
        <autoSelectScribe>true</autoSelectScribe>
        <toolContentId>11</toolContentId>
        <scribeAttachments class="org.hibernate.collection.PersistentSet">
          <set/>
          <initialized>true</initialized>
          <collectionSnapshot class="org.hibernate.engine.CollectionEntry">
            <dirty>false</dirty>
            <initialized>true</initialized>
            <loadedKey class="long">1</loadedKey>
            <snapshot class="map"/>
            <role>org.lamsfoundation.lams.tool.scribe.model.Scribe.scribeAttachments</role>
          </collectionSnapshot>
          <owner class="org.lamsfoundation.lams.tool.scribe.model.Scribe" reference="../.."/>
        </scribeAttachments>
        <scribeSessions class="org.hibernate.collection.PersistentSet">
          <initialized>false</initialized>
          <collectionSnapshot class="org.hibernate.engine.CollectionEntry">
            <dirty>false</dirty>
            <initialized>false</initialized>
            <loadedKey class="long">1</loadedKey>
            <role>org.lamsfoundation.lams.tool.scribe.model.Scribe.scribeSessions</role>
          </collectionSnapshot>
          <owner class="org.lamsfoundation.lams.tool.scribe.model.Scribe" reference="../.."/>
        </scribeSessions>
        <scribeHeadings class="org.hibernate.collection.PersistentSet">
          <set>
            <org.lamsfoundation.lams.tool.scribe.model.ScribeHeading>
              <uid>1</uid>
              <scribe reference="../../../.."/>
              <headingText>Scribe Heading</headingText>
              <displayOrder>0</displayOrder>
            </org.lamsfoundation.lams.tool.scribe.model.ScribeHeading>
          </set>
          <initialized>true</initialized>
          <collectionSnapshot class="org.hibernate.engine.CollectionEntry">
            <dirty>false</dirty>
            <initialized>true</initialized>
            <loadedKey class="long">1</loadedKey>
            <snapshot class="map">
              <entry>
                <org.lamsfoundation.lams.tool.scribe.model.ScribeHeading \
reference="../../../../set/org.lamsfoundation.lams.tool.scribe.model.ScribeHeading"/>
                <org.lamsfoundation.lams.tool.scribe.model.ScribeHeading \
reference="../../../../set/org.lamsfoundation.lams.tool.scribe.model.ScribeHeading"/>
              </entry>
            </snapshot>
            <role>org.lamsfoundation.lams.tool.scribe.model.Scribe.scribeHeadings</role>
          </collectionSnapshot>
          <owner class="org.lamsfoundation.lams.tool.scribe.model.Scribe" reference="../.."/>
        </scribeHeadings>
      </scribe>
      <headingText>Scribe Heading</headingText>
      <displayOrder>0</displayOrder>
    </org.lamsfoundation.lams.tool.scribe.model.ScribeHeading>
  </scribeHeadings>
</org.lamsfoundation.lams.tool.scribe.model.Scribe>

...