2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ===================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
21 package org.onap.aai.champcore.model;
23 import java.util.HashMap;
24 import java.util.HashSet;
26 import java.util.Optional;
29 import com.fasterxml.jackson.annotation.JsonIgnore;
30 import com.fasterxml.jackson.annotation.JsonProperty;
31 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
32 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
34 @JsonDeserialize(builder = ChampObjectConstraint.Builder.class)
35 public final class ChampObjectConstraint {
37 private final String type;
38 private final Map<String, ChampPropertyConstraint> propertyConstraints;
40 private ChampObjectConstraint() {
41 throw new RuntimeException("Cannot call ChampObjectConstraint() constructor");
44 private ChampObjectConstraint(Builder builder) {
45 this.type = builder.type;
46 this.propertyConstraints = builder.propertyConstraints;
49 public String getType() { return type; }
50 public Set<ChampPropertyConstraint> getPropertyConstraints() { return new HashSet<ChampPropertyConstraint> (propertyConstraints.values()); }
52 public Optional<ChampPropertyConstraint> getPropertyConstraint(String fieldName) {
53 if (!propertyConstraints.containsKey(fieldName)) return Optional.empty();
55 return Optional.of(propertyConstraints.get(fieldName));
58 @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
59 public static class Builder {
60 private final String type;
61 private final Map<String, ChampPropertyConstraint> propertyConstraints;
63 public Builder(@JsonProperty("type") String type) {
65 this.propertyConstraints = new HashMap<String, ChampPropertyConstraint> ();
68 @JsonProperty("propertyConstraints")
69 public Builder constraints(Set<ChampPropertyConstraint> propertyConstraints) {
71 for (ChampPropertyConstraint propConstraint : propertyConstraints) {
72 constraint(propConstraint);
79 public Builder constraint(ChampPropertyConstraint propConstraint) {
80 propertyConstraints.put(propConstraint.getField().getName(), propConstraint);
84 public ChampObjectConstraint build() {
85 return new ChampObjectConstraint(this);
90 public boolean equals(Object o) {
91 if (o instanceof ChampObjectConstraint) {
92 final ChampObjectConstraint objectConstraint = (ChampObjectConstraint) o;
94 if (objectConstraint.getType().equals(getType())) return true;
101 public String toString() {
102 return "{type: " + getType() +
103 ", propertyConstraints: " + getPropertyConstraints() +