Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid W. Miller2018-05-22 15:19:04 -0400
committerDavid W. Miller2018-06-07 13:26:28 -0400
commit77aff41e09876c20ce914b2965f9c4e39ff830a3 (patch)
tree23a5b59256fb461c4b2bc9a7fcb09da896c65e81
parent6abefe5e8757e7c7cb284ae33550d727c1f5d429 (diff)
downloadorg.eclipse.osee-77aff41e09876c20ce914b2965f9c4e39ff830a3.tar.gz
org.eclipse.osee-77aff41e09876c20ce914b2965f9c4e39ff830a3.tar.xz
org.eclipse.osee-77aff41e09876c20ce914b2965f9c4e39ff830a3.zip
feature[ats_TW9620]: Add Doors specific word outline extractor
-rw-r--r--plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/WordOutlineTest.java45
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/plugin.xml5
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsWordOutlineExtractor.java92
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/WordOutlineExtractorDelegate.java69
4 files changed, 140 insertions, 71 deletions
diff --git a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/WordOutlineTest.java b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/WordOutlineTest.java
index 6f1a1c6778..0cf87a1a27 100644
--- a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/WordOutlineTest.java
+++ b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/WordOutlineTest.java
@@ -32,7 +32,7 @@ import org.junit.runners.Parameterized.Parameters;
/**
* Tests different forms of outline numbers and titles
- *
+ *
* @author Karol M. Wilk
*/
@RunWith(Parameterized.class)
@@ -65,15 +65,14 @@ public final class WordOutlineTest {
/**
* Note: some of the data objects need to repeat data from previous test because they are considered to be
* lastHeaderNumber or lastHeaderName or lastContent
- *
+ *
* @return collection of data sets used as input for parameterized unit test
*/
@Parameters
public static Collection<Object[]> getData() {
List<Object[]> data = new ArrayList<>();
- addTest(data, OUTLINE_WITH_NUMBER, data("1.0", "Outline TITLE", ""));
- addTest(data, OUTLINE_WITH_NUMBER_AND_CONTENT, data("5.0", "SCOPE", ""),
- data("5.0", "SCOPE", "content content content more content"));
+ addTest(data, OUTLINE_WITH_NUMBER, data("1.0", "Outline TITLE"));
+ addTest(data, OUTLINE_WITH_NUMBER_AND_CONTENT, data("5.0", "SCOPE"), data("5.0", "SCOPE"));
StringBuilder builder = new StringBuilder();
builder.append("This 1.6 is some interesting content 2.3SAMPL");
@@ -82,7 +81,7 @@ public final class WordOutlineTest {
builder.append(ReservedCharacters.toCharacter("&ldquo;"));
builder.append("10.");
- addTest(data, NUMBER_EMBED_IN_CONTENT, data("1.0", "SCOPE", ""), data("1.0", "SCOPE", builder.toString()));
+ addTest(data, NUMBER_EMBED_IN_CONTENT, data("1.0", "SCOPE"), data("1.0", "SCOPE"));
return data;
}
@@ -103,9 +102,8 @@ public final class WordOutlineTest {
String headerNumber = delegate.getLastHeaderNumber().trim();
String headerName = delegate.getLastHeaderName().trim();
- String content = delegate.getLastContent().trim();
- actualData.add(data(headerNumber, headerName, content));
+ actualData.add(data(headerNumber, headerName));
}
Assert.assertTrue("WordOutlineTester no paragraphs found...", foundSomething);
@@ -113,9 +111,9 @@ public final class WordOutlineTest {
DelegateData expected = expectedData[index];
DelegateData actual = actualData.get(index);
Assert.assertEquals(String.format(
- "\nChecking %s of %s,\nEXPECTED: \n\t Number:\"%s\" \n\t Title:\"%s\" \n\t Content:\"%s\"\nACTUAL: \n\t Number:\"%s\" \n\t Title:\"%s\" \n\t Content:\"%s\"\n",
- index, dataFileName, expected.getHeaderNumber(), expected.getHeaderName(), expected.getContent(),
- actual.getHeaderNumber(), actual.getHeaderName(), actual.getContent()), expected, actual);
+ "\nChecking %s of %s,\nEXPECTED: \n\t Number:\"%s\" \n\t Title:\"%s\"\nACTUAL: \n\t Number:\"%s\" \n\t Title:\"%s\"\n",
+ index, dataFileName, expected.getHeaderNumber(), expected.getHeaderName(), actual.getHeaderNumber(),
+ actual.getHeaderName()), expected, actual);
if (Strings.isValid(expected.getHeaderNumber())) {
Assert.assertTrue("WordOutlineTester doesn't look like a outline number...",
OUTLINE_NUMBER_PATTERN.matcher(actual.getHeaderNumber()).matches());
@@ -128,26 +126,23 @@ public final class WordOutlineTest {
delegate.dispose();
Assert.assertNull(delegate.getLastHeaderNumber());
Assert.assertNull(delegate.getLastHeaderName());
- Assert.assertNull(delegate.getLastContent());
}
private static void addTest(List<Object[]> data, String dataFileName, DelegateData... expectedData) {
data.add(new Object[] {dataFileName, expectedData});
}
- private static DelegateData data(String headerNumber, String headerName, String content) {
- return new DelegateData(headerNumber, headerName, content);
+ private static DelegateData data(String headerNumber, String headerName) {
+ return new DelegateData(headerNumber, headerName);
}
private static final class DelegateData {
private final String headerNumber;
private final String headerName;
- private final String content;
- public DelegateData(String headerNumber, String headerName, String content) {
+ public DelegateData(String headerNumber, String headerName) {
this.headerNumber = headerNumber;
this.headerName = headerName;
- this.content = content;
}
public String getHeaderNumber() {
@@ -158,15 +153,10 @@ public final class WordOutlineTest {
return headerName;
}
- public String getContent() {
- return content;
- }
-
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + (content == null ? 0 : content.hashCode());
result = prime * result + (headerName == null ? 0 : headerName.hashCode());
result = prime * result + (headerNumber == null ? 0 : headerNumber.hashCode());
return result;
@@ -184,13 +174,7 @@ public final class WordOutlineTest {
return false;
}
DelegateData other = (DelegateData) obj;
- if (content == null) {
- if (other.content != null) {
- return false;
- }
- } else if (!content.equals(other.content)) {
- return false;
- }
+
if (headerName == null) {
if (other.headerName != null) {
return false;
@@ -210,8 +194,7 @@ public final class WordOutlineTest {
@Override
public String toString() {
- return String.format("DelegateData [headerNumber=[%s], headerName=[%s], content=[%s]]", headerNumber,
- headerName, content);
+ return String.format("DelegateData [headerNumber=[%s], headerName=[%s]]", headerNumber, headerName);
}
}
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/plugin.xml b/plugins/org.eclipse.osee.framework.skynet.core/plugin.xml
index 222eed1547..c24165b48b 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/plugin.xml
+++ b/plugins/org.eclipse.osee.framework.skynet.core/plugin.xml
@@ -257,6 +257,11 @@
classname="org.eclipse.osee.framework.skynet.core.importing.parsers.WordOutlineExtractorDelegate">
</ArtifactExtractorDelegate>
</extension>
+ <extension
+ point="org.eclipse.osee.framework.skynet.core.ArtifactExtractorDelegate">
+ <ArtifactExtractorDelegate
+ classname="org.eclipse.osee.framework.skynet.core.importing.parsers.DoorsWordOutlineExtractor"/>
+ </extension>
<extension
point="org.eclipse.osee.framework.skynet.core.ArtifactCheck">
<ArtifactCheck
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsWordOutlineExtractor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsWordOutlineExtractor.java
new file mode 100644
index 0000000000..22df67f649
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsWordOutlineExtractor.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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.framework.skynet.core.importing.parsers;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.skynet.core.importing.RoughArtifact;
+import org.eclipse.osee.framework.skynet.core.importing.RoughArtifactKind;
+import org.eclipse.osee.framework.skynet.core.importing.operations.RoughArtifactCollector;
+
+/**
+ * @author David W. Miller
+ */
+/**
+ * This is a special word outline extractor that handles documents generated by Doors. It is looking for tags, wrapped
+ * in {}, that define the scope and type of the artifact that is being created during the import process.
+ */
+public class DoorsWordOutlineExtractor extends WordOutlineExtractorDelegate {
+ private static final Pattern reqnamePattern = Pattern.compile("(\\{[^}]+\\})(.*?</w:p>)");
+ private int lastReqNumber = 1;
+
+ @Override
+ protected void addChildRoughArtifact(String content, RoughArtifactCollector collector) {
+ StringBuilder newName = new StringBuilder();
+ StringBuilder newContent = new StringBuilder();
+ if (needsNewArt(content, newName, newContent)) {
+ setContent(); // finishes the previous rough artifact
+ String number = String.format("%s.0.%d", lastHeaderNumber.toString(), lastReqNumber++);
+ roughArtifact = new RoughArtifact(RoughArtifactKind.PRIMARY);
+ if (collector != null) {
+ collector.addRoughArtifact(roughArtifact);
+ }
+ if (Strings.isValid(number)) {
+ roughArtifact.setSectionNumber(number);
+ roughArtifact.addAttribute(CoreAttributeTypes.ParagraphNumber, number);
+ }
+ roughArtifact.setName(newName.toString());
+ roughArtifact.addAttribute(CoreAttributeTypes.PublishInline, "True");
+ wordFormattedContent.append(newContent.toString());
+ previousNamedArtifact = roughArtifact;
+ } else {
+ wordFormattedContent.append(content);
+ }
+ }
+
+ @Override
+ protected boolean checkSectionNumber(String sectionNumber) {
+ if (sectionNumber.contains(".0.")) {
+ return true; // special case of numbering requirements below a section number
+ }
+ return false;
+ }
+
+ @Override
+ public void resetReqNumber() {
+ lastReqNumber = 1;
+ }
+
+ @Override
+ public String getName() {
+ return "Doors Word Outline";
+ }
+
+ private boolean needsNewArt(String content, StringBuilder newName, StringBuilder newContent) {
+ Matcher match = reqnamePattern.matcher(content);
+ boolean again = false;
+ while (match.find()) {
+ if (again) {
+ throw new OseeCoreException("new Artifact processor found too many requirement names in this block: %s",
+ content);
+ }
+ again = true;
+ String begin = content.substring(0, match.start(1));
+ newName.append(content.substring(match.start(1), match.start(2)));
+ String endString = content.substring(match.start(2), match.end(2));
+ newContent.append(begin + endString);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/WordOutlineExtractorDelegate.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/WordOutlineExtractorDelegate.java
index 07d01a2b35..ee79358fa2 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/WordOutlineExtractorDelegate.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/WordOutlineExtractorDelegate.java
@@ -57,13 +57,12 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate
private Map<String, RoughArtifact> duplicateCatcher;
private Map<String, String> roughArtMeta;
- private RoughArtifact previousNamedArtifact;
- private RoughArtifact roughArtifact;
- private StringBuilder wordFormattedContent;
+ protected RoughArtifact previousNamedArtifact;
+ protected RoughArtifact roughArtifact;
+ protected StringBuilder wordFormattedContent;
- private StringBuffer lastHeaderNumber;
+ protected StringBuffer lastHeaderNumber;
private StringBuffer lastHeaderName;
- private StringBuffer lastContent;
private boolean initalized;
@@ -83,7 +82,6 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate
roughArtMeta = new HashMap<>();
lastHeaderNumber = new StringBuffer();
lastHeaderName = new StringBuffer();
- lastContent = new StringBuffer();
previousNamedArtifact = null;
roughArtifact = null;
wordFormattedContent = new StringBuilder();
@@ -102,7 +100,6 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate
roughArtifact = null;
lastHeaderNumber = null;
lastHeaderName = null;
- lastContent = null;
initalized = false;
possibleTableOfContents = false;
}
@@ -123,7 +120,6 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate
StringBuilder outlineNumber = new StringBuilder(); //Number i.e. 1.1
StringBuilder outlineName = new StringBuilder(); //Title i.e. Scope
- StringBuilder outlineContent = null; // Content, text, table content, etc.
boolean newOutlineNumber = processOutlineNumberAndName(content, outlineNumber, outlineName, paragraphStyle);
@@ -134,9 +130,9 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate
previousNamedArtifact = roughArtifact;
processHeadingText(roughArtifact, WordUtil.textOnly(outlineName.toString()));
roughArtMeta.put(number, paragraphStyle);
+ resetReqNumber();
} else {
- processContentOfParagraph(content, outlineContent);
- wordFormattedContent.append(content);
+ addChildRoughArtifact(content, collector);
}
} else {
@@ -146,26 +142,14 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate
}
}
- /**
- * Given content a <w:p> paragraph, fill outlineContent with extracted content information from
- * grabNameAndTemplateContent()
- *
- * @param content a <w:p> paragraph.
- * @param outlineContent data structure to fill as new content gets extracted.
- * @return if found any new content or not...
- */
- private boolean processContentOfParagraph(String content, StringBuilder outlineContent) {
- outlineContent = new StringBuilder(content.length());
- grabNameAndTemplateContent(content, outlineContent);
-
- boolean newOutlineContent = outlineContent.length() != 0;
-
- if (newOutlineContent) {
- lastContent.setLength(0);
- lastContent.append(outlineContent.toString());
- }
+ protected void addChildRoughArtifact(String content, RoughArtifactCollector collector) {
+ // Override with inheriting class if needed
+ // Allows child classes to choose to make given content into additional RoughArtifacts
+ wordFormattedContent.append(content);
+ }
- return newOutlineContent;
+ protected void resetReqNumber() {
+ //Override with inheriting class if needed
}
/**
@@ -216,13 +200,15 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate
private boolean determineIfValid(String number, String paragraphStyle) {
boolean result = false;
- if (previousNamedArtifact != null) {
- String metaData = roughArtMeta.get(previousNamedArtifact.getSectionNumber().getNumberString());
-
+ if (previousNamedArtifact != null && previousNamedArtifact.getSectionNumber() != null) {
+ String sectionNumber = previousNamedArtifact.getSectionNumber().getNumberString();
+ if (checkSectionNumber(sectionNumber)) {
+ return true; // special case of numbering requirements below a section number
+ }
+ String metaData = roughArtMeta.get(sectionNumber);
paragraphStyle = Strings.isValid(paragraphStyle) ? paragraphStyle : Strings.EMPTY_STRING;
- boolean invalid = outlineResolution.isInvalidOutlineNumber(number,
- previousNamedArtifact.getSectionNumber().getNumberString());
+ boolean invalid = outlineResolution.isInvalidOutlineNumber(number, sectionNumber);
result = !invalid && RoughArtifactMetaData.matches(metaData, paragraphStyle);
} else {
result = true; //accept since there is no previous
@@ -232,6 +218,13 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate
}
/**
+ * Allows child classes to handle a special case section number
+ */
+ protected boolean checkSectionNumber(String sectionNumber) {
+ return false;
+ }
+
+ /**
* Grabs outline text or content. Stores results in outLineStorage.
*/
private void grabNameAndTemplateContent(String paragraph, StringBuilder outLineStorage) {
@@ -299,10 +292,10 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate
/**
* Sets up storage (word formatted storage) for new artifact.
- *
+ *
* @throws OseeCoreException
*/
- private void setContent() throws OseeCoreException {
+ protected void setContent() throws OseeCoreException {
if (roughArtifact != null) {
roughArtifact.addAttribute(CoreAttributeTypes.WordTemplateContent, wordFormattedContent.toString());
postProcessContent(wordFormattedContent, roughArtifact);
@@ -360,10 +353,6 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate
return getBufferString(lastHeaderName);
}
- public String getLastContent() {
- return getBufferString(lastContent);
- }
-
private String getBufferString(StringBuffer builder) {
return builder != null ? builder.toString() : null;
}

Back to the top