package adullact.publicrowdfunding.model.local.ressource;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
+import com.google.android.gms.maps.model.LatLng;
import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
import org.joda.time.Duration;
import org.joda.time.Interval;
-import rx.Observable;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
import adullact.publicrowdfunding.model.exception.NoAccountExistsInLocal;
import adullact.publicrowdfunding.model.local.cache.Cache;
import adullact.publicrowdfunding.model.local.cache.CacheSet;
import adullact.publicrowdfunding.model.server.event.CreateEvent;
import adullact.publicrowdfunding.model.server.event.ListerEvent;
import adullact.publicrowdfunding.model.server.request.ListerRequest;
-
-import com.google.android.gms.maps.model.LatLng;
+import rx.Observable;
/**
* @author Ferrand and Nelaupe
this.m_active = false;
}
- public Project(String name, String description, String proposedBy, String requestedFunding, DateTime beginDate, DateTime endDate, LatLng position, int illustration, String email, String website, String phone, boolean validate) {
+ public Project(String name, String description, String proposedBy, String requestedFunding, DateTime endDate, LatLng position, int illustration, String email, String website, String phone, boolean validate) {
this.m_id = null;
this.m_name = name;
this.m_description = description;
this.m_proposedBy = new User().getCache(proposedBy);
this.m_requestedFunding = new BigDecimal(requestedFunding);
this.m_currentFunding = new BigDecimal("0");
- this.m_creationDate = DateTime.now();
- this.m_fundingInterval = new Interval(beginDate, endDate);
+ this.m_creationDate = DateTime.now(DateTimeZone.getDefault());
this.m_fundingIntervals = new ArrayList<FundingInterval>();
+ if(validate) {
+ this.m_fundingInterval = new Interval(DateTime.now(DateTimeZone.getDefault()), endDate);
+ calculatePeriods();
+ }
+ else {
+ this.m_fundingInterval = new Interval(endDate, endDate);
+ }
this.m_position = position;
this.m_validate = validate;
this.m_illustration = illustration;
this.m_email = email;
this.m_website = website;
this.m_phone = phone;
-
- // Now, we calculate 10 periods for graphics
- calculatePeriods();
}
/**
this.m_email = email;
this.m_website = website;
this.m_phone = phone;
-
- // Now, we calculate 10 periods for graphics
- calculatePeriods();
}
int numberOfPeriod = 10;
DateTime startDateTime = m_fundingInterval.getStart();
long numberOfDayBetweenStartAndEnd = m_fundingInterval.toDuration().getStandardDays();
- long dayByPeriod = numberOfDayBetweenStartAndEnd/numberOfPeriod;
- DateTime today = new DateTime();
- for(int i = 0; i < (numberOfPeriod-1); i++){
- if(!startDateTime.isBefore(today)){
- return i;
- } else{
- startDateTime = startDateTime.plusDays((int) dayByPeriod);
+ if(numberOfDayBetweenStartAndEnd >= numberOfPeriod) {
+ long dayByPeriod = numberOfDayBetweenStartAndEnd / numberOfPeriod;
+ DateTime today = new DateTime();
+ for (int i = 0; i < (numberOfPeriod - 1); i++) {
+ if (!startDateTime.isBefore(today)) {
+ return i;
+ } else {
+ startDateTime = startDateTime.plusDays((int) dayByPeriod);
+ }
}
}
DateTime startDateTime = m_fundingInterval.getStart();
DateTime endDateTime = m_fundingInterval.getEnd();
long numberOfDayBetweenStartAndEnd = m_fundingInterval.toDuration().getStandardDays();
- long dayByPeriod = numberOfDayBetweenStartAndEnd/numberOfPeriod;
- for(int i = 0; i < (numberOfPeriod-1); i++){
- m_fundingIntervals.add(new FundingInterval(new Interval(startDateTime, startDateTime.plusDays((int) dayByPeriod))));
- startDateTime = startDateTime.plusDays((int) dayByPeriod);
+ if(numberOfDayBetweenStartAndEnd >= numberOfPeriod) {
+ long dayByPeriod = numberOfDayBetweenStartAndEnd/numberOfPeriod;
+ for(int i = 0; i < (numberOfPeriod-1); i++){
+ m_fundingIntervals.add(new FundingInterval(new Interval(startDateTime, startDateTime.plusDays((int) dayByPeriod))));
+ startDateTime = startDateTime.plusDays((int) dayByPeriod);
+ }
+ m_fundingIntervals.add(new FundingInterval(new Interval(startDateTime, endDateTime)));
}
- m_fundingIntervals.add(new FundingInterval(new Interval(startDateTime, endDateTime)));
}
public String getName() {
public void setValidate(boolean validate) {
m_validate = validate;
+
+ if(validate) {
+ m_fundingInterval = new Interval(DateTime.now(DateTimeZone.getDefault()), m_fundingInterval.getEnd());
+ calculatePeriods();
+ }
+ else {
+ m_fundingInterval = new Interval(m_fundingInterval.getEnd(), m_fundingInterval.getEnd());
+ }
}
* @brief Add value to current funding.
*/
public void finance(final String value, final CreateEvent<Funding> fundingCreateEvent) throws NoAccountExistsInLocal {
- Account account = Account.getOwn();
+ final Account account = Account.getOwn();
final Project _this = this;
account.getUser(new HoldToDo<User>() {
@Override
}
@Override
- public void onCreate(Funding resource) {
+ public void onCreate(final Funding funding) {
m_currentFunding = m_currentFunding.add(new BigDecimal(value));
- fundingCreateEvent.onCreate(resource);
-
+ account.getUser(new HoldToDo<User>() {
+ @Override
+ public void hold(User resource) {
+ resource.getFundedProjects().add(funding);
+ fundingCreateEvent.onCreate(funding);
+ }
+ });
}
@Override
public void errorAuthenticationRequired() {
fundingCreateEvent.errorAuthenticationRequired();
-
}
@Override
public void errorNetwork() {
fundingCreateEvent.errorNetwork();
-
}
@Override
fundingCreateEvent.errorServer();
}
+ @Override
+ public void errorAdministratorRequired() {
+ fundingCreateEvent.errorAdministratorRequired();
+ }
});
}
});
public void errorAuthenticationRequired() {
commentaryCreateEvent.errorAuthenticationRequired();
}
+
+ @Override
+ public void errorAdministratorRequired() {
+ commentaryCreateEvent.errorAdministratorRequired();
+ }
});
}
});