Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute')
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/Attribute.java326
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeExtensionManager.java136
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeResourceProcessor.java52
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTransactionData.java164
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeType.java212
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTypeManager.java273
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BinaryAttribute.java23
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BinaryBackedAttribute.java30
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BooleanAttribute.java43
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/CharacterBackedAttribute.java31
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/CompressedContentAttribute.java86
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/DateAttribute.java118
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/EnumeratedAttribute.java48
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/FloatingPointAttribute.java53
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/HttpAttributeTagger.java214
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/IntegerAttribute.java53
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/JavaObjectAttribute.java98
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumType.java261
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumTypeManager.java383
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumerationValidation.java53
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/StringAttribute.java48
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/TypeValidityManager.java208
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordAttribute.java122
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordTemplateAttribute.java24
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordWholeDocumentAttribute.java52
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/AbstractAttributeDataProvider.java35
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/ClobAttributeDataProvider.java26
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/DataStore.java118
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/DefaultAttributeDataProvider.java147
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/IAttributeDataProvider.java32
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/IBinaryAttributeDataProvider.java25
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/ICharacterAttributeDataProvider.java24
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/UriAttributeDataProvider.java174
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/AbstractResourceProcessor.java87
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/AttributeURL.java67
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/BinaryContentUtils.java68
36 files changed, 3914 insertions, 0 deletions
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/Attribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/Attribute.java
new file mode 100644
index 00000000000..ab4efc79542
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/Attribute.java
@@ -0,0 +1,326 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.osee.framework.core.enums.ModificationType;
+import org.eclipse.osee.framework.db.connection.DbTransaction;
+import org.eclipse.osee.framework.db.connection.OseeConnection;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.artifact.ArtifactChecks;
+import org.eclipse.osee.framework.skynet.core.artifact.ArtifactModType;
+import org.eclipse.osee.framework.skynet.core.artifact.ArtifactPersistenceManager;
+import org.eclipse.osee.framework.skynet.core.artifact.IArtifactCheck;
+import org.eclipse.osee.framework.skynet.core.attribute.providers.IAttributeDataProvider;
+import org.eclipse.osee.framework.skynet.core.event.OseeEventManager;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public abstract class Attribute<T> {
+ private final AttributeType attributeType;
+ private final Artifact artifact;
+ private IAttributeDataProvider attributeDataProvider;
+ private int attrId;
+ private int gammaId;
+ private boolean dirty;
+ private ModificationType modificationType;
+
+ protected Attribute(AttributeType attributeType, Artifact artifact) {
+ this.attributeType = attributeType;
+ this.artifact = artifact;
+ }
+
+ public void setValue(T value) throws OseeCoreException {
+ if (attributeType.getName().equals("Name") && !value.equals(getValue())) {
+ // Confirm artifact is fit to rename
+ for (IArtifactCheck check : ArtifactChecks.getArtifactChecks()) {
+ IStatus result = check.isRenamable(Arrays.asList(artifact));
+ if (!result.isOK()) {
+ throw new OseeCoreException(result.getMessage());
+ }
+ }
+ }
+
+ if (subClassSetValue(value)) {
+ setDirty();
+ }
+ }
+
+ public boolean setFromString(String value) throws OseeCoreException {
+ if (attributeType.getName().equals("Name") && !value.equals(getValue())) {
+ // Confirm artifact is fit to rename
+ for (IArtifactCheck check : ArtifactChecks.getArtifactChecks()) {
+ IStatus result = check.isRenamable(Arrays.asList(artifact));
+ if (!result.isOK()) {
+ throw new OseeCoreException(result.getMessage());
+ }
+ }
+ }
+
+ boolean response = subClassSetValue(convertStringToValue(value));
+ if (response) {
+ setDirty();
+ }
+ return response;
+ }
+
+ protected abstract T convertStringToValue(String value) throws OseeCoreException;
+
+ public final void initializeToDefaultValue() throws OseeCoreException {
+ setDirty(); // always do this since this is only called when creating an attribute so it should be dirty anyway
+ String defaultValue = getAttributeType().getDefaultValue();
+ if (defaultValue != null) {
+ subClassSetValue(convertStringToValue(defaultValue));
+ }
+ }
+
+ public boolean setValueFromInputStream(InputStream value) throws OseeCoreException {
+ try {
+ boolean response = setFromString(Lib.inputStreamToString(value));
+ if (response) {
+ setDirty();
+ }
+ return response;
+ } catch (IOException ex) {
+ throw new OseeCoreException(ex);
+ }
+ }
+
+ /**
+ * Subclasses must provide an implementation of this method and in general should not override the other set value
+ * methods
+ *
+ * @param value
+ * @throws OseeCoreException
+ */
+ protected abstract boolean subClassSetValue(T value) throws OseeCoreException;
+
+ public abstract T getValue() throws OseeCoreException;
+
+ public String getDisplayableString() throws OseeCoreException {
+ return getAttributeDataProvider().getDisplayableString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ try {
+ builder.append(getDisplayableString());
+ } catch (OseeCoreException ex) {
+ builder.append(Lib.exceptionToString(ex));
+ }
+ return builder.toString();
+ }
+
+ /**
+ * @param attributeDataProvider the attributeDataProvider to set
+ * @throws OseeCoreException
+ */
+ public void setAttributeDataProvider(IAttributeDataProvider attributeDataProvider) throws OseeCoreException {
+ this.attributeDataProvider = attributeDataProvider;
+ }
+
+ public IAttributeDataProvider getAttributeDataProvider() {
+ return attributeDataProvider;
+ }
+
+ /**
+ * @return <b>true</b> if this attribute is dirty
+ */
+ public boolean isDirty() {
+ return dirty;
+ }
+
+ protected void setDirty() {
+ dirty = true;
+
+ // Kick Local Event
+ try {
+ OseeEventManager.kickArtifactModifiedEvent(this, ArtifactModType.Changed, artifact);
+ } catch (Exception ex) {
+ // do nothing
+ }
+ }
+
+ public void setNotDirty() {
+ dirty = false;
+ }
+
+ public Artifact getArtifact() {
+ return artifact;
+ }
+
+ /**
+ * @return the attribute name/value description
+ */
+ public String getNameValueDescription() {
+ return attributeType.getName() + ": " + toString();
+ }
+
+ /**
+ * @return attributeType Attribute Type Information
+ */
+ public AttributeType getAttributeType() {
+ return attributeType;
+ }
+
+ /**
+ * Currently this method provides support for quasi attribute type inheritance
+ *
+ * @param artifactType
+ * @return whether this attribute's type or any of its super-types are the specified type
+ */
+ public boolean isOfType(String otherAttributeTypeName) {
+ String attributeTypeName = attributeType.getName();
+ return attributeTypeName.equals(otherAttributeTypeName);
+ }
+
+ /**
+ * Currently this method provides support for quasi attribute type inheritance
+ *
+ * @param artifactType
+ * @return whether this attribute's type or any of its super-types are the specified type
+ */
+ public boolean isOfType(AttributeType otherAttributeType) {
+ return attributeType.equals(otherAttributeType);
+ }
+
+ public void resetModType() {
+ this.modificationType = null;
+ }
+
+ /**
+ * Deletes the attribute
+ */
+ public final void setArtifactDeleted() {
+ setDeleteOrArtifactDeleted(ModificationType.ARTIFACT_DELETED);
+ }
+
+ /**
+ * Deletes the attribute
+ */
+ public final void delete() {
+ setDeleteOrArtifactDeleted(ModificationType.DELETED);
+ }
+
+ private final void setDeleteOrArtifactDeleted(ModificationType modificationType) {
+ this.modificationType = modificationType;
+ setDirty();
+ }
+
+ /**
+ * @return the modificationType Warning ... This is only currently being set for delete and artifact deleted.
+ */
+ public ModificationType getModificationType() {
+ return modificationType;
+ }
+
+ public boolean canDelete() {
+ try {
+ return artifact.getAttributeCount(attributeType.getName()) > attributeType.getMinOccurrences();
+ } catch (OseeCoreException ex) {
+ return false;
+ }
+ }
+
+ /**
+ * Purges the attribute from the database.
+ */
+ public void purge() throws OseeCoreException {
+ getAttributeDataProvider().purge();
+ }
+
+ public void markAsPurged() {
+ modificationType = ModificationType.DELETED;
+ dirty = false;
+ }
+
+ /**
+ * @return true if in data store
+ */
+ public boolean isInDb() {
+ return getGammaId() > 0;
+ }
+
+ /**
+ * @return Returns the attrId.
+ */
+ public int getAttrId() {
+ return attrId;
+ }
+
+ public int getGammaId() {
+ return gammaId;
+ }
+
+ public void internalSetGammaId(int gammaId) {
+ this.gammaId = gammaId;
+ }
+
+ public void internalSetAttributeId(int attrId) {
+ this.attrId = attrId;
+ }
+
+ /**
+ * @return the deleted
+ */
+ public boolean isDeleted() {
+ return this.modificationType == ModificationType.DELETED || this.modificationType == ModificationType.ARTIFACT_DELETED;
+ }
+
+ /**
+ * Called from remote events to mark this attribute as deleted
+ */
+ public void internalSetDeleted() {
+ this.modificationType = ModificationType.DELETED;
+ this.dirty = false;
+ }
+
+ public void revert() throws OseeCoreException {
+ DbTransaction dbTransaction = new DbTransaction() {
+ @Override
+ protected void handleTxWork(OseeConnection connection) throws OseeCoreException {
+ ArtifactPersistenceManager.revertAttribute(connection, Attribute.this);
+ }
+ };
+ dbTransaction.execute();
+ }
+
+ public static Attribute<?> initializeAttribute(Artifact artifact, int atttributeTypeId, int attributeId, int gammaId, Object... data) throws OseeCoreException {
+ return initializeAttribute(artifact, atttributeTypeId, attributeId, gammaId, null, false, data);
+ }
+
+ public static Attribute<?> initializeAttribute(Artifact artifact, int atttributeTypeId, int attributeId, int gammaId, ModificationType modificationType, boolean markDirty, Object... data) throws OseeCoreException {
+ AttributeType attributeType = AttributeTypeManager.getType(atttributeTypeId);
+ Attribute<?> attribute = artifact.createAttribute(attributeType, false);
+ attribute.getAttributeDataProvider().loadData(data);
+ attribute.internalSetAttributeId(attributeId);
+ attribute.internalSetGammaId(gammaId);
+
+ if (modificationType == ModificationType.DELETED) {
+ attribute.internalSetDeleted();
+ }
+
+ attribute.dirty = markDirty;
+ return attribute;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeExtensionManager.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeExtensionManager.java
new file mode 100644
index 00000000000..f1c06586722
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeExtensionManager.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.osee.framework.db.connection.exception.OseeArgumentException;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeStateException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.plugin.core.util.ExtensionPoints;
+import org.eclipse.osee.framework.skynet.core.attribute.providers.AbstractAttributeDataProvider;
+import org.eclipse.osee.framework.skynet.core.internal.Activator;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AttributeExtensionManager {
+ private static final String CLASS_ID = "class";
+ private static final String ATTRIBUTE_TYPE = Activator.PLUGIN_ID + ".AttributeType";
+ private static final String ATTRIBUTE_DATA_PROVIDER_TYPE = Activator.PLUGIN_ID + ".AttributeDataProvider";
+
+ private static final String[] attributeBaseTypes =
+ new String[] {"CharacterBackedAttributeType", "BinaryBackedAttributeType"};
+ private static final String[] attributeProviderBaseTypes =
+ new String[] {"CharacterAttributeDataProvider", "BinaryAttributeDataProvider"};
+
+ private static final AttributeExtensionManager instance = new AttributeExtensionManager();
+
+ private Map<String, Pair<String, String>> attributeTypeClasses;
+ private Map<String, Pair<String, String>> attributeDataProviderClasses;
+
+ private AttributeExtensionManager() {
+ this.attributeTypeClasses = null;
+ this.attributeDataProviderClasses = null;
+ }
+
+ public static Class<? extends Attribute<?>> getAttributeClassFor(String name) throws OseeCoreException {
+ if (instance.attributeTypeClasses == null) {
+ instance.attributeTypeClasses = instance.loadExtensions(ATTRIBUTE_TYPE, attributeBaseTypes, CLASS_ID);
+ }
+
+ Pair<String, String> entry = instance.attributeTypeClasses.get(name);
+ if (entry == null) {
+ throw new OseeArgumentException(String.format("Unable to find class for: [%s]", name));
+ }
+
+ return instance.loadClass(entry.getKey(), entry.getValue());
+ }
+
+ public static Class<? extends AbstractAttributeDataProvider> getAttributeProviderClassFor(String name) throws OseeCoreException {
+ if (instance.attributeDataProviderClasses == null) {
+ instance.attributeDataProviderClasses =
+ instance.loadExtensions(ATTRIBUTE_DATA_PROVIDER_TYPE, attributeProviderBaseTypes, CLASS_ID);
+ }
+ Pair<String, String> entry = instance.attributeDataProviderClasses.get(name);
+ if (entry == null) {
+ throw new OseeArgumentException(String.format("Unable to find class for: [%s]", name));
+ }
+ return instance.loadClass(entry.getKey(), entry.getValue());
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> Class<T> loadClass(String bundleName, String className) throws OseeWrappedException {
+ Class<T> toReturn = null;
+ try {
+ Bundle bundle = Platform.getBundle(bundleName);
+ toReturn = bundle.loadClass(className);
+ } catch (ClassNotFoundException ex) {
+ throw new OseeWrappedException(String.format("Unable to Load: [%s - %s]", bundleName, className), ex);
+ }
+ return toReturn;
+ }
+
+ private Map<String, Pair<String, String>> loadExtensions(String extensionPointId, String[] elementNames, String classNameAttribute) throws OseeStateException {
+ Map<String, Pair<String, String>> toReturn = new HashMap<String, Pair<String, String>>();
+ for (String elementName : elementNames) {
+ List<IConfigurationElement> elements = ExtensionPoints.getExtensionElements(extensionPointId, elementName);
+ for (IConfigurationElement element : elements) {
+ IExtension extension = ((IExtension) element.getParent());
+ String name = extension.getUniqueIdentifier();
+ String className = element.getAttribute(classNameAttribute);
+ String bundleName = element.getContributor().getName();
+
+ if (Strings.isValid(bundleName) && Strings.isValid(className)) {
+ toReturn.put(name, new Pair<String, String>(bundleName, className));
+ }
+ }
+ }
+ if (toReturn.size() == 0) {
+ throw new OseeStateException(String.format(
+ "No Objects loaded for [%s] with element names [%s] and attribute [%s]", extensionPointId, elementNames,
+ classNameAttribute));
+ }
+ return toReturn;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return super.toString();
+ }
+
+ public static Set<String> getAttributeProviders() throws OseeStateException {
+ if (instance.attributeDataProviderClasses == null) {
+ instance.attributeDataProviderClasses =
+ instance.loadExtensions(ATTRIBUTE_DATA_PROVIDER_TYPE, attributeProviderBaseTypes, CLASS_ID);
+ }
+ return instance.attributeDataProviderClasses.keySet();
+ }
+
+ public static Set<String> getAttributeClasses() throws OseeStateException {
+ if (instance.attributeTypeClasses == null) {
+ instance.attributeTypeClasses = instance.loadExtensions(ATTRIBUTE_TYPE, attributeBaseTypes, CLASS_ID);
+ }
+ return instance.attributeTypeClasses.keySet();
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeResourceProcessor.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeResourceProcessor.java
new file mode 100644
index 00000000000..eb220b15553
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeResourceProcessor.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import org.eclipse.osee.framework.core.exception.OseeAuthenticationRequiredException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.skynet.core.attribute.providers.DataStore;
+import org.eclipse.osee.framework.skynet.core.attribute.utils.AbstractResourceProcessor;
+import org.eclipse.osee.framework.skynet.core.attribute.utils.AttributeURL;
+
+public class AttributeResourceProcessor extends AbstractResourceProcessor {
+
+ private final Attribute<?> attribute;
+
+ public AttributeResourceProcessor(Attribute<?> attribute) {
+ this.attribute = attribute;
+ }
+
+ protected URL getAcquireURL(DataStore dataToStore) throws OseeDataStoreException {
+ return AttributeURL.getAcquireURL(dataToStore.getLocator());
+ }
+
+ protected URL getDeleteURL(DataStore dataToStore) throws OseeDataStoreException {
+ return AttributeURL.getDeleteURL(dataToStore.getLocator());
+ }
+
+ protected URL getStorageURL(int seed, String name, String extension) throws OseeDataStoreException, OseeAuthenticationRequiredException {
+ try {
+ return AttributeURL.getStorageURL(seed, name, extension);
+ } catch (MalformedURLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.utils.AbstractResourceProcessor#getStorageName()
+ */
+ @Override
+ public String getStorageName() {
+ return attribute.getArtifact().getHumanReadableId();
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTransactionData.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTransactionData.java
new file mode 100644
index 00000000000..fbbdbcfc480
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTransactionData.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.data.OseeSql;
+import org.eclipse.osee.framework.core.enums.ModificationType;
+import org.eclipse.osee.framework.db.connection.core.SequenceManager;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.jdk.core.util.HttpProcessor;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.skynet.core.artifact.ArtifactCache;
+import org.eclipse.osee.framework.skynet.core.artifact.StaticIdManager;
+import org.eclipse.osee.framework.skynet.core.attribute.utils.AttributeURL;
+import org.eclipse.osee.framework.skynet.core.event.ArtifactTransactionModifiedEvent;
+import org.eclipse.osee.framework.skynet.core.transaction.BaseTransactionData;
+import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
+import org.eclipse.osee.framework.skynet.core.transaction.TransactionId;
+
+/**
+ * @author Jeff C. Phillips
+ * @author Roberto E. Escobar
+ */
+public class AttributeTransactionData extends BaseTransactionData {
+ private static final String INSERT_ATTRIBUTE =
+ "INSERT INTO osee_attribute (art_id, attr_id, attr_type_id, value, gamma_id, uri, modification_id) VALUES (?, ?, ?, ?, ?, ?, ?)";
+
+ private final Attribute<?> attribute;
+ private final DAOToSQL daoToSql;
+
+ public AttributeTransactionData(Attribute<?> attribute, ModificationType modificationType) throws OseeDataStoreException {
+ super(attribute.getAttrId(), modificationType, attribute.getArtifact().isReflected() || modificationType == ModificationType.ARTIFACT_DELETED);
+ this.attribute = attribute;
+ this.daoToSql = new DAOToSQL();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.transaction.ITransactionData#getSelectTxNotCurrentSql()
+ */
+ @Override
+ public String getSelectTxNotCurrentSql() {
+ return OseeSql.Transaction.SELECT_PREVIOUS_TX_NOT_CURRENT_ATTRIBUTES;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.transaction.BaseTransactionData#addInsertToBatch(org.eclipse.osee.framework.jdk.core.type.HashCollection)
+ */
+ @Override
+ protected void addInsertToBatch(SkynetTransaction transaction) throws OseeCoreException {
+ super.addInsertToBatch(transaction);
+ if (!useExistingBackingData()) {
+ if (getModificationType() == ModificationType.MODIFIED || getModificationType() == ModificationType.NEW) {
+ attribute.getAttributeDataProvider().persist(getGammaId());
+ daoToSql.setData(attribute.getAttributeDataProvider().getData());
+ }
+ internalAddInsertToBatch(transaction, 3, INSERT_ATTRIBUTE, attribute.getArtifact().getArtId(), getItemId(),
+ attribute.getAttributeType().getAttrTypeId(), daoToSql.getValue(), getGammaId(), daoToSql.getUri(),
+ getModificationType().getValue());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.transaction.BaseTransactionData#internalUpdate()
+ */
+ @Override
+ protected void internalUpdate(TransactionId transactionId) throws OseeCoreException {
+ attribute.internalSetGammaId(getGammaId());
+
+ if (attribute.isOfType(StaticIdManager.STATIC_ID_ATTRIBUTE)) {
+ ArtifactCache.cacheByStaticId((String) attribute.getValue(), attribute.getArtifact());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.transaction.BaseTransactionData#internalClearDirtyState()
+ */
+ @Override
+ protected void internalClearDirtyState() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.transaction.BaseTransactionData#internalOnRollBack()
+ */
+ @Override
+ protected void internalOnRollBack() throws OseeCoreException {
+ if (Strings.isValid(daoToSql.getUri())) {
+ try {
+ HttpProcessor.delete(AttributeURL.getDeleteURL(daoToSql.getUri()));
+ } catch (Exception ex) {
+ throw new OseeWrappedException(ex);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.transaction.BaseTransactionData#createGammaId()
+ */
+ @Override
+ protected int createGammaId() throws OseeCoreException {
+ int newGammaId = 0;
+ if (useExistingBackingData()) {
+ newGammaId = attribute.getGammaId();
+ } else {
+ newGammaId = SequenceManager.getNextGammaId();
+ }
+ return newGammaId;
+ }
+
+ private final class DAOToSQL {
+ private String uri;
+ private String value;
+
+ public DAOToSQL(Object... data) {
+ if (data != null) {
+ setData(data);
+ } else {
+ uri = null;
+ value = null;
+ }
+ }
+
+ public void setData(Object... data) {
+ this.uri = getItemAt(1, data);
+ this.value = getItemAt(0, data);
+ }
+
+ private String getItemAt(int index, Object... data) {
+ String toReturn = null;
+ if (data != null && data.length > index) {
+ Object obj = data[index];
+ if (obj != null) {
+ toReturn = obj.toString();
+ }
+ }
+ return toReturn;
+ }
+
+ public String getUri() {
+ return uri != null ? uri : "";
+ }
+
+ public String getValue() {
+ return value != null ? value : "";
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.transaction.BaseTransactionData#internalAsModifiedEvent(org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction)
+ */
+ @Override
+ protected void internalAddToEvents(Collection<ArtifactTransactionModifiedEvent> events) throws OseeCoreException {
+ // Do Nothing - handled by artifact transaction data
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeType.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeType.java
new file mode 100644
index 00000000000..80aff842a69
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeType.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.skynet.core.attribute.providers.IAttributeDataProvider;
+
+/**
+ * Type information for dynamic attributes.
+ *
+ * @author Robert A. Fisher
+ * @author Ryan D. Brooks
+ */
+public class AttributeType implements Comparable<AttributeType> {
+ public static final AttributeType[] EMPTY_ARRAY = new AttributeType[0];
+ private Class<? extends Attribute<?>> baseAttributeClass;
+ private Class<? extends IAttributeDataProvider> providerAttributeClass;
+ private int attrTypeId;
+ private String namespace;
+ private String name;
+ private String defaultValue;
+ private int oseeEnumTypeId;
+ private int maxOccurrences;
+ private int minOccurrences;
+ private String tipText;
+ private String fileTypeExtension;
+ private String taggerId;
+
+ /**
+ * Create a dynamic attribute descriptor. Descriptors can be acquired for application use from the
+ * <code>ConfigurationPersistenceManager</code>.
+ *
+ * @param baseAttributeClass
+ * @param name
+ * @param defaultValue
+ * @param validityXml
+ * @param minOccurrences
+ * @param maxOccurrences
+ * @param tipText
+ */
+ protected AttributeType(int attrTypeId, Class<? extends Attribute<?>> baseAttributeClass, Class<? extends IAttributeDataProvider> providerAttributeClass, String fileTypeExtension, String namespace, String name, String defaultValue, int oseeEnumTypeId, int minOccurrences, int maxOccurrences, String tipText, String taggerId) {
+ if (minOccurrences < 0) {
+ throw new IllegalArgumentException("minOccurrences must be greater than or equal to zero");
+ }
+ if (maxOccurrences < minOccurrences) {
+ throw new IllegalArgumentException("maxOccurences can not be less than minOccurences");
+ }
+
+ this.attrTypeId = attrTypeId;
+ this.baseAttributeClass = baseAttributeClass;
+ this.providerAttributeClass = providerAttributeClass;
+ this.namespace = namespace == null ? "" : namespace;
+ this.name = name;
+ this.defaultValue = defaultValue;
+ this.oseeEnumTypeId = oseeEnumTypeId;
+ this.maxOccurrences = maxOccurrences;
+ this.minOccurrences = minOccurrences;
+ this.tipText = tipText;
+ this.fileTypeExtension = fileTypeExtension != null ? fileTypeExtension : "";
+ this.taggerId = taggerId;
+ }
+
+ /**
+ * @return Returns the attrTypeId.
+ */
+ public int getAttrTypeId() {
+ return attrTypeId;
+ }
+
+ /**
+ * @return Returns the baseAttributeClass.
+ */
+ public Class<? extends Attribute<?>> getBaseAttributeClass() {
+ return baseAttributeClass;
+ }
+
+ /**
+ * @return Returns the defaultValue.
+ */
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ /**
+ * @return Returns the maxOccurrences.
+ */
+ public int getMaxOccurrences() {
+ return maxOccurrences;
+ }
+
+ /**
+ * @return Returns the minOccurrences.
+ */
+ public int getMinOccurrences() {
+ return minOccurrences;
+ }
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the namespace
+ */
+ public String getNamespace() {
+ return namespace;
+ }
+
+ /**
+ * @return Returns the tipText.
+ */
+ public String getTipText() {
+ return tipText;
+ }
+
+ /**
+ * @return Returns the validityXml.
+ */
+ public int getOseeEnumTypeId() {
+ return oseeEnumTypeId;
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public String getFileTypeExtension() {
+ return fileTypeExtension;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ final AttributeType other = (AttributeType) obj;
+ if (name == null) {
+ if (other.name != null) return false;
+ } else if (!name.equals(other.name)) return false;
+ if (namespace == null) {
+ if (other.namespace != null) return false;
+ } else if (!namespace.equals(other.namespace)) return false;
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(T)
+ */
+ public int compareTo(AttributeType attributeType) {
+ if (attributeType == null) {
+ return -1;
+ }
+ return name.compareTo(attributeType.name);
+ }
+
+ /**
+ * @return the providerAttributeClass
+ */
+ public Class<? extends IAttributeDataProvider> getProviderAttributeClass() {
+ return providerAttributeClass;
+ }
+
+ /**
+ * Get the registered tagger id for this attribute type
+ *
+ * @return tagger id
+ */
+ public String getTaggerId() {
+ return taggerId;
+ }
+
+ /**
+ * Whether this attribute type is taggable.
+ *
+ * @return <b>true</b> if this attribute type is taggable. <b>false</b> if this is not taggable.
+ */
+ public boolean isTaggable() {
+ boolean toReturn = false;
+ if (taggerId != null) {
+ toReturn = Strings.isValid(taggerId.trim());
+ }
+ return toReturn;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTypeManager.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTypeManager.java
new file mode 100644
index 00000000000..e61b2a57975
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTypeManager.java
@@ -0,0 +1,273 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import static org.eclipse.osee.framework.db.connection.core.schema.SkynetDatabase.ATTRIBUTE_BASE_TYPE_TABLE;
+import static org.eclipse.osee.framework.db.connection.core.schema.SkynetDatabase.ATTRIBUTE_PROVIDER_TYPE_TABLE;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.ConnectionHandler;
+import org.eclipse.osee.framework.db.connection.ConnectionHandlerStatement;
+import org.eclipse.osee.framework.db.connection.core.SequenceManager;
+import org.eclipse.osee.framework.db.connection.exception.OseeArgumentException;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeTypeDoesNotExist;
+import org.eclipse.osee.framework.db.connection.info.SQL3DataType;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.skynet.core.attribute.providers.IAttributeDataProvider;
+import org.eclipse.osee.framework.skynet.core.internal.Activator;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class AttributeTypeManager {
+
+ private static final String SELECT_ATTRIBUTE_TYPES =
+ "SELECT * FROM osee_attribute_type aty1, osee_attribute_base_type aby1, osee_attribute_provider_type apy1 WHERE aty1.attr_base_type_id = aby1.attr_base_type_id AND aty1.attr_provider_type_id = apy1.attr_provider_type_id";
+ private static final String INSERT_ATTRIBUTE_TYPE =
+ "INSERT INTO osee_attribute_type (attr_type_id, attr_base_type_id, attr_provider_type_id, file_type_extension, namespace, name, default_value, enum_type_id, min_occurence, max_occurence, tip_text, tagger_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
+ private static final String INSERT_BASE_ATTRIBUTE_TYPE =
+ "INSERT INTO osee_attribute_base_type (attr_base_type_id, attribute_class) VALUES (?, ?)";
+ private static final String INSERT_ATTRIBUTE_PROVIDER_TYPE =
+ "INSERT INTO osee_attribute_provider_type (attr_provider_type_id, attribute_provider_class) VALUES (?, ?)";
+ private static final String SELECT_ATTRIBUTE_BASE_TYPE =
+ "SELECT attr_base_type_id FROM " + ATTRIBUTE_BASE_TYPE_TABLE + " WHERE attribute_class = ?";
+ private static final String SELECT_ATTRIBUTE_PROVIDER_TYPE =
+ "SELECT attr_provider_type_id FROM " + ATTRIBUTE_PROVIDER_TYPE_TABLE + " WHERE attribute_provider_class = ?";
+
+ private final HashMap<String, AttributeType> nameToTypeMap;
+ private final HashMap<Integer, AttributeType> idToTypeMap;
+ private static final AttributeTypeManager instance = new AttributeTypeManager();
+
+ private AttributeTypeManager() {
+ this.nameToTypeMap = new HashMap<String, AttributeType>();
+ this.idToTypeMap = new HashMap<Integer, AttributeType>();
+ }
+
+ private static synchronized void ensurePopulated() throws OseeDataStoreException {
+ if (instance.idToTypeMap.size() == 0) {
+ instance.populateCache();
+ }
+ }
+
+ private void populateCache() throws OseeDataStoreException {
+ ConnectionHandlerStatement chStmt = new ConnectionHandlerStatement();
+
+ try {
+ chStmt.runPreparedQuery(SELECT_ATTRIBUTE_TYPES);
+
+ while (chStmt.next()) {
+ String baseClassString = chStmt.getString("attribute_class");
+ String baseProviderClassString = chStmt.getString("attribute_provider_class");
+ try {
+ Class<? extends Attribute<?>> baseAttributeClass =
+ AttributeExtensionManager.getAttributeClassFor(baseClassString);
+ Class<? extends IAttributeDataProvider> providerAttributeClass =
+ AttributeExtensionManager.getAttributeProviderClassFor(baseProviderClassString);
+ AttributeType type =
+ new AttributeType(chStmt.getInt("attr_type_id"), baseAttributeClass, providerAttributeClass,
+ chStmt.getString("file_type_extension"), chStmt.getString("namespace"),
+ chStmt.getString("name"), chStmt.getString("default_value"), chStmt.getInt("enum_type_id"),
+ chStmt.getInt("min_occurence"), chStmt.getInt("max_occurence"),
+ chStmt.getString("tip_text"), chStmt.getString("tagger_id"));
+ cache(type);
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ }
+ } finally {
+ chStmt.close();
+ }
+ }
+
+ public static Collection<AttributeType> getAllTypes() throws OseeDataStoreException {
+ ensurePopulated();
+ return instance.idToTypeMap.values();
+ }
+
+ public static Collection<AttributeType> getTaggableTypes() throws OseeDataStoreException {
+ ensurePopulated();
+ Collection<AttributeType> taggableTypes = new ArrayList<AttributeType>();
+ for (AttributeType type : instance.idToTypeMap.values()) {
+ if (type.isTaggable()) {
+ taggableTypes.add(type);
+ }
+ }
+ return taggableTypes;
+ }
+
+ public static boolean typeExists(String namespace, String name) throws OseeDataStoreException {
+ ensurePopulated();
+ return instance.nameToTypeMap.get(namespace + name) != null;
+ }
+
+ /**
+ * @param namespace
+ * @param name
+ * @return the attribute type with the given name and namespace or throws an OseeTypeDoesNotExist if it does not
+ * exist.
+ * @throws OseeDataStoreException
+ * @throws OseeTypeDoesNotExist
+ */
+ public static AttributeType getType(String namespace, String name) throws OseeDataStoreException, OseeTypeDoesNotExist {
+ ensurePopulated();
+ AttributeType attributeType = instance.nameToTypeMap.get(namespace + name);
+ if (attributeType == null) {
+ throw new OseeTypeDoesNotExist(
+ "Attribute Type with namespace \"" + namespace + "\" and name \"" + name + "\" does not exist.");
+ }
+ return attributeType;
+ }
+
+ /**
+ * Returns the attribute type with the given type id or throws an IllegalArgumentException if it does not exist.
+ *
+ * @param attrTypeId
+ * @throws OseeTypeDoesNotExist
+ * @throws OseeDataStoreException
+ */
+ public static AttributeType getType(int attrTypeId) throws OseeTypeDoesNotExist, OseeDataStoreException {
+ ensurePopulated();
+ AttributeType attributeType = instance.idToTypeMap.get(attrTypeId);
+ if (attributeType == null) {
+ throw new OseeTypeDoesNotExist("Attribute type: " + attrTypeId + " is not available.");
+ }
+
+ return attributeType;
+ }
+
+ /**
+ * @param attrTypeId
+ * @return the attribute type with the given name or throws an IllegalArgumentException if it does not exist.
+ * @throws OseeTypeDoesNotExist
+ */
+ public static AttributeType getType(String name) throws OseeDataStoreException, OseeTypeDoesNotExist {
+ return getType("", name);
+ }
+
+ /**
+ * Cache a newly created type.
+ *
+ * @param attributeType
+ */
+ public void cache(AttributeType attributeType) {
+ nameToTypeMap.put(attributeType.getNamespace() + attributeType.getName(), attributeType);
+ idToTypeMap.put(attributeType.getAttrTypeId(), attributeType);
+ }
+
+ public static AttributeType createType(String attributeBaseType, String attributeProviderTypeName, String fileTypeExtension, String namespace, String name, String defaultValue, String validityXml, int minOccurrences, int maxOccurrences, String tipText, String taggerId) throws OseeCoreException {
+ if (minOccurrences > 0 && defaultValue == null) throw new OseeArgumentException(
+ "DefaultValue must be set for attribute namespace \"" + namespace + "\" and name \"" + name + "\" with minOccurrences " + minOccurrences);
+ if (typeExists(namespace, name)) {
+ return getType(namespace, name);
+ }
+
+ Class<? extends Attribute<?>> baseAttributeClass =
+ AttributeExtensionManager.getAttributeClassFor(attributeBaseType);
+ Class<? extends IAttributeDataProvider> providerAttributeClass =
+ AttributeExtensionManager.getAttributeProviderClassFor(attributeProviderTypeName);
+
+ int attrTypeId = SequenceManager.getNextAttributeTypeId();
+ int attrBaseTypeId = instance.getOrCreateAttributeBaseType(attributeBaseType);
+ int attrProviderTypeId = instance.getOrCreateAttributeProviderType(attributeProviderTypeName);
+
+ int enumTypeId;
+ if (EnumeratedAttribute.class.isAssignableFrom(baseAttributeClass)) {
+ enumTypeId = OseeEnumTypeManager.createEnumTypeFromXml(namespace + name, validityXml).getEnumTypeId();
+ } else {
+ enumTypeId = OseeEnumTypeManager.getDefaultEnumTypeId();
+ }
+
+ ConnectionHandler.runPreparedUpdate(INSERT_ATTRIBUTE_TYPE, attrTypeId, attrBaseTypeId, attrProviderTypeId,
+ fileTypeExtension == null ? SQL3DataType.VARCHAR : fileTypeExtension,
+ namespace == null ? SQL3DataType.VARCHAR : namespace, name,
+ defaultValue == null ? SQL3DataType.VARCHAR : defaultValue, enumTypeId, minOccurrences, maxOccurrences,
+ tipText == null ? SQL3DataType.VARCHAR : tipText, taggerId == null ? SQL3DataType.VARCHAR : taggerId);
+ AttributeType attributeType =
+ new AttributeType(attrTypeId, baseAttributeClass, providerAttributeClass, fileTypeExtension, namespace,
+ name, defaultValue, enumTypeId, minOccurrences, maxOccurrences, tipText, taggerId);
+ instance.cache(attributeType);
+ return attributeType;
+ }
+
+ private int getOrCreateAttributeProviderType(String attrProviderExtension) throws OseeDataStoreException {
+ int attrBaseTypeId = -1;
+ ConnectionHandlerStatement chStmt = new ConnectionHandlerStatement();
+ try {
+ chStmt.runPreparedQuery(SELECT_ATTRIBUTE_PROVIDER_TYPE, attrProviderExtension);
+ if (chStmt.next()) {
+ attrBaseTypeId = chStmt.getInt("attr_provider_type_id");
+ } else {
+ attrBaseTypeId = SequenceManager.getNextAttributeProviderTypeId();
+ ConnectionHandler.runPreparedUpdate(INSERT_ATTRIBUTE_PROVIDER_TYPE, attrBaseTypeId, attrProviderExtension);
+ }
+ } finally {
+ chStmt.close();
+ }
+ return attrBaseTypeId;
+ }
+
+ private int getOrCreateAttributeBaseType(String attrBaseExtension) throws OseeDataStoreException {
+ int attrBaseTypeId = -1;
+ ConnectionHandlerStatement chStmt = new ConnectionHandlerStatement();
+ try {
+ chStmt.runPreparedQuery(SELECT_ATTRIBUTE_BASE_TYPE, attrBaseExtension);
+ if (chStmt.next()) {
+ attrBaseTypeId = chStmt.getInt("attr_base_type_id");
+ } else {
+ attrBaseTypeId = SequenceManager.getNextAttributeBaseTypeId();
+ ConnectionHandler.runPreparedUpdate(INSERT_BASE_ATTRIBUTE_TYPE, attrBaseTypeId, attrBaseExtension);
+ }
+ } finally {
+ chStmt.close();
+ }
+
+ return attrBaseTypeId;
+ }
+
+ public static Set<String> getEnumerationValues(AttributeType attributeType) {
+ try {
+ int oseeEnumTypeId = attributeType.getOseeEnumTypeId();
+ OseeEnumType enumType = OseeEnumTypeManager.getType(oseeEnumTypeId);
+ return enumType.valuesAsOrderedStringSet();
+ } catch (Exception ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ return Collections.emptySet();
+ }
+ }
+
+ public static Set<String> getEnumerationValues(String attributeName) throws OseeDataStoreException, OseeTypeDoesNotExist {
+ return getEnumerationValues(getType(attributeName));
+ }
+
+ private static final String DELETE_VALID_ATTRIBUTE = "delete from osee_valid_attributes where attr_type_id = ?";
+ private static final String COUNT_ATTRIBUTE_OCCURRENCE =
+ "select count(1) FROM osee_attribute where attr_type_id = ?";
+ private static final String DELETE_ATTRIBUTE_TYPE = "delete from osee_attribute_type where attr_type_id = ?";
+
+ public static void purgeAttributeType(AttributeType attributeType) throws OseeCoreException {
+ int attributeTypeId = attributeType.getAttrTypeId();
+ int attributeCount = ConnectionHandler.runPreparedQueryFetchInt(0, COUNT_ATTRIBUTE_OCCURRENCE, attributeTypeId);
+
+ if (attributeCount != 0) {
+ throw new OseeArgumentException(
+ "Can not delete attribute type " + attributeType.getName() + " because there are " + attributeCount + " existing attributes of this type.");
+ }
+
+ ConnectionHandler.runPreparedUpdate(DELETE_VALID_ATTRIBUTE, attributeTypeId);
+ ConnectionHandler.runPreparedUpdate(DELETE_ATTRIBUTE_TYPE, attributeTypeId);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BinaryAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BinaryAttribute.java
new file mode 100644
index 00000000000..b30c2dfb7c8
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BinaryAttribute.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public abstract class BinaryAttribute<T> extends BinaryBackedAttribute<T> {
+ public BinaryAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BinaryBackedAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BinaryBackedAttribute.java
new file mode 100644
index 00000000000..1dc9d0ba802
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BinaryBackedAttribute.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.attribute.providers.IBinaryAttributeDataProvider;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public abstract class BinaryBackedAttribute<T> extends Attribute<T> {
+
+ protected BinaryBackedAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ public IBinaryAttributeDataProvider getAttributeDataProvider() {
+ // this cast is always safe since the the data provider passed in the constructor to
+ // the super class is of type IBinaryAttributeDataProvider
+ return (IBinaryAttributeDataProvider) super.getAttributeDataProvider();
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BooleanAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BooleanAttribute.java
new file mode 100644
index 00000000000..6c6b888ceb6
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/BooleanAttribute.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class BooleanAttribute extends CharacterBackedAttribute<Boolean> {
+ public static final String[] booleanChoices = new String[] {"yes", "no"};
+
+ public BooleanAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ @Override
+ public Boolean getValue() throws OseeCoreException {
+ return getAttributeDataProvider().getValueAsString().equals(booleanChoices[0]);
+ }
+
+ @Override
+ public boolean subClassSetValue(Boolean value) throws OseeCoreException {
+ return getAttributeDataProvider().setValue(value ? booleanChoices[0] : booleanChoices[1]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#convertStringToValue(java.lang.String)
+ */
+ @Override
+ protected Boolean convertStringToValue(String value) {
+ return value != null && value.equalsIgnoreCase(booleanChoices[0]);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/CharacterBackedAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/CharacterBackedAttribute.java
new file mode 100644
index 00000000000..0fd84305190
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/CharacterBackedAttribute.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.attribute.providers.ICharacterAttributeDataProvider;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public abstract class CharacterBackedAttribute<T> extends Attribute<T> {
+
+ protected CharacterBackedAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ @Override
+ public ICharacterAttributeDataProvider getAttributeDataProvider() {
+ // this cast is always safe since the the data provider passed in the constructor to
+ // the super class is of type ICharacterAttributeDataProvider
+ return (ICharacterAttributeDataProvider) super.getAttributeDataProvider();
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/CompressedContentAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/CompressedContentAttribute.java
new file mode 100644
index 00000000000..1cda3d143ee
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/CompressedContentAttribute.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.attribute.providers.IAttributeDataProvider;
+
+public final class CompressedContentAttribute extends BinaryAttribute<InputStream> {
+
+ public CompressedContentAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#getValue()
+ */
+ @Override
+ public InputStream getValue() throws OseeCoreException {
+ return Lib.byteBufferToInputStream(getAttributeDataProvider().getValueAsBytes());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#setValue(java.lang.Object)
+ */
+ @Override
+ public boolean subClassSetValue(InputStream value) throws OseeCoreException {
+ return setValueFromInputStream(value);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.IStreamableAttribute#setValueFromInputStream(java.io.InputStream)
+ */
+ @Override
+ public boolean setValueFromInputStream(InputStream value) throws OseeCoreException {
+ boolean response = false;
+ try {
+ if (value == null) {
+ response = getAttributeDataProvider().setValue(null);
+ } else {
+ byte[] data = Lib.inputStreamToBytes(value);
+ response = getAttributeDataProvider().setValue(ByteBuffer.wrap(data));
+ }
+ } catch (IOException ex) {
+ throw new OseeWrappedException(ex);
+ }
+ if (response) {
+ setDirty();
+ }
+ return response;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#setAttributeDataProvider(org.eclipse.osee.framework.skynet.core.attribute.providers.IAttributeDataProvider)
+ */
+ @Override
+ public void setAttributeDataProvider(IAttributeDataProvider attributeDataProvider) throws OseeCoreException {
+ super.setAttributeDataProvider(attributeDataProvider);
+ attributeDataProvider.setDisplayableString(getAttributeType().getName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#convertStringToValue(java.lang.String)
+ */
+ @Override
+ protected InputStream convertStringToValue(String value) throws OseeCoreException {
+ try {
+ return Lib.stringToInputStream(value);
+ } catch (Exception ex) {
+ throw new OseeCoreException(ex);
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/DateAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/DateAttribute.java
new file mode 100644
index 00000000000..3ef24ac2a8f
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/DateAttribute.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+
+/**
+ * @author Robert A. Fisher
+ * @author Ryan D. Brooks
+ */
+public class DateAttribute extends CharacterBackedAttribute<Date> {
+ public static final DateFormat MMDDYY = new SimpleDateFormat("MM/dd/yyyy");
+ public static final DateFormat MMDDYYHHMM = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
+ public static final DateFormat HHMM = new SimpleDateFormat("hh:mm");
+ public static final DateFormat MMDDYYYYHHMMSSAMPM = new SimpleDateFormat("MMM dd,yyyy hh:mm:ss a");
+ public static final DateFormat ALLDATETIME = new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy");
+
+ private static final DateFormat[] legacyDateFormats = new DateFormat[] {MMDDYYYYHHMMSSAMPM, ALLDATETIME, MMDDYYHHMM};
+
+ /**
+ * Create a date attribute with a given type, initialized to the current date and time.
+ *
+ * @param attributeType The type of the attribute
+ */
+ public DateAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ /**
+ * Return current date or null if not set
+ *
+ * @return date or null if not set
+ * @throws OseeCoreException
+ */
+ public Date getValue() throws OseeCoreException {
+ Date toReturn = null;
+ String value = getAttributeDataProvider().getValueAsString();
+ if (Strings.isValid(value) != false) {
+ //TODO Added for backward compatibility with inconsistent date formats;
+ try {
+ toReturn = new Date(Long.parseLong(value));
+ } catch (Exception ex) {
+ // We have a legacy date - need to figure out how to parse it
+ toReturn = handleLegacyDates(value);
+ }
+ }
+ return toReturn;
+ }
+
+ private Date handleLegacyDates(String rawValue) {
+ Date toReturn = null;
+ for (DateFormat format : legacyDateFormats) {
+ try {
+ toReturn = format.parse(rawValue);
+ break;
+ } catch (ParseException ex) {
+ }
+ }
+ return toReturn;
+ }
+
+ /**
+ * Sets date
+ *
+ * @param value value or null to clear
+ * @throws OseeCoreException
+ */
+ @Override
+ public boolean subClassSetValue(Date value) throws OseeCoreException {
+ String toSet = value != null ? Long.toString(value.getTime()) : "";
+ return getAttributeDataProvider().setValue(toSet);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#getDisplayableString()
+ */
+ @Override
+ public String getDisplayableString() throws OseeCoreException {
+ return getAsFormattedString(DateAttribute.MMDDYYHHMM);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#convertStringToValue(java.lang.String)
+ */
+ @Override
+ protected Date convertStringToValue(String value) {
+ if (value == null || value.equals("")) {
+ return null;
+ }
+ return new Date(Long.parseLong(value));
+ }
+
+ /**
+ * Return date in format given by pattern or "" if not set
+ *
+ * @param pattern DateAttribute.MMDDYY, etc...
+ * @return formated date
+ * @throws OseeCoreException
+ */
+ public String getAsFormattedString(DateFormat dateFormat) throws OseeCoreException {
+ Date date = getValue();
+ return date != null ? dateFormat.format(getValue()) : "";
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/EnumeratedAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/EnumeratedAttribute.java
new file mode 100644
index 00000000000..33b1361417c
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/EnumeratedAttribute.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class EnumeratedAttribute extends StringAttribute {
+ // When an enumerated attribute is required for an artifact, yet doesn't exist yet, it is created upon
+ // init of the artifact and given the "Unspecified" value
+ public static String UNSPECIFIED_VALUE = "Unspecified";
+
+ public EnumeratedAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#getDisplayableString()
+ */
+ @Override
+ public String getDisplayableString() throws OseeCoreException {
+ String toDisplay = getAttributeDataProvider().getDisplayableString();
+ return Strings.isValid(toDisplay) ? toDisplay : "<Select>";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#subClassSetValue(java.lang.Object)
+ */
+ @Override
+ public boolean subClassSetValue(String value) throws OseeCoreException {
+ if (!AttributeTypeManager.getEnumerationValues(getAttributeType()).contains(value)) {
+ //throw new OseeArgumentException(value + " is not a valid enumeration of the type " + getAttributeType());
+ }
+ return super.subClassSetValue(value);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/FloatingPointAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/FloatingPointAttribute.java
new file mode 100644
index 00000000000..8241469d830
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/FloatingPointAttribute.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class FloatingPointAttribute extends CharacterBackedAttribute<Double> {
+
+ public FloatingPointAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#getValue()
+ */
+ @Override
+ public Double getValue() throws OseeCoreException {
+ String doubleString = getAttributeDataProvider().getValueAsString();
+ return Strings.isValid(doubleString) ? Double.valueOf(doubleString) : null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#subClassSetValue(java.lang.Object)
+ */
+ @Override
+ public boolean subClassSetValue(Double value) throws OseeCoreException {
+ return getAttributeDataProvider().setValue(String.valueOf(value));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#convertStringToValue(java.lang.String)
+ */
+ @Override
+ protected Double convertStringToValue(String value) {
+ if (value == null || value.equals("")) {
+ return null;
+ }
+ return new Double(value);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/HttpAttributeTagger.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/HttpAttributeTagger.java
new file mode 100644
index 00000000000..a1768433384
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/HttpAttributeTagger.java
@@ -0,0 +1,214 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.core.client.ClientSessionManager;
+import org.eclipse.osee.framework.core.client.server.HttpUrlBuilder;
+import org.eclipse.osee.framework.core.data.OseeServerContext;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.HttpProcessor;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.messaging.event.skynet.event.SkynetAttributeChange;
+import org.eclipse.osee.framework.skynet.core.dbinit.SkynetDbInit;
+import org.eclipse.osee.framework.skynet.core.event.ArtifactModifiedEvent;
+import org.eclipse.osee.framework.skynet.core.event.ArtifactTransactionModifiedEvent;
+import org.eclipse.osee.framework.skynet.core.event.BranchEventType;
+import org.eclipse.osee.framework.skynet.core.event.FrameworkTransactionData;
+import org.eclipse.osee.framework.skynet.core.event.IArtifactsChangeTypeEventListener;
+import org.eclipse.osee.framework.skynet.core.event.IArtifactsPurgedEventListener;
+import org.eclipse.osee.framework.skynet.core.event.IBranchEventListener;
+import org.eclipse.osee.framework.skynet.core.event.IFrameworkTransactionEventListener;
+import org.eclipse.osee.framework.skynet.core.event.ITransactionsDeletedEventListener;
+import org.eclipse.osee.framework.skynet.core.event.OseeEventManager;
+import org.eclipse.osee.framework.skynet.core.event.Sender;
+import org.eclipse.osee.framework.skynet.core.internal.Activator;
+import org.eclipse.osee.framework.skynet.core.utility.LoadedArtifacts;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class HttpAttributeTagger {
+ private static final HttpAttributeTagger instance = new HttpAttributeTagger();
+ private static final String XML_START = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><AttributeTag>";
+ private static final String XML_FINISH = "</AttributeTag>";
+ private static final String PREFIX = "<entry gammaId=\"";
+ private static final String POSTFIX = "\"/>\n";
+ private final ExecutorService executor;
+ private final EventRelay eventRelay;
+
+ private HttpAttributeTagger() {
+ this.executor = Executors.newSingleThreadExecutor();
+ this.eventRelay = new EventRelay();
+ OseeEventManager.addListener(eventRelay);
+ }
+
+ public static HttpAttributeTagger getInstance() {
+ return instance;
+ }
+
+ public void deregisterFromEventManager() {
+ OseeEventManager.removeListener(eventRelay);
+ }
+
+ private final class TagService implements Runnable {
+ private final Set<Integer> changedGammas;
+
+ public TagService() {
+ this.changedGammas = new HashSet<Integer>();
+ }
+
+ public void add(int attributeGammaId) {
+ changedGammas.add(attributeGammaId);
+ }
+
+ public int size() {
+ return changedGammas.size();
+ }
+
+ public void run() {
+ long start = System.currentTimeMillis();
+ StringBuffer response = new StringBuffer();
+ ByteArrayInputStream inputStream = null;
+ try {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put("sessionId", ClientSessionManager.getSessionId());
+ if (SkynetDbInit.isDbInit()) {
+ parameters.put("wait", "true");
+ }
+ StringBuilder payload = new StringBuilder(XML_START);
+ for (int data : changedGammas) {
+ payload.append(PREFIX);
+ payload.append(data);
+ payload.append(POSTFIX);
+ }
+ payload.append(XML_FINISH);
+
+ inputStream = new ByteArrayInputStream(payload.toString().getBytes("UTF-8"));
+ String url =
+ HttpUrlBuilder.getInstance().getOsgiServletServiceUrl(OseeServerContext.SEARCH_TAGGING_CONTEXT,
+ parameters);
+ response.append(HttpProcessor.put(new URL(url), inputStream, "application/xml", "UTF-8"));
+ OseeLog.log(Activator.class, Level.FINEST, String.format("Transmitted to Tagger in [%d ms]",
+ System.currentTimeMillis() - start));
+ } catch (Exception ex) {
+ if (response.length() > 0) {
+ response.append("\n");
+ }
+ response.append(ex.getLocalizedMessage());
+ OseeLog.log(Activator.class, Level.SEVERE, response.toString(), ex);
+ } finally {
+ changedGammas.clear();
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex.toString(), ex);
+ }
+ }
+ }
+ }
+ }
+
+ private final class EventRelay implements IFrameworkTransactionEventListener, IBranchEventListener, IArtifactsPurgedEventListener, IArtifactsChangeTypeEventListener, ITransactionsDeletedEventListener {
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.event.IBranchEventListener#handleBranchEvent(org.eclipse.osee.framework.skynet.core.event.Sender, org.eclipse.osee.framework.skynet.core.event.BranchEventType, int)
+ */
+ @Override
+ public void handleBranchEvent(Sender sender, BranchEventType branchModType, int branchId) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.event.IBranchEventListener#handleLocalBranchToArtifactCacheUpdateEvent(org.eclipse.osee.framework.skynet.core.event.Sender)
+ */
+ @Override
+ public void handleLocalBranchToArtifactCacheUpdateEvent(Sender sender) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.event.IArtifactsPurgedEventListener#handleArtifactsPurgedEvent(org.eclipse.osee.framework.skynet.core.event.Sender, org.eclipse.osee.framework.skynet.core.utility.LoadedArtifacts)
+ */
+ @Override
+ public void handleArtifactsPurgedEvent(Sender sender, LoadedArtifacts loadedArtifacts) {
+ // if (sender.isRemote()) {
+ // return;
+ // }
+ // try {
+ // loadedArtifacts.
+ // //TODO: implements
+ // // Map<String, String> parameters = new HashMap<String, String>();
+ // // parameters.put("sessionId", ClientSessionManager.getSessionId());
+ // // parameters.put("queryId", Integer.toString(transactionJoinId));
+ // // String url =
+ // // HttpUrlBuilder.getInstance().getOsgiServletServiceUrl(OseeServerContext.SEARCH_TAGGING_CONTEXT,
+ // // parameters);
+ // // String response = HttpProcessor.delete(new URL(url));
+ //
+ // } catch (Exception ex) {
+ // OseeLog.log(Activator.class, Level.WARNING, "Error Deleting Tags during purge.", ex);
+ // }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.event.IArtifactsChangeTypeEventListener#handleArtifactsChangeTypeEvent(org.eclipse.osee.framework.skynet.core.event.Sender, int, org.eclipse.osee.framework.skynet.core.utility.LoadedArtifacts)
+ */
+ @Override
+ public void handleArtifactsChangeTypeEvent(Sender sender, int toArtifactTypeId, LoadedArtifacts loadedArtifacts) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.event.ITransactionsDeletedEventListener#handleTransactionsDeletedEvent(org.eclipse.osee.framework.skynet.core.event.Sender, int[])
+ */
+ @Override
+ public void handleTransactionsDeletedEvent(Sender sender, int[] transactionIds) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.event.IFrameworkTransactionEventListener#handleFrameworkTransactionEvent(org.eclipse.osee.framework.skynet.core.event.Sender, org.eclipse.osee.framework.skynet.core.event.FrameworkTransactionData)
+ */
+ @Override
+ public void handleFrameworkTransactionEvent(Sender sender, FrameworkTransactionData txData) throws OseeCoreException {
+ if (sender.isRemote()) {
+ return;
+ }
+ TagService taggingInfo = new TagService();
+ for (ArtifactTransactionModifiedEvent event : txData.getXModifiedEvents()) {
+ if (event instanceof ArtifactModifiedEvent) {
+ for (SkynetAttributeChange change : ((ArtifactModifiedEvent) event).getAttributeChanges()) {
+ if (AttributeTypeManager.getType(change.getTypeId()).isTaggable()) {
+ taggingInfo.add(change.getGammaId());
+ }
+ }
+ }
+ }
+ if (taggingInfo.size() > 0) {
+ Future<?> future = executor.submit(taggingInfo);
+ if (SkynetDbInit.isDbInit()) {
+ try {
+ future.get();
+ } catch (Exception ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, "Error while waiting for tagger to complete.", ex);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/IntegerAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/IntegerAttribute.java
new file mode 100644
index 00000000000..7e4f8eb0d7d
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/IntegerAttribute.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class IntegerAttribute extends CharacterBackedAttribute<Integer> {
+
+ public IntegerAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#getValue()
+ */
+ @Override
+ public Integer getValue() throws NumberFormatException, OseeCoreException {
+ String integerString = getAttributeDataProvider().getValueAsString();
+ return Strings.isValid(integerString) ? Integer.valueOf(integerString) : null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#subClassSetValue(java.lang.Object)
+ */
+ @Override
+ public boolean subClassSetValue(Integer value) throws OseeCoreException {
+ return getAttributeDataProvider().setValue(Integer.toString(value));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#convertStringToValue(java.lang.String)
+ */
+ @Override
+ protected Integer convertStringToValue(String value) throws OseeCoreException {
+ if (value == null || value.equals("")) {
+ return new Integer(0);
+ }
+ return Integer.parseInt(value);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/JavaObjectAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/JavaObjectAttribute.java
new file mode 100644
index 00000000000..f5a43f81862
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/JavaObjectAttribute.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.nio.ByteBuffer;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.internal.Activator;
+
+public final class JavaObjectAttribute extends BinaryAttribute<Object> {
+
+ public JavaObjectAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#getValue()
+ */
+ @Override
+ public Object getValue() throws OseeCoreException {
+ return getObjectFromBytes(getAttributeDataProvider().getValueAsBytes());
+ }
+
+ private Object getObjectFromBytes(ByteBuffer buffer) {
+ Object obj = null;
+ InputStream inputStream = null;
+ ObjectInputStream objectStream = null;
+ try {
+ inputStream = Lib.byteBufferToInputStream(buffer);
+ if (inputStream != null) {
+ objectStream = new ObjectInputStream(inputStream);
+ obj = objectStream.readObject();
+ }
+ } catch (Exception ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ } finally {
+ try {
+ if (inputStream != null) {
+ inputStream.reset();
+ }
+ } catch (IOException ex) {
+ }
+ try {
+ if (objectStream != null) {
+ objectStream.close();
+ }
+ } catch (IOException ex) {
+ }
+ }
+ return obj;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#subClassSetValue(java.lang.Object)
+ */
+ @Override
+ public boolean subClassSetValue(Object value) {
+ try {
+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectStream = new ObjectOutputStream(byteStream);
+ objectStream.writeObject(value);
+ objectStream.flush();
+ objectStream.close();
+ getAttributeDataProvider().setValue(ByteBuffer.wrap(byteStream.toByteArray()));
+ getAttributeDataProvider().setDisplayableString(value != null ? value.getClass().getName() : "null");
+ } catch (Exception ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#convertStringToValue(java.lang.String)
+ */
+ @Override
+ protected Object convertStringToValue(String value) throws OseeCoreException {
+ if (value == null) {
+ return null;
+ }
+ return getObjectFromBytes(ByteBuffer.wrap(value.getBytes()));
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumType.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumType.java
new file mode 100644
index 00000000000..a6355154697
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumType.java
@@ -0,0 +1,261 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import org.eclipse.osee.framework.db.connection.exception.OseeArgumentException;
+import org.eclipse.osee.framework.jdk.core.type.ObjectPair;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class OseeEnumType {
+
+ private final int enumTypeId;
+ private final String enumTypeName;
+
+ private final List<OseeEnumEntry> enumSet;
+ private boolean isDeleted;
+
+ protected OseeEnumType(int enumTypeId, String enumTypeName) {
+ this.enumTypeId = enumTypeId;
+ this.enumTypeName = enumTypeName;
+ this.enumSet = new ArrayList<OseeEnumEntry>();
+ this.isDeleted = false;
+ }
+
+ protected void internalSetDeleted(boolean deleted) {
+ this.isDeleted = deleted;
+ }
+
+ protected synchronized void internalAddEnum(String name, int ordinal) throws OseeArgumentException {
+ checkEnumEntryName(name);
+ checkOrdinal(ordinal);
+ OseeEnumEntry entry = new OseeEnumEntry(name, ordinal);
+ enumSet.add(entry);
+ }
+
+ protected void internalAddEnum(ObjectPair<String, Integer> entry) throws OseeArgumentException {
+ internalAddEnum(entry.object1, entry.object2);
+ }
+
+ protected synchronized void internalRemoveEnums(OseeEnumEntry... entries) {
+ if (entries != null) {
+ for (OseeEnumEntry entry : entries) {
+ enumSet.remove(entry);
+ }
+ }
+ }
+
+ public boolean isDeleted() {
+ return isDeleted;
+ }
+
+ public synchronized OseeEnumEntry[] values() {
+ Collections.sort(enumSet);
+ return enumSet.toArray(new OseeEnumEntry[enumSet.size()]);
+ }
+
+ public synchronized Set<String> valuesAsOrderedStringSet() {
+ Set<String> values = new LinkedHashSet<String>();
+ for (OseeEnumEntry oseeEnumEntry : enumSet) {
+ values.add(oseeEnumEntry.name());
+ }
+ return values;
+ }
+
+ public int getEnumTypeId() {
+ return enumTypeId;
+ }
+
+ public String getEnumTypeName() {
+ return enumTypeName;
+ }
+
+ private synchronized OseeEnumEntry valueOfAllowNullReturn(String entryName) {
+ if (entryName != null) {
+ for (OseeEnumEntry entry : enumSet) {
+ if (entry.name().equals(entryName)) {
+ return entry;
+ }
+ }
+ }
+ return null;
+ }
+
+ private synchronized OseeEnumEntry valueOfAllowNullReturn(int ordinal) throws OseeArgumentException {
+ for (OseeEnumEntry entry : enumSet) {
+ if (entry.ordinal() == ordinal) {
+ return entry;
+ }
+ }
+ return null;
+ }
+
+ public synchronized OseeEnumEntry valueOf(String entryName) throws OseeArgumentException {
+ OseeEnumEntry toReturn = valueOfAllowNullReturn(entryName);
+ if (toReturn == null) {
+ throw new OseeArgumentException(String.format("No enum const [%s].[%s]", getEnumTypeName(), entryName));
+ }
+ return toReturn;
+ }
+
+ public synchronized OseeEnumEntry valueOf(int ordinal) throws OseeArgumentException {
+ OseeEnumEntry toReturn = valueOfAllowNullReturn(ordinal);
+ if (toReturn == null) {
+ throw new OseeArgumentException(String.format("No enum const [%s] - ordinal [%s]", getEnumTypeName(), ordinal));
+ }
+ return toReturn;
+ }
+
+ private void checkEnumEntryName(String name) throws OseeArgumentException {
+ if (!Strings.isValid(name)) {
+ throw new OseeArgumentException("Enum entry name cannot be null");
+ }
+ OseeEnumEntry entry = valueOfAllowNullReturn(name);
+ if (entry != null) {
+ throw new OseeArgumentException(String.format("Unique enum entry name violation - %s already exists.", entry));
+ }
+ }
+
+ private void checkOrdinal(int ordinal) throws OseeArgumentException {
+ if (ordinal < 0) {
+ throw new OseeArgumentException("Enum entry ordinal cannot be of negative value");
+ }
+ OseeEnumEntry entry = valueOfAllowNullReturn(ordinal);
+ if (entry != null) {
+ throw new OseeArgumentException(String.format("Unique enum entry ordinal violation - %s already exists.",
+ entry));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof OseeEnumType) {
+ final OseeEnumType other = (OseeEnumType) obj;
+ boolean result = true;
+ if (other.getEnumTypeName() != null && getEnumTypeName() != null) {
+ result &= other.getEnumTypeName().equals(getEnumTypeName());
+ } else {
+ result &= other.getEnumTypeName() == null && getEnumTypeName() == null;
+ }
+ return result & getEnumTypeId() == other.getEnumTypeId();
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 37;
+ int result = prime * 17 + (getEnumTypeName() != null ? getEnumTypeName().hashCode() : 0);
+ return prime * result + getEnumTypeId();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return enumTypeName;
+ }
+
+ public final class OseeEnumEntry implements Comparable<OseeEnumEntry> {
+ private final int ordinal;
+ private final String name;
+
+ private OseeEnumEntry(String name, int ordinal) {
+ this.name = name;
+ this.ordinal = ordinal;
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public int ordinal() {
+ return ordinal;
+ }
+
+ public String getEnumTypeName() {
+ return OseeEnumType.this.getEnumTypeName();
+ }
+
+ public int getEnumTypeId() {
+ return OseeEnumType.this.getEnumTypeId();
+ }
+
+ public OseeEnumType getDeclaringClass() {
+ return OseeEnumType.this;
+ }
+
+ public OseeEnumEntry[] values() {
+ return OseeEnumType.this.values();
+ }
+
+ public ObjectPair<String, Integer> asObjectPair() {
+ return new ObjectPair<String, Integer>(name(), ordinal());
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof OseeEnumEntry) {
+ final OseeEnumEntry other = (OseeEnumEntry) obj;
+ boolean result = true;
+ if (other.name != null && name != null) {
+ result &= other.name.equals(name);
+ } else {
+ result &= other.name == null && name == null;
+ }
+ return result & ordinal == other.ordinal & getDeclaringClass().equals(other.getDeclaringClass());
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 37;
+ int result = prime * 17 + (name != null ? name.hashCode() : 0);
+ result = prime * result + ordinal;
+ result = prime * result + getDeclaringClass().hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("[%s].[%s:%s]", getEnumTypeName(), name, ordinal);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(OseeEnumEntry other) {
+ return this.ordinal() - other.ordinal();
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumTypeManager.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumTypeManager.java
new file mode 100644
index 00000000000..da782e28e53
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumTypeManager.java
@@ -0,0 +1,383 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.ConnectionHandler;
+import org.eclipse.osee.framework.db.connection.ConnectionHandlerStatement;
+import org.eclipse.osee.framework.db.connection.DbTransaction;
+import org.eclipse.osee.framework.db.connection.OseeConnection;
+import org.eclipse.osee.framework.db.connection.core.SequenceManager;
+import org.eclipse.osee.framework.db.connection.exception.OseeArgumentException;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeMultipleEnumTypesExist;
+import org.eclipse.osee.framework.db.connection.exception.OseeStateException;
+import org.eclipse.osee.framework.db.connection.exception.OseeTypeDoesNotExist;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.jdk.core.type.HashCollection;
+import org.eclipse.osee.framework.jdk.core.type.ObjectPair;
+import org.eclipse.osee.framework.jdk.core.util.Collections;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.skynet.core.attribute.OseeEnumType.OseeEnumEntry;
+import org.eclipse.osee.framework.skynet.core.internal.Activator;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class OseeEnumTypeManager {
+ private static final String QUERY_ENUM =
+ "select oet.enum_type_name, oetd.* from osee_enum_type oet, osee_enum_type_def oetd where oet.enum_type_id = oetd.enum_type_id order by oetd.enum_type_id, oetd.ordinal";
+
+ private static final String INSERT_ENUM_TYPE =
+ "insert into osee_enum_type (ENUM_TYPE_ID, ENUM_TYPE_NAME) values (?,?)";
+
+ private static final String INSERT_ENUM_TYPE_DEF =
+ "insert into osee_enum_type_def (ENUM_TYPE_ID, NAME, ORDINAL) values (?,?,?)";
+
+ private static final String DELETE_ENUM_TYPE_ENTRIES = "delete from osee_enum_type_def where enum_type_id = ?";
+
+ private static final String DELETE_ENUM_TYPE = "delete from osee_enum_type oet where enum_type_id = ?";
+
+ private static final OseeEnumTypeManager instance = new OseeEnumTypeManager();
+
+ private final HashCollection<String, OseeEnumType> enumTypeByNameMap;
+ private final Map<Integer, OseeEnumType> enumTypeByIdMap;
+
+ private OseeEnumTypeManager() {
+ enumTypeByNameMap = new HashCollection<String, OseeEnumType>();
+ enumTypeByIdMap = new HashMap<Integer, OseeEnumType>();
+ }
+
+ public static OseeEnumType getType(int enumTypeId, boolean includeDeleted) throws OseeDataStoreException, OseeTypeDoesNotExist {
+ instance.checkLoaded();
+ OseeEnumType oseeEnumType = instance.enumTypeByIdMap.get(enumTypeId);
+ if (oseeEnumType == null || !includeDeleted && oseeEnumType.isDeleted()) {
+ throw new OseeTypeDoesNotExist(String.format("Osee Enum Type with id:[%s] does not exist.", enumTypeId));
+ }
+ return oseeEnumType;
+ }
+
+ public static OseeEnumType getUniqueType(String enumTypeName, boolean includeDeleted) throws OseeDataStoreException, OseeTypeDoesNotExist, OseeMultipleEnumTypesExist {
+ Collection<OseeEnumType> results = getTypes(enumTypeName, includeDeleted);
+ if (results.size() > 1) {
+ throw new OseeMultipleEnumTypesExist(String.format("Found multiple OSEE enum types matching [%s] name",
+ enumTypeName));
+ }
+ return results.iterator().next();
+ }
+
+ public static Collection<OseeEnumType> getTypes(String enumTypeName, boolean includeDeleted) throws OseeDataStoreException, OseeTypeDoesNotExist {
+ Collection<OseeEnumType> toReturn = getTypesAllowEmpty(enumTypeName, includeDeleted);
+ if (toReturn.isEmpty()) {
+ throw new OseeTypeDoesNotExist(String.format("Osee Enum Type with name:[%s] does not exist.", enumTypeName));
+ }
+ return toReturn;
+ }
+
+ public static Collection<OseeEnumType> getTypesAllowEmpty(String enumTypeName, boolean includeDeleted) throws OseeDataStoreException {
+ instance.checkLoaded();
+ List<OseeEnumType> toReturn = new ArrayList<OseeEnumType>();
+ Collection<OseeEnumType> itemsFound = instance.enumTypeByNameMap.getValues(enumTypeName);
+ if (itemsFound != null) {
+ for (OseeEnumType oseeEnumType : itemsFound) {
+ if (includeDeleted || !oseeEnumType.isDeleted()) {
+ toReturn.add(oseeEnumType);
+ }
+ }
+ }
+ return toReturn;
+ }
+
+ public static Collection<OseeEnumType> getAllTypes(boolean includeDeleted) throws OseeDataStoreException {
+ instance.checkLoaded();
+ List<OseeEnumType> items = new ArrayList<OseeEnumType>();
+ for (OseeEnumType types : instance.enumTypeByIdMap.values()) {
+ if (includeDeleted || !types.isDeleted()) {
+ items.add(types);
+ }
+ }
+ return items;
+ }
+
+ public static Collection<String> getAllTypeNames(boolean includeDeleted) throws OseeDataStoreException {
+ List<String> items = new ArrayList<String>();
+ for (OseeEnumType types : getAllTypes(includeDeleted)) {
+ items.add(types.getEnumTypeName());
+ }
+ return items;
+ }
+
+ public static boolean typeExist(String enumTypeName, boolean includeDeleted) throws OseeDataStoreException {
+ return !getTypesAllowEmpty(enumTypeName, includeDeleted).isEmpty();
+ }
+
+ public static OseeEnumType getType(int enumTypeId) throws OseeDataStoreException, OseeTypeDoesNotExist {
+ return getType(enumTypeId, false);
+ }
+
+ public static OseeEnumType getUniqueType(String enumTypeName) throws OseeDataStoreException, OseeTypeDoesNotExist, OseeMultipleEnumTypesExist {
+ return getUniqueType(enumTypeName, false);
+ }
+
+ public static Collection<String> getAllTypeNames() throws OseeDataStoreException {
+ return getAllTypeNames(false);
+ }
+
+ public static Collection<OseeEnumType> getAllTypes() throws OseeDataStoreException {
+ return getAllTypes(false);
+ }
+
+ public static boolean typeExist(String enumTypeName) throws OseeDataStoreException {
+ return typeExist(enumTypeName, false);
+ }
+
+ private static void checkNull(Object value) throws OseeCoreException {
+ if (value == null) {
+ throw new OseeArgumentException("Object cannot be null.");
+ }
+ }
+
+ private static void checkEnumTypeName(String enumTypeName) throws OseeCoreException {
+ if (!Strings.isValid(enumTypeName)) {
+ throw new OseeArgumentException("Osee Enum Type Name cannot be null.");
+ }
+ }
+
+ private static void checkEntryIntegrity(String enumTypeName, List<ObjectPair<String, Integer>> entries) throws OseeCoreException {
+ if (entries == null) {
+ throw new OseeArgumentException(String.format("Osee Enum Type [%s] had null entries", enumTypeName));
+ }
+
+ // if (entries.size() <= 0) throw new OseeArgumentException(String.format("Osee Enum Type [%s] had 0 entries",
+ // enumTypeName));
+ Map<String, Integer> values = new HashMap<String, Integer>();
+ for (ObjectPair<String, Integer> entry : entries) {
+ String name = entry.object1;
+ int ordinal = entry.object2;
+ if (!Strings.isValid(name)) {
+ throw new OseeArgumentException("Enum entry name cannot be null");
+ }
+ if (ordinal < 0) {
+ throw new OseeArgumentException("Enum entry ordinal cannot be of negative value");
+ }
+ if (values.containsKey(name)) {
+ throw new OseeArgumentException(String.format("Unique enum entry name violation - [%s] already exists.",
+ name));
+ }
+ if (values.containsValue(ordinal)) {
+ throw new OseeArgumentException(String.format("Unique enum entry ordinal violation - [%s] already exists.",
+ ordinal));
+ }
+ values.put(name, ordinal);
+ }
+ }
+
+ public static int getDefaultEnumTypeId() throws OseeCoreException {
+ return -1;
+ }
+
+ public static OseeEnumType createEnumType(String enumTypeName, List<ObjectPair<String, Integer>> entries) throws OseeCoreException {
+ checkEnumTypeName(enumTypeName);
+ checkEntryIntegrity(enumTypeName, entries);
+
+ if (typeExist(enumTypeName)) {
+ return getUniqueType(enumTypeName);
+ }
+
+ int oseeEnumTypeId = SequenceManager.getNextOseeEnumTypeId();
+ OseeEnumType oseeEnumType = new OseeEnumType(oseeEnumTypeId, enumTypeName);
+ ConnectionHandler.runPreparedUpdate(INSERT_ENUM_TYPE, oseeEnumType.getEnumTypeId(),
+ oseeEnumType.getEnumTypeName());
+
+ addEntries(oseeEnumType, entries);
+ return oseeEnumType;
+ }
+
+ public static OseeEnumType createEnumTypeFromXml(String attributeTypeName, String xmlDefinition) throws OseeCoreException {
+ List<ObjectPair<String, Integer>> entries = new ArrayList<ObjectPair<String, Integer>>();
+ String enumTypeName = "";
+
+ if (!Strings.isValid(xmlDefinition)) {
+ throw new OseeArgumentException("The enum xml definition must not be null or empty");
+ }
+
+ Document document;
+ try {
+ document = Jaxp.readXmlDocument(xmlDefinition);
+ } catch (Exception ex) {
+ throw new OseeWrappedException(ex);
+ }
+ enumTypeName = attributeTypeName;
+ Element choicesElement = document.getDocumentElement();
+ NodeList enumerations = choicesElement.getChildNodes();
+ Set<String> choices = new LinkedHashSet<String>();
+
+ for (int i = 0; i < enumerations.getLength(); i++) {
+ Node node = enumerations.item(i);
+ if (node.getNodeName().equalsIgnoreCase("Enum")) {
+ choices.add(node.getTextContent());
+ } else {
+ throw new OseeArgumentException("Validity Xml not of excepted enum format");
+ }
+ }
+
+ int ordinal = 0;
+ for (String choice : choices) {
+ entries.add(new ObjectPair<String, Integer>(choice, ordinal++));
+ }
+
+ return createEnumType(enumTypeName, entries);
+ }
+
+ private void cache(OseeEnumType oseeEnumType) {
+ enumTypeByNameMap.put(oseeEnumType.getEnumTypeName(), oseeEnumType);
+ enumTypeByIdMap.put(oseeEnumType.getEnumTypeId(), oseeEnumType);
+ }
+
+ private synchronized void checkLoaded() throws OseeDataStoreException {
+ if (enumTypeByNameMap.isEmpty() && enumTypeByIdMap.isEmpty()) {
+ ConnectionHandlerStatement chStmt = new ConnectionHandlerStatement();
+ try {
+ chStmt.runPreparedQuery(QUERY_ENUM);
+ OseeEnumType oseeEnumType = null;
+ int lastEnumTypeId = -1;
+ while (chStmt.next()) {
+ try {
+ int currentEnumTypeId = chStmt.getInt("enum_type_id");
+ if (lastEnumTypeId != currentEnumTypeId) {
+ oseeEnumType = new OseeEnumType(currentEnumTypeId, chStmt.getString("enum_type_name"));
+ cache(oseeEnumType);
+ lastEnumTypeId = currentEnumTypeId;
+ }
+ oseeEnumType.internalAddEnum(chStmt.getString("name"), chStmt.getInt("ordinal"));
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ }
+ } finally {
+ chStmt.close();
+ }
+ }
+ }
+
+ public static void deleteEnumType(OseeEnumType typeToDelete) throws OseeCoreException {
+ boolean isInUse = false;
+ for (AttributeType attrType : AttributeTypeManager.getAllTypes()) {
+ if (typeToDelete.getEnumTypeId() == attrType.getOseeEnumTypeId()) {
+ isInUse = true;
+ }
+ }
+ if (isInUse) {
+ throw new OseeStateException(String.format(
+ "Osee Enum Type: [%s] with id: [%s] is in use by enumerated attributes", typeToDelete.getEnumTypeName(),
+ typeToDelete.getEnumTypeId()));
+ }
+ ConnectionHandler.runPreparedUpdate(DELETE_ENUM_TYPE, typeToDelete.getEnumTypeId());
+ typeToDelete.internalSetDeleted(true);
+ // TODO signal to other clients - Event here
+ }
+
+ public static void removeEntries(final OseeEnumType enumType, final OseeEnumEntry... entries) throws OseeCoreException {
+ checkNull(entries);
+ if (entries.length > 0) {
+ final List<OseeEnumEntry> itemsToRemove = Arrays.asList(entries);
+ final List<ObjectPair<String, Integer>> newEntries = new ArrayList<ObjectPair<String, Integer>>();
+ for (OseeEnumEntry entry : enumType.values()) {
+ if (!itemsToRemove.contains(entry)) {
+ newEntries.add(entry.asObjectPair());
+ }
+ }
+ UpdateEnumTx updateEnumTx = new UpdateEnumTx(enumType, newEntries);
+ updateEnumTx.execute();
+
+ enumType.internalRemoveEnums(entries);
+ // TODO Signal to other clients - Event here
+ }
+ }
+
+ public static void addEntries(final OseeEnumType oseeEnumType, final ObjectPair<String, Integer>... entries) throws OseeCoreException {
+ addEntries(oseeEnumType, Collections.getAggregate(entries));
+ }
+
+ public static void addEntries(final OseeEnumType oseeEnumType, final List<ObjectPair<String, Integer>> entries) throws OseeCoreException {
+ checkNull(oseeEnumType);
+ final List<ObjectPair<String, Integer>> newEntries = getCombinedEntries(oseeEnumType, entries);
+
+ UpdateEnumTx updateEnumTx = new UpdateEnumTx(oseeEnumType, newEntries);
+ updateEnumTx.execute();
+
+ boolean wasCreated = false;
+ if (!instance.enumTypeByIdMap.containsKey(oseeEnumType.getEnumTypeId())) {
+ instance.cache(oseeEnumType);
+ wasCreated = true;
+ }
+ for (ObjectPair<String, Integer> entry : entries) {
+ oseeEnumType.internalAddEnum(entry);
+ }
+ // TODO Signal to other clients - Event here
+ if (wasCreated) {
+ // TODO Signal newly created - Event here
+ }
+ }
+
+ private static List<ObjectPair<String, Integer>> getCombinedEntries(final OseeEnumType enumType, final List<ObjectPair<String, Integer>> entries) {
+ final List<ObjectPair<String, Integer>> combinedList = new ArrayList<ObjectPair<String, Integer>>();
+ if (entries != null) {
+ combinedList.addAll(entries);
+ }
+ for (OseeEnumEntry entry : enumType.values()) {
+ combinedList.add(entry.asObjectPair());
+ }
+ return combinedList;
+ }
+
+ private static final class UpdateEnumTx extends DbTransaction {
+ private final List<ObjectPair<String, Integer>> entries;
+ private final OseeEnumType enumType;
+
+ public UpdateEnumTx(final OseeEnumType enumType, final List<ObjectPair<String, Integer>> entries) throws OseeCoreException {
+ super();
+ this.enumType = enumType;
+ this.entries = entries;
+ }
+
+ @Override
+ protected void handleTxWork(OseeConnection connection) throws OseeCoreException {
+ checkNull(enumType);
+ checkEntryIntegrity(enumType.getEnumTypeName(), entries);
+
+ Integer oseeEnumTypeId = enumType.getEnumTypeId();
+ List<Object[]> data = new ArrayList<Object[]>();
+ for (ObjectPair<String, Integer> entry : entries) {
+ data.add(new Object[] {oseeEnumTypeId, entry.object1, entry.object2});
+ }
+ ConnectionHandler.runPreparedUpdate(connection, DELETE_ENUM_TYPE_ENTRIES, oseeEnumTypeId);
+ if (!data.isEmpty()) {
+ ConnectionHandler.runBatchUpdate(connection, INSERT_ENUM_TYPE_DEF, data);
+ }
+ }
+ };
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumerationValidation.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumerationValidation.java
new file mode 100644
index 00000000000..80044eaa60d
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumerationValidation.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.validation.IOseeValidator;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class OseeEnumerationValidation implements IOseeValidator {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.validation.IOseeValidator#getQualityOfService()
+ */
+ @Override
+ public int getQualityOfService() {
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.validation.IOseeValidator#isApplicable(org.eclipse.osee.framework.skynet.core.artifact.Artifact, org.eclipse.osee.framework.skynet.core.attribute.AttributeType)
+ */
+ @Override
+ public boolean isApplicable(Artifact artifact, AttributeType attributeType) {
+ Class<?> baseClass = attributeType.getBaseAttributeClass();
+ return EnumeratedAttribute.class.isAssignableFrom(baseClass);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.validation.IOseeValidator#validate(org.eclipse.osee.framework.skynet.core.artifact.Artifact, java.lang.Object)
+ */
+ @Override
+ public IStatus validate(Artifact artifact, AttributeType attributeType, Object proposedObject) throws OseeCoreException {
+ String text = (String) proposedObject;
+ OseeEnumType oseeEnumType = OseeEnumTypeManager.getType(attributeType.getOseeEnumTypeId());
+ oseeEnumType.valueOf(text);
+
+ return Status.OK_STATUS;
+ }
+
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/StringAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/StringAttribute.java
new file mode 100644
index 00000000000..203b09755f5
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/StringAttribute.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class StringAttribute extends CharacterBackedAttribute<String> {
+
+ public StringAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#getValue()
+ */
+ @Override
+ public String getValue() throws OseeCoreException {
+ return getAttributeDataProvider().getValueAsString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#subClassSetValue(java.lang.Object)
+ */
+ @Override
+ public boolean subClassSetValue(String value) throws OseeCoreException {
+ return getAttributeDataProvider().setValue(value);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#convertStringToValue(java.lang.String)
+ */
+ @Override
+ protected String convertStringToValue(String value) throws OseeCoreException {
+ return value;
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/TypeValidityManager.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/TypeValidityManager.java
new file mode 100644
index 00000000000..794bdcdca64
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/TypeValidityManager.java
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.TreeSet;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.ConnectionHandler;
+import org.eclipse.osee.framework.db.connection.ConnectionHandlerStatement;
+import org.eclipse.osee.framework.db.connection.exception.BranchDoesNotExist;
+import org.eclipse.osee.framework.db.connection.exception.OseeArgumentException;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeTypeDoesNotExist;
+import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap;
+import org.eclipse.osee.framework.jdk.core.type.HashCollection;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.skynet.core.artifact.ArtifactType;
+import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager;
+import org.eclipse.osee.framework.skynet.core.artifact.Branch;
+import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
+import org.eclipse.osee.framework.skynet.core.internal.Activator;
+
+/**
+ * Caches the mapping of valid attribute types to artifact types for which they are valid
+ *
+ * @see org.eclipse.osee.framework.skynet.core.artifact.ArtifactType
+ * @author Ryan D. Brooks
+ */
+public class TypeValidityManager {
+ private static final String SELECT_ATTRIBUTE_VALIDITY = "SELECT * FROM osee_valid_attributes";
+ private static final String INSERT_VALID_ATTRIBUTE =
+ "INSERT INTO osee_valid_attributes (art_type_id, attr_type_id, branch_id) VALUES (?, ?, ?)";
+ private static final TypeValidityManager instance = new TypeValidityManager();
+
+ private final CompositeKeyHashMap<Branch, ArtifactType, Collection<AttributeType>> artifactToAttributeMap =
+ new CompositeKeyHashMap<Branch, ArtifactType, Collection<AttributeType>>();
+ private final CompositeKeyHashMap<Branch, AttributeType, Collection<ArtifactType>> attributeToartifactMap =
+ new CompositeKeyHashMap<Branch, AttributeType, Collection<ArtifactType>>();
+
+ private final HashCollection<Branch, ArtifactType> branchToartifactTypeMap =
+ new HashCollection<Branch, ArtifactType>(false, TreeSet.class);
+
+ private TypeValidityManager() {
+ }
+
+ private static synchronized void ensurePopulated() throws OseeCoreException {
+ if (instance.artifactToAttributeMap.isEmpty()) {
+ instance.populateCache();
+ }
+ }
+
+ private void populateCache() throws OseeCoreException {
+ branchToartifactTypeMap.put(BranchManager.getSystemRootBranch(), ArtifactTypeManager.getAllTypes());
+
+ ConnectionHandlerStatement chStmt = new ConnectionHandlerStatement();
+ try {
+ chStmt.runPreparedQuery(2000, SELECT_ATTRIBUTE_VALIDITY);
+ while (chStmt.next()) {
+ try {
+ ArtifactType artifactType = ArtifactTypeManager.getType(chStmt.getInt("art_type_id"));
+ AttributeType attributeType = AttributeTypeManager.getType(chStmt.getInt("attr_type_id"));
+ Branch branch = BranchManager.getBranch(chStmt.getInt("branch_id"));
+
+ cacheAttributeValidity(artifactType, attributeType, branch);
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ }
+ } finally {
+ chStmt.close();
+ }
+ }
+
+ public static Collection<ArtifactType> getArtifactTypesFromAttributeType(String requestedAttributeType, Branch branch) throws OseeCoreException {
+ return getArtifactTypesFromAttributeType(AttributeTypeManager.getType(requestedAttributeType), branch);
+ }
+
+ /**
+ * Update type data to associate attributeType with artifactType on the given branch
+ *
+ * @param artifactType
+ * @param attributeType
+ * @param branch
+ * @throws OseeDataStoreException
+ * @throws BranchDoesNotExist
+ */
+ public static void persistAttributeValidity(ArtifactType artifactType, AttributeType attributeType, Branch branch) throws OseeCoreException {
+ if (!isValid(artifactType, attributeType, branch)) {
+ ConnectionHandler.runPreparedUpdate(INSERT_VALID_ATTRIBUTE, artifactType.getArtTypeId(),
+ attributeType.getAttrTypeId(), branch.getBranchId());
+
+ instance.cacheAttributeValidity(artifactType, attributeType, branch);
+ }
+ }
+
+ public static Collection<ArtifactType> getArtifactTypesFromAttributeType(AttributeType requestedAttributeType, Branch branch) throws OseeCoreException {
+ ensurePopulated();
+
+ Collection<ArtifactType> inheritedArtifactTypes = new HashSet<ArtifactType>();
+ Branch branchCursor = branch;
+ boolean notDone = true;
+ while (notDone) {
+ Collection<ArtifactType> artifactTypes =
+ instance.attributeToartifactMap.get(branchCursor, requestedAttributeType);
+ if (artifactTypes != null) {
+ inheritedArtifactTypes.addAll(artifactTypes);
+ }
+
+ if (branchCursor.isSystemRootBranch()) {
+ notDone = false;
+ } else {
+ branchCursor = branchCursor.getParentBranch();
+ }
+ }
+
+ if (inheritedArtifactTypes.isEmpty()) {
+ throw new OseeTypeDoesNotExist(
+ "There are no valid artifact types available for the attribute type " + requestedAttributeType);
+ }
+
+ return inheritedArtifactTypes;
+ }
+
+ public static Collection<AttributeType> getAttributeTypesFromArtifactType(ArtifactType artifactType, Branch branch) throws OseeCoreException {
+ ensurePopulated();
+
+ Collection<AttributeType> inhieritedAttributeTypes = new HashSet<AttributeType>();
+ Branch branchCursor = branch;
+ boolean notDone = true;
+ while (notDone) {
+ Collection<AttributeType> attributeTypes = instance.artifactToAttributeMap.get(branchCursor, artifactType);
+ if (attributeTypes != null) {
+ inhieritedAttributeTypes.addAll(attributeTypes);
+ }
+
+ if (branchCursor.isSystemRootBranch()) {
+ notDone = false;
+ } else {
+ branchCursor = branchCursor.getParentBranch();
+ }
+ }
+
+ if (inhieritedAttributeTypes.isEmpty()) {
+ throw new OseeTypeDoesNotExist(
+ "There are no valid attribute types available for the artifact type \"" + artifactType + "\"");
+ }
+ return inhieritedAttributeTypes;
+ }
+
+ public static boolean isValid(ArtifactType artifactType, AttributeType attributeType, Branch branch) throws OseeCoreException {
+ ensurePopulated();
+ Collection<AttributeType> attributeTypes = instance.artifactToAttributeMap.get(branch, artifactType);
+ if (attributeTypes != null) {
+ for (AttributeType otherAttributeType : attributeTypes) {
+ if (attributeType.equals(otherAttributeType)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void cacheAttributeValidity(ArtifactType artifactType, AttributeType attributeType, Branch branch) throws OseeDataStoreException {
+ Collection<AttributeType> attributeTypes = artifactToAttributeMap.get(branch, artifactType);
+ if (attributeTypes == null) {
+ attributeTypes = new LinkedList<AttributeType>();
+ artifactToAttributeMap.put(branch, artifactType, attributeTypes);
+ }
+ attributeTypes.add(attributeType);
+
+ Collection<ArtifactType> artifactTypes = attributeToartifactMap.get(branch, attributeType);
+ if (artifactTypes == null) {
+ artifactTypes = new LinkedList<ArtifactType>();
+ attributeToartifactMap.put(branch, attributeType, artifactTypes);
+ }
+ artifactTypes.add(artifactType);
+ }
+
+ public static Collection<AttributeType> getValidAttributeTypes(Branch branch) throws OseeCoreException {
+ return AttributeTypeManager.getAllTypes();
+ }
+
+ public static Collection<ArtifactType> getValidArtifactTypes(Branch branch) throws OseeCoreException {
+ if (false) { // TODO: Filter Types By Branch
+ ensurePopulated();
+ Branch topLevelBranch = branch.getTopLevelBranch();
+ Collection<ArtifactType> artifactTypes = instance.branchToartifactTypeMap.getValues(topLevelBranch);
+ if (artifactTypes == null) {
+ throw new OseeArgumentException(
+ "There are no valid artifact types available for the branch " + topLevelBranch);
+ }
+ return artifactTypes;
+ } else {
+ return ArtifactTypeManager.getAllTypes();
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordAttribute.java
new file mode 100644
index 00000000000..403b18245da
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordAttribute.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import java.io.InputStream;
+import org.eclipse.osee.framework.core.enums.BranchType;
+import org.eclipse.osee.framework.db.connection.exception.OseeArgumentException;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.jdk.core.util.io.xml.XmlTextInputStream;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.word.WordAnnotationHandler;
+import org.eclipse.osee.framework.skynet.core.word.WordUtil;
+
+/**
+ * @author Jeff C. Phillips
+ */
+public class WordAttribute extends StringAttribute {
+ public static final String WORD_TEMPLATE_CONTENT = "Word Template Content";
+ public static final String WHOLE_WORD_CONTENT = "Whole Word Content";
+ public static final String OLE_DATA_NAME = "Word Ole Data";
+ public static boolean noPopUps = false;
+ public static String displayTrackedChangesErrorMessage = "";
+
+ /**
+ * wraps the value in a simple word paragraph
+ *
+ * @param attributeType
+ * @param value
+ */
+ public WordAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ displayTrackedChangesErrorMessage = "";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#setValue(java.lang.Object)
+ */
+ @Override
+ public boolean subClassSetValue(String value) throws OseeCoreException {
+ // Do not allow save on tracked changes except on three way merges
+ if (WordAnnotationHandler.containsWordAnnotations(value) && getArtifact().getBranch().getBranchType() != BranchType.MERGE) {
+ displayTrackedChangesErrorMessage = "Cannot save - Detected tracked changes on this artifact. ";
+ throw new OseeArgumentException(displayTrackedChangesErrorMessage);
+ } else {
+ value = WordUtil.removeWordMarkupSmartTags(value);
+ return super.subClassSetValue(value);
+ }
+ }
+
+ public boolean containsWordAnnotations() throws OseeCoreException {
+ String temp = getValue();
+ return WordAnnotationHandler.containsWordAnnotations(temp);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.Attribute#getDisplayableString()
+ */
+ @Override
+ public String getDisplayableString() throws OseeCoreException {
+ InputStream inputStream = null;
+ try {
+ inputStream = new XmlTextInputStream(getValue());
+ return Lib.inputStreamToString(inputStream);
+ } catch (Exception ex) {
+ throw new OseeWrappedException(ex);
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (Exception ex) {
+ // Do Nothing
+ }
+ }
+ }
+ }
+
+ /**
+ * Mainly used for testing purposes
+ *
+ * @return the noPopUps
+ */
+ public static boolean isNoPopUps() {
+ return noPopUps;
+ }
+
+ /**
+ * Mainly used for testing purposes
+ *
+ * @param noPopUps the noPopUps to set
+ */
+ public static void setNoPopUps(boolean noPopUps) {
+ WordAttribute.noPopUps = noPopUps;
+ }
+
+ /**
+ * Mainly used for testing purposes
+ *
+ * @return the displayTrackedChangesErrorMessage
+ */
+ public static String getDisplayTrackedChangesErrorMessage() {
+ return displayTrackedChangesErrorMessage;
+ }
+
+ /**
+ * Mainly used for testing purposes
+ *
+ * @param displayTrackedChangesErrorMessage the displayTrackedChangesErrorMessage to set
+ */
+ public static void setDisplayTrackedChangesErrorMessage(String displayTrackedChangesErrorMessage) {
+ WordAttribute.displayTrackedChangesErrorMessage = displayTrackedChangesErrorMessage;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordTemplateAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordTemplateAttribute.java
new file mode 100644
index 00000000000..a50d6187082
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordTemplateAttribute.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+
+/**
+ * @author Jeff C. Phillips
+ */
+public class WordTemplateAttribute extends WordAttribute {
+
+ public WordTemplateAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordWholeDocumentAttribute.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordWholeDocumentAttribute.java
new file mode 100644
index 00000000000..80d3c52505f
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/WordWholeDocumentAttribute.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.attribute;
+
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+
+/**
+ * @author Jeff C. Phillips
+ */
+public class WordWholeDocumentAttribute extends WordAttribute {
+ private static final String wordLeader1 =
+ "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" + "<?mso-application progid='Word.Document'?>";
+ private static final String wordLeader2 =
+ "<w:wordDocument xmlns:w='http://schemas.microsoft.com/office/word/2003/wordml' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:w10='urn:schemas-microsoft-com:office:word' xmlns:sl='http://schemas.microsoft.com/schemaLibrary/2003/core' xmlns:aml='http://schemas.microsoft.com/aml/2001/core' xmlns:wx='http://schemas.microsoft.com/office/word/2003/auxHint' xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' xmlns:wsp='http://schemas.microsoft.com/office/word/2003/wordml/sp2' xmlns:ns0='http://www.w3.org/2001/XMLSchema' xmlns:ns1='http://eclipse.org/artifact.xsd' xmlns:st1='urn:schemas-microsoft-com:office:smarttags' w:macrosPresent='no' w:embeddedObjPresent='no' w:ocxPresent='no' xml:space='preserve'>";
+ private static final String wordBody = "<w:body></w:body>";
+ private static final String wordTrailer = "</w:wordDocument> ";
+ private static final String emptyDocumentContent = wordLeader1 + wordLeader2 + wordBody + wordTrailer;
+
+ /**
+ * @param attributeType
+ * @param value
+ */
+ public WordWholeDocumentAttribute(AttributeType attributeType, Artifact artifact) {
+ super(attributeType, artifact);
+ }
+
+ public static String getEmptyDocumentContent() {
+ return emptyDocumentContent;
+ }
+
+ // /* (non-Javadoc)
+ // * @see org.eclipse.osee.framework.skynet.core.attribute.StringAttribute#initializeDefaultValue()
+ // */
+ // @Override
+ // public void initializeToDefaultValue() {
+ // String value = getAttributeType().getDefaultValue();
+ // if (value == null || value.matches("")) {
+ // value = emptyDocumentContent;
+ // }
+ // subClassSetValue(value);
+ // }
+
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/AbstractAttributeDataProvider.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/AbstractAttributeDataProvider.java
new file mode 100644
index 00000000000..807c037bc77
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/AbstractAttributeDataProvider.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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.attribute.providers;
+
+import org.eclipse.osee.framework.skynet.core.attribute.Attribute;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public abstract class AbstractAttributeDataProvider implements IAttributeDataProvider {
+ private Attribute<?> attribute;
+
+ /**
+ * @param attribute
+ */
+ public AbstractAttributeDataProvider(Attribute<?> attribute) {
+ super();
+ this.attribute = attribute;
+ }
+
+ /**
+ * @return the attribute
+ */
+ protected Attribute<?> getAttribute() {
+ return attribute;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/ClobAttributeDataProvider.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/ClobAttributeDataProvider.java
new file mode 100644
index 00000000000..0717b5423fa
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/ClobAttributeDataProvider.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.attribute.providers;
+
+import org.eclipse.osee.framework.skynet.core.attribute.Attribute;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ClobAttributeDataProvider extends DefaultAttributeDataProvider {
+ /**
+ * @param attributeStateManager
+ */
+ public ClobAttributeDataProvider(Attribute<?> attribute) {
+ super(attribute);
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/DataStore.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/DataStore.java
new file mode 100644
index 00000000000..41a5805a18e
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/DataStore.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * 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.attribute.providers;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Arrays;
+import org.eclipse.osee.framework.core.exception.OseeAuthenticationRequiredException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.skynet.core.attribute.utils.AbstractResourceProcessor;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DataStore {
+ private AbstractResourceProcessor resourceProcessor;
+ private String locator;
+ private byte[] rawContent;
+ private String contentType;
+ private String encoding;
+ private String extension;
+ private boolean needToReadFromRemote;
+
+ public DataStore(AbstractResourceProcessor resourceProcessor) {
+ super();
+ this.resourceProcessor = resourceProcessor;
+ clear();
+ this.needToReadFromRemote = true;
+ }
+
+ public String getLocator() {
+ return this.locator;
+ }
+
+ public void setLocator(String locator) {
+ this.locator = locator;
+ needToReadFromRemote = true;
+ }
+
+ public boolean isLocatorValid() {
+ return this.locator != null && this.locator.length() > 0;
+ }
+
+ public boolean isDataValid() {
+ return this.rawContent != null && this.rawContent.length > 0;
+ }
+
+ public InputStream getInputStream() throws OseeDataStoreException, OseeAuthenticationRequiredException {
+ return new ByteArrayInputStream(getContent());
+ }
+
+ public byte[] getContent() throws OseeDataStoreException, OseeAuthenticationRequiredException {
+ if (isLocatorValid() != false && needToReadFromRemote) {
+ resourceProcessor.acquire(this);
+ needToReadFromRemote = false;
+ }
+ return this.rawContent;
+ }
+
+ public void setContent(byte[] rawContent, String extension, String contentType, String encoding) {
+ this.rawContent = rawContent;
+ this.contentType = contentType;
+ this.encoding = encoding;
+ this.extension = extension;
+ }
+
+ public void copyTo(DataStore other) {
+ other.rawContent = Arrays.copyOf(this.rawContent, this.rawContent.length);
+ other.contentType = this.contentType;
+ other.encoding = this.encoding;
+ }
+
+ public void persist(int storageId) throws OseeDataStoreException, OseeAuthenticationRequiredException {
+ if (this.rawContent != null && this.rawContent.length > 0) {
+ resourceProcessor.saveResource(storageId, resourceProcessor.getStorageName(), this);
+ }
+ }
+
+ public void purge() throws OseeDataStoreException {
+ if (isLocatorValid() != false) {
+ resourceProcessor.purge(this);
+ }
+ }
+
+ /**
+ * @return the contentType
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+ /**
+ * @return the encoding
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ public void clear() {
+ setContent(null, "txt", "txt/plain", "UTF-8");
+ setLocator(null);
+ }
+
+ /**
+ * @return the extension
+ */
+ public String getExtension() {
+ return extension;
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/DefaultAttributeDataProvider.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/DefaultAttributeDataProvider.java
new file mode 100644
index 00000000000..c3820831264
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/DefaultAttributeDataProvider.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * 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.attribute.providers;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import org.eclipse.osee.framework.core.exception.OseeAuthenticationRequiredException;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.skynet.core.attribute.Attribute;
+import org.eclipse.osee.framework.skynet.core.attribute.AttributeResourceProcessor;
+import org.eclipse.osee.framework.skynet.core.attribute.utils.BinaryContentUtils;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DefaultAttributeDataProvider extends AbstractAttributeDataProvider implements ICharacterAttributeDataProvider {
+
+ private static final int MAX_VARCHAR_LENGTH = 4000;
+ private String rawStringValue;
+
+ private final DataStore dataStore;
+
+ /**
+ * @param attributeStateManager
+ */
+ public DefaultAttributeDataProvider(Attribute<?> attribute) {
+ super(attribute);
+ this.dataStore = new DataStore(new AttributeResourceProcessor(attribute));
+ this.rawStringValue = "";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.AbstractAttributeDataProvider#getDisplayableString()
+ */
+ @Override
+ public String getDisplayableString() throws OseeCoreException {
+ return getValueAsString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.AbstractAttributeDataProvider#setDisplayableString(java.lang.String)
+ */
+ @Override
+ public void setDisplayableString(String toDisplay) throws OseeDataStoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.ICharacterAttributeDataProvider#getValueAsString()
+ */
+ @Override
+ public String getValueAsString() throws OseeCoreException {
+ String fromStorage = null;
+ byte[] data = null;
+ try {
+ data = dataStore.getContent();
+ if (data != null) {
+ data = Lib.decompressBytes(new ByteArrayInputStream(data));
+ fromStorage = new String(data, "UTF-8");
+ }
+ } catch (IOException ex) {
+ throw new OseeWrappedException("Error retrieving data.", ex);
+ }
+ String toReturn = fromStorage != null ? fromStorage : rawStringValue;
+ return toReturn != null ? toReturn : "";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.ICharacterAttributeDataProvider#setValue(java.lang.String)
+ */
+ @Override
+ public boolean setValue(String value) throws OseeCoreException {
+ boolean response = false;
+ if (getValueAsString() == value || (getValueAsString() != null && getValueAsString().equals(value))) {
+ response = false;
+ } else {
+ storeValue(value);
+ response = true;
+ }
+ return response;
+ }
+
+ private String getInternalFileName() throws OseeCoreException {
+ return BinaryContentUtils.generateFileName(getAttribute());
+ }
+
+ private void storeValue(String value) throws OseeCoreException {
+ if (value != null && value.length() > MAX_VARCHAR_LENGTH) {
+ try {
+ byte[] compressed =
+ Lib.compressStream(new ByteArrayInputStream(value.getBytes("UTF-8")), getInternalFileName());
+ dataStore.setContent(compressed, "zip", "application/zip", "ISO-8859-1");
+ } catch (IOException ex) {
+ throw new OseeWrappedException(ex);
+ }
+ } else {
+ this.rawStringValue = value;
+ dataStore.clear();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.IDataAccessObject#getData()
+ */
+ @Override
+ public Object[] getData() throws OseeDataStoreException {
+ return new Object[] {rawStringValue, dataStore.getLocator()};
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.IDataAccessObject#loadData(java.lang.Object[])
+ */
+ @Override
+ public void loadData(Object... objects) throws OseeCoreException {
+ if (objects != null && objects.length > 1) {
+ storeValue((String) objects[0]);
+ dataStore.setLocator((String) objects[1]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.IDataAccessObject#persist()
+ */
+ @Override
+ public void persist(int storageId) throws OseeDataStoreException, OseeAuthenticationRequiredException {
+ dataStore.persist(storageId);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.IAttributeDataProvider#purge()
+ */
+ @Override
+ public void purge() throws OseeCoreException {
+ dataStore.purge();
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/IAttributeDataProvider.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/IAttributeDataProvider.java
new file mode 100644
index 00000000000..3e2b27f5bbf
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/IAttributeDataProvider.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.attribute.providers;
+
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface IAttributeDataProvider {
+
+ public String getDisplayableString() throws OseeCoreException;
+
+ public void setDisplayableString(String toDisplay) throws OseeDataStoreException;
+
+ public void loadData(Object... objects) throws OseeCoreException;
+
+ public Object[] getData() throws OseeDataStoreException;
+
+ public void persist(int storageId) throws OseeCoreException;
+
+ public void purge() throws OseeCoreException;
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/IBinaryAttributeDataProvider.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/IBinaryAttributeDataProvider.java
new file mode 100644
index 00000000000..dc00a9839be
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/IBinaryAttributeDataProvider.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.attribute.providers;
+
+import java.nio.ByteBuffer;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface IBinaryAttributeDataProvider extends IAttributeDataProvider {
+
+ public ByteBuffer getValueAsBytes() throws OseeCoreException;
+
+ public boolean setValue(ByteBuffer data) throws OseeCoreException;
+
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/ICharacterAttributeDataProvider.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/ICharacterAttributeDataProvider.java
new file mode 100644
index 00000000000..b94a510a804
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/ICharacterAttributeDataProvider.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.attribute.providers;
+
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface ICharacterAttributeDataProvider extends IAttributeDataProvider {
+
+ public String getValueAsString() throws OseeCoreException;
+
+ public boolean setValue(String value) throws OseeCoreException;
+
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/UriAttributeDataProvider.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/UriAttributeDataProvider.java
new file mode 100644
index 00000000000..484f4d7d856
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/providers/UriAttributeDataProvider.java
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * 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.attribute.providers;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import org.eclipse.osee.framework.core.exception.OseeAuthenticationRequiredException;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.skynet.core.attribute.Attribute;
+import org.eclipse.osee.framework.skynet.core.attribute.AttributeResourceProcessor;
+import org.eclipse.osee.framework.skynet.core.attribute.utils.AbstractResourceProcessor;
+import org.eclipse.osee.framework.skynet.core.attribute.utils.BinaryContentUtils;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class UriAttributeDataProvider extends AbstractAttributeDataProvider implements ICharacterAttributeDataProvider, IBinaryAttributeDataProvider {
+ private DataStore dataStore;
+ private String displayable;
+
+ public UriAttributeDataProvider(Attribute<?> attribute) {
+ super(attribute);
+ AbstractResourceProcessor abstractResourceProcessor = new AttributeResourceProcessor(attribute);
+ this.dataStore = new DataStore(abstractResourceProcessor);
+ this.displayable = "";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.IAttributeDataProvider#getDisplayableString()
+ */
+ @Override
+ public String getDisplayableString() throws OseeDataStoreException {
+ return displayable;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.IAttributeDataProvider#setDisplayableString(java.lang.String)
+ */
+ @Override
+ public void setDisplayableString(String toDisplay) throws OseeDataStoreException {
+ this.displayable = toDisplay;
+ }
+
+ private String getInternalFileName() throws OseeCoreException {
+ return BinaryContentUtils.generateFileName(getAttribute());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.IAttributeDataProvider#setValue(ByteBuffer)
+ */
+ @Override
+ public boolean setValue(ByteBuffer data) throws OseeCoreException {
+ boolean response = false;
+ try {
+ if (!Arrays.equals(dataStore.getContent(), data != null ? data.array() : null)) {
+ if (data != null) {
+ byte[] compressed;
+ compressed = Lib.compressStream(Lib.byteBufferToInputStream(data), getInternalFileName());
+ dataStore.setContent(compressed, "zip", "application/zip", "ISO-8859-1");
+ response = true;
+ } else {
+ String loc = dataStore.getLocator();
+ dataStore.clear();
+ dataStore.setLocator(loc);
+ }
+ }
+ } catch (IOException ex) {
+ throw new OseeWrappedException("Error committing data. ", ex);
+ }
+ return response;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.IAttributeDataProvider#getValueAsBytes()
+ */
+ @Override
+ public ByteBuffer getValueAsBytes() throws OseeCoreException {
+ ByteBuffer decompressed = null;
+ byte[] rawData = dataStore.getContent();
+ if (rawData != null) {
+ try {
+ decompressed = ByteBuffer.wrap(Lib.decompressBytes(new ByteArrayInputStream(rawData)));
+ } catch (IOException ex) {
+ throw new OseeWrappedException("Error acquiring data. - ", ex);
+ }
+ }
+
+ return decompressed;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.data.IStringAttributeDataProvider#getValueAsString()
+ */
+ @Override
+ public String getValueAsString() throws OseeCoreException {
+ String toReturn = null;
+ ByteBuffer data = getValueAsBytes();
+ if (data != null) {
+ try {
+ toReturn = new String(data.array(), "UTF-8");
+ } catch (UnsupportedEncodingException ex) {
+ throw new OseeWrappedException("Error encoding data.", ex);
+ }
+ } else {
+ toReturn = "";
+ }
+ return toReturn;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.data.IStringAttributeDataProvider#setValue(java.lang.String)
+ */
+ @Override
+ public boolean setValue(String value) throws OseeCoreException {
+ ByteBuffer toSet = null;
+ if (value != null) {
+ try {
+ toSet = ByteBuffer.wrap(value.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException ex) {
+ throw new OseeWrappedException("Error encoding data.", ex);
+ }
+ }
+ setValue(toSet);
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.IDataAccessObject#getData()
+ */
+ @Override
+ public Object[] getData() throws OseeDataStoreException {
+ return new Object[] {"", dataStore.getLocator()};
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.IDataAccessObject#loadData(java.lang.Object[])
+ */
+ @Override
+ public void loadData(Object... objects) throws OseeCoreException {
+ if (objects != null && objects.length > 1) {
+ dataStore.setLocator((String) objects[1]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.IDataAccessObject#persist()
+ */
+ @Override
+ public void persist(int storageId) throws OseeDataStoreException, OseeAuthenticationRequiredException {
+ dataStore.persist(storageId);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.skynet.core.attribute.providers.IAttributeDataProvider#purge()
+ */
+ @Override
+ public void purge() throws OseeCoreException {
+ dataStore.purge();
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/AbstractResourceProcessor.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/AbstractResourceProcessor.java
new file mode 100644
index 00000000000..35b2f1e020f
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/AbstractResourceProcessor.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * 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.attribute.utils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.URL;
+import org.eclipse.osee.framework.core.exception.OseeAuthenticationRequiredException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.jdk.core.util.HttpProcessor;
+import org.eclipse.osee.framework.jdk.core.util.HttpProcessor.AcquireResult;
+import org.eclipse.osee.framework.skynet.core.attribute.providers.DataStore;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public abstract class AbstractResourceProcessor {
+
+ protected abstract URL getAcquireURL(DataStore dataStore) throws OseeDataStoreException, OseeAuthenticationRequiredException;
+
+ protected abstract URL getDeleteURL(DataStore dataStore) throws OseeDataStoreException, OseeAuthenticationRequiredException;
+
+ protected abstract URL getStorageURL(int seed, String name, String extension) throws OseeDataStoreException, OseeAuthenticationRequiredException;
+
+ public abstract String getStorageName();
+
+ public void saveResource(int seed, String name, DataStore dataStore) throws OseeDataStoreException, OseeAuthenticationRequiredException {
+ URL url = getStorageURL(seed, name, dataStore.getExtension());
+ InputStream inputStream = dataStore.getInputStream();
+ try {
+ URI uri = HttpProcessor.save(url, inputStream, dataStore.getContentType(), dataStore.getEncoding());
+ dataStore.setLocator(uri.toASCIIString());
+ } catch (Exception ex) {
+ throw new OseeDataStoreException("Error saving resource", ex);
+ } finally {
+ try {
+ inputStream.close();
+ } catch (Exception ex) {
+ throw new OseeDataStoreException("Error closing stream during save resource", ex);
+ }
+ }
+ }
+
+ public void acquire(DataStore dataStore) throws OseeDataStoreException, OseeAuthenticationRequiredException {
+ URL url = getAcquireURL(dataStore);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ AcquireResult result;
+ try {
+ result = HttpProcessor.acquire(url, outputStream);
+ } catch (Exception ex) {
+ throw new OseeDataStoreException(String.format("Error acquiring resource: [%s]", dataStore.getLocator()), ex);
+ }
+
+ int code = result.getCode();
+ if (code == HttpURLConnection.HTTP_OK) {
+ dataStore.setContent(outputStream.toByteArray(), "", result.getContentType(), result.getEncoding());
+ } else {
+ throw new OseeDataStoreException(String.format("Error acquiring resource: [%s] - status code: [%s]; %s",
+ dataStore.getLocator(), code, new String(outputStream.toByteArray())));
+ }
+ }
+
+ public void purge(DataStore dataStore) throws OseeDataStoreException {
+ int code = -1;
+ try {
+ URL url = getDeleteURL(dataStore);
+ String response = HttpProcessor.delete(url);
+ if (response != null && response.equals("Deleted: " + dataStore.getLocator())) {
+ dataStore.clear();
+ }
+ } catch (Exception ex) {
+ throw new OseeDataStoreException(String.format("Error deleting resource: [%s] - status code: [%s]",
+ dataStore.getLocator(), code), ex);
+ }
+ }
+
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/AttributeURL.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/AttributeURL.java
new file mode 100644
index 00000000000..708e46b648a
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/AttributeURL.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.attribute.utils;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.osee.framework.core.client.ClientSessionManager;
+import org.eclipse.osee.framework.core.client.server.HttpUrlBuilder;
+import org.eclipse.osee.framework.core.data.OseeServerContext;
+import org.eclipse.osee.framework.core.exception.OseeAuthenticationRequiredException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AttributeURL {
+
+ private AttributeURL() {
+ }
+
+ public static URL getStorageURL(int gammaId, String artifactHrid, String extension) throws OseeDataStoreException, MalformedURLException, OseeAuthenticationRequiredException {
+ Map<String, String> parameterMap = new HashMap<String, String>();
+ parameterMap.put("sessionId", ClientSessionManager.getSessionId());
+ parameterMap.put("protocol", "attr");
+ parameterMap.put("seed", Integer.toString(gammaId));
+ parameterMap.put("name", artifactHrid);
+ if (Strings.isValid(extension) != false) {
+ parameterMap.put("extension", extension);
+ }
+ String urlString =
+ HttpUrlBuilder.getInstance().getOsgiServletServiceUrl(OseeServerContext.RESOURCE_CONTEXT, parameterMap);
+ return new URL(urlString);
+ }
+
+ private static URL generatePathURL(String uri) throws OseeDataStoreException {
+ try {
+ Map<String, String> parameterMap = new HashMap<String, String>();
+ parameterMap.put("sessionId", ClientSessionManager.getSessionId());
+ parameterMap.put("uri", uri);
+ String urlString =
+ HttpUrlBuilder.getInstance().getOsgiServletServiceUrl(OseeServerContext.RESOURCE_CONTEXT, parameterMap);
+ return new URL(urlString);
+ } catch (Exception ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public static URL getAcquireURL(String uri) throws OseeDataStoreException {
+ return generatePathURL(uri);
+ }
+
+ public static URL getDeleteURL(String uri) throws OseeDataStoreException {
+ return generatePathURL(uri);
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/BinaryContentUtils.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/BinaryContentUtils.java
new file mode 100644
index 00000000000..d2fae0d7f66
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/utils/BinaryContentUtils.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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.attribute.utils;
+
+import java.net.HttpURLConnection;
+import java.net.URLEncoder;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.skynet.core.attribute.Attribute;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class BinaryContentUtils {
+
+ private final static int MAX_NAME_SIZE = 60;
+
+ private BinaryContentUtils() {
+ }
+
+ public static String getContentType(String extension) {
+ String contentType = null;
+ if (Strings.isValid(extension)) {
+ contentType = HttpURLConnection.guessContentTypeFromName("dummy." + extension);
+ } else {
+ contentType = "application/*";
+ }
+ return contentType;
+ }
+
+ public static String generateFileName(Attribute<?> attribute) throws OseeCoreException {
+ StringBuilder builder = new StringBuilder();
+ try {
+ String name = attribute.getArtifact().getDescriptiveName();
+ if (name.length() > MAX_NAME_SIZE) {
+ name = name.substring(0, MAX_NAME_SIZE);
+ }
+ builder.append(URLEncoder.encode(name, "UTF-8"));
+ builder.append(".");
+ } catch (Exception ex) {
+ // Do Nothing - this is not important
+ }
+ builder.append(attribute.getArtifact().getHumanReadableId());
+
+ String fileTypeExtension = getExtension(attribute);
+ if (Strings.isValid(fileTypeExtension)) {
+ builder.append(".");
+ builder.append(fileTypeExtension);
+ }
+ return builder.toString();
+ }
+
+ private static String getExtension(Attribute<?> attribute) throws OseeCoreException {
+ String fileTypeExtension = attribute.getAttributeType().getFileTypeExtension();
+ if (attribute.isOfType("Native Content")) {
+ fileTypeExtension = attribute.getArtifact().getSoleAttributeValue("Extension");
+ }
+ return fileTypeExtension;
+ }
+} \ No newline at end of file

Back to the top