This repository has been archived by the owner on Feb 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Model definition #33
Merged
Merged
Model definition #33
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7e9591a
add model definition for users, reviews and media
MariemBaccari ae4df91
add preconditions
MariemBaccari c1d82ac
Add user builder tests
MariemBaccari 43a55c9
fix code climate feedback
MariemBaccari 0877a6c
fix codeclimate threshold
MariemBaccari fcf9ae7
fix codeclimate revert fix
MariemBaccari 53d58fc
Make Media abstract and add String imageUrl attribute to Media
MariemBaccari 22e38d9
Adress Simone's comment by adding a Location class
MariemBaccari 2d89969
Adresses Simone's comments about the user builder and its tests
MariemBaccari 8b153b2
Add Collection class and CollectionType enum
MariemBaccari c13040e
Add untracked files
MariemBaccari 23d4c6c
Remove birthdate attribute from User class
MariemBaccari def6686
remove displayed name attribute from User class
MariemBaccari 0364cd3
Add untracked file
MariemBaccari b8cfec7
fix typo in custom constructor
MariemBaccari a25a809
Adresses Simone's IRL comment about Movie constructor
MariemBaccari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
exclude_patterns: | ||
- "**/test/" | ||
- "**/androidTest/" | ||
- "**test" | ||
- "**test" |
199 changes: 199 additions & 0 deletions
199
app/src/main/java/com/github/sdp/mediato/errorCheck/Preconditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
package com.github.sdp.mediato.errorCheck; | ||
|
||
import static com.github.sdp.mediato.model.Review.MAX_GRADE; | ||
import static com.github.sdp.mediato.model.Review.MIN_GRADE; | ||
import static com.github.sdp.mediato.model.User.LIMIT_LOCATION_SIZE; | ||
|
||
import com.github.sdp.mediato.model.User; | ||
import com.github.sdp.mediato.model.media.Media; | ||
import com.github.sdp.mediato.model.media.MediaType; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Class to check preconditions on attributes | ||
* @TODO Corner cases, dates and email formatting to be discussed and checked | ||
*/ | ||
public class Preconditions { | ||
|
||
/** | ||
* Checks if mandatory user fields are valid | ||
* @param user | ||
*/ | ||
public static void checkUser(User user){ | ||
Preconditions.checkUID(user.getId()); | ||
Preconditions.checkUsername(user.getUsername()); | ||
Preconditions.checkEmail(user.getEmail()); | ||
Preconditions.checkBirthDate(user.getBirthDate()); | ||
Preconditions.checkRegisterDate(user.getRegisterDate()); | ||
Preconditions.checkLocation(user.getLocation()); | ||
} | ||
|
||
/** | ||
* Checks if Media attributes are valid | ||
* @param mediaType | ||
* @param title | ||
* @param summary | ||
*/ | ||
public static void checkMedia(MediaType mediaType, String title, String summary){ | ||
Preconditions.checkTitle(title); | ||
Preconditions.checkSummary(summary); | ||
Objects.requireNonNull(mediaType); | ||
} | ||
|
||
/** | ||
* Checks if Review mandatory attributes are valid | ||
* @param username | ||
* @param media | ||
*/ | ||
public static void checkReview(String username, Media media){ | ||
Preconditions.checkUsername(username); | ||
Preconditions.checkMedia(media); | ||
} | ||
|
||
/** | ||
* Checks if Review attributes are valid when adding the grade | ||
* @param username | ||
* @param media | ||
* @param grade | ||
*/ | ||
public static void checkReview(String username, Media media, int grade){ | ||
Preconditions.checkReview(username, media); | ||
Preconditions.checkGrade(grade); | ||
} | ||
|
||
/** | ||
* Checks if Review attributes are valid when adding the grade and a comment | ||
* @param username | ||
* @param media | ||
* @param grade | ||
* @param comment | ||
*/ | ||
public static void checkReview(String username, Media media, int grade, String comment){ | ||
Preconditions.checkReview(username, media, grade); | ||
Preconditions.checkComment(comment); | ||
} | ||
|
||
/** | ||
* Checks if the user id is valid | ||
* @param uId the user id | ||
* @TODO determine conditions for user id validity | ||
*/ | ||
public static void checkUID(String uId){ | ||
checkNullOrEmptyString(uId, "user Id"); | ||
} | ||
|
||
/** | ||
* Checks if username is valid | ||
* @param username | ||
* @TODO determine condition for username validity (formatting, uniqueness...) | ||
*/ | ||
public static void checkUsername(String username){ | ||
checkNullOrEmptyString(username, "username"); | ||
} | ||
|
||
/** | ||
* Checks if displayed name is valid | ||
* @param displayedName | ||
* @TODO determine condition for displayed name validity (formatting, uniqueness...) | ||
*/ | ||
public static void checkDisplayedName(String displayedName){ | ||
checkNullOrEmptyString(displayedName, "displayed name"); | ||
} | ||
|
||
/** | ||
* Checks if email address is valid | ||
* @param email | ||
* @TODO determine - if necessary - condition for email validity (format, existence using google auth) | ||
*/ | ||
public static void checkEmail(String email){ | ||
checkNullOrEmptyString(email, "email"); | ||
} | ||
|
||
/** | ||
* Checks if birth date is valid | ||
* @param birthDate | ||
* @TODO determine birth date validity (format, date) | ||
*/ | ||
public static void checkBirthDate(String birthDate){ | ||
checkNullOrEmptyString(birthDate, "birth date"); | ||
} | ||
|
||
/** | ||
* Checks if register date is valid | ||
* @param registerDate | ||
* @TODO determine register date validity (format, date) | ||
*/ | ||
public static void checkRegisterDate(String registerDate){ | ||
checkNullOrEmptyString(registerDate, "register date"); | ||
} | ||
|
||
/** | ||
* Checks if the location is valid | ||
* @param location | ||
*/ | ||
public static void checkLocation(List<Double> location) { | ||
if (location == null || location.isEmpty()) throw new IllegalArgumentException("Location is unknown: list is null or empty"); | ||
if (location.size() != LIMIT_LOCATION_SIZE) throw new IllegalArgumentException("Location should contain exactly two doubles"); | ||
} | ||
|
||
/** | ||
* Checks if media is not null | ||
* @param media | ||
*/ | ||
public static void checkMedia(Media media){ | ||
if (media == null) { | ||
throw new IllegalArgumentException("Media must not be null"); | ||
} | ||
} | ||
|
||
/** | ||
* Checks if grade is within bounds | ||
* @param grade | ||
*/ | ||
public static void checkGrade(int grade){ | ||
if ((grade > MAX_GRADE) || (grade < MIN_GRADE)) { | ||
throw new IllegalArgumentException("Grade must be between " + MIN_GRADE + " and " + MAX_GRADE); | ||
} | ||
} | ||
|
||
/** | ||
* Checks if comment is valid | ||
* @param comment | ||
* @TODO determine remaining criteria: char limit etc... | ||
*/ | ||
public static void checkComment(String comment){ | ||
checkNullOrEmptyString(comment, "comment"); | ||
} | ||
|
||
/** | ||
* Checks if title is valid | ||
* @param title | ||
* @TODO determine - if necessary - other criteria for title validity | ||
*/ | ||
public static void checkTitle(String title){ | ||
checkNullOrEmptyString(title, "title"); | ||
} | ||
|
||
/** | ||
* Checks if summary is valid | ||
* @param summary | ||
* @TODO determine remaining criteria: char limit etc... | ||
*/ | ||
public static void checkSummary(String summary){ | ||
checkNullOrEmptyString(summary, "summary"); | ||
} | ||
|
||
/** | ||
* Checks if a string is null or empty | ||
* @param string to be checked | ||
* @param variable corresponding to string | ||
* @throws IllegalArgumentException indicating that the @param variable cannot not be null or empty | ||
*/ | ||
public static void checkNullOrEmptyString(String string, String variable){ | ||
if (string == null || string.isEmpty()){ | ||
throw new IllegalArgumentException(variable + "must not be null or empty"); | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
app/src/main/java/com/github/sdp/mediato/model/Review.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.github.sdp.mediato.model; | ||
|
||
import android.provider.MediaStore; | ||
|
||
import com.github.sdp.mediato.errorCheck.Preconditions; | ||
import com.github.sdp.mediato.model.media.Media; | ||
|
||
public class Review { | ||
|
||
public static final int MAX_GRADE = 10; | ||
public static final int MIN_GRADE = 1; | ||
private final String username; | ||
private final Media media; | ||
private int grade; | ||
private String comment; | ||
|
||
public Review(String username, Media media) { | ||
Preconditions.checkReview(username, media); | ||
this.username = username; | ||
this.media = media; | ||
} | ||
|
||
public Review(String username, Media media, int grade) { | ||
Preconditions.checkReview(username, media, grade); | ||
this.username = username; | ||
this.media = media; | ||
this.grade = grade; | ||
} | ||
|
||
public Review(String username, Media media, int grade, String comment) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 2 locations. Consider refactoring. |
||
Preconditions.checkReview(username, media, grade, comment); | ||
this.username = username; | ||
this.media = media; | ||
this.grade = grade; | ||
this.comment = comment; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
public Media getMedia() { | ||
return media; | ||
} | ||
public int getGrade() throws Exception { | ||
try { | ||
Preconditions.checkGrade(grade); | ||
return grade; | ||
} | ||
catch (Exception e){ | ||
throw new Exception("This review does not have a grade."); | ||
} | ||
} | ||
public void setGrade(int grade) { | ||
Preconditions.checkGrade(grade); | ||
this.grade = grade; | ||
} | ||
public String getComment() throws Exception { | ||
try { | ||
Preconditions.checkComment(comment); | ||
return comment; | ||
} | ||
catch (Exception e){ | ||
throw new Exception("This review does not have a comment."); | ||
} | ||
} | ||
|
||
public void setComment(String comment) { | ||
Preconditions.checkComment(comment); | ||
this.comment = comment; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.