Search in sources :

Example 1 with EmptyPickerResult

use of com.ibm.xsp.extlib.component.picker.data.EmptyPickerResult in project org.openntf.domino by OpenNTF.

the class OpenntfNABNamePickerData method readEntries.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ibm.xsp.extlib.component.picker.data.AbstractDominoViewPickerData#readEntries(com.ibm.xsp.extlib.component.picker.data.IPickerOptions
	 * )
	 */
@Override
public IPickerResult readEntries(final IPickerOptions options) {
    try {
        getReturnNameFormat();
        EntryMetaData meta = createOpenntfEntryMetaData(options);
        meta.setKey(getReturnNameFormatAsKey());
        View view = meta.getView();
        view.setAutoUpdate(false);
        try {
            ArrayList<IPickerEntry> entries = new ArrayList<IPickerEntry>();
            int start = options.getStart();
            int count = options.getCount();
            String key = options.getKey();
            String _startKey = options.getStartKey();
            if (StringUtil.isNotEmpty(_startKey)) {
                key = _startKey;
            }
            String searchType = getSearchType();
            if (StringUtil.isEmpty(searchType)) {
                searchType = SEARCH_STARTFROM;
            }
            if (StringUtil.equals(searchType, SEARCH_MATCH)) {
                ViewEntryCollection vc = view.getAllEntriesByKey(key);
                ViewEntry ve = start > 0 ? vc.getNthEntry(start) : vc.getFirstEntry();
                for (int i = 0; i < count && ve != null; i++) {
                    entries.add(meta.createEntry(ve));
                    ve = vc.getNextEntry(ve);
                }
                int nEntries = vc.getCount();
                return new Result(entries, nEntries);
            }
            if (StringUtil.equals(searchType, SEARCH_FTSEARCH)) {
                applyFTSearch(options, view, key);
                ViewEntryCollection vc = view.getAllEntries();
                ViewEntry ve = start > 0 ? vc.getNthEntry(start) : vc.getFirstEntry();
                for (int i = 0; i < count && ve != null; i++) {
                    entries.add(meta.createEntry(ve));
                    ve = vc.getNextEntry(ve);
                }
                int nEntries = vc.getCount();
                return new Result(entries, nEntries);
            } else {
                ViewNavigator nav = view.createViewNav();
                try {
                    ViewEntry ve = null;
                    if (key != null) {
                        int searchOptions = DominoUtils.FIND_GREATER_THAN | DominoUtils.FIND_EQUAL | DominoUtils.FIND_PARTIAL | DominoUtils.FIND_CASE_INSENSITIVE;
                        ve = DominoUtils.getViewEntryByKeyWithOptions(Factory.getWrapperFactory().toLotus(view), key, searchOptions);
                    } else {
                        ve = nav.getCurrent();
                    }
                    if (start > 0) {
                        if (nav.skip(start) != start) {
                            // ok not all of them are skipped, stop the process
                            count = 0;
                        }
                    }
                    for (int i = 0; i < count && ve != null; i++) {
                        entries.add(meta.createEntry(ve));
                        ve = nav.getNext(ve);
                    }
                    int nEntries = -1;
                    return new Result(entries, nEntries);
                } finally {
                    nav.recycle();
                }
            }
        } finally {
        // Recycle the view?
        }
    } catch (Exception ex) {
        Platform.getInstance().log(ex);
        // Swallow the exception for the end user and return an empty picker
        return new EmptyPickerResult();
    }
}
Also used : ViewNavigator(lotus.domino.ViewNavigator) ArrayList(java.util.ArrayList) IPickerEntry(com.ibm.xsp.extlib.component.picker.data.IPickerEntry) EmptyPickerResult(com.ibm.xsp.extlib.component.picker.data.EmptyPickerResult) View(lotus.domino.View) NotesException(lotus.domino.NotesException) EmptyPickerResult(com.ibm.xsp.extlib.component.picker.data.EmptyPickerResult) IPickerResult(com.ibm.xsp.extlib.component.picker.data.IPickerResult) DominoViewEntry(com.ibm.xsp.model.domino.wrapped.DominoViewEntry) ViewEntry(lotus.domino.ViewEntry) ViewEntryCollection(lotus.domino.ViewEntryCollection)

Example 2 with EmptyPickerResult

use of com.ibm.xsp.extlib.component.picker.data.EmptyPickerResult in project org.openntf.domino by OpenNTF.

the class OpenntfViewValuePickerData method readEntries.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ibm.xsp.extlib.component.picker.data.AbstractDominoViewPickerData#readEntries(com.ibm.xsp.extlib.component.picker.data.IPickerOptions
	 * )
	 */
@Override
public IPickerResult readEntries(final IPickerOptions options) {
    try {
        EntryMetaData meta = new _EntryMetaData(options);
        View view = meta.getView();
        view.setAutoUpdate(false);
        try {
            ArrayList<IPickerEntry> entries = new ArrayList<IPickerEntry>();
            int start = options.getStart();
            int count = options.getCount();
            String key = options.getKey();
            String _startKey = options.getStartKey();
            if (StringUtil.isNotEmpty(_startKey)) {
                key = _startKey;
            }
            String searchType = getSearchType();
            if (StringUtil.isEmpty(searchType)) {
                searchType = SEARCH_STARTFROM;
            }
            if (StringUtil.equals(searchType, SEARCH_MATCH)) {
                ViewEntryCollection vc = view.getAllEntriesByKey(key);
                ViewEntry ve = start > 0 ? vc.getNthEntry(start) : vc.getFirstEntry();
                for (int i = 0; i < count && ve != null; i++) {
                    entries.add(meta.createEntry(ve));
                    ve = vc.getNextEntry(ve);
                }
                int nEntries = vc.getCount();
                return new Result(entries, nEntries);
            }
            if (StringUtil.equals(searchType, SEARCH_FTSEARCH)) {
                applyFTSearch(options, view, key);
                ViewEntryCollection vc = view.getAllEntries();
                ViewEntry ve = start > 0 ? vc.getNthEntry(start) : vc.getFirstEntry();
                for (int i = 0; i < count && ve != null; i++) {
                    entries.add(meta.createEntry(ve));
                    ve = vc.getNextEntry(ve);
                }
                int nEntries = vc.getCount();
                return new Result(entries, nEntries);
            } else {
                ViewNavigator nav = view.createViewNav();
                try {
                    ViewEntry ve = null;
                    if (key != null) {
                        int searchOptions = DominoUtils.FIND_GREATER_THAN | DominoUtils.FIND_EQUAL | DominoUtils.FIND_PARTIAL | DominoUtils.FIND_CASE_INSENSITIVE;
                        // This is the one line that's different
                        ve = DominoUtils.getViewEntryByKeyWithOptions(Factory.getWrapperFactory().toLotus(view), key, searchOptions);
                    } else {
                        ve = nav.getCurrent();
                    }
                    if (start > 0) {
                        if (nav.skip(start) != start) {
                            // ok not all of them are skipped, stop the
                            // process
                            count = 0;
                        }
                    }
                    for (int i = 0; i < count && ve != null; i++) {
                        entries.add(meta.createEntry(ve));
                        ve = nav.getNext(ve);
                    }
                    int nEntries = -1;
                    return new Result(entries, nEntries);
                } finally {
                    nav.recycle();
                }
            }
        } finally {
        // Recycle the view?
        }
    } catch (Exception ex) {
        Platform.getInstance().log(ex);
        // Swallow the exception for the end user and return an empty picker
        return new EmptyPickerResult();
    }
}
Also used : ViewNavigator(lotus.domino.ViewNavigator) ArrayList(java.util.ArrayList) IPickerEntry(com.ibm.xsp.extlib.component.picker.data.IPickerEntry) EmptyPickerResult(com.ibm.xsp.extlib.component.picker.data.EmptyPickerResult) View(lotus.domino.View) NotesException(lotus.domino.NotesException) IPickerResult(com.ibm.xsp.extlib.component.picker.data.IPickerResult) EmptyPickerResult(com.ibm.xsp.extlib.component.picker.data.EmptyPickerResult) DominoViewEntry(com.ibm.xsp.model.domino.wrapped.DominoViewEntry) ViewEntry(lotus.domino.ViewEntry) ViewEntryCollection(lotus.domino.ViewEntryCollection)

Aggregations

EmptyPickerResult (com.ibm.xsp.extlib.component.picker.data.EmptyPickerResult)2 IPickerEntry (com.ibm.xsp.extlib.component.picker.data.IPickerEntry)2 IPickerResult (com.ibm.xsp.extlib.component.picker.data.IPickerResult)2 DominoViewEntry (com.ibm.xsp.model.domino.wrapped.DominoViewEntry)2 ArrayList (java.util.ArrayList)2 NotesException (lotus.domino.NotesException)2 View (lotus.domino.View)2 ViewEntry (lotus.domino.ViewEntry)2 ViewEntryCollection (lotus.domino.ViewEntryCollection)2 ViewNavigator (lotus.domino.ViewNavigator)2