Skip to content

Commit

Permalink
Merge pull request Open-MBEE#105 from mbee-dev/donbot-aaron
Browse files Browse the repository at this point in the history
Reworked MDKHelper and MDKValidationWindow for donbot.
  • Loading branch information
Ivan Gomes authored and GitHub Enterprise committed Nov 2, 2016
2 parents 1e3b396 + e0aa5d1 commit 92fa226
Show file tree
Hide file tree
Showing 9 changed files with 414 additions and 656 deletions.
1 change: 0 additions & 1 deletion src/main/java/gov/nasa/jpl/mbee/mdk/MMSConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.nomagic.magicdraw.actions.ActionsStateUpdater;
import com.nomagic.magicdraw.actions.MDActionsCategory;
import gov.nasa.jpl.mbee.mdk.ems.actions.*;
import gov.nasa.jpl.mbee.mdk.lib.MDUtils;

public class MMSConfigurator implements AMConfigurator {

Expand Down
463 changes: 202 additions & 261 deletions src/main/java/gov/nasa/jpl/mbee/mdk/api/MDKHelper.java

Large diffs are not rendered by default.

533 changes: 167 additions & 366 deletions src/main/java/gov/nasa/jpl/mbee/mdk/api/MDKValidationWindow.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public void setLogoutAction(EMSLogoutAction logout) {

@Override
public void actionPerformed(ActionEvent e) {
loginAction(Application.getInstance().getProject(), "", "");
loginAction(Application.getInstance().getProject());
ActionsStateUpdater.updateActionsState();
}

public boolean loginAction(Project project, String username, String password) {
return loginAction(project, username, password, true);
public boolean loginAction(Project project) {
return loginAction(project, true);
}

public static boolean loginAction(Project project, String username, String password, boolean initJms) {
public static boolean loginAction(Project project, boolean initJms) {
if (project == null) {
Utils.showPopupMessage("You need to have a project open first!");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public void setLoginAction(EMSLoginAction login) {

@Override
public void actionPerformed(ActionEvent e) {
logoutAction();
}

public void logoutAction() {
TicketUtils.clearUsernameAndPassword();
for (Project p : Application.getInstance().getProjectsManager().getProjects()) {
MMSSyncPlugin.getInstance().getJmsSyncProjectEventListenerAdapter().projectClosed(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,33 @@ public class DeltaSyncRunner implements RunnableWithProgress {

private boolean failure = true;

private ValidationSuite changelogSuite = new ValidationSuite("Updated Elements/Failed Updates");
private ValidationRule locallyChangedValidationRule = new ValidationRule("updated", "updated", ViolationSeverity.INFO);
private ValidationRule cannotUpdate = new ValidationRule("cannotUpdate", "cannotUpdate", ViolationSeverity.ERROR);
private ValidationRule cannotRemove = new ValidationRule("cannotDelete", "cannotDelete", ViolationSeverity.WARNING);
private ValidationRule cannotCreate = new ValidationRule("cannotCreate", "cannotCreate", ViolationSeverity.ERROR);
// private ValidationSuite changelogSuite = new ValidationSuite("Updated Elements/Failed Updates");
// private ValidationRule locallyChangedValidationRule = new ValidationRule("Updated Locally", "updated", ViolationSeverity.INFO);
// private ValidationRule cannotUpdate = new ValidationRule("Cannot Update", "cannotUpdate", ViolationSeverity.ERROR);
// private ValidationRule cannotRemove = new ValidationRule("Cannot Delete", "cannotDelete", ViolationSeverity.WARNING);
// private ValidationRule cannotCreate = new ValidationRule("Cannot Create", "cannotCreate", ViolationSeverity.ERROR);

private Changelog<String, Element> failedLocalChangelog = new Changelog<>();
private Changelog<String, Void> failedJmsChangelog = new Changelog<>(), successfulJmsChangelog = new Changelog<>();

private List<ValidationSuite> vss = new ArrayList<>();

{
changelogSuite.addValidationRule(locallyChangedValidationRule);
changelogSuite.addValidationRule(cannotUpdate);
changelogSuite.addValidationRule(cannotRemove);
changelogSuite.addValidationRule(cannotCreate);
}
// {
// changelogSuite.addValidationRule(locallyChangedValidationRule);
// changelogSuite.addValidationRule(cannotUpdate);
// changelogSuite.addValidationRule(cannotRemove);
// changelogSuite.addValidationRule(cannotCreate);
// }

/*public DeltaSyncRunner(boolean shouldCommit, boolean skipUpdate, boolean shouldDelete) {
this.shouldCommit = shouldCommit;
this.skipUpdate = skipUpdate;
this.shouldDelete = shouldDelete;
}*/

@Deprecated
public DeltaSyncRunner(boolean shouldCommit, boolean shouldCommitDeletes) {
this(shouldCommit, shouldCommitDeletes, true);
}
// @Deprecated
// public DeltaSyncRunner(boolean shouldCommit, boolean shouldCommitDeletes) {
// this(shouldCommit, shouldCommitDeletes, true);
// }

public DeltaSyncRunner(boolean shouldCommmit, boolean shouldCommitDeletes, boolean shouldUpdate) {
this.shouldCommit = shouldCommmit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
* Created by igomes on 9/26/16.
*/
public class ManualSyncRunner implements RunnableWithProgress {

public static final String INITIALIZE_PROJECT_COMMENT = "The project doesn't exist on the web.";
private final Collection<Element> rootElements;
private final Project project;
private final boolean recurse;
Expand Down Expand Up @@ -183,7 +185,7 @@ public boolean checkProject() {

String workspace = MMSUtils.getServiceWorkspacesUri(project).getPath();
if (workspace.contains("master")) {
v = new ValidationRuleViolation(project.getModel(), "The project doesn't exist on the web.");
v = new ValidationRuleViolation(project.getModel(), INITIALIZE_PROJECT_COMMENT);
v.addAction(new CommitProjectAction(project, true));
} else {
v = new ValidationRuleViolation(project.getModel(), "The trunk project doesn't exist on the web. Export the trunk first.");
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/gov/nasa/jpl/mbee/mdk/lib/TicketUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,30 @@ public static boolean isTicketSet() {
}

/**
* Logs in to MMS, using pre-specified credentials or prompting the user for new credentials.
*
* @return True if successfully logged in to MMS
* If username and password have been pre-specified, will not display the dialog even if popups are
* enabled. Else will display the login dialog and use the returned value.
*
* @return TRUE if successfully logged in to MMS, FALSE otherwise.
* Will always return FALSE if popups are disabled and username/password are not pre-specified
*/
public static boolean loginToMMS() {
if (!Utils.isPopupsDisabled()) {
if (!username.isEmpty() && !password.isEmpty()){
acquireTicket(password);
}
else if (!Utils.isPopupsDisabled()) {
acquireTicket(showLoginDialog());
}
else {
acquireTicket(password);
return false;
}
return !ticket.isEmpty();
}

/**
* Shows a login dialog window and uses its filled in values to set the username and password.
* Stores the entered username for future use / convenience, passes the entered password to acquireTicket().
*/
private static String showLoginDialog() {
// Pop up dialog for logging into Alfresco
Expand Down Expand Up @@ -186,8 +195,10 @@ public static void clearUsernameAndPassword() {
}

/**
* Uses the stored username and password to query MMS for a ticket. Will first check to see if an existing ticket is
* still valid, and will not resend for the ticket if it remains valid.
* Uses the stored username and passed password to query MMS for a ticket.
*
* Will first check to see if there is an existing ticket, and if so if it is valid. If valid, will not resend
* for new ticket. If invalid or not present, will send for new ticket.
*
* Since it can only be called by logInToMMS(), assumes that the username and password were recently
* acquired from the login dialogue or pre-specified if that's disabled.
Expand All @@ -203,7 +214,7 @@ private static void acquireTicket(String pass) {

// build request
// @donbot retained Application.getInstance().getProject() instead of making project agnostic because you can only
// log in to the currently opening project
// log in to the currently opening project
Project project = Application.getInstance().getProject();
URIBuilder requestUri = MMSUtils.getServiceUri(project);
if (requestUri == null || username.isEmpty() || pass.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.nomagic.teamwork.common.users.SessionInfo;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement;
import gov.nasa.jpl.mbee.mdk.api.MDKHelper;
import gov.nasa.jpl.mbee.mdk.ems.MMSUtils;
import gov.nasa.jpl.mbee.mdk.ems.ServerException;

import javax.xml.bind.DatatypeConverter;
Expand Down Expand Up @@ -245,7 +246,7 @@ private void checkSiteEditPermission() throws IOException, IllegalAccessExceptio
throw new IllegalAccessException("Automated View Generation failed - User " + teamworkUsername + " can not log in to MMS server.");
// LOG: Invalid account
}
if (!MDKHelper.hasSiteEditPermission()) {
if (!MMSUtils.isSiteEditable(Application.getInstance().getProject(), MMSUtils.getSiteName(Application.getInstance().getProject()))) {
String message = "[FAILURE] User " + teamworkUsername + " does not have permission to MMS site or MMS is unsupported version.";
logMessage(message);
error = 103;
Expand Down

0 comments on commit 92fa226

Please sign in to comment.