2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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============================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.champcore.model;
24 import java.util.HashMap;
25 import java.util.HashSet;
27 import java.util.Optional;
30 import com.fasterxml.jackson.annotation.JsonIgnore;
31 import com.fasterxml.jackson.annotation.JsonProperty;
32 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
33 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
35 @JsonDeserialize(builder = ChampObjectConstraint.Builder.class)
36 public final class ChampObjectConstraint {
38 private final String type;
39 private final Map<String, ChampPropertyConstraint> propertyConstraints;
41 private ChampObjectConstraint() {
42 throw new RuntimeException("Cannot call ChampObjectConstraint() constructor");
45 private ChampObjectConstraint(Builder builder) {
46 this.type = builder.type;
47 this.propertyConstraints = builder.propertyConstraints;
50 public String getType() { return type; }
51 public Set<ChampPropertyConstraint> getPropertyConstraints() { return new HashSet<ChampPropertyConstraint> (propertyConstraints.values()); }
53 public Optional<ChampPropertyConstraint> getPropertyConstraint(String fieldName) {
54 if (!propertyConstraints.containsKey(fieldName)) return Optional.empty();
56 return Optional.of(propertyConstraints.get(fieldName));
59 @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
60 public static class Builder {
61 private final String type;
62 private final Map<String, ChampPropertyConstraint> propertyConstraints;
64 public Builder(@JsonProperty("type") String type) {
66 this.propertyConstraints = new HashMap<String, ChampPropertyConstraint> ();
69 @JsonProperty("propertyConstraints")
70 public Builder constraints(Set<ChampPropertyConstraint> propertyConstraints) {
72 for (ChampPropertyConstraint propConstraint : propertyConstraints) {
73 constraint(propConstraint);
80 public Builder constraint(ChampPropertyConstraint propConstraint) {
81 propertyConstraints.put(propConstraint.getField().getName(), propConstraint);
85 public ChampObjectConstraint build() {
86 return new ChampObjectConstraint(this);
91 public boolean equals(Object o) {
92 if (o instanceof ChampObjectConstraint) {
93 final ChampObjectConstraint objectConstraint = (ChampObjectConstraint) o;
95 if (objectConstraint.getType().equals(getType())) return true;
102 public String toString() {
103 return "{type: " + getType() +
104 ", propertyConstraints: " + getPropertyConstraints() +