Browse Source

actualizacion

master
vigliom 1 year ago
parent
commit
0a43697ef9
16 changed files with 281 additions and 134 deletions
  1. +60
    -6
      .idea/workspace.xml
  2. +50
    -26
      README.md
  3. +5
    -0
      pom.xml
  4. +0
    -12
      src/main/java/com/jorpelu/ServicioDeProductos/ISercicioProductoDAO.java
  5. +5
    -5
      src/main/java/com/jorpelu/ServicioDeProductos/Main.java
  6. +0
    -22
      src/main/java/com/jorpelu/ServicioDeProductos/ProductoService.java
  7. +0
    -47
      src/main/java/com/jorpelu/ServicioDeProductos/ProductosDaoImplMemory.java
  8. +27
    -0
      src/main/java/com/jorpelu/ServicioDeProductos/config/AppConfig.java
  9. +30
    -0
      src/main/java/com/jorpelu/ServicioDeProductos/dao/Parser.java
  10. +17
    -0
      src/main/java/com/jorpelu/ServicioDeProductos/dao/ProductoService.java
  11. +15
    -0
      src/main/java/com/jorpelu/ServicioDeProductos/dao/ProductosDao.java
  12. +57
    -0
      src/main/java/com/jorpelu/ServicioDeProductos/dao/ProductosDaoImplMemory.java
  13. +1
    -1
      src/main/java/com/jorpelu/ServicioDeProductos/model/Producto.java
  14. +3
    -15
      src/main/resources/beans.xml
  15. +2
    -0
      src/main/resources/productos.properties
  16. +9
    -0
      src/main/resources/productos_data.csv

+ 60
- 6
.idea/workspace.xml View File

@ -4,8 +4,22 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="d0e2ddd8-efdc-4dce-b0fd-07c7411e37c2" name="Changes" comment="Implementacion de @Autowired en la clase">
<list default="true" id="d0e2ddd8-efdc-4dce-b0fd-07c7411e37c2" name="Changes" comment="llamo a los productos con el commpontent-scan y actualizo README.md">
<change afterPath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/config/AppConfig.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/dao/Parser.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/dao/ProductoService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/dao/ProductosDao.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/dao/ProductosDaoImplMemory.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/productos.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/productos_data.csv" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/ISercicioProductoDAO.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/Producto.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/model/Producto.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/ProductoService.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/ProductosDaoImplMemory.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/beans.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/beans.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -18,8 +32,8 @@
<list>
<option value="spring-beans.schema" />
<option value="Interface" />
<option value="Class" />
<option value="AnnotationType" />
<option value="Class" />
</list>
</option>
</component>
@ -60,6 +74,12 @@
<key name="CreateClassDialog.RecentsKey">
<recent name="com.jorpelu.ServicioDeProductos" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\ProyectosInteliJ\ServicioDeProductos\src\main\resources" />
</key>
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="dao" />
</key>
</component>
<component name="RunManager">
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
@ -67,7 +87,7 @@
<module name="ServicioDeProductos" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.jorpelu.ServicioDeProductos.*" />
<option name="PATTERN" value="config.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -96,7 +116,7 @@
<workItem from="1669327599329" duration="2673000" />
<workItem from="1669370939836" duration="5274000" />
<workItem from="1669388229176" duration="732000" />
<workItem from="1669403092395" duration="10568000" />
<workItem from="1669403092395" duration="19751000" />
</task>
<task id="LOCAL-00001" summary="innnit">
<created>1669371969480</created>
@ -147,7 +167,14 @@
<option name="project" value="LOCAL" />
<updated>1669476308821</updated>
</task>
<option name="localTasksCounter" value="8" />
<task id="LOCAL-00008" summary="llamo a los productos con el commpontent-scan y actualizo README.md">
<created>1669481268777</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1669481268777</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -172,6 +199,33 @@
<MESSAGE value="Intento añadir anotaciones, pero no me deja entrar al namespace" />
<MESSAGE value="Sigo sin conseguir anñadir Required, El resto me va bien" />
<MESSAGE value="Implementacion de @Autowired en la clase" />
<option name="LAST_COMMIT_MESSAGE" value="Implementacion de @Autowired en la clase" />
<MESSAGE value="llamo a los productos con el commpontent-scan y actualizo README.md" />
<option name="LAST_COMMIT_MESSAGE" value="llamo a los productos con el commpontent-scan y actualizo README.md" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/dao/Parser.java</url>
<line>16</line>
<option name="timeStamp" value="3" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/dao/Parser.java</url>
<line>19</line>
<option name="timeStamp" value="4" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/jorpelu/ServicioDeProductos/dao/Parser.java</url>
<line>20</line>
<option name="timeStamp" value="5" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<pin-to-top-manager>
<pinned-members>
<PinnedItemInfo parentTag="com.jorpelu.ServicioDeProductos.ProductosDaoImplMemory" memberName="productos" />
</pinned-members>
</pin-to-top-manager>
</component>
</project>

+ 50
- 26
README.md View File

@ -1,44 +1,68 @@
# Servicio de productos
### Introduccion
Creo un SpringCore Con el servicio de consultar productos con sus precios y todas las caracteristicas.
Creo un SpringCore Con el servicio de consultar productos
con sus precios y todas las caracteristicas.
### Documentacion
### Files
- *Parser* Clase que se encarga de leeer el archivo CSV donde estan guardados los datos
- *productos_data.csv* Archivo de datos
- *Main.java* Clase Principal del programa
- *IServicioProducto.java* Interfaz de producto
- *ProductoDao.java* Interfaz de productos
- *ProductosDaoImplMemory.java* implementa la memoria de la iinterfaz
- *Producto.java* Modelo del producto
- *ServicioProducto.java* Clase para el control de los servicios del producto (ampliable en un futuro)
- *beans.xml* Arvhivo que contiene los bean para la inyeccion de dependencias
#### Dependencias importadas:
- *ProductoService.java* Clase para el control de los servicios del producto
- *beans.xml* Arvhivo que contiene los bean para la inyeccion de dependencias _(Ya no se Utiliza)_
- *AppConfig.java* Para leer las anotaciones y configurar la app
### Dependencias importadas:
~~~
org.springframework id:spring-context v: 6.0.0
javax.annotation id:javax.annotation-api v:1.3.2
org.springframework id:spring-core v:6.0.0
~~~
### Salida por pantalla
~~~
id=0
nombre='Nevera'
descripcion='Producto para enfriar '
cantidad=200
precio=259.99}
id=1
nombre='pr1'
descripcion='ds1'
cantidad=100
precio=3.2}
nombre='Lampara'
descripcion='Ilumina tu cuarto'
cantidad=2500
precio=25.3}
id=2
nombre='pr2'
descripcion='ds2'
cantidad=200
precio=3.3}
nombre='Ordenador MSI'
descripcion='Portatil de Ultima generacion'
cantidad=100
precio=1199.99}
id=3
nombre='pr3'
descripcion='ds3'
cantidad=300
precio=3.4}
nombre='Pantalla Led'
descripcion='Mejor Imposible'
cantidad=250
precio=399.99}
id=4
nombre='pr4'
descripcion='ds4'
cantidad=400
precio=3.5}
nombre='Ratón'
descripcion='El mejor periférico'
cantidad=1500
precio=25.99}
id=5
nombre='Teclado'
descripcion='La nueva tecnologia'
cantidad=200
precio=25.99}
id=6
nombre='Regleta de luz'
descripcion='Solo eso, una regleta'
cantidad=1500
precio=9.99}
id=7
nombre='Cargador 65W'
descripcion='MaximaVelocidad'
cantidad=500
precio=99.99}
~~~
### Explicación de la Actividad
Process finished with exit code 0
Por ahora, Solo crea y genera un producto a traves de un BEAN, donde se
inicializa un BEAN con el producto y lo utiliza.
En el main hemos llamado ahora al producto a traves de la interfaz.
~~~

+ 5
- 0
pom.xml View File

@ -20,6 +20,11 @@
<artifactId>spring-context</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>


+ 0
- 12
src/main/java/com/jorpelu/ServicioDeProductos/ISercicioProductoDAO.java View File

@ -1,12 +0,0 @@
package com.jorpelu.ServicioDeProductos;
import java.util.Collection;
public interface ISercicioProductoDAO {
public Producto findByIndex(int index);
public Collection<Producto> findAll();
public void insert(Producto producto);
public void edit(int index, Producto producto);
public void delete(int index);
public void delete(Producto producto);
}

+ 5
- 5
src/main/java/com/jorpelu/ServicioDeProductos/Main.java View File

