Exemplo n.º 1
0
  /*
   * (non-Javadoc)
   * @see jp.go.nict.langrid.p2pgridbasis.dao#updateData(jp.go.nict.langrid.p2pgridbasis.data.Data)
   */
  public synchronized boolean updateDataTarget(Data data)
      throws UnmatchedDataTypeException, DataDaoException {
    logger.debug("[user] :" + data.getId());
    if (data.getClass().equals(UserData.class) == false) {
      throw new UnmatchedDataTypeException(UserData.class.toString(), data.getClass().toString());
    }

    if (data.getAttributes().getKeys().contains("IsDeleted")
        && data.getAttributes().getValue("IsDeleted").equals("true")) {
      logger.debug("Delete");
      boolean updated = false;
      try {
        UserData userData = (UserData) data;
        User user = userData.getUser();
        removeEntityListener();
        dao.deleteUser(user.getGridId(), user.getUserId());
        updated = true;
        setEntityListener();
        getController().baseSummaryAdd(data);
      } catch (ParseException e) {
        throw new DataDaoException(e);
      } catch (UserNotFoundException e) {
        //
        //
        try {
          getController().baseSummaryAdd(data);
        } catch (ControllerException e1) {
          e1.printStackTrace();
        }
      } catch (DaoException e) {
        throw new DataDaoException(e);
      } catch (ControllerException e) {
        throw new DataDaoException(e);
      }
      return updated;
    }

    User user = null;
    try {
      UserData userData = (UserData) data;
      user = userData.getUser();
      removeEntityListener();
      if (dao.isUserExist(user.getGridId(), user.getUserId())) {
        logger.debug("UpDate");
        daoContext.updateEntity(user);
      } else {
        logger.debug("New");
        dao.addUser(user);
      }
      setEntityListener();
      getController().baseSummaryAdd(data);
      return true;
    } catch (ParseException e) {
      throw new DataDaoException(e);
    } catch (DaoException e) {
      throw new DataDaoException(e);
    } catch (ControllerException e) {
      throw new DataDaoException(e);
    }
  }
  /*
   * (non-Javadoc)
   * @see jp.go.nict.langrid.p2pgridbasis.dao#updateData(jp.go.nict.langrid.p2pgridbasis.data.Data)
   */
  public synchronized boolean updateDataTarget(Data data)
      throws DataDaoException, UnmatchedDataTypeException {
    logger.debug("[AccessLimit] : " + data.getId());
    if (data.getClass().equals(AccessLimitData.class) == false) {
      throw new UnmatchedDataTypeException(
          AccessLimitData.class.toString(), data.getClass().toString());
    }

    boolean updated = false;
    if (data.getAttributes().getKeys().contains("IsDeleted")
        && data.getAttributes().getValue("IsDeleted").equals("true")) {
      try {
        logger.debug("Delete");
        AccessLimitData accessLimitData = (AccessLimitData) data;
        AccessLimit limit = accessLimitData.getAccessLimit();
        removeEntityListener();
        dao.deleteAccessLimit(
            limit.getUserGridId(),
            limit.getUserId(),
            limit.getServiceGridId(),
            limit.getServiceId(),
            limit.getPeriod(),
            limit.getLimitType());
        updated = true;
        setEntityListener();
        getController().baseSummaryAdd(data);
      } catch (DataConvertException e) {
        throw new DataDaoException(e);
      } catch (ServiceNotFoundException e) {
        //
        //
        try {
          getController().baseSummaryAdd(data);
        } catch (ControllerException e1) {
          e1.printStackTrace();
        }
      } catch (DaoException e) {
        throw new DataDaoException(e);
      } catch (ParseException e) {
        throw new DataDaoException(e);
      } catch (ControllerException e) {
        throw new DataDaoException(e);
      }
      return updated;
    }

    AccessLimit limit = null;
    try {
      AccessLimitData accessLimitData = (AccessLimitData) data;
      limit = accessLimitData.getAccessLimit();
      logger.debug("New or UpDate");
      removeEntityListener();
      daoContext.beginTransaction();
      daoContext.mergeEntity(limit);
      daoContext.commitTransaction();
      setEntityListener();
      getController().baseSummaryAdd(data);
      updated = true;
    } catch (ParseException e) {
      throw new DataDaoException(e);
    } catch (DaoException e) {
      throw new DataDaoException(e);
    } catch (DataConvertException e) {
      throw new DataDaoException(e);
    } catch (ControllerException e) {
      throw new DataDaoException(e);
    }
    return updated;
  }