Funcional. Error si se crea un pets vacio

parent 39a7b6b2
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
.project .project
.classpath .classpath
.settings .settings
.idea
WebContent WebContent
# Maven # Maven
......
-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Servidor: 127.0.0.1
-- Tiempo de generación: 24-02-2017 a las 13:08:25
-- Versión del servidor: 10.1.9-MariaDB
-- Versión de PHP: 5.6.15
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Base de datos: `daaexample`
--
CREATE DATABASE IF NOT EXISTS `daaexample` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `daaexample`;
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `people`
--
DROP TABLE IF EXISTS `people`;
CREATE TABLE `people` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`surname` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- RELACIONES PARA LA TABLA `people`:
--
--
-- Volcado de datos para la tabla `people`
--
INSERT INTO `people` (`id`, `name`, `surname`) VALUES
(1, 'Antonia', 'Percal'),
(2, 'Manuel', 'Martínez'),
(3, 'Laura', 'Reboredo'),
(4, 'Percal', 'Palotes'),
(5, 'Ana', 'María'),
(6, 'María', 'Nuevo'),
(7, 'Alba', 'Fernández');
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `pet`
--
DROP TABLE IF EXISTS `pet`;
CREATE TABLE `pet` (
`id` int(11) NOT NULL,
`name` varchar(45) NOT NULL,
`breed` varchar(45) DEFAULT NULL,
`idOwner` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- RELACIONES PARA LA TABLA `pet`:
-- `idOwner`
-- `people` -> `id`
--
--
-- Volcado de datos para la tabla `pet`
--
INSERT INTO `pet` (`id`, `name`, `breed`, `idOwner`) VALUES
(3, 'Joer', 'Pepa', 3),
(4, 'Barcos', 'Barca', 4),
(13, 'Alberto', 'Pesadilla en la cocina', 4);
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `users`
--
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`login` varchar(100) NOT NULL,
`password` varchar(64) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- RELACIONES PARA LA TABLA `users`:
--
--
-- Volcado de datos para la tabla `users`
--
INSERT INTO `users` (`login`, `password`) VALUES
('admin', '43f413b773f7d0cfad0e8e6529ec1249ce71e8697919eab30d82d800a3986b70'),
('normal', '688f21dd2d65970f174e2c9d35159250a8a23e27585452683db8c5d10b586336');
--
-- Índices para tablas volcadas
--
--
-- Indices de la tabla `people`
--
ALTER TABLE `people`
ADD PRIMARY KEY (`id`);
--
-- Indices de la tabla `pet`
--
ALTER TABLE `pet`
ADD PRIMARY KEY (`id`),
ADD KEY `idOwner_idx` (`idOwner`);
--
-- Indices de la tabla `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`login`);
--
-- AUTO_INCREMENT de las tablas volcadas
--
--
-- AUTO_INCREMENT de la tabla `people`
--
ALTER TABLE `people`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
--
-- AUTO_INCREMENT de la tabla `pet`
--
ALTER TABLE `pet`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;
--
-- Restricciones para tablas volcadas
--
--
-- Filtros para la tabla `pet`
--
ALTER TABLE `pet`
ADD CONSTRAINT `idOwner` FOREIGN KEY (`idOwner`) REFERENCES `people` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
CREATE DATABASE `daaexample`; -- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Servidor: 127.0.0.1
-- Tiempo de generación: 24-02-2017 a las 13:08:34
-- Versión del servidor: 10.1.9-MariaDB
-- Versión de PHP: 5.6.15
CREATE TABLE `daaexample`.`people` ( SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
`id` int NOT NULL AUTO_INCREMENT, SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Base de datos: `daaexample`
--
CREATE DATABASE IF NOT EXISTS `daaexample` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `daaexample`;
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `people`
--
DROP TABLE IF EXISTS `people`;
CREATE TABLE `people` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL, `name` varchar(50) NOT NULL,
`surname` varchar(100) NOT NULL, `surname` varchar(100) NOT NULL
PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
);
--
-- RELACIONES PARA LA TABLA `people`:
--
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `pet`
--
DROP TABLE IF EXISTS `pet`;
CREATE TABLE `pet` (
`id` int(11) NOT NULL,
`name` varchar(45) NOT NULL,
`breed` varchar(45) DEFAULT NULL,
`idOwner` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- RELACIONES PARA LA TABLA `pet`:
-- `idOwner`
-- `people` -> `id`
--
CREATE TABLE `daaexample`.`users` ( -- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `users`
--
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`login` varchar(100) NOT NULL, `login` varchar(100) NOT NULL,
`password` varchar(64) NOT NULL, `password` varchar(64) NOT NULL
PRIMARY KEY (`login`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
);
--
GRANT ALL ON `daaexample`.* TO 'daa'@'localhost' IDENTIFIED BY 'daa'; -- RELACIONES PARA LA TABLA `users`:
--
INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'Antón','Pérez');
INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'Manuel','Martínez'); --
INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'Laura','Reboredo'); -- Índices para tablas volcadas
INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'Perico','Palotes'); --
INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'Ana','María');
INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'María','Nuevo'); --
INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'Alba','Fernández'); -- Indices de la tabla `people`
INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'Asunción','Jiménez'); --
ALTER TABLE `people`
-- The password for each user is its login suffixed with "pass". For example, user "admin" has the password "adminpass". ADD PRIMARY KEY (`id`);
INSERT INTO `daaexample`.`users` (`login`,`password`) VALUES ('admin', '43f413b773f7d0cfad0e8e6529ec1249ce71e8697919eab30d82d800a3986b70');
INSERT INTO `daaexample`.`users` (`login`,`password`) VALUES ('normal', '688f21dd2d65970f174e2c9d35159250a8a23e27585452683db8c5d10b586336'); --
-- Indices de la tabla `pet`
--
ALTER TABLE `pet`
ADD PRIMARY KEY (`id`),
ADD KEY `idOwner_idx` (`idOwner`);
--
-- Indices de la tabla `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`login`);
--
-- AUTO_INCREMENT de las tablas volcadas
--
--
-- AUTO_INCREMENT de la tabla `people`
--
ALTER TABLE `people`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
--
-- AUTO_INCREMENT de la tabla `pet`
--
ALTER TABLE `pet`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;
--
-- Restricciones para tablas volcadas
--
--
-- Filtros para la tabla `pet`
--
ALTER TABLE `pet`
ADD CONSTRAINT `idOwner` FOREIGN KEY (`idOwner`) REFERENCES `people` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
CREATE DATABASE `daaexample`;
CREATE TABLE `daaexample`.`people` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`surname` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `daaexample`.`users` (
`login` varchar(100) NOT NULL,
`password` varchar(64) NOT NULL,
PRIMARY KEY (`login`)
);
GRANT ALL ON `daaexample`.* TO 'daa'@'localhost' IDENTIFIED BY 'daa';
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
</sourceRoots>
</configuration>
</facet>
<facet type="web" name="Web2">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/conf/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/conf" relative="/WEB-INF" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
</sourceRoots>
</configuration>
</facet>
<facet type="web" name="Web3">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/webapps/docs/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/webapps/docs" relative="/" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
</sourceRoots>
</configuration>
</facet>
<facet type="web" name="Web4">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/webapps/manager/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/webapps/manager" relative="/" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
</sourceRoots>
</configuration>
</facet>
<facet type="web" name="Web5">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/webapps/docs/appdev/sample/web/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/webapps/docs/appdev/sample/web" relative="/" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
</sourceRoots>
</configuration>
</facet>
<facet type="web" name="Web6">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/webapps/examples/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/webapps/examples" relative="/" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
</sourceRoots>
</configuration>
</facet>
<facet type="web" name="Web7">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/webapps/host-manager/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/servers/extracts/tomcat-8.5.11/apache-tomcat-8.5.11/webapps/host-manager" relative="/" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
</sourceRoots>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.containers:jersey-container-servlet:2.25" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.containers:jersey-container-servlet-core:2.25" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2.external:javax.inject:2.5.0-b30" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-common:2.25" level="project" />
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.2" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.bundles.repackaged:jersey-guava:2.25" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-api:2.5.0-b30" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-utils:2.5.0-b30" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2.external:aopalliance-repackaged:2.5.0-b30" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-locator:2.5.0-b30" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:osgi-resource-locator:1.0.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-server:2.25" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-client:2.25" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-jaxb:2.25" level="project" />
<orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" />
<orderEntry type="library" name="Maven: javax.ws.rs:javax.ws.rs-api:2.0.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-json-jackson:2.25" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.ext:jersey-entity-filtering:2.25" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:2.8.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.8.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.8.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.4" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-jdk14:1.7.22" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.22" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:java-hamcrest:2.0.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.easymock:easymock:3.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2:2.25" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.test-framework:jersey-test-framework-core:2.25" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.25" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.grizzly:grizzly-http-server:2.3.28" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.grizzly:grizzly-http:2.3.28" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.grizzly:grizzly-framework:2.3.28" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.containers:jersey-container-grizzly2-servlet:2.25" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.grizzly:grizzly-http-servlet:2.3.28" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.commons:commons-dbcp2:2.1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.commons:commons-pool2:2.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.seleniumhq.selenium:selenium-java:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.seleniumhq.selenium:selenium-api:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: cglib:cglib-nodep:3.2.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.commons:commons-exec:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.google.code.gson:gson:2.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.google.guava:guava:19.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.java.dev.jna:jna-platform:4.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.java.dev.jna:jna:4.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.seleniumhq.selenium:selenium-edge-driver:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.seleniumhq.selenium:selenium-opera-driver:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.netty:netty:3.5.7.Final" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.seleniumhq.selenium:selenium-support:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.sourceforge.htmlunit:htmlunit:2.23" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: xalan:xalan:2.7.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: xalan:serializer:2.7.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpmime:4.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.sourceforge.htmlunit:htmlunit-core-js:2.23" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.sourceforge.htmlunit:neko-htmlunit:2.23" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: xerces:xercesImpl:2.11.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.sourceforge.cssparser:cssparser:0.9.20" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.w3c.css:sac:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.codeborne:phantomjsdriver:1.3.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.eclipse.jetty.websocket:websocket-client:9.2.15.v20160210" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.eclipse.jetty:jetty-util:9.2.15.v20160210" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.eclipse.jetty:jetty-io:9.2.15.v20160210" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.eclipse.jetty.websocket:websocket-common:9.2.15.v20160210" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.eclipse.jetty.websocket:websocket-api:9.2.15.v20160210" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:4.3.6.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-core:4.3.6.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-context:4.3.6.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-aop:4.3.6.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-beans:4.3.6.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-expression:4.3.6.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-jdbc:4.3.6.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-tx:4.3.6.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.dbunit:dbunit:2.5.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.poi:poi-ooxml:3.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.poi:poi:3.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.poi:poi-ooxml-schemas:3.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.xmlbeans:xmlbeans:2.6.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: stax:stax-api:1.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.github.springtestdbunit:spring-test-dbunit:1.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hsqldb:hsqldb:2.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: mysql:mysql-connector-java:5.1.40" level="project" />
<orderEntry type="library" name="Maven: nl.jqno.equalsverifier:equalsverifier:2.2.1" level="project" />
</component>
</module>
\ No newline at end of file
...@@ -581,7 +581,7 @@ ...@@ -581,7 +581,7 @@
</activation> </activation>
<properties> <properties>
<geckodriver.url>https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz</geckodriver.url> <geckodriver.url>https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz</geckodriver.url>
<geckodriver.basepath>${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch}${file.separator}${project.build.directory}${file.separator}</geckodriver.basepath> <geckodriver.basepath>${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch}${file.separator}</geckodriver.basepath>
<geckodriver.compressed.path>${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz</geckodriver.compressed.path> <geckodriver.compressed.path>${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz</geckodriver.compressed.path>
<geckodriver.uncompressed.path>${geckodriver.basepath}${file.separator}geckodriver</geckodriver.uncompressed.path> <geckodriver.uncompressed.path>${geckodriver.basepath}${file.separator}geckodriver</geckodriver.uncompressed.path>
</properties> </properties>
...@@ -620,7 +620,7 @@ ...@@ -620,7 +620,7 @@
</activation> </activation>
<properties> <properties>
<geckodriver.url>https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.zip</geckodriver.url> <geckodriver.url>https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.zip</geckodriver.url>
<geckodriver.basepath>${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch}${file.separator}${project.build.directory}${file.separator}</geckodriver.basepath> <geckodriver.basepath>${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch}${file.separator}</geckodriver.basepath>
<geckodriver.compressed.path>${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.zip</geckodriver.compressed.path> <geckodriver.compressed.path>${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.zip</geckodriver.compressed.path>
<geckodriver.uncompressed.path>${geckodriver.basepath}${file.separator}geckodriver.exe</geckodriver.uncompressed.path> <geckodriver.uncompressed.path>${geckodriver.basepath}${file.separator}geckodriver.exe</geckodriver.uncompressed.path>
</properties> </properties>
...@@ -714,7 +714,7 @@ ...@@ -714,7 +714,7 @@
<properties> <properties>
<geckodriver.suffix>mac</geckodriver.suffix> <geckodriver.suffix>mac</geckodriver.suffix>
<geckodriver.url>https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz</geckodriver.url> <geckodriver.url>https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz</geckodriver.url>
<geckodriver.basepath>${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch}${file.separator}${project.build.directory}${file.separator}</geckodriver.basepath> <geckodriver.basepath>${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch}${file.separator}</geckodriver.basepath>
<geckodriver.compressed.path>${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz</geckodriver.compressed.path> <geckodriver.compressed.path>${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz</geckodriver.compressed.path>
<geckodriver.uncompressed.path>${geckodriver.basepath}${file.separator}geckodriver</geckodriver.uncompressed.path> <geckodriver.uncompressed.path>${geckodriver.basepath}${file.separator}geckodriver</geckodriver.uncompressed.path>
</properties> </properties>
......
...@@ -11,6 +11,7 @@ import javax.ws.rs.ApplicationPath; ...@@ -11,6 +11,7 @@ import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application; import javax.ws.rs.core.Application;
import es.uvigo.esei.daa.rest.PeopleResource; import es.uvigo.esei.daa.rest.PeopleResource;
import es.uvigo.esei.daa.rest.PetsResource;
import es.uvigo.esei.daa.rest.UsersResource; import es.uvigo.esei.daa.rest.UsersResource;
/** /**
...@@ -26,6 +27,7 @@ public class DAAExampleApplication extends Application { ...@@ -26,6 +27,7 @@ public class DAAExampleApplication extends Application {
public Set<Class<?>> getClasses() { public Set<Class<?>> getClasses() {
return Stream.of( return Stream.of(
PeopleResource.class, PeopleResource.class,
PetsResource.class,
UsersResource.class UsersResource.class
).collect(toSet()); ).collect(toSet());
} }
......
...@@ -188,4 +188,15 @@ public class PeopleDAO extends DAO { ...@@ -188,4 +188,15 @@ public class PeopleDAO extends DAO {
row.getString("surname") row.getString("surname")
); );
} }
private String getName(int id)
{
String toret = "";
try {
toret += this.get(id).getName() + ", " + this.get(id).getSurname();
} catch (DAOException e) {
e.printStackTrace();
}
return toret;
}
} }
package es.uvigo.esei.daa.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import es.uvigo.esei.daa.entities.Pet;
import static sun.misc.Version.print;
/**
* DAO class for the {@link Pet} entities.
*
* @author Miguel Reboiro Jato
*
*/
public class PetDAO extends DAO {
private final static Logger LOG = Logger.getLogger(PetDAO.class.getName());
/**
* Returns a pet stored persisted in the system.
*
* @param id identifier of the pet´s owner.
* @return a pet with the provided identifier.
* @throws DAOException if an error happens while retrieving the pet.
* @throws IllegalArgumentException if the provided id does not corresponds
* with any persisted pet.
*/
public Pet get(int id)
throws DAOException, IllegalArgumentException {
try (final Connection conn = this.getConnection()) {
final String query = "SELECT * FROM pets WHERE idOwner=?";
try (final PreparedStatement statement = conn.prepareStatement(query)) {
statement.setInt(1, id);
try (final ResultSet result = statement.executeQuery()) {
if (result.next()) {
return rowToEntity(result);
} else {
throw new IllegalArgumentException("Invalid id");
}
}
}
} catch (SQLException e) {
LOG.log(Level.SEVERE, "Error getting a pet", e);
throw new DAOException(e);
}
}
/**
* Returns a list with all the pet persisted in the system.
*
* @return a list with all the pet persisted in the system.
* @throws DAOException if an error happens while retrieving the pet.
*/
public List<Pet> list() throws DAOException {
try (final Connection conn = this.getConnection()) {
final String query = "SELECT * FROM pet";
try (final PreparedStatement statement = conn.prepareStatement(query)) {
try (final ResultSet result = statement.executeQuery()) {
final List<Pet> pet = new LinkedList<>();
while (result.next()) {
pet.add(rowToEntity(result));
}
return pet;
}
}
} catch (SQLException e) {
LOG.log(Level.SEVERE, "Error listing pet", e);
throw new DAOException(e);
}
}
/**
* Persists a new pet in the system. An identifier will be assigned
* automatically to the new pet.
*
* @param name name of the new pet. Can't be {@code null}.
* @param breed breed of the new pet. Can't be {@code null}.
* @param idOwner owner of the new pet. Can't be {@code null}.
* @return a {@link Pet} entity representing the persisted pet.
* @throws DAOException if an error happens while persisting the new pet.
* @throws IllegalArgumentException if the name or surname are {@code null}.
*/
public Pet add(String name, String breed, int idOwner)
throws DAOException, IllegalArgumentException {
if (name == null || breed == null || idOwner < 0) {
throw new IllegalArgumentException("name, breed or owner can't be null");
}
try (Connection conn = this.getConnection()) {
final String query = "INSERT INTO pet VALUES(null, ?, ?, ?)";
try (PreparedStatement statement = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS)) {
statement.setString(1, name);
statement.setString(2, breed);
statement.setInt(3, idOwner);
if (statement.executeUpdate() == 1) {
try (ResultSet resultKeys = statement.getGeneratedKeys()) {
if (resultKeys.next()) {
return new Pet(resultKeys.getInt(1), name, breed, idOwner);
} else {
LOG.log(Level.SEVERE, "Error retrieving inserted id");
throw new SQLException("Error retrieving inserted id");
}
}
} else {
LOG.log(Level.SEVERE, "Error inserting value");
throw new SQLException("Error inserting value");
}
}
} catch (SQLException e) {
LOG.log(Level.SEVERE, "Error adding a pet", e);
throw new DAOException(e);
}
}
/**
* Modifies a pet previously persisted in the system. The pet will be
* retrieved by the provided id and its current name and surname will be
* replaced with the provided.
*
* @param pet a {@link Pet} entity with the new data.
* @throws DAOException if an error happens while modifying the new pet.
* @throws IllegalArgumentException if the pet is {@code null}.
*/
public void modify(Pet pet)
throws DAOException, IllegalArgumentException {
if (pet == null) {
throw new IllegalArgumentException("pet can't be null");
}
try (Connection conn = this.getConnection()) {
final String query = "UPDATE pet SET name=?, breed=?, idOwner=? WHERE id=?";
try (PreparedStatement statement = conn.prepareStatement(query)) {
statement.setString(1, pet.getName());
statement.setString(2, pet.getBreed());
statement.setInt(3, pet.getIdOwner());
statement.setInt(4, pet.getId());
if (statement.executeUpdate() != 1) {
throw new IllegalArgumentException("name and surname can't be null");
}
}
} catch (SQLException e) {
LOG.log(Level.SEVERE, "Error modifying a pet", e);
throw new DAOException();
}
}
/**
* Removes a persisted pet from the system.
*
* @param id identifier of the pet to be deleted.
* @throws DAOException if an error happens while deleting the pet.
* @throws IllegalArgumentException if the provided id does not corresponds
* with any persisted pet.
*/
public void delete(int id)
throws DAOException, IllegalArgumentException {
try (final Connection conn = this.getConnection()) {
final String query = "DELETE FROM pet WHERE id=?";
try (final PreparedStatement statement = conn.prepareStatement(query)) {
statement.setInt(1, id);
if (statement.executeUpdate() != 1) {
throw new IllegalArgumentException("Invalid id");
}
}
} catch (SQLException e) {
LOG.log(Level.SEVERE, "Error deleting a pet", e);
throw new DAOException(e);
}
}
private Pet rowToEntity(ResultSet row) throws SQLException {
return new Pet(
row.getInt("id"),
row.getString("name"),
row.getString("breed"),
row.getInt("idOwner")
);
}
}
package es.uvigo.esei.daa.entities;
import static java.util.Objects.requireNonNull;
/**
* Created by Alex on 15/02/2017.
*/
public class Pet {
private int id;
private String name;
private String breed;
private int idOwner;
// Constructor needed for the JSON conversion
Pet() {}
/**
* Constructs a new instance of {@link Pet}.
*
* @param id identifier of the pet.
* @param name name of the pet.
* @param breed breed of the pet.
*/
public Pet(int id, String name, String breed, int idOwner) {
this.id = id;
this.setName(name);
this.setBreed(breed);
this.setIdOwner(idOwner);
}
/**
* Returns the identifier of the pet.
*
* @return the identifier of the pet.
*/
public int getId() {
return id;
}
/**
* Returns the identifier of the owner.
*
* @return the identifier of the owner.
*/
public int getIdOwner() {
return idOwner;
}
public void setIdOwner(int i) {
this.idOwner = i;
}
/**
* Returns the name of the pet.
*
* @return the name of the pet.
*/
public String getName() {
return name;
}
/**
* Set the name of this pet.
*
* @param name the new name of the pet.
* @throws NullPointerException if the {@code name} is {@code null}.
*/
public void setName(String name) {
this.name = requireNonNull(name, "Name can't be null");
}
/**
* Returns the breed of the pet.
*
* @return the breed of the pet.
*/
public String getBreed() {
return breed;
}
/**
* Set the breed of this pet.
*
* @param breed the new breed of the pet.
* @throws NullPointerException if the {@code breed} is {@code null}.
*/
public void setBreed(String breed) {
this.breed = requireNonNull(breed, "Breed can't be null");
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof Pet))
return false;
Pet other = (Pet) obj;
if (id != other.getId())
return false;
return true;
}
}
\ No newline at end of file
package es.uvigo.esei.daa.rest;
import es.uvigo.esei.daa.dao.DAOException;
import es.uvigo.esei.daa.dao.PetDAO;
import es.uvigo.esei.daa.entities.Pet;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Created by Alex on 20/02/2017.
*/
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import es.uvigo.esei.daa.dao.DAOException;
import es.uvigo.esei.daa.dao.PetDAO;
import es.uvigo.esei.daa.entities.Pet;
/**
* REST resource for managing pets.
*
* @author Miguel Reboiro Jato.
*/
@Path("/pets")
@Produces(MediaType.APPLICATION_JSON)
public class PetsResource {
private final static Logger LOG = Logger.getLogger(PetsResource.class.getName());
private final PetDAO dao;
/**
* Constructs a new instance of {@link PetsResource}.
*/
public PetsResource() {
this(new PetDAO());
}
// Needed for testing purposes
PetsResource(PetDAO dao) {
this.dao = dao;
}
/**
* Returns a pet with the provided identifier.
*
* @param id the identifier of the pet to retrieve.
* @return a 200 OK response with a pet that has the provided identifier.
* If the identifier does not corresponds with any user, a 400 Bad Request
* response with an error message will be returned. If an error happens
* while retrieving the list, a 500 Internal Server Error response with an
* error message will be returned.
*/
@GET
@Path("/{id}")
public Response get(
@PathParam("id") int id
) {
try {
final Pet pet = this.dao.get(id);
return Response.ok(pet).build();
} catch (IllegalArgumentException iae) {
LOG.log(Level.FINE, "Invalid pet id in get method", iae);
return Response.status(Response.Status.BAD_REQUEST)
.entity(iae.getMessage())
.build();
} catch (DAOException e) {
LOG.log(Level.SEVERE, "Error getting a pet", e);
return Response.serverError()
.entity(e.getMessage())
.build();
}
}
/**
* Returns the complete list of pets stored in the system.
*
* @return a 200 OK response with the complete list of pets stored in the
* system. If an error happens while retrieving the list, a 500 Internal
* Server Error response with an error message will be returned.
*/
@GET
public Response list() {
try {
return Response.ok(this.dao.list()).build();
} catch (DAOException e) {
LOG.log(Level.SEVERE, "Error listing pets", e);
return Response.serverError().entity(e.getMessage()).build();
}
}
/**
* Creates a new pet in the system.
*
* @param name the name of the new pet.
* @param breed the breed of the new pet.
* @return a 200 OK response with a pet that has been created. If the
* name or the breed are not provided, a 400 Bad Request response with an
* error message will be returned. If an error happens while retrieving the
* list, a 500 Internal Server Error response with an error message will be
* returned.
*/
@POST
public Response add(
@FormParam("name") String name,
@FormParam("breed") String breed,
@FormParam("idOwner") int idOwner
) {
try {
final Pet newPet = this.dao.add(name, breed, idOwner);
return Response.ok(newPet).build();
} catch (IllegalArgumentException iae) {
LOG.log(Level.FINE, "Invalid pet id in add method", iae);
return Response.status(Response.Status.BAD_REQUEST)
.entity(iae.getMessage())
.build();
} catch (DAOException e) {
LOG.log(Level.SEVERE, "Error adding a pet", e);
return Response.serverError()
.entity(e.getMessage())
.build();
}
}
/**
* Modifies the data of a pet.
*
* @param id identifier of the pet to modify.
* @param name the new name of the pet.
* @param breed the new breed of the pet.
* @param idOwner the owner of the pet.
* @return a 200 OK response with a pet that has been modified. If the
* identifier does not corresponds with any user or the name or breed are
* not provided, a 400 Bad Request response with an error message will be
* returned. If an error happens while retrieving the list, a 500 Internal
* Server Error response with an error message will be returned.
*/
@PUT
@Path("/{id}")
public Response modify(
@PathParam("id") int id,
@FormParam("name") String name,
@FormParam("breed") String breed,
@FormParam("idOwner") String idOwner
) {
int idOw;
try {
//Here it is controlled that idOwner can´t be null
if(idOwner == null)
idOw = -1;
else
idOw = Integer.parseInt(idOwner);
final Pet modifiedPet = new Pet(id, name, breed, idOw);
this.dao.modify(modifiedPet);
return Response.ok(modifiedPet).build();
} catch (NullPointerException npe) {
final String message = String.format("Invalid data for pet (name: %s, id: %d)", name, idOwner);
LOG.log(Level.FINE, message);
return Response.status(Response.Status.BAD_REQUEST)
.entity(message)
.build();
} catch (IllegalArgumentException iae) {
LOG.log(Level.FINE, "Invalid pet id in modify method", iae);
return Response.status(Response.Status.BAD_REQUEST)
.entity(iae.getMessage())
.build();
} catch (DAOException e) {
LOG.log(Level.SEVERE, "Error modifying a pet", e);
return Response.serverError()
.entity(e.getMessage())
.build();
}
}
/**
* Deletes a pet from the system.
*
* @param id the identifier of the pet to be deleted.
* @return a 200 OK response with the identifier of the pet that has
* been deleted. If the identifier does not corresponds with any user, a 400
* Bad Request response with an error message will be returned. If an error
* happens while retrieving the list, a 500 Internal Server Error response
* with an error message will be returned.
*/
@DELETE
@Path("/{id}")
public Response delete(
@PathParam("id") int id
) {
try {
this.dao.delete(id);
return Response.ok(id).build();
} catch (IllegalArgumentException iae) {
LOG.log(Level.FINE, "Invalid pet id in delete method", iae);
return Response.status(Response.Status.BAD_REQUEST)
.entity(iae.getMessage())
.build();
} catch (DAOException e) {
LOG.log(Level.SEVERE, "Error deleting a pet", e);
return Response.serverError()
.entity(e.getMessage())
.build();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/webapp/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/webapp" relative="/" />
</webroots>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: javax.ws.rs:javax.ws.rs-api:2.0.1" level="project" />
</component>
</module>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<link rel="stylesheet" href="css/main.css">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>DAA Example - Login</title> <title>DAA Example - Login</title>
</head> </head>
<body> <body>
<div class="form-group">
<h4 style="text-align: center; color:white;" class="modal-title">Iniciar Sesi&oacuten</h4>
<div class="text-center">
<div class="login-form-1">
<div class="login-form-main-message"></div>
<div class="main-login-form">
<div class="login-group">
<form action="main.html" method="POST"> <form action="main.html" method="POST">
<div>
Login: <input name="login" type="text" /> <p><label >Login:</label></p>
<input name="login" type="text" placeholder="Write your login name"/></p>
<p><label >Password: </label></p>
<input name="password" type="password" placeholder="****"/></p>
<p id="bot"><button type="submit" class="btn btn-default1" id="botonModificar" name="submit" style="margin-bottom: 10px;" class="btn btn-default3">Login</button></p>
</form>
</div>
</div>
</div> </div>
<div>
Password: <input name="password" type="password" />
</div> </div>
<div>
<input type="submit" value="Login" />
</div> </div>
</form>
</body> </body>
</html> </html>
\ No newline at end of file
/**
* Created by Alex on 15/02/2017.
*/
var PetsDAO = (function() {
var resourcePath = "rest/pets/";
var requestByAjax = function(data, done, fail, always) {
done = typeof done !== 'undefined' ? done : function() {};
fail = typeof fail !== 'undefined' ? fail : function() {};
always = typeof always !== 'undefined' ? always : function() {};
$.ajax(data)
.done(done)
.fail(fail)
.always(always);
};
function PetsDAO() {
this.listPets = function(done, fail, always) {
requestByAjax({
url: resourcePath,
type: 'GET'
}, done, fail, always);
};
this.addPet = function(pet, done, fail, always) {
requestByAjax({
url: resourcePath,
type: 'POST',
data: pet
}, done, fail, always);
};
this.modifyPet = function(pet, done, fail, always) {
requestByAjax({
url: resourcePath + pet.id,
type: 'PUT',
data: pet
}, done, fail, always);
};
this.deletePet = function(id, done, fail, always) {
requestByAjax({
url: resourcePath + id,
type: 'DELETE',
}, done, fail, always);
};
}
return PetsDAO;
})();
\ No newline at end of file
...@@ -118,6 +118,9 @@ var PeopleView = (function() { ...@@ -118,6 +118,9 @@ var PeopleView = (function() {
'<table id="' + listId + '">\ '<table id="' + listId + '">\
<tr>\ <tr>\
<th>Nombre</th>\ <th>Nombre</th>\
<th/>\
<th/>\
<th/>\
<th>Apellido</th>\ <th>Apellido</th>\
<th></th>\ <th></th>\
<th></th>\ <th></th>\
......
/**
* Created by Alex on 15/02/2017.
*/
var PetsView = (function() {
var dao;
// Referencia a this que permite acceder a las funciones públicas desde las funciones de jQuery.
var self;
var formId = 'pets-form';
var listId = 'pets-list';
var formQuery = '#' + formId;
var listQuery = '#' + listId;
function PetsView(petsDao, formContainerId, listContainerId) {
dao = petsDao;
self = this;
insertPetsForm($('#' + formContainerId));
insertPetsList($('#' + listContainerId));
this.init = function() {
dao.listPets(function(pets) {
$.each(pets, function(key, pet) {
appendToTable(pet);
});
});
// La acción por defecto de enviar formulario (submit) se sobreescribe
// para que el envío sea a través de AJAX
$(formQuery).submit(function(event) {
var pet = self.getPetInForm();
if (self.isEditing()) {
dao.modifyPet(pet,
function(pet) {
$('#pet-' + pet.id + ' td.name').text(pet.name);
$('#pet-' + pet.id + ' td.breed').text(pet.breed);
$('#pet-' + pet.id + ' td.idOwner').text(pet.idOwner);
self.resetForm();
},
showErrorMessage,
self.enableForm
);
} else {
dao.addPet(pet,
function(pet) {
appendToTable(pet);
self.resetForm();
},
showErrorMessage,
self.enableForm
);
}
return false;
});
$('#btnClear').click(this.resetForm);
};
this.getPetInForm = function() {
var form = $(formQuery);
return {
'id': form.find('input[name="id"]').val(),
'name': form.find('input[name="name"]').val(),
'breed': form.find('input[name="breed"]').val(),
'idOwner': form.find('input[name="idOwner"]').val()
};
};
this.getPetInRow = function(id) {
var row = $('#pet-' + id);
if (row !== undefined) {
return {
'id': id,
'name': row.find('td.name').text(),
'breed': row.find('td.breed').text(),
'idOwner': row.find('td.idOwner').text()
};
} else {
return undefined;
}
};
this.editPet = function(id) {
var row = $('#pet-' + id);
console.log(row);
if (row !== undefined) {
var form = $(formQuery);
console.log(form);
console.log(row.find('td.name').text());
console.log(row.find('td.breed').text());
console.log(row.find('td.idOwner').text());
form.find('input[name="id"]').val(id);
form.find('input[name="name"]').val(row.find('td.name').text());
form.find('input[name="breed"]').val(row.find('td.breed').text());
form.find('input[name="idOwner"]').val(row.find('td.idOwner').text());
}
}
this.isEditing = function() {
return $(formQuery + ' input[name="id"]').val() != "";
};
this.disableForm = function() {
$(formQuery + ' input').prop('disabled', true);
};
this.enableForm = function() {
$(formQuery + ' input').prop('disabled', false);
};
this.resetForm = function() {
$(formQuery)[0].reset();
$(formQuery + ' input[name="id"]').val('');
$('#btnSubmit').val('Crear');
};
}
var insertPetsList = function(parent) {
parent.append(
'<table id="' + listId + '">\
<tr>\
<th>Nombre</th>\
<th>Raza</th>\
<th>Owner</th>\
<th></th>\
</tr>\
</table>'
);
}
var insertPetsForm = function(parent) {
parent.append(
'<form id="' + formId + '">\
<input name="id" type="hidden" value=""/>\
<input name="name" type="text" value="" />\
<input name="breed" type="text" value=""/>\
<input name="idOwner" type="text" value=""/>\
<input id="btnSubmit" type="submit" value="Create"/>\
<input id="btnClear" type="reset" value="Limpiar"/>\
</form>'
);
}
var createPetRow = function(pet) {
return '<tr id="pet-'+ pet.id +'">\
<td class="name">' + pet.name + '</td>\
<td class="breed">' + pet.breed + '</td>\
<td class="idOwner">' + pet.idOwner + '</td>\
<td>\
<a class="edit" href="#">Edit</a>\
</td>\
<td>\
<a class="delete" href="#">Delete</a>\
</td>\
</tr>';
}
var showErrorMessage = function(jqxhr, textStatus, error) {
alert(textStatus + ": " + error);
}
var addRowListeners = function(pet) {
$('#pet-' + pet.id + ' a.edit').click(function() {
self.editPet(pet.id);
$('input#btnSubmit').val('Modificar');
});
$('#pet-' + pet.id + ' a.delete').click(function() {
if (confirm('Está a punto de eliminar a una peta. ¿Está seguro de que desea continuar?')) {
dao.deletePet(pet.id,
function() {
$('tr#pet-' + pet.id).remove();
},
showErrorMessage
);
}
});
}
var appendToTable = function(pet) {
$(listQuery + ' > tbody:last')
.append(createPetRow(pet));
addRowListeners(pet);
}
return PetsView;
})();
\ No newline at end of file
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<link rel="stylesheet" href="css/main.css">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>DAA Example</title> <title>DAA Example</title>
...@@ -7,12 +10,19 @@ ...@@ -7,12 +10,19 @@
<body> <body>
<div id="people-container"> <div id="people-container">
<h1>People</h1> <h1>People</h1>
<div align="left">
<a id="#animals" href="main_pet.html">Pets</a>
</div>
<div align="center">
<a id="#logout" href="logout">Logout</a> <a id="#logout" href="logout">Logout</a>
</div> </div>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.0.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
<script type="text/javascript" src="js/dao/people.js"></script> <script type="text/javascript" src="js/dao/people.js"></script>
<script type="text/javascript" src="js/dao/pets.js"></script>
<script type="text/javascript" src="js/view/people.js"></script> <script type="text/javascript" src="js/view/people.js"></script>
<script type="text/javascript" src="js/view/pets.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
var view = new PeopleView(new PeopleDAO(), 'people-container', 'people-container'); var view = new PeopleView(new PeopleDAO(), 'people-container', 'people-container');
......
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="css/main.css">
<head>
<meta charset="UTF-8">
<title>DAA Example</title>
</head>
<body>
<div id="pet-container">
<h1>Pets</h1>
<div align="left">
<a id="#back" href="main.html">Back</a>
<div/>
<div align="center">
<a id="#logout" href="logout">Logout</a>
<div/>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
<script type="text/javascript" src="js/dao/people.js"></script>
<script type="text/javascript" src="js/dao/pets.js"></script>
<script type="text/javascript" src="js/view/people.js"></script>
<script type="text/javascript" src="js/view/pets.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var view = new PetsView(new PetsDAO(), 'pet-container', 'pet-container');
view.init();
});
</script>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="main" />
</component>
</module>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment