예제 #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();
   }
 }
예제 #2
0
  /**
   * 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;
  }
 @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());
   }
 }
예제 #4
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;
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
예제 #7
0
 /**
  * @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;
 }
예제 #8
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;
 }
 /**
  * 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;
   }
 }
예제 #11
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;
 }
 /** {@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;
    }
  }
예제 #14
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;
 }