X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=aai-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fserialization%2Fqueryformats%2FChangesFormat.java;h=7caa1bd3839bd9679526f70f02f58a3331277691;hb=fbb02159b84435cf37221ae8ae5e0045167be15a;hp=bbaed36063a1d01331e067687f038e69ac4baf02;hpb=58f0fd2f6ef58de52e1f9a73540c1bb895c0d6e6;p=aai%2Faai-common.git diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ChangesFormat.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ChangesFormat.java index bbaed360..7caa1bd3 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ChangesFormat.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ChangesFormat.java @@ -22,15 +22,16 @@ package org.onap.aai.serialization.queryformats; import com.google.gson.JsonArray; import com.google.gson.JsonObject; + +import java.util.*; +import java.util.concurrent.TimeUnit; + import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.onap.aai.config.SpringContextAware; import org.onap.aai.db.props.AAIProperties; import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException; -import java.util.*; -import java.util.concurrent.TimeUnit; - public class ChangesFormat extends MultiFormatMapper { private Long startTs = 0L; @@ -39,9 +40,11 @@ public class ChangesFormat extends MultiFormatMapper { /* * StartTs = truncate time */ - if (startTime == null || startTime.isEmpty() || "now".equals(startTime) || "0".equals(startTime) || "-1".equals(startTime)){ - String historyTruncateDays = SpringContextAware.getApplicationContext().getEnvironment().getProperty("history.truncate.window.days", "365"); - this.startTs = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(Long.parseLong(historyTruncateDays)); + if (startTime == null || startTime.isEmpty() || "now".equals(startTime) || "0".equals(startTime) + || "-1".equals(startTime)) { + String historyTruncateDays = SpringContextAware.getApplicationContext().getEnvironment() + .getProperty("history.truncate.window.days", "365"); + this.startTs = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(Long.parseLong(historyTruncateDays)); } else { this.startTs = Long.parseLong(startTime); } @@ -50,29 +53,28 @@ public class ChangesFormat extends MultiFormatMapper { @Override protected Optional getJsonFromVertex(Vertex v) { JsonObject json = new JsonObject(); - if (!v.properties(AAIProperties.RESOURCE_VERSION).hasNext() || - !v.properties(AAIProperties.NODE_TYPE).hasNext() || - !v.properties(AAIProperties.AAI_URI).hasNext()) { + if (!v.properties(AAIProperties.RESOURCE_VERSION).hasNext() || !v.properties(AAIProperties.NODE_TYPE).hasNext() + || !v.properties(AAIProperties.AAI_URI).hasNext()) { return Optional.empty(); } json.addProperty("node-type", v.value(AAIProperties.NODE_TYPE)); json.addProperty("uri", v.value(AAIProperties.AAI_URI)); final Set changes = new HashSet<>(); - v.properties(AAIProperties.RESOURCE_VERSION).forEachRemaining(o-> - o.properties(AAIProperties.START_TS, AAIProperties.END_TS) - .forEachRemaining(p -> { - Long val = (Long) p.value(); - if(val >= startTs) { - changes.add(val); - } - } - )); + v.properties(AAIProperties.RESOURCE_VERSION).forEachRemaining( + o -> o.properties(AAIProperties.START_TS, AAIProperties.END_TS).forEachRemaining(p -> { + Long val = (Long) p.value(); + if (val >= startTs) { + changes.add(val); + } + })); v.edges(Direction.BOTH).forEachRemaining(e -> { - if(e.property(AAIProperties.START_TS).isPresent() && (Long)e.property(AAIProperties.START_TS).value() >= startTs) { + if (e.property(AAIProperties.START_TS).isPresent() + && (Long) e.property(AAIProperties.START_TS).value() >= startTs) { changes.add((Long) e.property(AAIProperties.START_TS).value()); } - if(e.property(AAIProperties.END_TS).isPresent() && (Long)e.property(AAIProperties.END_TS).value() >= startTs) { + if (e.property(AAIProperties.END_TS).isPresent() + && (Long) e.property(AAIProperties.END_TS).value() >= startTs) { changes.add((Long) e.property(AAIProperties.END_TS).value()); } }); @@ -88,7 +90,8 @@ public class ChangesFormat extends MultiFormatMapper { } @Override - protected Optional getJsonFromVertex(Vertex input, Map> properties) throws AAIFormatVertexException { + protected Optional getJsonFromVertex(Vertex input, Map> properties) + throws AAIFormatVertexException { return Optional.empty(); }