Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbroberts2018-09-20 20:32:36 -0400
committerbroberts2018-09-26 17:34:54 -0400
commit03c045c17959df0d771900ab23e0f51dae6f9cda (patch)
treedfedeb2549bfafc889cc3cd277228fc013f6c33a
parent201ec7e4043f77e80ab5980094731e952ba17728 (diff)
downloadorg.eclipse.osee-03c045c17959df0d771900ab23e0f51dae6f9cda.tar.gz
org.eclipse.osee-03c045c17959df0d771900ab23e0f51dae6f9cda.tar.xz
org.eclipse.osee-03c045c17959df0d771900ab23e0f51dae6f9cda.zip
bug[ats_TW10767]: Fix dragging native artifact. Also add multi-file popup checker.
Change-Id: Ide95cac57a18ad9dbeefab944ade423ddb07bbae Signed-off-by: broberts <baily.e.roberts@boeing.com>
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/resolvers/AttributeBasedArtifactResolver.java8
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/resolvers/DropTargetAttributeBasedResolver.java50
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactResolverFactory.java10
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/explorer/ArtifactExplorerDragAndDrop.java98
4 files changed, 138 insertions, 28 deletions
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 00cfa377d24..f032da87b68 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
@@ -31,8 +31,8 @@ import org.eclipse.osee.framework.skynet.core.internal.Activator;
*/
public class AttributeBasedArtifactResolver extends NewArtifactImportResolver {
- private final Collection<AttributeTypeToken> nonChangingAttributes;
- private final boolean createNewIfNotExist;
+ protected final Collection<AttributeTypeToken> nonChangingAttributes;
+ protected final boolean createNewIfNotExist;
public AttributeBasedArtifactResolver(IRoughArtifactTranslator translator, IArtifactType primaryArtifactType, IArtifactType secondaryArtifactType, Collection<AttributeTypeToken> nonChangingAttributes, boolean createNewIfNotExist, boolean deleteUnmatchedArtifacts) {
super(translator, primaryArtifactType, secondaryArtifactType);
@@ -40,7 +40,7 @@ public class AttributeBasedArtifactResolver extends NewArtifactImportResolver {
this.createNewIfNotExist = createNewIfNotExist;
}
- private boolean attributeValuesMatch(RoughArtifact roughArtifact, Artifact artifact) throws OseeCoreException {
+ protected boolean attributeValuesMatch(RoughArtifact roughArtifact, Artifact artifact) throws OseeCoreException {
RoughAttributeSet roughAttributeSet = roughArtifact.getAttributes();
for (AttributeTypeToken attributeType : nonChangingAttributes) {
@@ -66,7 +66,7 @@ public class AttributeBasedArtifactResolver extends NewArtifactImportResolver {
return false;
}
- private String normalizeAttributeValue(String value) {
+ protected String normalizeAttributeValue(String value) {
return value.trim().replaceAll("\\.$", "").toLowerCase();
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/resolvers/DropTargetAttributeBasedResolver.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/resolvers/DropTargetAttributeBasedResolver.java
new file mode 100644
index 00000000000..c6d7087c5d8
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/importing/resolvers/DropTargetAttributeBasedResolver.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.resolvers;
+
+import java.util.Collection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.osee.framework.core.data.AttributeTypeToken;
+import org.eclipse.osee.framework.core.data.BranchId;
+import org.eclipse.osee.framework.core.data.IArtifactType;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.importing.RoughArtifact;
+
+/**
+ * @author Baily E. Roberts
+ */
+public class DropTargetAttributeBasedResolver extends AttributeBasedArtifactResolver {
+ private final Artifact dropTarget;
+ public static final Pattern oseeFilePattern = Pattern.compile("([^_]+)_[^\\d]+[^_]+_[^-]+.*");
+ public static final Matcher oseeFileMatcher = oseeFilePattern.matcher("");
+
+ public DropTargetAttributeBasedResolver(IRoughArtifactTranslator translator, IArtifactType primaryArtifactType, IArtifactType secondaryArtifactType, Collection<AttributeTypeToken> nonChangingAttributes, boolean createNewIfNotExist, boolean deleteUnmatchedArtifacts, Artifact dropTarget) {
+ super(translator, primaryArtifactType, secondaryArtifactType, nonChangingAttributes, createNewIfNotExist,
+ deleteUnmatchedArtifacts);
+ this.dropTarget = dropTarget;
+ }
+
+ @Override
+ public Artifact resolve(RoughArtifact roughArtifact, BranchId branch, Artifact realParent, Artifact root) throws OseeCoreException {
+
+ oseeFileMatcher.reset(roughArtifact.getName());
+ if (oseeFileMatcher.find()) {
+ roughArtifact.setName(oseeFileMatcher.group(1));
+ }
+ if (dropTarget != null && attributeValuesMatch(roughArtifact, dropTarget)) {
+ getTranslator().translate(roughArtifact, dropTarget);
+ }
+
+ return dropTarget;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactResolverFactory.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactResolverFactory.java
index ca2dbeaf383..6c1ab1bdaed 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactResolverFactory.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/Import/ArtifactResolverFactory.java
@@ -14,8 +14,10 @@ import java.util.Collection;
import org.eclipse.osee.framework.core.data.AttributeTypeToken;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.importing.resolvers.AttributeBasedArtifactResolver;
import org.eclipse.osee.framework.skynet.core.importing.resolvers.DoorsBestFitArtifactResolver;
+import org.eclipse.osee.framework.skynet.core.importing.resolvers.DropTargetAttributeBasedResolver;
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.importing.resolvers.IRoughArtifactTranslator;
@@ -75,4 +77,12 @@ public final class ArtifactResolverFactory {
}
return toReturn;
}
+
+ public static IArtifactImportResolver createResolver(ArtifactCreationStrategy strategy, IArtifactType primaryArtifactType, Collection<AttributeTypeToken> nonChangingAttributes, boolean createNewIfNotExist, boolean deleteUnmatchedArtifacts, Artifact dropTarget) {
+
+ return new DropTargetAttributeBasedResolver(new RoughArtifactTranslatorImpl(), primaryArtifactType,
+ CoreArtifactTypes.HeadingMSWord, nonChangingAttributes, createNewIfNotExist, deleteUnmatchedArtifacts,
+ dropTarget);
+
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/explorer/ArtifactExplorerDragAndDrop.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/explorer/ArtifactExplorerDragAndDrop.java
index 489f254ebcc..16a183e7753 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/explorer/ArtifactExplorerDragAndDrop.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/explorer/ArtifactExplorerDragAndDrop.java
@@ -16,6 +16,7 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
+import java.util.regex.Matcher;
import org.apache.commons.io.FilenameUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
@@ -42,6 +43,7 @@ import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager;
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.DropTargetAttributeBasedResolver;
import org.eclipse.osee.framework.skynet.core.importing.resolvers.IArtifactImportResolver;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
@@ -229,43 +231,91 @@ public class ArtifactExplorerDragAndDrop extends SkynetDragAndDrop {
File importFile = new File(items[0]);
ArtifactImportWizard wizard = new ArtifactImportWizard();
+ Matcher fileMatcher = DropTargetAttributeBasedResolver.oseeFileMatcher;
wizard.setImportFile(importFile);
wizard.setDestinationArtifact(parentArtifact);
String fileName = importFile.getName();
- if (isSameName(parentArtifact, fileName)) {
- String promptMsg = String.format(
- "Artifact [%s] has same base file name as [%s]. \n\nDo you want to update the exisiting file? \nIf 'NO' selected, you'll be taken to the Artifact Import Wizard",
- parentArtifact.getName(), FilenameUtils.getName(fileName));
-
- if (MessageDialog.openQuestion(viewPart.getViewSite().getShell(), "Confirm Import", promptMsg)) {
-
- IArtifactImportResolver resolver =
- ArtifactResolverFactory.createResolver(ArtifactCreationStrategy.CREATE_ON_DIFFERENT_ATTRIBUTES,
- parentArtifact.getArtifactType(), Arrays.asList(CoreAttributeTypes.Name), true, false);
- try {
- ArtifactImportOperationParameter parameter = new ArtifactImportOperationParameter();
- parameter.setSourceFile(importFile);
- parameter.setDestinationArtifact(parentArtifact.getParent());
- parameter.setExtractor(getArtifactExtractor(parentArtifact.getArtifactType()));
- parameter.setResolver(resolver);
- parameter.setStopOnError(true);
-
- IOperation operation = ArtifactImportOperationFactory.completeOperation(parameter);
- Operations.executeWorkAndCheckStatus(operation);
- } catch (OseeCoreException ex) {
- OseeLog.log(getClass(), OseeLevel.SEVERE_POPUP, ex);
- }
+ boolean importWizardUserSelection = true;
+ if (items.length > 1) {
+ importWizardUserSelection = importWithMoreThanOneFile(fileName);
+ }
+
+ if (importWizardUserSelection == true) {
+ fileMatcher.reset(fileName);
+ if (fileMatcher.find()) {
+ fileName = fileMatcher.group(1);
+ }
+ if (isSameName(parentArtifact, fileName)) {
+ importSimilarArtifact(parentArtifact, importFile, wizard, fileName);
} else {
- Wizards.initAndOpen(wizard, viewPart, new ArtifactStructuredSelection(parentArtifact));
+ importOverChild(parentArtifact, importFile, wizard, fileName);
+ }
+ }
+ }
+ }
+
+ private void importOverChild(Artifact parentArt, File importFile, ArtifactImportWizard wizard, String fileName) {
+ boolean imported = false;
+ for (Artifact child : parentArt.getChildren()) {
+ if (child.getName().equals(FilenameUtils.getBaseName(fileName))) {
+ importSimilarArtifact(child, importFile, wizard, fileName);
+ imported = true;
+ break;
+ }
+ }
+ if (!imported) {
+ Wizards.initAndOpen(wizard, viewPart, new ArtifactStructuredSelection(parentArt));
+ }
+ }
+
+ private void importSimilarArtifact(Artifact parentArtifact, File importFile, ArtifactImportWizard wizard, String fileName) {
+ {
+ String promptMsg = String.format(
+ "Artifact [%s] has same base file name as [%s]. \n\nDo you want to update the exisiting file? \nIf 'NO' selected, you'll be taken to the Artifact Import Wizard",
+ parentArtifact.getName(), FilenameUtils.getName(fileName));
+
+ if (MessageDialog.openQuestion(viewPart.getViewSite().getShell(), "Confirm Import", promptMsg)) {
+
+ IArtifactImportResolver resolver = ArtifactResolverFactory.createResolver(
+ ArtifactCreationStrategy.CREATE_ON_DIFFERENT_ATTRIBUTES, parentArtifact.getArtifactType(),
+ Arrays.asList(CoreAttributeTypes.Name), true, false, parentArtifact);
+ try {
+ ArtifactImportOperationParameter parameter = new ArtifactImportOperationParameter();
+ parameter.setSourceFile(importFile);
+ parameter.setDestinationArtifact(parentArtifact.getParent());
+ parameter.setExtractor(getArtifactExtractor(parentArtifact.getArtifactType()));
+ parameter.setResolver(resolver);
+ parameter.setStopOnError(true);
+
+ IOperation operation = ArtifactImportOperationFactory.completeOperation(parameter);
+ Operations.executeWorkAndCheckStatus(operation);
+ } catch (OseeCoreException ex) {
+ OseeLog.log(getClass(), OseeLevel.SEVERE_POPUP, ex);
}
+
} else {
Wizards.initAndOpen(wizard, viewPart, new ArtifactStructuredSelection(parentArtifact));
}
}
}
+ private boolean importWithMoreThanOneFile(String fileName) {
+ {
+ String promptMsg = String.format(
+ "It appears you are trying to import more than 1 file, only the first file, [%s] will be choosen.\n\nIs that okay? \nIf no selected, the process will cease.",
+ FilenameUtils.getName(fileName));
+
+ if (MessageDialog.openQuestion(viewPart.getViewSite().getShell(), "Confirm First File Import", promptMsg)) {
+ return true;
+
+ } else {
+ return false;
+ }
+ }
+ }
+
private void performTextTransfer(final DropTargetEvent event, Artifact parentArtifact) {
Object object = TextTransfer.getInstance().nativeToJava(event.currentDataType);
try {

Back to the top