コード例 #1
0
 private void handleLocalizations(
     final LayerGroup lc, final String nameprefix, final HttpServletRequest request) {
   final Map<String, String> parsed = RequestHelper.parsePrefixedParamsMap(request, nameprefix);
   for (Map.Entry<String, String> entry : parsed.entrySet()) {
     lc.setName(entry.getKey(), entry.getValue());
   }
 }
コード例 #2
0
  @Override
  public void handleAction(ActionParameters params) throws ActionException {

    final HttpServletRequest request = params.getRequest();
    try {
      final int groupId = params.getHttpParam(PARAM_ID, -1);
      final LayerGroup group = new LayerGroup();
      group.setId(groupId);
      handleLocalizations(group, PARAM_NAME_PREFIX, request);
      if (group.getLocale() == null) {
        throw new ActionParamsException("Missing names for group!");
      }

      // ************** UPDATE ************************
      if (groupId != -1) {
        if (!layerGroupService.hasPermissionToUpdate(params.getUser(), groupId)) {
          throw new ActionDeniedException(
              "Unauthorized user tried to update layer group - id=" + groupId);
        }
        layerGroupService.update(group);
        ResponseHelper.writeResponse(params, group.getAsJSON());
      }
      // ************** INSERT ************************
      else if (params.getUser().isAdmin()) {
        final int id = layerGroupService.insert(group);
        group.setId(id);
        ResponseHelper.writeResponse(params, group.getAsJSON());
      } else {
        throw new ActionDeniedException(
            "Unauthorized user tried to update layer group - id=" + groupId);
      }

    } catch (Exception e) {
      throw new ActionException("Couldn't update/insert map layer group", e);
    }
  }