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
|
/*******************************************************************************
* Copyright (c) 2009 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;
import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import org.eclipse.osee.framework.core.data.ArtifactToken;
import org.eclipse.osee.framework.core.data.ArtifactTypeId;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.enums.CoreArtifactTokens;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.DeletionFlag;
import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
/**
* Simple creation and access point for artifact instances required by the framework
*
* @author Ryan D. Brooks
*/
public final class OseeSystemArtifacts {
public static Artifact getGlobalPreferenceArtifact() throws OseeCoreException {
Artifact artifact =
ArtifactQuery.getArtifactFromToken(CoreArtifactTokens.GlobalPreferences, COMMON, DeletionFlag.EXCLUDE_DELETED);
if (artifact == null) {
artifact = getCachedArtifact(CoreArtifactTypes.GlobalPreferences,
CoreArtifactTypes.GlobalPreferences.getName(), COMMON);
}
return artifact;
}
public static Artifact getDefaultHierarchyRootArtifact(BranchId branch) throws OseeCoreException {
return ArtifactQuery.getArtifactFromToken(CoreArtifactTokens.DefaultHierarchyRoot, branch);
}
public static Artifact createGlobalPreferenceArtifact() throws OseeCoreException {
return ArtifactTypeManager.addArtifact(CoreArtifactTokens.GlobalPreferences, COMMON);
}
/**
* @return the artifact specified by type, name, and branch from the cache if available otherwise the datastore is
* accessed, and finally a new artifact is created if it can not be found
*/
public static Artifact getOrCreateArtifact(ArtifactTypeId artifactType, String artifactName, BranchId branch) throws OseeCoreException {
return getOrCreateCachedArtifact(artifactType, artifactName, branch, null, true);
}
public static Artifact getOrCreateArtifact(ArtifactToken artifactToken, BranchId branch) throws OseeCoreException {
return getOrCreateCachedArtifact(artifactToken.getArtifactType(), artifactToken.getName(), branch,
artifactToken.getGuid(), artifactToken.getUuid(), true);
}
public static Artifact getCachedArtifact(ArtifactTypeId artifactType, String artifactName, BranchId branch) throws OseeCoreException {
return getOrCreateCachedArtifact(artifactType, artifactName, branch, null, false);
}
private static Artifact getOrCreateCachedArtifact(ArtifactTypeId artifactType, String artifactName, BranchId branch, String guid, boolean create) throws OseeCoreException {
return getOrCreateCachedArtifact(artifactType, artifactName, branch, guid, null, create);
}
private static Artifact getOrCreateCachedArtifact(ArtifactTypeId artifactType, String artifactName, BranchId branch, String guid, Long uuid, boolean create) throws OseeCoreException {
Artifact artifact = ArtifactQuery.checkArtifactFromTypeAndName(artifactType, artifactName, branch);
if (artifact == null && create) {
if (Strings.isValid(guid)) {
if (uuid != null && uuid > 0) {
artifact = ArtifactTypeManager.addArtifact(artifactType, branch, artifactName, guid, uuid);
} else {
artifact = ArtifactTypeManager.addArtifact(artifactType, branch, artifactName, guid);
}
artifact.setName(artifactName);
} else {
artifact = ArtifactTypeManager.addArtifact(artifactType, branch, artifactName);
}
}
if (artifact == null) {
throw new ArtifactDoesNotExist("Artifact of type [%s] with name [%s] does not exist on branch [%s]",
artifactType, artifactName, branch);
}
return artifact;
}
}
|