Skip to content

Commit

Permalink
refactor BotHtml, remove crawler guidance (should not try to use hash…
Browse files Browse the repository at this point in the history
… bang), and fix many instances of relying on the fragment for the href (now that it is a path, include /
  • Loading branch information
jay-hodgson committed May 15, 2024
1 parent f43a36b commit 76fd3c2
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 70 deletions.
23 changes: 1 addition & 22 deletions src/main/java/org/sagebionetworks/web/client/DisplayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,7 @@ public static String uppercaseFirstLetter(String display) {

public static String getTeamHistoryToken(String teamId) {
Team place = new Team(teamId);
return getTeamPlaceString(Team.class) + ":" + place.toToken();
}

public static String getTrashHistoryToken(String token, Integer start) {
Trash place = new Trash(token, start);
return getTrashPlaceString(Trash.class) + ":" + place.toToken();
return "/" + getTeamPlaceString(Team.class) + ":" + place.toToken();
}

public static String getSynapseHistoryToken(String entityId) {
Expand Down Expand Up @@ -705,22 +700,6 @@ private static String getTeamPlaceString(Class<Team> place) {
return getPlaceString(place.getName());
}

private static String getTeamSearchPlaceString(Class<TeamSearch> place) {
return getPlaceString(place.getName());
}

private static String getPeopleSearchPlaceString(Class<PeopleSearch> place) {
return getPlaceString(place.getName());
}

private static String getTrashPlaceString(Class<Trash> place) {
return getPlaceString(place.getName());
}

private static String getSearchPlaceString(Class<Search> place) {
return getPlaceString(place.getName());
}

private static String getPlaceString(String fullPlaceName) {
fullPlaceName = fullPlaceName.replaceAll(".+\\.", "");
return fullPlaceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ public static String getHrefForDotVersion(String dotNotation) {
if (dotNotation == null) {
return null;
}
return SYNAPSE_ENTITY_PREFIX + dotNotation.toLowerCase();
return "/" + SYNAPSE_ENTITY_PREFIX + dotNotation.toLowerCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public DockerRepoListGroupItem(

Heading heading = new Heading(size);
anchor.setText("Loading...");
anchor.setHref("Synapse:" + entityHeader.getId());
anchor.setHref("/Synapse:" + entityHeader.getId());
anchor.addClickHandler(event -> {
if (!DisplayUtils.isAnyModifierKeyDown(event)) {
event.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void setEntity(final EntityHeader entityHeader) {
entityAnchor.addStyleName(
"text-align-left text-overflow-ellipsis inline-block whitespace-nowrap overflowHidden maxWidth100"
);
entityAnchor.setHref("Synapse:" + entityHeader.getId());
entityAnchor.setHref("/Synapse:" + entityHeader.getId());
entityAnchor
.getElement()
.setAttribute(ENTITY_ID_ATTRIBUTE, entityHeader.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void showNoPreviewAvailable(String entityId, Long version) {
alert.add(new Text("No preview is available for"));
Anchor link = new Anchor();
link.addStyleName("margin-left-5");
link.setHref("Synapse:" + entityId + versionString);
link.setHref("/Synapse:" + entityId + versionString);
link.addClickHandler(event -> {
event.preventDefault();
placeChanger.goTo(new Synapse(entityId, version, null, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void configure(String challengeId, Callback callback) {
this.challengeId = challengeId;
view.setRecruitmentMessage("");
view.setNewTeamLink(
"Profile:" +
"/Profile:" +
authenticationController.getCurrentUserPrincipalId() +
Profile.DELIMITER +
Synapse.ProfileArea.TEAMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void configure(
String queryToken = queryTokenProvider.queryToToken(query);
view.setSourceDataLinkVisible(false);
view.setSourceDataLink(
"Synapse:" +
"/Synapse:" +
qbr.getEntityId() +
"/" +
TABLES.toString().toLowerCase() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void showNoRestrictionsUI() {
public void showFolderRestrictionsLink(String entityId) {
folderViewTermsLink.setVisible(true);
folderViewTermsLink.setHref(
"AccessRequirements:TYPE=ENTITY&ID=" + entityId
"/AccessRequirements:TYPE=ENTITY&ID=" + entityId
);
folderViewTermsLink.setTarget("_blank");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void configure(

@Override
public void updateHref(Synapse place) {
anchor.setHref("Synapse:" + place.toToken());
anchor.setHref("/Synapse:" + place.toToken());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void configure(EntityHeader header) {
entityAnchor.addClickHandler(EntityBadgeViewImpl.STANDARD_CLICKHANDLER);
entityAnchor.setText(header.getName());
entityAnchor.addStyleName("link");
entityAnchor.setHref("Synapse:" + header.getId());
entityAnchor.setHref("/Synapse:" + header.getId());
entityAnchor
.getElement()
.setAttribute(EntityBadgeViewImpl.ENTITY_ID_ATTRIBUTE, header.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void setTeam(final Team team, String description, String teamIconUrl) {
descriptionContainer.add(new HTML(linkify.linkify(descriptionWithoutHtml)));

nameLink.setText(name);
nameLink.setHref("Team:" + team.getId());
nameLink.setHref("/Team:" + team.getId());
pictureFocusPanel.addClickHandler(clickHandler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public VerificationSubmissionWidget configure(
initView(isModal);
view.setProfileLink(
verificationSubmission.getCreatedBy(),
"Profile:" + verificationSubmission.getCreatedBy()
"/Profile:" + verificationSubmission.getCreatedBy()
);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.sagebionetworks.web.server.servlet.filter;

public class BotHtml {

private String head = "";
private String body = "";

public BotHtml() {}

public BotHtml(String head, String body) {
this.head = head;
this.body = body;
}

public String getHead() {
return head;
}

public void setHead(String head) {
this.head = head;
}

public String getBody() {
return body;
}

public void setBody(String body) {
this.body = body;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,6 @@ public static String getPlainTextWiki(String entityId, WikiPage rootPage) {
return plainTextWiki;
}

public class BotHtml {

public String head = "";
public String body = "";
}

public BotHtml getEntityHtml(EntityBundle bundle)
throws RestServiceException, JSONObjectAdapterException, SynapseException {
BotHtml response = new BotHtml();
Expand Down Expand Up @@ -288,7 +282,7 @@ public BotHtml getEntityHtml(EntityBundle bundle)
StringBuilder html = new StringBuilder();

if (annotations.getAnnotations().containsKey("noindex")) {
response.head = META_ROBOTS_NOINDEX;
response.setHead(META_ROBOTS_NOINDEX);
}

html.append("<h1>" + name + "</h1>");
Expand Down Expand Up @@ -365,7 +359,7 @@ public BotHtml getEntityHtml(EntityBundle bundle)
request.setNextPageToken(childList.getNextPageToken());
i++;
} while (i < MAX_CHILD_PAGES && childList.getNextPageToken() != null);
response.body = html.toString();
response.setBody(html.toString());

// SWC-6609: removed for now
// response.head = getDatasetScriptElement(bundle, plainTextWiki);
Expand Down Expand Up @@ -562,8 +556,8 @@ public BotHtml getProfileHtml(UserProfile profile)
"\" />"
);

response.head = head.toString();
response.body = html.toString();
response.setHead(head.toString());
response.setBody(html.toString());

return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.GZIPInputStream;
Expand Down Expand Up @@ -38,6 +40,7 @@
import org.sagebionetworks.web.server.servlet.SynapseProvider;
import org.sagebionetworks.web.server.servlet.SynapseProviderImpl;
import org.sagebionetworks.web.server.servlet.UserDataProvider;
import org.sagebionetworks.web.shared.SearchQueryUtils;
import org.sagebionetworks.web.shared.WebConstants;
import org.springframework.web.filter.OncePerRequestFilter;

Expand Down Expand Up @@ -212,27 +215,35 @@ protected void doFilterInternal(
dataModel.put(PAGE_DESCRIPTION_KEY, description);

if (includeBotHtml) {
CrawlFilter.BotHtml botHtml = crawlFilter.getEntityHtml(bundle);
dataModel.put(BOT_HEAD_HTML_KEY, botHtml.head);
dataModel.put(BOT_BODY_HTML_KEY, botHtml.body);
BotHtml botHtml = crawlFilter.getEntityHtml(bundle);
dataModel.put(BOT_HEAD_HTML_KEY, botHtml.getHead());
dataModel.put(BOT_BODY_HTML_KEY, botHtml.getBody());
}
}
} else if (uri.startsWith("/Search")) {
// index all projects
String searchQueryJson = uri.substring(uri.indexOf(":") + 1);
SearchQuery inputQuery = EntityFactory.createEntityFromJSONString(
searchQueryJson,
SearchQuery.class
);
String searchQueryRawValue = uri.substring(uri.indexOf(":") + 1);
SearchQuery query = SearchQueryUtils.getDefaultSearchQuery();
try {
query =
EntityFactory.createEntityFromJSONString(
URLDecoder.decode(searchQueryRawValue, "UTF-8"),
SearchQuery.class
);
} catch (Exception e) {
query.setQueryTerm(
Collections.singletonList(searchQueryRawValue)
);
}
dataModel.put(
PAGE_TITLE_KEY,
"Searching for: " + inputQuery.getQueryTerm()
"Searching for: " + query.getQueryTerm().get(0)
);

if (includeBotHtml) {
dataModel.put(
BOT_BODY_HTML_KEY,
crawlFilter.getAllProjectsHtml(inputQuery)
crawlFilter.getAllProjectsHtml(query)
);
}
} else if (path.startsWith("/TeamSearch")) {
Expand Down Expand Up @@ -276,11 +287,9 @@ protected void doFilterInternal(
dataModel.put(PAGE_DESCRIPTION_KEY, profile.getSummary());

if (includeBotHtml) {
CrawlFilter.BotHtml botHtml = crawlFilter.getProfileHtml(
profile
);
dataModel.put(BOT_HEAD_HTML_KEY, botHtml.head);
dataModel.put(BOT_BODY_HTML_KEY, botHtml.body);
BotHtml botHtml = crawlFilter.getProfileHtml(profile);
dataModel.put(BOT_HEAD_HTML_KEY, botHtml.getHead());
dataModel.put(BOT_BODY_HTML_KEY, botHtml.getBody());
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/webapp/Portal.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@
<![endif]-->

<!-- SWC-6609 removed <script src="js/json-ld-element-loader.js"></script> -->

<!--
Adding the following meta tag should tell the crawler to try to crawl the ugly version of *this* URL.
-->
<meta name="fragment" content="!" />
<meta http-equiv="x-dns-prefetch-control" content="off" />

<!-- meta to instruct browser not to cache portal.html -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.sagebionetworks.repo.model.entitybundle.v2.EntityBundleRequest;
import org.sagebionetworks.schema.adapter.JSONObjectAdapterException;
import org.sagebionetworks.web.server.servlet.DiscussionForumClientImpl;
import org.sagebionetworks.web.server.servlet.filter.BotHtml;
import org.sagebionetworks.web.server.servlet.filter.CrawlFilter;
import org.sagebionetworks.web.server.servlet.filter.CrawlFilter.BotHtml;
import org.sagebionetworks.web.shared.exceptions.RestServiceException;

@RunWith(MockitoJUnitRunner.class)
Expand Down
Loading

0 comments on commit 76fd3c2

Please sign in to comment.