Author: bleny Date: 2010-12-15 09:40:35 +0000 (Wed, 15 Dec 2010) New Revision: 834 Log: modifying multiple observers ; bug fixes Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java trunk/wao-ui/src/main/webapp/Contacts.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-12-13 17:41:26 UTC (rev 833) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-12-15 09:40:35 UTC (rev 834) @@ -597,7 +597,7 @@ "topiaId CHARACTER VARYING(255) PRIMARY KEY," + "topiaVersion BIGINT NOT NULL," + "topiaCreateDate TIMESTAMP WITHOUT TIME ZONE NOT NULL," + - "waoUser character varying(255)," + + "waoUser CHARACTER VARYING(255)," + "obsProgramOrdinal SMALLINT NOT NULL," + "userRoleOrdinal SMALLINT NOT NULL," + "canWrite BOOLEAN NOT NULL," + Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-12-13 17:41:26 UTC (rev 833) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-12-15 09:40:35 UTC (rev 834) @@ -212,6 +212,7 @@ if (newUser) { userToUpdate = user; + context.prepareTopiaId(WaoUser.class, userToUpdate); WaoUser existUser = dao.findByLogin(user.getLogin()); // Check for a new user if login already exists @@ -222,8 +223,11 @@ user.getLogin()); } - if (userToUpdate.getUserProfile() != null) { - for (UserProfile profile : userToUpdate.getUserProfile()) { + if (user.getUserProfile() != null) { + + Collection<UserProfile> newProfiles = new ArrayList<UserProfile>(user.getUserProfile()); + userToUpdate.clearUserProfile(); + for (UserProfile profile : newProfiles) { log.debug("saving profile " + profile.getDescription()); UserProfile profileToAdd = userProfileDAO.create( UserProfile.PROPERTY_OBS_PROGRAM_ORDINAL, @@ -233,6 +237,7 @@ UserProfile.PROPERTY_CAN_WRITE, profile.getCanWrite() ); + userToUpdate.addUserProfile(profileToAdd); } } } else { @@ -251,9 +256,11 @@ */ // set may be buggy // userToUpdate.setUserProfile(new ArrayList<UserProfile>(user.getUserProfile())); - userToUpdate.clearUserProfile(); +// userToUpdate.clearUserProfile(); // userToUpdate.addAllUserProfile(user.getUserProfile()); + List<UserProfile> newProfiles = new ArrayList<UserProfile>(); + for (UserProfile profile : user.getUserProfile()) { UserProfile profileToAdd; if (profile.getTopiaId() == null) { @@ -272,9 +279,13 @@ } else { profileToAdd = userProfileDAO.findByTopiaId(profile.getTopiaId()); } - userToUpdate.addUserProfile(profileToAdd); + newProfiles.add(profileToAdd); } + + userToUpdate.clearUserProfile(); + userToUpdate.addAllUserProfile(newProfiles); + /* if (log.isDebugEnabled()) { log.debug("new profiles : " + userToUpdate.getUserProfile()); @@ -507,6 +518,7 @@ WaoQueryHelper.newWaoUserProperty(); TopiaQuery query = dao.createQuery(waoUserProperty.$alias()) + .addDistinct() .addJoin(waoUserProperty.userProfile(), userProfileProperty.$alias(), false) .addEquals(userProfileProperty.userRoleOrdinal(), UserRole.OBSERVER.ordinal(), UserRole.COORDINATOR.ordinal()) .addOrder(WaoUser.PROPERTY_FIRST_NAME, WaoUser.PROPERTY_LAST_NAME); Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java 2010-12-13 17:41:26 UTC (rev 833) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java 2010-12-15 09:40:35 UTC (rev 834) @@ -130,9 +130,15 @@ log.debug("trying to store " + user.getTopiaId()); service.createUpdateUser(user, false); + manager = new TestManager(); + setUp(); + profiles.add(coordinatorProfile); service.createUpdateUser(user, false); + manager = new TestManager(); + setUp(); + profiles.remove(adminProfile); service.createUpdateUser(user, false); @@ -180,6 +186,7 @@ UserProfile adminProfile = new UserProfileImpl(ObsProgram.OBSMER, UserRole.ADMIN, true); UserProfile coordinatorProfile = new UserProfileImpl(ObsProgram.OBSMER, UserRole.COORDINATOR, true); + UserProfile coordinatorProfile2 = new UserProfileImpl(ObsProgram.OBSMER, UserRole.COORDINATOR, true); UserProfile observerProfile = new UserProfileImpl(ObsProgram.OBSMER, UserRole.OBSERVER, true); UserProfile observerProfile2 = new UserProfileImpl(ObsProgram.OBSMER, UserRole.OBSERVER, true); @@ -223,6 +230,7 @@ user3.setLogin("user3"); user3.setFirstName("Denis"); user3.setLastName("La Malice"); + user3.addProfile(coordinatorProfile2); user3.addProfile(observerProfile2); user3.setCompany(company); user3.setActive(false); @@ -247,7 +255,7 @@ } } - // user1, user3 and user4 + // user1, user3 and user4 (user4 must appear only one time) Assert.assertEquals(3, users.size()); // Filter on company only Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-12-13 17:41:26 UTC (rev 833) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-12-15 09:40:35 UTC (rev 834) @@ -52,7 +52,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.tapestry5.ComponentResources; import org.apache.tapestry5.Field; -import org.apache.tapestry5.PersistenceConstants; import org.apache.tapestry5.RenderSupport; import org.apache.tapestry5.StreamResponse; import org.apache.tapestry5.annotations.Environmental; @@ -78,6 +77,7 @@ import java.io.InputStream; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; @@ -329,7 +329,7 @@ private GenericSelectModel<WaoUser> userSelectModel; @Property - @Persist(PersistenceConstants.FLASH) + @Persist private String contactUserId; private boolean even = true; @@ -585,8 +585,8 @@ } // ContactEdited is in session, previously set by Edit action // contactEdited.setState(contactState.toString()); - WaoUser contactUser = getUserSelectModel().findObject(contactUserId); - contactEdited.setMainObserver(contactUser); +// WaoUser contactUser = getUserSelectModel().findObject(contactUserId); +// contactEdited.setMainObserver(contactUser); if (logger.isDebugEnabled()) { logger.debug("Comment : " + contactEdited.getComment()); @@ -600,7 +600,7 @@ /**************************** CONTACT SAVE ********************************/ - @Persist(PersistenceConstants.FLASH) + @Persist//(PersistenceConstants.FLASH) private String contactSelectedId; @InjectComponent @@ -702,6 +702,10 @@ " du jour"); } + if (contactEdited.getMainObserver() == null) { + contactsForm.recordError("Il faut un observateur référant"); + } + // Non abouti, Refus ou Refus Définitif if (contactState.isUnfinishedState()) { String newComment = contactEdited.getComment(); @@ -750,10 +754,6 @@ " '" + contactState.libelle() + "'"); } - // XXX to bleny : Regression... It's better to check all case, - // when user (not admin) has a validation error, NPE appears on - // contactEdited.isValidationProgram() - if (logger.isDebugEnabled()) { logger.debug("ValidationProgram = " + contactEdited.isValidationProgram()); } @@ -885,4 +885,123 @@ serviceContact.saveComment(contactId, user.getRole(), extraComment); } + /****************************** OBSERVERS POPUP ***************************/ + + @Property + @Persist + private boolean observersFormZoneVisible; + + @InjectComponent + private Zone observersFormZone; + + @InjectComponent + private Form observersForm; + + private boolean saveObservers; + + @Persist + private List<WaoUser> secondaryObservers; + + @Persist + @Property + private String selectedSecondaryObserverId; + + @Property + private int secondaryObserverIndex; + + @Property + private WaoUser observer; // for loop + + public List<WaoUser> getSecondaryObservers() { + if (secondaryObservers == null) { + secondaryObservers = new ArrayList<WaoUser>(contactEdited.getSecondaryObservers()); + } + return secondaryObservers; + } + + @Log + public Zone onActionFromShowObserversForm() { + contactUserId = contactEdited.getMainObserver().getTopiaId(); + + // show form + observersFormZoneVisible = true; + return observersFormZone; + } + + @Log + public void onChangeFromSecondaryObserver(String value) { + if (StringUtils.isEmpty(value)) { + selectedSecondaryObserverId = null; + } else { + selectedSecondaryObserverId = value; + } + if (logger.isDebugEnabled()) { + logger.debug("selected observer changed to " + selectedSecondaryObserverId); + } + } + + @Log + public void onChangeFromMainObserver(String value) { + if (StringUtils.isEmpty(value)) { + contactUserId = null; + } else { + contactUserId = value; + } + } + + + @Log + public Zone onActionFromAddSecondaryObserver() { + if (selectedSecondaryObserverId != null) { + WaoUser observerToAdd = getObserverSelectModel().findObject(selectedSecondaryObserverId); + + if (observerToAdd == null) { + logger.error("observerToAdd is null, id is " + selectedSecondaryObserverId); + } else if ( ! getSecondaryObservers().contains(observersForm)) { + + getSecondaryObservers().add(observerToAdd); + } + } + return observersFormZone; + } + + @Log + public Zone onActionFromRemoveSecondaryObserver(int secondaryObserverIndex) { + getSecondaryObservers().remove(secondaryObserverIndex); + return observersFormZone; + } + + @Log + public void onSelectedFromCancelEditObservers() { + saveObservers = false; + } + + @Log + public void onSelectedFromSaveObservers() { + saveObservers = true; + } + + @Log + public void onValidateFromObserversForm() { + if (saveObservers) { + if (contactUserId == null) { + observersForm.recordError("Il faut renseigner au moins un observateur"); + } + } + } + + @Log + public Object onSuccessFromObserversForm() { + if (saveObservers) { + WaoUser mainObserver = getObserverSelectModel().findObject(contactUserId); + if (logger.isDebugEnabled()) { + logger.debug("main observer is " + mainObserver); + } + contactEdited.setMainObserver(mainObserver); + contactEdited.setSecondaryObservers(getSecondaryObservers()); + } + observersFormZoneVisible = false; + return this; + } + } Modified: trunk/wao-ui/src/main/webapp/Contacts.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Contacts.tml 2010-12-13 17:41:26 UTC (rev 833) +++ trunk/wao-ui/src/main/webapp/Contacts.tml 2010-12-15 09:40:35 UTC (rev 834) @@ -394,7 +394,7 @@ </p> <p> <t:label t:for="mainObserver" />: - <input t:type="select" t:id="mainObserver" t:model="observerSelectModel" t:validate="required" t:value="contactUserId"/> + <input t:type="select" t:id="mainObserver" t:model="observerSelectModel" t:validate="required" t:value="contactUserId" t:mixins="ck/onEvent" t:event="change" /> </p> <p> <t:label t:for="secondaryObserver" />: