if (spagoBISub != null) {
getSession().setAttribute("spagobisubobj", spagoBISub);
}
try {
ViewService viewService = ServiceProvider.getViewService(authUser);
/*SpagoBI modification begin*/
//View v = viewService.getView(view);
//Account name
String accountName = getValue("account", link);
//Connection
String connection = getValue("connection", link);
String cubeName = null;
Cube cube = null;
String accountId = null;
if(view.equalsIgnoreCase("")){
//cube name --> create view dinamically
cubeName = getValue("cubename", link);
}
View v = null;
for (Account a: authUser.getAccounts()) {
if(a != null){
if(view != null && !view.equals("")){
//if view specified
List<View> views = viewService.getViews(a);
if(!views.isEmpty()){
Iterator it = views.iterator();
while(it.hasNext()){
View selView = (View)it.next();
if(view != null && !view.equals("")){
if(selView.getName().equals(view)){
v = selView;
break;
}
}
}
}
}else{
///tries to get cube
if(a.getUser().getLoginName().equals(accountName)){
if(a.getConnection().getName().equals(connection)){
//use cube name
accountId = a.getId();
Connection con = ((PaloAccount) a).login();
for (Database db: con.getDatabases()) {
int connectionType = db.getConnection().getType();
Cube c = db.getCubeByName(cubeName);
if(c != null){
cube = c;
//((PaloAccount) a).logout();
break;
}
}
}
}
}
}
}
/*end*/
if (v != null) {
String connectionId = v.getAccount().getConnection().getId();
Account neededAccount = null;
for (Account a: authUser.getAccounts()) {
if (a.getConnection().getId().equals(connectionId)) {
PaloConnection paloCon = a.getConnection();
if (paloCon.getType() == PaloConnection.TYPE_WSS) {
continue;
} else {
neededAccount = a;
break;
}
}
}
if (neededAccount == null) {
data.addError(UserSession.trans(locale, "noAccountForView", v.getName(), v.getId()));
return data;
}
boolean allowed = false;
if (v.getOwner() != null) {
if (authUser.getId().equals(v.getOwner().getId())) {
allowed = true;
}
}
if (!allowed) {
for (Role r: v.getRoles()) {
for (Role r2: authUser.getRoles()) {
if (r2.getId().equals(r.getId())) {
if (r2.hasPermission(Right.READ)) {
allowed = true;
break;
}
}
}
for (Group g: authUser.getGroups()) {
for (Role r2: g.getRoles()) {
if (r2.getId().equals(r.getId())) {
if (r2.hasPermission(Right.READ)) {
allowed = true;
break;
}
}
}
}
}
}
if (!allowed) {
data.addError(UserSession.trans(locale, "viewCannotBeSeen", v.getName(), v.getId()));
logger.error("viewCannotBeSeen");
return data;
}
}else if(v == null && cube != null){
//dinamically create view
//if doesn't exist
View existingView = viewService.getViewByName(cubeName, cube);
if(existingView == null){
v = CubeViewConverter.createDefaultView(cubeName, cube, accountId, authUser, "", null);
viewService.save(v);
}else{
v = existingView;
}
}else{
data.addError(UserSession.trans(locale, "couldNotFindView", view));