/**
   * Creates a new user account in bibsonomy.
   *
   * @param user the user to be created
   * @throws IllegalArgumentException if the user is null or the user has neither username nor
   *     password specified.
   */
  public CreateUserQuery(final User user) throws IllegalArgumentException {
    if (!present(user)) throw new IllegalArgumentException("no user specified");
    if (!present(user.getName())) throw new IllegalArgumentException("no username specified");
    if (!present(user.getPassword())) throw new IllegalArgumentException("no password specified");

    this.user = user;
  }
  @Override
  public View workOn(AjaxSynchronizationCommand command) {

    final RequestWrapperContext context = command.getContext();

    /*
     * some security checks
     */
    if (!context.isUserLoggedIn()) {
      throw new org.springframework.security.access.AccessDeniedException("please log in");
    }
    final User loginUser = context.getLoginUser();
    if (loginUser.isSpammer()) {
      throw new AccessDeniedException("error.method_not_allowed");
    }
    if (!context.isValidCkey()) {
      this.errors.reject("error.field.valid.ckey");
    }

    if (!command.getContext().getUserLoggedIn()) {
      throw new AccessDeniedException();
    }

    if (!present(syncClient)) {
      errors.reject("error.synchronization.noclient");
      return Views.ERROR;
    }

    log.debug("try to get sync services for user");
    final List<SyncService> userServices =
        syncLogic.getSyncServer(command.getContext().getLoginUser().getName());

    log.debug("try to get synchronization data from remote service");
    for (final SyncService syncService : userServices) {
      final Map<String, SynchronizationData> lastSyncData =
          new HashMap<String, SynchronizationData>();
      try {
        for (final Class<? extends Resource> resourceType :
            ResourceUtils.getResourceTypesByClass(syncService.getResourceType())) {
          lastSyncData.put(
              resourceType.getSimpleName(), getLastSyncData(syncService, resourceType));
        }
      } catch (AccessDeniedException e) {
        log.debug("access denied to remote service " + syncService.getService().toString());
      }
      syncService.setLastSyncData(lastSyncData);
    }

    command.setSyncServer(userServices);

    return Views.SYNC;
  }
  @Override
  public View workOn(AjaxRecommenderCommand<R> command) {
    final RequestWrapperContext context = command.getContext();

    /*
     * only users which are logged in might post bookmarks -> send them to
     * login page
     */
    if (!context.isUserLoggedIn()) {
      command.setResponseString("");
      return Views.AJAX_XML;
    }

    final User loginUser = context.getLoginUser();

    // ------------------------------------------------------------------------
    // THIS IS AN ISSUE WE STILL HAVE TO DISCUSS:
    // During the ECML/PKDD recommender challenge, many recommender systems
    // couldn't deal with the high load, so we filter out those users, which
    // are flagged as spammer either by an admin, or by the framework for sure
    // TODO: we could probably also filter out those users, which are
    //       flagged as 'spammer unsure'
    // ------------------------------------------------------------------------
    final User dbUser = adminLogic.getUserDetails(loginUser.getName());

    /*
     * set the user of the post to the loginUser (the recommender might need
     * the user name)
     */
    command.getPost().setUser(loginUser);

    /*
     * initialize groups
     */
    GroupingCommandUtils.initGroups(command, command.getPost().getGroups());

    // set postID for recommender
    command.getPost().setContentId(command.getPostID());

    if ((dbUser.isSpammer())
        && ((dbUser.getPrediction() == null && dbUser.getAlgorithm() == null)
            || (dbUser.getPrediction().equals(1)
                || dbUser.getAlgorithm().equals(USERSPAMALGORITHM)))) {
      // the user is a spammer
      log.debug("Filtering out recommendation request from spammer");
      if (this.getSpamTagRecommender() != null) {
        SortedSet<RecommendedTag> result =
            this.getSpamTagRecommender().getRecommendedTags(command.getPost());
        this.processRecommendedTags(command, result);
      } else {
        command.setResponseString("");
      }
    } else {
      // the user doesn't seem to be a spammer
      /*
       * get the recommended tags for the post from the command
       */
      if (this.getTagRecommender() != null) {
        SortedSet<RecommendedTag> result =
            this.getTagRecommender().getRecommendedTags(command.getPost(), command.getPostID());
        this.processRecommendedTags(command, result);
      } else {
        command.setResponseString("");
      }
    }

    return Views.AJAX_XML;
  }