Beispiel #1
0
  private void storeIteration(LayoutGroupIteration iteration, Amendment amendment) {
    IterationHistoryToken iterationToken = new IterationHistoryToken();
    iterationToken.setDate(new Date());
    iterationToken.setCoreVersion(amendment);
    iterationToken.setLayoutGroup(iteration.getLayoutGroup());
    iterationToken.setLayoutGroupIterationId(iteration.getId());
    iterationToken.setName(iteration.getName());
    iterationToken.setProjectId(iteration.getContainerId());

    em().merge(iterationToken);
  }
Beispiel #2
0
  /**
   * Creates a new {@link Amendment} for the given {@code project}.
   *
   * @param project The Project instance.
   * @param name Name of the new amendment.
   * @return The created {@link Amendment} instance.
   */
  @Transactional
  public Amendment createAmendment(final Project project, String name) {

    final Amendment amendment = new Amendment();
    amendment.setParentProject(project);
    amendment.setLogFrame(
        project
            .getLogFrame()
            .copy(
                LogFrameCopyContext.toProject(project)
                    .withStrategy(IndicatorCopyStrategy.REFERENCE)));
    amendment.setState(project.getAmendmentState());
    amendment.setName(name);
    amendment.setVersion(project.getAmendmentVersion());
    amendment.setRevision(project.getAmendmentRevision());
    amendment.setDate(new Date());

    em().persist(amendment);

    // Running through every flexible element attached to the project [...] and saving the last
    // history token in the
    // values property.
    // @see GetHistoryHandler
    final List<HistoryToken> historyTokens = new ArrayList<HistoryToken>();

    // Looking for all groups
    final List<LayoutGroup> groups = new ArrayList<LayoutGroup>();
    for (final PhaseModel phaseModel : project.getProjectModel().getPhaseModels()) {
      groups.addAll(phaseModel.getLayout().getGroups());
    }
    groups.addAll(project.getProjectModel().getProjectDetails().getLayout().getGroups());

    // Iterating on groups
    for (final LayoutGroup group : groups) {
      // simple group
      if (!group.getHasIterations()) {
        for (final LayoutConstraint constraint : group.getConstraints()) {
          final FlexibleElement element = constraint.getElement();

          // Since the transformation of amendments into project core
          // versions, every value has to be saved.

          storeValue(project.getId(), element.getId(), null, amendment, historyTokens);
        }
      }

      // iterative group

      List<LayoutGroupIteration> iterations =
          layoutGroupIterationDAO.findByLayoutGroupAndContainer(group.getId(), project.getId(), -1);
      for (LayoutGroupIteration iteration : iterations) {

        storeIteration(iteration, amendment);

        for (final LayoutConstraint constraint : group.getConstraints()) {
          final FlexibleElement element = constraint.getElement();

          // Since the transformation of amendments into project core
          // versions, every value has to be saved.

          storeValue(project.getId(), element.getId(), iteration.getId(), amendment, historyTokens);
        }
      }
    }

    amendment.setValues(historyTokens);
    em().merge(amendment);

    return amendment;
  }