summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorBruno Sakoto <bruno.sakoto@bell.ca>2021-05-13 13:15:53 +0000
committerGerrit Code Review <gerrit@onap.org>2021-05-13 13:15:53 +0000
commit2d88ad8115c4f618275490e58c584f9b0c01c477 (patch)
treef49925c7f17476ee839979a1a31d7baadd55141e /src/main/java/org
parent32eaae9f106eeb7673ef2f2355bb687db9626aa1 (diff)
parentd31d8e1cc167abf7835a1771b5ddc8d78aba9ac6 (diff)
Merge "Implement service and repository layers for storing temporal data"
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/cps/temporal/domain/NetworkData.java78
-rw-r--r--src/main/java/org/onap/cps/temporal/domain/NetworkDataId.java41
-rw-r--r--src/main/java/org/onap/cps/temporal/repository/NetworkDataRepository.java28
-rw-r--r--src/main/java/org/onap/cps/temporal/service/NetworkDataService.java31
-rw-r--r--src/main/java/org/onap/cps/temporal/service/NetworkDataServiceImpl.java41
5 files changed, 219 insertions, 0 deletions
diff --git a/src/main/java/org/onap/cps/temporal/domain/NetworkData.java b/src/main/java/org/onap/cps/temporal/domain/NetworkData.java
new file mode 100644
index 0000000..c4f3176
--- /dev/null
+++ b/src/main/java/org/onap/cps/temporal/domain/NetworkData.java
@@ -0,0 +1,78 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2021 Bell Canada.
+ * ================================================================================
+ * 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.cps.temporal.domain;
+
+import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
+import java.io.Serializable;
+import java.time.OffsetDateTime;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.Table;
+import javax.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.hibernate.annotations.CreationTimestamp;
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+
+/**
+ * Entity to store an anchor configuration or state along with the moment it has been observed.
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@IdClass(NetworkDataId.class)
+@Builder
+@Entity
+@Table(name = "network_data")
+@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
+public class NetworkData implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @Column(name = "timestamp")
+ private OffsetDateTime observedTimestamp;
+
+ @Id
+ @Column
+ private String dataspace;
+
+ @Id
+ @Column
+ private String anchor;
+
+ @NotNull
+ @Column
+ private String schemaSet;
+
+ @NotNull
+ @Type(type = "jsonb")
+ @Column(columnDefinition = "jsonb")
+ private String payload;
+
+ @CreationTimestamp
+ @Column(name = "version", updatable = false)
+ private OffsetDateTime createdTimestamp;
+
+}
diff --git a/src/main/java/org/onap/cps/temporal/domain/NetworkDataId.java b/src/main/java/org/onap/cps/temporal/domain/NetworkDataId.java
new file mode 100644
index 0000000..e9742e2
--- /dev/null
+++ b/src/main/java/org/onap/cps/temporal/domain/NetworkDataId.java
@@ -0,0 +1,41 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2021 Bell Canada.
+ * ================================================================================
+ * 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.cps.temporal.domain;
+
+import java.io.Serializable;
+import java.time.OffsetDateTime;
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+/**
+ * Identifier class for network data.
+ */
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode
+public class NetworkDataId implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private String dataspace;
+ private String anchor;
+ private OffsetDateTime observedTimestamp;
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/cps/temporal/repository/NetworkDataRepository.java b/src/main/java/org/onap/cps/temporal/repository/NetworkDataRepository.java
new file mode 100644
index 0000000..2e9f34b
--- /dev/null
+++ b/src/main/java/org/onap/cps/temporal/repository/NetworkDataRepository.java
@@ -0,0 +1,28 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2021 Bell Canada.
+ * ================================================================================
+ * 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.cps.temporal.repository;
+
+import org.onap.cps.temporal.domain.NetworkData;
+import org.onap.cps.temporal.domain.NetworkDataId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface NetworkDataRepository extends JpaRepository<NetworkData, NetworkDataId> {
+}
diff --git a/src/main/java/org/onap/cps/temporal/service/NetworkDataService.java b/src/main/java/org/onap/cps/temporal/service/NetworkDataService.java
new file mode 100644
index 0000000..509e470
--- /dev/null
+++ b/src/main/java/org/onap/cps/temporal/service/NetworkDataService.java
@@ -0,0 +1,31 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2021 Bell Canada.
+ * ================================================================================
+ * 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.cps.temporal.service;
+
+import org.onap.cps.temporal.domain.NetworkData;
+
+public interface NetworkDataService {
+
+ /**
+ * Add Network data.
+ *
+ * @param networkData the network data to be stored
+ */
+ NetworkData addNetworkData(NetworkData networkData);
+}
diff --git a/src/main/java/org/onap/cps/temporal/service/NetworkDataServiceImpl.java b/src/main/java/org/onap/cps/temporal/service/NetworkDataServiceImpl.java
new file mode 100644
index 0000000..2e7afb2
--- /dev/null
+++ b/src/main/java/org/onap/cps/temporal/service/NetworkDataServiceImpl.java
@@ -0,0 +1,41 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2021 Bell Canada.
+ * ================================================================================
+ * 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.cps.temporal.service;
+
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.temporal.domain.NetworkData;
+import org.onap.cps.temporal.repository.NetworkDataRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * Service implementation for Network Data.
+ */
+@Component
+@Slf4j
+public class NetworkDataServiceImpl implements NetworkDataService {
+
+ @Autowired
+ NetworkDataRepository networkDataRepository;
+
+ @Override
+ public NetworkData addNetworkData(final NetworkData networkData) {
+ return networkDataRepository.save(networkData);
+ }
+}