Example #1
0
  public Long save(SectionCFODto bean, Long cfoId) throws AnyServiceException {
    SectionCFO entity = null;
    if (bean.getId() != null) {
      entity = findById(bean.getId());
    } else {
      entity = new SectionCFO();
    }

    /*
     * CFO cfo = null; if (bean.getCfo() == null) throw new
     * AcdpsException("ЦФО не указан!"); cfo =
     * cfoDao.findById(bean.getCfo().getId()); if (cfo == null) throw new
     * AcdpsException("ЦФО не найден!");
     */

    Section section = null;
    if (bean.getSection() == null) throw new AcdpsException("Статья не указана!");
    section = sectionDao.findById(bean.getSection().getId());
    if (section == null) throw new AcdpsException("Статья не найдена!");

    // entity.setCfo(cfo);
    entity.setSection(section);
    entity.setStartDate(
        bean.getStartDate() != null ? bean.getStartDate() : SystemConstants.startDate);
    entity.setEndDate(bean.getEndDate() != null ? bean.getEndDate() : SystemConstants.endDate);

    persist(entity);
    return entity.getId();
  }
Example #2
0
  public SectionCFODto toDto(SectionCFO sectionCfo, boolean full) {

    if (sectionCfo == null) return null;

    SectionCFODto dto =
        new SectionCFODto(
            sectionCfo.getId(),
            sectionDao.toDto(sectionCfo.getSection()),
            sectionCfo.getStartDate(),
            sectionCfo.getEndDate());

    return dto;
  }
Example #3
0
  @SuppressWarnings("unchecked")
  public List<SectionCFODto> getByCfoId(Long cfoId) {

    List<SectionCFODto> result = new ArrayList<SectionCFODto>();

    Query sectionCfoQuery =
        em.createQuery(
            "select sectionCfo from SectionCFO sectionCfo where sectionCfo.cfo.id = :cfoId");
    sectionCfoQuery.setParameter("cfoId", cfoId);

    List<SectionCFO> resultList = sectionCfoQuery.getResultList();

    for (SectionCFO sectionCfo : resultList) {

      // CFO cfo = sectionCfo.getCfo();
      Section section = sectionCfo.getSection();

      CfoDto cfoDto = new CfoDto(sectionCfo.getCfo().getId(), sectionCfo.getCfo().getName());
      SectionDto sectionDto = new SectionDto(section.getId(), section.getName(), section.getCode());

      SectionCFODto dto =
          new SectionCFODto(cfoDto, sectionDto, sectionCfo.getStartDate(), sectionCfo.getEndDate());
      result.add(dto);
    }

    return result;
  }