From 727be9a143d157ef3a90feed01b5d86a2c9bf0f9 Mon Sep 17 00:00:00 2001 From: rescobar Date: Thu, 5 Aug 2010 03:44:24 +0000 Subject: "Team Workflow" - YGHW1 - "Block changes to requirements unless done under an appropriate action." --- .../test/AllDslIntegrationTestSuite.java | 4 +- .../core/dsl/integration/test/ModelUtilTest.java | 94 ---------- .../core/dsl/integration/test/OseeUtilTest.java | 204 --------------------- .../dsl/integration/test/mocks/DslAsserts.java | 29 ++- .../core/dsl/integration/test/testAccessModel.osee | 62 ------- .../core/dsl/integration/test/testTypeModel.osee | 60 ------ .../integration/test/util/DslUtilTestSuite.java | 26 +++ .../dsl/integration/test/util/ModelUtilTest.java | 88 +++++++++ .../dsl/integration/test/util/OseeUtilTest.java | 204 +++++++++++++++++++++ .../dsl/integration/test/util/testAccessModel.osee | 60 ++++++ .../dsl/integration/test/util/testTypeModel.osee | 60 ++++++ .../META-INF/MANIFEST.MF | 3 +- .../framework/core/dsl/integration/ModelUtil.java | 191 ------------------- .../core/dsl/integration/OseeToXtextOperation.java | 1 + .../framework/core/dsl/integration/OseeUtil.java | 113 ------------ .../dsl/integration/XTextToOseeTypeOperation.java | 1 + .../ArtifactInstanceRestrictionHandler.java | 2 +- .../internal/ArtifactTypeRestrictionHandler.java | 2 +- .../internal/AttributeTypeRestrictionHandler.java | 2 +- .../internal/OseeModelingServiceImpl.java | 4 +- .../internal/RelationTypeRestrictionHandler.java | 2 +- .../core/dsl/integration/util/ModelUtil.java | 130 +++++++++++++ .../core/dsl/integration/util/OseeUtil.java | 113 ++++++++++++ .../META-INF/MANIFEST.MF | 1 + .../operations/OseeTypesImportOperation.java | 2 +- .../core/model/test/AllCoreModelTestSuite.java | 10 +- .../core/model/test/access/AccessDetailTest.java | 120 ++++++++++++ .../model/test/access/AccessFilterChainTest.java | 103 ----------- .../core/model/test/access/AccessTestSuite.java | 28 +++ .../model/test/access/PermissionStatusTest.java | 10 +- .../core/model/test/access/PermissionTest.java | 33 ---- .../test/access/exp/AccessFilterChainTest.java | 103 +++++++++++ .../core/model/test/cache/CacheTestSuite.java | 2 +- .../core/model/test/fields/FieldTestSuite.java | 2 +- .../core/model/test/mocks/MockDataFactory.java | 12 ++ .../core/model/test/type/ModelTestSuite.java | 30 --- .../core/model/test/type/TypeTestSuite.java | 30 +++ .../framework/core/model/access/AccessDetail.java | 17 +- .../core/model/access/AccessFilterFactory.java | 35 ---- .../core/model/access/ArtifactTypeFilter.java | 54 ------ .../core/model/access/AttributeTypeFilter.java | 53 ------ .../framework/core/model/access/IAcceptFilter.java | 25 --- .../core/model/access/PermissionStatus.java | 9 +- .../core/model/access/exp/AccessFilterFactory.java | 34 ++++ .../core/model/access/exp/ArtifactTypeFilter.java | 54 ++++++ .../core/model/access/exp/AttributeTypeFilter.java | 53 ++++++ .../core/model/access/exp/IAcceptFilter.java | 25 +++ 47 files changed, 1219 insertions(+), 1081 deletions(-) delete mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/ModelUtilTest.java delete mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/OseeUtilTest.java delete mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/testAccessModel.osee delete mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/testTypeModel.osee create mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/DslUtilTestSuite.java create mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/ModelUtilTest.java create mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/OseeUtilTest.java create mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/testAccessModel.osee create mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/testTypeModel.osee delete mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/ModelUtil.java delete mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/OseeUtil.java create mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtil.java create mode 100644 plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/OseeUtil.java create mode 100644 plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessDetailTest.java delete mode 100644 plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessFilterChainTest.java create mode 100644 plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessTestSuite.java delete mode 100644 plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/PermissionTest.java create mode 100644 plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/exp/AccessFilterChainTest.java delete mode 100644 plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/type/ModelTestSuite.java create mode 100644 plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/type/TypeTestSuite.java delete mode 100644 plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AccessFilterFactory.java delete mode 100644 plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/ArtifactTypeFilter.java delete mode 100644 plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AttributeTypeFilter.java delete mode 100644 plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/IAcceptFilter.java create mode 100644 plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/AccessFilterFactory.java create mode 100644 plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/ArtifactTypeFilter.java create mode 100644 plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/AttributeTypeFilter.java create mode 100644 plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/IAcceptFilter.java (limited to 'plugins') diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/AllDslIntegrationTestSuite.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/AllDslIntegrationTestSuite.java index 3398de3c38b..5cf50cb66b7 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/AllDslIntegrationTestSuite.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/AllDslIntegrationTestSuite.java @@ -11,6 +11,7 @@ package org.eclipse.osee.framework.core.dsl.integration.test; import org.eclipse.osee.framework.core.dsl.integration.test.internal.InternalTestSuite; +import org.eclipse.osee.framework.core.dsl.integration.test.util.DslUtilTestSuite; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -20,8 +21,7 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ // InternalTestSuite.class, // - ModelUtilTest.class, // - OseeUtilTest.class, // + DslUtilTestSuite.class, // }) public class AllDslIntegrationTestSuite { // Test Suite diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/ModelUtilTest.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/ModelUtilTest.java deleted file mode 100644 index 385e2d66314..00000000000 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/ModelUtilTest.java +++ /dev/null @@ -1,94 +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.dsl.integration.test; - -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import org.eclipse.osee.framework.core.dsl.integration.ModelUtil; -import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.util.Lib; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Test Case for {@link ModelUtil} - * - * @author Roberto E. Escobar - */ -public class ModelUtilTest { - - private static final String TYPE_TEST_INPUT = "testTypeModel.osee"; - private static final String ACCESS_TEST_INPUT = "testAccessModel.osee"; - - private String getRawXTextData(String testInputFile) throws IOException { - InputStream inputStream = null; - try { - inputStream = new BufferedInputStream(this.getClass().getResourceAsStream(testInputFile)); - return Lib.inputStreamToString(inputStream); - } finally { - Lib.close(inputStream); - } - } - - @Test - public void testModelUtilLoadType() throws OseeCoreException, IOException { - String rawXTextData = getRawXTextData(TYPE_TEST_INPUT); - - OseeDsl model1 = ModelUtil.loadModel("osee:/text.osee", rawXTextData); - Assert.assertEquals(5, model1.getArtifactTypes().size()); - Assert.assertEquals(3, model1.getAttributeTypes().size()); - Assert.assertEquals(1, model1.getRelationTypes().size()); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ModelUtil.saveModel(model1, "osee:/text.osee", outputStream, false); - outputStream.flush(); - String value = outputStream.toString("UTF-8"); - - OseeDsl model2 = ModelUtil.loadModel("osee:/text2.osee", value); - - Assert.assertEquals(model1.getArtifactTypes().size(), model2.getArtifactTypes().size()); - Assert.assertEquals(model1.getAttributeTypes().size(), model2.getAttributeTypes().size()); - Assert.assertEquals(model1.getRelationTypes().size(), model2.getRelationTypes().size()); - Assert.assertEquals(model1.getImports().size(), model2.getImports().size()); - Assert.assertEquals(model1.getEnumOverrides().size(), model2.getEnumOverrides().size()); - Assert.assertEquals(model1.getEnumTypes().size(), model2.getEnumTypes().size()); - } - - @Ignore - @Test - public void testModelUtilLoadAccess() throws OseeCoreException, IOException { - String rawXTextData = getRawXTextData(ACCESS_TEST_INPUT); - - OseeDsl model1 = ModelUtil.loadModel("osee:/text.osee", rawXTextData); - Assert.assertEquals(5, model1.getArtifactTypes().size()); - Assert.assertEquals(3, model1.getAttributeTypes().size()); - Assert.assertEquals(1, model1.getRelationTypes().size()); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ModelUtil.saveModel(model1, "osee:/text.osee", outputStream, false); - outputStream.flush(); - String value = outputStream.toString("UTF-8"); - - OseeDsl model2 = ModelUtil.loadModel("osee:/text2.osee", value); - - Assert.assertEquals(model1.getArtifactTypes().size(), model2.getArtifactTypes().size()); - Assert.assertEquals(model1.getAttributeTypes().size(), model2.getAttributeTypes().size()); - Assert.assertEquals(model1.getRelationTypes().size(), model2.getRelationTypes().size()); - Assert.assertEquals(model1.getImports().size(), model2.getImports().size()); - Assert.assertEquals(model1.getEnumOverrides().size(), model2.getEnumOverrides().size()); - Assert.assertEquals(model1.getEnumTypes().size(), model2.getEnumTypes().size()); - } - -} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/OseeUtilTest.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/OseeUtilTest.java deleted file mode 100644 index 7abd343a4bb..00000000000 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/OseeUtilTest.java +++ /dev/null @@ -1,204 +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.dsl.integration.test; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import junit.framework.Assert; -import org.eclipse.osee.framework.core.data.IArtifactType; -import org.eclipse.osee.framework.core.data.IAttributeType; -import org.eclipse.osee.framework.core.data.IRelationType; -import org.eclipse.osee.framework.core.data.Identity; -import org.eclipse.osee.framework.core.dsl.integration.OseeUtil; -import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessPermissionEnum; -import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction; -import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDslFactory; -import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeType; -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.XRelationSideEnum; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; -import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; -import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; -import org.eclipse.osee.framework.core.enums.CoreRelationTypes; -import org.eclipse.osee.framework.core.enums.PermissionEnum; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; -import org.eclipse.osee.framework.core.enums.RelationSide; -import org.eclipse.osee.framework.core.exception.OseeArgumentException; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.junit.Test; - -/** - * Test Case for {@link OseeUtil} - * - * @author Roberto E. Escobar - */ -public class OseeUtilTest { - - @Test - public void testIsSideRestricted() throws OseeCoreException { - checkIsRestricted(XRelationSideEnum.BOTH, true, true); - checkIsRestricted(XRelationSideEnum.SIDE_A, true, false); - checkIsRestricted(XRelationSideEnum.SIDE_B, false, true); - } - - @Test(expected = OseeArgumentException.class) - public void testIsSideRestrictionXRelationSideEnumNullCheck() throws OseeCoreException { - OseeUtil.isRestrictedSide(null, RelationSide.SIDE_A); - } - - @Test(expected = OseeArgumentException.class) - public void testIsSideRestrictionRelationSideNullCheck() throws OseeCoreException { - OseeUtil.isRestrictedSide(XRelationSideEnum.BOTH, null); - } - - @Test - public void testGetPermission() throws OseeCoreException { - ObjectRestriction restriction = OseeDslFactory.eINSTANCE.createObjectRestriction(); - restriction.setPermission(AccessPermissionEnum.ALLOW); - Assert.assertEquals(AccessPermissionEnum.ALLOW, restriction.getPermission()); - - PermissionEnum expectedEnum = PermissionEnum.WRITE; - PermissionEnum actualEnum = OseeUtil.getPermission(restriction); - Assert.assertEquals(expectedEnum, actualEnum); - - restriction.setPermission(AccessPermissionEnum.DENY); - Assert.assertEquals(AccessPermissionEnum.DENY, restriction.getPermission()); - expectedEnum = PermissionEnum.READ; - actualEnum = OseeUtil.getPermission(restriction); - Assert.assertEquals(expectedEnum, actualEnum); - } - - @Test - public void testToTokenArtifactType() { - XArtifactType type = OseeDslFactory.eINSTANCE.createXArtifactType(); - IArtifactType expected = CoreArtifactTypes.GlobalPreferences; - - setupToToken(type, expected); - - Object actual = OseeUtil.toToken(type); - Assert.assertEquals(expected, actual); - - type.setTypeGuid("x"); - actual = OseeUtil.toToken(type); - Assert.assertFalse(expected.equals(actual)); - } - - @Test - public void testToTokenAttributeType() { - XAttributeType type = OseeDslFactory.eINSTANCE.createXAttributeType(); - IAttributeType expected = CoreAttributeTypes.Description; - - setupToToken(type, expected); - - Object actual = OseeUtil.toToken(type); - Assert.assertEquals(expected, actual); - - type.setTypeGuid("x"); - actual = OseeUtil.toToken(type); - Assert.assertFalse(expected.equals(actual)); - } - - @Test - public void testToTokenRelationType() { - XRelationType type = OseeDslFactory.eINSTANCE.createXRelationType(); - IRelationType expected = CoreRelationTypes.Allocation__Component; - - setupToToken(type, expected); - - Object actual = OseeUtil.toToken(type); - Assert.assertEquals(expected, actual); - - type.setTypeGuid("x"); - actual = OseeUtil.toToken(type); - Assert.assertFalse(expected.equals(actual)); - } - - @Test(expected = OseeArgumentException.class) - public void testGetRelationOrderTypeNullCheck() throws OseeCoreException { - OseeUtil.getRelationOrderType(null); - } - - @Test(expected = OseeArgumentException.class) - public void testGetRelationOrderTypeEmptyCheck() throws OseeCoreException { - OseeUtil.getRelationOrderType(""); - } - - @Test(expected = OseeArgumentException.class) - public void testGetRelationOrderTypeNotFoundCheck() throws OseeCoreException { - OseeUtil.getRelationOrderType("a"); - } - - @Test - public void testGetRelationOrderType() throws OseeCoreException { - Map testData = new HashMap(); - testData.put(RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid(), "Lexicographical_Ascending"); - testData.put(RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC.getGuid(), "Lexicographical_Descending"); - testData.put(RelationOrderBaseTypes.UNORDERED.getGuid(), "Unordered"); - testData.put(RelationOrderBaseTypes.USER_DEFINED.getGuid(), "User_Defined"); - for (Entry entry : testData.entrySet()) { - String actualName = OseeUtil.getRelationOrderType(entry.getKey()); - String expectedName = entry.getValue(); - Assert.assertEquals(expectedName, actualName); - } - } - - @Test(expected = OseeArgumentException.class) - public void testOrderTypeNameToGuidNullCheck() throws OseeCoreException { - OseeUtil.orderTypeNameToGuid(null); - } - - @Test(expected = OseeArgumentException.class) - public void testOrderTypeNameToGuidEmptyCheck() throws OseeCoreException { - OseeUtil.orderTypeNameToGuid(""); - } - - @Test(expected = OseeArgumentException.class) - public void testOrderTypeNameToGuidNotFoundCheck() throws OseeCoreException { - OseeUtil.orderTypeNameToGuid("a"); - } - - @Test - public void testOrderTypeNameToGuid() throws OseeCoreException { - Map testData = new HashMap(); - testData.put("Lexicographical_Ascending", RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid()); - testData.put("Lexicographical_Descending", RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC.getGuid()); - testData.put("Unordered", RelationOrderBaseTypes.UNORDERED.getGuid()); - testData.put("User_Defined", RelationOrderBaseTypes.USER_DEFINED.getGuid()); - for (Entry entry : testData.entrySet()) { - String actualGuid = OseeUtil.orderTypeNameToGuid(entry.getKey()); - String expectedGuid = entry.getValue(); - Assert.assertEquals(expectedGuid, actualGuid); - } - } - - private static void setupToToken(OseeType typeToCheck, Identity expected) { - String name = "bogus name"; // This should not affect equality - String guid = expected.getGuid(); - typeToCheck.setName(name); - typeToCheck.setTypeGuid(guid); - - Assert.assertEquals(name, typeToCheck.getName()); - Assert.assertEquals(guid, typeToCheck.getTypeGuid()); - - } - - private static void checkIsRestricted(XRelationSideEnum side, boolean expectedSideA, boolean expectedSideB) throws OseeCoreException { - boolean actual = OseeUtil.isRestrictedSide(side, RelationSide.SIDE_A); - String message = String.format("[%s] - Side A error - expected[%s] actual[%s]", side, expectedSideA, actual); - Assert.assertEquals(message, expectedSideA, actual); - - actual = OseeUtil.isRestrictedSide(side, RelationSide.SIDE_B); - message = String.format("[%s] - Side B error - expected[%s] actual[%s]", side, expectedSideB, actual); - Assert.assertEquals(message, expectedSideB, actual); - } -} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/mocks/DslAsserts.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/mocks/DslAsserts.java index a33ed684193..dfd682c1829 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/mocks/DslAsserts.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/mocks/DslAsserts.java @@ -1,19 +1,28 @@ -/* - * Created on Aug 2, 2010 +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html * - * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE - */ + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ package org.eclipse.osee.framework.core.dsl.integration.test.mocks; import junit.framework.Assert; import org.eclipse.osee.framework.core.dsl.integration.ArtifactDataProvider.ArtifactData; import org.eclipse.osee.framework.core.dsl.integration.RestrictionHandler; import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; import org.eclipse.osee.framework.core.enums.PermissionEnum; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.model.access.AccessDetail; import org.eclipse.osee.framework.core.model.test.mocks.MockAccessDetailCollector; +/** + * @author Roberto E. Escobar + */ public final class DslAsserts { private DslAsserts() { @@ -36,4 +45,16 @@ public final class DslAsserts { Assert.assertEquals(expectedAccessObject, actualDetail.getAccessObject()); } } + + public static void assertEquals(OseeDsl model1, OseeDsl model2) { + Assert.assertEquals(model1.getAccessDeclarations().size(), model2.getAccessDeclarations().size()); + Assert.assertEquals(model1.getArtifactRefs().size(), model2.getArtifactRefs().size()); + Assert.assertEquals(model1.getArtifactTypes().size(), model2.getArtifactTypes().size()); + Assert.assertEquals(model1.getAttributeTypes().size(), model2.getAttributeTypes().size()); + Assert.assertEquals(model1.getBranchRefs().size(), model2.getBranchRefs().size()); + Assert.assertEquals(model1.getEnumOverrides().size(), model2.getEnumOverrides().size()); + Assert.assertEquals(model1.getEnumTypes().size(), model2.getEnumTypes().size()); + Assert.assertEquals(model1.getImports().size(), model2.getImports().size()); + Assert.assertEquals(model1.getRelationTypes().size(), model2.getRelationTypes().size()); + } } diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/testAccessModel.osee b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/testAccessModel.osee deleted file mode 100644 index aeef9db0441..00000000000 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/testAccessModel.osee +++ /dev/null @@ -1,62 +0,0 @@ -import "testTypeModel.osee" - -artifactType "Artifact" { - guid "BZOUrxO35x+LBZkEYzAA" -} - -artifactType "Software Requirement" extends "Artifact" { - guid "BZO4PuM+Oz58hpAcTGwA" -} - -attributeType "Qualification Method" extends StringAttribute { - guid "BZPB25t9fRVnLuII6+wA" - dataProvider DefaultAttributeDataProvider - min 0 - max 1 - defaultValue "test" -} - -artifact "Software Items" artGuid "AAMFEcWy0xc4e3tcem99"; -artifact "Systems" artGuid "AAMFEcWy0xc4e3tcem88"; -artifact "SubSystems" artGuid "AAMFEcWy0xc4e3tcem77"; - -// Access Contexts - -accessContext "System Context" { - guid "AAMFEcWy0xc4e3tcem11"; - DENY edit artifactType "Artifact"; - - childrenOf "Software Items" { - DENY edit artifactType "Artifact"; - } - - childrenOf "Systems" { - DENY edit artifactType "Artifact"; - } - - childrenOf "SubSystems" { - DENY edit artifactType "Artifact"; - } - -} - -accessContext "subsystem.requirement.writer" extends "System Context" { - guid "AAMFEcWy0xc4e3tcem22"; - DENY edit attributeType "Qualification Method" of artifactType "Software Requirement"; - - // ALLOW edit attributeType "Annotation" of artifactType "Software Requirement"; - ALLOW edit attributeType "Qualification Method" of artifactType "Software Requirement"; - ALLOW edit attributeType "Qualification Method" of artifactType "Software Requirement"; - - // childrenOf "SubSystem Requirement" { - // ALLOW edit artifactType "Artifact"; - // } - //} - // - //accessContext "software.requirement.writer" extends "System Context" { - // guid "AAMFEcWy0xc4e3tcem33"; - // childrenOf "SubSystem Requirement" { - // ALLOW edit artifactType "Artifact"; - // } - -} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/testTypeModel.osee b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/testTypeModel.osee deleted file mode 100644 index 318a7fb14e9..00000000000 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/testTypeModel.osee +++ /dev/null @@ -1,60 +0,0 @@ -artifactType "Artifact" { - guid "AAMFDh6S7gRLupAMwywA" - attribute "Name" - attribute "Annotation" -} - -abstract artifactType "Requirement" extends "Artifact" { - guid "BOm4NmAq+HC1O2hkMagA" - attribute "Qualification Method" -} - -artifactType "Software Requirement" extends "Requirement" { - guid "BOm+AIG2snNbAM5FFcwA" -} - -artifactType "System Requirement" extends "Requirement" { - guid "BOnAaYTBOG68_Tw5Y_AA" -} - -artifactType "SubSystem Requirement" extends "Requirement" { - guid "BOnBhJ1XAFGKcrku3LgA" -} - -attributeType "Name" extends StringAttribute { - guid "AAMFEcF1AzV7PKuHmxwA" - dataProvider DefaultAttributeDataProvider - min 1 - max 1 - taggerId DefaultAttributeTaggerProvider - description "Descriptive Name" - defaultValue "unnamed" -} - -attributeType "Annotation" extends StringAttribute { - guid "AAMFEcWy0xc4e3tcemQA" - dataProvider DefaultAttributeDataProvider - min 0 - max unlimited - taggerId DefaultAttributeTaggerProvider -} - -attributeType "Qualification Method" extends StringAttribute { - guid "BOk_ZLyYxyTYArzi63QA" - dataProvider DefaultAttributeDataProvider - min 0 - max unlimited - taggerId DefaultAttributeTaggerProvider -} - -relationType "Requirement" { - guid "BOkzi3U9VTe2fcUz_9gA" - sideAName "requirement-sideA" - sideAArtifactType "Requirement" - sideBName "subsystem-sideB" - sideBArtifactType "SubSystem Requirement" - defaultOrderType Lexicographical_Ascending - multiplicity ONE_TO_MANY -} - - diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/DslUtilTestSuite.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/DslUtilTestSuite.java new file mode 100644 index 00000000000..ea2ac7b258c --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/DslUtilTestSuite.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.integration.test.util; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * @author Roberto E. Escobar + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ // +ModelUtilTest.class, // + OseeUtilTest.class, // +}) +public class DslUtilTestSuite { + // Test Suite +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/ModelUtilTest.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/ModelUtilTest.java new file mode 100644 index 00000000000..6ca819d4683 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/ModelUtilTest.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * 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.dsl.integration.test.util; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import org.eclipse.osee.framework.core.dsl.integration.test.mocks.DslAsserts; +import org.eclipse.osee.framework.core.dsl.integration.util.ModelUtil; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test Case for {@link ModelUtil} + * + * @author Roberto E. Escobar + */ +public class ModelUtilTest { + + private static final String TYPE_TEST_INPUT = "testTypeModel.osee"; + private static final String ACCESS_TEST_INPUT = "testAccessModel.osee"; + + private String getRawXTextData(String testInputFile) throws IOException { + InputStream inputStream = null; + try { + inputStream = new BufferedInputStream(this.getClass().getResourceAsStream(testInputFile)); + return Lib.inputStreamToString(inputStream); + } finally { + Lib.close(inputStream); + } + } + + @Test + public void testModelUtilLoadType() throws OseeCoreException, IOException { + String rawXTextData = getRawXTextData(TYPE_TEST_INPUT); + + OseeDsl model1 = ModelUtil.loadModel("osee:/text.osee", rawXTextData); + Assert.assertEquals(5, model1.getArtifactTypes().size()); + Assert.assertEquals(3, model1.getAttributeTypes().size()); + Assert.assertEquals(1, model1.getRelationTypes().size()); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ModelUtil.saveModel(model1, "osee:/text.osee", outputStream, false); + outputStream.flush(); + String value = outputStream.toString("UTF-8"); + + OseeDsl model2 = ModelUtil.loadModel("osee:/text2.osee", value); + DslAsserts.assertEquals(model1, model2); + } + + @Test + public void testModelUtilLoadAccess() throws OseeCoreException, IOException { + String rawXTextData = getRawXTextData(ACCESS_TEST_INPUT); + + OseeDsl model1 = ModelUtil.loadModel("osee:/text.osee", rawXTextData); + Assert.assertEquals(2, model1.getArtifactTypes().size()); + Assert.assertEquals(1, model1.getAttributeTypes().size()); + Assert.assertEquals(0, model1.getRelationTypes().size()); + + Assert.assertEquals(3, model1.getArtifactRefs().size()); + Assert.assertEquals(2, model1.getAccessDeclarations().size()); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ModelUtil.saveModel(model1, "osee:/text.osee", outputStream, false); + outputStream.flush(); + String value = outputStream.toString("UTF-8"); + + OseeDsl model2 = ModelUtil.loadModel("osee:/text2.osee", value); + DslAsserts.assertEquals(model1, model2); + + // String modelRep = + // ModelUtil.modelToStringXText(model1, "osee:/text.osee", Collections. emptyMap()); + // OseeDsl model3 = ModelUtil.loadModel("osee:/text3.osee", modelRep); + // DslAsserts.assertEquals(model1, model3); + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/OseeUtilTest.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/OseeUtilTest.java new file mode 100644 index 00000000000..c1054f090ec --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/OseeUtilTest.java @@ -0,0 +1,204 @@ +/******************************************************************************* + * 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.dsl.integration.test.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import junit.framework.Assert; +import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.data.IRelationType; +import org.eclipse.osee.framework.core.data.Identity; +import org.eclipse.osee.framework.core.dsl.integration.util.OseeUtil; +import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessPermissionEnum; +import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDslFactory; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeType; +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.XRelationSideEnum; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.framework.core.enums.PermissionEnum; +import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; +import org.eclipse.osee.framework.core.enums.RelationSide; +import org.eclipse.osee.framework.core.exception.OseeArgumentException; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.junit.Test; + +/** + * Test Case for {@link OseeUtil} + * + * @author Roberto E. Escobar + */ +public class OseeUtilTest { + + @Test + public void testIsSideRestricted() throws OseeCoreException { + checkIsRestricted(XRelationSideEnum.BOTH, true, true); + checkIsRestricted(XRelationSideEnum.SIDE_A, true, false); + checkIsRestricted(XRelationSideEnum.SIDE_B, false, true); + } + + @Test(expected = OseeArgumentException.class) + public void testIsSideRestrictionXRelationSideEnumNullCheck() throws OseeCoreException { + OseeUtil.isRestrictedSide(null, RelationSide.SIDE_A); + } + + @Test(expected = OseeArgumentException.class) + public void testIsSideRestrictionRelationSideNullCheck() throws OseeCoreException { + OseeUtil.isRestrictedSide(XRelationSideEnum.BOTH, null); + } + + @Test + public void testGetPermission() throws OseeCoreException { + ObjectRestriction restriction = OseeDslFactory.eINSTANCE.createObjectRestriction(); + restriction.setPermission(AccessPermissionEnum.ALLOW); + Assert.assertEquals(AccessPermissionEnum.ALLOW, restriction.getPermission()); + + PermissionEnum expectedEnum = PermissionEnum.WRITE; + PermissionEnum actualEnum = OseeUtil.getPermission(restriction); + Assert.assertEquals(expectedEnum, actualEnum); + + restriction.setPermission(AccessPermissionEnum.DENY); + Assert.assertEquals(AccessPermissionEnum.DENY, restriction.getPermission()); + expectedEnum = PermissionEnum.READ; + actualEnum = OseeUtil.getPermission(restriction); + Assert.assertEquals(expectedEnum, actualEnum); + } + + @Test + public void testToTokenArtifactType() { + XArtifactType type = OseeDslFactory.eINSTANCE.createXArtifactType(); + IArtifactType expected = CoreArtifactTypes.GlobalPreferences; + + setupToToken(type, expected); + + Object actual = OseeUtil.toToken(type); + Assert.assertEquals(expected, actual); + + type.setTypeGuid("x"); + actual = OseeUtil.toToken(type); + Assert.assertFalse(expected.equals(actual)); + } + + @Test + public void testToTokenAttributeType() { + XAttributeType type = OseeDslFactory.eINSTANCE.createXAttributeType(); + IAttributeType expected = CoreAttributeTypes.Description; + + setupToToken(type, expected); + + Object actual = OseeUtil.toToken(type); + Assert.assertEquals(expected, actual); + + type.setTypeGuid("x"); + actual = OseeUtil.toToken(type); + Assert.assertFalse(expected.equals(actual)); + } + + @Test + public void testToTokenRelationType() { + XRelationType type = OseeDslFactory.eINSTANCE.createXRelationType(); + IRelationType expected = CoreRelationTypes.Allocation__Component; + + setupToToken(type, expected); + + Object actual = OseeUtil.toToken(type); + Assert.assertEquals(expected, actual); + + type.setTypeGuid("x"); + actual = OseeUtil.toToken(type); + Assert.assertFalse(expected.equals(actual)); + } + + @Test(expected = OseeArgumentException.class) + public void testGetRelationOrderTypeNullCheck() throws OseeCoreException { + OseeUtil.getRelationOrderType(null); + } + + @Test(expected = OseeArgumentException.class) + public void testGetRelationOrderTypeEmptyCheck() throws OseeCoreException { + OseeUtil.getRelationOrderType(""); + } + + @Test(expected = OseeArgumentException.class) + public void testGetRelationOrderTypeNotFoundCheck() throws OseeCoreException { + OseeUtil.getRelationOrderType("a"); + } + + @Test + public void testGetRelationOrderType() throws OseeCoreException { + Map testData = new HashMap(); + testData.put(RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid(), "Lexicographical_Ascending"); + testData.put(RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC.getGuid(), "Lexicographical_Descending"); + testData.put(RelationOrderBaseTypes.UNORDERED.getGuid(), "Unordered"); + testData.put(RelationOrderBaseTypes.USER_DEFINED.getGuid(), "User_Defined"); + for (Entry entry : testData.entrySet()) { + String actualName = OseeUtil.getRelationOrderType(entry.getKey()); + String expectedName = entry.getValue(); + Assert.assertEquals(expectedName, actualName); + } + } + + @Test(expected = OseeArgumentException.class) + public void testOrderTypeNameToGuidNullCheck() throws OseeCoreException { + OseeUtil.orderTypeNameToGuid(null); + } + + @Test(expected = OseeArgumentException.class) + public void testOrderTypeNameToGuidEmptyCheck() throws OseeCoreException { + OseeUtil.orderTypeNameToGuid(""); + } + + @Test(expected = OseeArgumentException.class) + public void testOrderTypeNameToGuidNotFoundCheck() throws OseeCoreException { + OseeUtil.orderTypeNameToGuid("a"); + } + + @Test + public void testOrderTypeNameToGuid() throws OseeCoreException { + Map testData = new HashMap(); + testData.put("Lexicographical_Ascending", RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid()); + testData.put("Lexicographical_Descending", RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC.getGuid()); + testData.put("Unordered", RelationOrderBaseTypes.UNORDERED.getGuid()); + testData.put("User_Defined", RelationOrderBaseTypes.USER_DEFINED.getGuid()); + for (Entry entry : testData.entrySet()) { + String actualGuid = OseeUtil.orderTypeNameToGuid(entry.getKey()); + String expectedGuid = entry.getValue(); + Assert.assertEquals(expectedGuid, actualGuid); + } + } + + private static void setupToToken(OseeType typeToCheck, Identity expected) { + String name = "bogus name"; // This should not affect equality + String guid = expected.getGuid(); + typeToCheck.setName(name); + typeToCheck.setTypeGuid(guid); + + Assert.assertEquals(name, typeToCheck.getName()); + Assert.assertEquals(guid, typeToCheck.getTypeGuid()); + + } + + private static void checkIsRestricted(XRelationSideEnum side, boolean expectedSideA, boolean expectedSideB) throws OseeCoreException { + boolean actual = OseeUtil.isRestrictedSide(side, RelationSide.SIDE_A); + String message = String.format("[%s] - Side A error - expected[%s] actual[%s]", side, expectedSideA, actual); + Assert.assertEquals(message, expectedSideA, actual); + + actual = OseeUtil.isRestrictedSide(side, RelationSide.SIDE_B); + message = String.format("[%s] - Side B error - expected[%s] actual[%s]", side, expectedSideB, actual); + Assert.assertEquals(message, expectedSideB, actual); + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/testAccessModel.osee b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/testAccessModel.osee new file mode 100644 index 00000000000..f859e264424 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/testAccessModel.osee @@ -0,0 +1,60 @@ +//import "platform:/org.eclipse.osee.framework.core.dsl.integration.test/testTypeModel.osee" +artifactType "Artifact" { + guid "BZOUrxO35x+LBZkEYzAA" +} + +artifactType "Software Requirement" extends "Artifact" { + guid "BZO4PuM+Oz58hpAcTGwA" +} + +attributeType "Qualification Method" extends StringAttribute { + guid "BZPB25t9fRVnLuII6+wA" + dataProvider DefaultAttributeDataProvider + min 0 + max 1 + defaultValue "test" +} + +artifact "Software Items" artGuid "AAMFEcWy0xc4e3tcem99"; +artifact "Systems" artGuid "AAMFEcWy0xc4e3tcem88"; +artifact "SubSystems" artGuid "AAMFEcWy0xc4e3tcem77"; + +// Access Contexts + +accessContext "System Context" { + guid "AAMFEcWy0xc4e3tcem11"; + DENY edit artifactType "Artifact"; + childrenOf "Software Items" { + DENY edit artifactType "Artifact"; + } + + childrenOf "Systems" { + DENY edit artifactType "Artifact"; + } + + childrenOf "SubSystems" { + DENY edit artifactType "Artifact"; + } + +} + +accessContext "subsystem.requirement.writer" extends "System Context" { + guid "AAMFEcWy0xc4e3tcem22"; + DENY edit attributeType "Qualification Method" of artifactType "Software Requirement"; + + // ALLOW edit attributeType "Annotation" of artifactType "Software Requirement"; + ALLOW edit attributeType "Qualification Method" of artifactType "Software Requirement"; + ALLOW edit attributeType "Qualification Method" of artifactType "Software Requirement"; + + // childrenOf "SubSystem Requirement" { + // ALLOW edit artifactType "Artifact"; + // } + //} + // + //accessContext "software.requirement.writer" extends "System Context" { + // guid "AAMFEcWy0xc4e3tcem33"; + // childrenOf "SubSystem Requirement" { + // ALLOW edit artifactType "Artifact"; + // } + +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/testTypeModel.osee b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/testTypeModel.osee new file mode 100644 index 00000000000..318a7fb14e9 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/test/util/testTypeModel.osee @@ -0,0 +1,60 @@ +artifactType "Artifact" { + guid "AAMFDh6S7gRLupAMwywA" + attribute "Name" + attribute "Annotation" +} + +abstract artifactType "Requirement" extends "Artifact" { + guid "BOm4NmAq+HC1O2hkMagA" + attribute "Qualification Method" +} + +artifactType "Software Requirement" extends "Requirement" { + guid "BOm+AIG2snNbAM5FFcwA" +} + +artifactType "System Requirement" extends "Requirement" { + guid "BOnAaYTBOG68_Tw5Y_AA" +} + +artifactType "SubSystem Requirement" extends "Requirement" { + guid "BOnBhJ1XAFGKcrku3LgA" +} + +attributeType "Name" extends StringAttribute { + guid "AAMFEcF1AzV7PKuHmxwA" + dataProvider DefaultAttributeDataProvider + min 1 + max 1 + taggerId DefaultAttributeTaggerProvider + description "Descriptive Name" + defaultValue "unnamed" +} + +attributeType "Annotation" extends StringAttribute { + guid "AAMFEcWy0xc4e3tcemQA" + dataProvider DefaultAttributeDataProvider + min 0 + max unlimited + taggerId DefaultAttributeTaggerProvider +} + +attributeType "Qualification Method" extends StringAttribute { + guid "BOk_ZLyYxyTYArzi63QA" + dataProvider DefaultAttributeDataProvider + min 0 + max unlimited + taggerId DefaultAttributeTaggerProvider +} + +relationType "Requirement" { + guid "BOkzi3U9VTe2fcUz_9gA" + sideAName "requirement-sideA" + sideAArtifactType "Requirement" + sideBName "subsystem-sideB" + sideBArtifactType "SubSystem Requirement" + defaultOrderType Lexicographical_Ascending + multiplicity ONE_TO_MANY +} + + diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.core.dsl.integration/META-INF/MANIFEST.MF index 947787b0f70..b228dba6367 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/META-INF/MANIFEST.MF @@ -31,4 +31,5 @@ Require-Bundle: org.eclipse.osee.framework.core.dsl, org.eclipse.xtext Eclipse-ExtensibleAPI: true Bundle-Activator: org.eclipse.osee.framework.core.dsl.integration.internal.Activator -Export-Package: org.eclipse.osee.framework.core.dsl.integration +Export-Package: org.eclipse.osee.framework.core.dsl.integration, + org.eclipse.osee.framework.core.dsl.integration.util diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/ModelUtil.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/ModelUtil.java deleted file mode 100644 index df1a5314a3c..00000000000 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/ModelUtil.java +++ /dev/null @@ -1,191 +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.dsl.integration; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.util.HashMap; -import java.util.Map; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.Resource.Diagnostic; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; -import org.eclipse.osee.framework.core.dsl.OseeDslStandaloneSetup; -import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.exception.OseeStateException; -import org.eclipse.osee.framework.core.exception.OseeWrappedException; -import org.eclipse.xtext.resource.SaveOptions; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.resource.XtextResourceSet; -import com.google.inject.Injector; - -/** - * @author Roberto E. Escobar - */ -public final class ModelUtil { - - private ModelUtil() { - // Utility Class - } - - // private void loadDependencies(OseeTypeModel baseModel, List models) throws OseeCoreException, URISyntaxException { - // // This is commented out cause we're using a combined file. Once combined files - // // are no longer generated, this should be uncommented. - // // for (Import dependant : baseModel.getImports()) { - // // OseeTypeModel childModel = OseeTypeModelUtil.loadModel(context, new URI(dependant.getImportURI())); - // // loadDependencies(childModel, models); - // // System.out.println("depends on: " + dependant.getImportURI()); - // // } - // // System.out.println("Added on: " + baseModel.eResource().getURI()); - // models.add(baseModel); - // - // } - - // OseeTypeModel targetModel = null; - // try { - // targetModel = OseeTypeModelUtil.loadModel(context, resource); - // } catch (OseeCoreException ex) { - // throw new OseeWrappedException(String.format("Error loading: [%s]", resource), ex); - // } - // loadDependencies(targetModel, models); - - public static OseeDsl loadModel(String uri, String xTextData) throws OseeCoreException { - try { - OseeDslStandaloneSetup setup = new OseeDslStandaloneSetup(); - Injector injector = setup.createInjectorAndDoEMFRegistration(); - XtextResourceSet set = injector.getInstance(XtextResourceSet.class); - - set.setClasspathURIContext(ModelUtil.class); - set.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); - - Resource resource = set.createResource(URI.createURI(uri)); - resource.load(new ByteArrayInputStream(xTextData.getBytes("UTF-8")), set.getLoadOptions()); - OseeDsl model = (OseeDsl) resource.getContents().get(0); - for (Diagnostic diagnostic : resource.getErrors()) { - throw new OseeStateException(diagnostic.toString()); - } - return model; - } catch (IOException ex) { - throw new OseeWrappedException(ex); - } - } - - public static OseeDsl loadModel(InputStream inputStream, boolean isZipped) throws OseeCoreException { - Injector injector = new OseeDslStandaloneSetup().createInjectorAndDoEMFRegistration(); - XtextResource resource = injector.getInstance(XtextResource.class); - - Map options = new HashMap(); - options.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); - if (isZipped) { - options.put(Resource.OPTION_ZIP, Boolean.TRUE); - } - try { - resource.setURI(URI.createURI("http://www.eclipse.org/osee/framework/OseeTypes")); - resource.load(inputStream, options); - } catch (IOException ex) { - throw new OseeWrappedException(ex); - } - OseeDsl model = (OseeDsl) resource.getContents().get(0); - for (Diagnostic diagnostic : resource.getErrors()) { - throw new OseeStateException(diagnostic.toString()); - } - return model; - } - - public static OseeDsl loadModel(Object context, java.net.URI target) throws OseeCoreException { - String uri = target.toASCIIString(); - Injector injector = new OseeDslStandaloneSetup().createInjectorAndDoEMFRegistration(); - XtextResourceSet set = injector.getInstance(XtextResourceSet.class); - - set.setClasspathURIContext(context); - set.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); - - Resource resource = set.getResource(URI.createURI(uri), true); - OseeDsl model = (OseeDsl) resource.getContents().get(0); - for (Diagnostic diagnostic : resource.getErrors()) { - throw new OseeStateException(diagnostic.toString()); - } - return model; - } - - public static void saveModel(java.net.URI uri, OseeDsl model) throws IOException { - OseeDslStandaloneSetup.doSetup(); - - ResourceSet resourceSet = new ResourceSetImpl(); - Resource resource = resourceSet.createResource(URI.createURI(uri.toASCIIString())); - resource.getContents().add(model); - - Map options = new HashMap(); - // options.put(XtextResource.OPTION_FORMAT, Boolean.TRUE); - SaveOptions saveOptions = SaveOptions.getOptions(options); - resource.save(saveOptions.toOptionsMap()); - } - - public static void saveModel(OseeDsl model, String uri, OutputStream outputStream, boolean isZipped) throws IOException { - OseeDslStandaloneSetup.doSetup(); - - ResourceSet resourceSet = new ResourceSetImpl(); - Resource resource = resourceSet.createResource(URI.createURI(uri)); - resource.getContents().add(model); - - Map options = new HashMap(); - // options.put(XtextResource.OPTION_FORMAT, Boolean.TRUE); - if (isZipped) { - options.put(Resource.OPTION_ZIP, Boolean.TRUE); - } - SaveOptions saveOptions = SaveOptions.getOptions(options); - resource.save(outputStream, saveOptions.toOptionsMap()); - } - - private static void storeModel(OutputStream outputStream, EObject object, String uri, Map options) throws OseeCoreException { - Resource resource = new XMLResourceImpl(); - try { - resource.setURI(URI.createURI(uri)); - resource.getContents().add(object); - resource.save(outputStream, options); - } catch (IOException ex) { - throw new OseeWrappedException(ex); - } - } - - public static String modelToString(EObject object, String uri, Map options) throws OseeCoreException { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - storeModel(outputStream, object, uri, options); - try { - return outputStream.toString("UTF-8"); - } catch (UnsupportedEncodingException ex) { - throw new OseeWrappedException(ex); - } - } - - public static ComparisonSnapshot loadComparisonSnapshot(String compareName, String compareData) throws OseeCoreException { - ComparisonSnapshot snapshot = null; - try { - ResourceSet resourceSet = new ResourceSetImpl(); - Resource resource = resourceSet.createResource(URI.createURI(compareName)); - resource.load(new ByteArrayInputStream(compareData.getBytes("UTF-8")), resourceSet.getLoadOptions()); - snapshot = (ComparisonSnapshot) resource.getContents().get(0); - } catch (IOException ex) { - throw new OseeWrappedException(ex); - } - return snapshot; - } - -} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/OseeToXtextOperation.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/OseeToXtextOperation.java index 5817833ccf6..c77ba196fc2 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/OseeToXtextOperation.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/OseeToXtextOperation.java @@ -17,6 +17,7 @@ import java.util.Map; import java.util.Map.Entry; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.osee.framework.core.dsl.integration.internal.Activator; +import org.eclipse.osee.framework.core.dsl.integration.util.OseeUtil; 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.RelationMultiplicityEnum; diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/OseeUtil.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/OseeUtil.java deleted file mode 100644 index 87694b2264d..00000000000 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/OseeUtil.java +++ /dev/null @@ -1,113 +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.dsl.integration; - -import org.eclipse.osee.framework.core.data.IArtifactType; -import org.eclipse.osee.framework.core.data.IAttributeType; -import org.eclipse.osee.framework.core.data.IRelationType; -import org.eclipse.osee.framework.core.data.NamedIdentity; -import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessPermissionEnum; -import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction; -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.XRelationSideEnum; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; -import org.eclipse.osee.framework.core.enums.PermissionEnum; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; -import org.eclipse.osee.framework.core.enums.RelationSide; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.util.Conditions; -import org.eclipse.osee.framework.jdk.core.util.Strings; - -/** - * @author Roberto E. Escobar - */ -public final class OseeUtil { - - private OseeUtil() { - // Utility Class - } - - public static IArtifactType toToken(XArtifactType model) { - return new ArtifactTypeToken(model); - } - - public static IAttributeType toToken(XAttributeType model) { - return new AttributeTypeToken(model); - } - - public static IRelationType toToken(XRelationType model) { - return new RelationTypeToken(model); - } - - private final static class ArtifactTypeToken extends NamedIdentity implements IArtifactType { - public ArtifactTypeToken(XArtifactType model) { - super(model.getTypeGuid(), Strings.unquote(model.getName())); - } - } - - private final static class AttributeTypeToken extends NamedIdentity implements IAttributeType { - public AttributeTypeToken(XAttributeType model) { - super(model.getTypeGuid(), Strings.unquote(model.getName())); - } - } - - private final static class RelationTypeToken extends NamedIdentity implements IRelationType { - public RelationTypeToken(XRelationType model) { - super(model.getTypeGuid(), Strings.unquote(model.getName())); - } - } - - public static boolean isRestrictedSide(XRelationSideEnum relationSideEnum, RelationSide relationSide) throws OseeCoreException { - Conditions.checkNotNull(relationSideEnum, "relation side restriction"); - Conditions.checkNotNull(relationSide, "relation side"); - - boolean toReturn = false; - switch (relationSideEnum) { - case BOTH: - toReturn = true; - break; - case SIDE_A: - toReturn = relationSide.isSideA(); - break; - case SIDE_B: - toReturn = !relationSide.isSideA(); - break; - default: - break; - } - return toReturn; - } - - public static PermissionEnum getPermission(ObjectRestriction restriction) throws OseeCoreException { - Conditions.checkNotNull(restriction, "restriction"); - AccessPermissionEnum modelPermission = restriction.getPermission(); - Conditions.checkNotNull(modelPermission, "restriction permission"); - PermissionEnum toReturn; - if (modelPermission == AccessPermissionEnum.ALLOW) { - toReturn = PermissionEnum.WRITE; - } else { - toReturn = PermissionEnum.READ; - } - return toReturn; - } - - public static String getRelationOrderType(String guid) throws OseeCoreException { - RelationOrderBaseTypes type = RelationOrderBaseTypes.getFromGuid(guid); - return type.getName().replaceAll(" ", "_"); - } - - public static String orderTypeNameToGuid(String orderTypeName) throws OseeCoreException { - Conditions.checkNotNull(orderTypeName, "orderTypeName"); - return RelationOrderBaseTypes.getFromOrderTypeName(orderTypeName.replaceAll("_", " ")).getGuid(); - } - -} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/XTextToOseeTypeOperation.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/XTextToOseeTypeOperation.java index 05b05de900b..5bf515dcb3c 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/XTextToOseeTypeOperation.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/XTextToOseeTypeOperation.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.osee.framework.core.dsl.integration.internal.Activator; +import org.eclipse.osee.framework.core.dsl.integration.util.OseeUtil; import org.eclipse.osee.framework.core.dsl.oseeDsl.AddEnum; import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDslFactory; diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/ArtifactInstanceRestrictionHandler.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/ArtifactInstanceRestrictionHandler.java index 06033f74e39..b5e250bb4db 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/ArtifactInstanceRestrictionHandler.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/ArtifactInstanceRestrictionHandler.java @@ -11,7 +11,7 @@ package org.eclipse.osee.framework.core.dsl.integration.internal; import org.eclipse.osee.framework.core.dsl.integration.ArtifactDataProvider.ArtifactData; -import org.eclipse.osee.framework.core.dsl.integration.OseeUtil; +import org.eclipse.osee.framework.core.dsl.integration.util.OseeUtil; import org.eclipse.osee.framework.core.dsl.integration.RestrictionHandler; import org.eclipse.osee.framework.core.dsl.oseeDsl.ArtifactInstanceRestriction; import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction; diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/ArtifactTypeRestrictionHandler.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/ArtifactTypeRestrictionHandler.java index 6a8aa88191b..11a7bf6d0f8 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/ArtifactTypeRestrictionHandler.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/ArtifactTypeRestrictionHandler.java @@ -12,7 +12,7 @@ package org.eclipse.osee.framework.core.dsl.integration.internal; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.dsl.integration.ArtifactDataProvider.ArtifactData; -import org.eclipse.osee.framework.core.dsl.integration.OseeUtil; +import org.eclipse.osee.framework.core.dsl.integration.util.OseeUtil; import org.eclipse.osee.framework.core.dsl.integration.RestrictionHandler; import org.eclipse.osee.framework.core.dsl.oseeDsl.ArtifactTypeRestriction; import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction; diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/AttributeTypeRestrictionHandler.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/AttributeTypeRestrictionHandler.java index 4a224f5c219..f9606dda3fa 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/AttributeTypeRestrictionHandler.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/AttributeTypeRestrictionHandler.java @@ -13,7 +13,7 @@ package org.eclipse.osee.framework.core.dsl.integration.internal; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.dsl.integration.ArtifactDataProvider.ArtifactData; -import org.eclipse.osee.framework.core.dsl.integration.OseeUtil; +import org.eclipse.osee.framework.core.dsl.integration.util.OseeUtil; import org.eclipse.osee.framework.core.dsl.integration.RestrictionHandler; import org.eclipse.osee.framework.core.dsl.oseeDsl.AttributeTypeRestriction; import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction; diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeModelingServiceImpl.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeModelingServiceImpl.java index 195a4907ae0..c40364dd39c 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeModelingServiceImpl.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeModelingServiceImpl.java @@ -20,10 +20,10 @@ import org.eclipse.emf.compare.diff.metamodel.ComparisonResourceSnapshot; import org.eclipse.emf.compare.diff.metamodel.DiffFactory; import org.eclipse.osee.framework.core.dsl.integration.CreateOseeTypeChangesReportOperation; import org.eclipse.osee.framework.core.dsl.integration.EMFCompareOperation; -import org.eclipse.osee.framework.core.dsl.integration.ModelUtil; import org.eclipse.osee.framework.core.dsl.integration.OseeToXtextOperation; import org.eclipse.osee.framework.core.dsl.integration.OseeTypeCache; import org.eclipse.osee.framework.core.dsl.integration.XTextToOseeTypeOperation; +import org.eclipse.osee.framework.core.dsl.integration.util.ModelUtil; import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDslFactory; import org.eclipse.osee.framework.core.exception.OseeCoreException; @@ -127,7 +127,7 @@ public class OseeModelingServiceImpl implements IOseeModelingService { if (request.isCreateCompareReport()) { response.setComparisonSnapshotModelName("osee_compare.diff"); String modelString = - ModelUtil.modelToString(comparisonSnapshot, "osee:/osee_compare.diff", + ModelUtil.modelToStringXML(comparisonSnapshot, "osee:/osee_compare.diff", Collections. emptyMap()); response.setComparisonSnapshotModel(modelString); } diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/RelationTypeRestrictionHandler.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/RelationTypeRestrictionHandler.java index bcf7cac2497..08946395b76 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/RelationTypeRestrictionHandler.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/RelationTypeRestrictionHandler.java @@ -13,7 +13,7 @@ package org.eclipse.osee.framework.core.dsl.integration.internal; import java.util.Collection; import org.eclipse.osee.framework.core.data.IRelationType; import org.eclipse.osee.framework.core.dsl.integration.ArtifactDataProvider.ArtifactData; -import org.eclipse.osee.framework.core.dsl.integration.OseeUtil; +import org.eclipse.osee.framework.core.dsl.integration.util.OseeUtil; import org.eclipse.osee.framework.core.dsl.integration.RestrictionHandler; import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction; import org.eclipse.osee.framework.core.dsl.oseeDsl.RelationTypeRestriction; diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtil.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtil.java new file mode 100644 index 00000000000..0cc7184506c --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtil.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * 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.dsl.integration.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.Resource.Diagnostic; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; +import org.eclipse.osee.framework.core.dsl.OseeDslStandaloneSetup; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeStateException; +import org.eclipse.osee.framework.core.exception.OseeWrappedException; +import org.eclipse.xtext.resource.SaveOptions; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.resource.XtextResourceSet; +import com.google.inject.Injector; + +/** + * @author Roberto E. Escobar + */ +public final class ModelUtil { + + private ModelUtil() { + // Utility Class + } + + public static OseeDsl loadModel(String uri, String xTextData) throws OseeCoreException { + try { + OseeDslStandaloneSetup setup = new OseeDslStandaloneSetup(); + Injector injector = setup.createInjectorAndDoEMFRegistration(); + XtextResourceSet set = injector.getInstance(XtextResourceSet.class); + + // set.setClasspathURIContext(ModelUtil.class); + set.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); + + Resource resource = set.createResource(URI.createURI(uri)); + resource.load(new ByteArrayInputStream(xTextData.getBytes("UTF-8")), set.getLoadOptions()); + OseeDsl model = (OseeDsl) resource.getContents().get(0); + for (Diagnostic diagnostic : resource.getErrors()) { + throw new OseeStateException(diagnostic.toString()); + } + return model; + } catch (IOException ex) { + throw new OseeWrappedException(ex); + } + } + + public static void saveModel(OseeDsl model, String uri, OutputStream outputStream, boolean isZipped) throws IOException { + OseeDslStandaloneSetup.doSetup(); + + ResourceSet resourceSet = new ResourceSetImpl(); + Resource resource = resourceSet.createResource(URI.createURI(uri)); + resource.getContents().add(model); + + Map options = new HashMap(); + // options.put(XtextResource.OPTION_FORMAT, Boolean.TRUE); + if (isZipped) { + options.put(Resource.OPTION_ZIP, Boolean.TRUE); + } + SaveOptions saveOptions = SaveOptions.getOptions(options); + resource.save(outputStream, saveOptions.toOptionsMap()); + } + + private static void storeModel(Resource resource, OutputStream outputStream, EObject object, String uri, Map options) throws OseeCoreException { + try { + resource.setURI(URI.createURI(uri)); + resource.getContents().add(object); + resource.save(outputStream, options); + } catch (IOException ex) { + throw new OseeWrappedException(ex); + } + } + + public static String modelToStringXML(EObject object, String uri, Map options) throws OseeCoreException { + return modelToString(new XMLResourceImpl(), object, uri, options); + } + + public static String modelToStringXText(EObject object, String uri, Map options) throws OseeCoreException { + OseeDslStandaloneSetup setup = new OseeDslStandaloneSetup(); + Injector injector = setup.createInjectorAndDoEMFRegistration(); + Resource resource = injector.getInstance(XtextResource.class); + Map options2 = new HashMap(); + options2.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); + return modelToString(resource, object, uri, options2); + } + + private static String modelToString(Resource resource, EObject object, String uri, Map options) throws OseeCoreException { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + storeModel(resource, outputStream, object, uri, options); + try { + return outputStream.toString("UTF-8"); + } catch (UnsupportedEncodingException ex) { + throw new OseeWrappedException(ex); + } + } + + public static ComparisonSnapshot loadComparisonSnapshot(String compareName, String compareData) throws OseeCoreException { + ComparisonSnapshot snapshot = null; + try { + ResourceSet resourceSet = new ResourceSetImpl(); + Resource resource = resourceSet.createResource(URI.createURI(compareName)); + resource.load(new ByteArrayInputStream(compareData.getBytes("UTF-8")), resourceSet.getLoadOptions()); + snapshot = (ComparisonSnapshot) resource.getContents().get(0); + } catch (IOException ex) { + throw new OseeWrappedException(ex); + } + return snapshot; + } + +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/OseeUtil.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/OseeUtil.java new file mode 100644 index 00000000000..764879f6d90 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/OseeUtil.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.integration.util; + +import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.data.IRelationType; +import org.eclipse.osee.framework.core.data.NamedIdentity; +import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessPermissionEnum; +import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction; +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.XRelationSideEnum; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; +import org.eclipse.osee.framework.core.enums.PermissionEnum; +import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; +import org.eclipse.osee.framework.core.enums.RelationSide; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.framework.jdk.core.util.Strings; + +/** + * @author Roberto E. Escobar + */ +public final class OseeUtil { + + private OseeUtil() { + // Utility Class + } + + public static IArtifactType toToken(XArtifactType model) { + return new ArtifactTypeToken(model); + } + + public static IAttributeType toToken(XAttributeType model) { + return new AttributeTypeToken(model); + } + + public static IRelationType toToken(XRelationType model) { + return new RelationTypeToken(model); + } + + private final static class ArtifactTypeToken extends NamedIdentity implements IArtifactType { + public ArtifactTypeToken(XArtifactType model) { + super(model.getTypeGuid(), Strings.unquote(model.getName())); + } + } + + private final static class AttributeTypeToken extends NamedIdentity implements IAttributeType { + public AttributeTypeToken(XAttributeType model) { + super(model.getTypeGuid(), Strings.unquote(model.getName())); + } + } + + private final static class RelationTypeToken extends NamedIdentity implements IRelationType { + public RelationTypeToken(XRelationType model) { + super(model.getTypeGuid(), Strings.unquote(model.getName())); + } + } + + public static boolean isRestrictedSide(XRelationSideEnum relationSideEnum, RelationSide relationSide) throws OseeCoreException { + Conditions.checkNotNull(relationSideEnum, "relation side restriction"); + Conditions.checkNotNull(relationSide, "relation side"); + + boolean toReturn = false; + switch (relationSideEnum) { + case BOTH: + toReturn = true; + break; + case SIDE_A: + toReturn = relationSide.isSideA(); + break; + case SIDE_B: + toReturn = !relationSide.isSideA(); + break; + default: + break; + } + return toReturn; + } + + public static PermissionEnum getPermission(ObjectRestriction restriction) throws OseeCoreException { + Conditions.checkNotNull(restriction, "restriction"); + AccessPermissionEnum modelPermission = restriction.getPermission(); + Conditions.checkNotNull(modelPermission, "restriction permission"); + PermissionEnum toReturn; + if (modelPermission == AccessPermissionEnum.ALLOW) { + toReturn = PermissionEnum.WRITE; + } else { + toReturn = PermissionEnum.READ; + } + return toReturn; + } + + public static String getRelationOrderType(String guid) throws OseeCoreException { + RelationOrderBaseTypes type = RelationOrderBaseTypes.getFromGuid(guid); + return type.getName().replaceAll(" ", "_"); + } + + public static String orderTypeNameToGuid(String orderTypeName) throws OseeCoreException { + Conditions.checkNotNull(orderTypeName, "orderTypeName"); + return RelationOrderBaseTypes.getFromOrderTypeName(orderTypeName.replaceAll("_", " ")).getGuid(); + } + +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/META-INF/MANIFEST.MF index bd07584e324..e7dc3b9a510 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/META-INF/MANIFEST.MF @@ -18,6 +18,7 @@ Import-Package: org.eclipse.compare, org.eclipse.osee.framework.core.client.server, org.eclipse.osee.framework.core.data, org.eclipse.osee.framework.core.dsl.integration, + org.eclipse.osee.framework.core.dsl.integration.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.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesImportOperation.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesImportOperation.java index 097370e7a57..fde3ce4f15b 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesImportOperation.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesImportOperation.java @@ -26,7 +26,7 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot; import org.eclipse.emf.compare.ui.editor.ModelCompareEditorInput; import org.eclipse.osee.framework.core.data.OseeServerContext; -import org.eclipse.osee.framework.core.dsl.integration.ModelUtil; +import org.eclipse.osee.framework.core.dsl.integration.util.ModelUtil; import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; import org.eclipse.osee.framework.core.enums.CoreTranslatorId; import org.eclipse.osee.framework.core.message.OseeImportModelRequest; diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/AllCoreModelTestSuite.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/AllCoreModelTestSuite.java index d2d8b41a742..92c9167ed94 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/AllCoreModelTestSuite.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/AllCoreModelTestSuite.java @@ -10,21 +10,23 @@ *******************************************************************************/ package org.eclipse.osee.framework.core.model.test; +import org.eclipse.osee.framework.core.model.test.access.AccessTestSuite; import org.eclipse.osee.framework.core.model.test.cache.CacheTestSuite; import org.eclipse.osee.framework.core.model.test.fields.FieldTestSuite; -import org.eclipse.osee.framework.core.model.test.type.ModelTestSuite; +import org.eclipse.osee.framework.core.model.test.type.TypeTestSuite; import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({// -CacheTestSuite.class, // +AccessTestSuite.class, // + CacheTestSuite.class, // FieldTestSuite.class, // - ModelTestSuite.class, // + TypeTestSuite.class, // }) /** * @author Roberto E. Escobar */ public class AllCoreModelTestSuite { - + // Test Suite } diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessDetailTest.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessDetailTest.java new file mode 100644 index 00000000000..4efc870dbbc --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessDetailTest.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2010 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.test.access; + +import java.util.ArrayList; +import java.util.Collection; +import junit.framework.Assert; +import org.eclipse.osee.framework.core.enums.PermissionEnum; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.access.AccessDetail; +import org.eclipse.osee.framework.core.model.test.mocks.MockDataFactory; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test Case for {@link AccessDetail} + * + * @author Roberto E. Escobar + */ +@RunWith(Parameterized.class) +public class AccessDetailTest { + + private final Object expAccessObject; + private final PermissionEnum expPermission; + private final String expReason; + private final AccessDetail target; + + public AccessDetailTest(AccessDetail target, Object expAccessObject, PermissionEnum expPermission, String expReason) { + this.target = target; + this.expAccessObject = expAccessObject; + this.expPermission = expPermission; + this.expReason = expReason; + } + + @Test + public void testGetReason() { + Assert.assertEquals(expReason, target.getReason()); + } + + @Test + public void testGetPermission() { + Assert.assertEquals(expPermission, target.getPermission()); + } + + @Test + public void testGetAccessObject() { + Assert.assertEquals(expAccessObject, target.getAccessObject()); + } + + @Test + public void testSetPermission() { + Assert.assertEquals(expPermission, target.getPermission()); + PermissionEnum anotherPermission = PermissionEnum.NONE; + + target.setPermission(anotherPermission); + Assert.assertEquals(anotherPermission, target.getPermission()); + + target.setPermission(expPermission); + Assert.assertEquals(expPermission, target.getPermission()); + } + + @Test + public void testHashCodeAndEquals() { + Assert.assertTrue(target.equals(target)); + Assert.assertTrue(target.hashCode() == target.hashCode()); + + AccessDetail other = MockDataFactory.createAccessDetails(expAccessObject, PermissionEnum.NONE, null); + Assert.assertTrue(target.equals(other)); + Assert.assertTrue(target.hashCode() == other.hashCode()); + + AccessDetail nulled = MockDataFactory.createAccessDetails(null, PermissionEnum.NONE, null); + Assert.assertFalse(target.equals(nulled)); + Assert.assertTrue(target.hashCode() != nulled.hashCode()); + + Collection> collect = new ArrayList>(); + collect.add(target); + Assert.assertEquals(1, collect.size()); + Assert.assertTrue(collect.contains(target)); + Assert.assertTrue(collect.contains(other)); + Assert.assertFalse(collect.contains(nulled)); + } + + @Test + public void testToString() { + String expected = + "Access [ accessObject=[" + expAccessObject + "] permission=[" + expPermission + "] reason=[" + expReason + "]]"; + Assert.assertEquals(expected, target.toString()); + } + + @Parameters + public static Collection getData() throws OseeCoreException { + Collection data = new ArrayList(); + addTest(data, "Hello", PermissionEnum.DENY, "A reason"); + addTest(data, 456, PermissionEnum.WRITE, null); + addTest(data, MockDataFactory.createArtifactType(4), PermissionEnum.FULLACCESS, "reason3"); + addTest(data, MockDataFactory.createAttributeType(), PermissionEnum.READ, "xx"); + return data; + } + + private static void addTest(Collection data, T expAccessObject, PermissionEnum expPermission, String expReason) { + String reasonToCheck = expReason; + if (expReason == null) { + reasonToCheck = Strings.emptyString(); + } + AccessDetail target = MockDataFactory.createAccessDetails(expAccessObject, expPermission, expReason); + data.add(new Object[] {target, expAccessObject, expPermission, reasonToCheck}); + } + +} \ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessFilterChainTest.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessFilterChainTest.java deleted file mode 100644 index 7b0fb84b50c..00000000000 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessFilterChainTest.java +++ /dev/null @@ -1,103 +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.test.access; - -import junit.framework.Assert; -import org.eclipse.osee.framework.core.data.IAttributeType; -import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; -import org.eclipse.osee.framework.core.enums.PermissionEnum; -import org.eclipse.osee.framework.core.model.DefaultBasicArtifact; -import org.eclipse.osee.framework.core.model.IBasicArtifact; -import org.eclipse.osee.framework.core.model.access.exp.AccessFilterChain; -import org.eclipse.osee.framework.core.model.access.exp.ArtifactAccessFilter; -import org.eclipse.osee.framework.core.model.access.exp.AttributeTypeAccessFilter; -import org.eclipse.osee.framework.core.model.access.exp.BranchAccessFilter; -import org.junit.Test; - -/** - * Test Case for {@link AccessFilterChain} - * - * @author Jeff C. Phillips - */ -public class AccessFilterChainTest { - - @Test - public void testUseCase() { - //Can we edit this attribute on an artifact - AccessFilterChain chain = new AccessFilterChain(); - IBasicArtifact basicArtifact = new DefaultBasicArtifact(1, "1", "123"); - IAttributeType attributeType = CoreAttributeTypes.WORD_TEMPLATE_CONTENT; - - BranchAccessFilter branchAccessFilter = new BranchAccessFilter(basicArtifact, PermissionEnum.READ); - ArtifactAccessFilter artifactAccessFilter = new ArtifactAccessFilter(basicArtifact, PermissionEnum.WRITE); - AttributeTypeAccessFilter attributeTypeAccessFilter = - new AttributeTypeAccessFilter(PermissionEnum.DENY, basicArtifact, attributeType); - - chain.add(artifactAccessFilter); - chain.add(branchAccessFilter); - chain.add(attributeTypeAccessFilter); - - PermissionEnum agrPermission = null; - Assert.assertFalse(chain.doFilter(basicArtifact, attributeTypeAccessFilter, PermissionEnum.WRITE, agrPermission)); - Assert.assertTrue(chain.doFilter(basicArtifact, basicArtifact, PermissionEnum.WRITE, agrPermission)); - } - - @Test - public void testWrongArtifactUseCase() { - AccessFilterChain chain = new AccessFilterChain(); - IBasicArtifact basicArtifact = new DefaultBasicArtifact(1, "1", "123"); - IBasicArtifact basicArtifact2 = new DefaultBasicArtifact(2, "2", "456"); - IAttributeType attributeType = CoreAttributeTypes.WORD_TEMPLATE_CONTENT; - - BranchAccessFilter branchAccessFilter = new BranchAccessFilter(basicArtifact, PermissionEnum.READ); - ArtifactAccessFilter artifactAccessFilter = new ArtifactAccessFilter(basicArtifact, PermissionEnum.WRITE); - AttributeTypeAccessFilter attributeTypeAccessFilter = - new AttributeTypeAccessFilter(PermissionEnum.DENY, basicArtifact, attributeType); - - chain.add(artifactAccessFilter); - chain.add(branchAccessFilter); - chain.add(attributeTypeAccessFilter); - - PermissionEnum agrPermission = null; - Assert.assertFalse(chain.doFilter(basicArtifact2, attributeTypeAccessFilter, PermissionEnum.WRITE, agrPermission)); - } - - @Test - public void testChain() { - AccessFilterChain chain = new AccessFilterChain(); - IBasicArtifact basicArtifact = new DefaultBasicArtifact(1, "1", "123"); - - BranchAccessFilter branchAccessFilter = new BranchAccessFilter(basicArtifact, PermissionEnum.READ); - ArtifactAccessFilter artifactAccessFilter = new ArtifactAccessFilter(basicArtifact, PermissionEnum.WRITE); - - chain.add(artifactAccessFilter); - chain.add(branchAccessFilter); - - PermissionEnum agrPermission = null; - Assert.assertTrue(chain.doFilter(basicArtifact, basicArtifact, PermissionEnum.READ, agrPermission)); - Assert.assertTrue(chain.doFilter(basicArtifact, basicArtifact, PermissionEnum.WRITE, agrPermission)); - } - - @Test - public void testChainDeny() { - AccessFilterChain chain = new AccessFilterChain(); - IBasicArtifact basicArtifact = new DefaultBasicArtifact(1, "1", "123"); - BranchAccessFilter branchAccessFilter = new BranchAccessFilter(basicArtifact, PermissionEnum.DENY); - ArtifactAccessFilter artifactAccessFilter = new ArtifactAccessFilter(basicArtifact, PermissionEnum.WRITE); - - chain.add(artifactAccessFilter); - chain.add(branchAccessFilter); - - PermissionEnum agrPermission = null; - Assert.assertFalse(chain.doFilter(basicArtifact, basicArtifact, PermissionEnum.READ, agrPermission)); - Assert.assertFalse(chain.doFilter(basicArtifact, basicArtifact, PermissionEnum.WRITE, agrPermission)); - } -} diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessTestSuite.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessTestSuite.java new file mode 100644 index 00000000000..e61946437d1 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/AccessTestSuite.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.test.access; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({// +AccessDataTest.class, // + AccessDataQueryTest.class, // + AccessDetailTest.class, // + PermissionStatusTest.class, // +}) +/** + * @author Roberto E. Escobar + */ +public class AccessTestSuite { + // Test Suite +} diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/PermissionStatusTest.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/PermissionStatusTest.java index 4051a3b883f..fca62ecebaf 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/PermissionStatusTest.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/PermissionStatusTest.java @@ -16,8 +16,9 @@ import org.junit.Test; /** * Test Case for {@link PermissionStatus} - * + * * @author Jeff C. Phillips + * @author Roberto E. Escobar */ public class PermissionStatusTest { @@ -25,6 +26,7 @@ public class PermissionStatusTest { public void testDefaultConstruction() { PermissionStatus permissionStatus = new PermissionStatus(); Assert.assertTrue(permissionStatus.matched()); + Assert.assertEquals("", permissionStatus.getReason()); } @Test @@ -33,4 +35,10 @@ public class PermissionStatusTest { Assert.assertFalse(permissionStatus.matched()); Assert.assertEquals(permissionStatus.getReason(), "Hello"); } + + @Test + public void testToString() { + PermissionStatus permissionStatus = new PermissionStatus(false, "Hello"); + Assert.assertEquals("PermissionStatus [reason=Hello, matchedPermission=false]", permissionStatus.toString()); + } } diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/PermissionTest.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/PermissionTest.java deleted file mode 100644 index 243ab7fecef..00000000000 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/PermissionTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.test.access; - -import org.eclipse.osee.framework.core.enums.PermissionEnum; - -public class PermissionTest { - - public void main(String[] args) { - PermissionEnum[] a = {PermissionEnum.DENY, PermissionEnum.FULLACCESS, null}; - PermissionEnum[] b = {PermissionEnum.LOCK, PermissionEnum.FULLACCESS, null}; - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - PermissionEnum branchPermission = a[i]; - PermissionEnum userPermission = b[j]; - if (branchPermission == PermissionEnum.DENY || userPermission == null) { - System.out.print("T"); - } else { - System.out.print("F"); - } - } - System.out.println(); - } - } -} diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/exp/AccessFilterChainTest.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/exp/AccessFilterChainTest.java new file mode 100644 index 00000000000..6b78af6645f --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/access/exp/AccessFilterChainTest.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * 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.test.access.exp; + +import junit.framework.Assert; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.enums.PermissionEnum; +import org.eclipse.osee.framework.core.model.DefaultBasicArtifact; +import org.eclipse.osee.framework.core.model.IBasicArtifact; +import org.eclipse.osee.framework.core.model.access.exp.AccessFilterChain; +import org.eclipse.osee.framework.core.model.access.exp.ArtifactAccessFilter; +import org.eclipse.osee.framework.core.model.access.exp.AttributeTypeAccessFilter; +import org.eclipse.osee.framework.core.model.access.exp.BranchAccessFilter; +import org.junit.Test; + +/** + * Test Case for {@link AccessFilterChain} + * + * @author Jeff C. Phillips + */ +public class AccessFilterChainTest { + + @Test + public void testUseCase() { + //Can we edit this attribute on an artifact + AccessFilterChain chain = new AccessFilterChain(); + IBasicArtifact basicArtifact = new DefaultBasicArtifact(1, "1", "123"); + IAttributeType attributeType = CoreAttributeTypes.WORD_TEMPLATE_CONTENT; + + BranchAccessFilter branchAccessFilter = new BranchAccessFilter(basicArtifact, PermissionEnum.READ); + ArtifactAccessFilter artifactAccessFilter = new ArtifactAccessFilter(basicArtifact, PermissionEnum.WRITE); + AttributeTypeAccessFilter attributeTypeAccessFilter = + new AttributeTypeAccessFilter(PermissionEnum.DENY, basicArtifact, attributeType); + + chain.add(artifactAccessFilter); + chain.add(branchAccessFilter); + chain.add(attributeTypeAccessFilter); + + PermissionEnum agrPermission = null; + Assert.assertFalse(chain.doFilter(basicArtifact, attributeTypeAccessFilter, PermissionEnum.WRITE, agrPermission)); + Assert.assertTrue(chain.doFilter(basicArtifact, basicArtifact, PermissionEnum.WRITE, agrPermission)); + } + + @Test + public void testWrongArtifactUseCase() { + AccessFilterChain chain = new AccessFilterChain(); + IBasicArtifact basicArtifact = new DefaultBasicArtifact(1, "1", "123"); + IBasicArtifact basicArtifact2 = new DefaultBasicArtifact(2, "2", "456"); + IAttributeType attributeType = CoreAttributeTypes.WORD_TEMPLATE_CONTENT; + + BranchAccessFilter branchAccessFilter = new BranchAccessFilter(basicArtifact, PermissionEnum.READ); + ArtifactAccessFilter artifactAccessFilter = new ArtifactAccessFilter(basicArtifact, PermissionEnum.WRITE); + AttributeTypeAccessFilter attributeTypeAccessFilter = + new AttributeTypeAccessFilter(PermissionEnum.DENY, basicArtifact, attributeType); + + chain.add(artifactAccessFilter); + chain.add(branchAccessFilter); + chain.add(attributeTypeAccessFilter); + + PermissionEnum agrPermission = null; + Assert.assertFalse(chain.doFilter(basicArtifact2, attributeTypeAccessFilter, PermissionEnum.WRITE, agrPermission)); + } + + @Test + public void testChain() { + AccessFilterChain chain = new AccessFilterChain(); + IBasicArtifact basicArtifact = new DefaultBasicArtifact(1, "1", "123"); + + BranchAccessFilter branchAccessFilter = new BranchAccessFilter(basicArtifact, PermissionEnum.READ); + ArtifactAccessFilter artifactAccessFilter = new ArtifactAccessFilter(basicArtifact, PermissionEnum.WRITE); + + chain.add(artifactAccessFilter); + chain.add(branchAccessFilter); + + PermissionEnum agrPermission = null; + Assert.assertTrue(chain.doFilter(basicArtifact, basicArtifact, PermissionEnum.READ, agrPermission)); + Assert.assertTrue(chain.doFilter(basicArtifact, basicArtifact, PermissionEnum.WRITE, agrPermission)); + } + + @Test + public void testChainDeny() { + AccessFilterChain chain = new AccessFilterChain(); + IBasicArtifact basicArtifact = new DefaultBasicArtifact(1, "1", "123"); + BranchAccessFilter branchAccessFilter = new BranchAccessFilter(basicArtifact, PermissionEnum.DENY); + ArtifactAccessFilter artifactAccessFilter = new ArtifactAccessFilter(basicArtifact, PermissionEnum.WRITE); + + chain.add(artifactAccessFilter); + chain.add(branchAccessFilter); + + PermissionEnum agrPermission = null; + Assert.assertFalse(chain.doFilter(basicArtifact, basicArtifact, PermissionEnum.READ, agrPermission)); + Assert.assertFalse(chain.doFilter(basicArtifact, basicArtifact, PermissionEnum.WRITE, agrPermission)); + } +} diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/cache/CacheTestSuite.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/cache/CacheTestSuite.java index 2894213f183..d4398361dd8 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/cache/CacheTestSuite.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/cache/CacheTestSuite.java @@ -26,5 +26,5 @@ ArtifactTypeCacheTest.class, // * @author Roberto E. Escobar */ public class CacheTestSuite { - + // Test Suite } diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/fields/FieldTestSuite.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/fields/FieldTestSuite.java index 165c4d8cc96..413b7547c8b 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/fields/FieldTestSuite.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/fields/FieldTestSuite.java @@ -28,5 +28,5 @@ ArtifactSuperTypeFieldTest.class, // * @author Roberto E. Escobar */ public class FieldTestSuite { - + // Test Suite } diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/mocks/MockDataFactory.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/mocks/MockDataFactory.java index 58ea3a3018d..0f4d69f23eb 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/mocks/MockDataFactory.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/mocks/MockDataFactory.java @@ -16,6 +16,7 @@ import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.enums.BranchState; import org.eclipse.osee.framework.core.enums.BranchType; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.PermissionEnum; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; import org.eclipse.osee.framework.core.enums.TransactionDetailsType; @@ -26,6 +27,7 @@ import org.eclipse.osee.framework.core.model.IBasicArtifact; import org.eclipse.osee.framework.core.model.OseeCachingService; import org.eclipse.osee.framework.core.model.OseeEnumEntry; import org.eclipse.osee.framework.core.model.TransactionRecord; +import org.eclipse.osee.framework.core.model.access.AccessDetail; 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; @@ -50,6 +52,16 @@ public final class MockDataFactory { // Utility Class } + public static AccessDetail createAccessDetails(T expAccessObject, PermissionEnum expPermission, String expReason) { + AccessDetail target; + if (expReason != null) { + target = new AccessDetail(expAccessObject, expPermission, expReason); + } else { + target = new AccessDetail(expAccessObject, expPermission); + } + return target; + } + public static IBasicArtifact createArtifact(int index) { return new DefaultBasicArtifact(index * 37, GUID.create(), "user_" + index); } diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/type/ModelTestSuite.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/type/ModelTestSuite.java deleted file mode 100644 index 44eafb8d58b..00000000000 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/type/ModelTestSuite.java +++ /dev/null @@ -1,30 +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.test.type; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({// -ArtifactTypeTest.class, // - AttributeTypeTest.class, // - BaseOseeTypeTest.class, // - BranchTest.class, // - OseeEnumTypeTest.class, // - RelationTypeTest.class, // -}) -/** - * @author Roberto E. Escobar - */ -public class ModelTestSuite { - -} diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/type/TypeTestSuite.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/type/TypeTestSuite.java new file mode 100644 index 00000000000..6228f0c7dfd --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/test/type/TypeTestSuite.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.model.test.type; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({// +ArtifactTypeTest.class, // + AttributeTypeTest.class, // + BaseOseeTypeTest.class, // + BranchTest.class, // + OseeEnumTypeTest.class, // + RelationTypeTest.class, // +}) +/** + * @author Roberto E. Escobar + */ +public class TypeTestSuite { + // Test Suite +} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AccessDetail.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AccessDetail.java index afad06c1393..499f57d8c42 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AccessDetail.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AccessDetail.java @@ -48,12 +48,25 @@ public class AccessDetail { @Override public int hashCode() { - return accessObject.hashCode(); + int hashCode = 11; + return hashCode * 37 + (accessObject != null ? accessObject.hashCode() : 0); } @Override public boolean equals(Object obj) { - return accessObject.equals(obj); + if (obj instanceof AccessDetail) { + AccessDetail other = (AccessDetail) obj; + Object object1 = getAccessObject(); + Object object2 = other.getAccessObject(); + boolean result = false; + if (object1 == null && object2 == null) { + result = true; + } else if (object1 != null && object2 != null) { + result = getAccessObject().equals(other.getAccessObject()); + } + return result; + } + return false; } @Override diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AccessFilterFactory.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AccessFilterFactory.java deleted file mode 100644 index 1645e7ccd57..00000000000 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AccessFilterFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.access; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import org.eclipse.osee.framework.core.model.access.exp.IAccessFilter; - -public class AccessFilterFactory { - - public Collection createFilter() { - List filters = new ArrayList(); - - // Collection allowedBranches = new List(); - // Collection> allowedArtifactType = new List(); - // Collection allowedArtifactType = new List(); - // - // filters.add(new BranchAccessFilter(artifact, branchPermission)); - // filters.add(new ArtifactAccessFilter()); - // filters.add(new ArtifactTypeFilter()); - // filters.add(new AttributeTypeFilter()); - // filters.add(new RelationTypeFilter()); - - return filters; - } -} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/ArtifactTypeFilter.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/ArtifactTypeFilter.java deleted file mode 100644 index dfa2fd67384..00000000000 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/ArtifactTypeFilter.java +++ /dev/null @@ -1,54 +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.access; - -import java.util.Collection; -import java.util.HashSet; -import org.eclipse.osee.framework.core.data.IArtifactType; -import org.eclipse.osee.framework.core.enums.PermissionEnum; -import org.eclipse.osee.framework.core.model.IBasicArtifact; - -/** - * @author Jeff C. Phillips - * @author Roberto E. Escobar - */ -public final class ArtifactTypeFilter implements IAcceptFilter { - private final PermissionEnum toMatch; - private final Collection itemsToCheck; - - public ArtifactTypeFilter(PermissionEnum toMatch, IArtifactType... itemsToCheck) { - this.toMatch = toMatch; - this.itemsToCheck = new HashSet(); - if (itemsToCheck != null) { - for (IArtifactType type : itemsToCheck) { - this.itemsToCheck.add(type); - } - } - } - - @Override - public boolean accept(IArtifactType item, IBasicArtifact artifact, PermissionEnum permission) { - boolean result = false; - if (itemsToCheck != null && itemsToCheck.contains(item)) { - result = permission.matches(toMatch); - } - return result; - } - - @Override - public IArtifactType getObject(Object object) { - IArtifactType toReturn = null; - if (object instanceof IArtifactType) { - toReturn = (IArtifactType) object; - } - return toReturn; - } -} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AttributeTypeFilter.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AttributeTypeFilter.java deleted file mode 100644 index 445164fb6e6..00000000000 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/AttributeTypeFilter.java +++ /dev/null @@ -1,53 +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.access; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import org.eclipse.osee.framework.core.data.IAttributeType; -import org.eclipse.osee.framework.core.enums.PermissionEnum; -import org.eclipse.osee.framework.core.model.IBasicArtifact; -import org.eclipse.osee.framework.jdk.core.type.Pair; - -public class AttributeTypeFilter implements IAcceptFilter { - private final PermissionEnum toMatch; - private final Map, IAttributeType> itemsToCheck; - - public AttributeTypeFilter(PermissionEnum toMatch, Collection, IAttributeType>> items) { - this.toMatch = toMatch; - this.itemsToCheck = new HashMap, IAttributeType>(); - - for (Pair, IAttributeType> pair : items) { - itemsToCheck.put(pair.getFirst(), pair.getSecond()); - } - } - - @Override - public IAttributeType getObject(Object object) { - IAttributeType toReturn = null; - if (object instanceof IAttributeType) { - toReturn = (IAttributeType) object; - } - return toReturn; - } - - @Override - public boolean accept(IAttributeType item, IBasicArtifact artifact, PermissionEnum permission) { - boolean result = false; - - if (itemsToCheck.containsKey(artifact)) { - result = permission.matches(toMatch); - } - return result; - } - -} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/IAcceptFilter.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/IAcceptFilter.java deleted file mode 100644 index 8ad6224509a..00000000000 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/IAcceptFilter.java +++ /dev/null @@ -1,25 +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.access; - -import org.eclipse.osee.framework.core.enums.PermissionEnum; -import org.eclipse.osee.framework.core.model.IBasicArtifact; - -/** - * @author Jeff C. Phillips - * @author Roberto E. Escobar - * @param - */ -public interface IAcceptFilter { - boolean accept(T item, IBasicArtifact artifact, PermissionEnum permission); - - T getObject(Object object); -} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/PermissionStatus.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/PermissionStatus.java index 9437b7c5f97..a82ca555ddd 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/PermissionStatus.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/PermissionStatus.java @@ -27,7 +27,9 @@ public final class PermissionStatus { public PermissionStatus(boolean matched, String reason) { this.reason = new StringBuilder(); this.matchedPermission = matched; - append(reason); + if (reason != null) { + append(reason); + } } public boolean matched() { @@ -38,6 +40,11 @@ public final class PermissionStatus { return reason.toString(); } + @Override + public String toString() { + return "PermissionStatus [reason=" + reason + ", matchedPermission=" + matchedPermission + "]"; + } + void append(String reason) { if (Strings.isValid(reason)) { this.reason.append(reason); diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/AccessFilterFactory.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/AccessFilterFactory.java new file mode 100644 index 00000000000..9a163b1366f --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/AccessFilterFactory.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 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.access.exp; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class AccessFilterFactory { + + public Collection createFilter() { + List filters = new ArrayList(); + + // Collection allowedBranches = new List(); + // Collection> allowedArtifactType = new List(); + // Collection allowedArtifactType = new List(); + // + // filters.add(new BranchAccessFilter(artifact, branchPermission)); + // filters.add(new ArtifactAccessFilter()); + // filters.add(new ArtifactTypeFilter()); + // filters.add(new AttributeTypeFilter()); + // filters.add(new RelationTypeFilter()); + + return filters; + } +} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/ArtifactTypeFilter.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/ArtifactTypeFilter.java new file mode 100644 index 00000000000..cd52bc11892 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/ArtifactTypeFilter.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.model.access.exp; + +import java.util.Collection; +import java.util.HashSet; +import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.enums.PermissionEnum; +import org.eclipse.osee.framework.core.model.IBasicArtifact; + +/** + * @author Jeff C. Phillips + * @author Roberto E. Escobar + */ +public final class ArtifactTypeFilter implements IAcceptFilter { + private final PermissionEnum toMatch; + private final Collection itemsToCheck; + + public ArtifactTypeFilter(PermissionEnum toMatch, IArtifactType... itemsToCheck) { + this.toMatch = toMatch; + this.itemsToCheck = new HashSet(); + if (itemsToCheck != null) { + for (IArtifactType type : itemsToCheck) { + this.itemsToCheck.add(type); + } + } + } + + @Override + public boolean accept(IArtifactType item, IBasicArtifact artifact, PermissionEnum permission) { + boolean result = false; + if (itemsToCheck != null && itemsToCheck.contains(item)) { + result = permission.matches(toMatch); + } + return result; + } + + @Override + public IArtifactType getObject(Object object) { + IArtifactType toReturn = null; + if (object instanceof IArtifactType) { + toReturn = (IArtifactType) object; + } + return toReturn; + } +} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/AttributeTypeFilter.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/AttributeTypeFilter.java new file mode 100644 index 00000000000..d5e8ce8d535 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/AttributeTypeFilter.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.model.access.exp; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.enums.PermissionEnum; +import org.eclipse.osee.framework.core.model.IBasicArtifact; +import org.eclipse.osee.framework.jdk.core.type.Pair; + +public class AttributeTypeFilter implements IAcceptFilter { + private final PermissionEnum toMatch; + private final Map, IAttributeType> itemsToCheck; + + public AttributeTypeFilter(PermissionEnum toMatch, Collection, IAttributeType>> items) { + this.toMatch = toMatch; + this.itemsToCheck = new HashMap, IAttributeType>(); + + for (Pair, IAttributeType> pair : items) { + itemsToCheck.put(pair.getFirst(), pair.getSecond()); + } + } + + @Override + public IAttributeType getObject(Object object) { + IAttributeType toReturn = null; + if (object instanceof IAttributeType) { + toReturn = (IAttributeType) object; + } + return toReturn; + } + + @Override + public boolean accept(IAttributeType item, IBasicArtifact artifact, PermissionEnum permission) { + boolean result = false; + + if (itemsToCheck.containsKey(artifact)) { + result = permission.matches(toMatch); + } + return result; + } + +} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/IAcceptFilter.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/IAcceptFilter.java new file mode 100644 index 00000000000..b7285735256 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/access/exp/IAcceptFilter.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.model.access.exp; + +import org.eclipse.osee.framework.core.enums.PermissionEnum; +import org.eclipse.osee.framework.core.model.IBasicArtifact; + +/** + * @author Jeff C. Phillips + * @author Roberto E. Escobar + * @param + */ +public interface IAcceptFilter { + boolean accept(T item, IBasicArtifact artifact, PermissionEnum permission); + + T getObject(Object object); +} -- cgit v1.2.3