-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SHIBUI-905' of bitbucket.org:unicon/shib-idp-ui into fe…
…ature/SHIBUI-914
- Loading branch information
Showing
6 changed files
with
1,446 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...nternet2/tier/shibboleth/admin/ui/controller/MetadataSourcesUiDefinitionController.groovy
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,68 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.controller | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import edu.internet2.tier.shibboleth.admin.ui.configuration.CustomAttributesConfiguration | ||
import groovy.json.JsonOutput | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.core.io.ResourceLoader | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
import javax.annotation.PostConstruct | ||
|
||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR | ||
|
||
/** | ||
* Controller implementing REST resource responsible for exposing structure definition for metadata sources user | ||
* interface in terms of JSON schema. | ||
* | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
@RestController('/api/ui/MetadataSources') | ||
@ConfigurationProperties('shibui') | ||
class MetadataSourcesUiDefinitionController { | ||
|
||
//Configured via @ConfigurationProperties with 'shibui.metadata-sources-ui-schema-location' property and default | ||
//value set here if that property is not explicitly set in application.properties | ||
String metadataSourcesUiSchemaLocation = 'classpath:metadata-sources-ui-schema.json' | ||
|
||
URL jsonSchemaUrl | ||
|
||
@Autowired | ||
ResourceLoader resourceLoader | ||
|
||
@Autowired | ||
ObjectMapper jacksonObjectMapper | ||
|
||
@Autowired | ||
CustomAttributesConfiguration customAttributesConfiguration | ||
|
||
@GetMapping | ||
ResponseEntity<?> getUiDefinitionJsonSchema() { | ||
try { | ||
def parsedJson = jacksonObjectMapper.readValue(this.jsonSchemaUrl, Map) | ||
def widget = parsedJson["properties"]["attributeRelease"]["widget"] | ||
def data = [] | ||
customAttributesConfiguration.getAttributes().each { | ||
def attribute = [:] | ||
attribute["key"] = it["name"] | ||
attribute["label"] = it["displayName"] | ||
data << attribute | ||
} | ||
widget["data"] = data | ||
return ResponseEntity.ok(parsedJson) | ||
} | ||
catch (Exception e) { | ||
return ResponseEntity.status(INTERNAL_SERVER_ERROR) | ||
.body([jsonParseError : e.getMessage(), | ||
sourceUiSchemaDefinitionFile: this.jsonSchemaUrl]) | ||
} | ||
} | ||
|
||
@PostConstruct | ||
def init() { | ||
jsonSchemaUrl = this.resourceLoader.getResource(this.metadataSourcesUiSchemaLocation).getURL() | ||
} | ||
} |
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.