diff options
author | megumi.telles | 2018-03-13 17:44:02 +0000 |
---|---|---|
committer | megumi.telles | 2018-03-13 18:39:13 +0000 |
commit | 2716a004eadb6dfefa6ec71648554d33a2837301 (patch) | |
tree | f0371bf1c2aff337f81c46f94351c0ee5e7dc1b6 | |
parent | c48d13aa9de89acc31f578af8d957260a886b619 (diff) | |
download | org.eclipse.osee-2716a004eadb6dfefa6ec71648554d33a2837301.tar.gz org.eclipse.osee-2716a004eadb6dfefa6ec71648554d33a2837301.tar.xz org.eclipse.osee-2716a004eadb6dfefa6ec71648554d33a2837301.zip |
feature[ats_TW7914]: Prompt for commit override when admin
5 files changed, 116 insertions, 22 deletions
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 @@ -198,14 +198,6 @@ </IHttpServerRequest> </extension> <extension - id="CatchWordMlChanges" - name="CatchWordMlChanges" - point="org.eclipse.osee.framework.skynet.core.CommitActions"> - <commitActions - className="org.eclipse.osee.framework.skynet.core.commit.actions.CatchWordMlChanges"> - </commitActions> - </extension> - <extension point="org.eclipse.osee.framework.skynet.core.OseeValidator"> <OseeValidator classname="org.eclipse.osee.framework.skynet.core.attribute.OseeEnumerationValidation"> @@ -282,5 +274,11 @@ <commitActions className="org.eclipse.osee.framework.skynet.core.commit.actions.CatchArtifactChanges"> </commitActions> + </extension> + <extension + point="org.eclipse.osee.framework.skynet.core.CommitActions"> + <commitActions + className="org.eclipse.osee.framework.skynet.core.commit.actions.CatchWordMlChanges"> + </commitActions> </extension> </plugin> 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"> </Operation> </extension> + <extension + point="org.eclipse.osee.framework.skynet.core.CommitActions"> + <commitActions + className="org.eclipse.osee.framework.ui.skynet.commit.CatchValidationChecks"> + </commitActions> + </extension> </plugin> 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<Artifact> changedArtifacts = new HashSet<>(); + Collection<Change> 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<Artifact> 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()); + } + +} |