use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class RemoteAPIController method connectToAPI.
/**
* Initiate a token request on a remote api if one does not yet exist. Works
* with
* {@link #handleOAuthException(HttpServletRequest, IridaOAuthException)} to
* initiate the request.
*
* @param apiId
* the ID of the api to connect to
* @param model
* the model to add attributes to.
* @return The name of the PARENT_FRAME_RELOAD_PAGE view
*/
@RequestMapping("/connect/{apiId}")
public String connectToAPI(@PathVariable Long apiId, Model model) {
RemoteAPI api = remoteAPIService.read(apiId);
projectRemoteService.getServiceStatus(api);
model.addAttribute("remoteApi", api);
return PARENT_FRAME_RELOAD_PAGE;
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class RemoteAPIController method postCreateRemoteAPI.
/**
* Create a new client
*
* @param client
* The client to add
* @param model
* Model for the view
* @param locale
* Locale of the current user session
* @return Redirect to the newly created client page, or back to the
* creation page in case of an error.
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String postCreateRemoteAPI(RemoteAPI client, Model model, Locale locale) {
Map<String, String> errors = new HashMap<>();
String responsePage = null;
try {
RemoteAPI create = remoteAPIService.create(client);
responsePage = "redirect:/remote_api/" + create.getId();
} catch (ConstraintViolationException ex) {
logger.error("Error creating api: " + ex.getMessage());
errors.putAll(getErrorsFromViolationException(ex));
} catch (DataIntegrityViolationException ex) {
logger.error("Error creating api: " + ex.getMessage());
errors.putAll(getErrorsFromDataIntegrityViolationException(ex, errorMessages, messageSource, locale));
}
if (!errors.isEmpty()) {
model.addAttribute("errors", errors);
model.addAttribute("given_name", client.getName());
model.addAttribute("given_clientId", client.getClientId());
model.addAttribute("given_clientSecret", client.getClientSecret());
model.addAttribute("given_serviceURI", client.getServiceURI());
responsePage = getAddRemoteAPIPage(model);
}
return responsePage;
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class RemoteAPIController method getAjaxAPIList.
/**
* Ajax request page for getting a list of all {@link RemoteAPI}s
*
* @param start
* The start element of the page
* @param length
* The page length
* @param draw
* Whether to draw the table
* @param sortColumn
* The column to sort on
* @param direction
* The direction of the sort
* @param searchValue
* The string search value for the table
* @param principal
* a reference to the logged in user.
* @param locale
* the locale specified by the browser.
* @return a Map for the table
*/
@RequestMapping(value = "/ajax/list", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, Object> getAjaxAPIList(@RequestParam(DataTable.REQUEST_PARAM_START) Integer start, @RequestParam(DataTable.REQUEST_PARAM_LENGTH) Integer length, @RequestParam(DataTable.REQUEST_PARAM_DRAW) Integer draw, @RequestParam(value = DataTable.REQUEST_PARAM_SORT_COLUMN, defaultValue = "0") Integer sortColumn, @RequestParam(value = DataTable.REQUEST_PARAM_SORT_DIRECTION, defaultValue = "asc") String direction, @RequestParam(DataTable.REQUEST_PARAM_SEARCH_VALUE) String searchValue, Principal principal, Locale locale) {
String sortString;
try {
sortString = SORT_COLUMNS.get(sortColumn);
} catch (IndexOutOfBoundsException ex) {
sortString = SORT_BY_ID;
}
Sort.Direction sortDirection = direction.equals(SORT_ASCENDING) ? Sort.Direction.ASC : Sort.Direction.DESC;
int pageNum = start / length;
Page<RemoteAPI> search = remoteAPIService.search(RemoteAPISpecification.searchRemoteAPI(searchValue), pageNum, length, sortDirection, sortString);
List<Map<String, String>> apiData = new ArrayList<>();
for (RemoteAPI api : search) {
Map<String, String> row = new HashMap<>();
row.put("id", api.getId().toString());
row.put("name", api.getName());
row.put("createdDate", dateFormatter.print(api.getCreatedDate(), locale));
apiData.add(row);
}
Map<String, Object> map = new HashMap<>();
map.put(DataTable.RESPONSE_PARAM_DRAW, draw);
map.put(DataTable.RESPONSE_PARAM_RECORDS_TOTAL, search.getTotalElements());
map.put(DataTable.RESPONSE_PARAM_RECORDS_FILTERED, search.getTotalElements());
map.put(DataTable.RESPONSE_PARAM_DATA, apiData);
return map;
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class ProjectRemoteServiceImplTest method testListProjectsForAPI.
@Test
public void testListProjectsForAPI() {
RemoteAPI api = new RemoteAPI();
api.setServiceURI("http://somewhere/");
String serviceURI = "http://somewhere/";
String projecsRel = serviceURI + ProjectRemoteServiceImpl.PROJECTS_BOOKMARK;
service.listProjectsForAPI(api);
verify(repository).list(projecsRel, api);
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class RemoteServiceImplTest method testRead.
@Test
public void testRead() {
String uri = "http://resource";
RemoteAPI remoteAPI = new RemoteAPI();
service.read(uri, remoteAPI);
verify(repository).read(uri, remoteAPI);
}
Aggregations