From 3e612591cdf00c7ecad874fecb9105ff8a534249 Mon Sep 17 00:00:00 2001
From: Rick Herrick <jrherrick@wustl.edu>
Date: Mon, 21 Mar 2016 19:43:02 -0500
Subject: [PATCH] Added DicomSCPApi to use Spring REST controller instead of
 restlet, updated DicomSCPManager to support required calls. Refactored XNAT
 support into abstract base class. Updated XnatWebAppInitializer to use plugin
 instead of module.

---
 .../java/org/nrg/dcm/DicomSCPManager.java     |  40 +++--
 .../nrg/xapi/rest/AbstractXnatRestApi.java    |  39 ++++
 .../nrg/xapi/rest/dicomscp/DicomSCPApi.java   | 168 ++++++++++++++++++
 .../org/nrg/xapi/rest/users/UsersApi.java     |  31 +---
 .../initialization/XnatWebAppInitializer.java |  34 ++--
 5 files changed, 254 insertions(+), 58 deletions(-)
 create mode 100644 src/main/java/org/nrg/xapi/rest/AbstractXnatRestApi.java
 create mode 100644 src/main/java/org/nrg/xapi/rest/dicomscp/DicomSCPApi.java

diff --git a/src/main/java/org/nrg/dcm/DicomSCPManager.java b/src/main/java/org/nrg/dcm/DicomSCPManager.java
index a1df4e5a..dc51a81a 100644
--- a/src/main/java/org/nrg/dcm/DicomSCPManager.java
+++ b/src/main/java/org/nrg/dcm/DicomSCPManager.java
@@ -35,13 +35,17 @@ public class DicomSCPManager {
         stopDicomSCPs();
     }
 
