예제 #1
0
  @Override
  public TypeDto createType(TypeDto type) {
    try {
      Type tp = new Type();
      tp.setEind(type.getEind());
      tp.setNaam(type.getNaam());
      tp.setStart(type.getStart());

      em.persist(tp);

      Query result = em.createQuery("select X from Dag");

      @SuppressWarnings("unchecked")
      List<Dag> dag = result.getResultList();

      for (Dag deel : dag) {
        Open open = new Open();
        open.setOpen(false);
        open.setType(tp);
        open.setDag(deel);

        em.persist(open);
      }

      return Convert.TypeToDto(tp);
    } catch (Exception e) {
      API.createIssue(
          "Service SQL exception in createType", "A service SQL exception has encountered", e);
      throw new RuntimeException(e);
    }
  }
예제 #2
0
  @Override
  public DagDto getDagByDate(DagRequest datum) {
    try {
      System.out.println("Getting data for datum: " + datum);
      Query result =
          em.createQuery(
              "select X from Dag as X where dag = :dag and maand = :maand and jaar = :jaar");
      result.setParameter("dag", datum.getDag());
      result.setParameter("maand", datum.getMaand());
      result.setParameter("jaar", datum.getJaar());

      try {
        Dag zt = (Dag) result.getSingleResult();
        return Convert.DagToDto(zt);
      } catch (NoResultException e) {

      }
      System.out.println("Date not exists yet");

      // No date found yet, lets create a standard date (And persist it!)
      Dag dag = new Dag();

      Query rs = em.createQuery("select X from Type as X");

      dag.setDag(datum.getDag());
      dag.setMaand(datum.getMaand());
      dag.setJaar(datum.getJaar());

      em.persist(dag);

      @SuppressWarnings("unchecked")
      List<Type> tp = rs.getResultList();

      Set<Open> op = new HashSet<Open>();
      for (Type deel : tp) {
        Open open = new Open();
        open.setOpen(false);
        open.setType(deel);
        open.setDag(dag);

        op.add(open);

        em.persist(open);
      }
      dag.setOpens(op);
      em.persist(dag);

      System.out.println("size: " + dag.getOpens().size());

      return Convert.DagToDto(dag);
    } catch (Exception e) {
      API.createIssue(
          "Service SQL exception in getDagByDate", "A service SQL exception has encountered", e);
      throw new RuntimeException(e);
    }
  }