@ -1,16 +1,16 @@
package com.jorpelu.ServicioDeProductos;
import com.jorpelu.ServicioDeProductos.config.AppConfig;
import com.jorpelu.ServicioDeProductos.dao.ProductoService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Main {
public static void main(String[] args) {
ApplicationContext appContext = new ClassPathXmlApplicationContext("beans.xml");
// ServicioProductos servicioProductos = (ServicioProductos) appContext.getBean("productosService", ServicioProductos.class);
ApplicationContext appContext = new AnnotationConfigApplicationContext(AppConfig.class);
ProductoService servicioProductos = appContext.getBean(ProductoService.class);
servicioProductos.productoList().forEach(System.out::println);
((ClassPathXmlApplicationContext) appContext).close();
((AnnotationConfigApplicationContext) appContext).close();
}
}

+ 0
- 22
src/main/java/com/jorpelu/ServicioDeProductos/ProductoService.java View File

@ -1,22 +0,0 @@
package com.jorpelu.ServicioDeProductos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.awt.*;
import java.util.Collection;
@Component
public class ProductoService {
@Autowired
private ISercicioProductoDAO productoDAO;
public void setProductoDAO(ISercicioProductoDAO productoDAO) {
this.productoDAO = productoDAO;
}
public Collection<Producto> productoList(){
return productoDAO.findAll();
}
}

+ 0
- 47
src/main/java/com/jorpelu/ServicioDeProductos/ProductosDaoImplMemory.java View File

@ -1,47 +0,0 @@
package com.jorpelu.ServicioDeProductos;
import java.util.ArrayList;
import java.util.List;
public class ProductosDaoImplMemory implements ISercicioProductoDAO {
List<Producto> productos = new ArrayList<>();
@Override
public Producto findByIndex(int index) {
return productos.get(index);
}
@Override
public List<Producto> findAll() {
return productos;
}
@Override
public void insert(Producto producto) {
productos.add(producto);
}
@Override
public void edit(int index, Producto producto) {
productos.remove(index);
productos.add(index,producto);
}
@Override
public void delete(int index) {
productos.remove(index);
}
@Override
public void delete(Producto producto) {
productos.remove(producto);
}
public void init() {
insert(new Producto(1,"pr1", "ds1", 100 , (float) 3.2));
insert(new Producto(2,"pr2", "ds2", 200 , (float) 3.3));
insert(new Producto(3,"pr3", "ds3", 300 , (float) 3.4));
insert(new Producto(4,"pr4", "ds4", 400 , (float) 3.5));
}
}

+ 27
- 0
src/main/java/com/jorpelu/ServicioDeProductos/config/AppConfig.java View File

@ -0,0 +1,27 @@
package com.jorpelu.ServicioDeProductos.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@ComponentScan(basePackages = "com.jorpelu.ServicioDeProductos")
@PropertySource("classpath:/productos.properties")
public class AppConfig {
@Value("${file.path}")
private String file;
@Value("${file.csv.separator}")
private String separator;
public String getFile() {
return file;
}
public String getSeparator() {
return separator;
}
}

+ 30
- 0
src/main/java/com/jorpelu/ServicioDeProductos/dao/Parser.java View File

@ -0,0 +1,30 @@
package com.jorpelu.ServicioDeProductos.dao;
import com.jorpelu.ServicioDeProductos.model.Producto;
import org.springframework.util.ResourceUtils;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Parser {
public static List<Producto> readFile(final String path, String separator) {
List<Producto> result = new ArrayList<>();
try {
result = Files.lines(Paths.get(ResourceUtils.getFile(path).toURI())).
skip(1).
map(line->{
String[] values = line.split(separator);
return new Producto(Integer.parseInt(values[0]), values[1], values[2], Integer.parseInt(values[3]), Float.parseFloat(values[4]) );
}).collect(Collectors.toList());
} catch (IOException e) {
System.out.println("Error al leer el archivo"+ e.getMessage());
}
return result;
}
}

+ 17
- 0
src/main/java/com/jorpelu/ServicioDeProductos/dao/ProductoService.java View File

@ -0,0 +1,17 @@
package com.jorpelu.ServicioDeProductos.dao;
import com.jorpelu.ServicioDeProductos.model.Producto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
@Service
public class ProductoService{
@Autowired
private ProductosDao productoDAO;
public Collection<Producto> productoList(){
return productoDAO.findAll();
}
}

