View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.common.lib.attr;
20  
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  import org.apache.syncope.common.lib.AbstractJDBCConf;
26  import org.apache.syncope.common.lib.to.AttrRepoTO;
27  import org.apache.syncope.common.lib.types.CaseCanonicalizationMode;
28  
29  public class JDBCAttrRepoConf extends AbstractJDBCConf implements AttrRepoConf {
30  
31      private static final long serialVersionUID = -4474060002361453868L;
32  
33      public enum QueryType {
34          AND,
35          OR
36  
37      }
38  
39      /**
40       * Designed to work against a table where there is a mapping of one row to one user.
41       */
42      private boolean singleRow = true;
43  
44      /**
45       * If the SQL should only be run if all attributes listed in the mappings exist in the query.
46       */
47      private boolean requireAllAttributes = true;
48  
49      /**
50       * When constructing the final person object from the attribute repository,
51       * indicate how the username should be canonicalized.
52       */
53      private CaseCanonicalizationMode caseCanonicalization = CaseCanonicalizationMode.NONE;
54  
55      /**
56       * Indicates how multiple attributes in a query should be concatenated together.
57       */
58      private QueryType queryType = QueryType.AND;
59  
60      /**
61       * Used only when there is a mapping of many rows to one user.
62       * This is done using a key-value structure where the key is the
63       * name of the "attribute name" column the value is the name of the "attribute value" column.
64       */
65      private final Map<String, String> columnMappings = new HashMap<>(0);
66  
67      /**
68       * Username attribute(s) to use when running the SQL query.
69       */
70      private final List<String> username = new ArrayList<>(0);
71  
72      /**
73       * Collection of attributes, used to build the SQL query, that should go through
74       * a case canonicalization process defined as {@code key->value}.
75       */
76      private final List<String> caseInsensitiveQueryAttributes = new ArrayList<>(0);
77  
78      /**
79       * Define a {@code Map} of query attribute names to data-layer attribute names to use when building the query.
80       * The key is always the name of the query attribute that is defined by CAS and passed internally,
81       * and the value is the database column that should map.
82       */
83      private final Map<String, String> queryAttributes = new HashMap<>(0);
84  
85      public boolean isSingleRow() {
86          return singleRow;
87      }
88  
89      public void setSingleRow(final boolean singleRow) {
90          this.singleRow = singleRow;
91      }
92  
93      public boolean isRequireAllAttributes() {
94          return requireAllAttributes;
95      }
96  
97      public void setRequireAllAttributes(final boolean requireAllAttributes) {
98          this.requireAllAttributes = requireAllAttributes;
99      }
100 
101     public CaseCanonicalizationMode getCaseCanonicalization() {
102         return caseCanonicalization;
103     }
104 
105     public void setCaseCanonicalization(final CaseCanonicalizationMode caseCanonicalization) {
106         this.caseCanonicalization = caseCanonicalization;
107     }
108 
109     public QueryType getQueryType() {
110         return queryType;
111     }
112 
113     public void setQueryType(final QueryType queryType) {
114         this.queryType = queryType;
115     }
116 
117     public Map<String, String> getColumnMappings() {
118         return columnMappings;
119     }
120 
121     public List<String> getUsername() {
122         return username;
123     }
124 
125     public List<String> getCaseInsensitiveQueryAttributes() {
126         return caseInsensitiveQueryAttributes;
127     }
128 
129     public Map<String, String> getQueryAttributes() {
130         return queryAttributes;
131     }
132 
133     @Override
134     public Map<String, Object> map(final AttrRepoTO attrRepo, final Mapper mapper) {
135         return mapper.map(attrRepo, this);
136     }
137 }