diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..98b99a551e28559528e090cbfc676dcff9bd7def --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# Eclipse +.classpath +.project +.settings/ + +# Intellij +.idea/ +*.iml +*.iws + +# Mac +.DS_Store + +# Maven +log/ +target/ diff --git a/README.md b/README.md index ca05f34dd8e1f09266bd70008a03a03330ec4f70..4594c6c3325614b57d8a487e460125c59423e4b0 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,6 @@ -# jakarta-jsf-archetype +# jakarta jsf quicksatr archetype +This project is base template to use jakartaEE technology with JakartaFaces (JSF) with PrimeFaces Bootstrap, fontAwesome on WildFly server together with CDI, JPA, Hibernate JPA Model Gen, lombok, SLF4J and others. +And contains seting to generate maven archetype io.github.jez04-cs.jakarta-jsf-quickstart -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.vsb.cz/jez04-vyuka/java2/jakarta-jsf-archetype.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.vsb.cz/jez04-vyuka/java2/jakarta-jsf-archetype/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/create-archetype-and-install.sh b/create-archetype-and-install.sh new file mode 100755 index 0000000000000000000000000000000000000000..85a9384f8cab83726ce534823200ca19e568893f --- /dev/null +++ b/create-archetype-and-install.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +mvn clean archetype:create-from-project + +GENERATED_ARCHETYPE_ROOT=target/generated-sources/archetype + +echo ======Updating archetype ...========================= +echo Inserting deployment plugins into project pom.xml +sed -i "/<\/project>/d" "$GENERATED_ARCHETYPE_ROOT/pom.xml" +cat "partial-archetype-pom.xml" >> "$GENERATED_ARCHETYPE_ROOT/pom.xml" +echo "</project>" >> "$GENERATED_ARCHETYPE_ROOT/pom.xml" +sed -i "s/jakarta-jsf-quickstart-archetype/jakarta-jsf-quickstart/g" "$GENERATED_ARCHETYPE_ROOT/pom.xml" + +echo Updating archetype template pom.xml +sed -i "s/<warName>jakarta-jsf-quickstart<\/warName>/<warName>\${artifactId}<\/warName>/g" "$GENERATED_ARCHETYPE_ROOT/src/main/resources/archetype-resources/pom.xml" +cp src/main/resources/META-INF/maven/archetype-metadata.xml $GENERATED_ARCHETYPE_ROOT/src/main/resources/META-INF/maven/archetype-metadata.xml +echo Rmoving script +rm $GENERATED_ARCHETYPE_ROOT/src/main/resources/archetype-resources/create-archetype-and-install.sh +echo Rmoving partial pom +rm $GENERATED_ARCHETYPE_ROOT/src/main/resources/archetype-resources/partial-archetype-pom.xml +echo Rmoving eclipse project files +rm -R $GENERATED_ARCHETYPE_ROOT/src/main/resources/archetype-resources/.settings +rm $GENERATED_ARCHETYPE_ROOT/src/main/resources/archetype-resources/.classpath +rm $GENERATED_ARCHETYPE_ROOT/src/main/resources/archetype-resources/.project +echo ======Update archetype done.========================= + +cd $GENERATED_ARCHETYPE_ROOT +mvn clean install +cd ../../.. \ No newline at end of file diff --git a/partial-archetype-pom.xml b/partial-archetype-pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..a0560d756d476dabd48eaed6a2c05123b7408a03 --- /dev/null +++ b/partial-archetype-pom.xml @@ -0,0 +1,76 @@ + + <distributionManagement> + <snapshotRepository> + <id>vsb-archetypes-snapshots</id> + <url>https://artifactory.cs.vsb.cz/repository/archetype-snapshots/</url> + </snapshotRepository> + <repository> + <id>vsb-archetypes-releases</id> + <url>https://artifactory.cs.vsb.cz/repository/archetype-releases/</url> + </repository> + </distributionManagement> + + <profiles> + <profile> + <id>release</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>3.10.0</version> + <executions> + <execution> + <id>attach-javadocs</id> + <phase>verify</phase> + <goals> + <goal>jar</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>net.nicoulaj.maven.plugins</groupId> + <artifactId>checksum-maven-plugin</artifactId> + <version>1.11</version> + <executions> + <execution> + <phase>verify</phase> + <goals> + <goal>artifacts</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-gpg-plugin</artifactId> + <version>3.2.6</version> + <executions> + <execution> + <id>sign-artifacts</id> + <phase>deploy</phase> + <goals> + <goal>sign</goal> + </goals> + <configuration> + <keyname>9B4FA2AD277F10F5</keyname> + <passphraseServerId>gpg.passphrase</passphraseServerId> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.sonatype.central</groupId> + <artifactId>central-publishing-maven-plugin</artifactId> + <version>0.5.0</version> + <extensions>true</extensions> + <configuration> + <publishingServerId>central</publishingServerId> + <tokenAuth>true</tokenAuth> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..3b83810b2bb37286799a325d05e93d6b94e9a8da --- /dev/null +++ b/pom.xml @@ -0,0 +1,217 @@ +<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>io.github.jez04-cs</groupId> + <artifactId>jakarta-jsf-quickstart</artifactId> + <version>1.0.0</version> + + <packaging>war</packaging> + + <name>jakarta-jsf-quickstart</name> + <description>This artifact is base template to use + jakartaEE technology with JakartaFaces (JSF), PrimeFaces, Bootstrap, + Font Awesome on WildFly server together with CDI, JPA, Hibernate JPA Model Gen, + lombok, SLF4J and others.</description> + <url>https://gitlab.vsb.cz/jez04-vyuka/java2/jakarta-jsf-quickstart</url> + + <licenses> + <license> + <name>MIT License</name> + <url>https://spdx.org/licenses/MIT.html</url> + </license> + </licenses> + + <developers> + <developer> + <name>David JeĹľek</name> + <email>david.jezek@vsb.cz</email> + <organization>VSB - Technical University of Ostrava</organization> + <organizationUrl>https://www.vsb.cz</organizationUrl> + </developer> + </developers> + + <scm> + <connection> + https://gitlab.vsb.cz/jez04-vyuka/java2/jakarta-jsf-quickstart.git</connection> + <developerConnection> + https://gitlab.vsb.cz/jez04-vyuka/java2/jakarta-jsf-quickstart.git</developerConnection> + <url>https://gitlab.vsb.cz/jez04-vyuka/java2/jakarta-jsf-quickstart.git</url> + </scm> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.release>21</maven.compiler.release> + <JUnit.version>5.11.0</JUnit.version> + <log4j.version>2.23.1</log4j.version> + <lombok.version>1.18.34</lombok.version> + <primefaces.version>14.0.5</primefaces.version> + <font.awesome.version>6.5.2</font.awesome.version> + </properties> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.junit</groupId> + <artifactId>junit-bom</artifactId> + <version>${JUnit.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>org.wildfly.bom</groupId> + <artifactId>wildfly-ee</artifactId> + <version>33.0.2.Final</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <scope>test</scope> + </dependency> + <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>${lombok.version}</version> + <scope>provided</scope> + </dependency> + + <!-- Import the CDI API, we use provided scope as the API is included in + WildFly / JBoss EAP --> + <dependency> + <groupId>jakarta.enterprise</groupId> + <artifactId>jakarta.enterprise.cdi-api</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Import the JPA API, we use provided scope as the API is included in + WildFly / JBoss EAP --> + <dependency> + <groupId>jakarta.persistence</groupId> + <artifactId>jakarta.persistence-api</artifactId> + <scope>provided</scope> + </dependency> + <!-- https://mvnrepository.com/artifact/jakarta.data/jakarta.data-api --> + <dependency> + <groupId>jakarta.data</groupId> + <artifactId>jakarta.data-api</artifactId> + <version>1.0.0</version> + </dependency> + <dependency> + <groupId>jakarta.faces</groupId> + <artifactId>jakarta.faces-api</artifactId> + <scope>provided</scope> + </dependency> + <!-- https://mvnrepository.com/artifact/org.primefaces/primefaces --> + <dependency> + <groupId>org.primefaces</groupId> + <artifactId>primefaces</artifactId> + <version>${primefaces.version}</version> + <classifier>jakarta</classifier> + </dependency> + <!-- https://mvnrepository.com/artifact/org.webjars/font-awesome --> + <dependency> + <groupId>org.webjars</groupId> + <artifactId>font-awesome</artifactId> + <version>${font.awesome.version}</version> + </dependency> + <!-- https://mvnrepository.com/artifact/org.webjars/bootstrap --> + <dependency> + <groupId>org.webjars</groupId> + <artifactId>bootstrap</artifactId> + <version>5.3.3</version> + </dependency> + + <!-- https://mvnrepository.com/artifact/org.omnifaces/omnifaces --> + <dependency> + <groupId>org.omnifaces</groupId> + <artifactId>omnifaces</artifactId> + <version>4.5.1</version> + </dependency> + + <!-- Servlet API --> + <dependency> + <groupId>jakarta.servlet</groupId> + <artifactId>jakarta.servlet-api</artifactId> + <scope>provided</scope> + </dependency> + <!-- Required for e.g. "javax.annotation.PostConstruct" --> + <dependency> + <groupId>jakarta.annotation</groupId> + <artifactId>jakarta.annotation-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.hibernate.orm</groupId> + <artifactId>hibernate-core</artifactId> + </dependency> + <dependency> + <groupId>jakarta.inject</groupId> + <artifactId>jakarta.inject-api</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.13.0</version> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>${lombok.version}</version> + </path> + <path> + <groupId>org.hibernate.orm</groupId> + <artifactId>hibernate-jpamodelgen</artifactId> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>3.5.0</version> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>3.6.0</version> + <configuration> + <sources> + <source>target/generated-sources/annotations</source> + </sources> + </configuration> + <executions> + <execution> + <id>add-source</id> + <phase>process-resources</phase> + <goals> + <goal>add-source</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-war-plugin</artifactId> + <version>3.4.0</version> + <configuration> + <warName>jakarta-jsf-quickstart</warName> + </configuration> + </plugin> + + </plugins> + </build> + +</project> diff --git a/src/main/java/cz/vsb/fei/java/FilterExample.java b/src/main/java/cz/vsb/fei/java/FilterExample.java new file mode 100644 index 0000000000000000000000000000000000000000..48e988173251a0fde1da45349edb6de5853386e7 --- /dev/null +++ b/src/main/java/cz/vsb/fei/java/FilterExample.java @@ -0,0 +1,24 @@ +package cz.vsb.fei.java; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.annotation.WebFilter; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@WebFilter(urlPatterns = {"/hello/*"}) +public class FilterExample implements Filter { + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + log.info("Filter works!!"); + chain.doFilter(request, response); + } + +} diff --git a/src/main/java/cz/vsb/fei/java/ServletExample.java b/src/main/java/cz/vsb/fei/java/ServletExample.java new file mode 100644 index 0000000000000000000000000000000000000000..5595420ffacb6700c3fe774e5dcd0730d9bc6121 --- /dev/null +++ b/src/main/java/cz/vsb/fei/java/ServletExample.java @@ -0,0 +1,28 @@ +package cz.vsb.fei.java; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(urlPatterns = { "/hello/*" }) +public class ServletExample extends HttpServlet { + + private static final long serialVersionUID = -6787199898225083657L; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + try (PrintWriter pw = resp.getWriter()) { + pw.println("<html><body>"); + pw.println("<h1>Hello world from servlet!!</h1>"); + + pw.println("<p>Path info: " + req.getPathInfo() + "</p>"); + pw.println("</body></html>"); + } + } + +} diff --git a/src/main/java/cz/vsb/fei/java/controllers/HelloController.java b/src/main/java/cz/vsb/fei/java/controllers/HelloController.java new file mode 100644 index 0000000000000000000000000000000000000000..0bc23fd345adca752b2df5a07eaa74980ea2f19b --- /dev/null +++ b/src/main/java/cz/vsb/fei/java/controllers/HelloController.java @@ -0,0 +1,13 @@ +package cz.vsb.fei.java.controllers; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Named; + +@Named +@RequestScoped +public class HelloController { + + public String getGreeting() { + return "Hello"; + } +} diff --git a/src/main/java/cz/vsb/fei/java/controllers/PersonController.java b/src/main/java/cz/vsb/fei/java/controllers/PersonController.java new file mode 100644 index 0000000000000000000000000000000000000000..44910a1bef0244caba24a61111d20cbc8a752487 --- /dev/null +++ b/src/main/java/cz/vsb/fei/java/controllers/PersonController.java @@ -0,0 +1,52 @@ +package cz.vsb.fei.java.controllers; + +import java.io.Serializable; +import java.util.List; + +import cz.vsb.fei.java.entities.Person; +import cz.vsb.fei.java.transactionalscripts.PersonTS; +import jakarta.enterprise.context.SessionScoped; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import lombok.Getter; + +@Named +@SessionScoped +public class PersonController implements Serializable { + + private static final long serialVersionUID = -4854945208036369881L; + + @Getter + private Person editedPerson; + + @Inject + private PersonTS personTS; + + public Person save(Person entity) { + return personTS.save(entity); + } + + public List<Person> findAll() { + return personTS.findAll(); + } + + public String edit(Person person) { + editedPerson = person; + return "editPerson"; + } + + public String create() { + editedPerson = new Person(); + return "editPerson"; + } + + public String delete(Person person) { + personTS.delete(person); + return ""; + } + + public String save() { + personTS.save(editedPerson); + return "persons"; + } +} diff --git a/src/main/java/cz/vsb/fei/java/controllers/PersonConverter.java b/src/main/java/cz/vsb/fei/java/controllers/PersonConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..d0b7fa64599c7249338175a96d3e6e5ee4cc06d1 --- /dev/null +++ b/src/main/java/cz/vsb/fei/java/controllers/PersonConverter.java @@ -0,0 +1,48 @@ +package cz.vsb.fei.java.controllers; + +import java.util.Objects; + +import cz.vsb.fei.java.entities.Person; +import cz.vsb.fei.java.transactionalscripts.PersonTS; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.faces.application.FacesMessage; +import jakarta.faces.component.UIComponent; +import jakarta.faces.context.FacesContext; +import jakarta.faces.convert.Converter; +import jakarta.faces.convert.ConverterException; +import jakarta.faces.convert.FacesConverter; +import jakarta.inject.Inject; + +@ApplicationScoped +@FacesConverter(forClass = Person.class, managed = true) +public class PersonConverter implements Converter<Person> { + + public static final String NULL_TEXT = "null"; + + @Inject + private PersonTS personTS; + + @Override + public Person getAsObject(FacesContext context, UIComponent component, String value) { + if (Objects.equals(NULL_TEXT, value)) { + return null; + } + long id; + try { + id = Long.parseLong(value); + } catch (NumberFormatException e) { + throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, + "Cannot convert ID value into object.", "Cannot convert ID value into object.")); + } + return personTS.findById(id); + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Person value) { + if (value == null || value.getId() == null) { + return NULL_TEXT; + } + return value.getId().toString(); + } + +} diff --git a/src/main/java/cz/vsb/fei/java/entities/Person.java b/src/main/java/cz/vsb/fei/java/entities/Person.java new file mode 100644 index 0000000000000000000000000000000000000000..b7156b56ee4eb91c009e78be37acc37e01fd5854 --- /dev/null +++ b/src/main/java/cz/vsb/fei/java/entities/Person.java @@ -0,0 +1,40 @@ +package cz.vsb.fei.java.entities; + +import java.util.List; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@Data +@Entity +@NoArgsConstructor +@EqualsAndHashCode(onlyExplicitlyIncluded = true) +public class Person { + + @Id + @GeneratedValue + @EqualsAndHashCode.Include + private Long id; + private String name; + @OneToMany(mappedBy = Person_.FOLLOW) + private List<Person> followers; + @ManyToOne + private Person follow; + + public Person(String name) { + this(name, null); + } + + public Person(String name, Person follow) { + super(); + this.name = name; + this.follow = follow; + } + +} diff --git a/src/main/java/cz/vsb/fei/java/repositoris/PersonRepository.java b/src/main/java/cz/vsb/fei/java/repositoris/PersonRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..b62a10ad1cce4f15eea1f9ce6214b81039b263f7 --- /dev/null +++ b/src/main/java/cz/vsb/fei/java/repositoris/PersonRepository.java @@ -0,0 +1,48 @@ +package cz.vsb.fei.java.repositoris; + +import java.io.Serializable; +import java.util.List; + +import cz.vsb.fei.java.entities.Person; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import jakarta.transaction.Transactional; + +@ApplicationScoped +public class PersonRepository implements Serializable { + + private static final long serialVersionUID = -220112245841041832L; + + @PersistenceContext + private EntityManager em; + + public Person findById(Long id) { + return em.find(Person.class, id); + } + + @Transactional + public Person save(Person entity) { + if (entity.getId() == null || entity.getId() == 0) { + em.persist(entity); + return entity; + } else { + return em.merge(entity); + } + } + + public List<Person> findAll() { + return em.createQuery("select p from Person p", Person.class).getResultList(); + } + + @Transactional + public void delete(Person entity) { + em.remove(refresh(entity)); + + } + + public Person refresh(Person person) { + Person p = em.find(Person.class, person.getId()); + return p; + } +} diff --git a/src/main/java/cz/vsb/fei/java/transactionalscripts/PersonTS.java b/src/main/java/cz/vsb/fei/java/transactionalscripts/PersonTS.java new file mode 100644 index 0000000000000000000000000000000000000000..4e29d912b1bdc28f106e87089a7a3d72d2d6929a --- /dev/null +++ b/src/main/java/cz/vsb/fei/java/transactionalscripts/PersonTS.java @@ -0,0 +1,52 @@ +package cz.vsb.fei.java.transactionalscripts; + +import java.io.Serializable; +import java.util.List; + +import cz.vsb.fei.java.entities.Person; +import cz.vsb.fei.java.repositoris.PersonRepository; +import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import lombok.extern.slf4j.Slf4j; + +@ApplicationScoped +@Slf4j +public class PersonTS implements Serializable { + + private static final long serialVersionUID = 5431735653459156669L; + @Inject + private PersonRepository personRepository; + + @PostConstruct + public void init() { + Person aa = new Person("aa"); + Person bb = new Person("bb"); + Person cc = new Person("cc", aa); + save(aa); + save(bb); + save(cc); + log.info("Default data initialized"); + } + + public Person save(Person entity) { + return personRepository.save(entity); + } + + public Person findById(Long id) { + return personRepository.findById(id); + } + + public List<Person> findAll() { + return personRepository.findAll(); + } + + public void delete(Person entity) { + personRepository.delete(entity); + } + + public Person refresh(Person person) { + return personRepository.refresh(person); + } + +} diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000000000000000000000000000000000000..8f438974a94937098d0777ba15842814073cf148 --- /dev/null +++ b/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<archetype-descriptor xsi:schemaLocation="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.1.0 https://maven.apache.org/xsd/archetype-catalog-1.1.0.xsd" name="jakarta-jsf-quickstart" + xmlns="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.1.0" + xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"> + <fileSets> + <fileSet filtered="true" packaged="true" encoding="UTF-8"> + <directory>src/main/java</directory> + <includes> + <include>**</include> + </includes> + </fileSet> + <fileSet filtered="true" encoding="UTF-8"> + <directory>src/main/resources</directory> + <excludes> + <exclude>**</exclude> + </excludes> + </fileSet> + <fileSet filtered="true" encoding="UTF-8"> + <directory>src/main/webapp</directory> + <includes> + <include>**</include> + </includes> + </fileSet> + <fileSet encoding="UTF-8"> + <directory>src/main/webapp</directory> + <includes> + <include>**</include> + </includes> + </fileSet> + <fileSet encoding="UTF-8"> + <directory></directory> + <includes> + <include>README.md</include> + <include>.gitignore</include> + </includes> + <excludes> + <exclude>.settings/**</exclude> + <exclude>create-archetype-and-install.sh</exclude> + <exclude>partial-archetype-pom.xml</exclude> + </excludes> + </fileSet> + </fileSets> +</archetype-descriptor> diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000000000000000000000000000000000..2f0d2b958fbc2c38a9a99d48148f2a23dcae2fdf --- /dev/null +++ b/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence version="3.0" + xmlns="https://jakarta.ee/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"> + <persistence-unit name="jakarta-jsf-quickstart"> + <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> + <properties> + <property + name="jakarta.persistence.schema-generation.database.action" + value="drop-and-create" /> + <property name="hibernate.enable_lazy_load_no_trans" + value="true" /> + <property name="hibernate.show_sql" value="true" /> + </properties> + </persistence-unit> +</persistence> diff --git a/src/main/webapp/META-INF/MANIFEST.MF b/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..5e9495128c0376427420c4189993b3851770b702 --- /dev/null +++ b/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/src/main/webapp/WEB-INF/beans.xml b/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000000000000000000000000000000000..b8fd3be17b538df9d2470da363a2cdcc69047f71 --- /dev/null +++ b/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_1.xsd" + version="4.1" bean-discovery-mode="annotated"> + + + +</beans> \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/faces-config.xml b/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000000000000000000000000000000000000..358f46142d080ffb313411992ec8e929dacca9e8 --- /dev/null +++ b/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<!-- This file is not required if you don't need any extra configuration. --> +<faces-config version="4.1" + xmlns="https://jakarta.ee/xml/ns/jakartaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + https://jakarta.ee/xml/ns/jakartaee + https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_4_1.xsd"> + + <!-- This descriptor activates the JSF Servlet --> + + <!-- Write your navigation rules here. You are encouraged to use CDI for + creating @Named managed beans. --> + + <application> + <resource-handler>org.omnifaces.resourcehandler.UnmappedResourceHandler</resource-handler> + </application> + +</faces-config> \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..18c6c83d69c4b195fe7c9f9674a7f63e7a4f7e7a --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app id="WebApp_ID" version="6.0" + xmlns="https://jakarta.ee/xml/ns/jakartaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"> + <display-name>pokus</display-name> + <welcome-file-list> + <welcome-file>index.xhtml</welcome-file> + </welcome-file-list> + <servlet> + <servlet-name>Faces Servlet</servlet-name> + <servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>Faces Servlet</servlet-name> + <url-pattern>*.xhtml</url-pattern> + <url-pattern>/jakarta.faces.resource/*</url-pattern> + </servlet-mapping> + + <context-param> + <param-name>primefaces.THEME</param-name> + <param-value>nova-light</param-value> + </context-param> + +</web-app> diff --git a/src/main/webapp/editPerson.xhtml b/src/main/webapp/editPerson.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..15f10dcbca0e184b947290f27ab3472d76e78ccf --- /dev/null +++ b/src/main/webapp/editPerson.xhtml @@ -0,0 +1,47 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<!-- Use old JSF namespaces to allow content assist in eclipse --> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://xmlns.jcp.org/jsf/html" + xmlns:f="http://xmlns.jcp.org/jsf/core" + xmlns:p="http://primefaces.org/ui" + xmlns:pt="jakarta.faces.passthrough"> +<!-- + xmlns:h="jakarta.faces.html" + xmlns:f="jakarta.faces.core" +--> + +<h:head> + <title>Edit person</title> + <h:outputStylesheet + name="webjars/font-awesome/6.5.2/css/fontawesome.css" /> + <h:outputStylesheet name="webjars/font-awesome/6.5.2/css/solid.css" /> + <h:outputStylesheet name="webjars/font-awesome/6.5.2/css/regular.css" /> + <h:outputStylesheet name="webjars/font-awesome/6.5.2/css/brands.css" /> + <h:outputStylesheet name="webjars/bootstrap/5.3.3/css/bootstrap.css" /> +</h:head> +<body> + <h2> + Edit Person <i class="fa-regular fa-thumbs-up"></i> + </h2> + <h:form> + <h:messages /> + <h:panelGrid columns="2"> + <h:outputText value="Name:" /> + <h:inputText value="#{personController.editedPerson.name}" pt:placeholder="some name" > + <f:validateLength minimum="2" /> + </h:inputText> + <h:outputText value="Follow:" /> + <h:selectOneMenu value="#{personController.editedPerson.follow}"> + <f:selectItem itemLabel="No one" itemValue="#{null}" + noSelectionOption="true" /> + <f:selectItems value="#{personController.findAll()}" var="p" + itemLabel="#{p.name}" itemValue="#{p}" /> + </h:selectOneMenu> + <p:button outcome="persons" value="Cancel" icon="fas fa-xmark" /> + <h:commandButton action="#{personController.save()}" value="Save" styleClass="btn btn-success"/> + </h:panelGrid> + </h:form> + <h:outputScript name="webjars/font-awesome/6.5.2/js/fontawesome.js" /> + <h:outputScript name="webjars/bootstrap/5.3.3/js/bootstrap.min.js" /> +</body> +</html> diff --git a/src/main/webapp/index.xhtml b/src/main/webapp/index.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..928affac00975300dbd96bfdd8deb54a11d21ba7 --- /dev/null +++ b/src/main/webapp/index.xhtml @@ -0,0 +1,20 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<!-- Use old namespaces to allow content assist in eclipse --> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://xmlns.jcp.org/jsf/html" + xmlns:f="http://xmlns.jcp.org/jsf/core"> +<!-- + xmlns:h="jakarta.faces.html" + xmlns:f="jakarta.faces.core" +--> + +<h:head> + <title>Index page</title> +</h:head> +<body> + <h2> + <h:outputText value="#{helloController.greeting}" /> from application javaee-wildfly-archetype + </h2> + <h:link outcome="persons" value="Persosns table"/> +</body> +</html> diff --git a/src/main/webapp/persons.xhtml b/src/main/webapp/persons.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..c3507577b2a1f063da96b18a88b375d339d2b11d --- /dev/null +++ b/src/main/webapp/persons.xhtml @@ -0,0 +1,49 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<!-- Use old namespaces to allow content assist in eclipse --> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://xmlns.jcp.org/jsf/html" + xmlns:f="http://xmlns.jcp.org/jsf/core" + xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> +<!-- + xmlns:h="jakarta.faces.html" + xmlns:f="jakarta.faces.core" + xmlns:ui="jakarta.faces.facelets" +--> + +<h:head> + <title>List Of persons</title> +</h:head> +<body> + <h2>List of Persons</h2> + <h:dataTable value="#{personController.findAll()}" var="p"> + <h:column> + #{p.id} + </h:column> + <h:column> + <f:facet name="header">Name</f:facet> + <h:outputText value="#{p.name}" /> + </h:column> + <h:column> + <f:facet name="header">Follow</f:facet> + <h:outputText value="#{p.follow.name}" /> + </h:column> + <h:column> + <f:facet name="header">Followers</f:facet> + <ui:repeat var="f" value="#{p.followers}" varStatus="iter"> + <h:outputText value="#{f.name}" /> + <h:outputText rendered="#{not iter.last}" value=", " /> + </ui:repeat> + </h:column> + <h:column> + <h:form> + <h:commandButton action="#{personController.edit(p)}" value="Edit" /> + <h:commandButton action="#{personController.delete(p)}" + value="Delete" /> + </h:form> + </h:column> + </h:dataTable> + <h:form> + <h:commandButton action="#{personController.create()}" value="Create" /> + </h:form> +</body> +</html>