private void applyAllocationWithDateChangesNotification(
         IOnTransaction<?> allocationDoer) {
     if (context != null) {
         org.zkoss.ganttz.data.Task ganttTask = context.getTask();
         transactionService.runOnReadOnlyTransaction(allocationDoer);
         ganttTask.enforceDependenciesDueToPositionPotentiallyModified();
     } else {
         // Update hours of a Task from Limiting Resource view
         transactionService.runOnReadOnlyTransaction(allocationDoer);
     }
 }
 PlanningState getPlanningState(final Order order, final Desktop desktop) {
     IAdHocTransactionService transactionService = Registry
             .getTransactionService();
     return transactionService
             .runOnReadOnlyTransaction(new IOnTransaction<PlanningState>() {
                 @Override
                 public PlanningState execute() {
                     return planningStateCreator.retrieveOrCreate(desktop,
                             order);
                 }
             });
 }
  @Test
  @Ignore("FIXME pending review after rename to libreplan")
  public void testAddingOrderElement() {
    final Order order = createValidOrder();
    orderModel.setPlanningState(createPlanningStateFor(order));
    OrderLineGroup container =
        adHocTransaction.runOnTransaction(
            new IOnTransaction<OrderLineGroup>() {
              @Override
              public OrderLineGroup execute() {
                return OrderLineGroup.create();
              }
            });
    order.add(container);
    container.setName("bla");
    container.setCode("code-" + UUID.randomUUID());
    OrderLine leaf = OrderLine.create();
    leaf.setName("leaf");
    leaf.setCode("code-" + UUID.randomUUID());
    container.add(leaf);
    HoursGroup hoursGroup = HoursGroup.create(leaf);
    hoursGroup.setCode("hoursGroupName");
    hoursGroup.setWorkingHours(3);
    leaf.addHoursGroup(hoursGroup);
    orderModel.save();
    adHocTransaction.runOnTransaction(
        new IOnTransaction<Void>() {

          @Override
          public Void execute() {
            try {
              Order reloaded = orderDAO.find(order.getId());
              assertFalse(order == reloaded);
              assertThat(reloaded.getOrderElements().size(), equalTo(1));
              OrderLineGroup containerReloaded =
                  (OrderLineGroup) reloaded.getOrderElements().get(0);
              assertThat(containerReloaded.getHoursGroups().size(), equalTo(1));
              assertThat(containerReloaded.getChildren().size(), equalTo(1));
              OrderElement leaf = containerReloaded.getChildren().get(0);
              assertThat(leaf.getHoursGroups().size(), equalTo(1));
              orderModel.remove(order);
            } catch (InstanceNotFoundException e) {
              throw new RuntimeException(e);
            }
            return null;
          }
        });
  }
 private Order givenOrderWithValidOrderLines() {
   return transactionService.runOnAnotherTransaction(
       new IOnTransaction<Order>() {
         @Override
         public Order execute() {
           return givenValidOrderWithValidOrderLinesAlreadyStored();
         }
       });
 }
  @Test
  @Ignore("FIXME pending review after rename to libreplan")
  public void testManyToManyHoursGroupCriterionMapping() {
    givenCriterion();
    final Order order = createValidOrder();
    orderModel.setPlanningState(createPlanningStateFor(order));

    OrderLine orderLine = OrderLine.create();
    orderLine.setName("Order element");
    orderLine.setCode("000000000");
    order.add(orderLine);

    HoursGroup hoursGroup = HoursGroup.create(orderLine);
    hoursGroup.setCode("hoursGroupName");
    hoursGroup.setWorkingHours(10);
    HoursGroup hoursGroup2 = HoursGroup.create(orderLine);
    hoursGroup2.setCode("hoursGroupName2");
    hoursGroup2.setWorkingHours(5);

    orderLine.addHoursGroup(hoursGroup);
    // orderLine.addHoursGroup(hoursGroup2);

    CriterionRequirement criterionRequirement = DirectCriterionRequirement.create(criterion);

    hoursGroup.addCriterionRequirement(criterionRequirement);
    // hoursGroup2.addCriterionRequirement(criterionRequirement);

    orderModel.save();
    adHocTransaction.runOnTransaction(
        new IOnTransaction<Void>() {

          @Override
          public Void execute() {
            try {
              sessionFactory.getCurrentSession().flush();
              Order reloaded = orderDAO.find(order.getId());
              List<OrderElement> orderElements = reloaded.getOrderElements();
              assertThat(orderElements.size(), equalTo(1));

              List<HoursGroup> hoursGroups = orderElements.get(0).getHoursGroups();
              assertThat(hoursGroups.size(), equalTo(1));

              Set<CriterionRequirement> criterionRequirements =
                  hoursGroups.get(0).getCriterionRequirements();
              assertThat(criterionRequirements.size(), equalTo(1));

              Set<Criterion> criterions = hoursGroups.get(0).getValidCriterions();
              assertThat(criterions.size(), equalTo(1));

            } catch (InstanceNotFoundException e) {
              throw new RuntimeException(e);
            }
            return null;
          }
        });
  }
  private PlanningState createPlanningStateFor(final Order newOrder) {
    return adHocTransaction.runOnAnotherReadOnlyTransaction(
        new IOnTransaction<PlanningState>() {

          @Override
          public PlanningState execute() {
            return planningStateCreator.createOn(mockDesktop(), newOrder);
          }
        });
  }
Exemple #7
0
  @Test
  public void thereIsNoOtherIfItsTheSame() {
    Criterion c =
        transactionService.runOnTransaction(
            new IOnTransaction<Criterion>() {

              @Override
              public Criterion execute() {
                return givenASavedCriterionWithAnExistentType();
              }
            });
    assertFalse(criterionDAO.thereIsOtherWithSameNameAndType(c));
  }
Exemple #8
0
  @Test
  public void thereIsOtherWithSameNameAndTypeWorksIsolatedFromCurrentTransaction() {
    transactionService.runOnTransaction(
        new IOnTransaction<Void>() {

          @Override
          public Void execute() {
            Criterion saved = givenASavedCriterionWithAnExistentType();
            assertFalse(criterionDAO.thereIsOtherWithSameNameAndType(saved));
            return null;
          }
        });
  }
Exemple #9
0
  @Test
  public void ifItsDifferentThereIsOther() {
    Criterion c =
        transactionService.runOnTransaction(
            new IOnTransaction<Criterion>() {

              @Override
              public Criterion execute() {
                return givenASavedCriterionWithAnExistentType();
              }
            });
    Criterion copy = Criterion.create(c.getName(), c.getType());
    assertTrue(criterionDAO.thereIsOtherWithSameNameAndType(copy));
  }
 private Order givenOrderFromPrepareForCreate() {
   adHocTransaction.runOnAnotherReadOnlyTransaction(
       new IOnTransaction<Void>() {
         @Override
         public Void execute() {
           orderModel.prepareForCreate(mockDesktop());
           return null;
         }
       });
   Order order = orderModel.getOrder();
   order.setName("name");
   order.setCode("code");
   order.setInitDate(new Date());
   order.setCustomer(createValidExternalCompany());
   return order;
 }
  @Before
  public void loadRequiredaData() {

    IOnTransaction<Void> load =
        new IOnTransaction<Void>() {

          @Override
          public Void execute() {
            defaultAdvanceTypesBootstrapListener.loadRequiredData();
            configurationBootstrap.loadRequiredData();
            scenariosBootstrap.loadRequiredData();
            workReportTypeBootstrap.loadRequiredData();
            issues = getJiraIssues();
            return null;
          }
        };

    transactionService.runOnAnotherTransaction(load);
  }
  private Order createValidOrder() {
    Order order = Order.create();
    order.setDescription("description");
    order.setInitDate(year(2000));
    order.setName("name");
    order.setResponsible("responsible");
    order.setCode("code-" + UUID.randomUUID());
    BaseCalendar calendar =
        adHocTransaction.runOnReadOnlyTransaction(
            new IOnTransaction<BaseCalendar>() {

              @Override
              public BaseCalendar execute() {
                BaseCalendar result =
                    configurationDAO.getConfigurationWithReadOnlyTransaction().getDefaultCalendar();
                BaseCalendarModel.forceLoadBaseCalendar(result);
                return result;
              }
            });
    order.setCalendar(calendar);
    return order;
  }
  private void givenCriterion() throws ValidationException {
    this.criterion =
        adHocTransaction.runOnTransaction(
            new IOnTransaction<Criterion>() {

              @Override
              public Criterion execute() {
                CriterionType criterionType = CriterionType.create("test" + UUID.randomUUID(), "");
                criterionType.setResource(ResourceEnum.WORKER);
                criterionTypeDAO.save(criterionType);
                Criterion criterion = Criterion.create("Test" + UUID.randomUUID(), criterionType);

                try {
                  criterionDAO.save(criterion);
                } catch (ValidationException e) {
                  throw new RuntimeException(e);
                }
                return criterion;
              }
            });
    this.criterion.dontPoseAsTransientObjectAnymore();
    this.criterion.getType().dontPoseAsTransientObjectAnymore();
  }
  @Test
  @Ignore("FIXME pending review after rename to libreplan")
  public void testOrderPreserved() throws ValidationException, InstanceNotFoundException {
    final Order order = createValidOrder();
    orderModel.setPlanningState(createPlanningStateFor(order));
    final OrderElement[] containers = new OrderLineGroup[10];
    for (int i = 0; i < containers.length; i++) {
      containers[i] =
          adHocTransaction.runOnTransaction(
              new IOnTransaction<OrderLineGroup>() {
                @Override
                public OrderLineGroup execute() {
                  return OrderLineGroup.create();
                }
              });
      containers[i].setName("bla");
      containers[i].setCode("code-" + UUID.randomUUID());
      order.add(containers[i]);
    }
    OrderLineGroup container = (OrderLineGroup) containers[0];

    final OrderElement[] orderElements = new OrderElement[10];
    for (int i = 0; i < orderElements.length; i++) {
      OrderLine leaf = createValidLeaf("bla");
      orderElements[i] = leaf;
      container.add(leaf);
    }

    for (int i = 1; i < containers.length; i++) {
      OrderLineGroup orderLineGroup = (OrderLineGroup) containers[i];
      OrderLine leaf = createValidLeaf("foo");
      orderLineGroup.add(leaf);
    }

    orderModel.save();
    adHocTransaction.runOnTransaction(
        new IOnTransaction<Void>() {

          @Override
          public Void execute() {
            try {
              Order reloaded = orderDAO.find(order.getId());
              List<OrderElement> elements = reloaded.getOrderElements();
              for (OrderElement orderElement : elements) {
                assertThat(
                    ((OrderLineGroup) orderElement).getIndirectAdvanceAssignments().size(),
                    equalTo(2));
              }
              for (int i = 0; i < containers.length; i++) {
                assertThat(elements.get(i).getId(), equalTo(containers[i].getId()));
              }
              OrderLineGroup container =
                  (OrderLineGroup) reloaded.getOrderElements().iterator().next();
              List<OrderElement> children = container.getChildren();
              for (int i = 0; i < orderElements.length; i++) {
                assertThat(children.get(i).getId(), equalTo(orderElements[i].getId()));
              }
              for (int i = 1; i < containers.length; i++) {
                OrderLineGroup orderLineGroup = (OrderLineGroup) containers[i];
                assertThat(orderLineGroup.getChildren().size(), equalTo(1));
              }
              return null;
            } catch (Exception e) {
              throw new RuntimeException(e);
            }
          }
        });

    orderModel.remove(order);
  }