-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
There was a problem hiding this 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.
src/main/scala/uk/gov/nationalarchives/tdr/api/service/ReferenceGeneratorService.scala
Outdated
Show resolved
Hide resolved
src/test/scala/uk/gov/nationalarchives/tdr/api/service/ReferenceGeneratorServiceSpec.scala
Outdated
Show resolved
Hide resolved
src/main/scala/uk/gov/nationalarchives/tdr/api/service/FileService.scala
Show resolved
Hide resolved
src/main/scala/uk/gov/nationalarchives/tdr/api/service/FileService.scala
Outdated
Show resolved
Hide resolved
src/main/scala/uk/gov/nationalarchives/tdr/api/service/FileService.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
src/main/scala/uk/gov/nationalarchives/tdr/api/service/ReferenceGeneratorService.scala
Outdated
Show resolved
Hide resolved
val refGeneratorUrl: String = config.getString("referenceGenerator.referenceGeneratorUrl") | ||
val refGeneratorLimit: Int = config.getInt("referenceGenerator.referenceLimit") | ||
|
||
def getReferences(numberOfRefs: Int): List[reference] = { |
There was a problem hiding this comment.
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()
}
}
...
There was a problem hiding this comment.
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.
src/main/scala/uk/gov/nationalarchives/tdr/api/service/ReferenceGeneratorService.scala
Outdated
Show resolved
Hide resolved
src/test/scala/uk/gov/nationalarchives/tdr/api/service/FileServiceSpec.scala
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks
No description provided.