Package org.palo.viewapi

Examples of org.palo.viewapi.View


      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);
View Full Code Here


  }

  public Boolean isOwner(String sessionId, String viewId)
      throws SessionExpiredException {
    AuthUser user = getLoggedInUser(sessionId);   
    View view = ServiceProvider.getViewService(user).getView(viewId);   
    if (user.getId().equals(view.getOwner().getId())) {
      if (checkPermission(sessionId, 2)) {
        return true;
      }
    }
    return false;
View Full Code Here

          return view;
        }
      }
    }
    for (ExplorerTreeNode kid: node.getChildren()) {
      View v = searchView(kid, view);
      if (v != null) {
        return v;
      }   
    }
    return null;
View Full Code Here

        String view = getValue("openview", linkToParse);
        if (view == null) {
          data.addError(UserSession.trans(locale, "noViewIdSpecified"));       
          continue;
        }
        View v = viewService.getView(view);
        if (v == null) {
          data.addError(UserSession.trans(locale, "couldNotFindView", view));             
          continue;
        }
       
        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()));             
          continue;
        }
       
//        FolderService fs = ServiceProvider.getFolderService(authUser);
//        if (searchView(fs.getTreeRoot(), v) == null) {
//          data.addError("The view " + v.getName() + " (" + v.getId() + ") cannot be seen by this user.");
//          continue;
//        }

        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()));             
          continue;
        }
       
        ViewConverter conv = new ViewConverter();
        XView xView = (XView) conv.toXObject(v);
View Full Code Here

      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{
View Full Code Here

    return false;
  }
 
  private final XDirectLinkData findPaloSuiteView(AuthUser authenticatedUser, String viewId, SimpleLogger log, XDirectLinkData data, ArrayList <ConnectionDescriptor> connections, String locale) {
    Account accountToUse = null;
    View viewToUse = null;
    IViewManagement mgmt = MapperRegistry.getInstance().getViewManagement();
    Account bestMatch = null;
    View bestView = null;
    View viewIdFound = null;
   
    log.debug("Listing all existing views:");
    try {
      for (View v: mgmt.listViews()) {
        log.debug("  " + v.getName() + " does it match?");
        if (checkPaloSuiteId(v, viewId, log)) {
          log.debug("   => it has the correct paloSuiteId, so go on... List accounts:");
          viewIdFound = v;
          for (Account acc: authenticatedUser.getAccounts()) {
            String host = acc.getConnection().getHost();
            String service = acc.getConnection().getService();
            String user = acc.getLoginName();
            boolean found = false;
            for (ConnectionDescriptor desc: connections) {
              if (desc.host.equals(host) &&
                desc.port.equals(service)) {
                found = true;
                break;
              }
            }
            if (!found) {
              // User has no rights for this connection (anymore).
              continue;
            }
            PaloConnection c = v.getAccount().getConnection();
            log.debug("       account: " + acc.getLoginName() + ", " + acc.getPassword() + " [" + host + ", " + service + ", " + user + "]");
            log.debug("       looking for: " + c.getHost() + ", " + c.getService() + ", " + v.getAccount().getUser().getLoginName());
            if (c.getHost().equals(host) && c.getService().equals(service)) {
              if (v.getAccount().getUser().getLoginName().equals(user)) {
                log.debug("             => HIT! All's well.");
                accountToUse = acc;
                viewToUse = v;
                break;
              }
              log.debug("            => Close match. All's well.");
              bestMatch = acc;
              bestView = v;
            }
          }
        }
        if (viewToUse != null && accountToUse != null) {
          break;
        }
      }
    } catch (SQLException e) {       
    }
    data.setUserPassword(authenticatedUser.getPassword());
    data.setPaloSuiteViewId(viewId);
   
    if (accountToUse == null && bestMatch == null) {
      log.debug("No account or no view found. Either the view does not exist, or something's rotten in the state of Denmark.");
    }
   
    if (accountToUse == null && bestMatch != null) {
      log.debug("No exact account match found, but something close enough: " + bestMatch.getLoginName() + ", " + bestMatch.getConnection().getHost() + ", " + bestMatch.getConnection().getService());
      accountToUse = bestMatch;
      viewToUse = bestView;
    }
    if (accountToUse != null) {
      AccountConverter co = new AccountConverter();
      XAccount xAccount = (XAccount) co.toXObject(accountToUse);
      data.setXAccount(xAccount);
      log.debug("AccountToUse:");
      log.debug("  Name: " + xAccount.getLogin());
      log.debug("  Pass: " + data.getUserPassword());
      log.debug("View: " + viewToUse.getName());
      data.setAuthenticated(true);     
      ViewConverter conv = new ViewConverter();
      XView xView = (XView) conv.toXObject(viewToUse);                   
      data.setViews(new XView [] {xView});                   
    }
    if (viewIdFound != null && accountToUse == null) {
      data.addError(UserSession.trans(locale, "viewCannotBeSeen", viewIdFound.getName(), viewIdFound.getId()));
    }
    return data;       
  }
View Full Code Here

      if (!doCreateDefaultView(xView)) {
        try {
          try {
            cube = getCube(xView, sessionId);
            ConnectionPoolManager.getInstance().disconnect(getAccount(xView.getAccountId()), sessionId, "WPaloCubeViewConverter.convertLegacyView");
            View v = convert(cube.getCubeView(xView.getId()), xView.getName(), sessionId);
            return v;
          } finally {
            ConnectionPoolManager.getInstance().disconnect(getAccount(xView.getAccountId()), sessionId, "WPaloCubeViewConverter.convertLegacyView2");
          }
         
View Full Code Here

    XView view = new XView(id, name);
    view.setCubeId(cube.getId());
    view.setDatabaseId(cube.getDatabase().getId());
    view.setAccountId(accountId);
    ViewService vService = ServiceProvider.getViewService(user);
    View v = vService.getView(id);
    if (v != null && v.getOwner() != null) {
      view.setOwnerId(v.getOwner().getId());     
    }
    if (v != null) {
      List <String> ids = new ArrayList<String>();
      List <String> names = new ArrayList <String>();
      for (Role r: v.getRoles()) {
        ids.add(r.getId());
        names.add(r.getName());
      }
      view.setRoleIds(ids);   
      view.setRoleNames(names);
View Full Code Here

  }

  public XUser[] getUsersForConnection(String sessionId, String viewId)
      throws SessionExpiredException {       
    LinkedHashSet <User> users = new LinkedHashSet<User>();
    View v = null;
    try {
      v = (View) MapperRegistry.getInstance().getViewManagement().find(viewId);
    } catch (SQLException e1) {
    }
    if (v != null) {     
      try {
        Account acc = v.getAccount();
        if (acc != null) {
          String conId = acc.getConnection().getId();
          List <Account> allAccounts = MapperRegistry.getInstance().getAccountManagement().getAccountsBy(conId);
          for (Account a: allAccounts) {
            users.add(a.getUser());
View Full Code Here

    }
    return new XUser[0];
  }
 
  public XConnection getConnection(String sessionId, XView view) throws SessionExpiredException {
    View v = null;
    try {
      v = (View) MapperRegistry.getInstance().getViewManagement().find(view.getId());
    } catch (SQLException e1) {
    }
    if (v != null && v.getAccount() != null && v.getAccount().getConnection() != null) {
      PaloConnection con = v.getAccount().getConnection();
      XConnection xCon = (XConnection) XConverter.createX(con);
      return xCon;
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of org.palo.viewapi.View

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.