From 0b99a5a8e99a6c2372d3328c057c64ee00e0372e Mon Sep 17 00:00:00 2001 From: rescobar Date: Thu, 6 Oct 2011 00:21:49 -0700 Subject: feature[ats_Q9NLC]: Attribute data proxy implementation --- .../osee/orcs/core/ds/AttributeContainer.java | 3 + .../org/eclipse/osee/orcs/core/ds/DataProxy.java | 6 +- .../osee/orcs/core/ds/ResourceNameResolver.java | 23 ++ .../osee/orcs/core/internal/artifact/Artifact.java | 6 + .../internal/attribute/AttributeContainerImpl.java | 11 + .../attribute/AttributeResourceNameResolver.java | 73 ++++++ .../META-INF/MANIFEST.MF | 2 + .../org/eclipse/osee/orcs/db/mock/OsgiUtil.java | 24 +- plugins/org.eclipse.osee.orcs.db.test/pom.xml | 5 + .../org/eclipse/osee/orcs/db/OrcsDbTestSuite.java | 5 +- .../osee/orcs/db/internal/InternalTestSuite.java | 25 ++ .../org/eclipse/osee/orcs/db/internal/SqlTest.java | 4 +- .../db/internal/loader/ArtifactLoaderTest.java | 13 +- .../orcs/db/internal/loader/LoaderTestSuite.java | 23 ++ .../db/internal/loader/RelationLoaderTest.java | 13 +- .../orcs/db/internal/proxy/ClobDataProxyTest.java | 59 +++++ .../orcs/db/internal/proxy/DataResourceTest.java | 145 ++++++++++++ .../orcs/db/internal/proxy/ProxyTestSuite.java | 29 +++ .../proxy/ResourceDataProxyFactoryTest.java | 31 +++ .../db/internal/proxy/ResourceHandlerTest.java | 57 +++++ .../osee/orcs/db/internal/proxy/StorageTest.java | 261 +++++++++++++++++++++ .../orcs/db/internal/proxy/UriDataProxyTest.java | 30 +++ .../osee/orcs/db/mocks/MockDataHandler.java | 114 +++++++++ .../orcs/db/mocks/MockResourceLocatorManager.java | 49 ++++ .../osee/orcs/db/mocks/MockResourceManager.java | 66 ++++++ .../orcs/db/mocks/MockResourceNameResolver.java | 47 ++++ .../OSGI-INF/data.proxy.factory.provider.xml | 4 +- .../orcs/db/internal/DataProxyFactoryProvider.java | 14 -- .../db/internal/DataProxyFactoryProviderImpl.java | 123 ++++++++++ .../internal/loader/AttributeDataProxyFactory.java | 7 +- .../orcs/db/internal/loader/AttributeLoader.java | 5 +- .../internal/loader/DataProxyFactoryProvider.java | 22 ++ .../orcs/db/internal/proxy/AbstractDataProxy.java | 54 +++++ .../db/internal/proxy/AbstractDataSourceProxy.java | 29 --- .../osee/orcs/db/internal/proxy/ClobDataProxy.java | 11 +- .../osee/orcs/db/internal/proxy/DataHandler.java | 4 +- .../proxy/DataProxyFactoryProviderImpl.java | 123 ---------- .../osee/orcs/db/internal/proxy/DataResource.java | 31 ++- .../orcs/db/internal/proxy/MappedDataProxy.java | 175 ++++++++++++++ .../db/internal/proxy/MappedFileDataProxy.java | 175 -------------- .../internal/proxy/ResourceDataProxyFactory.java | 34 +-- .../orcs/db/internal/proxy/ResourceHandler.java | 33 ++- .../osee/orcs/db/internal/proxy/Storage.java | 79 +++---- .../osee/orcs/db/internal/proxy/UriDataProxy.java | 10 +- .../orcs/db/internal/util/BinaryContentUtils.java | 75 ++---- 45 files changed, 1608 insertions(+), 524 deletions(-) create mode 100644 plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/ResourceNameResolver.java create mode 100644 plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeResourceNameResolver.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/InternalTestSuite.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/LoaderTestSuite.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ClobDataProxyTest.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/DataResourceTest.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ProxyTestSuite.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceDataProxyFactoryTest.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceHandlerTest.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/StorageTest.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/UriDataProxyTest.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockDataHandler.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceLocatorManager.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceManager.java create mode 100644 plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceNameResolver.java delete mode 100644 plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/DataProxyFactoryProvider.java create mode 100644 plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/DataProxyFactoryProviderImpl.java create mode 100644 plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataProxyFactoryProvider.java create mode 100644 plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/AbstractDataProxy.java delete mode 100644 plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/AbstractDataSourceProxy.java delete mode 100644 plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataProxyFactoryProviderImpl.java create mode 100644 plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedDataProxy.java delete mode 100644 plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedFileDataProxy.java (limited to 'plugins') diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeContainer.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeContainer.java index 25796f6fd04..6f781ce9b3a 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeContainer.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeContainer.java @@ -13,6 +13,7 @@ package org.eclipse.osee.orcs.core.ds; import java.util.Collection; import java.util.List; import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.data.NamedIdentity; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.orcs.core.internal.attribute.Attribute; import org.eclipse.osee.orcs.data.ReadableAttribute; @@ -22,6 +23,8 @@ import org.eclipse.osee.orcs.data.ReadableAttribute; */ public interface AttributeContainer { + NamedIdentity getParent(); + void add(IAttributeType type, Attribute attribute); int getCount(IAttributeType type) throws OseeCoreException; diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/DataProxy.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/DataProxy.java index eda47f058ab..a019f2f3ac9 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/DataProxy.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/DataProxy.java @@ -18,11 +18,15 @@ import org.eclipse.osee.framework.core.exception.OseeDataStoreException; */ public interface DataProxy { + public void setResolver(ResourceNameResolver resolver); + + public ResourceNameResolver getResolver(); + public String getDisplayableString() throws OseeCoreException; public void setDisplayableString(String toDisplay) throws OseeDataStoreException; - public void loadData(Object... objects) throws OseeCoreException; + public void setData(Object... objects) throws OseeCoreException; public Object[] getData() throws OseeDataStoreException; diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/ResourceNameResolver.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/ResourceNameResolver.java new file mode 100644 index 00000000000..d12a2bec410 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/ResourceNameResolver.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.orcs.core.ds; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; + +/** + * @author Roberto E. Escobar + */ +public interface ResourceNameResolver { + + String getStorageName() throws OseeCoreException; + + String getInternalFileName() throws OseeCoreException; +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/Artifact.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/Artifact.java index a3045d69a88..e9c58fe0894 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/Artifact.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/Artifact.java @@ -13,6 +13,7 @@ package org.eclipse.osee.orcs.core.internal.artifact; import java.util.Collection; import java.util.List; import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.data.NamedIdentity; import org.eclipse.osee.framework.core.enums.ModificationType; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.orcs.core.ds.AttributeContainer; @@ -62,4 +63,9 @@ public class Artifact implements AttributeContainer { public ReadableAttribute getSoleAttribute(IAttributeType attributeType) throws OseeCoreException { return null; } + + @Override + public NamedIdentity getParent() { + return null; + } } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeContainerImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeContainerImpl.java index 5a9c33ee3ba..2fa2bd0a94a 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeContainerImpl.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeContainerImpl.java @@ -13,6 +13,7 @@ package org.eclipse.osee.orcs.core.internal.attribute; import java.util.Collection; import java.util.List; import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.data.NamedIdentity; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.orcs.core.ds.AttributeContainer; import org.eclipse.osee.orcs.data.ReadableAttribute; @@ -24,8 +25,13 @@ public class AttributeContainerImpl implements AttributeContainer { private final AttributeCollection collection = new AttributeCollection(); + private final NamedIdentity parent; private boolean isLoaded; + public AttributeContainerImpl(NamedIdentity parent) { + this.parent = parent; + } + @Override public boolean isLoaded() { return isLoaded; @@ -75,4 +81,9 @@ public class AttributeContainerImpl implements AttributeContainer { public ReadableAttribute getSoleAttribute(IAttributeType attributeType) throws OseeCoreException { return null; } + + @Override + public NamedIdentity getParent() { + return parent; + } } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeResourceNameResolver.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeResourceNameResolver.java new file mode 100644 index 00000000000..2f84b85eca7 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeResourceNameResolver.java @@ -0,0 +1,73 @@ +/* + * Created on Oct 4, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.orcs.core.internal.attribute; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import org.eclipse.osee.framework.core.data.NamedIdentity; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.type.AttributeType; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.orcs.core.ds.ResourceNameResolver; + +public class AttributeResourceNameResolver implements ResourceNameResolver { + private final static int MAX_NAME_SIZE = 60; + + private final Attribute attribute; + + public AttributeResourceNameResolver(Attribute attribute) { + this.attribute = attribute; + } + + @Override + public String getStorageName() throws OseeCoreException { + NamedIdentity identity = attribute.getContainer().getParent(); + String guid = identity.getGuid(); + Conditions.checkExpressionFailOnTrue(!GUID.isValid(guid), "Artifact has an invalid guid [%s]", guid); + return guid; + } + + @Override + public String getInternalFileName() throws OseeCoreException { + NamedIdentity identity = attribute.getContainer().getParent(); + + StringBuilder builder = new StringBuilder(); + try { + String name = identity.getName(); + if (name.length() > MAX_NAME_SIZE) { + name = name.substring(0, MAX_NAME_SIZE); + } + builder.append(URLEncoder.encode(name, "UTF-8")); + builder.append("."); + } catch (UnsupportedEncodingException ex) { + // Do Nothing - this is not important + } + + builder.append(getStorageName()); + + String fileTypeExtension = getExtension(attribute); + if (Strings.isValid(fileTypeExtension)) { + builder.append("."); + builder.append(fileTypeExtension); + } + return builder.toString(); + } + + private String getExtension(Attribute attribute) throws OseeCoreException { + AttributeType attributeType = attribute.getAttributeType(); + String fileTypeExtension = null; + if (attribute.isOfType(CoreAttributeTypes.NativeContent)) { + fileTypeExtension = (String) attribute.getValue(); + } + if (!Strings.isValid(fileTypeExtension)) { + fileTypeExtension = attributeType.getFileTypeExtension(); + } + return fileTypeExtension; + } +} diff --git a/plugins/org.eclipse.osee.orcs.db.mock/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.db.mock/META-INF/MANIFEST.MF index 80a28e9da31..665c8b12e2b 100644 --- a/plugins/org.eclipse.osee.orcs.db.mock/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.orcs.db.mock/META-INF/MANIFEST.MF @@ -7,6 +7,7 @@ Bundle-Vendor: Eclipse Open System Engineering Environment Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Import-Package: org.eclipse.core.runtime;version="3.4.0", org.eclipse.osee.framework.core.data, + org.eclipse.osee.framework.core.exception, org.eclipse.osee.framework.database.core, org.eclipse.osee.framework.jdk.core.util, org.eclipse.osee.framework.jdk.core.util.network, @@ -18,3 +19,4 @@ Import-Package: org.eclipse.core.runtime;version="3.4.0", org.osgi.framework;version="1.6.0", org.osgi.util.tracker;version="1.5.0" Export-Package: org.eclipse.osee.orcs.db.mock +Require-Bundle: org.eclipse.core.runtime diff --git a/plugins/org.eclipse.osee.orcs.db.mock/src/org/eclipse/osee/orcs/db/mock/OsgiUtil.java b/plugins/org.eclipse.osee.orcs.db.mock/src/org/eclipse/osee/orcs/db/mock/OsgiUtil.java index dcb757d1a86..1f45791e53f 100644 --- a/plugins/org.eclipse.osee.orcs.db.mock/src/org/eclipse/osee/orcs/db/mock/OsgiUtil.java +++ b/plugins/org.eclipse.osee.orcs.db.mock/src/org/eclipse/osee/orcs/db/mock/OsgiUtil.java @@ -5,7 +5,12 @@ */ package org.eclipse.osee.orcs.db.mock; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeExceptions; +import org.junit.Assert; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; import org.osgi.framework.FrameworkUtil; import org.osgi.util.tracker.ServiceTracker; @@ -14,12 +19,27 @@ import org.osgi.util.tracker.ServiceTracker; */ public class OsgiUtil { - public static T getService(Class clazz) { + public static T getService(Class clazz) throws OseeCoreException { Bundle bundle = FrameworkUtil.getBundle(OseeDatabase.class); - ServiceTracker tracker = new ServiceTracker(bundle.getBundleContext(), clazz, null); + Assert.assertNotNull(bundle); + + int bundleState = bundle.getState(); + if (bundleState != Bundle.STARTING && bundleState != Bundle.ACTIVE) { + try { + bundle.start(); + } catch (BundleException ex) { + OseeExceptions.wrapAndThrow(ex); + } + } + BundleContext context = bundle.getBundleContext(); + Assert.assertNotNull(context); + + ServiceTracker tracker = new ServiceTracker(context, clazz, null); tracker.open(true); T service = tracker.getService(); tracker.close(); + + Assert.assertNotNull(service); return service; } } diff --git a/plugins/org.eclipse.osee.orcs.db.test/pom.xml b/plugins/org.eclipse.osee.orcs.db.test/pom.xml index 789f76ade7e..ddd36f076d9 100644 --- a/plugins/org.eclipse.osee.orcs.db.test/pom.xml +++ b/plugins/org.eclipse.osee.orcs.db.test/pom.xml @@ -29,6 +29,11 @@ org.h2 0.0.0 + + eclipse-plugin + org.eclipse.osee.framework.database + 0.0.0 + eclipse-plugin org.eclipse.osee.framework.h2 diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/OrcsDbTestSuite.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/OrcsDbTestSuite.java index bc37e479fa3..78b8a6c4ed5 100644 --- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/OrcsDbTestSuite.java +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/OrcsDbTestSuite.java @@ -10,8 +10,7 @@ *******************************************************************************/ package org.eclipse.osee.orcs.db; -import org.eclipse.osee.orcs.db.internal.loader.ArtifactLoaderTest; -import org.eclipse.osee.orcs.db.internal.loader.RelationLoaderTest; +import org.eclipse.osee.orcs.db.internal.InternalTestSuite; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -19,7 +18,7 @@ import org.junit.runners.Suite; * @author Roberto E. Escobar */ @RunWith(Suite.class) -@Suite.SuiteClasses({RelationLoaderTest.class, ArtifactLoaderTest.class}) +@Suite.SuiteClasses({InternalTestSuite.class}) public class OrcsDbTestSuite { // Test Suite } diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/InternalTestSuite.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/InternalTestSuite.java new file mode 100644 index 00000000000..1eb27fd4f73 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/InternalTestSuite.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.orcs.db.internal; + +import org.eclipse.osee.orcs.db.internal.proxy.ClobDataProxyTest; +import org.eclipse.osee.orcs.db.internal.proxy.ProxyTestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * @author Roberto E. Escobar + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ClobDataProxyTest.class, ProxyTestSuite.class}) +public class InternalTestSuite { + // Test Suite +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/SqlTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/SqlTest.java index d582799c0b0..8a8d1736667 100644 --- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/SqlTest.java +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/SqlTest.java @@ -11,9 +11,9 @@ package org.eclipse.osee.orcs.db.internal; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.database.core.ConnectionHandler; import org.eclipse.osee.framework.database.core.IOseeStatement; import org.eclipse.osee.orcs.db.mock.OseeDatabase; +import org.eclipse.osee.orcs.db.mock.OsgiUtil; import org.junit.Rule; /** @@ -26,7 +26,7 @@ public class SqlTest { @org.junit.Test public void testOne() throws OseeCoreException { - IOseeStatement chStmt = ConnectionHandler.getStatement(); + IOseeStatement chStmt = OsgiUtil.getService(IOseeStatement.class); chStmt.runPreparedQuery("select * from osee.osee_branch"); while (chStmt.next()) { System.out.println(chStmt.getString("branch_name")); diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/ArtifactLoaderTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/ArtifactLoaderTest.java index 3649b911290..f8bdc28eb2c 100644 --- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/ArtifactLoaderTest.java +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/ArtifactLoaderTest.java @@ -1,8 +1,13 @@ -/* - * Created on Oct 4, 2011 +/******************************************************************************* + * 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 * - * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE - */ + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ package org.eclipse.osee.orcs.db.internal.loader; import java.util.ArrayList; diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/LoaderTestSuite.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/LoaderTestSuite.java new file mode 100644 index 00000000000..36797d7ad86 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/LoaderTestSuite.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.orcs.db.internal.loader; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * @author Roberto E. Escobar + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ArtifactLoaderTest.class, RelationLoaderTest.class}) +public class LoaderTestSuite { + // Test Suite +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/RelationLoaderTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/RelationLoaderTest.java index 197041109cb..dc02d17cc67 100644 --- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/RelationLoaderTest.java +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/RelationLoaderTest.java @@ -1,8 +1,13 @@ -/* - * Created on Oct 4, 2011 +/******************************************************************************* + * 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 * - * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE - */ + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ package org.eclipse.osee.orcs.db.internal.loader; import java.util.ArrayList; diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ClobDataProxyTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ClobDataProxyTest.java new file mode 100644 index 00000000000..91c94aa1528 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ClobDataProxyTest.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.orcs.db.internal.proxy; + +import junit.framework.Assert; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.db.mock.MockLog; +import org.eclipse.osee.orcs.db.mocks.MockDataHandler; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Test Case for {@link ClobDataProxy} + * + * @author Roberto E. Escobar + */ +public class ClobDataProxyTest { + + @Test + @Ignore + public void testSetDisplay() { + + } + + @Test + @Ignore + public void test() throws OseeCoreException { + Assert.assertEquals(1, 1); + + DataHandler handler = new MockDataHandler(); + + ClobDataProxy proxy = new ClobDataProxy(); + proxy.setLogger(new MockLog()); + proxy.setStorage(new Storage(handler)); + + String toDisplay = "Hello"; + proxy.setDisplayableString(toDisplay); + String todisplay = proxy.getDisplayableString(); + Assert.assertEquals("Hello", todisplay); + } + + // getData() + // setData(Object...) + // + // getValueAsString() + // persist(int) + // purge() + // + // setValue(String) + +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/DataResourceTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/DataResourceTest.java new file mode 100644 index 00000000000..d0f4b7ccc63 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/DataResourceTest.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * 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.orcs.db.internal.proxy; + +import java.util.ArrayList; +import java.util.Collection; +import junit.framework.Assert; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.core.ds.ResourceNameResolver; +import org.eclipse.osee.orcs.db.mocks.MockResourceNameResolver; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test Case for {@link DataResource} + * + * @author Roberto E. Escobar + */ +@RunWith(Parameterized.class) +public class DataResourceTest { + + private final DataResource resource; + protected final String contentType; + protected final String encoding; + protected final String extension; + protected final String locator; + + public DataResourceTest(String contentType, String encoding, String extension, String locator) { + super(); + this.contentType = contentType; + this.encoding = encoding; + this.extension = extension; + this.locator = locator; + resource = createResource(); + } + + protected DataResource createResource() { + return new DataResource(contentType, encoding, extension, locator); + } + + protected DataResource getResource() { + return resource; + } + + @Test + public void testGetAndSetContentType() { + String original = resource.getContentType(); + Assert.assertEquals(contentType, original); + + resource.setContentType("testContentType"); + Assert.assertEquals("testContentType", resource.getContentType()); + + resource.setContentType(original); + } + + @Test + public void testGetAndSetEncoding() { + String original = resource.getEncoding(); + Assert.assertEquals(encoding, original); + + resource.setEncoding("testEncoding"); + Assert.assertEquals("testEncoding", resource.getEncoding()); + + resource.setEncoding(original); + } + + @Test + public void testGetAndSetExtension() { + String original = resource.getExtension(); + Assert.assertEquals(extension, original); + + resource.setExtension("testExtension"); + Assert.assertEquals("testExtension", resource.getExtension()); + + resource.setExtension(original); + } + + @Test + public void testGetAndSetLocator() { + String original = resource.getLocator(); + Assert.assertEquals(locator, original); + Assert.assertTrue(resource.isLocatorValid()); + + resource.setLocator("testLocator"); + Assert.assertEquals("testLocator", resource.getLocator()); + Assert.assertTrue(resource.isLocatorValid()); + + resource.setLocator(null); + Assert.assertFalse(resource.isLocatorValid()); + + resource.setLocator(""); + Assert.assertFalse(resource.isLocatorValid()); + + resource.setLocator(original); + } + + @Test + public void testGetAndSetResolver() { + Assert.assertNull(resource.getResolver()); + + ResourceNameResolver resolver = new MockResourceNameResolver("hello", "goodbye"); + resource.setResolver(resolver); + + ResourceNameResolver actual = resource.getResolver(); + Assert.assertEquals(resolver, actual); + } + + @Test(expected = OseeCoreException.class) + public void testGetStorageNameException() throws OseeCoreException { + resource.setResolver(null); + Assert.assertNull(resource.getResolver()); + + resource.getStorageName(); + } + + @Test + public void testGetStorageName() throws OseeCoreException { + resource.setResolver(null); + Assert.assertNull(resource.getResolver()); + + ResourceNameResolver resolver = new MockResourceNameResolver("hello", "goodbye"); + resource.setResolver(resolver); + + Assert.assertEquals("hello", resource.getStorageName()); + } + + @Parameters + public static Collection data() { + Collection data = new ArrayList(); + + data.add(new Object[] {"application/zip", "ISO-8859-1", ".zip", "http://hello.com"}); + data.add(new Object[] {"txt/plain", "UTF-8", ".txt", "attr://123/1123/1231/hello.txt"}); + return data; + } +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ProxyTestSuite.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ProxyTestSuite.java new file mode 100644 index 00000000000..2fba9b9844b --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ProxyTestSuite.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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.orcs.db.internal.proxy; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * @author Roberto E. Escobar + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + ClobDataProxyTest.class, + DataResourceTest.class, + ResourceDataProxyFactoryTest.class, + ResourceHandlerTest.class, + StorageTest.class, + UriDataProxyTest.class}) +public class ProxyTestSuite { + // Test Suite +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceDataProxyFactoryTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceDataProxyFactoryTest.java new file mode 100644 index 00000000000..fb1af1ca239 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceDataProxyFactoryTest.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.orcs.db.internal.proxy; + +import junit.framework.Assert; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Test Case for {@link ResourceDataProxyFactory} + * + * @author Roberto E. Escobar + */ +public class ResourceDataProxyFactoryTest { + + @Test + @Ignore + public void test() { + Assert.assertEquals(1, 1); + + // public DataProxy createInstance(String factoryAlias) throws OseeCoreException { + } +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceHandlerTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceHandlerTest.java new file mode 100644 index 00000000000..fa743189ba6 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceHandlerTest.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * 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.orcs.db.internal.proxy; + +import junit.framework.Assert; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.db.mocks.MockResourceLocatorManager; +import org.eclipse.osee.orcs.db.mocks.MockResourceManager; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Test Case for {@link ResourceHandler} + * + * @author Roberto E. Escobar + */ +public class ResourceHandlerTest { + + @Test + @Ignore + public void testAcquire() throws OseeCoreException { + Assert.assertEquals(1, 1); + + DataResource resource = new DataResource(); + + MockResourceManager resMgr = new MockResourceManager(); + MockResourceLocatorManager locMgr = new MockResourceLocatorManager(); + ResourceHandler handler = new ResourceHandler(resMgr, locMgr); + + byte[] data = handler.acquire(resource); + } + + @Test + @Ignore + public void testSave() { + Assert.assertEquals(1, 1); + + // save(int, DataResource, byte[]) + } + + @Test + @Ignore + public void testDelete() { + Assert.assertEquals(1, 1); + + // save(int, DataResource, byte[]) + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/StorageTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/StorageTest.java new file mode 100644 index 00000000000..0b5a1308871 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/StorageTest.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.orcs.db.internal.proxy; + +import java.io.IOException; +import java.util.Arrays; +import junit.framework.Assert; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.orcs.core.ds.ResourceNameResolver; +import org.eclipse.osee.orcs.db.mocks.MockDataHandler; +import org.eclipse.osee.orcs.db.mocks.MockResourceNameResolver; +import org.junit.Test; + +/** + * Test Case for {@link Storage} + * + * @author Roberto E. Escobar + */ +public class StorageTest extends DataResourceTest { + + private static final byte[] DATA_SET_1 = new byte[] {1, 2, 3, 4, 5, 6}; + private static final byte[] DATA_SET_2 = new byte[] {7, 8, 9, 10, 12, 13}; + + private MockDataHandler handler; + private final byte[] rawContent = DATA_SET_1; + + public StorageTest(String contentType, String encoding, String extension, String locator) { + super(contentType, encoding, extension, locator); + } + + @Override + protected DataResource createResource() { + handler = new MockDataHandler(); + Storage storage = new Storage(handler); + storage.setContent(rawContent, extension, contentType, encoding); + storage.setLocator(locator); + return storage; + } + + @Override + protected Storage getResource() { + return (Storage) super.getResource(); + } + + @Test + public void testGetSetResolver() { + Storage storage = getResource(); + + ResourceNameResolver actual = storage.getResolver(); + Assert.assertNull(actual); + + MockResourceNameResolver resolver = new MockResourceNameResolver("storageName", "internalFileName"); + storage.setResolver(resolver); + + actual = storage.getResolver(); + Assert.assertEquals(resolver, actual); + } + + @Test + public void testIsDataValid() { + Storage storage = getResource(); + Assert.assertFalse(storage.isDataValid()); + + storage.setContent(DATA_SET_1, extension, contentType, encoding); + Assert.assertTrue(storage.isDataValid()); + + storage.setContent(new byte[0], extension, contentType, encoding); + Assert.assertFalse(storage.isDataValid()); + } + + @Test + public void testLoading() throws OseeCoreException { + MockDataHandler loader = new MockDataHandler(); + loader.setContent(DATA_SET_1); + + Storage store = new Storage(loader); + + Assert.assertFalse(store.isLoadingAllowed()); + Assert.assertFalse(store.isLocatorValid()); + Assert.assertFalse(store.isInitialized()); + + Assert.assertNull(store.getContent()); + Assert.assertFalse(store.isInitialized()); + + store.setLocator(""); + Assert.assertFalse(store.isLocatorValid()); + Assert.assertFalse(store.isInitialized()); + Assert.assertFalse(store.isLoadingAllowed()); + + store.setLocator(null); + Assert.assertFalse(store.isLocatorValid()); + Assert.assertFalse(store.isInitialized()); + Assert.assertFalse(store.isLoadingAllowed()); + + // Valid Locator - loading allowed + store.setLocator("path"); + Assert.assertTrue(store.isLocatorValid()); + Assert.assertFalse(store.isInitialized()); + Assert.assertTrue(store.isLoadingAllowed()); + + Assert.assertEquals(DATA_SET_1, store.getContent()); + Assert.assertFalse(store.isLoadingAllowed()); + Assert.assertEquals(store, loader.getResource()); + Assert.assertTrue(store.isInitialized()); + + // Second Acquire not allowed + loader.setContent(DATA_SET_2); + Assert.assertEquals(DATA_SET_1, store.getContent()); + + // upon change of locator - acquire allowed again + store.setLocator("another location"); + Assert.assertTrue(store.isLoadingAllowed()); + Assert.assertFalse(store.isInitialized()); + Assert.assertEquals(DATA_SET_2, store.getContent()); + Assert.assertTrue(store.isInitialized()); + } + + @Test + public void testGetInputStream() throws OseeCoreException, IOException { + MockDataHandler loader = new MockDataHandler(); + loader.setContent(DATA_SET_1); + + Storage store = new Storage(loader); + Assert.assertNull(store.getContent()); + + store.setContent(DATA_SET_2, "ext", "ctype", "UTF-8"); + Assert.assertEquals(DATA_SET_2, store.getContent()); + Assert.assertFalse(loader.isAcquire()); + Assert.assertFalse(loader.isSave()); + Assert.assertFalse(loader.isDelete()); + + // Multiple Reads + Assert.assertTrue(Arrays.equals(DATA_SET_2, Lib.inputStreamToBytes(store.getInputStream()))); + Assert.assertTrue(Arrays.equals(DATA_SET_2, Lib.inputStreamToBytes(store.getInputStream()))); + + // Input after acquire + store.setLocator("path"); + Assert.assertTrue(Arrays.equals(DATA_SET_1, Lib.inputStreamToBytes(store.getInputStream()))); + Assert.assertTrue(loader.isAcquire()); + Assert.assertFalse(loader.isSave()); + Assert.assertFalse(loader.isDelete()); + } + + @Test + public void testSetContentAndCopyTo() throws OseeCoreException { + Storage store = new Storage(null); + Assert.assertNull(store.getContent()); + Assert.assertFalse(store.isLoadingAllowed()); + + store.setContent(DATA_SET_1, "ext", "ctype", "UTF-8"); + Assert.assertEquals(DATA_SET_1, store.getContent()); + Assert.assertEquals("ext", store.getExtension()); + Assert.assertEquals("ctype", store.getContentType()); + Assert.assertEquals("UTF-8", store.getEncoding()); + + Storage store2 = new Storage(null); + store2.setContent(DATA_SET_2, extension, contentType, encoding); + Assert.assertEquals(DATA_SET_2, store2.getContent()); + Assert.assertEquals(extension, store2.getExtension()); + Assert.assertEquals(contentType, store2.getContentType()); + Assert.assertEquals(encoding, store2.getEncoding()); + + store.copyTo(store2); + Assert.assertTrue(Arrays.equals(DATA_SET_1, store2.getContent())); + Assert.assertEquals("ext", store2.getExtension()); + Assert.assertEquals("ctype", store2.getContentType()); + Assert.assertEquals("UTF-8", store2.getEncoding()); + + getResource().copyTo(store2); + Assert.assertEquals(null, store2.getContent()); + Assert.assertEquals(extension, store2.getExtension()); + Assert.assertEquals(contentType, store2.getContentType()); + Assert.assertEquals(encoding, store2.getEncoding()); + } + + @Test + public void testClean() throws OseeCoreException { + MockDataHandler loader = new MockDataHandler(); + loader.setContent(DATA_SET_1); + + Storage store = new Storage(loader); + store.setLocator("path"); + Assert.assertEquals(DATA_SET_1, store.getContent()); + + store.setContent(DATA_SET_2, extension, contentType, encoding); + Assert.assertEquals(DATA_SET_2, store.getContent()); + Assert.assertEquals(extension, store.getExtension()); + Assert.assertEquals(contentType, store.getContentType()); + Assert.assertEquals(encoding, store.getEncoding()); + + Assert.assertEquals("path", store.getLocator()); + + store.clear(); + Assert.assertNull(store.getContent()); + Assert.assertEquals("txt", store.getExtension()); + Assert.assertEquals("txt/plain", store.getContentType()); + Assert.assertEquals("UTF-8", store.getEncoding()); + + Assert.assertNull(store.getLocator()); + } + + @Test + public void testPersist() throws OseeCoreException { + handler.reset(); + Storage storage = getResource(); + Assert.assertFalse(storage.isDataValid()); + storage.persist(45); + Assert.assertNull(handler.getResource()); + + Assert.assertFalse(handler.isAcquire()); + Assert.assertFalse(handler.isSave()); + Assert.assertFalse(handler.isDelete()); + + storage.setContent(rawContent, extension, contentType, encoding); + Assert.assertTrue(storage.isDataValid()); + storage.persist(45); + Assert.assertEquals(storage, handler.getResource()); + Assert.assertEquals(45, handler.getStorageId()); + Assert.assertEquals(rawContent, handler.getContent()); + + Assert.assertFalse(handler.isAcquire()); + Assert.assertTrue(handler.isSave()); + Assert.assertFalse(handler.isDelete()); + } + + @Test + public void testPurge() throws OseeCoreException { + handler.reset(); + Storage storage = getResource(); + Assert.assertTrue(storage.isLocatorValid()); + storage.purge(); + Assert.assertEquals(storage, handler.getResource()); + + Assert.assertFalse(handler.isAcquire()); + Assert.assertFalse(handler.isSave()); + Assert.assertTrue(handler.isDelete()); + + handler.reset(); + storage.setLocator(null); + Assert.assertFalse(storage.isLocatorValid()); + storage.purge(); + Assert.assertNull(handler.getResource()); + + Assert.assertFalse(handler.isAcquire()); + Assert.assertFalse(handler.isSave()); + Assert.assertFalse(handler.isDelete()); + + storage.setLocator(locator); + Assert.assertTrue(storage.isLocatorValid()); + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/UriDataProxyTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/UriDataProxyTest.java new file mode 100644 index 00000000000..fd7847dd29f --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/proxy/UriDataProxyTest.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.orcs.db.internal.proxy; + +import junit.framework.Assert; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Test Case for {@link UriDataProxy} + * + * @author Roberto E. Escobar + */ +public class UriDataProxyTest { + + @Test + @Ignore + public void test() { + Assert.assertEquals(1, 1); + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockDataHandler.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockDataHandler.java new file mode 100644 index 00000000000..437b96236e2 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockDataHandler.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * 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.orcs.db.mocks; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.db.internal.proxy.DataHandler; +import org.eclipse.osee.orcs.db.internal.proxy.DataResource; + +/** + * @author Roberto E. Escobar + */ +public class MockDataHandler implements DataHandler { + + private DataResource resource; + private int storageId; + private byte[] content; + private boolean acquire; + private boolean save; + private boolean delete; + + public MockDataHandler() { + super(); + reset(); + } + + @SuppressWarnings("unused") + @Override + public byte[] acquire(DataResource resource) throws OseeCoreException { + setAcquire(true); + this.resource = resource; + return content; + } + + @SuppressWarnings("unused") + @Override + public void save(int storageId, DataResource resource, byte[] rawContent) throws OseeCoreException { + setSave(true); + this.storageId = storageId; + this.resource = resource; + this.content = rawContent; + } + + @SuppressWarnings("unused") + @Override + public void delete(DataResource resource) throws OseeCoreException { + setDelete(true); + this.resource = resource; + } + + public DataResource getResource() { + return resource; + } + + public int getStorageId() { + return storageId; + } + + public byte[] getContent() { + return content; + } + + public void setContent(byte[] content) { + this.content = content; + } + + public void setResource(DataResource resource) { + this.resource = resource; + } + + public void setStorageId(int storageId) { + this.storageId = storageId; + } + + public boolean isAcquire() { + return acquire; + } + + public boolean isSave() { + return save; + } + + public boolean isDelete() { + return delete; + } + + public void setAcquire(boolean acquire) { + this.acquire = acquire; + } + + public void setSave(boolean save) { + this.save = save; + } + + public void setDelete(boolean delete) { + this.delete = delete; + } + + public void reset() { + setAcquire(false); + setSave(false); + setDelete(false); + resource = null; + content = null; + storageId = -1; + } +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceLocatorManager.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceLocatorManager.java new file mode 100644 index 00000000000..243ea5dd134 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceLocatorManager.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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.orcs.db.mocks; + +import java.util.Collection; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.resource.management.IResourceLocator; +import org.eclipse.osee.framework.resource.management.IResourceLocatorManager; +import org.eclipse.osee.framework.resource.management.IResourceLocatorProvider; + +/** + * @author Roberto E. Escobar + */ +public class MockResourceLocatorManager implements IResourceLocatorManager { + + @Override + public IResourceLocator generateResourceLocator(String protocol, String seed, String name) throws OseeCoreException { + return null; + } + + @Override + public IResourceLocator getResourceLocator(String path) throws OseeCoreException { + return null; + } + + @Override + public boolean addResourceLocatorProvider(IResourceLocatorProvider resourceLocatorProvider) { + return false; + } + + @Override + public boolean removeResourceLocatorProvider(IResourceLocatorProvider resourceLocatorProvider) { + return false; + } + + @Override + public Collection getProtocols() { + return null; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceManager.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceManager.java new file mode 100644 index 00000000000..ec365a34322 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceManager.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * 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.orcs.db.mocks; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.PropertyStore; +import org.eclipse.osee.framework.resource.management.IResource; +import org.eclipse.osee.framework.resource.management.IResourceListener; +import org.eclipse.osee.framework.resource.management.IResourceLocator; +import org.eclipse.osee.framework.resource.management.IResourceManager; +import org.eclipse.osee.framework.resource.management.IResourceProvider; + +/** + * @author Roberto E. Escobar + */ +public class MockResourceManager implements IResourceManager { + + @Override + public boolean addResourceListener(IResourceListener listener) { + return false; + } + + @Override + public boolean removeResourceListener(IResourceListener listener) { + return false; + } + + @Override + public boolean addResourceProvider(IResourceProvider resourceProvider) { + return false; + } + + @Override + public boolean removeResourceProvider(IResourceProvider resourceProvider) { + return false; + } + + @Override + public IResource acquire(IResourceLocator locator, PropertyStore options) throws OseeCoreException { + return null; + } + + @Override + public boolean exists(IResourceLocator locator) throws OseeCoreException { + return false; + } + + @Override + public IResourceLocator save(IResourceLocator locatorHint, IResource resource, PropertyStore options) throws OseeCoreException { + return null; + } + + @Override + public int delete(IResourceLocator locator) throws OseeCoreException { + return 0; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceNameResolver.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceNameResolver.java new file mode 100644 index 00000000000..cefcdbf6e2d --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockResourceNameResolver.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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.orcs.db.mocks; + +import org.eclipse.osee.orcs.core.ds.ResourceNameResolver; + +/** + * @author Roberto E. Escobar + */ +public class MockResourceNameResolver implements ResourceNameResolver { + + private String storageName; + private String internalFileName; + + public MockResourceNameResolver(String storageName, String internalFileName) { + super(); + this.storageName = storageName; + this.internalFileName = internalFileName; + } + + @Override + public String getStorageName() { + return storageName; + } + + @Override + public String getInternalFileName() { + return internalFileName; + } + + public void setStorageName(String storageName) { + this.storageName = storageName; + } + + public void setInternalFileName(String internalFileName) { + this.internalFileName = internalFileName; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db/OSGI-INF/data.proxy.factory.provider.xml b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/data.proxy.factory.provider.xml index 47d48c8b1f9..9a2bebbd9ed 100644 --- a/plugins/org.eclipse.osee.orcs.db/OSGI-INF/data.proxy.factory.provider.xml +++ b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/data.proxy.factory.provider.xml @@ -1,6 +1,6 @@ - - + + proxyClassMap = new ConcurrentHashMap(); + private final List> pending = + new CopyOnWriteArrayList>(); + + private Log logger; + private Thread thread; + private boolean isReady; + + public DataProxyFactoryProviderImpl() { + isReady = false; + } + + public void setLogger(Log logger) { + this.logger = logger; + } + + public Log getLogger() { + return logger; + } + + public void start() { + isReady = true; + thread = new Thread("Register Pending DataProxyFactories") { + @Override + public void run() { + for (ServiceReference reference : pending) { + try { + register(reference); + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error registering pending data proxy factories"); + } + } + pending.clear(); + } + }; + thread.start(); + } + + public void stop() { + if (thread != null && thread.isAlive()) { + thread.interrupt(); + } + isReady = false; + } + + public void addFactory(ServiceReference reference) throws Exception { + if (isReady) { + register(reference); + } else { + pending.add(reference); + } + } + + public void removeFactory(ServiceReference reference) throws Exception { + if (isReady) { + unregister(reference); + } else { + pending.remove(reference); + } + } + + private void unregister(ServiceReference reference) throws OseeCoreException { + String[] aliases = getAliases(reference); + for (String alias : aliases) { + proxyClassMap.remove(alias); + } + } + + private void register(ServiceReference reference) throws OseeCoreException { + Bundle bundle = reference.getBundle(); + DataProxyFactory factory = bundle.getBundleContext().getService(reference); + Conditions.checkNotNull(factory, "DataProxyFactory"); + String[] aliases = getAliases(reference); + for (String alias : aliases) { + proxyClassMap.put(alias, factory); + } + } + + private String[] getAliases(ServiceReference reference) throws OseeCoreException { + Object value = reference.getProperty(DataProxyFactory.PROXY_FACTORY_ALIAS); + String[] aliases = null; + if (value instanceof String[]) { + aliases = (String[]) value; + } + Conditions.checkNotNull(aliases, "Aliases", "Error getting [%s]", DataProxyFactory.PROXY_FACTORY_ALIAS); + return aliases; + } + + @Override + public DataProxyFactory getFactory(String factoryAlias) { + return proxyClassMap.get(factoryAlias); + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/AttributeDataProxyFactory.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/AttributeDataProxyFactory.java index 487f2c147bd..eee2edfd08d 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/AttributeDataProxyFactory.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/AttributeDataProxyFactory.java @@ -17,7 +17,6 @@ import org.eclipse.osee.framework.core.util.Conditions; import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.orcs.core.ds.DataProxy; import org.eclipse.osee.orcs.core.ds.DataProxyFactory; -import org.eclipse.osee.orcs.db.internal.DataProxyFactoryProvider; /** * @author Roberto E. Escobar @@ -34,12 +33,12 @@ public class AttributeDataProxyFactory implements AttributeLoader.DataProxyFacto } @Override - public DataProxy createProxy(int proxyId, long typeUuid, String value, String uri) throws OseeCoreException { + public DataProxy createProxy(long typeUuid, String value, String uri) throws OseeCoreException { AttributeType attributeType = attributeTypeCache.getByGuid(typeUuid); Conditions.checkNotNull(attributeType, "AttributeType", "Unable to find attributeType for [%s]", typeUuid); String dataProxyFactoryId = attributeType.getAttributeProviderId(); - DataProxyFactory factory = proxyProvider.getProxy(dataProxyFactoryId); + DataProxyFactory factory = proxyProvider.getFactory(dataProxyFactoryId); Conditions.checkNotNull(factory, "DataProxyFactory", "Unable to find data proxy factory for [%s]", dataProxyFactoryId); @@ -49,7 +48,7 @@ public class AttributeDataProxyFactory implements AttributeLoader.DataProxyFacto } DataProxy proxy = factory.createInstance(dataProxyFactoryId); - proxy.loadData(shortValue, uri); + proxy.setData(shortValue, uri); return proxy; } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/AttributeLoader.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/AttributeLoader.java index e959cee4d06..33bbad07e5b 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/AttributeLoader.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/AttributeLoader.java @@ -28,7 +28,7 @@ public class AttributeLoader { public static interface DataProxyFactory { - DataProxy createProxy(int proxyId, long typeUuid, String value, String uri) throws OseeCoreException; + DataProxy createProxy(long typeUuid, String value, String uri) throws OseeCoreException; } private final SqlProvider sqlProvider; @@ -83,8 +83,7 @@ public class AttributeLoader { String value = chStmt.getString("value"); String uri = chStmt.getString("uri"); - DataProxy proxy = - proxyFactory.createProxy(nextAttr.getArtifactId(), nextAttr.getAttrTypeUuid(), value, uri); + DataProxy proxy = proxyFactory.createProxy(nextAttr.getAttrTypeUuid(), value, uri); nextAttr.setDataProxy(proxy); if (options.isHistorical()) { diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataProxyFactoryProvider.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataProxyFactoryProvider.java new file mode 100644 index 00000000000..36b26b00dbb --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataProxyFactoryProvider.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * 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.orcs.db.internal.loader; + +import org.eclipse.osee.orcs.core.ds.DataProxyFactory; + +/** + * @author Roberto E. Escobar + */ +public interface DataProxyFactoryProvider { + + DataProxyFactory getFactory(String factoryAlias); + +} \ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/AbstractDataProxy.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/AbstractDataProxy.java new file mode 100644 index 00000000000..280b0a30a3c --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/AbstractDataProxy.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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.orcs.db.internal.proxy; + +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.core.ds.DataProxy; +import org.eclipse.osee.orcs.core.ds.ResourceNameResolver; + +/** + * @author Roberto E. Escobar + */ +public abstract class AbstractDataProxy implements DataProxy { + private Storage storage; + private Log logger; + + public AbstractDataProxy() { + super(); + } + + protected Storage getStorage() { + return storage; + } + + protected void setStorage(Storage storage) { + this.storage = storage; + } + + protected Log getLogger() { + return logger; + } + + protected void setLogger(Log logger) { + this.logger = logger; + } + + @Override + public void setResolver(ResourceNameResolver resolver) { + storage.setResolver(resolver); + } + + @Override + public ResourceNameResolver getResolver() { + return storage.getResolver(); + } + +} \ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/AbstractDataSourceProxy.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/AbstractDataSourceProxy.java deleted file mode 100644 index bff1f5e2526..00000000000 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/AbstractDataSourceProxy.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * 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.orcs.db.internal.proxy; - -import org.eclipse.osee.orcs.core.ds.DataProxy; - -/** - * @author Roberto E. Escobar - */ -public abstract class AbstractDataSourceProxy implements DataProxy { - private final Storage storage; - - public AbstractDataSourceProxy(Storage storage) { - super(); - this.storage = storage; - } - - protected Storage getStorage() { - return storage; - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ClobDataProxy.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ClobDataProxy.java index bfc3c79be27..44786f888ce 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ClobDataProxy.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ClobDataProxy.java @@ -20,13 +20,13 @@ import org.eclipse.osee.orcs.core.ds.CharacterDataProxy; /** * @author Roberto E. Escobar */ -public class ClobDataProxy extends AbstractDataSourceProxy implements CharacterDataProxy { +public class ClobDataProxy extends AbstractDataProxy implements CharacterDataProxy { public static final int MAX_VARCHAR_LENGTH = 4000; private String rawStringValue; - public ClobDataProxy(Storage storage) { - super(storage); + public ClobDataProxy() { + super(); this.rawStringValue = ""; } @@ -73,7 +73,8 @@ public class ClobDataProxy extends AbstractDataSourceProxy implements CharacterD if (value != null && value.length() > MAX_VARCHAR_LENGTH) { try { byte[] compressed = - Lib.compressStream(new ByteArrayInputStream(value.getBytes("UTF-8")), getStorage().getFileName()); + Lib.compressStream(new ByteArrayInputStream(value.getBytes("UTF-8")), + getResolver().getInternalFileName()); getStorage().setContent(compressed, "zip", "application/zip", "ISO-8859-1"); this.rawStringValue = ""; } catch (IOException ex) { @@ -91,7 +92,7 @@ public class ClobDataProxy extends AbstractDataSourceProxy implements CharacterD } @Override - public void loadData(Object... objects) throws OseeCoreException { + public void setData(Object... objects) throws OseeCoreException { if (objects != null && objects.length > 1) { storeValue((String) objects[0]); getStorage().setLocator((String) objects[1]); diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataHandler.java index 2734ac11a2f..1e38644a1b8 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataHandler.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataHandler.java @@ -21,8 +21,6 @@ public interface DataHandler { void save(int storageId, DataResource resource, byte[] rawContent) throws OseeCoreException; - //int gammaId, String artifactGuid, String extension - - void purge(DataResource resource) throws OseeCoreException; + void delete(DataResource resource) throws OseeCoreException; } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataProxyFactoryProviderImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataProxyFactoryProviderImpl.java deleted file mode 100644 index fc0721d2b80..00000000000 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataProxyFactoryProviderImpl.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * 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.orcs.db.internal.proxy; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.util.Conditions; -import org.eclipse.osee.logger.Log; -import org.eclipse.osee.orcs.core.ds.DataProxyFactory; -import org.eclipse.osee.orcs.db.internal.DataProxyFactoryProvider; -import org.osgi.framework.Bundle; -import org.osgi.framework.ServiceReference; - -/** - * @author Roberto E. Escobar - */ -public class DataProxyFactoryProviderImpl implements DataProxyFactoryProvider { - - private final Map proxyClassMap = new ConcurrentHashMap(); - private final List> pending = - new CopyOnWriteArrayList>(); - - private Log logger; - private Thread thread; - private boolean isReady; - - public DataProxyFactoryProviderImpl() { - isReady = false; - } - - public void setLogger(Log logger) { - this.logger = logger; - } - - public Log getLogger() { - return logger; - } - - public void start() { - isReady = true; - thread = new Thread("Register Pending DataProxyFactories") { - @Override - public void run() { - for (ServiceReference reference : pending) { - try { - register(reference); - } catch (OseeCoreException ex) { - getLogger().error(ex, "Error registering pending data proxy factories"); - } - } - pending.clear(); - } - }; - thread.start(); - } - - public void stop() { - if (thread != null && thread.isAlive()) { - thread.interrupt(); - } - isReady = false; - } - - public void addFactory(ServiceReference reference) throws Exception { - if (isReady) { - register(reference); - } else { - pending.add(reference); - } - } - - public void removeFactory(ServiceReference reference) throws Exception { - if (isReady) { - unregister(reference); - } else { - pending.remove(reference); - } - } - - private void unregister(ServiceReference reference) throws OseeCoreException { - String[] aliases = getAliases(reference); - for (String alias : aliases) { - proxyClassMap.remove(alias); - } - } - - private void register(ServiceReference reference) throws OseeCoreException { - Bundle bundle = reference.getBundle(); - DataProxyFactory factory = bundle.getBundleContext().getService(reference); - Conditions.checkNotNull(factory, "DataProxyFactory"); - String[] aliases = getAliases(reference); - for (String alias : aliases) { - proxyClassMap.put(alias, factory); - } - } - - private String[] getAliases(ServiceReference reference) throws OseeCoreException { - Object value = reference.getProperty(DataProxyFactory.PROXY_FACTORY_ALIAS); - String[] aliases = null; - if (value instanceof String[]) { - aliases = (String[]) value; - } - Conditions.checkNotNull(aliases, "Aliases", "Error getting [%s]", DataProxyFactory.PROXY_FACTORY_ALIAS); - return aliases; - } - - @Override - public DataProxyFactory getProxy(String factoryAlias) { - return proxyClassMap.get(factoryAlias); - } - -} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataResource.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataResource.java index 1b57f3fde4d..96d17edd2f7 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataResource.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/DataResource.java @@ -10,30 +10,39 @@ *******************************************************************************/ package org.eclipse.osee.orcs.db.internal.proxy; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.Conditions; import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.orcs.core.ds.ResourceNameResolver; /** * @author Roberto E. Escobar */ public class DataResource { + private ResourceNameResolver resolver; private String contentType; private String encoding; private String extension; private String locator; - private String name; public DataResource() { - } - public DataResource(String contentType, String encoding, String extension, String locator, String name) { + public DataResource(String contentType, String encoding, String extension, String locator) { super(); this.contentType = contentType; this.encoding = encoding; this.extension = extension; this.locator = locator; - this.name = name; + } + + public void setResolver(ResourceNameResolver resolver) { + this.resolver = resolver; + } + + public ResourceNameResolver getResolver() { + return resolver; } public String getContentType() { @@ -52,10 +61,6 @@ public class DataResource { return locator; } - public String getName() { - return name; - } - public void setContentType(String contentType) { this.contentType = contentType; } @@ -72,11 +77,13 @@ public class DataResource { this.locator = locator; } - public void setName(String name) { - this.name = name; - } - public boolean isLocatorValid() { return Strings.isValid(getLocator()); } + + public String getStorageName() throws OseeCoreException { + ResourceNameResolver resolver = getResolver(); + Conditions.checkNotNull(resolver, "resource name resolver"); + return resolver.getStorageName(); + } } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedDataProxy.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedDataProxy.java new file mode 100644 index 00000000000..8b7b4073823 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedDataProxy.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * 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.orcs.db.internal.proxy; + +import java.io.File; +import java.io.InputStream; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeExceptions; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.orcs.core.ds.CharacterDataProxy; + +/** + * @author Roberto E. Escobar + */ +public class MappedDataProxy extends AbstractDataProxy implements CharacterDataProxy { + private String localUri; + private String remoteUri; + private File backingFile; + + public MappedDataProxy() { + super(); + this.remoteUri = null; + this.localUri = null; + this.backingFile = null; + } + + @Override + public Object[] getData() { + return new Object[] {"", remoteUri}; + } + + @Override + public String getDisplayableString() { + return isFromLocalWorkspace() ? this.localUri : "Remote Content"; + } + + @Override + public void setData(Object... objects) { + if (objects != null && objects.length > 1) { + remoteUri = (String) objects[1]; + } + } + + // private String getOutfileName() throws OseeCoreException { + // StringBuilder builder = new StringBuilder(); + // //TestRunOperator operator = new TestRunOperator(getAttribute().getArtifact()); + // builder.append(getAttribute().getArtifact().getName()); + // builder.append("."); + // //builder.append(operator.getChecksum()); + // //builder.append("."); + // String extension = null; //operator.getOutfileExtension(); + // if (!Strings.isValid(extension)) { + // extension = getAttribute().getAttributeType().getFileTypeExtension(); + // } + // builder.append(extension); + // return builder.toString(); + // } + + @Override + public void persist(int storageId) throws OseeCoreException { + try { + if (isFromLocalWorkspace()) { + InputStream inputStream = null; + try { + // URI sourceUri = new URI(localUri); + // inputStream = sourceUri.toURL().openStream(); + // byte[] compressed = Lib.compressStream(inputStream, getOutfileName()); + // URL url = AttributeURL.getStorageURL(storageId, getAttribute().getArtifact().getGuid(), "zip"); + // URI uri = HttpProcessor.save(url, new ByteArrayInputStream(compressed), "applization/zip", "ISO-8859-1"); + // if (uri != null) { + // this.remoteUri = uri.toASCIIString(); + // this.localUri = null; + // } + } finally { + Lib.close(inputStream); + } + } + // } catch (OseeCoreException ex) { + // throw ex; // keep exceptions of type OseeCoreException from being unnecessarily wrapped + } catch (Exception ex) { + OseeExceptions.wrapAndThrow(ex); + } + } + + @Override + public void purge() throws OseeCoreException { + // try { + // if (isRemoteUriValid()) { + // URL url = AttributeURL.getAcquireURL(remoteUri); + // String response = HttpProcessor.delete(url); + // if (response != null && response.equals("Deleted: " + remoteUri)) { + // remoteUri = null; + // if (isBackingFileValid()) { + // backingFile.delete(true, null); + // } + // } + // } + // } catch (Exception ex) { + // OseeExceptions.wrapAndThrow(ex); + // } + } + + @Override + public void setDisplayableString(String toDisplay) { + // Do Nothing + } + + @Override + public String getValueAsString() { + if (isRemoteUriValid() && isBackingFileValid() != true) { + try { + this.backingFile = requestRemoteFile(); + this.localUri = null; + } catch (Exception ex) { + getLogger().error(ex, "Requesting remote file"); + } + } + String toReturn = this.localUri; + if (isBackingFileValid()) { + toReturn = backingFile.getAbsolutePath(); + } + return toReturn; + } + + private boolean isBackingFileValid() { + return backingFile != null && backingFile.exists() && backingFile.canRead(); + } + + @Override + public boolean setValue(String value) { + // DO NOTHING + return false; + } + + private File requestRemoteFile() throws Exception { + // IFile file = null; + // ByteArrayOutputStream downloadStream = new ByteArrayOutputStream(); + // URL url = AttributeURL.getAcquireURL(remoteUri); + // AcquireResult results = HttpProcessor.acquire(url, downloadStream); + // if (results.wasSuccessful()) { + // ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(downloadStream.toByteArray())); + // ZipEntry entry = zipInputStream.getNextEntry(); + // + // file = OseeData.getIFile(entry.getName(), zipInputStream, true); + // } + // return file; + return null; + } + + public void setLocalUri(String localUri) { + this.localUri = localUri; + } + + private boolean isRemoteUriValid() { + return Strings.isValid(remoteUri); + } + + private boolean isFromLocalWorkspace() { + // try { + //toReturn |= new TestRunOperator(getAttribute().getArtifact()).isFromLocalWorkspace(); + // } catch (Exception ex) { + // OseeLog.log(Activator.class, Level.SEVERE, ex); + // } + return !isRemoteUriValid(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedFileDataProxy.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedFileDataProxy.java deleted file mode 100644 index 0e1a9a4948e..00000000000 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedFileDataProxy.java +++ /dev/null @@ -1,175 +0,0 @@ -/******************************************************************************* - * 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.orcs.db.internal.proxy; - -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.orcs.core.ds.CharacterDataProxy; - -/** - * @author Roberto E. Escobar - */ -public class MappedFileDataProxy extends AbstractDataSourceProxy implements CharacterDataProxy { - private String localUri; - private String remoteUri; - - // private IFile backingFile; - - public MappedFileDataProxy(Storage dataStore) { - super(dataStore); - this.remoteUri = null; - this.localUri = null; - // this.backingFile = null; - } - - @Override - public Object[] getData() { - return new Object[] {"", remoteUri}; - } - - @Override - public String getDisplayableString() { - return isFromLocalWorkspace() ? this.localUri : "Remote Content"; - } - - @Override - public void loadData(Object... objects) { - if (objects != null && objects.length > 1) { - remoteUri = (String) objects[1]; - } - } - - // private String getOutfileName() throws OseeCoreException { - // StringBuilder builder = new StringBuilder(); - // //TestRunOperator operator = new TestRunOperator(getAttribute().getArtifact()); - // builder.append(getAttribute().getArtifact().getName()); - // builder.append("."); - // //builder.append(operator.getChecksum()); - // //builder.append("."); - // String extension = null; //operator.getOutfileExtension(); - // if (!Strings.isValid(extension)) { - // extension = getAttribute().getAttributeType().getFileTypeExtension(); - // } - // builder.append(extension); - // return builder.toString(); - // } - - @Override - public void persist(int storageId) throws OseeCoreException { - // try { - // if (isFromLocalWorkspace()) { - // InputStream inputStream = null; - // try { - // URI sourceUri = new URI(localUri); - // inputStream = sourceUri.toURL().openStream(); - // byte[] compressed = Lib.compressStream(inputStream, getOutfileName()); - // URL url = AttributeURL.getStorageURL(storageId, getAttribute().getArtifact().getGuid(), "zip"); - // URI uri = HttpProcessor.save(url, new ByteArrayInputStream(compressed), "applization/zip", "ISO-8859-1"); - // if (uri != null) { - // this.remoteUri = uri.toASCIIString(); - // this.localUri = null; - // } - // } finally { - // if (inputStream != null) { - // inputStream.close(); - // } - // } - // } - // } catch (OseeCoreException ex) { - // throw ex; // keep exceptions of type OseeCoreException from being unnecessarily wrapped - // } catch (Exception ex) { - // OseeExceptions.wrapAndThrow(ex); - // } - } - - @Override - public void purge() throws OseeCoreException { - // try { - // if (isRemoteUriValid()) { - // URL url = AttributeURL.getAcquireURL(remoteUri); - // String response = HttpProcessor.delete(url); - // if (response != null && response.equals("Deleted: " + remoteUri)) { - // remoteUri = null; - // if (isBackingFileValid()) { - // backingFile.delete(true, null); - // } - // } - // } - // } catch (Exception ex) { - // OseeExceptions.wrapAndThrow(ex); - // } - } - - @Override - public void setDisplayableString(String toDisplay) { - // Do Nothing - } - - @Override - public String getValueAsString() { - // if (isRemoteUriValid() && isBackingFileValid() != true) { - // try { - // this.backingFile = requestRemoteFile(); - // this.localUri = null; - // } catch (Exception ex) { - // OseeLog.log(Activator.class, Level.SEVERE, ex); - // } - // } - // String toReturn = this.localUri; - // if (isBackingFileValid()) { - // toReturn = backingFile.getLocationURI().toASCIIString(); - // } - // return toReturn; - return null; - } - - private boolean isBackingFileValid() { - // return backingFile != null && backingFile.isAccessible(); - return false; - } - - @Override - public boolean setValue(String value) { - // DO NOTHING - return false; - } - - // private IFile requestRemoteFile() throws Exception { - // IFile file = null; - // ByteArrayOutputStream downloadStream = new ByteArrayOutputStream(); - // URL url = AttributeURL.getAcquireURL(remoteUri); - // AcquireResult results = HttpProcessor.acquire(url, downloadStream); - // if (results.wasSuccessful()) { - // ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(downloadStream.toByteArray())); - // ZipEntry entry = zipInputStream.getNextEntry(); - // - // file = OseeData.getIFile(entry.getName(), zipInputStream, true); - // } - // return file; - // } - - public void setLocalUri(String localUri) { - this.localUri = localUri; - } - - private boolean isRemoteUriValid() { - return remoteUri != null && remoteUri.length() > 0; - } - - private boolean isFromLocalWorkspace() { - boolean toReturn = isRemoteUriValid() != true; - // try { - // //toReturn |= new TestRunOperator(getAttribute().getArtifact()).isFromLocalWorkspace(); - // } catch (Exception ex) { - // OseeLog.log(Activator.class, Level.SEVERE, ex); - // } - return toReturn; - } -} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceDataProxyFactory.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceDataProxyFactory.java index 9c3601ba41a..aa31b1a3f1f 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceDataProxyFactory.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceDataProxyFactory.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.osee.orcs.db.internal.proxy; -import java.lang.reflect.Constructor; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -31,8 +30,8 @@ import org.eclipse.osee.orcs.core.ds.DataProxyFactory; */ public class ResourceDataProxyFactory implements DataProxyFactory { - private final Map> proxyClassMap = - new HashMap>(); + private final Map> proxyClassMap = + new HashMap>(); private Log logger; private IResourceManager resourceManager; @@ -62,7 +61,7 @@ public class ResourceDataProxyFactory implements DataProxyFactory { this.resourceLocator = resourceLocator; } - private Class getProxyClazz(String id) { + private Class getProxyClazz(String id) { return proxyClassMap.get(id); } @@ -77,7 +76,7 @@ public class ResourceDataProxyFactory implements DataProxyFactory { proxyClassMap.put("DefaultAttributeDataProvider", ClobDataProxy.class); proxyClassMap.put("ClobAttributeDataProvider", ClobDataProxy.class); proxyClassMap.put("UriAttributeDataProvider", UriDataProxy.class); - proxyClassMap.put("MappedAttributeDataProvider", MappedFileDataProxy.class); + proxyClassMap.put("MappedAttributeDataProvider", UriDataProxy.class); List aliases = Arrays.asList(factoryAliases); Set keys = proxyClassMap.keySet(); @@ -94,25 +93,26 @@ public class ResourceDataProxyFactory implements DataProxyFactory { @Override public DataProxy createInstance(String factoryAlias) throws OseeCoreException { - - IResourceManager resourceManager = getResourceManager(); - IResourceLocatorManager locatorManager = getResourceLocator(); - - DataHandler handler = new ResourceHandler(resourceManager, locatorManager); - DataResource resource = new DataResource(); - Storage dataStore = new Storage(resource, handler); - - Class clazz = getProxyClazz(factoryAlias); + Class clazz = getProxyClazz(factoryAlias); Conditions.checkNotNull(clazz, "DataProxy", "Unable to find data proxy clazz [%s]", factoryAlias); - DataProxy dataProxy = null; + AbstractDataProxy dataProxy = null; try { - Constructor constructor = clazz.getConstructor(new Class[] {Storage.class}); - dataProxy = constructor.newInstance(new Object[] {dataStore}); + dataProxy = clazz.newInstance(); } catch (Exception ex) { getLogger().error(ex, "Error creating data proxy for [%s]", factoryAlias); OseeExceptions.wrapAndThrow(ex); } + dataProxy.setLogger(getLogger()); + dataProxy.setStorage(createStorage()); return dataProxy; } + + private Storage createStorage() { + IResourceManager resourceManager = getResourceManager(); + IResourceLocatorManager locatorManager = getResourceLocator(); + + DataHandler handler = new ResourceHandler(resourceManager, locatorManager); + return new Storage(handler); + } } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceHandler.java index d401b8454f2..0cc031788b4 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceHandler.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/ResourceHandler.java @@ -46,7 +46,8 @@ public class ResourceHandler implements DataHandler { Conditions.checkNotNull(path, "resource path"); IResourceLocator locator = resourceLocator.getResourceLocator(path); - Conditions.checkNotNull(locator, "resource locator", "Unable to locate resource: [%s]", dataResource.getName()); + Conditions.checkNotNull(locator, "resource locator", "Unable to locate resource: [%s]", + dataResource.getStorageName()); IResource resource = resourceManager.acquire(locator, DEFAULT_OPTIONS); resource.getName(); @@ -64,8 +65,8 @@ public class ResourceHandler implements DataHandler { dataResource.setEncoding("ISO-8859-1"); return Lib.inputStreamToBytes(inputStream); } catch (IOException ex) { - throw new OseeCoreException(ex, "Error acquiring resource - name[%s] locator[%s]", dataResource.getName(), - dataResource.getLocator()); + throw new OseeCoreException(ex, "Error acquiring resource - name[%s] locator[%s]", + dataResource.getStorageName(), dataResource.getLocator()); } finally { Lib.close(inputStream); } @@ -73,15 +74,19 @@ public class ResourceHandler implements DataHandler { @Override public void save(int storageId, DataResource dataResource, byte[] rawContent) throws OseeCoreException { - String name = dataResource.getName(); + StringBuilder storageName = new StringBuilder(); + storageName.append(dataResource.getStorageName()); String extension = dataResource.getExtension(); if (Strings.isValid(extension)) { - name += "." + extension; + storageName.append("."); + storageName.append(extension); } - boolean isCompressed = false; String seed = Integer.toString(storageId); - IResourceLocator locatorHint = resourceLocator.generateResourceLocator("attr", seed, name); + IResourceLocator locatorHint = resourceLocator.generateResourceLocator("attr", seed, storageName.toString()); + + String contentType = dataResource.getContentType(); + boolean isCompressed = Strings.isValid(contentType) && contentType.contains("zip"); IResource resource = new ByteStreamResource(locatorHint, rawContent, isCompressed); IResourceLocator locator = resourceManager.save(locatorHint, resource, DEFAULT_OPTIONS); @@ -91,25 +96,17 @@ public class ResourceHandler implements DataHandler { } @Override - public void purge(DataResource dataResource) throws OseeCoreException { + public void delete(DataResource dataResource) throws OseeCoreException { String path = dataResource.getLocator(); Conditions.checkNotNull(path, "resource path"); IResourceLocator locator = resourceLocator.getResourceLocator(path); - Conditions.checkNotNull(locator, "resource locator", "Unable to locate resource: [%s]", dataResource.getName()); + Conditions.checkNotNull(locator, "resource locator", "Unable to locate resource: [%s]", + dataResource.getStorageName()); int result = resourceManager.delete(locator); if (IResourceManager.OK != result) { throw new OseeDataStoreException("Error deleting resource located at [%s]", dataResource.getLocator()); } } - - // public static PropertyStore getOptions(HttpServletRequest request) { - // PropertyStore options = new PropertyStore(); - // options.put(StandardOptions.CompressOnSave.name(), request.getParameter(COMPRESS_ON_SAVE)); - // options.put(StandardOptions.CompressOnAcquire.name(), request.getParameter(COMPRESS_ON_ACQUIRE)); - // options.put(StandardOptions.DecompressOnAquire.name(), request.getParameter(DECOMPRESS_ON_ACQUIRE)); - // options.put(StandardOptions.Overwrite.name(), request.getParameter(IS_OVERWRITE_ALLOWED)); - // return options; - //} } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/Storage.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/Storage.java index 5d08b3c49b8..837835b6c90 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/Storage.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/Storage.java @@ -18,92 +18,81 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException; /** * @author Roberto E. Escobar */ -public class Storage { +public class Storage extends DataResource { - private final DataResource resource; private final DataHandler handler; - private byte[] rawContent; - private boolean needToReadFromRemote; + private boolean initialized; - public Storage(DataResource resource, DataHandler handler) { + public Storage(DataHandler handler) { super(); - this.resource = resource; this.handler = handler; clear(); - this.needToReadFromRemote = true; - } - - public String getLocator() { - return resource.getLocator(); + setInitialized(false); } + @Override public void setLocator(String locator) { - resource.setLocator(locator); - needToReadFromRemote = true; - } - - public boolean isLocatorValid() { - return resource.isLocatorValid(); + super.setLocator(locator); + setInitialized(false); } - public String getContentType() { - return resource.getContentType(); - } - - public String getEncoding() { - return resource.getEncoding(); + public boolean isDataValid() { + return this.rawContent != null && this.rawContent.length > 0; } - public String getExtension() { - return resource.getExtension(); + public InputStream getInputStream() throws OseeCoreException { + return new ByteArrayInputStream(getContent()); } - public String getFileName() { - return resource.getName(); + public boolean isInitialized() { + return initialized; } - //////// START OF DATA //////////// - public boolean isDataValid() { - return this.rawContent != null && this.rawContent.length > 0; + private void setInitialized(boolean initialized) { + this.initialized = initialized; } - public InputStream getInputStream() throws OseeCoreException { - return new ByteArrayInputStream(getContent()); + public boolean isLoadingAllowed() { + return !isInitialized() && isLocatorValid(); } public byte[] getContent() throws OseeCoreException { - if (isLocatorValid() != false && needToReadFromRemote) { - rawContent = handler.acquire(resource); - needToReadFromRemote = false; + if (isLoadingAllowed()) { + rawContent = handler.acquire(this); + setInitialized(true); } return this.rawContent; } public void persist(int storageId) throws OseeCoreException { - if (this.rawContent != null && this.rawContent.length > 0) { - handler.save(storageId, resource, rawContent); + if (isDataValid()) { + handler.save(storageId, this, rawContent); } } public void purge() throws OseeCoreException { if (isLocatorValid()) { - handler.purge(resource); + handler.delete(this); } } public void setContent(byte[] rawContent, String extension, String contentType, String encoding) { this.rawContent = rawContent; - this.resource.setContentType(contentType); - this.resource.setEncoding(encoding); + setContentType(contentType); + setEncoding(encoding); + setExtension(extension); } public void copyTo(Storage other) { - other.rawContent = Arrays.copyOf(this.rawContent, this.rawContent.length); - - other.resource.setContentType(this.resource.getContentType()); - other.resource.setEncoding(this.resource.getEncoding()); - other.resource.setExtension(this.resource.getExtension()); + if (this.rawContent != null) { + other.rawContent = Arrays.copyOf(this.rawContent, this.rawContent.length); + } else { + other.rawContent = null; + } + other.setContentType(this.getContentType()); + other.setEncoding(this.getEncoding()); + other.setExtension(this.getExtension()); } public void clear() { diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/UriDataProxy.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/UriDataProxy.java index 10888d70625..58c8102892a 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/UriDataProxy.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/UriDataProxy.java @@ -24,11 +24,11 @@ import org.eclipse.osee.orcs.core.ds.CharacterDataProxy; /** * @author Roberto E. Escobar */ -public class UriDataProxy extends AbstractDataSourceProxy implements CharacterDataProxy, BinaryDataProxy { +public class UriDataProxy extends AbstractDataProxy implements CharacterDataProxy, BinaryDataProxy { private String displayable; - public UriDataProxy(Storage storage) { - super(storage); + public UriDataProxy() { + super(); this.displayable = ""; } @@ -49,7 +49,7 @@ public class UriDataProxy extends AbstractDataSourceProxy implements CharacterDa if (!Arrays.equals(getStorage().getContent(), data != null ? data.array() : null)) { if (data != null) { byte[] compressed; - compressed = Lib.compressStream(Lib.byteBufferToInputStream(data), getStorage().getFileName()); + compressed = Lib.compressStream(Lib.byteBufferToInputStream(data), getResolver().getInternalFileName()); getStorage().setContent(compressed, "zip", "application/zip", "ISO-8859-1"); response = true; } else { @@ -115,7 +115,7 @@ public class UriDataProxy extends AbstractDataSourceProxy implements CharacterDa } @Override - public void loadData(Object... objects) { + public void setData(Object... objects) { if (objects != null && objects.length > 1) { getStorage().setLocator((String) objects[1]); } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/util/BinaryContentUtils.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/util/BinaryContentUtils.java index 1ff35d801a4..985eda313ae 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/util/BinaryContentUtils.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/util/BinaryContentUtils.java @@ -10,25 +10,36 @@ *******************************************************************************/ package org.eclipse.osee.orcs.db.internal.util; -import java.io.UnsupportedEncodingException; +import java.io.IOException; import java.net.URLConnection; -import java.net.URLEncoder; -import org.eclipse.osee.framework.core.data.Identity; -import org.eclipse.osee.framework.core.data.NamedIdentity; -import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.model.type.AttributeType; -import org.eclipse.osee.framework.core.util.Conditions; -import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.framework.jdk.core.util.Strings; -import org.eclipse.osee.orcs.data.ReadableAttribute; +import org.eclipse.osee.framework.resource.management.IResource; /** * @author Roberto E. Escobar */ -public class BinaryContentUtils { +public final class BinaryContentUtils { - private final static int MAX_NAME_SIZE = 60; + private BinaryContentUtils() { + // Utility Class + } + + public static String getContentType(IResource resource) throws OseeCoreException { + String mimeType; + try { + mimeType = URLConnection.guessContentTypeFromStream(resource.getContent()); + } catch (IOException ex) { + throw new OseeCoreException(ex, "Error determining mime type for - [%s]", resource.getName()); + } + if (mimeType == null) { + mimeType = URLConnection.guessContentTypeFromName(resource.getLocation().toASCIIString()); + if (mimeType == null) { + mimeType = "application/*"; + } + } + return mimeType; + } public static String getContentType(String extension) { String contentType = null; @@ -39,46 +50,4 @@ public class BinaryContentUtils { } return contentType; } - - public static String generateFileName(NamedIdentity identity, String fileTypeExtension) throws OseeCoreException { - StringBuilder builder = new StringBuilder(); - try { - String name = identity.getName(); - if (name.length() > MAX_NAME_SIZE) { - name = name.substring(0, MAX_NAME_SIZE); - } - builder.append(URLEncoder.encode(name, "UTF-8")); - builder.append("."); - } catch (UnsupportedEncodingException ex) { - // Do Nothing - this is not important - } - - builder.append(getStorageName(identity)); - - if (Strings.isValid(fileTypeExtension)) { - builder.append("."); - builder.append(fileTypeExtension); - } - return builder.toString(); - } - - private static String getStorageName(Identity identity) throws OseeCoreException { - String guid = identity.getGuid(); - Conditions.checkExpressionFailOnTrue(!GUID.isValid(guid), "Item has an invalid guid [%s]", guid); - return guid; - } - - private static String getExtension(ReadableAttribute attribute) throws OseeCoreException { - AttributeType attributeType = (AttributeType) attribute.getAttributeType(); - - String fileTypeExtension = null; - if (attributeType.equals(CoreAttributeTypes.NativeContent)) { - fileTypeExtension = attribute.getValue(); - } - if (!Strings.isValid(fileTypeExtension)) { - fileTypeExtension = attributeType.getFileTypeExtension(); - } - return fileTypeExtension; - } - } \ No newline at end of file -- cgit v1.2.3