Search in sources :

Example 1 with RemoteAPI

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;
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI)

Example 2 with RemoteAPI

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;
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) ConstraintViolationException(javax.validation.ConstraintViolationException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with RemoteAPI

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;
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Sort(org.springframework.data.domain.Sort) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with RemoteAPI

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);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Test(org.junit.Test)

Example 5 with RemoteAPI

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);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Test(org.junit.Test)

Aggregations

RemoteAPI (ca.corefacility.bioinformatics.irida.model.RemoteAPI)44 Test (org.junit.Test)30 RemoteAPIToken (ca.corefacility.bioinformatics.irida.model.RemoteAPIToken)6 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)6 URI (java.net.URI)5 Date (java.util.Date)5 Link (org.springframework.hateoas.Link)5 IridaOAuthException (ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException)4 Project (ca.corefacility.bioinformatics.irida.model.project.Project)4 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)3 RemoteStatus (ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus)3 Before (org.junit.Before)3 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 OAuthTokenRestTemplate (ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 MockRestServiceServer (org.springframework.test.web.client.MockRestServiceServer)2