Skip to content

Commit

Permalink
Updated javadoc (thx seb ;* )
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-prudhomme committed Nov 29, 2019
1 parent 5fdb231 commit a310248
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 20 deletions.
12 changes: 8 additions & 4 deletions src/main/java/fr/efrei/pandax/model/core/AbstractDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
import javax.persistence.TypedQuery;
import java.util.ArrayList;

//todo refactor open/close with lambda ?

/**
* Represents an general Database Access Object.
* Can generically read, delete, update, create and get all records of a generic type.
* @param <T> Generic type that will be queried in database. Should be a fr.efrei.pandax.model.business class.
* @param <T> Generic type that will be queried in database. Must implement {@link IDTO}.
*/
public abstract class AbstractDAO<T extends IDTO> {
/**
Expand All @@ -22,7 +20,7 @@ public abstract class AbstractDAO<T extends IDTO> {
private Class<T> managedKlazz;

/**
* FUK U TOMCAT
* DITTO
*/
private EntityManagerFactory emf;
/**
Expand Down Expand Up @@ -106,11 +104,17 @@ public ArrayList<T> getAll() {
return all;
}

/**
* Opens connection to the database
*/
protected void openEntityManager() {
emf = Persistence.createEntityManagerFactory("my_persistence_unit");
em = emf.createEntityManager();
}

/**
* Opens connection to the database
*/
protected void closeEntityManager() {
em.close();
emf.close();
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/fr/efrei/pandax/model/core/CommentDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
import javax.persistence.TypedQuery;
import java.util.List;

/**
* This class serves as an access to database-stored {@link Comment} entities.
*/
@Stateless
public class CommentDAO extends AbstractDAO<Comment> {
public CommentDAO(){
super(Comment.class);
}

/**
* Gets every {@link Comment} of a specific {@link fr.efrei.pandax.model.business.User}, represented by its {@link fr.efrei.pandax.model.business.User#id}.
* @param idUser should be the {@link fr.efrei.pandax.model.business.User#id}
* @return a {@link List} of matching {@link Comment}
*/
public List<Comment> getByUser(int idUser) {
openEntityManager();
TypedQuery<Comment> query = em.createNamedQuery("Comment.findByUser", Comment.class);
Expand All @@ -21,6 +29,11 @@ public List<Comment> getByUser(int idUser) {
return comments;
}

/**
* Gets every {@link Comment} of a specific {@link fr.efrei.pandax.model.business.Media}, represented by its {@link fr.efrei.pandax.model.business.Media#id}.
* @param idMedia should be the {@link fr.efrei.pandax.model.business.Media#id}
* @return a {@link List} of matching {@link Comment}
*/
public List<Comment> getByMedia(int idMedia) {
openEntityManager();
TypedQuery<Comment> query = em.createNamedQuery("Comment.findByMedia", Comment.class);
Expand All @@ -30,6 +43,14 @@ public List<Comment> getByMedia(int idMedia) {
return comments;
}


/**
* Gets every {@link Comment} for specifics {@link fr.efrei.pandax.model.business.Media} and {@link fr.efrei.pandax.model.business.User}
* They are respectively represented by their {@link fr.efrei.pandax.model.business.Media#id} and {@link fr.efrei.pandax.model.business.User#id}.
* @param idMedia should be the {@link fr.efrei.pandax.model.business.Media#id}
* @param idUser should be the {@link fr.efrei.pandax.model.business.User#id}
* @return a {@link List} of matching {@link Comment}
*/
public List<Comment> getByMediaAndUser(int idMedia, int idUser) {
openEntityManager();
TypedQuery<Comment> query = em.createNamedQuery("Comment.findByMediaAndUser", Comment.class);
Expand All @@ -40,6 +61,13 @@ public List<Comment> getByMediaAndUser(int idMedia, int idUser) {
return comments;
}

/**
* Gets a specific comment using every identifier involved with it.
* @param idComment should be the {@link fr.efrei.pandax.model.business.Comment#id}
* @param idMedia should be the {@link fr.efrei.pandax.model.business.Media#id}
* @param idUser should be the {@link fr.efrei.pandax.model.business.User#id}
* @return a specific {@link Comment}
*/
public Comment getByPk(int idComment, int idMedia, int idUser) {
openEntityManager();
TypedQuery<Comment> query = em.createNamedQuery("Comment.findByPk", Comment.class);
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/fr/efrei/pandax/model/core/PossessionDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
import javax.ejb.Stateless;
import javax.persistence.TypedQuery;

/**
* This class serves as an access to database-stored {@link Possession} entities.
*/
@Stateless
public class PossessionDAO extends AbstractDAO<Possession> {
private TypedQuery<Possession> PossessionQuery;

public PossessionDAO(){
super(Possession.class);
}

/**
* Reads the entity corresponding to the provided {@param id1, @param id2} in the database.
* @return the corresponding entity
*/
public Possession readPossession(int idUser, int idMedia){
openEntityManager();
TypedQuery<Possession> query = em.createNamedQuery("Possession.findByUserAndMedia", Possession.class);
Expand All @@ -23,6 +28,11 @@ public Possession readPossession(int idUser, int idMedia){
return x;
}


/**
* Deletes the {@link Possession} corresponding to the provided {@param id1, @param id2} in the database.
* @param possession the {@link Possession} to delete.
*/
public void deletePossession(Possession possession) {
openEntityManager();
em.getTransaction().begin();
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/fr/efrei/pandax/model/core/UserDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@
import javax.persistence.TypedQuery;
import java.util.List;

/**
* This class serves as an access to database-stored {@link User} entities.
*/
@Stateless
public class UserDAO extends AbstractDAO<User> {
public UserDAO() {
super(User.class);
}

/**
* Checks that the entered credentials correspond to an existing {@link User}
* @param login the {@link User#pseudo}
* @param password the {@link User#pwd}
* @return the corresponding {@link User}
*/
public User checkCredentials(String login, String password) {
openEntityManager();
TypedQuery<User> query = em.createNamedQuery("User.checkCred", User.class);
Expand All @@ -23,7 +32,12 @@ public User checkCredentials(String login, String password) {
return x;
}

public List<Media> getAllPossessions(int idUser){
/**
* Obtains all the {@link fr.efrei.pandax.model.business.Possession} of an specific {@link User}.
* @param idUser {@link User#id} of the {@link User}
* @return all correlated {@link Media}
*/
public List<Media> getAllPossessions(int idUser) {
openEntityManager();
TypedQuery<Media> mediaQuery = em.createNamedQuery("Media.findByUser", Media.class);
mediaQuery.setParameter("user", idUser);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/fr/efrei/pandax/resource/CommentResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public Response updateOne(@FormParam("comment")Comment c) {
.build();
}

/**
*
* @param c
* @return
*/
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
Expand Down
40 changes: 39 additions & 1 deletion src/main/java/fr/efrei/pandax/resource/MediaResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public Response getAll(@QueryParam("title")@DefaultValue("")String title,
medias = new MediaDAO().getAll(title, city, resume);
return Response.ok(new GenericEntity<>(medias) {}).build();
}


/**
* Adds a {@link fr.efrei.pandax.model.business.Media} to the database through the request /media/{id}
* @param m : user generated {@link fr.efrei.pandax.model.business.Media}
* @return request for the {@link fr.efrei.pandax.model.business.Media} creation
*/
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
Expand All @@ -53,6 +58,11 @@ public Response createOne(@FormParam("media")Media m) {
.build();
}

/**
* Deletes a {@link fr.efrei.pandax.model.business.Media} from the database through the request /media/{id}
* @param id is the {@link Media#id}
* @return request for the {@link fr.efrei.pandax.model.business.Media} deletion
*/
@DELETE
@Path("/{id}")
@Secured
Expand All @@ -72,6 +82,11 @@ public Response deleteOne(@PathParam("id")int id) {
.build();
}

/**
* Searches for the {@link fr.efrei.pandax.model.business.Media} with the corresponding id
* @param id is the {@link Media#id}
* @return Corresponding {@link fr.efrei.pandax.model.business.Media} item
*/
@GET
@Path("/{id}")
@Secured
Expand All @@ -80,6 +95,11 @@ public Response getOne(@PathParam("id")int id) {
return Response.ok(new MediaDAO().read(id)).build();
}

/**
* Modifies a {@link fr.efrei.pandax.model.business.Media} from the database through the request /media/{id}
* @param m : user generated {@link fr.efrei.pandax.model.business.Media}
* @return request for the {@link fr.efrei.pandax.model.business.Media} modification
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
Expand All @@ -96,6 +116,11 @@ public Response updateOne(@FormParam("media")Media m) {
.build();
}

/**
* Obtains all {@link Comment} for a specific {@link Media}
* @param id is the {@link Media#id}
* @return a list of all relevant {@link Comment}
*/
@GET
@Path("/{id}/comment")
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -104,6 +129,12 @@ public Response getAllComment(@PathParam("id")int id) {
return Response.ok(new GenericEntity<>(comments) {}).build();
}

/**
* Obtains all {@link Comment} for a specific {@link Media} and a specific * @param idMedia is the {@link fr.efrei.pandax.model.business.User#id}
* @param idMedia is the {@link Media#id}
* @param idUser is the {@link fr.efrei.pandax.model.business.User#id}
* @return a list of all relevant {@link Comment}
*/
@GET
@Path("{idMedia}/user/{idUser}/comment")
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -112,6 +143,13 @@ public Response getMediaCommentsForUser(@PathParam("idUser")int idUser, @PathPar
return Response.ok(new GenericEntity<>(comments) {}).build();
}

/**
* Obtains a particuliar comment for this particuliar {@link Media}
* @param idComment is the {@link Comment#id}
* @param idMedia is the {@link Media#id}
* @param idUser is the {@link fr.efrei.pandax.model.business.User#id}
* @return corresponding {@link Comment}
*/
@GET
@Path("{idMedia}/user/{idUser}/comment/{idComment}")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/fr/efrei/pandax/resource/MediaTypeResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public class MediaTypeResource {
@Context
UriInfo uriInfo;

/**
* Returns all the {@link fr.efrei.pandax.model.business.MediaType} in database.
* @return list of all {@link fr.efrei.pandax.model.business.MediaType}
*/
@GET
@Secured
@Produces(APPLICATION_JSON)
Expand All @@ -30,9 +34,14 @@ public Response getAll() {
return Response.ok(new GenericEntity<>(all) { }).build();
}

/**
* Adds a {@link fr.efrei.pandax.model.business.MediaType} to the database through the request /mediatype/id
* @param type : user generated {@link fr.efrei.pandax.model.business.MediaType}
* @return request for the {@link fr.efrei.pandax.model.business.MediaType} creation
*/
@POST
@Consumes(APPLICATION_FORM_URLENCODED)
public Response createOne(@FormParam("mediatype") MediaType type) {
public Response createOne(@FormParam("mediatype")MediaType type) {
type = new MediaTypeDAO().create(type);
return Response
.ok(uriInfo.getBaseUriBuilder()
Expand All @@ -42,6 +51,11 @@ public Response createOne(@FormParam("mediatype") MediaType type) {
.build();
}

/**
* Deletes a {@link fr.efrei.pandax.model.business.MediaType} from the database through the request /mediatype/id
* @param id
* @return request for the {@link fr.efrei.pandax.model.business.MediaType} deletion
*/
@DELETE
@Path("/{id}")
@Produces(APPLICATION_JSON)
Expand All @@ -55,6 +69,11 @@ public Response deleteOne(@PathParam("id")int id) {
.build();
}

/**
* Searches for the {@link fr.efrei.pandax.model.business.MediaType} with the corresponding id
* @param id
* @return Corresponding {@link fr.efrei.pandax.model.business.MediaType} item
*/
@GET
@Path("/{id}")
@Secured
Expand All @@ -65,9 +84,14 @@ public Response getOne(@PathParam("id")int id) {
.build();
}

/**
* Searches for the {@link fr.efrei.pandax.model.business.MediaType} with the corresponding id
* @param type {@link MediaType} to update.
* @return Corresponding {@link fr.efrei.pandax.model.business.MediaType} item
*/
@PUT
@Consumes(APPLICATION_FORM_URLENCODED)
public Response updateOne(@FormParam("mediatype") MediaType type) {
public Response updateOne(@FormParam("mediatype")MediaType type) {
type = new MediaTypeDAO().modify(type);
return Response
.ok(uriInfo.getBaseUriBuilder()
Expand Down
Loading

0 comments on commit a310248

Please sign in to comment.