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
|
/*******************************************************************************
* Copyright (c) 2004, 2007 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.framework.core.model;
import org.eclipse.osee.framework.core.enums.BranchState;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.enums.StorageState;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.cache.AbstractOseeCache;
import org.eclipse.osee.framework.core.model.cache.IOseeCache;
import org.eclipse.osee.framework.core.model.cache.IOseeTypeFactory;
import org.eclipse.osee.framework.core.util.Conditions;
/**
* @author Roberto E. Escobar
*/
public class BranchFactory implements IOseeTypeFactory {
public Branch create(String guid, String name, BranchType branchType, BranchState branchState, boolean isArchived) throws OseeCoreException {
Conditions.checkNotNullOrEmpty(name, "branch name");
Conditions.checkNotNull(branchType, "branch type");
Conditions.checkNotNull(branchState, "branch state");
String checkedGuid = Conditions.checkGuidCreateIfNeeded(guid);
Branch toReturn;
if (branchType.isMergeBranch()) {
toReturn = new MergeBranch(checkedGuid, name, branchType, branchState, isArchived);
} else {
toReturn = new Branch(checkedGuid, name, branchType, branchState, isArchived);
}
return toReturn;
}
public Branch createOrUpdate(AbstractOseeCache<String, Branch> cache, String guid, String name, BranchType branchType, BranchState branchState, boolean isArchived) throws OseeCoreException {
Conditions.checkNotNull(cache, "BranchCache");
Branch branch = cache.getByGuid(guid);
if (branch == null) {
branch = create(guid, name, branchType, branchState, isArchived);
cache.cache(branch);
} else {
branch.setName(name);
branch.setArchived(isArchived);
branch.setBranchState(branchState);
branch.setBranchType(branchType);
}
return branch;
}
public Branch createOrUpdate(IOseeCache<String, Branch> cache, int uniqueId, StorageState storageState, String guid, String name, BranchType branchType, BranchState branchState, boolean isArchived) throws OseeCoreException {
Conditions.checkNotNull(cache, "BranchCache");
Branch branch = cache.getById(uniqueId);
if (branch == null) {
branch = create(guid, name, branchType, branchState, isArchived);
branch.setId(uniqueId);
branch.setStorageState(storageState);
cache.cache(branch);
} else {
branch.setName(name);
branch.setArchived(isArchived);
branch.setBranchState(branchState);
branch.setBranchType(branchType);
branch.setStorageState(storageState);
}
return branch;
}
}
|