Skip to main content
summaryrefslogtreecommitdiffstats
blob: e09c751586f4eacbfb023588a84a71ed88da8cf2 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*******************************************************************************
 * Copyright (c) 2013 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.ats.core.client.branch.internal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import org.eclipse.osee.ats.api.IAtsServices;
import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow;
import org.eclipse.osee.ats.core.client.internal.AtsClientService;
import org.eclipse.osee.ats.core.client.team.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.core.util.AbstractAtsBranchService;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.ITransaction;
import org.eclipse.osee.framework.core.enums.BranchArchivedState;
import org.eclipse.osee.framework.core.enums.BranchState;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.exception.MultipleBranchesExist;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.TransactionRecord;
import org.eclipse.osee.framework.core.model.cache.BranchFilter;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.conflict.ConflictManagerExternal;
import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;

/**
 * @author Donald G. Dunne
 */
public class AtsBranchServiceImpl extends AbstractAtsBranchService {

   public AtsBranchServiceImpl(IAtsServices atsServices) {
      super(atsServices);
   }

   /**
    * Return working branch associated with SMA, even if it's been archived; This data is cached across all workflows
    * with the cache being updated by local and remote events. Filters out rebaseline branches (which are working
    * branches also).
    */
   @Override
   public IOseeBranch getWorkingBranchExcludeStates(IAtsTeamWorkflow teamWf, BranchState... negatedBranchStates) {
      BranchFilter branchFilter = new BranchFilter(BranchType.WORKING, BranchType.BASELINE);
      branchFilter.setNegatedBranchStates(negatedBranchStates);
      branchFilter.setAssociatedArtifact((Artifact) teamWf.getStoreObject());

      List<Branch> branches = BranchManager.getBranches(branchFilter);

      if (branches.isEmpty()) {
         return null;
      } else if (branches.size() > 1) {
         throw new MultipleBranchesExist(
            "Unexpected multiple associated un-deleted working branches found for workflow [%s]", teamWf.getAtsId());
      } else {
         return branches.get(0);
      }
   }

   @Override
   public IOseeBranch getCommittedWorkingBranch(IAtsTeamWorkflow teamWf) {
      BranchFilter branchFilter = new BranchFilter(BranchType.WORKING);
      branchFilter.setBranchStates(BranchState.COMMITTED);
      branchFilter.setAssociatedArtifact((Artifact) teamWf.getStoreObject());
      List<Branch> branches = BranchManager.getBranches(branchFilter);
      if (branches.isEmpty()) {
         return null;
      } else if (branches.size() > 1) {
         throw new MultipleBranchesExist(
            "Unexpected multiple associated un-deleted working branches found for workflow [%s]", teamWf.getAtsId());
      } else {
         return branches.get(0);
      }
   }

   @Override
   public BranchType getBranchType(IOseeBranch branch) {
      return BranchManager.getBranchType(branch);
   }

   @Override
   public BranchState getBranchState(IOseeBranch branch) {
      return BranchManager.getState(branch);
   }

   @Override
   public Collection<ITransaction> getCommittedArtifactTransactionIds(IAtsTeamWorkflow teamWf) {
      List<ITransaction> transactions = new ArrayList<ITransaction>();
      for (TransactionRecord trans : TransactionManager.getCommittedArtifactTransactionIds((Artifact) teamWf.getStoreObject())) {
         transactions.add(trans);
      }
      return transactions;
   }

   /**
    * Method available for optimized checking of merge branches so don't have to re-acquire working branch if already
    * have
    */
   @Override
   public boolean isMergeBranchExists(IAtsTeamWorkflow teamWf, IOseeBranch workingBranch, IOseeBranch destinationBranch) throws OseeCoreException {
      if (workingBranch == null) {
         return false;
      }
      return BranchManager.doesMergeBranchExist(workingBranch, destinationBranch);
   }

   public boolean isMergeCompleted(TeamWorkFlowArtifact teamWf, IOseeBranch destinationBranch) throws OseeCoreException {
      ConflictManagerExternal conflictManager =
         new ConflictManagerExternal(destinationBranch, AtsClientService.get().getBranchService().getWorkingBranch(
            teamWf));
      return !conflictManager.remainingConflictsExist();
   }

   @Override
   public IOseeBranch getBranchByUuid(long branchUuid) {
      return BranchManager.getBranch(branchUuid);
   }

   @Override
   public boolean branchExists(long branchUuid) {
      return BranchManager.branchExists(branchUuid);
   }

   @Override
   public BranchArchivedState getArchiveState(IOseeBranch branch) {
      return BranchManager.getBranch(branch).getArchiveState();
   }

   @Override
   public IOseeBranch getBranch(ITransaction transaction) {
      IOseeBranch result = null;
      TransactionRecord txRecord = (TransactionRecord) transaction;
      result = txRecord.getBranch();
      if (result == null) {
         result = TransactionManager.getTransactionId(transaction.getGuid()).getBranch();
      }
      return result;
   }

   @Override
   public Date getTimeStamp(ITransaction transaction) {
      return TransactionManager.getTransactionId(transaction.getGuid()).getTimeStamp();
   }

   @Override
   public IOseeBranch getParentBranch(IOseeBranch destinationBranch) {
      return BranchManager.getBranch(destinationBranch).getParentBranch();
   }

   @Override
   public ITransaction getBaseTransaction(IOseeBranch destinationBranch) {
      return BranchManager.getBranch(destinationBranch).getBaseTransaction();
   }

}

Back to the top