Package org.libreplan.business.orders.entities

Examples of org.libreplan.business.orders.entities.OrderLineGroup$ChildrenManipulator


    }

    @Test
    @Transactional
    public void parentPropertyMustBeSetWhenAddingOrderLineToContainer() {
        OrderLineGroup orderLineGroup = OrderLineGroup.create();
        orderLineGroup.useSchedulingDataFor(TaskTest.mockOrderVersion());
        OrderLine orderLine = OrderLine.create();
        orderLineGroup.add(orderLine);
        assertThat(orderLine.getParent(), equalTo(orderLineGroup));
    }
View Full Code Here


                orderModel.initEdit(order, null);
                order = orderModel.getOrder();

                orderElement = findOrderElement(order, orderElement.getId());

                OrderLineGroup parent = orderElement.getParent();
                parent.remove(orderElement);
                orderElement.detachFromParent();

                if (!parent.isOrder() && parent.getChildren().isEmpty()) {
                    OrderElement newElement = parent.toLeaf();
                    if (!order.isCodeAutogenerated()) {
                        newElement.setCode(UUID.randomUUID().toString());
                    }
                    parent.getParent().replace(parent, newElement);
                    parent.detachFromParent();
                }

                orderModel.save();
            }
View Full Code Here

                return "You cannot remove the order element '"
                        + orderElement.getName()
                        + "' because it or any of its children have tracked expenses in some expenses sheet";
            }

            OrderLineGroup parent = orderElement.getParent();
            if (parent != null && !parent.isOrder()
                    && parent.getChildren().size() == 1) {
                if (orderElementDAO.isAlreadyInUse(parent)) {
                    return "You cannot remove the order element '"
                            + orderElement.getName()
                            + "' because it is the only child of its parent and its parent has tracked time in some work report";
                }
                if (orderElementDAO.hasImputedExpenseSheet(parent.getId())) {
                    return "You cannot remove the order element '"
                            + orderElement.getName()
                            + "' because it is the only child of its parent and its parent has tracked expenses in some expenses sheet";
                }
            }
View Full Code Here

    }

    public void changeAdvanceTypeInParents(final AdvanceType oldType,
            AdvanceType newType, AdvanceAssignment advance) {
        if (getOrderElement() != null) {
            OrderLineGroup parent = getOrderElement().getParent();
            if (parent != null) {
                IndirectAdvanceAssignment oldIndirect = parent
                        .getIndirectAdvanceAssignment(oldType);
                if (oldIndirect != null) {
                    parent.removeIndirectAdvanceAssignment(oldType);
                    IndirectAdvanceAssignment newIndirect = advance
                            .createIndirectAdvanceFor(parent);
                    parent.addIndirectAdvanceAssignment(newIndirect);
                }
            }
        }
    }
View Full Code Here

        orderElements.add(orderElement);
    }

    private void givenOrderLineGroupWithTwoLines() {
        OrderLineGroup orderLineGroup = OrderLineGroup.create();
        orderLineGroup.setCode("default-order-line-group-" + UUID.randomUUID());
        orderLineGroup.setName("default-order-line-group-" + UUID.randomUUID());

        OrderVersion orderVersion = OrderVersion
                .createInitialVersion(scenarioManager.getCurrent());
        orderVersionDAO.save(orderVersion);
        orderLineGroup.useSchedulingDataFor(orderVersion);

        OrderLine orderLine1 = OrderLine
                .createOrderLineWithUnfixedPercentage(100);
        orderLine1.setCode("order-line-1-" + UUID.randomUUID());
        orderLine1.setName("order-line-1-" + UUID.randomUUID());
        orderLine1.getHoursGroups().get(0)
                .setCode("hours-group-1-" + UUID.randomUUID());
        orderLineGroup.add(orderLine1);

        OrderLine orderLine2 = OrderLine
                .createOrderLineWithUnfixedPercentage(100);
        orderLine2.setCode("order-line-2-" + UUID.randomUUID());
        orderLine2.setName("order-line-2-" + UUID.randomUUID());
        orderLine2.getHoursGroups().get(0)
                .setCode("hours-group-2-" + UUID.randomUUID());
        orderLineGroup.add(orderLine2);

        orderElementDAO.save(orderLineGroup);

        orderElements.add(orderLineGroup);
        orderElements.add(orderLine1);
View Full Code Here

                    });
            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);
View Full Code Here

    @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);
                }
View Full Code Here

        assertThat(order.getCriterionRequirements().size(), equalTo(1));
        assertDirectCriterion(order.getCriterionRequirements().iterator()
                .next(), criterion);
        assertThat(order.getWorkHours(), equalTo(150));

        OrderLineGroup container = (OrderLineGroup) order.getChildren().get(0);
        assertThat(container.getCriterionRequirements().size(), equalTo(1));
        assertIndirectCriterion(container.getCriterionRequirements().iterator()
                .next(), criterion);
        assertNotNull(container.getIndirectAdvanceAssignment(advanceType));
        assertThat(container.getWorkHours(), equalTo(150));

        assertThat(container.getChildren().size(), equalTo(2));
        for (OrderElement each : container.getChildren()) {
            if (each.getName().equals("")) {
                assertThat(each.getCriterionRequirements().size(), equalTo(2));
                assertThat(each.getDirectAdvanceAssignments().size(),
                        equalTo(1));
                assertNotNull(each
View Full Code Here

        model.addElement("element", 100);
        OrderLine element = (OrderLine) order.getChildren().get(0);

        model.addElementAt(element, "element2", 50);
        OrderLineGroup container = (OrderLineGroup) order.getChildren().get(0);
        container.setName("container");

        addAnotherCriterionRequirement(container);
        addDirectAdvanceAssignment(container);

        model.addElementAt(container, "element3", 150);

        assertThat(order.getWorkHours(), equalTo(300));

        assertThat(container.getChildren().size(), equalTo(3));
        for (OrderElement each : container.getChildren()) {
            if (each.getName().equals("element3")) {
                assertThat(each.getCriterionRequirements().size(), equalTo(2));
                for (CriterionRequirement criterionRequirement : each
                        .getCriterionRequirements()) {
                    assertTrue(criterionRequirement instanceof IndirectCriterionRequirement);
View Full Code Here

            DuplicateAdvanceAssignmentForOrderElementException {
        model.addElement("element", 100);
        OrderLine element = (OrderLine) order.getChildren().get(0);
        model.addElementAt(element, "element2", 50);

        OrderLineGroup container = (OrderLineGroup) order.getChildren().get(0);
        model.removeNode(container.getChildren().iterator().next());

        element = (OrderLine) container.getChildren().get(0);

        addCriterionRequirement(element);
        addDirectAdvanceAssignment(element);

        // * infoComponent (code, name, description)
        String name = "container";
        container.setName(name);
        String code = "code";
        container.setCode(code);
        String description = "description";
        container.setDescription(description);

        // * initDate
        Date date = new Date();
        container.setInitDate(date);
        // * deadline
        container.setDeadline(date);

        // * directAdvanceAssignments
        addAnotherDirectAdvanceAssignment(container);

        // * materialAssignments
        addMaterialAssignment(container);

        // * labels
        addLabel(container);

        // * taskQualityForms
        addQualityForm(container);

        // * criterionRequirements
        addAnotherCriterionRequirement(container);

        // * template
        addTemplate(container);

        // * externalCode
        String externalCode = "external-code";
        container.setExternalCode(externalCode);

        model.removeNode(element);

        assertTrue(order.getDirectAdvanceAssignments().isEmpty());
        assertNull(order.getIndirectAdvanceAssignment(advanceType));
View Full Code Here

TOP

Related Classes of org.libreplan.business.orders.entities.OrderLineGroup$ChildrenManipulator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.