public void delete(String sessionId, XObject xObj) throws DbOperationFailedException, SessionExpiredException {
try {
String type = xObj.getType();
if (type.equals(XAccount.TYPE)) {
Account a = getNative(sessionId, (XAccount) xObj);
IViewManagement viewManagement = MapperRegistry.getInstance().getViewManagement();
try {
List <View> allViews = viewManagement.findViews(a);
ViewService viewService = ServiceProvider.getViewService(getLoggedInUser(sessionId));
try {
CubeViewReader.CHECK_RIGHTS = false;
for (View v: allViews) {
Account acc = v.getAccount();
Account replaceAccount = findReplaceAccount(sessionId, a.getUser(), acc);
if (replaceAccount != null && !v.getAccount().getId().equals(replaceAccount.getId())) {
((ViewImpl) v).setAccount(replaceAccount);
viewService.save(v);
}
}
} finally {
CubeViewReader.CHECK_RIGHTS = true;
}
} catch (SQLException e) {
e.printStackTrace();
}
delete(sessionId, getNative(sessionId, (XAccount) xObj));
}
else if (type.equals(XConnection.TYPE))
delete(sessionId, getNative(sessionId, (XConnection) xObj));
else if (type.equals(XGroup.TYPE))
delete(sessionId, getNative(sessionId, (XGroup) xObj));
else if (type.equals(XRole.TYPE))
delete(sessionId, getNative(sessionId, (XRole) xObj));
else if (type.equals(XUser.TYPE)) {
User user = getNative(sessionId, (XUser) xObj);
IViewManagement viewManagement = MapperRegistry.getInstance().getViewManagement();
try {
try {
IFolderManagement folders = MapperRegistry.getInstance().
getFolderManagement();
AuthUser aUser = ServiceProvider.getAuthenticationService().authenticateHash(user.getLoginName(),
user.getPassword());
List <ExplorerTreeNode> nodes = folders.reallyGetFolders(aUser);
for (ExplorerTreeNode nd: nodes) {
folders.delete(nd);
}
} catch (SQLException e) {
e.printStackTrace();
} catch (AuthenticationFailedException e) {
e.printStackTrace();
}
List <View> allViews = viewManagement.findViews(user);
ViewService viewService = ServiceProvider.getViewService(getLoggedInUser(sessionId));
// At this point, the user has agreed to map all his views to admin...
if (!viewManagement.findViews(user).isEmpty()) {
User adminUser = getLoggedInUser(sessionId);
try {
CubeViewReader.CHECK_RIGHTS = false;
for (View v: allViews) {
viewService.setOwner(adminUser, v);
viewService.save(v);
}
} finally {
CubeViewReader.CHECK_RIGHTS = true;
}
}
IAccountManagement accountManagement = MapperRegistry.getInstance().getAccountManagement();
for (Account a: accountManagement.getAccounts(user.getId())) {
allViews = viewManagement.findViews(a);
try {
CubeViewReader.CHECK_RIGHTS = false;
for (View v: allViews) {
Account acc = v.getAccount();
Account replaceAccount = findReplaceAccount(sessionId, user, acc);
if (replaceAccount != null && !v.getAccount().getId().equals(replaceAccount.getId())) {
((ViewImpl) v).setAccount(replaceAccount);
viewService.save(v);
}
}
} finally {