Skip to content

Commit

Permalink
NAS-2473 review followup
Browse files Browse the repository at this point in the history
  • Loading branch information
svcarlsen committed Dec 4, 2015
1 parent 443393d commit b4c548b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ Display all the form information for this domain
String maxObjects = "";
String maxBytes = "";
if (dc != null) {
nameString = "value=\"" + HTMLUtils.escapeHtmlValues(configName) + "\""; // Allow for changing the confignames
// + "\" readonly=\"readonly\"";
nameString = "value=\"" + HTMLUtils.escapeHtmlValues(configName) + "\"";
load = "value=\"" + dc.getMaxRequestRate() + "\"";
maxObjects = "value=\"" +
HTMLUtils.localiseLong(dc.getMaxObjects(), pageContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,20 @@ public abstract Iterator<HarvestInfo> getHarvestInfoBasedOnPreviousHarvestDefini
* @return The list of ID for the used configurations.
*/
public abstract List<Long> findUsedConfigurations(Long domainID);

/**
* Rename and update a DomainConfiguration for a specific domain.
* @param domain The given domain
* @param domainConf The given domainConfig
* @param configOldName The old name of the domainConfig
*/
public abstract void renameAndUpdateConfig(Domain domain, DomainConfiguration domainConf, String configOldName);

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

/**
* Get the name of the default configuration for the given domain.
*
* @param domainName a name of a domain
* @return the name of the default configuration for the given domain.
*/
public abstract String getDefaultDomainConfigurationName(String domainName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1111,12 +1111,6 @@ public boolean mayDelete(DomainConfiguration config) {
}
}

/**
* Get the name of the default configuration for the given domain.
*
* @param domainName a name of a domain
* @return the name of the default configuration for the given domain.
*/
@Override
public String getDefaultDomainConfigurationName(String domainName) {
Connection c = HarvestDBConnection.get();
Expand Down Expand Up @@ -1565,7 +1559,7 @@ public List<String> getDomains(String glob, String searchField) {
}

@Override
public void renameConfig(Domain domain, DomainConfiguration domainConf,
public void renameAndUpdateConfig(Domain domain, DomainConfiguration domainConf,
String configOldName) {
Connection connection = HarvestDBConnection.get();
Long configId = DBUtils.selectLongValue(connection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public static void processRequest(PageContext context, I18n i18n) {
String configName = request.getParameter(Constants.CONFIG_NAME_PARAM).trim();
String configOldName = request.getParameter(Constants.CONFIG_OLDNAME_PARAM);
if (configOldName != null) {
configOldName = configOldName.trim();
configOldName = configOldName.trim();
} else {
configOldName = "";
configOldName = "";
}
String order_xml = request.getParameter(Constants.ORDER_XML_NAME_PARAM).trim();
String[] urlListList = request.getParameterValues(Constants.SEEDLIST_LIST_PARAM);
Expand Down Expand Up @@ -136,39 +136,37 @@ public static void processRequest(PageContext context, I18n i18n) {
String comments = request.getParameter(Constants.COMMENTS_PARAM);

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);
// 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);
} 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 {
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().renameAndUpdateConfig(domain, domainConf, configOldName);
}
}
} else {
updateDomainConfig(domain, configName, order_xml, load, maxObjects, maxBytes, urlListList, comments);
updateDomainConfig(domain, configName, order_xml, load, maxObjects, maxBytes, urlListList, comments);
}
}
}

/**
* Given the parsed values, update or create a configuration in the domain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,5 +721,5 @@ wednesday = Wednesday
yes = Yes
harvestdefinition.schedule.edit.minutes=minutes

errormsg;configuration.exists.0=Configuration {0} already exist
errormsg;configuration.exists.0=Configuration {0} already exists
errormsg;cannot.rename.defaultconfiguration.0=Configuration {0} cannot be renamed. It is the defaultconfiguration

0 comments on commit b4c548b

Please sign in to comment.