Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #114 from ritosilva/master
Browse files Browse the repository at this point in the history
integrate persistence into the solution of the second part
  • Loading branch information
ruimaranhao authored Mar 30, 2018
2 parents de9a055 + d34dd67 commit e439279
Show file tree
Hide file tree
Showing 102 changed files with 2,238 additions and 1,815 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ infer-out
*.iml
.idea
.DS_Store
fenix-framework.properties
4 changes: 4 additions & 0 deletions activity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>pt.ist</groupId>
<artifactId>ff-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
63 changes: 63 additions & 0 deletions activity/src/main/dml/activity.dml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package pt.ulisboa.tecnico.softeng.activity.domain;

class ActivityProvider {
String name;
String code;
}

relation DomainRootHasActivityProviders {
.pt.ist.fenixframework.DomainRoot playsRole root {
multiplicity 1..1;
}
ActivityProvider playsRole activityProvider {
multiplicity 0..*;
}
}

class Activity {
String name;
String code;
int minAge;
int maxAge;
int capacity;
}

relation ActivityProviderHasActivities {
ActivityProvider playsRole activityProvider {
multiplicity 1..1;
}
Activity playsRole activity {
multiplicity 0..*;
}
}

class ActivityOffer {
LocalDate begin;
LocalDate end;
int capacity;
}

relation ActivityHasActivityOffers {
Activity playsRole activity {
multiplicity 1..1;
}
ActivityOffer playsRole activityOffer {
multiplicity 0..*;
}
}

class Booking {
String reference;
String cancel;
LocalDate cancellationDate;
}

relation ActivityOfferHasBookings {
ActivityOffer playsRole activityOffer {
multiplicity 1..1;
}
Booking playsRole booking {
multiplicity 0..*;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ActivityReservationData {

public ActivityReservationData(ActivityProvider provider, ActivityOffer offer, Booking booking) {
this.reference = booking.getReference();
this.cancellation = booking.getCancellation();
this.cancellation = booking.getCancel();
this.name = provider.getName();
this.code = provider.getCode();
this.begin = offer.getBegin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@

import pt.ulisboa.tecnico.softeng.activity.exception.ActivityException;

public class Activity {
public class Activity extends Activity_Base {
private static final int MIN_AGE = 18;
private static final int MAX_AGE = 100;

private static int counter = 0;

private final String name;
private final String code;
private final int minAge;
private final int maxAge;
private final int capacity;
private final Set<ActivityOffer> offers = new HashSet<>();

public Activity(ActivityProvider provider, String name, int minAge, int maxAge, int capacity) {
checkArguments(provider, name, minAge, maxAge, capacity);

this.code = provider.getCode() + Integer.toString(++Activity.counter);
this.name = name;
this.minAge = minAge;
this.maxAge = maxAge;
this.capacity = capacity;
setCode(provider.getCode() + Integer.toString(++Activity.counter));
setName(name);
setMinAge(minAge);
setMaxAge(maxAge);
setCapacity(capacity);

setActivityProvider(provider);
}

public void delete() {
setActivityProvider(null);

for (ActivityOffer offer : getActivityOfferSet()) {
offer.delete();
}

provider.addActivity(this);
deleteDomainObject();
}

private void checkArguments(ActivityProvider provider, String name, int minAge, int maxAge, int capacity) {
Expand All @@ -47,37 +50,9 @@ private void checkArguments(ActivityProvider provider, String name, int minAge,

}

String getName() {
return this.name;
}

String getCode() {
return this.code;
}

int getMinAge() {
return this.minAge;
}

int getMaxAge() {
return this.maxAge;
}

int getCapacity() {
return this.capacity;
}

int getNumberOfOffers() {
return this.offers.size();
}

void addOffer(ActivityOffer offer) {
this.offers.add(offer);
}

Set<ActivityOffer> getOffers(LocalDate begin, LocalDate end, int age) {
Set<ActivityOffer> result = new HashSet<>();
for (ActivityOffer offer : this.offers) {
for (ActivityOffer offer : getActivityOfferSet()) {
if (matchAge(age) && offer.available(begin, end)) {
result.add(offer);
}
Expand All @@ -86,11 +61,11 @@ Set<ActivityOffer> getOffers(LocalDate begin, LocalDate end, int age) {
}

boolean matchAge(int age) {
return age >= this.minAge && age <= this.maxAge;
return age >= getMinAge() && age <= getMaxAge();
}

public Booking getBooking(String reference) {
for (ActivityOffer offer : this.offers) {
for (ActivityOffer offer : getActivityOfferSet()) {
Booking booking = offer.getBooking(reference);
if (booking != null) {
return booking;
Expand All @@ -99,8 +74,4 @@ public Booking getBooking(String reference) {
return null;
}

public Set<ActivityOffer> getOffers() {
return this.offers;
}

}
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
package pt.ulisboa.tecnico.softeng.activity.domain;

import java.util.HashSet;
import java.util.Set;

import org.joda.time.LocalDate;

import pt.ulisboa.tecnico.softeng.activity.exception.ActivityException;

public class ActivityOffer {
private final LocalDate begin;
private final LocalDate end;
private final int capacity;
public class ActivityOffer extends ActivityOffer_Base {

private final int amount;
private final Set<Booking> bookings = new HashSet<>();

public ActivityOffer(Activity activity, LocalDate begin, LocalDate end, int amount) {
checkArguments(activity, begin, end, amount);

this.begin = begin;
this.end = end;
this.capacity = activity.getCapacity();
setBegin(begin);
setEnd(end);
setCapacity(activity.getCapacity());

this.amount = amount;

activity.addOffer(this);
setActivity(activity);
}

public void delete() {
setActivity(null);

for (Booking booking : getBookingSet()) {
booking.delete();
}

deleteDomainObject();
}

private void checkArguments(Activity activity, LocalDate begin, LocalDate end, int amount) {
Expand All @@ -39,35 +44,18 @@ private void checkArguments(Activity activity, LocalDate begin, LocalDate end, i
}
}

public LocalDate getBegin() {
return this.begin;
}

public LocalDate getEnd() {
return this.end;
}

public int getPrice() {
return this.amount;
}

int getNumberOfBookings() {
int getNumberActiveOfBookings() {
int count = 0;
for (Booking booking : this.bookings) {
for (Booking booking : getBookingSet()) {
if (!booking.isCancelled()) {
count++;
}
}
return count;
}

void addBooking(Booking booking) {
if (this.capacity == getNumberOfBookings()) {
throw new ActivityException();
}

this.bookings.add(booking);

public int getPrice() {
return this.amount;
}

boolean available(LocalDate begin, LocalDate end) {
Expand All @@ -83,13 +71,13 @@ boolean matchDate(LocalDate begin, LocalDate end) {
}

boolean hasVacancy() {
return this.capacity > getNumberOfBookings();
return getCapacity() > getNumberActiveOfBookings();
}

public Booking getBooking(String reference) {
for (Booking booking : this.bookings) {
for (Booking booking : getBookingSet()) {
if (booking.getReference().equals(reference)
|| (booking.isCancelled() && booking.getCancellation().equals(reference))) {
|| booking.isCancelled() && booking.getCancel().equals(reference)) {
return booking;
}
}
Expand Down
Loading

0 comments on commit e439279

Please sign in to comment.