示例#1
0
 @Override
 public Answer updateSystemsByUser(User user, List<UserSystem> newGroups) {
   Answer a = new Answer(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
   AnswerList an = this.readByUser(user.getLogin());
   if (an.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
     List<UserSystem> oldGroups = an.getDataList();
     // delete if don't exist in new
     for (UserSystem old : oldGroups) {
       if (!newGroups.contains(old)) {
         Answer del = userSystemDAO.remove(old);
         if (!del.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
           a = del;
         }
       }
     }
     // insert if don't exist in old
     for (UserSystem group : newGroups) {
       if (!oldGroups.contains(group)) {
         Answer add = userSystemDAO.create(group);
         if (!add.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
           a = add;
         }
       }
     }
   }
   return a;
 }
示例#2
0
  @Override
  public void updateUserSystems(User user, List<UserSystem> newSystems) throws CerberusException {
    List<UserSystem> oldSystems = this.findUserSystemByUser(user.getLogin());

    // delete if don't exist in new
    for (UserSystem old : oldSystems) {
      if (!newSystems.contains(old)) {
        this.deleteUserSystem(old);
      }
    }
    // insert if don't exist in old
    for (UserSystem newS : newSystems) {
      if (!oldSystems.contains(newS)) {
        this.insertUserSystem(newS);
      }
    }
  }