-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Back end endpoints for MetaData (#397)
* Add paths for jobcodes * Add paths for named references * Enable EnableGlobalMethodSecurity
- Loading branch information
1 parent
fedf594
commit 9f4aea8
Showing
11 changed files
with
437 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
api/src/main/kotlin/edu/wgu/osmt/api/model/JobCodeUpdate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package edu.wgu.osmt.api.model | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import edu.wgu.osmt.db.JobCodeLevel | ||
|
||
data class JobCodeUpdate( | ||
@JsonProperty("code") | ||
val code: String, | ||
@JsonProperty("targetNode") | ||
val targetNode: String? = null, | ||
@JsonProperty("targetNodeName") | ||
val targetNodeName: String? = null, | ||
@JsonProperty("frameworkName") | ||
val framework: String? = null, | ||
@JsonProperty("level") | ||
val level: JobCodeLevel? = null, | ||
@JsonProperty("parents") | ||
val parents: List<JobCodeUpdate>? = null | ||
) { | ||
} |
82 changes: 82 additions & 0 deletions
82
api/src/main/kotlin/edu/wgu/osmt/jobcode/JobCodeController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package edu.wgu.osmt.jobcode; | ||
|
||
import edu.wgu.osmt.RoutePaths | ||
import edu.wgu.osmt.api.model.ApiJobCode | ||
import edu.wgu.osmt.api.model.JobCodeUpdate | ||
import edu.wgu.osmt.elasticsearch.OffsetPageable | ||
import edu.wgu.osmt.task.TaskResult | ||
import edu.wgu.osmt.task.TaskStatus | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.http.HttpEntity | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.MediaType | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.stereotype.Controller | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.springframework.web.bind.annotation.DeleteMapping | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.server.ResponseStatusException | ||
|
||
@Controller | ||
@Transactional | ||
class JobCodeController @Autowired constructor( | ||
val jobCodeEsRepo: JobCodeEsRepo, | ||
val jobCodeRepository: JobCodeRepository | ||
) { | ||
|
||
@GetMapping(RoutePaths.JOB_CODE_LIST, produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
@PreAuthorize("isAuthenticated()") | ||
fun allPaginated( | ||
@RequestParam(required = true) size: Int, | ||
@RequestParam(required = true) from: Int, | ||
@RequestParam(required = false) sort: String? | ||
): HttpEntity<List<ApiJobCode>> { | ||
val searchResults = jobCodeEsRepo.typeAheadSearch("", OffsetPageable(from, size, null)) | ||
return ResponseEntity.status(200).body(searchResults.map { ApiJobCode.fromJobCode(it.content) }.toList()) | ||
} | ||
|
||
@GetMapping(RoutePaths.JOB_CODE_DETAIL, produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
@PreAuthorize("isAuthenticated()") | ||
fun byId( | ||
@PathVariable id: Long, | ||
): HttpEntity<ApiJobCode> { | ||
val jobCode = jobCodeRepository.findById(id) | ||
if (jobCode != null) { | ||
return ResponseEntity.status(200).body(ApiJobCode.fromJobCode(jobCode.toModel())) | ||
} else { | ||
throw ResponseStatusException(HttpStatus.NOT_FOUND) | ||
} | ||
} | ||
|
||
@PostMapping(RoutePaths.JOB_CODE_CREATE, produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
@PreAuthorize("hasAuthority(@appConfig.roleAdmin)") | ||
fun createJobCode( | ||
@RequestBody jobCodes: List<JobCodeUpdate> | ||
): HttpEntity<List<ApiJobCode>> { | ||
val newJobCodes = jobCodeRepository.createFromApi(jobCodes) | ||
return ResponseEntity.status(200).body(newJobCodes.map { ApiJobCode.fromJobCode(it.toModel()) }.toList()) | ||
} | ||
|
||
@PostMapping(RoutePaths.JOB_CODE_UPDATE, produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
@PreAuthorize("hasAuthority(@appConfig.roleAdmin)") | ||
fun updateJobCode( | ||
@PathVariable id: Int, | ||
@RequestBody jobCodeUpdate: JobCodeUpdate | ||
): HttpEntity<ApiJobCode> { | ||
return ResponseEntity.status(200).body(ApiJobCode(code = "1", targetNode = "target", targetNodeName = "targetNodeName", frameworkName = "frameworkName", parents = listOf())) | ||
} | ||
|
||
@DeleteMapping(RoutePaths.JOB_CODE_REMOVE) | ||
@PreAuthorize("hasAuthority(@appConfig.roleAdmin)") | ||
fun deleteJobCode( | ||
@PathVariable id: Int, | ||
): HttpEntity<TaskResult> { | ||
return ResponseEntity.status(200).body(TaskResult(uuid = "uuid", contentType = "application/json", status = TaskStatus.Processing, apiResultPath = "path")) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package edu.wgu.osmt.keyword | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class ApiKeywordUpdate( | ||
@JsonProperty("name") | ||
val name: String?, | ||
@JsonProperty("value") | ||
val value: String?, | ||
@JsonProperty("type") | ||
val type: KeywordTypeEnum, | ||
@JsonProperty("framework") | ||
val framework: String? | ||
) { | ||
} | ||
|
||
data class NamedReference( | ||
val id: Long?, | ||
val name: String?, | ||
val value: String?, | ||
val type: KeywordTypeEnum, | ||
val framework: String? | ||
) { | ||
|
||
companion object factory { | ||
fun fromKeyword(keyword: Keyword): NamedReference { | ||
return NamedReference(keyword.id, keyword.value, keyword.value, keyword.type, keyword.framework) | ||
} | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
api/src/main/kotlin/edu/wgu/osmt/keyword/NamedReferencesController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package edu.wgu.osmt.keyword | ||
|
||
import edu.wgu.osmt.PaginationDefaults | ||
import edu.wgu.osmt.RoutePaths | ||
import edu.wgu.osmt.task.TaskResult | ||
import edu.wgu.osmt.task.TaskStatus | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.http.HttpEntity | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.MediaType | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.stereotype.Controller | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.springframework.web.bind.annotation.DeleteMapping | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.server.ResponseStatusException | ||
|
||
@Controller | ||
@Transactional | ||
class NamedReferencesController @Autowired constructor( | ||
val keywordEsRepo: KeywordEsRepo, | ||
val keywordRepository: KeywordRepository | ||
) { | ||
|
||
@GetMapping(RoutePaths.NAMED_REFERENCES_LIST, produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
@PreAuthorize("isAuthenticated()") | ||
fun allPaginated( | ||
@RequestParam(required = true) type: String, | ||
@RequestParam(required = false, defaultValue = PaginationDefaults.size.toString()) size: Int, | ||
@RequestParam(required = false, defaultValue = "0") from: Int, | ||
@RequestParam(required = false) sort: String? | ||
): HttpEntity<List<NamedReference>> { | ||
val keywordType = KeywordTypeEnum.forApiValue(type) ?: throw ResponseStatusException(HttpStatus.BAD_REQUEST) | ||
val searchResults = keywordEsRepo.typeAheadSearch("", keywordType) | ||
return ResponseEntity.status(200).body(searchResults.map { NamedReference.fromKeyword(it.content) }.toList()) | ||
} | ||
|
||
@GetMapping(RoutePaths.NAMED_REFERENCES_DETAIL, produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
@PreAuthorize("isAuthenticated()") | ||
fun byId( | ||
@PathVariable id: Long, | ||
): HttpEntity<NamedReference> { | ||
val keyword = keywordRepository.findById(id) | ||
if (keyword != null) { | ||
return ResponseEntity.status(200).body(NamedReference.fromKeyword(keyword.toModel())) | ||
} else { | ||
throw ResponseStatusException(HttpStatus.NOT_FOUND) | ||
} | ||
} | ||
|
||
@PostMapping(RoutePaths.NAMED_REFERENCES_CREATE, produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
@PreAuthorize("hasAuthority(@appConfig.roleAdmin)") | ||
fun createNamedReference( | ||
@RequestBody keywords: List<ApiKeywordUpdate> | ||
): HttpEntity<List<NamedReference>> { | ||
return ResponseEntity.status(200).body( | ||
keywords.map { | ||
NamedReference(id = 1, name = it.name, value = it.value, type = it.type, framework = it.framework) | ||
} | ||
) | ||
} | ||
|
||
@PostMapping(RoutePaths.NAMED_REFERENCES_UPDATE, produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
@PreAuthorize("hasAuthority(@appConfig.roleAdmin)") | ||
fun updateNamedReference( | ||
@PathVariable id: Int, | ||
@RequestBody apiKeyword: ApiKeywordUpdate | ||
): HttpEntity<NamedReference> { | ||
return ResponseEntity.status(200).body(NamedReference(134, "my name", "my value", KeywordTypeEnum.Keyword, "my framework")) | ||
} | ||
|
||
@DeleteMapping(RoutePaths.NAMED_REFERENCES_REMOVE) | ||
@PreAuthorize("hasAuthority(@appConfig.roleAdmin)") | ||
fun deleteNamedReference( | ||
@PathVariable id: Int, | ||
): HttpEntity<TaskResult> { | ||
return ResponseEntity.status(200).body(TaskResult(uuid = "uuid", contentType = "application/json", status = TaskStatus.Processing, apiResultPath = "path")) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.