Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-5059

Remove duplication in LocationService.getDefaultLocation

    XMLWordPrintable

    Details

    • Complexity:
      Low

      Description

      LocationServiceImpl.getDefaultLocation() contains duplicate logic to set a local Location variable to a location defined as a global properties. If the location is not found attempt is made to set it to "Unknown Location", and if that Location cant be found to "Unkown".

      See the code sections:

      https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/api/impl/LocationServiceImpl.java#L118-L126
      https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/api/impl/LocationServiceImpl.java#L128-L131

      They might be extracted into a private methods so that it becomes

      setLocationToGivenLocationOrDefault(result, location, "Unknown Location");
      setLocationToGivenLocationOrDefault(result, location, "Unknown");
      
      private void setLocationToGivenLocationOrDefault(Location result, String location, String defaultLocation)
      

      also it might be more readable to

      • rename the local variable that is returned to result

        Gliffy Diagrams

          Attachments

            Activity

              People

              Assignee:
              navareth Bartłomiej Rasztabiga
              Reporter:
              teleivo Ivo Ulrich
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: