From cf45ea31632f648e78179a394342665c3bfef4a9 Mon Sep 17 00:00:00 2001 From: kwilk Date: Fri, 6 Jan 2012 16:57:30 -0700 Subject: refactor: Add import parameter for artifact import operation factory --- .../osee/ats/config/demo/PopulateDemoActions.java | 21 ++- .../Import/ArtifactImportOperationFactory.java | 38 ++++- .../Import/ArtifactImportOperationParameter.java | 164 +++++++++++++++++++++ 3 files changed, 211 insertions(+), 12 deletions(-) create mode 100644 plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactImportOperationParameter.java diff --git a/plugins/org.eclipse.osee.ats.config.demo/src/org/eclipse/osee/ats/config/demo/PopulateDemoActions.java b/plugins/org.eclipse.osee.ats.config.demo/src/org/eclipse/osee/ats/config/demo/PopulateDemoActions.java index 1da3f2469d5..2c1fd496707 100644 --- a/plugins/org.eclipse.osee.ats.config.demo/src/org/eclipse/osee/ats/config/demo/PopulateDemoActions.java +++ b/plugins/org.eclipse.osee.ats.config.demo/src/org/eclipse/osee/ats/config/demo/PopulateDemoActions.java @@ -83,6 +83,7 @@ import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateComposite.TableLo import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateItem; import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateItemAction; import org.eclipse.osee.framework.ui.skynet.Import.ArtifactImportOperationFactory; +import org.eclipse.osee.framework.ui.skynet.Import.ArtifactImportOperationParameter; import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.osee.support.test.util.DemoArtifactTypes; import org.eclipse.osee.support.test.util.DemoSawBuilds; @@ -126,13 +127,14 @@ public class PopulateDemoActions extends XNavigateItemAction { } private static void validateArtifactCache() throws OseeStateException { - if (ArtifactCache.getDirtyArtifacts().size() > 0) { - for (Artifact artifact : ArtifactCache.getDirtyArtifacts()) { + final Collection list = ArtifactCache.getDirtyArtifacts(); + if (!list.isEmpty()) { + for (Artifact artifact : list) { System.err.println(String.format("Artifact [%s] is dirty [%s]", artifact.toStringWithId(), Artifacts.getDirtyReport(artifact))); } throw new OseeStateException("[%d] Dirty Artifacts found after populate (see console for details)", - ArtifactCache.getDirtyArtifacts().size()); + list.size()); } } @@ -156,7 +158,7 @@ public class PopulateDemoActions extends XNavigateItemAction { // Import all requirements on SAW_Bld_1 Branch demoDbImportReqsTx(); - DemoDbUtil.sleep(5000); + //DemoDbUtil.sleep(5000); // Create traceability between System, Subsystem and Software requirements SkynetTransaction demoDbTraceability = @@ -164,7 +166,7 @@ public class PopulateDemoActions extends XNavigateItemAction { demoDbTraceabilityTx(demoDbTraceability, DemoSawBuilds.SAW_Bld_1); demoDbTraceability.execute(); - DemoDbUtil.sleep(5000); + //DemoDbUtil.sleep(5000); // Create SAW_Bld_2 Child Main Working Branch off SAW_Bld_1 createMainWorkingBranchTx(); @@ -375,8 +377,13 @@ public class PopulateDemoActions extends XNavigateItemAction { IArtifactExtractor extractor = new WordOutlineExtractor(); extractor.setDelegate(new WordOutlineExtractorDelegate()); - IOperation operation = - ArtifactImportOperationFactory.createOperation(file, systemReq, null, extractor, artifactResolver, false); + ArtifactImportOperationParameter importOptions = new ArtifactImportOperationParameter(); + importOptions.setSourceFile(file); + importOptions.setDestinationArtifact(systemReq); + importOptions.setExtractor(extractor); + importOptions.setResolver(artifactResolver); + + IOperation operation = ArtifactImportOperationFactory.createOperation(importOptions); Operations.executeWorkAndCheckStatus(operation); // Validate that something was imported diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactImportOperationFactory.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactImportOperationFactory.java index 85b5a36f996..bef73483b7c 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactImportOperationFactory.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactImportOperationFactory.java @@ -15,12 +15,14 @@ import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.operation.AbstractOperation; import org.eclipse.osee.framework.core.operation.CompositeOperation; import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.core.operation.NullOperationLogger; import org.eclipse.osee.framework.core.operation.OperationLogger; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.skynet.core.importing.RoughArtifact; @@ -46,19 +48,45 @@ public final class ArtifactImportOperationFactory { super(); } - public static IOperation createOperation(File sourceFile, Artifact destinationArtifact, OperationLogger logger, IArtifactExtractor extractor, IArtifactImportResolver resolver, boolean stopOnError) throws OseeCoreException { - SkynetTransaction transaction = - new SkynetTransaction(destinationArtifact.getBranch(), "Artifact Import Wizard transaction"); + public static IOperation createOperation(ArtifactImportOperationParameter param) throws OseeCoreException { + return completeOperation(param.getSourceFile(), param.getDestinationArtifact(), param.getLogger(), + param.getExtractor(), param.getResolver(), param.isStopOnError(), param.getGoverningTransaction(), + param.isExecuteTransaction()); + } + + public static IOperation completeOperation(File sourceFile, Artifact destinationArtifact, OperationLogger logger, IArtifactExtractor extractor, IArtifactImportResolver resolver, boolean stopOnError, SkynetTransaction governingTransaction, boolean executeTransaction) throws OseeCoreException { + CheckAndThrow(sourceFile, destinationArtifact, extractor, resolver); + RoughArtifactCollector collector = new RoughArtifactCollector(new RoughArtifact(RoughArtifactKind.PRIMARY)); + if (logger == null) { + logger = NullOperationLogger.getSingleton(); + } + + SkynetTransaction transaction = governingTransaction; + if (transaction == null) { + executeTransaction = true; + transaction = + new SkynetTransaction(destinationArtifact.getBranch(), + "ArtifactImportOperationFactory: Artifact Import Wizard transaction"); + } + List ops = new ArrayList(); ops.add(new SourceToRoughArtifactOperation(logger, extractor, sourceFile, collector)); ops.add(new RoughToRealArtifactOperation(transaction, destinationArtifact, collector, resolver, false)); ops.add(new ArtifactValidationCheckOperation(destinationArtifact.getDescendants(), stopOnError)); - ops.add(new CompleteArtifactImportOperation(transaction, destinationArtifact)); + if (executeTransaction) { + ops.add(new CompleteArtifactImportOperation(transaction, destinationArtifact)); + } return new CompositeOperation("Artifact Import", Activator.PLUGIN_ID, ops); } + private static void CheckAndThrow(Object... objects) { + for (Object object : objects) { + Assert.isNotNull(object); + } + } + public static IOperation createArtifactAndRoughToRealOperation(File sourceFile, Artifact destinationArtifact, OperationLogger logger, IArtifactExtractor extractor, IArtifactImportResolver resolver, RoughArtifactCollector collector, Collection selectionArtifactTypes, boolean stopOnError, boolean deleteUnMatched, boolean runFilterByAttributes) throws OseeCoreException { List ops = new ArrayList(); ops.add(createArtifactsCompOperation( @@ -119,4 +147,4 @@ public final class ArtifactImportOperationFactory { return new CompositeOperation(opName, Activator.PLUGIN_ID, ops); } -} \ No newline at end of file +} diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactImportOperationParameter.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactImportOperationParameter.java new file mode 100644 index 00000000000..e693e08123f --- /dev/null +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactImportOperationParameter.java @@ -0,0 +1,164 @@ +/******************************************************************************* + * 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.ui.skynet.Import; + +import java.io.File; +import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.core.operation.OperationLogger; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.importing.parsers.ExcelArtifactExtractor; +import org.eclipse.osee.framework.skynet.core.importing.parsers.IArtifactExtractor; +import org.eclipse.osee.framework.skynet.core.importing.parsers.NativeDocumentExtractor; +import org.eclipse.osee.framework.skynet.core.importing.parsers.WholeWordDocumentExtractor; +import org.eclipse.osee.framework.skynet.core.importing.resolvers.AttributeBasedArtifactResolver; +import org.eclipse.osee.framework.skynet.core.importing.resolvers.GuidBasedArtifactResolver; +import org.eclipse.osee.framework.skynet.core.importing.resolvers.IArtifactImportResolver; +import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction; + +/** + * Encapsulating parameter class for creating Artifact Import {@link IOperation}s
+ *
+ * Example: + * + *
+ * ...
+ * ArtifactImportOperationParameter importParams = new ArtifactImportOperationParameter();
+ * importParameters.setSourceFile(sourceFile);
+ * importParameters.setDestinationArtifact(destinationFolder);
+ * importParameters.setExtractor(new WholeWordDocumentExtractor());
+ * importParameters.setResolver(resolver);
+ * importParameters.setGoverningTransaction(transaction);
+ * ...
+ * IOperation operation = ArtifactImportOperationFactory.createOperation(importParams);
+ * ...
+ * 
+ */ +public class ArtifactImportOperationParameter { + private File sourceFile; + private Artifact destinationArtifact; + private OperationLogger logger; + private IArtifactExtractor extractor; + private IArtifactImportResolver resolver; + private boolean stopOnError; + private SkynetTransaction governingTransaction; + private boolean executeTransaction; + + public ArtifactImportOperationParameter() { + this(null, null, null, null, null, false, null, false); + } + + public ArtifactImportOperationParameter(File sourceFile, Artifact destinationArtifact, OperationLogger logger, IArtifactExtractor extractor, IArtifactImportResolver resolver, boolean stopOnError, SkynetTransaction governingTransaction, boolean executeTransaction) { + this.sourceFile = sourceFile; + this.destinationArtifact = destinationArtifact; + this.logger = logger; + this.extractor = extractor; + this.resolver = resolver; + this.stopOnError = stopOnError; + this.governingTransaction = governingTransaction; + this.executeTransaction = executeTransaction; + } + + public SkynetTransaction getGoverningTransaction() { + return governingTransaction; + } + + /** + * @param governingTransaction transaction governing the import process, if null, operation will create and execute + * its own. + */ + public void setGoverningTransaction(SkynetTransaction governingTransaction) { + this.governingTransaction = governingTransaction; + } + + public boolean isExecuteTransaction() { + return executeTransaction; + } + + /** + * @param executeTransaction manual flag to execute passed in {@link SkynetTransaction} + */ + public void setExecuteTransaction(boolean executeTransaction) { + this.executeTransaction = executeTransaction; + } + + public File getSourceFile() { + return sourceFile; + } + + /** + * @param sourceFile being imported + */ + public void setSourceFile(File sourceFile) { + this.sourceFile = sourceFile; + } + + public Artifact getDestinationArtifact() { + return destinationArtifact; + } + + /** + *
+    * destinationArtifact
+    * |
+    * |- some artifact A from sourceFile
+    * |
+    * `- some artifact B from sourceFile
+    * 
+ * + * @param destinationArtifact parent artifact under which all imported artifact will "live" + */ + public void setDestinationArtifact(Artifact destinationArtifact) { + this.destinationArtifact = destinationArtifact; + } + + public OperationLogger getLogger() { + return logger; + } + + /** + * @param logger used during this operation + */ + public void setLogger(OperationLogger logger) { + this.logger = logger; + } + + public IArtifactExtractor getExtractor() { + return extractor; + } + + /** + * @param extractor specific artifact extractor {@link ExcelArtifactExtractor}, {@link NativeDocumentExtractor}, + * {@link WholeWordDocumentExtractor} + */ + public void setExtractor(IArtifactExtractor extractor) { + this.extractor = extractor; + } + + public IArtifactImportResolver getResolver() { + return resolver; + } + + /** + * @param resolver encapsulated logic helping to resolve artifacts, most common are + * {@link AttributeBasedArtifactResolver} or {@link GuidBasedArtifactResolver} + */ + public void setResolver(IArtifactImportResolver resolver) { + this.resolver = resolver; + } + + public boolean isStopOnError() { + return stopOnError; + } + + public void setStopOnError(boolean stopOnError) { + this.stopOnError = stopOnError; + } +} \ No newline at end of file -- cgit v1.2.3