Search in sources :

Example 1 with FilterTypeString

use of org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString in project alfresco-repository by Alfresco.

the class GetChildrenCannedQuery method includeFilter.

// note: currently inclusive and OR-based
private boolean includeFilter(Map<QName, Serializable> propVals, List<FilterProp> filterProps) {
    for (FilterProp filterProp : filterProps) {
        Serializable propVal = propVals.get(filterProp.getPropName());
        if (propVal != null) {
            if ((filterProp instanceof FilterPropString) && (propVal instanceof String)) {
                String val = (String) propVal;
                String filter = (String) filterProp.getPropVal();
                switch((FilterTypeString) filterProp.getFilterType()) {
                    case STARTSWITH:
                        if (val.startsWith(filter)) {
                            return true;
                        }
                        break;
                    case STARTSWITH_IGNORECASE:
                        if (val.toLowerCase().startsWith(filter.toLowerCase())) {
                            return true;
                        }
                        break;
                    case EQUALS:
                        if (val.equals(filter)) {
                            return true;
                        }
                        break;
                    case EQUALS_IGNORECASE:
                        if (val.equalsIgnoreCase(filter)) {
                            return true;
                        }
                        break;
                    case ENDSWITH:
                        if (val.endsWith(filter)) {
                            return true;
                        }
                        break;
                    case ENDSWITH_IGNORECASE:
                        if (val.toLowerCase().endsWith(filter.toLowerCase())) {
                            return true;
                        }
                        break;
                    case MATCHES:
                        if (val.matches(filter)) {
                            return true;
                        }
                        break;
                    case MATCHES_IGNORECASE:
                        if (val.toLowerCase().matches(filter.toLowerCase())) {
                            return true;
                        }
                        break;
                    default:
                }
            }
        }
        if ((filterProp instanceof FilterPropBoolean) && (propVal instanceof Boolean)) {
            Boolean val = (Boolean) propVal;
            Boolean filter = (Boolean) filterProp.getPropVal();
            return (val == filter);
        }
    }
    return false;
}
Also used : FilterTypeString(org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString) Serializable(java.io.Serializable) FilterTypeString(org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString)

Example 2 with FilterTypeString

use of org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString in project alfresco-repository by Alfresco.

the class GetChildrenCannedQueryTest method filterByPropAndCheck.

private void filterByPropAndCheck(NodeRef parentNodeRef, QName filterPropQName, String filterVal, FilterTypeString filterType, int expectedCount) {
    FilterProp filter = new FilterPropString(filterPropQName, filterVal, filterType);
    List<FilterProp> filterProps = new ArrayList<FilterProp>(1);
    filterProps.add(filter);
    // note: currently inclusive filter
    PagingResults<NodeRef> results = list(parentNodeRef, -1, -1, 0, null, filterProps, null);
    int count = results.getPage().size();
    assertEquals(expectedCount, count);
    if (logger.isInfoEnabled()) {
        logger.info("testFiltering: " + count + " items [" + filterPropQName + "," + filterVal + "," + filterType + "]");
    }
    for (NodeRef nodeRef : results.getPage()) {
        Serializable propVal = nodeService.getProperty(nodeRef, filterPropQName);
        if (logger.isInfoEnabled()) {
            logger.info("testFiltering:     [" + nodeRef + "," + propVal + "]");
        }
        if (propVal instanceof String) {
            String val = (String) propVal;
            switch(filterType) {
                case STARTSWITH:
                    if (!val.startsWith(filterVal)) {
                        fail("Unexpected val: " + val + " (does not 'startWith': " + filterVal + ")");
                    }
                    break;
                case STARTSWITH_IGNORECASE:
                    if (!val.toLowerCase().startsWith(filterVal.toLowerCase())) {
                        fail("Unexpected val: " + val + " (does not 'startWithIgnoreCase': " + filterVal + ")");
                    }
                    break;
                case EQUALS:
                    if (!val.equals(filterVal)) {
                        fail("Unexpected val: " + val + " (does not 'equal': " + filterVal + ")");
                    }
                    break;
                case EQUALS_IGNORECASE:
                    if (!val.equalsIgnoreCase(filterVal)) {
                        fail("Unexpected val: " + val + " (does not 'equalIgnoreCase': " + filterVal + ")");
                    }
                    break;
                default:
            }
        } else {
            fail("Unsupported filter type: " + propVal.getClass().getName());
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) FilterTypeString(org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString)

Aggregations

Serializable (java.io.Serializable)2 FilterTypeString (org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString)2 ArrayList (java.util.ArrayList)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1