Add side effect to check pnf owning entity 14/112414/4
authorRodrigo Lima <rodrigo.lima@yoppworks.com>
Wed, 9 Sep 2020 18:54:15 +0000 (14:54 -0400)
committerRodrigo Lima <rodrigo.lima@yoppworks.com>
Thu, 10 Sep 2020 19:08:25 +0000 (15:08 -0400)
- Create side effect to check : user's groups contains pnf's owning entity name
- Create unit tests for side effect
- Add new process method in HttpEntry to pass set of groups
- Pass set of groups to db serializer

Issue-ID: AAI-3176
Signed-off-by: Rodrigo Lima <rodrigo.lima@yoppworks.com>
Change-Id: I4bc7ab6e22bce8cbe60bd7ef6bb5db73dac3a1c4

23 files changed:
aai-aaf-auth/pom.xml
aai-annotations/pom.xml
aai-annotations/src/main/java/org/onap/aai/schema/enums/PropertyMetadata.java
aai-auth/pom.xml
aai-common-docker/aai-common-images/pom.xml
aai-common-docker/aai-haproxy-image/pom.xml
aai-common-docker/pom.xml
aai-core/pom.xml
aai-core/src/main/java/org/onap/aai/introspection/sideeffect/OwnerCheck.java [new file with mode: 0644]
aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java
aai-core/src/test/java/org/onap/aai/introspection/sideeffect/OwnerCheckTest.java [new file with mode: 0644]
aai-core/src/test/resources/onap/dbedgerules/v14/DbEdgeRules_v14.json
aai-core/src/test/resources/onap/oxm/v14/aai_oxm_v14.xml
aai-els-onap-logging/pom.xml
aai-failover/pom.xml
aai-parent/pom.xml
aai-rest/pom.xml
aai-schema-abstraction/pom.xml
aai-schema-ingest/pom.xml
aai-utils/pom.xml
pom.xml
version.properties

