Search in sources :

Example 6 with DataGridFilePropertySearch

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

the class FilePropertiesController method search.

@RequestMapping(value = "/search")
@ResponseBody
public String search(@RequestParam(value = "jsonFilePropertySearch", required = false) final String jsonFilePropertySearch, @RequestParam("draw") final int draw, @RequestParam("start") final int start, @RequestParam("length") final int length) throws DataGridConnectionRefusedException, JargonException {
    if (jsonFilePropertySearch != null) {
        currentPage = (int) (Math.floor(start / length) + 1);
        this.jsonFilePropertySearch = jsonFilePropertySearch;
    }
    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 {
        JsonNode jsonNode = mapper.readTree(this.jsonFilePropertySearch);
        currentFilePropertySearch = new ArrayList<>();
        JsonNode attributes = jsonNode.get("attribute");
        JsonNode operators = jsonNode.get("operator");
        JsonNode values = jsonNode.get("value");
        for (int i = 0; i < attributes.size(); i++) {
            DataGridFilePropertySearch ms = new DataGridFilePropertySearch(FilePropertyField.valueOf(attributes.get(i).textValue()), DataGridSearchOperatorEnum.valueOf(operators.get(i).textValue()), values.get(i).textValue());
            currentFilePropertySearch.add(ms);
        }
        DataGridPageContext pageContext = new DataGridPageContext();
        List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = filePropertyService.findByFileProperties(currentFilePropertySearch, pageContext, currentPage, length);
        jsonResponse.put("recordsTotal", String.valueOf(pageContext.getTotalNumberOfItems()));
        jsonResponse.put("recordsFiltered", String.valueOf(pageContext.getTotalNumberOfItems()));
        jsonResponse.put("data", dataGridCollectionAndDataObjects);
    } catch (DataGridConnectionRefusedException e) {
        logger.error("data grid error in search", e);
        throw e;
    } catch (JargonException e) {
        logger.error("Could not search by metadata: ", e.getMessage());
        throw e;
    } catch (ParseException e) {
        logger.error("Could not search by metadata: ", e.getMessage());
        throw new JargonException(e);
    } catch (JsonProcessingException e) {
        logger.error("Could not search by metadata: ", e.getMessage());
        throw new JargonException(e);
    } catch (IOException e) {
        logger.error("Could not search by metadata: ", e.getMessage());
        throw new JargonException(e);
    }
    try {
        jsonString = mapper.writeValueAsString(jsonResponse);
    } catch (JsonProcessingException e) {
        logger.error("Could not parse hashmap in file properties search to json: {}", e.getMessage());
        throw new JargonException(e);
    }
    return jsonString;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) HashMap(java.util.HashMap) JargonException(org.irods.jargon.core.exception.JargonException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) DataGridFilePropertySearch(com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) ParseException(java.text.ParseException) 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 7 with DataGridFilePropertySearch

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

the class SpecQueryServiceImplTest method testSearchByFilePropertiesForDataObjects.

@Test
public void testSearchByFilePropertiesForDataObjects() throws Exception {
    SpecQueryServiceImpl specQueryService = new SpecQueryServiceImpl();
    IRODSServices irodsService = Mockito.mock(IRODSServices.class);
    AdminServices adminServices = Mockito.mock(AdminServices.class);
    IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties);
    IRODSAccount test3Account = testingPropertiesHelper.buildIRODSAccountFromSecondaryTestProperties(testingProperties);
    EnvironmentalInfoAO environmentalInfoAO = irodsFileSystem.getIRODSAccessObjectFactory().getEnvironmentalInfoAO(irodsAccount);
    SpecificQueryAO specificQueryAO = irodsFileSystem.getIRODSAccessObjectFactory().getSpecificQueryAO(irodsAccount);
    Mockito.when(irodsService.getEnvironmentalInfoAO()).thenReturn(environmentalInfoAO);
    Mockito.when(adminServices.getSpecificQueryAO()).thenReturn(specificQueryAO);
    specQueryService.setIrodsServices(irodsService);
    specQueryService.setAdminServices(adminServices);
    List<DataGridFilePropertySearch> filePropertiesSearch = new ArrayList<>();
    DataGridFilePropertySearch dataSearch = new DataGridFilePropertySearch(FilePropertyField.OWNER_NAME, DataGridSearchOperatorEnum.EQUAL, // use test3 because its smaller
    test3Account.getUserName());
    filePropertiesSearch.add(dataSearch);
    dataSearch = new DataGridFilePropertySearch(FilePropertyField.SIZE, DataGridSearchOperatorEnum.BIGGER_THAN, "200");
    filePropertiesSearch.add(dataSearch);
    SpecificQueryResultSet result = specQueryService.searchByFileProperties(filePropertiesSearch, irodsAccount.getZone(), false, null, 0, 0);
    Assert.assertNotNull("no result", result.getResults());
}
Also used : EnvironmentalInfoAO(org.irods.jargon.core.pub.EnvironmentalInfoAO) AdminServices(com.emc.metalnx.services.interfaces.AdminServices) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) DataGridFilePropertySearch(com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch) ArrayList(java.util.ArrayList) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) IRODSServices(com.emc.metalnx.services.interfaces.IRODSServices) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) Test(org.junit.Test)

Aggregations

DataGridFilePropertySearch (com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch)7 AdminServices (com.emc.metalnx.services.interfaces.AdminServices)4 IRODSServices (com.emc.metalnx.services.interfaces.IRODSServices)4 ArrayList (java.util.ArrayList)4 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)4 EnvironmentalInfoAO (org.irods.jargon.core.pub.EnvironmentalInfoAO)4 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)4 Test (org.junit.Test)4 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)2 DataGridPageContext (com.emc.metalnx.core.domain.entity.DataGridPageContext)2 SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1