Skip to content

Commit

Permalink
Merge pull request #1 from rogin/more6276
Browse files Browse the repository at this point in the history
#6276 add unit test
  • Loading branch information
Shurazi authored Sep 12, 2024
2 parents 4b148e4 + 30d2760 commit ba81a31
Show file tree
Hide file tree
Showing 30 changed files with 325 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ donkey/donkey-test
.sonar
**/junit-reports
**/code-coverage-reports
.vscode/settings.json

# /client/
/client/logs
Expand All @@ -24,6 +25,7 @@ donkey/donkey-test
/client/nbdist
/client/test_classes
/client/junit-reports
/client/.project

# /client/lib/
/client/lib/*-shared.jar
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "disabled"
}
11 changes: 11 additions & 0 deletions client/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1725236689250</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
8 changes: 8 additions & 0 deletions client/src/com/mirth/connect/client/ui/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public class Frame extends FrameBase {
public LinkedHashMap<String, String> displayNameToDataType;
private Map<String, PluginMetaData> loadedPlugins;
private Map<String, ConnectorMetaData> loadedConnectors;
private Map<String, Map<String, String>> extensionMaxCoreVersions;
private Map<String, Integer> safeErrorFailCountMap = new HashMap<String, Integer>();
private Map<Component, String> componentTaskMap = new HashMap<Component, String>();
private boolean acceleratorKeyPressed = false;
Expand Down Expand Up @@ -827,6 +828,7 @@ public void dispose() {
private void loadExtensionMetaData() throws ClientException {
loadedPlugins = mirthClient.getPluginMetaData();
loadedConnectors = mirthClient.getConnectorMetaData();
extensionMaxCoreVersions = mirthClient.getExtensionMaxCoreVersions();

// Register extension JAX-RS providers with the client
Set<String> apiProviderPackages = new HashSet<String>();
Expand Down Expand Up @@ -4759,6 +4761,7 @@ public void doRefreshExtensions() {
}

public void refreshExtensions() {
extensionsPanel.setExtensionMaxCoreVersions(getExtensionMaxCoreVersions());
extensionsPanel.setPluginData(getPluginMetaData());
extensionsPanel.setConnectorData(getConnectorMetaData());
}
Expand Down Expand Up @@ -5008,6 +5011,11 @@ public Map<String, ConnectorMetaData> getConnectorMetaData() {
return this.loadedConnectors;
}

@Override
public Map<String, Map<String, String>> getExtensionMaxCoreVersions() {
return this.extensionMaxCoreVersions;
}

public String getSelectedChannelIdFromDashboard() {
return dashboardPanel.getSelectedStatuses().get(0).getChannelId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.jdesktop.swingx.decorator.HighlighterFactory;

import com.mirth.connect.client.core.ClientException;
import com.mirth.connect.client.core.Version;
import com.mirth.connect.client.ui.CellData;
import com.mirth.connect.client.ui.Frame;
import com.mirth.connect.client.ui.ImageCellRenderer;
Expand Down Expand Up @@ -60,6 +59,7 @@ public class ExtensionManagerPanel extends javax.swing.JPanel {
private final String ENABLED_STATUS = "Enabled";
private Map<String, PluginMetaData> pluginData = null;
private Map<String, ConnectorMetaData> connectorData = null;
private Map<String, Map<String, String>> extensionMaxCoreVersions = null;
private Frame parent;

public ExtensionManagerPanel() {
Expand All @@ -70,6 +70,10 @@ public ExtensionManagerPanel() {
makeLoadedPluginsTable();
}

public void setExtensionMaxCoreVersions(Map<String, Map<String, String>> extensionMaxCoreVersions) {
this.extensionMaxCoreVersions = extensionMaxCoreVersions;
}

/**
* Gets the selected extension index that corresponds to the saved extensions list
*/
Expand Down Expand Up @@ -231,7 +235,7 @@ private void setToolTipTexts(MirthTable table) {
table.getColumnExt(PLUGIN_URL_COLUMN_NAME).setToolTipText("A website you can visit to learn more about this extension.");
table.getColumnExt(PLUGIN_VERSION_COLUMN_NAME).setToolTipText("The version of this extension.");
table.getColumnExt(PLUGIN_BUILD_COLUMN_NAME).setToolTipText("<html>The specific build number of this extension, if applicable.<br/>For \"core\" extensions that come bundled with Mirth Connect by default,<br/>this build number will equal the build number of Mirth Connect itself.</html>");
table.getColumnExt(MC_VERSIONS_COLUMN_NAME).setToolTipText("<html>The version(s) of Mirth Connect that this version of this<br/>extension is compatible with. This may be a single version,<br/>a range from min-max, or a comma-separated list of versions.</html>");
table.getColumnExt(MC_VERSIONS_COLUMN_NAME).setToolTipText("<html>The version(s) of Mirth Connect that this version of this<br/>extension is compatible with. This may be a single version,<br/>a range from min-max, or a comma-separated list of versions.<br/><br/>If a \"+\" appears at the end, it means that there is not<br/>yet any known max version specified, so this plugin should<br/>be fully compatible with higher versions of Mirth Connect.</html>");
table.getColumnExt(CORE_COLUMN_NAME).setToolTipText("<html>Indicates whether this extension is a \"core\" extension<br/>that comes bundled with Mirth Connect by default.</html>");
}

