Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,31 @@ public void setXsyncWhitelistEnabled(boolean xsyncWhitelistEnabled) {
}
}

@NrgPreference(defaultValue = "true")
public boolean getHttpsEnabled() {
return getBooleanValue("httpsEnabled");
}

public void setHttpsEnabled(boolean httpsEnabled) {
try {
set(String.valueOf(httpsEnabled), "httpsEnabled");
} catch (InvalidPreferenceName invalidPreferenceName) {
_log.error("Invalid preference name: httpsEnabled");
}
}

@NrgPreference(defaultValue = "false")
public boolean getAsperaEnabled() {
return getBooleanValue("asperaEnabled");
}

public void setAsperaEnabled(boolean asperaEnabled) {
try {
set(String.valueOf(asperaEnabled), "asperaEnabled");
} catch (InvalidPreferenceName invalidPreferenceName) {
_log.error("Invalid preference name: asperaEnabled");
}
}

/**
* Sets the Max. Total Uncompressed File Size
Expand Down Expand Up @@ -297,6 +322,12 @@ public void update(final XsyncSitePreferencesPojo xsyncSitePreferencesPojo) thro
if (null != xsyncSitePreferencesPojo.getXsyncWhitelistEnabled()) {
this.setXsyncWhitelistEnabled(xsyncSitePreferencesPojo.getXsyncWhitelistEnabled());
}
if (null != xsyncSitePreferencesPojo.getHttpsEnabled()) {
this.setHttpsEnabled(xsyncSitePreferencesPojo.getHttpsEnabled());
}
if (null != xsyncSitePreferencesPojo.getAsperaEnabled()) {
this.setAsperaEnabled(xsyncSitePreferencesPojo.getAsperaEnabled());
}
}

public XsyncSitePreferencesPojo toPojo() {
Expand All @@ -305,7 +336,9 @@ public XsyncSitePreferencesPojo toPojo() {
getSyncRetryInterval(),
getSyncRetryCount(),
getSyncMaxUncompressedZipFileSize(),
getXsyncWhitelistEnabled()
getXsyncWhitelistEnabled(),
getHttpsEnabled(),
getAsperaEnabled()
);
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/nrg/xsync/pojo/XsyncSitePreferencesPojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ public XsyncSitePreferencesPojo(final String tokenRefreshInterval,
final String syncRetryInterval,
final String syncRetryCount,
final String syncMaxUncompressedZipFileSize,
final Boolean xsyncWhitelistEnabled) {
final Boolean xsyncWhitelistEnabled,
final Boolean httpsEnabled,
final Boolean asperaEnabled) {
this.tokenRefreshInterval = tokenRefreshInterval;
this.syncRetryInterval = syncRetryInterval;
this.syncRetryCount = syncRetryCount;
this.syncMaxUncompressedZipFileSize = syncMaxUncompressedZipFileSize;
this.xsyncWhitelistEnabled = xsyncWhitelistEnabled;
this.httpsEnabled = httpsEnabled;
this.asperaEnabled = asperaEnabled;

}

private String tokenRefreshInterval;
private String syncRetryInterval;
private String syncRetryCount;
private String syncMaxUncompressedZipFileSize;
private Boolean xsyncWhitelistEnabled;
private Boolean xsyncWhitelistEnabled;
private Boolean httpsEnabled;
private Boolean asperaEnabled;
}
56 changes: 46 additions & 10 deletions src/main/java/org/nrg/xsync/xapi/XsyncPreferencesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*/

