summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkwilk2010-12-01 18:23:32 (EST)
committer Ryan D. Brooks2010-12-01 18:23:32 (EST)
commit5e51d64f91080047870e3f05f38345410e5dfcb7 (patch)
tree38eaddd434e4855f9c96d2c9af0a44b94b818e92
parente0c27d7d5c5fcd567cd140b46d70f8bedcfd9093 (diff)
downloadorg.eclipse.osee-5e51d64f91080047870e3f05f38345410e5dfcb7.zip
org.eclipse.osee-5e51d64f91080047870e3f05f38345410e5dfcb7.tar.gz
org.eclipse.osee-5e51d64f91080047870e3f05f38345410e5dfcb7.tar.bz2
bug[ats_7QF9T]: Fix ArtifactFactory
Prevent artifacts from being initialized with an invalid guid or hrid
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/DuplicateHridTest.java10
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java22
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactFactory.java42
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeResourceProcessor.java3
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/BinaryContentUtils.java9
5 files changed, 51 insertions, 35 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/DuplicateHridTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/DuplicateHridTest.java
index 96ab6b6..5758e9d 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/DuplicateHridTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/DuplicateHridTest.java
@@ -16,7 +16,7 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.jdk.core.util.HumanReadableId;
-import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.artifact.ArtifactFactory;
import org.eclipse.osee.support.test.util.TestUtil;
import org.junit.Before;
@@ -33,10 +33,10 @@ public class DuplicateHridTest {
public void testDuplicatePrevention() throws OseeCoreException {
String known_duplicate = get_used_HRID();
String random_HRID = generate_random_HRID();
- assertFalse("Duplicate check returned false positive", Artifact.isUniqueHRID(known_duplicate));
- assertTrue("Duplicate check returned false negative", Artifact.isUniqueHRID(random_HRID));
- System.out.println("isUniqueHrid(\"" + known_duplicate + "\") returns " + Artifact.isUniqueHRID(known_duplicate));
- System.out.println("isUnqiueHrid(\"" + random_HRID + "\") returns " + Artifact.isUniqueHRID(random_HRID));
+ assertFalse("Duplicate check returned false positive", ArtifactFactory.isUniqueHRID(known_duplicate));
+ assertTrue("Duplicate check returned false negative", ArtifactFactory.isUniqueHRID(random_HRID));
+ System.out.println("isUniqueHrid(\"" + known_duplicate + "\") returns " + ArtifactFactory.isUniqueHRID(known_duplicate));
+ System.out.println("isUnqiueHrid(\"" + random_HRID + "\") returns " + ArtifactFactory.isUniqueHRID(random_HRID));
}
/* Queries the database and grabs the first HRID it sees */
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java
index 9736a4c..38a60e2 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java
@@ -64,13 +64,11 @@ import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.core.model.type.AttributeType;
import org.eclipse.osee.framework.core.model.type.RelationType;
import org.eclipse.osee.framework.core.services.IAccessControlService;
-import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.database.core.DbTransaction;
import org.eclipse.osee.framework.database.core.OseeConnection;
import org.eclipse.osee.framework.jdk.core.type.HashCollection;
import org.eclipse.osee.framework.jdk.core.type.Pair;
import org.eclipse.osee.framework.jdk.core.util.Collections;
-import org.eclipse.osee.framework.jdk.core.util.HumanReadableId;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLog;
@@ -110,7 +108,7 @@ public class Artifact extends NamedIdentity implements IArtifact, IAdaptable, Co
private final Set<DefaultBasicGuidRelationReorder> relationOrderRecords =
new HashSet<DefaultBasicGuidRelationReorder>();
private final Branch branch;
- private String humanReadableId;
+ private final String humanReadableId;
private ArtifactType artifactType;
private final ArtifactFactory parentFactory;
private AttributeAnnotationManager annotationMgr;
@@ -128,12 +126,7 @@ public class Artifact extends NamedIdentity implements IArtifact, IAdaptable, Co
objectEditState = EditState.NO_CHANGE;
modType = ModificationType.NEW;
- if (humanReadableId == null) {
- populateHumanReadableID();
- } else {
- this.humanReadableId = humanReadableId;
- }
-
+ this.humanReadableId = humanReadableId;
this.parentFactory = parentFactory;
this.branch = branch;
this.artifactType = ArtifactTypeManager.getType(artifactType);
@@ -1262,17 +1255,6 @@ public class Artifact extends NamedIdentity implements IArtifact, IAdaptable, Co
return humanReadableId;
}
- private void populateHumanReadableID() throws OseeCoreException {
- String hrid = HumanReadableId.generate();
- humanReadableId = isUniqueHRID(hrid) ? hrid : HumanReadableId.generate();
- }
-
- public static boolean isUniqueHRID(String id) throws OseeCoreException {
- String DUPLICATE_HRID_SEARCH =
- "select count(1) from (select DISTINCT(art_id) from osee_artifact where human_readable_id = ?) t1";
- return ConnectionHandler.runPreparedQueryFetchLong(0L, DUPLICATE_HRID_SEARCH, id) <= 0;
- }
-
/**
* @return Returns the descriptor.
*/
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactFactory.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactFactory.java
index dd3c21e..6272cd5 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactFactory.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactFactory.java
@@ -16,11 +16,14 @@ import java.util.Collections;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.enums.ModificationType;
-import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
+import org.eclipse.osee.framework.core.util.Conditions;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.framework.jdk.core.util.HumanReadableId;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
/**
* @author Ryan D. Brooks
@@ -39,17 +42,36 @@ public abstract class ArtifactFactory {
this.artifactTypeNames = null;
}
+ public Artifact makeNewArtifact(IOseeBranch branch, IArtifactType artifactTypeToken, String guid, String humandReadableId, ArtifactProcessor earlyArtifactInitialization) throws OseeCoreException {
+ return makeNewArtifact(branch, artifactTypeToken, null, guid, humandReadableId, earlyArtifactInitialization);
+ }
+
/**
* Used to create a new artifact (one that has never been saved into the datastore)
*/
- public Artifact makeNewArtifact(IOseeBranch branch, IArtifactType artifactTypeToken, String guid, String humandReadableId, ArtifactProcessor earlyArtifactInitialization) throws OseeCoreException {
+ public Artifact makeNewArtifact(IOseeBranch branch, IArtifactType artifactTypeToken, String artifactName, String guid, String humanReadableId, ArtifactProcessor earlyArtifactInitialization) throws OseeCoreException {
ArtifactType artifactType = ArtifactTypeManager.getType(artifactTypeToken);
- if (artifactType.isAbstract()) {
- throw new OseeArgumentException("Cannot create an instance of abstract type [%s]", artifactType);
+ Conditions.checkExpressionFailOnTrue(artifactType.isAbstract(),
+ "Cannot create an instance of abstract type [%s]", artifactType);
+
+ if (guid == null) {
+ guid = GUID.create();
+ } else {
+ Conditions.checkExpressionFailOnTrue(!GUID.isValid(guid),
+ "Invalid guid [%s] during artifact creation [name: %s]", guid, artifactName);
}
- Artifact artifact = getArtifactInstance(guid, humandReadableId, BranchManager.getBranch(branch), artifactType);
+ if (humanReadableId == null) {
+ String hrid = HumanReadableId.generate();
+ humanReadableId = ArtifactFactory.isUniqueHRID(hrid) ? hrid : HumanReadableId.generate();
+ } else {
+ Conditions.checkExpressionFailOnTrue(!HumanReadableId.isValid(humanReadableId),
+ "Invalid human readable id [%s] during artifact creation [name: %s, guid: %s]", humanReadableId,
+ artifactName, guid);
+ }
+
+ Artifact artifact = getArtifactInstance(guid, humanReadableId, BranchManager.getBranch(branch), artifactType);
artifact.setArtId(ConnectionHandler.getSequence().getNextArtifactId());
if (earlyArtifactInitialization != null) {
@@ -61,9 +83,19 @@ public abstract class ArtifactFactory {
artifact.onBirth();
artifact.onInitializationComplete();
+ if (Strings.isValid(artifactName)) {
+ artifact.setName(artifactName);
+ }
+
return artifact;
}
+ public static boolean isUniqueHRID(String id) throws OseeCoreException {
+ String DUPLICATE_HRID_SEARCH =
+ "select count(1) from (select DISTINCT(art_id) from osee_artifact where human_readable_id = ?) t1";
+ return ConnectionHandler.runPreparedQueryFetchLong(0L, DUPLICATE_HRID_SEARCH, id) <= 0;
+ }
+
public synchronized Artifact reflectExisitingArtifact(int artId, String guid, String humandReadableId, IArtifactType artifactType, int gammaId, IOseeBranch branch, ModificationType modificationType) throws OseeCoreException {
return internalExistingArtifact(artId, guid, humandReadableId, artifactType, gammaId, branch, modificationType,
false, Artifact.TRANSACTION_SENTINEL);
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeResourceProcessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeResourceProcessor.java
index de73872..aa25ee1 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeResourceProcessor.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeResourceProcessor.java
@@ -14,7 +14,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
-import org.eclipse.osee.framework.core.exception.OseeStateException;
import org.eclipse.osee.framework.skynet.core.artifact.Attribute;
import org.eclipse.osee.framework.skynet.core.attribute.providers.DataStore;
import org.eclipse.osee.framework.skynet.core.attribute.utils.AbstractResourceProcessor;
@@ -50,7 +49,7 @@ public class AttributeResourceProcessor extends AbstractResourceProcessor {
}
@Override
- public String createStorageName() throws OseeStateException {
+ public String createStorageName() throws OseeCoreException {
return BinaryContentUtils.getStorageName(attribute);
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/BinaryContentUtils.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/BinaryContentUtils.java
index 1606f09..4a86e8b 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/BinaryContentUtils.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/BinaryContentUtils.java
@@ -15,7 +15,8 @@ import java.net.URLConnection;
import java.net.URLEncoder;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.exception.OseeStateException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.skynet.core.artifact.Attribute;
@@ -67,7 +68,9 @@ public class BinaryContentUtils {
return fileTypeExtension;
}
- public static String getStorageName(Attribute<?> attribute) throws OseeStateException {
- return attribute.getArtifact().getGuid();
+ public static String getStorageName(Attribute<?> attribute) throws OseeCoreException {
+ String guid = attribute.getArtifact().getGuid();
+ Conditions.checkExpressionFailOnTrue(!GUID.isValid(guid), "Artifact has an invalid guid [%s]", guid);
+ return guid;
}
} \ No newline at end of file