Search in sources :

Example 1 with DataSourceDumpReport

use of org.entando.entando.aps.system.init.model.DataSourceDumpReport in project entando-core by entando.

the class DatabaseManager method getDumpReport.

private DataSourceDumpReport getDumpReport(String subFolderName) throws ApsSystemException {
    InputStream is = null;
    DataSourceDumpReport report = null;
    try {
        String key = this.getLocalBackupsFolder() + subFolderName + File.separator + DUMP_REPORT_FILE_NAME;
        is = this.getStorageManager().getStream(key, true);
        String xml = FileTextReader.getText(is);
        report = new DataSourceDumpReport(xml);
    } catch (Throwable t) {
        logger.error("Error while extracting Dump Report of subfolder {}", subFolderName, t);
        throw new RuntimeException("Error while extracting Dump Report of subfolder " + subFolderName);
    } finally {
        if (null != is) {
            try {
                is.close();
            } catch (IOException ex) {
            }
        }
    }
    return report;
}
Also used : DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 2 with DataSourceDumpReport

use of org.entando.entando.aps.system.init.model.DataSourceDumpReport in project entando-core by entando.

the class DatabaseManager method getBackupReports.

@Override
public List<DataSourceDumpReport> getBackupReports() throws ApsSystemException {
    List<DataSourceDumpReport> reports = new ArrayList<DataSourceDumpReport>();
    try {
        // backupsFolder.list();
        String[] children = this.getStorageManager().listDirectory(this.getLocalBackupsFolder(), true);
        if (null == children || children.length == 0) {
            return null;
        }
        for (String subFolderName : children) {
            if (this.checkBackupFolder(subFolderName)) {
                DataSourceDumpReport report = this.getDumpReport(subFolderName);
                reports.add(report);
            }
        }
        Collections.sort(reports, new BeanComparator("date"));
    } catch (Throwable t) {
        logger.error("Error while extracting Backup Reports", t);
        throw new RuntimeException("Error while extracting Backup Reports");
    }
    return reports;
}
Also used : DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 3 with DataSourceDumpReport

use of org.entando.entando.aps.system.init.model.DataSourceDumpReport in project entando-core by entando.

the class DatabaseService method getShortDumpReportDtos.

@Override
public PagedMetadata<ShortDumpReportDto> getShortDumpReportDtos(RestListRequest requestList) {
    PagedMetadata<ShortDumpReportDto> result = null;
    List<ShortDumpReportDto> dtos = new ArrayList<>();
    try {
        List<DataSourceDumpReport> reports = this.getDatabaseManager().getBackupReports();
        if (null != reports) {
            reports.stream().forEach(report -> dtos.add(new ShortDumpReportDto(report)));
        }
        List<ShortDumpReportDto> sublist = requestList.getSublist(dtos);
        int size = (null != reports) ? reports.size() : 0;
        SearcherDaoPaginatedResult searchResult = new SearcherDaoPaginatedResult(size, sublist);
        result = new PagedMetadata<>(requestList, searchResult);
        result.setBody(sublist);
    } catch (Throwable t) {
        logger.error("error extracting database reports", t);
        throw new RestServerError("error extracting database reports", t);
    }
    return result;
}
Also used : DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) ShortDumpReportDto(org.entando.entando.aps.system.services.database.model.ShortDumpReportDto)

Example 4 with DataSourceDumpReport

use of org.entando.entando.aps.system.init.model.DataSourceDumpReport in project entando-core by entando.

the class DatabaseServiceTest method getValidReport.

@Test
public void getValidReport() throws Throwable {
    String xml = null;
    DataSourceDumpReport report = new DataSourceDumpReport(xml);
    when(databaseManager.getBackupReport(ArgumentMatchers.anyString())).thenReturn(report);
    DumpReportDto dto = this.databaseService.getDumpReportDto("reportCode");
    Assert.assertNotNull(dto);
}
Also used : DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) DumpReportDto(org.entando.entando.aps.system.services.database.model.DumpReportDto) Test(org.junit.Test)

Example 5 with DataSourceDumpReport

use of org.entando.entando.aps.system.init.model.DataSourceDumpReport in project entando-core by entando.

the class DatabaseControllerTest method getReport_1.

@Test
public void getReport_1() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String xml = null;
    DataSourceDumpReport report = new DataSourceDumpReport(xml);
    when(databaseManager.getBackupReport(ArgumentMatchers.anyString())).thenReturn(report);
    ResultActions result = mockMvc.perform(get("/database/report/{reportCode}", new Object[] { "develop" }).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Aggregations

DataSourceDumpReport (org.entando.entando.aps.system.init.model.DataSourceDumpReport)10 Test (org.junit.Test)4 UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)3 ResultActions (org.springframework.test.web.servlet.ResultActions)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 RestServerError (org.entando.entando.aps.system.exception.RestServerError)2 Component (org.entando.entando.aps.system.init.model.Component)2 DumpReportDto (org.entando.entando.aps.system.services.database.model.DumpReportDto)2 ShortDumpReportDto (org.entando.entando.aps.system.services.database.model.ShortDumpReportDto)2 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)1 Resource (org.springframework.core.io.Resource)1