}
public XView setVisibility(String sessionId, XFolderElement element,
boolean visible, boolean editable, String ownerId,
String accountId, String dbId, String cubeId) throws SessionExpiredException {
XView xView = (XView) element.getSourceObject();
AuthUser user = getLoggedInUser(sessionId);
ViewService vService = ServiceProvider.getViewService(user);
View view = vService.getView(xView.getId());
if (!accountId.equals(xView.getAccountId())) {
try {
Account newAccount = (Account) MapperRegistry.getInstance().getAccountManagement().find(accountId);
if (newAccount != null) {
vService.setAccount(newAccount, view);
xView.setAccountId(newAccount.getId());
}
} catch (SQLException e) {
}
}
if (!dbId.equals(xView.getDatabaseId())) {
try {
CubeViewReader.CHECK_RIGHTS = false;
vService.setDatabase(dbId, view);
xView.setDatabaseId(dbId);
} finally {
CubeViewReader.CHECK_RIGHTS = true;
}
}
if (!cubeId.equals(xView.getCubeId())) {
try {
CubeViewReader.CHECK_RIGHTS = false;
vService.setCube(cubeId, view);
xView.setCubeId(cubeId);
String def = view.getDefinition();
int index = def.indexOf("cube=\"");
if (index != -1) {
int rIndex = def.indexOf("\"", index + 6);
if (rIndex != -1) {
def = def.substring(0, index + 6) +
cubeId + def.substring(rIndex);
vService.setDefinition(def, view);
xView.setDefinition(def);
}
}
} finally {
CubeViewReader.CHECK_RIGHTS = true;
}
}
if (!ownerId.equals(xView.getOwnerId())) {
try {
User newOwner = (User) MapperRegistry.getInstance().getUserManagement().find(ownerId);
if (newOwner != null) {
try {
CubeViewReader.CHECK_RIGHTS = false;
vService.setOwner(newOwner, view);
xView.setOwnerId(newOwner.getId());
} finally {
CubeViewReader.CHECK_RIGHTS = true;
}
}
} catch (SQLException e) {
}
}
try {
ExplorerTreeNode root = FolderModel.getInstance().load(getLoggedInUser(sessionId));
FolderElement folderElement = (FolderElement) find(root, element.getId());
try {
CubeViewReader.CHECK_RIGHTS = false;
assignViewerAndEditorRole(sessionId, folderElement, view, visible, editable);
} catch (SQLException e) {
e.printStackTrace();
} finally {
CubeViewReader.CHECK_RIGHTS = true;
}
folderElement.setSourceObject(view);
saveRoot(sessionId, root);
try {
CubeViewReader.CHECK_RIGHTS = false;
vService.save(view);
} catch (OperationFailedException e) {
e.printStackTrace();
} finally {
CubeViewReader.CHECK_RIGHTS = true;
}
} catch (PaloIOException e) {
e.printStackTrace();
} finally {
CubeViewReader.CHECK_RIGHTS = true;
}
List <String> roles = new ArrayList<String>();
List <String> names = new ArrayList<String>();
for (Role r: view.getRoles()) {
roles.add(r.getId());
names.add(r.getName());
}
xView.setRoleIds(roles);
xView.setRoleNames(names);
return xView;
}