Skip to content

Commit

Permalink
SAM-2561 Import attachements for EMI question types.
Browse files Browse the repository at this point in the history
  • Loading branch information
ern committed Aug 10, 2015
1 parent 07f3472 commit 3ff9947
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<items type="list">
[<xsl:value-of select="outcomes/decvar[@varname='requiredOptionsCount']/@maxvalue" />|<xsl:value-of select="outcomes/decvar[@varname='scoreUserSet']/@defaultval" />]<xsl:value-of select="outcomes/interpretvar/material/mattext" />
@ATTACH@
<xsl:for-each
select="outcomes/interpretvar/material/mattext">
@<xsl:value-of select='@label' />[<xsl:value-of select='@texttype' />](<xsl:value-of select='@size' />)<xsl:value-of select="@uri" />
</xsl:for-each>
<xsl:for-each
select="outcomes/interpretvar/material/matimage">
@<xsl:value-of select='@label' />[<xsl:value-of select='@imagtype' />](<xsl:value-of select='@size' />)<xsl:value-of select="@uri" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.content.api.ContentResource;
import org.sakaiproject.entity.api.ResourceProperties;
//import org.sakaiproject.tool.assessment.api.SamigoApiFactory;
import org.sakaiproject.tool.assessment.data.dao.assessment.Answer;
import org.sakaiproject.tool.assessment.data.dao.assessment.AnswerFeedback;
Expand Down Expand Up @@ -3121,7 +3122,7 @@ private Set<ItemText> makeEMIItems(ItemFacade item, List<String> items,
text, answers);
itemText.setRequiredOptionsCount(required);
index = itemdata.indexOf("@ANSWERS@");
// itemText.setItemTextAttachmentSet(makeEMIItemTextAttachmentSet(itemText, itemdata.substring(0, index)));
itemText.setItemTextAttachmentSet(makeEMIItemTextAttachmentSet(itemText, itemdata.substring(0, index)));
itemTextSet.add(itemText);
itemdata = itemdata.substring(index + "@ANSWERS@".length()).trim();
index = itemdata.indexOf("[");
Expand All @@ -3143,14 +3144,13 @@ private Set<ItemText> makeEMIItems(ItemFacade item, List<String> items,
return itemTextSet;
}

