<commit_before>package io.github.cloudiator.rest.api;


import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.cloudiator.rest.UserInfo;
import io.github.cloudiator.rest.converter.NodeConverter;
import io.github.cloudiator.rest.converter.NodeRequirementsConverter;
import io.github.cloudiator.rest.model.Node;
import io.github.cloudiator.rest.model.NodeRequest;
import io.github.cloudiator.rest.model.Queue;
import io.github.cloudiator.rest.queue.QueueService;
import io.github.cloudiator.rest.queue.QueueService.QueueItem;
import io.swagger.annotations.ApiParam;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.cloudiator.messages.Node.NodeQueryMessage;
import org.cloudiator.messages.Node.NodeQueryResponse;
import org.cloudiator.messages.Node.NodeRequestMessage;
import org.cloudiator.messages.Node.NodeRequestResponse;
import org.cloudiator.messaging.ResponseException;
import org.cloudiator.messaging.services.NodeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;


@Controller
public class NodeApiController implements NodeApi {

  private static final Logger log = LoggerFactory.getLogger(PlatformApiController.class);
  private final ObjectMapper objectMapper;
  private final HttpServletRequest request;

  @org.springframework.beans.factory.annotation.Autowired
  public NodeApiController(ObjectMapper objectMapper, HttpServletRequest request) {
    this.objectMapper = objectMapper;
    this.request = request;
  }

  @Autowired
  private NodeService nodeService;

  @Autowired
  private QueueService queueService;

  private NodeRequirementsConverter nodeRequirementsConverter = new NodeRequirementsConverter();
  private NodeConverter nodeConverter = new NodeConverter();

  @Override
  public ResponseEntity<Queue> addNode(NodeRequest nodeRequest) {
    String accept = request.getHeader("Accept");
    if (accept != null && accept.contains("application/json")) {

      final String tenant = UserInfo.of(request).tenant();
      final QueueItem<NodeRequestResponse> queueItem = queueService
          .queueCallback(tenant,
              nodeRequestResponse -> "nodeGroup/" + nodeRequestResponse.getNodeGroup().getId());

      final NodeRequestMessage nodeRequestMessage = NodeRequestMessage.newBuilder()
          .setUserId(tenant)
          .setGroupName(nodeRequest.getGroupName())
          .setNodeRequest(nodeRequirementsConverter.apply(nodeRequest.getRequirements())).build();

      nodeService.createNodesAsync(nodeRequestMessage, queueItem.getCallback());

      final HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.add(HttpHeaders.LOCATION, queueItem.getQueueLocation());

      return new ResponseEntity<Queue>(queueItem.getQueue(), httpHeaders, HttpStatus.OK);


    }
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
  }

  @Override
  public ResponseEntity<List<Node>> findNodes() {
    String accept = request.getHeader("Accept");

    final String tenant = UserInfo.of(request).tenant();

    if (accept != null && accept.contains("application/json")) {
      try {
        final NodeQueryResponse nodeQueryResponse = nodeService
            .queryNodes(NodeQueryMessage.newBuilder().setUserId(tenant).build());

        final List<Node> nodes = nodeQueryResponse.getNodesList().stream()
            .map(nodeConverter::applyBack).collect(
                Collectors.toList());

        return new ResponseEntity<>(nodes, HttpStatus.OK);<commit_msg>added group name to node request<commit_after>package io.github.cloudiator.rest.api;


import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.cloudiator.rest.UserInfo;
import io.github.cloudiator.rest.converter.NodeConverter;
import io.github.cloudiator.rest.converter.NodeRequirementsConverter;
import io.github.cloudiator.rest.model.Node;
import io.github.cloudiator.rest.model.NodeRequest;
import io.github.cloudiator.rest.model.Queue;
import io.github.cloudiator.rest.queue.QueueService;
import io.github.cloudiator.rest.queue.QueueService.QueueItem;
import io.swagger.annotations.ApiParam;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.cloudiator.messages.Node.NodeQueryMessage;
import org.cloudiator.messages.Node.NodeQueryResponse;
import org.cloudiator.messages.Node.NodeRequestMessage;
import org.cloudiator.messages.Node.NodeRequestMessage.Builder;
import org.cloudiator.messages.Node.NodeRequestResponse;
import org.cloudiator.messaging.ResponseException;
import org.cloudiator.messaging.services.NodeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;


@Controller
public class NodeApiController implements NodeApi {

  private static final Logger log = LoggerFactory.getLogger(PlatformApiController.class);
  private final ObjectMapper objectMapper;
  private final HttpServletRequest request;

  @org.springframework.beans.factory.annotation.Autowired
  public NodeApiController(ObjectMapper objectMapper, HttpServletRequest request) {
    this.objectMapper = objectMapper;
    this.request = request;
  }

  @Autowired
  private NodeService nodeService;

  @Autowired
  private QueueService queueService;

  private NodeRequirementsConverter nodeRequirementsConverter = new NodeRequirementsConverter();
  private NodeConverter nodeConverter = new NodeConverter();

  @Override
  public ResponseEntity<Queue> addNode(
      @ApiParam(value = "Node Request", required = true) @Valid @RequestBody NodeRequest nodeRequest) {
    String accept = request.getHeader("Accept");
    if (accept != null && accept.contains("application/json")) {

      final String tenant = UserInfo.of(request).tenant();
      final QueueItem<NodeRequestResponse> queueItem = queueService
          .queueCallback(tenant,
              nodeRequestResponse -> "nodeGroup/" + nodeRequestResponse.getNodeGroup().getId());

      Builder builder = NodeRequestMessage.newBuilder()
          .setUserId(tenant)
          .setNodeRequest(nodeRequirementsConverter.apply(nodeRequest.getRequirements()));

      if (nodeRequest.getGroupName() != null) {
        builder.setGroupName(nodeRequest.getGroupName());
      }

      final NodeRequestMessage nodeRequestMessage = builder.build();

      nodeService.createNodesAsync(nodeRequestMessage, queueItem.getCallback());

      final HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.add(HttpHeaders.LOCATION, queueItem.getQueueLocation());

      return new ResponseEntity<Queue>(queueItem.getQueue(), httpHeaders, HttpStatus.OK);


    }
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
  }

  @Override
  public ResponseEntity<List<Node>> findNodes() {
    String accept = request.getHeader("Accept");

    final String tenant = UserInfo.of(request).tenant();

    if (accept != null && accept.contains("application/json")) {
      try {
        final NodeQueryResponse nodeQueryResponse = nodeService
            .queryNodes(NodeQueryMessage.newBuilder().setUserId(tenant).build());

        final List<Node> nodes = nodeQueryResponse.getNodesList().stream()
            .map(nodeConverter::applyBack).collect(
                Collectors.toList());

        return new ResponseEntity<>(nodes, HttpStatus.OK);
{'fraction_non_alphanumeric': 0.09901114031793716, 'fraction_numerical': 0.0005006884466140943, 'mean_word_length': 5.030188679245283, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3109574', 'n_tokens_mistral': 2120, 'n_tokens_neox': 2072, 'n_words': 390}