From 356d2fd1deaaa9fc40457ffd636d7934a107fd20 Mon Sep 17 00:00:00 2001 From: Dayana31 <70593166+Dayana31@users.noreply.github.com> Date: Sun, 10 Apr 2022 22:45:03 -0500 Subject: Create LAB_5_ACC_2021_1.ipynb --- test/LAB_5_ACC_2021_1.ipynb | 700 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 700 insertions(+) create mode 100644 test/LAB_5_ACC_2021_1.ipynb diff --git a/test/LAB_5_ACC_2021_1.ipynb b/test/LAB_5_ACC_2021_1.ipynb new file mode 100644 index 0000000..8eed3f8 --- /dev/null +++ b/test/LAB_5_ACC_2021_1.ipynb @@ -0,0 +1,700 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "2VP6d4IEg-qk" + }, + "source": [ + "# APLICACIONES EN CIENCIAS DE COMPUTACION" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "s4LxYBghg-qy" + }, + "source": [ + "## Laboratorio 5: Algoritmo genético\n", + "Indicaciones previas:\n", + "- Las respuestas deben tener un buen fundamento teórico, se realizarán descuentos en el puntaje a respuestas que no contesten a lo solicitado\n", + "- Cualquier indicio de plagio resultará en la anulación de la prueba.\n", + "\n", + "La tarea de este laboratorio consiste en comparar métodos en la elaboración de un algoritmo genético para la resolución de la asignación de vuelos.
Al final de este notebook se encuentran las preguntas que serán evaluadas en este laboratorio. \n", + "\n", + "\n", + "#### Representacion de Individuo:\n", + "\n", + "Un objeto Individual representaa una determinada asignacion de un subconjunto de vuelos (almacenado en list_of_flights) a un conjunto de gates (almacenado en chromosome). La lista de gates disponibles que se pueden asignar a los vuelos se almacena en la variable allele_pool del individuo. Ver el siguiente grafico ilustrativo:\n", + "\n", + "\n", + "\n", + "**Usted deberá completar el código en las secciones indicadas con ######### COMPLETAR #########**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "3BiTFdyNhskY" + }, + "outputs": [], + "source": [ + "from random import seed, randint, sample, uniform, randrange\n", + "from copy import deepcopy" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IRVDEMS3g-q1" + }, + "source": [ + "### Clase Individual\n", + "\n", + "Esta es una clase para definir a un individuo de la población. Cada individuo posee un cromosoma, los vuelos a asignar, todos los posibles alelos y su respectivo fitness. Además, los métodos de esta clase permiten realizar el cruzamiento (crossover) y la mutación (mutation) sobre el cromosoma del individuo." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "wD-qU6LnGM8_" + }, + "outputs": [], + "source": [ + "class Individual(object):\n", + " \"\"\" Clase que implementa el individuo y sus operadores. El cromosoma de un individuo es una lista de caracteres,\n", + " cada elemento de la lista es un gen cuyos alelos (caracteres) posibles se indican en allele_pool\"\"\"\n", + "\n", + " def __init__(self, chromosome, list_of_flights, allele_pool): # El constructor recibe el cromosoma y el pool de alelos posibles\n", + " self.chromosome = chromosome[:]\n", + " self.list_of_flights = list_of_flights[:]\n", + " self.allele_pool = allele_pool\n", + " self.fitness = -1 # -1 indica que el individuo no ha sido evaluado\n", + "\n", + " def crossover_onepoint(self, other):\n", + " \"Retorna dos nuevos individuos del cruzamiento de un punto entre individuos self y other \"\n", + " c = randrange(len(self.chromosome))\n", + " ind1 = Individual(self.chromosome[:c] + other.chromosome[c:], self.list_of_flights, self.allele_pool)\n", + " ind2 = Individual(other.chromosome[:c] + self.chromosome[c:], self.list_of_flights, self.allele_pool)\n", + " return [ind1, ind2]\n", + " \n", + " def crossover_permutation(self, other):\n", + " new_list = list(set(self.chromosome + other.chromosome))\n", + " flights_to_assign = len(self.list_of_flights)\n", + " ind1 = Individual(sample(new_list, flights_to_assign), self.list_of_flights, self.allele_pool)\n", + " ind2 = Individual(sample(new_list, flights_to_assign), self.list_of_flights, self.allele_pool)\n", + " return [ind1, ind2]\n", + " \n", + " def crossover_uniform(self, other):\n", + " chromosome1 = []\n", + " chromosome2 = []\n", + " \"Retorna dos nuevos individuos del cruzamiento uniforme entre self y other \"\n", + " for i in range(len(self.chromosome)):\n", + " if uniform(0, 1) < 0.5:\n", + " chromosome1.append(self.chromosome[i])\n", + " chromosome2.append(other.chromosome[i])\n", + " else:\n", + " chromosome1.append(other.chromosome[i])\n", + " chromosome2.append(self.chromosome[i])\n", + " ind1 = Individual(chromosome1, self.list_of_flights, self.allele_pool)\n", + " ind2 = Individual(chromosome2, self.list_of_flights, self.allele_pool)\n", + " return [ind1, ind2]\n", + "\n", + " def mutate_swap(self):\n", + " \"Escoge dos genes e intercambia sus alelos\"\n", + " mutated_chromosome = deepcopy(self.chromosome)\n", + " mutGen1 = randrange(0, len(mutated_chromosome))\n", + " mutGen2 = randrange(0, len(mutated_chromosome))\n", + " temp = mutated_chromosome[mutGen1]\n", + " mutated_chromosome[mutGen1] = mutated_chromosome[mutGen2]\n", + " mutated_chromosome[mutGen2] = temp\n", + " return Individual(mutated_chromosome, self.list_of_flights, self.allele_pool)\n", + " \n", + " def mutate_position(self):\n", + " \"Cambia aleatoriamente el alelo de un gen.\"\n", + " mutated_chromosome = deepcopy(self.chromosome)\n", + " ######### COMPLETAR #########\n", + " ....\n", + " return Individual(mutated_chromosome, self.list_of_flights, self.allele_pool)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "c8x_4uA5i9XT" + }, + "source": [ + "### Clase Gate\n", + "\n", + "Esta es una clase abstracta para definir los lugares donde los vuelos serán asignados. Se debe hacer subclases con el fin de diferenciar los tipos de lugar donde un vuelo puede ser asignado." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "rycIj2j6i_PZ" + }, + "outputs": [], + "source": [ + "class Gate(object):\n", + " def __init__(self, identifier, x, y, z):\n", + " self.identifier = identifier\n", + " self.distance = x\n", + " self.potential_of_speed = y\n", + " self.number_of_persons_every_10m = z\n", + " \n", + " def __hash__(self):\n", + " return self.identifier" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fbHPYQ4qj6fb" + }, + "source": [ + "### Clase Sleeve\n", + "\n", + "Esta clase implementa concretamente el Gate tipo Sleeve (Manga). En este tipo de gate, los pasajeros deben realizar un recorrido a pie hasta abandonar totalmente el Gate. Se tiene en cuenta la longitud de la manga, la velocidad de los pasajeros y la cantidad de personas que pueden estar cada 10m (este valor es variable porque ya refleja el ancho de la manga, puesto que una manga más ancha permite una mayor cantidad de pasajeros)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "E9XCmO-3j472" + }, + "outputs": [], + "source": [ + "class Sleeve(Gate):\n", + " def __init__(self, identifier, length_of_sleeve, speed_of_passengers_on_sleeve, number_of_passengers_every_10m):\n", + " super().__init__(identifier, length_of_sleeve, speed_of_passengers_on_sleeve, number_of_passengers_every_10m)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0T5fySg6lytA" + }, + "source": [ + "### Clase Zone\n", + "\n", + "Esta clase implementa concretamente el Gate tipo Zone (zona). En este tipo de gate, los pasajeros son recogidos por un bus y son llevados hasta una puerta. Se tiene en cuenta la distancia de la zona a la puerta, la velocidad y capacidad del bus." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "yzwjyLG_l0nz" + }, + "outputs": [], + "source": [ + "class Zone(Gate):\n", + " def __init__(self, identifier, distance_zone_door, speed_bus, capacity_of_bus):\n", + " super().__init__(identifier, distance_zone_door, speed_bus, capacity_of_bus)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ieZ9wq8amMgT" + }, + "source": [ + "### Clase Flight\n", + "\n", + "Esta es una clase para definir a los vuelos a asignar. Cada vuelo posee una capacidad máxima, la cantidad de pasajeros, el tiempo de estacionamiento que le toma al vuelo, la longitud de las alas del avión, el tiempo de inspección al avión luego de aterrizar, el tiempo que demorarían en bajar las escaleras los pasajeros si el avión estuviera repleto, el momento de llegada al aeropuerto y el momento en que debería irse del aeropuerto." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "3Nt88YPkmLb7" + }, + "outputs": [], + "source": [ + "class Flight(object):\n", + " def __init__(self, identifier, maximum_capacity, number_of_passengers, parking_time, length_wings, inspection_time, landing_time_on_stairs, arriving_time, leaving_time):\n", + " self.identifier = identifier\n", + " self.maximum_capacity = maximum_capacity\n", + " self.number_of_passengers = number_of_passengers\n", + " self.parking_time = parking_time\n", + " self.length_wings = length_wings\n", + " self.inspection_time = inspection_time\n", + " self.landing_time_on_stairs = landing_time_on_stairs\n", + " self.arriving_time = arriving_time\n", + " self.leaving_time = leaving_time\n", + " \n", + " def __hash__(self):\n", + " return self.identifier" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tJ5cKDEOg-q4" + }, + "source": [ + "### Funciones utilitarias para generar los Gates y Vuelos\n", + "Estas son funciones utilitarias para generar automáticamente los Gates y Vuelos" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "k8p8en78FCcq" + }, + "outputs": [], + "source": [ + "def generate_list_of_gates(number_of_gates, max_length_of_sleeve=20, max_speed_of_passengers_on_sleeve=3, max_number_of_passengers_every_10m=12, max_distance_zone_door=50, max_speed_bus=15, max_capacity_of_bus=200):\n", + " list_of_gates = list()\n", + "\n", + " for gate_identifier in range(number_of_gates):\n", + " gate_type = randint(0, 1)\n", + "\n", + " if gate_type == 0:\n", + " distance = randint(1, max_length_of_sleeve)\n", + " potential_of_speed = randint(1, max_speed_of_passengers_on_sleeve)\n", + " number_of_persons_every_10m = randint(1, max_number_of_passengers_every_10m)\n", + "\n", + " gate = Sleeve(gate_identifier, distance, potential_of_speed, number_of_persons_every_10m)\n", + " else:\n", + " distance = randint(1, max_distance_zone_door)\n", + " potential_of_speed = randint(1, max_speed_bus)\n", + " number_of_persons_every_10m = randint(1, max_capacity_of_bus)\n", + "\n", + " gate = Zone(gate_identifier, distance, potential_of_speed, number_of_persons_every_10m)\n", + " \n", + " list_of_gates.append(gate)\n", + " \n", + " return list_of_gates\n", + "\n", + "def generate_list_of_flights(number_of_flights, max_maximum_capacity=100, max_number_of_passengers_factor=0.8, max_parking_time=30, max_length_wings=25, max_inspection_time=180, max_landing_time_on_stairs=60, max_arriving_time=200, max_leaving_time=1000):\n", + " list_of_flights = list()\n", + "\n", + " max_number_of_passengers = max_number_of_passengers_factor * max_maximum_capacity\n", + "\n", + " for flight_identifier in range(number_of_flights):\n", + " maximum_capacity = randint(max_number_of_passengers, max_maximum_capacity)\n", + " number_of_passengers = randint(1, max_number_of_passengers)\n", + " parking_time = randint(1, max_parking_time)\n", + " length_wings = randint(1, max_length_wings)\n", + " inspection_time = randint(1, max_inspection_time)\n", + " landing_time_on_stairs = randint(1, max_landing_time_on_stairs)\n", + " arriving_time = randint(1, max_arriving_time)\n", + " leaving_time = randint(max_arriving_time + 1, max_leaving_time)\n", + "\n", + " flight = Flight(flight_identifier, maximum_capacity, number_of_passengers, parking_time, length_wings, inspection_time, landing_time_on_stairs, arriving_time, leaving_time)\n", + " \n", + " list_of_flights.append(flight)\n", + " \n", + " return list_of_flights" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "uHsytNf6oaXJ" + }, + "source": [ + "### Funciones utilitarias para ordenar los Vuelos y Gates\n", + "Estas son funciones utilitarias para ordenar los Vuelos acorde a su deseabilidad y los Gates por su flujo personas" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "25baejsnob3d" + }, + "outputs": [], + "source": [ + "def process_desirability(n):\n", + " return n.number_of_passengers / (n.leaving_time - n.arriving_time)\n", + "\n", + "def process_flow(n):\n", + " return n.number_of_persons_every_10m * n.potential_of_speed * 10 / n.distance" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Gqws5RELpMG1" + }, + "source": [ + "### Funciones utilitarias para el Algoritmo Genético\n", + "Estas son funciones utilitarias para realizar el Algoritmo Genético que se encargue de la asignación de vuelos" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Glf8GsaujEF6" + }, + "outputs": [], + "source": [ + "# Inicialización aleatoria de la población\n", + "def init_population(population_number, flights_to_assign, allele_pool, list_of_flights):\n", + " population = []\n", + " for i in range(population_number):\n", + " new_chromosome_for_individual = sample(allele_pool, flights_to_assign)\n", + " list_of_flights_for_individual = sample(list_of_flights, flights_to_assign)\n", + " population.append( Individual(new_chromosome_for_individual, list_of_flights_for_individual, allele_pool) )\n", + " return population\n", + "\n", + "# Funcion de fitness: evalua un individuo dada su lista de vuelos (solution_flights) y los gates asignados (solution_gates)\n", + "# El fitness representa la suma total de ratios de numeros de pasajeros desembarcados por unidad de tiempo en cada gate asignado \n", + "def fitness(solution_flights, solution_gates):\n", + " grace_time = 5/100\n", + "\n", + " cumulative_time = 0\n", + " for flight, gate in zip(solution_flights, solution_gates):\n", + " number_of_passengers = flight.number_of_passengers\n", + " if isinstance(gate, Sleeve):\n", + " disembarkation_time_of_passengers = ( (number_of_passengers * (gate.distance + flight.length_wings) / process_flow(gate)) + flight.parking_time + flight.inspection_time ) * (1 + grace_time)\n", + " else:\n", + " disembarkation_time_of_passengers = ( (number_of_passengers * gate.distance / process_flow(gate)) + flight.parking_time + (flight.landing_time_on_stairs * number_of_passengers / flight.maximum_capacity) + flight.inspection_time ) * (1 + grace_time)\n", + " cumulative_time += number_of_passengers / disembarkation_time_of_passengers\n", + " return cumulative_time\n", + "\n", + "# Evaluar la población con la función fitness\n", + "def evaluate_population(population, fitness_fn):\n", + " \"\"\" Evalua una poblacion de individuos con la funcion de fitness pasada \"\"\"\n", + " population_size = len(population)\n", + " for i in range(population_size):\n", + " if population[i].fitness == -1: # Evalúa sólo si el individuo no esta evaluado\n", + " population[i].fitness = fitness_fn(population[i].list_of_flights, population[i].chromosome)\n", + "\n", + "# Selección de parientes por el método roulette\n", + "def select_parents_roulette(population):\n", + " population_size = len(population)\n", + " \n", + " sumfitness = sum([indiv.fitness for indiv in population])\n", + " pickfitness = uniform(0, sumfitness)\n", + " cumfitness = 0\n", + " for i in range(population_size):\n", + " cumfitness += population[i].fitness\n", + " if cumfitness > pickfitness: \n", + " iParent1 = i\n", + " break\n", + " \n", + " sumfitness = sumfitness - population[iParent1].fitness\n", + " pickfitness = uniform(0, sumfitness)\n", + " cumfitness = 0\n", + " for i in range(population_size):\n", + " if i == iParent1:\n", + " continue\n", + " cumfitness += population[i].fitness\n", + " if cumfitness > pickfitness: \n", + " iParent2 = i\n", + " break\n", + " return (population[iParent1], population[iParent2])\n", + "\n", + "# Selección de parientes por el método tournament\n", + "def select_parents_tournament(population, percentage_size):\n", + " population_size = len(population)\n", + " tournament_size = int(percentage_size*population_size/100)\n", + " \n", + " # Escoge el primer padre\n", + " tournament_pool = sample(population, tournament_size)\n", + " max_fitness = -1\n", + " for i in range(len(tournament_pool)): # recorre los individuos que participan en el torneo buscando el mejor individuo\n", + " if tournament_pool[i].fitness > max_fitness:\n", + " max_fitness = tournament_pool[i].fitness\n", + " iParent1 = i\n", + " \n", + " # Escoge el segundo padre\n", + " ######### COMPLETAR #########\n", + " ....\n", + " return (population[iParent1], population[iParent2])\n", + "\n", + "# Selección de la nueva población\n", + "def select_survivors(population, offspring_population, numsurvivors):\n", + " next_population = []\n", + " population.extend(offspring_population) # Une las dos poblaciones\n", + " survivors = sorted(population, key=lambda x: x.fitness, reverse=True)[:numsurvivors]\n", + " next_population.extend(survivors)\n", + " return next_population\n", + "\n", + "def genetic_algorithm(list_of_flights, list_of_gates, num_individuals, flights_to_assign, fitness_fn, n_generations, selection_fn=\"roulette\", crossover=\"onepoint\", mutation=\"position\", percentage_size=5, p_mut=0.05):\n", + " seed(0)\n", + "\n", + " allele_pool = list_of_gates\n", + "\n", + " #Inicializa una poblacion inicial de forma aleatoria\n", + " population = init_population(num_individuals, flights_to_assign, allele_pool, list_of_flights)\n", + "\n", + " population_size = len(population)\n", + " ######### COMPLETAR #########\n", + " ....\n", + " \n", + " for _ in range(n_generations): # Por cada generacion\n", + " \n", + " ## Selecciona las parejas de padres para cruzamiento\n", + " mating_pool = []\n", + " for i in range(int(population_size/2)):\n", + " if selection_fn == \"roulette\":\n", + " ######### COMPLETAR #########\n", + " ....\n", + " elif selection_fn == \"tournament\":\n", + " mating_pool.append(select_parents_tournament(population, percentage_size))\n", + "\n", + " ## Crea la poblacion descendencia cruzando las parejas del mating pool \n", + " offspring_population = []\n", + " for i in range(len(mating_pool)):\n", + " if crossover == \"onepoint\":\n", + " offspring_population.extend( mating_pool[i][0].crossover_onepoint(mating_pool[i][1]) )\n", + " elif crossover == \"permutation\":\n", + " ######### COMPLETAR #########\n", + " ....\n", + " elif crossover == \"uniform\":\n", + " ######### COMPLETAR #########\n", + " ....\n", + " \n", + " ## Aplica el operador de mutacion con probabilidad p_mut en cada hijo generado\n", + " for i in range(len(offspring_population)):\n", + " if uniform(0, 1) < p_mut: \n", + " if mutation == \"swap\":\n", + " ######### COMPLETAR #########\n", + " ....\n", + " elif mutation == \"position\":\n", + " offspring_population[i] = offspring_population[i].mutate_position()\n", + "\n", + " ######### COMPLETAR #########\n", + " ....\n", + " \n", + " best = sorted(population, key=lambda x: x.fitness, reverse=True)[0]\n", + "\n", + " return best" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "pc90jPukpbwN" + }, + "source": [ + "### Funciones utilitarias para manejar la solución del Algoritmo Genético\n", + "Esta es una función utilitarias que permite mostrar la configuración usada en el Algoritmo Genético y la asignación de Vuelos a Gates encontrada en la solución" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "yb6LUKwKpXDJ" + }, + "outputs": [], + "source": [ + "def make_solution_report(solution, selection_fn, crossover, mutation):\n", + " print(\"Selection: {} - Crossover: {} - Mutation: {} - Fitness: {}\".format(selection_fn, crossover, mutation, solution.fitness), flush=True)\n", + " print(\" - \".join([\"Flight {} in {} {}\".format(flight.identifier, \"Zone\" if isinstance(gate, Zone) == True else \"Sleeve\", gate.identifier) for flight, gate in zip(solution.list_of_flights, solution.chromosome)]) + \"\\n\", flush=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "qYjVdTfeg-q6" + }, + "source": [ + "## Algoritmo Genético " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1m0pxINHqQ2m" + }, + "source": [ + "### Generación de Gates y Vuelos \n", + "\n", + "Implementación para generar los Gates y Vuelos, **sin filtrar los primeros N vuelos más deseables que pueden ser asignados, dejando el trabajo de selección de vuelos al Algoritmo Genético**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "DaqP5VHngUVg" + }, + "outputs": [], + "source": [ + "seed(0)\n", + "\n", + "number_of_gates = 7\n", + "number_of_flights = 20\n", + "\n", + "list_of_gates = generate_list_of_gates(number_of_gates)\n", + "list_of_flights = generate_list_of_flights(number_of_flights)\n", + "\n", + "number_of_gates = len(list_of_gates)\n", + "number_of_flights = len(list_of_flights)\n", + "\n", + "flights_to_assign = number_of_flights if number_of_flights <= number_of_gates\telse number_of_gates\n", + " \n", + "list_of_flights = sorted(list_of_flights, key=process_desirability, reverse=True)\n", + "list_of_gates = sorted(list_of_gates, key=process_flow, reverse=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "PmmLPnvYrP6v" + }, + "source": [ + "### Experimentación con el Algoritmo Genético " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "CnfOnMijrP6x" + }, + "outputs": [], + "source": [ + "num_individuals = 100\n", + "\n", + "fitness_fn = fitness\n", + "n_generations = 20\n", + "\n", + "best_fitness = 0\n", + "\n", + "selection_fn = \"roulette\"\n", + "crossover = \"onepoint\"\n", + "mutation = \"position\"\n", + "\n", + "solution = genetic_algorithm(list_of_flights, list_of_gates, num_individuals, flights_to_assign, fitness_fn, n_generations, selection_fn, crossover, mutation)\n", + "\n", + "make_solution_report(solution, selection_fn, crossover, mutation)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "wDZA5IJ5gUVh" + }, + "outputs": [], + "source": [ + "num_individuals = 100\n", + "\n", + "fitness_fn = fitness\n", + "n_generations = 20\n", + "\n", + "best_fitness = 0\n", + "\n", + "######### COMPLETAR #########\n", + "for selection_fn in [\"roulette\", \"tournament\"]: # por cada operador de seleccion\n", + " for crossover in [....]: # por cada operador de cruzamiento\n", + " for mutation in [....]: # por cada operador de mutacion\n", + " ....\n", + "\n", + "print(\"Best Fitness: {}\".format(best_fitness))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JnfUrB-aqegj" + }, + "source": [ + "# Preguntas:" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "yZHjKv4Lyfa2" + }, + "source": [ + "**1.** Completar el código\n", + "\n", + "**(4 Puntos)**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xCdMlpt1vpJj" + }, + "source": [ + "**2.** Para la \"Generación de Gates y Vuelos\", experimentar con el algoritmo genético usando las siguientes configuraciones:\n", + "\n", + "- selection_fn: \"roulette\", \"tournament\"\n", + "- crossover: \"onepoint\", \"uniform\", \"permutation\"\n", + "- mutation: \"position\", \"swap\"\n", + "\n", + "En total son 12 combinaciones a realizar. En cada configuración se debe usar la función \"make_solution_report\" para obtener los resultados. La lista de Vuelos y Gates sólo se generan 1 vez, a partir de las cuales se experimenta con cada configuración del Algoritmo Genético.\n", + "\n", + "**No modificar los valores de \"percentage_size\" y \"p_mut\" al ejecutar el algoritmo genético**\n", + "\n", + "**Se debe mostrar el código respectivo y la solución generada en cada configuración o se considerará como inválido. Para este fin, puede agregar celdas a su gusto.**\n", + "\n", + "**(5 Puntos, cada 3 configuraciones realizadas equivale a 1 punto)**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "iobk9RW2vtcr" + }, + "source": [ + "**3.** Para la \"Generación de Gates y Vuelos no restringida\", seleccionar las soluciones con el mejor fitness.\n", + "\n", + "**En total debería tener 5 configuraciones con el mejor fitness (contando todos los decimales devueltos en la impresión de make_solution_report**\n", + "\n", + "**(5 Puntos, cada configuración explicada equivale a 1 punto)**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "h1-xDv92SYnF" + }, + "source": [ + "**4.** Por cada solución (de la pregunta 3), explicar teóricamente porque dicha configuración (\"selection_fn\", \"crossover\" y \"mutation\") obtiene el mejor fitness. Se debe tener en cuenta que en este caso el Algoritmo Genético se encargó de elegir los vuelos a ser asignados.\n", + "\n", + "**Es necesario que indique en que parte del código el Algoritmo Genético eligió los vuelos, o las justificaciones teóricas no se considerarán válidas.**\n", + "\n", + "**Se debe explicar teóricamente cada configuración por separado, o se considerará como inválido.**\n", + "\n", + "**En total debería tener 5 configuraciones con el mejor fitness (contando todos los decimales devueltos en la impresión de make_solution_report**\n", + "\n", + "**(6 Puntos, indicar la parte del código el Algoritmo Genético eligió los vuelos equivale 1 punto, y cada configuración explicada equivale a 1 punto)**" + ] + } + ], + "metadata": { + "colab": { + "collapsed_sections": [], + "name": "LAB_5_ACC_2021_1.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} -- cgit v1.2.3 From b84975e11b70045c2eaa9e1981da1478513bf51f Mon Sep 17 00:00:00 2001 From: Dayana31 <70593166+Dayana31@users.noreply.github.com> Date: Mon, 11 Apr 2022 01:55:25 -0500 Subject: Clases para algoritmo en Java --- .gitignore | 2 + VRP/build.xml | 73 ++ VRP/manifest.mf | 3 + VRP/nbproject/build-impl.xml | 1771 +++++++++++++++++++++++++++++++++ VRP/nbproject/genfiles.properties | 8 + VRP/nbproject/project.properties | 95 ++ VRP/nbproject/project.xml | 15 + VRP/src/Algoritmo/Almacen.java | 24 + VRP/src/Algoritmo/Ciudad.java | 18 + VRP/src/Algoritmo/Main.java | 15 + VRP/src/Algoritmo/PlanTransporte.java | 14 + VRP/src/Algoritmo/TipoAlmacen.java | 15 + VRP/src/Algoritmo/Tramo.java | 24 + VRP/src/Algoritmo/VRP.java | 57 ++ VRP/src/Algoritmo/Vehiculo.java | 18 + 15 files changed, 2152 insertions(+) create mode 100644 .gitignore create mode 100644 VRP/build.xml create mode 100644 VRP/manifest.mf create mode 100644 VRP/nbproject/build-impl.xml create mode 100644 VRP/nbproject/genfiles.properties create mode 100644 VRP/nbproject/project.properties create mode 100644 VRP/nbproject/project.xml create mode 100644 VRP/src/Algoritmo/Almacen.java create mode 100644 VRP/src/Algoritmo/Ciudad.java create mode 100644 VRP/src/Algoritmo/Main.java create mode 100644 VRP/src/Algoritmo/PlanTransporte.java create mode 100644 VRP/src/Algoritmo/TipoAlmacen.java create mode 100644 VRP/src/Algoritmo/Tramo.java create mode 100644 VRP/src/Algoritmo/VRP.java create mode 100644 VRP/src/Algoritmo/Vehiculo.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5fe501 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/VRP/nbproject/private/ +/VRP/build/ diff --git a/VRP/build.xml b/VRP/build.xml new file mode 100644 index 0000000..33b72e9 --- /dev/null +++ b/VRP/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project VRP. + + + diff --git a/VRP/manifest.mf b/VRP/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/VRP/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/VRP/nbproject/build-impl.xml b/VRP/nbproject/build-impl.xml new file mode 100644 index 0000000..4367b20 --- /dev/null +++ b/VRP/nbproject/build-impl.xml @@ -0,0 +1,1771 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/VRP/nbproject/genfiles.properties b/VRP/nbproject/genfiles.properties new file mode 100644 index 0000000..1ff5f4f --- /dev/null +++ b/VRP/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=e2f7ff6d +build.xml.script.CRC32=04b6befe +build.xml.stylesheet.CRC32=f85dc8f2@1.98.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=e2f7ff6d +nbproject/build-impl.xml.script.CRC32=0fe6cb3b +nbproject/build-impl.xml.stylesheet.CRC32=d549e5cc@1.98.0.48 diff --git a/VRP/nbproject/project.properties b/VRP/nbproject/project.properties new file mode 100644 index 0000000..6689d76 --- /dev/null +++ b/VRP/nbproject/project.properties @@ -0,0 +1,95 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/VRP.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/VRP +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=VRP +main.class= +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/VRP/nbproject/project.xml b/VRP/nbproject/project.xml new file mode 100644 index 0000000..f980bc3 --- /dev/null +++ b/VRP/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + VRP + + + + + + + + + diff --git a/VRP/src/Algoritmo/Almacen.java b/VRP/src/Algoritmo/Almacen.java new file mode 100644 index 0000000..52f3f13 --- /dev/null +++ b/VRP/src/Algoritmo/Almacen.java @@ -0,0 +1,24 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package Algoritmo; + +/** + * + * @author DAYANA + */ +public class Almacen { + Ciudad ciudad; + String region; + TipoAlmacen tipo; + + public Almacen(Ciudad ciudad, String region, TipoAlmacen tipo) { + this.ciudad = ciudad; + this.region = region; + this.tipo = tipo; + } + + +} diff --git a/VRP/src/Algoritmo/Ciudad.java b/VRP/src/Algoritmo/Ciudad.java new file mode 100644 index 0000000..81ef2c6 --- /dev/null +++ b/VRP/src/Algoritmo/Ciudad.java @@ -0,0 +1,18 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package Algoritmo; + +/** + * + * @author DAYANA + */ +public class Ciudad { + String nombre; + String region; + double longitud; + double latitud; + +} diff --git a/VRP/src/Algoritmo/Main.java b/VRP/src/Algoritmo/Main.java new file mode 100644 index 0000000..8b8aa93 --- /dev/null +++ b/VRP/src/Algoritmo/Main.java @@ -0,0 +1,15 @@ +package Algoritmo; + +/** + * + * @author DAYANA + */ +public class Main { + + public static void main (String[] args){ + int num_iter=45; + VRP vrp = new VRP(); + vrp.init_data(); + vrp.genetic_algorithm(num_iter); + } +} diff --git a/VRP/src/Algoritmo/PlanTransporte.java b/VRP/src/Algoritmo/PlanTransporte.java new file mode 100644 index 0000000..cf5d66b --- /dev/null +++ b/VRP/src/Algoritmo/PlanTransporte.java @@ -0,0 +1,14 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package Algoritmo; + +/** + * + * @author DAYANA + */ +public class PlanTransporte { + +} diff --git a/VRP/src/Algoritmo/TipoAlmacen.java b/VRP/src/Algoritmo/TipoAlmacen.java new file mode 100644 index 0000000..2f107ed --- /dev/null +++ b/VRP/src/Algoritmo/TipoAlmacen.java @@ -0,0 +1,15 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package Algoritmo; + +/** + * + * @author DAYANA + */ +public class TipoAlmacen { + String nombre; + double capacidad; +} diff --git a/VRP/src/Algoritmo/Tramo.java b/VRP/src/Algoritmo/Tramo.java new file mode 100644 index 0000000..eb2955d --- /dev/null +++ b/VRP/src/Algoritmo/Tramo.java @@ -0,0 +1,24 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package Algoritmo; + +/** + * + * @author DAYANA + */ +public class Tramo { + Ciudad ciudad1; + Ciudad ciudad2; + double distancia; + + public Tramo(Ciudad ciudad1, Ciudad ciudad2, double distancia) { + this.ciudad1 = ciudad1; + this.ciudad2 = ciudad2; + this.distancia = distancia; + } + + +} diff --git a/VRP/src/Algoritmo/VRP.java b/VRP/src/Algoritmo/VRP.java new file mode 100644 index 0000000..b1423b9 --- /dev/null +++ b/VRP/src/Algoritmo/VRP.java @@ -0,0 +1,57 @@ + +package Algoritmo; + +/** + * + * @author DAYANA + */ + + +public class VRP { + + + public static void genetic_algorithm(int max_iter){ + //generar poblacion inicial aleatoria + PlanTransporte poblacion[] = new PlanTransporte[200]; + PlanTransporte nueva_generacion[] = new PlanTransporte[200]; + + poblacion = init_population(); + + //evaluar fitness de la poblacion + evaluar(poblacion); + + for(int i=1;i Date: Mon, 11 Apr 2022 01:58:05 -0500 Subject: Clases compiladas --- .gitignore | 1 + VRP/src/Algoritmo/VRP.java | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c5fe501..849623f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /VRP/nbproject/private/ /VRP/build/ +/VRP/dist/ diff --git a/VRP/src/Algoritmo/VRP.java b/VRP/src/Algoritmo/VRP.java index b1423b9..a512e40 100644 --- a/VRP/src/Algoritmo/VRP.java +++ b/VRP/src/Algoritmo/VRP.java @@ -28,15 +28,15 @@ public class VRP { } - private static Tramo[] generar_nueva_generacion(Tramo[] poblacion) { + private static PlanTransporte[] generar_nueva_generacion(PlanTransporte[] poblacion) { return null; } - private static Tramo[] survive(Tramo[] poblacion, Tramo[] nueva_generacion) { + private static PlanTransporte[] survive(PlanTransporte[] poblacion, PlanTransporte[] nueva_generacion) { return null; } - public static Tramo[] init_population(){ + public static PlanTransporte[] init_population(){ for(int i=1;i<10;i++){ @@ -46,7 +46,7 @@ public class VRP { return null; } - public static void evaluar(Tramo[] poblacion){ + public static void evaluar(PlanTransporte[] poblacion){ } -- cgit v1.2.3 From 7b36b160afa08f6f6e58c7368b4a9d49fa2bce59 Mon Sep 17 00:00:00 2001 From: Dayana31 <70593166+Dayana31@users.noreply.github.com> Date: Thu, 21 Apr 2022 18:31:15 -0500 Subject: Gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d69fa8b..fca6674 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ hs_err_pid* replay_pid* # JS +*/node_modules \ No newline at end of file -- cgit v1.2.3 From 758d03eae1d7d83c8e7685fa04e8ae9b3a62bddb Mon Sep 17 00:00:00 2001 From: Dayana31 <70593166+Dayana31@users.noreply.github.com> Date: Fri, 22 Apr 2022 00:16:25 -0500 Subject: node_modules en gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fca6674..2489cb0 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ hs_err_pid* replay_pid* # JS -*/node_modules \ No newline at end of file +node_modules \ No newline at end of file -- cgit v1.2.3 From 685e55b7db795579f69bb158276fbb4cec0a14e1 Mon Sep 17 00:00:00 2001 From: Dayana31 <70593166+Dayana31@users.noreply.github.com> Date: Tue, 24 May 2022 21:48:43 -0500 Subject: Avance dao, controllers --- .../odiparback/controllers/AlmacenController.java | 55 ++++++++++++++++++++++ .../odiparback/controllers/AveriaController.java | 5 ++ .../odiparback/controllers/CamionController.java | 5 ++ .../odiparback/controllers/PedidoController.java | 5 ++ .../pe/edu/pucp/odiparback/dao/AlmacenDao.java | 13 +++++ .../java/pe/edu/pucp/odiparback/dao/AveriaDao.java | 12 +++++ .../java/pe/edu/pucp/odiparback/dao/CamionDao.java | 13 +++++ .../pe/edu/pucp/odiparback/dao/ClienteDao.java | 13 +++++ .../java/pe/edu/pucp/odiparback/dao/PedidoDao.java | 13 +++++ .../java/pe/edu/pucp/odiparback/dao/RegionDao.java | 13 +++++ .../java/pe/edu/pucp/odiparback/dao/RutaDao.java | 13 +++++ .../pe/edu/pucp/odiparback/dao/TipoAveriaDao.java | 13 +++++ .../pe/edu/pucp/odiparback/dao/TipoCamionDao.java | 13 +++++ .../java/pe/edu/pucp/odiparback/dao/TramoDao.java | 13 +++++ .../pe/edu/pucp/odiparback/dao/UsuarioDao.java | 14 ++++++ .../pucp/odiparback/services/AlmacenService.java | 33 +++++++++++++ 16 files changed, 246 insertions(+) create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AlmacenController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AveriaController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/CamionController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PedidoController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/AlmacenDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/AveriaDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/CamionDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/ClienteDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/PedidoDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/RegionDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/RutaDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TipoAveriaDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TipoCamionDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TramoDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/UsuarioDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/AlmacenService.java diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AlmacenController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AlmacenController.java new file mode 100644 index 0000000..e8d32a0 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AlmacenController.java @@ -0,0 +1,55 @@ +package pe.edu.pucp.odiparback.controllers; + +import pe.edu.pucp.odiparback.models.Almacen; +import pe.edu.pucp.odiparback.services.AlmacenService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/almacen") +@CrossOrigin +public class AlmacenController { + @Autowired + AlmacenService almacenService; + + @GetMapping(value = "/") + List getAll(){ + return almacenService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "almacen",key = "#id") + Almacen get(@PathVariable int id)throws AuthenticationException{ + return almacenService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody Almacen almacen)throws SQLException{ + almacenService.register(almacen); + } + + @PutMapping(value = "/") + Almacen update(@RequestBody Almacen almacen)throws SQLException{ + return almacenService.update(almacen); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "almacen", allEntries = true) + void delete(@PathVariable int id){ + almacenService.delete(id); + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AveriaController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AveriaController.java new file mode 100644 index 0000000..ae107cf --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AveriaController.java @@ -0,0 +1,5 @@ +package pe.edu.pucp.odiparback.controllers; + +public class AveriaController { + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/CamionController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/CamionController.java new file mode 100644 index 0000000..e455438 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/CamionController.java @@ -0,0 +1,5 @@ +package pe.edu.pucp.odiparback.controllers; + +public class CamionController { + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PedidoController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PedidoController.java new file mode 100644 index 0000000..e875f78 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PedidoController.java @@ -0,0 +1,5 @@ +package pe.edu.pucp.odiparback.controllers; + +public class PedidoController { + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/AlmacenDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/AlmacenDao.java new file mode 100644 index 0000000..e728313 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/AlmacenDao.java @@ -0,0 +1,13 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.Almacen; + + +public interface AlmacenDao { + public List getAll(); + public Almacen get(int id); + public void register(Almacen almacen); + public Almacen update(Almacen almacen); + public void delete(int id); +} \ No newline at end of file diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/AveriaDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/AveriaDao.java new file mode 100644 index 0000000..ebd56d3 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/AveriaDao.java @@ -0,0 +1,12 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.Averia; + +public interface AveriaDao { + public List getAll(); + public Averia get(int id); + public void register(Averia averia); + public Averia update(Averia averia); + public void delete(int id); +} \ No newline at end of file diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/CamionDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/CamionDao.java new file mode 100644 index 0000000..d1a81f1 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/CamionDao.java @@ -0,0 +1,13 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.Camion; + + +public interface CamionDao { + public List getAll(); + public Camion get(int id); + public void register(Camion camion); + public Camion update(Camion camion); + public void delete(int id); +} \ No newline at end of file diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/ClienteDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/ClienteDao.java new file mode 100644 index 0000000..531f02c --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/ClienteDao.java @@ -0,0 +1,13 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.Cliente; + + +public interface ClienteDao { + public List getAll(); + public Cliente get(int id); + public void register(Cliente cliente); + public Cliente update(Cliente cliente); + public void delete(int id); +} \ No newline at end of file diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/PedidoDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/PedidoDao.java new file mode 100644 index 0000000..2b619ab --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/PedidoDao.java @@ -0,0 +1,13 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.Pedido; + + +public interface PedidoDao { + public List getAll(); + public Pedido get(int id); + public void register(Pedido pedido); + public Pedido update(Pedido pedido); + public void delete(int id); +} \ No newline at end of file diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/RegionDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/RegionDao.java new file mode 100644 index 0000000..b4673e1 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/RegionDao.java @@ -0,0 +1,13 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.Region; + + +public interface RegionDao { + public List getAll(); + public Region get(int id); + public void register(Region region); + public Region update(Region region); + public void delete(int id); +} \ No newline at end of file diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/RutaDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/RutaDao.java new file mode 100644 index 0000000..9dd79d5 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/RutaDao.java @@ -0,0 +1,13 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.Ruta; + + +public interface RutaDao { + public List getAll(); + public Ruta get(int id); + public void register(Ruta ruta); + public Ruta update(Ruta ruta); + public void delete(int id); +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TipoAveriaDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TipoAveriaDao.java new file mode 100644 index 0000000..2d98140 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TipoAveriaDao.java @@ -0,0 +1,13 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.TipoAveria; + + +public interface TipoAveriaDao { + public List getAll(); + public TipoAveria get(int id); + public void register(TipoAveria tipoAveria); + public TipoAveria update(TipoAveria tipoAveria); + public void delete(int id); +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TipoCamionDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TipoCamionDao.java new file mode 100644 index 0000000..4340dfc --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TipoCamionDao.java @@ -0,0 +1,13 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.TipoCamion; + + +public interface TipoCamionDao { + public List getAll(); + public TipoCamion get(int id); + public void register(TipoCamion tipoCamion); + public TipoCamion update(TipoCamion tipoCamion); + public void delete(int id); +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TramoDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TramoDao.java new file mode 100644 index 0000000..ddd573e --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TramoDao.java @@ -0,0 +1,13 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.Tramo; + + +public interface TramoDao { + public List getAll(); + public Tramo get(int id); + public void register(Tramo tramo); + public Tramo update(Tramo tramo); + public void delete(int id); +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/UsuarioDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/UsuarioDao.java new file mode 100644 index 0000000..b8b5eca --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/UsuarioDao.java @@ -0,0 +1,14 @@ +package pe.edu.pucp.odiparback.dao; + +import java.util.List; +import pe.edu.pucp.odiparback.models.Usuario; + + +public interface UsuarioDao { + public List getAll(); + public Usuario get(int id); + public void register(Usuario usuario); + public Usuario update(Usuario usuario); + public void delete(int id); +} + diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/AlmacenService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/AlmacenService.java new file mode 100644 index 0000000..9bafcd6 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/AlmacenService.java @@ -0,0 +1,33 @@ +package pe.edu.pucp.odiparback.services; + +import java.util.List; +import pe.edu.pucp.odiparback.dao.AlmacenDao; +import pe.edu.pucp.odiparback.models.Almacen; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class AlmacenService { + @Autowired + AlmacenDao daoAlmacen; + + public List getAll(){ + return daoAlmacen.getAll(); + } + + public Almacen get(int id){ + return daoAlmacen.get(id); + } + + public void register(Almacen almacen){ + daoAlmacen.register(almacen); + } + + public Almacen update(Almacen almacen){ + return daoAlmacen.update(almacen); + } + + public void delete(int id){ + daoAlmacen.delete(id); + } +} -- cgit v1.2.3 From 0a6262eed672dc25f9d0efefc836a370541b6020 Mon Sep 17 00:00:00 2001 From: Dayana31 <70593166+Dayana31@users.noreply.github.com> Date: Wed, 25 May 2022 00:46:47 -0500 Subject: Dao, Controller y Services --- .../odiparback/controllers/AveriaController.java | 50 ++++++++++++++++++++ .../odiparback/controllers/CamionController.java | 49 ++++++++++++++++++++ .../odiparback/controllers/ClienteController.java | 54 ++++++++++++++++++++++ .../pucp/odiparback/controllers/PTGController.java | 53 +++++++++++++++++++++ .../odiparback/controllers/PedidoController.java | 49 ++++++++++++++++++++ .../odiparback/controllers/RegionController.java | 54 ++++++++++++++++++++++ .../odiparback/controllers/RutaController.java | 54 ++++++++++++++++++++++ .../controllers/TipoAveriaController.java | 54 ++++++++++++++++++++++ .../controllers/TipoCamionController.java | 54 ++++++++++++++++++++++ .../odiparback/controllers/TramoController.java | 54 ++++++++++++++++++++++ .../controllers/TramoRutaController.java | 54 ++++++++++++++++++++++ .../odiparback/controllers/UsuarioController.java | 54 ++++++++++++++++++++++ .../java/pe/edu/pucp/odiparback/dao/PTGDao.java | 11 +++++ .../pe/edu/pucp/odiparback/dao/TramoRutaDao.java | 11 +++++ .../pucp/odiparback/services/AveriaService.java | 32 +++++++++++++ .../pucp/odiparback/services/CamionService.java | 32 +++++++++++++ .../pucp/odiparback/services/ClienteService.java | 32 +++++++++++++ .../edu/pucp/odiparback/services/PTGService.java | 32 +++++++++++++ .../pucp/odiparback/services/PedidoService.java | 32 +++++++++++++ .../pucp/odiparback/services/RegionService.java | 32 +++++++++++++ .../edu/pucp/odiparback/services/RutaService.java | 32 +++++++++++++ .../odiparback/services/TipoAveriaService.java | 32 +++++++++++++ .../odiparback/services/TipoCamionService.java | 32 +++++++++++++ .../pucp/odiparback/services/TramoRutaService.java | 32 +++++++++++++ .../edu/pucp/odiparback/services/TramoService.java | 32 +++++++++++++ .../pucp/odiparback/services/UsuarioService.java | 32 +++++++++++++ 26 files changed, 1039 insertions(+) create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/ClienteController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PTGController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/RegionController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/RutaController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TipoAveriaController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TipoCamionController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TramoController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TramoRutaController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/UsuarioController.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/PTGDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TramoRutaDao.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/AveriaService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/CamionService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/ClienteService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/PTGService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/PedidoService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/RegionService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/RutaService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TipoAveriaService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TipoCamionService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TramoRutaService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TramoService.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/UsuarioService.java diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AveriaController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AveriaController.java index ae107cf..f5555d6 100644 --- a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AveriaController.java +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/AveriaController.java @@ -1,5 +1,55 @@ package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.Averia; +import pe.edu.pucp.odiparback.services.AveriaService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/averia") +@CrossOrigin public class AveriaController { + @Autowired + AveriaService averiaService; + + @GetMapping(value = "/") + List getAll(){ + return averiaService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "averia",key = "#id") + Averia get(@PathVariable int id)throws AuthenticationException{ + return averiaService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody Averia averia)throws SQLException{ + averiaService.register(averia); + } + + @PutMapping(value = "/") + Averia update(@RequestBody Averia averia)throws SQLException{ + return averiaService.update(averia); + } + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "averia", allEntries = true) + void delete(@PathVariable int id){ + averiaService.delete(id); + } + } diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/CamionController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/CamionController.java index e455438..59336b5 100644 --- a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/CamionController.java +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/CamionController.java @@ -1,5 +1,54 @@ package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.Camion; +import pe.edu.pucp.odiparback.services.CamionService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +@RestController +@RequestMapping("/camion") +@CrossOrigin public class CamionController { + @Autowired + CamionService camionService; + + @GetMapping(value = "/") + List getAll(){ + return camionService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "camion",key = "#id") + Camion get(@PathVariable int id)throws AuthenticationException{ + return camionService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody Camion camion)throws SQLException{ + camionService.register(camion); + } + + @PutMapping(value = "/") + Camion update(@RequestBody Camion camion)throws SQLException{ + return camionService.update(camion); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "camion", allEntries = true) + void delete(@PathVariable int id){ + camionService.delete(id); + } } diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/ClienteController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/ClienteController.java new file mode 100644 index 0000000..c3e0b6d --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/ClienteController.java @@ -0,0 +1,54 @@ +package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.Cliente; +import pe.edu.pucp.odiparback.services.ClienteService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/cliente") +@CrossOrigin +public class ClienteController { + @Autowired + ClienteService clienteService; + + @GetMapping(value = "/") + List getAll(){ + return clienteService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "cliente",key = "#id") + Cliente get(@PathVariable int id)throws AuthenticationException{ + return clienteService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody Cliente cliente)throws SQLException{ + clienteService.register(cliente); + } + + @PutMapping(value = "/") + Cliente update(@RequestBody Cliente cliente)throws SQLException{ + return clienteService.update(cliente); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "cliente", allEntries = true) + void delete(@PathVariable int id){ + clienteService.delete(id); + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PTGController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PTGController.java new file mode 100644 index 0000000..adba375 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PTGController.java @@ -0,0 +1,53 @@ +package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.PTG; +import pe.edu.pucp.odiparback.services.PTGService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/ptg") +@CrossOrigin +public class PTGController { + @Autowired + PTGService ptgService; + + @GetMapping(value = "/") + List getAll(){ + return ptgService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "ptg",key = "#id") + PTG get(@PathVariable int id)throws AuthenticationException{ + return ptgService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody PTG ptg)throws SQLException{ + ptgService.register(ptg); + } + + @PutMapping(value = "/") + PTG update(@RequestBody PTG ptg)throws SQLException{ + return ptgService.update(ptg); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "ptg", allEntries = true) + void delete(@PathVariable int id){ + ptgService.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PedidoController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PedidoController.java index e875f78..a1a6c2e 100644 --- a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PedidoController.java +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/PedidoController.java @@ -1,5 +1,54 @@ package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.Pedido; +import pe.edu.pucp.odiparback.services.PedidoService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +@RestController +@RequestMapping("/pedido") +@CrossOrigin public class PedidoController { + @Autowired + PedidoService pedidoService; + + @GetMapping(value = "/") + List getAll(){ + return pedidoService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "pedido",key = "#id") + Pedido get(@PathVariable int id)throws AuthenticationException{ + return pedidoService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody Pedido pedido)throws SQLException{ + pedidoService.register(pedido); + } + + @PutMapping(value = "/") + Pedido update(@RequestBody Pedido pedido)throws SQLException{ + return pedidoService.update(pedido); + } + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "pedido", allEntries = true) + void delete(@PathVariable int id){ + pedidoService.delete(id); + } + } diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/RegionController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/RegionController.java new file mode 100644 index 0000000..a55e68d --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/RegionController.java @@ -0,0 +1,54 @@ +package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.Region; +import pe.edu.pucp.odiparback.services.RegionService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/region") +@CrossOrigin +public class RegionController { + @Autowired + RegionService regionService; + + @GetMapping(value = "/") + List getAll(){ + return regionService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "region",key = "#id") + Region get(@PathVariable int id)throws AuthenticationException{ + return regionService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody Region region)throws SQLException{ + regionService.register(region); + } + + @PutMapping(value = "/") + Region update(@RequestBody Region region)throws SQLException{ + return regionService.update(region); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "region", allEntries = true) + void delete(@PathVariable int id){ + regionService.delete(id); + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/RutaController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/RutaController.java new file mode 100644 index 0000000..096013a --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/RutaController.java @@ -0,0 +1,54 @@ +package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.Ruta; +import pe.edu.pucp.odiparback.services.RutaService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/ruta") +@CrossOrigin +public class RutaController { + @Autowired + RutaService rutaService; + + @GetMapping(value = "/") + List getAll(){ + return rutaService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "ruta",key = "#id") + Ruta get(@PathVariable int id)throws AuthenticationException{ + return rutaService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody Ruta ruta)throws SQLException{ + rutaService.register(ruta); + } + + @PutMapping(value = "/") + Ruta update(@RequestBody Ruta ruta)throws SQLException{ + return rutaService.update(ruta); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "ruta", allEntries = true) + void delete(@PathVariable int id){ + rutaService.delete(id); + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TipoAveriaController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TipoAveriaController.java new file mode 100644 index 0000000..d66f813 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TipoAveriaController.java @@ -0,0 +1,54 @@ +package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.TipoAveria; +import pe.edu.pucp.odiparback.services.TipoAveriaService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/tipoAveria") +@CrossOrigin +public class TipoAveriaController { + @Autowired + TipoAveriaService tipoAveriaService; + + @GetMapping(value = "/") + List getAll(){ + return tipoAveriaService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "tipoAveria",key = "#id") + TipoAveria get(@PathVariable int id)throws AuthenticationException{ + return tipoAveriaService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody TipoAveria tipoAveria)throws SQLException{ + tipoAveriaService.register(tipoAveria); + } + + @PutMapping(value = "/") + TipoAveria update(@RequestBody TipoAveria tipoAveria)throws SQLException{ + return tipoAveriaService.update(tipoAveria); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "tipoAveria", allEntries = true) + void delete(@PathVariable int id){ + tipoAveriaService.delete(id); + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TipoCamionController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TipoCamionController.java new file mode 100644 index 0000000..72beae9 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TipoCamionController.java @@ -0,0 +1,54 @@ +package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.TipoCamion; +import pe.edu.pucp.odiparback.services.TipoCamionService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/tipoCamion") +@CrossOrigin +public class TipoCamionController { + @Autowired + TipoCamionService tipoCamionService; + + @GetMapping(value = "/") + List getAll(){ + return tipoCamionService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "tipoCamion",key = "#id") + TipoCamion get(@PathVariable int id)throws AuthenticationException{ + return tipoCamionService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody TipoCamion tipoCamion)throws SQLException{ + tipoCamionService.register(tipoCamion); + } + + @PutMapping(value = "/") + TipoCamion update(@RequestBody TipoCamion tipoCamion)throws SQLException{ + return tipoCamionService.update(tipoCamion); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "tipoCamion", allEntries = true) + void delete(@PathVariable int id){ + tipoCamionService.delete(id); + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TramoController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TramoController.java new file mode 100644 index 0000000..05606ad --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TramoController.java @@ -0,0 +1,54 @@ +package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.Tramo; +import pe.edu.pucp.odiparback.services.TramoService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/tramo") +@CrossOrigin +public class TramoController { + @Autowired + TramoService tramoService; + + @GetMapping(value = "/") + List getAll(){ + return tramoService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "tramo",key = "#id") + Tramo get(@PathVariable int id)throws AuthenticationException{ + return tramoService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody Tramo tramo)throws SQLException{ + tramoService.register(tramo); + } + + @PutMapping(value = "/") + Tramo update(@RequestBody Tramo tramo)throws SQLException{ + return tramoService.update(tramo); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "tramo", allEntries = true) + void delete(@PathVariable int id){ + tramoService.delete(id); + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TramoRutaController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TramoRutaController.java new file mode 100644 index 0000000..9c37098 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/TramoRutaController.java @@ -0,0 +1,54 @@ +package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.TramoRuta; +import pe.edu.pucp.odiparback.services.TramoRutaService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/tramoRuta") +@CrossOrigin +public class TramoRutaController { + @Autowired + TramoRutaService tramoRutaService; + + @GetMapping(value = "/") + List getAll(){ + return tramoRutaService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "tramo",key = "#id") + TramoRuta get(@PathVariable int id)throws AuthenticationException{ + return tramoRutaService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody TramoRuta tramoRuta)throws SQLException{ + tramoRutaService.register(tramoRuta); + } + + @PutMapping(value = "/") + TramoRuta update(@RequestBody TramoRuta tramoRuta)throws SQLException{ + return tramoRutaService.update(tramoRuta); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "tramoRuta", allEntries = true) + void delete(@PathVariable int id){ + tramoRutaService.delete(id); + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/UsuarioController.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/UsuarioController.java new file mode 100644 index 0000000..aaa9038 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/controllers/UsuarioController.java @@ -0,0 +1,54 @@ +package pe.edu.pucp.odiparback.controllers; +import pe.edu.pucp.odiparback.models.Usuario; +import pe.edu.pucp.odiparback.services.UsuarioService; +import java.sql.SQLException; +import java.util.List; +import org.apache.tomcat.websocket.AuthenticationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/usuario") +@CrossOrigin +public class UsuarioController { + @Autowired + UsuarioService usuarioService; + + @GetMapping(value = "/") + List getAll(){ + return usuarioService.getAll(); + } + + @GetMapping(value = "/{id}") + @Cacheable(value = "usuario",key = "#id") + Usuario get(@PathVariable int id)throws AuthenticationException{ + return usuarioService.get(id); + } + + @PostMapping(value = "/") + void register(@RequestBody Usuario usuario)throws SQLException{ + usuarioService.register(usuario); + } + + @PutMapping(value = "/") + Usuario update(@RequestBody Usuario usuario)throws SQLException{ + return usuarioService.update(usuario); + } + + @DeleteMapping(value = "/{id}") + @CacheEvict(value = "usuario", allEntries = true) + void delete(@PathVariable int id){ + usuarioService.delete(id); + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/PTGDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/PTGDao.java new file mode 100644 index 0000000..ca6f5b0 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/PTGDao.java @@ -0,0 +1,11 @@ +package pe.edu.pucp.odiparback.dao; +import java.util.List; +import pe.edu.pucp.odiparback.models.PTG; + +public interface PTGDao { + public List getAll(); + public PTG get(int id); + public void register(PTG planTransporte); + public PTG update(PTG planTransporte); + public void delete(int id); +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TramoRutaDao.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TramoRutaDao.java new file mode 100644 index 0000000..5186bc5 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/TramoRutaDao.java @@ -0,0 +1,11 @@ +package pe.edu.pucp.odiparback.dao; +import java.util.List; +import pe.edu.pucp.odiparback.models.TramoRuta; + +public interface TramoRutaDao { + public List getAll(); + public TramoRuta get(int id); + public void register(TramoRuta tramoRuta); + public TramoRuta update(TramoRuta tramoRuta); + public void delete(int id); +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/AveriaService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/AveriaService.java new file mode 100644 index 0000000..656452e --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/AveriaService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.AveriaDao; +import pe.edu.pucp.odiparback.models.Averia; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class AveriaService { + @Autowired + AveriaDao daoAveria; + + public List getAll(){ + return daoAveria.getAll(); + } + + public Averia get(int id){ + return daoAveria.get(id); + } + + public void register(Averia averia){ + daoAveria.register(averia); + } + + public Averia update(Averia averia){ + return daoAveria.update(averia); + } + + public void delete(int id){ + daoAveria.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/CamionService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/CamionService.java new file mode 100644 index 0000000..eabf02f --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/CamionService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.CamionDao; +import pe.edu.pucp.odiparback.models.Camion; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class CamionService { + @Autowired + CamionDao daoCamion; + + public List getAll(){ + return daoCamion.getAll(); + } + + public Camion get(int id){ + return daoCamion.get(id); + } + + public void register(Camion camion){ + daoCamion.register(camion); + } + + public Camion update(Camion camion){ + return daoCamion.update(camion); + } + + public void delete(int id){ + daoCamion.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/ClienteService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/ClienteService.java new file mode 100644 index 0000000..2e8eb1b --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/ClienteService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.ClienteDao; +import pe.edu.pucp.odiparback.models.Cliente; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class ClienteService { + @Autowired + ClienteDao daoCliente; + + public List getAll(){ + return daoCliente.getAll(); + } + + public Cliente get(int id){ + return daoCliente.get(id); + } + + public void register(Cliente cliente){ + daoCliente.register(cliente); + } + + public Cliente update(Cliente cliente){ + return daoCliente.update(cliente); + } + + public void delete(int id){ + daoCliente.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/PTGService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/PTGService.java new file mode 100644 index 0000000..1c7bfd0 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/PTGService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.PTGDao; +import pe.edu.pucp.odiparback.models.PTG; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class PTGService { + @Autowired + PTGDao daoPTG; + + public List getAll(){ + return daoPTG.getAll(); + } + + public PTG get(int id){ + return daoPTG.get(id); + } + + public void register(PTG planTransporte){ + daoPTG.register(planTransporte); + } + + public PTG update(PTG planTransporte){ + return daoPTG.update(planTransporte); + } + + public void delete(int id){ + daoPTG.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/PedidoService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/PedidoService.java new file mode 100644 index 0000000..e0ca661 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/PedidoService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.PedidoDao; +import pe.edu.pucp.odiparback.models.Pedido; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class PedidoService { + @Autowired + PedidoDao daoPedido; + + public List getAll(){ + return daoPedido.getAll(); + } + + public Pedido get(int id){ + return daoPedido.get(id); + } + + public void register(Pedido pedido){ + daoPedido.register(pedido); + } + + public Pedido update(Pedido pedido){ + return daoPedido.update(pedido); + } + + public void delete(int id){ + daoPedido.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/RegionService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/RegionService.java new file mode 100644 index 0000000..3f0f226 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/RegionService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.RegionDao; +import pe.edu.pucp.odiparback.models.Region; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class RegionService { + @Autowired + RegionDao daoRegion; + + public List getAll(){ + return daoRegion.getAll(); + } + + public Region get(int id){ + return daoRegion.get(id); + } + + public void register(Region region){ + daoRegion.register(region); + } + + public Region update(Region region){ + return daoRegion.update(region); + } + + public void delete(int id){ + daoRegion.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/RutaService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/RutaService.java new file mode 100644 index 0000000..0055ae8 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/RutaService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.RutaDao; +import pe.edu.pucp.odiparback.models.Ruta; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class RutaService { + @Autowired + RutaDao daoRuta; + + public List getAll(){ + return daoRuta.getAll(); + } + + public Ruta get(int id){ + return daoRuta.get(id); + } + + public void register(Ruta ruta){ + daoRuta.register(ruta); + } + + public Ruta update(Ruta ruta){ + return daoRuta.update(ruta); + } + + public void delete(int id){ + daoRuta.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TipoAveriaService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TipoAveriaService.java new file mode 100644 index 0000000..6cb7719 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TipoAveriaService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.TipoAveriaDao; +import pe.edu.pucp.odiparback.models.TipoAveria; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class TipoAveriaService { + @Autowired + TipoAveriaDao daoTipoAveria; + + public List getAll(){ + return daoTipoAveria.getAll(); + } + + public TipoAveria get(int id){ + return daoTipoAveria.get(id); + } + + public void register(TipoAveria tipoAveria){ + daoTipoAveria.register(tipoAveria); + } + + public TipoAveria update(TipoAveria tipoAveria){ + return daoTipoAveria.update(tipoAveria); + } + + public void delete(int id){ + daoTipoAveria.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TipoCamionService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TipoCamionService.java new file mode 100644 index 0000000..fd7b811 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TipoCamionService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.TipoCamionDao; +import pe.edu.pucp.odiparback.models.TipoCamion; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class TipoCamionService { + @Autowired + TipoCamionDao daoTipoCamion; + + public List getAll(){ + return daoTipoCamion.getAll(); + } + + public TipoCamion get(int id){ + return daoTipoCamion.get(id); + } + + public void register(TipoCamion tipoCamion){ + daoTipoCamion.register(tipoCamion); + } + + public TipoCamion update(TipoCamion tipoCamion){ + return daoTipoCamion.update(tipoCamion); + } + + public void delete(int id){ + daoTipoCamion.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TramoRutaService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TramoRutaService.java new file mode 100644 index 0000000..2348992 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TramoRutaService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.TramoRutaDao; +import pe.edu.pucp.odiparback.models.TramoRuta; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class TramoRutaService { + @Autowired + TramoRutaDao daoTramoRuta; + + public List getAll(){ + return daoTramoRuta.getAll(); + } + + public TramoRuta get(int id){ + return daoTramoRuta.get(id); + } + + public void register(TramoRuta tramoRuta){ + daoTramoRuta.register(tramoRuta); + } + + public TramoRuta update(TramoRuta tramoRuta){ + return daoTramoRuta.update(tramoRuta); + } + + public void delete(int id){ + daoTramoRuta.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TramoService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TramoService.java new file mode 100644 index 0000000..13fc5b2 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/TramoService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.TramoDao; +import pe.edu.pucp.odiparback.models.Tramo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class TramoService { + @Autowired + TramoDao daoTramo; + + public List getAll(){ + return daoTramo.getAll(); + } + + public Tramo get(int id){ + return daoTramo.get(id); + } + + public void register(Tramo tramo){ + daoTramo.register(tramo); + } + + public Tramo update(Tramo tramo){ + return daoTramo.update(tramo); + } + + public void delete(int id){ + daoTramo.delete(id); + } +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/UsuarioService.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/UsuarioService.java new file mode 100644 index 0000000..c7215ad --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/services/UsuarioService.java @@ -0,0 +1,32 @@ +package pe.edu.pucp.odiparback.services; +import java.util.List; +import pe.edu.pucp.odiparback.dao.UsuarioDao; +import pe.edu.pucp.odiparback.models.Usuario; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class UsuarioService { + @Autowired + UsuarioDao daoUsuario; + + public List getAll(){ + return daoUsuario.getAll(); + } + + public Usuario get(int id){ + return daoUsuario.get(id); + } + + public void register(Usuario usuario){ + daoUsuario.register(usuario); + } + + public Usuario update(Usuario usuario){ + return daoUsuario.update(usuario); + } + + public void delete(int id){ + daoUsuario.delete(id); + } +} -- cgit v1.2.3 From a9b520b0d51db85cec0c11c11d22ee70414e5034 Mon Sep 17 00:00:00 2001 From: Dayana31 <70593166+Dayana31@users.noreply.github.com> Date: Sat, 28 May 2022 18:16:11 -0500 Subject: Imp de Dao --- .../edu/pucp/odiparback/dao/imp/AlmacenDaoImp.java | 87 ++++++++++++++++++++++ .../edu/pucp/odiparback/dao/imp/AveriaDaoImp.java | 87 ++++++++++++++++++++++ .../edu/pucp/odiparback/dao/imp/CamionDaoImp.java | 87 ++++++++++++++++++++++ .../edu/pucp/odiparback/dao/imp/ClienteDaoImp.java | 86 +++++++++++++++++++++ .../pe/edu/pucp/odiparback/dao/imp/PTGDaoImp.java | 86 +++++++++++++++++++++ .../edu/pucp/odiparback/dao/imp/PedidoDaoImp.java | 85 +++++++++++++++++++++ .../edu/pucp/odiparback/dao/imp/RegionDaoImp.java | 85 +++++++++++++++++++++ .../pe/edu/pucp/odiparback/dao/imp/RutaDaoImp.java | 85 +++++++++++++++++++++ .../pucp/odiparback/dao/imp/TipoAveriaDaoImp.java | 85 +++++++++++++++++++++ .../pucp/odiparback/dao/imp/TipoCamionDaoImp.java | 85 +++++++++++++++++++++ .../edu/pucp/odiparback/dao/imp/TramoDaoImp.java | 85 +++++++++++++++++++++ .../pucp/odiparback/dao/imp/TramoRutaDaoImp.java | 86 +++++++++++++++++++++ .../edu/pucp/odiparback/dao/imp/UsuarioDaoImp.java | 85 +++++++++++++++++++++ 13 files changed, 1114 insertions(+) create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/AlmacenDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/AveriaDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/CamionDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/ClienteDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/PTGDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/PedidoDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/RegionDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/RutaDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TipoAveriaDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TipoCamionDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TramoDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TramoRutaDaoImp.java create mode 100644 back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/UsuarioDaoImp.java diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/AlmacenDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/AlmacenDaoImp.java new file mode 100644 index 0000000..575d38a --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/AlmacenDaoImp.java @@ -0,0 +1,87 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.Almacen; +import pe.edu.pucp.odiparback.dao.AlmacenDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class AlmacenDaoImp implements AlmacenDao { + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_Almacen"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public Almacen get(int id) { + Almacen resultado = null; + try { + resultado = entityManager.find(Almacen.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(Almacen almacen) { + try { + entityManager.merge(almacen); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + } + + @Transactional + @Override + public Almacen update(Almacen almacen) { + try { + entityManager.merge(almacen); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return almacen; + } + + @Transactional + @Override + public void delete(int id) { + Almacen resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/AveriaDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/AveriaDaoImp.java new file mode 100644 index 0000000..1bf1882 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/AveriaDaoImp.java @@ -0,0 +1,87 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.Averia; +import pe.edu.pucp.odiparback.dao.AveriaDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class AveriaDaoImp implements AveriaDao{ + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_Averia"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public Averia get(int id) { + Averia resultado = null; + try { + resultado = entityManager.find(Averia.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(Averia averia) { + try { + entityManager.merge(averia); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + } + + @Transactional + @Override + public Averia update(Averia averia) { + try { + entityManager.merge(averia); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return averia; + } + + @Transactional + @Override + public void delete(int id) { + Averia resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/CamionDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/CamionDaoImp.java new file mode 100644 index 0000000..4c97808 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/CamionDaoImp.java @@ -0,0 +1,87 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.Camion; +import pe.edu.pucp.odiparback.dao.CamionDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class CamionDaoImp implements CamionDao { + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_Camion"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public Camion get(int id) { + Camion resultado = null; + try { + resultado = entityManager.find(Camion.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(Camion camion) { + try { + entityManager.merge(camion); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + } + + @Transactional + @Override + public Camion update(Camion camion) { + try { + entityManager.merge(camion); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return camion; + } + + @Transactional + @Override + public void delete(int id) { + Camion resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/ClienteDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/ClienteDaoImp.java new file mode 100644 index 0000000..2a9ae44 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/ClienteDaoImp.java @@ -0,0 +1,86 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.Cliente; +import pe.edu.pucp.odiparback.dao.ClienteDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class ClienteDaoImp implements ClienteDao { + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_Cliente"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public Cliente get(int id) { + Cliente resultado = null; + try { + resultado = entityManager.find(Cliente.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(Cliente cliente) { + try { + entityManager.merge(cliente); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + } + + @Transactional + @Override + public Cliente update(Cliente cliente) { + try { + entityManager.merge(cliente); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return cliente; + } + + @Transactional + @Override + public void delete(int id) { + Cliente resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/PTGDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/PTGDaoImp.java new file mode 100644 index 0000000..ac076cf --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/PTGDaoImp.java @@ -0,0 +1,86 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.PTG; +import pe.edu.pucp.odiparback.dao.PTGDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class PTGDaoImp implements PTGDao{ + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_PTG"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public PTG get(int id) { + PTG resultado = null; + try { + resultado = entityManager.find(PTG.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(PTG planTransporte) { + try { + entityManager.merge(planTransporte); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + } + + @Transactional + @Override + public PTG update(PTG planTransporte) { + try { + entityManager.merge(planTransporte); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return planTransporte; + } + + @Transactional + @Override + public void delete(int id) { + PTG resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/PedidoDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/PedidoDaoImp.java new file mode 100644 index 0000000..3ebc387 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/PedidoDaoImp.java @@ -0,0 +1,85 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.Pedido; +import pe.edu.pucp.odiparback.dao.PedidoDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class PedidoDaoImp implements PedidoDao { + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_Pedido"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public Pedido get(int id) { + Pedido resultado = null; + try { + resultado = entityManager.find(Pedido.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(Pedido pedido) { + try { + entityManager.merge(pedido); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + + @Transactional + @Override + public Pedido update(Pedido pedido) { + try { + entityManager.merge(pedido); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return pedido; + } + + @Transactional + @Override + public void delete(int id) { + Pedido resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/RegionDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/RegionDaoImp.java new file mode 100644 index 0000000..15788d4 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/RegionDaoImp.java @@ -0,0 +1,85 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.Region; +import pe.edu.pucp.odiparback.dao.RegionDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class RegionDaoImp implements RegionDao { + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_Region"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public Region get(int id) { + Region resultado = null; + try { + resultado = entityManager.find(Region.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(Region region) { + try { + entityManager.merge(region); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + + @Transactional + @Override + public Region update(Region region) { + try { + entityManager.merge(region); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return region; + } + + @Transactional + @Override + public void delete(int id) { + Region resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/RutaDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/RutaDaoImp.java new file mode 100644 index 0000000..0e491b7 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/RutaDaoImp.java @@ -0,0 +1,85 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.Ruta; +import pe.edu.pucp.odiparback.dao.RutaDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class RutaDaoImp implements RutaDao { + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_Ruta"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public Ruta get(int id) { + Ruta resultado = null; + try { + resultado = entityManager.find(Ruta.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(Ruta ruta) { + try { + entityManager.merge(ruta); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + + @Transactional + @Override + public Ruta update(Ruta ruta) { + try { + entityManager.merge(ruta); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return ruta; + } + + @Transactional + @Override + public void delete(int id) { + Ruta resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TipoAveriaDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TipoAveriaDaoImp.java new file mode 100644 index 0000000..f2980cf --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TipoAveriaDaoImp.java @@ -0,0 +1,85 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.TipoAveria; +import pe.edu.pucp.odiparback.dao.TipoAveriaDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class TipoAveriaDaoImp implements TipoAveriaDao{ + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_TipoAveria"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public TipoAveria get(int id) { + TipoAveria resultado = null; + try { + resultado = entityManager.find(TipoAveria.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(TipoAveria tipoAveria) { + try { + entityManager.merge(tipoAveria); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + + @Transactional + @Override + public TipoAveria update(TipoAveria tipoAveria) { + try { + entityManager.merge(tipoAveria); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return tipoAveria; + } + + @Transactional + @Override + public void delete(int id) { + TipoAveria resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TipoCamionDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TipoCamionDaoImp.java new file mode 100644 index 0000000..0889570 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TipoCamionDaoImp.java @@ -0,0 +1,85 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.TipoCamion; +import pe.edu.pucp.odiparback.dao.TipoCamionDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class TipoCamionDaoImp implements TipoCamionDao{ + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_TipoCamion"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public TipoCamion get(int id) { + TipoCamion resultado = null; + try { + resultado = entityManager.find(TipoCamion.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(TipoCamion tipoCamion) { + try { + entityManager.merge(tipoCamion); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + + @Transactional + @Override + public TipoCamion update(TipoCamion tipoCamion) { + try { + entityManager.merge(tipoCamion); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return tipoCamion; + } + + @Transactional + @Override + public void delete(int id) { + TipoCamion resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TramoDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TramoDaoImp.java new file mode 100644 index 0000000..717dcf2 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TramoDaoImp.java @@ -0,0 +1,85 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.Tramo; +import pe.edu.pucp.odiparback.dao.TramoDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class TramoDaoImp implements TramoDao{ + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_Tramo"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public Tramo get(int id) { + Tramo resultado = null; + try { + resultado = entityManager.find(Tramo.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(Tramo tramo) { + try { + entityManager.merge(tramo); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + + @Transactional + @Override + public Tramo update(Tramo tramo) { + try { + entityManager.merge(tramo); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return tramo; + } + + @Transactional + @Override + public void delete(int id) { + Tramo resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TramoRutaDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TramoRutaDaoImp.java new file mode 100644 index 0000000..1808c61 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/TramoRutaDaoImp.java @@ -0,0 +1,86 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.TramoRuta; +import pe.edu.pucp.odiparback.dao.TramoRutaDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class TramoRutaDaoImp implements TramoRutaDao { + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_TramoRuta"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public TramoRuta get(int id) { + TramoRuta resultado = null; + try { + resultado = entityManager.find(TramoRuta.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(TramoRuta tramoRuta) { + try { + entityManager.merge(tramoRuta); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + } + + @Transactional + @Override + public TramoRuta update(TramoRuta tramoRuta) { + try { + entityManager.merge(tramoRuta); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return tramoRuta; + } + + @Transactional + @Override + public void delete(int id) { + TramoRuta resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + +} diff --git a/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/UsuarioDaoImp.java b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/UsuarioDaoImp.java new file mode 100644 index 0000000..c0e6ef1 --- /dev/null +++ b/back/odiparback/src/main/java/pe/edu/pucp/odiparback/dao/imp/UsuarioDaoImp.java @@ -0,0 +1,85 @@ +package pe.edu.pucp.odiparback.dao.imp; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import pe.edu.pucp.odiparback.models.Usuario; +import pe.edu.pucp.odiparback.dao.UsuarioDao; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Repository +@SuppressWarnings("unchecked") +public class UsuarioDaoImp implements UsuarioDao{ + @PersistenceContext + EntityManager entityManager; + + @Transactional + @Override + public List getAll() { + List resultado = null; + try{ + String query = "SELECT * FROM ODP_Usuario"; + resultado = entityManager.createQuery(query).getResultList(); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public Usuario get(int id) { + Usuario resultado = null; + try { + resultado = entityManager.find(Usuario.class, id); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + + return resultado; + } + + @Transactional + @Override + public void register(Usuario usuario) { + try { + entityManager.merge(usuario); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + + @Transactional + @Override + public Usuario update(Usuario usuario) { + try { + entityManager.merge(usuario); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + return usuario; + } + + @Transactional + @Override + public void delete(int id) { + Usuario resultado = get(id); + try { + entityManager.remove(resultado); + } + catch(Exception ex){ + System.out.print(ex.getMessage()); + } + } + +} -- cgit v1.2.3