private Set<ItemTextAttachmentIfc> makeEMIItemTextAttachmentSet(
ItemText itemText, String attachments) {
private Set<ItemTextAttachmentIfc> makeEMIItemTextAttachmentSet(ItemText itemText, String attachments) {
attachments = attachments.trim();
if(attachments.length() == 0){
return null;
}
List<String> attachList = Arrays.asList(attachments.split("@"));
Set<ItemTextAttachmentIfc> attachSet = new TreeSet<ItemTextAttachmentIfc>();
Set<ItemTextAttachmentIfc> attachSet = new HashSet<ItemTextAttachmentIfc>();
for(String attach: attachList){
attach = attach.trim();
if(attach.length() == 0) continue;
Expand All @@ -3162,13 +3162,19 @@ private Set<ItemTextAttachmentIfc> makeEMIItemTextAttachmentSet(
index = attach.indexOf("(");
attach = attach.substring(index);
index = attach.indexOf(")");
Long size = Long.valueOf(attach.substring(1, index));
attach = attach.substring(index+1);
String location = attach;
String resourceId = location.replace("%2B", "+").replace("%20", " ").replace("/access/content", "");
attachSet.add(new ItemTextAttachment(null, itemText, resourceId,
fileName, mimeType, size, null, location,
false, ItemTextAttachmentIfc.ACTIVE_STATUS, null, null, null, null));
if (index > 1) {
Long size = Long.valueOf(attach.substring(1, index));
attach = attach.substring(index+1);
String resourceId = attach.replace("%2B", "+").replace("%20", " ").replace("/access/content", "");
try {
ContentResource cr = new AssessmentService().createCopyOfContentResource(resourceId, fileName);

attachSet.add(new ItemTextAttachment(null, itemText, cr.getId(), fileName, mimeType, size, null, cr.getUrl(true),
false, ItemTextAttachmentIfc.ACTIVE_STATUS, itemText.getItem().getCreatedBy(), new Date(), itemText.getItem().getLastModifiedBy(), new Date()));
} catch (Exception e) {
log.warn("Unable to add EMI attachment " + resourceId + ", " + e.getMessage());
}
}
}
return attachSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ public Set prepareItemSet(SectionData newSection, Set itemSet,
// itemFeedbackSet later
item.getTriesAllowed(), item.getPartialCreditFlag());
Set newItemTextSet = prepareItemTextSet(newItem, item
.getItemTextSet(), protocol);
.getItemTextSet(), protocol, toContext);
Set newItemMetaDataSet = prepareItemMetaDataSet(newItem, item
.getItemMetaDataSet());
Set newItemFeedbackSet = prepareItemFeedbackSet(newItem, item
Expand All @@ -2241,7 +2241,7 @@ public Set prepareItemSet(SectionData newSection, Set itemSet,
return prepareItemSet(newSection, itemSet, protocol, null);
}

public Set prepareItemTextSet(ItemData newItem, Set itemTextSet, String protocol) {
public Set prepareItemTextSet(ItemData newItem, Set itemTextSet, String protocol, String toContext) {
log.debug("new item text size = " + itemTextSet.size());
HashSet h = new HashSet();
Iterator k = itemTextSet.iterator();
Expand All @@ -2255,7 +2255,7 @@ public Set prepareItemTextSet(ItemData newItem, Set itemTextSet, String protocol
newItemText.setAnswerSet(newAnswerSet);

Set itemTextAttachmentSet = this.prepareItemTextAttachmentSet(newItemText,
itemText.getItemTextAttachmentSet(), protocol);
itemText.getItemTextAttachmentSet(), protocol, toContext);
newItemText.setItemTextAttachmentSet(itemTextAttachmentSet);
newItemText.setRequiredOptionsCount(itemText.getRequiredOptionsCount());

Expand Down Expand Up @@ -2324,7 +2324,7 @@ public Set prepareItemAttachmentSet(ItemData newItem,

// EMI ItemText attachments
public Set prepareItemTextAttachmentSet(ItemText newItemText,
Set itemTextAttachmentSet, String protocol) {
Set itemTextAttachmentSet, String protocol, String toContext) {
HashSet h = new HashSet();
Iterator o = itemTextAttachmentSet.iterator();
while (o.hasNext()) {
Expand All @@ -2334,7 +2334,7 @@ public Set prepareItemTextAttachmentSet(ItemText newItemText,
AssessmentService service = new AssessmentService();
ContentResource cr_copy = service.createCopyOfContentResource(
itemTextAttachment.getResourceId(), itemTextAttachment
.getFilename());
.getFilename(), toContext);
// get relative path
String url = getRelativePath(cr_copy.getUrl(), protocol);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,22 +861,8 @@ public ContentResource createCopyOfContentResource(String resourceId,
ToolManager.getTool("sakai.samigo").getTitle(), cr
.getContentType(), cr.streamContent(), cr.getProperties());
}
} catch (IdInvalidException e) {
log.warn(e.getMessage());
} catch (PermissionException e) {
log.warn(e.getMessage());
} catch (IdUnusedException e) {
log.warn(e.getMessage());
} catch (TypeException e) {
log.warn(e.getMessage());
} catch (InconsistentException e) {
log.warn(e.getMessage());
} catch (IdUsedException e) {
log.warn(e.getMessage());
} catch (OverQuotaException e) {
log.warn(e.getMessage());
} catch (ServerOverloadException e) {
log.warn(e.getMessage());
} catch (Exception e) {
log.warn("Could not copy resource " + resourceId + ", " + e.getMessage());
}
return cr_copy;
}
Expand Down

0 comments on commit 3ff9947

Please sign in to comment.