/*
 * Copyright 2014 Open mHealth
 *
 * 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.
 */

package org.openmhealth.dsu.domain;

import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.data.annotation.Id;

import javax.validation.Valid;

import static com.google.common.base.Preconditions.checkNotNull;


/**
 * A data point.
 *
 * @author Emerson Farrugia
 */
public class DataPoint {

    private String userId;
    private DataPointMetadata metadata;
    private JsonNode data;


    /**
     * @param userId the identifier of the user this data point belongs to
     * @param metadata the metadata of this data point
     * @param data the data of this data point
     */
    public DataPoint(String userId, DataPointMetadata metadata, JsonNode data) {

        checkNotNull(userId);
        checkNotNull(metadata);
        checkNotNull(data);

        this.userId = userId;
        this.metadata = metadata;
        this.data = data;
    }

    @Id
    public String getId() {
        return getMetadata().getId();
    }

    public String getUserId() {
        return userId;
    }

    @Valid
    public DataPointMetadata getMetadata() {
        return metadata;
    }

    public JsonNode getData() {
        return data;
    }
}

@@ -631,56 +631,8 @@
 n;%0A%0A
-import com.fasterxml.jackson.databind.JsonNode;%0A
 impo
@@ -670,18 +670,38 @@
 otation.
-Id
+PersistenceConstructor
 ;%0A%0Aimpor
@@ -725,16 +725,38 @@
 n.Valid;
+%0Aimport java.util.Map;
 %0A%0Aimport
@@ -977,24 +977,25 @@
 private 
-JsonNode
+Map%3C?, ?%3E
  data;%0A%0A
@@ -1252,24 +1252,25 @@
 tadata, 
-JsonNode
+Map%3C?, ?%3E
  data) %7B
@@ -1468,76 +1468,48 @@
    @
-Id%0A    public String getId() %7B%0A        return getMetadata().getId();
+PersistenceConstructor%0A    DataPoint() %7B
 %0A   
@@ -1677,16 +1677,17 @@
 lic 
-JsonNode
+Map%3C?, ?%3E
  get

Update data point to natively persist structured data using a Map.