Search in sources :

Example 1 with ReportsResult

use of org.activityinfo.shared.command.result.ReportsResult in project activityinfo by bedatadriven.

the class GetReportsTest method selectByUser2.

@Test
public void selectByUser2() {
    setUser(2);
    ReportsResult result = execute(new GetReports());
    assertNotNull(result);
    assertThat(result.getData().size(), equalTo(1));
    assertEquals(2, result.getData().get(0).getId());
    assertEquals("Report 1", result.getData().get(0).getTitle());
    assertEquals("Bavon", result.getData().get(0).getOwnerName());
}
Also used : GetReports(org.activityinfo.shared.command.GetReports) ReportsResult(org.activityinfo.shared.command.result.ReportsResult) Test(org.junit.Test)

Example 2 with ReportsResult

use of org.activityinfo.shared.command.result.ReportsResult in project activityinfo by bedatadriven.

the class GetReportsHandler method execute.

@Override
public void execute(final GetReports command, final ExecutionContext context, final AsyncCallback<ReportsResult> callback) {
    // note that we are excluding reports with a null title-- these
    // reports have not yet been explicitly saved by the user
    SqlQuery mySubscriptions = SqlQuery.selectAll().from(Tables.REPORT_SUBSCRIPTION).where("userId").equalTo(context.getUser().getUserId());
    SqlQuery myDatabases = SqlQuery.selectSingle("d.databaseid").from(Tables.USER_DATABASE, "d").leftJoin(SqlQuery.selectAll().from(Tables.USER_PERMISSION).where("userpermission.UserId").equalTo(context.getUser().getId()), "p").on("p.DatabaseId = d.DatabaseId").where("d.ownerUserId").equalTo(context.getUser().getUserId()).or("p.AllowView").equalTo(1);
    SqlQuery.select().appendColumn("r.reportTemplateId", "reportId").appendColumn("r.title", "title").appendColumn("r.ownerUserId", "ownerUserId").appendColumn("o.name", "ownerName").appendColumn("s.dashboard", "dashboard").appendColumn("s.emaildelivery", "emaildelivery").appendColumn("s.emailday", "emailday").appendColumn(SqlQuery.selectSingle("max(defaultDashboard)").from(Tables.REPORT_VISIBILITY, "v").where("v.databaseId").in(myDatabases).whereTrue("v.reportid=r.reportTemplateId"), "defaultDashboard").from(Tables.REPORT_TEMPLATE, "r").leftJoin(Tables.USER_LOGIN, "o").on("o.userid=r.ownerUserId").leftJoin(mySubscriptions, "s").on("r.reportTemplateId=s.reportId").whereTrue("r.title is not null").where("r.ownerUserId").equalTo(context.getUser().getId()).or("r.reportTemplateId").in(SqlQuery.select("reportId").from(Tables.REPORT_VISIBILITY, "v").where("v.databaseid").in(myDatabases)).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(final SqlTransaction tx, final SqlResultSet results) {
            List<ReportMetadataDTO> dtos = Lists.newArrayList();
            for (SqlResultSetRow row : results.getRows()) {
                ReportMetadataDTO dto = new ReportMetadataDTO();
                dto.setId(row.getInt("reportId"));
                dto.setAmOwner(row.getInt("ownerUserId") == context.getUser().getId());
                dto.setOwnerName(row.getString("ownerName"));
                dto.setTitle(row.getString("title"));
                dto.setEditAllowed(dto.getAmOwner());
                if (!row.isNull("emaildelivery")) {
                    dto.setEmailDelivery(EmailDelivery.valueOf(row.getString("emaildelivery")));
                }
                if (row.isNull("emailday")) {
                    dto.setDay(1);
                } else {
                    dto.setDay(row.getInt("emailday"));
                }
                if (row.isNull("dashboard")) {
                    // inherited from database-wide visibility
                    dto.setDashboard(!row.isNull("defaultDashboard") && row.getBoolean("defaultDashboard"));
                } else {
                    dto.setDashboard(row.getBoolean("dashboard"));
                }
                dtos.add(dto);
            }
            callback.onSuccess(new ReportsResult(dtos));
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) ReportsResult(org.activityinfo.shared.command.result.ReportsResult) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) List(java.util.List) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) ReportMetadataDTO(org.activityinfo.shared.dto.ReportMetadataDTO)

Example 3 with ReportsResult

use of org.activityinfo.shared.command.result.ReportsResult in project activityinfo by bedatadriven.

the class GetReportsTest method selectByUser1.

@Test
public void selectByUser1() {
    setUser(1);
    ReportsResult result = execute(new GetReports());
    assertNotNull(result);
    assertTrue(result.getData().size() == 2);
    assertEquals(1, result.getData().get(0).getId());
    assertEquals("Report 1", result.getData().get(0).getTitle());
    assertEquals("Alex", result.getData().get(0).getOwnerName());
    assertEquals(3, result.getData().get(1).getId());
    assertEquals("Report 3", result.getData().get(1).getTitle());
    assertEquals("Alex", result.getData().get(1).getOwnerName());
}
Also used : GetReports(org.activityinfo.shared.command.GetReports) ReportsResult(org.activityinfo.shared.command.result.ReportsResult) Test(org.junit.Test)

Example 4 with ReportsResult

use of org.activityinfo.shared.command.result.ReportsResult in project activityinfo by bedatadriven.

the class ReportVisibilityTest method update.

@Test
public void update() {
    setUser(1);
    ReportVisibilityDTO db1 = new ReportVisibilityDTO();
    db1.setDatabaseId(1);
    db1.setVisible(true);
    db1.setDefaultDashboard(true);
    ReportVisibilityDTO db2 = new ReportVisibilityDTO();
    db2.setDatabaseId(2);
    db2.setVisible(false);
    ReportVisibilityDTO db3 = new ReportVisibilityDTO();
    db3.setDatabaseId(3);
    db3.setVisible(true);
    UpdateReportVisibility update = new UpdateReportVisibility(1, Arrays.asList(db1, db2, db3));
    execute(update);
    ReportVisibilityResult result = execute(new GetReportVisibility(1));
    assertThat(result.getList().size(), equalTo(2));
    // make sure we can still see the report
    ReportsResult visibleToMe = execute(new GetReports());
    assertThat(visibleToMe.getData().size(), equalTo(1));
    // Bavon
    setUser(2);
    ReportsResult visibleToBavon = execute(new GetReports());
    assertThat(visibleToBavon.getData().size(), equalTo(2));
    assertThat(getById(visibleToBavon, 1).isDashboard(), equalTo(true));
    assertThat(getById(visibleToBavon, 2).isDashboard(), equalTo(false));
    // Stefan, no access to db
    setUser(3);
    ReportsResult visibleToStefan = execute(new GetReports());
    assertThat(visibleToStefan.getData().size(), equalTo(0));
}
Also used : ReportVisibilityDTO(org.activityinfo.shared.dto.ReportVisibilityDTO) ReportVisibilityResult(org.activityinfo.shared.command.result.ReportVisibilityResult) ReportsResult(org.activityinfo.shared.command.result.ReportsResult) Test(org.junit.Test)

Aggregations

ReportsResult (org.activityinfo.shared.command.result.ReportsResult)4 Test (org.junit.Test)3 GetReports (org.activityinfo.shared.command.GetReports)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)1 List (java.util.List)1 ReportVisibilityResult (org.activityinfo.shared.command.result.ReportVisibilityResult)1 ReportMetadataDTO (org.activityinfo.shared.dto.ReportMetadataDTO)1 ReportVisibilityDTO (org.activityinfo.shared.dto.ReportVisibilityDTO)1