List of usage examples for org.joda.time DateMidnight DateMidnight
public DateMidnight(Object instant)
From source file:org.jtransfo.jodatime.DateDateMidnightConverter.java
License:Apache License
@Override public DateMidnight convert(Date object, SyntheticField domainField, Object domainObject, String... tags) throws JTransfoException { if (null == object) { return null; }/*from w ww . j a va 2 s . c o m*/ return new DateMidnight(object.getTime()); }
From source file:org.key2gym.business.services.CashServiceBean.java
License:Apache License
@Override public CashAdjustmentDTO getAdjustmentByDate(DateMidnight date) throws SecurityViolationException { if (!callerHasRole(SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Access.Denied")); }//from ww w. j av a2s . c o m if (date == null) { throw new NullPointerException("The date is null."); //NOI18N } CashAdjustment cashAdjustmentEntity = em.find(CashAdjustment.class, date.toDate()); if (cashAdjustmentEntity == null) { cashAdjustmentEntity = new CashAdjustment(); cashAdjustmentEntity.setAmount(BigDecimal.ZERO); cashAdjustmentEntity.setDateRecorded(date.toDate()); cashAdjustmentEntity.setNote(""); em.persist(cashAdjustmentEntity); } CashAdjustmentDTO cashAdjustmentDTO = new CashAdjustmentDTO(); cashAdjustmentDTO.setAmount(cashAdjustmentEntity.getAmount()); cashAdjustmentDTO.setDate(new DateMidnight(cashAdjustmentEntity.getDateRecorded())); cashAdjustmentDTO.setNote(cashAdjustmentEntity.getNote()); return cashAdjustmentDTO; }
From source file:org.key2gym.business.services.ClientProfilesServiceBean.java
License:Apache License
@Override public void updateClientProfile(ClientProfileDTO clientProfile) throws BusinessException, ValidationException { if (clientProfile == null) { throw new NullPointerException("The clientProfile is null."); //NOI18N } else if (clientProfile.getClientId() == null) { throw new NullPointerException("The clientProfile.getClientId() is null."); //NOI18N } else if (clientProfile.getAddress() == null) { throw new NullPointerException("The clientProfile.getAddress() is null."); //NOI18N } else if (clientProfile.getTelephone() == null) { throw new NullPointerException("The clientProfile.getTelephone() is null."); //NOI18N } else if (clientProfile.getFavouriteSport() == null) { throw new NullPointerException("The clientProfile.getFavouriteSport() is null."); //NOI18N } else if (clientProfile.getGoal() == null) { throw new NullPointerException("The clientProfile.getGoal() is null."); //NOI18N } else if (clientProfile.getHealthRestrictions() == null) { throw new NullPointerException("The clientProfile.getHealthRestrictions() is null."); //NOI18N } else if (clientProfile.getPossibleAttendanceRate() == null) { throw new NullPointerException("The clientProfile.getPossibleAttendanceRate() is null."); //NOI18N } else if (clientProfile.getSpecialWishes() == null) { throw new NullPointerException("The clientProfile.getSpecialWishes() is null."); //NOI18N }//ww w. ja v a 2s .c o m getHeightValidator().validate(clientProfile.getHeight()); getWeightValidator().validate(clientProfile.getWeight()); /* * Birthday */ getBirthdayValidator().validate(clientProfile.getBirthday()); if (clientProfile.getBirthday() == null) { clientProfile.setBirthday(new DateMidnight(ClientProfile.DATE_BIRTHDAY_UNKNOWN)); } AdSource adSource = null; if (clientProfile.getAdSourceId() != null) { adSource = em.find(AdSource.class, clientProfile.getAdSourceId()); if (adSource == null) { throw new ValidationException(getString("Invalid.AdSource.ID")); } } /* * Builds an exact copy of the entity, because it's not a good * practive to make entites instances used as DTO managed. */ ClientProfile entityClientProfile = new ClientProfile(clientProfile.getClientId(), ClientProfile.Sex.values()[clientProfile.getSex().ordinal()], clientProfile.getBirthday().toDate(), clientProfile.getAddress(), clientProfile.getTelephone(), clientProfile.getGoal(), clientProfile.getPossibleAttendanceRate(), clientProfile.getHealthRestrictions(), clientProfile.getFavouriteSport(), ClientProfile.FitnessExperience.values()[clientProfile.getFitnessExperience().ordinal()], clientProfile.getSpecialWishes(), clientProfile.getHeight(), clientProfile.getWeight(), adSource); if (em.find(ClientProfile.class, clientProfile.getClientId()) == null) { em.persist(entityClientProfile); } else { em.merge(entityClientProfile); } em.flush(); }
From source file:org.key2gym.business.services.ClientProfilesServiceBean.java
License:Apache License
@Override public ClientProfileDTO getById(Integer id) throws ValidationException { if (id == null) { throw new NullPointerException("The id is null."); //NOI18N }/* w ww . ja v a2s . c o m*/ ClientProfile clientProfile = em.find(ClientProfile.class, id); if (clientProfile == null) { throw new ValidationException(getString("Invalid.Client.ID")); } ClientProfileDTO clientProfileDTO = new ClientProfileDTO(clientProfile.getId(), ClientProfileDTO.Sex.values()[clientProfile.getSex().ordinal()], clientProfile.getBirthday().equals(ClientProfile.DATE_BIRTHDAY_UNKNOWN) ? null : new DateMidnight(clientProfile.getBirthday()), clientProfile.getAddress(), clientProfile.getTelephone(), clientProfile.getGoal(), clientProfile.getPossibleAttendanceRate(), clientProfile.getHealthRestrictions(), clientProfile.getFavouriteSport(), ClientProfileDTO.FitnessExperience.values()[clientProfile.getFitnessExperience().ordinal()], clientProfile.getSpecialWishes(), clientProfile.getHeight(), clientProfile.getWeight(), clientProfile.getAdSource() == null ? null : clientProfile.getAdSource().getId()); return clientProfileDTO; }
From source file:org.key2gym.business.services.ClientsServiceBean.java
License:Apache License
@Override public ClientDTO getById(Integer clientId) throws ValidationException { if (clientId == null) { throw new NullPointerException("The clientId is null."); //NOI18N }//from w ww . j a v a2 s .co m Client client = em.find(Client.class, clientId); if (client == null) { throw new ValidationException(getString("Invalid.Client.ID")); } ClientDTO clientDTO = new ClientDTO(); clientDTO.setId(clientId); clientDTO.setFullName(client.getFullName()); clientDTO.setAttendancesBalance(client.getAttendancesBalance()); clientDTO.setMoneyBalance(client.getMoneyBalance().underlying()); clientDTO.setRegistrationDate(new DateMidnight(client.getRegistrationDate())); clientDTO.setExpirationDate(new DateMidnight(client.getExpirationDate())); clientDTO.setNote(client.getNote()); clientDTO.setCard(client.getCard()); return clientDTO; }
From source file:org.key2gym.business.services.ClientsServiceBean.java
License:Apache License
@Override public List<ClientDTO> findByFullName(String fullName, Boolean exactMatch) throws IllegalArgumentException { if (fullName == null) { throw new IllegalArgumentException("The fullName is null."); //NOI18N }//from ww w.jav a2 s .c o m if (exactMatch == null) { throw new IllegalArgumentException("The exactMatch is null."); //NOI18N } List<Client> clients; if (exactMatch == true) { clients = em.createNamedQuery("Client.findByFullNameExact") //NOI18N .setParameter("fullName", fullName) //NOI18N .getResultList(); } else { clients = em.createNamedQuery("Client.findByFullNameNotExact") //NOI18N .setParameter("fullName", fullName) //NOI18N .getResultList(); //NOI18N } List<ClientDTO> result = new LinkedList<ClientDTO>(); for (Client client : clients) { ClientDTO clientDTO = new ClientDTO(); clientDTO.setId(client.getId()); clientDTO.setFullName(client.getFullName()); clientDTO.setAttendancesBalance(client.getAttendancesBalance()); clientDTO.setMoneyBalance(client.getMoneyBalance().underlying()); clientDTO.setRegistrationDate(new DateMidnight(client.getRegistrationDate())); clientDTO.setExpirationDate(new DateMidnight(client.getExpirationDate())); clientDTO.setNote(client.getNote()); clientDTO.setCard(client.getCard()); result.add(clientDTO); } return result; }
From source file:org.key2gym.business.services.FreezesServiceBean.java
License:Apache License
@Override public void remove(Integer id) throws SecurityViolationException, ValidationException, BusinessException { if (!callerHasRole(SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Operation.Denied")); }// ww w . j a va 2 s.co m if (id == null) { throw new NullPointerException("The id is null."); //NOI18N } ClientFreeze clientFreeze = getEntityManager().find(ClientFreeze.class, id); if (clientFreeze == null) { throw new ValidationException(getString("Invalid.Freeze.ID")); } if (new DateMidnight(clientFreeze.getDateIssued()).plusDays(clientFreeze.getDays()).isBeforeNow()) { throw new BusinessException(getString("BusinessRule.Freeze.AlreadyExpired")); } Client client = clientFreeze.getClient(); client.setExpirationDate( new DateMidnight(client.getExpirationDate()).minusDays(clientFreeze.getDays()).toDate()); // TODO: note change getEntityManager().remove(clientFreeze); getEntityManager().flush(); }
From source file:org.key2gym.business.services.FreezesServiceBean.java
License:Apache License
public FreezeDTO wrapFreeze(ClientFreeze freeze) { FreezeDTO freezeDTO = new FreezeDTO(); freezeDTO.setId(freeze.getId());//from w w w . j a v a 2 s. co m freezeDTO.setAdministratorFullName(freeze.getAdministrator().getFullName()); freezeDTO.setAdministratorId(freeze.getAdministrator().getId()); freezeDTO.setClientFullName(freeze.getClient().getFullName()); freezeDTO.setClientId(freeze.getClient().getId()); freezeDTO.setDateIssued(new DateMidnight(freeze.getDateIssued())); freezeDTO.setDays(freeze.getDays()); freezeDTO.setNote(freeze.getNote()); return freezeDTO; }
From source file:org.key2gym.business.services.OrdersServiceBean.java
License:Apache License
public static OrderDTO wrapOrderEntity(OrderEntity order) { OrderDTO orderDTO = new OrderDTO(); orderDTO.setId(order.getId());/*from ww w. j a va 2 s . co m*/ orderDTO.setDate(new DateMidnight(order.getDate())); orderDTO.setPayment(order.getPayment().setScale(2)); /* * Order lines */ List<OrderLineDTO> orderLineDTOs = new LinkedList<OrderLineDTO>(); BigDecimal total = BigDecimal.ZERO.setScale(2); if (order.getOrderLines() != null) { for (OrderLine orderLine : order.getOrderLines()) { Item item = orderLine.getItem(); Discount discount = orderLine.getDiscount(); OrderLineDTO orderLineDTO = new OrderLineDTO(); orderLineDTO.setId(orderLine.getId()); orderLineDTO.setItemId(item.getId()); orderLineDTO.setItemTitle(item.getTitle()); orderLineDTO.setItemPrice(item.getPrice()); if (discount != null) { orderLineDTO.setDiscountPercent(discount.getPercent()); orderLineDTO.setDiscountTitle(discount.getTitle()); orderLineDTO.setDiscountId(discount.getId()); } orderLineDTO.setQuantity(orderLine.getQuantity()); orderLineDTO.setTotal(orderLine.getTotal()); total = total.add(orderLine.getTotal()); orderLineDTOs.add(orderLineDTO); } } orderDTO.setOrderLines(orderLineDTOs); /* * Client */ if (order.getClient() != null) { orderDTO.setClientId(order.getClient().getId()); orderDTO.setClientFullName(order.getClient().getFullName()); } /* * Attendance */ if (order.getAttendance() != null) { orderDTO.setAttendanceId(order.getAttendance().getId()); orderDTO.setKeyTitle(order.getAttendance().getKey().getTitle()); } /* * Total */ orderDTO.setTotal(total); /* * Due */ orderDTO.setDue(total.subtract(order.getPayment())); /* * Money balance */ if (order.getClient() != null) { orderDTO.setMoneyBalance(order.getClient().getMoneyBalance().setScale(2).underlying()); } return orderDTO; }
From source file:org.key2gym.client.dialogs.PickDateDialog.java
License:Apache License
@Override protected void onOkActionPerformed(ActionEvent evt) { String value = (String) dateComboBox.getSelectedItem(); try {/*from w w w .java 2 s. c o m*/ date = new DateMidnight(new SimpleDateFormat("dd-MM-yyyy").parse(value)); } catch (ParseException ex) { UserExceptionHandler.getInstance() .processException(new ValidationException(getString("Message.DateInvalid"))); return; } super.onOkActionPerformed(evt); }