Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,67 @@ En este ejercicio se va a construír un modelo de clases para la capa lógica de
* Agregar las dependencias de Spring.
* Agregar la configuración de Spring.
* Configurar la aplicación -mediante anotaciones- para que el esquema de persistencia sea inyectado al momento de ser creado el bean 'BlueprintServices'.
Debemos revisar dependecias:

![](./img/media/Image1.jpeg)

![](./img/media/Image2.jpeg)

Agregamos el @Service a la clase BlueprintsPersistence
![](./img/media/Image3.jpeg)

Creamos el archivo xml applicationContext.xml
![](./img/media/Image5.jpeg)

Añadimos la clase Main y lo conectamos con el archivo 'new ClassPathXmlApplicationContext("applicationContext.xml");'
![](./img/media/Image4.jpeg)

2. Complete los operaciones getBluePrint() y getBlueprintsByAuthor(). Implemente todo lo requerido de las capas inferiores (por ahora, el esquema de persistencia disponible 'InMemoryBlueprintPersistence') agregando las pruebas correspondientes en 'InMemoryPersistenceTest'.

El método getBluePrint() será @Override y actualizado con las condiciones necesarias
![](./img/media/Image6.jpeg)

El método addNewBlueprint(Blueprint bp), traera el dato dpp.saveBlueprint(bp);

![](./img/media/Image7.jpeg)

LLamaremos al método anterior desde la clase de BlueprintsPersistence
![](./img/media/Image8.jpeg)

Pruebas correspondientes a lo implementado anteriormente:
![](./img/media/Image9.jpeg)
![](./img/media/Image10.jpeg)

3. Haga un programa en el que cree (mediante Spring) una instancia de BlueprintServices, y rectifique la funcionalidad del mismo: registrar planos, consultar planos, registrar planos específicos, etc.

Se deben realizar los siguientes cambios para las clases correspondientes para crear la instancia de BlueprintServices:
a.
![](./img/media/Image11.jpeg)
b.
![](./img/media/Image12.jpeg)
c.
![](./img/media/Image13.jpeg)
d.
![](./img/media/Image14.jpeg)

4. Se quiere que las operaciones de consulta de planos realicen un proceso de filtrado, antes de retornar los planos consultados. Dichos filtros lo que buscan es reducir el tamaño de los planos, removiendo datos redundantes o simplemente submuestrando, antes de retornarlos. Ajuste la aplicación (agregando las abstracciones e implementaciones que considere) para que a la clase BlueprintServices se le inyecte uno de dos posibles 'filtros' (o eventuales futuros filtros). No se contempla el uso de más de uno a la vez:
* (A) Filtrado de redundancias: suprime del plano los puntos consecutivos que sean repetidos.
* (B) Filtrado de submuestreo: suprime 1 de cada 2 puntos del plano, de manera intercalada.

Se creara una carpeta de filters, con tres clases como se muestra a continuación:
![](./img/media/Image15.jpeg)

Clase BlueprintsFilter:
![](./img/media/Image19.jpeg)

Clase SubsamplingFilter:
![](./img/media/Image16.jpeg)

Clase RedundancyFilter:
![](./img/media/Image17.jpeg)

Y se realiza la inserción de dependencias por:
![](./img/media/Image18.jpeg)

5. Agrege las pruebas correspondientes a cada uno de estos filtros, y pruebe su funcionamiento en el programa de prueba, comprobando que sólo cambiando la posición de las anotaciones -sin cambiar nada más-, el programa retorne los planos filtrados de la manera (A) o de la manera (B).
![](./img/media/Image20.jpeg)
Binary file added img/media/Image1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image10.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image11.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image12.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image13.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image14.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image15.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image16.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image17.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image18.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image19.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image20.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image5.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image6.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image7.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image8.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/media/Image9.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 38 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,60 @@
<packaging>jar</packaging>

<name>Blueprints_Middleware</name>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring-boot.version>3.2.10</spring-boot.version> <!-- Asegúrate de usar una versión compatible de Spring Boot -->
</properties>

<dependencies>
<!-- Spring Boot Starter Data JPA (incluye Hibernate y JPA) -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.4.RELEASE</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring-boot.version}</version>
</dependency>

<!-- Spring Boot Starter Web (para aplicaciones web, si es necesario) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>

<!-- H2 Database (para desarrollo y pruebas) -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<!-- JUnit para pruebas -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.4.RELEASE</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Plugin para compilar código y empaquetar la aplicación -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package edu.eci.arsw.blueprints.filters;

import edu.eci.arsw.blueprints.model.Blueprint;
public interface BlueprintsFilter {
void filter(Blueprint bp);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package edu.eci.arsw.blueprints.filters;

import edu.eci.arsw.blueprints.model.Blueprint;
import edu.eci.arsw.blueprints.model.Point;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class RedundancyFilter implements BlueprintsFilter {

@Override
public void filter(Blueprint bp) {
List<Point> uniquePoints = new ArrayList<>();

for (Point i : bp.getPoints()) {
boolean found = false;
for (Point j : uniquePoints) {
if (i.equals(j)) {
found = true;
break;
}
}
if (!found) {
uniquePoints.add(i);
}
}

Point[] uniquePointsArray = uniquePoints.toArray(new Point[0]);

new Blueprint(bp.getAuthor(), bp.getName(), uniquePointsArray);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edu.eci.arsw.blueprints.filters;

import edu.eci.arsw.blueprints.model.Blueprint;
import edu.eci.arsw.blueprints.model.Point;

import java.util.ArrayList;
import java.util.List;


public class SubsamplingFilter implements BlueprintsFilter {
@Override
public void filter(Blueprint bp) {
List<Point> oldPoints = bp.getPoints();
List<Point> sampledPoints = new ArrayList<>();

for (int i = 0; i < oldPoints.size(); i++) {
if (i % 2 == 0) {
sampledPoints.add(oldPoints.get(i));
}
}

// Convert ArrayList to Point array
Point[] sampledPointsArray = sampledPoints.toArray(new Point[0]);

new Blueprint(bp.getAuthor(), bp.getName(), sampledPointsArray);
}
}
90 changes: 38 additions & 52 deletions src/main/java/edu/eci/arsw/blueprints/model/Blueprint.java
Original file line number Diff line number Diff line change
@@ -1,91 +1,77 @@

package edu.eci.arsw.blueprints.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;


public class Blueprint {

private String author=null;

private List<Point> points=null;

private String name=null;

public Blueprint(String author,String name,Point[] pnts){
this.author=author;
this.name=name;
points=Arrays.asList(pnts);
}

public Blueprint(String author, String name){
this.name=name;
points=new ArrayList<>();
private String author;
private List<Point> points;
private String name;

// Constructor que acepta un array de puntos
public Blueprint(String author, String name, Point[] pnts) {
this.author = author;
this.name = name;
this.points = new ArrayList<>(Arrays.asList(pnts)); // Convierte el array a una lista
}

// Constructor por defecto
public Blueprint() {
}

this.points = new ArrayList<>();
}

// Constructor para inicializar con autor y nombre
public Blueprint(String author, String name) {
this.author = author;
this.name = name;
this.points = new ArrayList<>();
}

// Métodos getter
public String getName() {
return name;
}

public String getAuthor() {
return author;
}

public List<Point> getPoints() {
return points;
}

public void addPoint(Point p){

// Método para agregar un punto
public void addPoint(Point p) {
this.points.add(p);
}

// Método toString
@Override
public String toString() {
return "Blueprint{" + "author=" + author + ", name=" + name + '}';
}

@Override
public int hashCode() {
int hash = 7;
return hash;
return "Blueprint{" + "author=" + author + ", name=" + name + ", points=" + points + '}';
}

// Método equals
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final Blueprint other = (Blueprint) obj;
if (!Objects.equals(this.author, other.author)) {
return false;
}
if (!Objects.equals(this.name, other.name)) {
return false;
}
if (this.points.size()!=other.points.size()){
return false;
}
for (int i=0;i<this.points.size();i++){
if (this.points.get(i)!=other.points.get(i)){
return false;
}
}

return true;
return Objects.equals(this.author, other.author) &&
Objects.equals(this.name, other.name) &&
Objects.equals(this.points, other.points);
}

// Método hashCode
@Override
public int hashCode() {
return Objects.hash(author, name, points);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
package edu.eci.arsw.blueprints.persistence;

import edu.eci.arsw.blueprints.model.Blueprint;
import edu.eci.arsw.blueprints.persistence.impl.Tuple;

import java.util.List;
import java.util.Set;

/**
*
Expand All @@ -29,5 +33,12 @@ public interface BlueprintsPersistence {
* @throws BlueprintNotFoundException if there is no such blueprint
*/
public Blueprint getBlueprint(String author,String bprintname) throws BlueprintNotFoundException;


public Set<Blueprint> getAllBlueprints();

public List<Tuple> getAllKeys();

public Blueprint getBlueprintByAuthor(String author) throws BlueprintNotFoundException;

Set<Blueprint> getBlueprintsByAuthor(String author) throws BlueprintNotFoundException;
}
Loading