Example #1
0
  public Offer postOffer(
      String title, String description, String location, String url, Integer companyId) {

    Validate.isTrue(
        companyService.exists(companyId), "Company with Id=" + companyId + " does not exist");

    Offer offer = new Offer();
    offer.setTitle(normalize(title));
    offer.setDescription(normalize(description));
    offer.setLocation(normalize(location));
    offer.setUrl(normalize(url));
    offer.setPublicationDate(new Date());
    offer.setUpdated(new Date());
    offer.setCompanyId(companyId);

    try {
      offerDAO.create(offer);
      return offer;
    } catch (DataIntegrityViolationException e) {
      throw new IllegalArgumentException("Cannot create offer with given parameters", e);
    }
  }
Example #2
0
  public Offer updateOffer(
      Integer id, String title, String description, String location, String url) {

    Offer offer = offerDAO.findById(id);
    Validate.notNull(offer, "Cannot find offer with Id=" + id);

    offer.setTitle(normalize(title));
    offer.setDescription(normalize(description));
    offer.setLocation(normalize(location));
    offer.setUrl(normalize(url));
    offer.setUpdated(new Date());

    try {
      offerDAO.update(offer);
      return offer;
    } catch (DataIntegrityViolationException e) {
      throw new IllegalArgumentException(
          "Cannot update offer #" + id + " with given parameters", e);
    }
  }