Skip to content
Snippets Groups Projects
Commit 8e959797 authored by Rick Herrick's avatar Rick Herrick
Browse files

XNAT-4382 Added /plugins XAPI function to return plugin registry.

parent 5e302001
No related branches found
No related tags found
No related merge requests found
package org.nrg.xapi.rest.settings;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.nrg.framework.annotations.XapiRestController;
import org.nrg.xdat.rest.AbstractXapiRestController;
import org.nrg.xdat.security.services.RoleHolder;
import org.nrg.xdat.security.services.UserManagementServiceI;
import org.nrg.xnat.services.XnatAppInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
@Api(description = "XNAT Plugin Admin API")
@XapiRestController
@RequestMapping(value = "/plugins")
public class XnatPluginAdminApi extends AbstractXapiRestController {
@Autowired
public XnatPluginAdminApi(final UserManagementServiceI userManagementService, final RoleHolder roleHolder, final XnatAppInfo appInfo) {
super(userManagementService, roleHolder);
_appInfo = appInfo;
}
@ApiOperation(value = "Returns a list of all of the installed XNAT plugins.", notes = "The maps returned from this call include all of the properties specified in the plugin's property file.", response = String.class, responseContainer = "Map")
@ApiResponses({@ApiResponse(code = 200, message = "XNAT plugin properties successfully retrieved."),
@ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."),
@ApiResponse(code = 500, message = "Unexpected error")})
@RequestMapping(produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.GET})
public ResponseEntity<Map<String, Properties>> getAllDataTypeSchemas() throws IOException {
return new ResponseEntity<>(_appInfo.getPluginProperties(), HttpStatus.OK);
}
@ApiOperation(value = "Returns the requested XNAT plugin properties.", notes = "The maps returned from this call include all of the properties specified in the plugin's property file.", response = Properties.class)
@ApiResponses({@ApiResponse(code = 200, message = "XNAT plugin properties successfully retrieved."),
@ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."),
@ApiResponse(code = 404, message = "The requested resource wasn't found."),
@ApiResponse(code = 500, message = "Unexpected error")})
@RequestMapping(value = "{plugin}", produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.GET})
public ResponseEntity<Properties> getRequestedDataTypeSchema(@PathVariable("plugin") final String plugin) throws IOException {
final Map<String, Properties> plugins = _appInfo.getPluginProperties();
if (!plugins.containsKey(plugin)) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(plugins.get(plugin), HttpStatus.OK);
}
private final XnatAppInfo _appInfo;
}
\ No newline at end of file
package org.nrg.xnat.services;
import org.nrg.framework.utilities.BasicXnatResourceLocator;
import org.python.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
......@@ -59,6 +63,10 @@ public class XnatAppInfo {
}
}
}
for (final Resource resource : BasicXnatResourceLocator.getResources("classpath*:META-INF/xnat/**/*-plugin.properties")) {
final Properties properties = PropertiesLoaderUtils.loadProperties(resource);
_plugins.put(properties.getProperty("name"), properties);
}
_template = template;
}
......@@ -208,15 +216,26 @@ public class XnatAppInfo {
return buffer.toString();
}
/**
* Returns the properties for all of the installed and active plugins in the deployed XNAT server.
*
* @return A map of all of the plugins installed on the server.
*/
public Map<String, Properties> getPluginProperties() throws IOException {
return ImmutableMap.copyOf(_plugins);
}
private static final Logger _log = LoggerFactory.getLogger(XnatAppInfo.class);
private static final List<String> PRIMARY_MANIFEST_ATTRIBUTES = Arrays.asList("Build-Number", "Build-Date", "Implementation-Version", "Implementation-Sha");
private final JdbcTemplate _template;
private final Date _startTime = new Date();
private final Properties _properties = new Properties();
private final Map<String, Map<String, String>> _attributes = new HashMap<>();
private boolean _initialized = false;
private final Date _startTime = new Date();
private final Properties _properties = new Properties();
private final Map<String, Map<String, String>> _attributes = new HashMap<>();
private final Map<String, Properties> _plugins = new HashMap<>();
private boolean _initialized = false;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment