Search in sources :

Example 1 with FilterExpression

use of com.pogeyan.cmis.api.uri.expression.FilterExpression in project copper-cms by PogeyanOSS.

the class MNavigationServiceDAOImpl method getChildren.

/*
	 * (non-Javadoc) filterExpression supports eq, ne, ge, gt, le, lt, startswith,
	 * endswith. example filter:
	 * "properties.orderId eq 100 and name eq pogeyan or startswith (name::'a')"
	 * "*,modifiedAt le 123456789 and typeId eq cmis:folder" -->* represents to get
	 * all properties data in that object
	 * "properties.isRead eq false and typeId ne cmis:folder"
	 * "properties.orderId gt 100 properties.purchaseOrder ge 100"
	 * "startswith (name::'a') and properties.orderId lt 100"
	 * "properties.orderId le 100"
	 * 
	 * example order: "name asc, repositoryId" "name desc"
	 * 
	 * @see
	 * com.pogeyan.cmis.api.data.services.MNavigationServiceDAO#getChildren(java
	 * .lang.String, java.lang.String[], boolean, int, int, java.lang.String,
	 * java.lang.String[], java.lang.String)
	 */
@SuppressWarnings("unchecked")
@Override
public List<MBaseObject> getChildren(String path, String[] principalIds, boolean aclPropagation, int maxItems, int skipCount, String orderBy, String[] mappedColumns, String filterExpression) {
    Query<MBaseObject> query = createQuery().disableValidation().filter("internalPath", path).field("token.changeType").notEqual(TokenChangeType.DELETED.value());
    if (!StringUtils.isEmpty(orderBy)) {
        if (this.isOrderByParsable(orderBy)) {
            try {
                OrderByExpression orderByExpression = UriParser.parseOrderBy(orderBy);
                query = (Query<MBaseObject>) orderByExpression.accept(new MongoExpressionVisitor<MBaseObject>(query));
            } catch (ExpressionParserException | ExceptionVisitExpression e) {
            }
        } else {
            query = query.order(orderBy);
        }
    }
    if (!StringUtils.isEmpty(filterExpression)) {
        try {
            FilterExpression expression = UriParser.parseFilter(filterExpression);
            query = (Query<MBaseObject>) expression.accept(new MongoExpressionVisitor<MBaseObject>(query));
        } catch (ExpressionParserException | ExceptionVisitExpression e) {
        }
    }
    if (maxItems > 0) {
        query = query.offset(skipCount).limit(maxItems);
    }
    if (mappedColumns != null && mappedColumns.length > 0) {
        query = query.retrievedFields(true, mappedColumns);
    }
    if (aclPropagation) {
        query.or(getAclCriteria(principalIds, query));
        return query.asList();
    } else {
        return query.asList();
    }
}
Also used : MBaseObject(com.pogeyan.cmis.data.mongo.MBaseObject) ExceptionVisitExpression(com.pogeyan.cmis.api.uri.expression.ExceptionVisitExpression) ExpressionParserException(com.pogeyan.cmis.api.uri.expression.ExpressionParserException) OrderByExpression(com.pogeyan.cmis.api.uri.expression.OrderByExpression) FilterExpression(com.pogeyan.cmis.api.uri.expression.FilterExpression)

Example 2 with FilterExpression

use of com.pogeyan.cmis.api.uri.expression.FilterExpression in project copper-cms by PogeyanOSS.

the class MNavigationServiceDAOImpl method getDescendants.

/*
	 * (non-Javadoc) filterExpression supports eq, ne, ge, gt, le, lt, startswith,
	 * endswith. example filter:
	 * "properties.orderId eq 100 and name eq pogeyan or startswith (name::'a')"
	 * "*,modifiedAt le 123456789 and typeId eq cmis:folder" -->* represents to get
	 * all properties data in that object
	 * "properties.isRead eq false and typeId ne cmis:folder"
	 * "properties.orderId gt 100 properties.purchaseOrder ge 100"
	 * "startswith (name::'a') and properties.orderId lt 100"
	 * "properties.orderId le 100"
	 * 
	 * example order: "name asc, repositoryId", "name desc"
	 * 
	 * @see com.pogeyan.cmis.api.data.services.MNavigationServiceDAO#getDescendants(
	 * java .lang.String, java.lang.String[], boolean,java.lang.String[],
	 * java.lang.String)
	 */
