Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDR-3326 Assign references to file/directories #705

Merged
merged 12 commits into from
Oct 12, 2023

Conversation

thanhz
Copy link
Contributor

@thanhz thanhz commented Oct 10, 2023

No description provided.

Copy link
Contributor

@TomJKing TomJKing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks. Some initial comments, after a quick look through.

Still thinking about the recursive method in the reference generator service. So there will be more comments after I've had a more detailed look at the code.

Copy link
Contributor

@TomJKing TomJKing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional comments. Thanks

val refGeneratorUrl: String = config.getString("referenceGenerator.referenceGeneratorUrl")
val refGeneratorLimit: Int = config.getInt("referenceGenerator.referenceLimit")

def getReferences(numberOfRefs: Int): List[reference] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would abstract out some of this code from the getReferences method, to make it a little clearer, ie so that it is doing one thing.

Some thing like this:

...
  def getReferences(numberOfRefs: Int): List[reference] = {
    @tailrec
    def fetchReferences(numberOfRefs: Int, acc: List[reference]): List[reference] = {
      if (numberOfRefs <= 0) acc
      else {
        val batchSize = Math.min(numberOfRefs, refGeneratorLimit)
        fetchReferences(numberOfRefs - batchSize, acc ++ sendRequest(batchSize))
      }
    }

    fetchReferences(numberOfRefs, Nil)
  }

  private def sendRequest(numberOfRefs: Int): List[reference] = {
    val response = client.send(basicRequest.get(uri"$refGeneratorUrl/$environment/counter?numberofrefs=$numberOfRefs"))

    try {
      response.body match {
        case Left(body) =>
          val message = "Failed to get references from reference generator api"
          logger.error(s"${response.code} $message:\n$body")
          throw new HttpResponseException(response.code.code, message)
        case Right(body) =>
          val references = parse(body).getOrElse(null)
          val listOfReferences = references.as[List[reference]].getOrElse(null)
          logger.info(s"2xx response to GET:\n$listOfReferences")
          listOfReferences
      }
    } finally {
      client.close()
    }
  }
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much cleaner. I've made the changes.

Copy link
Contributor

@TomJKing TomJKing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks

@thanhz thanhz merged commit 9068afc into master Oct 12, 2023
102 checks passed
@thanhz thanhz deleted the TDR-3329_create_reference_generator_servive branch October 12, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants