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