diff --git a/src/main/java/org/nrg/xapi/rest/JsonYamlRestValidator.java b/src/main/java/org/nrg/xapi/rest/JsonYamlRestValidator.java index 3d91d558f04fcc0ab2ac0748dbb0a122ac5a4ab0..884ff26dcd98e6925eacbf340b98e5694090088f 100644 --- a/src/main/java/org/nrg/xapi/rest/JsonYamlRestValidator.java +++ b/src/main/java/org/nrg/xapi/rest/JsonYamlRestValidator.java @@ -14,8 +14,12 @@ import io.swagger.annotations.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Api(description = "JSON / YAML REST Validator") @RestController @@ -25,38 +29,31 @@ public class JsonYamlRestValidator { @ApiOperation(value = "Validates the JSON string passed in as an escaped query variable.", notes = "Query string variable is json", response = String.class, responseContainer = "String") @ApiResponses({@ApiResponse(code = 200, message = "Reports \"Success\" if valid or the parsing error message if not."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(produces = {"application/json", "application/xml"}, method = RequestMethod.GET) - public ResponseEntity<String> validateQueryJson(@ApiParam(value="the JSON string to validate", required=true) @RequestParam(value="json", required=true) String json) { - try { - if(validateJson(json)) { - return new ResponseEntity<>("Success", HttpStatus.OK); - } - } catch (Exception e) { - e.printStackTrace(); - return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); - } - return new ResponseEntity<>("Failed", HttpStatus.OK); + @RequestMapping(produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}, method = RequestMethod.GET) + public ResponseEntity<String> validateQueryJson(@ApiParam(value="the JSON string to validate", required=true) @RequestParam(value="json") String json) { + return validate(json); } @ApiOperation(value = "Validates the posted JSON string.", response = String.class, responseContainer = "String") @ApiResponses({@ApiResponse(code = 200, message = "Reports \"Success\" if valid or the parsing error message if not."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(produces = {"application/json", "application/xml"}, method = RequestMethod.POST) - public ResponseEntity<String> validatePostedJson(@ApiParam(value="the JSON string to validate", required=true) @RequestParam(value="json", required=true) String json) { + @RequestMapping(produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}, method = RequestMethod.POST) + public ResponseEntity<String> validatePostedJson(@ApiParam(value="the JSON string to validate", required=true) @RequestParam(value="json") String json) { + return validate(json); + } + + private ResponseEntity<String> validate(final String json) { try { - if(validateJson(json)) { - return new ResponseEntity<>("Success", HttpStatus.OK); - } + return validateJson(json) ? new ResponseEntity<>("Success", HttpStatus.OK) : new ResponseEntity<>("Failed", HttpStatus.OK); } catch (Exception e) { - e.printStackTrace(); + _log.error("Error occurred validating JSON", e); return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } - return new ResponseEntity<>("Failed", HttpStatus.OK); } /** * @param json the JSON string to be validated */ - public boolean validateJson(String json) throws Exception { + private boolean validateJson(String json) throws Exception { if(json != null) { _log.debug("Valid JSON: "); return true; diff --git a/src/main/java/org/nrg/xapi/rest/dicomscp/DicomSCPApi.java b/src/main/java/org/nrg/xapi/rest/dicomscp/DicomSCPApi.java index d005355000c4a03b326eda906bec6e66930817ed..c3c4d14206346f3fc6ee48e7b3eeba360be973b8 100644 --- a/src/main/java/org/nrg/xapi/rest/dicomscp/DicomSCPApi.java +++ b/src/main/java/org/nrg/xapi/rest/dicomscp/DicomSCPApi.java @@ -10,6 +10,7 @@ import org.nrg.xdat.rest.AbstractXnatRestApi; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -24,7 +25,7 @@ public class DicomSCPApi extends AbstractXnatRestApi { @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) + @RequestMapping(produces = {MediaType.APPLICATION_JSON_VALUE}, method = RequestMethod.GET) @ResponseBody public ResponseEntity<List<DicomSCPInstance>> dicomSCPsGet() { return new ResponseEntity<>(_manager.getDicomSCPInstances(), HttpStatus.OK); @@ -32,7 +33,7 @@ public class DicomSCPApi extends AbstractXnatRestApi { @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}) + @RequestMapping(value = {"/{id}"}, produces = {MediaType.APPLICATION_JSON_VALUE}, 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) { @@ -44,7 +45,7 @@ public class DicomSCPApi extends AbstractXnatRestApi { @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}) + @RequestMapping(value = {"/{id}"}, produces = {MediaType.APPLICATION_JSON_VALUE}, 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) { @@ -65,7 +66,7 @@ public class DicomSCPApi extends AbstractXnatRestApi { @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}) + @RequestMapping(value = {"/{id}"}, produces = {MediaType.APPLICATION_JSON_VALUE}, 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) { @@ -85,7 +86,7 @@ public class DicomSCPApi extends AbstractXnatRestApi { @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}) + @RequestMapping(value = {"/{id}/enabled"}, produces = {MediaType.APPLICATION_JSON_VALUE}, 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) { @@ -97,7 +98,7 @@ public class DicomSCPApi extends AbstractXnatRestApi { @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}) + @RequestMapping(value = {"/{id}/enabled/{flag}"}, produces = {MediaType.APPLICATION_JSON_VALUE}, 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); @@ -113,7 +114,7 @@ public class DicomSCPApi extends AbstractXnatRestApi { @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}) + @RequestMapping(value = {"/start"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.PUT}) public ResponseEntity<List<String>> dicomSCPInstancesStart() { HttpStatus status = isPermitted(); if (status != null) { @@ -124,7 +125,7 @@ public class DicomSCPApi extends AbstractXnatRestApi { @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}) + @RequestMapping(value = {"/{id}/start"}, produces = {MediaType.APPLICATION_JSON_VALUE}, 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) { @@ -139,7 +140,7 @@ public class DicomSCPApi extends AbstractXnatRestApi { @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}) + @RequestMapping(value = {"/stop"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.PUT}) public ResponseEntity<List<String>> dicomSCPInstancesStop() { HttpStatus status = isPermitted(); if (status != null) { @@ -150,7 +151,7 @@ public class DicomSCPApi extends AbstractXnatRestApi { @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 stopped and false if not.", response = Boolean.class) @ApiResponses({@ApiResponse(code = 200, message = "DICOM SCP receiver 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 = {"/{id}/stop"}, produces = {"application/json"}, method = {RequestMethod.PUT}) + @RequestMapping(value = {"/{id}/stop"}, produces = {MediaType.APPLICATION_JSON_VALUE}, 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) { diff --git a/src/main/java/org/nrg/xapi/rest/event/EventHandlerApi.java b/src/main/java/org/nrg/xapi/rest/event/EventHandlerApi.java index 07e1ff4e66d77e40588b8ae2167fed4fcf79a75c..112eac6d6ca87b23654a7cbb923e347908751dbc 100644 --- a/src/main/java/org/nrg/xapi/rest/event/EventHandlerApi.java +++ b/src/main/java/org/nrg/xapi/rest/event/EventHandlerApi.java @@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; @@ -59,6 +60,7 @@ public class EventHandlerApi { private HibernateAutomationFiltersService filtersService; /** The event packages. */ + @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") @Autowired private EventPackages eventPackages; @@ -79,7 +81,7 @@ public class EventHandlerApi { */ @ApiOperation(value = "Get list of event classes.", notes = "Returns a list of classes implementing AutomationEventI.", response = List.class) @ApiResponses({@ApiResponse(code = 200, message = "An array of class names"), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/projects/{project_id}/eventHandlers/automationEventClasses"}, produces = {"application/json"}, method = RequestMethod.GET) + @RequestMapping(value = {"/projects/{project_id}/eventHandlers/automationEventClasses"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = RequestMethod.GET) @ResponseBody public ResponseEntity<List<EventClassInfo>> automationEventClassesGet(@PathVariable("project_id") String project_id) { final HttpStatus status = isPermitted(project_id); @@ -96,7 +98,7 @@ public class EventHandlerApi { */ @ApiOperation(value = "Get list of event classes.", notes = "Returns a list of classes implementing AutomationEventI.", response = List.class) @ApiResponses({@ApiResponse(code = 200, message = "An array of class names"), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/eventHandlers/automationEventClasses"}, produces = {"application/json"}, method = RequestMethod.GET) + @RequestMapping(value = {"/eventHandlers/automationEventClasses"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = RequestMethod.GET) @ResponseBody public ResponseEntity<List<EventClassInfo>> automationEventClassesGet() { final HttpStatus status = isPermitted(null); @@ -144,8 +146,7 @@ public class EventHandlerApi { final String[] annoInitialValues = (annoInitialValuesObj != null && annoInitialValuesObj instanceof String[]) ? (String[])annoInitialValuesObj : new String[] {}; final Object annoIncludeValuesFromDatabase = AnnotationUtils.getValue(anno, "includeValuesFromDatabase"); - boolean includeValuesFromDatabase = (annoIncludeValuesFromDatabase != null && annoIncludeValuesFromDatabase instanceof Boolean) ? - (boolean)annoIncludeValuesFromDatabase : true; + boolean includeValuesFromDatabase = !(annoIncludeValuesFromDatabase != null && annoIncludeValuesFromDatabase instanceof Boolean) || (boolean) annoIncludeValuesFromDatabase; if (!filterableFields.containsKey(column)) { final List<String> newValueList = Lists.newArrayList(); filterableFields.put(column,newValueList); @@ -262,16 +263,16 @@ public class EventHandlerApi { /** * Checks if is permitted. * - * @param project_id the project_id + * @param projectId the project ID * @return the http status */ - private HttpStatus isPermitted(String project_id) { + private HttpStatus isPermitted(String projectId) { final UserI sessionUser = getSessionUser(); if ((sessionUser instanceof XDATUser)) { - if (project_id != null) { - final XnatProjectdata proj = AutoXnatProjectdata.getXnatProjectdatasById(project_id, sessionUser, false); + if (projectId != null) { + final XnatProjectdata project = AutoXnatProjectdata.getXnatProjectdatasById(projectId, sessionUser, false); try { - return Permissions.canEdit(sessionUser, proj) ? null : HttpStatus.FORBIDDEN; + return Permissions.canEdit(sessionUser, project) ? null : HttpStatus.FORBIDDEN; } catch (Exception e) { _log.error("Error checking read status for project",e); return HttpStatus.INTERNAL_SERVER_ERROR; diff --git a/src/main/java/org/nrg/xapi/rest/notifications/NotificationsApi.java b/src/main/java/org/nrg/xapi/rest/notifications/NotificationsApi.java index 151a17d59def11969b0830bdf2c5fcecbc2caa99..e14bf5c40e1631a0c8550fac3d04eda8aac3936c 100644 --- a/src/main/java/org/nrg/xapi/rest/notifications/NotificationsApi.java +++ b/src/main/java/org/nrg/xapi/rest/notifications/NotificationsApi.java @@ -8,6 +8,7 @@ import org.nrg.xdat.rest.AbstractXnatRestApi; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.web.bind.annotation.RequestMapping; @@ -27,7 +28,7 @@ public class NotificationsApi extends AbstractXnatRestApi { @ApiOperation(value = "Sets all the mail service properties.", notes = "Sets the mail service host, port, username, password, and protocol.", response = Void.class) @ApiResponses({@ApiResponse(code = 200, message = "Mail service properties successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set the mail service properties."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/all"}, produces = {"application/json"}, method = {RequestMethod.POST}) + @RequestMapping(value = {"/all"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST}) public ResponseEntity<Void> setMailProperties(@ApiParam(value = "The value to set for the email host.") @RequestParam(value = "host", required = false) final String host, @ApiParam(value = "The value to set for the email port.") @RequestParam(value = "port", required = false) final int port, @ApiParam(value = "The value to set for the email username.") @RequestParam(value = "username", required = false) final String username, @@ -80,7 +81,7 @@ public class NotificationsApi extends AbstractXnatRestApi { @ApiOperation(value = "Sets the mail service host.", notes = "Sets the mail service host.", response = Void.class) @ApiResponses({@ApiResponse(code = 200, message = "Mail service host successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set the mail service host."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/host"}, produces = {"application/json"}, method = {RequestMethod.POST}) + @RequestMapping(value = {"/host"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST}) public ResponseEntity<Void> setHostProperty(@ApiParam(value = "The value to set for the email host.", required = true) @RequestParam("host") final String host) { final HttpStatus status = isPermitted(); if (status != null) { @@ -96,7 +97,7 @@ public class NotificationsApi extends AbstractXnatRestApi { @ApiOperation(value = "Sets the mail service port.", notes = "Sets the mail service port.", response = Void.class) @ApiResponses({@ApiResponse(code = 200, message = "Mail service port successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set the mail service port."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/port"}, produces = {"application/json"}, method = {RequestMethod.POST}) + @RequestMapping(value = {"/port"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST}) public ResponseEntity<Void> setPortProperty(@ApiParam(value = "The value to set for the email port.", required = true) @RequestParam("port") final int port) { final HttpStatus status = isPermitted(); if (status != null) { @@ -112,7 +113,7 @@ public class NotificationsApi extends AbstractXnatRestApi { @ApiOperation(value = "Sets the mail service protocol.", notes = "Sets the mail service protocol.", response = Void.class) @ApiResponses({@ApiResponse(code = 200, message = "Mail service protocol successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set the mail service protocol."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/protocol"}, produces = {"application/json"}, method = {RequestMethod.POST}) + @RequestMapping(value = {"/protocol"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST}) public ResponseEntity<Void> setProtocolProperty(@ApiParam(value = "The value to set for the email protocol.", required = true) @RequestParam("protocol") final String protocol) { final HttpStatus status = isPermitted(); if (status != null) { @@ -127,7 +128,7 @@ public class NotificationsApi extends AbstractXnatRestApi { @ApiOperation(value = "Sets the mail service username.", notes = "Sets the mail service username.", response = Void.class) @ApiResponses({@ApiResponse(code = 200, message = "Mail service username successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set the mail service username."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/username"}, produces = {"application/json"}, method = {RequestMethod.POST}) + @RequestMapping(value = {"/username"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST}) public ResponseEntity<Void> setUsernameProperty(@ApiParam(value = "The value to set for the email username.", required = true) @RequestParam("username") final String username) { final HttpStatus status = isPermitted(); if (status != null) { @@ -142,7 +143,7 @@ public class NotificationsApi extends AbstractXnatRestApi { @ApiOperation(value = "Sets the mail service password.", notes = "Sets the mail service password.", response = Void.class) @ApiResponses({@ApiResponse(code = 200, message = "Mail service password successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set the mail service password."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/password"}, produces = {"application/json"}, method = {RequestMethod.POST}) + @RequestMapping(value = {"/password"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST}) public ResponseEntity<Void> setPasswordProperty(@ApiParam(value = "The value to set for the email password.", required = true) @RequestParam("password") final String password) { final HttpStatus status = isPermitted(); if (status != null) { diff --git a/src/main/java/org/nrg/xapi/rest/settings/SiteConfigApi.java b/src/main/java/org/nrg/xapi/rest/settings/SiteConfigApi.java index c9f5766ac084e5628187aeb2e7703b81ea6d71a7..7c11a03a5edba2d9fc366c54478ba644e04f7bf1 100644 --- a/src/main/java/org/nrg/xapi/rest/settings/SiteConfigApi.java +++ b/src/main/java/org/nrg/xapi/rest/settings/SiteConfigApi.java @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -24,7 +25,7 @@ import java.util.Map; public class SiteConfigApi extends AbstractXnatRestApi { @ApiOperation(value = "Returns the full map of site configuration properties.", notes = "Complex objects may be returned as encapsulated JSON strings.", response = SiteConfigPreferences.class) @ApiResponses({@ApiResponse(code = 200, message = "Site configuration properties successfully retrieved."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set site configuration properties."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(produces = {"application/json"}, method = {RequestMethod.GET}) + @RequestMapping(produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.GET}) public ResponseEntity<SiteConfigPreferences> getAllSiteConfigProperties() { final HttpStatus status = isPermitted(); if (status != null) { @@ -38,7 +39,7 @@ public class SiteConfigApi extends AbstractXnatRestApi { @ApiOperation(value = "Returns a map of the selected site configuration properties.", notes = "Complex objects may be returned as encapsulated JSON strings.", response = String.class, responseContainer = "Map") @ApiResponses({@ApiResponse(code = 200, message = "Site configuration properties successfully retrieved."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set site configuration properties."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(consumes = {"application/json"}, produces = {"application/json"}, method = {RequestMethod.PUT}) + @RequestMapping(consumes = {MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.PUT}) public ResponseEntity<Map<String, String>> getSpecifiedSiteConfigProperties(@RequestBody final List<String> preferences) { final HttpStatus status = isPermitted(); if (status != null) { @@ -58,7 +59,7 @@ public class SiteConfigApi extends AbstractXnatRestApi { @ApiOperation(value = "Returns a map of the selected site configuration properties.", notes = "Complex objects may be returned as encapsulated JSON strings.", response = String.class, responseContainer = "Map") @ApiResponses({@ApiResponse(code = 200, message = "Site configuration properties successfully retrieved."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set site configuration properties."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = "{property}", consumes = {"application/json"}, produces = {"application/json"}, method = {RequestMethod.GET}) + @RequestMapping(value = "{property}", produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.GET}) public ResponseEntity<String> getSpecifiedSiteConfigProperties(@ApiParam(value = "The site configuration property to retrieve.", required = true) @PathVariable final String property) { final HttpStatus status = isPermitted(); if (status != null) { @@ -73,7 +74,7 @@ public class SiteConfigApi extends AbstractXnatRestApi { @ApiOperation(value = "Sets a map of site configuration properties.", notes = "Sets the site configuration properties specified in the map.", response = Void.class) @ApiResponses({@ApiResponse(code = 200, message = "Site configuration properties successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set site configuration properties."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/batch"}, consumes = {"application/json"}, produces = {"application/json"}, method = {RequestMethod.POST}) + @RequestMapping(value = {"/batch"}, consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE, MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST}) public ResponseEntity<Void> setBatchSiteConfigProperties(@ApiParam(value = "The map of site configuration properties to be set.", required = true) @RequestBody final Map<String, String> properties) { HttpStatus status = isPermitted(); if (status != null) { @@ -101,7 +102,7 @@ public class SiteConfigApi extends AbstractXnatRestApi { @ApiOperation(value = "Sets a single site configuration property.", notes = "Sets the site configuration property specified in the URL to the value set in the body.", response = Void.class) @ApiResponses({@ApiResponse(code = 200, message = "Site configuration properties successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set site configuration properties."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/{property}"}, consumes = {"application/json"}, produces = {"application/json"}, method = {RequestMethod.POST}) + @RequestMapping(value = {"/{property}"}, consumes = {MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST}) public ResponseEntity<Void> setSiteConfigProperty(@ApiParam(value = "The map of site configuration properties to be set.", required = true) @PathVariable("property") final String property, @RequestBody final String value) { HttpStatus status = isPermitted(); if (status != null) { diff --git a/src/main/java/org/nrg/xapi/rest/theme/ThemeApi.java b/src/main/java/org/nrg/xapi/rest/theme/ThemeApi.java index 3819a244e12663343f80cdffa232e91a795b4034..c52959b5a245d7cbd6e36f11bd3633ba1c09a250 100644 --- a/src/main/java/org/nrg/xapi/rest/theme/ThemeApi.java +++ b/src/main/java/org/nrg/xapi/rest/theme/ThemeApi.java @@ -24,6 +24,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; @@ -45,7 +46,7 @@ public class ThemeApi { @ApiOperation(value = "Get the currently selected global theme or a role based theme if specified.", notes = "Use this to get the theme selected by the system administrator on the Theme Management page.", response = ThemeConfig.class, responseContainer = "ThemeConfig") @ApiResponses({@ApiResponse(code = 200, message = "Reports the currently selected global theme (if there is one) and whether or not it's enabled."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/{role}"}, produces = {"application/json", "application/xml"}, method = RequestMethod.GET) + @RequestMapping(value = {"/{role}"}, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}, method = RequestMethod.GET) public ResponseEntity<ThemeConfig> themeGet(@ApiParam(value = "\"global\" or role name of currently set theme", required = true) @PathVariable("role") String role) { if("global".equalsIgnoreCase(role)){ return new ResponseEntity<>(themeService.getTheme(), HttpStatus.OK); @@ -55,14 +56,14 @@ public class ThemeApi { @ApiOperation(value = "Get list of available themes.", notes = "Use this to get a list of all available themes on the XNAT system.", response = ThemeService.TypeOption.class, responseContainer = "List") @ApiResponses({@ApiResponse(code = 200, message = "Reports the currently selected global theme (if there is one), whether or not it's enabled, and a list of available themes on the system in a JSON string."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(produces = {"application/json", "application/xml"}, method = RequestMethod.GET) + @RequestMapping(produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}, method = RequestMethod.GET) public ResponseEntity<List<ThemeService.TypeOption>> themesGet() { return new ResponseEntity<>(themeService.loadExistingThemes(), HttpStatus.OK); } @ApiOperation(value = "Deletes the theme with the specified name.", notes = "Returns success on deletion. ", response = String.class) @ApiResponses({@ApiResponse(code = 200, message = "Theme was successfully deleted."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to delete a theme."), @ApiResponse(code = 404, message = "Theme not found."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/{theme}"}, produces = {"application/json", "application/xml", "text/html"}, method = {RequestMethod.DELETE}) + @RequestMapping(value = {"/{theme}"}, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_HTML_VALUE}, method = {RequestMethod.DELETE}) public ResponseEntity<ThemeConfig> themeDelete(@ApiParam(value = "Name of the theme to delete", required = true) @PathVariable("theme") String theme) { ThemeConfig themeConfig = null; HttpStatus status = isPermitted(); @@ -94,7 +95,7 @@ public class ThemeApi { @ApiOperation(value = "Sets the current global theme to the one specified.", notes = "Returns the updated serialized theme object.", response = ThemeConfig.class) @ApiResponses({@ApiResponse(code = 200, message = "Successfully updated the current global theme."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to create or update this user."), @ApiResponse(code = 404, message = "Theme not found."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/{theme}"}, produces = {"application/json", "application/xml", "text/html"}, method = {RequestMethod.PUT}) + @RequestMapping(value = {"/{theme}"}, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_HTML_VALUE}, method = {RequestMethod.PUT}) public ResponseEntity<ThemeConfig> themePut(@ApiParam(value = "The name of the theme to select.", required = true) @PathVariable("theme") String theme, @RequestParam(value = "enabled", required=false, defaultValue="true") String enabled) throws NotFoundException { HttpStatus status = isPermitted(); if (status != null) { @@ -122,7 +123,7 @@ public class ThemeApi { @ApiOperation(value = "Accepts a multipart form with a zip file upload and extracts its contents in the theme system folder. If successful, the first (root) directory name (or theme name) unzipped is returned in the response. This will overwrite any other directories already existing with the same name without warning.", notes = "The structure of the zipped package must have only directories at it's root.", response = String.class) @ApiResponses({@ApiResponse(code = 200, message = "Theme package successfully uploaded and extracted."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to upload a theme package."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(produces = {"application/json"}, method = {RequestMethod.POST}) + @RequestMapping(produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST}) public ResponseEntity<List<ThemeService.TypeOption>> themePostUpload(@ApiParam(value = "Multipart file object being uploaded", required = true) @RequestParam(value="themePackage", required=false) MultipartFile themePackage) { HttpStatus status = isPermitted(); if (status != null) { 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 80691aef62ff33a548583777bc9c3204dbb4a1b4..0b2cc17a59a245cf2e2b6f8f0f23e49bcffdce3c 100644 --- a/src/main/java/org/nrg/xapi/rest/users/UsersApi.java +++ b/src/main/java/org/nrg/xapi/rest/users/UsersApi.java @@ -15,6 +15,7 @@ import org.nrg.xft.security.UserI; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -29,7 +30,7 @@ public class UsersApi extends AbstractXnatRestApi { @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") @ApiResponses({@ApiResponse(code = 200, message = "An array of users"), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(produces = {"application/json", "application/xml"}, method = RequestMethod.GET) + @RequestMapping(produces = {MediaType.APPLICATION_JSON_VALUE}, method = RequestMethod.GET) @ResponseBody public ResponseEntity<List<String>> usersGet() { return new ResponseEntity<List<String>>(new ArrayList<>(Users.getAllLogins()), HttpStatus.OK); @@ -37,7 +38,7 @@ public class UsersApi extends AbstractXnatRestApi { @ApiOperation(value = "Gets the user with the specified user ID.", notes = "Returns the serialized user object with the specified user ID.", response = User.class) @ApiResponses({@ApiResponse(code = 200, message = "User successfully retrieved."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to view this user."), @ApiResponse(code = 404, message = "User not found."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/{id}"}, produces = {"application/json", "application/xml", "text/html"}, method = {RequestMethod.GET}) + @RequestMapping(value = {"/{id}"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.GET}) public ResponseEntity<User> usersIdGet(@ApiParam(value = "ID of the user to fetch", required = true) @PathVariable("id") String id) { HttpStatus status = isPermitted(id); if (status != null) { @@ -57,7 +58,7 @@ public class UsersApi extends AbstractXnatRestApi { @ApiOperation(value = "Creates or updates the user object with the specified user ID.", notes = "Returns the updated serialized user object with the specified user ID.", response = User.class) @ApiResponses({@ApiResponse(code = 200, message = "User 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 user."), @ApiResponse(code = 404, message = "User not found."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/{id}"}, produces = {"application/json", "application/xml", "text/html"}, method = {RequestMethod.PUT}) + @RequestMapping(value = {"/{id}"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.PUT}) public ResponseEntity<User> usersIdPut(@ApiParam(value = "The ID of the user to create or update.", required = true) @PathVariable("id") String id, @RequestBody User model) throws NotFoundException { HttpStatus status = isPermitted(id); if (status != null) { @@ -98,7 +99,7 @@ public class UsersApi extends AbstractXnatRestApi { @ApiOperation(value = "Returns whether the user with the specified user ID is enabled.", notes = "Returns true or false based on whether the specified user is enabled or not.", response = Boolean.class) @ApiResponses({@ApiResponse(code = 200, message = "User 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 user."), @ApiResponse(code = 404, message = "User not found."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/{id}/enabled"}, produces = {"application/json"}, method = {RequestMethod.GET}) + @RequestMapping(value = {"/{id}/enabled"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.GET}) public ResponseEntity<Boolean> usersIdEnabledGet(@ApiParam(value = "The ID of the user to retrieve the enabled status for.", required = true) @PathVariable("id") String id) { HttpStatus status = isPermitted(id); if (status != null) { @@ -120,7 +121,7 @@ public class UsersApi extends AbstractXnatRestApi { @ApiOperation(value = "Sets the user's enabled state.", notes = "Sets the enabled state of the user with the specified user ID to the value of the flag parameter.", response = Boolean.class) @ApiResponses({@ApiResponse(code = 200, message = "User 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 user."), @ApiResponse(code = 404, message = "User not found."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/{id}/enabled/{flag}"}, produces = {"application/json"}, method = {RequestMethod.PUT}) + @RequestMapping(value = {"/{id}/enabled/{flag}"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.PUT}) public ResponseEntity<Boolean> usersIdEnabledFlagPut(@ApiParam(value = "ID of the user to fetch", required = true) @PathVariable("id") String id, @ApiParam(value = "The value to set for the enabled status.", required = true) @PathVariable("flag") Boolean flag) { HttpStatus status = isPermitted(id); if (status != null) { @@ -149,7 +150,7 @@ public class UsersApi extends AbstractXnatRestApi { @ApiOperation(value = "Returns whether the user with the specified user ID is verified.", notes = "Returns true or false based on whether the specified user is verified or not.", response = Boolean.class) @ApiResponses({@ApiResponse(code = 200, message = "User verified 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 user."), @ApiResponse(code = 404, message = "User not found."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/{id}/verified"}, produces = {"application/json"}, method = {RequestMethod.GET}) + @RequestMapping(value = {"/{id}/verified"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.GET}) public ResponseEntity<Boolean> usersIdVerifiedGet(@ApiParam(value = "The ID of the user to retrieve the verified status for.", required = true) @PathVariable("id") String id) { HttpStatus status = isPermitted(id); if (status != null) { @@ -171,7 +172,7 @@ public class UsersApi extends AbstractXnatRestApi { @ApiOperation(value = "Sets the user's verified state.", notes = "Sets the verified state of the user with the specified user ID to the value of the flag parameter.", response = Boolean.class) @ApiResponses({@ApiResponse(code = 200, message = "User verified status successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to verify or un-verify this user."), @ApiResponse(code = 404, message = "User not found."), @ApiResponse(code = 500, message = "Unexpected error")}) - @RequestMapping(value = {"/{id}/verified/{flag}"}, produces = {"application/json"}, method = {RequestMethod.PUT}) + @RequestMapping(value = {"/{id}/verified/{flag}"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.PUT}) public ResponseEntity<Boolean> usersIdVerifiedFlagPut(@ApiParam(value = "ID of the user to fetch", required = true) @PathVariable("id") String id, @ApiParam(value = "The value to set for the verified status.", required = true) @PathVariable("flag") Boolean flag) { HttpStatus status = isPermitted(id); if (status != null) { diff --git a/src/main/java/org/nrg/xnat/configuration/WebConfig.java b/src/main/java/org/nrg/xnat/configuration/WebConfig.java index b6bcb890a39819f8492dade1c4dc5573154bde16..ae542c22c86fd8b025e3e341fbbc85011b0e770a 100644 --- a/src/main/java/org/nrg/xnat/configuration/WebConfig.java +++ b/src/main/java/org/nrg/xnat/configuration/WebConfig.java @@ -1,5 +1,6 @@ package org.nrg.xnat.configuration; +import com.fasterxml.jackson.annotation.JsonInclude; import org.nrg.framework.annotations.XapiRestController; import org.nrg.xnat.spawner.configuration.SpawnerConfig; import org.slf4j.Logger; @@ -10,6 +11,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.web.multipart.MultipartResolver; import org.springframework.web.multipart.support.StandardServletMultipartResolver; import org.springframework.web.servlet.ViewResolver; @@ -31,6 +33,13 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @Import(SpawnerConfig.class) @ComponentScan({"org.nrg.xapi.rest", "org.nrg.xnat.spawner.controllers"}) public class WebConfig extends WebMvcConfigurerAdapter { + @Bean + public Jackson2ObjectMapperBuilder objectMapperBuilder() { + Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); + builder.serializationInclusion(JsonInclude.Include.NON_NULL); + return builder; + } + @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("**/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); diff --git a/src/main/java/org/nrg/xnat/initialization/RootConfig.java b/src/main/java/org/nrg/xnat/initialization/RootConfig.java index 41893262c2fe7132473074cc0645dfeb0dbce665..a7cb0e5034139610dd9f2b79065124aa3da65108 100644 --- a/src/main/java/org/nrg/xnat/initialization/RootConfig.java +++ b/src/main/java/org/nrg/xnat/initialization/RootConfig.java @@ -1,10 +1,12 @@ package org.nrg.xnat.initialization; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.PrettyPrinter; import com.fasterxml.jackson.core.util.DefaultIndenter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import org.nrg.framework.datacache.SerializerRegistry; import org.nrg.framework.exceptions.NrgServiceException; @@ -67,6 +69,9 @@ public class RootConfig { final PrettyPrinter printer = prettyPrinter(); final ObjectMapper mapper = new ObjectMapper().setDefaultPrettyPrinter(printer); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); + mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); + mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); return mapper; } @@ -75,6 +80,9 @@ public class RootConfig { final PrettyPrinter printer = prettyPrinter(); final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()).setDefaultPrettyPrinter(printer); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); + mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); + mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); return mapper; } diff --git a/src/main/webapp/WEB-INF/conf/log4j.properties b/src/main/webapp/WEB-INF/conf/log4j.properties index bedf1c6530aeff811d962d3a09863f8a6b9d370b..ab3132b478d430a128201e1b290ac2fddab42d6f 100644 --- a/src/main/webapp/WEB-INF/conf/log4j.properties +++ b/src/main/webapp/WEB-INF/conf/log4j.properties @@ -93,9 +93,46 @@ log4j.additivity.org.nrg.xft.db.PoolDBUtils=false # Security logs, both Spring Framework and XNAT log4j.category.org.springframework.security=WARN, security log4j.additivity.org.springframework.security=false +log4j.category.org.springframework.ldap=WARN, security +log4j.additivity.org.springframework.ldap=false log4j.category.org.nrg.xnat.security=WARN, security log4j.additivity.org.nrg.xnat.security=false +# Spring Framework logs +log4j.appender.org.springframework.beans=WARN, spring +log4j.additivity.org.springframework.beans=false +log4j.appender.org.springframework.context=WARN, spring +log4j.additivity.org.springframework.context=false +log4j.appender.org.springframework.core=WARN, spring +log4j.additivity.org.springframework.core=false +log4j.appender.org.springframework.http=WARN, spring +log4j.additivity.org.springframework.http=false +log4j.appender.org.springframework.mail=WARN, spring +log4j.additivity.org.springframework.mail=false +log4j.appender.org.springframework.oxm=WARN, spring +log4j.additivity.org.springframework.oxm=false +log4j.appender.org.springframework.scheduling=WARN, spring +log4j.additivity.org.springframework.scheduling=false +log4j.appender.org.springframework.stereotype=WARN, spring +log4j.additivity.org.springframework.stereotype=false +log4j.appender.org.springframework.util=WARN, spring +log4j.additivity.org.springframework.util=false +log4j.appender.org.springframework.web=WARN, spring +log4j.additivity.org.springframework.web=false + +# Database and ORM logging. +log4j.appender.org.nrg.framework.orm=WARN, orm +log4j.additivity.org.nrg.framework.orm=false +log4j.appender.org.springframework.orm=WARN, orm +log4j.additivity.org.springframework.orm=false +log4j.appender.org.springframework.dao=WARN, orm +log4j.additivity.org.springframework.dao=false +log4j.appender.org.springframework.jdbc=WARN, orm +log4j.additivity.org.springframework.jdbc=false +log4j.appender.org.springframework.transaction=WARN, orm +log4j.additivity.org.springframework.transaction=false + + # DICOM services log4j.category.org.nrg.dcm=WARN, dicom log4j.additivity.org.nrg.dcm=false @@ -278,6 +315,26 @@ log4j.appender.security.layout=org.apache.log4j.PatternLayout log4j.appender.security.layout.conversionPattern=%d [%t] %-5p %c - %m%n log4j.appender.security.append=true +# +# Spring Framework logs +# +log4j.appender.spring=org.apache.log4j.DailyRollingFileAppender +log4j.appender.spring.DatePattern='.'yyy-MM-dd +log4j.appender.spring.file=${xnat.home}/logs/spring.log +log4j.appender.spring.layout=org.apache.log4j.PatternLayout +log4j.appender.spring.layout.conversionPattern=%d [%t] %-5p %c - %m%n +log4j.appender.spring.append=true + +# +# NRG and Spring ORM Framework logs +# +log4j.appender.orm=org.apache.log4j.DailyRollingFileAppender +log4j.appender.orm.DatePattern='.'yyy-MM-dd +log4j.appender.orm.file=${xnat.home}/logs/orm.log +log4j.appender.orm.layout=org.apache.log4j.PatternLayout +log4j.appender.orm.layout.conversionPattern=%d [%t] %-5p %c - %m%n +log4j.appender.orm.append=true + # # Automation log output #