Esempio n. 1
0
 private void setUser(
     AccessRight defaultRight,
     String userGridId,
     String userId,
     String serviceGridId,
     String serviceId,
     boolean permitted)
     throws DaoException {
   AccessRightDao arDao = getAccessRightDao();
   if (defaultRight.isPermitted() != permitted) {
     arDao.setAccessRight(userGridId, userId, serviceGridId, serviceId, permitted);
   } else {
     arDao.deleteAccessRight(userGridId, userId, serviceGridId, serviceId);
   }
   AccessLimitDao alDao = getAccessLimitDao();
   alDao.deleteAccessLimits(userGridId, userId, serviceGridId, serviceId);
   if (permitted) {
     for (AccessLimit l :
         alDao.getServiceDefaultAccessLimits(userGridId, serviceGridId, serviceId)) {
       alDao.setAccessLimit(
           userGridId,
           userId,
           serviceGridId,
           serviceId,
           l.getPeriod(),
           l.getLimitType(),
           l.getLimitCount());
     }
   }
 }
  /*
   * (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;
  }