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
|
/*******************************************************************************
* 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.skynet.core.artifact;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.data.OseeServerContext;
import org.eclipse.osee.framework.core.data.SystemUser;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.enums.CoreTranslatorId;
import org.eclipse.osee.framework.core.enums.Function;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.message.BranchCreationRequest;
import org.eclipse.osee.framework.core.message.BranchCreationResponse;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.skynet.core.event.BranchEventType;
import org.eclipse.osee.framework.skynet.core.event.OseeEventManager;
import org.eclipse.osee.framework.skynet.core.event2.BranchEvent;
import org.eclipse.osee.framework.skynet.core.internal.Activator;
import org.eclipse.osee.framework.skynet.core.utility.DbUtil;
/**
* @author Andrew M. Finkbeiner
*/
public class HttpBranchCreation {
/**
* Creates a new root branch. Should NOT be used outside BranchManager.
*
* @return the newly created branch
* @throws OseeCoreException
*/
public static Branch createBranch(BranchType branchType, int sourceTransactionId, int parentBranchId, String branchName, String branchGuid, Artifact associatedArtifact, String creationComment, int populateBaseTxFromAddressingQueryId, int destinationBranchId) throws OseeCoreException {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("function", Function.CREATE_BRANCH.name());
BranchCreationRequest request =
new BranchCreationRequest(branchType, sourceTransactionId, parentBranchId, branchGuid, branchName,
getAssociatedArtifactId(associatedArtifact), getAuthorId(), creationComment,
populateBaseTxFromAddressingQueryId, destinationBranchId);
BranchCreationResponse response =
HttpClientMessage.send(OseeServerContext.BRANCH_CONTEXT, parameters, CoreTranslatorId.BRANCH_CREATION_REQUEST,
request, CoreTranslatorId.BRANCH_CREATION_RESPONSE);
Branch branch = BranchManager.getBranch(response.getBranchId());
try {
OseeEventManager.kickBranchEvent(HttpBranchCreation.class,
new BranchEvent(BranchEventType.Added, branch.getGuid()), branch.getId());
} catch (OseeCoreException ex) {
OseeLog.log(Activator.class, Level.SEVERE, ex);
}
return branch;
}
private static int getAssociatedArtifactId(Artifact associatedArtifact) throws OseeCoreException {
int associatedArtifactId = -1;
if (associatedArtifact == null && !DbUtil.isDbInit()) {
associatedArtifact = UserManager.getUser(SystemUser.OseeSystem);
}
if (associatedArtifact != null) {
associatedArtifactId = associatedArtifact.getArtId();
}
return associatedArtifactId;
}
private static int getAuthorId() throws OseeCoreException {
return UserManager.getUser().getArtId();
}
}
|