Skip to content

Commit

Permalink
Merge pull request #152 from drustanyjt/drus-remove-ab-files
Browse files Browse the repository at this point in the history
Prevent malicious manual updating of save file
  • Loading branch information
drustanyjt authored Apr 4, 2024
2 parents d3482fd + ae1a2b5 commit b18f11a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/LogsCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class LogsCenter {
private static final int MAX_FILE_COUNT = 5;
private static final int MAX_FILE_SIZE_IN_BYTES = (int) (Math.pow(2, 20) * 5); // 5MB
private static final String LOG_FILE = "addressbook.log";
private static final String LOG_FILE = "clinicmate.log";
private static final Logger logger; // logger for this class
private static Logger baseLogger; // to be used as the parent of all other loggers created by this class.
private static Level currentLogLevel = Level.INFO;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public static String format(Person person) {
.append("; Sex: ")
.append(person.getSex())
.append("; Note: ")
.append(person.getNote())
.append("; Tags: ");
person.getTags().forEach(builder::append);
.append(person.getNote());
return builder.toString();
}

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public Person(Name name, Phone phone, Email email, IdentityCardNumber identityCa
this.sex = sex;
this.address = address;
this.note = note;
this.tags.addAll(tags);
}

public Name getName() {
Expand Down Expand Up @@ -123,14 +122,13 @@ public boolean equals(Object other) {
&& age.equals(otherPerson.age)
&& sex.equals(otherPerson.sex)
&& address.equals(otherPerson.address)
&& note.equals(otherPerson.note)
&& tags.equals(otherPerson.tags);
&& note.equals(otherPerson.note);
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, phone, email, identityCardNumber, age, sex, address, note, tags);
return Objects.hash(name, phone, email, identityCardNumber, age, sex, address, note);
}

@Override
Expand All @@ -144,7 +142,6 @@ public String toString() {
.add("sex", sex)
.add("address", address)
.add("note", note)
.add("tags", tags)
.toString();
}

Expand Down
21 changes: 2 additions & 19 deletions src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package seedu.address.storage;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -36,8 +33,6 @@ class JsonAdaptedPerson {
private final String sex;
private final String address;
private final String note;
private final List<JsonAdaptedTag> tags = new ArrayList<>();

/**
* Constructs a {@code JsonAdaptedPerson} with the given person details.
*/
Expand All @@ -48,8 +43,7 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone
@JsonProperty("age") Integer age,
@JsonProperty("sex") String sex,
@JsonProperty("address") String address,
@JsonProperty("note") String note,
@JsonProperty("tags") List<JsonAdaptedTag> tags) {
@JsonProperty("note") String note) {
this.name = name;
this.phone = phone;
this.email = email;
Expand All @@ -58,9 +52,6 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone
this.sex = sex;
this.address = address;
this.note = note;
if (tags != null) {
this.tags.addAll(tags);
}
}

/**
Expand All @@ -75,9 +66,6 @@ public JsonAdaptedPerson(Person source) {
sex = source.getSex().value;
address = source.getAddress().value;
note = source.getNote().value;
tags.addAll(source.getTags().stream()
.map(JsonAdaptedTag::new)
.collect(Collectors.toList()));
}

/**
Expand All @@ -86,11 +74,6 @@ public JsonAdaptedPerson(Person source) {
* @throws IllegalValueException if there were any data constraints violated in the adapted person.
*/
public Person toModelType() throws IllegalValueException {
final List<Tag> personTags = new ArrayList<>();
for (JsonAdaptedTag tag : tags) {
personTags.add(tag.toModelType());
}

if (name == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()));
}
Expand Down Expand Up @@ -157,7 +140,7 @@ public Person toModelType() throws IllegalValueException {
}
final Note modelNote = new Note(note);

final Set<Tag> modelTags = new HashSet<>(personTags);
final Set<Tag> modelTags = new HashSet<>();
return new Person(modelName, modelPhone, modelEmail, modelIdentityCardNumber, modelAge, modelSex, modelAddress,
modelNote, modelTags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
/**
* An Immutable AddressBook that is serializable to JSON format.
*/
@JsonRootName(value = "addressbook")
@JsonRootName(value = "clinicmate")
class JsonSerializableAddressBook {

public static final String MESSAGE_DUPLICATE_PERSON = "Persons list contains duplicate person(s).";

public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";

public static final String MESSAGE_MISSING_FIELD = "Person's %s field is missing!";

public static final String MESSAGE_EMPTY_FIELD = "Person's %s field is empty!";

private final List<JsonAdaptedPerson> persons = new ArrayList<>();

/**
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package seedu.address.ui;

import java.util.Comparator;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
Expand Down Expand Up @@ -97,11 +95,7 @@ public PersonCard(Person person, int displayedIndex) {
ic.setText(person.getIdentityCardNumber().value);
age.setText(String.valueOf(person.getAge().value));
sex.setText(person.getSex().value);

StringBuilder truncatedAddress = new StringBuilder();
address.setText(truncatedAddress.append("Address: ").append(person.getAddress().value).toString());
person.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
}
}
10 changes: 1 addition & 9 deletions src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ public void equals() {
// different address -> returns false
editedAlice = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).build();
assertFalse(ALICE.equals(editedAlice));

// different tags -> returns false
editedAlice = new PersonBuilder(ALICE).withTags(VALID_TAG_HUSBAND).build();
assertFalse(ALICE.equals(editedAlice));
}

@Test
Expand Down Expand Up @@ -117,10 +113,6 @@ public void hash() {
Person editedAlice4 = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).build();
assertNotEquals(ALICE.hashCode(), editedAlice4.hashCode());

// different tags -> returns false
Person editedAlice5 = new PersonBuilder(ALICE).withTags(VALID_TAG_HUSBAND).build();
assertNotEquals(ALICE.hashCode(), editedAlice5.hashCode());

// different person -> returns false
assertNotEquals(ALICE.hashCode(), BOB.hashCode());
}
Expand All @@ -130,7 +122,7 @@ public void toStringMethod() {
String expected = Person.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone()
+ ", email=" + ALICE.getEmail() + ", identityCardNumber=" + ALICE.getIdentityCardNumber()
+ ", age=" + ALICE.getAge() + ", sex=" + ALICE.getSex() + ", address=" + ALICE.getAddress()
+ ", note=" + ALICE.getNote() + ", tags=" + ALICE.getTags() + "}";
+ ", note=" + ALICE.getNote() + "}";
assertEquals(expected, ALICE.toString());
}
}
49 changes: 15 additions & 34 deletions src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.BENSON;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.jupiter.api.Test;

import seedu.address.commons.exceptions.IllegalValueException;
Expand All @@ -29,7 +25,6 @@ public class JsonAdaptedPersonTest {
private static final Integer INVALID_AGE = -12;
private static final String INVALID_SEX = "G";
private static final String INVALID_ADDRESS = " ";
private static final String INVALID_TAG = "#friend";

private static final String VALID_NAME = BENSON.getName().toString();
private static final String VALID_PHONE = BENSON.getPhone().toString();
Expand All @@ -39,9 +34,6 @@ public class JsonAdaptedPersonTest {
private static final String VALID_SEX = BENSON.getSex().value;
private static final String VALID_ADDRESS = BENSON.getAddress().toString();
private static final String VALID_NOTE = BENSON.getNote().toString();
private static final List<JsonAdaptedTag> VALID_TAGS = BENSON.getTags().stream()
.map(JsonAdaptedTag::new)
.collect(Collectors.toList());

@Test
public void toModelType_validPersonDetails_returnsPerson() throws Exception {
Expand All @@ -53,15 +45,15 @@ public void toModelType_validPersonDetails_returnsPerson() throws Exception {
public void toModelType_invalidName_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_IDENTITY_CARD_NUMBER, VALID_AGE,
VALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = Name.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullName_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(null, VALID_PHONE, VALID_EMAIL, VALID_IDENTITY_CARD_NUMBER,
VALID_AGE, VALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_AGE, VALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -70,15 +62,15 @@ public void toModelType_nullName_throwsIllegalValueException() {
public void toModelType_invalidPhone_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_IDENTITY_CARD_NUMBER, VALID_AGE,
VALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = Phone.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullPhone_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_IDENTITY_CARD_NUMBER,
VALID_AGE, VALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_AGE, VALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -87,15 +79,15 @@ public void toModelType_nullPhone_throwsIllegalValueException() {
public void toModelType_invalidEmail_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_IDENTITY_CARD_NUMBER, VALID_AGE,
VALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = Email.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullEmail_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null,
VALID_IDENTITY_CARD_NUMBER, VALID_AGE, VALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_IDENTITY_CARD_NUMBER, VALID_AGE, VALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -104,31 +96,31 @@ public void toModelType_nullEmail_throwsIllegalValueException() {
public void toModelType_invalidIdentityCardNumber_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_IDENTITY_CARD_NUMBER, VALID_AGE,
VALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = IdentityCardNumber.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullIdentityCardNumber_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null,
VALID_AGE, VALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_AGE, VALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, IdentityCardNumber.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@Test
public void toModelType_invalidAge_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_IDENTITY_CARD_NUMBER, INVALID_AGE,
VALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = Age.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullAge_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL,
VALID_IDENTITY_CARD_NUMBER, null, VALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_IDENTITY_CARD_NUMBER, null, VALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Age.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -137,15 +129,15 @@ public void toModelType_nullAge_throwsIllegalValueException() {
public void toModelType_invalidSex_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_IDENTITY_CARD_NUMBER, VALID_AGE,
INVALID_SEX, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
INVALID_SEX, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = Sex.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullSex_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL,
VALID_IDENTITY_CARD_NUMBER, VALID_AGE, null, VALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_IDENTITY_CARD_NUMBER, VALID_AGE, null, VALID_ADDRESS, VALID_NOTE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Sex.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -154,35 +146,24 @@ public void toModelType_nullSex_throwsIllegalValueException() {
public void toModelType_invalidAddress_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_IDENTITY_CARD_NUMBER, VALID_AGE,
VALID_SEX, INVALID_ADDRESS, VALID_NOTE, VALID_TAGS);
VALID_SEX, INVALID_ADDRESS, VALID_NOTE);
String expectedMessage = Address.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullAddress_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL,
VALID_IDENTITY_CARD_NUMBER, VALID_AGE, VALID_SEX, null, VALID_NOTE, VALID_TAGS);
VALID_IDENTITY_CARD_NUMBER, VALID_AGE, VALID_SEX, null, VALID_NOTE);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullNote_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL,
VALID_IDENTITY_CARD_NUMBER, VALID_AGE, VALID_SEX, VALID_ADDRESS, null, VALID_TAGS);
VALID_IDENTITY_CARD_NUMBER, VALID_AGE, VALID_SEX, VALID_ADDRESS, null);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Note.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_invalidTags_throwsIllegalValueException() {
List<JsonAdaptedTag> invalidTags = new ArrayList<>(VALID_TAGS);
invalidTags.add(new JsonAdaptedTag(INVALID_TAG));
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_IDENTITY_CARD_NUMBER, VALID_AGE,
VALID_SEX, VALID_ADDRESS, VALID_NOTE, invalidTags);
assertThrows(IllegalValueException.class, person::toModelType);
}

}

0 comments on commit b18f11a

Please sign in to comment.