/**
   * Create a data group
   *
   * @param doi
   * @param webAddress
   * @param title
   * @return
   */
  @POST
  @Authenticated
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Produces(MediaType.APPLICATION_JSON)
  public Response mint(
      @FormParam("doi") String doi,
      @FormParam("webAddress") String webAddress,
      @FormParam("graph") String graph,
      @FormParam("title") String title,
      @FormParam("resourceType") String resourceTypeString,
      @FormParam("resourceTypesMinusDataset") Integer resourceTypesMinusDataset,
      @FormParam("finalCopy") @DefaultValue("false") Boolean finalCopy) {

    // If resourceType is specified by an integer, then use that to set the String resourceType.
    // If the user omits
    try {
      if (resourceTypesMinusDataset != null && resourceTypesMinusDataset > 0) {
        resourceTypeString = new ResourceTypes().get(resourceTypesMinusDataset).uri;
      }
    } catch (IndexOutOfBoundsException e) {
      throw new BadRequestException(
          "BCID System Unable to set resource type",
          "There was an error retrieving the resource type uri. Did you provide a valid resource type?");
    }

    if (resourceTypeString == null || resourceTypeString.isEmpty()) {
      throw new BadRequestException("ResourceType is required");
    }

    // Mint the Bcid
    if (title == null || title.isEmpty()) {
      title = resourceTypeString;
    }

    Bcid.BcidBuilder builder =
        new Bcid.BcidBuilder(resourceTypeString)
            .ezidRequest(Boolean.valueOf(settingsManager.retrieveValue("ezidRequests")))
            .doi(doi)
            .title(title)
            .graph(graph)
            .finalCopy(finalCopy);

    if (!StringUtils.isEmpty(webAddress)) {
      UriComponents webAddressComponents = UriComponentsBuilder.fromUriString(webAddress).build();
      builder.webAddress(webAddressComponents.toUri());
    }

    Bcid bcid = builder.build();
    bcidService.create(bcid, user.getUserId());

    // TODO return the bcid object here
    return Response.ok("{\"identifier\": \"" + bcid.getIdentifier() + "\"}").build();
  }
  /*
   * (non-Javadoc)
   * @see org.springframework.hateoas.MethodLinkBuilderFactory#linkTo(java.lang.Object)
   */
  @Override
  public ControllerLinkBuilder linkTo(Object invocationValue) {

    Assert.isInstanceOf(LastInvocationAware.class, invocationValue);
    LastInvocationAware invocations = (LastInvocationAware) invocationValue;

    MethodInvocation invocation = invocations.getLastInvocation();
    Iterator<Object> classMappingParameters = invocations.getObjectParameters();
    Method method = invocation.getMethod();

    String mapping = DISCOVERER.getMapping(method);
    UriComponentsBuilder builder = ControllerLinkBuilder.getBuilder().path(mapping);

    UriTemplate template = new UriTemplate(mapping);
    Map<String, Object> values = new HashMap<String, Object>();

    Iterator<String> names = template.getVariableNames().iterator();
    while (classMappingParameters.hasNext()) {
      values.put(names.next(), classMappingParameters.next());
    }

    for (BoundMethodParameter parameter : PATH_VARIABLE_ACCESSOR.getBoundParameters(invocation)) {
      values.put(parameter.getVariableName(), parameter.asString());
    }

    for (BoundMethodParameter parameter : REQUEST_PARAM_ACCESSOR.getBoundParameters(invocation)) {

      Object value = parameter.getValue();
      String key = parameter.getVariableName();

      if (value instanceof Collection) {
        for (Object element : (Collection<?>) value) {
          builder.queryParam(key, element);
        }
      } else {
        builder.queryParam(key, parameter.asString());
      }
    }

    UriComponents components =
        applyUriComponentsContributer(builder, invocation).buildAndExpand(values);
    return new ControllerLinkBuilder(UriComponentsBuilder.fromUri(components.toUri()));
  }
Esempio n. 3
0
  public CellLine getCellLine(String biosampleId) throws RestClientException {
    UriComponents uriComponents =
        UriComponentsBuilder.newInstance()
            .scheme("https")
            .host(apiHost)
            .pathSegment("api", "v0", "cell-lines", biosampleId)
            .build();

    log.trace("URI = " + uriComponents.toUriString());

    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "ApiKey " + apiUsername + ":" + apiKey);
    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);

    ResponseEntity<CellLine> responce =
        restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, entity, CellLine.class);

    log.trace("HTTP code = " + responce.getStatusCode());

    return responce.getBody();
  }
  public GoogleSearchResponse search(String searchString, String referer) {
    try {
      if (ValidatorUtil.isNull(referer)) {
        referer = "http://longfalcon.net";
      }

      String v = "1.0";
      String userip = "192.168.0.1";
      HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.set("Referer", referer);

      HttpEntity<?> requestEntity = new HttpEntity(httpHeaders);

      UriComponents uriComponents =
          UriComponentsBuilder.fromUriString(_SEARCH_URL)
              .queryParam("v", v)
              .queryParam("q", searchString)
              .queryParam("userip", userip)
              .build();
      ResponseEntity<GoogleSearchResponse> responseEntity =
          restTemplate.exchange(
              uriComponents.toUri(), HttpMethod.GET, requestEntity, GoogleSearchResponse.class);
      HttpStatus statusCode = responseEntity.getStatusCode();
      if (statusCode.is2xxSuccessful() || statusCode.is3xxRedirection()) {
        return responseEntity.getBody();
      } else {
        _log.error(
            String.format(
                "Search request: \n%s\n failed with HTTP code %s : %s",
                uriComponents.toString(), statusCode.toString(), statusCode.getReasonPhrase()));
        return null;
      }
    } catch (Exception e) {
      _log.error(e);
    }

    return null;
  }