Search in sources :

Example 6 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method listDataObjectsUnderPathThatMatchSearchText.

/**
 * Lists all data objects under the given path that match a search term. Any
 * data object where the term appears in the beginning, middle, and the end of
 * its name will be retrieved.
 *
 * @param parentPath
 *            path to the parent collection where you are looking for items that
 *            match a search term
 * @param searchText
 *            term to be matched
 * @param offset
 *            partial start index
 * @param limit
 *            max number of items retrieved
 * @return list of data objects that match the given search text
 * @throws DataGridConnectionRefusedException
 */
private List<DataGridCollectionAndDataObject> listDataObjectsUnderPathThatMatchSearchText(String parentPath, String searchText, int offset, int limit, int orderColumn, String orderDir) throws DataNotFoundException, JargonQueryException, DataGridConnectionRefusedException {
    logger.info("listDataObjectsUnderPathThatMatchSearchText()");
    logger.info("parentPath:{}", parentPath);
    logger.info("searchText:{}", searchText);
    logger.info("offset:{}", offset);
    logger.info("limit:{}", limit);
    logger.info("orderColumn:{}", orderColumn);
    logger.info("orderDir:{}", orderDir);
    SpecificQueryAO specificQueryAO = adminServices.getSpecificQueryAO();
    SpecificQueryDefinition queryDef = null;
    List<CollectionAndDataObjectListingEntry> dataGridList = null;
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
    String sqlAlias = null;
    try {
        dataGridCollectionAndDataObjects = new ArrayList<DataGridCollectionAndDataObject>();
        sqlAlias = SQL_LIST_DATA_OBJECTS_MATCHING_SEARCH_TEXT_ALIAS_WITH_ORDERING;
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildSelectDataObjectsUnderPathThatMatchSearchText(parentPath, searchText, offset, limit, orderColumn, orderDir);
        // Creating Specific Query instance
        queryDef = new SpecificQueryDefinition();
        queryDef.setAlias(sqlAlias);
        queryDef.setSql(query.toString());
        // Creating spec query on iRODS
        specificQueryAO.addSpecificQuery(queryDef);
        // Executing specific query
        String zone = irodsServices.getCurrentUserZone();
        List<String> args = new ArrayList<String>();
        args.add(parentPath);
        args.add("%" + searchText + "%");
        args.add(String.valueOf(offset));
        args.add(String.valueOf(limit));
        SpecificQuery specQuery = SpecificQuery.instanceArguments(sqlAlias, args, 0, zone);
        SpecificQueryResultSet queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, MAX_RESULTS_PER_PAGE, 0);
        // Mapping spec query results to DataGrid* objects
        dataGridList = DataGridUtils.mapQueryResultSetToDataGridObjectsForSearch(queryResultSet);
        dataGridCollectionAndDataObjects.addAll(DataGridUtils.mapListingEntryToDataGridCollectionAndDataObject(dataGridList));
    } catch (JargonException | UnsupportedDataGridFeatureException e) {
        logger.error("Could not execute specific query for listing data objects that match a search text", e);
    } finally {
        try {
            // after running the user specific query, we need to remove from the database
            specificQueryAO.removeSpecificQueryByAlias(sqlAlias);
        } catch (JargonException e) {
            logger.error("Could not remove specific query {}: ", sqlAlias, e.getMessage());
        }
    }
    return dataGridCollectionAndDataObjects;
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) SpecificQueryProvider(com.emc.metalnx.services.irods.utils.SpecificQueryProvider) JargonException(org.irods.jargon.core.exception.JargonException) ClientHints(org.irods.jargon.core.pub.domain.ClientHints) ArrayList(java.util.ArrayList) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) CollectionAndDataObjectListingEntry(org.irods.jargon.core.query.CollectionAndDataObjectListingEntry) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) SpecificQueryDefinition(org.irods.jargon.core.pub.domain.SpecificQueryDefinition) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SpecificQuery(org.irods.jargon.core.query.SpecificQuery)

Example 7 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class BrowseController method getCollBrowserView.

/**
 * Finds all collections and data objects existing under a certain path
 *
 * @param model
 * @param path
 *            path to get all directories and data objects from
 * @return collections browser template that renders all items of certain path
 *         (parent)
 * @throws DataGridConnectionRefusedException
 *             if Metalnx cannot connect to the grid.
 */
