/* (non-Javadoc)
   * @see org.sakaiproject.entity.api.EntityTransferrer#transferCopyEntities(java.lang.String, java.lang.String, java.util.List, boolean)
   */
  public void transferCopyEntities(
      String fromContext, String toContext, List ids, boolean cleanup) {
    // determine report definitions to copy
    List<ReportDef> list = null;
    if (ids != null && ids.size() > 0) {
      list = new ArrayList<ReportDef>();
      for (String id : (List<String>) ids) {
        ReportDef rd = M_rm.getReportDefinition(Long.valueOf(id));
        if (rd != null) {
          list.add(rd);
        }
      }
    } else {
      list = M_rm.getReportDefinitions(fromContext, false, true);
    }

    // cleanup existing reports on destination site before copying
    if (cleanup) {
      List<ReportDef> listToCleanUp = M_rm.getReportDefinitions(toContext, false, true);
      for (ReportDef rd : listToCleanUp) {
        M_rm.removeReportDefinition(rd);
      }
    }

    // copy to destination
    for (ReportDef rd : list) {
      rd.setId(0);
      rd.setSiteId(toContext);
      rd.getReportParams().setSiteId(toContext);
      M_rm.saveReportDefinition(rd);
    }
  }
示例#2
0
  public void testLoadSaveReports() {
    String siteId = null;
    Report r = null;
    ReportParams rp = null;
    List<String> totalsBy = null;

    siteId = FakeData.SITE_A_ID;
    ReportDef rd = new ReportDef();
    rd.setId(0);
    rd.setSiteId(siteId);
    rd.setCreatedBy(FakeData.USER_A_ID);
    rd.setModifiedBy(FakeData.USER_A_ID);
    rd.setTitle("Title 1");
    rp = new ReportParams(siteId);
    rp.setWhat(ReportManager.WHAT_RESOURCES);
    rp.setWhen(ReportManager.WHEN_ALL);
    rp.setWho(ReportManager.WHO_ALL);
    totalsBy = new ArrayList<String>();
    totalsBy.add(StatsManager.T_SITE);
    totalsBy.add(StatsManager.T_USER);
    rp.setHowTotalsBy(totalsBy);
    rp.setHowSort(false);
    rp.setHowPresentationMode(ReportManager.HOW_PRESENTATION_TABLE);
    rd.setReportParams(rp);

    // non-existent
    try {
      assertNull(M_rm.getReportDefinition(100));
    } catch (Exception e) {
      assertTrue(true);
    }
    // normal
    assertTrue(M_rm.saveReportDefinition(rd));
    assertNotNull(M_rm.getReportDefinition(1));
    // hidden
    ReportDef rd2 = new ReportDef();
    rd2.setId(0);
    rd2.setSiteId(siteId);
    rd2.setCreatedBy(FakeData.USER_A_ID);
    rd2.setModifiedBy(FakeData.USER_A_ID);
    rd2.setTitle("Title 2");
    rd2.setHidden(true);
    rd2.setReportParams(new ReportParams());
    assertTrue(M_rm.saveReportDefinition(rd2));
    // pre-defined
    ReportDef rd3 = new ReportDef();
    rd3.setId(0);
    rd3.setSiteId(null);
    rd3.setCreatedBy(FakeData.USER_A_ID);
    rd3.setModifiedBy(FakeData.USER_A_ID);
    rd3.setTitle("Title 3");
    rd3.setHidden(false);
    rd3.setReportParams(new ReportParams());
    assertTrue(M_rm.saveReportDefinition(rd3));

    List<ReportDef> list = M_rm.getReportDefinitions(null, true, true);
    assertNotNull(list);
    assertEquals(1, list.size());
    list = M_rm.getReportDefinitions(FakeData.SITE_A_ID, true, true);
    assertNotNull(list);
    assertEquals(3, list.size());
    list = M_rm.getReportDefinitions(FakeData.SITE_A_ID, true, false);
    assertNotNull(list);
    assertEquals(2, list.size());
    list = M_rm.getReportDefinitions(FakeData.SITE_A_ID, false, true);
    assertNotNull(list);
    assertEquals(2, list.size());
    list = M_rm.getReportDefinitions(FakeData.SITE_A_ID, false, false);
    assertNotNull(list);
    assertEquals(1, list.size());

    assertTrue(M_rm.removeReportDefinition(rd2));
    list = M_rm.getReportDefinitions(FakeData.SITE_A_ID, true, true);
    assertNotNull(list);
    assertEquals(2, list.size());
  }