diff options
author | Angel Avila | 2015-03-19 21:38:21 +0000 |
---|---|---|
committer | Angel Avila | 2015-03-19 21:38:21 +0000 |
commit | bfe1648e0da57ed3e7576fb20933f7103c7c6624 (patch) | |
tree | da40c935729f87b5ddba6f731db4709046d10446 | |
parent | 7bafb944e66673012c7be7cf053b17462235745a (diff) | |
download | org.eclipse.osee-bfe1648e0da57ed3e7576fb20933f7103c7c6624.tar.gz org.eclipse.osee-bfe1648e0da57ed3e7576fb20933f7103c7c6624.tar.xz org.eclipse.osee-bfe1648e0da57ed3e7576fb20933f7103c7c6624.zip |
feature[ats_ATS172843]: Integrate ORCS Types JAX-RS API
Change-Id: Ibdd8cc8a6ef8a7219d6690f24b08d21ad2e0d279
Signed-off-by: Angel Avila <angel.avila2@boeing.com>
45 files changed, 840 insertions, 869 deletions
diff --git a/plugins/org.eclipse.osee.framework.access/src/org/eclipse/osee/framework/access/internal/AccessControlService.java b/plugins/org.eclipse.osee.framework.access/src/org/eclipse/osee/framework/access/internal/AccessControlService.java index f1335569e43..ebe4f0d1382 100644 --- a/plugins/org.eclipse.osee.framework.access/src/org/eclipse/osee/framework/access/internal/AccessControlService.java +++ b/plugins/org.eclipse.osee.framework.access/src/org/eclipse/osee/framework/access/internal/AccessControlService.java @@ -225,7 +225,7 @@ public class AccessControlService implements IAccessControlService { objectToSubjectCache.put(branchAccessObject, subjectId); ArtifactType subjectArtifactType = getArtifactTypeCache().getById(subjectArtifactTypeId); - if (subjectArtifactType.inheritsFrom(CoreArtifactTypes.UserGroup)) { + if (subjectArtifactType != null && subjectArtifactType.inheritsFrom(CoreArtifactTypes.UserGroup)) { populateGroupMembers(subjectId); } } @@ -244,7 +244,7 @@ public class AccessControlService implements IAccessControlService { Integer subjectId = chStmt.getInt("privilege_entity_id"); Integer objectId = chStmt.getInt("art_id"); Long branchUuid = chStmt.getLong("branch_id"); - long subjectArtifactTypeId = chStmt.getLong("art_type_id"); + Long subjectArtifactTypeId = chStmt.getLong("art_type_id"); PermissionEnum permission = PermissionEnum.getPermission(chStmt.getInt("permission_id")); if (permission.equals(PermissionEnum.LOCK)) { @@ -255,7 +255,7 @@ public class AccessControlService implements IAccessControlService { cacheAccessObject(objectId, subjectId, permission, accessObject); ArtifactType subjectArtifactType = getArtifactTypeCache().getById(subjectArtifactTypeId); - if (subjectArtifactType.inheritsFrom(CoreArtifactTypes.UserGroup)) { + if (subjectArtifactType != null && subjectArtifactType.inheritsFrom(CoreArtifactTypes.UserGroup)) { populateGroupMembers(subjectId); } } diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCacheTest.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCacheTest.java index d5d9887aed8..c0c9ad0c300 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCacheTest.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCacheTest.java @@ -192,15 +192,19 @@ public abstract class AbstractOseeCacheTest<K, T extends AbstractOseeType<K>> { @Test public void testReload() throws OseeCoreException { - int fullCacheSize = cache.size(); - Assert.assertTrue(fullCacheSize > 0); - for (T type : cache.getAll()) { - cache.decache(type); - } + if (cache instanceof IOseeLoadingCache) { + int fullCacheSize = cache.size(); + Assert.assertTrue(fullCacheSize > 0); + for (T type : cache.getAll()) { + cache.decache(type); + } - Assert.assertEquals(0, cache.size()); - Assert.assertTrue(cache.reloadCache()); - Assert.assertEquals(fullCacheSize, cache.size()); + Assert.assertEquals(0, cache.size()); + if (cache instanceof IOseeLoadingCache) { + Assert.assertTrue(((IOseeLoadingCache<?, ?>) cache).reloadCache()); + } + Assert.assertEquals(fullCacheSize, cache.size()); + } } @Test(expected = OseeTypeDoesNotExist.class) diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/ArtifactTypeCacheTest.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/ArtifactTypeCacheTest.java index d88e9c62df9..2322aed5d06 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/ArtifactTypeCacheTest.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/ArtifactTypeCacheTest.java @@ -13,10 +13,8 @@ package org.eclipse.osee.framework.core.model.cache; import java.util.ArrayList; import java.util.List; import org.eclipse.osee.framework.core.model.mocks.MockDataFactory; -import org.eclipse.osee.framework.core.model.mocks.MockOseeDataAccessor; import org.eclipse.osee.framework.core.model.type.ArtifactType; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.junit.Assert; import org.junit.BeforeClass; /** @@ -32,37 +30,19 @@ public class ArtifactTypeCacheTest extends AbstractOseeTypeCacheTest<ArtifactTyp @BeforeClass public static void prepareTestData() throws OseeCoreException { artifactTypes = new ArrayList<ArtifactType>(); - - ArtifactDataAccessor artData = new ArtifactDataAccessor(artifactTypes); - artCache = new ArtifactTypeCache(artData); - - artCache.ensurePopulated(); - Assert.assertTrue(artData.wasLoaded()); + artCache = new ArtifactTypeCache(); + + int typeId = 100; + for (int index = 0; index < 10; index++) { + ArtifactType item = MockDataFactory.createArtifactType(index); + artifactTypes.add(item); + item.setId(typeId++); + artCache.cache(item); + } } public ArtifactTypeCacheTest() { super(artifactTypes, artCache); } - private final static class ArtifactDataAccessor extends MockOseeDataAccessor<Long, ArtifactType> { - private final List<ArtifactType> artifactTypes; - - public ArtifactDataAccessor(List<ArtifactType> artifactTypes) { - super(); - this.artifactTypes = artifactTypes; - } - - @Override - public void load(IOseeCache<Long, ArtifactType> cache) throws OseeCoreException { - super.load(cache); - - int typeId = 100; - for (int index = 0; index < 10; index++) { - ArtifactType item = MockDataFactory.createArtifactType(index); - artifactTypes.add(item); - item.setId(typeId++); - cache.cache(item); - } - } - } } diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/AttributeTypeCacheTest.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/AttributeTypeCacheTest.java index f8e5263a451..9ec3234990c 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/AttributeTypeCacheTest.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/AttributeTypeCacheTest.java @@ -13,10 +13,8 @@ package org.eclipse.osee.framework.core.model.cache; import java.util.ArrayList; import java.util.List; import org.eclipse.osee.framework.core.model.mocks.MockDataFactory; -import org.eclipse.osee.framework.core.model.mocks.MockOseeDataAccessor; import org.eclipse.osee.framework.core.model.type.AttributeType; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.junit.Assert; import org.junit.BeforeClass; /** @@ -33,36 +31,19 @@ public class AttributeTypeCacheTest extends AbstractOseeTypeCacheTest<AttributeT public static void prepareTestData() throws OseeCoreException { attributeTypes = new ArrayList<AttributeType>(); - AttributeDataAccessor attrData = new AttributeDataAccessor(attributeTypes); - attrCache = new AttributeTypeCache(attrData); + attrCache = new AttributeTypeCache(); - attrCache.ensurePopulated(); - Assert.assertTrue(attrData.wasLoaded()); + int typeId = 100; + for (int index = 0; index < 10; index++) { + AttributeType item = MockDataFactory.createAttributeType(index, null); + attributeTypes.add(item); + item.setId(typeId++); + attrCache.cache(item); + } } public AttributeTypeCacheTest() { super(attributeTypes, attrCache); } - private final static class AttributeDataAccessor extends MockOseeDataAccessor<Long, AttributeType> { - - private final List<AttributeType> attributeTypes; - - public AttributeDataAccessor(List<AttributeType> attributeTypes) { - super(); - this.attributeTypes = attributeTypes; - } - - @Override - public void load(IOseeCache<Long, AttributeType> cache) throws OseeCoreException { - super.load(cache); - int typeId = 100; - for (int index = 0; index < 10; index++) { - AttributeType item = MockDataFactory.createAttributeType(index, null); - attributeTypes.add(item); - item.setId(typeId++); - cache.cache(item); - } - } - } } diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/OseeEnumTypeCacheTest.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/OseeEnumTypeCacheTest.java index 9d6c9fb5a86..3b20df1520f 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/OseeEnumTypeCacheTest.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/OseeEnumTypeCacheTest.java @@ -14,11 +14,9 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.osee.framework.core.model.OseeEnumEntry; import org.eclipse.osee.framework.core.model.mocks.MockDataFactory; -import org.eclipse.osee.framework.core.model.mocks.MockOseeDataAccessor; import org.eclipse.osee.framework.core.model.mocks.ModelAsserts; import org.eclipse.osee.framework.core.model.type.OseeEnumType; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.junit.Assert; import org.junit.BeforeClass; /** @@ -35,11 +33,22 @@ public class OseeEnumTypeCacheTest extends AbstractOseeTypeCacheTest<OseeEnumTyp public static void prepareTestData() throws OseeCoreException { data = new ArrayList<OseeEnumType>(); - EnumDataAccessor enumAccessor = new EnumDataAccessor(data); - cache = new OseeEnumTypeCache(enumAccessor); + cache = new OseeEnumTypeCache(); - cache.ensurePopulated(); - Assert.assertTrue(enumAccessor.wasLoaded()); + int typeId = 100; + for (int index = 0; index < 10; index++) { + OseeEnumType item = MockDataFactory.createEnumType(index); + List<OseeEnumEntry> entries = new ArrayList<OseeEnumEntry>(); + for (int j = 1; j <= 5; j++) { + OseeEnumEntry enumEntry = MockDataFactory.createEnumEntry(index + j); + entries.add(enumEntry); + } + item.setEntries(entries); + + data.add(item); + item.setId(typeId++); + cache.cache(item); + } } public OseeEnumTypeCacheTest() { @@ -51,31 +60,4 @@ public class OseeEnumTypeCacheTest extends AbstractOseeTypeCacheTest<OseeEnumTyp ModelAsserts.checkEnumType(expected, actual); } - private final static class EnumDataAccessor extends MockOseeDataAccessor<Long, OseeEnumType> { - private final List<OseeEnumType> oseeEnumTypes; - - public EnumDataAccessor(List<OseeEnumType> oseeEnumTypes) { - super(); - this.oseeEnumTypes = oseeEnumTypes; - } - - @Override - public void load(IOseeCache<Long, OseeEnumType> cache) throws OseeCoreException { - super.load(cache); - int typeId = 100; - for (int index = 0; index < 10; index++) { - OseeEnumType item = MockDataFactory.createEnumType(index); - List<OseeEnumEntry> entries = new ArrayList<OseeEnumEntry>(); - for (int j = 1; j <= 5; j++) { - OseeEnumEntry enumEntry = MockDataFactory.createEnumEntry(index + j); - entries.add(enumEntry); - } - item.setEntries(entries); - - oseeEnumTypes.add(item); - item.setId(typeId++); - cache.cache(item); - } - } - } } diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/RelationTypeCacheTest.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/RelationTypeCacheTest.java index 7fa3a34520a..a4de99558a4 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/RelationTypeCacheTest.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/cache/RelationTypeCacheTest.java @@ -13,10 +13,8 @@ package org.eclipse.osee.framework.core.model.cache; import java.util.ArrayList; import java.util.List; import org.eclipse.osee.framework.core.model.mocks.MockDataFactory; -import org.eclipse.osee.framework.core.model.mocks.MockOseeDataAccessor; import org.eclipse.osee.framework.core.model.type.RelationType; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.junit.Assert; import org.junit.BeforeClass; /** @@ -33,36 +31,18 @@ public class RelationTypeCacheTest extends AbstractOseeTypeCacheTest<RelationTyp public static void prepareTestData() throws OseeCoreException { data = new ArrayList<RelationType>(); - RelationDataAccessor relationAccessor = new RelationDataAccessor(data); - cache = new RelationTypeCache(relationAccessor); - - cache.ensurePopulated(); - Assert.assertTrue(relationAccessor.wasLoaded()); + cache = new RelationTypeCache(); + int typeId = 100; + for (int index = 0; index < 10; index++) { + RelationType item = MockDataFactory.createRelationType(index, null, null); + data.add(item); + item.setId(typeId++); + cache.cache(item); + } } public RelationTypeCacheTest() { super(data, cache); } - private final static class RelationDataAccessor extends MockOseeDataAccessor<Long, RelationType> { - private final List<RelationType> relationTypes; - - public RelationDataAccessor(List<RelationType> relationTypes) { - super(); - this.relationTypes = relationTypes; - } - - @Override - public void load(IOseeCache<Long, RelationType> cache) throws OseeCoreException { - super.load(cache); - int typeId = 100; - for (int index = 0; index < 10; index++) { - RelationType item = MockDataFactory.createRelationType(index, null, null); - relationTypes.add(item); - item.setId(typeId++); - cache.cache(item); - } - } - } - } diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/OseeCachingService.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/OseeCachingService.java deleted file mode 100644 index 147d64d76dd..00000000000 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/OseeCachingService.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.model; - -import java.util.Collection; -import java.util.HashSet; -import org.eclipse.osee.framework.core.enums.OseeCacheEnum; -import org.eclipse.osee.framework.core.model.cache.ArtifactTypeCache; -import org.eclipse.osee.framework.core.model.cache.AttributeTypeCache; -import org.eclipse.osee.framework.core.model.cache.BranchCache; -import org.eclipse.osee.framework.core.model.cache.IOseeCache; -import org.eclipse.osee.framework.core.model.cache.OseeEnumTypeCache; -import org.eclipse.osee.framework.core.model.cache.RelationTypeCache; -import org.eclipse.osee.framework.core.model.cache.TransactionCache; -import org.eclipse.osee.framework.core.services.IOseeCachingService; -import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.util.Conditions; - -/** - * @author Roberto E. Escobar - */ -public class OseeCachingService implements IOseeCachingService { - - private final BranchCache branchCache; - private final TransactionCache transactionCache; - - private final ArtifactTypeCache artifactTypeCache; - private final AttributeTypeCache attributeTypeCache; - private final RelationTypeCache relationTypeCache; - private final OseeEnumTypeCache oseeEnumTypeCache; - private final Collection<IOseeCache<?, ?>> caches; - - public OseeCachingService(BranchCache branchCache, TransactionCache transactionCache, ArtifactTypeCache artifactTypeCache, AttributeTypeCache attributeTypeCache, RelationTypeCache relationTypeCache, OseeEnumTypeCache oseeEnumTypeCache) { - this.branchCache = branchCache; - this.transactionCache = transactionCache; - this.artifactTypeCache = artifactTypeCache; - this.attributeTypeCache = attributeTypeCache; - this.relationTypeCache = relationTypeCache; - this.oseeEnumTypeCache = oseeEnumTypeCache; - caches = new HashSet<IOseeCache<?, ?>>(); - caches.add(branchCache); - caches.add(transactionCache); - caches.add(artifactTypeCache); - caches.add(attributeTypeCache); - caches.add(relationTypeCache); - caches.add(oseeEnumTypeCache); - } - - @Override - public BranchCache getBranchCache() { - return branchCache; - } - - @Override - public TransactionCache getTransactionCache() { - return transactionCache; - } - - @Override - public ArtifactTypeCache getArtifactTypeCache() { - return artifactTypeCache; - } - - @Override - public AttributeTypeCache getAttributeTypeCache() { - return attributeTypeCache; - } - - @Override - public OseeEnumTypeCache getEnumTypeCache() { - return oseeEnumTypeCache; - } - - @Override - public RelationTypeCache getRelationTypeCache() { - return relationTypeCache; - } - - @Override - public Collection<IOseeCache<?, ?>> getCaches() { - return caches; - } - - @Override - public IOseeCache<?, ?> getCache(OseeCacheEnum cacheId) throws OseeCoreException { - Conditions.checkNotNull(cacheId, "cache id to find"); - for (IOseeCache<?, ?> cache : getCaches()) { - if (cache.getCacheId().equals(cacheId)) { - return cache; - } - } - throw new OseeArgumentException("Unable to find cache for id [%s]", cacheId); - } - - @Override - public synchronized void reloadAll() throws OseeCoreException { - getBranchCache().reloadCache(); - getTransactionCache().reloadCache(); - getArtifactTypeCache().reloadCache(); - - //reloading the artifactTypeCache will reload these: - // getEnumTypeCache().reloadCache(); - // getAttributeTypeCache().reloadCache(); - // getRelationTypeCache().reloadCache(); - } - - @Override - public synchronized void clearAll() { - getBranchCache().decacheAll(); - getTransactionCache().decacheAll(); - getEnumTypeCache().decacheAll(); - getAttributeTypeCache().decacheAll(); - getArtifactTypeCache().decacheAll(); - getRelationTypeCache().decacheAll(); - } - -} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCache.java index 97cdab4feb8..f7bf3f8f1da 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCache.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCache.java @@ -17,8 +17,6 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Level; import org.eclipse.osee.framework.core.enums.OseeCacheEnum; import org.eclipse.osee.framework.core.enums.StorageState; import org.eclipse.osee.framework.core.exception.OseeTypeDoesNotExist; @@ -31,7 +29,6 @@ import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.type.OseeStateException; import org.eclipse.osee.framework.jdk.core.util.Conditions; import org.eclipse.osee.framework.jdk.core.util.GUID; -import org.eclipse.osee.framework.logging.OseeLog; /** * @author Roberto E. Escobar @@ -42,31 +39,20 @@ public abstract class AbstractOseeCache<K, T extends AbstractOseeType<K>> implem private final ConcurrentHashMap<Long, T> idToTypeMap = new ConcurrentHashMap<Long, T>(); private final ConcurrentHashMap<K, T> guidToTypeMap = new ConcurrentHashMap<K, T>(); - private final IOseeDataAccessor<K, T> dataAccessor; private final OseeCacheEnum cacheId; private final boolean uniqueName; - private final AtomicBoolean wasLoaded; - private long lastLoaded; - protected AbstractOseeCache(OseeCacheEnum cacheId, IOseeDataAccessor<K, T> dataAccessor, boolean uniqueName) { - this.lastLoaded = 0; + protected AbstractOseeCache(OseeCacheEnum cacheId, boolean uniqueName) { this.cacheId = cacheId; - this.wasLoaded = new AtomicBoolean(false); - this.dataAccessor = dataAccessor; this.uniqueName = uniqueName; } - public void invalidate() { - wasLoaded.set(false); - } - @Override public synchronized void decacheAll() { clearAdditionalData(); nameToTypeMap.clear(); idToTypeMap.clear(); guidToTypeMap.clear(); - wasLoaded.set(false); } protected void clearAdditionalData() { @@ -253,18 +239,6 @@ public abstract class AbstractOseeCache<K, T extends AbstractOseeType<K>> implem storeItems(getAllDirty()); } - @Override - public synchronized void ensurePopulated() throws OseeCoreException { - if (wasLoaded.compareAndSet(false, true)) { - try { - reloadCache(); - } catch (OseeCoreException ex) { - wasLoaded.set(false); - throw ex; - } - } - } - public void storeByGuid(Collection<K> guids) throws OseeCoreException { ensurePopulated(); Conditions.checkNotNull(guids, "guids to store"); @@ -280,32 +254,6 @@ public abstract class AbstractOseeCache<K, T extends AbstractOseeType<K>> implem } @Override - public long getLastLoaded() { - return lastLoaded; - } - - private void setLastLoaded(long lastLoaded) { - this.lastLoaded = lastLoaded; - } - - @Override - public synchronized boolean reloadCache() throws OseeCoreException { - dataAccessor.load(this); - OseeLog.log(this.getClass(), Level.INFO, "Loaded " + getCacheId().toString().toLowerCase()); - setLastLoaded(System.currentTimeMillis()); - wasLoaded.set(true); - return true; - } - - public void resetWasLoaded() { - wasLoaded.set(false); - } - - public boolean isLoaded() { - return wasLoaded.get(); - } - - @Override public void storeItems(T... items) throws OseeCoreException { storeItems(Arrays.asList(items)); } @@ -314,7 +262,7 @@ public abstract class AbstractOseeCache<K, T extends AbstractOseeType<K>> implem public void storeItems(Collection<T> toStore) throws OseeCoreException { Conditions.checkDoesNotContainNulls(toStore, "items to store"); if (!toStore.isEmpty()) { - dataAccessor.store(toStore); + store(toStore); synchronized (this) { for (T type : toStore) { decache(type); @@ -331,4 +279,12 @@ public abstract class AbstractOseeCache<K, T extends AbstractOseeType<K>> implem cache(type); } } + + protected void ensurePopulated() throws OseeCoreException { + // Do nothing + } + + protected void store(Collection<T> toStore) throws OseeCoreException { + // Do nothing + } } diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeLoadingCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeLoadingCache.java new file mode 100644 index 00000000000..d79353ae410 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeLoadingCache.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2015 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.model.cache; + +import java.util.Collection; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Level; +import org.eclipse.osee.framework.core.enums.OseeCacheEnum; +import org.eclipse.osee.framework.core.model.AbstractOseeType; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.logging.OseeLog; + +/** + * @author Roberto E. Escobar + */ +public abstract class AbstractOseeLoadingCache<K, T extends AbstractOseeType<K>> extends AbstractOseeCache<K, T> implements IOseeLoadingCache<K, T> { + private final IOseeDataAccessor<K, T> dataAccessor; + private final AtomicBoolean wasLoaded; + private long lastLoaded; + + protected AbstractOseeLoadingCache(OseeCacheEnum cacheId, IOseeDataAccessor<K, T> dataAccessor, boolean uniqueName) { + super(cacheId, uniqueName); + this.lastLoaded = 0; + this.wasLoaded = new AtomicBoolean(false); + this.dataAccessor = dataAccessor; + } + + @Override + public long getLastLoaded() { + return lastLoaded; + } + + private void setLastLoaded(long lastLoaded) { + this.lastLoaded = lastLoaded; + } + + @Override + public boolean isLoaded() { + return wasLoaded.get(); + } + + @Override + public void invalidate() { + wasLoaded.set(false); + } + + @Override + public synchronized void decacheAll() { + super.decacheAll(); + invalidate(); + } + + @Override + public synchronized void ensurePopulated() throws OseeCoreException { + if (wasLoaded.compareAndSet(false, true)) { + try { + reloadCache(); + } catch (OseeCoreException ex) { + wasLoaded.set(false); + throw ex; + } + } + } + + @Override + public synchronized boolean reloadCache() throws OseeCoreException { + dataAccessor.load(this); + OseeLog.log(this.getClass(), Level.INFO, "Loaded " + getCacheId().toString().toLowerCase()); + setLastLoaded(System.currentTimeMillis()); + wasLoaded.set(true); + return true; + } + + @Override + protected void store(Collection<T> toStore) throws OseeCoreException { + dataAccessor.store(toStore); + } + +} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ArtifactTypeCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ArtifactTypeCache.java index 5eb0b6636b0..01857f5322c 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ArtifactTypeCache.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ArtifactTypeCache.java @@ -18,8 +18,8 @@ import org.eclipse.osee.framework.core.model.type.ArtifactType; */ public class ArtifactTypeCache extends AbstractOseeCache<Long, ArtifactType> { - public ArtifactTypeCache(IOseeDataAccessor<Long, ArtifactType> dataAccessor) { - super(OseeCacheEnum.ARTIFACT_TYPE_CACHE, dataAccessor, true); + public ArtifactTypeCache() { + super(OseeCacheEnum.ARTIFACT_TYPE_CACHE, true); } } diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AttributeTypeCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AttributeTypeCache.java index bced08cd1c7..00479939957 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AttributeTypeCache.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AttributeTypeCache.java @@ -18,7 +18,7 @@ import org.eclipse.osee.framework.core.model.type.AttributeType; */ public class AttributeTypeCache extends AbstractOseeCache<Long, AttributeType> { - public AttributeTypeCache(IOseeDataAccessor<Long, AttributeType> dataAccessor) { - super(OseeCacheEnum.ATTRIBUTE_TYPE_CACHE, dataAccessor, true); + public AttributeTypeCache() { + super(OseeCacheEnum.ATTRIBUTE_TYPE_CACHE, true); } } diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/BranchCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/BranchCache.java index d2bdf17c0b1..7c9854b0d44 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/BranchCache.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/BranchCache.java @@ -28,7 +28,7 @@ import org.eclipse.osee.framework.jdk.core.util.Conditions; * @author Roberto E. Escobar * @author Ryan D. Brooks */ -public class BranchCache extends AbstractOseeCache<Long, Branch> { +public class BranchCache extends AbstractOseeLoadingCache<Long, Branch> { private final TransactionCache txCache; diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/IOseeCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/IOseeCache.java index a5cba5fa000..c63adb12d59 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/IOseeCache.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/IOseeCache.java @@ -23,10 +23,6 @@ public interface IOseeCache<KEY, TYPE> { int size(); - long getLastLoaded(); - - boolean reloadCache() throws OseeCoreException; - void decacheAll(); void decache(TYPE... types) throws OseeCoreException; @@ -47,8 +43,6 @@ public interface IOseeCache<KEY, TYPE> { void storeAllModified() throws OseeCoreException; - void ensurePopulated() throws OseeCoreException; - void storeItems(TYPE... items) throws OseeCoreException; void storeItems(Collection<TYPE> toStore) throws OseeCoreException; diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/IOseeLoadingCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/IOseeLoadingCache.java new file mode 100644 index 00000000000..0b655f3625e --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/IOseeLoadingCache.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 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.model.cache; + +/** + * @author Roberto E. Escobar + */ +public interface IOseeLoadingCache<KEY, TYPE> extends IOseeCache<KEY, TYPE> { + + long getLastLoaded(); + + boolean isLoaded(); + + void invalidate(); + + boolean reloadCache(); + +} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/OseeEnumTypeCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/OseeEnumTypeCache.java index 10ae72be66a..62d504998b1 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/OseeEnumTypeCache.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/OseeEnumTypeCache.java @@ -18,8 +18,8 @@ import org.eclipse.osee.framework.core.model.type.OseeEnumType; */ public final class OseeEnumTypeCache extends AbstractOseeCache<Long, OseeEnumType> { - public OseeEnumTypeCache(IOseeDataAccessor<Long, OseeEnumType> dataAccessor) { - super(OseeCacheEnum.OSEE_ENUM_TYPE_CACHE, dataAccessor, true); + public OseeEnumTypeCache() { + super(OseeCacheEnum.OSEE_ENUM_TYPE_CACHE, true); } } diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/RelationTypeCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/RelationTypeCache.java index 3bc88b9522a..f3fc7725f41 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/RelationTypeCache.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/RelationTypeCache.java @@ -18,7 +18,7 @@ import org.eclipse.osee.framework.core.model.type.RelationType; */ public final class RelationTypeCache extends AbstractOseeCache<Long, RelationType> { - public RelationTypeCache(IOseeDataAccessor<Long, RelationType> dataAccessor) { - super(OseeCacheEnum.RELATION_TYPE_CACHE, dataAccessor, true); + public RelationTypeCache() { + super(OseeCacheEnum.RELATION_TYPE_CACHE, true); } } diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java index 178650be763..d356e8ddfda 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import org.eclipse.osee.framework.core.enums.OseeCacheEnum; import org.eclipse.osee.framework.core.enums.TransactionVersion; @@ -32,20 +33,20 @@ import org.eclipse.osee.framework.logging.OseeLog; /** * @author Roberto E. Escobar */ -public class TransactionCache implements IOseeCache<String, TransactionRecord> { +public class TransactionCache implements IOseeLoadingCache<String, TransactionRecord> { private ITransactionDataAccessor accessor; private final Map<Integer, TransactionRecord> transactionIdCache = new ConcurrentHashMap<Integer, TransactionRecord>(); private final OseeCacheEnum cacheId; - private boolean ensurePopulatedRanOnce; + private final AtomicBoolean wasLoaded; private long lastLoaded; public TransactionCache() { this.lastLoaded = 0; this.cacheId = OseeCacheEnum.TRANSACTION_CACHE; - this.ensurePopulatedRanOnce = false; + this.wasLoaded = new AtomicBoolean(false); } public void setAccessor(ITransactionDataAccessor accessor) { @@ -191,10 +192,8 @@ public class TransactionCache implements IOseeCache<String, TransactionRecord> { } } - @Override - public synchronized void ensurePopulated() throws OseeCoreException { - if (!ensurePopulatedRanOnce) { - ensurePopulatedRanOnce = true; + private synchronized void ensurePopulated() throws OseeCoreException { + if (wasLoaded.compareAndSet(false, true)) { reloadCache(); } } @@ -224,6 +223,16 @@ public class TransactionCache implements IOseeCache<String, TransactionRecord> { @Override public void decacheAll() { transactionIdCache.clear(); - this.ensurePopulatedRanOnce = false; + invalidate(); + } + + @Override + public boolean isLoaded() { + return wasLoaded.get(); + } + + @Override + public void invalidate() { + wasLoaded.set(false); } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/ArtifactTypeFactory.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/ArtifactTypeFactory.java index 122a913a6da..eb8c1336fec 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/ArtifactTypeFactory.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/ArtifactTypeFactory.java @@ -32,6 +32,7 @@ public final class ArtifactTypeFactory implements IOseeTypeFactory { ArtifactType artifactType = cache.getByGuid(guid); if (artifactType == null) { artifactType = create(guid, isAbstract, name); + artifactType.setId(guid); cache.cache(artifactType); } else { artifactType.setName(name); diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/AttributeTypeFactory.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/AttributeTypeFactory.java index f2f93722bb5..17d4f06af6f 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/AttributeTypeFactory.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/AttributeTypeFactory.java @@ -49,6 +49,7 @@ public class AttributeTypeFactory implements IOseeTypeFactory { attributeType = create(guid, typeName, baseAttributeTypeId, attributeProviderNameId, fileTypeExtension, defaultValue, minOccurrences, maxOccurrences, description, taggerId, mediaType); + attributeType.setId(guid); attributeType.setOseeEnumType(oseeEnumType); cache.cache(attributeType); } else { diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/OseeEnumTypeFactory.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/OseeEnumTypeFactory.java index 89f8ad9cd6c..cd5fd872350 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/OseeEnumTypeFactory.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/OseeEnumTypeFactory.java @@ -54,6 +54,7 @@ public class OseeEnumTypeFactory implements IOseeTypeFactory { OseeEnumType oseeEnumType = cache.getByGuid(guid); if (oseeEnumType == null) { oseeEnumType = createEnumType(guid, enumTypeName); + oseeEnumType.setId(guid); cache.cache(oseeEnumType); } else { oseeEnumType.setName(enumTypeName); diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationTypeFactory.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationTypeFactory.java index 841f5f48a3a..752e4c448d0 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationTypeFactory.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationTypeFactory.java @@ -42,6 +42,7 @@ public class RelationTypeFactory implements IOseeTypeFactory { relationType = create(guid, typeName, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB, multiplicity, defaultOrderTypeGuid); + relationType.setId(guid); cache.cache(relationType); } else { relationType.setFields(typeName, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB, multiplicity, diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/services/IOseeCachingService.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/services/IOseeCachingService.java index b892f3ce3c3..9ed5a8825ab 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/services/IOseeCachingService.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/services/IOseeCachingService.java @@ -19,7 +19,6 @@ import org.eclipse.osee.framework.core.model.cache.IOseeCache; import org.eclipse.osee.framework.core.model.cache.OseeEnumTypeCache; import org.eclipse.osee.framework.core.model.cache.RelationTypeCache; import org.eclipse.osee.framework.core.model.cache.TransactionCache; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; /** * @author Roberto E. Escobar @@ -40,9 +39,11 @@ public interface IOseeCachingService { Collection<?> getCaches(); - IOseeCache<?, ?> getCache(OseeCacheEnum cacheId) throws OseeCoreException; + IOseeCache<?, ?> getCache(OseeCacheEnum cacheId); - void reloadAll() throws OseeCoreException; + void reloadTypes(); + + void reloadAll(); void clearAll(); } diff --git a/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/internal/DbBootstrapTask.java b/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/internal/DbBootstrapTask.java index b9d38262e33..94736208049 100644 --- a/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/internal/DbBootstrapTask.java +++ b/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/internal/DbBootstrapTask.java @@ -92,6 +92,7 @@ public class DbBootstrapTask implements IDbInitializationTask { oseeTypesSetup.execute(oseeTypes); service.clearAll(); + service.reloadTypes(); } private void createOseeDatastore() throws OseeCoreException { diff --git a/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/internal/PostDbUserCleanUp.java b/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/internal/PostDbUserCleanUp.java index 918c715780c..e2c28c8a73c 100644 --- a/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/internal/PostDbUserCleanUp.java +++ b/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/internal/PostDbUserCleanUp.java @@ -71,5 +71,6 @@ public class PostDbUserCleanUp implements IDbInitializationTask { } DatabaseInitActivator.getInstance().getCachingService().clearAll(); + DatabaseInitActivator.getInstance().getCachingService().reloadTypes(); } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorterTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorterTest.java index a299db354e9..4b7eaabce79 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorterTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorterTest.java @@ -41,7 +41,6 @@ import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.framework.skynet.core.mocks.DataFactory; import org.eclipse.osee.framework.skynet.core.mocks.MockIArtifact; -import org.eclipse.osee.framework.skynet.core.mocks.MockOseeDataAccessor; import org.eclipse.osee.framework.skynet.core.relation.order.IRelationOrderAccessor; import org.eclipse.osee.framework.skynet.core.relation.order.IRelationSorter; import org.eclipse.osee.framework.skynet.core.relation.order.RelationOrderData; @@ -214,7 +213,7 @@ public class RelationTypeSideSorterTest { RelationSorterProvider provider = new RelationSorterProvider(); IRelationOrderAccessor accessor = new DoNothingAccessor(); - RelationTypeCache cache = new RelationTypeCache(new MockOseeDataAccessor<Long, RelationType>()); + RelationTypeCache cache = new RelationTypeCache(); RelationType relationType1 = createRelationType(cache, "Rel 1", RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid()); diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderDataTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderDataTest.java index 3ed45ae194e..c6338ca4c7e 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderDataTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderDataTest.java @@ -33,7 +33,6 @@ import org.eclipse.osee.framework.jdk.core.util.Collections; import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.framework.skynet.core.mocks.DataFactory; -import org.eclipse.osee.framework.skynet.core.mocks.MockOseeDataAccessor; import org.eclipse.osee.framework.skynet.core.types.IArtifact; import org.junit.After; import org.junit.Assert; @@ -59,7 +58,7 @@ public class RelationOrderDataTest { accessor = new MockRelationOrderAccessor(); data = new RelationOrderData(accessor, artifact); - RelationTypeCache cache = new RelationTypeCache(new MockOseeDataAccessor<Long, RelationType>()); + RelationTypeCache cache = new RelationTypeCache(); relationType1 = createRelationType(cache, "Rel 1", RelationOrderBaseTypes.USER_DEFINED.getGuid()); relationType2 = createRelationType(cache, "Rel 2", RelationOrderBaseTypes.UNORDERED.getGuid()); diff --git a/plugins/org.eclipse.osee.framework.skynet.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.skynet.core/META-INF/MANIFEST.MF index a1b3e3ff910..66dd0ba9240 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.skynet.core/META-INF/MANIFEST.MF @@ -46,7 +46,8 @@ Export-Package: org.eclipse.osee.framework.skynet.core, org.eclipse.osee.framework.skynet.core.validation, org.eclipse.osee.framework.skynet.core.word Bundle-Vendor: Eclipse Open System Engineering Environment -Import-Package: com.google.common.collect;version="[11.0.0,15.0.0]", +Import-Package: com.google.common.collect;version="[11.0.0,15.0.0)", + com.google.common.io;version="[11.0.0,15.0.0)", javax.ws.rs.core;version="2.0.0", org.apache.commons.lang;version="2.4.0", org.apache.xerces.parsers;version="2.9.0", @@ -54,10 +55,16 @@ Import-Package: com.google.common.collect;version="[11.0.0,15.0.0]", org.apache.xml.serialize;version="2.9.0", org.cyberneko.html.parsers, org.eclipse.debug.core, + org.eclipse.emf.common.util, + org.eclipse.emf.ecore, + org.eclipse.emf.ecore.util, org.eclipse.osee.cache.admin, org.eclipse.osee.framework.core.client, org.eclipse.osee.framework.core.client.server, org.eclipse.osee.framework.core.data, + org.eclipse.osee.framework.core.dsl, + org.eclipse.osee.framework.core.dsl.oseeDsl, + org.eclipse.osee.framework.core.dsl.oseeDsl.util, org.eclipse.osee.framework.core.enums, org.eclipse.osee.framework.core.exception, org.eclipse.osee.framework.core.message, diff --git a/plugins/org.eclipse.osee.framework.skynet.core/OSGI-INF/osee.client.caching.service.xml b/plugins/org.eclipse.osee.framework.skynet.core/OSGI-INF/osee.client.caching.service.xml index dfff7fbd066..9cf8540e0e5 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/OSGI-INF/osee.client.caching.service.xml +++ b/plugins/org.eclipse.osee.framework.skynet.core/OSGI-INF/osee.client.caching.service.xml @@ -4,6 +4,6 @@ <service> <provide interface="org.eclipse.osee.framework.core.services.IOseeCachingService"/> </service> - <reference bind="setModelFactory" cardinality="1..1" interface="org.eclipse.osee.framework.core.services.IOseeModelFactoryService" name="IOseeModelFactoryService" policy="static"/> <reference bind="setJdbcService" cardinality="1..1" interface="org.eclipse.osee.jdbc.JdbcService" name="JdbcService" policy="static" target="(osgi.binding=skynet.jdbc.service)"/> + <reference bind="setOseeClient" cardinality="1..1" interface="org.eclipse.osee.orcs.rest.client.OseeClient" name="OseeClient" policy="static"/> </scr:component> diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactTypeManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactTypeManager.java index 24146631053..2a7d8f2a575 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactTypeManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactTypeManager.java @@ -45,6 +45,8 @@ import org.eclipse.osee.framework.skynet.core.internal.OseeTypesExportOperation; import org.eclipse.osee.framework.skynet.core.internal.OseeTypesImportOperation; import org.eclipse.osee.framework.skynet.core.internal.ServiceUtil; import org.eclipse.osee.framework.skynet.core.utility.ConnectionHandler; +import org.eclipse.osee.orcs.rest.client.OseeClient; +import org.eclipse.osee.orcs.rest.model.TypesEndpoint; /** * Contains methods specific to artifact types. All artifact methods will eventually be moved from the @@ -113,7 +115,7 @@ public class ArtifactTypeManager { } ArtifactType artifactType = getCache().getByGuid(guid); if (artifactType == null) { - getCache().reloadCache(); + getCacheService().reloadTypes(); artifactType = getCache().getByGuid(guid); if (artifactType == null) { throw new OseeTypeDoesNotExist("Artifact type [%s] is not available.", guid); @@ -220,10 +222,6 @@ public class ArtifactTypeManager { } } - public static void persist() throws OseeCoreException { - getCache().storeAllModified(); - } - /** * @return Returns the ArtifactType factory. */ @@ -235,11 +233,16 @@ public class ArtifactTypeManager { } public static IOperation newImportTypesOp(URI model) { - return new OseeTypesImportOperation(getCacheService(), model); + IOseeCachingService caches = getCacheService(); + OseeClient oseeClient = ServiceUtil.getOseeClient(); + TypesEndpoint typesEndpoint = oseeClient.getTypesEndpoint(); + return new OseeTypesImportOperation(typesEndpoint, caches, model, true); } public static IOperation newExportTypesOp(OutputStream outputStream) { - return new OseeTypesExportOperation(outputStream); + OseeClient oseeClient = ServiceUtil.getOseeClient(); + TypesEndpoint typesEndpoint = oseeClient.getTypesEndpoint(); + return new OseeTypesExportOperation(typesEndpoint, outputStream); } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java index d4f02a7b07a..dd2cb8f8d86 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java @@ -666,7 +666,7 @@ public class BranchManager { } public static void resetWasLoaded() { - getCache().resetWasLoaded(); + getCache().invalidate(); } public static boolean isLoaded() { diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTypeManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTypeManager.java index 9c4b2b69445..ca19c63a47e 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTypeManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/AttributeTypeManager.java @@ -88,7 +88,7 @@ public class AttributeTypeManager { } AttributeType attributeType = getCache().getByGuid(guid); if (attributeType == null) { - getCache().reloadCache(); + getCacheService().reloadTypes(); attributeType = getCache().getByGuid(guid); if (attributeType == null) { throw new OseeTypeDoesNotExist("Attribute Type [%s] is not available.", guid); @@ -140,10 +140,6 @@ public class AttributeTypeManager { return getEnumerationValues(getType(attributeName)); } - public static void persist() throws OseeCoreException { - getCache().storeAllModified(); - } - @SuppressWarnings("rawtypes") public static boolean isBaseTypeCompatible(Class<? extends Attribute> baseType, IAttributeType attributeType) throws OseeCoreException { return baseType.isAssignableFrom(getAttributeBaseClass(attributeType)); diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumTypeManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumTypeManager.java index dd4c6dd6819..e74b677899f 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumTypeManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/attribute/OseeEnumTypeManager.java @@ -65,7 +65,4 @@ public class OseeEnumTypeManager { return -1; } - public static void persist() throws OseeCoreException { - getCache().storeAllModified(); - } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java index 9bbb96bd115..06083f9b807 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java @@ -10,9 +10,15 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.internal; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; +import java.util.logging.Level; +import javax.ws.rs.core.Response; import org.eclipse.osee.framework.core.enums.OseeCacheEnum; -import org.eclipse.osee.framework.core.model.OseeCachingService; +import org.eclipse.osee.framework.core.model.BranchFactory; import org.eclipse.osee.framework.core.model.TransactionRecordFactory; import org.eclipse.osee.framework.core.model.cache.ArtifactTypeCache; import org.eclipse.osee.framework.core.model.cache.AttributeTypeCache; @@ -22,123 +28,172 @@ import org.eclipse.osee.framework.core.model.cache.OseeEnumTypeCache; import org.eclipse.osee.framework.core.model.cache.RelationTypeCache; import org.eclipse.osee.framework.core.model.cache.TransactionCache; import org.eclipse.osee.framework.core.services.IOseeCachingService; -import org.eclipse.osee.framework.core.services.IOseeModelFactoryService; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientArtifactTypeAccessor; -import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientAttributeTypeAccessor; -import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientOseeEnumTypeAccessor; -import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientRelationTypeAccessor; +import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; +import org.eclipse.osee.framework.jdk.core.util.Conditions; +import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.skynet.core.internal.accessors.DatabaseBranchAccessor; import org.eclipse.osee.framework.skynet.core.internal.accessors.DatabaseTransactionRecordAccessor; +import org.eclipse.osee.jaxrs.client.JaxRsExceptions; import org.eclipse.osee.jdbc.JdbcClient; import org.eclipse.osee.jdbc.JdbcService; +import org.eclipse.osee.orcs.rest.client.OseeClient; +import org.eclipse.osee.orcs.rest.model.TypesEndpoint; +import com.google.common.io.InputSupplier; /** * @author Roberto E. Escobar */ public class ClientCachingServiceProxy implements IOseeCachingService { - private IOseeModelFactoryService modelFactory; + public static interface TypesLoader { + void loadTypes(IOseeCachingService service, InputSupplier<? extends InputStream> supplier); + } + private JdbcService jdbcService; + private OseeClient oseeClient; - private IOseeCachingService proxiedService; + private DslToTypeLoader typesLoader; + private BranchCache branchCache; + private TransactionCache txCache; - public void setModelFactory(IOseeModelFactoryService modelFactory) { - this.modelFactory = modelFactory; - } + private OseeEnumTypeCache enumTypeCache; + private AttributeTypeCache attributeTypeCache; + private ArtifactTypeCache artifactTypeCache; + private RelationTypeCache relationTypeCache; + + private List<IOseeCache<?, ?>> caches; public void setJdbcService(JdbcService jdbcService) { this.jdbcService = jdbcService; } + public void setOseeClient(OseeClient oseeClient) { + this.oseeClient = oseeClient; + } + public void start() { - proxiedService = createService(modelFactory); + JdbcClient jdbcClient = jdbcService.getClient(); + + txCache = new TransactionCache(); + branchCache = new BranchCache(new DatabaseBranchAccessor(jdbcClient, txCache, new BranchFactory()), txCache); + txCache.setAccessor(new DatabaseTransactionRecordAccessor(jdbcClient, branchCache, new TransactionRecordFactory())); + + typesLoader = new DslToTypeLoader(branchCache); + + artifactTypeCache = new ArtifactTypeCache(); + enumTypeCache = new OseeEnumTypeCache(); + attributeTypeCache = new AttributeTypeCache(); + relationTypeCache = new RelationTypeCache(); + + caches = new ArrayList<IOseeCache<?, ?>>(); + caches.add(branchCache); + caches.add(txCache); + caches.add(artifactTypeCache); + caches.add(attributeTypeCache); + caches.add(relationTypeCache); + caches.add(enumTypeCache); } public void stop() { - if (proxiedService != null) { - proxiedService = null; - } - } + caches.clear(); + + enumTypeCache = null; + attributeTypeCache = null; + relationTypeCache = null; + artifactTypeCache = null; + + branchCache = null; + txCache = null; - private IOseeCachingService getProxiedService() { - return proxiedService; + typesLoader = null; } @Override public BranchCache getBranchCache() { - return getProxiedService().getBranchCache(); + return branchCache; } @Override public TransactionCache getTransactionCache() { - return getProxiedService().getTransactionCache(); + return txCache; } @Override public ArtifactTypeCache getArtifactTypeCache() { - return getProxiedService().getArtifactTypeCache(); + return artifactTypeCache; } @Override public AttributeTypeCache getAttributeTypeCache() { - return getProxiedService().getAttributeTypeCache(); + return attributeTypeCache; } @Override public RelationTypeCache getRelationTypeCache() { - return getProxiedService().getRelationTypeCache(); + return relationTypeCache; } @Override public OseeEnumTypeCache getEnumTypeCache() { - return getProxiedService().getEnumTypeCache(); + return enumTypeCache; } @Override public Collection<?> getCaches() { - return getProxiedService().getCaches(); + return caches; } @Override - public IOseeCache<?, ?> getCache(OseeCacheEnum cacheId) throws OseeCoreException { - return getProxiedService().getCache(cacheId); + public IOseeCache<?, ?> getCache(OseeCacheEnum cacheId) { + Conditions.checkNotNull(cacheId, "cache id to find"); + for (IOseeCache<?, ?> cache : caches) { + if (cache.getCacheId().equals(cacheId)) { + return cache; + } + } + throw new OseeArgumentException("Unable to find cache for id [%s]", cacheId); } @Override - public void reloadAll() throws OseeCoreException { - getProxiedService().reloadAll(); + public void reloadTypes() { + synchronized (typesLoader) { + typesLoader.loadTypes(this, new InputSupplier<InputStream>() { + @Override + public InputStream getInput() { + OseeLog.log(Activator.class, Level.INFO, "Loading All type caches <<<<<<<<<<<<<<<<<<<<<<"); + TypesEndpoint typesEndpoint = oseeClient.getTypesEndpoint(); + try { + Response response = typesEndpoint.getTypes(); + return response.hasEntity() ? response.readEntity(InputStream.class) : new ByteArrayInputStream( + new byte[0]); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); + } + } + }); + } } @Override - public void clearAll() { - getProxiedService().clearAll(); - } - - private IOseeCachingService createService(IOseeModelFactoryService factory) { - JdbcClient jdbcClient = jdbcService.getClient(); - TransactionCache transactionCache = new TransactionCache(); - DatabaseBranchAccessor clientBranchAccessor = - new DatabaseBranchAccessor(jdbcClient, transactionCache, factory.getBranchFactory()); - BranchCache branchCache = new BranchCache(clientBranchAccessor, transactionCache); - - TransactionRecordFactory txFactory = factory.getTransactionFactory(); + public void reloadAll() { + getBranchCache().reloadCache(); + getTransactionCache().reloadCache(); - transactionCache.setAccessor(new DatabaseTransactionRecordAccessor(jdbcClient, branchCache, txFactory)); - OseeEnumTypeCache oseeEnumTypeCache = - new OseeEnumTypeCache(new ClientOseeEnumTypeAccessor(factory.getOseeEnumTypeFactory())); - - AttributeTypeCache attributeTypeCache = - new AttributeTypeCache(new ClientAttributeTypeAccessor(factory.getAttributeTypeFactory(), oseeEnumTypeCache)); - - ArtifactTypeCache artifactTypeCache = - new ArtifactTypeCache(new ClientArtifactTypeAccessor(factory.getArtifactTypeFactory(), attributeTypeCache, - branchCache)); + reloadTypes(); + } - RelationTypeCache relationTypeCache = - new RelationTypeCache(new ClientRelationTypeAccessor(factory.getRelationTypeFactory(), artifactTypeCache)); + @Override + public void clearAll() { + getBranchCache().decacheAll(); + getTransactionCache().decacheAll(); + clearAllTypes(); + } - return new OseeCachingService(branchCache, transactionCache, artifactTypeCache, attributeTypeCache, - relationTypeCache, oseeEnumTypeCache); + private void clearAllTypes() { + getEnumTypeCache().decacheAll(); + getAttributeTypeCache().decacheAll(); + getRelationTypeCache().decacheAll(); + getArtifactTypeCache().decacheAll(); } + } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/DslToTypeLoader.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/DslToTypeLoader.java new file mode 100644 index 00000000000..b7a43271572 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/DslToTypeLoader.java @@ -0,0 +1,445 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.skynet.core.internal; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import org.eclipse.emf.common.util.EList; +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.data.TokenFactory; +import org.eclipse.osee.framework.core.dsl.OseeDslResource; +import org.eclipse.osee.framework.core.dsl.OseeDslResourceUtil; +import org.eclipse.osee.framework.core.dsl.oseeDsl.AddAttribute; +import org.eclipse.osee.framework.core.dsl.oseeDsl.AddEnum; +import org.eclipse.osee.framework.core.dsl.oseeDsl.AttributeOverrideOption; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDslFactory; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OverrideOption; +import org.eclipse.osee.framework.core.dsl.oseeDsl.RemoveAttribute; +import org.eclipse.osee.framework.core.dsl.oseeDsl.RemoveEnum; +import org.eclipse.osee.framework.core.dsl.oseeDsl.UpdateAttribute; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactType; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeType; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeTypeRef; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XOseeArtifactTypeOverride; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XOseeEnumEntry; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XOseeEnumOverride; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XOseeEnumType; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; +import org.eclipse.osee.framework.core.dsl.oseeDsl.util.OseeDslSwitch; +import org.eclipse.osee.framework.core.enums.CoreBranches; +import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; +import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; +import org.eclipse.osee.framework.core.model.IOseeStorable; +import org.eclipse.osee.framework.core.model.OseeEnumEntry; +import org.eclipse.osee.framework.core.model.cache.ArtifactTypeCache; +import org.eclipse.osee.framework.core.model.cache.AttributeTypeCache; +import org.eclipse.osee.framework.core.model.cache.BranchCache; +import org.eclipse.osee.framework.core.model.cache.IOseeCache; +import org.eclipse.osee.framework.core.model.cache.OseeEnumTypeCache; +import org.eclipse.osee.framework.core.model.cache.RelationTypeCache; +import org.eclipse.osee.framework.core.model.type.ArtifactType; +import org.eclipse.osee.framework.core.model.type.ArtifactTypeFactory; +import org.eclipse.osee.framework.core.model.type.AttributeType; +import org.eclipse.osee.framework.core.model.type.AttributeTypeFactory; +import org.eclipse.osee.framework.core.model.type.OseeEnumType; +import org.eclipse.osee.framework.core.model.type.OseeEnumTypeFactory; +import org.eclipse.osee.framework.core.model.type.RelationTypeFactory; +import org.eclipse.osee.framework.core.services.IOseeCachingService; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Conditions; +import org.eclipse.osee.framework.jdk.core.util.HexUtil; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.skynet.core.internal.ClientCachingServiceProxy.TypesLoader; +import com.google.common.io.InputSupplier; + +/** + * @author Roberto E. Escobar + */ +public class DslToTypeLoader implements TypesLoader { + + private final ArtifactTypeFactory artTypeFactory = new ArtifactTypeFactory(); + private final AttributeTypeFactory attrTypeFactory = new AttributeTypeFactory(); + private final OseeEnumTypeFactory enumTypeFactory = new OseeEnumTypeFactory(); + private final RelationTypeFactory relTypeFactory = new RelationTypeFactory(); + + private final BranchCache branchCache; + + public DslToTypeLoader(BranchCache branchCache) { + super(); + this.branchCache = branchCache; + } + + @Override + public void loadTypes(IOseeCachingService caches, InputSupplier<? extends InputStream> supplier) { + OseeDslResource loadModel; + InputStream inputStream = null; + try { + inputStream = supplier.getInput(); + loadModel = OseeDslResourceUtil.loadModel("osee:/text.osee", inputStream); + } catch (Exception ex) { + throw asOseeCoreException(ex); + } finally { + Lib.close(inputStream); + } + + TypeBuffer buffer = new TypeBuffer(); + + OseeDsl model = loadModel.getModel(); + if (model != null) { + loadTypes(buffer, branchCache, model); + } + + buffer.copyEnumTypes(caches.getEnumTypeCache()); + buffer.copyAttrTypes(caches.getAttributeTypeCache()); + buffer.copyArtTypes(caches.getArtifactTypeCache()); + buffer.copyRelTypes(caches.getRelationTypeCache()); + } + + private OseeCoreException asOseeCoreException(Exception ex) { + return ex instanceof OseeCoreException ? (OseeCoreException) ex : new OseeCoreException(ex); + } + + private void loadTypes(TypeBuffer buffer, BranchCache branchCache, OseeDsl model) { + for (XOseeArtifactTypeOverride xArtifactTypeOverride : model.getArtifactTypeOverrides()) { + translateXArtifactTypeOverride(xArtifactTypeOverride); + } + + for (XArtifactType xArtifactType : model.getArtifactTypes()) { + translateXArtifactType(buffer, xArtifactType); + } + + for (XOseeEnumOverride xEnumOverride : model.getEnumOverrides()) { + translateXEnumOverride(xEnumOverride); + } + + for (XOseeEnumType xEnumType : model.getEnumTypes()) { + translateXEnumType(buffer, xEnumType); + } + + for (XAttributeType xAttributeType : model.getAttributeTypes()) { + translateXAttributeType(buffer, xAttributeType); + } + + for (XArtifactType xArtifactType : model.getArtifactTypes()) { + handleXArtifactTypeCrossRef(buffer, branchCache, xArtifactType); + } + + for (XRelationType xRelationType : model.getRelationTypes()) { + translateXRelationType(buffer, xRelationType); + } + } + + private void handleXArtifactTypeCrossRef(TypeBuffer buffer, BranchCache branchCache, XArtifactType xArtifactType) throws OseeCoreException { + ArtifactType targetArtifactType = buffer.getArtTypes().getByGuid(HexUtil.toLong(xArtifactType.getUuid())); + translateSuperTypes(buffer, targetArtifactType, xArtifactType); + Map<IOseeBranch, Collection<AttributeType>> validAttributesPerBranch = + getOseeAttributes(buffer, branchCache, xArtifactType); + targetArtifactType.setAllAttributeTypes(validAttributesPerBranch); + } + + private void translateSuperTypes(TypeBuffer buffer, ArtifactType targetArtifactType, XArtifactType xArtifactType) throws OseeCoreException { + Set<ArtifactType> oseeSuperTypes = new HashSet<ArtifactType>(); + for (XArtifactType xSuperType : xArtifactType.getSuperArtifactTypes()) { + String superTypeName = xSuperType.getName(); + ArtifactType oseeSuperType = buffer.getArtTypes().getUniqueByName(superTypeName); + oseeSuperTypes.add(oseeSuperType); + } + + if (!oseeSuperTypes.isEmpty()) { + targetArtifactType.setSuperTypes(oseeSuperTypes); + } + } + + private Map<IOseeBranch, Collection<AttributeType>> getOseeAttributes(TypeBuffer buffer, BranchCache branchCache, XArtifactType xArtifactType) throws OseeCoreException { + Map<IOseeBranch, Collection<AttributeType>> validAttributes = + new HashMap<IOseeBranch, Collection<AttributeType>>(); + for (XAttributeTypeRef xAttributeTypeRef : xArtifactType.getValidAttributeTypes()) { + XAttributeType xAttributeType = xAttributeTypeRef.getValidAttributeType(); + IOseeBranch branch = getAttributeBranch(branchCache, xAttributeTypeRef); + Long attrUuid = HexUtil.toLong(xAttributeType.getUuid()); + AttributeType oseeAttributeType = buffer.getAttrTypes().getByGuid(attrUuid); + if (oseeAttributeType != null) { + Collection<AttributeType> listOfAllowedAttributes = validAttributes.get(branch); + if (listOfAllowedAttributes == null) { + listOfAllowedAttributes = new HashSet<AttributeType>(); + validAttributes.put(branch, listOfAllowedAttributes); + } + listOfAllowedAttributes.add(oseeAttributeType); + } else { + OseeLog.logf(Activator.class, Level.WARNING, "Type was null for \"%s\"", xArtifactType.getName()); + } + } + return validAttributes; + } + + private IOseeBranch getAttributeBranch(BranchCache branchCache, XAttributeTypeRef xAttributeTypeRef) throws OseeCoreException { + String branchGuid = xAttributeTypeRef.getBranchUuid(); + if (branchGuid == null) { + return CoreBranches.SYSTEM_ROOT; + } else { + long branchUuid = Long.parseLong(branchGuid); + IOseeBranch branch = branchCache.getByUuid(branchUuid); + if (branch == null) { + branch = TokenFactory.createBranch(branchUuid, branchGuid); + } + return branch; + } + } + + private void translateXArtifactTypeOverride(XOseeArtifactTypeOverride xArtTypeOverride) { + XArtifactType xArtifactType = xArtTypeOverride.getOverridenArtifactType(); + final EList<XAttributeTypeRef> validAttributeTypes = xArtifactType.getValidAttributeTypes(); + if (!xArtTypeOverride.isInheritAll()) { + validAttributeTypes.clear(); + } + + OseeDslSwitch<Void> overrideVisitor = new OseeDslSwitch<Void>() { + + @Override + public Void caseAddAttribute(AddAttribute addOption) { + XAttributeTypeRef attributeRef = addOption.getAttribute(); + validAttributeTypes.add(attributeRef); + return super.caseAddAttribute(addOption); + } + + @Override + public Void caseRemoveAttribute(RemoveAttribute removeOption) { + XAttributeType attribute = removeOption.getAttribute(); + String guidToMatch = attribute.getUuid(); + List<XAttributeTypeRef> toRemove = new LinkedList<XAttributeTypeRef>(); + for (XAttributeTypeRef xAttributeTypeRef : validAttributeTypes) { + String itemGuid = xAttributeTypeRef.getValidAttributeType().getUuid(); + if (guidToMatch.equals(itemGuid)) { + toRemove.add(xAttributeTypeRef); + } + } + validAttributeTypes.removeAll(toRemove); + return super.caseRemoveAttribute(removeOption); + } + + @Override + public Void caseUpdateAttribute(UpdateAttribute updateAttribute) { + XAttributeTypeRef refToUpdate = updateAttribute.getAttribute(); + String guidToMatch = refToUpdate.getValidAttributeType().getUuid(); + List<XAttributeTypeRef> toRemove = new LinkedList<XAttributeTypeRef>(); + for (XAttributeTypeRef xAttributeTypeRef : validAttributeTypes) { + String itemGuid = xAttributeTypeRef.getValidAttributeType().getUuid(); + if (guidToMatch.equals(itemGuid)) { + toRemove.add(xAttributeTypeRef); + } + } + validAttributeTypes.removeAll(toRemove); + validAttributeTypes.add(refToUpdate); + return super.caseUpdateAttribute(updateAttribute); + } + + }; + + for (AttributeOverrideOption xOverrideOption : xArtTypeOverride.getOverrideOptions()) { + overrideVisitor.doSwitch(xOverrideOption); + } + } + + private void translateXArtifactType(TypeBuffer buffer, XArtifactType xArtifactType) throws OseeCoreException { + String artifactTypeName = xArtifactType.getName(); + Long artUuid = HexUtil.toLong(xArtifactType.getUuid()); + artTypeFactory.createOrUpdate(buffer.getArtTypes(), artUuid, xArtifactType.isAbstract(), artifactTypeName); + } + + private void translateXEnumType(TypeBuffer buffer, XOseeEnumType xEnumType) throws OseeCoreException { + String enumTypeName = xEnumType.getName(); + Long enumUuid = HexUtil.toLong(xEnumType.getUuid()); + OseeEnumType oseeEnumType = enumTypeFactory.createOrUpdate(buffer.getEnumTypes(), enumUuid, enumTypeName); + + int lastOrdinal = 0; + List<OseeEnumEntry> oseeEnumEntries = new ArrayList<OseeEnumEntry>(); + for (XOseeEnumEntry xEnumEntry : xEnumType.getEnumEntries()) { + String entryName = xEnumEntry.getName(); + String ordinal = xEnumEntry.getOrdinal(); + if (Strings.isValid(ordinal)) { + lastOrdinal = Integer.parseInt(ordinal); + } + oseeEnumEntries.add(enumTypeFactory.createEnumEntry(entryName, lastOrdinal, xEnumEntry.getDescription())); + lastOrdinal++; + } + oseeEnumType.setEntries(oseeEnumEntries); + } + + private void translateXEnumOverride(XOseeEnumOverride xEnumOverride) { + XOseeEnumType xEnumType = xEnumOverride.getOverridenEnumType(); + final EList<XOseeEnumEntry> enumEntries = xEnumType.getEnumEntries(); + if (!xEnumOverride.isInheritAll()) { + enumEntries.clear(); + } + + OseeDslSwitch<Void> overrideVisitor = new OseeDslSwitch<Void>() { + + @Override + public Void caseAddEnum(AddEnum addEnum) { + String entryName = addEnum.getEnumEntry(); + String entryGuid = addEnum.getEntryGuid(); + String description = addEnum.getDescription(); + XOseeEnumEntry xEnumEntry = OseeDslFactory.eINSTANCE.createXOseeEnumEntry(); + xEnumEntry.setName(entryName); + xEnumEntry.setEntryGuid(entryGuid); + xEnumEntry.setDescription(description); + enumEntries.add(xEnumEntry); + return super.caseAddEnum(addEnum); + } + + @Override + public Void caseRemoveEnum(RemoveEnum removeEnum) { + XOseeEnumEntry enumEntry = removeEnum.getEnumEntry(); + String guidToMatch = enumEntry.getEntryGuid(); + List<XOseeEnumEntry> toRemove = new LinkedList<XOseeEnumEntry>(); + for (XOseeEnumEntry item : enumEntries) { + String itemGuid = item.getEntryGuid(); + if (guidToMatch.equals(itemGuid)) { + toRemove.add(item); + } + } + enumEntries.removeAll(toRemove); + return super.caseRemoveEnum(removeEnum); + } + + }; + + for (OverrideOption xOverrideOption : xEnumOverride.getOverrideOptions()) { + overrideVisitor.doSwitch(xOverrideOption); + } + } + + private void translateXAttributeType(TypeBuffer buffer, XAttributeType xAttributeType) throws OseeCoreException { + int min = Integer.parseInt(xAttributeType.getMin()); + int max = Integer.MAX_VALUE; + if (!xAttributeType.getMax().equals("unlimited")) { + max = Integer.parseInt(xAttributeType.getMax()); + } + XOseeEnumType xEnumType = xAttributeType.getEnumType(); + OseeEnumType oseeEnumType = null; + if (xEnumType != null) { + Long enumUuid = HexUtil.toLong(xEnumType.getUuid()); + oseeEnumType = buffer.getEnumTypes().getByGuid(enumUuid); + } + + Long attrUuid = HexUtil.toLong(xAttributeType.getUuid()); + attrTypeFactory.createOrUpdate(buffer.getAttrTypes(), // + attrUuid, // + xAttributeType.getName(), // + getQualifiedTypeName(xAttributeType.getBaseAttributeType()), // + getQualifiedTypeName(xAttributeType.getDataProvider()), // + xAttributeType.getFileExtension(), // + xAttributeType.getDefaultValue(), // + oseeEnumType, // + min, // + max, // + xAttributeType.getDescription(), // + xAttributeType.getTaggerId(),// + xAttributeType.getMediaType()); + } + + private String getQualifiedTypeName(String id) { + String value = id; + if (!value.contains(".")) { + value = "org.eclipse.osee.framework.skynet.core." + id; + } + return value; + } + + private void translateXRelationType(TypeBuffer buffer, XRelationType xRelationType) throws OseeCoreException { + RelationTypeMultiplicity multiplicity = + RelationTypeMultiplicity.getFromString(xRelationType.getMultiplicity().name()); + + String sideATypeName = xRelationType.getSideAArtifactType().getName(); + String sideBTypeName = xRelationType.getSideBArtifactType().getName(); + + ArtifactType sideAType = buffer.getArtTypes().getUniqueByName(sideATypeName); + ArtifactType sideBType = buffer.getArtTypes().getUniqueByName(sideBTypeName); + + Long relUuid = HexUtil.toLong(xRelationType.getUuid()); + relTypeFactory.createOrUpdate(buffer.getRelTypes(), // + relUuid, // + xRelationType.getName(), // + xRelationType.getSideAName(), // + xRelationType.getSideBName(), // + sideAType, // + sideBType, // + multiplicity, // + orderTypeNameToGuid(xRelationType.getDefaultOrderType()) // + ); + } + + private String orderTypeNameToGuid(String orderTypeName) throws OseeCoreException { + Conditions.checkNotNull(orderTypeName, "orderTypeName"); + return RelationOrderBaseTypes.getFromOrderTypeName(orderTypeName.replaceAll("_", " ")).getGuid(); + } + + private static final class TypeBuffer { + private final ArtifactTypeCache artTypes = new ArtifactTypeCache(); + private final OseeEnumTypeCache enumTypes = new OseeEnumTypeCache(); + private final AttributeTypeCache attrTypes = new AttributeTypeCache(); + private final RelationTypeCache relTypes = new RelationTypeCache(); + + public ArtifactTypeCache getArtTypes() { + return artTypes; + } + + public OseeEnumTypeCache getEnumTypes() { + return enumTypes; + } + + public AttributeTypeCache getAttrTypes() { + return attrTypes; + } + + public RelationTypeCache getRelTypes() { + return relTypes; + } + + public void copyArtTypes(ArtifactTypeCache dest) { + copy(artTypes, dest); + } + + public void copyEnumTypes(OseeEnumTypeCache dest) { + copy(enumTypes, dest); + } + + public void copyAttrTypes(AttributeTypeCache dest) { + copy(attrTypes, dest); + } + + public void copyRelTypes(RelationTypeCache dest) { + copy(relTypes, dest); + } + + private <T extends IOseeStorable> void copy(IOseeCache<Long, T> src, IOseeCache<Long, T> dest) { + synchronized (dest) { + dest.decacheAll(); + for (T type : src.getAll()) { + type.clearDirty(); + dest.cache(type); + } + } + } + + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/OseeTypesExportOperation.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/OseeTypesExportOperation.java index 6bb9eac63a8..c9a83e52f00 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/OseeTypesExportOperation.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/OseeTypesExportOperation.java @@ -10,43 +10,46 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.internal; +import java.io.InputStream; import java.io.OutputStream; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.core.client.ClientSessionManager; -import org.eclipse.osee.framework.core.client.server.HttpUrlBuilderClient; -import org.eclipse.osee.framework.core.data.OseeServerContext; import org.eclipse.osee.framework.core.operation.AbstractOperation; -import org.eclipse.osee.framework.core.util.HttpProcessor; -import org.eclipse.osee.framework.core.util.HttpProcessor.AcquireResult; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.Conditions; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.jaxrs.client.JaxRsExceptions; +import org.eclipse.osee.orcs.rest.model.TypesEndpoint; /** * @author Roberto E. Escobar */ public class OseeTypesExportOperation extends AbstractOperation { + + private final TypesEndpoint typesEndpoint; private final OutputStream outputStream; - public OseeTypesExportOperation(OutputStream outputStream) { + public OseeTypesExportOperation(TypesEndpoint typesEndpoint, OutputStream outputStream) { super("Export Osee Types Model", Activator.PLUGIN_ID); + this.typesEndpoint = typesEndpoint; this.outputStream = outputStream; } @Override protected void doWork(IProgressMonitor monitor) throws Exception { Conditions.checkNotNull(outputStream, "outputStream"); - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("sessionId", ClientSessionManager.getSessionId()); - - String url = - HttpUrlBuilderClient.getInstance().getOsgiServletServiceUrl(OseeServerContext.OSEE_MODEL_CONTEXT, parameters); - - AcquireResult results = HttpProcessor.acquire(new URL(url), outputStream); - if (!results.wasSuccessful()) { - throw new OseeCoreException("Error exporting osee types"); + try { + Response response = typesEndpoint.getTypes(); + if (Status.OK.getStatusCode() == response.getStatus()) { + InputStream inputStream = response.readEntity(InputStream.class); + try { + Lib.inputStreamToOutputStream(inputStream, outputStream); + } finally { + Lib.close(inputStream); + } + } + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); } } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/OseeTypesImportOperation.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/OseeTypesImportOperation.java index 9ed486ba1e0..d40dc8c2f42 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/OseeTypesImportOperation.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/OseeTypesImportOperation.java @@ -10,73 +10,49 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.internal; -import java.io.BufferedInputStream; -import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.core.data.OseeServerContext; -import org.eclipse.osee.framework.core.enums.CoreTranslatorId; -import org.eclipse.osee.framework.core.model.OseeImportModelRequest; -import org.eclipse.osee.framework.core.model.OseeImportModelResponse; import org.eclipse.osee.framework.core.operation.AbstractOperation; import org.eclipse.osee.framework.core.services.IOseeCachingService; import org.eclipse.osee.framework.jdk.core.util.Lib; -import org.eclipse.osee.framework.skynet.core.artifact.HttpClientMessage; +import org.eclipse.osee.jaxrs.client.JaxRsExceptions; +import org.eclipse.osee.orcs.rest.model.TypesEndpoint; /** * @author Roberto E. Escobar */ public class OseeTypesImportOperation extends AbstractOperation { + private final TypesEndpoint typesEndpoint; private final IOseeCachingService cacheService; private final URI model; + private final boolean refreshCaches; - public OseeTypesImportOperation(IOseeCachingService cacheService, URI model) { + public OseeTypesImportOperation(TypesEndpoint typesEndpoint, IOseeCachingService cacheService, URI model, boolean refreshCaches) { super("Import Osee Types Model", Activator.PLUGIN_ID); + this.typesEndpoint = typesEndpoint; this.cacheService = cacheService; this.model = model; + this.refreshCaches = refreshCaches; } - private String getModel(URL url) throws IOException { + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { InputStream inputStream = null; try { - inputStream = new BufferedInputStream(url.openStream()); - return Lib.inputStreamToString(inputStream); + inputStream = model.toURL().openStream(); + Response response = typesEndpoint.setTypes(inputStream); + if (Status.OK.getStatusCode() == response.getStatus()) { + if (refreshCaches) { + cacheService.reloadTypes(); + } + } + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); } finally { Lib.close(inputStream); } } - - private String getName(URI uri) { - String name = uri.toASCIIString(); - int index = name.lastIndexOf("/"); - if (index > 0) { - name = name.substring(index + 1, name.length()); - } - return name; - } - - @Override - protected void doWork(IProgressMonitor monitor) throws Exception { - Map<String, String> parameters = new HashMap<String, String>(); - - OseeImportModelRequest modelRequest = - new OseeImportModelRequest(getName(model), getModel(model.toURL()), false, false); - - OseeImportModelResponse response = - HttpClientMessage.send(OseeServerContext.OSEE_MODEL_CONTEXT, parameters, - CoreTranslatorId.OSEE_IMPORT_MODEL_REQUEST, modelRequest, CoreTranslatorId.OSEE_IMPORT_MODEL_RESPONSE); - - if (response.wasPersisted()) { - cacheService.getEnumTypeCache().reloadCache(); - cacheService.getAttributeTypeCache().reloadCache(); - cacheService.getArtifactTypeCache().reloadCache(); - cacheService.getRelationTypeCache().reloadCache(); - } - - } - } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ServiceUtil.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ServiceUtil.java index 75bb75a15e7..93444d6f036 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ServiceUtil.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ServiceUtil.java @@ -15,9 +15,7 @@ import java.util.logging.Level; import org.eclipse.core.runtime.Platform; import org.eclipse.osee.cache.admin.CacheAdmin; import org.eclipse.osee.framework.core.client.ClientSessionManager; -import org.eclipse.osee.framework.core.model.TransactionRecordFactory; import org.eclipse.osee.framework.core.services.IOseeCachingService; -import org.eclipse.osee.framework.core.services.IOseeModelFactoryService; import org.eclipse.osee.framework.core.translation.IDataTranslationService; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; @@ -71,11 +69,6 @@ public final class ServiceUtil { return getService(IDataTranslationService.class); } - public static TransactionRecordFactory getTransactionFactory() throws OseeCoreException { - IOseeModelFactoryService service = getService(IOseeModelFactoryService.class); - return service != null ? service.getTransactionFactory() : null; - } - public static AttributeAdapterService getAttributeAdapterService() throws OseeCoreException { return getService(AttributeAdapterService.class); } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/AbstractClientDataAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/AbstractClientDataAccessor.java deleted file mode 100644 index d21b86ac537..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/AbstractClientDataAccessor.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * 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.skynet.core.internal.accessors; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import org.eclipse.osee.framework.core.data.OseeServerContext; -import org.eclipse.osee.framework.core.enums.CacheOperation; -import org.eclipse.osee.framework.core.enums.CoreTranslatorId; -import org.eclipse.osee.framework.core.message.CacheUpdateRequest; -import org.eclipse.osee.framework.core.model.IOseeStorable; -import org.eclipse.osee.framework.core.model.cache.IOseeCache; -import org.eclipse.osee.framework.core.model.cache.IOseeDataAccessor; -import org.eclipse.osee.framework.core.translation.ITranslatorId; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.skynet.core.artifact.HttpClientMessage; - -/** - * @author Roberto E. Escobar - */ -public abstract class AbstractClientDataAccessor<K, T extends IOseeStorable> implements IOseeDataAccessor<K, T> { - - protected AbstractClientDataAccessor() { - // Hide default constructor - } - - @Override - public void load(IOseeCache<K, T> cache) throws OseeCoreException { - Collection<T> updatedItems = updateCache(cache); - for (T item : updatedItems) { - item.clearDirty(); - } - } - - @Override - public void store(Collection<T> types) throws OseeCoreException { - //do nothing - } - - protected <J> J requestUpdateMessage(IOseeCache<K, T> cache, ITranslatorId txId) throws OseeCoreException { - CacheUpdateRequest updateRequest = new CacheUpdateRequest(cache.getCacheId()); - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("function", CacheOperation.UPDATE.name()); - - return HttpClientMessage.send(OseeServerContext.CACHE_CONTEXT, parameters, - CoreTranslatorId.OSEE_CACHE_UPDATE_REQUEST, updateRequest, txId); - } - - protected abstract Collection<T> updateCache(IOseeCache<K, T> cache) throws OseeCoreException; -} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientArtifactTypeAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientArtifactTypeAccessor.java deleted file mode 100644 index d7bb717c9ed..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientArtifactTypeAccessor.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.skynet.core.internal.accessors; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; -import org.eclipse.osee.framework.core.data.IOseeBranch; -import org.eclipse.osee.framework.core.data.TokenFactory; -import org.eclipse.osee.framework.core.enums.CoreTranslatorId; -import org.eclipse.osee.framework.core.message.ArtifactTypeCacheUpdateResponse; -import org.eclipse.osee.framework.core.message.ArtifactTypeCacheUpdateResponse.ArtifactTypeRow; -import org.eclipse.osee.framework.core.model.Branch; -import org.eclipse.osee.framework.core.model.cache.AbstractOseeCache; -import org.eclipse.osee.framework.core.model.cache.IOseeCache; -import org.eclipse.osee.framework.core.model.type.ArtifactType; -import org.eclipse.osee.framework.core.model.type.ArtifactTypeFactory; -import org.eclipse.osee.framework.core.model.type.AttributeType; -import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.type.Pair; -import org.eclipse.osee.framework.jdk.core.type.Triplet; - -/** - * @author Roberto E. Escobar - */ -public class ClientArtifactTypeAccessor extends AbstractClientDataAccessor<Long, ArtifactType> { - - private final AbstractOseeCache<Long, AttributeType> attrCache; - private final AbstractOseeCache<Long, Branch> branchCache; - - private final ArtifactTypeFactory artifactTypeFactory; - - public ClientArtifactTypeAccessor(ArtifactTypeFactory artifactTypeFactory, AbstractOseeCache<Long, AttributeType> attrCache, AbstractOseeCache<Long, Branch> branchCache) { - this.artifactTypeFactory = artifactTypeFactory; - this.attrCache = attrCache; - this.branchCache = branchCache; - } - - private ArtifactTypeFactory getFactory() { - return artifactTypeFactory; - } - - @Override - public void load(IOseeCache<Long, ArtifactType> cache) throws OseeCoreException { - attrCache.ensurePopulated(); - branchCache.ensurePopulated(); - super.load(cache); - } - - @Override - protected Collection<ArtifactType> updateCache(IOseeCache<Long, ArtifactType> cache) throws OseeCoreException { - List<ArtifactType> updatedItems = new ArrayList<ArtifactType>(); - - ArtifactTypeCacheUpdateResponse response = - requestUpdateMessage(cache, CoreTranslatorId.ARTIFACT_TYPE_CACHE_UPDATE_RESPONSE); - - ArtifactTypeFactory factory = getFactory(); - for (ArtifactTypeRow row : response.getArtTypeRows()) { - ArtifactType cached = - factory.createOrUpdate(cache, row.getId(), row.getStorageState(), row.getGuid(), row.isAbstract(), - row.getName()); - updatedItems.add(cached); - } - - for (Entry<Long, Long[]> entry : response.getBaseToSuperTypes().entrySet()) { - ArtifactType baseType = cache.getById(entry.getKey()); - Set<ArtifactType> superTypes = new HashSet<ArtifactType>(); - for (Long superId : entry.getValue()) { - ArtifactType superType = cache.getById(superId); - if (superType != null) { - superTypes.add(superType); - } - } - baseType.setSuperTypes(superTypes); - } - - CompositeKeyHashMap<ArtifactType, IOseeBranch, Collection<AttributeType>> attrs = - new CompositeKeyHashMap<ArtifactType, IOseeBranch, Collection<AttributeType>>(); - - for (Triplet<Long, Long, Long> entry : response.getAttributeTypes()) { - ArtifactType key1 = cache.getByGuid(entry.getFirst()); - Long branchUuid = entry.getSecond(); - IOseeBranch branchToken = branchCache.getByGuid(branchUuid); - if (branchToken == null) { - branchToken = TokenFactory.createBranch(branchUuid, String.valueOf(branchUuid)); - } - Collection<AttributeType> types = attrs.get(key1, branchToken); - if (types == null) { - types = new HashSet<AttributeType>(); - attrs.put(key1, branchToken, types); - } - types.add(attrCache.getByGuid(entry.getThird())); - } - - for (Entry<Pair<ArtifactType, IOseeBranch>, Collection<AttributeType>> entry : attrs.entrySet()) { - ArtifactType type = entry.getKey().getFirst(); - IOseeBranch branch = entry.getKey().getSecond(); - Collection<AttributeType> attrTypes = entry.getValue(); - type.setAttributeTypes(attrTypes, branch); - } - return updatedItems; - } -} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientAttributeTypeAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientAttributeTypeAccessor.java deleted file mode 100644 index f5242a78a70..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientAttributeTypeAccessor.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.skynet.core.internal.accessors; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.eclipse.osee.framework.core.enums.CoreTranslatorId; -import org.eclipse.osee.framework.core.message.AttributeTypeCacheUpdateResponse; -import org.eclipse.osee.framework.core.model.cache.AbstractOseeCache; -import org.eclipse.osee.framework.core.model.cache.IOseeCache; -import org.eclipse.osee.framework.core.model.type.AttributeType; -import org.eclipse.osee.framework.core.model.type.AttributeTypeFactory; -import org.eclipse.osee.framework.core.model.type.OseeEnumType; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; - -/** - * @author Roberto E. Escobar - */ -public class ClientAttributeTypeAccessor extends AbstractClientDataAccessor<Long, AttributeType> { - - private final AbstractOseeCache<Long, OseeEnumType> enumCache; - private final AttributeTypeFactory attributeTypeFactory; - - public ClientAttributeTypeAccessor(AttributeTypeFactory attributeTypeFactory, AbstractOseeCache<Long, OseeEnumType> enumCache) { - super(); - this.attributeTypeFactory = attributeTypeFactory; - this.enumCache = enumCache; - } - - private AttributeTypeFactory getFactory() { - return attributeTypeFactory; - } - - @Override - public void load(IOseeCache<Long, AttributeType> cache) throws OseeCoreException { - enumCache.ensurePopulated(); - super.load(cache); - } - - @Override - protected Collection<AttributeType> updateCache(IOseeCache<Long, AttributeType> cache) throws OseeCoreException { - List<AttributeType> updatedItems = new ArrayList<AttributeType>(); - - AttributeTypeCacheUpdateResponse response = - requestUpdateMessage(cache, CoreTranslatorId.ATTRIBUTE_TYPE_CACHE_UPDATE_RESPONSE); - - Map<Long, Long> attrToEnums = response.getAttrToEnums(); - AttributeTypeFactory factory = getFactory(); - for (AttributeType row : response.getAttrTypeRows()) { - long uniqueId = row.getId(); - OseeEnumType oseeEnumType = null; - Long enumId = attrToEnums.get(uniqueId); - if (enumId != null) { - oseeEnumType = enumCache.getById(enumId); - } - factory.createOrUpdate(cache, row.getId(), row.getStorageState(), row.getGuid(), row.getName(), - row.getBaseAttributeTypeId(), row.getAttributeProviderId(), row.getFileTypeExtension(), - row.getDefaultValue(), oseeEnumType, row.getMinOccurrences(), row.getMaxOccurrences(), - row.getDescription(), row.getTaggerId(), row.getMediaType()); - } - return updatedItems; - } -} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientOseeEnumTypeAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientOseeEnumTypeAccessor.java deleted file mode 100644 index 7f9e500a3d0..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientOseeEnumTypeAccessor.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.skynet.core.internal.accessors; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import org.eclipse.osee.framework.core.enums.CoreTranslatorId; -import org.eclipse.osee.framework.core.enums.StorageState; -import org.eclipse.osee.framework.core.message.OseeEnumTypeCacheUpdateResponse; -import org.eclipse.osee.framework.core.model.cache.IOseeCache; -import org.eclipse.osee.framework.core.model.type.OseeEnumType; -import org.eclipse.osee.framework.core.model.type.OseeEnumTypeFactory; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; - -/** - * @author Roberto E. Escobar - */ -public class ClientOseeEnumTypeAccessor extends AbstractClientDataAccessor<Long, OseeEnumType> { - - private final OseeEnumTypeFactory enumTypeFactory; - - public ClientOseeEnumTypeAccessor(OseeEnumTypeFactory enumTypeFactory) { - super(); - this.enumTypeFactory = enumTypeFactory; - } - - private OseeEnumTypeFactory getFactory() { - return enumTypeFactory; - } - - @Override - protected Collection<OseeEnumType> updateCache(IOseeCache<Long, OseeEnumType> cache) throws OseeCoreException { - List<OseeEnumType> enumTypes = new ArrayList<OseeEnumType>(); - OseeEnumTypeCacheUpdateResponse response = - requestUpdateMessage(cache, CoreTranslatorId.OSEE_ENUM_TYPE_CACHE_UPDATE_RESPONSE); - - OseeEnumTypeFactory factory = getFactory(); - - for (String[] enumTypeRow : response.getEnumTypeRows()) { - enumTypes.add(factory.createOrUpdate(cache, Long.parseLong(enumTypeRow[0]), - StorageState.valueOf(enumTypeRow[1]), Long.valueOf(enumTypeRow[2]), enumTypeRow[3])); - } - - for (String[] enumEntryRow : response.getEnumEntryRows()) { - factory.createOrUpdate(cache, Long.valueOf(enumEntryRow[0]), enumEntryRow[1], - Integer.parseInt(enumEntryRow[2]), enumEntryRow[3]); - } - return enumTypes; - } -} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientRelationTypeAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientRelationTypeAccessor.java deleted file mode 100644 index 815424e9e82..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientRelationTypeAccessor.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.skynet.core.internal.accessors; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import org.eclipse.osee.framework.core.data.IArtifactType; -import org.eclipse.osee.framework.core.enums.CoreTranslatorId; -import org.eclipse.osee.framework.core.message.RelationTypeCacheUpdateResponse; -import org.eclipse.osee.framework.core.message.RelationTypeCacheUpdateResponse.RelationTypeRow; -import org.eclipse.osee.framework.core.model.cache.AbstractOseeCache; -import org.eclipse.osee.framework.core.model.cache.IOseeCache; -import org.eclipse.osee.framework.core.model.type.ArtifactType; -import org.eclipse.osee.framework.core.model.type.RelationType; -import org.eclipse.osee.framework.core.model.type.RelationTypeFactory; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; - -/** - * @author Roberto E. Escobar - */ -public class ClientRelationTypeAccessor extends AbstractClientDataAccessor<Long, RelationType> { - - private final AbstractOseeCache<Long, ArtifactType> artCache; - private final RelationTypeFactory relationTypeFactory; - - public ClientRelationTypeAccessor(RelationTypeFactory relationTypeFactory, AbstractOseeCache<Long, ArtifactType> artCache) { - super(); - this.relationTypeFactory = relationTypeFactory; - this.artCache = artCache; - } - - private RelationTypeFactory getFactory() { - return relationTypeFactory; - } - - @Override - public void load(IOseeCache<Long, RelationType> cache) throws OseeCoreException { - artCache.ensurePopulated(); - super.load(cache); - } - - @Override - protected Collection<RelationType> updateCache(IOseeCache<Long, RelationType> cache) throws OseeCoreException { - List<RelationType> updatedItems = new ArrayList<RelationType>(); - - RelationTypeCacheUpdateResponse response = - requestUpdateMessage(cache, CoreTranslatorId.RELATION_TYPE_CACHE_UPDATE_RESPONSE); - - RelationTypeFactory factory = getFactory(); - for (RelationTypeRow row : response.getRelationTypeRows()) { - IArtifactType aSideType = artCache.getById(row.getArtifactTypeSideA()); - IArtifactType bSideType = artCache.getById(row.getArtifactTypeSideB()); - - RelationType type = - factory.createOrUpdate(cache, row.getId(), row.getStorageState(), row.getGuid(), row.getName(), - row.getSideAName(), row.getSideBName(), aSideType, bSideType, row.getMultiplicity(), - row.getDefaultOrderTypeGuid()); - updatedItems.add(type); - } - return updatedItems; - } -} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeManager.java index 83d360ace0a..60d45874d99 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeManager.java @@ -84,7 +84,7 @@ public class RelationTypeManager { public static RelationType getTypeByGuid(Long guid) throws OseeCoreException { RelationType relationType = getCache().getByGuid(guid); if (relationType == null) { - getCache().reloadCache(); + getCacheService().reloadTypes(); relationType = getCache().getByGuid(guid); if (relationType == null) { throw new OseeTypeDoesNotExist("The relation with type guid [%s] does not exist", guid); @@ -109,7 +109,4 @@ public class RelationTypeManager { return !getCache().getByName(name).isEmpty(); } - public static void persist() throws OseeCoreException { - getCache().storeAllModified(); - } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java index 902c76165e2..24058f62f37 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java @@ -67,6 +67,8 @@ public final class TransactionManager { private static final String SELECT_BRANCH_TRANSACTION_BY_DATE = "SELECT * FROM osee_tx_details WHERE branch_id = ? AND time < ? ORDER BY time DESC"; + private static final TransactionRecordFactory factory = new TransactionRecordFactory(); + private static final HashMap<Integer, List<TransactionRecord>> commitArtifactIdMap = new HashMap<Integer, List<TransactionRecord>>(); @@ -197,7 +199,6 @@ public final class TransactionManager { int authorArtId = userToBlame.getArtId(); TransactionDetailsType txType = TransactionDetailsType.NonBaselined; Date transactionTime = GlobalTime.GreenwichMeanTimestamp(); - TransactionRecordFactory factory = ServiceUtil.getTransactionFactory(); TransactionRecord transactionId = factory.createOrUpdate(getTransactionCache(), transactionNumber, branch.getUuid(), comment, transactionTime, authorArtId, 0, txType, getBranchCache()); @@ -268,9 +269,7 @@ public final class TransactionManager { } TransactionDetailsType txType = TransactionDetailsType.toEnum(chStmt.getInt("tx_type")); - TransactionRecordFactory factory = ServiceUtil.getTransactionFactory(); BranchCache branchCache = getBranchCache(); - transactionRecord = factory.createOrUpdate(txCache, txId, chStmt.getLong("branch_id"), chStmt.getString("osee_comment"), chStmt.getTimestamp("time"), chStmt.getInt("author"), chStmt.getInt("commit_art_id"), txType, diff --git a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/renderer/RelationOrderRendererTest.java b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/renderer/RelationOrderRendererTest.java index 0de9375107d..3e9a44a9ad4 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/renderer/RelationOrderRendererTest.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/renderer/RelationOrderRendererTest.java @@ -50,8 +50,7 @@ public class RelationOrderRendererTest { public static void prepareTest() throws Exception { MockArtifactGuidResolver resolver = new MockArtifactGuidResolver(null); - AbstractOseeCache<Long, RelationType> typeCache = - new RelationTypeCache(new MockOseeDataAccessor<Long, RelationType>()); + AbstractOseeCache<Long, RelationType> typeCache = new RelationTypeCache(); addRelationTypeData(typeCache); sorterProvider = new RelationSorterProvider(); renderer = new RelationOrderRenderer(typeCache, resolver, sorterProvider); @@ -189,7 +188,7 @@ public class RelationOrderRendererTest { } private final static void addRelationTypeData(AbstractOseeCache<Long, RelationType> cache) throws OseeCoreException { - ArtifactTypeCache artCache = new ArtifactTypeCache(new MockOseeDataAccessor<Long, ArtifactType>()); + ArtifactTypeCache artCache = new ArtifactTypeCache(); IArtifactType artifactType1 = createArtifactType(artCache, "Artifact 2"); IArtifactType artifactType2 = createArtifactType(artCache, "Artifact 1"); |