web stats
Ability to write to the configuration map - Mirth Community

Go Back   Mirth Community > Mirth Connect > Development

Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2019, 08:21 AM
clarksss clarksss is offline
OBX.2 Kenobi
 
Join Date: Jul 2013
Posts: 75
clarksss is on a distinguished road
Thumbs up Ability to write to the configuration map

wondering if NextGen Connect had plans to allow the configuration map values to be updated in code (within Mirth) as a place to store a static value, and read and update that value as the state changes??


something like:
Code:
configurationMap.put("key", value) and/or configurationMap.update("key", value)
Reply With Quote
  #2  
Old 10-17-2019, 10:23 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,005
agermano is on a distinguished road
Default

The globalMap already does this, but I think your intention is to also persist the data.

While I can't speak for them, I don't think they have any plans to do that. They explicitly make the Map immutable before handing it off to user code. Part of the reason for this is that there is a comment associated with each key as well as a value.

Here's a code template that will do what you want, but before using it consider:
  1. This method is unsupported and could break without notice during future updates. You could make it more future proof by using the Client API, but then you need to deal with providing valid login credentials.
  2. The configuration map is read and written as a whole. This copies the entire map, makes your change, and commits the entire map back to the db. You could end up with lost changes if multiple threads try doing this at the same time and you don't implement any additional locking mechanism to ensure only one thread is updating the map at a time.

Code:
function updateConfigurationMap(key, value, comment) {
	const ControllerFactory = com.mirth.connect.server.controllers.ControllerFactory;
	const ConfigurationProperty = com.mirth.connect.util.ConfigurationProperty;

	if (comment == null) comment = '';
	
	const configurationController = ControllerFactory.getFactory().createConfigurationController();

	const props = configurationController.getConfigurationProperties();
	var result = props.put(key, new ConfigurationProperty(value, comment));
	if (result != null) {
		result = result.getValue();
	}
	configurationController.setConfigurationProperties(props, true);
	return result;
}
I think you'd be better off using a database to persist the information. You can either write a code template or a dedicated channel that can be called by your other channels to read and write values. If you don't want to stand up a new database server or piggyback on the existing mirthdb, mirth also ships with a sqlite driver which can be backed by a local file and should avoid the mentioned concurrency issues.

As I mentioned in my post to your other thread, you could also try using the saveProperty and getProperty methods on the ConfigurationController.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 01:20 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation