Skip to content

Commit

Permalink
Include Rentals EOModel in eogen configuration. Refactor EOs from the…
Browse files Browse the repository at this point in the history
… Rentals model to use superclass methods where possible. Add ERCoreUserInterface implementation to User entity and use this instead of the newly added AppUser entity. Remove AppUser entity from the Movies model and delete the related migration.
  • Loading branch information
fbarthez committed Nov 15, 2015
1 parent fd065de commit 87b880d
Show file tree
Hide file tree
Showing 24 changed files with 2,111 additions and 441 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-destination Sources -extension java -java -javaTemplate _WonderEntity.java -model Resources/Movies.eomodeld -packagedirs -subclassDestination Sources -subclassJavaTemplate WonderEntity.java -templatedir EOTemplates -verbose -loadModelGroup -define-EOGenericRecord er.extensions.eof.ERXGenericRecord
-destination Sources -extension java -java -javaTemplate _WonderEntity.java -model Resources/Movies.eomodeld -model Resources/Rentals.eomodeld -packagedirs -subclassDestination Sources -subclassJavaTemplate WonderEntity.java -templatedir EOTemplates -verbose -loadModelGroup -define-EOGenericRecord er.extensions.eof.ERXGenericRecord

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
EOModelVersion = "2.1";
adaptorName = JDBC;
entities = (
{
className = "webobjectsexamples.businesslogic.movies.common.AppUser";
name = AppUser;
},
{className = EOGenericRecord; name = Director; },
{
className = "webobjectsexamples.businesslogic.movies.common.Movie";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,13 @@
import java.math.BigDecimal;

import com.webobjects.eocontrol.EOEditingContext;
import com.webobjects.eocontrol.EOGenericRecord;
import com.webobjects.foundation.NSTimestamp;

public class CreditCard extends EOGenericRecord {
private static final long serialVersionUID = 8148546767562117626L;
public class CreditCard extends _CreditCard {

public static final String AuthorizationDateKey = "authorizationDate";
private static final long serialVersionUID = 1L;

public static final String AuthorizationNumKey = "authorizationNum";

public static final String CardNumberKey = "cardNumber";

public static final String CustomerKey = "customer";

public static final String ExpirationDateKey = "expirationDate";

public static final String LimitKey = "limit";

public static final BigDecimal DefaultLimit = new BigDecimal(150);
public static final BigDecimal DefaultLimit = new BigDecimal(150);

public CreditCard() {
super();
Expand All @@ -50,19 +38,4 @@ public void awakeFromInsertion(EOEditingContext editingContext) {
}
}

public NSTimestamp authorizationDate() {
return (NSTimestamp) (storedValueForKey(AuthorizationDateKey));
}

public void setAuthorizationDate(NSTimestamp value) {
takeStoredValueForKey(value, AuthorizationDateKey);
}

public BigDecimal limit() {
return (BigDecimal) (storedValueForKey(LimitKey));
}

public void setLimit(BigDecimal value) {
takeStoredValueForKey(value, LimitKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import java.math.BigDecimal;

import com.webobjects.eocontrol.EOEditingContext;
import com.webobjects.eocontrol.EOEnterpriseObject;
import com.webobjects.eocontrol.EOGenericRecord;
import com.webobjects.eocontrol.EOKeyValueQualifier;
import com.webobjects.eocontrol.EOQualifier;
import com.webobjects.foundation.NSArray;
Expand All @@ -25,30 +23,11 @@
import com.webobjects.foundation.NSTimestamp;
import com.webobjects.foundation.NSValidation;

public class Customer extends EOGenericRecord {
private static final long serialVersionUID = -1996155567059278076L;
public class Customer extends _Customer {

public static final String CityKey = "city";
private static final long serialVersionUID = 1L;

public static final String CreditCardKey = "creditCard";

public static final String FirstNameKey = "firstName";

public static final String LastNameKey = "lastName";

public static final String MemberSinceKey = "memberSince";

public static final String PhoneKey = "phone";

public static final String RentalsKey = "rentals";

public static final String StateKey = "state";

public static final String StreetAddressKey = "streetAddress";

public static final String ZipKey = "zip";

private static final String _DepositAmountKeyPath = "unit.video.rentalTerms.depositAmount";
private static final String _DepositAmountKeyPath = "unit.video.rentalTerms.depositAmount";

public static final BigDecimal DefaultCostRestriction = new BigDecimal(50);

Expand All @@ -57,8 +36,8 @@ public Customer() {
}

@Override
public void awakeFromInsertion(EOEditingContext editingContext) {
super.awakeFromInsertion(editingContext);
public void init(EOEditingContext editingContext) {
super.init(editingContext);
if (memberSince() == null) {
setMemberSince(new NSTimestamp());
}
Expand All @@ -68,10 +47,10 @@ public void awakeFromInsertion(EOEditingContext editingContext) {
public void validateForSave() throws NSValidation.ValidationException {
// calculate deposit
BigDecimal deposit = new BigDecimal(0);
NSArray outRentals = outRentals();
NSArray<Rental> outRentals = outRentals();
int count = outRentals.count();
for (int i = 0; i < count; i++) {
BigDecimal amount = (BigDecimal) (((EOEnterpriseObject) (outRentals.objectAtIndex(i))).valueForKeyPath(_DepositAmountKeyPath));
BigDecimal amount = (BigDecimal) ((outRentals.objectAtIndex(i)).valueForKeyPath(_DepositAmountKeyPath));
if (amount != null) {
deposit = deposit.add(amount);
}
Expand All @@ -85,38 +64,6 @@ public void validateForSave() throws NSValidation.ValidationException {
super.validateForSave();
}

public CreditCard creditCard() {
return (CreditCard) (storedValueForKey(CreditCardKey));
}

public String firstName() {
return (String) (storedValueForKey(FirstNameKey));
}

public void setFirstName(String value) {
takeStoredValueForKey(value, FirstNameKey);
}

public String lastName() {
return (String) (storedValueForKey(LastNameKey));
}

public void setLastName(String value) {
takeStoredValueForKey(value, LastNameKey);
}

public NSTimestamp memberSince() {
return (NSTimestamp) (storedValueForKey(MemberSinceKey));
}

public void setMemberSince(NSTimestamp value) {
takeStoredValueForKey(value, MemberSinceKey);
}

public NSArray rentals() {
return (NSArray) (storedValueForKey(RentalsKey));
}

public BigDecimal costRestriction() {
CreditCard creditCard = creditCard();
return (creditCard != null) ? creditCard.limit() : DefaultCostRestriction;
Expand All @@ -130,14 +77,13 @@ public String fullName() {
return buffer.toString();
}

@SuppressWarnings("unchecked")
public NSArray allFees() {
NSMutableArray<Object> allFees = new NSMutableArray<Object>();
NSArray rentals = rentals();
public NSArray<Fee> allFees() {
NSMutableArray<Fee> allFees = new NSMutableArray<Fee>();
NSArray<Rental> rentals = rentals();
if (rentals != null) {
int count = rentals.count();
for (int i = 0; i < count; i++) {
NSArray fees = ((Rental) (rentals.objectAtIndex(i))).fees();
NSArray<Fee> fees = rentals.objectAtIndex(i).fees();
if (fees != null) {
allFees.addObjectsFromArray(fees);
}
Expand All @@ -150,8 +96,8 @@ public Number numberOfAllFees() {
return Integer.valueOf(allFees().count());
}

public NSArray unpaidFees() {
EOQualifier qualifier = new EOKeyValueQualifier(Fee.DatePaidKey, EOQualifier.QualifierOperatorEqual, NSKeyValueCoding.NullValue);
public NSArray<Fee> unpaidFees() {
EOQualifier qualifier = new EOKeyValueQualifier(Fee.DATE_PAID_KEY, EOQualifier.QualifierOperatorEqual, NSKeyValueCoding.NullValue);
return EOQualifier.filteredArrayWithQualifier(allFees(), qualifier);
}

Expand All @@ -163,16 +109,16 @@ public boolean hasUnpaidFees() {
return (unpaidFees().count() > 0);
}

public NSArray allRentals() {
NSArray rentals = rentals();
return (rentals != null) ? rentals : new NSArray();
public NSArray<Rental> allRentals() {
NSArray<Rental> rentals = rentals();
return (rentals != null) ? rentals : new NSArray<Rental>();
}

public Number numberOfAllRentals() {
return Integer.valueOf(allRentals().count());
}

public NSArray outRentals() {
public NSArray<Rental> outRentals() {
EOQualifier qualifier = new EOKeyValueQualifier(Rental.IsOutKey, EOQualifier.QualifierOperatorEqual, Boolean.TRUE);
return EOQualifier.filteredArrayWithQualifier(allRentals(), qualifier);
}
Expand All @@ -185,7 +131,7 @@ public boolean hasOutRentals() {
return (outRentals().count() > 0);
}

public NSArray overdueRentals() {
public NSArray<Rental> overdueRentals() {
EOQualifier qualifier = new EOKeyValueQualifier(Rental.IsOverdueKey, EOQualifier.QualifierOperatorEqual, Boolean.TRUE);
return EOQualifier.filteredArrayWithQualifier(allRentals(), qualifier);
}
Expand All @@ -211,8 +157,8 @@ public void rentUnit(Unit unit) {
editingContext.insertObject(fee);
editingContext.insertObject(rental);
// manipulate relationships after inserting objects
rental.addObjectToBothSidesOfRelationshipWithKey(unit, Rental.UnitKey);
rental.addObjectToBothSidesOfRelationshipWithKey(fee, Rental.FeesKey);
addObjectToBothSidesOfRelationshipWithKey(rental, RentalsKey);
rental.addObjectToBothSidesOfRelationshipWithKey(unit, Rental.UNIT_KEY);
rental.addObjectToBothSidesOfRelationshipWithKey(fee, Rental.FEES_KEY);
addObjectToBothSidesOfRelationshipWithKey(rental, RENTALS_KEY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,16 @@
import java.math.BigDecimal;

import com.webobjects.eocontrol.EOEditingContext;
import com.webobjects.eocontrol.EOGenericRecord;
import com.webobjects.foundation.NSTimestamp;
import com.webobjects.foundation.NSValidation;

public class Fee extends EOGenericRecord {
private static final long serialVersionUID = -6593943328561415279L;
public class Fee extends _Fee {

private static final long serialVersionUID = 1L;

public static final String AmountKey = "amount";

public static final String DatePaidKey = "datePaid";

public static final String FeeTypeKey = "feeType";

public static final String RentalKey = "rental";

private static final String _CostKeyPath = "rental.unit.video.rentalTerms.cost";

public static final int LateFeeAmountPerDay = 3;
private static final String _CostKeyPath = "rental.unit.video.rentalTerms.cost";

public static final int LateFeeAmountPerDay = 3;

public Fee() {
super();
Expand All @@ -48,8 +40,8 @@ public Fee(NSTimestamp date, EOEditingContext editingContext) {
}

@Override
public void awakeFromInsertion(EOEditingContext editingContext) {
super.awakeFromInsertion(editingContext);
public void init(EOEditingContext editingContext) {
super.init(editingContext);
if (amount() == null) {
setAmount((BigDecimal) (valueForKeyPath(_CostKeyPath)));
}
Expand All @@ -66,36 +58,8 @@ public void validateForDelete() throws NSValidation.ValidationException {
super.validateForDelete();
}

public BigDecimal amount() {
return (BigDecimal) (storedValueForKey(AmountKey));
}

public void setAmount(BigDecimal value) {
takeStoredValueForKey(value, AmountKey);
}

public NSTimestamp datePaid() {
return (NSTimestamp) (storedValueForKey(DatePaidKey));
}

public void setDatePaid(NSTimestamp value) {
takeStoredValueForKey(value, DatePaidKey);
}

public FeeType feeType() {
return (FeeType) (storedValueForKey(FeeTypeKey));
}

public void setFeeType(FeeType value) {
takeStoredValueForKey(value, FeeTypeKey);
}

public Rental rental() {
return (Rental) (storedValueForKey(RentalKey));
}

public void setRental(Rental value) {
takeStoredValueForKey(value, RentalKey);
super.setRental(value);
if (amount() == null) {
setAmount((BigDecimal) (valueForKeyPath(_CostKeyPath)));
}
Expand Down
Loading

0 comments on commit 87b880d

Please sign in to comment.