Search in sources :

Example 1 with DataGridMetadataSearch

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

the class PostgresSpecificQueryProviderImpl method buildSpecificQueryForMetadataSearch.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.emc.metalnx.services.irods.utils.SpecificQueryProvider#
	 * buildSpecificQueryForMetadataSearch(java.util.List, java.lang.String,
	 * boolean)
	 */
@Override
public String buildSpecificQueryForMetadataSearch(List<DataGridMetadataSearch> metadataSearch, String zone, boolean searchAgainstColls) {
    // This is the first part of the query. It selects all objects (collections or
    // data objects)
    // that has a piece of metadata matching the query
    StringBuilder objQuery = new StringBuilder();
    // This is the query that actually looks for metadata tags in the data grid.
    StringBuilder metadataSearchQuery = new StringBuilder();
    // This is the last part of the query. It groups the objects by their attributes
    // in order to
    // have unique results.
    StringBuilder gb = new StringBuilder();
    // This is the final query that will be sent to the data grid database
    StringBuilder q = new StringBuilder();
    if (searchAgainstColls) {
        objQuery.append(" SELECT obj_name, parent_path, obj_owner, create_ts, modify_ts, resc_name, totalMatches");
        objQuery.append(" FROM (");
        objQuery.append(" SELECT c.coll_name as obj_name,");
        objQuery.append("      c.parent_coll_name as parent_path,");
        objQuery.append("      c.coll_owner_name as obj_owner,");
        objQuery.append("      c.create_ts as create_ts,");
        objQuery.append("      c.modify_ts as modify_ts,");
        objQuery.append("      '' as resc_name,");
        objQuery.append("      c.coll_inheritance,");
        objQuery.append("      COUNT(c.coll_name) as totalMatches");
        objQuery.append(" FROM ");
        objQuery.append("      r_coll_main c ");
        objQuery.append(" JOIN ( ");
        gb.append(" ) AS coll_metadata ON (c.coll_id = map_object_id) ");
        gb.append(" GROUP BY ");
        gb.append("      c.coll_name,");
        gb.append("      c.parent_coll_name,");
        gb.append("      c.coll_owner_name,");
        gb.append("      c.create_ts,");
        gb.append("      c.modify_ts,");
        gb.append("      resc_name,");
        gb.append("      c.coll_inheritance");
        gb.append(" ORDER BY totalMatches DESC, c.coll_name ");
        gb.append(" ) AS ms ");
    } else {
        objQuery.append(" SELECT obj_name, size, obj_owner, repl_num, create_ts, modify_ts, resc_name, parent_path, totalMatches");
        objQuery.append(" FROM (");
        objQuery.append(" SELECT ");
        objQuery.append("      d.data_name as obj_name, ");
        objQuery.append("      d.data_size as size,  ");
        objQuery.append("      d.data_owner_name as obj_owner, ");
        objQuery.append("      d.data_repl_num as repl_num, ");
        objQuery.append("      d.create_ts as create_ts,");
        objQuery.append("      d.modify_ts as modify_ts, ");
        objQuery.append("      d.resc_name as resc_name, ");
        objQuery.append("      c.coll_name as parent_path,");
        objQuery.append("      COUNT(d.data_name) as totalMatches");
        objQuery.append(" FROM r_data_main d ");
        objQuery.append(" JOIN r_coll_main c ON (d.coll_id = c.coll_id) ");
        objQuery.append(" JOIN ( ");
        gb.append(" ) AS data_obj_metadata ON (d.data_id = map_object_id) ");
        gb.append(" GROUP BY ");
        gb.append("      d.data_name,");
        gb.append("      d.data_size,");
        gb.append("      d.data_owner_name,");
        gb.append("      d.data_repl_num,");
        gb.append("      d.create_ts,");
        gb.append("      d.modify_ts,");
        gb.append("      d.resc_name, ");
        gb.append("      c.coll_name");
        gb.append(" ORDER BY totalMatches DESC, d.data_name ");
        gb.append(" ) AS ms ");
    }
    for (DataGridMetadataSearch d : metadataSearch) {
        metadataSearchQuery.append(d.getSpecQueryAsString());
        // appending conditions
        if (metadataSearch.indexOf(d) != metadataSearch.size() - 1) {
            metadataSearchQuery.append(" UNION ALL ");
        }
    }
    // combining the three parts of the metadata query into a single SQL query
    q.append(objQuery.toString());
    q.append(metadataSearchQuery.toString());
    q.append(gb.toString());
    return q.toString();
}
Also used : DataGridMetadataSearch(com.emc.metalnx.core.domain.entity.DataGridMetadataSearch)

