diff options
author | john.r.misinco | 2011-06-02 21:46:24 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2011-06-02 21:46:24 +0000 |
commit | 1d3371c60f951506e8588d1767484ce442a9db72 (patch) | |
tree | 61631ea3bce580aa862e8a500b1303750d3486eb | |
parent | 454d214bdc54d64c553b890bf6d0f8fc948fccb6 (diff) | |
download | org.eclipse.osee-1d3371c60f951506e8588d1767484ce442a9db72.tar.gz org.eclipse.osee-1d3371c60f951506e8588d1767484ce442a9db72.tar.xz org.eclipse.osee-1d3371c60f951506e8588d1767484ce442a9db72.zip |
feature[bgz_348142]: Add getOrCreate method to ArtifactQuery
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 d93ad95a47e..b1dcd3f60ed 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 53e7d0c8a3d..620ed6ac50e 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; + } } |