/** * Returns whether user is allowed to edit the entity if he created the entity * * @param <T> any object that extends TDPersistable * @param tdUser logged in user * @param t instance of T * @return */ @SuppressWarnings("unchecked") public static <T extends TDPersistable> boolean isAccessible(Long id, T t) { boolean isAccessAllowed = true; try { TDUser tdUser = TDUserService.getUser(); if (id != null && null != tdUser && tdUser.getRole() == TDUserRole.ROLE_STANDARD) { try { T returnValT = (T) Datastore.get(KeyFactory.createKey(t.getClass().getSimpleName(), id)); if (returnValT != null) { if (returnValT.getCreator().getId() != Long.valueOf(tdUser.getKey().getId())) { isAccessAllowed = false; } } } catch (JDOObjectNotFoundException jdoe) { isAccessAllowed = false; } catch (Exception e) { isAccessAllowed = false; } } return isAccessAllowed; } catch (UserNotLoggedInException e) { return false; } catch (UserNotFoundException e) { return false; } }