Index: basiclti-blis/src/java/org/sakaiproject/blti/ServiceServlet.java =================================================================== --- basiclti-blis/src/java/org/sakaiproject/blti/ServiceServlet.java (revision 126763) +++ basiclti-blis/src/java/org/sakaiproject/blti/ServiceServlet.java (working copy) @@ -1084,13 +1084,23 @@ List> resultList = new ArrayList>(); recursivelyAddResourcesXML(context_id, thePage, nl, seq, resultList); + // One success means overall status is a success + boolean success = false; + for ( Map result : resultList ) { + if ( "success".equals(result.get("/status")) ) success = true; + } Map theMap = new TreeMap(); theMap.put("/addCourseResourcesResponse/resources/resource",resultList); String theXml = XMLMap.getXMLFragment(theMap, true); response.setContentType("application/xml"); - String output = pox.getResponseSuccess("Items Added",theXml); + String output = null; + if ( success ) { + output = pox.getResponseSuccess("Items Added",theXml); + } else { + output = pox.getResponseFailure("Items were not added", null); + } PrintWriter out = response.getWriter(); out.println(output); Index: basiclti-blis/src/java/org/sakaiproject/blti/LessonsFacade.java =================================================================== --- basiclti-blis/src/java/org/sakaiproject/blti/LessonsFacade.java (revision 126763) +++ basiclti-blis/src/java/org/sakaiproject/blti/LessonsFacade.java (working copy) @@ -105,7 +105,7 @@ SimplePage subPage = simplePageToolDao.makePage(actualPage.getToolId(), actualPage.getSiteId(), nameStr, parent, topParent); Listelist = new ArrayList(); simplePageToolDao.saveItem(subPage, elist, "ERROR WAS HERE", false); - System.out.println("Page Saved "+elist); + M_log.debug("Page Saved "+elist); // System.out.println("subPage="+subPage); String selectedEntity = String.valueOf(subPage.getPageId()); @@ -115,12 +115,13 @@ subPageItem.setFormat(""); elist = new ArrayList(); simplePageToolDao.saveItem(subPageItem, elist, "ERROR WAS HERE", false); - System.out.println("Item Saved "+elist); + M_log.debug("Item Saved "+elist); // System.out.println("subItem = "+subPageItem); return subPageItem; } public static String doImportTool(String siteId, String launchUrl, String bltiTitle, String strXml, String custom) + throws Exception { if ( ltiService == null ) return null; @@ -138,61 +139,59 @@ toolName = toolUrl; } + // Check for global tool configurations (prefer global) Map theTool = null; - List> tools = ltiService.getToolsDao(null,null,0,0,siteId); - String lastLaunch = ""; + List> tools = ltiService.getToolsDao(null,null,0,0,"!admin"); + String lastLaunch = ""; for ( Map tool : tools ) { String toolLaunch = (String) tool.get(LTIService.LTI_LAUNCH); + // Prefer the longest match if ( toolUrl.startsWith(toolLaunch) && toolLaunch.length() > lastLaunch.length()) { theTool = tool; - lastLaunch = toolLaunch; - break; + lastLaunch = toolLaunch; } } + // Check for within-site tool configurations (prefer global) if ( theTool == null ) { - M_log.debug("Inserting tool - "+toolUrl); - Properties props = new Properties (); - props.setProperty(LTIService.LTI_LAUNCH,toolUrl); - props.setProperty(LTIService.LTI_TITLE, toolName); - props.setProperty(LTIService.LTI_PAGETITLE, toolName); - props.setProperty(LTIService.LTI_CONSUMERKEY, LTIService.LTI_SECRET_INCOMPLETE); - props.setProperty(LTIService.LTI_SECRET, LTIService.LTI_SECRET_INCOMPLETE); - - props.setProperty(LTIService.LTI_ALLOWCUSTOM, "1"); - props.setProperty(LTIService.LTI_SENDNAME, "1"); - props.setProperty(LTIService.LTI_SENDEMAILADDR, "1"); - props.setProperty(LTIService.LTI_ALLOWTITLE, "1"); - props.setProperty(LTIService.LTI_ALLOWPAGETITLE, "1"); - props.setProperty(LTIService.LTI_ALLOWLAUNCH, "1"); - props.setProperty(LTIService.LTI_ALLOWOUTCOMES, "1"); - props.setProperty(LTIService.LTI_ALLOWROSTER, "1"); - - props.setProperty(LTIService.LTI_SITE_ID,siteId); - - // Go ahead and throw up... - Object result = ltiService.insertToolDao(props, siteId); - - if ( result instanceof String ) { - M_log.error("Could not insert tool - "+result); + tools = ltiService.getToolsDao(null,null,0,0,siteId); + lastLaunch = ""; + for ( Map tool : tools ) { + String toolLaunch = (String) tool.get(LTIService.LTI_LAUNCH); + // Prefer the longest match + if ( toolUrl.startsWith(toolLaunch) && toolLaunch.length() > lastLaunch.length()) { + theTool = tool; + lastLaunch = toolLaunch; + } } - if ( result instanceof Long ) theTool = ltiService.getToolDao((Long) result, siteId); } + + // If we still do not have a tool configuration throw an error + if ( theTool == null ) { + M_log.error("LORI Launch configuration not found- "+toolUrl); + throw new Exception("LORI Launch configuration not found"); + } + // Found a tool - time to insert content Map theContent = null; Long contentKey = null; if ( theTool != null ) { Properties props = new Properties (); - props.setProperty(LTIService.LTI_TOOL_ID,foorm.getLong(theTool.get(LTIService.LTI_ID)).toString()); - props.setProperty(LTIService.LTI_PLACEMENTSECRET, UUID.randomUUID().toString()); + String toolId = foorm.getLong(theTool.get(LTIService.LTI_ID)).toString(); + props.setProperty(LTIService.LTI_TOOL_ID,toolId); + props.setProperty(LTIService.LTI_PLACEMENTSECRET, UUID.randomUUID().toString()); props.setProperty(LTIService.LTI_TITLE, bltiTitle); props.setProperty(LTIService.LTI_PAGETITLE, bltiTitle); props.setProperty(LTIService.LTI_LAUNCH,launchUrl); + props.setProperty(LTIService.LTI_SITE_ID,siteId); + if ( strXml != null) props.setProperty(LTIService.LTI_XMLIMPORT,strXml); if ( custom != null ) props.setProperty(LTIService.LTI_CUSTOM,custom); - // Throw upwards.. - Object result = ltiService.insertContentDao(props, siteId); + M_log.debug("Inserting content - "+toolId); + + // Insert as admin into siteId, on error throw upwards + Object result = ltiService.insertContentDao(props, "!admin"); if ( result instanceof String ) { M_log.error("Could not insert content - "+result); } else { Index: basiclti-impl/src/java/org/sakaiproject/lti/impl/DBLTIService.java =================================================================== --- basiclti-impl/src/java/org/sakaiproject/lti/impl/DBLTIService.java (revision 126763) +++ basiclti-impl/src/java/org/sakaiproject/lti/impl/DBLTIService.java (working copy) @@ -270,7 +270,7 @@ Long visible = foorm.getLongNull(tool.get(LTIService.LTI_VISIBLE)); if ( visible == null ) visible = new Long(0); - if ( ! isAdmin(siteId) ) { + if ( ! isAdmin(siteId, isMaintainRole) ) { if ( visible == 1 ) { return rb.getString("error.invalid.toolid"); } @@ -371,7 +371,7 @@ // a tool that is stealthed Long visible = foorm.getLongNull(tool.get(LTIService.LTI_VISIBLE)); if ( visible == null ) visible = new Long(0); - if ( ( !isAdmin(siteId) ) && ( ! oldToolKey.equals(newToolKey) ) ) { + if ( ( !isAdmin(siteId, isMaintainRole) ) && ( ! oldToolKey.equals(newToolKey) ) ) { if ( visible == 1 ) { return rb.getString("error.invalid.toolid"); } @@ -432,7 +432,7 @@ theKey = foorm.formSqlKey(fullModel); } if ((Arrays.asList(columns).indexOf(LTIService.LTI_SITE_ID) >= 0)) { - if (!isAdmin(siteId) && newMapping.get(LTIService.LTI_SITE_ID) == null) { + if (!isAdmin(siteId, isMaintainRole) && newMapping.get(LTIService.LTI_SITE_ID) == null) { newMapping.put(LTIService.LTI_SITE_ID, siteId); } } @@ -514,7 +514,7 @@ Object fields[] = null; String[] columns = foorm.getFields(model); - if (siteId != null && Arrays.asList(columns).indexOf(LTIService.LTI_SITE_ID) >= 0 && !isAdmin(siteId)) { + if (siteId != null && Arrays.asList(columns).indexOf(LTIService.LTI_SITE_ID) >= 0 && !isAdmin(siteId, isMaintainRole)) { statement += " AND (SITE_ID = ? OR SITE_ID IS NULL)"; fields = new Object[2]; fields[0] = key; @@ -546,15 +546,15 @@ */ public List> getThingsDao(String table, String[] model, String search, String order, int first, int last, String siteId, boolean isMaintainRole) { - if (table == null || model == null || siteId == null ) { - throw new IllegalArgumentException("siteId, table, and model must be non-null"); + if (table == null || model == null ) { + throw new IllegalArgumentException("table and model must be non-null"); } String statement = "SELECT " + foorm.formSelect(model) + " FROM " + table; String[] columns = foorm.getFields(model); String whereClause = ""; Object fields[] = null; - if ( ! isAdmin(siteId) ) { + if ( ! isAdmin(siteId, isMaintainRole) ) { if (Arrays.asList(columns).indexOf(LTIService.LTI_VISIBLE) >= 0 && Arrays.asList(columns).indexOf(LTIService.LTI_SITE_ID) >= 0 ) { whereClause = " ("+LTIService.LTI_SITE_ID+" = ? OR "+ @@ -598,7 +598,7 @@ // Hack to insure that We *Can* delete this since SqlService cannot tell us if updates // work - if (!isAdmin(siteId)) { + if (!isAdmin(siteId, isMaintainRole)) { Object thing = getThingDao(table, model, key, siteId, isMaintainRole); if (thing == null || !(thing instanceof Map)) { return false; @@ -611,7 +611,7 @@ } } - if (Arrays.asList(columns).indexOf(LTIService.LTI_SITE_ID) >= 0 && !isAdmin(siteId) ) { + if (Arrays.asList(columns).indexOf(LTIService.LTI_SITE_ID) >= 0 && !isAdmin(siteId, isMaintainRole) ) { if (!isMaintainRole) { M_log.info("Non-maintain attemped delete on " + table); return false; @@ -679,7 +679,7 @@ } if ( (Arrays.asList(columns).indexOf(LTIService.LTI_SITE_ID) >= 0)) { - if ( !isAdmin(siteId) && newMapping.get(LTIService.LTI_SITE_ID) == null) { + if ( !isAdmin(siteId, isMaintainRole) && newMapping.get(LTIService.LTI_SITE_ID) == null) { newMapping.put(LTIService.LTI_SITE_ID, siteId); } } @@ -687,7 +687,7 @@ String sql = "UPDATE " + table + " SET " + foorm.updateForm(newMapping) + " WHERE id=" + key.toString(); - if ( isMaintainRole && !isAdmin(siteId) && (Arrays.asList(columns).indexOf(LTIService.LTI_SITE_ID) >= 0)) { + if ( isMaintainRole && !isAdmin(siteId, isMaintainRole) && (Arrays.asList(columns).indexOf(LTIService.LTI_SITE_ID) >= 0)) { sql += " AND SITE_ID = '" + siteId + "'"; foorm.setField(newMapping, LTIService.LTI_SITE_ID, siteId); } Index: basiclti-impl/src/java/org/sakaiproject/lti/impl/BaseLTIService.java =================================================================== --- basiclti-impl/src/java/org/sakaiproject/lti/impl/BaseLTIService.java (revision 126763) +++ basiclti-impl/src/java/org/sakaiproject/lti/impl/BaseLTIService.java (working copy) @@ -265,7 +265,7 @@ */ protected String[] getContentModelDao(Map tool, String siteId, boolean isMaintainRole) { String[] retval = foorm.filterForm(tool, CONTENT_MODEL); - if (!isAdmin(siteId)) retval = foorm.filterForm(null, retval, null, ".*:role=admin.*"); + if (!isAdmin(siteId, isMaintainRole)) retval = foorm.filterForm(null, retval, null, ".*:role=admin.*"); return retval; } @@ -352,11 +352,15 @@ } protected boolean isAdmin(String siteId) { + return isAdmin(siteId,isMaintain(siteId)); + } + + protected boolean isAdmin(String siteId, boolean isMaintainRole) { if ( siteId == null ) { throw new java.lang.RuntimeException("isAdmin() requires non-null siteId"); } if (!ADMIN_SITE.equals(siteId) ) return false; - return isMaintain(siteId); + return isMaintainRole; } /** @@ -865,7 +869,7 @@ String siteStr = (String) content.get(LTI_SITE_ID); // only admin can remve content from other site - if ( ! siteId.equals(siteStr) && !isAdmin() ) { + if ( ! siteId.equals(siteStr) && !isAdmin(siteId, isMaintainRole) ) { return rb.getString("error.placement.not.found"); }