/**
   * @param rundata
   * @param context
   * @return
   */
  private SelectQuery<TurbineUser> getSelectQuery(RunData rundata, Context context) {
    SelectQuery<TurbineUser> query = null;
    String word = searchWord.getValue();
    String transWord =
        ALStringUtil.convertHiragana2Katakana(ALStringUtil.convertH2ZKana(searchWord.getValue()));

    query = Database.query(TurbineUser.class);

    Expression exp_exclude_my_group =
        ExpressionFactory.matchExp(
            TurbineUser.TURBINE_USER_GROUP_ROLE_PROPERTY
                + "."
                + TurbineUserGroupRole.TURBINE_GROUP_PROPERTY
                + "."
                + TurbineGroup.OWNER_ID_PROPERTY,
            1);

    Expression exp01 = ExpressionFactory.matchExp(TurbineUser.DISABLED_PROPERTY, "F");
    query.setQualifier(exp01);

    Expression exp02 =
        ExpressionFactory.noMatchDbExp(TurbineUser.USER_ID_PK_COLUMN, Integer.valueOf(1));
    Expression exp03 =
        ExpressionFactory.noMatchDbExp(TurbineUser.USER_ID_PK_COLUMN, Integer.valueOf(2));
    Expression exp04 =
        ExpressionFactory.noMatchDbExp(TurbineUser.USER_ID_PK_COLUMN, Integer.valueOf(3));
    query.andQualifier(exp02.andExp(exp03).andExp(exp04));

    Expression exp11 = ExpressionFactory.likeExp(TurbineUser.FIRST_NAME_PROPERTY, "%" + word + "%");
    Expression exp12 = ExpressionFactory.likeExp(TurbineUser.LAST_NAME_PROPERTY, "%" + word + "%");
    Expression exp13 =
        ExpressionFactory.likeExp(TurbineUser.FIRST_NAME_KANA_PROPERTY, "%" + word + "%");
    Expression exp14 =
        ExpressionFactory.likeExp(TurbineUser.LAST_NAME_KANA_PROPERTY, "%" + word + "%");
    Expression exp15 = ExpressionFactory.likeExp(TurbineUser.EMAIL_PROPERTY, "%" + word + "%");
    Expression exp16 =
        ExpressionFactory.likeExp(
            TurbineUser.TURBINE_USER_GROUP_ROLE_PROPERTY
                + "."
                + TurbineUserGroupRole.TURBINE_GROUP_PROPERTY
                + "."
                + TurbineGroup.GROUP_ALIAS_NAME_PROPERTY,
            "%" + word + "%");
    exp16 = exp16.andExp(exp_exclude_my_group);
    Expression exp21 =
        ExpressionFactory.likeExp(TurbineUser.OUT_TELEPHONE_PROPERTY, "%" + word + "%");
    Expression exp22 =
        ExpressionFactory.likeExp(TurbineUser.IN_TELEPHONE_PROPERTY, "%" + word + "%");
    Expression exp23 =
        ExpressionFactory.likeExp(TurbineUser.CELLULAR_PHONE_PROPERTY, "%" + word + "%");

    Expression exp31 =
        ExpressionFactory.likeExp(TurbineUser.FIRST_NAME_PROPERTY, "%" + transWord + "%");
    Expression exp32 =
        ExpressionFactory.likeExp(TurbineUser.LAST_NAME_PROPERTY, "%" + transWord + "%");
    Expression exp33 =
        ExpressionFactory.likeExp(TurbineUser.FIRST_NAME_KANA_PROPERTY, "%" + transWord + "%");
    Expression exp34 =
        ExpressionFactory.likeExp(TurbineUser.LAST_NAME_KANA_PROPERTY, "%" + transWord + "%");
    Expression exp35 =
        ExpressionFactory.likeExp(
            TurbineUser.TURBINE_USER_GROUP_ROLE_PROPERTY
                + "."
                + TurbineUserGroupRole.TURBINE_GROUP_PROPERTY
                + "."
                + TurbineGroup.GROUP_ALIAS_NAME_PROPERTY,
            "%" + transWord + "%");
    exp35 = exp35.andExp(exp_exclude_my_group);
    Expression exp36 = ExpressionFactory.likeExp(TurbineUser.CODE_PROPERTY, "%" + transWord + "%");
    if (word != null && !"".equals(word)) {
      query.andQualifier(
          exp11
              .orExp(exp12)
              .orExp(exp13)
              .orExp(exp14)
              .orExp(exp15)
              .orExp(exp16)
              .orExp(exp21)
              .orExp(exp22)
              .orExp(exp23)
              .orExp(exp31)
              .orExp(exp32)
              .orExp(exp33)
              .orExp(exp34)
              .orExp(exp35)
              .orExp(exp36));
    }
    query.distinct();
    return query;
  }
Beispiel #2
0
  /**
   * セッションで指定されたアドレスIDを持つアドレス情報を取得する。
   *
   * @param rundata
   * @param context
   * @return
   */
  public static EipMAddressbook getEipMAddressbook(RunData rundata, Context context) {
    // セッションから指定された アドレスID を取得
    String addressid = ALEipUtils.getTemp(rundata, context, ALEipConstants.ENTITY_ID);
    try {
      if (addressid == null || Integer.valueOf(addressid) == null) {
        logger.debug("[AddressBook] Address ID...");
        return null;
      }

      SelectQuery<EipMAddressbook> query = Database.query(EipMAddressbook.class);
      Expression exp11 =
          ExpressionFactory.matchDbExp(
              EipMAddressbook.ADDRESS_ID_PK_COLUMN, Integer.valueOf(addressid));
      query.setQualifier(exp11);

      Expression exp21 = ExpressionFactory.matchExp(EipMAddressbook.PUBLIC_FLAG_PROPERTY, "T");
      Expression exp22 =
          ExpressionFactory.matchExp(
              EipMAddressbook.OWNER_ID_PROPERTY, ALEipUtils.getUserId(rundata));
      Expression exp23 = ExpressionFactory.matchExp(EipMAddressbook.PUBLIC_FLAG_PROPERTY, "F");
      query.andQualifier(exp21.orExp(exp22.andExp(exp23)));

      List<EipMAddressbook> addresses = query.fetchList();

      if (addresses == null || addresses.size() == 0) {
        logger.debug("[AddressBook] Not found Address ID...");
        return null;
      }
      return addresses.get(0);
    } catch (Exception ex) {
      logger.error("AddressBookUtils.getEipMAddressbook", ex);
      return null;
    }
  }
  @Test
  public void testEvaluate_Null() {
    Expression gtNull = new ASTGreaterOrEqual(new ASTObjPath("estimatedPrice"), null);
    Expression gtNotNull =
        new ASTGreaterOrEqual(new ASTObjPath("estimatedPrice"), new BigDecimal(10000d));

    Painting noMatch = new Painting();
    assertFalse(gtNull.match(noMatch));
    assertFalse(gtNotNull.match(noMatch));
  }
Beispiel #4
0
 public static Expression getIncompleteExpression() {
   Expression exp = null;
   for (String status : incompleteStatus) {
     Expression tmp = ExpressionFactory.matchExp(EipTProjectTask.STATUS_PROPERTY, status);
     if (null == exp) {
       exp = tmp;
     } else {
       exp = exp.orExp(tmp);
     }
   }
   return exp;
 }
  @Test
  public void testEvaluate() {
    Expression e = new ASTGreaterOrEqual(new ASTObjPath("estimatedPrice"), new BigDecimal(10000d));

    Painting noMatch = new Painting();
    noMatch.setEstimatedPrice(new BigDecimal(9999));
    assertFalse(e.match(noMatch));

    Painting match1 = new Painting();
    match1.setEstimatedPrice(new BigDecimal(10000));
    assertTrue(e.match(match1));

    Painting match = new Painting();
    match.setEstimatedPrice(new BigDecimal(10001));
    assertTrue("Failed: " + e, e.match(match));
  }
Beispiel #6
0
  /**
   * Transforms an Expression rooted in this entity to an analogous expression rooted in related
   * entity.
   *
   * @since 1.1
   */
  @Override
  public Expression translateToRelatedEntity(Expression expression, String relationshipPath) {

    if (expression == null) {
      return null;
    }

    if (relationshipPath == null) {
      return expression;
    }

    if (getDbEntity() == null) {
      throw new CayenneRuntimeException(
          "Can't transform expression, no DbEntity for '" + getName() + "'.");
    }

    // converts all OBJ_PATH expressions to DB_PATH expressions
    // and pass control to the DB entity

    DBPathConverter transformer = new DBPathConverter();

    String dbPath = transformer.toDbPath(createPathIterator(relationshipPath));
    Expression dbClone = expression.transform(transformer);

    return getDbEntity().translateToRelatedEntity(dbClone, dbPath);
  }
Beispiel #7
0
    public Object transform(Object input) {

      if (!(input instanceof Expression)) {
        return input;
      }

      Expression expression = (Expression) input;

      if (expression.getType() != Expression.OBJ_PATH) {
        return input;
      }

      // convert obj_path to db_path

      String converted = toDbPath(createPathIterator((String) expression.getOperand(0)));
      Expression exp = ExpressionFactory.expressionOfType(Expression.DB_PATH);
      exp.setOperand(0, converted);
      return exp;
    }
