Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormegumi.telles2017-08-09 10:32:17 -0400
committerMorgan E. Cook2017-08-09 14:58:39 -0400
commit5ca07e8816cda0c16e488ce67b01a84c061344c1 (patch)
tree280f42866fbe2211c4831905103f03746d62b3aa
parentdc8cb34328ae6b8dd7cb7ae8f506b4c022bf0953 (diff)
downloadorg.eclipse.osee-5ca07e8816cda0c16e488ce67b01a84c061344c1.tar.gz
org.eclipse.osee-5ca07e8816cda0c16e488ce67b01a84c061344c1.tar.xz
org.eclipse.osee-5ca07e8816cda0c16e488ce67b01a84c061344c1.zip
refinement: Add word hyperlink check
Signed-off-by: Morgan E. Cook <morgan.e.cook@boeing.com> Change-Id: I403cb5394927d66fe69d3a15c9becc46eeac2ce0
-rw-r--r--plugins/org.eclipse.osee.define/plugin.xml6
-rw-r--r--plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FindErroneousEmbeddedLinksBlam.java116
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/WordMlLinkHandler.java22
3 files changed, 136 insertions, 8 deletions
diff --git a/plugins/org.eclipse.osee.define/plugin.xml b/plugins/org.eclipse.osee.define/plugin.xml
index d959bb6523..b24e60de91 100644
--- a/plugins/org.eclipse.osee.define/plugin.xml
+++ b/plugins/org.eclipse.osee.define/plugin.xml
@@ -285,4 +285,10 @@
className="org.eclipse.osee.define.traceability.blam.RemoveObjectIdsFromTraceUnits">
</Operation>
</extension>
+ <extension
+ point="org.eclipse.osee.framework.ui.skynet.BlamOperation">
+ <Operation
+ className="org.eclipse.osee.define.blam.operation.FindErroneousEmbeddedLinksBlam">
+ </Operation>
+ </extension>
</plugin>
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
new file mode 100644
index 0000000000..5eb32b9eb3
--- /dev/null
+++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FindErroneousEmbeddedLinksBlam.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.define.blam.operation;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.osee.framework.core.data.BranchId;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.jdk.core.type.HashCollection;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
+import org.eclipse.osee.framework.skynet.core.artifact.search.QueryBuilderArtifact;
+import org.eclipse.osee.framework.skynet.core.linking.WordMlLinkHandler;
+import org.eclipse.osee.framework.skynet.core.linking.WordMlLinkHandler.MatchRange;
+import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam;
+import org.eclipse.osee.framework.ui.skynet.blam.VariableMap;
+
+/**
+ * @author Megumi Telles
+ */
+public class FindErroneousEmbeddedLinksBlam extends AbstractBlam {
+
+ private static final String BRANCH = "Branch Input";
+
+ @Override
+ public String getXWidgetsXml() throws OseeCoreException {
+ return String.format("<xWidgets><XWidget xwidgetType=\"XBranchSelectWidget\" displayName=\"%s\"/></xWidgets>",
+ BRANCH);
+ }
+
+ @Override
+ public String getDescriptionUsage() {
+ return "For a given branch, locate all WordTemplateContent attributes and list those artifacts with hyperlinks pointing to itself";
+ }
+
+ @Override
+ public String getName() {
+ return "Find Erroneous Hyperlinks";
+ }
+
+ @Override
+ public void runOperation(VariableMap variableMap, IProgressMonitor monitor) throws Exception {
+ BranchId branch = variableMap.getBranch(BRANCH);
+ QueryBuilderArtifact queryBuilder = ArtifactQuery.createQueryBuilder(branch);
+ queryBuilder.andExists(CoreAttributeTypes.WordTemplateContent);
+ ResultSet<Artifact> arts = queryBuilder.getResults();
+ Iterator<Artifact> artIter = arts.iterator();
+ while (artIter.hasNext()) {
+ Artifact artifact = artIter.next();
+ if (artifact.isAttributeTypeValid(CoreAttributeTypes.WordTemplateContent)) {
+ try {
+ String content = artifact.getSoleAttributeValueAsString(CoreAttributeTypes.WordTemplateContent, "");
+ if (Strings.isValid(content)) {
+ findIncorrectLinks(artifact, content);
+ }
+ } catch (OseeCoreException ex) {
+ logf("Artifact: [%s]: [%s]", artifact.getName(), ex);
+ }
+ }
+ artIter.remove();
+ }
+ }
+
+ private void findIncorrectLinks(Artifact artifact, String content) {
+ Set<String> unknownGuids = new HashSet<>();
+ HashCollection<String, MatchRange> links = WordMlLinkHandler.getLinks(content);
+ if (!links.isEmpty()) {
+ unknownGuids.addAll(links.keySet());
+ }
+
+ Iterator<String> guidIter = unknownGuids.iterator();
+ while (guidIter.hasNext()) {
+ // Pointing to itself
+ String linkGuid = guidIter.next();
+ logLinksToSelf(artifact, linkGuid);
+ logInvalidGuidLink(artifact, linkGuid);
+
+ guidIter.remove();
+ }
+ }
+
+ private void logInvalidGuidLink(Artifact artifact, String linkGuid) {
+ try {
+ ArtifactQuery.getArtifactFromId(linkGuid, artifact.getBranch());
+ } catch (Exception e) {
+ logf("Warning: this artifact contains an invalid link - Artifact: [%s] Guid: [%s] Invalid Link Guid: [%s]", artifact.getName(), artifact.getGuid(), linkGuid);
+ }
+ }
+
+ private void logLinksToSelf(Artifact artifact, String linkGuid) {
+ if (linkGuid.equals(artifact.getGuid())) {
+ logf("Warning: this artifact contains a link pointing to itself - Artifact: [%s] Guid: [%s]", artifact.getName(), artifact.getGuid());
+ }
+ }
+
+ @Override
+ public Collection<String> getCategories() {
+ return Collections.singletonList("Util");
+ }
+
+}
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 c814f9c016..e2705a9f3e 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
@@ -125,6 +125,19 @@ public class WordMlLinkHandler {
LinkType linkType = checkLinkType(destLinkType);
String modified = content;
+ HashCollection<String, MatchRange> matchMap = getLinks(content);
+ if (!matchMap.isEmpty()) {
+ modified = modifiedContent(linkType, source, content, matchMap, false, unknownGuids, presentationType);
+ unknownGuids.addAll(matchMap.keySet());
+ }
+ if (linkType != LinkType.OSEE_SERVER_LINK) {
+ // Add a bookmark to the start of the content so internal links can link later
+ modified = linkBuilder.getWordMlBookmark(source) + modified;
+ }
+ return modified;
+ }
+
+ public static HashCollection<String, MatchRange> getLinks(String content) {
// Detect legacy links
HashCollection<String, MatchRange> matchMap = parseOseeWordMLLinks(content);
@@ -137,14 +150,7 @@ public class WordMlLinkHandler {
}
}
OSEE_LINK_PATTERN.reset();
- if (!matchMap.isEmpty()) {
- modified = modifiedContent(linkType, source, content, matchMap, false, unknownGuids, presentationType);
- }
- if (linkType != LinkType.OSEE_SERVER_LINK) {
- // Add a bookmark to the start of the content so internal links can link later
- modified = linkBuilder.getWordMlBookmark(source) + modified;
- }
- return modified;
+ return matchMap;
}
/**

Back to the top