private String getCollBrowserView(final Model model, String path) throws JargonException, DataGridException {
    logger.info("getCollBrowserView()");
    logger.info("model:{}", model);
    logger.info("path:{}", path);
    logger.info("find collection by name:{}", path);
    DataGridCollectionAndDataObject dataGridObj = null;
    try {
        dataGridObj = cs.findByName(path);
    } catch (FileNotFoundException fnf) {
        logger.warn("file not found for:{}", path);
        // I don't have a path so use the user home
        logger.info("no path, so using user home directory");
        // TODO: refactor into something more elegant - mcc
        model.addAttribute("invalidPath", path);
        IRODSAccount irodsAccount = irodsServices.getCollectionAO().getIRODSAccount();
        path = MiscIRODSUtils.buildIRODSUserHomeForAccountUsingDefaultScheme(irodsAccount);
    }
    if (path.endsWith("/") && path.compareTo("/") != 0) {
        path = path.substring(0, path.length() - 1);
    }
    currentPath = path;
    logger.info("currentPath:{}", currentPath);
    DataGridUser user = loggedUserUtils.getLoggedDataGridUser();
    if (zoneTrashPath == null || zoneTrashPath.isEmpty()) {
        zoneTrashPath = String.format("/%s/trash", irodsServices.getCurrentUserZone());
    }
    // TODO: do I really need these permission path checks? I can let iRODS worry
    // about permissions - mcc
    CollectionOrDataObjectForm collectionForm = new CollectionOrDataObjectForm();
    String permissionType = "none";
    if (dataGridObj.isProxy()) {
        logger.info("this is a proxy, so fake out the options");
        collectionForm.setInheritOption(false);
        permissionType = "read";
    } else {
        logger.info("this is not a proxy, so gather permission info");
        permissionType = cs.getPermissionsForPath(path);
        collectionForm.setInheritOption(cs.getInheritanceOptionForCollection(currentPath));
        permissionsService.resolveMostPermissiveAccessForUser(dataGridObj, user);
    }
    logger.debug("permission options are set");
    boolean isPermissionOwn = "own".equals(permissionType);
    boolean isTrash = path.contains(zoneTrashPath) && (isPermissionOwn || user.isAdmin());
    boolean inheritanceDisabled = !isPermissionOwn && collectionForm.getInheritOption();
    model.addAttribute("collectionAndDataObject", dataGridObj);
    model.addAttribute("isTrash", isTrash);
    model.addAttribute("permissionType", permissionType);
    model.addAttribute("currentPath", currentPath);
    model.addAttribute("encodedCurrentPath", URLEncoder.encode(currentPath));
    model.addAttribute("isCurrentPathCollection", cs.isCollection(path));
    model.addAttribute("user", user);
    model.addAttribute("trashColl", cs.getTrashForPath(currentPath));
    model.addAttribute("collection", collectionForm);
    model.addAttribute("inheritanceDisabled", inheritanceDisabled);
    model.addAttribute("requestMapping", "/browse/add/action/");
    model.addAttribute("parentPath", parentPath);
    setBreadcrumbToModel(model, dataGridObj);
    logger.info("forwarding to collections/collectionsBrowser");
    return "collections/collectionsBrowser";
}
Also used : IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) CollectionOrDataObjectForm(com.emc.metalnx.modelattribute.collection.CollectionOrDataObjectForm)

Example 8 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class BrowseController method getFileInfo.

/**
 * Gets checksum, total number of replicas and where each replica lives in the
 * data grid for a specific data object
 *
 * @param model
 * @param path
 *            path to the data object to get checksum and replica information
 * @return the template that shows the data object information
 * @throws DataGridException
 * @throws FileNotFoundException
 */