Beispiel #8
0
  /**
   * Returns an Iterable instance over expression path components based on this entity.
   *
   * @since 3.0
   */
  @Override
  @SuppressWarnings("unchecked")
  public Iterable<PathComponent<ObjAttribute, ObjRelationship>> resolvePath(
      final Expression pathExp, final Map aliasMap) {

    if (pathExp.getType() == Expression.OBJ_PATH) {

      return new Iterable<PathComponent<ObjAttribute, ObjRelationship>>() {

        public Iterator iterator() {
          return new PathComponentIterator(
              ObjEntity.this, (String) pathExp.getOperand(0), aliasMap);
        }
      };
    }

    throw new ExpressionException(
        "Invalid expression type: '" + pathExp.expName() + "',  OBJ_PATH is expected.");
  }
  /**
   * Returns the deepest possible entity in the inheritance hierarchy that can be used to create
   * objects from a given DataRow.
   */
  public ObjEntity entityMatchingRow(DataRow row) {
    // match depth first
    if (subentities != null) {
      for (EntityInheritanceTree child : subentities) {
        ObjEntity matched = child.entityMatchingRow(row);

        if (matched != null) {
          return matched;
        }
      }
    }

    Expression qualifier = getDbQualifier();
    if (qualifier != null) {
      return qualifier.match(row) ? entity : null;
    }

    // no qualifier ... matches all rows
    return entity;
  }
Beispiel #10
0
  @Override
  public Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp)
      throws ExpressionException {

    // resolve DB_PATH if we can
    if (pathExp.getType() == Expression.DB_PATH) {
      if (getDbEntity() == null) {
        throw new ExpressionException(
            "Can't resolve DB_PATH '" + pathExp + "', DbEntity is not set.");
      }

      return getDbEntity().resolvePathComponents(pathExp);
    }

    if (pathExp.getType() == Expression.OBJ_PATH) {
      return new PathIterator((String) pathExp.getOperand(0));
    }

    throw new ExpressionException(
        "Invalid expression type: '" + pathExp.expName() + "',  OBJ_PATH is expected.");
  }
  public void testPrefetchToMany_WithQualfier() throws Exception {
    createTwoArtistsAndTwoPaintingsDataSet();

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("name1", "artist2");
    params.put("name2", "artist3");
    Expression e = Expression.fromString("artistName = $name1 or artistName = $name2");
    SelectQuery q = new SelectQuery("Artist", e.expWithParameters(params));
    q.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY);

    final List<Artist> artists = context.performQuery(q);

    queryInterceptor.runWithQueriesBlocked(
        new UnitTestClosure() {

          public void execute() {

            assertEquals(2, artists.size());

            Artist a1 = artists.get(0);
            List<?> toMany = (List<?>) a1.readPropertyDirectly(Artist.PAINTING_ARRAY_PROPERTY);
            assertNotNull(toMany);
            assertFalse(((ValueHolder) toMany).isFault());
            assertEquals(1, toMany.size());

            Painting p1 = (Painting) toMany.get(0);
            assertEquals("p_" + a1.getArtistName(), p1.getPaintingTitle());

            Artist a2 = artists.get(1);
            List<?> toMany2 = (List<?>) a2.readPropertyDirectly(Artist.PAINTING_ARRAY_PROPERTY);
            assertNotNull(toMany2);
            assertFalse(((ValueHolder) toMany2).isFault());
            assertEquals(1, toMany2.size());

            Painting p2 = (Painting) toMany2.get(0);
            assertEquals("p_" + a2.getArtistName(), p2.getPaintingTitle());
          }
        });
  }
  /**
   * Advanced checking of an expression, needed because Expression.fromString() might terminate
   * normally, but returned Expression will not be appliable for real Entities. Current
   * implementation assures all attributes in expression are present in Entity
   *
   * @param root Root of a query
   * @param ex Expression to check
   * @throws ValidationException when something's wrong
   */
  static void checkExpression(Entity root, Expression ex) throws ValidationException {
    try {
      if (ex instanceof ASTPath) {
        /**
         * Try to iterate through path, if some attributes are not present, exception will be raised
         */
        Iterator<CayenneMapEntry> path = root.resolvePathComponents(ex);
        while (path.hasNext()) {
          path.next();
        }
      }

      if (ex != null) {
        for (int i = 0; i < ex.getOperandCount(); i++) {
          if (ex.getOperand(i) instanceof Expression) {
            checkExpression(root, (Expression) ex.getOperand(i));
          }
        }
      }
    } catch (ExpressionException eex) {
      throw new ValidationException(eex.getUnlabeledMessage());
    }
  }