-    public DicomSCP create(final DicomSCPInstance instance) throws IOException, NrgServiceException {
+    public DicomSCP create(final DicomSCPInstance instance) throws NrgServiceException {
         final String scpId = instance.getScpId();
         if (_preferences.hasDicomSCPInstance(scpId)) {
             throw new NrgServiceException(NrgServiceError.ConfigurationError, "There is already a DICOM SCP instance with the ID " + scpId);
         }
-        _preferences.setDicomSCPInstance(instance);
-        return _preferences.getDicomSCP(scpId);
+        try {
+            _preferences.setDicomSCPInstance(instance);
+            return _preferences.getDicomSCP(scpId);
+        } catch (IOException e) {
+            throw new NrgServiceRuntimeException(NrgServiceError.Unknown, "Unable to create DICOM SCP: " + instance.getAeTitle() + ":" + instance.getPort(), e);
+        }
     }
 
     public void delete(final String scpId) throws NrgServiceException {
@@ -55,31 +59,43 @@ public class DicomSCPManager {
         return new ArrayList<>(_preferences.getDicomSCPInstances().values());
     }
 
-    public void startOrStopDicomSCPAsDictatedByConfiguration() {
-        final boolean enableDicomReceiver = _siteConfigurationService.getBoolSiteConfigurationProperty("enableDicomReceiver", true);
-        if (enableDicomReceiver) {
-            startDicomSCPs();
-        } else {
-            stopDicomSCPs();
+    public void setDicomSCPInstance(final DicomSCPInstance instance) {
+        try {
+            _preferences.setDicomSCPInstance(instance);
+        } catch (IOException e) {
+            throw new NrgServiceRuntimeException(NrgServiceError.Unknown, "Unable to update DICOM SCP: " + instance.getAeTitle() + ":" + instance.getPort(), e);
         }
     }
 
-    public void startDicomSCPs() {
+    public List<String> startOrStopDicomSCPAsDictatedByConfiguration() {
+        final boolean enableDicomReceiver = _siteConfigurationService.getBoolSiteConfigurationProperty("enableDicomReceiver", true);
+        return enableDicomReceiver ? startDicomSCPs() : stopDicomSCPs();
+    }
+
+    public List<String> startDicomSCPs() {
+        final List<String> started = new ArrayList<>();
         for (final DicomSCPInstance instance : _preferences.getDicomSCPInstances().values()) {
             if (instance.isEnabled()) {
                 startDicomSCP(instance);
+                started.add(instance.getScpId());
             }
         }
+        return started;
     }
 
     public void startDicomSCP(final String scpId) {
         startDicomSCP(_preferences.getDicomSCPInstance(scpId));
     }
 
-    public void stopDicomSCPs() {
+    public List<String> stopDicomSCPs() {
+        final List<String> stopped = new ArrayList<>();
         for (final DicomSCP dicomSCP : _preferences.getDicomSCPs()) {
-            dicomSCP.stop();
+            if (dicomSCP.isStarted()) {
+                dicomSCP.stop();
+                stopped.add(dicomSCP.getScpId());
+            }
         }
+        return stopped;
     }
 
     public void stopDicomSCP(final String scpId) {
diff --git a/src/main/java/org/nrg/xapi/rest/AbstractXnatRestApi.java b/src/main/java/org/nrg/xapi/rest/AbstractXnatRestApi.java
new file mode 100644
index 00000000..1c2e5618
--- /dev/null
+++ b/src/main/java/org/nrg/xapi/rest/AbstractXnatRestApi.java
@@ -0,0 +1,39 @@
+package org.nrg.xapi.rest;
+
+import org.nrg.xdat.security.XDATUser;
+import org.nrg.xft.security.UserI;
+import org.springframework.http.HttpStatus;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+/**
+ * Provides basic functions for integrating Spring REST controllers with XNAT.
+ */
+public abstract class AbstractXnatRestApi {
+    protected HttpStatus isPermitted(String id) {
+        UserI sessionUser = getSessionUser();
+        if (sessionUser == null) {
+            return HttpStatus.UNAUTHORIZED;
+        }
+        if ((sessionUser.getUsername().equals(id)) || (isPermitted() == null)) {
+            return null;
+        }
+        return HttpStatus.FORBIDDEN;
+    }
+
+    protected UserI getSessionUser() {
+        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+        if ((principal instanceof UserI)) {
+            return (UserI) principal;
+        }
+        return null;
+    }
+
+    protected HttpStatus isPermitted() {
+        UserI sessionUser = getSessionUser();
+        if ((sessionUser instanceof XDATUser)) {
+            return ((XDATUser) sessionUser).isSiteAdmin() ? null : HttpStatus.FORBIDDEN;
+        }
+
+        return null;
+    }
+}
diff --git a/src/main/java/org/nrg/xapi/rest/dicomscp/DicomSCPApi.java b/src/main/java/org/nrg/xapi/rest/dicomscp/DicomSCPApi.java
new file mode 100644
index 00000000..6ef05d7c
--- /dev/null
+++ b/src/main/java/org/nrg/xapi/rest/dicomscp/DicomSCPApi.java
@@ -0,0 +1,168 @@
+package org.nrg.xapi.rest.dicomscp;
+
+import io.swagger.annotations.*;
+import org.nrg.dcm.DicomSCPManager;
+import org.nrg.dcm.preferences.DicomSCPInstance;
+import org.nrg.framework.exceptions.NrgServiceException;
+import org.nrg.xapi.rest.NotFoundException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import javax.inject.Inject;
+import java.util.List;
+
+// @XnatRestlet({"/services/dicomscp", "/services/dicomscp/instance/{SCP_ID}", "/services/dicomscp/instance/{SCP_ID}/{ACTION}", "/services/dicomscp/{ACTION}"})
+
+@Api(description = "XNAT DICOM SCP management API")
+@RestController
+@RequestMapping(value = "/dicomscp")
+public class DicomSCPApi extends org.nrg.xapi.rest.AbstractXnatRestApi {
+    private static final Logger _log = LoggerFactory.getLogger(DicomSCPApi.class);
+
+    @ApiOperation(value = "Get list of all configured DICOM SCP receiver definitions.", notes = "The primary DICOM SCP retrieval function returns a list of all DICOM SCP receivers defined for the current system.", response = DicomSCPInstance.class, responseContainer = "List")
+    @ApiResponses({@ApiResponse(code = 200, message = "A list of DICOM SCP receiver definitions."), @ApiResponse(code = 500, message = "Unexpected error")})
+    @RequestMapping(produces = {"application/json", "application/xml"}, method = RequestMethod.GET)
+    @ResponseBody
+    public ResponseEntity<List<DicomSCPInstance>> dicomSCPsGet() {
+        return new ResponseEntity<>(_manager.getDicomSCPInstances(), HttpStatus.OK);
+    }
+
+    @ApiOperation(value = "Gets the DICOM SCP receiver definition with the specified ID.", notes = "Returns the DICOM SCP receiver definition with the specified ID.", response = DicomSCPInstance.class)
+    @ApiResponses({@ApiResponse(code = 200, message = "DICOM SCP receiver definition successfully retrieved."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to view this DICOM SCP receiver definition."), @ApiResponse(code = 404, message = "DICOM SCP receiver definition not found."), @ApiResponse(code = 500, message = "Unexpected error")})
+    @RequestMapping(value = {"/{id}"}, produces = {"application/json", "application/xml", "text/html"}, method = {RequestMethod.GET})
+    public ResponseEntity<DicomSCPInstance> dicomSCPInstanceGet(@ApiParam(value = "ID of the DICOM SCP receiver definition to fetch", required = true) @PathVariable("id") final String id) {
+        HttpStatus status = isPermitted(id);
+        if (status != null) {
+            return new ResponseEntity<>(status);
+        }
+        return _manager.hasDicomSCP(id) ? new ResponseEntity<>(_manager.getDicomSCPInstance(id), HttpStatus.OK)
+                                        : new ResponseEntity<DicomSCPInstance>(HttpStatus.NOT_FOUND);
+    }
+
+    @ApiOperation(value = "Creates or updates the DICOM SCP receiver definition object with the specified ID.", notes = "Returns the updated DICOM SCP receiver definition.", response = DicomSCPInstance.class)
+    @ApiResponses({@ApiResponse(code = 200, message = "DICOM SCP receiver definition successfully created or updated."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to create or update this DICOM SCP receiver definition."), @ApiResponse(code = 404, message = "DICOM SCP receiver definition not found."), @ApiResponse(code = 500, message = "Unexpected error")})
+    @RequestMapping(value = {"/{id}"}, produces = {"application/json", "application/xml", "text/html"}, method = {RequestMethod.PUT})
+    public ResponseEntity<DicomSCPInstance> dicomSCPInstanceCreateOrUpdate(@ApiParam(value = "The ID of the DICOM SCP receiver definition to create or update.", required = true) @PathVariable("id") final String id, @RequestBody final DicomSCPInstance instance) throws NotFoundException {
+        HttpStatus status = isPermitted(id);
+        if (status != null) {
+            return new ResponseEntity<>(status);
+        }
+        if (!_manager.hasDicomSCP(id)) {
+            try {
+                _manager.create(instance);
+            } catch (NrgServiceException e) {
+                _log.error("An error occurred trying to create a new DICOM SCP instance", e);
+                return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+            }
+        } else {
+            _manager.setDicomSCPInstance(instance);
+        }
+        return new ResponseEntity<>(instance, HttpStatus.OK);
+    }
+
+    @ApiOperation(value = "Deletes the DICOM SCP receiver definition object with the specified ID.", notes = "This call will stop the receiver if it's currently running.", response = Void.class)
+    @ApiResponses({@ApiResponse(code = 200, message = "DICOM SCP receiver definition successfully created or updated."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to delete this DICOM SCP receiver definition."), @ApiResponse(code = 404, message = "DICOM SCP receiver definition not found."), @ApiResponse(code = 500, message = "Unexpected error")})
+    @RequestMapping(value = {"/{id}"}, produces = {"application/json", "application/xml", "text/html"}, method = {RequestMethod.DELETE})
+    public ResponseEntity<Void> dicomSCPInstanceDelete(@ApiParam(value = "The ID of the DICOM SCP receiver definition to delete.", required = true) @PathVariable("id") final String id) throws NotFoundException {
+        HttpStatus status = isPermitted(id);
+        if (status != null) {
+            return new ResponseEntity<>(status);
+        }
+        if (!_manager.hasDicomSCP(id)) {
+            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+        }
+        try {
+            _manager.delete(id);
+            return new ResponseEntity<>(HttpStatus.OK);
+        } catch (NrgServiceException e) {
+            _log.error("An error occurred trying to delete the DICOM SCP instance " + id, e);
+            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @ApiOperation(value = "Returns whether the DICOM SCP receiver definition with the specified ID is enabled.", notes = "Returns true or false based on whether the specified DICOM SCP receiver definition is enabled or not.", response = Boolean.class)
+    @ApiResponses({@ApiResponse(code = 200, message = "DICOM SCP receiver definition enabled status successfully retrieved."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to view this DICOM SCP receiver definition."), @ApiResponse(code = 404, message = "DICOM SCP receiver definition not found."), @ApiResponse(code = 500, message = "Unexpected error")})
+    @RequestMapping(value = {"/{id}/enabled"}, produces = {"application/json"}, method = {RequestMethod.GET})
+    public ResponseEntity<Boolean> dicomSCPInstanceEnabledGet(@ApiParam(value = "The ID of the DICOM SCP receiver definition to retrieve the enabled status for.", required = true) @PathVariable("id") final String id) {
+        HttpStatus status = isPermitted(id);
+        if (status != null) {
+            return new ResponseEntity<>(status);
+        }
+        return _manager.hasDicomSCP(id) ? new ResponseEntity<>(_manager.getDicomSCPInstance(id).isEnabled(), HttpStatus.OK)
+                                        : new ResponseEntity<Boolean>(HttpStatus.NOT_FOUND);
+    }
+
+    @ApiOperation(value = "Sets the DICOM SCP receiver definition's enabled state.", notes = "Sets the enabled state of the DICOM SCP receiver definition with the specified ID to the value of the flag parameter.", response = Void.class)
+    @ApiResponses({@ApiResponse(code = 200, message = "DICOM SCP receiver definition enabled status successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to enable or disable this DICOM SCP receiver definition."), @ApiResponse(code = 404, message = "DICOM SCP receiver definition not found."), @ApiResponse(code = 500, message = "Unexpected error")})
+    @RequestMapping(value = {"/{id}/enabled/{flag}"}, produces = {"application/json"}, method = {RequestMethod.PUT})
+    public ResponseEntity<Void> dicomSCPInstanceSetEnabledFlag(@ApiParam(value = "ID of the DICOM SCP receiver definition to modify", required = true) @PathVariable("id") final String id,
+                                                               @ApiParam(value = "The value to set for the enabled status.", required = true) @PathVariable("flag") final Boolean flag) {
+        HttpStatus status = isPermitted(id);
+        if (status != null) {
+            return new ResponseEntity<>(status);
+        }
+        if (!_manager.hasDicomSCP(id)) {
+            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+        }
+        _manager.getDicomSCPInstance(id).setEnabled(flag);
+        return new ResponseEntity<>(HttpStatus.OK);
+    }
+
+    @ApiOperation(value = "Starts all enabled DICOM SCP receivers.", notes = "This starts all enabled DICOM SCP receivers. The return value notes the number of ", responseContainer = "List", response = String.class)
+    @ApiResponses({@ApiResponse(code = 200, message = "DICOM SCP receivers successfully started."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to enable or disable this DICOM SCP receiver definition."), @ApiResponse(code = 404, message = "DICOM SCP receiver definition not found."), @ApiResponse(code = 500, message = "Unexpected error")})
+    @RequestMapping(value = {"/start"}, produces = {"application/json"}, method = {RequestMethod.PUT})
+    public ResponseEntity<List<String>> dicomSCPInstancesStart() {
+        HttpStatus status = isPermitted();
+        if (status != null) {
+            return new ResponseEntity<>(status);
+        }
+        return new ResponseEntity<>(_manager.startDicomSCPs(), HttpStatus.OK);
+    }
+
+    @ApiOperation(value = "Starts the DICOM SCP receiver.", notes = "This starts the DICOM SCP receiver. Note that this will start the receiver regardless of its enabled or disabled setting. This returns true if the instance was started and false if not.", response = Boolean.class)
+    @ApiResponses({@ApiResponse(code = 200, message = "DICOM SCP receiver successfully started."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to enable or disable this DICOM SCP receiver definition."), @ApiResponse(code = 404, message = "DICOM SCP receiver definition not found."), @ApiResponse(code = 500, message = "Unexpected error")})
+    @RequestMapping(value = {"/{id}/start"}, produces = {"application/json"}, method = {RequestMethod.PUT})
+    public ResponseEntity<Boolean> dicomSCPInstanceStart(@ApiParam(value = "ID of the DICOM SCP receiver to start.", required = true) @PathVariable("id") final String id) {
+        HttpStatus status = isPermitted(id);
+        if (status != null) {
+            return new ResponseEntity<>(status);
+        }
+        if (!_manager.hasDicomSCP(id)) {
+            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+        }
+        _manager.startDicomSCP(id);
+        return new ResponseEntity<>(true, HttpStatus.OK);
+    }
+
+    @ApiOperation(value = "Stops all enabled DICOM SCP receivers.", notes = "This stops all enabled DICOM SCP receivers. The return value notes the number of ", responseContainer = "List", response = String.class)
+    @ApiResponses({@ApiResponse(code = 200, message = "DICOM SCP receivers successfully stopped."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to enable or disable this DICOM SCP receiver definition."), @ApiResponse(code = 404, message = "DICOM SCP receiver definition not found."), @ApiResponse(code = 500, message = "Unexpected error")})
+    @RequestMapping(value = {"/stop"}, produces = {"application/json"}, method = {RequestMethod.PUT})
+    public ResponseEntity<List<String>> dicomSCPInstancesStop() {
+        HttpStatus status = isPermitted();
+        if (status != null) {
+            return new ResponseEntity<>(status);
+        }
+        return new ResponseEntity<>(_manager.stopDicomSCPs(), HttpStatus.OK);
+    }
+
+    @ApiOperation(value = "Stops the DICOM SCP receiver.", notes = "This stops the DICOM SCP receiver. Note that this will stop the receiver regardless of its enabled or disabled setting. This returns true if the instance was stoped and false if not.", response = Boolean.class)
+    @ApiResponses({@ApiResponse(code = 200, message = "DICOM SCP receiver successfully stoped."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to enable or disable this DICOM SCP receiver definition."), @ApiResponse(code = 404, message = "DICOM SCP receiver definition not found."), @ApiResponse(code = 500, message = "Unexpected error")})
+    @RequestMapping(value = {"/{id}/stop"}, produces = {"application/json"}, method = {RequestMethod.PUT})
+    public ResponseEntity<Boolean> dicomSCPInstanceStop(@ApiParam(value = "ID of the DICOM SCP receiver to stop.", required = true) @PathVariable("id") final String id) {
+        HttpStatus status = isPermitted(id);
+        if (status != null) {
+            return new ResponseEntity<>(status);
+        }
+        if (!_manager.hasDicomSCP(id)) {
+            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+        }
+        _manager.stopDicomSCP(id);
+        return new ResponseEntity<>(true, HttpStatus.OK);
+    }
+
+    @Inject
+    private DicomSCPManager _manager;
+}
diff --git a/src/main/java/org/nrg/xapi/rest/users/UsersApi.java b/src/main/java/org/nrg/xapi/rest/users/UsersApi.java
index feb7cd73..34fe4503 100644
--- a/src/main/java/org/nrg/xapi/rest/users/UsersApi.java
+++ b/src/main/java/org/nrg/xapi/rest/users/UsersApi.java
@@ -3,6 +3,7 @@ package org.nrg.xapi.rest.users;
 import io.swagger.annotations.*;
 import org.apache.commons.lang3.StringUtils;
 import org.nrg.xapi.model.users.User;
+import org.nrg.xapi.rest.AbstractXnatRestApi;
 import org.nrg.xapi.rest.NotFoundException;
 import org.nrg.xdat.security.XDATUser;
 import org.nrg.xdat.security.helpers.Users;
@@ -24,7 +25,7 @@ import java.util.List;
 @Api(description = "The XNAT POC User Management API")
 @RestController
 @RequestMapping(value = "/users")
-public class UsersApi {
+public class UsersApi extends AbstractXnatRestApi {
     private static final Logger _log = LoggerFactory.getLogger(UsersApi.class);
 
     @ApiOperation(value = "Get list of users.", notes = "The primary users function returns a list of all users of the XNAT system.", response = User.class, responseContainer = "List")
@@ -198,34 +199,6 @@ public class UsersApi {
         }
     }
 
-    private UserI getSessionUser() {
-        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        if ((principal instanceof UserI)) {
-            return (UserI) principal;
-        }
-        return null;
-    }
-
-    private HttpStatus isPermitted(String id) {
-        UserI sessionUser = getSessionUser();
-        if (sessionUser == null) {
-            return HttpStatus.UNAUTHORIZED;
-        }
-        if ((sessionUser.getUsername().equals(id)) || (isPermitted() == null)) {
-            return null;
-        }
-        return HttpStatus.FORBIDDEN;
-    }
-
-    private HttpStatus isPermitted() {
-        UserI sessionUser = getSessionUser();
-        if ((sessionUser instanceof XDATUser)) {
-            return ((XDATUser) sessionUser).isSiteAdmin() ? null : HttpStatus.FORBIDDEN;
-        }
-
-        return null;
-    }
-
     @SuppressWarnings("unused")
     public static class Event {
         public static String Added                 = "Added User";
diff --git a/src/main/java/org/nrg/xnat/initialization/XnatWebAppInitializer.java b/src/main/java/org/nrg/xnat/initialization/XnatWebAppInitializer.java
index 5d89b0b3..55ca5b3e 100644
--- a/src/main/java/org/nrg/xnat/initialization/XnatWebAppInitializer.java
+++ b/src/main/java/org/nrg/xnat/initialization/XnatWebAppInitializer.java
@@ -6,7 +6,7 @@ import org.apache.axis.transport.http.AxisServlet;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.turbine.Turbine;
 import org.nrg.framework.exceptions.NrgServiceRuntimeException;
-import org.nrg.framework.processors.XnatModuleBean;
+import org.nrg.framework.processors.XnatPluginBean;
 import org.nrg.xdat.servlet.XDATAjaxServlet;
 import org.nrg.xdat.servlet.XDATServlet;
 import org.nrg.xnat.restlet.servlet.XNATRestletServlet;
@@ -62,14 +62,14 @@ public class XnatWebAppInitializer extends AbstractAnnotationConfigDispatcherSer
 
     @Override
     protected String[] getServletMappings() {
-        return new String[] { "/admin/*", "/xapi/*" };
+        return new String[] {"/admin/*", "/xapi/*"};
     }
 
     @Override
     protected Class<?>[] getRootConfigClasses() {
         final List<Class<?>> configClasses = new ArrayList<>();
         configClasses.add(RootConfig.class);
-        configClasses.addAll(getModuleConfigs());
+        configClasses.addAll(getPluginConfigs());
         return configClasses.toArray(new Class[configClasses.size()]);
     }
 
@@ -101,7 +101,7 @@ public class XnatWebAppInitializer extends AbstractAnnotationConfigDispatcherSer
             tmpDir.toFile().deleteOnExit();
             return new MultipartConfigElement(tmpDir.toAbsolutePath().toString(), MAX_FILE_SIZE, MAX_REQUEST_SIZE, FILE_SIZE_THRESHOLD);
         } catch (IOException e) {
-            throw new NrgServiceRuntimeException("An error occurred trying to create the temp folder " + prefix + " in the containing folder "+ root);
+            throw new NrgServiceRuntimeException("An error occurred trying to create the temp folder " + prefix + " in the containing folder " + root);
         }
     }
 
@@ -111,35 +111,35 @@ public class XnatWebAppInitializer extends AbstractAnnotationConfigDispatcherSer
 
     private static final int FILE_SIZE_THRESHOLD = 0; // Threshold turned off.
 
-    private List<Class<?>> getModuleConfigs() {
-        final List<Class<?>> moduleConfigs = new ArrayList<>();
+    private List<Class<?>> getPluginConfigs() {
+        final List<Class<?>> configs = new ArrayList<>();
         try {
             final PathMatchingResourcePatternResolver resolver  = new PathMatchingResourcePatternResolver();
-            final Resource[]                          resources = resolver.getResources("classpath*:META-INF/xnat/**/*-module.properties");
+            final Resource[]                          resources = resolver.getResources("classpath*:META-INF/xnat/**/*-plugin.properties");
             for (final Resource resource : resources) {
-                final Properties     properties   = PropertiesLoaderUtils.loadProperties(resource);
-                final XnatModuleBean module       = new XnatModuleBean(properties);
-                final Class<?>       moduleConfig = module.getConfigClass();
-                moduleConfigs.add(moduleConfig);
+                final Properties     properties = PropertiesLoaderUtils.loadProperties(resource);
+                final XnatPluginBean plugin     = new XnatPluginBean(properties);
+                final Class<?>       config     = plugin.getConfigClass();
+                configs.add(config);
             }
         } catch (IOException e) {
-            throw new RuntimeException("An error occurred trying to locate XNAT module definitions.");
+            throw new RuntimeException("An error occurred trying to locate XNAT plugin definitions.");
         } catch (ClassNotFoundException e) {
-            _log.error("Did not find a class specified in a module definition.", e);
+            _log.error("Did not find a class specified in a plugin definition.", e);
         }
 
-        return moduleConfigs;
+        return configs;
     }
 
     private void addServlet(final Class<? extends Servlet> clazz, final int loadOnStartup, final String... mappings) {
-        final String                      name = StringUtils.uncapitalize(clazz.getSimpleName());
-        final ServletRegistration.Dynamic registration  = _context.addServlet(name, clazz);
+        final String                      name         = StringUtils.uncapitalize(clazz.getSimpleName());
+        final ServletRegistration.Dynamic registration = _context.addServlet(name, clazz);
         registration.setLoadOnStartup(loadOnStartup);
         registration.addMapping(mappings);
     }
 
     private static class XnatTurbineConfig implements ServletConfig {
-        public XnatTurbineConfig(final ServletContext context) {
+        XnatTurbineConfig(final ServletContext context) {
             _context = context;
         }
 
-- 
GitLab