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.client.ui.commons;
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.commons.lang3.StringUtils;
26  import org.apache.syncope.common.lib.SyncopeConstants;
27  import org.apache.syncope.common.lib.to.PlainSchemaTO;
28  
29  public final class SchemaUtils {
30  
31      private SchemaUtils() {
32          // private constructor for static utility class
33      }
34  
35      public static List<String> getEnumeratedValues(final PlainSchemaTO schemaTO) {
36          final List<String> res = new ArrayList<>();
37  
38          final String[] values = StringUtils.isBlank(schemaTO.getEnumerationValues())
39                  ? new String[0]
40                  : schemaTO.getEnumerationValues().split(SyncopeConstants.ENUM_VALUES_SEPARATOR);
41  
42          for (String value : values) {
43              res.add(value.trim());
44          }
45  
46          return res;
47      }
48  
49      public static Map<String, String> getEnumeratedKeyValues(final PlainSchemaTO schemaTO) {
50          final Map<String, String> res = new HashMap<>();
51  
52          final String[] values = StringUtils.isBlank(schemaTO.getEnumerationValues())
53                  ? new String[0]
54                  : schemaTO.getEnumerationValues().split(SyncopeConstants.ENUM_VALUES_SEPARATOR);
55  
56          final String[] keys = StringUtils.isBlank(schemaTO.getEnumerationKeys())
57                  ? new String[0]
58                  : schemaTO.getEnumerationKeys().split(SyncopeConstants.ENUM_VALUES_SEPARATOR);
59  
60          for (int i = 0; i < values.length; i++) {
61              res.put(values[i].trim(), keys.length > i ? keys[i].trim() : null);
62          }
63  
64          return res;
65      }
66  }