Skip to content

Commit

Permalink
SAK-28971; site copy does not map direct url
Browse files Browse the repository at this point in the history
  • Loading branch information
clhedrick committed Jan 22, 2015
1 parent afa1f72 commit 00cfb49
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ public interface ShortenedUrlService {
*/
public String resolve(String key);



/**
* Specify whether the short form of the URL should be placed in the transversal map
* when duplicating sites. If so, SiteAction will call shorten on the URL. Depending
* upon the implementation, it may not be desirable to call shorten once for each
* tool, so implementations may choose to return false all the time, or return true
* only if there is reason to think that this specific URL has been shortened.
*
* @param url
* @return true if this URL should be shortened by SiteAction in duplicating sites
*/
public boolean shouldCopy(String url);

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public String resolve(String key) {
return service.resolve(key);
}

/**
* @{inheritDoc}
*/
public boolean shouldCopy(String url) {
return service.shouldCopy(url);
}

private ServerConfigurationService serverConfigurationService;
public void setServerConfigurationService(ServerConfigurationService serverConfigurationService) {
this.serverConfigurationService = serverConfigurationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,12 @@ public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}

/*
* this is a placeholder until someone who understands bitly decides what the
* right approach is
*/
public boolean shouldCopy(String url) {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ public void init() {
log.debug("Sakai NoOpUrlService init().");
}

/**
* since the short URL is the same as the original, there's no
* point in adding it to the transversal map along with the original
*/
public boolean shouldCopy(String url) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ public Object doInHibernate(Session session) throws HibernateException, SQLExcep
return key;
}

/**
* See if we should include this in the transversal map. Do so only
* if a mapping exists, since otherwise there can't be any references
* to it.
*/
public boolean shouldCopy(String url) {
return (getExistingKey(url) != null);
}

/**
* Checks if a given key is unique by checking for its existence
* @param key
Expand Down
4 changes: 4 additions & 0 deletions site-manage/site-manage-tool/tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
<groupId>org.sakaiproject.userauditservice</groupId>
<artifactId>userauditservice-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.shortenedurl</groupId>
<artifactId>shortenedurl-api</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
import org.sakaiproject.user.cover.UserDirectoryService;
import org.sakaiproject.userauditservice.api.UserAuditRegistration;
import org.sakaiproject.userauditservice.api.UserAuditService;
import org.sakaiproject.shortenedurl.api.ShortenedUrlService;
import org.sakaiproject.util.*;
// for basiclti integration

Expand Down Expand Up @@ -215,6 +216,8 @@ public class SiteAction extends PagedResourceActionII {
private static org.sakaiproject.sitemanage.api.UserNotificationProvider userNotificationProvider = (org.sakaiproject.sitemanage.api.UserNotificationProvider) ComponentManager
.get(org.sakaiproject.sitemanage.api.UserNotificationProvider.class);

private static ShortenedUrlService shortenedUrlService = (ShortenedUrlService) ComponentManager.get(ShortenedUrlService.class);

private static final String SITE_MODE_SITESETUP = "sitesetup";

private static final String SITE_MODE_SITEINFO = "siteinfo";
Expand Down Expand Up @@ -13006,7 +13009,7 @@ protected Map transferCopyEntities(String toolId, String fromContext,
// TODO: used to offer to resources first - why? still needed? -ggolden

Map transversalMap = new HashMap();

// offer to all EntityProducers
for (Iterator i = EntityManager.getEntityProducers().iterator(); i
.hasNext();) {
Expand Down Expand Up @@ -13035,6 +13038,50 @@ protected Map transferCopyEntities(String toolId, String fromContext,
}
}

// record direct URL for this tool in old and new sites, so anyone using the URL in HTML text will
// get a proper update for the HTML in the new site
// Some tools can have more than one instance. Because getTools should always return tools
// in order, we can assume that if there's more than one instance of a tool, the instances
// correspond

Site fromSite = null;
Site toSite = null;
Collection<ToolConfiguration> fromTools = null;
Collection<ToolConfiguration> toTools = null;
try {
fromSite = SiteService.getSite(fromContext);
toSite = SiteService.getSite(toContext);
fromTools = fromSite.getTools(toolId);
toTools = toSite.getTools(toolId);
} catch (Exception e) {
M_log.warn(this + "transferCopyEntities: can't get site:" + e.getMessage());
}

// getTools appears to return tools in order. So we should be able to match them
if (fromTools != null && toTools != null) {
Iterator<ToolConfiguration> toToolIt = toTools.iterator();
// step through tools in old and new site in parallel
// I believe the first time this is called for a given
// tool all instances will be copied, but stop if not
// all instances have been copied yet
for (ToolConfiguration fromTool: fromTools) {
if (toToolIt.hasNext()) {
ToolConfiguration toTool = toToolIt.next();
String fromUrl = ServerConfigurationService.getPortalUrl() + "/directtool/" + Web.escapeUrl(fromTool.getId()) + "/";
String toUrl = ServerConfigurationService.getPortalUrl() + "/directtool/" + Web.escapeUrl(toTool.getId()) + "/";
if (transversalMap.get(fromUrl) == null)
transversalMap.put(fromUrl, toUrl);
if (shortenedUrlService.shouldCopy(fromUrl)) {
fromUrl = shortenedUrlService.shorten(fromUrl, false);
toUrl = shortenedUrlService.shorten(toUrl, false);
if (fromUrl != null && toUrl != null)
transversalMap.put(fromUrl, toUrl);
}
} else
break;
}
}

return transversalMap;
}

Expand Down

0 comments on commit 00cfb49

Please sign in to comment.