From cbe6ea0c4d58a4eb2891fc418ecd8e2443cc9812 Mon Sep 17 00:00:00 2001 From: wangjoshuah Date: Sat, 17 Jun 2017 17:18:47 -0700 Subject: [PATCH 1/2] create layer model in SDK --- .../java/com/optimizely/ab/config/Layer.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 core-api/src/main/java/com/optimizely/ab/config/Layer.java diff --git a/core-api/src/main/java/com/optimizely/ab/config/Layer.java b/core-api/src/main/java/com/optimizely/ab/config/Layer.java new file mode 100644 index 000000000..5c084697b --- /dev/null +++ b/core-api/src/main/java/com/optimizely/ab/config/Layer.java @@ -0,0 +1,71 @@ +/** + * + * Copyright 2017, Optimizely and contributors + * + * 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 com.optimizely.ab.config; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +import javax.annotation.concurrent.Immutable; + +/** + * Represents a Optimizely Layer configuration + * + * @see Project JSON + */ +@Immutable +@JsonIgnoreProperties(ignoreUnknown = true) +public class Layer implements IdMapped { + + private final String id; + private final String policy; + private final List experiments; + + public static final String SINGLE_EXPERIMENT_POLICY = "single_experiment"; + + @JsonCreator + public Layer(@JsonProperty("id") String id, + @JsonProperty("policy") String policy, + @JsonProperty("experiments") List experiments) { + this.id = id; + this.policy = policy; + this.experiments = experiments; + } + + public String getId() { + return id; + } + + public String getPolicy() { + return policy; + } + + public List getExperiments() { + return experiments; + } + + @Override + public String toString() { + return "Layer{" + + "id='" + id + '\'' + + ", policy='" + policy + '\'' + + ", experiments=" + experiments + + '}'; + } +} From ecd9efa574a2d12ec7c99bbd83fbc8b144f4b617 Mon Sep 17 00:00:00 2001 From: wangjoshuah Date: Sat, 17 Jun 2017 20:43:42 -0700 Subject: [PATCH 2/2] create rollout model --- .../java/com/optimizely/ab/config/Layer.java | 6 +-- .../com/optimizely/ab/config/Rollout.java | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 core-api/src/main/java/com/optimizely/ab/config/Rollout.java diff --git a/core-api/src/main/java/com/optimizely/ab/config/Layer.java b/core-api/src/main/java/com/optimizely/ab/config/Layer.java index 5c084697b..dc4c476b4 100644 --- a/core-api/src/main/java/com/optimizely/ab/config/Layer.java +++ b/core-api/src/main/java/com/optimizely/ab/config/Layer.java @@ -33,9 +33,9 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class Layer implements IdMapped { - private final String id; - private final String policy; - private final List experiments; + protected final String id; + protected final String policy; + protected final List experiments; public static final String SINGLE_EXPERIMENT_POLICY = "single_experiment"; diff --git a/core-api/src/main/java/com/optimizely/ab/config/Rollout.java b/core-api/src/main/java/com/optimizely/ab/config/Rollout.java new file mode 100644 index 000000000..06b8af1b3 --- /dev/null +++ b/core-api/src/main/java/com/optimizely/ab/config/Rollout.java @@ -0,0 +1,44 @@ +/** + * + * Copyright 2017, Optimizely and contributors + * + * 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 com.optimizely.ab.config; + +import javax.annotation.concurrent.Immutable; +import java.util.List; + +/** + * Represents a Optimizely Rollout configuration + * + * @see Project JSON + */ +@Immutable +public class Rollout extends Layer implements IdMapped { + + public Rollout(String id, + String policy, + List experiments) { + super(id, policy, experiments); + } + + @Override + public String toString() { + return "Rollout{" + + "id='" + id + '\'' + + ", policy='" + policy + '\'' + + ", experiments=" + experiments + + '}'; + } +}