Search in sources :

Example 6 with BasicReportDefinition

use of org.opennms.features.reporting.model.basicreport.BasicReportDefinition in project opennms by OpenNMS.

the class LegacyLocalReportRepository method getReports.

/**
 * {@inheritDoc}
 */
@Override
public List<BasicReportDefinition> getReports() {
    List<BasicReportDefinition> resultList = new ArrayList<>();
    for (BasicReportDefinition report : m_localReportsDao.getReports()) {
        BasicReportDefinition resultReport = new LegacyLocalReportDefinition();
        try {
            BeanUtils.copyProperties(resultReport, report);
            resultReport.setId(REPOSITORY_ID + "_" + report.getId());
            // Community reports are allowed by default, no permission restriction
            resultReport.setAllowAccess(true);
        } catch (IllegalAccessException e) {
            logger.error("IllegalAccessException during BeanUtils.copyProperties for BasicReportDefinion '{}'", e.getMessage());
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            logger.error("InvocationTargetException during BeanUtils.copyProperties for BasicReportDefinion '{}'", e.getMessage());
            e.printStackTrace();
        }
        resultList.add(resultReport);
    }
    return resultList;
}
Also used : LegacyLocalReportDefinition(org.opennms.features.reporting.model.basicreport.LegacyLocalReportDefinition) ArrayList(java.util.ArrayList) BasicReportDefinition(org.opennms.features.reporting.model.basicreport.BasicReportDefinition) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with BasicReportDefinition

use of org.opennms.features.reporting.model.basicreport.BasicReportDefinition in project opennms by OpenNMS.

the class DefaultRemoteRepository method getReports.

/**
 * {@inheritDoc}
 */
@Override
public List<BasicReportDefinition> getReports() {
    List<BasicReportDefinition> resultReports = new ArrayList<>();
    if (isConfigOk()) {
        WebTarget target = getTarget(m_remoteRepositoryDefintion.getURI() + "reports" + "/" + m_jasperReportsVersion);
        List<RemoteReportSDO> webCallResult = new ArrayList<>();
        try {
            webCallResult = getBuilder(target).get(new GenericType<List<RemoteReportSDO>>() {
            });
        } catch (Exception e) {
            logger.error("Error requesting report template from repository. Error message: '{}' Uri was: '{}'", e.getMessage(), target.getUri());
            e.printStackTrace();
        }
        logger.debug("getReports got '{}' RemoteReportSDOs from uri '{}'", webCallResult.size(), target.getUri());
        resultReports = this.mapSDOListToBasicReportList(webCallResult);
    }
    return resultReports;
}
Also used : RemoteReportSDO(org.opennms.features.reporting.sdo.RemoteReportSDO) GenericType(javax.ws.rs.core.GenericType) ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget) BasicReportDefinition(org.opennms.features.reporting.model.basicreport.BasicReportDefinition) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with BasicReportDefinition

use of org.opennms.features.reporting.model.basicreport.BasicReportDefinition in project opennms by OpenNMS.

the class LegacyLocalReportRepositoryTest method setUp.

/**
 * <p>setUp</p>
 * <p/>
 * Initialize and mockup the LegacyLocalReportRepository
 *
 * @throws Exception
 */
@Before
public void setUp() throws Exception {
    // Mocked report list as a result from DAOs
    List<BasicReportDefinition> reports = new ArrayList<>();
    List<BasicReportDefinition> onlineReports = new ArrayList<>();
    reports.add(new LegacyLocalReportDefinition());
    reports.add(new LegacyLocalReportDefinition());
    onlineReports.add(new LegacyLocalReportDefinition());
    // Mock DAOs for the local repository test
    LocalReportsDao m_localReportsDao = EasyMock.createMock(LocalReportsDao.class);
    LocalJasperReportsDao m_localJasperReportsDao = EasyMock.createMock(LocalJasperReportsDao.class);
    // TODO indigo: Mockup an InputStream with EasyMock is not trivial, InputStream isn't an interface
    // InputStream jrTemplateStream = EasyMock.createMock(InputStream.class);
    // EasyMock.expect(m_localJasperReportsDao.getTemplateStream("sample-report")).andReturn(jrTemplateStream);
    // Initialize the local report repository to provide reports from database-reports.xml and jasper-reports.xml
    m_legacyLocalReportRepository = new LegacyLocalReportRepository(m_localReportsDao, m_localJasperReportsDao);
    m_legacyLocalReportRepository.setLocalReportsDao(m_localReportsDao);
    m_legacyLocalReportRepository.setLocalJasperReportsDao(m_localJasperReportsDao);
    EasyMock.expect(m_localReportsDao.getOnlineReports()).andReturn(onlineReports);
    EasyMock.expect(m_localReportsDao.getDisplayName("sample-report")).andReturn("displayNameMockup");
    EasyMock.expect(m_localReportsDao.getReports()).andReturn(reports);
    EasyMock.expect(m_localReportsDao.getOnlineReports()).andReturn(onlineReports);
    EasyMock.expect(m_localReportsDao.getReportService("sample-report")).andReturn("jasperReportServiceMockup");
    EasyMock.expect(m_localJasperReportsDao.getTemplateLocation("sample-report")).andReturn("mocked-jdbc");
    EasyMock.expect(m_localJasperReportsDao.getEngine("sample-report")).andReturn("mocked-jdbc");
    EasyMock.replay(m_localReportsDao);
    EasyMock.replay(m_localJasperReportsDao);
    // Sanitycheck
    assertNotNull("Test if mocked DAO for database-reports.xml is not null", m_legacyLocalReportRepository.getLocalReportsDao());
    assertNotNull("Test if mocked DAo for jasper-reports.xml is not null", m_legacyLocalReportRepository.getLocalJasperReportsDao());
}
Also used : LegacyLocalReportDefinition(org.opennms.features.reporting.model.basicreport.LegacyLocalReportDefinition) ArrayList(java.util.ArrayList) LocalJasperReportsDao(org.opennms.features.reporting.dao.jasper.LocalJasperReportsDao) LocalReportsDao(org.opennms.features.reporting.dao.LocalReportsDao) BasicReportDefinition(org.opennms.features.reporting.model.basicreport.BasicReportDefinition) Before(org.junit.Before)

