Skip to content

Commit

Permalink
SAK-19035
Browse files Browse the repository at this point in the history
Created a new value for the "system" attribute of the main document element in the archive export files. The new value is "Sakai 2.8".
Export and merge code now looks for this new value. When it is encountered the site.xml file is processed differently. "roleId" is
now encoded as an attribute on a "role" element instead of using the value of "roleId" as the element name.

Processing of "Sakai 1.0" files remains the same. All processing of "Sakai 2.8" files are protected by conditional statements checking
for that value.


git-svn-id: https://source.sakaiproject.org/svn/common/trunk@82043 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
Duffy Gillman committed Sep 1, 2010
1 parent 7001c53 commit 154e066
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface ArchiveService

static final String FROM_SAKAI = "Sakai 1.0";

static final String FROM_SAKAI_2_8 = "Sakai 2.8";

// the list of boolean tells if the imported item needs to be set as draft
static final boolean SAKAI_msg_draft_import = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public String archive(String siteId)
root.setAttribute("source", siteId);
root.setAttribute("server", m_serverConfigurationService.getServerId());
root.setAttribute("date", now.toString());
root.setAttribute("system", FROM_SAKAI);
root.setAttribute("system", FROM_SAKAI_2_8);

stack.push(root);

Expand Down Expand Up @@ -268,7 +268,7 @@ public String archive(String siteId)
root.setAttribute("source", siteId);
root.setAttribute("server", m_serverConfigurationService.getServerId());
root.setAttribute("date", now.toString());
root.setAttribute("system", FROM_SAKAI);
root.setAttribute("system", FROM_SAKAI_2_8);

stack.push(root);

Expand All @@ -290,7 +290,7 @@ public String archive(String siteId)
doc.appendChild(root);
root.setAttribute("site", siteId);
root.setAttribute("date", now.toString());
root.setAttribute("system", FROM_SAKAI);
root.setAttribute("system", FROM_SAKAI_2_8);

stack.push(root);

Expand All @@ -308,7 +308,7 @@ public String archive(String siteId)
doc.appendChild(root);
root.setAttribute("site", siteId);
root.setAttribute("date", now.toString());
root.setAttribute("system", FROM_SAKAI);
root.setAttribute("system", FROM_SAKAI_2_8);

stack.push(root);

