From 870a4d560f09e2667044fc3f28ee8fea5a88df39 Mon Sep 17 00:00:00 2001 From: kwilk Date: Mon, 18 Apr 2011 13:34:40 -0700 Subject: feature[ats_NZFDT]: Rule to support conversion of DOORS Word export documents to OSEE --- .../jdk/core/test/text/UtfReadingRuleTest.java | 4 - .../eclipse/osee/framework/jdk/core/text/Rule.java | 6 + .../jdk/core/text/rules/DoorsToOseeRule.java | 209 +++++++++++++++++++++ .../jdk/core/text/rules/WordMLNewLineMaker.java | 23 ++- .../jdk/core/util/ReservedCharacters.java | 6 +- .../osee/framework/jdk/core/util/Strings.java | 11 +- .../jdk/core/util/io/xml/AbstractSaxHandler.java | 20 +- .../jdk/core/util/io/xml/ExcelXmlWriter.java | 3 +- .../skynet/core/importing/ReqNumberingTest.java | 57 +++++- .../parsers/OutlineResolutionAndNumberTest.java | 21 ++- .../core/importing/parsers/WordOutlineTest.java | 67 ++++--- .../parsers/numberEmbeddedInTheContent.xml | 2 +- .../parsers/outlineNameNumberAndContent.xml | 2 +- .../importing/parsers/outlineNameWithNumber.xml | 2 +- .../skynet/core/importing/ReqNumbering.java | 54 ++++-- .../skynet/core/importing/RoughArtifact.java | 24 ++- .../skynet/core/importing/RoughAttributeSet.java | 8 + .../operations/RoughToRealArtifactOperation.java | 8 +- .../importing/parsers/ExcelArtifactExtractor.java | 8 +- .../core/importing/parsers/OutlineResolution.java | 92 +++------ .../parsers/WordOutlineExtractorDelegate.java | 64 +++---- .../resolvers/AttributeBasedArtifactResolver.java | 14 +- .../test/importer/ArtifactImportWizardTest.java | 9 +- .../ui/skynet/Import/MatchingStrategy.java | 6 +- .../framework/ui/skynet/RelationsComposite.java | 11 +- 25 files changed, 487 insertions(+), 244 deletions(-) create mode 100644 plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/DoorsToOseeRule.java diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/UtfReadingRuleTest.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/UtfReadingRuleTest.java index 66c2c1cec0c..ab23c806991 100644 --- a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/UtfReadingRuleTest.java +++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/UtfReadingRuleTest.java @@ -102,10 +102,6 @@ public final class UtfReadingRuleTest { private static final class Utf8TestRule extends Rule { private CharSequence lastOutput; - public Utf8TestRule() { - lastOutput = null; - } - @Override public ChangeSet computeChanges(final CharSequence seq) { lastOutput = seq; diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/Rule.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/Rule.java index e4030b3c346..ee4c15cad8f 100644 --- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/Rule.java +++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/Rule.java @@ -49,6 +49,12 @@ public abstract class Rule { this.subdirectoryName = null; } + /** + * Implement this to receive the content of the entire file in {@code seq} + * + * @param seq + * @return + */ public abstract ChangeSet computeChanges(CharSequence seq); public final void process(Collection list) { diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/DoorsToOseeRule.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/DoorsToOseeRule.java new file mode 100644 index 00000000000..9566db13737 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/DoorsToOseeRule.java @@ -0,0 +1,209 @@ +/******************************************************************************* + * Copyright (c) 2011 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.jdk.core.text.rules; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; + +/** + * Converts Doors exported Word documents to format friendlier to OSEE. + * + * @author Karol M. Wilk + */ +public final class DoorsToOseeRule extends Rule { + + private enum DoorsItemEnum { + OBJECT_NUMBER, + OBJECT_SHORT_TEXT_DASHED, //will be converted to regular paragraphs + OBJECT_SHORT_TEXT_NON_DASHED, //will be deleted + OBJECT_BODY, + NONE + } + + private final Pattern bodyRegex = Pattern.compile("(.*?)", Pattern.DOTALL); + private final Pattern paragraphRegex = Pattern.compile("].*?", Pattern.DOTALL); + private final Pattern objectNumberParagraphRegex = Pattern.compile( + ".*?((?>\\d+\\.)+\\d+-\\d+(?>\\.\\d+-\\d+)*).*", Pattern.DOTALL | Pattern.MULTILINE); + private final Pattern regularObjectNumberParagraphRegex = Pattern.compile( + ".*?Object Number\\s*.*:\\s+(.*?)", Pattern.DOTALL | Pattern.MULTILINE); + private final Pattern objectShortTextParagraphRegex = Pattern.compile( + "].*?Object Short Text.*?\\s+:\\s+(.*?).*?", Pattern.DOTALL); + private final Pattern headingParagraphRegex = Pattern.compile( + "].*?.*?(\\d+\\s+.*?).*?", Pattern.DOTALL); + + private StringBuilder modifiedText; + + public DoorsToOseeRule() { + super("_converted.xml"); + } + + @Override + public ChangeSet computeChanges(CharSequence entireFile) { + modifiedText = new StringBuilder(entireFile.length() * 2); + + Matcher bodySectionMatcher = bodyRegex.matcher(entireFile); + if (bodySectionMatcher.find()) { + write(entireFile.subSequence(0, bodySectionMatcher.start())); + write("\n"); + + processText(bodySectionMatcher.group(1)); + + write("\n"); + write("\n"); + } + return decideOnResult(modifiedText, entireFile); + } + + private void processText(CharSequence text) { + Matcher paragraphMatcher = paragraphRegex.matcher(text); + + DoorsItemEnum currentDoorsItem = DoorsItemEnum.OBJECT_NUMBER; + + boolean startedSectionProcessing = true; + int startIndexOfLastParagraph = -1; + int endIndexOfLastParagraph = -1; + + while (paragraphMatcher.find()) { + + if (startedSectionProcessing) { + startedSectionProcessing = false; + write(text.subSequence(0, paragraphMatcher.start())); + } else if (startIndexOfLastParagraph != -1 && endIndexOfLastParagraph != -1) { + write(text.subSequence(endIndexOfLastParagraph, paragraphMatcher.start())); + } + + DoorsItemEnum prevDoorsItem = currentDoorsItem; + currentDoorsItem = processParagraph(paragraphMatcher.group(), currentDoorsItem); + + startIndexOfLastParagraph = paragraphMatcher.start(); + endIndexOfLastParagraph = paragraphMatcher.end(); + + if (prevDoorsItem == currentDoorsItem) { + write("\n" + paragraphMatcher.group()); + } + } + write(text.subSequence(endIndexOfLastParagraph, text.length())); + } + + private DoorsItemEnum processParagraph(String paragraph, DoorsItemEnum nextDoorsItem) { + switch (nextDoorsItem) { + + case OBJECT_NUMBER: + Matcher objectNumberMatcher = objectNumberParagraphRegex.matcher(paragraph); + if (objectNumberMatcher.find()) { + + String updatedObjectNumber = objectNumberMatcher.group(1).replace("-", "."); + + System.out.print("\t" + objectNumberMatcher.group(1) + " --> " + updatedObjectNumber); + + write("\n\t"); + + write(""); + write(""); + write(""); + + write("\n\t"); + write(""); + write(""); + write(""); + write(""); + write(String.format("\n%s ", updatedObjectNumber)); + write("\n\t"); + + nextDoorsItem = DoorsItemEnum.OBJECT_SHORT_TEXT_DASHED; + } else { + //Attempt to remove unnecessary Object Number nodes + Matcher regularParagraphMatcher = regularObjectNumberParagraphRegex.matcher(paragraph); + if (regularParagraphMatcher.find()) { + + nextDoorsItem = DoorsItemEnum.OBJECT_SHORT_TEXT_NON_DASHED; + System.out.print("- \t\t" + regularParagraphMatcher.group(1)); + } + } + break; + + case OBJECT_SHORT_TEXT_DASHED: { + Matcher objectShortTextMatcher = objectShortTextParagraphRegex.matcher(paragraph); + if (objectShortTextMatcher.find()) { + + System.out.print(" " + objectShortTextMatcher.group(1) + "\n"); + + write("\n\t"); + write("\n\t"); + write("\n\t"); + write("\n\t"); + write("\n\t"); + write("\n\t"); + write(String.format("\n\t%s", objectShortTextMatcher.group(1))); + write("\n\t"); + write("\n\t"); + + nextDoorsItem = DoorsItemEnum.OBJECT_BODY; + } + } + break; + + case OBJECT_SHORT_TEXT_NON_DASHED: + Matcher objectShortTextMatcher = objectShortTextParagraphRegex.matcher(paragraph); + if (objectShortTextMatcher.find()) { + + System.out.print(" " + objectShortTextMatcher.group(1) + "\n"); + + nextDoorsItem = DoorsItemEnum.OBJECT_BODY; + } + break; + + case OBJECT_BODY: + //detect body or heading paragraph that need to be adjusted... + Matcher headingParagraphMatcher = headingParagraphRegex.matcher(paragraph); + if (headingParagraphMatcher.find()) { + System.out.print("\t" + headingParagraphMatcher.group(1)); + + write(paragraph.subSequence(0, headingParagraphMatcher.start(1))); + + String wt = headingParagraphMatcher.group(1); + + StringBuilder resultingWt = new StringBuilder(wt.length() * 2 / 3); + //Split at " " + int indexOfFirstSpace = wt.indexOf(" "); + + resultingWt.append(wt.subSequence(0, indexOfFirstSpace)); + resultingWt.append(".0"); + resultingWt.append(wt.subSequence(indexOfFirstSpace, wt.length())); + + System.out.print(" --> " + resultingWt + "\n"); + write(resultingWt); + + write(paragraph.subSequence(headingParagraphMatcher.end(1), paragraph.length())); + } else { + write(paragraph); + } + nextDoorsItem = DoorsItemEnum.OBJECT_NUMBER; + break; + case NONE: + default: + break; + } + return nextDoorsItem; + } + + private void write(CharSequence subSequence) { + modifiedText.append(subSequence); + } + + private ChangeSet decideOnResult(StringBuilder modifiedFile, CharSequence entireFile) { + boolean insertModified = modifiedText.length() > 0; + setRuleWasApplicable(insertModified); + return new ChangeSet((insertModified) ? modifiedText : entireFile); + } +} diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/WordMLNewLineMaker.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/WordMLNewLineMaker.java index ccf6e771e60..3828c2f5ef3 100644 --- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/WordMLNewLineMaker.java +++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/WordMLNewLineMaker.java @@ -16,10 +16,11 @@ import org.eclipse.osee.framework.jdk.core.text.Rule; import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; /** + * Processes WordML documents and inserts WordML equivalent new lines. Used in importing tasks. TODO: update methods to + * use ChangeSet rather than current logic + * * @see WordMLNewLineMakerTest * @author Karol M. Wilk - * @note Rule implements a main(), so start this by passing path to files as argument
- * TODO: update methods to use ChangeSet rather than current logic */ public final class WordMLNewLineMaker extends Rule { @@ -83,17 +84,15 @@ public final class WordMLNewLineMaker extends Rule { } } + /** + * if modifiedText is valid, it will be the changeset, otherwise entirefile + * + * @return changset representing result + */ private ChangeSet decideOnResultAndReturnIt(StringBuilder modifiedFile, CharSequence entireFile) { - ChangeSet returningChangeSet = null; - if (modifiedText.length() > 0) { - // modified text becomes the char sequence - returningChangeSet = new ChangeSet(modifiedText); - setRuleWasApplicable(true); - } else { - returningChangeSet = new ChangeSet(entireFile); - setRuleWasApplicable(false); - } - return returningChangeSet; + boolean insertModified = modifiedText.length() > 0; + setRuleWasApplicable(insertModified); + return new ChangeSet((insertModified) ? modifiedText : entireFile); } private void processWxSubSection(String wxSubSection) { diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ReservedCharacters.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ReservedCharacters.java index b096db98d38..702504cbc4f 100644 --- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ReservedCharacters.java +++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ReservedCharacters.java @@ -140,12 +140,12 @@ public final class ReservedCharacters { } public static Character toCharacter(String entity) { - Character toReturn = null; + Character character = null; if (Strings.isValid(entity)) { entity = entity.trim(); - toReturn = reservedCharacters.get(entity); + character = reservedCharacters.get(entity); } - return toReturn; + return character; } public static Collection getChars() { diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java index a2b3a9f2be5..b58979d6206 100644 --- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java +++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java @@ -52,18 +52,11 @@ public class Strings { * @return a string with doubled ampersands. */ public static String escapeAmpersands(String stringWithAmp) { - if (isValid(stringWithAmp)) { - return stringWithAmp.replace("&", "&&"); - } else { - return null; - } + return isValid(stringWithAmp) ? stringWithAmp.replace("&", "&&") : null; } public static String intern(String str) { - if (str == null) { - return null; - } - return str.intern(); + return (str == null) ? null : str.intern(); } /** diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/AbstractSaxHandler.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/AbstractSaxHandler.java index a806df3ee84..3b00d582661 100644 --- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/AbstractSaxHandler.java +++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/AbstractSaxHandler.java @@ -17,9 +17,18 @@ import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.DefaultHandler; /** - * @author Ryan D. Brooks If you want to preserve CDATA sections you need to follow this pattern: XMLReader xmlReader = - * XMLReaderFactory.createXMLReader(); xmlReader.setContentHandler(this); - * xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", this); //This is the important part + *

+ * If you want to preserve CDATA sections you need to follow this pattern:
+ * + *

+ * XMLReader xmlReader = XMLReaderFactory.createXMLReader();
+ * xmlReader.setContentHandler(this);
+ * xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", this); //This is the important part
+ * 
+ * + *

+ * + * @author Ryan D. Brooks */ public abstract class AbstractSaxHandler extends DefaultHandler implements LexicalHandler { // Buffer for collecting data from the "characters" SAX event. @@ -77,6 +86,7 @@ public abstract class AbstractSaxHandler extends DefaultHandler implements Lexic @Override public void comment(char[] ch, int start, int length) throws SAXException { + //Do nothing } @Override @@ -86,10 +96,12 @@ public abstract class AbstractSaxHandler extends DefaultHandler implements Lexic @Override public void endDTD() throws SAXException { + //Do nothing } @Override public void endEntity(String name) throws SAXException { + //Do nothing } @Override @@ -99,9 +111,11 @@ public abstract class AbstractSaxHandler extends DefaultHandler implements Lexic @Override public void startDTD(String name, String publicId, String systemId) throws SAXException { + //Do nothing } @Override public void startEntity(String name) throws SAXException { + //Do nothing } } \ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ExcelXmlWriter.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ExcelXmlWriter.java index 63ddf8be38f..ea242bb15a1 100644 --- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ExcelXmlWriter.java +++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ExcelXmlWriter.java @@ -22,8 +22,7 @@ import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.framework.jdk.core.util.xml.Xml; /** - * Test: @link ExcelXmlWriterTest - * + * @see ExcelXmlWriterTest * @author Ryan D. Brooks * @author Karol M. Wilk */ diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/ReqNumberingTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/ReqNumberingTest.java index b3ea1de45c2..363cb0376a7 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/ReqNumberingTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/ReqNumberingTest.java @@ -21,6 +21,7 @@ import org.junit.Assert; import org.junit.Test; /** + * @see ReqNumbering * @author Ryan Schmitt */ public class ReqNumberingTest { @@ -50,6 +51,15 @@ public class ReqNumberingTest { assertTrue(reqParent.isChild(reqChild)); } + @Test + public void testIsChild_DoubleZeroBasedParagraphNumber() { + String parent = "1.3.4"; + String child = "1.3.4.0-6.0-1"; + ReqNumbering reqParent = new ReqNumbering(parent); + ReqNumbering reqChild = new ReqNumbering(child); + assertTrue(reqParent.isChild(reqChild)); + } + @Test public void testIsNotChild_ZeroBasedParagraphNumber() { String parent = "1.3.4"; @@ -68,15 +78,54 @@ public class ReqNumberingTest { assertFalse(reqChild.isChild(reqParent)); } + @Test + public void test_isChild_ZeroBasedParagraphNumbers_OddCase() { + ReqNumbering A = new ReqNumbering("1.0"); + ReqNumbering B = new ReqNumbering("1.0-1"); + assertFalse(B.isChild(A)); + assertTrue(A.isChild(B)); + } + + /** + *

+ * a.compareTo(b) = x
+ * b.compareTo(a) = -x + *

+ */ + @Test + public void test_compareTo_NonCommutative() { + ReqNumbering A = new ReqNumbering("1.0", false); + ReqNumbering B = new ReqNumbering("1.2.3"); + assertTrue(B.compareTo(A) == 1); + assertTrue(A.compareTo(B) == -1); + } + + /** + *

+ * a.compareTo(b) = 1
+ * b.compareTo(c) = 1, then
+ * a.compareTo(c) = 1 + *

+ */ + @Test + public void test_compareTo_Transitive() { + ReqNumbering A = new ReqNumbering("2.4.6"); + ReqNumbering B = new ReqNumbering("1.2.3"); + ReqNumbering C = new ReqNumbering("1.0", false); + assertTrue(A.compareTo(B) == 1); + assertTrue(B.compareTo(C) == 1); + assertTrue(A.compareTo(C) == 1); + } + @Test public void testCompare() { List referenceList = - Arrays.asList(new ReqNumbering("1"), new ReqNumbering("1.3"), new ReqNumbering("1.3.1.1.1.1.1.1"), - new ReqNumbering("2.4"), new ReqNumbering("2.4.0.1"), new ReqNumbering("3")); + Arrays.asList(new ReqNumbering("1"), new ReqNumbering("1.0-1"), new ReqNumbering("1.3"), new ReqNumbering( + "1.3.1.1.1.1.1.1"), new ReqNumbering("2.4"), new ReqNumbering("2.4.0.1"), new ReqNumbering("3")); List sampleList = - Arrays.asList(new ReqNumbering("3"), new ReqNumbering("2.4.0-1"), new ReqNumbering("2.4"), new ReqNumbering( - "1.3.1.1.1.1.1.1"), new ReqNumbering("1.3"), new ReqNumbering("1")); + Arrays.asList(new ReqNumbering("3"), new ReqNumbering("1.0-1"), new ReqNumbering("2.4.0-1"), new ReqNumbering( + "2.4"), new ReqNumbering("1.3.1.1.1.1.1.1"), new ReqNumbering("1.3"), new ReqNumbering("1")); Collections.sort(sampleList); diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/OutlineResolutionAndNumberTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/OutlineResolutionAndNumberTest.java index 69c199c399f..021fbdcc751 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/OutlineResolutionAndNumberTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/OutlineResolutionAndNumberTest.java @@ -14,17 +14,17 @@ import org.junit.Assert; import org.junit.Test; /** + * Asserting true in general means GUI should be called for user to make decision; false - opposite + * * @author Karol M. Wilk */ public final class OutlineResolutionAndNumberTest { + //TODO: change to parameterized type test + private static final String LAST_OUTLINE_NUMBER = "3.1.1.2.1.7"; /* realistic outline number */ private final OutlineResolution outlineResolution = new OutlineResolution(); - /** - * ! Asserting true in general means GUI should be called for user to make decision; false - opposite - */ - @Test public void testLowerOutlineNumbers() { Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("3.1.1.2.1.6", LAST_OUTLINE_NUMBER)); @@ -36,6 +36,7 @@ public final class OutlineResolutionAndNumberTest { Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("2.10", LAST_OUTLINE_NUMBER)); Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("2.1", LAST_OUTLINE_NUMBER)); Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("1.8", LAST_OUTLINE_NUMBER)); + Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("0.15", LAST_OUTLINE_NUMBER)); } @Test @@ -48,15 +49,17 @@ public final class OutlineResolutionAndNumberTest { Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("3.1.1.4.1.1", LAST_OUTLINE_NUMBER)); } + @Test + public void testZeroBasedOutlineNumbers() { + Assert.assertFalse(outlineResolution.isInvalidOutlineNumber("3.2.1.0.1", "3.2.1")); + Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("3.2.0.0.1", "3.2.1")); + } + @Test public void testRandomOutlineNumbers() { Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("6.5", LAST_OUTLINE_NUMBER)); Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("0.25", LAST_OUTLINE_NUMBER)); Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("10.48", LAST_OUTLINE_NUMBER)); - Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("-5.6", LAST_OUTLINE_NUMBER)); - Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("34.fin3bbtb34fm34", LAST_OUTLINE_NUMBER)); - Assert.assertFalse(outlineResolution.isInvalidOutlineNumber("", "")); - Assert.assertFalse(outlineResolution.isInvalidOutlineNumber(null, null)); Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("200.12.3", LAST_OUTLINE_NUMBER)); Assert.assertFalse(outlineResolution.isInvalidOutlineNumber("4.0", "3.1")); Assert.assertFalse(outlineResolution.isInvalidOutlineNumber("2.1.1.1.2", "2.1.1.1.1")); @@ -66,7 +69,5 @@ public final class OutlineResolutionAndNumberTest { Assert.assertFalse(outlineResolution.isInvalidOutlineNumber("2.2", "2.1.1.1.1")); Assert.assertFalse(outlineResolution.isInvalidOutlineNumber("2.1.2", "2.1.1.1.1")); Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("3.2", "2.1.1.1.1")); - Assert.assertTrue(outlineResolution.isInvalidOutlineNumber("b", "c")); } - } diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/WordOutlineTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/WordOutlineTest.java index 032b6329d7f..baa5aa9822e 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/WordOutlineTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/WordOutlineTest.java @@ -17,7 +17,6 @@ import java.util.Collection; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.framework.jdk.core.util.ReservedCharacters; import org.eclipse.osee.framework.jdk.core.util.Strings; @@ -54,50 +53,28 @@ public final class WordOutlineTest { this.expectedData = expectedData; } - //@formatter:off /** - * 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 - */ + * 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 getData() { List data = new ArrayList(); - addTest(data, OUTLINE_WITH_NUMBER, data("1.", "Outline TITLE", "")); - addTest(data, OUTLINE_WITH_NUMBER_AND_CONTENT, data("5.", "SCOPE", ""), data("5.", "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", "content content content more content")); + StringBuilder builder = new StringBuilder(); builder.append("This 1.6 is some interesting content 2.3SAMPL"); builder.append(ReservedCharacters.toCharacter("â")); builder.append(ReservedCharacters.toCharacter("€")); builder.append(ReservedCharacters.toCharacter("“")); builder.append("10."); - - addTest(data, NUMBER_EMBED_IN_CONTENT, data("1.", "SCOPE", ""), data("1.", "SCOPE", builder.toString())); - return data; - } - //@formatter:on - - private static void addTest(List 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 String getResourceData(String name) throws IOException { - InputStream inputStream = null; - try { - inputStream = WordOutlineTest.class.getResourceAsStream(name); - String data = Lib.inputStreamToString(inputStream); - Assert.assertTrue(Strings.isValid(data)); - return data; - } finally { - Lib.close(inputStream); - } + addTest(data, NUMBER_EMBED_IN_CONTENT, data("1.0", "SCOPE", ""), data("1.0", "SCOPE", builder.toString())); + return data; } @Test @@ -146,13 +123,33 @@ public final class WordOutlineTest { Assert.assertNull(delegate.getLastContent()); } + private static void addTest(List 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 String getResourceData(String name) throws IOException { + InputStream inputStream = null; + String data; + try { + inputStream = WordOutlineTest.class.getResourceAsStream(name); + data = Lib.inputStreamToString(inputStream); + Assert.assertTrue(Strings.isValid(data)); + } finally { + Lib.close(inputStream); + } + return data; + } + 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) { - super(); this.headerNumber = headerNumber; this.headerName = headerName; this.content = content; diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/numberEmbeddedInTheContent.xml b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/numberEmbeddedInTheContent.xml index e8bdce1050d..acb720890dc 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/numberEmbeddedInTheContent.xml +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/numberEmbeddedInTheContent.xml @@ -1,2 +1,2 @@ -1. SCOPE +1.0 SCOPE This 1.6 is some interesting content 2.3fe "SAMPL-10"SAMPL–10. diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/outlineNameNumberAndContent.xml b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/outlineNameNumberAndContent.xml index b6b22c2e785..cfa26a9a6f0 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/outlineNameNumberAndContent.xml +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/outlineNameNumberAndContent.xml @@ -1,2 +1,2 @@ -5. SCOPE +5.0 SCOPE content content contentblah more content diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/outlineNameWithNumber.xml b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/outlineNameWithNumber.xml index d5a27b1bf6c..5c33ebad72a 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/outlineNameWithNumber.xml +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/outlineNameWithNumber.xml @@ -1 +1 @@ -1. Outline TITLE +1.0 Outline TITLE diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/ReqNumbering.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/ReqNumbering.java index 6943ece4bb4..eb9a7b62baa 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/ReqNumbering.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/ReqNumbering.java @@ -11,29 +11,40 @@ package org.eclipse.osee.framework.skynet.core.importing; /** + * Requirement Numbering + * + * @see ReqNumberingTest * @author Robert A. Fisher */ -public class ReqNumbering implements Comparable { - private static final int ZERO_BASED_NUMBERING = 2; - private static final int ONE_BASED_NUMBERING = 1; +public final class ReqNumbering implements Comparable { + private static final int ZERO_BASED_NUMBERING = 0; // 1.0-1 + private static final int ONE_BASED_NUMBERING = 1; // 1.1 - private final String number; + private final boolean removeEndingZero; + private final String numberStr; private final String[] values; + //TODO: to implement support for i. ii. iii. or a. b. c. + //reimplement the comparators and the below. + + public ReqNumbering(String number) { + this(number, true); + } + /** - * Requirement Numbering - * * @note When a number with a separator - is used, i.e. 1.2-1. All - are replaced with . at construction. * @param number */ - public ReqNumbering(String number) { + public ReqNumbering(String number, boolean removeEndingZero) { //When additional separators are used (- instead of .) - this.number = number.replace("-", "."); - values = tokenize(); + this.numberStr = number.replace("-", "."); + + this.removeEndingZero = removeEndingZero; + this.values = tokenize(removeEndingZero); } public String getNumberString() { - return number; + return numberStr; } /** @@ -42,9 +53,11 @@ public class ReqNumbering implements Comparable { public boolean isChild(ReqNumbering numbering) { String[] numberVals = numbering.values; - switch (numberVals.length - values.length) { + int delta = numberVals.length - values.length; + + switch (delta % 2) { case ZERO_BASED_NUMBERING: - if (!numberVals[numberVals.length - 2].equals("0")) { + if (delta <= 0) { return false; } break; @@ -54,19 +67,24 @@ public class ReqNumbering implements Comparable { return false; } - for (int i = 0; i < values.length; i++) { + for (int i = 0; i < Math.min(values.length, numberVals.length); i++) { if (!values[i].equals(numberVals[i])) { return false; } } + return true; } public String[] tokenize() { - String[] returnVal = number.split("\\."); + return tokenize(removeEndingZero); + } + + public String[] tokenize(boolean chopOffZero) { + String[] returnVal = numberStr.split("\\."); - // If the very last token is a 0, then chop it off - if (returnVal[returnVal.length - 1].equals("0")) { + if (chopOffZero && returnVal[returnVal.length - 1].equals("0")) { + // If the very last token is a 0, then chop it off String[] temp = new String[returnVal.length - 1]; System.arraycopy(returnVal, 0, temp, 0, temp.length); returnVal = temp; @@ -99,7 +117,7 @@ public class ReqNumbering implements Comparable { @Override public int hashCode() { - return number.hashCode(); + return numberStr.hashCode(); } private int getValue(int index) { @@ -112,6 +130,6 @@ public class ReqNumbering implements Comparable { @Override public String toString() { - return number; + return numberStr; } } \ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/RoughArtifact.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/RoughArtifact.java index 37493638c1e..f6943e844f7 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/RoughArtifact.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/RoughArtifact.java @@ -29,8 +29,7 @@ import org.eclipse.osee.framework.skynet.core.attribute.AttributeTypeManager; import org.eclipse.osee.framework.skynet.core.internal.Activator; /** - * Test: @link RoughArtifactTest - * + * @see RoughArtifactTest * @author Robert A. Fisher * @author Ryan D. Brooks */ @@ -44,8 +43,12 @@ public class RoughArtifact { private final Collection children; private IArtifactType primaryArtifactType; - public RoughArtifact(RoughArtifactKind roughArtifactKind) { + public RoughArtifact(RoughArtifactKind roughArtifactKind, String name) { + this(roughArtifactKind); + addAttribute("Name", name); + } + public RoughArtifact(RoughArtifactKind roughArtifactKind) { this.attributes = new RoughAttributeSet(); this.children = new ArrayList(); this.roughArtifactKind = roughArtifactKind; @@ -61,11 +64,6 @@ public class RoughArtifact { primaryArtifactType = null; } - public RoughArtifact(RoughArtifactKind roughArtifactKind, String name) { - this(roughArtifactKind); - addAttribute("Name", name); - } - public Set getAttributeTypeNames() { return attributes.getAttributeTypeNames(); } @@ -172,6 +170,16 @@ public class RoughArtifact { return children; } + public Collection getDescendants() { + Collection decendants = new ArrayList(); + for (RoughArtifact child : getChildren()) { + if (equals(child.roughParent)) { + decendants.add(child); + } + } + return decendants; + } + public void setGuid(String guid) { this.guid = guid; } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/RoughAttributeSet.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/RoughAttributeSet.java index 929f9634d54..7b7ed702574 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/RoughAttributeSet.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/RoughAttributeSet.java @@ -64,6 +64,14 @@ public final class RoughAttributeSet { return getAttributeValueList(attributeType.getName()); } + /** + * @return Same as getAttributeValueList, returns defaultList if getAttributeValueList is null. + */ + public Collection getAttributeValueList(IAttributeType attributeType, Collection defaultList) { + Collection list = getAttributeValueList(attributeType); + return (list != null) ? list : defaultList; + } + public void addURIAttribute(String name, URI url) { uriAttributes.put(new CaseInsensitiveString(name), url); } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/operations/RoughToRealArtifactOperation.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/operations/RoughToRealArtifactOperation.java index 78db8b4d989..aa96a92af96 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/operations/RoughToRealArtifactOperation.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/operations/RoughToRealArtifactOperation.java @@ -10,13 +10,13 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.importing.operations; -import static org.eclipse.osee.framework.core.enums.CoreRelationTypes.Default_Hierarchical__Parent; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.osee.framework.core.data.IRelationSorterId; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.model.type.RelationType; @@ -78,7 +78,7 @@ public class RoughToRealArtifactOperation extends AbstractOperation { monitor.worked(unitOfWork); } - if (deleteUnmatchedArtifacts && !unmatchedArtifacts.isEmpty()) { + if (deleteUnmatchedArtifacts) { for (Artifact toDelete : unmatchedArtifacts) { toDelete.deleteAndPersist(transaction); } @@ -94,7 +94,7 @@ public class RoughToRealArtifactOperation extends AbstractOperation { realArtifact = artifactResolver.resolve(roughArtifact, transaction.getBranch(), realParent, destinationArtifact); unmatchedArtifacts.remove(realArtifact); - for (RoughArtifact childRoughArtifact : roughArtifact.getChildren()) { + for (RoughArtifact childRoughArtifact : roughArtifact.getDescendants()) { Artifact childArtifact = createArtifact(monitor, childRoughArtifact, realArtifact); if (areValid(realArtifact, childArtifact)) { removeOtherParent(childArtifact, realArtifact); @@ -112,7 +112,7 @@ public class RoughToRealArtifactOperation extends AbstractOperation { private void removeOtherParent(Artifact child, Artifact parent) throws OseeCoreException { if (hasDifferentParent(child, parent)) { - child.deleteRelations(Default_Hierarchical__Parent); + child.deleteRelations(CoreRelationTypes.Default_Hierarchical__Parent); child.persist(transaction); } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/ExcelArtifactExtractor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/ExcelArtifactExtractor.java index 41320f4cd50..177e4bbb77d 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/ExcelArtifactExtractor.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/ExcelArtifactExtractor.java @@ -46,6 +46,7 @@ import org.xml.sax.helpers.XMLReaderFactory; public class ExcelArtifactExtractor extends AbstractArtifactExtractor { private static final Pattern guidPattern = Pattern.compile("(\\d*);(.*)"); + private static final Pattern paragraphNumberPattern = Pattern.compile("\\d{1}+"); @Override public String getDescription() { @@ -201,7 +202,10 @@ public class ExcelArtifactExtractor extends AbstractArtifactExtractor { if (Strings.isValid(rowValue)) { switch (rowType) { case PARAGRAPH_NO: - roughArtifact.setSectionNumber(row[rowIndex]); + if (paragraphNumberPattern.matcher(rowValue).matches()) { + rowValue = String.format("%s.0", rowValue); //forcing \\d.0 format + } + roughArtifact.setSectionNumber(rowValue); roughArtifact.addAttribute(CoreAttributeTypes.ParagraphNumber, rowValue); break; case ARTIFACT_NAME: @@ -250,7 +254,5 @@ public class ExcelArtifactExtractor extends AbstractArtifactExtractor { public void reachedEndOfWorksheet() { // do nothing } - } - } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/OutlineResolution.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/OutlineResolution.java index 0a1e5637c36..65ef4cdd488 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/OutlineResolution.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/parsers/OutlineResolution.java @@ -10,95 +10,65 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.importing.parsers; +import java.util.Collection; +import java.util.HashSet; import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.skynet.core.importing.ReqNumbering; public final class OutlineResolution { - private static final String OUTLINE_NUMBER_DELIMITER = "\\."; - public final boolean isInvalidOutlineNumber(String currentOutlineNumber, String lastOutlineNumber) { - if (Strings.isValid(currentOutlineNumber) && Strings.isValid(lastOutlineNumber) && currentOutlineNumber.length() >= 1 && lastOutlineNumber.length() >= 1) { + if (Strings.isValid(currentOutlineNumber, lastOutlineNumber)) { - String[] lastOutlineNumberArray = lastOutlineNumber.split(OUTLINE_NUMBER_DELIMITER); - String[] currentOutlineNumberArray = currentOutlineNumber.split(OUTLINE_NUMBER_DELIMITER); + ReqNumbering current = new ReqNumbering(currentOutlineNumber, false); + ReqNumbering last = new ReqNumbering(lastOutlineNumber, false); - int minLength = currentOutlineNumberArray.length; - if (minLength > lastOutlineNumberArray.length) { - minLength = lastOutlineNumberArray.length; + switch (last.compareTo(current)) { + case 1: + case -1: + boolean check = !generateNextSet(last).contains(current.getNumberString()); + return check; + case 0: + default: + return false; } - - //should I show GUI to resolve conflict? - return decideNextPossibleOutlineNumber(currentOutlineNumberArray, lastOutlineNumberArray, minLength) ? false : true; - } else { return false; } } /** - * Determines if the incoming number follows a logical next based on the previous outline number found. + * @param lastNumberParagrah i.e. new ReqNumbering("4.0"); + * @return set of combinations i.e ["4.1, 5.0"] */ - private boolean decideNextPossibleOutlineNumber(String[] currentOutlineNumberArray, String[] lastOutlineNumberArray, int minLength) { - boolean detectedAtLeastOnePositive = false; // set to true moment a delta of 1 is found. - boolean finalDecisionIfNumberFollowsPattern = false; // decision that gets returned to calling method, whether the paragraph follows the right pattern - int zeroDeltaCounter = 0; // counts amount of time delta is 0 - for (int nextNumberIndex = 0; nextNumberIndex < minLength; nextNumberIndex++) { - int currentDigit = extractDigitsSafely(currentOutlineNumberArray[nextNumberIndex]); - int lastDigit = extractDigitsSafely(lastOutlineNumberArray[nextNumberIndex]); + public Collection generateNextSet(ReqNumbering lastNumberParagrah) { + String last = lastNumberParagrah.getNumberString(); + Collection nextParagraphs = new HashSet(); - int delta = currentDigit - lastDigit; + for (int i = last.length() - 1; i >= 0; i--) { - if (delta == 1) { - if (detectedAtLeastOnePositive) { - detectedAtLeastOnePositive = false; - break; - } else { - detectedAtLeastOnePositive = true; - } - } else if (delta == 0) { - //made to track difference between previous and next is 0 - //i.e. last=2.1.1.1 current=2.1.1.1.1 - zeroDeltaCounter++; - } else if (delta < 0) { - //negative delta, therefore number - //does not follow pattern - //invalidate previous findings. - if (currentDigit == 0) { - //current if zero will disqualify a valid outline number - //example: last: 3.1 current: 4.0 - break; - } else { - detectedAtLeastOnePositive = false; - break; - } - } + if (last.charAt(i) != '.') { + int currentInt = extractDigitsSafely(last.subSequence(i, i + 1).toString()); - //check for last=2.1.1.1 current=2.1.1.1.1, indented paragraphs - if (nextNumberIndex == minLength - 1 && zeroDeltaCounter == minLength && currentOutlineNumberArray.length > lastOutlineNumberArray.length) { - if (Strings.isValid(currentOutlineNumberArray[currentOutlineNumberArray.length - 1])) { - if (currentOutlineNumberArray[currentOutlineNumberArray.length - 1].compareTo("1") == 0) { - detectedAtLeastOnePositive = true; - } else { - detectedAtLeastOnePositive = false; - } - break; + if (i == last.length() - 1) { + nextParagraphs.add(String.format("%s%s", last, ".0.1")); + nextParagraphs.add(String.format("%s%s", last, ".1")); } - } - } - if (detectedAtLeastOnePositive) { - finalDecisionIfNumberFollowsPattern = true; + nextParagraphs.add(String.format("%s%s", last.subSequence(0, i), + (i != 0) ? currentInt + 1 : String.format("%s.0", currentInt + 1))); + } } - return finalDecisionIfNumberFollowsPattern; + return nextParagraphs; } private int extractDigitsSafely(String stringContainingDigit) { - int returnValue = -1; + int returnValue = 0; try { returnValue = Integer.parseInt(stringContainingDigit); } catch (NumberFormatException ex) { - returnValue = -1; + returnValue = 0; } return returnValue; } 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 5a52cfaad8c..83cf8814c5c 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 @@ -34,8 +34,7 @@ import org.eclipse.osee.framework.skynet.core.internal.Activator; import org.eclipse.osee.framework.skynet.core.word.WordUtil; /** - * Test: @link WordOutlineTest - * + * @see WordOutlineTest * @author Karol M. Wilk */ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate { @@ -44,7 +43,7 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate private static final Pattern WT_ELEMENT_REGEX = Pattern.compile("(.*?)"); // Node: private static final Pattern LIST_ITEM_REGEX = Pattern.compile(""); - private static final Pattern OUTLINE_NUMBER = Pattern.compile("((?>\\d+\\.)+\\d*)\\s*"); + private static final Pattern OUTLINE_NUMBER_REGEX = Pattern.compile("((?>\\d+\\.)+\\d*(?>-\\d+)*)\\s*"); // This assumes that the user uses a generated Table of Contents from Word and does not come up with // his/hers own version of of a style can call it "TOC\d+" @@ -53,7 +52,7 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate private boolean possibleTableOfContents; private static String detectedTableOfContentsReportError = - "Table of Contents found in document. Please remove per the spec on: \n http://wiki.eclipse.org/OSEE/HowTo/ImportArtifactsFromWordML"; + "Table of Contents found in document. Please remove per the spec on: \n http://wiki.eclipse.org/OSEE/HowTo/ImportArtifacts"; public enum ContentType { CONTENT, @@ -102,7 +101,6 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate } public WordOutlineExtractorDelegate(IConflictResolvingGui gui) { - super(); conflictResolvingGui = gui; } @@ -137,7 +135,7 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate } /** - * Sublcasses may extend this method to dispose resources. + * Subclasses may extend this method to dispose resources. */ @Override public void dispose() { @@ -189,7 +187,7 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate } /** - * Given content (a paragraph), fill outlineContent with extracted content information from + * Given content a paragraph, fill outlineContent with extracted content information from * grabNameAndTemplateContent() * * @param content a paragraph. @@ -197,15 +195,14 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate * @return if found any new content or not... */ private boolean processContentOfParagraph(String content, StringBuilder outlineContent) { - outlineContent = new StringBuilder(300); //average content is larger than 16 chars + outlineContent = new StringBuilder(content.length()); grabNameAndTemplateContent(content, outlineContent); - boolean newOutlineContent = false; - newOutlineContent = outlineContent.length() != 0; + boolean newOutlineContent = outlineContent.length() != 0; if (newOutlineContent) { - resetLastContent(); - setLastContent(outlineContent.toString()); + lastContent.setLength(0); + lastContent.append(outlineContent.toString()); } return newOutlineContent; @@ -229,13 +226,13 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate boolean outlineNumberDetected = outlineNumber.length() != 0; if (outlineNumberDetected) { - resetLastHeaderNumber(); + lastHeaderNumber.setLength(0); setLastHeaderNumber(outlineNumber.toString()); grabNameAndTemplateContent(content, outlineName); if (outlineName.length() != 0) { - resetLastHeaderName(); - setLastHeaderName(outlineName.toString()); + lastHeaderName.setLength(0); + lastHeaderName.append(outlineName.toString()); } } return outlineNumberDetected; @@ -248,7 +245,7 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate if (outLineStorage.length() == 0) { Matcher wtElementMatcher = WT_ELEMENT_REGEX.matcher(paragraph); while (wtElementMatcher.find()) { - Matcher checkingForOutlineNumber = OUTLINE_NUMBER.matcher(wtElementMatcher.group(1)); + Matcher checkingForOutlineNumber = OUTLINE_NUMBER_REGEX.matcher(wtElementMatcher.group(1)); if (!checkingForOutlineNumber.matches()) { outLineStorage.append(wtElementMatcher.group(1)); } @@ -257,8 +254,10 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate } /** - * Specializes in extraction of "1. scope" type of outline number and names. Outline name can also be spread out over - * multiple s + * Specializes in extraction of "1.0 scope" type of outline number and names. Outline name can also be spread out + * over multiple {@code } elements.
+ * + * @note Paragraph numbering must be zero based. "1.0 SCOPE" instead of "1. SCOPE" */ private void specializedOutlineNumberTitleExtract(String paragraph, StringBuilder outlineNumberStorage, StringBuilder outlineTitleStorage) throws OseeCoreException { StringBuilder wtStorage = new StringBuilder(paragraph.length()); @@ -269,11 +268,11 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate int indexOfFirstSpace = wtStorage.toString().indexOf(" "); if (indexOfFirstSpace != -1) { - CharSequence title = wtStorage.subSequence(0, indexOfFirstSpace); - Matcher outlineNumberMatcher = OUTLINE_NUMBER.matcher(title); - if (outlineNumberMatcher.matches()) { + CharSequence paragraphNumber = wtStorage.subSequence(0, indexOfFirstSpace); + Matcher outlineNumberMatcher = OUTLINE_NUMBER_REGEX.matcher(paragraphNumber); + if (outlineNumberMatcher.matches() && paragraphNumber.length() > 2) { //length check excludes 1. non-zero based paragraph numbers. processSpecializedOutlineNumberAndTitle(outlineNumberMatcher.group(), - (String) wtStorage.subSequence(indexOfFirstSpace, wtStorage.length()), outlineNumberStorage, + wtStorage.subSequence(indexOfFirstSpace, wtStorage.length()).toString(), outlineNumberStorage, outlineTitleStorage); } else { outlineTitleStorage = wtStorage; @@ -376,32 +375,11 @@ public class WordOutlineExtractorDelegate implements IArtifactExtractorDelegate return getBufferString(lastHeaderName); } - private void setLastHeaderName(String headerName) { - lastHeaderName.append(headerName); - } - public String getLastContent() { return getBufferString(lastContent); } - private void setLastContent(String content) { - lastContent.append(content); - } - private String getBufferString(StringBuffer builder) { return builder != null ? builder.toString() : null; } - - private void resetLastHeaderNumber() { - lastHeaderNumber.setLength(0); - } - - private void resetLastHeaderName() { - lastHeaderName.setLength(0); - } - - private void resetLastContent() { - lastContent.setLength(0); - } - } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/resolvers/AttributeBasedArtifactResolver.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/resolvers/AttributeBasedArtifactResolver.java index a29903d093c..c0c773c9092 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/resolvers/AttributeBasedArtifactResolver.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/resolvers/AttributeBasedArtifactResolver.java @@ -10,8 +10,8 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.importing.resolvers; +import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -44,11 +44,8 @@ public class AttributeBasedArtifactResolver extends NewArtifactImportResolver { for (IAttributeType attributeType : nonChangingAttributes) { Collection attributeValues = artifact.getAttributesToStringList(attributeType); - Collection roughAttributes = roughAttributeSet.getAttributeValueList(attributeType); - - if (roughAttributes == null) { - roughAttributes = Collections.emptyList(); - } + Collection roughAttributes = + roughAttributeSet.getAttributeValueList(attributeType, new ArrayList()); if (attributeValues.size() == roughAttributes.size()) { for (String attributeValue : attributeValues) { @@ -81,7 +78,10 @@ public class AttributeBasedArtifactResolver extends NewArtifactImportResolver { List descendants = root.getDescendants(); Collection candidates = new LinkedList(); - for (Artifact artifact : descendants) { + System.out.println(String.format("Resolved using: %s", + !descendants.isEmpty() ? "root node." : "realParent descendants.")); + + for (Artifact artifact : !descendants.isEmpty() ? descendants : realParent.getDescendants()) { if (attributeValuesMatch(roughArtifact, artifact)) { candidates.add(artifact); } diff --git a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/importer/ArtifactImportWizardTest.java b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/importer/ArtifactImportWizardTest.java index 71642aa2312..ea72a03a9d9 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/importer/ArtifactImportWizardTest.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/importer/ArtifactImportWizardTest.java @@ -90,8 +90,8 @@ public final class ArtifactImportWizardTest { // copy imported paragraph over... because they will be matched on guid... Map answerParagraphNumbers = new HashMap(); - answerParagraphNumbers.put("B", "3"); - answerParagraphNumbers.put("D", "2"); + answerParagraphNumbers.put("B", "3.0"); + answerParagraphNumbers.put("D", "2.0"); int numberOfDescendants = myRootArtifact.getDescendants().size(); @@ -102,12 +102,11 @@ public final class ArtifactImportWizardTest { //check if artifacts have correct attributes copied over for (Artifact artifact : afterArtifacts) { - String artifactName = artifact.getName(); List attributes = artifact.getAttributes(CoreAttributeTypes.ParagraphNumber); for (Object attribute : attributes) { - String paragraphNumberAnswer = answerParagraphNumbers.get(artifactName); + String paragraphNumberAnswer = answerParagraphNumbers.get(artifact.getName()); if (paragraphNumberAnswer != null) { - Assert.assertTrue(String.format("Expected attribute: %s, on Artifact %s, wasn't copied. ", + Assert.assertTrue(String.format("Expected attribute: %s, on Artifact %s, was not copied. ", CoreAttributeTypes.ParagraphNumber, artifact), paragraphNumberAnswer.equals(attribute.toString())); } } diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/MatchingStrategy.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/MatchingStrategy.java index c1311dac12b..6753475aee9 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/MatchingStrategy.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/MatchingStrategy.java @@ -20,9 +20,9 @@ import org.eclipse.osee.framework.skynet.core.importing.resolvers.IArtifactImpor import org.eclipse.osee.framework.skynet.core.importing.resolvers.NewArtifactImportResolver; public enum MatchingStrategy { - ATTRIBUTE(), - GUID(), - NONE(); + ATTRIBUTE, + GUID, + NONE; public IArtifactImportResolver getResolver(IArtifactType primaryArtifactType, Collection nonChangingAttributes, boolean createNewIfNotExist, boolean deleteUnmatchedArtifacts) { switch (this) { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/RelationsComposite.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/RelationsComposite.java index e76647068ed..97c7cad85e1 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/RelationsComposite.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/RelationsComposite.java @@ -12,6 +12,7 @@ package org.eclipse.osee.framework.ui.skynet; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -45,6 +46,7 @@ import org.eclipse.osee.framework.skynet.core.relation.RelationTypeSideSorter; import org.eclipse.osee.framework.ui.plugin.util.HelpUtil; import org.eclipse.osee.framework.ui.skynet.accessProviders.RelationTypeAccessProvider; import org.eclipse.osee.framework.ui.skynet.RelationOrderContributionItem.SelectionListener; +import org.eclipse.osee.framework.ui.skynet.accessProviders.RelationTypeAccessProvider; import org.eclipse.osee.framework.ui.skynet.action.RevealInExplorerAction; import org.eclipse.osee.framework.ui.skynet.artifact.massEditor.MassArtifactEditor; import org.eclipse.osee.framework.ui.skynet.relation.explorer.RelationExplorerWindow; @@ -500,11 +502,6 @@ public class RelationsComposite extends Composite implements ISelectedArtifact { }); } - @Override - public void dispose() { - super.dispose(); - } - private void expandAll(IStructuredSelection selection) { Iterator iter = selection.iterator(); while (iter.hasNext()) { @@ -772,7 +769,7 @@ public class RelationsComposite extends Composite implements ISelectedArtifact { RelationTypeAccessProvider relationTypeAccessProvider = new RelationTypeAccessProvider(); hasPermission = relationTypeAccessProvider.relationTypeHasPermission( - SkynetGuiPlugin.getInstance().getPolicyHandlerService(), Collections.asCollection(relationTypeSide)); + SkynetGuiPlugin.getInstance().getPolicyHandlerService(), Arrays.asList(relationTypeSide)); } catch (OseeCoreException ex) { OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex); } @@ -798,4 +795,4 @@ public class RelationsComposite extends Composite implements ISelectedArtifact { return null; } -} \ No newline at end of file +} -- cgit v1.2.3