title: Should I put my business invariant check in controller
body: <p>I am working with Spring MVC. I need to check duplicated <code>premises name</code> before saving premises.
  In Controller</p>
  
  <pre><code>public void savePremises() {
      // Check duplicate 
      Set&lt;String&gt; premiseNames = new HashSet&lt;String&gt;();
      //premises is global variable which contain the list of premises to save
      for (Premise premise : premises) {
          String premiseName = premise.getPremiseName();
          if (premiseNames.contains(premiseName)) {
              Clients.showNotification("Duplicated primise name "
                      + premiseName);
              return;
          } else {
              premiseNames.add(premiseName);
          }
      }
  ..............
  }
  </code></pre>
  
  <p>Because I will use this checking code for premises in another controller, so I want to put it in service class to reuse later. 
  <br/>Then I need to return 2 value from service function: 
  <br/>+ A boolean value to indicate the result of checking.
  <br/>+ A string value for duplicated premise name. 
  <br/> I have a solution that returning null value for premise name to indicate no duplicated premise name. Is it bad practice to do this?<br/>
  In Controller <br/></p>
  
  <pre><code>public void savePremises(){
      String premiseName =premiseService.isDuplicatedPremiseName(premises);
      if( premiseName!=null) {
          Clients.showNotification("Duplicated primise name "
                  + premiseName);
          return;
      }
  }
  </code></pre>
  
  <p>In Service</p>
  
  <pre><code>public String isDuplicatedPremiseName(List&lt;Premise&gt; premises) {
     Set&lt;String&gt; premiseNames = new HashSet&lt;String&gt;();
     for (Premise premise : premises) {
      String premiseName = premise.getPremiseName();
      if (premiseNames.contains(premiseName)) {
          return premiseName;
      } else {
          premiseNames.add(premiseName);
      }
     }
     return null;
  }
  </code></pre>