refinement: Add support to find other invalid links
diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FindErroneousEmbeddedLinksBlam.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FindErroneousEmbeddedLinksBlam.java
index 178703a..3df13c0 100644
--- a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FindErroneousEmbeddedLinksBlam.java
+++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FindErroneousEmbeddedLinksBlam.java
@@ -118,11 +118,22 @@
private void findIncorrectLinks(Artifact artifact, String content, ISheetWriter excelWriter) throws IOException {
Set<String> unknownGuids = new HashSet<>();
- HashCollection<String, MatchRange> links = WordMlLinkHandler.getLinks(content);
+ HashCollection<String, MatchRange> errorMap = new HashCollection<>();
+ HashCollection<String, MatchRange> links = WordMlLinkHandler.getLinks(content, errorMap);
if (!links.isEmpty()) {
unknownGuids.addAll(links.keySet());
}
+ findInvalid(artifact, excelWriter, unknownGuids);
+ unknownGuids.clear();
+ if (!errorMap.isEmpty()) {
+ unknownGuids.addAll(errorMap.keySet());
+ }
+ findInvalid(artifact, excelWriter, unknownGuids);
+
+ }
+
+ private void findInvalid(Artifact artifact, ISheetWriter excelWriter, Set<String> unknownGuids) throws IOException {
Iterator<String> guidIter = unknownGuids.iterator();
while (guidIter.hasNext()) {
// Pointing to itself
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/OseeLinkParser.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/OseeLinkParser.java
index cb2b023..ff4db67 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/OseeLinkParser.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/OseeLinkParser.java
@@ -30,18 +30,33 @@
private static final Matcher PARAMETER_MATCHER = Pattern.compile("([^&]*?)=([^&]*)").matcher("");
private final Map<String, String> parameterMap;
+ private final Map<String, String> errorParamMap;
public OseeLinkParser() {
this.parameterMap = new HashMap<>();
+ this.errorParamMap = new HashMap<>();
}
public void parse(String link) {
parameterMap.clear();
+ errorParamMap.clear();
link = link.replaceAll("&", "&");
boolean wasHandled = parseOldSchoolStyleLinks(link);
+
if (!wasHandled) {
- parseNewStyleRequests(link);
+ wasHandled = parseNewStyleRequests(link);
}
+
+ if (!wasHandled) {
+ errorParamMap.put("linkerr", link);
+ }
+ }
+
+ public String getErrLink() {
+ if (errorParamMap != null) {
+ return errorParamMap.get("linkerr");
+ }
+ return null;
}
public BranchId getId() throws OseeCoreException {
@@ -85,7 +100,8 @@
* Process new style requests are of the following format: http://127.0.0.1:<port>/
* <ProcessType>?key1=value1&key2=value2...&key3=value3
*/
- private void parseNewStyleRequests(String link) {
+ private boolean parseNewStyleRequests(String link) {
+ boolean wasHandled = false;
String noHostStr = link.replaceFirst("^http:\\/\\/(.*?)\\/", "/");
Matcher matcher = LINK_CONTEXT_MATCHER;
matcher.reset(noHostStr);
@@ -94,8 +110,10 @@
dataMatcher.reset(matcher.group(2));
while (dataMatcher.find()) {
parameterMap.put(dataMatcher.group(1), dataMatcher.group(2));
+ wasHandled = true;
}
}
+ return wasHandled;
}
/**
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/WordMlLinkHandler.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/WordMlLinkHandler.java
index e2705a9..2677b2e 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/WordMlLinkHandler.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/WordMlLinkHandler.java
@@ -102,7 +102,7 @@
public static String unlink(LinkType sourceLinkType, Artifact source, String content) throws OseeCoreException {
LinkType linkType = checkLinkType(sourceLinkType);
String modified = content;
- HashCollection<String, MatchRange> matchMap = parseOseeWordMLLinks(content);
+ HashCollection<String, MatchRange> matchMap = parseOseeWordMLLinks(content, new HashCollection<>());
if (!matchMap.isEmpty()) {
modified = modifiedContent(linkType, source, content, matchMap, true, null);
}
@@ -125,7 +125,7 @@
LinkType linkType = checkLinkType(destLinkType);
String modified = content;
- HashCollection<String, MatchRange> matchMap = getLinks(content);
+ HashCollection<String, MatchRange> matchMap = getLinks(content, new HashCollection<>());
if (!matchMap.isEmpty()) {
modified = modifiedContent(linkType, source, content, matchMap, false, unknownGuids, presentationType);
unknownGuids.addAll(matchMap.keySet());
@@ -137,9 +137,9 @@
return modified;
}
- public static HashCollection<String, MatchRange> getLinks(String content) {
+ public static HashCollection<String, MatchRange> getLinks(String content, HashCollection<String, MatchRange> errorMap) {
// Detect legacy links
- HashCollection<String, MatchRange> matchMap = parseOseeWordMLLinks(content);
+ HashCollection<String, MatchRange> matchMap = parseOseeWordMLLinks(content, errorMap);
// Detect new style link marker
OSEE_LINK_PATTERN.reset(content);
@@ -147,6 +147,8 @@
String guid = OSEE_LINK_PATTERN.group(1);
if (Strings.isValid(guid)) {
matchMap.put(guid, new MatchRange(OSEE_LINK_PATTERN.start(), OSEE_LINK_PATTERN.end()));
+ } else {
+ errorMap.put(guid, new MatchRange(WORDML_LINK.start(), WORDML_LINK.end()));
}
}
OSEE_LINK_PATTERN.reset();
@@ -158,7 +160,7 @@
*
* @return locations where WordMlLinks were found grouped by GUID
*/
- private static HashCollection<String, MatchRange> parseOseeWordMLLinks(String content) throws OseeCoreException {
+ private static HashCollection<String, MatchRange> parseOseeWordMLLinks(String content, HashCollection<String, MatchRange> errorMap) throws OseeCoreException {
HashCollection<String, MatchRange> matchMap = new HashCollection<>();
OseeLinkParser linkParser = new OseeLinkParser();
WORDML_LINK.reset(content);
@@ -169,6 +171,8 @@
String guid = linkParser.getGuid();
if (Strings.isValid(guid)) {
matchMap.put(guid, new MatchRange(WORDML_LINK.start(), WORDML_LINK.end()));
+ } else {
+ errorMap.put(linkParser.getErrLink(), new MatchRange(WORDML_LINK.start(), WORDML_LINK.end()));
}
}
}
@@ -182,6 +186,9 @@
String guid = linkParser.getGuid();
if (Strings.isValid(guid)) {
matchMap.put(guid, new MatchRange(HYPERLINK_PATTERN.start(), HYPERLINK_PATTERN.end()));
+ } else {
+ errorMap.put(linkParser.getErrLink(),
+ new MatchRange(HYPERLINK_PATTERN.start(), HYPERLINK_PATTERN.end()));
}
}
}