Beispiel #13
0
  /**
   * Transforms an Expression to an analogous expression in terms of the underlying DbEntity.
   *
   * @since 1.1
   */
  public Expression translateToDbPath(Expression expression) {

    if (expression == null) {
      return null;
    }

    if (getDbEntity() == null) {
      throw new CayenneRuntimeException(
          "Can't translate expression to DB_PATH, no DbEntity for '" + getName() + "'.");
    }

    // converts all OBJ_PATH expressions to DB_PATH expressions
    // and pass control to the DB entity
    return expression.transform(new DBPathConverter());
  }
  private SelectQuery<EipTTodo> getSelectQueryForTodo(RunData rundata, Context context) {
    Integer uid = Integer.valueOf(userid);

    SelectQuery<EipTTodo> query = Database.query(EipTTodo.class);
    Expression exp1 =
        ExpressionFactory.noMatchExp(EipTTodo.STATE_PROPERTY, Short.valueOf((short) 100));
    query.setQualifier(exp1);

    Expression exp01 = ExpressionFactory.matchDbExp(TurbineUser.USER_ID_PK_COLUMN, uid);
    Expression exp02 = ExpressionFactory.noMatchDbExp(TurbineUser.USER_ID_PK_COLUMN, uid);
    Expression exp03 = ExpressionFactory.matchExp(EipTTodo.PUBLIC_FLAG_PROPERTY, "T");
    Expression exp04 = ExpressionFactory.matchExp(EipTTodo.ADDON_SCHEDULE_FLG_PROPERTY, "T");
    query.andQualifier(exp01.orExp(exp02.andExp(exp03)).andExp(exp04));

    // 終了日時
    Expression exp11 =
        ExpressionFactory.greaterOrEqualExp(EipTTodo.END_DATE_PROPERTY, getViewDate().getValue());
    // 開始日時
    Expression exp12 =
        ExpressionFactory.lessOrEqualExp(EipTTodo.START_DATE_PROPERTY, getViewDate().getValue());

    // 開始日時のみ指定されている ToDo を検索
    Expression exp21 =
        ExpressionFactory.lessOrEqualExp(EipTTodo.START_DATE_PROPERTY, getViewDate().getValue());
    Expression exp22 =
        ExpressionFactory.matchExp(EipTTodo.END_DATE_PROPERTY, ToDoUtils.getEmptyDate());

    // 終了日時のみ指定されている ToDo を検索
    Expression exp31 =
        ExpressionFactory.greaterOrEqualExp(EipTTodo.END_DATE_PROPERTY, getViewDate().getValue());
    Expression exp32 =
        ExpressionFactory.matchExp(EipTTodo.START_DATE_PROPERTY, ToDoUtils.getEmptyDate());

    query.andQualifier((exp11.andExp(exp12)).orExp(exp21.andExp(exp22)).orExp(exp31.andExp(exp32)));
    return query;
  }
  /**
   * Returns a qualifier Expression that matches root entity of this tree and all its subentities.
   */
  public Expression qualifierForEntityAndSubclasses() {
    Expression qualifier = entity.getDeclaredQualifier();

    if (qualifier == null) {
      // match all
      return null;
    }

    if (subentities != null) {
      for (EntityInheritanceTree child : subentities) {
        Expression childQualifier = child.qualifierForEntityAndSubclasses();

        // if any child qualifier is null, just return null, since no filtering is
        // possible
        if (childQualifier == null) {
          return null;
        }

        qualifier = qualifier.orExp(childQualifier);
      }
    }

    return qualifier;
  }
  /**
   * 検索条件を設定した SelectQuery を返します。 <br>
   *
   * @param rundata
   * @param context
   * @return
   */
  protected SelectQuery<TurbineUser> getSelectQuery(RunData rundata, Context context) {

    ObjectId oid = new ObjectId("TurbineUser", TurbineUser.USER_ID_PK_COLUMN, 3);

    Expression exp_base =
        ExpressionFactory.matchAllDbExp(oid.getIdSnapshot(), Expression.GREATER_THAN);

    SelectQuery<TurbineUser> query =
        Database.query(TurbineUser.class, exp_base)
            .where(
                Operations.eq(TurbineUser.COMPANY_ID_PROPERTY, Integer.valueOf(1)),
                Operations.ne(TurbineUser.DISABLED_PROPERTY, "T"));

    String filter = ALEipUtils.getTemp(rundata, context, LIST_FILTER_STR);
    String filter_role = ALEipUtils.getTemp(rundata, context, LIST_FILTER_ROLE_STR);
    currentPost = filter;
    currentRole = filter_role;

    if (target_keyword != null && !target_keyword.getValue().equals("")) {
      String transWord =
          ALStringUtil.convertHiragana2Katakana(
              ALStringUtil.convertH2ZKana(target_keyword.getValue()));
      transWord = transWord.replace(" ", "").replace(" ", ""); // 全角/半角スペースを削除
      String[] transWords = transWord.split(""); // 1文字ずつに分解

      for (int i = 0; i < transWords.length; i++) {
        Expression exp11 =
            ExpressionFactory.likeExp(
                TurbineUser.FIRST_NAME_PROPERTY, "%" + target_keyword.getValue() + "%");
        Expression exp12 =
            ExpressionFactory.likeExp(
                TurbineUser.LAST_NAME_PROPERTY, "%" + target_keyword.getValue() + "%");
        Expression exp13 =
            ExpressionFactory.likeExp(
                TurbineUser.FIRST_NAME_KANA_PROPERTY, "%" + target_keyword.getValue() + "%");
        Expression exp14 =
            ExpressionFactory.likeExp(
                TurbineUser.LAST_NAME_KANA_PROPERTY, "%" + target_keyword.getValue() + "%");
        Expression exp15 =
            ExpressionFactory.likeExp(
                TurbineUser.EMAIL_PROPERTY, "%" + target_keyword.getValue() + "%");
        Expression exp16 =
            ExpressionFactory.likeExp(
                TurbineUser.TURBINE_USER_GROUP_ROLE_PROPERTY
                    + "."
                    + TurbineUserGroupRole.TURBINE_GROUP_PROPERTY
                    + "."
                    + TurbineGroup.GROUP_ALIAS_NAME_PROPERTY,
                "%" + target_keyword.getValue() + "%");
        Expression exp17 =
            ExpressionFactory.likeExp(
                TurbineUser.LOGIN_NAME_PROPERTY, "%" + target_keyword.getValue() + "%");
        Expression exp21 =
            ExpressionFactory.likeExp(
                TurbineUser.OUT_TELEPHONE_PROPERTY, "%" + target_keyword.getValue() + "%");
        Expression exp22 =
            ExpressionFactory.likeExp(
                TurbineUser.IN_TELEPHONE_PROPERTY, "%" + target_keyword.getValue() + "%");
        Expression exp23 =
            ExpressionFactory.likeExp(
                TurbineUser.CELLULAR_PHONE_PROPERTY, "%" + target_keyword.getValue() + "%");
        Expression exp31 =
            ExpressionFactory.likeExp(TurbineUser.FIRST_NAME_PROPERTY, "%" + transWords[i] + "%");
        Expression exp32 =
            ExpressionFactory.likeExp(TurbineUser.LAST_NAME_PROPERTY, "%" + transWords[i] + "%");
        Expression exp33 =
            ExpressionFactory.likeExp(
                TurbineUser.FIRST_NAME_KANA_PROPERTY, "%" + transWords[i] + "%");
        Expression exp34 =
            ExpressionFactory.likeExp(
                TurbineUser.LAST_NAME_KANA_PROPERTY, "%" + transWords[i] + "%");
        Expression exp35 =
            ExpressionFactory.likeExp(
                TurbineUser.TURBINE_USER_GROUP_ROLE_PROPERTY
                    + "."
                    + TurbineUserGroupRole.TURBINE_GROUP_PROPERTY
                    + "."
                    + TurbineGroup.GROUP_ALIAS_NAME_PROPERTY,
                "%" + transWords[i] + "%");

        query.andQualifier(
            exp11
                .orExp(exp12)
                .orExp(exp13)
                .orExp(exp14)
                .orExp(exp15)
                .orExp(exp16)
                .orExp(exp17)
                .orExp(exp21)
                .orExp(exp22)
                .orExp(exp23)
                .orExp(exp31)
                .orExp(exp32)
                .orExp(exp33)
                .orExp(exp34)
                .orExp(exp35));
      }
    }

    // ユーザーの状態によるフィルターが指定されている場合。
    if (filter_role != null && !filter_role.equals("")) {

      // 管理者かどうか
      if (filter_role.equals(AccountUtils.ROLE_ADMIN.toString())) {
        try {
          Group group = JetspeedSecurity.getGroup("LoginUser");
          Role adminrole = JetspeedSecurity.getRole("admin");
          List<TurbineUserGroupRole> admins =
              Database.query(TurbineUserGroupRole.class)
                  .where(
                      Operations.eq(TurbineUserGroupRole.TURBINE_ROLE_PROPERTY, adminrole.getId()),
                      Operations.eq(TurbineUserGroupRole.TURBINE_GROUP_PROPERTY, group.getId()),
                      Operations.ne(TurbineUserGroupRole.TURBINE_USER_PROPERTY, 1))
                  .distinct(true)
                  .fetchList();
          List<Integer> admin_ids = new ArrayList<Integer>();
          admin_ids.add(Integer.valueOf(1));
          for (TurbineUserGroupRole tugr : admins) {
            admin_ids.add(tugr.getTurbineUser().getUserId());
          }
          query.andQualifier(ExpressionFactory.inDbExp(TurbineUser.USER_ID_PK_COLUMN, admin_ids));

        } catch (Exception ex) {
          logger.error("AccountUserSelectData.getSelectQuery", ex);
        }
      }

      // 有効ユーザーかどうか
      if (filter_role.equals(AccountUtils.ROLE_ACTIVE.toString())) {
        query.andQualifier(ExpressionFactory.matchExp(TurbineUser.DISABLED_PROPERTY, "F"));
      }

      // 有効ユーザーかどうか
      if (filter_role.equals(AccountUtils.ROLE_IN_ACTIVE.toString())) {
        query.andQualifier(ExpressionFactory.matchExp(TurbineUser.DISABLED_PROPERTY, "N"));
      }
    }

    // 部署によるフィルターが指定されている場合。
    if (filter != null && !filter.equals("")) {

      String groupName =
          (ALEipManager.getInstance().getPostMap().get(Integer.valueOf(filter)))
              .getGroupName()
              .getValue();

      query.where(
          Operations.eq(
              TurbineUser.TURBINE_USER_GROUP_ROLE_PROPERTY
                  + "."
                  + TurbineUserGroupRole.TURBINE_GROUP_PROPERTY
                  + "."
                  + TurbineGroup.GROUP_NAME_PROPERTY,
              groupName));
    }

    query.distinct();

    return query;
  }
  protected void indexQualifiers(
      final PersistentDescriptor descriptor, EntityInheritanceTree inheritanceTree) {

    Expression qualifier;

    if (inheritanceTree != null) {
      qualifier = inheritanceTree.qualifierForEntityAndSubclasses();
    } else {
      qualifier = descriptor.getEntity().getDeclaredQualifier();
    }

    if (qualifier != null) {

      // using map instead of a Set to collect attributes, as
      // ObjEntity.getAttribute may return a decorator for attribute on
      // each call, resulting in dupes
      final Map<String, ObjAttribute> attributes = new HashMap<>();
      final DbEntity dbEntity = descriptor.getEntity().getDbEntity();

      qualifier.traverse(
          new TraversalHelper() {

            @Override
            public void startNode(Expression node, Expression parentNode) {
              if (node.getType() == Expression.DB_PATH) {
                String path = node.getOperand(0).toString();
                final DbAttribute attribute = dbEntity.getAttribute(path);
                if (attribute != null) {

                  ObjAttribute objectAttribute =
                      descriptor.getEntity().getAttributeForDbAttribute(attribute);

                  if (objectAttribute == null) {
                    objectAttribute =
                        new ObjAttribute(attribute.getName()) {

                          @Override
                          public DbAttribute getDbAttribute() {
                            return attribute;
                          }
                        };

                    // we semi-officially DO NOT support inheritance
                    // descriptors based on related entities, so
                    // here we
                    // assume that DbAttribute is rooted in the root
                    // DbEntity, and no relationship is involved.
                    objectAttribute.setDbAttributePath(attribute.getName());
                    objectAttribute.setType(TypesMapping.getJavaBySqlType(attribute.getType()));
                  }

                  attributes.put(objectAttribute.getName(), objectAttribute);
                }
              } else if (node.getType() == Expression.OBJ_PATH) {
                String path = node.getOperand(0).toString();
                ObjAttribute attribute = descriptor.getEntity().getAttribute(path);
                attributes.put(path, attribute);
              }
            }
          });

      descriptor.setDiscriminatorColumns(attributes.values());
      descriptor.setEntityQualifier(qualifier);
    }
  }
