Skip to content

Commit

Permalink
dont throw exception if instance already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Bauhardt committed Aug 26, 2009
1 parent b1de4e0 commit 3315b2f
Showing 1 changed file with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.apache.nutch.admin.ConfigurationUtil;
import org.apache.nutch.admin.NavigationSelector;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ValidationUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -48,7 +46,7 @@ public CreateInstanceCommandObject referenceDataInstance() {
public String[] referenceDataNames(HttpSession session) {
ServletContext servletContext = session.getServletContext();
ConfigurationUtil configurationUtil = (ConfigurationUtil) servletContext
.getAttribute("configurationUtil");
.getAttribute("configurationUtil");
String[] allNames = configurationUtil.getAllNames();
String[] allInstancesNames = new String[allNames.length - 1];
int counter = 0;
Expand All @@ -63,27 +61,16 @@ public String[] referenceDataNames(HttpSession session) {

@RequestMapping(method = RequestMethod.POST)
public String createIstance(
@ModelAttribute("createInstance") CreateInstanceCommandObject commandObject,
BindingResult bindingResult, HttpSession httpSession) throws IOException {
@ModelAttribute("createInstance") CreateInstanceCommandObject commandObject,
HttpSession httpSession) throws IOException {
ServletContext servletContext = httpSession.getServletContext();
ConfigurationUtil configurationUtil = (ConfigurationUtil) servletContext
.getAttribute("configurationUtil");
.getAttribute("configurationUtil");
String folderName = commandObject.getFolderName();

// TODO refactore in a validator
ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "folderName",
"empty");
if (!bindingResult.hasErrors()) {
if (configurationUtil.existsConfiguration(folderName)) {
bindingResult.rejectValue("folderName", "alreadyExists");
}
if (folderName != null && !"".equals(folderName.trim())
&& !configurationUtil.existsConfiguration(folderName)) {
configurationUtil.createNewConfiguration(folderName);
}

if (bindingResult.hasErrors()) {
return "instance";
}

configurationUtil.createNewConfiguration(folderName);
return "redirect:index.html";
}

Expand Down

0 comments on commit 3315b2f

Please sign in to comment.