Search in sources :

Example 11 with IridaClientDetails

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);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 12 with IridaClientDetails

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));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) Sort(org.springframework.data.domain.Sort) Specification(org.springframework.data.jpa.domain.Specification) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) Test(org.junit.Test)

Example 13 with IridaClientDetails

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);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DTClient(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTClient) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with IridaClientDetails

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;
}
Also used : IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with IridaClientDetails

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;
}
Also used : IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IridaClientDetails (ca.corefacility.bioinformatics.irida.model.IridaClientDetails)15 Test (org.junit.Test)8 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)2 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 PageRequest (org.springframework.data.domain.PageRequest)2 DataTablesParams (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams)1 DTClient (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTClient)1 PageImpl (org.springframework.data.domain.PageImpl)1 Sort (org.springframework.data.domain.Sort)1 Specification (org.springframework.data.jpa.domain.Specification)1 Authentication (org.springframework.security.core.Authentication)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1