Author: fdesbois Date: 2009-12-10 16:18:20 +0000 (Thu, 10 Dec 2009) New Revision: 118 Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactContext.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactContextImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactState.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoardingDone.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoardingExpected.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatDefinitiveRefused.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatRefused.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatUnavailable.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyAccepted.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyLocked.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyRefused.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyUnlocked.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateEnum.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateException.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramAccepted.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramLocked.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramRefused.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramUnlocked.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateStart.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateUnfinished.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/bean/ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/bean/states/ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/bean/states/ContactContextTest.java Removed: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactState.java Modified: trunk/pom.xml trunk/suiviobsmer-business/pom.xml trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerUtils.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceSamplingMock.java trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java trunk/suiviobsmer-ui/src/main/webapp/SamplingPlan.tml trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js Log: - Add state pattern for Contact - Evol #1952, problem with delete on bidirectional relationship --> Ano #1961 Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/pom.xml 2009-12-10 16:18:20 UTC (rev 118) @@ -107,7 +107,7 @@ <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> - <version>1.1.114</version> + <version>1.2.125</version> </dependency> <dependency> <groupId>org.jvnet.hudson.winstone</groupId> Modified: trunk/suiviobsmer-business/pom.xml =================================================================== --- trunk/suiviobsmer-business/pom.xml 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-business/pom.xml 2009-12-10 16:18:20 UTC (rev 118) @@ -104,6 +104,21 @@ <goal>generate</goal> </goals> </execution> + <execution> + <id>generate-statemodel</id> + <phase>generate-test-sources</phase> + <configuration> + <reader>org.nuiton.eugene.StateModelReader</reader> + <fullPackagePath>fr.ifremer.suiviobsmer</fullPackagePath> + <extractedPackages>fr.ifremer.suiviobsmer</extractedPackages> + <includes>**/*.statemodel</includes> + <extraClassPathDirectory>target/classes</extraClassPathDirectory> + </configuration> + <goals> + <goal>zargo2xmi</goal> + <goal>xmi2statemodel</goal> + </goals> + </execution> </executions> </plugin> </plugins> Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerUtils.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerUtils.java 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerUtils.java 2009-12-10 16:18:20 UTC (rev 118) @@ -30,6 +30,7 @@ import java.util.Properties; import java.util.Random; import org.apache.commons.lang.StringUtils; +import org.hibernate.exception.SQLGrammarException; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; @@ -118,6 +119,11 @@ throw new SuiviObsmerException("Fatal topia error when close context", eeee); } } + if (eee instanceof SQLGrammarException) { + if (log.isErrorEnabled()) { + log.error("SQL executed with error : " + ((SQLGrammarException)eee).getSQL()); + } + } throw new SuiviObsmerException(message,eee); } else { throw (SuiviObsmerException)eee; Deleted: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactState.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactState.java 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactState.java 2009-12-10 16:18:20 UTC (rev 118) @@ -1,54 +0,0 @@ -/* - * *##% - * SuiviObsmer Business - * Copyright (C) 2009 Ifremer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * ##%* - */ - -package fr.ifremer.suiviobsmer.bean; - -/** - * ContactState - * - * Created: 3 déc. 2009 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public enum ContactState { - - CONTACT_START("Contact pris"), - BOARDING_EXPECTED("Embarquement prévu"), - BOARDING_DONE("Embarquement réalisé"), - UNAVAILABLE("Indisponible/Injoignable"), - REFUSED("Refus"), - DEFINITIVE_REFUSED("Refus définitif"); - - private String value; - - ContactState(String value) { - this.value = value; - } - - public String getValue() { - return this.value; - } - -} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactContext.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactContext.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactContext.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,117 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang.BooleanUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ContactContext + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public abstract class ContactContext { + + public static final Logger log = LoggerFactory.getLogger(ContactContext.class); + + protected Contact contact; + + protected ContactState currentState; + + protected ContactState nextState; + + public ContactContext(Contact contact) throws ContactStateException { + this.contact = contact; + ContactStateEnum state = init(); + this.currentState = createContactState(state); + this.currentState.entry(this); + if (log.isInfoEnabled()) { + log.info("context init state with : " + this.currentState.getValue()); + } + } + + protected abstract ContactStateEnum init(); + + public Contact getContact() { + return contact; + } + + public void nextState(ContactStateEnum nextStateValue) throws ContactStateException { + this.nextState = createContactState(nextStateValue); + currentState.nextState(this); + } + + public List<String> getAvailableNextStatesAsString() { + List<String> results = new ArrayList<String>(); + for (ContactStateEnum state : getAvailableNextStatesAsEnum()) { + results.add(state.getStringValue()); + } + return results; + } + + public List<ContactStateEnum> getAvailableNextStatesAsEnum() { + return this.currentState.getNextValues(); + } + + public ContactState getCurrentState() { + return this.currentState; + } + + ContactState getNextState() { + return nextState; + } + + void setState(ContactState state) { + if (log.isInfoEnabled()) { + log.info("context change state to : " + state.getValue()); + } + this.currentState = state; + // WARNING, can be dangerous for validation (lose real state ?) + //contact.setState(state.getValue()); + } + + protected static ContactState createContactState(ContactStateEnum stateValue) throws ContactStateException { + try { + return stateValue.getStateClass().newInstance(); + } catch (Exception eee) { + throw new ContactStateException("Impossible de créer l'état : " + stateValue.getStringValue(), eee); + } + } + +// protected static ContactState createContactState(String value) { +// if (value == null) { +// return null; +// } +// if (value.equals(ContactStateStart.VALUE)) { +// return new ContactStateStart(); +// } else if (value.equals(ContactStateBoardingExpected.VALUE)) { +// return new ContactStateBoardingExpected(); +// } else if (value.equals(ContactStateBoardingDone.VALUE)) { +// return new ContactStateBoardingDone(); +// } else if (value.equals(ContactStateBoatUnavailable.VALUE)) { +// return new ContactStateBoatUnavailable(); +// } else if (value.equals(ContactStateBoatRefused.VALUE)) { +// return new ContactStateBoatRefused(); +// } else if (value.equals(ContactStateBoatDefinitiveRefused.VALUE)) { +// return new ContactStateBoatDefinitiveRefused(); +// } else if (value.equals(ContactStateCompanyAccepted.VALUE)) { +// return new ContactStateCompanyAccepted(); +// } else if (value.equals(ContactStateCompanyRefused.VALUE)) { +// return new ContactStateCompanyRefused(); +// } else if (value.equals(ContactStateProgramAccepted.VALUE)) { +// return new ContactStateProgramAccepted(); +// } else if (value.equals(ContactStateProgramRefused.VALUE)) { +// return new ContactStateProgramRefused(); +// } +// return null; +// } +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactContextImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactContextImpl.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactContextImpl.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,46 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import org.apache.commons.lang.BooleanUtils; + +/** + * ContactContextImpl + * + * Created: 10 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactContextImpl extends ContactContext { + + public ContactContextImpl(Contact contact) throws ContactStateException { + super(contact); + } + + // tagValue pour generation du impl par defaut obliatoire sur la StateMachine (ici ContactState) : tagValue.init=state + // return ContactStateEnum.createContactStateEnum(getContact().getState()); + @Override + protected ContactStateEnum init() { + ContactStateEnum result = null; + if (BooleanUtils.isTrue(contact.getValidationProgram())) { + result = ContactStateEnum.PROGRAM_ACCEPTED; + } else if (BooleanUtils.isFalse(contact.getValidationProgram())) { + result = ContactStateEnum.PROGRAM_REFUSED; + } else { + if (BooleanUtils.isTrue(contact.getValidationCompany())) { + result = ContactStateEnum.COMPANY_ACCEPTED; + } else if (BooleanUtils.isFalse(contact.getValidationCompany())) { + result = ContactStateEnum.COMPANY_REFUSED; + } + } + if (result == null) { + return ContactStateEnum.createContactStateEnum(getContact().getState()); + } + return result; + } + +} Copied: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactState.java (from rev 110, trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactState.java) =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactState.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactState.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,151 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import java.util.Arrays; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ContactState + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public abstract class ContactState { + + public static final Logger log = LoggerFactory.getLogger(ContactState.class); + + /** + * Method to override for a non abstract state : get the literal value of the state. + * @return a String corresponding to the value + */ + public ContactStateEnum getValue() { + return null; + } + + /** + * Method to override for an abstract state : get literals values of sons states. + * @return a List of String corresponding of sons states values + */ + public List<ContactStateEnum> getValues() { + return Arrays.asList(getValue()); + } + + /** + * Abstract method : get next transitions of the state. + * The order is important to have transitions numbers. + * @return a List of Class wich extends ContactState + */ + protected abstract List<? extends Class<? extends ContactState>> getTransitions(); + + /** + * Abstract method : get next values of the next states (corresponding to transitions) + * @return a List of all values for next states + */ + public abstract List<ContactStateEnum> getNextValues(); + + /** + * Method to override : Entry action of the state (after being set in context). + * @param context Context to manipulate for entry action + * @throws ContactStateException + */ + protected void entry(ContactContext context) throws ContactStateException { + } + + /** + * Method to override : Exit action of the state. Launch before changing to next state in context. + * @param context Context to manipulate for exit action + * @throws ContactStateException + */ + protected void exit(ContactContext context) throws ContactStateException { + } + + /** + * Method to override : Validation of the transition for the next state. First method launch when + * changing state. + * @param context Context to manipulate for validation + * @param transitionNum Number of the transaction to validate + * @return true if the transition is validate, false either + * @throws ContactStateException + */ + protected boolean validate(ContactContext context, int transitionNum) throws ContactStateException { + return true; + } + + /** + * Method to override : Action of the transition for the next state. Launch after validation. + * @param context Context to manipulate for the action + * @param transitionNum + * @throws ContactStateException + */ + protected void action(ContactContext context, int transitionNum) throws ContactStateException { + } + + /** + * Go to the nextState set in context. An exception will be thrown if the nextState is not an allowed + * state for the current one. Execution of nextState is : + * <pre> + * - Verification of the next state object (allowed for the current one) + * - Validation of the transition to the next state + * - Action of the transition to the next state + * - Exit action of the current state + * - Change state in context + * - Entry action for the nextState (current one in context) + * </pre> + * @param context Context to manipulate to get the next state and used for actions. + * @throws IllegalStateException if nextState is not allowed + * @throws ContactStateException for state actions problems + */ + public void nextState(ContactContext context) throws IllegalStateException, ContactStateException { + ContactState nextState = context.getNextState(); + if (log.isDebugEnabled()) { + log.debug("Verification of next state : " + nextState.getClass().getName()); + } + if (getTransitions() == null) { + throw new IllegalStateException("L'état '" + context.getContact().getState() + "' " + + "est final et ne peut être changé"); + } + int transitionNum = -1; + for (int i = 0; i < getTransitions().size(); i++) { + Class<? extends ContactState> stateClass = getTransitions().get(i); + if (stateClass.isAssignableFrom(nextState.getClass())) { + transitionNum = i; + break; + } + } + if (transitionNum == -1) { + throw new IllegalStateException("Etat '" + nextState.getValue() + "' non autorisé après " + + "'" + this.getValue() + "'"); + } + if (log.isDebugEnabled()) { + log.debug("Validation for next state transition : " + transitionNum); + } + if (validate(context, transitionNum)) { + if (log.isDebugEnabled()) { + log.debug("Action for next state transition : " + transitionNum); + } + action(context, transitionNum); + if (log.isDebugEnabled()) { + log.debug("Exit action of current state : " + this.getValue()); + } + exit(context); + context.setState(nextState); + if (log.isDebugEnabled()) { + log.debug("Entry action for new state : " + nextState.getValue()); + } + nextState.entry(context); + } else { + if (log.isWarnEnabled()) { + log.warn("Erreur de validation lors du changement d'état de " + + "'" + this.getValue() + "' à " + nextState.getValue()); + } + } + } + +} Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactState.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Added: svn:mergeinfo + Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoardingDone.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoardingDone.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoardingDone.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,62 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * ContactStateBoardingDone + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateBoardingDone extends ContactState { + + private static final int TRANSITION_COMPANY_UNLOCKED = 0; + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.BOARDING_DONE; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + + @Override + protected List<? extends Class<? extends ContactState>> getTransitions() { + return Collections.singletonList( + ContactStateCompanyUnlocked.class + ); + } + + @Override + public List<ContactStateEnum> getNextValues() { + List<ContactStateEnum> results = new ArrayList<ContactStateEnum>(); + results.add(ContactStateCompanyUnlocked.ENUM_VALUE); + return results; + } + + @Override + protected void entry(ContactContext context) throws ContactStateException { + Contact contact = context.getContact(); + contact.setState(ENUM_VALUE.getStringValue()); + context.nextState(ContactStateEnum.COMPANY_UNLOCKED); + } + + @Override + protected boolean validate(ContactContext context, int transitionNum) { + Contact contact = context.getContact(); + switch (transitionNum) { + case TRANSITION_COMPANY_UNLOCKED: + return contact.getDataInputDate() != null; + } + return true; + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoardingExpected.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoardingExpected.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoardingExpected.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,57 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * ContactStateBoardingExpected + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateBoardingExpected extends ContactState { + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.BOARDING_EXPECTED; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + + @Override + protected List<? extends Class<? extends ContactState>> getTransitions() { + return Collections.singletonList( + ContactStateBoardingDone.class + ); + } + + @Override + public List<ContactStateEnum> getNextValues() { + List<ContactStateEnum> results = new ArrayList<ContactStateEnum>(); + results.add(ContactStateBoardingDone.ENUM_VALUE); + return results; + } + + @Override + protected void entry(ContactContext context) { + Contact contact = context.getContact(); + contact.setState(ENUM_VALUE.getStringValue()); + } + + @Override + protected boolean validate(ContactContext context, int transitionNumber) throws ContactStateException { + //contact.beginTideDate >= contact.sampleRow.program.periodBegin && + // contact.beginTideDate <= contact.sampleRow.program.periodEnd && contact.endTideDate >= contact.beginTideDate + // && contact.endTideDate <= contact.sampleRow.program.periodEnd && nbObservants != 0 + return true; + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatDefinitiveRefused.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatDefinitiveRefused.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatDefinitiveRefused.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,24 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +/** + * ContactStateDefinitiveRefused + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateBoatDefinitiveRefused extends ContactStateUnfinished { + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.BOAT_DEFINITIVE_REFUSED; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatRefused.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatRefused.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatRefused.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,24 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +/** + * ContactStateRefused + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateBoatRefused extends ContactStateUnfinished { + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.BOAT_REFUSED; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatUnavailable.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatUnavailable.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateBoatUnavailable.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,24 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +/** + * ContactStateUnavailable + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateBoatUnavailable extends ContactStateUnfinished { + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.BOAT_UNAVAILABLE; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyAccepted.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyAccepted.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyAccepted.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,57 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import fr.ifremer.suiviobsmer.entity.SampleRow; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * ContactStateCompanyAccepted + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateCompanyAccepted extends ContactStateCompanyLocked { + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.COMPANY_ACCEPTED; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + + @Override + protected List<? extends Class<? extends ContactState>> getTransitions() { + return Collections.unmodifiableList(Arrays.asList( + ContactStateProgramUnlocked.class, + ContactStateCompanyUnlocked.class + )); + } + + @Override + public List<ContactStateEnum> getNextValues() { + List<ContactStateEnum> results = new ArrayList<ContactStateEnum>(); + results.add(ContactStateProgramUnlocked.ENUM_VALUE); + results.add(ContactStateCompanyUnlocked.ENUM_VALUE); + return results; + } + + @Override + protected void entry(ContactContext context) throws ContactStateException { + Contact contact = context.getContact(); + SampleRow row = contact.getSampleRow(); + contact.setValidationCompany(Boolean.TRUE); + // contact.sampleRow.addTideTime(contact.endTideDate - contact.beginTideDate) + context.nextState(ContactStateEnum.PROGRAM_UNLOCKED); + } + + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyLocked.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyLocked.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyLocked.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,32 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * ContactStateCompanyLocked + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public abstract class ContactStateCompanyLocked extends ContactState { + + public static final List<ContactStateEnum> ENUM_VALUES = Collections.unmodifiableList(Arrays.asList( + ContactStateEnum.COMPANY_ACCEPTED, + ContactStateEnum.COMPANY_REFUSED, + ContactStateEnum.PROGRAM_UNLOCKED + )); + + @Override + public List<ContactStateEnum> getValues() { + return ENUM_VALUES; + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyRefused.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyRefused.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyRefused.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,47 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * ContactStateCompanyRefused + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateCompanyRefused extends ContactStateCompanyLocked { + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.COMPANY_REFUSED; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + + @Override + protected List<? extends Class<? extends ContactState>> getTransitions() { + return Collections.singletonList(ContactStateCompanyUnlocked.class); + } + + @Override + public List<ContactStateEnum> getNextValues() { + List<ContactStateEnum> results = new ArrayList<ContactStateEnum>(); + results.add(ContactStateCompanyUnlocked.ENUM_VALUE); + return results; + } + + @Override + public void entry(ContactContext context) { + Contact contact = context.getContact(); + contact.setValidationCompany(Boolean.FALSE); + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyUnlocked.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyUnlocked.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateCompanyUnlocked.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,47 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * ContactStateCompanyUnlocked + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateCompanyUnlocked extends ContactState { + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.COMPANY_UNLOCKED; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + + @Override + protected List<? extends Class<? extends ContactState>> getTransitions() { + return Collections.singletonList(ContactStateCompanyLocked.class); + } + + @Override + public List<ContactStateEnum> getNextValues() { + List<ContactStateEnum> results = new ArrayList<ContactStateEnum>(); + results.addAll(ContactStateCompanyLocked.ENUM_VALUES); + return results; + } + + @Override + public void entry(ContactContext context) { + Contact contact = context.getContact(); + contact.setValidationCompany(null); + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateEnum.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateEnum.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateEnum.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,95 @@ +/* + * *##% + * SuiviObsmer Business + * Copyright (C) 2009 Ifremer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * ##%* + */ + +package fr.ifremer.suiviobsmer.bean.states; + +/** + * ContactState + * + * Created: 3 déc. 2009 + * + * @author fdesbois + * @version $Revision: 110 $ + * + * Mise a jour: $Date: 2009-12-07 19:42:18 +0100 (lun. 07 déc. 2009) $ + * par : $Author: fdesbois $ + */ +public enum ContactStateEnum { + + PROGRAM_REFUSED("Refusé par le programme", ContactStateProgramRefused.class), + + PROGRAM_ACCEPTED("Accepté par le programme", ContactStateProgramAccepted.class), + + PROGRAM_UNLOCKED("Non accepté par le programme", ContactStateProgramUnlocked.class), + + COMPANY_REFUSED("Refusé par la société", ContactStateCompanyRefused.class), + + COMPANY_ACCEPTED("Accepté par la société", ContactStateCompanyAccepted.class), + + COMPANY_UNLOCKED("Non accepté par la société", ContactStateCompanyUnlocked.class), + + BOAT_UNAVAILABLE("Non abouti", ContactStateBoatUnavailable.class), + + BOAT_REFUSED("Refus", ContactStateBoatRefused.class), + + BOAT_DEFINITIVE_REFUSED("Refus définitif", ContactStateBoatDefinitiveRefused.class), + + BOARDING_DONE("Embarquement réalisé", ContactStateBoardingDone.class), + + BOARDING_EXPECTED("Embarquement prévu", ContactStateBoardingExpected.class), + + CONTACT_START("Contact pris", ContactStateStart.class); + + private String value; + + private Class<? extends ContactState> stateClass; + + ContactStateEnum(String value, Class<? extends ContactState> stateClass) { + this.value = value; + this.stateClass = stateClass; + } + + public String getStringValue() { + return this.value; + } + + public Class<? extends ContactState> getStateClass() { + return this.stateClass; + } + + public static ContactStateEnum createContactStateEnum(String value) { + if (value.equals(CONTACT_START.getStringValue())) { + return CONTACT_START; + } else if (value.equals(BOARDING_EXPECTED.getStringValue())) { + return BOARDING_EXPECTED; + } else if (value.equals(BOARDING_DONE.getStringValue())) { + return BOARDING_DONE; + } else if (value.equals(BOAT_UNAVAILABLE.getStringValue())) { + return BOAT_UNAVAILABLE; + } else if (value.equals(BOAT_REFUSED.getStringValue())) { + return BOAT_REFUSED; + } else if (value.equals(BOAT_DEFINITIVE_REFUSED.getStringValue())) { + return BOAT_DEFINITIVE_REFUSED; + } + return null; + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateException.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateException.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateException.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,24 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +/** + * ContactStateException + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateException extends Exception { + + public ContactStateException(String msg) { + super(msg); + } + + public ContactStateException(String msg, Throwable ex) { + super(msg, ex); + } +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramAccepted.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramAccepted.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramAccepted.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,35 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import fr.ifremer.suiviobsmer.entity.SampleRow; +import java.util.ArrayList; +import java.util.List; + +/** + * ContactStateProgramAccepted + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateProgramAccepted extends ContactStateProgramLocked { + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.PROGRAM_ACCEPTED; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + + @Override + protected void entry(ContactContext context) throws ContactStateException { + Contact contact = context.getContact(); + contact.setValidationProgram(Boolean.TRUE); + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramLocked.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramLocked.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramLocked.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,44 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * ContactStateProgramLocked + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public abstract class ContactStateProgramLocked extends ContactState { + + public static final List<ContactStateEnum> ENUM_VALUES = Collections.unmodifiableList(Arrays.asList( + ContactStateEnum.PROGRAM_ACCEPTED, + ContactStateEnum.PROGRAM_REFUSED + )); + + @Override + public List<ContactStateEnum> getValues() { + return ENUM_VALUES; + } + + @Override + protected List<? extends Class<? extends ContactState>> getTransitions() { + return Collections.singletonList(ContactStateProgramUnlocked.class); + } + + @Override + public List<ContactStateEnum> getNextValues() { + List<ContactStateEnum> results = new ArrayList<ContactStateEnum>(); + results.add(ContactStateProgramUnlocked.ENUM_VALUE); + return results; + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramRefused.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramRefused.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramRefused.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,38 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import fr.ifremer.suiviobsmer.entity.SampleRow; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * ContactStateProgramRefused + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateProgramRefused extends ContactStateProgramLocked { + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.PROGRAM_REFUSED; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + + @Override + protected void entry(ContactContext context) throws ContactStateException { + Contact contact = context.getContact(); + SampleRow row = contact.getSampleRow(); + contact.setValidationProgram(Boolean.FALSE); + // contact.sampleRow.removeTideTime(contact) + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramUnlocked.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramUnlocked.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateProgramUnlocked.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,52 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * ContactStateProgramUnlocked + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateProgramUnlocked extends ContactStateCompanyLocked { + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.PROGRAM_UNLOCKED; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + + @Override + protected List<? extends Class<? extends ContactState>> getTransitions() { + return Collections.unmodifiableList(Arrays.asList( + ContactStateProgramLocked.class, + ContactStateCompanyUnlocked.class + )); + } + + @Override + public List<ContactStateEnum> getNextValues() { + List<ContactStateEnum> results = new ArrayList<ContactStateEnum>(); + results.addAll(ContactStateProgramLocked.ENUM_VALUES); + results.add(ContactStateCompanyUnlocked.ENUM_VALUE); + return results; + } + + @Override + public void entry(ContactContext context) { + Contact contact = context.getContact(); + contact.setValidationProgram(null); + } + +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateStart.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateStart.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateStart.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,82 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.apache.commons.lang.StringUtils; + +/** + * ContactStateStart + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateStart extends ContactState { + + private static final int TRANSITION_UNFINISHED = 0; + + //private static final int TRANSITION_BOARDING_EXPECTED = 1; + + public static final ContactStateEnum ENUM_VALUE = ContactStateEnum.CONTACT_START; + + @Override + public ContactStateEnum getValue() { + return ENUM_VALUE; + } + + @Override + public List<ContactStateEnum> getNextValues() { + List<ContactStateEnum> results = new ArrayList<ContactStateEnum>(); + results.addAll(ContactStateUnfinished.ENUM_VALUES); + results.add(ContactStateBoardingExpected.ENUM_VALUE); + return results; + } + + @Override + protected List<? extends Class<? extends ContactState>> getTransitions() { + return Collections.unmodifiableList(Arrays.asList( + ContactStateUnfinished.class, + ContactStateBoardingExpected.class + )); + } + + @Override + protected void entry(ContactContext context) { + Contact contact = context.getContact(); + contact.setState(ENUM_VALUE.getStringValue()); + } + + @Override + protected boolean validate(ContactContext context, int transitionNum) throws ContactStateException { + Contact contact = context.getContact(); + switch (transitionNum) { + case TRANSITION_UNFINISHED: +// if (StringUtils.isEmpty(contact.getComment())) { +// throw new ContactStateException( +// "Le commentaire du contact ne doit pas être vide pour passer à un état " + +// "'non abouti', 'refus' ou 'refus définitif'"); +// } + return StringUtils.isEmpty(contact.getComment()); + } + return true; + } + + @Override + protected void action(ContactContext context, int transitionNum) throws ContactStateException { + switch (transitionNum) { + case TRANSITION_UNFINISHED: + Contact contact = context.getContact(); + contact.setTideBeginDate(null); + contact.setTideEndDate(null); + contact.setNbObservants(0); + } + } +} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateUnfinished.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateUnfinished.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/states/ContactStateUnfinished.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,53 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * ContactStateUnfinished + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactStateUnfinished extends ContactState { + + public static final List<ContactStateEnum> ENUM_VALUES = Collections.unmodifiableList(Arrays.asList( + ContactStateEnum.BOAT_UNAVAILABLE, + ContactStateEnum.BOAT_REFUSED, + ContactStateEnum.BOAT_DEFINITIVE_REFUSED + )); + + @Override + public List<ContactStateEnum> getValues() { + return ENUM_VALUES; + } + + @Override + protected List<? extends Class<? extends ContactState>> getTransitions() { + return Collections.singletonList(ContactStateCompanyUnlocked.class); + } + + @Override + public List<ContactStateEnum> getNextValues() { + List<ContactStateEnum> results = new ArrayList<ContactStateEnum>(); + results.add(ContactStateCompanyUnlocked.ENUM_VALUE); + return results; + } + + @Override + protected void entry(ContactContext context) throws ContactStateException { + Contact contact = context.getContact(); + contact.setState(getValue().getStringValue()); + context.nextState(ContactStateEnum.COMPANY_UNLOCKED); + } + +} Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java 2009-12-10 16:18:20 UTC (rev 118) @@ -47,6 +47,12 @@ private static final long serialVersionUID = 1L; + /** + * Get a SampleMonth from the month and year paramater. + * @param month the month of the SampleMonth to get + * @param year the year of the SampleMonth to get + * @return the SampleMonth if it exists in the SampleMonth list or null either + */ @Override public SampleMonth getSampleMonth(int month, int year) { if (getSampleMonth() == null) { @@ -60,6 +66,11 @@ return null; } + /** + * Get a SampleMonth from a date. The month and year of the date must correspond to the SampleMonth to get. + * @param date a Date + * @return the SampleMonth if it exists in the SampleMonth list or null either + */ @Override public SampleMonth getSampleMonth(Date date) { if (getSampleMonth() == null) { @@ -75,6 +86,10 @@ return null; } + /** + * Return the first fishingZone of the list linked with the SampleRow. + * @return a FishingZone or null if there is no fishingZone linked with the SampleRow + */ @Override public FishingZone getFirstFishingZone() { if (getFishingZone().size() > 0) { @@ -83,6 +98,12 @@ return null; } + /** + * Check if the sampleRow has an ElligibleBoat corresponding to the boat in argument. + * The test return true only if it's a global ElligbleBoat set by an admin and not by a user (companyActive). + * @param boat Boat to test + * @return true if the ElligibleBoat is find, false either + */ @Override public boolean hasElligibleBoat(Boat boat) { for (ElligibleBoat elligible : this.getElligibleBoat()) { @@ -94,6 +115,12 @@ return false; } + /** + * Check from the list of ElligibleBoat linked with the SampleRow if the boats in argument corresponding. + * The argument means new boats to linked with SampleRow, so an ElligibleBoat not contains in this list is removed. + * @param boats a List of Boats to check with ElligibleBoats linked with the SampleRow. + * @see fr.ifremer.suiviobsmer.impl.ServiceSamplingImpl#createUpdateSampleRow(fr.ifremer.suiviobsmer.entity.SampleRow, java.util.List) + */ @Override public void removeNoLongerElligibleBoats(List<Boat> boats) { Iterator<ElligibleBoat> it = getElligibleBoat().iterator(); @@ -113,6 +140,10 @@ } } + /** + * Used to get a list of boat's immatriculations linked with the sampleRow. + * @return a simple String which contains immatriculations separate by a space + */ @Override public String getMainElligibleBoatsAsString() { String result = ""; @@ -125,16 +156,19 @@ return result; } - /*@Override - public List<FishingZone> getAllFishingZones() { - if (fishingZones == null) { - fishingZones = new ArrayList<FishingZone>(); - for (FishingZoneToSampleRow assoc : getFishingZoneFishingZoneToSampleRow()) { - FishingZone zone = assoc.getFishingZone(); - fishingZones.add(zone); + /** + * Check if SampleMonth of the SampleRow has already realTidesValue set (different from 0). + * It means the SampleRow could'nt be deleted and have some modification constraints. + * @return true if a SampleMonth have realTidesValue, false either + */ + @Override + public boolean hasSampleMonthRealTideTime() { + for (SampleMonth month : getSampleMonth()) { + if (month.getRealTidesValue() != 0) { + return true; } } - return fishingZones; - }*/ + return false; + } } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2009-12-10 16:18:20 UTC (rev 118) @@ -25,7 +25,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import fr.ifremer.suiviobsmer.SuiviObsmerUtils; -import fr.ifremer.suiviobsmer.bean.ContactState; +import fr.ifremer.suiviobsmer.bean.states.ContactStateEnum; import fr.ifremer.suiviobsmer.entity.Boat; import fr.ifremer.suiviobsmer.entity.Company; import fr.ifremer.suiviobsmer.entity.Contact; @@ -110,7 +110,7 @@ result.setUser(user); result.setSampleRow(row); result.setBoat(boat); - result.setState(ContactState.CONTACT_START.getValue()); + result.setState(ContactStateEnum.CONTACT_START.getStringValue()); return result; } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java 2009-12-10 16:18:20 UTC (rev 118) @@ -305,6 +305,25 @@ } @Override + public void deleteSampleRow(SampleRow sampleRow) throws SuiviObsmerException { + TopiaContext transaction = null; + try { + transaction = rootContext.beginTransaction(); + + SampleRowDAO dao = SuiviObsmerModelDAOHelper.getSampleRowDAO(transaction); + + dao.delete(sampleRow); + + transaction.commitTransaction(); + transaction.closeContext(); + } catch (Exception eee) { + SuiviObsmerUtils.serviceException(transaction, + "Impossible de supprimer la ligne d'échantillon : " + sampleRow.getCode(), + eee); + } + } + + @Override public SampleRow getNewSampleRow() { SampleRow row = new SampleRowImpl(); row.setProfession(new ProfessionImpl()); Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceSamplingMock.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceSamplingMock.java 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceSamplingMock.java 2009-12-10 16:18:20 UTC (rev 118) @@ -252,4 +252,9 @@ throw new UnsupportedOperationException("Not supported yet."); } + @Override + public void deleteSampleRow(SampleRow sampleRow) throws SuiviObsmerException { + throw new UnsupportedOperationException("Not supported yet."); + } + } Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo =================================================================== (Binary files differ) Added: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/bean/states/ContactContextTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/bean/states/ContactContextTest.java (rev 0) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/bean/states/ContactContextTest.java 2009-12-10 16:18:20 UTC (rev 118) @@ -0,0 +1,159 @@ + +package fr.ifremer.suiviobsmer.bean.states; + +import fr.ifremer.suiviobsmer.entity.Contact; +import fr.ifremer.suiviobsmer.entity.ContactImpl; +import java.util.Date; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ContactContextTest + * + * Created: 9 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ContactContextTest { + + private static final Logger log = LoggerFactory.getLogger(ContactContextTest.class); + + private ContactContext instance; + + public ContactContextTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() throws ContactStateException { + Contact contact = new ContactImpl(); + contact.setState(ContactStateEnum.CONTACT_START.getStringValue()); + instance = new ContactContextImpl(contact); + } + + @After + public void tearDown() { + } + + /** + * Test of nextState method, of class ContactContext. + */ + @Test + public void testNextState() throws Exception { + log.info("nextState"); + + // CONTACT_START -> BOARDING_EXPECTED + instance.nextState(ContactStateEnum.BOARDING_EXPECTED); + Contact contact = instance.getContact(); + Assert.assertEquals(ContactStateEnum.BOARDING_EXPECTED, instance.currentState.getValue()); + Assert.assertEquals(ContactStateEnum.BOARDING_EXPECTED.getStringValue(), contact.getState()); + + // BOARDING_EXPECTED -> BOARDING_DONE + instance.nextState(ContactStateEnum.BOARDING_DONE); + Assert.assertEquals(ContactStateEnum.BOARDING_DONE, instance.currentState.getValue()); + Assert.assertEquals(ContactStateEnum.BOARDING_DONE.getStringValue(), contact.getState()); + + // BOARDING_DONE -> COMPANY_UNLOCKED + contact.setDataInputDate(new Date()); + instance.nextState(ContactStateEnum.COMPANY_UNLOCKED); + Assert.assertEquals(ContactStateEnum.COMPANY_UNLOCKED, instance.currentState.getValue()); + Assert.assertEquals(ContactStateEnum.BOARDING_DONE.getStringValue(), contact.getState()); + Assert.assertNull(contact.getValidationCompany()); + + // Reinitialize of ContactContext to take other transition from CONTACT_START + contact = new ContactImpl(); + contact.setState(ContactStateEnum.CONTACT_START.getStringValue()); + instance = new ContactContextImpl(contact); + + // CONTACT_START -> BOAT_UNAVAILABLE -> COMPANY_UNLOCKED + contact.setNbObservants(2); + contact.setTideBeginDate(new Date()); + contact.setTideEndDate(new Date()); + instance.nextState(ContactStateEnum.BOAT_UNAVAILABLE); + Assert.assertEquals(ContactStateEnum.COMPANY_UNLOCKED, instance.currentState.getValue()); + Assert.assertEquals(ContactStateEnum.BOAT_UNAVAILABLE.getStringValue(), contact.getState()); + Assert.assertEquals(0, contact.getNbObservants()); + Assert.assertNull(contact.getTideEndDate()); + Assert.assertNull(contact.getTideBeginDate()); + + // COMPANY_UNLOCKED -> COMPANY_ACCEPTED -> PROGRAM_UNLOCKED + instance.nextState(ContactStateEnum.COMPANY_ACCEPTED); + Assert.assertEquals(ContactStateEnum.PROGRAM_UNLOCKED, instance.currentState.getValue()); + Assert.assertTrue(contact.getValidationCompany()); + Assert.assertNull(contact.getValidationProgram()); + + // PROGRAM_UNLOCKED -> COMPANY_UNLOCKED + instance.nextState(ContactStateEnum.COMPANY_UNLOCKED); + Assert.assertEquals(ContactStateEnum.COMPANY_UNLOCKED, instance.currentState.getValue()); + Assert.assertNull(contact.getValidationCompany()); + + // COMPANY_UNLOCKED -> COMPANY_REFUSED + instance.nextState(ContactStateEnum.COMPANY_REFUSED); + Assert.assertEquals(ContactStateEnum.COMPANY_REFUSED, instance.currentState.getValue()); + Assert.assertFalse(contact.getValidationCompany()); + + // Reinitialize of ContactContext to take other transition from PROGRAM_UNLOCKED + contact = new ContactImpl(); + contact.setValidationCompany(Boolean.TRUE); + contact.setState(ContactStateEnum.BOARDING_DONE.getStringValue()); + instance = new ContactContextImpl(contact); + Assert.assertEquals(ContactStateEnum.PROGRAM_UNLOCKED, instance.currentState.getValue()); + + // PROGRAM_UNLOCKED -> PROGRAM_ACCEPTED + instance.nextState(ContactStateEnum.PROGRAM_ACCEPTED); + Assert.assertEquals(ContactStateEnum.PROGRAM_ACCEPTED, instance.currentState.getValue()); + Assert.assertTrue(contact.getValidationProgram()); + + + } + + /** + * Test of getAvailableNextStatesAsString method, of class ContactContext. + */ + //@Test + public void testGetAvailableNextStatesAsString() { + System.out.println("getAvailableNextStatesAsString"); + } + + /** + * Test of getAvailableNextStatesAsEnum method, of class ContactContext. + */ + //@Test + public void testGetAvailableNextStatesAsEnum() { + System.out.println("getAvailableNextStatesAsEnum"); + } + + /** + * Test of setState method, of class ContactContext. + */ + //@Test + public void testSetState() { + System.out.println("setState"); + } + + /** + * Test of createContactState method, of class ContactContext. + */ + //@Test + public void testCreateContactState() throws Exception { + System.out.println("createContactState"); + } + +} \ No newline at end of file Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java 2009-12-10 16:18:20 UTC (rev 118) @@ -29,6 +29,8 @@ import fr.ifremer.suiviobsmer.entity.Boat; import fr.ifremer.suiviobsmer.entity.Company; import fr.ifremer.suiviobsmer.entity.CompanyDAO; +import fr.ifremer.suiviobsmer.entity.ElligibleBoat; +import fr.ifremer.suiviobsmer.entity.ElligibleBoatDAO; import fr.ifremer.suiviobsmer.entity.FishingZone; import fr.ifremer.suiviobsmer.entity.FishingZoneDAO; import fr.ifremer.suiviobsmer.entity.Profession; @@ -356,6 +358,49 @@ System.out.println("getSampleRow"); } + //@Test + public void testDeleteSampleRow() throws Exception { + log.info("deleteSampleRow"); + + /** PREPARE DATA **/ + TopiaContext transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + + FishingZoneDAO zoneDAO = SuiviObsmerModelDAOHelper.getFishingZoneDAO(transaction); + FishingZone zoneIId = zoneDAO.create(FishingZone.DISTRICT_CODE, "IId"); + FishingZone zoneIV = zoneDAO.create(FishingZone.DISTRICT_CODE, "IV"); + FishingZone zoneI = zoneDAO.create(FishingZone.DISTRICT_CODE, "I"); + + transaction.commitTransaction(); + + + InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); + service.importSamplingPlanCsv(input); + + SampleRowDAO rowDAO = SuiviObsmerModelDAOHelper.getSampleRowDAO(transaction); + SampleRow row = rowDAO.findByCode("2010_1"); + row.getProfession(); + row.getProgram(); + row.getCompany(); + transaction.closeContext(); + + input = getClass().getResourceAsStream("/import/navires.csv"); + ServiceBoat serviceBoat = new ServiceBoatImpl(); + serviceBoat.importBoatCsv(input); + List<Boat> boats = serviceBoat.getBoats("174592 978419 273129"); + + service.createUpdateSampleRow(row, boats); + /** EXEC METHOD **/ + + service.deleteSampleRow(row); + row = rowDAO.findByCode("2010_1"); + assertNull(row); + + transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + ElligibleBoatDAO elligibleDAO = SuiviObsmerModelDAOHelper.getElligibleBoatDAO(transaction); + List<ElligibleBoat> elligibles = elligibleDAO.findAll(); + assertEquals(0, elligibles.size()); + } + @Test public void testImportSamplingPlanCsv() throws SuiviObsmerException, TopiaException { log.info("importSamplingPlanCsv"); Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2009-12-10 16:18:20 UTC (rev 118) @@ -22,7 +22,7 @@ package fr.ifremer.suiviobsmer.ui.pages; import fr.ifremer.suiviobsmer.SuiviObsmerException; -import fr.ifremer.suiviobsmer.bean.ContactState; +import fr.ifremer.suiviobsmer.bean.states.ContactStateEnum; import fr.ifremer.suiviobsmer.entity.Boat; import fr.ifremer.suiviobsmer.entity.Company; import fr.ifremer.suiviobsmer.entity.Contact; @@ -191,6 +191,8 @@ private boolean even = true; +// private ContactContext contactContext; + public Map<String, Contact> getContacts() throws SuiviObsmerException { if (contacts == null) { if (log.isInfoEnabled()) { @@ -211,11 +213,22 @@ return contactModel; } +// public ContactContext getContactContext() throws ContactStateException { +// if (contactContext == null) { +// contactContext = new ContactContextImpl(contact); +// } +// return contactContext; +// } +// +// public List<ContactStateEnum> getContactStateAvailables() throws ContactStateException { +// return getContactContext().getAvailableNextStatesAsEnum(); +// } + public SelectModel getStateSelectModel() { if (stateSelectModel == null) { List<OptionModel> options = new ArrayList<OptionModel>(); - for (ContactState state : ContactState.values()) { - options.add(new OptionModelImpl(state.getValue(), state.getValue())); + for (ContactStateEnum state : ContactStateEnum.values()) { + options.add(new OptionModelImpl(state.getStringValue(), state.getStringValue())); } stateSelectModel = new SelectModelImpl(null, options); } @@ -272,8 +285,12 @@ return contact.getValidationCompany() == null && contact.getValidationProgram() == null; } +// if (!user.getAdmin()) { +// return getContactStateAvailables().contains(ContactStateEnum.COMPANY_UNLOCKED); +// } // pour un admin : affichage uniquement si la compagnie a validé la ligne return BooleanUtils.isTrue(contact.getValidationCompany()); +// return getContactStateAvailables().contains(ContactStateEnum.PROGRAM_UNLOCKED); } @Log Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java 2009-12-10 16:18:20 UTC (rev 118) @@ -344,5 +344,10 @@ period.setFromDate(program.getPeriodBegin()); period.setThruDate(program.getPeriodEnd()); } + + void onActionFromDeleteSampleRow(int rowIndex) throws SuiviObsmerException { + row = getData().get(rowIndex); + serviceSampling.deleteSampleRow(row); + } } Modified: trunk/suiviobsmer-ui/src/main/webapp/SamplingPlan.tml =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/SamplingPlan.tml 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-ui/src/main/webapp/SamplingPlan.tml 2009-12-10 16:18:20 UTC (rev 118) @@ -147,13 +147,15 @@ <img src="${asset:context:}/img/boat.png" alt="Navire" title="Voir les navires elligibles pour cette ligne"/> </a> <t:if t:test="user.admin"> - <!--a t:id="editRow" t:type="actionlink" t:zone="samplingZone" - t:context="[facadeIndex, sectorIndex, rowIndex]"--> - <a t:type="pagelink" t:page="sampleRowForm" t:context="row.topiaId"> - <img src="${asset:context:}/img/edit.png" alt="Modifier" title="Modifier la ligne"/> + <a t:type="pagelink" t:page="sampleRowForm" t:context="row.topiaId"> + <img src="${asset:context:}/img/edit.png" alt="Modifier" title="Modifier la ligne"/> + </a> + <t:unless t:test="row.hasSampleMonthRealTideTime()"> + <a t:type="actionlink" t:id="deleteSampleRow" t:context="rowIndex" title="Supprimer la ligne d'échantillon" + t:mixins="confirm" t:message="Etes-vous sûr de vouloir supprimer définitivement cette ligne du plan d'échantillonnage ?"> + <img src="${asset:context:}/img/delete2.png" alt="Supprimer" title="Supprimer la ligne"/> </a> - <img src="${asset:context:}/img/delete2.png" alt="Supprimer" title="Supprimer la ligne"/> - <!--/a--> + </t:unless> </t:if> </td> </tr> Modified: trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js 2009-12-10 14:05:38 UTC (rev 117) +++ trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js 2009-12-10 16:18:20 UTC (rev 118) @@ -8,11 +8,12 @@ */ initialize: function(element, message) { this.message = message; + Tapestry.debug('click ' + element); Event.observe($(element), 'click', this.doConfirm.bindAsEventListener(this)); }, doConfirm: function(e) { if(! confirm(this.message)) { - //Tapestry.debug('STOP ' + e); + Tapestry.debug('STOP ' + e); Event.stop(e); } }