Expand Down Expand Up @@ -500,23 +504,43 @@ private String getSupportedMCVersions(MetaData metaData) {

// If core library min versions are specified, derive a range of supported versions
if (MapUtils.isNotEmpty(metaData.getMinCoreVersions())) {
// Assume the minimum supported MC version is the highest core library version
String minSupportedMCVersion = null;
for (Entry<String, String> minCoreVersionEntry : metaData.getMinCoreVersions().entrySet()) {
if (minSupportedMCVersion == null || MigrationUtil.compareVersions(minSupportedMCVersion, minCoreVersionEntry.getValue()) < 0) {
minSupportedMCVersion = minCoreVersionEntry.getValue();
try {
// Assume the minimum supported MC version is the highest core library version
String minSupportedMCVersion = null;
for (Entry<String, String> minCoreVersionEntry : metaData.getMinCoreVersions().entrySet()) {
if (minSupportedMCVersion == null || MigrationUtil.compareVersions(minSupportedMCVersion, minCoreVersionEntry.getValue()) < 0) {
minSupportedMCVersion = minCoreVersionEntry.getValue();
}
}
}

if (minSupportedMCVersion != null) {
supportedMCVersions = minSupportedMCVersion;

// Assume the highest supported MC version is the current version
// TODO: Get this from server-side
Version matchingMinVersion = Version.fromString(minSupportedMCVersion);
if (matchingMinVersion != null && matchingMinVersion != Version.getLatest()) {
supportedMCVersions += " - " + Version.getLatest().toString();
if (minSupportedMCVersion != null) {
supportedMCVersions = minSupportedMCVersion;

String maxSupportedMCVersion = null;

// Get max version from the server-side map, if available
if (MapUtils.isNotEmpty(extensionMaxCoreVersions)) {
Map<String, String> maxVersions = extensionMaxCoreVersions.get(metaData.getPath());
if (MapUtils.isNotEmpty(maxVersions)) {
for (Entry<String, String> maxCoreVersionEntry : maxVersions.entrySet()) {
if (StringUtils.isNotBlank(maxCoreVersionEntry.getValue()) && (maxSupportedMCVersion == null || MigrationUtil.compareVersions(maxSupportedMCVersion, maxCoreVersionEntry.getValue()) > 0)) {
maxSupportedMCVersion = maxCoreVersionEntry.getValue();
}
}
}
}

if (maxSupportedMCVersion != null) {
if (MigrationUtil.compareVersions(minSupportedMCVersion, maxSupportedMCVersion) < 0) {
supportedMCVersions += " - " + maxSupportedMCVersion;
}
} else {
supportedMCVersions += "+";
}
}
} catch (Exception e) {
// Ignore, and just use the mirthVersion from the metadata
e.printStackTrace();
}
}

Expand Down
11 changes: 11 additions & 0 deletions command/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1725236689259</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions core-client-api/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1725236689267</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public void uninstallExtension(@Param("extensionPath") @RequestBody(description
@ExampleObject(name = "pluginMetaData", ref = "../apiexamples/plugin_metadata_map_json") }) })
public Map<String, PluginMetaData> getPluginMetaData() throws ClientException;

@GET
@Path("/maxcoreversions")
@Operation(summary = "Returns max core library versions for loaded extensions.")
@MirthOperation(name = "getExtensionMaxCoreVersions", display = "Get extension max core versions", auditable = false)
@ApiResponse(content = { @Content(mediaType = MediaType.APPLICATION_XML, examples = {
@ExampleObject(name = "extensionMaxCoreVersions", ref = "../apiexamples/extension_maxcoreversions_map_xml") }),
@Content(mediaType = MediaType.APPLICATION_JSON, examples = {
@ExampleObject(name = "extensionMaxCoreVersions", ref = "../apiexamples/extension_maxcoreversions_map_json") }) })
public Map<String, Map<String, String>> getExtensionMaxCoreVersions() throws ClientException;

@GET
@Path("/{extensionName}/enabled")
@Operation(summary = "Returns the enabled status of an extension.")
Expand Down
11 changes: 11 additions & 0 deletions core-client-base/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1725236689271</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions core-client-plugins/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1725236689279</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions core-client/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1725236689264</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
10 changes: 10 additions & 0 deletions core-client/src/com/mirth/connect/client/core/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -2588,6 +2588,16 @@ public Map<String, PluginMetaData> getPluginMetaData() throws ClientException {
return getServlet(ExtensionServletInterface.class).getPluginMetaData();
}

/**
* Returns max core library versions for loaded extensions.
*
* @see ExtensionServletInterface#getExtensionMaxCoreVersions
*/
@Override
public Map<String, Map<String, String>> getExtensionMaxCoreVersions() throws ClientException {
return getServlet(ExtensionServletInterface.class).getExtensionMaxCoreVersions();
}

/**
* Returns the enabled status of an extension.
*
Expand Down
11 changes: 11 additions & 0 deletions core-models/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1725236689284</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions core-server-plugins/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1725236689287</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static ExtensionLoader getInstance() {
private Map<String, PluginMetaData> pluginMetaDataMap = new HashMap<String, PluginMetaData>();
private Map<String, ConnectorMetaData> connectorProtocolsMap = new HashMap<String, ConnectorMetaData>();
private Map<String, MetaData> invalidMetaDataMap = new HashMap<String, MetaData>();
private Map<String, Map<String, String>> allExtensionMaxCoreVersions = new HashMap<String, Map<String, String>>();
private boolean loadedExtensions = false;
private ObjectXMLSerializer serializer = ObjectXMLSerializer.getInstance();
private static Logger logger = LogManager.getLogger(ExtensionLoader.class);
Expand Down Expand Up @@ -116,6 +117,11 @@ public Map<String, MetaData> getInvalidMetaData() {
return invalidMetaDataMap;
}

public Map<String, Map<String, String>> getExtensionMaxCoreVersions() {
loadExtensions();
return allExtensionMaxCoreVersions;
}

@SuppressWarnings("unchecked")
public <T> Class<T> getControllerClass(Class<T> abstractClass) {
Class<T> overrideClass = null;
Expand Down Expand Up @@ -183,7 +189,7 @@ public boolean isExtensionCompatible(MetaData metaData) {
Map<String, String> extensionMaxCoreVersions = new HashMap<String, String>();
try {
extensionMinCoreVersions = metaData.getMinCoreVersions();
extensionMaxCoreVersions = getExtensionMaxCoreVersions(metaData.getPath(), metaData.getPluginVersion(), extensionMinCoreVersions);
extensionMaxCoreVersions = getExtensionMaxCoreVersions(metaData.getPath(), metaData.getPluginVersion());
} catch (Exception e) {
logger.error("An error occurred while attempting to determine the extension's Core versions.", e);
return false;
Expand All @@ -206,13 +212,14 @@ public boolean isExtensionCompatible(MetaData metaData) {

if (!MapUtils.isEmpty(extensionMaxCoreVersions)) {
if (extensionMaxCoreVersions.containsKey(connectCoreVersionEntry.getKey())) {
if (!StringUtils.isEmpty(extensionMaxCoreVersions.get(connectCoreVersionEntry.getKey())) && connectCoreVersion.isGreaterThan(extensionMaxCoreVersions.get(connectCoreVersionEntry.getKey()))) {
if (StringUtils.isNotBlank(extensionMaxCoreVersions.get(connectCoreVersionEntry.getKey())) && connectCoreVersion.isGreaterThan(extensionMaxCoreVersions.get(connectCoreVersionEntry.getKey()))) {
return false;
}
}
}
}

allExtensionMaxCoreVersions.put(metaData.getPath(), extensionMaxCoreVersions);
return true;
} else {
// validate extension the old way for non-commercial extensions
Expand Down Expand Up @@ -416,7 +423,7 @@ private static Map<String, String> getConnectCoreVersions(ManifestEntry[] manife
* @throws JsonProcessingException
* @throws JsonMappingException
*/
private Map<String, String> getExtensionMaxCoreVersions(String pluginPath, String pluginVersion, Map<String, String> extensionMinCoreVersions) throws JsonMappingException, JsonProcessingException {
private Map<String, String> getExtensionMaxCoreVersions(String pluginPath, String pluginVersion) throws JsonMappingException, JsonProcessingException {
Map<String, String> extensionMaxCoreVersions = new HashMap<String, String>();

if (!StringUtils.isEmpty(extensionsCoreVersionsS3File)) {
Expand All @@ -433,20 +440,11 @@ private Map<String, String> getExtensionMaxCoreVersions(String pluginPath, Strin
while(extensionCoreVersionsS3FileIt.hasNext()) {
Map.Entry<String, JsonNode> extensionCoreVersionS3FileEntry = extensionCoreVersionsS3FileIt.next();

String extensionCoreVersionS3FileEntryValue = "";
if (extensionCoreVersionS3FileEntry.getValue().has("max") && !StringUtils.isEmpty(extensionCoreVersionS3FileEntry.getValue().get("max").textValue())) {
extensionCoreVersionS3FileEntryValue = extensionCoreVersionS3FileEntry.getValue().get("max").textValue();
} else {
extensionCoreVersionS3FileEntryValue = extensionMinCoreVersions.get(extensionCoreVersionS3FileEntry.getKey());
if (extensionCoreVersionS3FileEntry.getValue().has("max") && StringUtils.isNotBlank(extensionCoreVersionS3FileEntry.getValue().get("max").textValue())) {
extensionMaxCoreVersions.put(extensionCoreVersionS3FileEntry.getKey(), extensionCoreVersionS3FileEntry.getValue().get("max").textValue());
}

extensionMaxCoreVersions.put(extensionCoreVersionS3FileEntry.getKey(), extensionCoreVersionS3FileEntryValue);
}
} else {
extensionMaxCoreVersions.putAll(extensionMinCoreVersions);
}
} else {
extensionMaxCoreVersions.putAll(extensionMinCoreVersions);
}

return extensionMaxCoreVersions;
Expand Down
Loading

0 comments on commit ba81a31

Please sign in to comment.