2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.migration.v12;
22 import java.util.Optional;
24 import org.apache.commons.lang.exception.ExceptionUtils;
25 import org.apache.tinkerpop.gremlin.structure.Edge;
26 import org.onap.aai.migration.MigrationDangerRating;
27 import org.onap.aai.migration.Enabled;
28 import org.onap.aai.migration.MigrationPriority;
29 import org.onap.aai.migration.Migrator;
30 import org.onap.aai.migration.Status;
31 import org.onap.aai.serialization.db.AAIDirection;
32 import org.onap.aai.serialization.db.EdgeProperty;
33 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
38 @MigrationPriority(-100)
39 @MigrationDangerRating(10)
40 public class ContainmentDeleteOtherVPropertyMigration extends Migrator {
42 private boolean success = true;
44 public ContainmentDeleteOtherVPropertyMigration(TransactionalGraphEngine engine) {
48 //just for testing using test edge rule files
49 public ContainmentDeleteOtherVPropertyMigration(TransactionalGraphEngine engine, String edgeRulesFile) {
56 engine.asAdmin().getTraversalSource().E().sideEffect(t -> {
58 logger.info("out vertex: " + e.outVertex().property("aai-node-type").value() +
59 " in vertex: " + e.inVertex().property("aai-node-type").value() +
60 " label : " + e.label());
61 if (e.property(EdgeProperty.CONTAINS.toString()).isPresent() &&
62 e.property(EdgeProperty.DELETE_OTHER_V.toString()).isPresent()) {
64 if (!("constrained-element-set".equals(e.inVertex().property("aai-node-type").value())
65 && "model-element".equals(e.outVertex().property("aai-node-type").value()))) {
66 //skip the weird horrible problem child edge
67 String containment = (String) e.property(EdgeProperty.CONTAINS.toString()).value();
68 if (AAIDirection.OUT.toString().equalsIgnoreCase(containment) ||
69 AAIDirection.IN.toString().equalsIgnoreCase(containment) ||
70 AAIDirection.BOTH.toString().equalsIgnoreCase(containment)) {
71 logger.info("updating delete-other-v property");
72 e.property(EdgeProperty.DELETE_OTHER_V.toString(), containment);
77 } catch (Exception e) {
78 logger.info("error encountered " + e.getClass() + " " + e.getMessage() + " " + ExceptionUtils.getFullStackTrace(e));
79 logger.error("error encountered " + e.getClass() + " " + e.getMessage() + " " + ExceptionUtils.getFullStackTrace(e));
86 public Status getStatus() {
88 return Status.SUCCESS;
90 return Status.FAILURE;
95 public Optional<String[]> getAffectedNodeTypes() {
96 return Optional.empty();
100 public String getMigrationName() {
101 return "migrate-containment-delete-other-v";