Skip to content
Permalink
Browse files

Implemented NAS-2473

  • Loading branch information...
svcarlsen committed Nov 26, 2015
1 parent 305be20 commit 0c796be3580bfc451c8b7bf3de7794e8a1724880
@@ -61,6 +61,8 @@ passwordList:
java.util.Iterator,
java.util.Locale,
java.util.Set,
org.slf4j.Logger,
org.slf4j.LoggerFactory,
dk.netarkivet.common.exceptions.ForwardedToErrorPage,
dk.netarkivet.common.utils.I18n,
dk.netarkivet.common.webinterface.HTMLUtils,
@@ -130,7 +132,8 @@ Display all the form information for this domain
<input type="hidden" name="<%=Constants.UPDATE_PARAM%>" value="1"/>
<input type="hidden" name="<%=Constants.EDITION_PARAM%>"
value="<%= domain.getEdition() %>"/>

<input type="hidden" name="<%=Constants.CONFIG_OLDNAME_PARAM%>"
value="<%=HTMLUtils.escapeHtmlValues(configName) %>"/>
<div id="configuration">

<%-- table for selecting/editing configurations --%>
@@ -148,8 +151,8 @@ Display all the form information for this domain
String maxObjects = "";
String maxBytes = "";
if (dc != null) {
nameString = "value=\"" + HTMLUtils.escapeHtmlValues(configName)
+ "\" readonly=\"readonly\"";
nameString = "value=\"" + HTMLUtils.escapeHtmlValues(configName) + "\""; // Allow for changing the confignames
// + "\" readonly=\"readonly\"";
load = "value=\"" + dc.getMaxRequestRate() + "\"";
maxObjects = "value=\"" +
HTMLUtils.localiseLong(dc.getMaxObjects(), pageContext)
@@ -217,12 +220,12 @@ Display all the form information for this domain
</tr>
</table>
</td>
<%-- Second element is also a two-column table containing mulitple-selects for the url-lists and passwords --%>
<%-- Second element is also a two-column table containing multiple-selects for the seed-lists and passwords --%>
<td>
<table>
<tr>
<td><fmt:message key="seed.list"/> <br/>
<select name="<%=Constants.URLLIST_LIST_PARAM%>" multiple="multiple" size="8">
<select name="<%=Constants.SEEDLIST_LIST_PARAM%>" multiple="multiple" size="8">
<%-- list of url list options --%>
<%
Iterator<SeedList> allSeedListsIt
@@ -67,8 +67,8 @@ Parameters:
SeedList sl = null;
String seedListName =
request.getParameter(Constants.URLLIST_NAME_PARAM);
if (request.getParameter(Constants.EDIT_URLLIST_PARAM) != null
request.getParameter(Constants.SEEDLIST_NAME_PARAM);
if (request.getParameter(Constants.EDIT_SEEDLIST_PARAM) != null
&& seedListName != null) {
if (!domain.hasSeedList(seedListName)) {
HTMLUtils.forwardWithErrorMessage(pageContext, I18N,
@@ -117,7 +117,7 @@ Display all the form information for this domain
}
%>
<td><span id="focusElement">
<input size="25" name="<%= Constants.URLLIST_NAME_PARAM %>" <%=listname%>/>
<input size="25" name="<%= Constants.SEEDLIST_NAME_PARAM %>" <%=listname%>/>
</span></td></tr>
<tr>
<td><fmt:message key="prompt;harvestdefinition.seedlist.edit.seeds"/></td>
@@ -283,8 +283,8 @@ Display all the form information for this domain
String rowClass = HTMLUtils.getRowClass(rowcount++);
String listName = sl.getName();
String editLink = "Definitions-edit-domain-seedlist.jsp?"
+ Constants.EDIT_URLLIST_PARAM + "=1&"
+ Constants.URLLIST_NAME_PARAM + "="
+ Constants.EDIT_SEEDLIST_PARAM + "=1&"
+ Constants.SEEDLIST_NAME_PARAM + "="
+ HTMLUtils.encode(listName) + "&"
+ Constants.DOMAIN_PARAM + "="
+ HTMLUtils.encode(domainName);
@@ -302,7 +302,7 @@ Display all the form information for this domain
<%
}
String newSeedLink = "Definitions-edit-domain-seedlist.jsp?"
+ Constants.EDIT_URLLIST_PARAM + "=1&"
+ Constants.EDIT_SEEDLIST_PARAM + "=1&"
+ Constants.DOMAIN_PARAM + "="
+ HTMLUtils.encode(domainName);
%>
@@ -242,7 +242,7 @@ setupNextdateCalendar();
function submitNextDate() {
var nextDate = document.getElementById("<%=Constants.NEXTDATE_PARAM%>").value;
document.location.href="<%=pageContext.getServletContext().getContextPath()%>"
document.location.href="<%=request.getContextPath()%>"
+ "/Definitions-edit-selective-harvest.jsp?"
+ "<%=Constants.NEXTDATE_SUBMIT%>=true"
+ "&<%=Constants.NEXTDATE_PARAM%>=" + nextDate
@@ -560,4 +560,12 @@ public void setDomainhistory(DomainHistory newDomainhistory) {
this.domainhistory = newDomainhistory;
}

/**
* Change the name of configuration to the given configName.
* @param configName a new name for this configuration.
*/
public void setName(String configName) {
this.configName = configName;
}

}
@@ -333,4 +333,7 @@ static void resetSingleton() {
*/
public abstract List<Long> findUsedConfigurations(Long domainID);

public abstract void renameConfig(Domain domain, DomainConfiguration domainConf, String configOldName);

public abstract String getDefaultDomainConfigurationName(String domainName);
}
@@ -1117,7 +1117,8 @@ public boolean mayDelete(DomainConfiguration config) {
* @param domainName a name of a domain
* @return the name of the default configuration for the given domain.
*/
private String getDefaultDomainConfigurationName(String domainName) {
@Override
public String getDefaultDomainConfigurationName(String domainName) {
Connection c = HarvestDBConnection.get();
try {
return DBUtils.selectStringValue(c, "SELECT configurations.name " + "FROM domains, configurations "
@@ -1563,4 +1564,34 @@ public DomainHistory getDomainHistory(String domainName) {
}
}

@Override
public void renameConfig(Domain domain, DomainConfiguration domainConf,
String configOldName) {
Connection connection = HarvestDBConnection.get();
Long configId = DBUtils.selectLongValue(connection,
"SELECT config_id FROM configurations WHERE domain_id = ? and name = ?", domain.getID(), configOldName);

try {
PreparedStatement s = connection.prepareStatement("UPDATE configurations SET name = ?, comments = ?, "
+ "template_id = ( SELECT template_id FROM ordertemplates " + "WHERE name = ? ), " + "maxobjects = ?, "
+ "maxrate = ?, " + "maxbytes = ? " + "WHERE config_id = ? AND domain_id = ?");
s.setString(1, domainConf.getName());
DBUtils.setComments(s, 2, domainConf, Constants.MAX_COMMENT_SIZE);
s.setString(3, domainConf.getOrderXmlName());
s.setLong(4, domainConf.getMaxObjects());
s.setInt(5, domainConf.getMaxRequestRate());
s.setLong(6, domainConf.getMaxBytes());
s.setLong(7, configId);
s.setLong(8, domain.getID());
s.executeUpdate();
s.clearParameters();
updateConfigPasswordsEntries(connection, domain, domainConf);
updateConfigSeedlistsEntries(connection, domain, domainConf);
s.close();
} catch (SQLException e) {
throw new IOFailure("Error while renaming configuration '" + configOldName + "' to: " + domainConf.getName(), e);
} finally {
HarvestDBConnection.release(connection);
}
}
}
@@ -51,9 +51,9 @@ private Constants() {

public static final String DEFAULT_PARAM = "default";

public static final String EDIT_URLLIST_PARAM = "editUrlList";
public static final String EDIT_SEEDLIST_PARAM = "editSeedList";

public static final String URLLIST_NAME_PARAM = "urlListName";
public static final String SEEDLIST_NAME_PARAM = "seedListName";

public static final String CRAWLERTRAPS_PARAM = "crawlerTraps";

@@ -113,6 +113,8 @@ private Constants() {
public static final String DOMAIN_PARAM = "name";

public static final String CONFIG_NAME_PARAM = "configName";

public static final String CONFIG_OLDNAME_PARAM = "configOldName";

public static final String ORDER_XML_NAME_PARAM = "order_xml";

@@ -130,7 +132,7 @@ private Constants() {

public static final String SHOW_UNUSED_SEEDS_PARAM = "showUnusedSeeds";

public static final String URLLIST_LIST_PARAM = "urlListList";
public static final String SEEDLIST_LIST_PARAM = "seedListList";

public static final String JOB_PARAM = "jobID";

@@ -271,4 +273,6 @@ private Constants() {
public static final String DEFAULT_DOMAIN_SEARCH_TYPE = NAME_DOMAIN_SEARCH;

public static final String JOB_ORDERING_BY_STARTDATE_PARAM = "ORDERING_BY_STARTDATE";


}
@@ -45,7 +45,8 @@
*/

public class DomainConfigurationDefinition {

//private static final Logger log = LoggerFactory.getLogger(DomainConfigurationDefinition.class);

/**
* Extracts all required parameters from the request, checks for any inconsistencies, and passes the requisite data
* to the updateDomain method for processing. The specified domain configuration is then updated and the result
@@ -79,12 +80,18 @@ public static void processRequest(PageContext context, I18n i18n) {
return; // no need to continue
}

HTMLUtils.forwardOnEmptyParameter(context, Constants.DOMAIN_PARAM, Constants.CONFIG_NAME_PARAM,
Constants.ORDER_XML_NAME_PARAM, Constants.URLLIST_LIST_PARAM);
HTMLUtils.forwardOnEmptyParameter(context, Constants.DOMAIN_PARAM, Constants.CONFIG_NAME_PARAM,
Constants.ORDER_XML_NAME_PARAM, Constants.SEEDLIST_LIST_PARAM);
String name = request.getParameter(Constants.DOMAIN_PARAM).trim();
String configName = request.getParameter(Constants.CONFIG_NAME_PARAM).trim();
String configOldName = request.getParameter(Constants.CONFIG_OLDNAME_PARAM);
if (configOldName != null) {
configOldName = configOldName.trim();
} else {
configOldName = "";
}
String order_xml = request.getParameter(Constants.ORDER_XML_NAME_PARAM).trim();
String[] urlListList = request.getParameterValues(Constants.URLLIST_LIST_PARAM);
String[] urlListList = request.getParameterValues(Constants.SEEDLIST_LIST_PARAM);

if (!DomainDAO.getInstance().exists(name)) {
HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;unknown.domain.0", name);
@@ -128,45 +135,78 @@ public static void processRequest(PageContext context, I18n i18n) {

String comments = request.getParameter(Constants.COMMENTS_PARAM);

updateDomain(domain, configName, order_xml, load, maxObjects, maxBytes, urlListList, comments);
}
if (!configOldName.isEmpty() && !configOldName.equals(configName)){
// Are we allowed to rename to the new name? or does it already exist?
if (domain.hasConfiguration(configName)) {
HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;configuration.exists.0", configName);
throw new ForwardedToErrorPage("Configuration " + configName + " already exist");
} else {
DomainConfiguration domainConf = domain.getConfiguration(configOldName);
String defaultConfigName = DomainDAO.getInstance().getDefaultDomainConfigurationName(domain.getName());
if (defaultConfigName.equals(configName)){
HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;cannot.rename.defaultconfiguration.0", configOldName);
throw new ForwardedToErrorPage("Configuration " + configOldName + " cannot be renamed. It is the defaultconfiguration");
} else {
List<SeedList> seedlistList = new ArrayList<SeedList>();
for (String seedlistName : urlListList) {
seedlistList.add(domain.getSeedList(seedlistName));
}
domainConf.setName(configName);
domainConf.setOrderXmlName(order_xml);
domainConf.setMaxObjects(maxObjects);
domainConf.setMaxBytes(maxBytes);
domainConf.setMaxRequestRate(load);
domainConf.setSeedLists(domain, seedlistList);
if (comments != null) {
domainConf.setComments(comments);
}
DomainDAO.getInstance().renameConfig(domain, domainConf, configOldName);


}
}
} else {
updateDomainConfig(domain, configName, order_xml, load, maxObjects, maxBytes, urlListList, comments);
}
}

/**
* Given the parsed values, update or create a configuration in the domain.
*
* @param domain The domain
* @param configName Name of config - if this exists we update, otherwise we create a new.
* @param configName Name of config - if this exists we update, otherwise we create a new.
* @param orderXml Order-template name
* @param load Request rate
* @param maxObjects Max objects
* @param maxBytes Max bytes
* @param urlListList List of url list names
* @param comments Comments, or null for none.
*/
private static void updateDomain(Domain domain, String configName, String orderXml, int load, long maxObjects,
long maxBytes, String[] urlListList, String comments) {
private static void updateDomainConfig(Domain domain, String configName, String orderXml, int load, long maxObjects,
long maxBytes, String[] urlListList, String comments) {

// Update/create new configuration
List<SeedList> seedlistList = new ArrayList<SeedList>();
for (String seedlistName : urlListList) {
seedlistList.add(domain.getSeedList(seedlistName));
}
DomainConfiguration domainConf;
if (domain.hasConfiguration(configName)) {
domainConf = domain.getConfiguration(configName);
} else { // new DomainConfiguration
domainConf = new DomainConfiguration(configName, domain, seedlistList, new ArrayList<Password>());
domain.addConfiguration(domainConf);
}
domainConf.setOrderXmlName(orderXml);
domainConf.setMaxObjects(maxObjects);
domainConf.setMaxBytes(maxBytes);
domainConf.setMaxRequestRate(load);
domainConf.setSeedLists(domain, seedlistList);
if (comments != null) {
domainConf.setComments(comments);
}
DomainDAO.getInstance().update(domain);

// Update/create new configuration

List<SeedList> seedlistList = new ArrayList<SeedList>();
for (String seedlistName : urlListList) {
seedlistList.add(domain.getSeedList(seedlistName));
}
DomainConfiguration domainConf;
if (domain.hasConfiguration(configName)) {
domainConf = domain.getConfiguration(configName);
} else { // new DomainConfiguration
domainConf = new DomainConfiguration(configName, domain, seedlistList, new ArrayList<Password>());
domain.addConfiguration(domainConf);
}
domainConf.setOrderXmlName(orderXml);
domainConf.setMaxObjects(maxObjects);
domainConf.setMaxBytes(maxBytes);
domainConf.setMaxRequestRate(load);
domainConf.setSeedLists(domain, seedlistList);
if (comments != null) {
domainConf.setComments(comments);
}
DomainDAO.getInstance().update(domain);
}
}
@@ -87,11 +87,11 @@ public static void processRequest(PageContext context, I18n i18n) {
return;
}

HTMLUtils.forwardOnEmptyParameter(context, Constants.DOMAIN_PARAM, Constants.URLLIST_NAME_PARAM,
HTMLUtils.forwardOnEmptyParameter(context, Constants.DOMAIN_PARAM, Constants.SEEDLIST_NAME_PARAM,
Constants.SEED_LIST_PARAMETER);

String name = request.getParameter(Constants.DOMAIN_PARAM).trim();
String urlListName = request.getParameter(Constants.URLLIST_NAME_PARAM).trim();
String urlListName = request.getParameter(Constants.SEEDLIST_NAME_PARAM).trim();
String seedList = request.getParameter(Constants.SEED_LIST_PARAMETER).trim();

// check the edition number before updating
@@ -720,3 +720,6 @@ wednesday = Wednesday

yes = Yes
harvestdefinition.schedule.edit.minutes=minutes

errormsg;configuration.exists.0=Configuration {0} already exist
errormsg;cannot.rename.defaultconfiguration.0=Configuration {0} cannot be renamed. It is the defaultconfiguration
@@ -92,9 +92,9 @@ public void testExtendedFields() {
parameterMap.put(Constants.DOMAIN_PARAM, new String[] {"netarkivet.dk"});
parameterMap.put(Constants.DEFAULT_PARAM, new String[] {"conf2"});
TestServletRequest request = new TestServletRequest();
parameterMap.put("configName", new String[] {"new_config"});
parameterMap.put("order_xml", new String[] {"OneLevel-order"});
parameterMap.put("urlListList", new String[] {"seeds", "defaultseeds"});
parameterMap.put(Constants.CONFIG_NAME_PARAM, new String[] {"new_config"});
parameterMap.put(Constants.ORDER_XML_NAME_PARAM, new String[] {"OneLevel-order"});
parameterMap.put(Constants.SEEDLIST_LIST_PARAM, new String[] {"seeds", "defaultseeds"});
parameterMap.put(Constants.EDITION_PARAM, new String[] {1l + ""});
parameterMap.put(Constants.CRAWLERTRAPS_PARAM, new String[] {""});
parameterMap.put(Constants.COMMENTS_PARAM, new String[] {""});
@@ -157,7 +157,7 @@ public void testAddDomainConfiguration() {
TestServletRequest request = new TestServletRequest();
parameterMap.put("configName", new String[] {"new_config"});
parameterMap.put("order_xml", new String[] {"OneLevel-order"});
parameterMap.put("urlListList", new String[] {"seeds", "defaultseeds"});
parameterMap.put("seedListList", new String[] {"seeds", "defaultseeds"});
parameterMap.put(Constants.EDITION_PARAM, new String[] {1l + ""});
parameterMap.put(Constants.CRAWLERTRAPS_PARAM, new String[] {""});
parameterMap.put(Constants.COMMENTS_PARAM, new String[] {""});
@@ -202,7 +202,7 @@ public void testUpdateConfiguration() {
parameterMap.put("order_xml", new String[] {conf.getOrderXmlName()});
parameterMap.put("maxRate", new String[] {"20"});
parameterMap.put("maxObjects", new String[] {"10"});
parameterMap.put("urlListList", new String[] {"seeds"});
parameterMap.put("seedListList", new String[] {"seeds"});
parameterMap.put(Constants.EDITION_PARAM, new String[] {1l + ""});
request.setParameterMap(parameterMap);
I18n I18N = new I18n(dk.netarkivet.harvester.Constants.TRANSLATIONS_BUNDLE);
@@ -238,8 +238,8 @@ public void testUpdateUrlList() {
parameterMap.put(Constants.DOMAIN_PARAM, new String[] {"netarkivet.dk"});
parameterMap.put(Constants.DEFAULT_PARAM, new String[] {"conf2"});
TestServletRequest request = new TestServletRequest();
parameterMap.put("urlListName", new String[] {"seeds"});
parameterMap.put("seedList", new String[] {"www.netarkivet.dk\nwww.netarchive.dk"});
parameterMap.put(Constants.SEEDLIST_NAME_PARAM, new String[] {"seeds"});
parameterMap.put(Constants.SEED_LIST_PARAMETER, new String[] {"www.netarkivet.dk\nwww.netarchive.dk"});
parameterMap.put(Constants.EDITION_PARAM, new String[] {1l + ""});
request.setParameterMap(parameterMap);
I18n I18N = new I18n(dk.netarkivet.harvester.Constants.TRANSLATIONS_BUNDLE);

0 comments on commit 0c796be

Please sign in to comment.
You can’t perform that action at this time.