Navigation Menu

Skip to content

Commit

Permalink
Tidy up the interface between the http repo and the catalogue
Browse files Browse the repository at this point in the history
  • Loading branch information
colugo committed Jul 6, 2018
1 parent fe50585 commit 16ede26
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 672 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,3 +11,4 @@
/.project
/out
*.DS_Store
.ENV
3 changes: 0 additions & 3 deletions src/main/kotlin/au/gov/dxa/Controller.kt
Expand Up @@ -38,10 +38,7 @@ class Controller {
@RequestMapping("/service/{id}/{title}")
fun detailPage(@PathVariable id:String,@PathVariable title:String, model:MutableMap<String, Any?>): String{
val serviceDescription = serviceDescriptionService.get(id)
return _detailPage(serviceDescription, title, id, model)
}

private fun _detailPage(serviceDescription:ServiceDTO?, title: String, id: String, model: MutableMap<String, Any?>): String {
if (serviceDescription == null) return "detail"
var content:String = ""
var pageTitle:String = title
Expand Down
24 changes: 9 additions & 15 deletions src/main/kotlin/au/gov/dxa/ServiceDescriptionRepository.kt
Expand Up @@ -2,7 +2,6 @@ package au.gov.dxa

import com.beust.klaxon.*
import org.springframework.stereotype.Component
import javax.servlet.http.HttpServletRequest
import java.net.URL

data class ServiceDTO(val name:String = "", val description:String = "", val pages:List<String> = listOf(""))
Expand All @@ -18,8 +17,7 @@ class ServiceDescriptionRepository(mock:MutableList<String>? = null) {
private fun getService(id:String) : ServiceDTO
{
var returnString: String = getRESTReturnString("service",id)
val serviceDTO = Klaxon().parse<ServiceDTO>(returnString) ?: ServiceDTO()
return serviceDTO
return Klaxon().parse<ServiceDTO>(returnString) ?: ServiceDTO()
}

private fun read(name:String):String{
Expand All @@ -29,30 +27,26 @@ class ServiceDescriptionRepository(mock:MutableList<String>? = null) {
return inputAsString
}


fun get(id:String):ServiceDTO?{
return getService(id)
}

data class IndexDTO(val content:List<IndexServiceDTO>)
data class IndexServiceDTO(val id:String, val name:String, val description:String)
fun list(): List<ServiceListVM>{

val list = mutableListOf<ServiceListVM>()
var returnString: String = getRESTReturnString()
val index = Klaxon().parse<IndexDTO>(returnString)

val splitdata = returnString.replace("[\"","").replace("\"]","").split("\",\"")

for(serviceData in splitdata)
{
//temp code until structure is final
var serviceCuttent = getService(serviceData.split("/").last())
list.add(ServiceListVM(serviceCuttent.name, serviceCuttent.description,"Metadata", "Published", serviceData.split("/").last()))
}
return list.toList()
return index!!.content.map { it -> ServiceListVM(it.name, it.description, "Metadata", "Published", it.id) }
}

private fun getRESTReturnString(endpoint : String = "index", endPointID:String = "") : String {
var returnString: String = ""
val url = System.getenv("BaseRepoURI") + endpoint + if (endpoint.last() == '/') endPointID else "/$endPointID"
val baseRepoUri = System.getenv("BaseRepoURI")?: throw RuntimeException("No environment variable: BaseRepoURI")


val url = baseRepoUri + endpoint + if (endpoint.last() == '/') endPointID else "/$endPointID"
try {
val con = URL(url).openConnection()
con.readTimeout = 1000
Expand Down
255 changes: 0 additions & 255 deletions src/main/resources/samples/ato.accrole.0001.2017.list.01.00.xsd

This file was deleted.

This file was deleted.

0 comments on commit 16ede26

Please sign in to comment.