001package com.identityworksllc.iiq.common;
002
003import sailpoint.tools.Util;
004
005import java.util.ArrayList;
006import java.util.Collections;
007import java.util.List;
008import java.util.function.Function;
009
010/**
011 * Some constants that will be useful in many IIQ scenarios.
012 */
013public final class CommonConstants {
014    /**
015     * A constant so we don't misspell 'false' anywhere
016     */
017    public static final String ARG_STRING_FALSE = "false";
018
019    /**
020     * A constant so we don't misspell 'true' anywhere
021     */
022    public static final String ARG_STRING_TRUE = "true";
023
024    /**
025     * The Unix timestamp value in milliseconds of January 1 1900, midnight, UTC
026     */
027    public static final long EPOCH_1900 = -2208988800000L;
028
029    /**
030     * The Unix timestamp value in milliseconds of January 1 1950, midnight, UTC
031     */
032    public static final long EPOCH_1950 = -631152000000L;
033    /**
034     * The common attribute name to use for filters
035     */
036    public static final String FILTER_ATTR = "filter";
037    /**
038     * The CSV parser API as a function
039     */
040    public static final Function<String, List<String>> FUNC_CSV_PARSER = Util::csvToList;
041
042    /**
043     * The null or empty API as a function
044     */
045    public static final Function<String, Boolean> FUNC_STR_EMPTY = Util::isNullOrEmpty;
046
047    /**
048     * The not null or empty API as a function
049     */
050    public static final Function<String, Boolean> FUNC_STR_NOT_EMPTY = Util::isNotNullOrEmpty;
051
052    /**
053     * A List intended to be passed to context.search to retrieve ID only
054     */
055    public static final List<String> SEARCH_ID = listOf("id");
056
057    /**
058     * A List intended to be passed to context.search to retrieve id and name only
059     */
060    public static final List<String> SEARCH_ID_NAME = listOf("id", "name");
061
062    /**
063     * A List intended to be passed to context.search to retrieve useful fields specific to Links
064     */
065    public static final List<String> SEARCH_LINK_FIELDS = listOf("id", "application.id", "nativeIdentity", "identity.id");
066
067    /**
068     * The field number in the {@link #SEARCH_LINK_FIELDS} indicating the application ID
069     */
070    public static final int SEARCH_LINK_FIELD_APP_ID = 1;
071
072    /**
073     * The field number in the {@link #SEARCH_LINK_FIELDS} indicating the Link ID
074     */
075    public static final int SEARCH_LINK_FIELD_ID = 0;
076
077    /**
078     * The field number in the {@link #SEARCH_LINK_FIELDS} indicating the owning Identity ID
079     */
080    public static final int SEARCH_LINK_FIELD_IDENTITY = 3;
081
082    /**
083     * The field number in the {@link #SEARCH_LINK_FIELDS} indicating the Link Native Identity
084     */
085    public static final int SEARCH_LINK_FIELD_NATIVE_ID = 2;
086
087    /**
088     * A List intended to be passed to context.search to retrieve name only
089     */
090    public static final List<String> SEARCH_NAME = listOf("name");
091    /**
092     * A standard timestamp format
093     */
094    public static final String STANDARD_TIMESTAMP = "yyyy-MM-dd HH:mm:ss Z";
095    /**
096     * The common attribute used for threading across multiple requests and tasks
097     */
098    public static final String THREADS_ATTR = "threads";
099
100    /**
101     * Constant of the 8.2 version string
102     */
103    public static final String VERSION_8_2 = "8.2";
104
105    /**
106     * Constant of the 8.3 version string
107     */
108    public static final String VERSION_8_3 = "8.3";
109
110    /**
111     * Constant of the 8.4 version string
112     */
113    public static final String VERSION_8_4 = "8.4";
114
115    private CommonConstants() {
116        /* This class is not intended to be instantiated */
117    }
118
119    /**
120     * Private method to simulate List.of in pre-10 versions of Java
121     * @param values The values to add to the list
122     * @param <T> The type of the values
123     * @return The resulting unmodifiable list
124     */
125    @SafeVarargs
126    private static <T> List<T> listOf(T... values) {
127        List<T> list = new ArrayList<>();
128        if (values != null) {
129            Collections.addAll(list, values);
130        }
131        return Collections.unmodifiableList(list);
132    }
133}