Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields')
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/AbstractOseeField.java38
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/ArtifactSuperTypeField.java49
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/ArtifactTypeAttributesField.java80
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/AssociatedArtifactField.java51
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/BranchAliasesField.java34
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/CollectionField.java49
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/EnumEntryField.java116
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/IOseeField.java27
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/OseeField.java41
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/UniqueIdField.java45
10 files changed, 530 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/AbstractOseeField.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/AbstractOseeField.java
new file mode 100644
index 00000000000..c5f336b8aeb
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/AbstractOseeField.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.framework.core.internal.fields;
+
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public abstract class AbstractOseeField<T> implements IOseeField<T> {
+
+ protected boolean isDirty;
+
+ public AbstractOseeField() {
+ isDirty = false;
+ }
+
+ public abstract void set(T value) throws OseeCoreException;
+
+ public abstract T get() throws OseeCoreException;
+
+ public void clearDirty() {
+ this.isDirty = false;
+ }
+
+ public boolean isDirty() {
+ return isDirty;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/ArtifactSuperTypeField.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/ArtifactSuperTypeField.java
new file mode 100644
index 00000000000..c1e47f110a3
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/ArtifactSuperTypeField.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.framework.core.internal.fields;
+
+import java.util.Collection;
+import java.util.Collections;
+import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeInvalidInheritanceException;
+import org.eclipse.osee.framework.core.model.ArtifactType;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class ArtifactSuperTypeField extends CollectionField<ArtifactType> {
+
+ private final ArtifactType baseType;
+
+ public ArtifactSuperTypeField(ArtifactType baseType, Collection<ArtifactType> superTypes) {
+ super(superTypes);
+ this.baseType = baseType;
+ }
+
+ @Override
+ protected Collection<ArtifactType> checkInput(Collection<ArtifactType> input) throws OseeCoreException {
+ Collection<ArtifactType> toReturn = Collections.emptyList();
+ if (input == null || input.isEmpty()) {
+ if (!baseType.equals(CoreArtifactTypes.Artifact)) {
+ throw new OseeInvalidInheritanceException(String.format(
+ "All artifacts must inherit from [Artifact] - attempted make [%s] have null inheritance", baseType));
+ }
+ } else {
+ if (input.contains(baseType)) {
+ throw new OseeInvalidInheritanceException(String.format(
+ "Circular inheritance detected for artifact type [%s]", baseType));
+ }
+ toReturn = input;
+ }
+ return toReturn;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/ArtifactTypeAttributesField.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/ArtifactTypeAttributesField.java
new file mode 100644
index 00000000000..477a7372a29
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/ArtifactTypeAttributesField.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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.framework.core.internal.fields;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.AttributeType;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.util.Compare;
+import org.eclipse.osee.framework.core.util.Conditions;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class ArtifactTypeAttributesField extends AbstractOseeField<Map<Branch, Collection<AttributeType>>> {
+
+ private final Map<Branch, Collection<AttributeType>> validityMap;
+
+ public ArtifactTypeAttributesField(Map<Branch, Collection<AttributeType>> validityMap) {
+ super();
+ this.validityMap = validityMap;
+ }
+
+ @Override
+ public Map<Branch, Collection<AttributeType>> get() throws OseeCoreException {
+ return new HashMap<Branch, Collection<AttributeType>>(validityMap);
+ }
+
+ public void put(Branch branch , Collection<AttributeType> attributes){
+ Collection<AttributeType> current = validityMap.get(branch);
+ validityMap.put(branch, attributes);
+ if (Compare.isDifferent(current, attributes)) {
+ isDirty = true;
+ }
+ }
+
+ @Override
+ public void set(Map<Branch, Collection<AttributeType>> attributeTypeMap) throws OseeCoreException {
+ Conditions.checkNotNull(attributeTypeMap, "attribute type map input");
+ boolean isDifferent = Compare.isDifferent(get(), attributeTypeMap);
+ if (isDifferent) {
+ validityMap.clear();
+ for (Entry<Branch, Collection<AttributeType>> entry : attributeTypeMap.entrySet()) {
+ // Ensure we are using a hash set - don't use putAll
+ set(entry.getKey(), entry.getValue());
+ }
+ }
+ isDirty |= isDifferent;
+ }
+
+ private void set(Branch branch, Collection<AttributeType> attributeTypes) throws OseeCoreException {
+ Conditions.checkNotNull(branch, "branch");
+ Conditions.checkNotNull(attributeTypes, "attribute types list");
+
+ if (attributeTypes.isEmpty()) {
+ validityMap.remove(branch);
+ } else {
+ Collection<AttributeType> cachedItems = validityMap.get(branch);
+ if (cachedItems == null) {
+ cachedItems = new HashSet<AttributeType>(attributeTypes);
+ validityMap.put(branch, cachedItems);
+ } else {
+ cachedItems.clear();
+ cachedItems.addAll(attributeTypes);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/AssociatedArtifactField.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/AssociatedArtifactField.java
new file mode 100644
index 00000000000..38be708cc6c
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/AssociatedArtifactField.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.framework.core.internal.fields;
+
+import org.eclipse.osee.framework.core.data.IBasicArtifact;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AssociatedArtifactField extends AbstractOseeField<IBasicArtifact<?>> {
+
+ private IBasicArtifact<?> basicArtifact;
+
+ public AssociatedArtifactField(IBasicArtifact<?> basicArtifact) {
+ super();
+ this.basicArtifact = basicArtifact;
+ }
+
+ @Override
+ public IBasicArtifact<?> get() throws OseeCoreException {
+ return basicArtifact;
+ }
+
+ @Override
+ public void set(IBasicArtifact<?> artifact) throws OseeCoreException {
+ boolean wasDifferent = isDifferent(get(), artifact);
+ if (wasDifferent) {
+ this.basicArtifact = artifact;
+ }
+ isDirty |= wasDifferent;
+ }
+
+ private boolean isDifferent(IBasicArtifact<?> art1, IBasicArtifact<?> art2) {
+ boolean result = false;
+ if (art1 != null && art2 == null || art1 == null && art2 != null) {
+ result = true;
+ } else {
+ result = art1.getArtId() != art2.getArtId();
+ }
+ return result;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/BranchAliasesField.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/BranchAliasesField.java
new file mode 100644
index 00000000000..c0ab3ff36cd
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/BranchAliasesField.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.framework.core.internal.fields;
+
+import java.util.Collection;
+import java.util.HashSet;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class BranchAliasesField extends CollectionField<String> {
+
+ public BranchAliasesField(Collection<String> aliases) {
+ super(aliases);
+ }
+
+ @Override
+ protected Collection<String> checkInput(Collection<String> input) throws OseeCoreException {
+ Collection<String> items = new HashSet<String>();
+ for (String alias : input) {
+ items.add(alias.toLowerCase());
+ }
+ return items;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/CollectionField.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/CollectionField.java
new file mode 100644
index 00000000000..1ff16d467fe
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/CollectionField.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.framework.core.internal.fields;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Compare;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CollectionField<T> extends AbstractOseeField<Collection<T>> {
+
+ private final Collection<T> items;
+
+ public CollectionField(Collection<T> items) {
+ super();
+ this.items = items;
+ }
+
+ @Override
+ public Collection<T> get() throws OseeCoreException {
+ return items;
+ }
+
+ @Override
+ public void set(Collection<T> input) throws OseeCoreException {
+ Collection<T> checked = checkInput(input);
+ boolean isDifferent = Compare.isDifferent(get(), checked);
+ if (isDifferent) {
+ items.clear();
+ items.addAll(checked);
+ }
+ isDirty |= isDifferent;
+ }
+
+ protected Collection<T> checkInput(Collection<T> input) throws OseeCoreException {
+ return input;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/EnumEntryField.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/EnumEntryField.java
new file mode 100644
index 00000000000..3c32fe16c18
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/EnumEntryField.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * 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.framework.core.internal.fields;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.internal.Activator;
+import org.eclipse.osee.framework.core.model.OseeEnumEntry;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class EnumEntryField extends CollectionField<OseeEnumEntry> {
+
+ public EnumEntryField(Collection<OseeEnumEntry> enumEntries) {
+ super(enumEntries);
+ }
+
+ @Override
+ protected Collection<OseeEnumEntry> checkInput(Collection<OseeEnumEntry> input) throws OseeCoreException {
+ checkEnumEntryIntegrity(input);
+ Set<OseeEnumEntry> toReturn = new HashSet<OseeEnumEntry>();
+
+ Set<OseeEnumEntry> newEntries = new HashSet<OseeEnumEntry>();
+ Collection<OseeEnumEntry> currentEntries = get();
+ for (OseeEnumEntry entry : input) {
+ boolean wasFound = false;
+
+ String nameToCheck = entry.getName();
+ int ordinalToCheck = entry.ordinal();
+ String guidToCheck = entry.getGuid();
+
+ for (OseeEnumEntry existingEntry : currentEntries) {
+ if (existingEntry.getGuid().equals(guidToCheck)) {
+ wasFound = true;
+ existingEntry.setName(nameToCheck);
+ existingEntry.setOrdinal(ordinalToCheck);
+ } else if (existingEntry.getName().equals(nameToCheck)) {
+ wasFound = true;
+ }
+ if (wasFound) {
+ toReturn.add(existingEntry);
+ break;
+ }
+ }
+ if (!wasFound) {
+ newEntries.add(entry);
+ }
+ }
+ toReturn.addAll(newEntries);
+ return toReturn;
+ }
+
+ private void checkEnumEntryIntegrity(Collection<OseeEnumEntry> oseeEnumEntries) throws OseeCoreException {
+ for (OseeEnumEntry entry : oseeEnumEntries) {
+ Conditions.checkNotNullOrEmpty(entry.getName(), "Osee Enum Entry name");
+
+ Conditions.checkExpressionFailOnTrue(entry.ordinal() < 0, "Osee Enum Entry ordinal must be greater than zero");
+
+ for (OseeEnumEntry existingEntry : oseeEnumEntries) {
+ if (!entry.equals(existingEntry)) {
+ Conditions.checkExpressionFailOnTrue(entry.getName().equals(existingEntry.getName()),
+ "Unique enumEntry name violation - %s already exists.", entry);
+
+ Conditions.checkExpressionFailOnTrue(
+ entry.ordinal() == existingEntry.ordinal(),
+ "Unique enumEntry ordinal violation - ordinal [%d] is used by existing entry:[%s] and new entry:[%s]",
+ entry.ordinal(), existingEntry, entry);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void clearDirty() {
+ super.clearDirty();
+ try {
+ for (OseeEnumEntry entry : get()) {
+ entry.clearDirty();
+ }
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ }
+
+ @Override
+ public boolean isDirty() {
+ boolean result = super.isDirty();
+ if (!result) {
+ try {
+ for (OseeEnumEntry entry : get()) {
+ if (entry.isDirty()) {
+ result = true;
+ break;
+ }
+ }
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ }
+ return result;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/IOseeField.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/IOseeField.java
new file mode 100644
index 00000000000..36fab143de7
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/IOseeField.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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.framework.core.internal.fields;
+
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface IOseeField<T> {
+
+ void set(T value) throws OseeCoreException;
+
+ T get() throws OseeCoreException;
+
+ void clearDirty();
+
+ boolean isDirty();
+}
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/OseeField.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/OseeField.java
new file mode 100644
index 00000000000..e2bba64e9b0
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/OseeField.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.framework.core.internal.fields;
+
+import org.eclipse.osee.framework.core.util.Compare;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class OseeField<T> extends AbstractOseeField<T> {
+
+ private T object;
+
+ public OseeField(T initValue) {
+ super();
+ set(initValue);
+ }
+
+ public OseeField() {
+ super();
+ }
+
+ @Override
+ public void set(T value) {
+ isDirty |= Compare.isDifferent(get(), value);
+ this.object = value;
+ }
+
+ @Override
+ public T get() {
+ return object;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/UniqueIdField.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/UniqueIdField.java
new file mode 100644
index 00000000000..9f6d8d35f24
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/internal/fields/UniqueIdField.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.framework.core.internal.fields;
+
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeStateException;
+import org.eclipse.osee.framework.core.model.IOseeStorable;
+import org.eclipse.osee.framework.core.util.Compare;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class UniqueIdField extends AbstractOseeField<Integer> {
+
+ private Integer value;
+
+ public UniqueIdField() {
+ super();
+ this.value = IOseeStorable.UNPERSISTED_VALUE;
+ isDirty = true;
+ }
+
+ @Override
+ public void set(Integer value) throws OseeCoreException {
+ if (IOseeStorable.UNPERSISTED_VALUE.equals(get())) {
+ isDirty |= Compare.isDifferent(get(), value);
+ this.value = value;
+ } else {
+ throw new OseeStateException("can not change the type id once it has been set");
+ }
+ }
+
+ @Override
+ public Integer get() {
+ return value;
+ }
+}

Back to the top