Beispiel #18
0
  /**
   * フォームに入力されたデータの妥当性検証を行います。 <br>
   *
   * @param msgList
   * @return TRUE 成功 FALSE 失敗
   */
  @Override
  protected boolean validate(List<String> msgList) {
    String tmp_acl_role_name = acl_role_name.getValue();
    if (tmp_acl_role_name != null && !"".equals(tmp_acl_role_name)) {
      // ロール名の重複をチェックする
      try {
        SelectQuery<EipTAclRole> query = Database.query(EipTAclRole.class);
        if (ALEipConstants.MODE_INSERT.equals(getMode())) {
          Expression exp =
              ExpressionFactory.matchExp(EipTAclRole.ROLE_NAME_PROPERTY, tmp_acl_role_name);
          query.setQualifier(exp);
        } else if (ALEipConstants.MODE_UPDATE.equals(getMode())) {
          Expression exp1 =
              ExpressionFactory.matchExp(EipTAclRole.ROLE_NAME_PROPERTY, tmp_acl_role_name);
          query.setQualifier(exp1);
          Expression exp2 =
              ExpressionFactory.noMatchDbExp(
                  EipTAclRole.ROLE_ID_PK_COLUMN, Integer.valueOf(acl_role_id));
          query.andQualifier(exp2);
        }

        if (query.fetchList().size() != 0) {
          msgList.add(
              ALLocalizationUtils.getl10nFormat(
                  "ACCESSCTL_ALERT_ALREADY_CREATED", acl_role_name.toString()));
        }
      } catch (Exception ex) {
        logger.error("AccessControlFormData.validate", ex);
        return false;
      }
    }

    // ロール名
    acl_role_name.validate(msgList);
    // メモ
    note.validate(msgList);

    acllist.validate(msgList);
    acldetail.validate(msgList);
    aclinsert.validate(msgList);
    aclupdate.validate(msgList);
    acldelete.validate(msgList);
    aclexport.validate(msgList);

    // アクセス権限
    if (acllist.getValue() == 0
        && acldetail.getValue() == 0
        && aclinsert.getValue() == 0
        && aclupdate.getValue() == 0
        && acldelete.getValue() == 0
        && aclexport.getValue() == 0) {
      msgList.add(ALLocalizationUtils.getl10n("ACCESSCTL_ALERT_NO_FEATURE_SELECTED"));
    }

    // 所属メンバー
    if (memberList.size() == 0) {
      msgList.add(ALLocalizationUtils.getl10n("ACCESSCTL_ALERT_NO_MEMBER_SELECTED"));
    } else {
      try {
        // 同一機能の他ロールには所属できないようにする

        List<Integer> uids = new ArrayList<Integer>();
        int msize = memberList.size();
        for (int i = 0; i < msize; i++) {
          ALEipUser user = memberList.get(i);
          uids.add(Integer.valueOf((int) user.getUserId().getValue()));
        }

        SelectQuery<EipTAclRole> rolequery = Database.query(EipTAclRole.class);
        Expression exp11 =
            ExpressionFactory.matchDbExp(
                EipTAclRole.EIP_TACL_PORTLET_FEATURE_PROPERTY
                    + "."
                    + EipTAclPortletFeature.FEATURE_ID_PK_COLUMN,
                Integer.valueOf((int) feature_id.getValue()));
        Expression exp12 =
            ExpressionFactory.inDbExp(
                EipTAclRole.EIP_TACL_USER_ROLE_MAPS_PROPERTY
                    + "."
                    + EipTAclUserRoleMap.TURBINE_USER_PROPERTY
                    + "."
                    + TurbineUser.USER_ID_PK_COLUMN,
                uids);
        rolequery.setQualifier(exp11.andExp(exp12));

        if (ALEipConstants.MODE_UPDATE.equals(getMode())) {
          Expression exp13 =
              ExpressionFactory.noMatchDbExp(
                  EipTAclRole.ROLE_ID_PK_COLUMN, Integer.valueOf(acl_role_id));
          rolequery.andQualifier(exp13);
        }

        List<EipTAclRole> roleList = rolequery.fetchList();
        if (roleList != null && roleList.size() != 0) {
          msgList.add(ALLocalizationUtils.getl10n("ACCESSCTL_ALERT_OTHER_ROLE"));
        }
      } catch (Exception ex) {
        logger.error("AccessControlFormData.validate", ex);
        return false;
      }
    }

    return (msgList.size() == 0);
  }
