Commit 18ebe8e6 authored by kolo1984's avatar kolo1984
Browse files

primer commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>practico</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding/<project>=UTF-8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
This project was created from the archetype "wildfly-jakartaee-ear-archetype".
To deploy it:
Run the maven goals "install wildfly:deploy"
To undeploy it:
Run the maven goals "wildfly:undeploy"
==========================
DataSource:
This sample includes a "persistence.xml" file in the EJB project. This file defines
a persistence unit "practicoPersistenceUnit" which uses the JakartaEE default database.
In production environment, you should define a database in WildFly config and point to this database
in "persistence.xml".
If you don't use entity beans, you can delete "persistence.xml".
==========================
JSF:
The web application is prepared for JSF by bundling an empty "faces-config.xml" in "src\main\webapp\WEB-INF".
In case you don't want to use JSF, simply delete this file.
==========================
Testing:
This sample is prepared for running unit tests with the Arquillian framework.
The configuration can be found in "practico\pom.xml":
Three profiles are defined:
-"default": no integration tests are executed.
-"arq-remote": you have to start a WildFly server on your machine. The tests are executed by deploying
the application to this server.
Here the "maven-failsafe-plugin" is enabled so that integration tests can be run.
Run maven with these arguments: "clean verify -Parq-remote"
-"arq-managed": this requires the environment variable "JBOSS_HOME" to be set:
The server found in this path is started and the tests are executed by deploying the application to this server.
Instead of using this environment variable, you can also define the path in "arquillian.xml".
Here the "maven-failsafe-plugin" is enabled so that integration tests can be run.
Run maven with these arguments: "clean verify -Parq-managed"
The Arquillian test runner is configured with the file "src\test\resources\arquillian.xml"
(duplicated in EJB and WEB project, depending where your tests are placed).
The profile "arq-remote" uses the container qualifier "remote" in this file.
The profile "arq-managed" uses the container qualifier "managed" in this file.
Unit tests can be added to EJB project and/or to Web project.
The web project contains an integration test "SampleIT" which shows how to create the deployable EAR file using the ShrinkWrap API.
You can delete this test file if no tests are necessary.
Why integration tests instead of the "maven-surefire-plugin" testrunner?
The Arquillian test runner deploys the EAR file to the WildFly server and thus you have to build it yourself with the ShrinkWrap API.
The goal "verify" (which triggers the maven-surefire-plugin) is executed later in the maven build lifecyle than the "test" goal so that the target
artifacts ("practico-ejb.jar" and "practico-web.war") are already built. You can build
the final EAR by including those files. The "maven-surefire-plugin" is executed before the JAR/WAR files
are created, so those JAR/WAR files would have to be built in the "@Deployment" method, too.
<?xml version="1.0" encoding="UTF-8"?>
<!-- JBoss, Home of Professional Open Source Copyright 2015, Red Hat, Inc.
and/or its affiliates, and individual contributors by the @authors tag. See
the copyright.txt in the distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ejercicio</groupId>
<artifactId>practico</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>practico</name>
<description>Insert description for your project here.</description>
<modules>
<module>practico-ejb</module>
<module>practico-web</module>
<module>practico-ear</module>
</modules>
<properties>
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- JBoss dependency versions -->
<version.wildfly.maven.plugin>2.0.0.Final</version.wildfly.maven.plugin>
<!-- Define the version of the JBoss BOMs we want to import to specify
tested stacks. -->
<version.jboss.bom>18.0.0.Final</version.jboss.bom>
<version.wildfly>18.0.0.Final</version.wildfly>
<!-- other plugin versions -->
<version.compiler.plugin>3.8.0</version.compiler.plugin>
<version.ear.plugin>3.0.1</version.ear.plugin>
<version.ejb.plugin>3.0.0</version.ejb.plugin>
<version.surefire.plugin>2.22.1</version.surefire.plugin>
<version.failsafe.plugin>2.22.1</version.failsafe.plugin>
<version.war.plugin>3.2.2</version.war.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<!-- Define the version of the EJB jar so that we don't need to repeat
ourselves in every module -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>practico-ejb</artifactId>
<version>${project.version}</version>
<type>ejb</type>
</dependency>
<!-- Define the version of the WAR so that we don't need to repeat ourselves
in every module -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>practico-web</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>compile</scope>
</dependency>
<!-- JBoss distributes a complete set of Jakarta EE 8 APIs including a
Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or a
collection) of artifacts. We use this here so that we always get the correct
versions of artifacts. Here we use the wildfly-jakartaee-8.0-with-tools stack
(you can read this as the WildFly stack of the Jakarta EE 8 APIs -->
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-jakartaee8-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${org.wildfly.plugin.version}</version>
<!--exclusions>
<exclusion>
<groupId>sun.jdk</groupId>
<artifactId>jconsole</artifactId>
</exclusion>
</exclusions-->
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<!-- The WildFly plugin deploys your ear to a local JBoss AS container -->
<!-- Due to Maven's lack of intelligence with EARs we need to configure
the wildfly maven plugin to skip deployment for all modules. We then enable
it specifically in the ear module. -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
<inherited>true</inherited>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- All the modules that require nothing but JBoss Enterprise Application
Platform or JBoss EAP -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- An optional Arquillian testing profile that executes tests in your
JBoss EAP instance. This profile will start a new JBoss EAP instance, and
execute the test, shutting it down when done. Run with: mvn clean verify
-Parq-managed -->
<id>arq-managed</id>
<dependencies>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.failsafe.plugin}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Configuration for Arquillian: -->
<systemPropertyVariables>
<!-- Defines the container qualifier in "arquillian.xml" -->
<arquillian.launch>managed</arquillian.launch>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- An optional Arquillian testing profile that executes tests in a remote
JBoss EAP instance. Run with: mvn clean verify -Parq-remote -->
<id>arq-remote</id>
<dependencies>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.failsafe.plugin}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Configuration for Arquillian: -->
<systemPropertyVariables>
<!-- Defines the container qualifier in "arquillian.xml" -->
<arquillian.launch>remote</arquillian.launch>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>practico</groupId>
<artifactId>practico-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<!-- Dependency on the EJB module so we can use it's services if needed -->
<dependency>
<groupId>ejercicio</groupId>
<artifactId>practico-ejb</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-client-all</artifactId>
<version>18.0.0.Final</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package app.tse;
import java.math.BigDecimal;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import ejercicio.practico.entitidades.Recurso;
import ejercicio.practico.entitidades.TipoRecurso;
import ejercicio.practico.negocio.IServicioRecursoRemoto;
import io.undertow.server.protocol.ParseTimeoutUpdater;
public class Main {
public static Scanner scanner;
public static void main(String[] args) throws NamingException {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
props.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
Context ctx = new InitialContext(props);
String jndiName = "ejb:practico/practico-ejb/ServicioRecursoLocal!ejercicio.practico.negocio.IServicioRecursoRemoto";
IServicioRecursoRemoto iServicioRecursoRemoto = (IServicioRecursoRemoto) ctx.lookup(jndiName);
scanner = new Scanner(System.in);
int opcion = -1;
while (opcion != 0) {
opcion = mostrarMenuPpal();
switch (opcion) {
case 1:
try {
String codigo = altaRecurso();
int cantidad = solicitarCantidadAltaRecurso();
BigDecimal precioUnitario = solicitarPrecioUnitarioAltaRecurso();
String nombreTipoRecurso = solicitarNombreTipoRecursoAltaRecurso();
boolean dioAlta = iServicioRecursoRemoto.altaRecurso(codigo, precioUnitario, cantidad,
nombreTipoRecurso);
mensageResultado(dioAlta);
} catch (Exception e) {
break;
}
break;
case 2:
List<TipoRecurso> tipoRecursos = iServicioRecursoRemoto.listarTipoRecursos();
mostrarlistarTipoRecurso(tipoRecursos);
break;
case 3:
String nombre = solicitarNombreTipoRecurso();
if (nombre != null && !nombre.isEmpty()) {
List<Recurso> listarRecursosPorTipo = iServicioRecursoRemoto.listarRecursosPorTipo(nombre);
mostrarlistarRecurso(listarRecursosPorTipo);
}
break;
case 0:
System.out.println("Chauuu!!!");
break;
}
}
}
private static void mensageResultado(boolean dioAlta) {
String msg = dioAlta ? "Se realizo el alta exitosamente." : "No se pudo realizar el alta.";
System.out.println(msg);
}
private static String solicitarNombreTipoRecursoAltaRecurso() throws Exception {
System.out.print("Ingrese el nombre del tipo de recurso: ");
try {
String nombre = scanner.nextLine();
return nombre;
} catch (Exception e) {
System.out.println("Ocurrio un error al ingresar el nombre del tipo de recurso.");
throw new Exception();
}
}
private static BigDecimal solicitarPrecioUnitarioAltaRecurso() throws Exception {
System.out.print("Ingrese el precio unitario: ");
try {
String linea = scanner.nextLine();
BigDecimal precioUnitario = new BigDecimal(linea);
return precioUnitario;
} catch (Exception e) {
System.out.println("Ocurrio un error al ingresar el precio unitario.");
throw new Exception();
}
}
private static int solicitarCantidadAltaRecurso() throws Exception {
System.out.print("Ingrese la cantidad: ");
try {
String linea = scanner.nextLine();
int opcion = Integer.parseInt(linea);
return opcion;
} catch (Exception e) {
System.out.println("Ocurrio un error al ingresar la cantidad.");
throw new Exception();
}
}
private static String altaRecurso() throws Exception {
System.out.println("###############################################");
System.out.println("#### ALTA RECURSO DE UN TIPO DE RECURSO #######");
System.out.println("###############################################");
System.out.println("");
System.out.print("Ingrese el codigo: ");
try {
String codigo = scanner.nextLine();
return codigo;
} catch (Exception e) {
System.out.println("Ocurrio un error al ingresar el codigo.");
throw new Exception();
}
}
private static void mostrarlistarRecurso(List<Recurso> listarRecursosPorTipo) {
System.out.println("");
System.out.println("Codigo - Cantidad - Precio unitario");
listarRecursosPorTipo.stream().forEach(r -> {
System.out.println(r.getCodigo() + " - " + r.getCantidad() + " - " + r.getPrecioUnitario());
});
System.out.println("");
System.out.println("");
}
private static String solicitarNombreTipoRecurso() {
System.out.println("###############################################");
System.out.println("#### LISTA DE RECURSOS DE UN DETERMINADO TIPO #");
System.out.println("###############################################");
System.out.println("");
System.out.print("Ingrese en nombre del tipo de recurso: ");
try {
String nombre = scanner.nextLine();
return nombre;
} catch (InputMismatchException e) {
System.out.println("Ocurrio un error.");
return null;
}
}
private static void mostrarlistarTipoRecurso(List<TipoRecurso> tipoRecursos) {
System.out.println("###############################################");
System.out.println("#### LISTA DE TIPOS DE RECURSOS ###############");
System.out.println("###############################################");
System.out.println("");
System.out.println("Nombre - Descripcion - Precio referencia");
tipoRecursos.stream().forEach(tr -> {
System.out.println(tr.getNombre() + " - " + tr.getDescripcion() + " - " + tr.getPrecioReferencia());
});
System.out.println("");
System.out.println("");
}
private static int mostrarMenuPpal() {
System.out.println("###############################################");
System.out.println("#### GESTOR DE RECURSOS #######################");
System.out.println("###############################################");
System.out.println("");
System.out.println("Opciones: ");
System.out.println("1) Agregar un Recurso de un Tipo de Recurso.");
System.out.println("2) Listar Tipos de Recursos.");
System.out.println("3) Listar Recursos de un determinado tipo.");
System.out.println("0) Salir.");
System.out.println("");
System.out.print("Seleccione opcion: ");
try {
String linea = scanner.nextLine();
int opcion = Integer.parseInt(linea);
return opcion;
} catch (Exception e) {
System.out.println("Ocurrio un error.");
return -1;
}
}
public Main() {
super();
}
}
\ No newline at end of file
eclipse.preferences.version=1
encoding/<project>=UTF-8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="practico">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/ear-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/application" tag="defaultRootSource"/>
<dependent-module archiveName="practico-ejb.jar" deploy-path="/" handle="module:/resource/practico-ejb/practico-ejb">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="practico-web.war" deploy-path="/" handle="module:/resource/practico-web/practico-web">