Пример #1
0
  /** {@inheritDoc} */
  @Override
  public Feature mapRow(ResultSet rs, int rowNum) throws SQLException {
    String featUid = rs.getString(COL_FEAT_UID);
    Feature f = new Feature(featUid, rs.getInt(COL_FEAT_ENABLE) > 0);
    f.setDescription(rs.getString(COL_FEAT_DESCRIPTION));
    f.setGroup(rs.getString(COL_FEAT_GROUPNAME));

    // Build Flipping Strategy From DataBase
    String strategy = rs.getString(COL_FEAT_STRATEGY);
    if (strategy != null && !"".equals(strategy)) {
      try {
        FlippingStrategy flipStrategy = (FlippingStrategy) Class.forName(strategy).newInstance();
        flipStrategy.init(featUid, ParameterUtils.toMap(rs.getString(COL_FEAT_EXPRESSION)));
        f.setFlippingStrategy(flipStrategy);
      } catch (InstantiationException ie) {
        throw new FeatureAccessException(
            "Cannot instantiate Strategy, no default constructor available", ie);
      } catch (IllegalAccessException iae) {
        throw new FeatureAccessException(
            "Cannot instantiate Strategy, no visible constructor", iae);
      } catch (ClassNotFoundException e) {
        throw new FeatureAccessException("Cannot instantiate Strategy, classNotFound", e);
      }
    }
    return f;
  }
Пример #2
0
  /**
   * User action to update a target feature's description.
   *
   * @param req http request containing operation parameters
   */
  @SuppressWarnings("unchecked")
  private void opUpdateFeatureDescription(FeatureStore store, HttpServletRequest req) {
    // uid
    final String featureId = req.getParameter(FEATID);
    if (featureId != null && !featureId.isEmpty()) {
      Feature fp = new Feature(featureId, false);

      // Description
      final String featureDesc = req.getParameter(DESCRIPTION);
      if (null != featureDesc && !featureDesc.isEmpty()) {
        fp.setDescription(featureDesc);
      }

      // GroupName
      final String groupName = req.getParameter(GROUPNAME);
      if (null != groupName && !groupName.isEmpty()) {
        fp.setGroup(groupName);
      }

      // Strategy
      final String strategy = req.getParameter(STRATEGY);
      if (null != strategy && !strategy.isEmpty()) {
        try {
          Class<?> strategyClass = Class.forName(strategy);
          FlippingStrategy fstrategy = (FlippingStrategy) strategyClass.newInstance();

          final String strategyParams = req.getParameter(STRATEGY_INIT);
          if (null != strategyParams && !strategyParams.isEmpty()) {
            Map<String, String> initParams = new HashMap<String, String>();
            String[] params = strategyParams.split(";");
            for (String currentP : params) {
              String[] cur = currentP.split("=");
              if (cur.length < 2) {
                throw new IllegalArgumentException(
                    "Invalid Syntax : param1=val1,val2;param2=val3,val4");
              }
              initParams.put(cur[0], cur[1]);
            }
            fstrategy.init(featureId, initParams);
          }
          fp.setFlippingStrategy(fstrategy);

        } catch (ClassNotFoundException e) {
          throw new IllegalArgumentException("Cannot find strategy class", e);
        } catch (InstantiationException e) {
          throw new IllegalArgumentException("Cannot instanciate strategy", e);
        } catch (IllegalAccessException e) {
          throw new IllegalArgumentException("Cannot instanciate : no public constructor", e);
        }
      }

      populateFeatureWithPermissions(fp, req);

      // Creation
      store.update(fp);
      log.info(featureId + " has been updated");
    }
  }