index abd5bec..9eeb34e 100644 (file)
@@ -6,7 +6,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
+        <version>1.7.1-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-aaf-auth</artifactId>
index 9b794df..bc4ebb9 100644 (file)
@@ -27,7 +27,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
+        <version>1.7.1-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-annotations</artifactId>
index 559501a..8b28fc7 100644 (file)
@@ -71,7 +71,13 @@ public enum PropertyMetadata {
      * Add a private edge between two objects based on the uri provided by user which should provide
      * the appropriate information from the url similar to dataCopy
      */
-    PRIVATE_EDGE("privateEdge");
+    PRIVATE_EDGE("privateEdge"),
+
+    /**
+     * Checks if user's owning entity equals to pnf's owning entity (if it exists)
+     *
+     */
+    OWNER_CHECK("ownerCheck");
 
     private final String name;
 
index 397da69..1c64aaa 100644 (file)
@@ -27,7 +27,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
+        <version>1.7.1-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-auth</artifactId>
index 500d3bb..24f0acb 100644 (file)
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-common-docker</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
+        <version>1.7.1-SNAPSHOT</version>
     </parent>
 
     <artifactId>aai-common-images</artifactId>
-    <version>1.7.0-SNAPSHOT</version>
+    <version>1.7.1-SNAPSHOT</version>
     <packaging>pom</packaging>
     <name>aai-aai-common-images</name>
     <description>Contains dockerfiles for aai-common images (alpine and ubuntu based).</description>
index ed7af0c..ebbdede 100644 (file)
@@ -25,7 +25,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-common-docker</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
+        <version>1.7.1-SNAPSHOT</version>
     </parent>
 
     <artifactId>aai-haproxy-image</artifactId>
index 5d7dcfd..d6896f5 100644 (file)
@@ -26,7 +26,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
+        <version>1.7.1-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
 
index e0460a1..cf387c1 100644 (file)
@@ -26,7 +26,7 @@ limitations under the License.
        <parent>
                <groupId>org.onap.aai.aai-common</groupId>
                <artifactId>aai-parent</artifactId>
-               <version>1.7.0-SNAPSHOT</version>
+               <version>1.7.1-SNAPSHOT</version>
                <relativePath>../aai-parent/pom.xml</relativePath>
        </parent>
        <artifactId>aai-core</artifactId>
diff --git a/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/OwnerCheck.java b/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/OwnerCheck.java
new file mode 100644 (file)
index 0000000..a32c4ec
--- /dev/null
@@ -0,0 +1,78 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.introspection.sideeffect;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Optional;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException;
+import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.schema.enums.PropertyMetadata;
+import org.onap.aai.serialization.db.DBSerializer;
+import org.onap.aai.serialization.engines.TransactionalGraphEngine;
+
+public class OwnerCheck extends SideEffect {
+
+    public OwnerCheck(Introspector obj, Vertex self, TransactionalGraphEngine dbEngine, DBSerializer serializer) {
+        super(obj, self, dbEngine, serializer);
+    }
+
+    @Override
+    protected void processURI(Optional<String> completeUri, Entry<String, String> entry)
+        throws AAIException {
+        if (serializer.getGroups() != null && !serializer.getGroups().isEmpty()) {
+            List<Vertex> owningEntity = self.graph().traversal()
+                .V(self)
+                .inE("org.onap.relationships.inventory.BelongsTo")
+                .outV()
+                .has("aai-node-type", "owning-entity")
+                .toList();
+
+            if(!owningEntity.isEmpty()) {
+                VertexProperty owningEntityName = owningEntity.get(0).property("owning-entity-name");
+
+                if(!serializer.getGroups().contains(owningEntityName.orElseGet(null))) {
+                    throw new AAIException("AAI_3304",
+                        "Group(s) :" + serializer.getGroups() + " not authorized to perform function");
+                }
+            }
+        } //else skip processing because no required properties were specified
+
+    }
+
+    @Override
+    protected PropertyMetadata getPropertyMetadata() {
+        return PropertyMetadata.OWNER_CHECK;
+    }
+
+    @Override
+    protected boolean replaceWithWildcard() {
+        return false;
+    }
+
+}
index 2899a81..aa4fb8c 100644 (file)
@@ -243,6 +243,13 @@ public class HttpEntry {
         return dbEngine;
     }
 
+    public Pair<Boolean, List<Pair<URI, Response>>> process(List<DBRequest> requests,
+        String sourceOfTruth,
+        Set<String> groups)
+        throws AAIException {
+        return this.process(requests, sourceOfTruth, groups, true);
+    }
+
     public Pair<Boolean, List<Pair<URI, Response>>> process(List<DBRequest> requests, String sourceOfTruth)
             throws AAIException {
         return this.process(requests, sourceOfTruth, true);
@@ -339,14 +346,21 @@ public class HttpEntry {
      * @throws AAIException the AAI exception
      */
     public Pair<Boolean, List<Pair<URI, Response>>> process(List<DBRequest> requests, String sourceOfTruth,
-            boolean enableResourceVersion) throws AAIException {
+        boolean enableResourceVersion) throws AAIException {
+        return this.process(requests, sourceOfTruth, Collections.EMPTY_SET, enableResourceVersion);
+    }
+
+    private Pair<Boolean, List<Pair<URI, Response>>> process(List<DBRequest> requests,
+        String sourceOfTruth,
+        Set<String> groups,
+        boolean enableResourceVersion) throws AAIException {
 
         DBSerializer serializer = null;
 
         if(serverBase != null){
-            serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, sourceOfTruth, notificationDepth, serverBase);
+            serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, sourceOfTruth, groups, notificationDepth, serverBase);
         } else {
-            serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, sourceOfTruth, notificationDepth);
+            serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, sourceOfTruth, groups, notificationDepth);
         }
 
         Response response;
