From b1818546c0089915256e161353528f3095cd86ee Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 12 Dec 2014 14:43:11 +0100 Subject: [PATCH] =?UTF-8?q?U=C5=BEivatele=20a=20komisi=20nelze=20smazat,?= =?UTF-8?q?=20pokud=20jsou=20=C4=8Dlenem=20n=C4=9Bkter=C3=A9ho=20st=C5=99e?= =?UTF-8?q?diska,=20nebo=20komise.=20closes=20#178?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/users/DeleteUserException.java | 17 +++++++++++++++++ .../isspst/services/users/UserServiceImpl.java | 14 ++++++++++++++ .../services/workgroups/WorkgroupException.java | 2 ++ .../workgroups/WorkgroupServiceImpl.java | 5 +++++ .../info/bukova/isspst/ui/ListViewModel.java | 13 +++++++++++++ .../webapp/WEB-INF/locales/zk-label.properties | 2 ++ 6 files changed, 53 insertions(+) create mode 100644 src/main/java/info/bukova/isspst/services/users/DeleteUserException.java diff --git a/src/main/java/info/bukova/isspst/services/users/DeleteUserException.java b/src/main/java/info/bukova/isspst/services/users/DeleteUserException.java new file mode 100644 index 00000000..6b42026d --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/users/DeleteUserException.java @@ -0,0 +1,17 @@ +package info.bukova.isspst.services.users; + +import info.bukova.isspst.services.IsspstException; + +public class DeleteUserException extends IsspstException { + + /** + * + */ + private static final long serialVersionUID = -5326664758639660224L; + + public DeleteUserException(String message) { + super(message); + setReason(message); + } + +} diff --git a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java index 470abf14..514b1978 100644 --- a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java @@ -9,6 +9,7 @@ import info.bukova.isspst.services.AbstractService; import info.bukova.isspst.services.StringXmlMarshaller; //import info.bukova.isspst.services.LazyLoader; +import info.bukova.isspst.services.workgroups.WorkgroupService; import java.util.ArrayList; import java.util.HashSet; @@ -35,6 +36,8 @@ public class UserServiceImpl extends AbstractService implements UserServic private PasswordEncoder encoder; @Autowired private RoleService roleService; + @Autowired + private WorkgroupService workgroupService; private StringXmlMarshaller marshaller; private AuthMethod authMethod; @@ -216,4 +219,15 @@ public class UserServiceImpl extends AbstractService implements UserServic return authMethod; } + @Override + public void delete(User entity) { + workgroupService.loadParents(entity); + + if (entity.getParents().isEmpty()) { + super.delete(entity); + } else { + throw new DeleteUserException("UserIsInWorkgroup"); + } + } + } diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java index 6b588f38..accda6e8 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java @@ -13,9 +13,11 @@ public class WorkgroupException extends IsspstException { public final static String MSUT_HAS_CENTER = "RoleMustHasCentre"; public final static String MUST_HAS_WORKGROUP = "WorkgroupMustHasCentre"; public final static String CYCLIC_MEMBER = "CyclicMembership"; + public final static String HAS_PARENT = "WorkgroupIsInWorkgroup"; public WorkgroupException(String message) { super(message); + setReason(message); } } diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java index 5057396e..9b2c3a1d 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java @@ -248,6 +248,11 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem @Transactional @PreAuthorize("hasPermission(this, 'PERM_DELETE')") public void delete(Workgroup entity) { + Workgroup dbWg = dao.getById(entity.getId()); + if (!dbWg.getParents().isEmpty()) { + throw new WorkgroupException(WorkgroupException.HAS_PARENT); + } + loadMembers(entity); for (JobMapping m : entity.getMembers()) { loadParents(m.getMember()); diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index 0fb8b86d..9d5d4be8 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -3,6 +3,7 @@ package info.bukova.isspst.ui; import info.bukova.isspst.StringUtils; import info.bukova.isspst.data.DataModel; import info.bukova.isspst.filters.Filter; +import info.bukova.isspst.services.IsspstException; import info.bukova.isspst.services.Service; import java.util.ArrayList; @@ -202,6 +203,18 @@ public class ListViewModel extends DocumentViewModel BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataBean"); BindUtils.postGlobalCommand(null, null, "reloadRelated", null); + } catch (IsspstException e) { + if (e.getReason() != null) { + Messagebox.show( + StringUtils.localize(e.getReason()), + StringUtils.localize("Error"), + Messagebox.OK, Messagebox.ERROR); + } else { + Messagebox.show( + StringUtils.localize("DbSaveError"), + StringUtils.localize("Error"), + Messagebox.OK, Messagebox.ERROR); + } } catch (DataIntegrityViolationException e) { Messagebox.show(StringUtils.localize("DbCannotDelete"), StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR); } catch (AccessDeniedException e) { diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index eb050a4a..93457367 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -117,6 +117,7 @@ UsersGridColumnLogin=Login UsersGridColumnPersonalID=Osobní číslo UsersGridColumnFirstName=Jméno UsersGridColumnSureName=Příjmení +UserIsInWorkgroup=Uživatele nelze smazat, protože je členem některé pracovní skupiny AgendaMaterial=Skupiny materiálu MaterialFormTitle=Skupina materiálu @@ -354,3 +355,4 @@ WorkgroupFormMemberIsCenterMember=Některý ze členů přidávané komise je č WorkgroupFormCannotAddUser=Uživatele nelze přidat WorkgroupFormCannotAddWorkgroup=Komisi nelze přidat WorkgroupFormOrderLimit=Limit nákupů +WorkgroupIsInWorkgroup=Komisi nelze smazat, protože je členem některého střediska