summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjohn.r.misinco2011-06-02 17:46:24 (EDT)
committer Ryan D. Brooks2011-06-02 17:46:24 (EDT)
commit1d3371c60f951506e8588d1767484ce442a9db72 (patch)
tree61631ea3bce580aa862e8a500b1303750d3486eb
parent454d214bdc54d64c553b890bf6d0f8fc948fccb6 (diff)
downloadorg.eclipse.osee-1d3371c60f951506e8588d1767484ce442a9db72.zip
org.eclipse.osee-1d3371c60f951506e8588d1767484ce442a9db72.tar.gz
org.eclipse.osee-1d3371c60f951506e8588d1767484ce442a9db72.tar.bz2
feature[bgz_348142]: Add getOrCreate method to ArtifactQuery
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/ArtifactQueryTestDemo.java13
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQuery.java18
2 files changed, 31 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/ArtifactQueryTestDemo.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/ArtifactQueryTestDemo.java
index d93ad95..b1dcd3f 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/ArtifactQueryTestDemo.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/ArtifactQueryTestDemo.java
@@ -18,6 +18,8 @@ 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.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
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.BranchManager;
@@ -92,4 +94,15 @@ public class ArtifactQueryTestDemo {
}
Assert.assertTrue("No artifacts on multiple branches found", pass);
}
+
+ @Test
+ public void testGetOrCreate() throws OseeCoreException {
+ String guid = GUID.create();
+ Branch branch = BranchManager.createTopLevelBranch("test branch");
+ Artifact artifact1 = ArtifactQuery.getOrCreate(guid, null, CoreArtifactTypes.GeneralData, branch);
+ Assert.assertNotNull(artifact1);
+ Artifact artifact2 = ArtifactQuery.getOrCreate(guid, null, CoreArtifactTypes.GeneralData, branch);
+ Assert.assertEquals(artifact1, artifact2);
+ BranchManager.deleteBranch(branch);
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQuery.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQuery.java
index 53e7d0c..620ed6a 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQuery.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/search/ArtifactQuery.java
@@ -33,6 +33,7 @@ import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.message.SearchOptions;
import org.eclipse.osee.framework.core.message.SearchRequest;
+import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.TransactionRecord;
import org.eclipse.osee.framework.core.model.event.IBasicGuidArtifact;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
@@ -510,4 +511,21 @@ public class ArtifactQuery {
OseeEventManager.kickLocalArtifactReloadEvent(query, reloadedArts);
return reloadedArts;
}
+
+ public static Artifact getOrCreate(String guid, String hrid, IArtifactType type, IOseeBranch branch) throws OseeCoreException {
+ Artifact artifact = null;
+ try {
+ artifact = ArtifactQuery.getArtifactFromId(guid, branch);
+ } catch (ArtifactDoesNotExist ex) {
+ //do nothing since this is expected if the artifact does not exist
+ }
+ if (artifact == null) {
+ Branch fullBranch = BranchManager.getBranch(branch);
+ artifact = ArtifactTypeManager.addArtifact(type, fullBranch, guid, hrid);
+ }
+ if (artifact == null) {
+ throw new ArtifactDoesNotExist("Artifact of type [%s] does not exist on branch [%s]", type, branch);
+ }
+ return artifact;
+ }
}