/*
 * 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 javax.validation.Valid;
import java.util.Map;

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


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

    private String userId;
    private DataPointMetadata metadata;
    private Map<?, ?> 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, Map<?, ?> data) {

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

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

    // may be required for persistence, not using @PersistenceConstructor to avoid Spring Data dependency
    @SuppressWarnings("UnusedDeclaration")
    DataPoint() {
    }

    public String getUserId() {
        return userId;
    }

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

    public Map<?, ?> getData() {
        return data;
    }
}

@@ -826,24 +826,109 @@
 ataPoint %7B%0A%0A
+    private String id; // duplicated from metadata to make Spring Data MongoDB happy%0A
     private 
@@ -1379,16 +1379,52 @@
 data);%0A%0A
+        this.id = metadata.getId();%0A
         
@@ -1678,32 +1678,86 @@
 oint() %7B%0A    %7D%0A%0A
+    public String getId() %7B%0A        return id;%0A    %7D%0A%0A
     public Strin

Add data point identifier to root domain object to greatly simplify persistence.