Skip to main content
summaryrefslogtreecommitdiffstats
blob: a0fcef45ba7cab0131d6f6b1ebaa47d0e6b931a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2012 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.orcs.core.internal.branch;

import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.TransactionId;
import org.eclipse.osee.framework.core.data.TransactionToken;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.data.CreateBranchData;
import org.eclipse.osee.orcs.search.BranchQuery;
import org.eclipse.osee.orcs.search.QueryFactory;
import org.eclipse.osee.orcs.search.TransactionQuery;

/**
 * @author David W. Miller
 */
public class BranchDataFactory {

   private final QueryFactory queryFactory;

   public BranchDataFactory(QueryFactory queryFactory) {
      this.queryFactory = queryFactory;
   }

   public CreateBranchData createTopLevelBranchData(IOseeBranch branch, ArtifactReadable author) {
      return createBranchData(branch, author, CoreBranches.SYSTEM_ROOT, null, BranchType.BASELINE);
   }

   public CreateBranchData createBaselineBranchData(IOseeBranch branch, ArtifactReadable author, IOseeBranch parent, ArtifactReadable associatedArtifact) {
      return createBranchData(branch, author, parent, associatedArtifact, BranchType.BASELINE);
   }

   public CreateBranchData createWorkingBranchData(IOseeBranch branch, ArtifactReadable author, IOseeBranch parent, ArtifactReadable associatedArtifact) {
      return createBranchData(branch, author, parent, associatedArtifact, BranchType.WORKING);
   }

   private CreateBranchData createBranchData(IOseeBranch branch, ArtifactReadable author, IOseeBranch parent, ArtifactReadable associatedArtifact, BranchType branchType) {
      TransactionQuery txQuery = queryFactory.transactionQuery();
      TransactionId fromTx = txQuery.andIsHead(parent).getTokens().getExactlyOne();
      String creationComment = String.format("New Branch from %s (%s)", parent.getName(), fromTx);
      return createBranchData(branch, parent, branchType, creationComment, fromTx, author, associatedArtifact, false);
   }

   public CreateBranchData createCopyTxBranchData(IOseeBranch branch, ArtifactReadable author, TransactionId fromTransaction, ArtifactReadable associatedArtifact) throws OseeCoreException {
      return createBranchData(branch, author, fromTransaction, associatedArtifact, BranchType.WORKING, "copied");
   }

   public CreateBranchData createPortBranchData(IOseeBranch branch, ArtifactReadable author, TransactionId fromTransaction, ArtifactReadable associatedArtifact) throws OseeCoreException {
      return createBranchData(branch, author, fromTransaction, associatedArtifact, BranchType.PORT, "ported");
   }

   private CreateBranchData createBranchData(IOseeBranch branch, ArtifactReadable author, TransactionId fromTransaction, ArtifactReadable associatedArtifact, BranchType branchType, String verb) {
      TransactionQuery txQuery = queryFactory.transactionQuery();
      BranchQuery branchQuery = queryFactory.branchQuery();
      TransactionToken fromTx = txQuery.andTxId(fromTransaction).getTokens().getExactlyOne();
      IOseeBranch parent = branchQuery.andIds(fromTx.getBranch()).getResults().getExactlyOne();

      String creationComment = String.format("Transaction %d %s from %s to create Branch %s", fromTransaction.getId(),
         verb, parent.getName(), branch.getName());
      return createBranchData(branch, parent, branchType, creationComment, fromTx, author, associatedArtifact, true);
   }

   private CreateBranchData createBranchData(IOseeBranch branch, BranchId parent, BranchType branchType, String creationComment, TransactionId sysRootHeadTx, ArtifactReadable author, ArtifactReadable associatedArtifact, boolean bCopyTx) {
      CreateBranchData createData = new CreateBranchData();
      createData.setUuid(branch.getUuid());
      createData.setName(branch.getName());
      if (branch.getUuid() > 0) {
         createData.setUuid(branch.getUuid());
      }
      createData.setBranchType(branchType);
      createData.setCreationComment(creationComment);
      createData.setFromTransaction(sysRootHeadTx);
      createData.setUserArtifact(author);
      createData.setAssociatedArtifact(associatedArtifact);
      createData.setTxCopyBranchType(bCopyTx);
      createData.setParentBranch(parent);
      return createData;
   }

}

Back to the top