use of ca.corefacility.bioinformatics.irida.model.IridaClientDetails in project irida by phac-nml.
the class ClientsControllerTest method testPostCreateClientError.
@Test
public void testPostCreateClientError() {
IridaClientDetails client = new IridaClientDetails();
client.setId(1L);
ExtendedModelMap model = new ExtendedModelMap();
Locale locale = LocaleContextHolder.getLocale();
String scope_read = "read";
String scope_write = "";
DataIntegrityViolationException ex = new DataIntegrityViolationException("Error: " + IridaClientDetails.CLIENT_ID_CONSTRAINT_NAME);
when(clientDetailsService.create(client)).thenThrow(ex);
String postCreateClient = controller.postCreateClient(client, scope_read, scope_write, "", "", "", model, locale);
assertEquals(ClientsController.ADD_CLIENT_PAGE, postCreateClient);
assertTrue(model.containsAttribute("errors"));
@SuppressWarnings("unchecked") Map<String, String> errors = (Map<String, String>) model.get("errors");
assertTrue(errors.containsKey("clientId"));
verify(clientDetailsService).create(client);
}
use of ca.corefacility.bioinformatics.irida.model.IridaClientDetails in project irida by phac-nml.
the class ClientsControllerTest method testGetAjaxClientList.
@SuppressWarnings("unchecked")
@Test
public void testGetAjaxClientList() {
IridaClientDetails client1 = new IridaClientDetails();
client1.setId(1L);
IridaClientDetails client2 = new IridaClientDetails();
client2.setId(2L);
Page<IridaClientDetails> clientPage = new PageImpl<>(Lists.newArrayList(client1, client2));
when(clientDetailsService.search(any(Specification.class), any(PageRequest.class))).thenReturn(clientPage);
DataTablesParams params = new DataTablesParams(1, 10, 1, "", new Sort(Sort.Direction.ASC, "createdDate"), new HashMap<>());
DataTablesResponse response = controller.getAjaxClientsList(params);
List<DataTablesResponseModel> models = response.getData();
assertEquals(2, models.size());
verify(clientDetailsService).search(any(Specification.class), any(PageRequest.class));
}
use of ca.corefacility.bioinformatics.irida.model.IridaClientDetails in project irida by phac-nml.
the class ClientsController method getAjaxClientsList.
/**
* Get a {@link DataTablesResponse} for the Clients page.
*
* @param params
* {@link DataTablesParams} for the current DataTable.
*
* @return {@link DataTablesResponse}
*/
@RequestMapping(value = "/ajax/list", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public DataTablesResponse getAjaxClientsList(@DataTablesRequest DataTablesParams params) {
Specification<IridaClientDetails> specification = IridaClientDetailsSpecification.searchClient(params.getSearchValue());
Page<IridaClientDetails> page = clientDetailsService.search(specification, new PageRequest(params.getCurrentPage(), params.getLength(), params.getSort()));
List<DataTablesResponseModel> models = new ArrayList<>();
for (IridaClientDetails client : page.getContent()) {
models.add(new DTClient(client, clientDetailsService.countActiveTokensForClient(client)));
}
return new DataTablesResponse(params, page, models);
}
use of ca.corefacility.bioinformatics.irida.model.IridaClientDetails in project irida by phac-nml.
the class ClientsController method revokeTokens.
/**
* Delete all tokens for a given {@link IridaClientDetails}
*
* @param id
* The database id of the {@link IridaClientDetails} to revoke
* tokens for
* @return redirect back to the client page
*/
@RequestMapping("/revoke")
public String revokeTokens(@RequestParam Long id) {
IridaClientDetails read = clientDetailsService.read(id);
clientDetailsService.revokeTokensForClient(read);
return "redirect:/clients/" + id;
}
use of ca.corefacility.bioinformatics.irida.model.IridaClientDetails in project irida by phac-nml.
the class ClientsController method read.
/**
* Read an individual client
*
* @param clientId
* The ID of the client to display
* @param model
* The model object for this view
* @return The view name of the client details page
*/
@RequestMapping("/{clientId}")
public String read(@PathVariable Long clientId, Model model) {
IridaClientDetails client = clientDetailsService.read(clientId);
String grants = StringUtils.collectionToDelimitedString(client.getAuthorizedGrantTypes(), ", ");
String scopes = StringUtils.collectionToDelimitedString(client.getScope(), ", ");
String autoApproveScopes = StringUtils.collectionToDelimitedString(client.getAutoApprovableScopes(), ", ");
model.addAttribute("client", client);
model.addAttribute("grants", grants);
model.addAttribute("scopes", scopes);
model.addAttribute("autoApproveScopes", autoApproveScopes);
int allTokensForClient = clientDetailsService.countTokensForClient(client);
int activeTokensForClient = clientDetailsService.countActiveTokensForClient(client);
model.addAttribute("activeTokens", activeTokensForClient);
model.addAttribute("expiredTokens", allTokensForClient - activeTokensForClient);
return CLIENT_DETAILS_PAGE;
}
Aggregations