Search in sources :

Example 1 with CollectionUtils.isEmpty

use of org.apache.commons.collections4.CollectionUtils.isEmpty in project archiva by apache.

the class FileTypes method getFileTypePatterns.

/**
 * Get the list of patterns for a specified filetype.
 * You will always get a list.  In this order.
 * <ul>
 * <li>The Configured List</li>
 * <li>The Default List</li>
 * <li>A single item list of <code>&quot;**&#47;*&quot;</code></li>
 * </ul>
 *
 * @param id the id to lookup.
 * @return the list of patterns.
 */
public List<String> getFileTypePatterns(String id) {
    Configuration config = archivaConfiguration.getConfiguration();
    Predicate selectedFiletype = new FiletypeSelectionPredicate(id);
    RepositoryScanningConfiguration repositoryScanningConfiguration = config.getRepositoryScanning();
    if (repositoryScanningConfiguration != null) {
        FileType filetype = IterableUtils.find(config.getRepositoryScanning().getFileTypes(), selectedFiletype);
        if ((filetype != null) && CollectionUtils.isNotEmpty(filetype.getPatterns())) {
            return filetype.getPatterns();
        }
    }
    List<String> defaultPatterns = defaultTypeMap.get(id);
    if (CollectionUtils.isEmpty(defaultPatterns)) {
        return Collections.singletonList("**/*");
    }
    return defaultPatterns;
}
Also used : CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) Predicate(org.apache.commons.collections4.Predicate) FiletypeSelectionPredicate(org.apache.archiva.configuration.functors.FiletypeSelectionPredicate) FiletypeSelectionPredicate(org.apache.archiva.configuration.functors.FiletypeSelectionPredicate)

Example 2 with CollectionUtils.isEmpty

use of org.apache.commons.collections4.CollectionUtils.isEmpty in project herd by FINRAOS.

the class Hive13DdlGenerator method generateCreateTableDdlHelper.

/**
 * Generates and append to the string builder the create table Hive 13 DDL as per specified parameters.
 */
private String generateCreateTableDdlHelper(GenerateDdlRequest generateDdlRequest) {
    // TODO: We might want to consider using a template engine such as Velocity to generate this DDL so we don't wind up just doing string manipulation.
    StringBuilder sb = new StringBuilder();
    // For custom DDL, we would need to substitute the custom DDL tokens with their relative values.
    HashMap<String, String> replacements = new HashMap<>();
    // Validate that partition values passed in the list of partition filters do not contain '/' character.
    if (generateDdlRequest.isPartitioned && !CollectionUtils.isEmpty(generateDdlRequest.partitionFilters)) {
        // Validate that partition values do not contain '/' characters.
        for (List<String> partitionFilter : generateDdlRequest.partitionFilters) {
            for (String partitionValue : partitionFilter) {
                Assert.doesNotContain(partitionValue, "/", String.format("Partition value \"%s\" can not contain a '/' character.", partitionValue));
            }
        }
    }
    // Get business object format model object to directly access schema columns and partitions.
    BusinessObjectFormat businessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(generateDdlRequest.businessObjectFormatEntity);
    // Validate that we have at least one column specified in the business object format schema.
    assertSchemaColumnsNotEmpty(businessObjectFormat, generateDdlRequest.businessObjectFormatEntity);
    if (generateDdlRequest.isPartitioned) {
        // Validate that we have at least one partition column specified in the business object format schema.
        Assert.notEmpty(businessObjectFormat.getSchema().getPartitions(), String.format("No schema partitions specified for business object format {%s}.", businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(generateDdlRequest.businessObjectFormatEntity)));
        // Validate that partition column names do not contain '/' characters.
        for (SchemaColumn partitionColumn : businessObjectFormat.getSchema().getPartitions()) {
            Assert.doesNotContain(partitionColumn.getName(), "/", String.format("Partition column name \"%s\" can not contain a '/' character. Business object format: {%s}", partitionColumn.getName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(generateDdlRequest.businessObjectFormatEntity)));
        }
    }
    // Add drop table if requested.
    if (BooleanUtils.isTrue(generateDdlRequest.includeDropTableStatement)) {
        sb.append(String.format("DROP TABLE IF EXISTS `%s`;\n\n", generateDdlRequest.tableName));
    }
    // Depending on the flag, prepare "if not exists" option text or leave it an empty string.
    String ifNotExistsOption = BooleanUtils.isTrue(generateDdlRequest.includeIfNotExistsOption) ? "IF NOT EXISTS " : "";
    // Only generate the create table DDL statement, if custom DDL was not specified.
    if (generateDdlRequest.customDdlEntity == null) {
        generateStandardBaseDdl(generateDdlRequest, sb, businessObjectFormat, ifNotExistsOption);
    } else {
        // Use the custom DDL in place of the create table statement.
        sb.append(String.format("%s\n\n", generateDdlRequest.customDdlEntity.getDdl()));
        // We need to substitute the relative custom DDL token with an actual table name.
        replacements.put(TABLE_NAME_CUSTOM_DDL_TOKEN, generateDdlRequest.tableName);
    }
    // Add alter table statements only if the list of partition filters is not empty - this is applicable to generating DDL for business object data only.
    if (!CollectionUtils.isEmpty(generateDdlRequest.partitionFilters)) {
        processPartitionFiltersForGenerateDdl(generateDdlRequest, sb, replacements, generateDdlRequest.businessObjectFormatEntity, businessObjectFormat, ifNotExistsOption);
    } else // Add a location statement with a token if this is format dll that does not use custom ddl.
    if (!generateDdlRequest.isPartitioned && generateDdlRequest.customDdlEntity == null) {
        // Since custom DDL is not specified, there are no partition values, and this table is not partitioned, add a LOCATION clause with a token.
        sb.append(String.format("LOCATION '%s';", NON_PARTITIONED_TABLE_LOCATION_CUSTOM_DDL_TOKEN));
    }
    // Trim to remove unnecessary end-of-line characters, if any, from the end of the generated DDL.
    String resultDdl = sb.toString().trim();
    // For custom DDL, substitute the relative custom DDL tokens with their values.
    if (generateDdlRequest.customDdlEntity != null) {
        for (Map.Entry<String, String> entry : replacements.entrySet()) {
            String token = entry.getKey();
            String value = entry.getValue();
            resultDdl = resultDdl.replaceAll(Pattern.quote(token), value);
        }
    }
    return resultDdl;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Map(java.util.Map) MultiValuedMap(org.apache.commons.collections4.MultiValuedMap)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 FiletypeSelectionPredicate (org.apache.archiva.configuration.functors.FiletypeSelectionPredicate)1 MultiValuedMap (org.apache.commons.collections4.MultiValuedMap)1 Predicate (org.apache.commons.collections4.Predicate)1 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)1 CombinedConfiguration (org.apache.commons.configuration.CombinedConfiguration)1 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)1 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)1