Beispiel #19
0
  /**
   * Prints itself as XML to the provided XMLEncoder.
   *
   * @since 1.1
   */
  @Override
  public void encodeAsXML(XMLEncoder encoder) {
    encoder.print("<obj-entity name=\"");
    encoder.print(getName());

    // additionally validate that superentity exists
    if (getSuperEntityName() != null && getSuperEntity() != null) {
      encoder.print("\" superEntityName=\"");
      encoder.print(getSuperEntityName());
    }

    if (isAbstract()) {
      encoder.print("\" abstract=\"true");
    }

    if (isServerOnly()) {
      encoder.print("\" serverOnly=\"true");
    }

    if (getClassName() != null) {
      encoder.print("\" className=\"");
      encoder.print(getClassName());
    }

    if (getClientClassName() != null) {
      encoder.print("\" clientClassName=\"");
      encoder.print(getClientClassName());
    }

    if (isReadOnly()) {
      encoder.print("\" readOnly=\"true");
    }

    if (getDeclaredLockType() == LOCK_TYPE_OPTIMISTIC) {
      encoder.print("\" lock-type=\"optimistic");
    }

    if (getDbEntityName() != null && getDbEntity() != null) {

      // not writing DbEntity name if sub entity has same DbEntity
      // as super entity, see CAY-1477
      if (!(getSuperEntity() != null && getSuperEntity().getDbEntity() == getDbEntity())) {
        encoder.print("\" dbEntityName=\"");
        encoder.print(Util.encodeXmlAttribute(getDbEntityName()));
      }
    }

    if (getSuperEntityName() == null && getSuperClassName() != null) {
      encoder.print("\" superClassName=\"");
      encoder.print(getSuperClassName());
    }

    if (getSuperEntityName() == null && getClientSuperClassName() != null) {
      encoder.print("\" clientSuperClassName=\"");
      encoder.print(getClientSuperClassName());
    }

    // deprecated
    if (isExcludingSuperclassListeners()) {
      encoder.print("\" exclude-superclass-listeners=\"true");
    }

    // deprecated
    if (isExcludingDefaultListeners()) {
      encoder.print("\" exclude-default-listeners=\"true");
    }

    encoder.println("\">");
    encoder.indent(1);

    if (qualifier != null) {
      encoder.print("<qualifier>");
      qualifier.encodeAsXML(encoder);
      encoder.println("</qualifier>");
    }

    // store attributes
    encoder.print(getDeclaredAttributes());

    for (Map.Entry<String, String> override : attributeOverrides.entrySet()) {
      encoder.print("<attribute-override name=\"" + override.getKey() + '\"');
      encoder.print(" db-attribute-path=\"");
      encoder.print(Util.encodeXmlAttribute(override.getValue()));
      encoder.print('\"');
      encoder.println("/>");
    }

    // deprecated
    // write entity listeners
    for (EntityListener entityListener : entityListeners) {
      entityListener.encodeAsXML(encoder);
    }

    // write entity-level callbacks
    getCallbackMap().encodeCallbacksAsXML(encoder);

    encoder.indent(-1);
    encoder.println("</obj-entity>");
  }
  /**
   * 掲示板カテゴリをデータベースから読み出します。 <br>
   *
   * @param rundata
   * @param context
   * @param msgList
   * @return
   */
  @Override
  protected boolean loadFormData(RunData rundata, Context context, List<String> msgList)
      throws ALPageNotFoundException, ALDBErrorException {
    try {
      String loginUserStatus = null;
      int uid = (int) login_user.getUserId().getValue();

      // オブジェクトモデルを取得
      EipTMsgboardCategory category = MsgboardUtils.getEipTMsgboardCategory(rundata, context, true);
      if (category == null) {
        return false;
      }
      // カテゴリ名
      category_name.setValue(category.getCategoryName());
      // メモ
      note.setValue(category.getNote());
      // 公開区分
      boolean public_flag =
          (MsgboardUtils.PUBLIC_FLG_VALUE_PUBLIC).equals(category.getPublicFlag());

      // このカテゴリを共有しているメンバーを取得
      SelectQuery<EipTMsgboardCategoryMap> mapquery = Database.query(EipTMsgboardCategoryMap.class);
      Expression mapexp =
          ExpressionFactory.matchDbExp(
              EipTMsgboardCategory.CATEGORY_ID_PK_COLUMN, category.getCategoryId());
      mapquery.setQualifier(mapexp);

      List<EipTMsgboardCategoryMap> list = mapquery.fetchList();

      List<Integer> users = new ArrayList<Integer>();
      int size = list.size();
      for (int i = 0; i < size; i++) {
        EipTMsgboardCategoryMap map = list.get(i);
        users.add(map.getUserId());
        if (uid == map.getUserId().intValue()) {
          loginUserStatus = map.getStatus();
        }
      }

      SelectQuery<TurbineUser> query = Database.query(TurbineUser.class);
      Expression exp = ExpressionFactory.inDbExp(TurbineUser.USER_ID_PK_COLUMN, users);
      Expression nonDisabledexp = ExpressionFactory.noMatchExp(TurbineUser.DISABLED_PROPERTY, "T");
      query.setQualifier(exp.andExp(nonDisabledexp));
      memberList.addAll(ALEipUtils.getUsersFromSelectQuery(query));

      if (public_flag) {
        if ((MsgboardUtils.STAT_VALUE_ALL).equals(loginUserStatus)) {
          access_flag.setValue(MsgboardUtils.ACCESS_PUBLIC_ALL);
          is_member = false;
        } else {
          access_flag.setValue(MsgboardUtils.ACCESS_PUBLIC_MEMBER);
          is_member = true;
        }
      } else {
        if ((MsgboardUtils.STAT_VALUE_ALL).equals(loginUserStatus)) {
          access_flag.setValue(MsgboardUtils.ACCESS_SEACRET_SELF);
          is_member = false;
        } else {
          access_flag.setValue(MsgboardUtils.ACCESS_SEACRET_MEMBER);
          is_member = true;
        }
      }

    } catch (Exception e) {
      logger.error("[MsgboardFormData]", e);
      throw new ALDBErrorException();
    }
    return true;
  }