001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.api.model.collections;
015
016import org.gbif.api.vocabulary.collections.MasterSourceType;
017
018import java.io.Serializable;
019import java.util.ArrayList;
020import java.util.List;
021import java.util.Objects;
022
023/** Holds the info about the GRSciColl fields whose master source is outside GRSciColl. */
024public class SourceableField implements Serializable {
025
026  private String fieldName;
027  private List<Source> sources = new ArrayList<>();
028
029  public String getFieldName() {
030    return fieldName;
031  }
032
033  public void setFieldName(String fieldName) {
034    this.fieldName = fieldName;
035  }
036
037  public List<Source> getSources() {
038    return sources;
039  }
040
041  public void setSources(List<Source> sources) {
042    this.sources = sources;
043  }
044
045  public static class Source {
046    private MasterSourceType masterSource;
047    private boolean overridable;
048    private List<String> sourceableParts = new ArrayList<>();
049
050    public MasterSourceType getMasterSource() {
051      return masterSource;
052    }
053
054    public void setMasterSource(MasterSourceType masterSource) {
055      this.masterSource = masterSource;
056    }
057
058    public boolean isOverridable() {
059      return overridable;
060    }
061
062    public void setOverridable(boolean overridable) {
063      this.overridable = overridable;
064    }
065
066    public List<String> getSourceableParts() {
067      return sourceableParts;
068    }
069
070    public void setSourceableParts(List<String> sourceableParts) {
071      this.sourceableParts = sourceableParts;
072    }
073
074    @Override
075    public boolean equals(Object o) {
076      if (this == o) {
077        return true;
078      }
079      if (o == null || getClass() != o.getClass()) {
080        return false;
081      }
082      Source source = (Source) o;
083      return overridable == source.overridable
084          && masterSource == source.masterSource
085          && Objects.equals(sourceableParts, source.sourceableParts);
086    }
087
088    @Override
089    public int hashCode() {
090      return Objects.hash(masterSource, overridable, sourceableParts);
091    }
092  }
093
094  @Override
095  public boolean equals(Object o) {
096    if (this == o) {
097      return true;
098    }
099    if (o == null || getClass() != o.getClass()) {
100      return false;
101    }
102    SourceableField that = (SourceableField) o;
103    return Objects.equals(fieldName, that.fieldName) && Objects.equals(sources, that.sources);
104  }
105
106  @Override
107  public int hashCode() {
108    return Objects.hash(fieldName, sources);
109  }
110}