Search in sources :

Example 1 with ListOrderedSet

use of org.apache.commons.collections.set.ListOrderedSet in project symmetric-ds by JumpMind.

the class ForeignKey method clone.

/**
 * {@inheritDoc}
 */
public Object clone() throws CloneNotSupportedException {
    ForeignKey result = (ForeignKey) super.clone();
    result.name = name;
    result.foreignTableName = foreignTableName;
    result.references = new ListOrderedSet();
    for (Iterator<?> it = references.iterator(); it.hasNext(); ) {
        result.references.add(((Reference) it.next()).clone());
    }
    return result;
}
Also used : ListOrderedSet(org.apache.commons.collections.set.ListOrderedSet)

Example 2 with ListOrderedSet

use of org.apache.commons.collections.set.ListOrderedSet in project openmrs-core by openmrs.

the class ConceptValidatorChangeSet method getAllowedLocalesList.

/**
 * Retrieves the list of allowed locales from the database, sets the default locale, english and
 * the default locale will be added to the list allowed locales if not yet included
 *
 * @param connection The database connection
 * @return A list of allowed locales
 */
@SuppressWarnings("unchecked")
private List<Locale> getAllowedLocalesList(JdbcConnection connection) {
    Statement stmt = null;
    ListOrderedSet allowedLocales = new ListOrderedSet();
    try {
        // get the default locale
        stmt = connection.createStatement();
        ResultSet rsDefaultLocale = stmt.executeQuery("SELECT property_value FROM global_property WHERE property = '" + OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE + "'");
        if (rsDefaultLocale.next()) {
            String defaultLocaleStr = rsDefaultLocale.getString("property_value");
            if (!StringUtils.isBlank(defaultLocaleStr) && defaultLocaleStr.length() > 1) {
                Locale defaultLocaleGP = LocaleUtility.fromSpecification(defaultLocaleStr);
                if (defaultLocaleGP != null) {
                    defaultLocale = defaultLocaleGP;
                }
            } else {
                updateWarnings.add("'" + defaultLocaleStr + "' is an invalid value for the global property default locale");
            }
        }
        allowedLocales.add(defaultLocale);
        // get the locale.allowed.list
        ResultSet rsAllowedLocales = stmt.executeQuery("SELECT property_value FROM global_property WHERE property = '" + OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST + "'");
        if (rsAllowedLocales.next()) {
            String allowedLocaleStr = rsAllowedLocales.getString("property_value");
            if (!StringUtils.isBlank(allowedLocaleStr)) {
                String[] localesArray = allowedLocaleStr.split(",");
                for (String localeStr : localesArray) {
                    if (localeStr.trim().length() > 1) {
                        allowedLocales.add(LocaleUtility.fromSpecification(localeStr.trim()));
                    } else {
                        updateWarnings.add("'" + localeStr + "' is an invalid value for the global property locale.allowed.list");
                    }
                }
            }
        } else {
            log.warn("The global property '" + OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST + "' isn't set");
        }
    } catch (DatabaseException | SQLException e) {
        log.warn("Error generated", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                log.warn("Failed to close the statement object");
            }
        }
    }
    // if it isn't among
    allowedLocales.add(new Locale("en"));
    return allowedLocales.asList();
}
Also used : Locale(java.util.Locale) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ListOrderedSet(org.apache.commons.collections.set.ListOrderedSet) DatabaseException(liquibase.exception.DatabaseException)

Aggregations

ListOrderedSet (org.apache.commons.collections.set.ListOrderedSet)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Locale (java.util.Locale)1 DatabaseException (liquibase.exception.DatabaseException)1