Example #1
0
 /**
  * Saves a settings section of a bundle.
  *
  * @param bundleId the id of the bundle
  * @param bundleSettings the settings section to be saved
  * @throws IOException if there was a problem reading the settings (if the config mode is FILE)
  */
 @ResponseStatus(HttpStatus.OK)
 @RequestMapping(value = "/settings/{bundleId}", method = RequestMethod.POST)
 public void saveBundleSettings(@PathVariable long bundleId, @RequestBody Settings bundleSettings)
     throws IOException {
   settingsService.saveBundleSettings(bundleSettings, bundleId);
   statusMessageService.info("{admin.settings.saved.bundle}", ADMIN_MODULE_NAME);
 }
Example #2
0
 /**
  * Handles adding a new configuration location to the system.
  *
  * @param location the location to be added
  * @throws IOException if we were unable to add the location
  */
 @ResponseStatus(HttpStatus.OK)
 @RequestMapping(value = "/settings/platform/location", method = RequestMethod.POST)
 public void uploadSettingsLocation(@RequestParam(required = true) String location)
     throws IOException {
   settingsService.addSettingsPath(location);
   statusMessageService.info("{settings.saved.location}", ADMIN_MODULE_NAME);
 }
Example #3
0
 /**
  * Handles an upload of a raw configuration file for a bundle.
  *
  * @param bundleId the id of the bundle which registers this file
  * @param filename the name of the file
  * @param file the representation of the file being uploaded
  */
 @ResponseStatus(HttpStatus.OK)
 @RequestMapping(value = "/settings/{bundleId}/raw", method = RequestMethod.POST)
 void uploadRawFile(
     @PathVariable long bundleId,
     @RequestParam(required = true) String filename,
     @RequestParam(required = true) MultipartFile file) {
   settingsService.saveRawFile(file, filename, bundleId);
   statusMessageService.info("{admin.settings.saved.file}", ADMIN_MODULE_NAME);
 }
  @ExceptionHandler(Exception.class)
  public void handleBundleException(HttpServletResponse response, Exception ex) throws IOException {
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    Throwable rootEx = (ex.getCause() == null ? ex : ex.getCause());

    String msg =
        (StringUtils.isNotBlank(rootEx.getMessage())) ? rootEx.getMessage() : rootEx.toString();
    statusMessageService.error(msg);

    try (Writer writer = response.getWriter()) {
      writer.write(ExceptionUtils.getStackTrace(ex));
    }
  }
 @ResponseStatus(HttpStatus.OK)
 @RequestMapping(value = "/bundles/{bundleId}/uninstall", method = RequestMethod.POST)
 public void uninstallBundle(@PathVariable long bundleId) throws BundleException {
   moduleAdminService.uninstallBundle(bundleId);
   statusMessageService.ok("{bundles.uninstall.success}");
 }
Example #6
0
 /**
  * Saves a particular section of the platform settings.
  *
  * @param platformSettings the platform settings section to be saved
  * @throws IOException if there was a problem reading the settings (if the config mode is FILE)
  */
 @RequestMapping(value = "/settings/platform", method = RequestMethod.POST)
 @ResponseStatus(HttpStatus.OK)
 public void savePlatformSettings(@RequestBody Settings platformSettings) throws IOException {
   settingsService.savePlatformSettings(platformSettings);
   statusMessageService.info(PLATFORM_SETTINGS_SAVED, ADMIN_MODULE_NAME);
 }
Example #7
0
 /**
  * Saves all platform settings.
  *
  * @param platformSettings an array of {@link org.motechproject.admin.settings.Settings} objects
  *     representing sections of the platform settings
  */
 @ResponseStatus(HttpStatus.OK)
 @RequestMapping(value = "/settings/platform/list", method = RequestMethod.POST)
 public void savePlatformSettings(@RequestBody Settings[] platformSettings) {
   settingsService.savePlatformSettings(Arrays.asList(platformSettings));
   statusMessageService.info("{admin.settings.saved.bundle}", ADMIN_MODULE_NAME);
 }
Example #8
0
 /**
  * Handles exceptions thrown in the controller. Logs an error and publishes a status message in
  * the system.
  *
  * @param e the exception thrown
  * @see org.motechproject.admin.domain.StatusMessage
  */
 @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
 @ExceptionHandler(value = Exception.class)
 public void handleException(Exception e) {
   LOGGER.error(e.getMessage(), e);
   statusMessageService.error("Error: " + e.getMessage(), ADMIN_MODULE_NAME);
 }
Example #9
0
 /**
  * Handles platform settings update through file upload.
  *
  * @param settingsFile the representation of the file being uploaded
  */
 @ResponseStatus(HttpStatus.OK)
 @RequestMapping(value = "/settings/platform/upload", method = RequestMethod.POST)
 public void uploadSettingsFile(@RequestParam(required = true) MultipartFile settingsFile) {
   settingsService.saveSettingsFile(settingsFile);
   statusMessageService.info(PLATFORM_SETTINGS_SAVED, ADMIN_MODULE_NAME);
 }