Search in sources :

Example 11 with DataGridCollectionAndDataObject

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

the class FilePropertiesController method searchToCSVFile.

@RequestMapping(value = "/downloadCSVResults/")
public void searchToCSVFile(final HttpServletResponse response) throws DataGridConnectionRefusedException, IOException, JargonException {
    ServletOutputStream outputStream = response.getOutputStream();
    String loggedUser = getLoggedDataGridUser().getUsername();
    String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String filename = String.format("search-result_%s_%s.csv", loggedUser, date);
    // Setting CSV Mime type
    response.setContentType("text/csv");
    response.setHeader("Content-disposition", "attachment;filename=" + filename);
    // Building search parameters lines
    outputStream.print("Search condition #;Condition\n");
    int i = 1;
    for (DataGridFilePropertySearch field : currentFilePropertySearch) {
        String condition = field.toString();
        outputStream.print(String.format("%d;%s\n", i, condition));
        i++;
    }
    outputStream.print("\n");
    outputStream.flush();
    // Executing query
    DataGridPageContext pageContext = new DataGridPageContext();
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = filePropertyService.findByFileProperties(currentFilePropertySearch, pageContext, 1, Integer.MAX_VALUE);
    // Printing number of results
    outputStream.print("Number of results\n");
    outputStream.print(String.format("%d\n", pageContext.getTotalNumberOfItems()));
    outputStream.print("\n");
    outputStream.flush();
    // Printing results
    outputStream.print("Filename;Path;Owner;Kind;Modified;Size;Matches\n");
    for (DataGridCollectionAndDataObject obj : dataGridCollectionAndDataObjects) {
        outputStream.print(obj.getName() + ";");
        outputStream.print(obj.getPath() + ";");
        outputStream.print(obj.getOwner() + ";");
        outputStream.print((obj.isCollection() ? "collection" : "data object") + ";");
        outputStream.print(obj.getModifiedAtFormattedForCSVReport() + ";");
        outputStream.print(String.valueOf(obj.getSize()) + ";");
        outputStream.print(String.valueOf(obj.getNumberOfMatches()));
        outputStream.print("\n");
        outputStream.flush();
    }
}
Also used : DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) ServletOutputStream(javax.servlet.ServletOutputStream) DataGridFilePropertySearch(com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with DataGridCollectionAndDataObject

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

the class MetadataController method searchByMetadata.

@RequestMapping(value = "/search/", method = RequestMethod.POST)
@ResponseBody
public String searchByMetadata(@RequestParam(required = false) final String jsonMetadataSearch, @RequestParam("draw") final int draw, @RequestParam("start") final int start, @RequestParam("length") final int length) throws DataGridConnectionRefusedException {
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonResponse = new HashMap<String, Object>();
    jsonResponse.put("draw", String.valueOf(draw));
    jsonResponse.put("recordsTotal", String.valueOf(0));
    jsonResponse.put("recordsFiltered", String.valueOf(0));
    jsonResponse.put("data", new ArrayList<String>());
    String jsonString = "";
    try {
        if (jsonMetadataSearch != null) {
            currPage = (int) (Math.floor(start / length) + 1);
            this.jsonMetadataSearch = jsonMetadataSearch;
        }
        // Creating parser
        JsonNode jsonObject = mapper.readTree(this.jsonMetadataSearch);
        currSearch = new ArrayList<>();
        JsonNode attributes = jsonObject.get("attribute");
        JsonNode operators = jsonObject.get("operator");
        JsonNode values = jsonObject.get("value");
        JsonNode units = jsonObject.get("unit");
        for (int i = 0; i < attributes.size(); i++) {
            String attr = attributes.get(i).textValue();
            String val = values.get(i).textValue();
            String unit = units.get(i).textValue();
            String opt = operators.get(i).textValue();
            DataGridSearchOperatorEnum op = DataGridSearchOperatorEnum.valueOf(opt);
            DataGridMetadataSearch ms = new DataGridMetadataSearch(attr, val, unit, op);
            currSearch.add(ms);
        }
        DataGridPageContext pageContext = new DataGridPageContext();
        List<DataGridCollectionAndDataObject> dgCollDataObjs = metadataService.findByMetadata(currSearch, pageContext, currPage, length);
        jsonResponse.put("recordsTotal", String.valueOf(pageContext.getTotalNumberOfItems()));
        jsonResponse.put("recordsFiltered", String.valueOf(pageContext.getTotalNumberOfItems()));
        jsonResponse.put("data", dgCollDataObjs);
    } catch (DataGridConnectionRefusedException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not search by metadata: ", e.getMessage());
    }
    try {
        jsonString = mapper.writeValueAsString(jsonResponse);
    } catch (JsonProcessingException e) {
        logger.error("Could not parse hashmap in metadata search to json: {}", e.getMessage());
    }
    return jsonString;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridSearchOperatorEnum(com.emc.metalnx.core.domain.entity.enums.DataGridSearchOperatorEnum) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) DataGridMetadataSearch(com.emc.metalnx.core.domain.entity.DataGridMetadataSearch) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with DataGridCollectionAndDataObject

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

the class DataGridUtils method mapMetadataResultSetToDataGridObjects.

/**
 * Maps a query result set coming from a metadata search into a list of data objects.
 *
 * @param queryResultSet
 *            sql result set returned from the execution of a specific query
 * @return List of data objects
 * @throws JargonException
 */
public static List<DataGridCollectionAndDataObject> mapMetadataResultSetToDataGridObjects(SpecificQueryResultSet queryResultSet) throws JargonException {
    List<DataGridCollectionAndDataObject> objs = new ArrayList<DataGridCollectionAndDataObject>();
    if (queryResultSet != null) {
        List<IRODSQueryResultRow> results = queryResultSet.getResults();
        for (IRODSQueryResultRow row : results) {
            String objName = row.getColumn("obj_name");
            String parentPath = row.getColumn("parent_path");
            String dataObjDisplaySize = MiscIRODSUtils.humanReadableByteCount(Long.valueOf(row.getColumn("size")));
            String path = parentPath + "/" + objName;
            if (parentPath.compareTo("/") == 0)
                path = parentPath + objName;
            DataGridCollectionAndDataObject obj = new DataGridCollectionAndDataObject();
            obj.setName(objName);
            obj.setPath(path);
            obj.setParentPath(parentPath);
            obj.setSize(Long.valueOf(row.getColumn("size")));
            obj.setDisplaySize(dataObjDisplaySize);
            obj.setOwner(row.getColumn("obj_owner"));
            obj.setCollection(false);
            obj.setReplicaNumber(row.getColumn("repl_num"));
            obj.setCreatedAt(IRODSDataConversionUtil.getDateFromIRODSValue(row.getColumn("create_ts")));
            obj.setModifiedAt(IRODSDataConversionUtil.getDateFromIRODSValue(row.getColumn("modify_ts")));
            obj.setResourceName(row.getColumn("resc_name"));
            obj.setNumberOfMatches(Integer.valueOf(row.getColumn("totalMatches")));
            objs.add(obj);
        }
    }
    return objs;
}
Also used : IRODSQueryResultRow(org.irods.jargon.core.query.IRODSQueryResultRow) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)

Example 14 with DataGridCollectionAndDataObject

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

the class DataGridUtils method mapPropertiesResultSetToDataGridObjects.

/**
 * Maps a query result set coming from a file properties search into a list of data objects.
 *
 * @param queryResultSet
 *            sql result set returned from the execution of a specific query
 * @return List of data objects
 * @throws JargonException
 */
public static List<DataGridCollectionAndDataObject> mapPropertiesResultSetToDataGridObjects(SpecificQueryResultSet queryResultSet) throws JargonException {
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = new ArrayList<DataGridCollectionAndDataObject>();
    if (queryResultSet != null) {
        List<IRODSQueryResultRow> results = queryResultSet.getResults();
        for (IRODSQueryResultRow irodsQueryResultRow : results) {
            DataGridCollectionAndDataObject dataGridObj = new DataGridCollectionAndDataObject();
            String objName = irodsQueryResultRow.getColumn(0);
            String dataObjDisplaySize = MiscIRODSUtils.humanReadableByteCount(Long.valueOf(irodsQueryResultRow.getColumn(4)));
            dataGridObj.setName(objName);
            dataGridObj.setPath(irodsQueryResultRow.getColumn(6));
            dataGridObj.setSize(Long.valueOf(irodsQueryResultRow.getColumn(4)));
            dataGridObj.setDisplaySize(dataObjDisplaySize);
            dataGridObj.setOwner(irodsQueryResultRow.getColumn(2));
            dataGridObj.setCollection(dataGridObj.getSize() == 0 ? true : false);
            dataGridObj.setReplicaNumber(irodsQueryResultRow.getColumn(1));
            dataGridObj.setCreatedAt(IRODSDataConversionUtil.getDateFromIRODSValue(irodsQueryResultRow.getColumn(8)));
            dataGridObj.setModifiedAt(IRODSDataConversionUtil.getDateFromIRODSValue(irodsQueryResultRow.getColumn(9)));
            dataGridObj.setNumberOfMatches(0);
            dataGridObj.setResourceName(irodsQueryResultRow.getColumn(5));
            dataGridObj.setChecksum(irodsQueryResultRow.getColumn(7));
            dataGridCollectionAndDataObjects.add(dataGridObj);
        }
    }
    return dataGridCollectionAndDataObjects;
}
Also used : IRODSQueryResultRow(org.irods.jargon.core.query.IRODSQueryResultRow) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)

Example 15 with DataGridCollectionAndDataObject

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

the class DataGridUtils method getDataGridCollectionAndDataObject.

/**
 * Maps a Data Object object from Jargon to the Metalnx representation of Data object
 *
 * @param dataObject
 *            data object instance to be mapped
 * @return DataGridCollectionAndDataObject instance the given Data object
 */
public static DataGridCollectionAndDataObject getDataGridCollectionAndDataObject(DataObject dataObject) {
    DataGridCollectionAndDataObject dataGridCollectionAndDataObject = new DataGridCollectionAndDataObject();
    dataGridCollectionAndDataObject.setName(dataObject.getDataName());
    dataGridCollectionAndDataObject.setPath(dataObject.getDataPath());
    dataGridCollectionAndDataObject.setReplicaNumber(String.valueOf(dataObject.getDataReplicationNumber()));
    dataGridCollectionAndDataObject.setChecksum(dataObject.getChecksum());
    dataGridCollectionAndDataObject.setCreatedAt(dataObject.getCreatedAt());
    dataGridCollectionAndDataObject.setModifiedAt(dataObject.getUpdatedAt());
    dataGridCollectionAndDataObject.setOwner(dataObject.getDataOwnerName());
    dataGridCollectionAndDataObject.setCollection(false);
    dataGridCollectionAndDataObject.setDisplaySize(dataObject.getDisplayDataSize());
    dataGridCollectionAndDataObject.setSize(dataObject.getDataSize());
    dataGridCollectionAndDataObject.setResourceName(dataObject.getResourceName());
    return dataGridCollectionAndDataObject;
}
Also used : DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)

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