Skip to content

Commit d02e6ad

Browse files
PLUGINS-234 & PLUGINS-235
* PLUGINS-234 Xsync connection management system. * PLUGINS-235 removing aspera references when setting not turned on.
1 parent 7259425 commit d02e6ad

9 files changed

Lines changed: 355 additions & 26 deletions

File tree

src/main/java/org/nrg/xsync/components/XsyncSitePreferencesBean.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,31 @@ public void setXsyncWhitelistEnabled(boolean xsyncWhitelistEnabled) {
104104
}
105105
}
106106

107+
@NrgPreference(defaultValue = "true")
108+
public boolean getHttpsEnabled() {
109+
return getBooleanValue("httpsEnabled");
110+
}
111+
112+
public void setHttpsEnabled(boolean httpsEnabled) {
113+
try {
114+
set(String.valueOf(httpsEnabled), "httpsEnabled");
115+
} catch (InvalidPreferenceName invalidPreferenceName) {
116+
_log.error("Invalid preference name: httpsEnabled");
117+
}
118+
}
119+
120+
@NrgPreference(defaultValue = "false")
121+
public boolean getAsperaEnabled() {
122+
return getBooleanValue("asperaEnabled");
123+
}
124+
125+
public void setAsperaEnabled(boolean asperaEnabled) {
126+
try {
127+
set(String.valueOf(asperaEnabled), "asperaEnabled");
128+
} catch (InvalidPreferenceName invalidPreferenceName) {
129+
_log.error("Invalid preference name: asperaEnabled");
130+
}
131+
}
107132

108133
/**
109134
* Sets the Max. Total Uncompressed File Size
@@ -297,6 +322,12 @@ public void update(final XsyncSitePreferencesPojo xsyncSitePreferencesPojo) thro
297322
if (null != xsyncSitePreferencesPojo.getXsyncWhitelistEnabled()) {
298323
this.setXsyncWhitelistEnabled(xsyncSitePreferencesPojo.getXsyncWhitelistEnabled());
299324
}
325+
if (null != xsyncSitePreferencesPojo.getHttpsEnabled()) {
326+
this.setHttpsEnabled(xsyncSitePreferencesPojo.getHttpsEnabled());
327+
}
328+
if (null != xsyncSitePreferencesPojo.getAsperaEnabled()) {
329+
this.setAsperaEnabled(xsyncSitePreferencesPojo.getAsperaEnabled());
330+
}
300331
}
301332

302333
public XsyncSitePreferencesPojo toPojo() {
@@ -305,7 +336,9 @@ public XsyncSitePreferencesPojo toPojo() {
305336
getSyncRetryInterval(),
306337
getSyncRetryCount(),
307338
getSyncMaxUncompressedZipFileSize(),
308-
getXsyncWhitelistEnabled()
339+
getXsyncWhitelistEnabled(),
340+
getHttpsEnabled(),
341+
getAsperaEnabled()
309342
);
310343
}
311344

src/main/java/org/nrg/xsync/pojo/XsyncSitePreferencesPojo.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ public XsyncSitePreferencesPojo(final String tokenRefreshInterval,
1515
final String syncRetryInterval,
1616
final String syncRetryCount,
1717
final String syncMaxUncompressedZipFileSize,
18-
final Boolean xsyncWhitelistEnabled) {
18+
final Boolean xsyncWhitelistEnabled,
19+
final Boolean httpsEnabled,
20+
final Boolean asperaEnabled) {
1921
this.tokenRefreshInterval = tokenRefreshInterval;
2022
this.syncRetryInterval = syncRetryInterval;
2123
this.syncRetryCount = syncRetryCount;
2224
this.syncMaxUncompressedZipFileSize = syncMaxUncompressedZipFileSize;
2325
this.xsyncWhitelistEnabled = xsyncWhitelistEnabled;
26+
this.httpsEnabled = httpsEnabled;
27+
this.asperaEnabled = asperaEnabled;
28+
2429
}
2530

2631
private String tokenRefreshInterval;
2732
private String syncRetryInterval;
2833
private String syncRetryCount;
2934
private String syncMaxUncompressedZipFileSize;
30-
private Boolean xsyncWhitelistEnabled;
35+
private Boolean xsyncWhitelistEnabled;
36+
private Boolean httpsEnabled;
37+
private Boolean asperaEnabled;
3138
}

src/main/java/org/nrg/xsync/xapi/XsyncPreferencesController.java

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646

4747
@XapiRestController
48-
@Api(description = "XSync Preferences API")
48+
@Api("XSync Preferences API")
4949
@SuppressWarnings("unused")
5050
public class XsyncPreferencesController extends AbstractXapiRestController {
5151

@@ -79,7 +79,6 @@ public void setPreferences(@RequestBody XsyncSitePreferencesPojo xsyncSitePrefer
7979
*
8080
* @return the preferences
8181
*/
82-
@SuppressWarnings("deprecation")
8382
@XapiRequestMapping(value = "xsyncSitePreferences", method = RequestMethod.GET, produces = {
8483
MediaType.APPLICATION_JSON_VALUE }, restrictTo = AccessLevel.Admin)
8584
@ApiOperation(value = "Gets the XSync site preferences", response = XsyncSitePreferencesPojo.class)
@@ -128,6 +127,34 @@ public ResponseEntity<AsperaSitePrefsInfo> getAsperaPreferences() throws NrgServ
128127
return new ResponseEntity<>(new AsperaSitePrefsInfo(asperaSitePrefs), HttpStatus.OK);
129128
}
130129

