diff options
author | rescobar | 2011-09-28 05:35:52 +0000 |
---|---|---|
committer | Roberto E. Escobar | 2011-09-28 05:35:52 +0000 |
commit | a6703ca765f19eb52380142db670bcf224ec2553 (patch) | |
tree | 7c4b14358d5d7d1fe481a481a0aba6598d3f0610 | |
parent | 44300a60083ba2c973abbcf58378f721c9ee212e (diff) | |
download | org.eclipse.osee-a6703ca765f19eb52380142db670bcf224ec2553.tar.gz org.eclipse.osee-a6703ca765f19eb52380142db670bcf224ec2553.tar.xz org.eclipse.osee-a6703ca765f19eb52380142db670bcf224ec2553.zip |
feature[ats_Q9NLC]: Create attributes model
31 files changed, 1747 insertions, 2 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core/.project b/plugins/org.eclipse.osee.orcs.core/.project index 97a4233e3fa..869e58a74a1 100644 --- a/plugins/org.eclipse.osee.orcs.core/.project +++ b/plugins/org.eclipse.osee.orcs.core/.project @@ -20,6 +20,11 @@ <arguments> </arguments> </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ds.core.builder</name> + <arguments> + </arguments> + </buildCommand> </buildSpec> <natures> <nature>org.eclipse.pde.PluginNature</nature> diff --git a/plugins/org.eclipse.osee.orcs.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.core/META-INF/MANIFEST.MF index 3092b736772..8b160ec6107 100644 --- a/plugins/org.eclipse.osee.orcs.core/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.orcs.core/META-INF/MANIFEST.MF @@ -5,4 +5,15 @@ Bundle-SymbolicName: org.eclipse.osee.orcs.core Bundle-Version: 0.9.9.qualifier Bundle-Vendor: Eclipse Open System Engineering Environment Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: org.osgi.framework;version="1.3.0" +Service-Component: OSGI-INF/*.xml +Import-Package: org.eclipse.osee.framework.core.data, + org.eclipse.osee.framework.core.enums, + org.eclipse.osee.framework.core.exception, + org.eclipse.osee.framework.core.model, + org.eclipse.osee.framework.core.model.type, + org.eclipse.osee.framework.core.util, + org.eclipse.osee.framework.jdk.core.util, + org.eclipse.osee.logger, + org.eclipse.osee.orcs +Export-Package: org.eclipse.osee.orcs.core, + org.eclipse.osee.orcs.core.ds diff --git a/plugins/org.eclipse.osee.orcs.core/OSGI-INF/data.proxy.factory.xml b/plugins/org.eclipse.osee.orcs.core/OSGI-INF/data.proxy.factory.xml new file mode 100644 index 00000000000..32c61c00456 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/OSGI-INF/data.proxy.factory.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" name="org.eclipse.osee.orcs.core.internal.AttributeDataProxyFactory"> + <implementation class="org.eclipse.osee.orcs.core.internal.AttributeDataProxyFactory"/> + <reference interface="org.eclipse.osee.logger.Log" name="Log" + cardinality="1..1" + policy="static" + bind="setLogger" /> + <reference bind="addFactory" cardinality="1..1" interface="org.eclipse.osee.orcs.core.ds.DataProxyFactory" name="DataProxyFactory" policy="static"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.orcs.core/build.properties b/plugins/org.eclipse.osee.orcs.core/build.properties index 34d2e4d2dad..d50d24b6ac0 100644 --- a/plugins/org.eclipse.osee.orcs.core/build.properties +++ b/plugins/org.eclipse.osee.orcs.core/build.properties @@ -1,4 +1,10 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - . + .,\ + OSGI-INF/ +additional.bundles = org.eclipse.osee.logger,\ + org.eclipse.osee.orcs,\ + org.eclipse.osee.framework.core,\ + org.eclipse.osee.framework.jdk.core,\ + org.eclipse.osee.framework.core.model diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/SystemPreferences.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/SystemPreferences.java new file mode 100644 index 00000000000..759d923a3e7 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/SystemPreferences.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2009 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; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; + +/** + * @author Roberto E. Escobar + */ +public interface SystemPreferences { + + public String getSystemUuid() throws OseeCoreException; + + public String getValue(String key) throws OseeCoreException; + + public String getCachedValue(String key) throws OseeCoreException; + + /** + * Return true if key is set and value = "true". Return false if key is either not set OR value != "true".<br> + * <br> + * Note: This call will hit the datastore every time, so shouldn't be used for often repeated calls. use + * isCacheEnabled that will cache the value + */ + public boolean isEnabled(String key) throws OseeCoreException; + + /** + * Return true if key is set and value = "true". Return false if key is either not set OR value != "true".<br> + * <br> + * Return cached value (value only loaded once per session. Restart will reset value if changed + */ + public boolean isCacheEnabled(String key) throws OseeCoreException; + + public void setEnabled(String key, boolean enabled) throws OseeCoreException; + + public void setBoolean(String key, boolean value) throws OseeCoreException; + + /** + * Return true if key is set in osee_info table and value = "true". Return false if key is either not in osee_info + * table OR value != "true".<br> + * <br> + * Note: This call will hit the database every time, so shouldn't be used for often repeated calls. use + * isCacheEnabled that will cache the value + */ + public boolean isBoolean(String key) throws OseeCoreException; + + public void putValue(String key, String value) throws OseeCoreException; +} 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 new file mode 100644 index 00000000000..460a43f698b --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeContainer.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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 java.util.Collection; +import java.util.List; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.core.internal.attribute.Attribute; + +/** + * @author Roberto E. Escobar + */ +public interface AttributeContainer<PARENT> { + + PARENT getContainer(); + + void add(IAttributeType type, Attribute<?> attribute); + + int getCount(IAttributeType type); + + Collection<IAttributeType> getAttributeTypes() throws OseeCoreException; + + <T> List<Attribute<T>> getAttributes(IAttributeType attributeType) throws OseeCoreException; + + //TODO is this needed + boolean isLoaded(); + + void setLoaded(boolean value); +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeRow.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeRow.java new file mode 100644 index 00000000000..39a3d38b8e0 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeRow.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds; + +import org.eclipse.osee.framework.core.enums.ModificationType; + +/** + * @author Roberto E. Escobar + */ +public class AttributeRow { + private int artifactId = -1; + private int branchId = -1; + private int attrId = -1; + private int gammaId = -1; + private ModificationType modType = null; + private int transactionId = -1; + private long attrTypeUuid = -1; + private String value = ""; + private int stripeId = -1; + private String uri = ""; + private boolean isHistorical = false; + + public AttributeRow() { + // do nothing + } + + public int getArtifactId() { + return artifactId; + } + + public int getBranchId() { + return branchId; + } + + public int getAttrId() { + return attrId; + } + + public int getGammaId() { + return gammaId; + } + + public ModificationType getModType() { + return modType; + } + + public int getTransactionId() { + return transactionId; + } + + public long getAttrTypeUuid() { + return attrTypeUuid; + } + + public String getValue() { + return value; + } + + public int getStripeId() { + return stripeId; + } + + public String getUri() { + return uri; + } + + public boolean isHistorical() { + return isHistorical; + } + + public void setArtifactId(int artifactId) { + this.artifactId = artifactId; + } + + public void setBranchId(int branchId) { + this.branchId = branchId; + } + + public void setAttrId(int attrId) { + this.attrId = attrId; + } + + public void setGammaId(int gammaId) { + this.gammaId = gammaId; + } + + public void setModType(ModificationType modType) { + this.modType = modType; + } + + public void setTransactionId(int transactionId) { + this.transactionId = transactionId; + } + + public void setAttrTypeUuid(long attrTypeUuid) { + this.attrTypeUuid = attrTypeUuid; + } + + public void setValue(String value) { + this.value = value; + } + + public void setStripeId(int stripeId) { + this.stripeId = stripeId; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public void setHistorical(boolean isHistorical) { + this.isHistorical = isHistorical; + } + + public boolean isSameArtifact(AttributeRow other) { + return this.branchId == other.branchId && this.artifactId == other.artifactId; + } + + public boolean isSameAttribute(AttributeRow other) { + return this.attrId == other.attrId && isSameArtifact(other); + } + + @Override + public String toString() { + return "AttributeRow [artifactId=" + artifactId + ", branchId=" + branchId + ", attrId=" + attrId + ", gammaId=" + gammaId + ", modType=" + modType + "]"; + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeRowHandler.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeRowHandler.java new file mode 100644 index 00000000000..4799e7437b3 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/AttributeRowHandler.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * 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 java.util.List; +import org.eclipse.osee.framework.core.exception.OseeCoreException; + +/** + * @author Roberto E. Escobar + */ +public interface AttributeRowHandler { + public void onRow(List<AttributeRow> row) throws OseeCoreException; +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BinaryDataProxy.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BinaryDataProxy.java new file mode 100644 index 00000000000..94f7ba1abe9 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BinaryDataProxy.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.core.ds; + +import java.nio.ByteBuffer; +import org.eclipse.osee.framework.core.exception.OseeCoreException; + +/** + * @author Roberto E. Escobar + */ +public interface BinaryDataProxy extends DataProxy { + + public ByteBuffer getValueAsBytes() throws OseeCoreException; + + public boolean setValue(ByteBuffer data) throws OseeCoreException; + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/CharacterDataProxy.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/CharacterDataProxy.java new file mode 100644 index 00000000000..3ac32977ee2 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/CharacterDataProxy.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; + +/** + * @author Roberto E. Escobar + */ +public interface CharacterDataProxy extends DataProxy { + + public String getValueAsString() throws OseeCoreException; + + public boolean setValue(String value) 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 new file mode 100644 index 00000000000..eda47f058ab --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/DataProxy.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeDataStoreException; + +/** + * @author Roberto E. Escobar + */ +public interface DataProxy { + + public String getDisplayableString() throws OseeCoreException; + + public void setDisplayableString(String toDisplay) throws OseeDataStoreException; + + public void loadData(Object... objects) throws OseeCoreException; + + public Object[] getData() throws OseeDataStoreException; + + public void persist(int storageId) throws OseeCoreException; + + public void purge() throws OseeCoreException; +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/DataProxyFactory.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/DataProxyFactory.java new file mode 100644 index 00000000000..875d384cc41 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/DataProxyFactory.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 DataProxyFactory { + + public static final String PROXY_FACTORY_ALIAS = "proxy.factory.alias"; + + DataProxy createInstance(String factoryAlias) throws OseeCoreException; +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/AttributeDataProxyFactory.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/AttributeDataProxyFactory.java new file mode 100644 index 00000000000..4a023facf46 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/AttributeDataProxyFactory.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * 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.internal; + +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.DataProxy; +import org.eclipse.osee.orcs.core.ds.DataProxyFactory; +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceReference; + +/** + * @author Roberto E. Escobar + */ +public class AttributeDataProxyFactory { + + private final Map<String, DataProxyFactory> proxyClassMap = new ConcurrentHashMap<String, DataProxyFactory>(); + private final List<ServiceReference<DataProxyFactory>> pending = + new CopyOnWriteArrayList<ServiceReference<DataProxyFactory>>(); + + private Log logger; + private Thread thread; + private boolean isReady; + + public AttributeDataProxyFactory() { + 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<DataProxyFactory> 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<DataProxyFactory> reference) throws Exception { + if (isReady) { + register(reference); + } else { + pending.add(reference); + } + } + + public void removeFactory(ServiceReference<DataProxyFactory> reference) throws Exception { + if (isReady) { + unregister(reference); + } else { + pending.remove(reference); + } + } + + private void unregister(ServiceReference<DataProxyFactory> reference) throws OseeCoreException { + String[] aliases = getAliases(reference); + for (String alias : aliases) { + proxyClassMap.remove(alias); + } + } + + private void register(ServiceReference<DataProxyFactory> 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<DataProxyFactory> 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; + } + + private DataProxyFactory getProxy(String factoryAlias) { + return proxyClassMap.get(factoryAlias); + } + + public DataProxy createDataProxy(String factoryAlias) throws OseeCoreException { + DataProxyFactory factory = getProxy(factoryAlias); + Conditions.checkNotNull(factory, "DataProxyFactory", "Unable to find data proxy factory for [%s]", factoryAlias); + return factory.createInstance(factoryAlias); + } +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SessionContext.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SessionContext.java new file mode 100644 index 00000000000..b023801719b --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SessionContext.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.internal; + +import org.eclipse.osee.orcs.core.ds.AttributeContainer; + +/** + * @author Roberto E. Escobar + */ +public interface SessionContext { + + AttributeContainer<?> getHistorical(int artId, int stripeId); + + AttributeContainer<?> getActive(int artId, int branchId); + +} 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 new file mode 100644 index 00000000000..5e94c15135c --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/Artifact.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * 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.internal.artifact; + +public class Artifact { + // Place-holder + + void setTransactionId(int transactionId) { + // + } +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactData.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactData.java new file mode 100644 index 00000000000..58f6693c1c3 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactData.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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.internal.artifact; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.HashCollection; +import org.eclipse.osee.orcs.core.ds.AttributeContainer; +import org.eclipse.osee.orcs.core.internal.attribute.Attribute; + +/** + * @author Roberto E. Escobar + */ +public class ArtifactData implements AttributeContainer<Artifact> { + + @SuppressWarnings("unused") + private final HashCollection<IAttributeType, Attribute<?>> attributes = + new HashCollection<IAttributeType, Attribute<?>>(false, LinkedList.class, 12); + + @SuppressWarnings("unused") + private boolean isLoaded; + + @Override + public Artifact getContainer() { + return null; + } + + @Override + public boolean isLoaded() { + return false; + } + + @Override + public void setLoaded(boolean value) { + this.isLoaded = value; + if (value == true) { + onLoaded(); + } + } + + @Override + public int getCount(IAttributeType type) { + return 0; + } + + @Override + public void add(IAttributeType type, Attribute<?> attribute) { + // + } + + @SuppressWarnings("unused") + @Override + public Collection<IAttributeType> getAttributeTypes() throws OseeCoreException { + return null; + } + + @SuppressWarnings("unused") + @Override + public <T> List<Attribute<T>> getAttributes(IAttributeType attributeType) throws OseeCoreException { + return null; + } + + private void onLoaded() { + // computeLastDateModified(); + // artifact.meetMinimumAttributeCounts(false); + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/Attribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/Attribute.java new file mode 100644 index 00000000000..c7ccb660f47 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/Attribute.java @@ -0,0 +1,336 @@ +/******************************************************************************* + * 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.internal.attribute; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.ref.Reference; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.enums.ModificationType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeExceptions; +import org.eclipse.osee.framework.core.exception.OseeStateException; +import org.eclipse.osee.framework.core.model.type.AttributeType; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.WritableAttribute; +import org.eclipse.osee.orcs.core.ds.AttributeContainer; +import org.eclipse.osee.orcs.core.ds.DataProxy; + +/** + * @author Ryan D. Brooks + */ +public abstract class Attribute<T> implements Comparable<Attribute<T>>, WritableAttribute<T> { + private AttributeType attributeType; + private Reference<AttributeContainer<?>> containerReference; + private DataProxy dataProxy; + private int attrId; + private int gammaId; + private boolean dirty; + private ModificationType modificationType; + private String defaultValue; + private Log logger; + + void internalInitialize(AttributeType attributeType, DataProxy dataProxy, Reference<AttributeContainer<?>> containerReference, ModificationType modificationType, boolean markDirty, boolean setDefaultValue) throws OseeCoreException { + this.attributeType = attributeType; + this.containerReference = containerReference; + this.modificationType = modificationType; + this.dataProxy = dataProxy; + if (setDefaultValue) { + setToDefaultValue(); + } + dirty = markDirty; + uponInitialize(); + } + + public void internalInitialize(AttributeType attributeType, DataProxy dataProxy, Reference<AttributeContainer<?>> containerReference, ModificationType modificationType, int attributeId, int gammaId, boolean markDirty, boolean setDefaultValue) throws OseeCoreException { + internalInitialize(attributeType, dataProxy, containerReference, modificationType, markDirty, setDefaultValue); + this.attrId = attributeId; + this.gammaId = gammaId; + } + + protected Log getLogger() { + return logger; + } + + /** + * Base implementation does nothing. Subclasses may override to do setup that depends on the attribute state data. + */ + @SuppressWarnings("unused") + protected void uponInitialize() throws OseeCoreException { + // provided for subclass implementation + } + + private void markAsNewOrChanged() { + if (isInDb()) { + markAsChanged(ModificationType.MODIFIED); + } else { + markAsChanged(ModificationType.NEW); + } + } + + public void setValue(T value) throws OseeCoreException { + // TODO Artifact Checks + // if (attributeType.getName().equals("Name") && !value.equals(getValue())) { + // // Confirm artifact is fit to rename + // for (IArtifactCheck check : ArtifactChecks.getArtifactChecks()) { + // IStatus result = check.isRenamable(Arrays.asList(getArtifact())); + // if (!result.isOK()) { + // throw new OseeCoreException(result.getMessage()); + // } + // } + // } + + if (subClassSetValue(value)) { + markAsNewOrChanged(); + } + } + + public boolean setFromString(String value) throws OseeCoreException { + // TODO Artifact Checks + // if (attributeType.equals(CoreAttributeTypes.Name) && !value.equals(getValue())) { + // // Confirm artifact is fit to rename + // for (IArtifactCheck check : ArtifactChecks.getArtifactChecks()) { + // IStatus result = check.isRenamable(Arrays.asList(getArtifact())); + // if (!result.isOK()) { + // throw new OseeCoreException(result.getMessage()); + // } + // } + // } + + boolean response = subClassSetValue(convertStringToValue(value)); + if (response) { + markAsNewOrChanged(); + } + return response; + } + + protected abstract T convertStringToValue(String value) throws OseeCoreException; + + public final void resetToDefaultValue() throws OseeCoreException { + modificationType = ModificationType.MODIFIED; + setToDefaultValue(); + } + + protected void setToDefaultValue() throws OseeCoreException { + if (defaultValue != null) { + subClassSetValue(convertStringToValue(defaultValue)); + } + } + + public boolean setValueFromInputStream(InputStream value) throws OseeCoreException { + try { + boolean response = setFromString(Lib.inputStreamToString(value)); + if (response) { + markAsNewOrChanged(); + } + return response; + } catch (IOException ex) { + OseeExceptions.wrapAndThrow(ex); + return false; // unreachable since wrapAndThrow() always throws an exception + } + } + + /** + * Subclasses must provide an implementation of this method and in general should not override the other set value + * methods + */ + protected abstract boolean subClassSetValue(T value) throws OseeCoreException; + + @Override + public abstract T getValue() throws OseeCoreException; + + @Override + public String getDisplayableString() throws OseeCoreException { + return getDataProxy().getDisplayableString(); + } + + @Override + public String toString() { + try { + return getDisplayableString(); + } catch (OseeCoreException ex) { + return Lib.exceptionToString(ex); + } + } + + public DataProxy getDataProxy() { + return dataProxy; + } + + /** + * @return <b>true</b> if this attribute is dirty + */ + public boolean isDirty() { + return dirty; + } + + protected void markAsChanged(ModificationType modificationType) { + setDirtyFlag(true); + this.modificationType = modificationType; + } + + public void setNotDirty() { + setDirtyFlag(false); + } + + private void setDirtyFlag(boolean dirty) { + this.dirty = dirty; + // try { + // Artifact artifact = getArtifact(); + // ArtifactCache.updateCachedArtifact(artifact.getArtId(), artifact.getBranch().getId()); + // } catch (OseeCoreException ex) { + // OseeLog.log(Attribute.class, Level.SEVERE, ex); + // } + } + + public AttributeContainer<?> getContainer() throws OseeStateException { + if (containerReference.get() == null) { + throw new OseeStateException("Attribute parent has been garbage collected"); + } + return containerReference.get(); + } + + /** + * @return attributeType Attribute Type Information + */ + @Override + public AttributeType getAttributeType() { + return attributeType; + } + + /** + * Currently this method provides support for quasi attribute type inheritance + * + * @return whether this attribute's type or any of its super-types are the specified type + */ + public boolean isOfType(String otherAttributeTypeName) { + return getAttributeType().getName().equals(otherAttributeTypeName); + } + + /** + * Currently this method provides support for quasi attribute type inheritance + * + * @return whether this attribute's type or any of its super-types are the specified type + */ + public boolean isOfType(IAttributeType otherAttributeType) { + return getAttributeType().equals(otherAttributeType); + } + + public void resetModType() { + this.modificationType = ModificationType.MODIFIED; + } + + /** + * Deletes the attribute + */ + public final void setArtifactDeleted() { + markAsChanged(ModificationType.ARTIFACT_DELETED); + } + + /** + * Deletes the attribute + */ + public final void delete() { + markAsChanged(ModificationType.DELETED); + } + + @Override + public ModificationType getModificationType() { + return modificationType; + } + + public boolean canDelete() { + try { + return getContainer().getCount(getAttributeType()) > getAttributeType().getMinOccurrences(); + } catch (OseeCoreException ex) { + return false; + } + } + + /** + * Purges the attribute from the database. + */ + public void purge() throws OseeCoreException { + getDataProxy().purge(); + } + + public void markAsPurged() { + modificationType = ModificationType.DELETED; + setDirtyFlag(false); + } + + /** + * @return true if in data store + */ + public boolean isInDb() { + return getGammaId() > 0; + } + + /** + * @return Returns the attrId. + */ + @Override + public int getId() { + return attrId; + } + + @Override + public int getGammaId() { + return gammaId; + } + + public void internalSetGammaId(int gammaId) { + this.gammaId = gammaId; + } + + public void internalSetAttributeId(int attrId) { + this.attrId = attrId; + } + + /** + * @return the deleted + */ + public boolean isDeleted() { + return modificationType.isDeleted(); + } + + /** + * artifact.persist(); artifact.reloadAttributesAndRelations(); Will need to be called afterwards to see replaced + * data in memory + * + * @throws OseeCoreException + */ + public void replaceWithVersion(int gammaId) throws OseeCoreException { + internalSetModificationType(ModificationType.REPLACED_WITH_VERSION); + this.gammaId = gammaId; + setDirtyFlag(true); + } + + /** + * @param modificationType the modificationType to set + * @throws OseeCoreException + */ + public void internalSetModificationType(ModificationType modificationType) throws OseeCoreException { + Conditions.checkNotNull(modificationType, "modification type"); + this.modificationType = modificationType; + } + + public void internalSetDeletedFromRemoteEvent() throws OseeCoreException { + internalSetModificationType(ModificationType.DELETED); + } + + @Override + public int compareTo(Attribute<T> other) { + return toString().compareTo(other.toString()); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeFactory.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeFactory.java new file mode 100644 index 00000000000..db4e0a18f65 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeFactory.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * 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.internal.attribute; + +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeExceptions; +import org.eclipse.osee.framework.core.model.cache.AttributeTypeCache; +import org.eclipse.osee.framework.core.model.type.AttributeType; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.core.ds.AttributeContainer; +import org.eclipse.osee.orcs.core.ds.AttributeRow; +import org.eclipse.osee.orcs.core.ds.DataProxy; +import org.eclipse.osee.orcs.core.internal.AttributeDataProxyFactory; +import org.eclipse.osee.orcs.core.internal.attribute.primitives.BooleanAttribute; +import org.eclipse.osee.orcs.core.internal.attribute.primitives.CompressedContentAttribute; +import org.eclipse.osee.orcs.core.internal.attribute.primitives.DateAttribute; +import org.eclipse.osee.orcs.core.internal.attribute.primitives.EnumeratedAttribute; +import org.eclipse.osee.orcs.core.internal.attribute.primitives.FloatingPointAttribute; +import org.eclipse.osee.orcs.core.internal.attribute.primitives.IntegerAttribute; +import org.eclipse.osee.orcs.core.internal.attribute.primitives.JavaObjectAttribute; +import org.eclipse.osee.orcs.core.internal.attribute.primitives.StringAttribute; + +/** + * @author Roberto E. Escobar + */ +public class AttributeFactory { + + private final Map<String, Class<? extends Attribute<?>>> primitiveAttributes = + new HashMap<String, Class<? extends Attribute<?>>>(); + + private final AttributeDataProxyFactory dataProxyFactory; + private final AttributeTypeCache attributeTypeCache; + + public AttributeFactory(Log logger, AttributeDataProxyFactory dataProxyFactory, AttributeTypeCache attributeTypeCache) { + this.dataProxyFactory = dataProxyFactory; + this.attributeTypeCache = attributeTypeCache; + + primitiveAttributes.put("", BooleanAttribute.class); + primitiveAttributes.put("", IntegerAttribute.class); + primitiveAttributes.put("", FloatingPointAttribute.class); + primitiveAttributes.put("", StringAttribute.class); + primitiveAttributes.put("", DateAttribute.class); + primitiveAttributes.put("", EnumeratedAttribute.class); + primitiveAttributes.put("", JavaObjectAttribute.class); + primitiveAttributes.put("", CompressedContentAttribute.class); + } + + private DataProxy createDataProxy(AttributeType attributeType) throws OseeCoreException { + return dataProxyFactory.createDataProxy(attributeType.getAttributeProviderId()); + } + + public <T> void loadAttribute(AttributeContainer<?> container, AttributeRow row) throws OseeCoreException { + AttributeType attributeType = attributeTypeCache.getByGuid(row.getAttrTypeUuid()); + String value = row.getValue(); + if (isEnumOrBoolean(attributeType)) { + value = Strings.intern(value); + } + boolean markDirty = false; + + Class<? extends Attribute<T>> attributeClass = null; + Attribute<T> attribute = createAttribute(attributeClass); + container.add(attributeType, attribute); + + DataProxy dataProxy = createDataProxy(attributeType); + Reference<AttributeContainer<?>> artifactRef = new WeakReference<AttributeContainer<?>>(container); + + attribute.internalInitialize(attributeType, dataProxy, artifactRef, row.getModType(), row.getAttrId(), + row.getGammaId(), markDirty, false); + } + + @SuppressWarnings("unused") + private boolean isEnumOrBoolean(IAttributeType attributeType) throws OseeCoreException { + boolean isBooleanAttribute = false; + // AttributeTypeManager.isBaseTypeCompatible(BooleanAttribute.class, attributeType); + boolean isEnumAttribute = false; + // AttributeTypeManager.isBaseTypeCompatible(EnumeratedAttribute.class, attributeType); + return isBooleanAttribute || isEnumAttribute; + } + + /** + * Creates an instance of <code>Attribute</code> of the given attribute type. This method should not be called by + * applications. Use addAttribute() instead + */ + private <T> Attribute<T> createAttribute(Class<? extends Attribute<T>> attributeClass) throws OseeCoreException { + Attribute<T> attribute = null; + try { + attribute = attributeClass.newInstance(); + } catch (InstantiationException ex) { + OseeExceptions.wrapAndThrow(ex); + } catch (IllegalAccessException ex) { + OseeExceptions.wrapAndThrow(ex); + } + return attribute; + } + + // public static boolean isBaseTypeCompatible(Class<? extends Attribute> baseType, IAttributeType attributeType) throws OseeCoreException { + // return baseType.isAssignableFrom(getAttributeBaseClass(attributeType)); + // } + // + // public static Class<? extends Attribute<?>> getAttributeBaseClass(IAttributeType attributeType) throws OseeCoreException { + // return AttributeExtensionManager.getAttributeClassFor(getType(attributeType).getBaseAttributeTypeId()); + // } + // + // public static Class<? extends IAttributeDataProvider> getAttributeProviderClass(AttributeType attributeType) throws OseeCoreException { + // return AttributeExtensionManager.getAttributeProviderClassFor(attributeType.getAttributeProviderId()); + // } +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeRowMapper.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeRowMapper.java new file mode 100644 index 00000000000..bdb8b920c6e --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeRowMapper.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * 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.internal.attribute; + +import java.util.List; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.core.ds.AttributeContainer; +import org.eclipse.osee.orcs.core.ds.AttributeRow; +import org.eclipse.osee.orcs.core.ds.AttributeRowHandler; +import org.eclipse.osee.orcs.core.internal.SessionContext; + +/** + * @author Roberto E. Escobar + */ +public class AttributeRowMapper implements AttributeRowHandler { + + private final AttributeFactory factory; + private final SessionContext context; + private final Log logger; + + public AttributeRowMapper(Log logger, SessionContext context, AttributeFactory factory) { + this.logger = logger; + this.context = context; + this.factory = factory; + } + + private AttributeContainer<?> getContainer(AttributeRow current) { + AttributeContainer<?> container = null; + if (current.isHistorical()) { + container = context.getHistorical(current.getArtifactId(), current.getStripeId()); + } else { + container = context.getActive(current.getArtifactId(), current.getBranchId()); + } + if (container == null) { + logger.warn("Orphaned attribute detected - [%s]", current); + } + return container; + } + + @Override + public void onRow(List<AttributeRow> rows) throws OseeCoreException { + AttributeRow firstRow = rows.iterator().next(); + AttributeContainer<?> container = getContainer(firstRow); + if (container == null) { + return; // If the artifact is null, it means the attributes are orphaned. + } + AttributeRow previous = new AttributeRow(); + synchronized (container) { + if (!container.isLoaded()) { + // int maxTransactionId = Integer.MIN_VALUE; + for (AttributeRow current : rows) { + if (previous.isSameAttribute(current)) { + handleMultipleVersions(previous, current); + } else { + factory.loadAttribute(container, current); + } + previous = current; + // maxTransactionId = Math.max(maxTransactionId, current.getTransactionId()); + } + // getContainer().setTransactionId(maxTransactionId); + container.setLoaded(true); + } + } + } + + private void handleMultipleVersions(AttributeRow previous, AttributeRow current) { + // Do not warn about skipping on historical loading, because the most recent + // transaction is used first due to sorting on the query + if (!previous.isHistorical() && !current.isHistorical()) { + logger.warn("Multiple attribute versions detected - \n\t[%s]\n\t[%s]", current, previous); + } + } +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/BinaryBackedAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/BinaryBackedAttribute.java new file mode 100644 index 00000000000..7ff24e86bc3 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/BinaryBackedAttribute.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.core.internal.attribute; + +import org.eclipse.osee.orcs.core.ds.BinaryDataProxy; + +/** + * @author Roberto E. Escobar + */ +public abstract class BinaryBackedAttribute<T> extends Attribute<T> { + @Override + public BinaryDataProxy getDataProxy() { + // this cast is always safe since the the data provider passed in the constructor to + // the super class is of type IBinaryAttributeDataProvider + return (BinaryDataProxy) super.getDataProxy(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/CharacterBackedAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/CharacterBackedAttribute.java new file mode 100644 index 00000000000..65cd50a8cf1 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/CharacterBackedAttribute.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.core.internal.attribute; + +import org.eclipse.osee.orcs.core.ds.CharacterDataProxy; + +/** + * @author Roberto E. Escobar + */ +public abstract class CharacterBackedAttribute<T> extends Attribute<T> { + @Override + public CharacterDataProxy getDataProxy() { + // this cast is always safe since the the data provider passed in the constructor to + // the super class is of type ICharacterAttributeDataProvider + return (CharacterDataProxy) super.getDataProxy(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/BinaryAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/BinaryAttribute.java new file mode 100644 index 00000000000..00e7441dd4b --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/BinaryAttribute.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.core.internal.attribute.primitives; + +import org.eclipse.osee.orcs.core.internal.attribute.BinaryBackedAttribute; + + +/** + * @author Ryan D. Brooks + */ +public abstract class BinaryAttribute<T> extends BinaryBackedAttribute<T> { + // do nothing +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/BooleanAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/BooleanAttribute.java new file mode 100644 index 00000000000..4cfc1703b9d --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/BooleanAttribute.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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.internal.attribute.primitives; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.core.internal.attribute.CharacterBackedAttribute; + +/** + * @author Ryan D. Brooks + */ +public class BooleanAttribute extends CharacterBackedAttribute<Boolean> { + public static final String[] booleanChoices = new String[] {"yes", "no"}; + + @Override + public Boolean getValue() throws OseeCoreException { + return getDataProxy().getValueAsString().equals(booleanChoices[0]); + } + + @Override + public boolean subClassSetValue(Boolean value) throws OseeCoreException { + return getDataProxy().setValue(value ? booleanChoices[0] : booleanChoices[1]); + } + + @Override + protected Boolean convertStringToValue(String value) { + return value != null && value.equalsIgnoreCase(booleanChoices[0]); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/CompressedContentAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/CompressedContentAttribute.java new file mode 100644 index 00000000000..c0d47ffa173 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/CompressedContentAttribute.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.core.internal.attribute.primitives; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import org.eclipse.osee.framework.core.enums.ModificationType; +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; + +public final class CompressedContentAttribute extends BinaryAttribute<InputStream> { + + @Override + public InputStream getValue() throws OseeCoreException { + return Lib.byteBufferToInputStream(getDataProxy().getValueAsBytes()); + } + + @Override + public boolean subClassSetValue(InputStream value) throws OseeCoreException { + return setValueFromInputStream(value); + } + + @Override + public boolean setValueFromInputStream(InputStream value) throws OseeCoreException { + boolean response = false; + try { + if (value == null) { + response = getDataProxy().setValue(null); + } else { + byte[] data = Lib.inputStreamToBytes(value); + response = getDataProxy().setValue(ByteBuffer.wrap(data)); + } + } catch (IOException ex) { + OseeExceptions.wrapAndThrow(ex); + } + if (response) { + markAsChanged(ModificationType.MODIFIED); + } + return response; + } + + @Override + protected InputStream convertStringToValue(String value) throws OseeCoreException { + try { + return Lib.stringToInputStream(value); + } catch (Exception ex) { + OseeExceptions.wrapAndThrow(ex); + return null; // unreachable since wrapAndThrow() always throws an exception + } + } + + @Override + protected void uponInitialize() throws OseeCoreException { + getDataProxy().setDisplayableString(getAttributeType().getName()); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/DateAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/DateAttribute.java new file mode 100644 index 00000000000..f52d1070a6b --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/DateAttribute.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * 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.internal.attribute.primitives; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.orcs.core.internal.attribute.CharacterBackedAttribute; + +/** + * @author Robert A. Fisher + * @author Ryan D. Brooks + */ +public class DateAttribute extends CharacterBackedAttribute<Date> { + public static final DateFormat MMDDYY = new SimpleDateFormat("MM/dd/yyyy"); + public static final DateFormat HHMM = new SimpleDateFormat("hh:mm"); + public final DateFormat MMDDYYHHMM = new SimpleDateFormat("MM/dd/yyyy hh:mm a"); + public final DateFormat MMDDYYYYHHMMSSAMPM = new SimpleDateFormat("MMM dd,yyyy hh:mm:ss a"); + public final DateFormat ALLDATETIME = new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy"); + + private final DateFormat[] legacyDateFormats = new DateFormat[] {MMDDYYYYHHMMSSAMPM, ALLDATETIME, MMDDYYHHMM}; + + /** + * Return current date or null if not set + * + * @return date or null if not set + */ + @Override + public Date getValue() throws OseeCoreException { + Date toReturn = null; + String value = getDataProxy().getValueAsString(); + if (Strings.isValid(value) != false) { + //TODO Added for backward compatibility with inconsistent date formats; + try { + toReturn = new Date(Long.parseLong(value)); + } catch (Exception ex) { + // We have a legacy date - need to figure out how to parse it + toReturn = handleLegacyDates(value); + } + } + return toReturn; + } + + @Override + protected void setToDefaultValue() throws OseeCoreException { + String defaultValue = getAttributeType().getDefaultValue(); + if (Strings.isValid(defaultValue)) { + subClassSetValue(convertStringToValue(defaultValue)); + } else { + subClassSetValue(new Date()); + } + } + + private Date handleLegacyDates(String rawValue) { + Date toReturn = null; + for (DateFormat format : legacyDateFormats) { + try { + toReturn = format.parse(rawValue); + break; + } catch (ParseException ex) { + getLogger().error(ex, "Error parsing date value [%s] using format[%s]", rawValue, format); + } + } + return toReturn; + } + + /** + * Sets date + * + * @param value value or null to clear + */ + @Override + public boolean subClassSetValue(Date value) throws OseeCoreException { + String toSet = value != null ? Long.toString(value.getTime()) : ""; + return getDataProxy().setValue(toSet); + } + + @Override + public String getDisplayableString() throws OseeCoreException { + return getAsFormattedString(MMDDYYHHMM); + } + + @Override + protected Date convertStringToValue(String value) { + if (!Strings.isValid(value)) { + return null; + } + return new Date(Long.parseLong(value)); + } + + /** + * Return date in format given by pattern or "" if not set + * + * @param pattern DateAttribute.MMDDYY, etc... + * @return formated date + */ + public String getAsFormattedString(DateFormat dateFormat) throws OseeCoreException { + Date date = getValue(); + return date != null ? dateFormat.format(date) : ""; + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/EnumeratedAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/EnumeratedAttribute.java new file mode 100644 index 00000000000..b81e706e904 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/EnumeratedAttribute.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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.internal.attribute.primitives; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Strings; + +/** + * @author Ryan D. Brooks + */ +public class EnumeratedAttribute extends StringAttribute { + // When an enumerated attribute is required for an artifact, yet doesn't exist yet, it is created upon + // init of the artifact and given the "Unspecified" value + public static String UNSPECIFIED_VALUE = "Unspecified"; + + @Override + public String getDisplayableString() throws OseeCoreException { + String toDisplay = getDataProxy().getDisplayableString(); + return Strings.isValid(toDisplay) ? toDisplay : "<Select>"; + } + + @Override + public boolean subClassSetValue(String value) throws OseeCoreException { + return super.subClassSetValue(value); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/FloatingPointAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/FloatingPointAttribute.java new file mode 100644 index 00000000000..e6cda3a63b7 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/FloatingPointAttribute.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.internal.attribute.primitives; + +import org.eclipse.osee.framework.core.exception.OseeArgumentException; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.orcs.core.internal.attribute.CharacterBackedAttribute; + +/** + * @author Ryan D. Brooks + */ +public class FloatingPointAttribute extends CharacterBackedAttribute<Double> { + + private static final Double DEFAULT_DOUBLE = Double.MIN_VALUE; + + @Override + public Double getValue() throws OseeCoreException { + return convertStringToValue(getDataProxy().getValueAsString()); + } + + @Override + public boolean subClassSetValue(Double value) throws OseeCoreException { + if (value == null) { + throw new OseeArgumentException("Attribute value was null"); + } + return getDataProxy().setValue(String.valueOf(value)); + } + + @Override + protected Double convertStringToValue(String value) { + Double toReturn = null; + if (isValidDouble(value)) { + toReturn = Double.valueOf(value); + } else { + toReturn = getDefaultValue(); + } + return toReturn; + } + + public Double getDefaultValue() { + Double toReturn = DEFAULT_DOUBLE; + String defaultValue = getAttributeType().getDefaultValue(); + if (isValidDouble(defaultValue)) { + toReturn = Double.valueOf(defaultValue); + } + return toReturn; + } + + private boolean isValidDouble(String value) { + boolean result = false; + if (Strings.isValid(value)) { + try { + Double.parseDouble(value); + result = true; + } catch (NumberFormatException ex) { + // Do Nothing; + } + } + return result; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/IntegerAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/IntegerAttribute.java new file mode 100644 index 00000000000..7fdc93c8392 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/IntegerAttribute.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.internal.attribute.primitives; + +import org.eclipse.osee.framework.core.exception.OseeArgumentException; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.orcs.core.internal.attribute.CharacterBackedAttribute; + +/** + * @author Ryan D. Brooks + */ +public class IntegerAttribute extends CharacterBackedAttribute<Integer> { + + private static final Integer DEFAULT_INTEGER = Integer.MIN_VALUE; + + @Override + public Integer getValue() throws OseeCoreException { + return convertStringToValue(getDataProxy().getValueAsString()); + } + + @Override + public boolean subClassSetValue(Integer value) throws OseeCoreException { + if (value == null) { + throw new OseeArgumentException("Attribute value was null"); + } + return getDataProxy().setValue(String.valueOf(value)); + } + + @Override + protected Integer convertStringToValue(String value) { + Integer toReturn = null; + if (isValidInteger(value)) { + toReturn = Integer.valueOf(value); + } else { + toReturn = getDefaultValue(); + } + return toReturn; + } + + public Integer getDefaultValue() { + Integer toReturn = DEFAULT_INTEGER; + String defaultValue = getAttributeType().getDefaultValue(); + if (isValidInteger(defaultValue)) { + toReturn = Integer.valueOf(defaultValue); + } + return toReturn; + } + + private boolean isValidInteger(String value) { + boolean result = false; + if (Strings.isValid(value)) { + try { + Integer.parseInt(value); + result = true; + } catch (NumberFormatException ex) { + // Do Nothing; + } + } + return result; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/JavaObjectAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/JavaObjectAttribute.java new file mode 100644 index 00000000000..869cf0904b4 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/JavaObjectAttribute.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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.internal.attribute.primitives; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.nio.ByteBuffer; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +public final class JavaObjectAttribute extends BinaryAttribute<Object> { + @Override + public Object getValue() throws OseeCoreException { + return getObjectFromBytes(getDataProxy().getValueAsBytes()); + } + + private Object getObjectFromBytes(ByteBuffer buffer) { + Object obj = null; + InputStream inputStream = null; + ObjectInputStream objectStream = null; + try { + inputStream = Lib.byteBufferToInputStream(buffer); + if (inputStream != null) { + objectStream = new ObjectInputStream(inputStream); + obj = objectStream.readObject(); + } + } catch (Exception ex) { + getLogger().error(ex, ""); + } finally { + try { + if (inputStream != null) { + inputStream.reset(); + } + } catch (IOException ex) { + getLogger().error(ex, "Error resetting inputstream for attrId:[%s] gammaId:[%s]", getId(), getGammaId()); + } finally { + Lib.close(objectStream); + } + } + return obj; + } + + @Override + public boolean subClassSetValue(Object value) { + try { + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + ObjectOutputStream objectStream = new ObjectOutputStream(byteStream); + objectStream.writeObject(value); + objectStream.flush(); + objectStream.close(); + getDataProxy().setValue(ByteBuffer.wrap(byteStream.toByteArray())); + getDataProxy().setDisplayableString(value != null ? value.getClass().getName() : "null"); + } catch (Exception ex) { + getLogger().error(ex, "Error setting value"); + } + return true; + } + + @Override + protected Object convertStringToValue(String value) { + if (value == null) { + return null; + } + return getObjectFromBytes(ByteBuffer.wrap(value.getBytes())); + } +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/StringAttribute.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/StringAttribute.java new file mode 100644 index 00000000000..f841d1f192a --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/primitives/StringAttribute.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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.internal.attribute.primitives; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.core.internal.attribute.CharacterBackedAttribute; + +/** + * @author Ryan D. Brooks + */ +public class StringAttribute extends CharacterBackedAttribute<String> { + @Override + public String getValue() throws OseeCoreException { + return getDataProxy().getValueAsString(); + } + + @Override + public boolean subClassSetValue(String value) throws OseeCoreException { + return getDataProxy().setValue(value); + } + + @Override + protected String convertStringToValue(String value) { + return value; + } +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/placeholder.txt b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/placeholder.txt deleted file mode 100644 index e69de29bb2d..00000000000 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/placeholder.txt +++ /dev/null |