Search in sources :

Example 1 with DataGridFilePropertySearch

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

the class PostgresSpecificQueryProviderImpl method buildQueryForFilePropertiesSearch.

@Override
public String buildQueryForFilePropertiesSearch(List<DataGridFilePropertySearch> filePropertiesSearches, String zone, boolean searchAgainstColls, int offset, int limit) {
    StringBuilder query = new StringBuilder();
    if (filePropertiesSearches.size() > 0) {
        if (searchAgainstColls) {
            query.append(buildSelectClauseForCollectionsForPropertiesSearch());
        } else {
            query.append(buildSelectClauseForDataObjectsForPropertiesSearch());
        }
        for (DataGridFilePropertySearch filePropertiesSearch : filePropertiesSearches) {
            // where clause - conditions
            query.append(buildWhereClauseForDataGridPropertySearch(filePropertiesSearch.getAttribute(), filePropertiesSearch.getOperator(), filePropertiesSearch.getValue()));
            // appending conditions
            if (filePropertiesSearches.indexOf(filePropertiesSearch) != filePropertiesSearches.size() - 1) {
                query.append(" AND ");
            }
        }
    }
    if (offset == 0 && limit == 0) {
    // ignored
    } else {
        query.append(" OFFSET ");
        query.append(offset);
        query.append(" LIMIT ");
        query.append(limit);
    }
    return query.toString();
}
Also used : DataGridFilePropertySearch(com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch)

Example 2 with DataGridFilePropertySearch

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

the class SpecQueryServiceImplTest method testSearchByFilePropertiesForCollections.

@Test
public void testSearchByFilePropertiesForCollections() 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, test3Account.getUserName());
    filePropertiesSearch.add(dataSearch);
    SpecificQueryResultSet result = specQueryService.searchByFileProperties(filePropertiesSearch, 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) 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)

Example 3 with DataGridFilePropertySearch

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

the class SpecQueryServiceImplTest method testCountCollectionsMatchingFileProperties.

@Test
public void testCountCollectionsMatchingFileProperties() 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<DataGridFilePropertySearch> filePropertiesSearch = new ArrayList<>();
    DataGridFilePropertySearch dataSearch = new DataGridFilePropertySearch(FilePropertyField.OWNER_NAME, DataGridSearchOperatorEnum.EQUAL, irodsAccount.getUserName());
    filePropertiesSearch.add(dataSearch);
    int count = specQueryService.countCollectionsMatchingFileProperties(filePropertiesSearch, 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) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) DataGridFilePropertySearch(com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch) ArrayList(java.util.ArrayList) IRODSServices(com.emc.metalnx.services.interfaces.IRODSServices) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) Test(org.junit.Test)

Example 4 with DataGridFilePropertySearch

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

the class SpecQueryServiceImplTest method testCountDataObjectsMatchingFileProperties.

@Test
public void testCountDataObjectsMatchingFileProperties() 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<DataGridFilePropertySearch> filePropertiesSearch = new ArrayList<>();
    DataGridFilePropertySearch dataSearch = new DataGridFilePropertySearch(FilePropertyField.OWNER_NAME, DataGridSearchOperatorEnum.EQUAL, irodsAccount.getUserName());
    filePropertiesSearch.add(dataSearch);
    dataSearch = new DataGridFilePropertySearch(FilePropertyField.SIZE, DataGridSearchOperatorEnum.BIGGER_THAN, "200");
    filePropertiesSearch.add(dataSearch);
    int count = specQueryService.countDataObjectsMatchingFileProperties(filePropertiesSearch, 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) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) DataGridFilePropertySearch(com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch) 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 DataGridFilePropertySearch

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

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