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
035    /**
036     * A standard timestamp format
037     */
038    public static final String STANDARD_TIMESTAMP = "yyyy-MM-dd HH:mm:ss Z";
039
040    /**
041     * The CSV parser API as a function
042     */
043    public static final Function<String, List<String>> FUNC_CSV_PARSER = Util::csvToList;
044
045    /**
046     * The null or empty API as a function
047     */
048    public static final Function<String, Boolean> FUNC_STR_EMPTY = Util::isNullOrEmpty;
049
050    /**
051     * The not null or empty API as a function
052     */
053    public static final Function<String, Boolean> FUNC_STR_NOT_EMPTY = Util::isNotNullOrEmpty;
054
055    /**
056     * A List intended to be passed to context.search to retrieve ID only
057     */
058    public static final List<String> SEARCH_ID = listOf("id");
059
060    /**
061     * A List intended to be passed to context.search to retrieve id and name only
062     */
063    public static final List<String> SEARCH_ID_NAME = listOf("id", "name");
064
065    /**
066     * A List intended to be passed to context.search to retrieve useful fields specific to Links
067     */
068    public static final List<String> SEARCH_LINK_FIELDS = listOf("id", "application.id", "nativeIdentity", "identity.id");
069
070    /**
071     * The field number in the {@link #SEARCH_LINK_FIELDS} indicating the application ID
072     */
073    public static final int SEARCH_LINK_FIELD_APP_ID = 1;
074
075    /**
076     * The field number in the {@link #SEARCH_LINK_FIELDS} indicating the Link ID
077     */
078    public static final int SEARCH_LINK_FIELD_ID = 0;
079
080    /**
081     * The field number in the {@link #SEARCH_LINK_FIELDS} indicating the owning Identity ID
082     */
083    public static final int SEARCH_LINK_FIELD_IDENTITY = 3;
084
085    /**
086     * The field number in the {@link #SEARCH_LINK_FIELDS} indicating the Link Native Identity
087     */
088    public static final int SEARCH_LINK_FIELD_NATIVE_ID = 2;
089
090    /**
091     * A List intended to be passed to context.search to retrieve name only
092     */
093    public static final List<String> SEARCH_NAME = listOf("name");
094
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     * The common attribute name to use for filters
102     */
103    public static final String FILTER_ATTR = "filter";
104
105    /**
106     * Private method to simulate List.of in pre-10 versions of Java
107     * @param values The values to add to the list
108     * @param <T> The type of the values
109     * @return The resulting unmodifiable list
110     */
111    @SafeVarargs
112    private static <T> List<T> listOf(T... values) {
113        List<T> list = new ArrayList<>();
114        if (values != null) {
115            Collections.addAll(list, values);
116        }
117        return Collections.unmodifiableList(list);
118    }
119
120    private CommonConstants() {
121        /* This class is not intended to be instantiated */
122    }
123}