Package evolaris.framework.sys.business.exception

Examples of evolaris.framework.sys.business.exception.InputException


        return null;
      }
     
    } catch(ParseException e) {
      LOGGER.error("begin or end date couldn't be parsed",e);
      throw new InputException(resources.getMessage(locale, "smssvc.invalidDateTimeFormat"));
    }
  }
View Full Code Here


    user.setPassword(password)// first store unencoded for check
    checkUsernameAndPassword(user);
    // check for existing user and create a reasonable exception if necessary
    if (user.getUsername() != null && getUserDetails(user.getUsername()) != null){
      ResourceBundle messages = ResourceBundle.getBundle("UserManagement", locale);
      throw new InputException(messages.getString("TheUsername") +" \"" + user.getUsername() + "\" " + messages.getString("alreadyExists"));
    }
    Calendar cal = Calendar.getInstance();
    user.setCreationdate(cal.getTime());
    if(password != null){
      user.setPassword(RealmBase.Digest(password,"MD5",null));
View Full Code Here

  public void createUser(User user) {
    checkUsernameAndPassword(user);
    // check for existing user and create a reasonable exception if necessary
    if (user.getUsername() != null && getUserDetails(user.getUsername()) != null){
      ResourceBundle messages = ResourceBundle.getBundle("UserManagement", locale);
      throw new InputException(messages.getString("userExists"));
    }
    Calendar cal = Calendar.getInstance();
    user.setCreationdate(cal.getTime());
    session.save(user);
  }
View Full Code Here

   */
  public void checkUsernameAndPassword(User user) {
    ResourceBundle messages = ResourceBundle.getBundle("UserManagement", locale);
    if (user.getUsername() != null){
      if (user.getUsername().length() < MIN_USERNAME_LENGTH){
        throw new InputException(messages.getString("um.usernameTooShort"));
      }
      if (user.getPassword() == null){
        throw new InputException(messages.getString("um.passwordRequired"));
      } else if (user.getPassword().length() < MIN_PASSWORD_LENGTH){
        throw new InputException(messages.getString("um.passwordTooShort"));
      }
    } else {
      user.setPassword(null)// just to be clean
    }
  }
View Full Code Here

    try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(stream,characterSet));
      CsvParser parser = new CsvParser(delimiter);
      line = reader.readLine(); // caption row
      if(line == null){
        throw new InputException(messages.getString("RowWithCaptionsIsInvalid"));
      }
      // ignore non-latin-1 characters in caption row => avoid problems with Little/BigEndian markers
      StringBuffer latin1line = new StringBuffer(line.length());
      for(int i=0; i < line.length(); i++){
        char c = line.charAt(i);
        if (c >= 0x20 && c <= 0xFE){
          latin1line.append(c);
        }
      }
      line = latin1line.toString();
      if(line.length() == 0){
        throw new InputException(messages.getString("RowWithCaptionsIsInvalid"));
      }
      int lineNumber = 1;

      if(LOGGER.isDebugEnabled()){
        LOGGER.debug("trying to parse following caption row: " + line);
      }

      ArrayList<String> captionRow = parser.parse(line);
      ArrayList<String> methods = validateColumnMapping(captionRow);

      UserImportResult importResult = new UserImportResult();
      List<String> errorMessages = new ArrayList<String>();
      importResult.setErrorMessages(errorMessages);
     
      CsvUser csvUser = new CsvUser(locale);
     
      while((line = reader.readLine()) != null){
        batchTransactionCounter++;
       
        if (line.trim().length() == 0){
          continue;
        }
        lineNumber++;
        if(LOGGER.isDebugEnabled()){
          LOGGER.debug("trying to parse line " + lineNumber + ": " + line);
        }

        ArrayList<String> row = parser.parse(line);
        if(row.size() != captionRow.size()){
          errorMessages.add(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("InvalidNumberOfColumns"));
          LOGGER.info(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("InvalidNumberOfColumns"));
          continue;
        }

        csvUser.reset();
        csvUser.setLineNumber(lineNumber);

        Iterator<String> iterator = row.iterator();
        int i = 0;
        while (iterator.hasNext()) {
          String element =  iterator.next();
          Object[] arguments = new Object[] {element};
          Class[] parameterTypes = new Class[] {String.class};
          LOGGER.debug(i + ": trying to call the method " + methods.get(i));
          Method method = CsvUser.class.getMethod(methods.get(i), parameterTypes);

          method.invoke(csvUser, arguments);
          i++;
        }

        User userToImport = csvUser.getUser(errorMessages);
        if(userToImport == null){
          // error during parsing the user
          importResult.incUsersIgnored();
          continue;
        }
       
        // users with too less data will be ignored
        if((userToImport.getUsername() == null || userToImport.getUsername().trim().equals("")) &&
            (userToImport.getFirstName() == null || userToImport.getFirstName().trim().equals("")) &&
            (userToImport.getLastName() == null || userToImport.getLastName().trim().equals("")) &&
            (userToImport.getMsisdn() == null) &&
            (userToImport.getEmail() == null || userToImport.getEmail().trim().equals("")) &&
            (userToImport.getPersonalNumber() == null || userToImport.getPersonalNumber().equals(""))){
         
            importResult.incUsersIgnored();
            continue;
        }
       
        User alreadyExistingUser = null;

        if(mergeAccordingToUsername){
          if(userToImport.getUsername() != null && userToImport.getUsername().length() > 0){
            alreadyExistingUser = getUserDetails(userToImport.getUsername(),userSet.getGroup());
          }
        } else if(mergeAccordingToMsisdn){
          if(userToImport.getMsisdn() != null){
            alreadyExistingUser = getUserDetails(userToImport.getMsisdn(),userSet.getGroup());
          }
        } else if(mergeAccordingToPersonelNumber){
          if(userToImport.getPersonalNumber() != null && userToImport.getPersonalNumber().length() > 0){
            alreadyExistingUser = getUserDetailsByPersonalNumber(userToImport.getPersonalNumber(),userSet.getGroup());

          }
        }

        User userInDb = null;
        if(alreadyExistingUser == null){
          LOGGER.debug("create new User data objet");

          if(userToImport.getUsername() != null && !userToImport.getUsername().equals("")){ // a default role will be assigned
            Role role = getRole(USER);
            Set<Role> roles = new  HashSet<Role>(1);
            roles.add(role);
            userToImport.setRoles(roles);
          }
          userToImport.setGroup(userSet.getGroup());
          userInDb = createUser(userToImport, userToImport.getPassword());
          importResult.incUsersCreated();

        } else{
          LOGGER.debug("merge existing user data object");
          User user = mergeUser(userToImport,alreadyExistingUser);
          modifyUser(user);
          importResult.incUsersUpdated();
          userInDb = user;
        }

        UserSetManager usersetManager = new UserSetManager(locale,session);
        usersetManager.add(userSet, userInDb);
       
        // the transaction will be committed after BATCH_TRANSACTION_SIZE
        // records are written to the database to enable other users to get a session
        if ((batchTransactionCounter % BATCH_TRANSACTION_SIZE) == 0) {
          HibernateSessions.commitTransaction(session);
          LOGGER.debug("Batch transaction committed - "+batchTransactionCounter+" record(s) written.");
          HibernateSessions.beginTransaction(session);
          batchTransactionCounter = 0;
        }
      }
     
      if (batchTransactionCounter > 0) {
        HibernateSessions.commitTransaction(session);
        LOGGER.debug("Batch transaction committed - "+batchTransactionCounter+" record(s) written, batch processing finished");
        // In case AnonymousLocalizedAction expects a open transaction...
        HibernateSessions.beginTransaction(session);
      }
     
      return importResult;
    } catch (IOException e) {
      throw new InputException(messages.getString("ErrorDuringReadingTheFile"),e);
    catch (NoSuchMethodException e) {
      throw new BugException("a caption to method mapping is invalid",e);
    catch (IllegalAccessException e) {
      throw new BugException("a caption to method mapping is invalid",e);
    } catch (InvocationTargetException e) {
View Full Code Here

    Iterator<String> iterator = header.iterator();
    while (iterator.hasNext()) {
      String caption =  iterator.next().toLowerCase().trim();
      String method = columnMap.get(caption);
      if(method == null){
        throw new InputException(messages.getString("TheCaption") + " \"" + caption + "\" " + messages.getString("isUnknown"));
      }

      methods.add(method);
      if(method.equalsIgnoreCase("username")){
        hasUsername = true;
      } else if(method.equalsIgnoreCase("password")){
        hasPassword = true;
      }
    }

    if(!(hasUsername == hasPassword)){
      throw new InputException(messages.getString("EitherUsernameAndPasswordMustBeProvidedOrNothing"));
    }
    return methods;
  }
View Full Code Here

      if (webUser != null) {
        blog = blogMgr.getBlog(webUser.getUsername(), webUser.getGroup());
      }
    }
    if (blog == null) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.BlogNotFound", idParam, codeParam));
    }
    Set<Long> permissions = getPermissions(blog, webUser);
    if (!permissions.contains(PermissionManager.READ_PERMISSION)) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.insufficientRights"));
    }
    req.setAttribute("blog", blog);   
    Collection<Article> articles = null;
    List<DisplayableArticle> displayArticles = new ArrayList<DisplayableArticle>();
    Date from = null, to = null;
View Full Code Here

      } catch (Exception e) {
        blog = null;
      }
    }
    if (blog == null) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.BlogNotFound", idParam, codeParam));
    }
    try {
      Document rssDoc = createArticleRssFeed(blog, req, 20);
      byte[] bytes = rssDoc.asXML().getBytes();
      resp.setCharacterEncoding(rssDoc.getXMLEncoding());
View Full Code Here

      } catch (Exception e) {
        blog = null;
      }
    }
    if (blog == null) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.BlogNotFound", idParam, codeParam));
    }
    try {
      Document rssDoc = createCommentRssFeed(blog, req, 20);
      byte[] bytes = rssDoc.asXML().getBytes();
      resp.setCharacterEncoding(rssDoc.getXMLEncoding());
View Full Code Here

    BlogArticleForm f = (BlogArticleForm)form;
    BlogManager blogMgr = new BlogManager(locale, session);
    Long id = Long.parseLong(req.getParameter("id"));
    Blog blog = blogMgr.getBlog(id);
    if (blog == null) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.BlogNotFound", id, ""));
    }
    Set<Long> permissions = getPermissions(blog, webUser);
    if (!permissions.contains(PermissionManager.WRITE_PERMISSION)) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.insufficientRights"));
    }
    f.setBlogId(id);
    req.getSession().setAttribute("blog", blog);
    req.getSession().setAttribute("blogCode", blog.getCode())// for fckeditor ...
    req.getSession().setAttribute("labels", blog.getLabels().toArray());
View Full Code Here

TOP

Related Classes of evolaris.framework.sys.business.exception.InputException

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.