Skip to content

Commit

Permalink
Merge pull request #191 from Open-MBEE/release/4.4.0
Browse files Browse the repository at this point in the history
Release/4.4.0
  • Loading branch information
ivan-gomes authored Jul 21, 2020
2 parents 237ad84 + 8a86375 commit 37f025b
Show file tree
Hide file tree
Showing 24 changed files with 188 additions and 78 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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<library name=\"' + file.absolutePath.replaceAll(~/.*build\/generated-dist\/plugins\/${groupName}\//, '') + '\"/>' + System.lineSeparator()
pluginLibraries += '\t\t<library name=\"' + file.absolutePath.replace(File.separator, '/').replaceAll(~/.*build\/generated-dist\/plugins\/${groupName}\//, '') + '\"/>' + System.lineSeparator()
}
project.copy {
from 'src/main/dist/template/plugins/${group}/plugin.xml'
Expand All @@ -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<file from=\"' + relativePath + '\" to=\"' + relativePath + '\"/>' + System.lineSeparator()
}
project.copy {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<String> exportDiagram(Diagram diagram, File directory) throws IOException {
int dpi = 72;
int scalePercent = 100;
Project project = Application.getInstance().getProject();
if (project == null) {
return Collections.emptyList();
Expand All @@ -442,9 +447,9 @@ public static List<String> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -660,7 +661,7 @@ public List<EStructuralFeatureOverride> 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();
}
Expand Down Expand Up @@ -692,7 +693,7 @@ public List<EStructuralFeatureOverride> 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();
}
Expand Down
51 changes: 32 additions & 19 deletions src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -74,7 +72,8 @@ public static AtomicReference<Exception> 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<String> elementIds = new ArrayList<>(1);
elementIds.add(elementId);
File responseFile = getElementsRecursively(project, elementIds, 0, progressStatus);
Expand All @@ -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<String> elementIds = new ArrayList<>(1);
elementIds.add(elementId);
return getElementsRecursively(project, elementIds, depth, progressStatus);
Expand All @@ -104,7 +104,8 @@ public static File getElementRecursively(Project project, String elementId, int
* @throws IOException
* @throws URISyntaxException
*/
public static File getElements(Project project, Collection<String> elementIds, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException {
public static File getElements(Project project, Collection<String> elementIds, ProgressStatus progressStatus)
throws IOException, ServerException, URISyntaxException, GeneralSecurityException {
return getElementsRecursively(project, elementIds, 0, progressStatus);
}

Expand All @@ -118,7 +119,8 @@ public static File getElements(Project project, Collection<String> elementIds, P
* @throws IOException
* @throws URISyntaxException
*/
public static File getElementsRecursively(Project project, Collection<String> elementIds, int depth, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException {
public static File getElementsRecursively(Project project, Collection<String> elementIds, int depth, ProgressStatus progressStatus)
throws ServerException, IOException, URISyntaxException, GeneralSecurityException {
// verify elements
if (elementIds == null || elementIds.isEmpty()) {
return null;
Expand All @@ -138,7 +140,7 @@ public static File getElementsRecursively(Project project, Collection<String> el
return sendMMSRequest(project, MMSUtils.buildRequest(MMSUtils.HttpRequestType.PUT, requestUri, sendData, ContentType.APPLICATION_JSON), progressStatus);
}

public static File getArtifacts(Project project, Collection<String> artifactIds, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException {
public static File getArtifacts(Project project, Collection<String> artifactIds, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException, GeneralSecurityException {
if (artifactIds == null || artifactIds.isEmpty()) {
return null;
}
Expand All @@ -150,15 +152,18 @@ public static File getArtifacts(Project project, Collection<String> 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;
Expand Down Expand Up @@ -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 "";
Expand Down Expand Up @@ -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<String> responseBody = new AtomicReference<>();
final AtomicReference<Integer> responseCode = new AtomicReference<>();
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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));
}
Expand Down
Loading

0 comments on commit 37f025b

Please sign in to comment.