Example 9 with BasicReportDefinition

use of org.opennms.features.reporting.model.basicreport.BasicReportDefinition in project opennms by OpenNMS.

the class DefaultDatabaseReportListService method getAll.

/**
 * <p>
 * getAll Reports from all Repositories
 * </p>
 *
 * @return a {@link java.util.List} object.
 */
@Deprecated
@Override
public List<DatabaseReportDescription> getAll() {
    List<DatabaseReportDescription> allReports = new ArrayList<>();
    for (ReportRepository globalRepository : m_globalReportRepository.getRepositoryList()) {
        for (BasicReportDefinition report : globalRepository.getReports()) {
            DatabaseReportDescription summary = new DatabaseReportDescription();
            summary.setRepositoryId(globalRepository.getRepositoryId());
            summary.setId(report.getId());
            summary.setDisplayName(report.getDisplayName());
            summary.setDescription(report.getDescription());
            summary.setIsOnline(report.getOnline());
            summary.setAllowAccess(report.getAllowAccess());
            allReports.add(summary);
        }
    }
    return allReports;
}
Also used : DatabaseReportDescription(org.opennms.web.svclayer.model.DatabaseReportDescription) ArrayList(java.util.ArrayList) GlobalReportRepository(org.opennms.features.reporting.repository.global.GlobalReportRepository) ReportRepository(org.opennms.features.reporting.repository.ReportRepository) BasicReportDefinition(org.opennms.features.reporting.model.basicreport.BasicReportDefinition)

Example 10 with BasicReportDefinition

use of org.opennms.features.reporting.model.basicreport.BasicReportDefinition in project opennms by OpenNMS.

the class DefaultRemoteRepositoryTest method reportIdsWithRepoIdgetMappedToRemoteReportTest.

@Test
public void reportIdsWithRepoIdgetMappedToRemoteReportTest() {
    List<BasicReportDefinition> reports = m_defaultRemoteRepository.getReports();
    for (BasicReportDefinition report : reports) {
        assertTrue(m_defaultRemoteRepository.getDisplayName(report.getId()).length() > 0);
        logger.debug("'{}' \t '{}'", report.getId(), m_defaultRemoteRepository.getDisplayName(report.getId()));
    }
}
Also used : BasicReportDefinition(org.opennms.features.reporting.model.basicreport.BasicReportDefinition) Test(org.junit.Test)

Aggregations

BasicReportDefinition (org.opennms.features.reporting.model.basicreport.BasicReportDefinition)20 ArrayList (java.util.ArrayList)14 ReportRepository (org.opennms.features.reporting.repository.ReportRepository)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Test (org.junit.Test)4 DatabaseReportDescription (org.opennms.web.svclayer.model.DatabaseReportDescription)4 LegacyLocalReportDefinition (org.opennms.features.reporting.model.basicreport.LegacyLocalReportDefinition)3 GlobalReportRepository (org.opennms.features.reporting.repository.global.GlobalReportRepository)3 RemoteReportSDO (org.opennms.features.reporting.sdo.RemoteReportSDO)3 WebTarget (javax.ws.rs.client.WebTarget)2 GenericType (javax.ws.rs.core.GenericType)2 Before (org.junit.Before)2 HashMap (java.util.HashMap)1 ReportFormat (org.opennms.api.reporting.ReportFormat)1 LocalReportsDao (org.opennms.features.reporting.dao.LocalReportsDao)1 LocalJasperReportsDao (org.opennms.features.reporting.dao.jasper.LocalJasperReportsDao)1 SimpleJasperReportDefinition (org.opennms.features.reporting.model.jasperreport.SimpleJasperReportDefinition)1 DefaultDatabaseReportListService (org.opennms.web.svclayer.support.DefaultDatabaseReportListService)1