@XapiRestController
@Api(description = "XSync Preferences API")
@Api("XSync Preferences API")
@SuppressWarnings("unused")
public class XsyncPreferencesController extends AbstractXapiRestController {

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

@XapiRequestMapping(value = "xsyncSitePreferences/httpsEnabled", method =
RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Checks whether Https connection is enabled on the site level.")
@ApiResponses({ @ApiResponse(code = 200, message = "Https enabled returned."),
@ApiResponse(code = 500, message = "Unexpected error") })
public ResponseEntity<Boolean> getHttpsEnabled() {
return new ResponseEntity<>(prefs.getHttpsEnabled(), HttpStatus.OK);
}

@XapiRequestMapping(value = "xsyncSitePreferences/asperaEnabled", method =
RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Checks whether Aspera is enabled on the site level.")
@ApiResponses({ @ApiResponse(code = 200, message = "Aspera enabled returned."),
@ApiResponse(code = 500, message = "Unexpected error") })
public ResponseEntity<Boolean> getAsperaEnabled() {
return new ResponseEntity<>(prefs.getAsperaEnabled(), HttpStatus.OK);
}

@XapiRequestMapping(value = "xsyncProjectPreferences/project/{projectId}/asperaEnabled", method =
RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE, restrictTo = AccessLevel.Read)
@ApiOperation(value = "Checks whether Aspera is enabled for project.")
@ApiResponses({ @ApiResponse(code = 200, message = "Aspera enabled returned."),
@ApiResponse(code = 500, message = "Unexpected error") })
public ResponseEntity<Boolean> getProjectAsperaEnabled(@PathVariable("projectId") final String projectId) {
final AsperaProjectPrefsInfo prefsInfo = new AsperaProjectPrefsInfo(asperaProjectPrefs, projectId);
return new ResponseEntity<>(prefsInfo.getAsperaEnabled(), HttpStatus.OK);
}

/**
* Sets the preferences.
*
Expand All @@ -150,7 +177,7 @@ public ResponseEntity<String> setAsperaProjectPreferences(@PathVariable("project
asperaProjectPrefs.setSshPort(projectId, asperaPrefs.getSshPort());
asperaProjectPrefs.setUdpPort(projectId, asperaPrefs.getUdpPort());
} catch (Exception exception) {
_logger.error("ERROR: Error setting preferences: " + ExceptionUtils.getFullStackTrace(exception));
_logger.error("ERROR: Error setting preferences: {}", ExceptionUtils.getFullStackTrace(exception));
return new ResponseEntity<>("XSync preferences assignment failed ", HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>("XSync preferences set", HttpStatus.OK);
Expand All @@ -170,12 +197,12 @@ public ResponseEntity<AsperaProjectPrefsInfo> getAsperaProjectPreferences(
@PathVariable("projectId") final String projectId) throws NrgServiceException {
final AsperaProjectPrefsInfo prefsInfo = new AsperaProjectPrefsInfo(asperaProjectPrefs, projectId);
// Get site defaults, if project settings have not been configured
if ((prefsInfo.getAsperaNodeUrl() == null || prefsInfo.getAsperaNodeUrl().length() < 1)
&& (prefsInfo.getAsperaNodeUser() == null || prefsInfo.getAsperaNodeUser().length() < 1)
&& (asperaSitePrefs.getAsperaNodeUrl() != null || asperaSitePrefs.getAsperaNodeUrl().length() > 0)
&& (asperaSitePrefs.getAsperaNodeUser() != null || asperaSitePrefs.getAsperaNodeUser().length() > 0)) {
_logger.warn("WARNING: Project Aspera preferences not found for project " + projectId +
". Returning site preferences instead for project preference call.");
if ((prefsInfo.getAsperaNodeUrl() == null || prefsInfo.getAsperaNodeUrl().isEmpty())
&& (prefsInfo.getAsperaNodeUser() == null || prefsInfo.getAsperaNodeUser().isEmpty())
&& (asperaSitePrefs.getAsperaNodeUrl() != null || !asperaSitePrefs.getAsperaNodeUrl().isEmpty())
&& (asperaSitePrefs.getAsperaNodeUser() != null || !asperaSitePrefs.getAsperaNodeUser().isEmpty())) {
_logger.warn("WARNING: Project Aspera preferences not found for project {}. " +
"Returning site preferences instead for project preference call.", projectId);
prefsInfo.setAsperaEnabled(false);
prefsInfo.setAsperaNodeUrl(asperaSitePrefs.getAsperaNodeUrl());
prefsInfo.setAsperaNodeUser(asperaSitePrefs.getAsperaNodeUser());
Expand All @@ -189,8 +216,17 @@ public ResponseEntity<AsperaProjectPrefsInfo> getAsperaProjectPreferences(
return new ResponseEntity<>(prefsInfo, HttpStatus.OK);
}

@XapiRequestMapping(value = "xsyncProjectPreferences/whitelistEnabled", method =
RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Checks whether site whitelist is enabled on the site level.")
@ApiResponses({ @ApiResponse(code = 200, message = "Site whitelist enabled returned."),
@ApiResponse(code = 500, message = "Unexpected error") })
public ResponseEntity<Boolean> getWhitelistEnabled() {
return new ResponseEntity<>(prefs.getXsyncWhitelistEnabled(), HttpStatus.OK);
}

@XapiRequestMapping(value = "xsyncSitePreferences/whitelistSites", method = RequestMethod.GET, produces = {
MediaType.APPLICATION_JSON_VALUE }, restrictTo = AccessLevel.Admin)
MediaType.APPLICATION_JSON_VALUE }, restrictTo = AccessLevel.Read)
@ApiOperation(value = "Get the whitelist of sites allowed for syncing")
@ApiResponses({ @ApiResponse(code = 200, message = "Xsync whitelist sites retrieved."),
@ApiResponse(code = 500, message = "Unexpected error") })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* web: xsyncConnectionManager.js
* XNAT http://www.xnat.org
* Copyright (c) 2005-2017, Washington University School of Medicine and Howard Hughes Medical Institute
* All Rights Reserved
*
* Released under the Simplified BSD.
*/

/*!
* Manage the backend connection by which Xsync transfers will be made.
*/

console.log('xsyncConnectionManager.js');

var XNAT = getObject(XNAT || {});
XNAT.plugin = getObject(XNAT.plugin || {});
XNAT.plugin.xsync = getObject(XNAT.plugin.xsync || {});

(function(factory){
if (typeof define === 'function' && define.amd) {
define(factory);
}
else if (typeof exports === 'object') {
module.exports = factory();
}
else {
return factory();
}
}(function() {

var restUrl = XNAT.url.restUrl;
var xsyncConnectionManager;
XNAT.plugin.xsync.xsyncConnectionManager = xsyncConnectionManager = getObject(XNAT.plugin.xsync.xsyncConnectionManager || {});

$(document).on('change','#https-enabled', function(){
xsyncConnectionManager.toggleHttpsEnabled($(this).val());
});

$(document).on('change','#aspera-enabled', function(){
xsyncConnectionManager.toggleAsperaEnabled($(this).val());
});

xsyncConnectionManager.toggleHttpsEnabled = function(enabled) {
let inputPrefs = {};
if (enabled === "true") {
inputPrefs['httpsEnabled'] = true;
} else {
inputPrefs['httpsEnabled'] = false;
}

xsyncConnectionManager.postSitePreferencesUpdate(inputPrefs, 'https');
}

xsyncConnectionManager.toggleAsperaEnabled = function(enabled) {
let inputPrefs = {};
if (enabled === "true") {
inputPrefs['asperaEnabled'] = true;
} else {
inputPrefs['asperaEnabled'] = false;
inputPrefs['httpsEnabled'] = true;
}

xsyncConnectionManager.postSitePreferencesUpdate(inputPrefs, 'aspera');
if ($('#aspera-enabled').val() === 'false') {
$("#https-enabled").parent().parent().parent().parent().addClass('disabled');
$("#https-enabled").prop('disabled', true);
$("a[title='Aspera Server Defaults']").parent().addClass('hidden');
} else {
$("#https-enabled").parent().parent().parent().parent().removeClass('disabled');
$("#https-enabled").prop('disabled', false);
$("a[title='Aspera Server Defaults']").parent().removeClass('hidden');
}
}

xsyncConnectionManager.postSitePreferencesUpdate = function(inputPrefs, preferenceName) {
XNAT.xhr.post({
url: restUrl('/xapi/xsyncSitePreferences/'),
async: false,
contentType: 'application/json',
data: JSON.stringify(inputPrefs),
success: function () {
console.log('Updated ' + preferenceName + ' preference.');
XNAT.ui.banner.top(2000, 'Updated ' + preferenceName + ' enabled preference.', 'success');
},
fail: function (e) {
XNAT.ui.banner.top(2000, 'Could not update ' + preferenceName + ' enabled preference: ' + e.responseText, 'error');
}
});
}

xsyncConnectionManager.init = function() {
XNAT.xhr.get({
url: restUrl('/xapi/xsyncSitePreferences/'),
async: false,
success: function (data) {
let httpsEnabled = data['httpsEnabled'];
let asperaEnabled = data['asperaEnabled'];
if (httpsEnabled == true) {
$('#https-enabled').prop("checked",true);
}
if (asperaEnabled == true) {
$('#aspera-enabled').prop("checked",true);
} else {
$("#https-enabled").parent().parent().parent().parent().addClass('disabled');
$("#https-enabled").prop('disabled', true);
$("a[title='Aspera Server Defaults']").parent().addClass('hidden');
}
},
fail: function (e) {
XNAT.ui.banner.top(2000, 'Could not retrieve connection information: ' + e.responseText, 'error');
}
});
}

$(document).ready(function () {
xsyncConnectionManager.init();
})

}));
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ XNAT.plugin.xsync = getObject(XNAT.plugin.xsync || {});

xsyncWhitelistManager.toggleWhitelistSwitch = function(enabled) {
let $whitelistTableDiv = $('div#xsync-whitelist-table');
let inputPrefs = {}
let inputPrefs = {};
if (enabled === "true") {
inputPrefs['xsyncWhitelistEnabled'] = true;
$whitelistTableDiv.empty().append(xsyncWhitelistManager.table());
Expand Down Expand Up @@ -126,7 +126,7 @@ XNAT.plugin.xsync = getObject(XNAT.plugin.xsync || {});
form.id = 'form';

form.appendChild(spawn('div|class="warning"',{'style': {visibility: 'hidden'}, 'id': 'warning'}));
form.appendChild(createInputElement('Site Id', 'site_id_input', item.id, 'text', 'The unique identifier for the site.'));
form.appendChild(createInputElement('Site Id', 'site_id_input', item.siteId, 'text', 'The unique identifier for the site.'));
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.'));
form.appendChild(createInputElement('Site Url', 'site_url_input', item.siteUrl, 'text', 'The url of the site.'));
let options = ['CLINICAL', 'RESEARCH', 'PUBLIC']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ if (typeof XSYNC.credentialsConfig === 'undefined') {
XSYNC.xsyncConfig.configuration.subject_assessors.sync_type = 'none';
XSYNC.xsyncConfig.configuration.imaging_sessions.sync_type = 'all';
// XSYNC.xsyncConfig.configuration.imaging_sessions.xsi_types.types_list = ['xnat:mrSessionData'];

XSYNC.xsyncConfig.isProjectAsperaEnabled = false;
XSYNC.xsyncConfig.isSiteWideAsperaEnabled = false;
};

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

function configPanel() {
XNAT.xhr.get({
url: restUrl('/xapi/xsyncSitePreferences/'),
url: restUrl('/xapi/xsyncSitePreferences/asperaEnabled/'),
async: false,
success: function (data) {
let enabled = data['xsyncWhitelistEnabled'];
XSYNC.xsyncConfig.isWhitelistEnabledBackend = enabled;
if (enabled == true) {
XSYNC.xsyncConfig.isSiteWideAsperaEnabled = data;
},
fail: function (e) {
XNAT.ui.banner.top(2000, 'Could not retrieve aspera information: ' + e.responseText, 'error');
}
});
XNAT.xhr.get({
url: restUrl('/xapi/xsyncProjectPreferences/project/' + XNAT.data.context.project + '/asperaEnabled/'),
async: false,
success: function (data) {
XSYNC.xsyncConfig.isProjectAsperaEnabled = data;
},
fail: function (e) {
XNAT.ui.banner.top(2000, 'Could not retrieve aspera information: ' + e.responseText, 'error');
}
});
XNAT.xhr.get({
url: restUrl('/xapi/xsyncProjectPreferences/whitelistEnabled/'),
async: false,
success: function (data) {
XSYNC.xsyncConfig.isWhitelistEnabledBackend = data;
if (XSYNC.xsyncConfig.isWhitelistEnabledBackend == true) {
XNAT.xhr.get({
url: restUrl('/xapi/xsyncSitePreferences/whitelistSites/'),
async: false,
Expand Down Expand Up @@ -720,9 +742,13 @@ if (typeof XSYNC.credentialsConfig === 'undefined') {
///////////////////////////

function aspera() {
return {
tag: "div.message.bold",
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."
if (XSYNC.xsyncConfig.isProjectAsperaEnabled === true && XSYNC.xsyncConfig.isSiteWideAsperaEnabled) {
return {
tag: "div.message.bold",
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."
}
} else {
return '';
}
}

Expand Down
Loading