Skip to content

Commit

Permalink
Pull request #847: Allowing Extensions view to pull max core versions…
Browse files Browse the repository at this point in the history
… from server.

Merge in MC/connect from feature/ROCKSOLID-12902-add-columns-to-extensions-view to development

* commit 'c454101dab9875999e93a534e7f8f24996e0ae22':
  Allowing Extensions view to pull max core versions from server.
  • Loading branch information
narupley authored and jdonextgen committed Jul 2, 2024
2 parents af932b0 + c454101 commit be90435
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 35 deletions.
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
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
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public Properties getPluginProperties(String name) throws ControllerException {

public abstract Map<String, MetaData> getInvalidMetaData();

/**
* Returns max core library versions for loaded extensions.
*/
public abstract Map<String, Map<String, String>> getExtensionMaxCoreVersions();

// ************************************************************
// Connectors
// ************************************************************
Expand Down
6 changes: 4 additions & 2 deletions core-ui/src/com/mirth/connect/client/ui/FrameBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ public abstract class FrameBase extends JXFrame {
public abstract void setVisibleTasks(JXTaskPane pane, JPopupMenu menu, int startIndex, int endIndex, boolean visible);

public abstract Map<String, PluginMetaData> getPluginMetaData();

public abstract Map<String, ConnectorMetaData> getConnectorMetaData();


public abstract Map<String, Map<String, String>> getExtensionMaxCoreVersions();

/**
* Enables the save button for needed page.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public Map<String, PluginMetaData> getPluginMetaData() {
return extensionController.getPluginMetaData();
}

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

@Override
public boolean isExtensionEnabled(String extensionName) {
return extensionController.isExtensionEnabled(extensionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ public Map<String, MetaData> getInvalidMetaData() {
return extensionLoader.getInvalidMetaData();
}

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

/**
* Executes the script that removes that database tables for plugins that are marked for
* removal. The actual removal of the plugin directory happens in MirthLauncher.java, before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
requestedObject = getPasswordRequirementListExample();
} else if (exampleRequested.equals("plugin_metadata_map")) {
requestedObject = getPluginMetaDataMapExample();
} else if (exampleRequested.equals("extension_maxcoreversions_map")) {
requestedObject = getExtensionMaxCoreVersionsExample();
} else if (exampleRequested.equals("properties")) {
requestedObject = getPropertiesExample();
} else if (exampleRequested.equals("protocols_and_cipher_suites_map")) {
Expand Down Expand Up @@ -1198,9 +1200,24 @@ private Map<String, PluginMetaData> getPluginMetaDataMapExample() {
Map<String, PluginMetaData> pluginMetaDataMap = new HashMap<>();
pluginMetaDataMap.put("Name", getPluginMetaDataExample());
return pluginMetaDataMap;
}

private Properties getPropertiesExample() {
}

private Map<String, Map<String, String>> getExtensionMaxCoreVersionsExample() {
Map<String, Map<String, String>> extensionMaxCoreVersions = new HashMap<>();
Map<String, String> versionsMap = new HashMap<>();
versionsMap.put("mirth-core-client", Version.getLatest().toString());
versionsMap.put("mirth-core-client-api", Version.getLatest().toString());
versionsMap.put("mirth-core-client-base", Version.getLatest().toString());
versionsMap.put("mirth-core-client-plugins", Version.getLatest().toString());
versionsMap.put("mirth-core-models", Version.getLatest().toString());
versionsMap.put("mirth-core-server-plugins", Version.getLatest().toString());
versionsMap.put("mirth-core-ui", Version.getLatest().toString());
versionsMap.put("mirth-core-util", Version.getLatest().toString());
extensionMaxCoreVersions.put("Name", versionsMap);
return extensionMaxCoreVersions;
}

private Properties getPropertiesExample() {
Properties properties = new Properties();
properties.setProperty("exampleKey1", "exampleValue1");
properties.setProperty("exampleKey2", "exampleValue2");
Expand Down

0 comments on commit be90435

Please sign in to comment.