From e7de013b386ffc2f7bb762f202baa9551e0d467f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacobo=20Aragunde=20P=C3=A9rez?= Date: Fri, 18 Dec 2009 10:50:35 +0100 Subject: [PATCH] ItEr39S19CUAltaGrupoUsuarios: First UI to list and edit Profiles. Profiles can be edited but not saved, since the edition of roles is not implemented yet. --- .../business/users/entities/Profile.java | 4 + .../web/users/IProfileCRUDController.java | 39 ++++++ .../navalplanner/web/users/IProfileModel.java | 69 +++++++++ .../web/users/ProfileCRUDController.java | 132 ++++++++++++++++++ .../navalplanner/web/users/ProfileModel.java | 82 +++++++++++ .../src/main/webapp/users/_editProfile.zul | 58 ++++++++ .../src/main/webapp/users/_listProfiles.zul | 45 ++++++ .../src/main/webapp/users/profiles.zul | 38 +++++ 8 files changed, 467 insertions(+) create mode 100644 navalplanner-webapp/src/main/java/org/navalplanner/web/users/IProfileCRUDController.java create mode 100644 navalplanner-webapp/src/main/java/org/navalplanner/web/users/IProfileModel.java create mode 100644 navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileCRUDController.java create mode 100644 navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileModel.java create mode 100644 navalplanner-webapp/src/main/webapp/users/_editProfile.zul create mode 100644 navalplanner-webapp/src/main/webapp/users/_listProfiles.zul create mode 100644 navalplanner-webapp/src/main/webapp/users/profiles.zul diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java index 0ca042e22..00248b057 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java @@ -48,6 +48,10 @@ public class Profile extends BaseEntity { this.setRoles(roles); } + public static Profile create() { + return create(new Profile()); + } + public static Profile create(String loginName, Set roles) { return create(new Profile(loginName, roles)); } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/users/IProfileCRUDController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/IProfileCRUDController.java new file mode 100644 index 000000000..ec2b8587c --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/IProfileCRUDController.java @@ -0,0 +1,39 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.navalplanner.web.users; + +import org.navalplanner.business.users.entities.Profile; +import org.navalplanner.web.common.entrypoints.EntryPoint; +import org.navalplanner.web.common.entrypoints.EntryPoints; + +@EntryPoints(page = "/users/profiles.zul", registerAs = "profileCRUD") +public interface IProfileCRUDController { + + @EntryPoint("edit") + public abstract void goToEditForm(Profile profile); + + @EntryPoint("create") + public abstract void goToCreateForm(); + + @EntryPoint("list") + public abstract void goToList(); + +} diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/users/IProfileModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/IProfileModel.java new file mode 100644 index 000000000..1b7023b80 --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/IProfileModel.java @@ -0,0 +1,69 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.navalplanner.web.users; + +import java.util.List; + +import org.navalplanner.business.common.exceptions.ValidationException; +import org.navalplanner.business.users.entities.Profile; + +/** + * Model for UI operations related to {@link Profile} + * + * @author Jacobo Aragunde Perez + */ +public interface IProfileModel { + + /** + * Makes some operations needed before edit a {@link Profile}. + * + * @param profile + * The object to be edited + */ + void initEdit(Profile profile); + + /** + * Makes some operations needed before create a new {@link Profile}. + */ + void initCreate(); + + /** + * Get all {@link Profile} elements + * + * @return + */ + List getProfiles(); + + /** + * Gets the current {@link Profile}. + * + * @return A {@link Profile} + */ + Profile getProfile(); + + /** + * Stores the current {@link Profile}. + * + * @throws ValidationException + * If validation fails + */ + void confirmSave() throws ValidationException; +} diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileCRUDController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileCRUDController.java new file mode 100644 index 000000000..463d03a24 --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileCRUDController.java @@ -0,0 +1,132 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.navalplanner.web.users; + +import static org.navalplanner.web.I18nHelper._; + +import java.util.List; + +import org.navalplanner.business.common.exceptions.ValidationException; +import org.navalplanner.business.users.entities.Profile; +import org.navalplanner.web.common.ConstraintChecker; +import org.navalplanner.web.common.IMessagesForUser; +import org.navalplanner.web.common.Level; +import org.navalplanner.web.common.MessagesForUser; +import org.navalplanner.web.common.OnlyOneVisible; +import org.navalplanner.web.common.Util; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.util.GenericForwardComposer; +import org.zkoss.zul.api.Window; + +/** + * Controller for CRUD actions over a {@link Profile} + * + * @author Jacobo Aragunde Perez + */ +@SuppressWarnings("serial") +public class ProfileCRUDController extends GenericForwardComposer implements + IProfileCRUDController { + + private Window createWindow; + + private Window listWindow; + + private IProfileModel profileModel; + + private OnlyOneVisible visibility; + + private IMessagesForUser messagesForUser; + + private Component messagesContainer; + + @Override + public void doAfterCompose(Component comp) throws Exception { + super.doAfterCompose(comp); + comp.setVariable("controller", this, true); + messagesForUser = new MessagesForUser(messagesContainer); + getVisibility().showOnly(listWindow); + } + + @Override + public void goToCreateForm() { + profileModel.initCreate(); + getVisibility().showOnly(createWindow); + Util.reloadBindings(createWindow); + } + + @Override + public void goToEditForm(Profile profile) { + profileModel.initEdit(profile); + getVisibility().showOnly(createWindow); + Util.reloadBindings(createWindow); + } + + @Override + public void goToList() { + getVisibility().showOnly(listWindow); + Util.reloadBindings(listWindow); + } + + public void cancel() { + goToList(); + } + + public void saveAndExit() { + if (save()) { + goToList(); + } + } + + public void saveAndContinue() { + if (save()) { + goToEditForm(getProfile()); + } + } + + public boolean save() { + if(!ConstraintChecker.isValid(createWindow)) { + return false; + } + try { + profileModel.confirmSave(); + messagesForUser.showMessage(Level.INFO, + _("Profile saved")); + return true; + } catch (ValidationException e) { + messagesForUser.showInvalidValues(e); + } + return false; + } + + public List getProfiles() { + return profileModel.getProfiles(); + } + + public Profile getProfile() { + return profileModel.getProfile(); + } + + private OnlyOneVisible getVisibility() { + return (visibility == null) ? new OnlyOneVisible(createWindow, + listWindow) + : visibility; + } +} diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileModel.java new file mode 100644 index 000000000..36d53a6b8 --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileModel.java @@ -0,0 +1,82 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.navalplanner.web.users; + +import java.util.List; + +import org.navalplanner.business.common.exceptions.InstanceNotFoundException; +import org.navalplanner.business.common.exceptions.ValidationException; +import org.navalplanner.business.users.daos.IProfileDAO; +import org.navalplanner.business.users.entities.Profile; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * Model for UI operations related to {@link Profile} + * + * @author Jacobo Aragunde Perez + */ +@Service +@Scope(BeanDefinition.SCOPE_PROTOTYPE) +public class ProfileModel implements IProfileModel { + + private Profile profile; + + @Autowired + private IProfileDAO profileDAO; + + @Override + @Transactional + public void confirmSave() throws ValidationException { + profileDAO.save(profile); + } + + @Override + @Transactional(readOnly=true) + public List getProfiles() { + return profileDAO.list(Profile.class); + } + + @Override + public Profile getProfile() { + return profile; + } + + @Override + @Transactional(readOnly = true) + public void initCreate() { + profile = Profile.create(); + } + + @Override + public void initEdit(Profile profile) { + try { + this.profile = profileDAO.find(profile.getId()); + } + catch (InstanceNotFoundException e) { + initCreate(); + } + } + +} diff --git a/navalplanner-webapp/src/main/webapp/users/_editProfile.zul b/navalplanner-webapp/src/main/webapp/users/_editProfile.zul new file mode 100644 index 000000000..693fb9356 --- /dev/null +++ b/navalplanner-webapp/src/main/webapp/users/_editProfile.zul @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/navalplanner-webapp/src/main/webapp/users/profiles.zul b/navalplanner-webapp/src/main/webapp/users/profiles.zul new file mode 100644 index 000000000..ce452271b --- /dev/null +++ b/navalplanner-webapp/src/main/webapp/users/profiles.zul @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + +