Skip to content

Commit

Permalink
More cleanup - restire site id on tool edit when non-blank
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Jan 22, 2025
1 parent d4054d3 commit d290214
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,6 @@ protected String archiveSite(Site site, Document doc, Stack stack, String fromSy
}
}

// /access/lti/site/22153323-3037-480f-b979-c630e3e2b3cf/content:1
Pattern ltiPattern = null;

try {
ltiPattern = Pattern.compile(LTIService.LAUNCH_CONTENT_REGEX);
}
catch (Exception e) {
ltiPattern = null;
}

NodeList nl = siteNode.getElementsByTagName("property");
List<Element> toRemove = new ArrayList<Element>();

Expand All @@ -351,12 +341,10 @@ protected String archiveSite(Site site, Document doc, Stack stack, String fromSy
}
}

if ( ltiPattern != null && propname.equals("source") ) {
if ( propname.equals("source") ) {
String propvalue = Xml.decodeAttribute(proptag, "value");
Matcher ltiMatcher = ltiPattern.matcher(propvalue);
if (ltiMatcher.find()) {
String number = ltiMatcher.group(1);
Long contentKey = NumberUtils.toLong(number, -1);
Long contentKey = ltiService.getContentKeyFromLaunch(propvalue);
if ( contentKey > 0 ) {
Element contentElement = ltiService.archiveContentByKey(doc, contentKey, site.getId());
// Attach to the <tool> tag
if ( contentElement != null ) proptag.getParentNode().getParentNode().appendChild(contentElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,6 @@ protected void mergeSite(String siteId, String fromSiteId, Element element, Hash
{
String source = "";

// If this is a sakai.web.168 tool we need to check if the
//source URL matches the content launch pattern:
// /access/lti/site/22153323-3037-480f-b979-c630e3e2b3cf/content:1
Pattern ltiPattern = null;
try {
ltiPattern = Pattern.compile(LTIService.LAUNCH_CONTENT_REGEX);
}
catch (Exception e) {
ltiPattern = null;
}

Node parent = element.getParentNode();
if (parent.getNodeType() == Node.ELEMENT_NODE)
{
Expand Down Expand Up @@ -519,7 +508,7 @@ protected void mergeSite(String siteId, String fromSiteId, Element element, Hash
// If this is a sakai.web.168 that launches an LTI url
// import the associated content item and tool and re-link them
// to the tool placement
if ( ltiPattern != null && LTIService.WEB_PORTLET.equals(toolId) ) {
if ( LTIService.WEB_PORTLET.equals(toolId) ) {
Element foundProperty = null;
NodeList propertyChildren = element3.getElementsByTagName("property");
for(int i3 = 0; i3 < propertyChildren.getLength(); i3++)
Expand All @@ -528,8 +517,7 @@ protected void mergeSite(String siteId, String fromSiteId, Element element, Hash
String propname = propElement.getAttribute("name");
if ( "source".equals(propname) ) {
String propvalue = Xml.decodeAttribute(propElement, "value");
Matcher ltiMatcher = ltiPattern.matcher(propvalue);
if (ltiMatcher.find()) {
if ( ltiService.getContentKeyFromLaunch(propvalue) > 0 ) {
foundProperty = propElement;
break;
}
Expand Down
4 changes: 4 additions & 0 deletions lti/docs/IMPORTCC.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ Then continue to import another course, fix its LTI tools, and so forth. The th
importing 100 sites, and ending up with 300 broken stub tools that need to be fixed by hand or
transferred to another tool instance.

Also keep in mind the power of Tool Transfer versus Tool Delete. If you delete a tool, all the
associated content items are deleted. If you transfer the content items to a new tool and delete
the tool, nothing is lost.




Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ public String buildToolEditPanelContext(VelocityPortlet portlet, Context context
context.put("issuerURL", SakaiLTIUtil.getIssuer(siteId));

// If siteId is not blank, there is no option for visibility since the tool is always be visible in the site; otherwise, the tool can be visible or stealth
String excludePattern = StringUtils.isNotEmpty(siteId) ? "^SITE_ID:.*|visible:.*" : "^SITE_ID:.*";
String excludePattern = StringUtils.isNotEmpty(siteId) ? "^visible:.*" : "^SITE_ID:.*";
String[] mappingForm = foorm.filterForm(ltiService.getToolModel(getSiteId(state)), null, excludePattern);
String formInput = ltiService.formInput(tool, mappingForm);
context.put("formInput", formInput);
Expand Down

0 comments on commit d290214

Please sign in to comment.