@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);
    }
  }