@SuppressWarnings("unchecked")
@Override
public List<MBaseObject> getDescendants(String path, String[] principalIds, boolean aclPropagation, String[] mappedColumns, String filterExpression) {
    Pattern exp = Pattern.compile(path, Pattern.CASE_INSENSITIVE);
    Query<MBaseObject> query = createQuery().disableValidation().filter("internalPath =", exp).field("token.changeType").notEqual(TokenChangeType.DELETED.value());
    if (!StringUtils.isEmpty(filterExpression)) {
        try {
            FilterExpression expression = UriParser.parseFilter(filterExpression);
            query = (Query<MBaseObject>) expression.accept(new MongoExpressionVisitor<MBaseObject>(query));
        } catch (ExpressionParserException | ExceptionVisitExpression e) {
        }
    }
    if (mappedColumns != null && mappedColumns.length > 0) {
        query = query.retrievedFields(true, mappedColumns);
    }
    if (aclPropagation) {
        query.or(getAclCriteria(principalIds, query));
    }
    return query.asList();
}
Also used : Pattern(java.util.regex.Pattern) MBaseObject(com.pogeyan.cmis.data.mongo.MBaseObject) ExceptionVisitExpression(com.pogeyan.cmis.api.uri.expression.ExceptionVisitExpression) ExpressionParserException(com.pogeyan.cmis.api.uri.expression.ExpressionParserException) FilterExpression(com.pogeyan.cmis.api.uri.expression.FilterExpression)

Example 3 with FilterExpression

use of com.pogeyan.cmis.api.uri.expression.FilterExpression in project copper-cms by PogeyanOSS.

the class App method main.

public static void main(String[] args) throws Exception, ExpressionParserException, ExpressionParserInternalError, ExceptionVisitExpression {
    RepositoryManagerFactory.getInstance().init(new LocalRepoImpl());
    MongoClientFactory dbFactory = (MongoClientFactory) MongoClientFactory.createDatabaseService();
    MDocumentObjectDAOImpl dao = (MDocumentObjectDAOImpl) dbFactory.getObjectService("TestRepo", MDocumentObjectDAO.class);
    Query<MDocumentObject> query = dao.createQuery();
    // String filterExpressionQuery = "name eq 'fd' and name ne 'sd'";
    String filterExpressionQuery = "contains(name, 'fd')";
    FilterExpression expression = UriParser.parseFilter(filterExpressionQuery);
    Object filterExp = expression.accept(new MongoExpressionVisitor<MDocumentObject>(query));
    System.out.print("output: " + filterExp != null ? filterExp.toString() : "error");
    String orderByExpressionQuery = "name asc, repositoryId desc";
    OrderByExpression orderByExpression = UriParser.parseOrderBy(orderByExpressionQuery);
    Object orderByExp = orderByExpression.accept(new MongoExpressionVisitor<MDocumentObject>(query));
    System.out.print("output: " + orderByExp != null ? orderByExp.toString() : "error");
}
Also used : MDocumentObjectDAO(com.pogeyan.cmis.api.data.services.MDocumentObjectDAO) MongoClientFactory(com.pogeyan.cmis.data.mongo.services.MongoClientFactory) LocalRepoImpl(com.pogeyan.cmis.repo.local.LocalRepoImpl) MDocumentObjectDAOImpl(com.pogeyan.cmis.data.mongo.services.MDocumentObjectDAOImpl) FilterExpression(com.pogeyan.cmis.api.uri.expression.FilterExpression) OrderByExpression(com.pogeyan.cmis.api.uri.expression.OrderByExpression)

Aggregations

FilterExpression (com.pogeyan.cmis.api.uri.expression.FilterExpression)3 ExceptionVisitExpression (com.pogeyan.cmis.api.uri.expression.ExceptionVisitExpression)2 ExpressionParserException (com.pogeyan.cmis.api.uri.expression.ExpressionParserException)2 OrderByExpression (com.pogeyan.cmis.api.uri.expression.OrderByExpression)2 MBaseObject (com.pogeyan.cmis.data.mongo.MBaseObject)2 MDocumentObjectDAO (com.pogeyan.cmis.api.data.services.MDocumentObjectDAO)1 MDocumentObjectDAOImpl (com.pogeyan.cmis.data.mongo.services.MDocumentObjectDAOImpl)1 MongoClientFactory (com.pogeyan.cmis.data.mongo.services.MongoClientFactory)1 LocalRepoImpl (com.pogeyan.cmis.repo.local.LocalRepoImpl)1 Pattern (java.util.regex.Pattern)1