Search in sources :

Example 1 with Document

use of org.hisp.dhis.document.Document in project dhis2-core by dhis2.

the class DashboardTest method testGetAvailableItemByType.

@Test
public void testGetAvailableItemByType() {
    Dashboard dashboard = new Dashboard();
    DashboardItem diA = new DashboardItem();
    DashboardItem diB = new DashboardItem();
    DashboardItem diC = new DashboardItem();
    diA.setUid("A");
    diB.setUid("B");
    diC.setUid("C");
    diA.setChart(new Chart("A"));
    diB.getReports().add(new Report("A", null, null, null));
    diB.getReports().add(new Report("B", null, null, null));
    diC.getResources().add(new Document("A", null, false, null));
    diC.getResources().add(new Document("B", null, false, null));
    diC.getResources().add(new Document("C", null, false, null));
    dashboard.getItems().add(diA);
    dashboard.getItems().add(diB);
    dashboard.getItems().add(diC);
    assertEquals(diB, dashboard.getAvailableItemByType(DashboardItemType.REPORTS));
    assertEquals(diC, dashboard.getAvailableItemByType(DashboardItemType.RESOURCES));
    assertNull(dashboard.getAvailableItemByType(DashboardItemType.MAP));
}
Also used : Report(org.hisp.dhis.report.Report) Document(org.hisp.dhis.document.Document) Chart(org.hisp.dhis.chart.Chart) Test(org.junit.Test)

Example 2 with Document

use of org.hisp.dhis.document.Document in project dhis2-core by dhis2.

the class SaveDocumentAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    Document document = id == null ? new Document() : documentService.getDocument(id);
    if (document == null) {
        throw new RuntimeException("Document with id " + id + " was not found");
    }
    if (file != null) {
        if (document.getFileResource() != null) {
            documentService.deleteFileFromDocument(document);
        }
        document.setUrl(fileName);
        document.setFileResource(uploadFile(file, fileName, contentType));
        document.setContentType(contentType);
    } else if (external) {
        document.setUrl(getValidUrl(url));
    }
    document.setName(name);
    document.setExternal(external);
    document.setAttachment(attachment);
    documentService.saveDocument(document);
    if (jsonAttributeValues != null) {
        attributeService.updateAttributeValues(document, jsonAttributeValues);
    }
    documentService.saveDocument(document);
    return SUCCESS;
}
Also used : Document(org.hisp.dhis.document.Document)

Example 3 with Document

use of org.hisp.dhis.document.Document in project dhis2-core by dhis2.

the class RemoveDocumentAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    if (id != null) {
        Document document = documentService.getDocument(id);
        documentService.deleteDocument(document);
    }
    return SUCCESS;
}
Also used : Document(org.hisp.dhis.document.Document)

Example 4 with Document

use of org.hisp.dhis.document.Document in project dhis2-core by dhis2.

the class DashboardServiceTest method setUpTest.

@Override
public void setUpTest() {
    chartA = createChart('A');
    chartB = createChart('B');
    chartService.addChart(chartA);
    chartService.addChart(chartB);
    Document docA = new Document("A", "url", false, null);
    Document docB = new Document("B", "url", false, null);
    Document docC = new Document("C", "url", false, null);
    Document docD = new Document("D", "url", false, null);
    documentService.saveDocument(docA);
    documentService.saveDocument(docB);
    documentService.saveDocument(docC);
    documentService.saveDocument(docD);
    diA = new DashboardItem();
    diA.setAutoFields();
    diA.setChart(chartA);
    diB = new DashboardItem();
    diB.setAutoFields();
    diB.setChart(chartB);
    diC = new DashboardItem();
    diC.setAutoFields();
    diC.getResources().add(docA);
    diC.getResources().add(docB);
    diD = new DashboardItem();
    diD.setAutoFields();
    diD.getResources().add(docC);
    diD.getResources().add(docD);
    dA = new Dashboard("A");
    dA.setAutoFields();
    dA.getItems().add(diA);
    dA.getItems().add(diB);
    dA.getItems().add(diC);
    dB = new Dashboard("B");
    dB.setAutoFields();
    dB.getItems().add(diD);
}
Also used : Document(org.hisp.dhis.document.Document)

Aggregations

Document (org.hisp.dhis.document.Document)4 Chart (org.hisp.dhis.chart.Chart)1 Report (org.hisp.dhis.report.Report)1 Test (org.junit.Test)1