Exemple #1
1
 public void deleteNotValidatedUser(String _username) throws MSMApplicationException {
   NdgUser user = findNdgUserByName(_username);
   if (user != null) {
     try {
       // deleting transactionlog
       Query query = manager.createNamedQuery("transactionlog.findByUser");
       query.setParameter("_user", user);
       Transactionlog t = (Transactionlog) query.getSingleResult();
       manager.remove(t);
       // deleting surveys
       query = manager.createNamedQuery("survey.findByUser");
       query.setParameter("_user", user);
       ArrayList<Survey> surveysListDB = (ArrayList<Survey>) query.getResultList();
       for (Survey survey : surveysListDB) {
         manager.remove(survey);
       }
       // deleting user
       manager.remove(user);
     } catch (NoResultException e) {
       System.err.println(e.getMessage());
     }
   } else {
     throw new UserNotFoundException();
   }
 }
 @Override
 @Transactional
 public void updatePart(PartModel partModel, String modelNumber) {
   log.debug("Update Part model: {}", partModel);
   if (partModel == null) {
     throw new IllegalArgumentException("Cannot update null Part");
   }
   try {
     Part part = bindPart(partModel);
     log.debug("Update part: part: {}", part);
     if (modelNumber != null) {
       try {
         HeliParts heliParts = null;
         Heli heli = entityManager.find(Heli.class, modelNumber);
         if (heli != null) {
           heliParts = heliPartsService.getHeliPart(modelNumber, part.getPartNumber());
           if (heliParts == null) {
             log.debug("Update part heli: {}", heli);
             log.debug("Update part helipart: {}", heliParts);
             heliPartsService.createHeliPart(heli, part);
           }
         }
       } catch (NoResultException e) {
         log.debug("Update part error: {}", e.getMessage());
       }
     }
     log.debug("Part updated in database: {}", part);
     entityManager.merge(part);
   } catch (Exception e) {
     throw new IllegalArgumentException(e.getMessage());
   }
 }
  /**
   * Execute search request on User entity and return the ValueObject list
   *
   * @param queryString jpql query
   * @param parameters jpql parameters
   * @return list of UserVO
   */
  private List<UserVO> executeUserRequestList(
      String queryString, HashMap<String, Object> parameters) {
    List<User> users = null;
    List<UserVO> vos = new ArrayList<UserVO>();
    EntityManager em = EntityManagerLoaderListener.createEntityManager();
    try {

      TypedQuery<User> query = em.createQuery(queryString, User.class);
      if (parameters != null) {
        Iterator<String> it = parameters.keySet().iterator();
        while (it.hasNext()) {
          String pName = it.next();
          query.setParameter(pName, parameters.get(pName));
        }
      }
      query.setMaxResults(Constants.MAX_RESULT);
      users = query.getResultList();

      /* Populate the value object */
      for (User user : users) {
        UserVO u = new UserVO();
        BeanUtils.populate(u, BeanUtils.describe(user));
        u.setAccountId(user.getAccount().getAccountId());
        vos.add(u);
      }
    } catch (NoResultException nre) {
      System.out.println("No result found while search users " + nre.getMessage());
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      em.close();
    }
    return vos;
  }
 public List<Usuarios> buscarTodosUsuarios() {
   try {
     return entityManager.createQuery("Select u from Usuarios u").getResultList();
   } catch (NoResultException e) {
     e.printStackTrace();
     return null;
   }
 }
 /**
  * Thrown by the persistence provider when getSingleResult() is executed on a query and there is
  * no result to return.
  */
 @ExceptionHandler(NoResultException.class)
 public ResponseEntity<Map<String, Object>> handleNoResultException(NoResultException error) {
   Map<String, Object> errorMap = new HashMap<String, Object>();
   errorMap.put("hasErrors", "true");
   errorMap.put("developerMessage", error.getMessage());
   errorMap.put("userMessage", "");
   errorMap.put("moreInfo", error.getStackTrace()[0]);
   errorMap.put("errorCode", HttpStatus.NOT_FOUND);
   error.printStackTrace();
   return new ResponseEntity<Map<String, Object>>(errorMap, HttpStatus.NOT_FOUND);
 }
Exemple #6
0
 public NdgUser findNdgUserByName(String username) throws MSMApplicationException {
   Query query = manager.createNamedQuery("user.findByName");
   query.setParameter("userName", username);
   NdgUser user = null;
   try {
     user = (NdgUser) query.getSingleResult();
   } catch (NoResultException e) {
     System.err.println(e.getMessage());
   }
   return user;
 }
Exemple #7
0
 public List<ExecutedBlock> getExecutedBlocks() {
   String sql = "From ExecutedBlock";
   try {
     List<ExecutedBlock> execBlockList =
         entityManager.createQuery(sql, ExecutedBlock.class).getResultList();
     return execBlockList;
   } catch (NoResultException e) {
     e.printStackTrace();
     return null;
   }
 }
Exemple #8
0
  public static void setVersaoBanco(int versao) {
    try {
      String sql = "UPDATE versao_banco SET versao = '" + versao + "'";

      EntityManagerLocal.begin();
      EntityManagerLocal.getEntityManager().createNativeQuery(sql).executeUpdate();
      EntityManagerLocal.commit();
    } catch (NoResultException ex) {
      ex.printStackTrace();
    }
  }
 /**
  * Thrown when the application calls Query.uniqueResult() and the query returned more than one
  * result. Unlike all other Hibernate exceptions, this one is recoverable!
  */
 @ExceptionHandler(NonUniqueResultException.class)
 public ResponseEntity<Map<String, Object>> handleNonUniqueResultException(
     NoResultException error) {
   Map<String, Object> errorMap = new HashMap<String, Object>();
   errorMap.put("hasErrors", "true");
   errorMap.put("developerMessage", "Fetched more than one object/entity but expected only one");
   errorMap.put("userMessage", "");
   errorMap.put("moreInfo", error.getMessage());
   errorMap.put("errorCode", HttpStatus.INTERNAL_SERVER_ERROR);
   error.printStackTrace();
   return new ResponseEntity<Map<String, Object>>(errorMap, HttpStatus.INTERNAL_SERVER_ERROR);
 }
 /**
  * @return name of logged in user
  * @throws UserNotFoundException
  */
 public String getName() throws UserNotFoundException {
   try {
     return userData.getLoggedUser().getUsername();
   } catch (NoResultException ex) {
     errorMessage = ex.getMessage();
     Logger.getLogger(UserControllerBB.class.getName()).log(Level.SEVERE, null, ex);
     return "/faces/login.xhtml?faces-redirect=true";
   } catch (UserGuideException ex) {
     Logger.getLogger(UserControllerBB.class.getName()).log(Level.SEVERE, null, ex);
   }
   return null;
 }
  public void listar() {

    List<Curso> encontrados = new ArrayList<Curso>();

    TypedQuery<Curso> query = em.createQuery("select u from Curso u order by u.id", Curso.class);
    try {
      encontrados = query.getResultList();
    } catch (NoResultException e) {
      e.printStackTrace();
    }

    cadastro.setListaCursos(encontrados);
  }
  public List<Curso> getCursos() {

    List<Curso> encontrados = new ArrayList<Curso>();

    TypedQuery<Curso> query = em.createQuery("select u from Curso u order by u.id", Curso.class);
    try {
      encontrados = query.getResultList();
    } catch (NoResultException e) {
      e.printStackTrace();
    }

    return encontrados;
  }
 private void addLog(String mark) {
   String eql = "from Permission p where p.mark = :mark";
   Query query = entityManager.createQuery(eql);
   query.setParameter("mark", mark);
   Permission permission;
   try {
     permission = (Permission) query.getSingleResult();
     OptLog optLog = new OptLog();
     optLog.setOptTime(new Date());
     optLog.setPermission(permission);
     entityManager.persist(optLog);
   } catch (NoResultException e) {
     e.printStackTrace();
   }
 }
Exemple #14
0
 public UserBalanceVO findUserBalanceByUser(String username) throws MSMApplicationException {
   Query query = manager.createNamedQuery("userbalance.findByUserAdmin");
   query.setParameter("useradmin", username);
   UserBalance userBalance = null;
   UserBalanceVO userBalanceVO = null;
   try {
     userBalance = (UserBalance) query.getSingleResult();
     if (userBalance != null) {
       userBalanceVO = userBalancePojoToVo(userBalance);
     }
   } catch (NoResultException e) {
     System.err.println(e.getMessage());
   }
   return userBalanceVO;
 }
 public User findUser(String username, String passwd) {
   try {
     TypedQuery<User> query =
         entityManager.createQuery(
             "SELECT u FROM User u WHERE u.username = :username and u.passwd=:passwd", User.class);
     query.setParameter("username", username);
     query.setParameter("passwd", passwd);
     User u = query.getSingleResult();
     u.setPermissions("root"); // TODO: dit moet natuurlijk anders! (moet uit de DB komen)
     return u;
   } catch (NoResultException e) {
     e.printStackTrace();
   }
   return null;
 }
Exemple #16
0
 @Override
 public UserVO getUserByEmail(String email) throws MSMApplicationException {
   Query query = manager.createNamedQuery("user.findByEmail");
   query.setParameter("email", email);
   NdgUser user = null;
   UserVO vo = null;
   try {
     user = (NdgUser) query.getSingleResult();
   } catch (NoResultException e) {
     System.err.println(e.getMessage());
   }
   if (user != null) {
     vo = userPojoToVo(user);
   }
   return vo;
 }
 /**
  * This method implements finding of contracts by telephone number in the database.
  *
  * @param number contract number for search that contract in the database.
  * @return found contract entity.
  */
 @Transactional
 public Contract getContractByPhoneNumber(int number) {
   logger.info("Find contract by telephone number: " + number + " in DB.");
   Contract cn = null;
   try {
     // Search of contract in the database by DAO method.
     cn = cnDao.findContractByNumber(number);
     // If contract does not exist in database, block try catches the NoResultException and
     // throws an ECareException.
   } catch (NoResultException nrx) {
     logger.warn(nrx.getMessage(), nrx);
     return null;
   }
   logger.info("Contract " + cn + " found and loaded from DB.");
   return cn;
 }
 /** {@inheritDoc} */
 @Override
 public BranchExpenseTypePeriodical findLatestBranchExpenseTypePeriodicalByBranchAssembly(
     final BranchAssembly branchAssembly) {
   try {
     TypedQuery<BranchExpenseTypePeriodical> query =
         this.getEntityManager()
             .createQuery(
                 "select bft from BranchExpenseTypePeriodical bft where bft.branchAssembly = :branchAssembly and bft.startDate = (select MAX(e.startDate) from BranchExpenseTypePeriodical e where e.branchAssembly = :branchAssembly)",
                 BranchExpenseTypePeriodical.class);
     query.setParameter("branchAssembly", branchAssembly);
     return query.getSingleResult();
   } catch (NoResultException e) {
     log.info(e.getMessage());
     return null;
   }
 }
 /** {@inheritDoc} */
 @Override
 public BranchExpenseTypePeriodical findBranchExpenseByBranchAssemblyAndEndDate(
     final BranchAssembly branchAssembly, final Date referenceDate) {
   try {
     TypedQuery<BranchExpenseTypePeriodical> query =
         this.getEntityManager()
             .createQuery(
                 "select bft from BranchExpenseTypePeriodical bft where bft.branchAssembly = :branchAssembly and bft.endDate = :referenceDate",
                 BranchExpenseTypePeriodical.class);
     query.setParameter("branchAssembly", branchAssembly);
     query.setParameter("referenceDate", referenceDate);
     return query.getSingleResult();
   } catch (NoResultException e) {
     log.info(e.getMessage());
     return null;
   }
 }
  /** {@inheritDoc} */
  @Override
  public Collection<BranchExpenseTypePeriodical> findBranchExpenseTypePeriodicalsByBranchAssembly(
      final BranchAssembly branchAssembly) {

    try {
      TypedQuery<BranchExpenseTypePeriodical> query =
          this.getEntityManager()
              .createQuery(
                  "select bf from BranchExpenseTypePeriodical bf where bf.branchAssembly = :branchAssembly order by bf.startDate",
                  BranchExpenseTypePeriodical.class);
      query.setParameter("branchAssembly", branchAssembly);
      return query.getResultList();
    } catch (NoResultException e) {
      log.info(e.getMessage());
      return null;
    }
  }