+ 15
- 0
src/main/java/com/jorpelu/ServicioDeProductos/dao/ProductosDao.java View File

@ -0,0 +1,15 @@
package com.jorpelu.ServicioDeProductos.dao;
import com.jorpelu.ServicioDeProductos.model.Producto;
import java.util.Collection;
public interface ProductosDao {
Producto findByIndex(int index);
Collection<Producto> findAll();
void insert(Producto producto);
void edit(int index, Producto producto);
void delete(int index);
void delete(Producto producto);
}

+ 57
- 0
src/main/java/com/jorpelu/ServicioDeProductos/dao/ProductosDaoImplMemory.java View File

@ -0,0 +1,57 @@
package com.jorpelu.ServicioDeProductos.dao;
import com.jorpelu.ServicioDeProductos.config.AppConfig;
import com.jorpelu.ServicioDeProductos.model.Producto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
@Repository
public class ProductosDaoImplMemory implements ProductosDao {
List<Producto> productos = new ArrayList<>();
@Autowired
private AppConfig appConfig;
@Override
public Producto findByIndex(int index) {
return productos.get(index);
}
@Override
public List<Producto> findAll() {
return productos;
}
@Override
public void insert(Producto producto) {
productos.add(producto);
}
@Override
public void edit(int index, Producto producto) {
productos.remove(index);
productos.add(index,producto);
}
@Override
public void delete(int index) {
productos.remove(index);
}
@Override
public void delete(Producto producto) {
productos.remove(producto);
}
@PostConstruct
public void init() {
productos = Parser.readFile(appConfig.getFile(), appConfig.getSeparator());
// productos.add(new Producto(1,"pr1", "ds1", 100 , (float) 3.2));
// productos.add(new Producto(2,"pr2", "ds2", 200 , (float) 3.3));
// productos.add(new Producto(3,"pr3", "ds3", 300 , (float) 3.4));
// productos.add(new Producto(4,"pr4", "ds4", 400 , (float) 3.5));
}
}

src/main/java/com/jorpelu/ServicioDeProductos/Producto.java → src/main/java/com/jorpelu/ServicioDeProductos/model/Producto.java View File

@ -1,4 +1,4 @@
package com.jorpelu.ServicioDeProductos;
package com.jorpelu.ServicioDeProductos.model;
import java.util.Objects;

+ 3
- 15
src/main/resources/beans.xml View File

@ -7,22 +7,10 @@
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<bean id="productosDaoImplMemory" class ="com.jorpelu.ServicioDeProductos.ProductosDaoImplMemory"
init-method="init">
</bean>
<context:component-scan base-package="com.jorpelu.ServicioDeProductos"/>
<!-- <bean id="ProductoService" class="com.jorpelu.ServicioDeProductos.ProductoService">-->
<!-- </bean>-->
<!-- <bean id="producto" class="com.jorpelu.ServicioDeProductos.Producto">-->
<!-- <constructor-arg index="0" value="1"/>-->
<!-- <constructor-arg index="1" value="nombreProducto"/>-->
<!-- <constructor-arg index="2" value="descripcion_producto"/>-->
<!-- <constructor-arg index="3" value="100"/>-->
<!-- <constructor-arg index="4" value="19.99"/>-->
<!-- <bean id="productosDaoImplMemory" class ="com.jorpelu.ServicioDeProductos.ProductosDaoImplMemory"-->
<!-- init-method="init">-->
<!-- </bean>-->
<context:component-scan base-package="com.jorpelu.ServicioDeProductos"/>
</beans>

+ 2
- 0
src/main/resources/productos.properties View File

@ -0,0 +1,2 @@
file.path=classpath:productos_data.csv
file.csv.separator=;

+ 9
- 0
src/main/resources/productos_data.csv View File

@ -0,0 +1,9 @@
id;nombre;descripcion;cantidad;precio
0;Nevera;Producto para enfriar ;200;259.99
1;Lampara;Ilumina tu cuarto;2500;25.3
2;Ordenador MSI;Portatil de Ultima generacion;100;1199.99
3;Pantalla Led;Mejor Imposible;250;399.99
4;Ratón;El mejor periférico;1500;25.99
5;Teclado;La nueva tecnologia;200;25.99
6;Regleta de luz;Solo eso, una regleta;1500;9.99
7;Cargador 65W;MaximaVelocidad;500;99.99

Loading…
Cancel
Save