@RequestMapping(value = "/info/", method = RequestMethod.POST)
public String getFileInfo(final Model model, final String path) throws DataGridException, FileNotFoundException {
    logger.info("CollectionController getInfoFile() starts :: " + path);
    DataGridCollectionAndDataObject dataGridObj = null;
    Map<DataGridCollectionAndDataObject, DataGridResource> replicasMap = null;
    try {
        dataGridObj = cs.findByName(path);
        if (dataGridObj != null && !dataGridObj.isCollection()) {
            replicasMap = cs.listReplicasByResource(path);
            dataGridObj.setChecksum(cs.getChecksum(path));
            dataGridObj.setNumberOfReplicas(cs.getTotalNumberOfReplsForDataObject(path));
            dataGridObj.setReplicaNumber(String.valueOf(cs.getReplicationNumber(path)));
            permissionsService.resolveMostPermissiveAccessForUser(dataGridObj, loggedUserUtils.getLoggedDataGridUser());
        }
    } catch (DataGridConnectionRefusedException e) {
        logger.error("Could not connect to the data grid", e);
        throw e;
    } catch (DataGridException e) {
        logger.error("Could not get file info for {}", path, e);
        throw e;
    } catch (FileNotFoundException e) {
        logger.error("file does not exist for:{}", path, e);
        throw e;
    }
    model.addAttribute("collectionAndDataObject", dataGridObj);
    model.addAttribute("currentCollection", dataGridObj);
    model.addAttribute("replicasMap", replicasMap);
    model.addAttribute("infoFlag", true);
    logger.info("CollectionController getInfoFile() ends !!");
    return "collections/info :: infoView";
// return "collections/info";
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class TestAddDataGridMetadataListToObjs method setUp.

@Before
public void setUp() throws DataGridException {
    parentPath = String.format("/%s/home/%s", zone, username);
    path = String.format("%s/test-metadata-transfer", parentPath);
    fos.deleteCollection(path, true);
    cs.createCollection(new DataGridCollectionAndDataObject(path, parentPath, true));
    expectedMetadataList = new ArrayList<>();
    expectedMetadataList.add(new DataGridMetadata("attr1", "val1", "unit1"));
    expectedMetadataList.add(new DataGridMetadata("attr2", "val2", "unit2"));
    expectedMetadataList.add(new DataGridMetadata("attr3", "val3", "unit3"));
    MockMultipartFile file;
    for (int i = 0; i < NUMBER_OF_FILES; i++) {
        String filename = BASE_FILE_NAME + i;
        String filepath = String.format("%s/%s", path, filename);
        file = new MockMultipartFile(filename, "Hello World Transfer".getBytes());
        us.upload(file, path, false, false, "", RESOURCE, false);
        metadataService.addMetadataToPath(filepath, expectedMetadataList);
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataGridMetadata(com.emc.metalnx.core.domain.entity.DataGridMetadata) Before(org.junit.Before)

Example 10 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class TestAddDataGridMetadataToObjs method setUp.

@Before
public void setUp() throws DataGridException {
    parentPath = String.format("/%s/home/%s", zone, username);
    path = String.format("%s/test-metadata-transfer", parentPath);
    fos.deleteCollection(path, true);
    cs.createCollection(new DataGridCollectionAndDataObject(path, parentPath, true));
    expectedMetadataList = MetadataUtils.createRandomMetadata(NUMBER_OF_METADATA_TAGS);
    MockMultipartFile file;
    for (int i = 0; i < NUMBER_OF_FILES; i++) {
        String filename = BASE_FILE_NAME + i;
        String filepath = String.format("%s/%s", path, filename);
        file = new MockMultipartFile(filename, "Hello World Transfer".getBytes());
        us.upload(file, path, false, false, "", RESOURCE, false);
        for (DataGridMetadata metadata : expectedMetadataList) {
            metadataService.addMetadataToPath(filepath, metadata);
        }
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataGridMetadata(com.emc.metalnx.core.domain.entity.DataGridMetadata) Before(org.junit.Before)

Aggregations

DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)55 JargonException (org.irods.jargon.core.exception.JargonException)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Before (org.junit.Before)11 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)9 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)9 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)7 ArrayList (java.util.ArrayList)7 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)7 DataGridPageContext (com.emc.metalnx.core.domain.entity.DataGridPageContext)6 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)6 DataGridMetadata (com.emc.metalnx.core.domain.entity.DataGridMetadata)5 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 JargonQueryException (org.irods.jargon.core.query.JargonQueryException)4 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)3 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3