From 2716a004eadb6dfefa6ec71648554d33a2837301 Mon Sep 17 00:00:00 2001 From: megumi.telles Date: Tue, 13 Mar 2018 10:44:02 -0700 Subject: feature[ats_TW7914]: Prompt for commit override when admin --- .../plugin.xml | 14 ++- .../core/commit/actions/CatchWordMlChanges.java | 14 --- .../META-INF/MANIFEST.MF | 1 + .../plugin.xml | 6 ++ .../ui/skynet/commit/CatchValidationChecks.java | 103 +++++++++++++++++++++ 5 files changed, 116 insertions(+), 22 deletions(-) create mode 100644 plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/commit/CatchValidationChecks.java diff --git a/plugins/org.eclipse.osee.framework.skynet.core/plugin.xml b/plugins/org.eclipse.osee.framework.skynet.core/plugin.xml index 393ea67ffbc..222eed1547f 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/plugin.xml +++ b/plugins/org.eclipse.osee.framework.skynet.core/plugin.xml @@ -197,14 +197,6 @@ classname="org.eclipse.osee.framework.skynet.core.httpRequests.ClientLoopbackHandler"> - - - - + + + + diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/commit/actions/CatchWordMlChanges.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/commit/actions/CatchWordMlChanges.java index 3aaacb229ac..14b84e817f7 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/commit/actions/CatchWordMlChanges.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/commit/actions/CatchWordMlChanges.java @@ -16,9 +16,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.eclipse.core.runtime.IStatus; import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.exception.OseeWrappedException; import org.eclipse.osee.framework.core.operation.IOperation; import org.eclipse.osee.framework.core.operation.Operations; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; @@ -31,8 +29,6 @@ import org.eclipse.osee.framework.skynet.core.revision.ChangeManager; import org.eclipse.osee.framework.skynet.core.revision.LoadChangeType; import org.eclipse.osee.framework.skynet.core.utility.ApplicabilityUtility; import org.eclipse.osee.framework.skynet.core.utility.OseeInfo; -import org.eclipse.osee.framework.skynet.core.validation.IOseeValidator; -import org.eclipse.osee.framework.skynet.core.validation.OseeValidator; import org.eclipse.osee.framework.skynet.core.word.WordUtil; /** @@ -106,16 +102,6 @@ public class CatchWordMlChanges implements CommitAction { throw new OseeCoreException(err); } - OseeValidator validator = OseeValidator.getInstance(); - for (Artifact artifactChanged : changedArtifacts) { - if (!artifactChanged.isDeleted()) { - IStatus status = validator.validate(IOseeValidator.LONG, artifactChanged); - if (status.getSeverity() == IStatus.ERROR) { - throw new OseeWrappedException(getArtifactErrorMessage(artifactChanged) + " " + status.getMessage(), - status.getException()); - } - } - } } private String getArtifactErrorMessage(Artifact artifact) { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF index 9a96aaa1376..6d6e170a8d5 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF @@ -103,6 +103,7 @@ Import-Package: com.google.common.base;version="15.0.0", org.eclipse.osee.framework.skynet.core.artifact.update, org.eclipse.osee.framework.skynet.core.attribute, org.eclipse.osee.framework.skynet.core.change, + org.eclipse.osee.framework.skynet.core.commit.actions, org.eclipse.osee.framework.skynet.core.conflict, org.eclipse.osee.framework.skynet.core.event, org.eclipse.osee.framework.skynet.core.event.filter, diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml b/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml index 36d285e6bdf..0f8cade9c0c 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml +++ b/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml @@ -1641,4 +1641,10 @@ className="org.eclipse.osee.framework.ui.skynet.blam.operation.ChangeArtifactName"> + + + + diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/commit/CatchValidationChecks.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/commit/CatchValidationChecks.java new file mode 100644 index 00000000000..2cf3641ff80 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/commit/CatchValidationChecks.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 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.commit; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osee.framework.core.data.BranchId; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.framework.core.exception.OseeWrappedException; +import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.jdk.core.type.MutableBoolean; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.skynet.core.UserManager; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.change.Change; +import org.eclipse.osee.framework.skynet.core.commit.actions.CommitAction; +import org.eclipse.osee.framework.skynet.core.revision.ChangeManager; +import org.eclipse.osee.framework.skynet.core.validation.IOseeValidator; +import org.eclipse.osee.framework.skynet.core.validation.OseeValidator; +import org.eclipse.osee.framework.ui.swt.Displays; + +/** + * @author Megumi Telles + */ +public class CatchValidationChecks implements CommitAction { + + private static final String ATS_TEMP_ADMIN = "AtsTempAdmin"; + private static final String ATS_ADMIN = "AtsAdmin"; + + @Override + public void runCommitAction(BranchId sourceBranch, BranchId destinationBranch) throws OseeCoreException { + Set changedArtifacts = new HashSet<>(); + Collection changes = new ArrayList<>(); + IOperation operation = ChangeManager.compareTwoBranchesHead(sourceBranch, destinationBranch, changes); + Operations.executeWorkAndCheckStatus(operation); + + for (Change change : changes) { + if (!change.getModificationType().isDeleted()) { + Artifact artifactChanged = change.getChangeArtifact(); + if (artifactChanged != null) { + changedArtifacts.add(artifactChanged); + } + } + } + + final MutableBoolean adminOverride = new MutableBoolean(false); + OseeValidator validator = OseeValidator.getInstance(); + for (Artifact artifactChanged : changedArtifacts) { + if (!artifactChanged.isDeleted()) { + IStatus status = validator.validate(IOseeValidator.LONG, artifactChanged); + if (status.getSeverity() == IStatus.ERROR) { + // Allow Admin to override state validation + checkForOverride(adminOverride, status, artifactChanged); + if (!adminOverride.getValue()) { + throw new OseeWrappedException(getArtifactErrorMessage(artifactChanged) + " " + status.getMessage(), + status.getException()); + } + } + } + } + + } + + private void checkForOverride(final MutableBoolean adminOverride, IStatus status, Artifact artifactChanged) { + List relatedArtifacts = UserManager.getUser().getRelatedArtifacts(CoreRelationTypes.Users_Artifact); + for (Artifact related : relatedArtifacts) { + if (related.getName().equals(ATS_ADMIN) || related.getName().equals(ATS_TEMP_ADMIN)) { + Displays.pendInDisplayThread(new Runnable() { + @Override + public void run() { + if (MessageDialog.openConfirm(Displays.getActiveShell(), "Override State Validation", + status.getMessage() + " [" + artifactChanged.getName() + "(" + artifactChanged.getArtId() + ")]" // + + "\n\nYou are set as Admin, OVERRIDE this?")) { + adminOverride.setValue(true); + } else { + adminOverride.setValue(false); + } + } + }); + } + } + } + + private String getArtifactErrorMessage(Artifact artifact) { + return String.format("Error validating: [(%s)(%s) - %s] on branchUuid:[%s]", artifact.getArtId(), + artifact.getGuid(), artifact.getName(), artifact.getBranch()); + } + +} -- cgit v1.2.3