elveos

elveos Commit Details

Date:2011-05-03 20:02:36 (2 years 16 days ago)
Author:Thomas Guyard
Branch:
Commit:064d414fde3eb095f9abea60659dc71f5a6cf49f
Parents: 1be8f1481c9064982a5983a727140b1088e9163d
Message:Fix the validation of an offer

File differences

main/src/main/java/com/bloatit/data/DaoOffer.java
233233    }
234234
235235    /**
236     * @return the last milestone in the list of milestones.
237     */
238    public DaoMilestone getLastMilestone() {
239        return this.milestones.get(this.milestones.size() - 1);
240    }
241
242    /**
236243     * @return a cloned version of the expirationDate attribute.
237244     */
238245    public Date getExpirationDate() {
...... 
382389        }
383390        return true;
384391    }
385
386392}
main/src/main/java/com/bloatit/model/Milestone.java
164164    }
165165
166166    /**
167     * Validate the milestone after it has been relreased.
167     * Validate the milestone after it has been released.
168168     *
169169     * @return true, if successful
170170     * @throws UnauthorizedPublicAccessException
...... 
172172     */
173173    public boolean validate() throws UnauthorizedPublicAccessException {
174174        tryAccess(new RgtMilestone.State(), Action.WRITE);
175        return getDao().validate(false);
175        if (getDao().validate(false)) {
176            getOffer().notifyMilestoneIsValidated(this);
177            return true;
178        }
179        return false;
176180    }
177181
178182    /**
...... 
187191        if (!getRights().hasAdminUserPrivilege()) {
188192            throw new UnauthorizedOperationException(SpecialCode.ADMIN_ONLY);
189193        }
190        return getDao().validate(true);
194        if (getDao().validate(true)) {
195            getOffer().notifyMilestoneIsValidated(this);
196            return true;
197        }
198        return false;
191199    }
192200
193201    /**
main/src/main/java/com/bloatit/model/Offer.java
126126        return isAllValidated;
127127    }
128128
129    protected void notifyMilestoneIsValidated(final Milestone milestone) {
130        if (!milestone.getOffer().equals(this)) {
131            throw new BadProgrammerException("This offer is not the owner of this milestone.");
132        }
133        if (getDao().hasMilestonesLeft()) {
134            getFeatureImplementation().setMilestoneIsValidated();
135        } else {
136            getFeatureImplementation().setOfferIsValidated();
137        }
138    }
139
129140    // Must be internal call. Make me protected ?
130141    protected boolean shouldValidateCurrentMilestonePart(final Level level) {
131142        final DaoMilestone currentMilestone = findCurrentDaoMilestone();
...... 
223234    public Milestone getCurrentMilestone() {
224235        return Milestone.create(getDao().getCurrentMilestone());
225236    }
237
238    // Public data, no right management.
239    public Milestone getLastMilestone() {
240        return Milestone.create(getDao().getLastMilestone());
241    }
226242
227243    // Public data, no right management.
228244    public boolean hasRelease() {
main/src/main/java/com/bloatit/model/feature/DevelopingState.java
3333        feature.setFeatureStateUnprotected(getState());
3434    }
3535
36    /*
37     * (non-Javadoc)
38     * @see
39     * com.bloatit.model.feature.AbstractFeatureState#eventMilestoneReleased()
40     */
4136    @Override
4237    public AbstractFeatureState eventMilestoneReleased() {
4338        return this;
4439    }
4540
46    /*
47     * (non-Javadoc)
48     * @see
49     * com.bloatit.model.feature.AbstractFeatureState#eventDeveloperCanceled()
50     */
41    @Override
42    public AbstractFeatureState eventMilestoneIsValidated() {
43        return this;
44    }
45
46    @Override
47    public AbstractFeatureState eventOfferIsValidated() {
48        return new FinishedState(feature);
49    }
50
5151    @Override
5252    public AbstractFeatureState eventDeveloperCanceled() {
5353        return new DiscardedState(feature);
5454    }
5555
56    /*
57     * (non-Javadoc)
58     * @see
59     * com.bloatit.model.feature.AbstractFeatureState#eventDevelopmentTimeOut()
60     */
6156    @Override
6257    public AbstractFeatureState eventDevelopmentTimeOut() {
6358        // TODO: make Penality.
main/src/main/java/com/bloatit/model/feature/FeatureImplementation.java
2929import com.bloatit.data.DaoOffer;
3030import com.bloatit.data.DaoTeamRight.UserTeamRight;
3131import com.bloatit.data.exceptions.NotEnoughMoneyException;
32import com.bloatit.framework.exceptions.highlevel.BadProgrammerException;
3233import com.bloatit.framework.exceptions.lowlevel.UnauthorizedOperationException;
3334import com.bloatit.framework.exceptions.lowlevel.UnauthorizedOperationException.SpecialCode;
3435import com.bloatit.framework.exceptions.lowlevel.WrongStateException;
...... 
300301        if (getDao().getSelectedOffer() == null || getDao().getSelectedOffer().getAmount().compareTo(getDao().getContribution()) > 0) {
301302            throw new WrongStateException("Cannot be in development state, not enough money.");
302303        }
304        if (getSelectedOffer().isFinished()) {
305            throw new BadProgrammerException("Cannot be in development state and have no milestone left.");
306        }
303307        getDao().setFeatureState(FeatureState.DEVELOPPING);
304308        getSelectedOffer().getCurrentMilestone().setDevelopingUnprotected();
305309        new TaskDevelopmentTimeOut(getId(), getDao().getSelectedOffer().getCurrentMilestone().getExpirationDate());
main/src/main/java/com/bloatit/web/linkable/admin/AdministrationAction.java
1818
1919import java.util.List;
2020
21import com.bloatit.common.Log;
2122import com.bloatit.data.DaoFeature.FeatureState;
2223import com.bloatit.framework.exceptions.lowlevel.UnauthorizedOperationException;
2324import com.bloatit.framework.webprocessor.annotations.ConversionErrorException;
...... 
5253    @ParamConstraint
5354    @Optional
5455    private final DisplayableState stateToSet;
56
57    @RequestParam(name = FEATURE_STATE_CODE, role = Role.POST)
58    @ParamConstraint
59    @Optional
60    private final DisplayableFeatureState featureStateToSet;
5561
5662    @SuppressWarnings("unused")
5763    private final AdministrationActionUrl url;
...... 
6369        contents = url.getContents();
6470        action = url.getAction();
6571        stateToSet = url.getStateToSet();
72        featureStateToSet = url.getFeatureStateToSet();
6673    }
6774
6875    @Override
...... 
100107                        break;
101108                    case SET_FEATURE_IN_DEVELOPMENT:
102109                        final Feature feature = Loaders.fromStr(Feature.class, id);
103                        if (feature.getSelectedOffer() == null || feature.getSelectedOffer().getAmount().compareTo(feature.getContribution()) > 0) {
104                            session.notifyBad("There is no offer or not enough money. So no developement state for id: " + feature.getId() + ".");
105                        } else {
106                            feature.setFeatureState(FeatureState.DEVELOPPING);
110                            switch (featureStateToSet) {
111                                case DEVELOPPING:
112                                    if (feature.getSelectedOffer() == null || feature.getSelectedOffer().getAmount().compareTo(feature.getContribution()) > 0) {
113                                        session.notifyBad("There is no offer or not enough money. So no development state for id: " + feature.getId() + ".");
114                                    } else {
115                                        feature.setFeatureState(FeatureState.DEVELOPPING);
116                                    }
117                                    break;
118                                case DISCARDED:
119                                    feature.setFeatureState(FeatureState.DISCARDED);
120                                    break;
121                                case FINISHED:
122                                    feature.setFeatureState(FeatureState.FINISHED);
123                                    break;
124                                case PENDING:
125                                case PREPARING:
126                                case NO_FILTER:
127                                default:
128                                    Log.web().info("Wrong feature state. Nothing to do.");
129                                    session.notifyBad("Wrong feature state. Nothing to do.");
130                                    break;
107131                        }
108132                        break;
109133                    case VALIDATE_BATCH:
main/src/main/java/com/bloatit/web/linkable/admin/DisplayableFeatureState.java
2525    PENDING(tr("Validate")), //
2626    PREPARING(tr("Pending")), //
2727    DEVELOPPING(tr("Developing")), //
28    INCOME(tr("Income")), //
2928    DISCARDED(tr("Discarded")), //
3029    FINISHED(tr("Finished")), //
3130    ;
main/src/main/java/com/bloatit/web/linkable/admin/FeatureAdminPage.java
2121import java.util.EnumSet;
2222
2323import com.bloatit.data.DaoFeature;
24import com.bloatit.framework.webprocessor.annotations.Optional;
2425import com.bloatit.framework.webprocessor.annotations.ParamContainer;
2526import com.bloatit.framework.webprocessor.annotations.RequestParam;
2627import com.bloatit.framework.webprocessor.components.advanced.HtmlGenericTableModel;
...... 
3839public final class FeatureAdminPage extends KudosableAdminPage<DaoFeature, Feature, FeatureAdminListFactory> {
3940
4041    @RequestParam(role = RequestParam.Role.POST)
42    @Optional("NO_FILTER")
4143    private DisplayableFeatureState filterByState;
4244
4345    @RequestParam(role = RequestParam.Role.POST)
46    @Optional("NO_FILTER")
4447    private DisplayableFilterType filterSelectedOffer;
4548
4649    @RequestParam(role = RequestParam.Role.POST)
50    @Optional("NO_FILTER")
4751    private DisplayableFilterType filterHasOffer;
4852
4953    @RequestParam(role = RequestParam.Role.POST)
54    @Optional("NO_FILTER")
5055    private DisplayableFilterType filterHasContribution;
5156
5257    private final FeatureAdminPageUrl url;
main/src/main/java/com/bloatit/web/linkable/admin/MilestoneAdminPage.java
2626import com.bloatit.framework.exceptions.lowlevel.UnauthorizedOperationException;
2727import com.bloatit.framework.exceptions.lowlevel.UnauthorizedPublicAccessException;
2828import com.bloatit.framework.utils.i18n.DateLocale.FormatStyle;
29import com.bloatit.framework.webprocessor.annotations.Optional;
2930import com.bloatit.framework.webprocessor.annotations.ParamContainer;
3031import com.bloatit.framework.webprocessor.annotations.RequestParam;
3132import com.bloatit.framework.webprocessor.components.HtmlParagraph;
...... 
4950public final class MilestoneAdminPage extends IdentifiablesAdminPage<DaoMilestone, Milestone, MilestoneAdminListFactory> {
5051
5152    @RequestParam(role = RequestParam.Role.POST)
53    @Optional("NOT_SELECTED")
5254    private final DisplayableMilestoneState milestoneState;
5355
5456    private final MilestoneAdminPageUrl url;
main/src/main/java/com/bloatit/web/linkable/bugs/ReportBugPage.java
5858    private final ReportBugPageUrl url;
5959
6060    public ReportBugPage(final ReportBugPageUrl url) {
61        super(url, (url.getOffer() == null ? null : new ReportBugActionUrl(url.getOffer().getCurrentMilestone())));
61        super(url, (computeActionUrl(computeMilestone(url))));
6262        this.url = url;
63        milestone = (url.getOffer() == null ? null:url.getOffer().getCurrentMilestone());
63        milestone = computeMilestone(url);
6464        offer = url.getOffer();
6565    }
6666
67    private static Milestone computeMilestone(final ReportBugPageUrl url) {
68        if (url.getOffer() == null) {
69            return null;
70        }
71        if (url.getOffer().isFinished()) {
72            return url.getOffer().getLastMilestone();
73        }
74        return url.getOffer().getCurrentMilestone();
75    }
76
77    private static ReportBugActionUrl computeActionUrl(final Milestone milestone) {
78        if (milestone == null) {
79            return null;
80        }
81        return new ReportBugActionUrl(milestone);
82    }
83
6784    @Override
6885    protected String createPageTitle() {
6986        return "Report a bug";
main/src/main/java/com/bloatit/web/linkable/features/FeatureSummaryComponent.java
291291        final PlaceHolderElement element = new PlaceHolderElement();
292292
293293        final Offer selectedOffer = feature.getSelectedOffer();
294        final Milestone currentMilestone = selectedOffer.getCurrentMilestone();
294        final Milestone currentMilestone = selectedOffer.isFinished() ? selectedOffer.getLastMilestone() : selectedOffer.getCurrentMilestone();
295295        if (!selectedOffer.hasRelease()) {
296296            final Date releaseDate = currentMilestone.getExpirationDate();
297297
...... 
422422                                                                "<0> will receive {0}% of the amount when the {1} remaining FATAL bugs are resolved.",
423423                                                                fatalSize,
424424                                                                fatalBugsPercent,
425                                                                fatalSize), authorLink)));
425                                                                fatalSize),
426                                                            authorLink)));
426427        }
427428        if (majorSize > 0 && majorBugsPercent > 0) {
428429            details.add(new HtmlParagraph(new HtmlMixedText(trn("<0> will receive {0}% of the amount when the remaining MAJOR bug are resolved.",
429430                                                                "<0> will receive {0}% of the amount when the {1} remaining MAJOR bugs are resolved.",
430431                                                                majorSize,
431432                                                                majorBugsPercent,
432                                                                majorSize), authorLink)));
433                                                                majorSize),
434                                                            authorLink)));
433435        }
434436        if (minorSize > 0 && minorBugsPercent > 0) {
435437            details.add(new HtmlParagraph(new HtmlMixedText(trn("<0> will receive {0}% of the amount when the remaining MINOR bug are resolved.",
436438                                                                "<0> will receive {0}% of the amount when the {1} remaining MINOR bugs are resolved.",
437439                                                                minorSize,
438440                                                                minorBugsPercent,
439                                                                minorSize), authorLink)));
441                                                                minorSize),
442                                                            authorLink)));
440443        }
441444        final HtmlBranch showHideLink = new HtmlSpan().addText(" " + tr("Details"));
442445        element.add(showHideLink);
main/src/test/java/com/bloatit/model/feature/FeatureImplementationTest.java
413413        return feature;
414414    }
415415
416    // public void testFinishedDevelopment() throws NotEnoughMoneyException,
417    // UnauthorizedOperationException {
418    // final Feature feature =
419    // createFeatureAddOffer120AddContribution120BeginDev();
420    //
421    // try {
422    // feature.getSelectedOffer().;
423    // fail();
424    // } catch (final UnauthorizedOperationException e) {
425    // assertEquals(UnauthorizedOperationException.SpecialCode.AUTHENTICATION_NEEDED,
426    // e.getCode());
427    // }
428    //
429    // try {
430    // feature.authenticate(yoAuthToken);
431    // feature.releaseCurrentMilestone();
432    // fail();
433    // } catch (final UnauthorizedOperationException e) {
434    // assertEquals(UnauthorizedOperationException.SpecialCode.NON_DEVELOPER_FINISHED_FEATURE,
435    // e.getCode());
436    // }
437    //
438    // feature.authenticate(tomAuthToken);
439    // feature.releaseCurrentMilestone();
440    //
441    // assertEquals(FeatureState.DEVELOPPING, feature.getFeatureState());
442    // assertEquals(120, feature.getContribution().intValue());
443    // TODO
444    // }
416// public void testFinishedDevelopment() throws NotEnoughMoneyException, UnauthorizedOperationException {
417// final Feature feature = createFeatureAddOffer120AddContribution120BeginDev();
418//
419// try {
420// feature.getSelectedOffer();
421// fail();
422// } catch (final UnauthorizedOperationException e) {
423// assertEquals(UnauthorizedOperationException.SpecialCode.AUTHENTICATION_NEEDED, e.getCode());
424// }
425//
426// try {
427// feature.authenticate(yoAuthToken);
428// feature.releaseCurrentMilestone();
429// fail();
430// } catch (final UnauthorizedOperationException e) {
431// assertEquals(UnauthorizedOperationException.SpecialCode.NON_DEVELOPER_FINISHED_FEATURE, e.getCode());
432// }
433//
434// feature.authenticate(tomAuthToken);
435// feature.releaseCurrentMilestone();
436//
437// assertEquals(FeatureState.DEVELOPPING, feature.getFeatureState());
438// assertEquals(120, feature.getContribution().intValue());
439// }
445440
446441    @Test
447442    public void testOfferWithALotOfMilestone() throws UnauthorizedOperationException, NotEnoughMoneyException {

Archive Download the corresponding diff file