Expand Down Expand Up @@ -562,7 +562,7 @@ protected boolean checkSystemRole(String system, String roleId)
return true;
}
}
else if (system.equalsIgnoreCase(FROM_SAKAI))
else if (system.equalsIgnoreCase(FROM_SAKAI) || system.equalsIgnoreCase(FROM_SAKAI_2_8))
{
// Check - if CTools accepts the resource made by this role during importing
for (int i = 0; i <SAKAI_roles.length; i++)
Expand Down Expand Up @@ -736,7 +736,8 @@ else if (element.getTagName().equals(UserDirectoryService.APPLICATION_ID))
// if the xml file is from WT site, merge it with user id translation
if (system.equalsIgnoreCase(FROM_WT))
msg = service.merge(siteId, element, fileName, fromSite, attachmentNames, userIdTrans, new HashSet());
else if (system.equalsIgnoreCase(FROM_SAKAI) && (checkSakaiService(serviceName)))
else if ((system.equalsIgnoreCase(FROM_SAKAI) || system.equalsIgnoreCase(FROM_SAKAI_2_8))
&& (checkSakaiService(serviceName)))
msg = service.merge(siteId, element, fileName, fromSite, attachmentNames, new HashMap() /* empty userIdTran map */, UsersListAllowImport);
else if (system.equalsIgnoreCase(FROM_CT))
msg = service.merge(siteId, element, fileName, fromSite, attachmentNames, new HashMap() /* empty userIdTran map */, UsersListAllowImport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void destroy() {
*/
public String archive(String siteId)
{
return m_siteArchiver.archive(siteId, m_storagePath, FROM_SAKAI);
return m_siteArchiver.archive(siteId, m_storagePath, FROM_SAKAI_2_8);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.archive.api.ArchiveService;
import org.sakaiproject.authz.api.AuthzGroup;
import org.sakaiproject.authz.api.GroupNotDefinedException;
import org.sakaiproject.authz.api.Role;
Expand Down Expand Up @@ -201,7 +202,7 @@ public String archive(String siteId, String m_storagePath, String fromSystem)

stack.push(root);

String msg = archiveSite(theSite, doc, stack);
String msg = archiveSite(theSite, doc, stack, fromSystem);
results.append(msg);

stack.pop();
Expand Down Expand Up @@ -238,7 +239,7 @@ public String archive(String siteId, String m_storagePath, String fromSystem)
* element of the "site" element.
*/

protected String archiveSite(Site site, Document doc, Stack stack)
protected String archiveSite(Site site, Document doc, Stack stack, String fromSystem)
{
Element element = doc.createElement(SiteService.APPLICATION_ID);
((Element)stack.peek()).appendChild(element);
Expand Down Expand Up @@ -292,24 +293,33 @@ protected String archiveSite(Site site, Document doc, Stack stack)
stack.push(realmNode);

roles.addAll(realm.getRoles());

for (int i = 0; i< roles.size(); i++)
{
role = (Role) roles.get(i);
String roleId = role.getId();
Element node = doc.createElement(roleId);
realmNode.appendChild(node);

List users = new Vector();
users.addAll(realm.getUsersHasRole(role.getId()));
for (int j = 0; j < users.size(); j++)
{
Element abilityNode = doc.createElement("ability");
abilityNode.setAttribute("roleId", roleId);
abilityNode.setAttribute("userId", ((String)users.get(j)));
node.appendChild(abilityNode);
}
}

for (int i = 0; i< roles.size(); i++)
{
role = (Role) roles.get(i);
String roleId = role.getId();
Element node = null;
if (ArchiveService.FROM_SAKAI_2_8.equals(fromSystem))
{
node = doc.createElement("role");
node.setAttribute("roleId", roleId);
}
else
{
node = doc.createElement(roleId);
}
realmNode.appendChild(node);

List users = new Vector();
users.addAll(realm.getUsersHasRole(role.getId()));
for (int j = 0; j < users.size(); j++)
{
Element abilityNode = doc.createElement("ability");
abilityNode.setAttribute("roleId", roleId);
abilityNode.setAttribute("userId", ((String)users.get(j)));
node.appendChild(abilityNode);
}
}
}
catch(Exception any)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ else if (element.getTagName().equals(UserDirectoryService.APPLICATION_ID))
try
{
String msg = "";
if (system.equalsIgnoreCase(ArchiveService.FROM_SAKAI) && (checkSakaiService(filterSakaiService,filteredSakaiService, serviceName)))
if ((system.equalsIgnoreCase(ArchiveService.FROM_SAKAI) || system.equalsIgnoreCase(ArchiveService.FROM_SAKAI_2_8))
&& (checkSakaiService(filterSakaiService,filteredSakaiService, serviceName)))
msg = service.merge(siteId, element, fileName, fromSite, attachmentNames, new HashMap() /* empty userIdTran map */, UsersListAllowImport);

results.append(msg);
Expand Down Expand Up @@ -466,10 +467,22 @@ protected void mergeSiteRoles(Element el, String siteId, HashMap useIdTrans, boo
Node child = children.item(i);
if (child.getNodeType() != Node.ELEMENT_NODE) continue;
Element element2 = (Element)child;

String roleId = null;

if (ArchiveService.FROM_SAKAI_2_8.equals(source))
{
if (!"role".equals(element2.getTagName())) continue;

roleId = element2.getAttribute("roleId");
}
else
{
roleId = element2.getTagName();
}

//SWG Getting rid of WT part above, this was previously the else branch labeled "for both CT classic and Sakai CTools"
// check is this roleId is a qualified one
if (!checkSystemRole(source, element2.getTagName(), filterSakaiRoles, filteredSakaiRoles)) continue;
if (!checkSystemRole(source, roleId, filterSakaiRoles, filteredSakaiRoles)) continue;

NodeList children2 = element2.getChildNodes();
final int length2 = children2.getLength();
Expand Down Expand Up @@ -562,7 +575,7 @@ protected void unlock(String lock, String reference) throws PermissionException
* @return boolean value - true: the role is accepted for importing; otherwise, not;
*/
protected boolean checkSystemRole(String system, String roleId, boolean filterSakaiRoles, String[] filteredSakaiRoles) {
if (system.equalsIgnoreCase(ArchiveService.FROM_SAKAI)) {
if (system.equalsIgnoreCase(ArchiveService.FROM_SAKAI) || system.equalsIgnoreCase(ArchiveService.FROM_SAKAI_2_8)) {
if (filterSakaiRoles)
{
for (int i = 0; i <filteredSakaiRoles.length; i++)
Expand Down

0 comments on commit 154e066

Please sign in to comment.