Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Take responsibility for the API controller
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/main/java/uk/org/iay/incommon/validator/api/ValidatorsApiController.java
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,69 @@ | ||
package uk.org.iay.incommon.validator.api; | ||
|
||
import uk.org.iay.incommon.validator.models.Status; | ||
import uk.org.iay.incommon.validator.models.Validator; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.swagger.annotations.*; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import javax.validation.constraints.*; | ||
import javax.validation.Valid; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.io.IOException; | ||
import java.util.List; | ||
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2018-05-11T08:14:22.184+01:00") | ||
|
||
@Controller | ||
public class ValidatorsApiController implements ValidatorsApi { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(ValidatorsApiController.class); | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
private final HttpServletRequest request; | ||
|
||
@org.springframework.beans.factory.annotation.Autowired | ||
public ValidatorsApiController(ObjectMapper objectMapper, HttpServletRequest request) { | ||
this.objectMapper = objectMapper; | ||
this.request = request; | ||
} | ||
|
||
public ResponseEntity<List<Validator>> getValidators() { | ||
String accept = request.getHeader("Accept"); | ||
if (accept != null && accept.contains("application/json")) { | ||
try { | ||
return new ResponseEntity<List<Validator>>(objectMapper.readValue("[ { \"validator_id\" : \"eduGAIN\", \"description\" : \"validation ruleset for entities from eduGAIN\"}, { \"validator_id\" : \"eduGAIN\", \"description\" : \"validation ruleset for entities from eduGAIN\"} ]", List.class), HttpStatus.NOT_IMPLEMENTED); | ||
} catch (IOException e) { | ||
log.error("Couldn't serialize response for content type application/json", e); | ||
return new ResponseEntity<List<Validator>>(HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
return new ResponseEntity<List<Validator>>(HttpStatus.NOT_IMPLEMENTED); | ||
} | ||
|
||
public ResponseEntity<List<Status>> validate(@ApiParam(value = "An identifier for the validation to be performed. ",required=true) @PathVariable("validator_id") String validatorId,@ApiParam(value = "The metadata to be validated." ,required=true ) @Valid @RequestBody String metadata) { | ||
String accept = request.getHeader("Accept"); | ||
if (accept != null && accept.contains("application/json")) { | ||
try { | ||
return new ResponseEntity<List<Status>>(objectMapper.readValue("[ { \"status\" : \"error\", \"componentId\" : \"checkSchemas\", \"message\" : \"the entityID doesn't have the correct format\"}, { \"status\" : \"error\", \"componentId\" : \"checkSchemas\", \"message\" : \"the entityID doesn't have the correct format\"} ]", List.class), HttpStatus.NOT_IMPLEMENTED); | ||
} catch (IOException e) { | ||
log.error("Couldn't serialize response for content type application/json", e); | ||
return new ResponseEntity<List<Status>>(HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
return new ResponseEntity<List<Status>>(HttpStatus.NOT_IMPLEMENTED); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/uk/org/iay/incommon/validator/api/package-info.java
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,4 @@ | ||
/** | ||
* API classes for the metadata validator service. | ||
*/ | ||
package uk.org.iay.incommon.validator.api; |
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