Exemple #21
0
 @Override
 public User findByCode(String code) {
   try {
     TypedQuery<User> query =
         em.createQuery("SELECT u FROM User u WHERE u.code = :code", User.class);
     query.setParameter("code", code);
     return query.getSingleResult();
   } catch (NoResultException e) {
     LOGGER.log(Level.WARNING, e.toString(), e);
     return null;
   } catch (NonUniqueResultException e) {
     throw new AppException(
         ErrorInfo.UNIQUE_CONSTRAINT_ERROR,
         "Has more than one records existing with code =" + code,
         e);
   }
 }
Exemple #22
0
  public String authenticate() {

    String result = "error";

    if (!email.isEmpty() && !password.isEmpty()) {
      try {

        switch (userType) {
          case "Usuario":
            // Adding the user to the Session
            User user = userService.authenticate(this.email, this.password);
            mapSession.put(MapSessionKeys.LOGGED_TYPE, MapSessionKeys.USER);
            mapSession.put(MapSessionKeys.USER, user);
            // Removing a possible Bussines Session
            mapSession.remove(MapSessionKeys.BUSINESS);
            result = Action.SUCCESS;
            break;

          case "Negocio":
            logger.info("Email: " + this.email + ", password: "******"error";
            break;
        }

      } catch (NoResultException nre) {

        logger.error("Error en inicio de sesión: " + nre.getMessage());
        result = "error";
      }
    }

    return result;
  }
 /**
  * (non-Javadoc)
  *
  * @see com.telefonica.euro_iaas.paasmanager.dao.TierDao#findByTierId(java.lang .String)
  */
 private NetworkInstance findByNetworkInstanceName(String name) throws EntityNotFoundException {
   Query query =
       getEntityManager()
           .createQuery(
               "select p from NetworkInstance p left join "
                   + "fetch p.subNets where p.name = :name");
   query.setParameter("name", name);
   NetworkInstance networkInstance = null;
   try {
     networkInstance = (NetworkInstance) query.getSingleResult();
   } catch (NoResultException e) {
     String message =
         " No NetworkInstance found in the database with id: "
             + name
             + " Exception: "
             + e.getMessage();
     throw new EntityNotFoundException(NetworkInstance.class, "name", name);
   }
   return networkInstance;
 }
Exemple #24
0
 @Override
 public User findByUsernameAndPassword(String username, String password) {
   try {
     TypedQuery<User> query =
         em.createQuery(
             "SELECT u FROM User u WHERE u.username = :username and u.password = :password",
             User.class);
     query.setParameter("username", username);
     query.setParameter("password", StringUtil.digest("SHA-256", password));
     return query.getSingleResult();
   } catch (NoResultException e) {
     LOGGER.log(Level.WARNING, e.toString(), e);
     return null;
   } catch (NonUniqueResultException e) {
     throw new AppException(
         ErrorInfo.UNIQUE_CONSTRAINT_ERROR,
         "Has more than one records existing with username ="******", password = "
             + password,
         e);
   }
 }