index 7cd0e78..5b274ee 100644 (file)
@@ -96,6 +96,7 @@ public class DBSerializer {
 
     private final TransactionalGraphEngine engine;
     private final String sourceOfTruth;
+    private final Set<String> groups;
     private final ModelType introspectionType;
     private final SchemaVersion version;
     private final Loader latestLoader;
@@ -128,6 +129,7 @@ public class DBSerializer {
             String sourceOfTruth) throws AAIException {
         this.engine = engine;
         this.sourceOfTruth = sourceOfTruth;
+        this.groups = Collections.EMPTY_SET;
         this.introspectionType = introspectionType;
         this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
         SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
@@ -144,6 +146,27 @@ public class DBSerializer {
         initBeans();
     }
 
+    public DBSerializer(SchemaVersion version, TransactionalGraphEngine engine, ModelType introspectionType,
+        String sourceOfTruth, Set<String> groups) throws AAIException {
+        this.engine = engine;
+        this.sourceOfTruth = sourceOfTruth;
+        this.groups = groups;
+        this.introspectionType = introspectionType;
+        this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
+        SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
+        this.latestLoader =
+            SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, latestVersion);
+        this.version = version;
+        this.loader =
+            SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
+        this.namedPropNodes = this.latestLoader.getNamedPropNodes();
+        this.baseURL = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE);
+        this.currentTimeMillis = System.currentTimeMillis();
+        // If creating the DBSerializer the old way then set the notification depth to maximum
+        this.notificationDepth = AAIProperties.MAXIMUM_DEPTH;
+        initBeans();
+    }
+
     public DBSerializer(SchemaVersion version,
                         TransactionalGraphEngine engine,
                         ModelType introspectionType,
@@ -151,6 +174,31 @@ public class DBSerializer {
                         int notificationDepth) throws AAIException {
         this.engine = engine;
         this.sourceOfTruth = sourceOfTruth;
+        this.groups = Collections.EMPTY_SET;
+        this.introspectionType = introspectionType;
+        this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
+        SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
+        this.latestLoader =
+            SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, latestVersion);
+        this.version = version;
+        this.loader =
+            SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
+        this.namedPropNodes = this.latestLoader.getNamedPropNodes();
+        this.baseURL = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE);
+        this.currentTimeMillis = System.currentTimeMillis();
+        this.notificationDepth = notificationDepth;
+        initBeans();
+    }
+
+    public DBSerializer(SchemaVersion version,
+        TransactionalGraphEngine engine,
+        ModelType introspectionType,
+        String sourceOfTruth,
+        Set<String> groups,
+        int notificationDepth) throws AAIException {
+        this.engine = engine;
+        this.sourceOfTruth = sourceOfTruth;
+        this.groups = groups;
         this.introspectionType = introspectionType;
         this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
         SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
@@ -174,6 +222,32 @@ public class DBSerializer {
                         String serverBase) throws AAIException {
         this.engine = engine;
         this.sourceOfTruth = sourceOfTruth;
+        this.groups = Collections.EMPTY_SET;
+        this.introspectionType = introspectionType;
+        this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
+        SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
+        this.latestLoader =
+            SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, latestVersion);
+        this.version = version;
+        this.loader =
+            SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
+        this.namedPropNodes = this.latestLoader.getNamedPropNodes();
+        this.baseURL = serverBase;
+        this.currentTimeMillis = System.currentTimeMillis();
+        this.notificationDepth = notificationDepth;
+        initBeans();
+    }
+
+    public DBSerializer(SchemaVersion version,
+        TransactionalGraphEngine engine,
+        ModelType introspectionType,
+        String sourceOfTruth,
+        Set<String> groups,
+        int notificationDepth,
+        String serverBase) throws AAIException {
+        this.engine = engine;
+        this.sourceOfTruth = sourceOfTruth;
+        this.groups = groups;
         this.introspectionType = introspectionType;
         this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
         SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
@@ -223,6 +297,10 @@ public class DBSerializer {
         return impliedDeleteUriObjectPair;
     }
 
+    public Set<String> getGroups() {
+        return this.groups;
+    }
+
     /**
      * Touch standard vertex properties.
      *  @param v the v
@@ -2193,7 +2271,7 @@ public class DBSerializer {
     private void executePreSideEffects(Introspector obj, Vertex self) throws AAIException {
 
         SideEffectRunner runner = new SideEffectRunner.Builder(this.engine, this).addSideEffect(DataCopy.class)
-                .addSideEffect(PrivateEdge.class).build();
+                .addSideEffect(PrivateEdge.class).addSideEffect(OwnerCheck.class).build();
 
         runner.execute(obj, self);
     }
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/OwnerCheckTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/OwnerCheckTest.java
new file mode 100644 (file)
index 0000000..0e33f6c
--- /dev/null
@@ -0,0 +1,229 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.introspection.sideeffect;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphFactory;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.aai.AAISetup;
+import org.onap.aai.db.props.AAIProperties;
+import org.onap.aai.edges.enums.EdgeProperty;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.ModelType;
+import org.onap.aai.parsers.query.QueryParser;
+import org.onap.aai.serialization.db.DBSerializer;
+import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
+import org.onap.aai.serialization.engines.TransactionalGraphEngine;
+
+@RunWith(value = Parameterized.class)
+
+public class OwnerCheckTest extends AAISetup {
+
+    private static JanusGraph graph;
+    private final static ModelType introspectorFactoryType = ModelType.MOXY;
+    private static Loader loader;
+    private static TransactionalGraphEngine dbEngine;
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    @Parameterized.Parameter
+    public QueryStyle queryStyle;
+
+    @Parameterized.Parameters(name = "QueryStyle.{0}")
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
+    }
+
+    @BeforeClass
+    public static void setup() {
+        graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
+        System.setProperty("AJSC_HOME", ".");
+        System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
+
+        graph.traversal()
+            .addV("pnf")
+            .property("aai-node-type", "pnf")
+            .property("pnf-name", "my-pnf")
+            .property(AAIProperties.AAI_URI, "/network/pnfs/pnf/my-pnf")
+            .property("model-invariant-id", "key1")
+            .as("v1")
+            .addV("owning-entity")
+            .property("aai-node-type", "owning-entity")
+            .property("owning-entity-name", "OE-Generic")
+            .property("owning-entity-id", "367c897c-8cec-47ba-b7f5-4b6139f06691")
+            .property(AAIProperties.AAI_URI,"/network/pnfs/pnf/my-pnf/business/owning-entities/owning-entity/367c897c-8cec-47ba-b7f5-4b6139f06691")
+            .as("oe")
+            .addE("org.onap.relationships.inventory.BelongsTo").to("v1").from("oe")
+            .property(EdgeProperty.CONTAINS.toString(), true)
+            .addV("model-ver")
+            .property("aai-node-type", "model-ver")
+            .property("model-ver", "myValue")
+            .property("model-version-id", "key2")
+            .property("model-version", "testValue")
+            .property(AAIProperties.AAI_URI, "/network/pnfs/pnf/my-pnf/model-vers/model-ver/key2")
+            .as("v2")
+            .addE("org.onap.relationships.inventory.BelongsTo").to("v1").from("v2")
+            .property(EdgeProperty.CONTAINS.toString(), true)
+            .addV("model")
+            .property("aai-node-type", "model")
+            .property("model-invariant-id", "key3")
+            .property(AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3")
+            .as("v3")
+            .addV()
+            .property("aai-node-type", "model-ver")
+            .property("model-ver", "myValue")
+            .property("model-version-id", "key4")
+            .property(AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3/model-vers/model-ver/key4")
+            .as("v4")
+            .addE("org.onap.relationships.inventory.BelongsTo").to("v3").from("v4")
+            .property(EdgeProperty.CONTAINS.toString(), true)
+            .next();
+        graph.tx().commit();
+    }
+
+    @AfterClass
+    public static void tearDown() {
+        graph.tx().rollback();
+        graph.close();
+    }
+
+    @Before
+    public void initMock() {
+        loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
+        MockitoAnnotations.initMocks(this);
+        dbEngine = new JanusGraphDBEngine(queryStyle, loader);
+    }
+
+    @Test
+    public void shouldFailComparisonWithDiffOwningEntity() throws Exception  {
+
+        final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
+        final Introspector obj = loader.introspectorFromName("pnf");
+        obj.setValue("pnf-name", "my-pnf");
+        obj.setValue("model-invariant-id", "key1");
+        obj.setValue("model-version-id", "key2");
+        //obj.setValue("owning-entity-id", "367c897c-8cec-47ba-b7f5-4b6139f06691");
+        TransactionalGraphEngine spy = spy(dbEngine);
+        TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
+        Graph g = graph.newTransaction();
+        GraphTraversalSource traversal = g.traversal();
+        when(spy.asAdmin()).thenReturn(adminSpy);
+        when(adminSpy.getTraversalSource()).thenReturn(traversal);
+        DBSerializer serializer =
+                new DBSerializer(schemaVersions.getDefaultVersion(),
+                    spy, introspectorFactoryType,
+                    "AAI_TEST", new HashSet<>(Arrays.asList("OE-GenericI", "OE-GenericII")));
+
+        Vertex selfV = g.traversal().V().has("aai-node-type", "pnf").next();
+
+        OwnerCheck ownerCheck = new OwnerCheck(obj, selfV, spy, serializer);
+
+        thrown.expect(AAIException.class);
+        thrown.expectMessage("Group(s) :[OE-GenericI, OE-GenericII] not authorized to perform function");
+        ownerCheck.execute();
+        g.tx().rollback();
+
+    }
+
+    @Test
+    public void shouldPassIfOwningEntityEqual() throws Exception  {
+
+        final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
+        final Introspector obj = loader.introspectorFromName("pnf");
+        obj.setValue("pnf-name", "my-pnf");
+        obj.setValue("model-invariant-id", "key1");
+        obj.setValue("model-version-id", "key2");
+        //obj.setValue("owning-entity-id", "367c897c-8cec-47ba-b7f5-4b6139f06691");
+        TransactionalGraphEngine spy = spy(dbEngine);
+        TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
+        Graph g = graph.newTransaction();
+        GraphTraversalSource traversal = g.traversal();
+        when(spy.tx()).thenReturn(g);
+        when(spy.asAdmin()).thenReturn(adminSpy);
+        when(adminSpy.getTraversalSource()).thenReturn(traversal);
+
+        Vertex selfV = g.traversal().V().has("aai-node-type", "pnf").next();
+
+        DBSerializer serializer =
+            new DBSerializer(schemaVersions.getDefaultVersion(),
+                spy, introspectorFactoryType,
+                "AAI_TEST", new HashSet<>(Arrays.asList("OE-Generic", "OE-GenericII")));
+
+        OwnerCheck ownerCheck = new OwnerCheck(obj, selfV, spy, serializer);
+
+        ownerCheck.execute();
+
+
+        g.tx().rollback();
+    }
+
+    @Test
+    public void shouldPassIfUserOwningEntityEmptyl() throws Exception  {
+
+        final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
+        final Introspector obj = loader.introspectorFromName("pnf");
+        obj.setValue("pnf-name", "my-pnf");
+        obj.setValue("model-invariant-id", "key1");
+        obj.setValue("model-version-id", "key2");
+        //obj.setValue("owning-entity-id", "367c897c-8cec-47ba-b7f5-4b6139f06691");
+        TransactionalGraphEngine spy = spy(dbEngine);
+        TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
+        Graph g = graph.newTransaction();
+        GraphTraversalSource traversal = g.traversal();
+        when(spy.asAdmin()).thenReturn(adminSpy);
+        when(adminSpy.getTraversalSource()).thenReturn(traversal);
+        DBSerializer serializer =
+            new DBSerializer(schemaVersions.getDefaultVersion(),
+                spy, introspectorFactoryType,
+                "AAI_TEST");
+
+        Vertex selfV = g.traversal().V().has("aai-node-type", "pnf").next();
+
+        OwnerCheck ownerCheck = new OwnerCheck(obj, selfV, spy, serializer);
+
+        ownerCheck.execute();
+        g.tx().rollback();
+    }
+}
index 7b5c26a..0480bb8 100644 (file)
                        "default": "true",
                        "description":""
                },
+        {
+            "from": "pnf",
+            "to": "owning-entity",
+            "label": "org.onap.relationships.inventory.BelongsTo",
+            "direction": "OUT",
+            "multiplicity": "MANY2ONE",
+            "contains-other-v": "NONE",
+            "delete-other-v": "NONE",
+            "prevent-delete": "NONE",
+            "default": "true",
+            "description":""
+        },
                {
                        "from": "cvlan-tag",
                        "to": "port-group",
index 8436fac..b08e4fb 100644 (file)
         <xml-element java-attribute="pnfName" name="pnf-name" required="true" type="java.lang.String" xml-key="true">
           <xml-properties>
             <xml-property name="description" value="unique name of Physical Network Function."/>
+            <xml-property name="ownerCheck" value="N/A"/>
           </xml-properties>
         </xml-element>
         <xml-element java-attribute="pnfName2" name="pnf-name2" type="java.lang.String">
index aa0c7b4..3920418 100644 (file)
@@ -6,7 +6,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
+        <version>1.7.1-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-els-onap-logging</artifactId>
index f03e3b8..7af38e4 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
+        <version>1.7.1-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
index ea50ef7..6c923d7 100644 (file)
@@ -27,7 +27,7 @@ limitations under the License.
   <parent>
     <groupId>org.onap.aai.aai-common</groupId>
     <artifactId>aai-common</artifactId>
-    <version>1.7.0-SNAPSHOT</version>
+    <version>1.7.1-SNAPSHOT</version>
   </parent>
   <artifactId>aai-parent</artifactId>
   <name>aai-parent</name>
index 267bbbc..087da87 100644 (file)
@@ -29,7 +29,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
+        <version>1.7.1-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-rest</artifactId>
index f12d306..78423ed 100644 (file)
@@ -28,7 +28,7 @@
   <parent>
     <groupId>org.onap.aai.aai-common</groupId>
     <artifactId>aai-parent</artifactId>
-    <version>1.7.0-SNAPSHOT</version>
+    <version>1.7.1-SNAPSHOT</version>
     <relativePath>../aai-parent/pom.xml</relativePath>
   </parent>
 
index 1eb9384..c0b76da 100644 (file)
@@ -26,7 +26,7 @@ limitations under the License.
        <parent>
                <groupId>org.onap.aai.aai-common</groupId>
                <artifactId>aai-parent</artifactId>
-               <version>1.7.0-SNAPSHOT</version>
+               <version>1.7.1-SNAPSHOT</version>
                <relativePath>../aai-parent/pom.xml</relativePath>
        </parent>
        <artifactId>aai-schema-ingest</artifactId>
index d2bc91f..70413b7 100644 (file)
@@ -29,7 +29,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
+        <version>1.7.1-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-utils</artifactId>
diff --git a/pom.xml b/pom.xml
index 92a5654..7c4167d 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
 
     <groupId>org.onap.aai.aai-common</groupId>
     <artifactId>aai-common</artifactId>
-    <version>1.7.0-SNAPSHOT</version>
+    <version>1.7.1-SNAPSHOT</version>
     <packaging>pom</packaging>
     <name>aai-aai-common</name>
     <description>Contains all of the common code for resources and traversal repos</description>
index 85a0227..6434a15 100644 (file)
@@ -5,7 +5,7 @@
 
 major_version=1
 minor_version=7
-patch_version=0
+patch_version=1
 
 base_version=${major_version}.${minor_version}.${patch_version}