Skip to content

Commit

Permalink
Added DAO methods to return only active or inactive templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
csrster committed Nov 5, 2015
1 parent 74eedad commit b344c91
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public static synchronized TemplateDAO getInstance() {
*/
public abstract Iterator<String> getAll();


/**
* Returns an iterator with names of either all active or all inactive order.xml-templates.
*
* @param active true if active templates are wanted, false otherwise.
* @return Iterator<String> with all names of templates (without .xml).
*/
public abstract Iterator<String> getAll(boolean active);

/**
* Returns an iterator of all templates. Note that this is not the most efficient way of getting all names of
* templates, for that just use getAll(). Implements the Iterable interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ public synchronized Iterator<String> getAll() {
}
}

@Override
public synchronized Iterator<String> getAll(boolean active) {
Connection c = HarvestDBConnection.get();
try {
List<String> names = DBUtils.selectStringList(c, "SELECT name FROM ordertemplates WHERE isActive=? ORDER BY name ", active);
return names.iterator();
} finally {
HarvestDBConnection.release(c);
}
}

/**
* Return true if the database contains a template with the given name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ public void testGetAll() throws Exception {
Iterator<String> i = dao.getAll();
// File[] order_files = TestInfo.BASE_DIR_ORDER_XML_TEMPLATES.listFiles(FileUtils.getXmlFilesFilter());
StringBuffer sb = new StringBuffer();
String templateName = null;
int total = 0;
while (i.hasNext()) {
templateName = i.next();
sb.append(templateName + ",");
total++;
}
assertEquals("More or less templates found ", "FullSite-order,Max_20_2-order,OneLevel-order,default_orderxml,",
sb.toString());
HeritrixTemplate heritrixTemplate = dao.read(templateName);
heritrixTemplate.setIsActive(!heritrixTemplate.isActive());
dao.update(templateName, heritrixTemplate);
assertEquals("Expect 1 inactive template now.", 1, dao.getAll(false));
assertEquals("Expect number of active templates to have decreased by 1.", total-1, dao.getAll(true));
}

@Category(SlowTest.class)
@Test
public void testGetAllWithArg() throws Exception {
TemplateDAO dao = TemplateDAO.getInstance();
Iterator<String> i = dao.getAll(true);
// File[] order_files = TestInfo.BASE_DIR_ORDER_XML_TEMPLATES.listFiles(FileUtils.getXmlFilesFilter());
StringBuffer sb = new StringBuffer();
while (i.hasNext()) {
String templateName = i.next();
sb.append(templateName + ",");
Expand All @@ -72,6 +95,7 @@ public void testGetAll() throws Exception {
sb.toString());
}


@Category(SlowTest.class)
@Test
public void testCreate() throws DocumentException {
Expand Down

0 comments on commit b344c91

Please sign in to comment.