/*
 * 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.google.common.collect.Range;

import java.time.OffsetDateTime;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;


/**
 * A search criteria bean used to represent a search for data points.
 *
 * @author Emerson Farrugia
 */
public class DataPointSearchCriteria {

    private String userId;
    private String schemaNamespace;
    private String schemaName;
    private String schemaVersion;
    private Range<OffsetDateTime> creationTimestampRange;

    public DataPointSearchCriteria(String userId, String schemaNamespace, String schemaName, String schemaVersion) {

        checkNotNull(userId);
        checkArgument(!isNullOrEmpty(userId));

        this.userId = userId;
        this.schemaNamespace = schemaNamespace;
        this.schemaName = schemaName;
        this.schemaVersion = schemaVersion;
    }

    public String getUserId() {
        return userId;
    }

    public String getSchemaNamespace() {
        return schemaNamespace;
    }

    public String getSchemaName() {
        return schemaName;
    }

    public String getSchemaVersion() {
        return schemaVersion;
    }

    public Optional<Range<OffsetDateTime>> getCreationTimestampRange() {
        return Optional.of(creationTimestampRange);
    }

    public void setCreationTimestampRange(Range<OffsetDateTime> creationTimestampRange) {
        this.creationTimestampRange = creationTimestampRange;
    }
}

@@ -666,16 +666,68 @@
 t.Range;
+%0Aimport org.openmhealth.schema.domain.SchemaVersion;
 %0A%0Aimport
@@ -972,16 +972,227 @@
 rEmpty;%0A
+import static org.openmhealth.schema.domain.SchemaId.isValidName;%0Aimport static org.openmhealth.schema.domain.SchemaId.isValidNamespace;%0Aimport static org.openmhealth.schema.domain.SchemaVersion.isValidVersion;%0A
 %0A%0A/**%0A *
@@ -1437,29 +1437,36 @@
    private S
-tring
+chemaVersion
  schemaVersi
@@ -1724,16 +1724,360 @@
 rId));%0A%0A
+        // TODO determine how restrictive the search criteria should be%0A        checkNotNull(schemaNamespace);%0A        checkNotNull(schemaName);%0A        checkNotNull(schemaVersion);%0A%0A        checkArgument(isValidNamespace(schemaNamespace));%0A        checkArgument(isValidName(schemaName));%0A        checkArgument(isValidVersion(schemaVersion));%0A%0A
         
@@ -2213,16 +2213,34 @@
 rsion = 
+new SchemaVersion(
 schemaVe
@@ -2236,32 +2236,33 @@
 on(schemaVersion
+)
 ;%0A    %7D%0A%0A    pub
@@ -2470,37 +2470,44 @@
  %7D%0A%0A    public S
-tring
+chemaVersion
  getSchemaVersio

Add full schema version to data point search criteria.