130+
@XapiRequestMapping(value = "xsyncSitePreferences/httpsEnabled", method =
131+
RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
132+
@ApiOperation(value = "Checks whether Https connection is enabled on the site level.")
133+
@ApiResponses({ @ApiResponse(code = 200, message = "Https enabled returned."),
134+
@ApiResponse(code = 500, message = "Unexpected error") })
135+
public ResponseEntity<Boolean> getHttpsEnabled() {
136+
return new ResponseEntity<>(prefs.getHttpsEnabled(), HttpStatus.OK);
137+
}
138+
139+
@XapiRequestMapping(value = "xsyncSitePreferences/asperaEnabled", method =
140+
RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
141+
@ApiOperation(value = "Checks whether Aspera is enabled on the site level.")
142+
@ApiResponses({ @ApiResponse(code = 200, message = "Aspera enabled returned."),
143+
@ApiResponse(code = 500, message = "Unexpected error") })
144+
public ResponseEntity<Boolean> getAsperaEnabled() {
145+
return new ResponseEntity<>(prefs.getAsperaEnabled(), HttpStatus.OK);
146+
}
147+
148+
@XapiRequestMapping(value = "xsyncProjectPreferences/project/{projectId}/asperaEnabled", method =
149+
RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE, restrictTo = AccessLevel.Read)
150+
@ApiOperation(value = "Checks whether Aspera is enabled for project.")
151+
@ApiResponses({ @ApiResponse(code = 200, message = "Aspera enabled returned."),
152+
@ApiResponse(code = 500, message = "Unexpected error") })
153+
public ResponseEntity<Boolean> getProjectAsperaEnabled(@PathVariable("projectId") final String projectId) {
154+
final AsperaProjectPrefsInfo prefsInfo = new AsperaProjectPrefsInfo(asperaProjectPrefs, projectId);
155+
return new ResponseEntity<>(prefsInfo.getAsperaEnabled(), HttpStatus.OK);
156+
}
157+
131158
/**
132159
* Sets the preferences.
133160
*
@@ -150,7 +177,7 @@ public ResponseEntity<String> setAsperaProjectPreferences(@PathVariable("project
150177
asperaProjectPrefs.setSshPort(projectId, asperaPrefs.getSshPort());
151178
asperaProjectPrefs.setUdpPort(projectId, asperaPrefs.getUdpPort());
152179
} catch (Exception exception) {
153-
_logger.error("ERROR: Error setting preferences: " + ExceptionUtils.getFullStackTrace(exception));
180+
_logger.error("ERROR: Error setting preferences: {}", ExceptionUtils.getFullStackTrace(exception));
154181
return new ResponseEntity<>("XSync preferences assignment failed ", HttpStatus.INTERNAL_SERVER_ERROR);
155182
}
156183
return new ResponseEntity<>("XSync preferences set", HttpStatus.OK);
@@ -170,12 +197,12 @@ public ResponseEntity<AsperaProjectPrefsInfo> getAsperaProjectPreferences(
170197
@PathVariable("projectId") final String projectId) throws NrgServiceException {
171198
final AsperaProjectPrefsInfo prefsInfo = new AsperaProjectPrefsInfo(asperaProjectPrefs, projectId);
172199
// Get site defaults, if project settings have not been configured
173-
if ((prefsInfo.getAsperaNodeUrl() == null || prefsInfo.getAsperaNodeUrl().length() < 1)
174-
&& (prefsInfo.getAsperaNodeUser() == null || prefsInfo.getAsperaNodeUser().length() < 1)
175-
&& (asperaSitePrefs.getAsperaNodeUrl() != null || asperaSitePrefs.getAsperaNodeUrl().length() > 0)
176-
&& (asperaSitePrefs.getAsperaNodeUser() != null || asperaSitePrefs.getAsperaNodeUser().length() > 0)) {
177-
_logger.warn("WARNING: Project Aspera preferences not found for project " + projectId +
178-
". Returning site preferences instead for project preference call.");
200+
if ((prefsInfo.getAsperaNodeUrl() == null || prefsInfo.getAsperaNodeUrl().isEmpty())
201+
&& (prefsInfo.getAsperaNodeUser() == null || prefsInfo.getAsperaNodeUser().isEmpty())
202+
&& (asperaSitePrefs.getAsperaNodeUrl() != null || !asperaSitePrefs.getAsperaNodeUrl().isEmpty())
203+
&& (asperaSitePrefs.getAsperaNodeUser() != null || !asperaSitePrefs.getAsperaNodeUser().isEmpty())) {
204+
_logger.warn("WARNING: Project Aspera preferences not found for project {}. " +
205+
"Returning site preferences instead for project preference call.", projectId);
179206
prefsInfo.setAsperaEnabled(false);
180207
prefsInfo.setAsperaNodeUrl(asperaSitePrefs.getAsperaNodeUrl());
181208
prefsInfo.setAsperaNodeUser(asperaSitePrefs.getAsperaNodeUser());
@@ -189,8 +216,17 @@ public ResponseEntity<AsperaProjectPrefsInfo> getAsperaProjectPreferences(
189216
return new ResponseEntity<>(prefsInfo, HttpStatus.OK);
190217
}
191218

219+
@XapiRequestMapping(value = "xsyncProjectPreferences/whitelistEnabled", method =
220+
RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
221+
@ApiOperation(value = "Checks whether site whitelist is enabled on the site level.")
222+
@ApiResponses({ @ApiResponse(code = 200, message = "Site whitelist enabled returned."),
223+
@ApiResponse(code = 500, message = "Unexpected error") })
224+
public ResponseEntity<Boolean> getWhitelistEnabled() {
225+
return new ResponseEntity<>(prefs.getXsyncWhitelistEnabled(), HttpStatus.OK);
226+
}
227+
192228
@XapiRequestMapping(value = "xsyncSitePreferences/whitelistSites", method = RequestMethod.GET, produces = {
193-
MediaType.APPLICATION_JSON_VALUE }, restrictTo = AccessLevel.Admin)
229+
MediaType.APPLICATION_JSON_VALUE }, restrictTo = AccessLevel.Read)
194230
@ApiOperation(value = "Get the whitelist of sites allowed for syncing")
195231
@ApiResponses({ @ApiResponse(code = 200, message = "Xsync whitelist sites retrieved."),
196232
@ApiResponse(code = 500, message = "Unexpected error") })
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* web: xsyncConnectionManager.js
3+
* XNAT http://www.xnat.org
4+
* Copyright (c) 2005-2017, Washington University School of Medicine and Howard Hughes Medical Institute
5+
* All Rights Reserved
6+
*
7+
* Released under the Simplified BSD.
8+
*/
9+
10+
/*!
11+
* Manage the backend connection by which Xsync transfers will be made.
12+
*/
13+
14+
console.log('xsyncConnectionManager.js');
15+
16+
var XNAT = getObject(XNAT || {});
17+
XNAT.plugin = getObject(XNAT.plugin || {});
18+
XNAT.plugin.xsync = getObject(XNAT.plugin.xsync || {});
19+
20+
(function(factory){
21+
if (typeof define === 'function' && define.amd) {
22+
define(factory);
23+
}
24+
else if (typeof exports === 'object') {
25+
module.exports = factory();
26+
}
27+
else {
28+
return factory();
29+
}
30+
}(function() {
31+
32+
var restUrl = XNAT.url.restUrl;
33+
var xsyncConnectionManager;
34+
XNAT.plugin.xsync.xsyncConnectionManager = xsyncConnectionManager = getObject(XNAT.plugin.xsync.xsyncConnectionManager || {});
35+
36+
$(document).on('change','#https-enabled', function(){
37+
xsyncConnectionManager.toggleHttpsEnabled($(this).val());
38+
});
39+
40+
$(document).on('change','#aspera-enabled', function(){
41+
xsyncConnectionManager.toggleAsperaEnabled($(this).val());
42+
});
43+
44+
xsyncConnectionManager.toggleHttpsEnabled = function(enabled) {
45+
let inputPrefs = {};
46+
if (enabled === "true") {
47+
inputPrefs['httpsEnabled'] = true;
48+
} else {
49+
inputPrefs['httpsEnabled'] = false;
50+
}
51+
52+
xsyncConnectionManager.postSitePreferencesUpdate(inputPrefs, 'https');
53+
}
54+
55+
xsyncConnectionManager.toggleAsperaEnabled = function(enabled) {
56+
let inputPrefs = {};
57+
if (enabled === "true") {
58+
inputPrefs['asperaEnabled'] = true;
59+
} else {
60+
inputPrefs['asperaEnabled'] = false;
61+
inputPrefs['httpsEnabled'] = true;
62+
}
63+
64+
xsyncConnectionManager.postSitePreferencesUpdate(inputPrefs, 'aspera');
65+
if ($('#aspera-enabled').val() === 'false') {
66+
$("#https-enabled").parent().parent().parent().parent().addClass('disabled');
67+
$("#https-enabled").prop('disabled', true);
68+
$("a[title='Aspera Server Defaults']").parent().addClass('hidden');
69+
} else {
70+
$("#https-enabled").parent().parent().parent().parent().removeClass('disabled');
71+
$("#https-enabled").prop('disabled', false);
72+
$("a[title='Aspera Server Defaults']").parent().removeClass('hidden');
73+
}
74+
}
75+
76+
xsyncConnectionManager.postSitePreferencesUpdate = function(inputPrefs, preferenceName) {
77+
XNAT.xhr.post({
78+
url: restUrl('/xapi/xsyncSitePreferences/'),
79+
async: false,
80+
contentType: 'application/json',
81+
data: JSON.stringify(inputPrefs),
82+
success: function () {
83+
console.log('Updated ' + preferenceName + ' preference.');
84+
XNAT.ui.banner.top(2000, 'Updated ' + preferenceName + ' enabled preference.', 'success');
85+
},
86+
fail: function (e) {
87+
XNAT.ui.banner.top(2000, 'Could not update ' + preferenceName + ' enabled preference: ' + e.responseText, 'error');
88+
}
89+
});
90+
}
91+
92+
xsyncConnectionManager.init = function() {
93+
XNAT.xhr.get({
94+
url: restUrl('/xapi/xsyncSitePreferences/'),
95+
async: false,
96+
success: function (data) {
97+
let httpsEnabled = data['httpsEnabled'];
98+
let asperaEnabled = data['asperaEnabled'];
99+
if (httpsEnabled == true) {
100+
$('#https-enabled').prop("checked",true);
101+
}
102+
if (asperaEnabled == true) {
103+
$('#aspera-enabled').prop("checked",true);
104+
} else {
105+
$("#https-enabled").parent().parent().parent().parent().addClass('disabled');
106+
$("#https-enabled").prop('disabled', true);
107+
$("a[title='Aspera Server Defaults']").parent().addClass('hidden');
108+
}
109+
},
110+
fail: function (e) {
111+
XNAT.ui.banner.top(2000, 'Could not retrieve connection information: ' + e.responseText, 'error');
112+
}
113+
});
114+
}
115+
116+
$(document).ready(function () {
117+
xsyncConnectionManager.init();
118+
})
119+
120+
}));

src/main/resources/META-INF/resources/scripts/xnat-plugins/xsyncPlugin/admin/xsyncWhitelistManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ XNAT.plugin.xsync = getObject(XNAT.plugin.xsync || {});
3737

3838
xsyncWhitelistManager.toggleWhitelistSwitch = function(enabled) {
3939
let $whitelistTableDiv = $('div#xsync-whitelist-table');
40-
let inputPrefs = {}
40+
let inputPrefs = {};
4141
if (enabled === "true") {
4242
inputPrefs['xsyncWhitelistEnabled'] = true;
4343
$whitelistTableDiv.empty().append(xsyncWhitelistManager.table());
@@ -126,7 +126,7 @@ XNAT.plugin.xsync = getObject(XNAT.plugin.xsync || {});
126126
form.id = 'form';
127127

128128
form.appendChild(spawn('div|class="warning"',{'style': {visibility: 'hidden'}, 'id': 'warning'}));
129-
form.appendChild(createInputElement('Site Id', 'site_id_input', item.id, 'text', 'The unique identifier for the site.'));
129+
form.appendChild(createInputElement('Site Id', 'site_id_input', item.siteId, 'text', 'The unique identifier for the site.'));
130130
form.appendChild(createInputElement('Site Name', 'site_name_input', item.siteName, 'text', 'The name given to the site so that it is clearly identifiable to users.'));
131131
form.appendChild(createInputElement('Site Url', 'site_url_input', item.siteUrl, 'text', 'The url of the site.'));
132132
let options = ['CLINICAL', 'RESEARCH', 'PUBLIC']

src/main/resources/META-INF/resources/scripts/xnat-plugins/xsyncPlugin/xsync-config.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ if (typeof XSYNC.credentialsConfig === 'undefined') {
6565
XSYNC.xsyncConfig.configuration.subject_assessors.sync_type = 'none';
6666
XSYNC.xsyncConfig.configuration.imaging_sessions.sync_type = 'all';
6767
// XSYNC.xsyncConfig.configuration.imaging_sessions.xsi_types.types_list = ['xnat:mrSessionData'];
68+
69+
XSYNC.xsyncConfig.isProjectAsperaEnabled = false;
70+
XSYNC.xsyncConfig.isSiteWideAsperaEnabled = false;
6871
};
6972

7073
XSYNC.xsyncConfig.initialConfig = function(){
@@ -543,12 +546,31 @@ if (typeof XSYNC.credentialsConfig === 'undefined') {
543546

544547
function configPanel() {
545548
XNAT.xhr.get({
546-
url: restUrl('/xapi/xsyncSitePreferences/'),
549+
url: restUrl('/xapi/xsyncSitePreferences/asperaEnabled/'),
547550
async: false,
548551
success: function (data) {
549-
let enabled = data['xsyncWhitelistEnabled'];
550-
XSYNC.xsyncConfig.isWhitelistEnabledBackend = enabled;
551-
if (enabled == true) {
552+
XSYNC.xsyncConfig.isSiteWideAsperaEnabled = data;
553+
},
554+
fail: function (e) {
555+
XNAT.ui.banner.top(2000, 'Could not retrieve aspera information: ' + e.responseText, 'error');
556+
}
557+
});
558+
XNAT.xhr.get({
559+
url: restUrl('/xapi/xsyncProjectPreferences/project/' + XNAT.data.context.project + '/asperaEnabled/'),
560+
async: false,
561+
success: function (data) {
562+
XSYNC.xsyncConfig.isProjectAsperaEnabled = data;
563+
},
564+
fail: function (e) {
565+
XNAT.ui.banner.top(2000, 'Could not retrieve aspera information: ' + e.responseText, 'error');
566+
}
567+
});
568+
XNAT.xhr.get({
569+
url: restUrl('/xapi/xsyncProjectPreferences/whitelistEnabled/'),
570+
async: false,
571+
success: function (data) {
572+
XSYNC.xsyncConfig.isWhitelistEnabledBackend = data;
573+
if (XSYNC.xsyncConfig.isWhitelistEnabledBackend == true) {
552574
XNAT.xhr.get({
553575
url: restUrl('/xapi/xsyncSitePreferences/whitelistSites/'),
554576
async: false,
@@ -720,9 +742,13 @@ if (typeof XSYNC.credentialsConfig === 'undefined') {
720742
///////////////////////////
721743

722744
function aspera() {
723-
return {
724-
tag: "div.message.bold",
725-
content: "NOTICE: Aspera transfers are now supported, if your destination site supports them. Please see project settings, in the actions menu, to configure Aspera settings."
745+
if (XSYNC.xsyncConfig.isProjectAsperaEnabled === true && XSYNC.xsyncConfig.isSiteWideAsperaEnabled) {
746+
return {
747+
tag: "div.message.bold",
748+
content: "NOTICE: Aspera transfers are now supported, if your destination site supports them. Please see project settings, in the actions menu, to configure Aspera settings."
749+
}
750+
} else {
751+
return '';
726752
}
727753
}
728754

0 commit comments

Comments
 (0)