<commit_before>package net.floodlightcontroller.routing.web;

import com.fasterxml.jackson.databind.ObjectMapper;
import net.floodlightcontroller.routing.VirtualGatewayInterface;
import org.restlet.resource.Delete;
import org.restlet.resource.Post;
import org.restlet.resource.Put;
import org.restlet.resource.ServerResource;

import java.io.IOException;

/**
 * @author <NAME> (<EMAIL>) at 12/29/17
 */
public class VirtualInterfaceResource extends ServerResource {

    @Put
    @Post
    // This also includes overwrite an existing interface
    public void addVirtualInterface(String jsonData) throws IOException {


        try {
            VirtualGatewayInterface vInterface = new ObjectMapper()
                    .reader(VirtualGatewayInterface.class)
                    .readValue(jsonData);

        }
        catch (IOException e) {
            throw new IOException(e);
        }

    }


    @Delete
    public void deleteVirtualInterface(String jsonData) throws IOException {


    }

}
<commit_msg>Okay, REST API part should be closed.<commit_after>package net.floodlightcontroller.routing.web;

import com.fasterxml.jackson.databind.ObjectMapper;
import net.floodlightcontroller.routing.IRoutingService;
import net.floodlightcontroller.routing.VirtualGateway;
import net.floodlightcontroller.routing.VirtualGatewayInterface;
import org.restlet.resource.*;

import java.io.IOException;
import java.util.Collections;
import java.util.Optional;

/**
 * @author <NAME> (<EMAIL>) at 12/29/17
 */
public class VirtualInterfaceResource extends ServerResource {

    @Get
    public Object getVirtualInterfaces() {
        IRoutingService routingService =
                (IRoutingService) getContext().getAttributes()
                        .get(IRoutingService.class.getCanonicalName());

        String gatewayName = (String) getRequestAttributes().get("gateway-name");
        String interfaceName = (String) getRequestAttributes().get("interface-name");

        Optional<VirtualGateway> gateway = routingService.getVirtualGateway(gatewayName);
        if (!gateway.isPresent()) {
            return Collections.singletonMap("INFO: ", "Virtual gateway " + gatewayName + " not found");
        }
        if (routingService.getGatewayInterfaces(gateway.get()).get().isEmpty()) {
            return Collections.singletonMap("INFO: ", "No virtual interface exists on " + gatewayName + " yet");
        }

        if (interfaceName.equals("all")) {
            return routingService.getGatewayInterfaces(gateway.get()).get();
        }
        else {
            return routingService.getGatewayInterface(interfaceName, gateway.get());
        }


    }

    @Delete
    public Object removeVirtualInterface() throws IOException {
        IRoutingService routingService =
                (IRoutingService) getContext().getAttributes()
                        .get(IRoutingService.class.getCanonicalName());

        String gatewayName = (String) getRequestAttributes().get("gateway-name");
        String interfaceName = (String) getRequestAttributes().get("interface-name");

        Optional<VirtualGateway> gateway = routingService.getVirtualGateway(gatewayName);
        if (!gateway.isPresent()) {
            return Collections.singletonMap("INFO: ", "Virtual gateway " + gatewayName + " not found");
        }
        if (routingService.getGatewayInterfaces(gateway.get()).get().isEmpty()) {
            return Collections.singletonMap("INFO: ", "No virtual interface exists on " + gatewayName + " yet");
        }

        if (interfaceName.equals("all")) {
            routingService.removeAllVirtualInterfaces(gateway.get());
            return Collections.singletonMap("INFO: ", "All virtual interface from" + gatewayName + " removed");
        }
        else {
            if (routingService.removeVirtualInterface(interfaceName, gateway.get())) {
                return Collections.singletonMap("INFO: ", "Virtual interface" + interfaceName +
                        " from gateway " + gatewayName + " removed");
            }
            else {
                return Collections.singletonMap("INFO: ", "Virtual interface" + interfaceName +
                        " from gateway " + gatewayName + "not found");
            }
        }

    }

    @Put
    @Post
    public Object createVirtualInterface(String jsonData) throws IOException {
        IRoutingService routingService =
                (IRoutingService) getContext().getAttributes()
                        .get(IRoutingService.class.getCanonicalName());

        String gatewayName = (String) getRequestAttributes().get("gateway-name");
        String interfaceName = (String) getRequestAttributes().get("interface-name");

        Optional<VirtualGateway> gateway = routingService.getVirtualGateway(gatewayName);
        if (!gateway.isPresent()) {
            return Collections.singletonMap("INFO: ", "Virtual gateway" + gatewayName + " not found");
        }

        try{
            VirtualGatewayInterface vInterface = new ObjectMapper()
                    .reader(VirtualGatewayInterface.class)
                    .readValue(jsonData);

            routingService.createVirtualInterface(gateway.get(), vInterface);
            return Collections.singletonMap("INFO: ", "Virtual interface " + interfaceName + " created on" + gatewayName );
        }
        catch (IOException e) {
            throw new IOException(e);
        }

    }


}

{'fraction_non_alphanumeric': 0.10625, 'fraction_numerical': 0.0022058823529411764, 'mean_word_length': 2.7784722222222222, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '7153971', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1322, 'n_words': 276}