diff --git a/build.gradle b/build.gradle index 0e3bf979d..c3ea9aaa3 100644 --- a/build.gradle +++ b/build.gradle @@ -272,7 +272,7 @@ class PreDist extends DefaultTask { String pluginLibraries = '' project.fileTree(dir: "build/generated-dist/plugins/${groupName}", include: '**/*.jar').each { file -> - pluginLibraries += '\t\t' + System.lineSeparator() + pluginLibraries += '\t\t' + System.lineSeparator() } project.copy { from 'src/main/dist/template/plugins/${group}/plugin.xml' @@ -284,7 +284,7 @@ class PreDist extends DefaultTask { String descriptorFiles = '' project.fileTree(dir: 'build/generated-dist').each { file -> - String relativePath = file.absolutePath.replaceAll(/.*build\/generated-dist\//, '') + String relativePath = file.absolutePath.replace(File.separator, '/').replaceAll(/.*build\/generated-dist\//, '') descriptorFiles += '\t\t' + System.lineSeparator() } project.copy { diff --git a/gradle.properties b/gradle.properties index 4de47ab51..23bbd3f86 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=4.3.1 +version=4.4.0 group=org.openmbee.magicdraw.mdk descriptorFile=MDR_Plugin_Model_Development_Kit_91110_descriptor.xml magicdDrawGroupName=gov.nasa.jpl.cae.magicdraw.mdk diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java index 3b2b5ca8d..9db2d0daf 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java @@ -32,7 +32,7 @@ import java.io.*; import java.net.HttpURLConnection; import java.net.URISyntaxException; -import java.rmi.RemoteException; +import java.security.GeneralSecurityException; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -266,7 +266,7 @@ private void loadTeamworkProject() throws IOException, URISyntaxException, Inter mmsRefUri.setParameter("alf_ticket", ticketStore).setPath(mmsRefUri.getPath() + "/" + parser.getOptionValue(REF_ID)); MMSUtils.sendMMSRequest(null, MMSUtils.buildRequest(MMSUtils.HttpRequestType.GET, mmsRefUri), null, refsNode); } - } catch (IOException | ServerException e) { + } catch (IOException | ServerException | GeneralSecurityException e) { illegalStateFailure("[FAILURE] Unable to load project, exception occurred while resolving one of the required project URI parameters."); e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java index e4303bac5..30a70b614 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java @@ -1,7 +1,6 @@ package gov.nasa.jpl.mbee.mdk.docgen; import com.nomagic.magicdraw.core.Application; -import com.nomagic.magicdraw.core.GUILog; import com.nomagic.magicdraw.core.Project; import com.nomagic.magicdraw.export.image.ImageExporter; import com.nomagic.magicdraw.properties.BooleanProperty; @@ -12,12 +11,17 @@ import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*; import gov.nasa.jpl.mbee.mdk.docgen.docbook.DocumentElement; import gov.nasa.jpl.mbee.mdk.docgen.view.ViewElement; +import gov.nasa.jpl.mbee.mdk.util.MDUtils; import org.apache.commons.lang3.StringEscapeUtils; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; -import java.io.*; +import javax.xml.transform.TransformerException; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -87,6 +91,9 @@ public class DocGenUtils { }; private static final Pattern ENTITY_PATTERN = Pattern.compile("(&[^\\s]+?;)"); + public static int DOCGEN_DIAGRAM_DPI = 72; + public static int DOCGEN_DIAGRAM_SCALE_PERCENT = 100; + /** * docbook ignores regular white space in table cells, this is to force * indentation in docbook, 1 indent is 4 spaces @@ -418,13 +425,11 @@ public static String html2docbook(String html) { * will be the diagram id in magicdraw. The images will be 72 dpi and 100% * scaling. * - * @param diagram the magicdraw diagram element - * @param directory directory for docbook xml output (without trailing slash) + * @param diagram the magicdraw diagram element + * @param directory directory for docbook xml output (without trailing slash) * @throws IOException */ public static List exportDiagram(Diagram diagram, File directory) throws IOException { - int dpi = 72; - int scalePercent = 100; Project project = Application.getInstance().getProject(); if (project == null) { return Collections.emptyList(); @@ -442,9 +447,9 @@ public static List exportDiagram(Diagram diagram, File directory) throws results.add(directory.getName() + "/" + svgFileName); try { - ImageExporter.export(diagramPresentationElement, ImageExporter.SVG, svgDiagramFile, false, dpi, scalePercent); - ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, pngDiagramFile, false, dpi, scalePercent); - } catch (IOException e) { + MDUtils.exportSVG(svgDiagramFile, diagramPresentationElement); + ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, pngDiagramFile, false, DOCGEN_DIAGRAM_DPI, DOCGEN_DIAGRAM_SCALE_PERCENT); + } catch (IOException | TransformerException e) { e.printStackTrace(); return results; } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java b/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java index 17ab179af..f8c7c1c3e 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java @@ -12,8 +12,8 @@ import com.nomagic.uml2.ext.jmi.helpers.ModelHelper; import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper; import com.nomagic.uml2.ext.magicdraw.auxiliaryconstructs.mdmodels.Model; -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Package; +import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*; import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.Connector; import com.nomagic.uml2.ext.magicdraw.mdprofiles.Stereotype; import com.nomagic.uml2.ext.magicdraw.metadata.UMLPackage; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java index 64845c452..a0dc89507 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java @@ -16,8 +16,8 @@ import com.nomagic.task.EmptyProgressStatus; import com.nomagic.task.ProgressStatus; import com.nomagic.task.RunnableWithProgress; -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Package; +import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*; import gov.nasa.jpl.mbee.mdk.api.incubating.MDKConstants; import gov.nasa.jpl.mbee.mdk.api.incubating.convert.Converters; import gov.nasa.jpl.mbee.mdk.docgen.ViewViewpointValidator; @@ -51,6 +51,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -268,7 +269,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { viewResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { failure = true; Application.getInstance().getGUILog().log("[ERROR] An error occurred. View generation aborted. Please check your network connection or view logs for more information. Reason: " + e.getMessage()); e.printStackTrace(); @@ -336,7 +337,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { instanceAndSlotResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { failure = true; Application.getInstance().getGUILog().log("[ERROR] An error occurred. View generation aborted. Please check your network connection or view logs for more information. Reason: " + e.getMessage()); e.printStackTrace(); @@ -660,7 +661,7 @@ public List getEStructuralFeatureOverrides() { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } @@ -692,7 +693,7 @@ public List getEStructuralFeatureOverrides() { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java index d5be33fbf..0e99b6ada 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java @@ -46,10 +46,8 @@ import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; +import java.security.GeneralSecurityException; +import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -74,7 +72,8 @@ public static AtomicReference getLastException() { return LAST_EXCEPTION; } - public static ObjectNode getElement(Project project, String elementId, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException { + public static ObjectNode getElement(Project project, String elementId, ProgressStatus progressStatus) + throws IOException, ServerException, URISyntaxException, GeneralSecurityException { Collection elementIds = new ArrayList<>(1); elementIds.add(elementId); File responseFile = getElementsRecursively(project, elementIds, 0, progressStatus); @@ -89,7 +88,8 @@ public static ObjectNode getElement(Project project, String elementId, ProgressS return null; } - public static File getElementRecursively(Project project, String elementId, int depth, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException { + public static File getElementRecursively(Project project, String elementId, int depth, ProgressStatus progressStatus) + throws IOException, ServerException, URISyntaxException, GeneralSecurityException { Collection elementIds = new ArrayList<>(1); elementIds.add(elementId); return getElementsRecursively(project, elementIds, depth, progressStatus); @@ -104,7 +104,8 @@ public static File getElementRecursively(Project project, String elementId, int * @throws IOException * @throws URISyntaxException */ - public static File getElements(Project project, Collection elementIds, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException { + public static File getElements(Project project, Collection elementIds, ProgressStatus progressStatus) + throws IOException, ServerException, URISyntaxException, GeneralSecurityException { return getElementsRecursively(project, elementIds, 0, progressStatus); } @@ -118,7 +119,8 @@ public static File getElements(Project project, Collection elementIds, P * @throws IOException * @throws URISyntaxException */ - public static File getElementsRecursively(Project project, Collection elementIds, int depth, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static File getElementsRecursively(Project project, Collection elementIds, int depth, ProgressStatus progressStatus) + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { // verify elements if (elementIds == null || elementIds.isEmpty()) { return null; @@ -138,7 +140,7 @@ public static File getElementsRecursively(Project project, Collection el return sendMMSRequest(project, MMSUtils.buildRequest(MMSUtils.HttpRequestType.PUT, requestUri, sendData, ContentType.APPLICATION_JSON), progressStatus); } - public static File getArtifacts(Project project, Collection artifactIds, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static File getArtifacts(Project project, Collection artifactIds, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException, GeneralSecurityException { if (artifactIds == null || artifactIds.isEmpty()) { return null; } @@ -150,15 +152,18 @@ public static File getArtifacts(Project project, Collection artifactIds, return sendMMSRequest(project, MMSUtils.buildRequest(MMSUtils.HttpRequestType.PUT, requestUri, sendData, ContentType.APPLICATION_JSON), progressStatus); } - public static String getCredentialsTicket(Project project, String username, String password, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static String getCredentialsTicket(Project project, String username, String password, ProgressStatus progressStatus) + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { return getCredentialsTicket(project, null, username, password, progressStatus); } - public static String getCredentialsTicket(String baseUrl, String username, String password, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static String getCredentialsTicket(String baseUrl, String username, String password, ProgressStatus progressStatus) + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { return getCredentialsTicket(null, baseUrl, username, password, progressStatus); } - private static String getCredentialsTicket(Project project, String baseUrl, String username, String password, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + private static String getCredentialsTicket(Project project, String baseUrl, String username, String password, ProgressStatus progressStatus) + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { URIBuilder requestUri = MMSUtils.getServiceUri(project, baseUrl); if (requestUri == null) { return null; @@ -189,7 +194,8 @@ private static String getCredentialsTicket(Project project, String baseUrl, Stri return null; } - public static String validateCredentialsTicket(Project project, String ticket, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static String validateCredentialsTicket(Project project, String ticket, ProgressStatus progressStatus) + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { URIBuilder requestUri = MMSUtils.getServiceUri(project); if (requestUri == null) { return ""; @@ -362,7 +368,7 @@ else if (node instanceof String && jsonBlobType == JsonBlobType.ELEMENT_ID || js * @throws IOException * @throws ServerException */ - public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus, final ObjectNode responseJson) throws IOException, ServerException, URISyntaxException { + public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus, final ObjectNode responseJson) throws IOException, ServerException, GeneralSecurityException { final File responseFile = (responseJson == null ? File.createTempFile("Response-", null) : null); final AtomicReference responseBody = new AtomicReference<>(); final AtomicReference responseCode = new AtomicReference<>(); @@ -454,11 +460,11 @@ public static File sendMMSRequest(Project project, HttpRequestBase request, Prog return responseFile; } - public static File sendMMSRequest(Project project, HttpRequestBase request) throws IOException, ServerException, URISyntaxException { + public static File sendMMSRequest(Project project, HttpRequestBase request) throws IOException, ServerException, URISyntaxException, GeneralSecurityException { return sendMMSRequest(project, request, null, null); } - public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException { + public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException, GeneralSecurityException { return sendMMSRequest(project, request, progressStatus, null); } @@ -561,7 +567,8 @@ else if (ProjectUtilities.isStandardSystemProfile(project.getPrimaryProject())) return urlString.trim(); } - public static String getMmsOrg(Project project) throws IOException, URISyntaxException, ServerException { + public static String getMmsOrg(Project project) + throws IOException, URISyntaxException, ServerException, GeneralSecurityException { URIBuilder uriBuilder = getServiceProjectsUri(project); File responseFile = sendMMSRequest(project, buildRequest(HttpRequestType.GET, uriBuilder)); try (JsonParser responseParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { @@ -612,8 +619,14 @@ private static URIBuilder getServiceUri(Project project, String baseUrl) { e.printStackTrace(); return null; } - - uri.setPath("/alfresco/service"); + String path = Optional.ofNullable(uri.getPath()).orElse(""); + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } + if (!path.endsWith("alfresco/service")) { + path += "/alfresco/service"; + } + uri.setPath(path); if (project != null && TicketUtils.isTicketSet(project)) { uri.setParameter("alf_ticket", TicketUtils.getTicket(project)); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java index 1c310419b..87aa8937f 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java @@ -37,6 +37,7 @@ import java.io.IOException; import java.lang.reflect.Field; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -179,7 +180,7 @@ public void run(ProgressStatus progressStatus) { } } } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS branches. Branch commit aborted. Reason: " + e.getMessage()); return; @@ -212,7 +213,7 @@ public void run(ProgressStatus progressStatus) { File sendFile = MMSUtils.createEntityFile(this.getClass(), ContentType.APPLICATION_JSON, refsNodes, MMSUtils.JsonBlobType.REF); HttpRequestBase request = MMSUtils.buildRequest(MMSUtils.HttpRequestType.POST, requestUri, sendFile, ContentType.APPLICATION_JSON); MMSUtils.sendMMSRequest(project, request); - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while posting branch. Branch commit aborted. Reason: " + e.getMessage()); e.printStackTrace(); return; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java index 473ff8101..19d09d7f7 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collection; @@ -124,7 +125,7 @@ private static void request(List elementsToUpdate, List elem TaskRunner.runWithProgressStatus(progressStatus -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } @@ -144,7 +145,7 @@ private static void request(List elementsToUpdate, List elem TaskRunner.runWithProgressStatus(progressStatus -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java index 52fe7b7b7..76f359156 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.util.Collection; import java.util.Collections; import java.util.Set; @@ -86,7 +87,7 @@ public void actionPerformed(@CheckForNull ActionEvent actionEvent) { File file = MMSUtils.createEntityFile(CommitClientElementAction.class, ContentType.APPLICATION_JSON, Collections.singleton(objectNode), MMSUtils.JsonBlobType.ELEMENT_JSON); HttpRequestBase request = MMSUtils.buildRequest(MMSUtils.HttpRequestType.POST, elementsRequestUri, file, ContentType.APPLICATION_JSON); MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] Failed to commit diagram artifacts for " + Converters.getElementToHumanNameConverter().apply(diagram) + ". Reason: " + e.getMessage()); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java index 5e05c462b..327df631d 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.util.Collection; import java.util.LinkedList; import java.util.UUID; @@ -95,7 +96,7 @@ public String commitAction() { } } } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS orgs. Aborting org creation. Reason: " + e.getMessage()); e.printStackTrace(); return null; @@ -113,7 +114,7 @@ public String commitAction() { try { File sendData = MMSUtils.createEntityFile(this.getClass(), ContentType.APPLICATION_JSON, orgs, MMSUtils.JsonBlobType.ORG); MMSUtils.sendMMSRequest(project, MMSUtils.buildRequest(MMSUtils.HttpRequestType.POST, requestUri, sendData, ContentType.APPLICATION_JSON)); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while committing org. Org commit cancelled. Reason: " + e.getMessage()); e.printStackTrace(); return null; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java index 11c6228e5..912103532 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java @@ -27,6 +27,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.util.*; public class CommitProjectAction extends RuleViolationAction implements AnnotationAction, IRuleViolationAction { @@ -78,7 +79,7 @@ public String commitAction() { try { orgId = MMSUtils.getMmsOrg(project); // a null result here just means the project isn't on mms - } catch (IOException | URISyntaxException | ServerException e1) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e1) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while checking for project org on MMS. Project commit cancelled. Reason: " + e1.getMessage()); e1.printStackTrace(); return null; @@ -92,7 +93,7 @@ public String commitAction() { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { response = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException e1) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e1) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS orgs. Project commit cancelled. Reason: " + e1.getMessage()); e1.printStackTrace(); return null; @@ -156,7 +157,7 @@ public String toString() { // crude method of waiting for project post to propagate Thread.sleep(5000); } - } catch (IOException | URISyntaxException | ServerException | InterruptedException e1) { + } catch (IOException | URISyntaxException | ServerException | InterruptedException | GeneralSecurityException e1) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while posting project to MMS. Project commit cancelled. Reason: " + e1.getMessage()); e1.printStackTrace(); return null; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java index ae5a5fc61..37b97bd9c 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.util.Collection; import java.util.Map; @@ -79,7 +80,7 @@ public static boolean postImage(Project project, String key, Map { try { MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java index 5bb6b5f5f..5bc8bf127 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java @@ -13,6 +13,7 @@ import java.awt.event.ActionEvent; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; public class MMSLoginAction extends MDAction { private static final long serialVersionUID = 1L; @@ -45,7 +46,7 @@ public static boolean loginAction(Project project) { TaskRunner.runWithProgressStatus(progressStatus -> { try { MMSDeltaProjectEventListenerAdapter.getProjectMapping(project).update(); - } catch (URISyntaxException | IOException | ServerException e) { + } catch (URISyntaxException | IOException | ServerException | GeneralSecurityException e) { e.printStackTrace(); } }, "MMS Fetch", false, TaskRunner.ThreadExecutionStrategy.POOLED, false); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java index cc3a95647..1fad20adf 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java @@ -36,6 +36,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -72,7 +73,7 @@ public void run(ProgressStatus progressStatus) { Utils.guilog("[WARNING] You are not logged in to MMS. Skipping sync. All changes will be persisted in the model and re-attempted in the next sync."); return; } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { Utils.guilog("[ERROR] An error occurred while validating credentials. Credentials will be cleared. Skipping sync. All changes will be persisted in the model and re-attempted in the next sync. Reason: " + e.getMessage()); return; } @@ -114,7 +115,7 @@ public void run(ProgressStatus progressStatus) { Application.getInstance().getGUILog().log("[WARNING] MMS history is unavailable. Skipping sync. All changes will be re-attempted in the next sync."); return; } - } catch (URISyntaxException | IOException | IllegalStateException | ServerException e) { + } catch (URISyntaxException | IOException | IllegalStateException | GeneralSecurityException | ServerException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while updating MMS history. Credentials will be cleared. Skipping sync. All changes will be persisted in the model and re-attempted in the next sync. Reason: " + e.getMessage()); e.printStackTrace(); return; @@ -185,7 +186,7 @@ else if (value instanceof Element) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { response = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { if (progressStatus.isCancel()) { Application.getInstance().getGUILog().log("[INFO] Sync manually cancelled. All changes will be re-attempted in the next sync."); return; @@ -325,7 +326,7 @@ else if (shouldUpdate && mmsChange != null) { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } @@ -351,7 +352,7 @@ else if (shouldUpdate && mmsChange != null) { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java index 609a6025a..2956bc492 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.util.*; import java.util.stream.Collectors; @@ -114,7 +115,7 @@ public void run(ProgressStatus progressStatus) { responseFiles.add(responseFile); } } - } catch (ServerException | URISyntaxException | IOException e) { + } catch (ServerException | URISyntaxException | IOException | GeneralSecurityException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting elements from the server. Manual sync aborted. Reason: " + e.getMessage()); e.printStackTrace(); validationSuite = null; @@ -155,7 +156,7 @@ private static void collectClientElementsRecursively(Project project, Element el } private static File collectServerElementsRecursively(Project project, Element element, int depth, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { String id = Converters.getElementToIdConverter().apply(element); Collection elementIds = new ArrayList<>(1); elementIds.add(id); @@ -163,7 +164,7 @@ private static File collectServerElementsRecursively(Project project, Element el } private static File collectServerModuleElementsRecursively(Project project, int depth, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { Collection attachedModels = new ArrayList<>(project.getModels()); attachedModels.remove(project.getPrimaryModel()); Collection attachedModelIds = attachedModels.stream().map(Converters.getElementToIdConverter()).filter(amId -> amId != null).collect(Collectors.toList()); @@ -171,7 +172,7 @@ private static File collectServerModuleElementsRecursively(Project project, int } private static File collectServerHoldingBinElementsRecursively(Project project, int depth, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { String holdingBinId = MDKConstants.HOLDING_BIN_ID_PREFIX + Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()); return MMSUtils.getElementRecursively(project, holdingBinId, depth, progressStatus); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java index 7e41ab17c..2d4688d2d 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java @@ -30,6 +30,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.*; import java.util.concurrent.ScheduledFuture; @@ -48,7 +49,7 @@ public void projectOpened(Project project) { getProjectMapping(project).setScheduledFuture(TaskRunner.scheduleWithProgressStatus(progressStatus -> { try { getProjectMapping(project).update(); - } catch (URISyntaxException | IOException | ServerException e) { + } catch (URISyntaxException | IOException | ServerException | GeneralSecurityException e) { e.printStackTrace(); } }, "MMS Fetch", false, TaskRunner.ThreadExecutionStrategy.POOLED, false, (r, ses) -> ses.scheduleAtFixedRate(r, 0, 1, TimeUnit.MINUTES))); @@ -159,7 +160,7 @@ public String getLastSyncedMmsCommit() throws RuntimeException { }).map(json -> json.get("commitId")).filter(commitIdNode -> commitIdNode != null && commitIdNode.isTextual()).map(JsonNode::asText).findAny().orElse(null); } - public synchronized boolean update() throws URISyntaxException, IOException, ServerException, IllegalStateException { + public synchronized boolean update() throws URISyntaxException, IOException, ServerException, IllegalStateException, GeneralSecurityException { if (!project.isRemote()) { return false; } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java index 315f4a429..cc5c0b292 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java @@ -19,6 +19,7 @@ import java.awt.event.ActionEvent; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; /** @@ -184,7 +185,7 @@ public void actionPerformed(@CheckForNull ActionEvent actionEvent) { MMSDeltaProjectEventListenerAdapter.getProjectMapping(project).update(); progressStatus.setDescription("Updating table"); update(); - } catch (URISyntaxException | IOException | ServerException e) { + } catch (URISyntaxException | IOException | ServerException | GeneralSecurityException e) { e.printStackTrace(); } }, "Sync Status Update", false, 0); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java index 0a8876477..95954a3a3 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java @@ -33,6 +33,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.*; @@ -143,7 +144,7 @@ public void validate(ProgressStatus progressStatus, boolean allBranches) { } } } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { errors = true; e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS branches. Branch validation aborted. Reason: " + e.getMessage()); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java index e5844889b..e75b29296 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java @@ -12,12 +12,14 @@ import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Diagram; import gov.nasa.jpl.mbee.mdk.api.incubating.MDKConstants; import gov.nasa.jpl.mbee.mdk.api.incubating.convert.Converters; +import gov.nasa.jpl.mbee.mdk.docgen.DocGenUtils; import gov.nasa.jpl.mbee.mdk.http.ServerException; import gov.nasa.jpl.mbee.mdk.json.JacksonUtils; import gov.nasa.jpl.mbee.mdk.mms.MMSArtifact; import gov.nasa.jpl.mbee.mdk.mms.MMSUtils; import gov.nasa.jpl.mbee.mdk.mms.actions.CommitDiagramArtifactsAction; import gov.nasa.jpl.mbee.mdk.mms.actions.ValidateElementAction; +import gov.nasa.jpl.mbee.mdk.util.MDUtils; import gov.nasa.jpl.mbee.mdk.util.Pair; import gov.nasa.jpl.mbee.mdk.validation.ValidationRule; import gov.nasa.jpl.mbee.mdk.validation.ValidationRuleViolation; @@ -26,10 +28,12 @@ import org.apache.commons.codec.digest.DigestUtils; import org.apache.http.entity.ContentType; +import javax.xml.transform.TransformerException; import java.io.*; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; +import java.security.GeneralSecurityException; import java.util.*; import java.util.stream.Collectors; @@ -79,7 +83,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { diagramElementsResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An unexpected error occurred while generating diagrams. Skipping image validation. Reason: " + e.getMessage()); return; @@ -118,7 +122,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { artifactsResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An unexpected error occurred while generating diagrams. Skipping image validation. Reason: " + e.getMessage()); return; @@ -161,13 +165,19 @@ public void run(ProgressStatus progressStatus) { for (Map.Entry> entry : EXPORT_FORMATS.entrySet()) { Path path; String checksum; + try { path = Files.createTempFile(DiagramValidator.class.getSimpleName() + "-" + diagramId, "." + entry.getKey()); - ImageExporter.export(diagramPresentationElement, entry.getValue().getKey(), path.toFile()); + if (entry.getValue().getKey() == ImageExporter.SVG) { + MDUtils.exportSVG(path.toFile(), diagramPresentationElement); + } + else { + ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, path.toFile(), false, DocGenUtils.DOCGEN_DIAGRAM_DPI, DocGenUtils.DOCGEN_DIAGRAM_SCALE_PERCENT); + } try (InputStream inputStream = new FileInputStream(path.toFile())) { checksum = DigestUtils.md5Hex(inputStream); } - } catch (IOException e) { + } catch (IOException | TransformerException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An unexpected error occurred while generating diagrams. Skipping image validation for " + Converters.getElementToHumanNameConverter().apply(diagram) + ". Reason: " + e.getMessage()); break; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java index 70522d6c9..5eea1ef1f 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java @@ -23,21 +23,22 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; /** * SysML 2 Pilot Implementation * Copyright (C) 2018 California Institute of Technology ("Caltech") - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . * @@ -72,7 +73,7 @@ public void validate() { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { response = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { errors = true; e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS projects. Project validation aborted. Reason: " + e.getMessage()); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java index f0cae40bc..0de8fff73 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java @@ -4,18 +4,26 @@ import com.nomagic.magicdraw.core.Project; import com.nomagic.magicdraw.core.ProjectUtilities; import com.nomagic.magicdraw.esi.EsiUtils; +import com.nomagic.magicdraw.export.image.ImageExporter; import com.nomagic.magicdraw.ui.browser.BrowserTabTree; import com.nomagic.magicdraw.ui.browser.Node; import com.nomagic.magicdraw.uml.BaseElement; import com.nomagic.magicdraw.uml.symbols.DiagramPresentationElement; import com.nomagic.magicdraw.uml.symbols.PresentationElement; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element; +import gov.nasa.jpl.mbee.mdk.docgen.DocGenUtils; +import org.apache.batik.dom.svg.SAXSVGDocumentFactory; +import org.apache.batik.util.XMLResourceDescriptor; +import org.w3c.dom.Document; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.io.*; +import java.util.*; /** * A collection of utility functions for accessing the MagicDraw (MD) @@ -23,6 +31,8 @@ */ public class MDUtils { + public static String SVG_ENRICHED_EXPORT_PROPERTY_NAME = "svg.enriched.export"; + /** * @return true iff MD was started with the DEVELOPER option at the command * line. @@ -181,4 +191,30 @@ public static long getRemoteVersion(Project project) { } return Long.valueOf(ProjectUtilities.getVersion(project.getPrimaryProject()).getName()); } + + public static void exportSVG(File svgFile, DiagramPresentationElement diagramPresentationElement) throws IOException, TransformerException { + String originalSvgEnrichedExportPropertyValue = System.getProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME); + System.setProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME, Boolean.toString(!diagramPresentationElement.getDiagramType().getRootType().equals(com.nomagic.magicdraw.uml.DiagramTypeConstants.DEPENDENCY_MATRIX))); + + try (InputStream svgInputStream = new FileInputStream(svgFile); Writer svgWriter = new FileWriter(svgFile)) { + ImageExporter.export(diagramPresentationElement, ImageExporter.SVG, svgFile, false, DocGenUtils.DOCGEN_DIAGRAM_DPI, DocGenUtils.DOCGEN_DIAGRAM_SCALE_PERCENT); + String parser = XMLResourceDescriptor.getXMLParserClassName(); + SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); + Document svg = f.createDocument(null, svgInputStream); + XMLUtil.asList(svg.getElementsByTagName("g")).stream() + .filter(g -> g instanceof org.w3c.dom.Element) + .map(g -> (org.w3c.dom.Element) g) + .filter(g -> Objects.equals(g.getAttribute("class"), "element")) + .forEach(g -> g.setAttribute("stroke-width", "0px")); + DOMSource source = new DOMSource(svg); + StreamResult result = new StreamResult(svgWriter); + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + transformer.transform(source, result); + } finally { + System.setProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME, originalSvgEnrichedExportPropertyValue); + } + } + } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java index da58dadb7..644031e9a 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java @@ -19,6 +19,7 @@ import java.awt.event.HierarchyListener; import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; @@ -52,7 +53,7 @@ public static boolean isTicketSet(Project project) { return ticket != null && !ticket.isEmpty(); } - public static boolean isTicketValid(Project project, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static boolean isTicketValid(Project project, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException, GeneralSecurityException { if (!isTicketSet(project)) { return false; } @@ -243,7 +244,7 @@ private static boolean acquireTicket(Project project, String pass) { String ticket; try { ticket = MMSUtils.getCredentialsTicket(project, username, pass, progressStatus); - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while acquiring credentials. Reason: " + e.getMessage()); e.printStackTrace(); return; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java new file mode 100644 index 000000000..4b6979e56 --- /dev/null +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java @@ -0,0 +1,31 @@ +package gov.nasa.jpl.mbee.mdk.util; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.util.AbstractList; +import java.util.Collections; +import java.util.List; +import java.util.RandomAccess; + +public final class XMLUtil { + public static List asList(NodeList n) { + return n.getLength() == 0 ? Collections.emptyList() : new NodeListWrapper(n); + } + + static final class NodeListWrapper extends AbstractList implements RandomAccess { + private final NodeList list; + + NodeListWrapper(NodeList l) { + list = l; + } + + public Node get(int index) { + return list.item(index); + } + + public int size() { + return list.getLength(); + } + } +} \ No newline at end of file