Example 2 with DataGridMetadataSearch

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

the class SpecQueryServiceImplTest method testCountCollectionsMatchingMetadata.

@Test
public void testCountCollectionsMatchingMetadata() throws Exception {
    SpecQueryServiceImpl specQueryService = new SpecQueryServiceImpl();
    IRODSServices irodsService = Mockito.mock(IRODSServices.class);
    AdminServices adminServices = Mockito.mock(AdminServices.class);
    IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(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<DataGridMetadataSearch> metadataSearch = new ArrayList<DataGridMetadataSearch>();
    DataGridMetadataSearch search = new DataGridMetadataSearch(COLL_AVU_ATTR1, COLL_AVU_VAL1, "", DataGridSearchOperatorEnum.EQUAL);
    metadataSearch.add(search);
    int count = specQueryService.countCollectionsMatchingMetadata(metadataSearch, irodsAccount.getZone());
    Assert.assertTrue("no recs returned", count > 1);
}
Also used : EnvironmentalInfoAO(org.irods.jargon.core.pub.EnvironmentalInfoAO) AdminServices(com.emc.metalnx.services.interfaces.AdminServices) DataGridMetadataSearch(com.emc.metalnx.core.domain.entity.DataGridMetadataSearch) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) ArrayList(java.util.ArrayList) IRODSServices(com.emc.metalnx.services.interfaces.IRODSServices) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) Test(org.junit.Test)

Example 3 with DataGridMetadataSearch

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

the class SpecQueryServiceImplTest method testSearchByMetadataCollections.

@Test
public void testSearchByMetadataCollections() throws Exception {
    SpecQueryServiceImpl specQueryService = new SpecQueryServiceImpl();
    IRODSServices irodsService = Mockito.mock(IRODSServices.class);
    AdminServices adminServices = Mockito.mock(AdminServices.class);
    IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(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<DataGridMetadataSearch> metadataSearch = new ArrayList<DataGridMetadataSearch>();
    DataGridMetadataSearch search = new DataGridMetadataSearch(COLL_AVU_ATTR1, COLL_AVU_VAL1, "", DataGridSearchOperatorEnum.EQUAL);
    metadataSearch.add(search);
    SpecificQueryResultSet result = specQueryService.searchByMetadata(metadataSearch, irodsAccount.getZone(), true, null, 0, 0);
    Assert.assertFalse("no result", result.getResults().isEmpty());
}
Also used : EnvironmentalInfoAO(org.irods.jargon.core.pub.EnvironmentalInfoAO) AdminServices(com.emc.metalnx.services.interfaces.AdminServices) DataGridMetadataSearch(com.emc.metalnx.core.domain.entity.DataGridMetadataSearch) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) 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)

Example 4 with DataGridMetadataSearch

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

the class SpecQueryServiceImplTest method testCountDataObjectsMatchingMetadata.

@Test
public void testCountDataObjectsMatchingMetadata() throws Exception {
    SpecQueryServiceImpl specQueryService = new SpecQueryServiceImpl();
    IRODSServices irodsService = Mockito.mock(IRODSServices.class);
    AdminServices adminServices = Mockito.mock(AdminServices.class);
    IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(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<DataGridMetadataSearch> metadataSearch = new ArrayList<DataGridMetadataSearch>();
    DataGridMetadataSearch search = new DataGridMetadataSearch(DATA_AVU_ATTR1, DATA_AVU_VAL1, "", DataGridSearchOperatorEnum.EQUAL);
    metadataSearch.add(search);
    int count = specQueryService.countDataObjectsMatchingMetadata(metadataSearch, irodsAccount.getZone());
    Assert.assertTrue("no recs returned", count > 1);
}
Also used : EnvironmentalInfoAO(org.irods.jargon.core.pub.EnvironmentalInfoAO) AdminServices(com.emc.metalnx.services.interfaces.AdminServices) DataGridMetadataSearch(com.emc.metalnx.core.domain.entity.DataGridMetadataSearch) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) ArrayList(java.util.ArrayList) IRODSServices(com.emc.metalnx.services.interfaces.IRODSServices) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) Test(org.junit.Test)

Example 5 with DataGridMetadataSearch

use of com.emc.metalnx.core.domain.entity.DataGridMetadataSearch 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)

Aggregations

DataGridMetadataSearch (com.emc.metalnx.core.domain.entity.DataGridMetadataSearch)9 Test (org.junit.Test)6 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 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 DataGridSearchOperatorEnum (com.emc.metalnx.core.domain.entity.enums.DataGridSearchOperatorEnum)1 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)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 SimpleDateFormat (java.text.SimpleDateFormat)1