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();
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations