Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Josemgarcia #13

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
48afbc5
Improved security module with an relation between Users an Authorities
japarejo Sep 10, 2020
5b74d64
Added base a extended class diagramas of the data model of our domain.
japarejo Sep 22, 2020
e20022e
Mejoras en las anotaciones del diagrama
japarejo Sep 23, 2020
c46f23f
Improved diagram annotations.
japarejo Sep 24, 2020
8899ac6
Refactoring of the repositories for a clearer structure. First new
japarejo Oct 2, 2020
a894421
Merge branch 'master' of https://github.com/gii-is-DP1/spring-petclin…
japarejo Oct 2, 2020
db2003e
Eliminados scripts de mysql para simplificar la estructura del repo
japarejo Oct 2, 2020
42546d6
Removed disease for setting an starting point for the exercises
japarejo Oct 3, 2020
116cbda
Modified links from DP2 to DP1
japarejo Oct 7, 2020
ba815e4
Changes to support submenus in menu items
japarejo Oct 7, 2020
44e3080
Merge branch 'master' of https://github.com/gii-is-DP1/spring-petclin…
japarejo Oct 7, 2020
537797d
Added messaging notifications
japarejo Oct 7, 2020
80cf8ba
Update readme.md
josemgarcia Oct 13, 2020
f72b8ac
Added generic Entity converter for ease of use and simplicty.
japarejo Oct 16, 2020
b3aee02
Removed unused import causing errors in JDK11
japarejo Oct 19, 2020
1440379
Arrangement of diagrams in conceptual models and domain models.
japarejo Oct 27, 2020
241afd6
Minor fixes in conceptual diagram of petclinic extensio n
japarejo Oct 27, 2020
232c9e5
Removed superfluous classes with no use
japarejo Oct 27, 2020
e42f27b
@Data annotation removed due to the undesired effects
japarejo Dec 21, 2020
f2c431d
Updated to Java 11
resinas Sep 30, 2021
48dc239
Reorganized packages to a domain-oriented approach
resinas Sep 30, 2021
0c2033b
Removes warnings by cleaning up imports
resinas Sep 30, 2021
760c5e7
Improved DB initialization script by including column names in vet in…
japarejo Oct 20, 2021
9d8720e
Ignored VSCode configuration files
japarejo Oct 20, 2021
9806b13
Accents and ñ working
japarejo Oct 20, 2021
1a7581c
Added dices on session controller and improved PetService.
japarejo Nov 25, 2021
29d86f5
Updated lombok version for JDKs higher than 11
japarejo Sep 20, 2022
6c68f05
Rename the project
josemgarcia Sep 21, 2022
50ff3cb
Update pom.xml
josemgarcia Sep 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ _site/
.metadata/.plugins/org.eclipse.ui.intro/introstate
.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml
.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml

.vscode/
26 changes: 0 additions & 26 deletions .vscode/launch.json

This file was deleted.

3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

19 changes: 0 additions & 19 deletions .vscode/tasks.json

This file was deleted.

36 changes: 26 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic</artifactId>
<artifactId>spring-petclinic-josemgarcia</artifactId>
<version>2.2.0.BUILD-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
</parent>
<name>petclinic</name>
<name>petclinic-josemgarcia</name>

<properties>

<!-- Generic properties -->
<java.version>1.8</java.version>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

Expand All @@ -31,6 +31,21 @@
<spring-format.version>0.0.19</spring-format.version>

</properties>

<developers>
<developer>
<id>japarejo</id>
<name>Jose Antonio Parejo</name>
<email>japarejo@us.es</email>
<url>http://www.us.es</url>
<roles>
<role>leader</role>
</roles>
<properties>
<picUrl>https://pbs.twimg.com/media/Eh4n9GhUMAAdO8x?format=jpg</picUrl>
</properties>
</developer>
<developers>

<dependencies>
<!-- Spring and Spring Boot dependencies -->
Expand All @@ -50,16 +65,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<!-- Databases - Uses H2 by default -->
<!-- dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency-->
</dependency-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand All @@ -69,7 +84,7 @@
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- validation
<!-- validation
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
Expand Down Expand Up @@ -139,6 +154,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -154,7 +170,7 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<!-- Spring Boot Actuator displays build-related information if a META-INF/build-info.properties
<!-- Spring Boot Actuator displays build-related information if a META-INF/build-info.properties
file is present -->
<goals>
<goal>build-info</goal>
Expand Down Expand Up @@ -190,7 +206,7 @@
</executions>
</plugin>

<!-- Spring Boot Actuator displays build-related information if a git.properties
<!-- Spring Boot Actuator displays build-related information if a git.properties
file is present at the classpath -->
<plugin>
<groupId>pl.project13.maven</groupId>
Expand Down
27 changes: 9 additions & 18 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Spring PetClinic Sample Application

This is a fork of https://github.com/spring-projects/spring-petclinic to be used for the DP2 course. The main changes that have been performed were:
This is a fork of https://github.com/spring-projects/spring-petclinic to be used for the DP1 course. The main changes that have been performed were:
- Trimming several parts of the application to keep the example low
- Reorganize some parts of the code according to best practices introduced in the course

Expand All @@ -12,7 +12,7 @@ Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) applicatio


```
git clone https://github.com/gii-is-DP2/spring-petclinic.git
git clone https://github.com/gii-is-DP1/spring-petclinic.git
cd spring-petclinic
./mvnw package
java -jar target/*.jar
Expand All @@ -29,22 +29,13 @@ Or you can run it from Maven directly using the Spring Boot Maven plugin. If you
```

## In case you find a bug/suggested improvement for Spring Petclinic
Our issue tracker is available here: https://github.com/gii-is-DP2/spring-petclinic/issues
Our issue tracker is available here: https://github.com/gii-is-DP1/spring-petclinic/issues


## Database configuration

In its default configuration, Petclinic uses an in-memory database (H2) which
gets populated at startup with data. A similar setup is provided for MySql in case a persistent database configuration is needed.
Note that whenever the database type is changed, the app needs to be run with a different profile: `spring.profiles.active=mysql` for MySql.

You could start MySql locally with whatever installer works for your OS, or with docker:

```
docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8
```

Further documentation is provided [here](https://github.com/gii-is-DP2/spring-petclinic/blob/master/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt).
gets populated at startup with data.

## Working with Petclinic in your IDE

Expand All @@ -63,7 +54,7 @@ The following items should be installed in your system:

1) On the command line
```
git clone https://github.com/gii-is-DP2/spring-petclinic.git
git clone https://github.com/gii-is-DP1/spring-petclinic.git
```
2) Inside Eclipse or STS
```
Expand Down Expand Up @@ -92,9 +83,9 @@ Visit [http://localhost:8080](http://localhost:8080) in your browser.

|Spring Boot Configuration | Class or Java property files |
|--------------------------|---|
|The Main Class | [PetClinicApplication](https://github.com/gii-is-DP2/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) |
|Properties Files | [application.properties](https://github.com/gii-is-DP2/spring-petclinic/blob/master/src/main/resources) |
|Caching | [CacheConfiguration](https://github.com/gii-is-DP2/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) |
|The Main Class | [PetClinicApplication](https://github.com/gii-is-DP1/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) |
|Properties Files | [application.properties](https://github.com/gii-is-DP1/spring-petclinic/blob/master/src/main/resources) |
|Caching | [CacheConfiguration](https://github.com/gii-is-DP1/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) |

## Interesting Spring Petclinic branches and forks

Expand All @@ -106,7 +97,7 @@ that could be used to implement the Pet Clinic then please join the community th

# Contributing

The [issue tracker](https://github.com/gii-is-DP2/spring-petclinic/issues) is the preferred channel for bug reports, features requests and submitting pull requests.
The [issue tracker](https://github.com/gii-is-DP1/spring-petclinic/issues) is the preferred channel for bug reports, features requests and submitting pull requests.

For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at <https://editorconfig.org>. If you have not previously done so, please fill out and submit the [Contributor License Agreement](https://cla.pivotal.io/sign/spring).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.springframework.samples.petclinic;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.springframework.samples.petclinic.configuration;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Converter;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.samples.petclinic.model.BaseEntity;
import org.springframework.stereotype.Component;

@Component()
public final class GenericIdToEntityConverter implements ConditionalGenericConverter {
private static final Logger log = LoggerFactory.getLogger(GenericIdToEntityConverter.class);

private final ConversionService conversionService=new DefaultConversionService();

@Autowired(required = false)
private EntityManager entityManager;



public Set<ConvertiblePair> getConvertibleTypes() {
Set<ConvertiblePair> result=new HashSet<ConvertiblePair>();
result.add(new ConvertiblePair(Number.class, BaseEntity.class));
result.add(new ConvertiblePair(CharSequence.class, BaseEntity.class));
return result;
}

public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return BaseEntity.class.isAssignableFrom(targetType.getType())
&& this.conversionService.canConvert(sourceType, TypeDescriptor.valueOf(Integer.class));
}

public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null || entityManager==null) {
return null;
}

Integer id = (Integer) this.conversionService.convert(source, sourceType, TypeDescriptor.valueOf(Integer.class));

Object entity = entityManager.find(targetType.getType(), id);
if (entity == null) {
log.info("Did not find an entity with id {} of type {}", id, targetType.getType());
return null;
}

return entity;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/resources/**","/webjars/**","/h2-console/**").permitAll()
.antMatchers(HttpMethod.GET, "/","/oups").permitAll()
.antMatchers("/users/new").permitAll()
.antMatchers("/session/**").permitAll()
.antMatchers("/admin/**").hasAnyAuthority("admin")
.antMatchers("/owners/**").hasAnyAuthority("owner","admin")
.antMatchers("/vets/**").authenticated()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.springframework.samples.petclinic.configuration;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;


public class WebConfig implements WebMvcConfigurer {

@Autowired
GenericIdToEntityConverter idToEntityConverter;

@Override
public void addFormatters(FormatterRegistry registry) {

registry.addConverter(idToEntityConverter);
}

@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
registry.viewResolver(resolver);
}
}

This file was deleted.

This file was deleted.

Loading