Search in sources :

Example 1 with DataGridDataNotFoundException

use of com.emc.metalnx.core.domain.exceptions.DataGridDataNotFoundException in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method getSubCollectionsAndDataObjectsUnderPathThatMatchSearchTextPaginated.

@Override
public List<DataGridCollectionAndDataObject> getSubCollectionsAndDataObjectsUnderPathThatMatchSearchTextPaginated(String parentPath, String searchText, int pageNum, int pageSize, int orderColumn, String orderDir, DataGridPageContext pageContext) throws DataGridDataNotFoundException, DataGridQueryException, DataGridException {
    logger.info("getSubCollectionsAndDataObjectsUnderPathThatMatchSearchTextPaginated()");
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = new ArrayList<>();
    List<DataGridCollectionAndDataObject> dataGridCollections = null;
    List<DataGridCollectionAndDataObject> dataGridObjects = null;
    int totalCollections = 0;
    int totalDataObjects = 0;
    int startIndex = (pageNum - 1) * pageSize;
    int endIndex = pageNum * pageSize - 1;
    int endIndexForDataObjs;
    int endIndexForCollections;
    try {
        totalCollections = getTotalCollectionsUnderPathThatMatchSearchText(parentPath, searchText);
        totalDataObjects = getTotalDataObjectsUnderPathThatMatchSearchText(parentPath, searchText);
        pageContext.setStartItemNumber(startIndex + 1);
        pageContext.setTotalNumberOfItems(totalCollections + totalDataObjects);
        if (endIndex + 1 <= totalCollections) {
            dataGridCollections = listCollectionsUnderPathThatMatchSearchText(parentPath, searchText, startIndex, pageSize, orderColumn, orderDir);
            int collectionEntriesSize = dataGridCollections.size();
            endIndexForCollections = collectionEntriesSize;
            dataGridCollectionAndDataObjects = dataGridCollections.subList(0, endIndexForCollections);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForCollections - 1);
        } else if (startIndex + 1 > totalCollections) {
            dataGridObjects = listDataObjectsUnderPathThatMatchSearchText(parentPath, searchText, startIndex - totalCollections, pageSize, orderColumn, orderDir);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + dataGridObjects.size() - 1);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
        } else {
            dataGridCollections = listCollectionsUnderPathThatMatchSearchText(parentPath, searchText, startIndex, pageSize, orderColumn, orderDir);
            endIndexForDataObjs = pageSize - totalCollections % pageSize;
            dataGridObjects = listDataObjectsUnderPathThatMatchSearchText(parentPath, searchText, 0, endIndexForDataObjs, orderColumn, orderDir);
            endIndexForDataObjs = endIndexForDataObjs > dataGridObjects.size() ? dataGridObjects.size() : endIndexForDataObjs;
            dataGridCollectionAndDataObjects.addAll(dataGridCollections);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForDataObjs + dataGridCollections.size() - 1);
        }
    } catch (DataNotFoundException e) {
        logger.error("Could not find items under path: {}", e.getMessage());
        throw new DataGridDataNotFoundException(e.getMessage());
    } catch (JargonQueryException e) {
        logger.error("Could not query catalog for items under path: {}", e.getMessage());
        throw new DataGridQueryException(e.getMessage());
    }
    return dataGridCollectionAndDataObjects;
}
Also used : DataGridQueryException(com.emc.metalnx.core.domain.exceptions.DataGridQueryException) DataNotFoundException(org.irods.jargon.core.exception.DataNotFoundException) DataGridDataNotFoundException(com.emc.metalnx.core.domain.exceptions.DataGridDataNotFoundException) DataGridDataNotFoundException(com.emc.metalnx.core.domain.exceptions.DataGridDataNotFoundException) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) ArrayList(java.util.ArrayList)

Aggregations

DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)1 DataGridDataNotFoundException (com.emc.metalnx.core.domain.exceptions.DataGridDataNotFoundException)1 DataGridQueryException (com.emc.metalnx.core.domain.exceptions.DataGridQueryException)1 ArrayList (java.util.ArrayList)1 DataNotFoundException (org.irods.jargon.core.exception.DataNotFoundException)1 JargonQueryException (org.irods.jargon.core.query.JargonQueryException)1