Java源码示例:org.eclipse.collections.api.RichIterable

示例1
@Test
void shouldCollectSingleResultForSingleAxis() {
    IssuesRecorder recorder = mock(IssuesRecorder.class);
    IssuesAggregator aggregator = createIssueAggregator(recorder);

    Issue warning = createIssue(PMD);
    aggregator.endRun(createBuild(AXIS_WINDOWS, createAction(warning)));

    assertThat(aggregator.getNames()).containsExactly(AXIS_WINDOWS);

    Map<String, RichIterable<AnnotatedReport>> results = aggregator.getResultsPerTool();
    assertThat(results).containsOnlyKeys(PMD);

    assertThat(results.get(PMD)).hasSize(1)
            .satisfies(reports -> assertThat(reports.iterator().next().getReport()).hasSize(1).contains(warning));

    aggregator.endBuild();

    verify(recorder).publishResult(any(), any(), anyString(), any(), anyString(), any());
}
 
示例2
@Test @org.jvnet.hudson.test.Issue("JENKINS-59178")
void shouldCollectDifferentResultsForTwoAxes() {
    IssuesRecorder recorder = mock(IssuesRecorder.class);
    IssuesAggregator aggregator = createIssueAggregator(recorder);

    Issue warning = createIssue(PMD);
    aggregator.endRun(createBuild(AXIS_WINDOWS, createAction(warning)));
    Issue bug = createIssue(SPOTBUGS);
    aggregator.endRun(createBuild(AXIS_UNIX, createAction(bug)));

    assertThat(aggregator.getNames()).containsExactly(AXIS_WINDOWS, AXIS_UNIX);

    Map<String, RichIterable<AnnotatedReport>> results = aggregator.getResultsPerTool();
    assertThat(results).containsOnlyKeys(PMD, SPOTBUGS);

    assertThat(results.get(PMD)).hasSize(1)
            .satisfies(reports -> assertThat(reports.iterator().next().getReport()).hasSize(1).contains(warning));
    assertThat(results.get(SPOTBUGS)).hasSize(1)
            .satisfies(reports -> assertThat(reports.iterator().next().getReport()).hasSize(1).contains(bug));

    aggregator.endBuild();

    verify(recorder, times(2)).publishResult(any(), any(), anyString(), any(), anyString(), any());
}
 
示例3
@Test
void shouldCollectMultipleToolsOneAxis() {
    IssuesRecorder recorder = mock(IssuesRecorder.class);
    IssuesAggregator aggregator = createIssueAggregator(recorder);

    Issue warning = createIssue(PMD);
    Issue bug = createIssue(SPOTBUGS);
    aggregator.endRun(createBuild(AXIS_UNIX, createAction(warning), createAction(bug)));

    assertThat(aggregator.getNames()).containsExactly(AXIS_UNIX);

    Map<String, RichIterable<AnnotatedReport>> results = aggregator.getResultsPerTool();
    assertThat(results).containsOnlyKeys(PMD, SPOTBUGS);

    assertThat(results.get(PMD)).hasSize(1)
            .satisfies(reports -> assertThat(reports.iterator().next().getReport()).hasSize(1).contains(warning));
    assertThat(results.get(SPOTBUGS)).hasSize(1)
            .satisfies(reports -> assertThat(reports.iterator().next().getReport()).hasSize(1).contains(bug));

    aggregator.endBuild();

    verify(recorder, times(2)).publishResult(any(), any(), anyString(), any(), anyString(), any());
}
 
示例4
private MutableCollection<ClassCompareInfo> getClassCompareInfos(final Class clazz) {
    if (!this.classCompareInfoMap.containsKey(clazz)) {
        // We may have defined the comparison on a generalization (interface or superclass), so we check if there
        // are any compatible classes to check
        RichIterable<Class> realizedClasses = this.classCompareInfoMap.keysView().select(new Predicate<Class>() {
            @Override
            public boolean accept(Class each) {
                return each.isAssignableFrom(clazz);
            }
        });

        RichIterable<ClassCompareInfo> realizedClassCompareInfos = realizedClasses
                .flatCollect(new Function<Class, MutableCollection<ClassCompareInfo>>() {
                    @Override
                    public MutableCollection<ClassCompareInfo> valueOf(Class realizedClass) {
                        return DeepCompareUtil.this.classCompareInfoMap.get(realizedClass);
                    }
                });

        this.classCompareInfoMap.putAll(clazz, realizedClassCompareInfos.toList());
    }
    return this.classCompareInfoMap.get(clazz);
}
 
示例5
public void execute(DbFileMergerArgs args) {
    Configuration config;
    try {
        config = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class)
                .configure(new Parameters().properties()
                        .setFile(args.getDbMergeConfigFile())
                        .setListDelimiterHandler(new LegacyListDelimiterHandler(','))
                ).getConfiguration();
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
    RichIterable<DbMergeInfo> dbMergeInfos = DbMergeInfo.parseFromProperties(config);

    RichIterable<TableSyncSide> tableSyncSides = dbMergeInfos.collect(new Function<DbMergeInfo, TableSyncSide>() {
        @Override
        public TableSyncSide valueOf(DbMergeInfo dbMergeInfo) {
            DataSource ds = ds(dbMergeInfo.getDriverClassName(), dbMergeInfo.getUrl(), dbMergeInfo.getUsername(),
                    dbMergeInfo.getPassword());
            return new TableSyncSide(ds, PhysicalSchema.parseFromString(dbMergeInfo.getPhysicalSchema()));
        }
    });

    this.syncSchemaTables(DbPlatformConfiguration.getInstance().valueOf(config.getString("dbType")), tableSyncSides, args.getOutputDir());
}
 
示例6
private ChangeTypeInfo determineChangeType(final String wholeFileString) {
    RichIterable<ChangeTypeInfo> changeTypeInfos = this.patternMap.keyValuesView().collect(
            new Function<Pair<ChangeType, Pattern>, ChangeTypeInfo>() {
                @Override
                public ChangeTypeInfo valueOf(Pair<ChangeType, Pattern> object) {
                    Pair<Integer, String> contentInfo = getStartIndex(wholeFileString, object.getTwo());
                    return new ChangeTypeInfo(object.getOne()
                            , contentInfo.getOne()
                            , contentInfo.getTwo()
                    );
                }
            });
    ChangeTypeInfo chosenChangeTypeInfo = changeTypeInfos.minBy(ChangeTypeInfo.TO_START_INDEX);

    if (chosenChangeTypeInfo.getStartIndex() == Integer.MAX_VALUE) {
        return new ChangeTypeInfo(UnclassifiedChangeType.INSTANCE, Integer.MAX_VALUE, null);
    } else {
        return chosenChangeTypeInfo;
    }
}
 
示例7
/**
 * Functions need to be referred by their signatures for drops and grants in postgresql
 * For functions query info:
 * https://www.postgresql.org/docs/9.5/static/functions-info.html
 * https://www.postgresql.org/docs/9.5/static/catalog-pg-proc.html
 * https://www.postgresql.org/docs/9.5/static/catalog-pg-namespace.html
 */
@Override
protected Pair<Boolean, RichIterable<String>> getQualifiedObjectNames(Connection conn, PhysicalSchema physicalSchema, String objectName) {
    String schemaName = getDbPlatform().convertDbObjectName().valueOf(physicalSchema.getPhysicalName());
    String functionNameWithCase = getDbPlatform().convertDbObjectName().valueOf(objectName);

    String sql = "select format('%s.%s(%s)',n.nspname, p.proname, pg_get_function_identity_arguments(p.oid)) " +
            "as functionname\n" +
            "FROM   pg_proc p\n" +
            "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n" +
            "WHERE n.nspname = '" + schemaName + "' and p.proname = '" + functionNameWithCase + "'";

    List<Map<String, Object>> funcNameResults = getSqlExecutor().getJdbcTemplate().queryForList(conn, sql);

    MutableList<String> names = Lists.mutable.empty();
    for (Map<String, Object> funcNameResult : funcNameResults) {
        names.add((String) funcNameResult.get("functionname"));
    }

    return Tuples.<Boolean, RichIterable<String>>pair(false, names);
}
 
示例8
private void recompileInvalidObjects(RichIterable<PhysicalSchema> physicalSchemas) {
    MutableList<String> warnings = Lists.mutable.empty();
    for (final PhysicalSchema physicalSchema : physicalSchemas) {
        try {
            this.stmtExecutor.executeWithinContext(physicalSchema, new Procedure<Connection>() {
                @Override
                public void value(Connection conn) {
                    stmtExecutor.getJdbcTemplate().update(conn, "CALL SYSPROC.ADMIN_REVALIDATE_DB_OBJECTS(NULL, '" + physicalSchema.getPhysicalName() + "', NULL)");
                }
            });
            LOG.info("Successfully recompiled objects in schema", physicalSchema);
        } catch (DataAccessException e) {
            warnings.add(physicalSchema.getPhysicalName() + ": " + e.getMessage());
            LOG.warn("Failed to recompile objects on schema {}; will not fail the overall deployment due to this", physicalSchema, e);
        }
    }

    if (warnings.notEmpty()) {
        deployMetricsCollector.addMetric(POST_DEPLOY_WARNINGS, "Failures on recompiling invalid objects: " + warnings.makeString("\n"));
    }
}
 
示例9
public RichIterable<FileObject> getSourceDirs() {
    if (this.sourceDirs == null) {
        // only keep the distinct list of files here
        LinkedHashSet<FileObject> fileObjects = new LinkedHashSet<FileObject>();
        if (coreSourcePath != null) {
            fileObjects.add(coreSourcePath);
        }
        if (additionalSourceDirs != null) {
            fileObjects.addAll(additionalSourceDirs.flatCollect(new Function<String, Iterable<FileObject>>() {
                @Override
                public Iterable<FileObject> valueOf(String path) {
                    MutableList<FileObject> resolvedFileObjects = Lists.mutable.empty();
                    for (FileResolverStrategy fileResolverStrategy : fileResolverStrategies) {
                        resolvedFileObjects.addAllIterable(fileResolverStrategy.resolveFileObjects(path));
                    }
                    if (resolvedFileObjects.isEmpty()) {
                        throw new IllegalArgumentException("Unable to find the given path [" + path + "] via any of the fileResolverStrategies:" + fileResolverStrategies.makeString(", "));
                    }
                    return resolvedFileObjects;
                }
            }).toList());
        }
        this.sourceDirs = Lists.mutable.withAll(fileObjects);
    }
    return this.sourceDirs;
}
 
示例10
public static Predicates<? super String> convert(ImmutableCollection<String> patterns) {
    if (patterns == null) {
        return Predicates.alwaysTrue();
    }
    PartitionIterable<String> wildcardPartition = patterns.partition(Predicates.or(StringPredicates.contains("*"), StringPredicates.contains("%")));
    RichIterable<String> wildcardPatterns = wildcardPartition.getSelected();
    RichIterable<WildcardPatternIndex> wildcardPatternIndexes = wildcardPatterns.collect(new Function<String, WildcardPatternIndex>() {
        @Override
        public WildcardPatternIndex valueOf(String patternString) {
            return new WildcardPatternIndex(patternString);
        }
    });

    RichIterable<String> lookupPatterns = wildcardPartition.getRejected();
    LookupIndex lookupIndex = lookupPatterns.notEmpty() ? new LookupIndex(lookupPatterns.toSet().toImmutable()) : null;

    MutableList<Index> indexes = Lists.mutable.empty();
    if (lookupIndex != null) {
        indexes.add(lookupIndex);
    }
    indexes.withAll(wildcardPatternIndexes);

    return Predicates.or(indexes);
}
 
示例11
public void execute(DbFileMergerArgs args) {
    PropertiesConfiguration config;
    RichIterable<DbMergeInfo> dbNameLocationPairs;
    try {
        config = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class)
                .configure(new Parameters().properties()
                        .setFile(args.getDbMergeConfigFile())
                        .setListDelimiterHandler(new LegacyListDelimiterHandler(','))
                )
                .getConfiguration();
        dbNameLocationPairs = DbMergeInfo.parseFromProperties(config);
    } catch (Exception e) {
        throw new DeployerRuntimeException("Exception reading configs from file " + args.getDbMergeConfigFile(), e);
    }

    Platform dialect = PlatformConfiguration.getInstance().valueOf(config.getString("dbType"));
    this.generateDiffs(dialect, dbNameLocationPairs, args.getOutputDir());
}
 
示例12
private RichIterable<EnvType> getRequestedEnvironments(String sourcePath, String... envNames) {
    MutableCollection<EnvType> environments = getRequestedSystem(sourcePath);

    MutableList<EnvType> requestedEnvs = Lists.mutable.empty();

    if (envNames == null || envNames.length == 0) {
        requestedEnvs.add(readSingleEnvironment(environments, sourcePath));
    } else {
        for (EnvType sysEnv : environments) {
            for (String envPattern : envNames) {
                if (Pattern.compile(RegexUtil.convertWildcardPatternToRegex(envPattern))
                        .matcher(sysEnv.getName())
                        .matches()) {
                    requestedEnvs.add(sysEnv);
                }
            }
        }
    }

    if (requestedEnvs.isEmpty()) {
        throw new IllegalArgumentException("No environment with name/s "
                + Lists.mutable.with(envNames).makeString("(", ",", ")") + " found");
    }

    return requestedEnvs;
}
 
示例13
private List<String> detectNotFullTopLevelObjects(final Map<String, MithraObjectConfigurationType> allDefinedClasses, CacheLoaderType cacheLoaderType)
{
    final List<String> notFullClassNames = FastList.newList();

    MutableListMultimap<String,TopLevelLoaderType> classesByName = ListAdapter.adapt(cacheLoaderType.getTopLevelLoaders()).groupBy(new Function<TopLevelLoaderType, String>()
    {
        @Override
        public String valueOf(final TopLevelLoaderType topLevelLoaderType)
        {
            MithraObjectConfigurationType objectConfigurationType = allDefinedClasses.get(topLevelLoaderType.getClassToLoad());
            if (objectConfigurationType == null || !objectConfigurationType.getCacheType().isFull())
            {
                notFullClassNames.add(topLevelLoaderType.getClassToLoad());
            }
            return topLevelLoaderType.getClassToLoad() + topLevelLoaderType.getSourceAttributes() + topLevelLoaderType.getFactoryClass();
        }
    });
    RichIterable<RichIterable<TopLevelLoaderType>> listOfDupes = classesByName.multiValuesView().select(Predicates.attributeGreaterThan(Functions.getSizeOf(), 1));
    this.assertEmpty("Found duplicates in TopLevel Loader:" + this.printListOfTopLevelLoaderType(listOfDupes), listOfDupes.toList());

    return notFullClassNames;
}
 
示例14
private List<String> detectNotFullDependentObjects(final Map<String, MithraObjectConfigurationType> allDefinedClasses, CacheLoaderType cacheLoaderType)
{
    final List<String> notFullClassNames = FastList.newList();
    MutableListMultimap<String,DependentLoaderType> classesByName = ListAdapter.adapt(cacheLoaderType.getDependentLoaders()).groupBy(new Function<DependentLoaderType, String>()
    {
        @Override
        public String valueOf(final DependentLoaderType dependentLoaderType)
        {
            final String className = dependentLoaderType.getRelationship().substring(0, dependentLoaderType.getRelationship().lastIndexOf("."));
            MithraObjectConfigurationType objectConfigurationType = allDefinedClasses.get(className);
            if (objectConfigurationType == null || !objectConfigurationType.getCacheType().isFull())
            {
                notFullClassNames.add(dependentLoaderType.getRelationship());
            }
            return dependentLoaderType.getRelationship() + dependentLoaderType.getHelperFactoryClass();
        }
    });
    RichIterable<RichIterable<DependentLoaderType>> listOfDupes = classesByName.multiValuesView().select(Predicates.attributeGreaterThan(Functions.getSizeOf(), 1));
    this.assertEmpty("Found duplicates in Dependent Relationship:" + this.printListOfDependentLoaderType(listOfDupes), listOfDupes.toList());
    return notFullClassNames;
}
 
示例15
@Test
void shouldCollectOneToolMultipleAxes() {
    IssuesRecorder recorder = mock(IssuesRecorder.class);
    IssuesAggregator aggregator = createIssueAggregator(recorder);

    Issue unixWarning = createIssue(PMD);
    aggregator.endRun(createBuild(AXIS_UNIX, createAction(unixWarning)));

    Issue windowsWarning = createIssue(PMD);
    aggregator.endRun(createBuild(AXIS_WINDOWS, createAction(windowsWarning)));

    assertThat(aggregator.getNames()).containsExactly(AXIS_UNIX, AXIS_WINDOWS);

    Map<String, RichIterable<AnnotatedReport>> results = aggregator.getResultsPerTool();
    assertThat(results).containsOnlyKeys(PMD);

    assertThat(results.get(PMD)).hasSize(2)
            .satisfies(reports -> {
                Iterator<? extends AnnotatedReport> iterator = reports.iterator();
                assertThat(iterator.next().getReport()).hasSize(1).contains(unixWarning);
                assertThat(iterator.next().getReport()).hasSize(1).contains(windowsWarning);
            });

    aggregator.endBuild();

    verify(recorder).publishResult(any(), any(), anyString(), any(), anyString(), any());
}
 
示例16
@Override
public void applyGrants(Connection conn, PhysicalSchema schema, String objectName, RichIterable<Permission> permsToApply) {
    CommandExecutionContext cec = new CommandExecutionContext();
    applyGrants(conn, schema, objectName, permsToApply, cec);
    if (cec.getWarnings().notEmpty()) {
        LOG.warn("Failed to execute grants on schema {} and object {}", schema, objectName);
        for (String warning : cec.getWarnings()) {
            LOG.warn(warning);
        }
    }
}
 
示例17
/**
 * To avoid irrecoverable deploy state, we allow the deploy to succeed even if grant fails, and we will simply log out warnings.
 */
private void applyGrants(Connection conn, PhysicalSchema schema, String objectName, RichIterable<Permission> permsToApply, CommandExecutionContext cec) {
    String lastExecutedSql = null;
    try {
        Pair<Boolean, RichIterable<String>> qualifiedObjectNames = getQualifiedObjectNames(conn, schema, objectName);
        ImmutableList<String> grants = this.grantChangeParser.generateGrantChanges(permsToApply, dbChangeType, schema, objectName, qualifiedObjectNames.getTwo(), qualifiedObjectNames.getOne());

        LOG.info(String.format("Applying grants on db object [%s]: found %d total SQL statements to apply",
                objectName, grants.size()));

        for (String grant : grants) {
            if (!StringUtils.isBlank(grant)) {
                // need to check for blank in case it gets tokenized away during the in-memory conversion
                LOG.debug("Executing grant: {}", grant);
                lastExecutedSql = grant;

                // grants are automatically included as part of the original change, so we don't track the deployment in the
                // audit table
                sqlExecutor.getJdbcTemplate().update(conn, grant);
            }
        }
    } catch (Exception exc) {
        String warningMessage = "Failed executing grant on schema [" + schema + "] and object [" + objectName + "]";
        if (lastExecutedSql != null) {
            warningMessage += " on SQL " + lastExecutedSql + ":";
        }
        cec.addWarning(warningMessage + exc.getMessage() + "\n        Proceeding with deploy. Please use a /migration script to correct this. Watch https://github.com/goldmansachs/obevo/issues/3 to see when we improve this logic.");
        LOG.error(warningMessage, exc);
    }
}
 
示例18
ImmutableList<String> generateGrantChanges(RichIterable<Permission> permsToApply, final DbChangeType changeType, final PhysicalSchema physicalSchema, final String mainObjectName, RichIterable<String> objectNames, final boolean specific) {
    final MutableList<String> changes = Lists.mutable.empty();

    for (Permission perm : permsToApply) {
        for (final Grant grant : perm.getGrants()) {
            grant.validate();

            for (final String objectName : objectNames) {
                grant.getGrantTargets().forEachKeyValue(new Procedure2<GrantTargetType, String>() {
                    @Override
                    public void value(GrantTargetType grantTargetType, String grantTarget) {
                        for (String privilege : grant.getPrivileges()) {
                            changes.add(GrantChangeParser.this.createGrant(env, privilege, changeType, physicalSchema, objectName, grantTargetType, grantTarget, specific));
                        }
                    }
                });
            }
        }
    }

    if (LOG.isInfoEnabled()) {
        LOG.info(String.format("Applying grants on [%s] with [%d] permission entries on these qualified object names: [%s]",
                mainObjectName, permsToApply.size(), objectNames.makeString("; ")));
    }

    return changes.toImmutable();
}
 
示例19
/**
 * http://infocenter.sybase.com/archive/index.jsp?topic=/com.sybase.help.ase_15.0.tables/html/tables/tables25.htm
 */
private RichIterable<DaTable> createIdealTables(RichIterable<TableSyncSide> syncSides) {
    Multimap<String, DaTable> tableMap = syncSides.flatCollect(TableSyncSide.TO_TABLES).groupBy(DaNamedObject.TO_NAME);

    return tableMap.keyMultiValuePairsView().collect(new Function<Pair<String, RichIterable<DaTable>>, DaTable>() {
        @Override
        public DaTable valueOf(Pair<String, RichIterable<DaTable>> pair) {
            RichIterable<DaTable> tables = pair.getTwo();

            final DaTable table = tables.getFirst();
            DaTableImpl idealTable = new DaTableImpl(table.getSchema(), table.getName());
            idealTable.setPrimaryKey(table.getPrimaryKey());

            idealTable.setColumns(createIdealColumns(tables).toList().toImmutable());

            MutableList<DaIndex> indices = Lists.mutable.empty();
            for (DaIndex idealColumn : TableSyncher.this.createIdealIndices(tables)) {
                if (idealColumn instanceof DaPrimaryKey) {
                    idealTable.setPrimaryKey((DaPrimaryKey) idealColumn);
                } else {
                    indices.add(idealColumn);
                }
            }

            idealTable.setIndices(indices.toImmutable());

            return idealTable;
        }
    });
}
 
示例20
private RichIterable<DaIndex> createIdealIndices(RichIterable<DaTable> tables) {
    Multimap<String, DaIndex> indexMap = tables.flatCollect(DaTable.TO_INDICES).groupBy(
            new Function<DaIndex, String>() {
                @Override
                public String valueOf(DaIndex index) {
                    return index.getName() + ":" + index.getParent().getName();
                }
            }
    );
    return indexMap.multiValuesView().collect(new Function<RichIterable<DaIndex>, DaIndex>() {
        @Override
        public DaIndex valueOf(RichIterable<DaIndex> indices) {
            if (indices.size() == 1) {
                return indices.getFirst();
            }
            DaIndex candidate = indices.detect(DaIndex::isUnique);
            if (candidate != null) {
                return candidate;
            }

            candidate = indices.detect(Predicates.attributeEqual(DaIndex::getIndexType, DaIndexType.CLUSTERED));
            if (candidate != null) {
                return candidate;
            }

            return indices.getFirst();
        }
    });
}
 
示例21
@Override
public Pair<Boolean, RichIterable<String>> getQualifiedObjectNames(Connection conn, PhysicalSchema physicalSchema, final String objectName) {
    ImmutableCollection<String> specificNames = getDbMetadataManager().getRoutineInfo(physicalSchema, objectName)
            .collect(DaRoutine.TO_SPECIFIC_NAME);

    return Tuples.<Boolean, RichIterable<String>>pair(true, specificNames);
}
 
示例22
@VisibleForTesting
void checkForInvalidObjects(Connection conn, RichIterable<PhysicalSchema> physicalSchemas) {
    SetIterable<SchemaObjectRow> invalidObjects = this.getInvalidObjects(conn, physicalSchemas);
    if (!invalidObjects.isEmpty()) {
        LOG.info("Found invalid objects, will attempt to recompile: {}", invalidObjects);
        recompileInvalidObjects(physicalSchemas);
    }
}
 
示例23
@VisibleForTesting
MutableSet<SchemaObjectRow> getInvalidObjects(Connection conn, RichIterable<PhysicalSchema> physicalSchemas) {
    LOG.info("Checking for invalid objects");

    String schemaInClause = physicalSchemas.collect(new Function<PhysicalSchema, String>() {
        @Override
        public String valueOf(PhysicalSchema physicalSchema) {
            return physicalSchema.getPhysicalName();
        }
    }).makeString("('", "','", "')");

    MutableSet<SchemaObjectRow> oldInvalidObjects = queryOldInvalidObjects(conn, schemaInClause);
    try {
        MutableSet<SchemaObjectRow> newInvalidObjects = queryNewInvalidObjects(conn, schemaInClause);

        if (oldInvalidObjects.isEmpty() && newInvalidObjects.notEmpty()) {
            deployMetricsCollector.addMetric("invalidObjectQuery.resultsOnlyInNew", true);
        } else if (oldInvalidObjects.notEmpty() && newInvalidObjects.isEmpty()) {
            deployMetricsCollector.addMetric("invalidObjectQuery.resultsOnlyInOld", true);
        }

        return oldInvalidObjects.withAll(newInvalidObjects);
    } catch (DataAccessException e) {
        deployMetricsCollector.addMetric("oldInvalidObjectQueryRequired", true);
        LOG.debug("Failed to execute new invalid objects SQL; falling back to old query");
        return oldInvalidObjects;
    }
}
 
示例24
/**
 * Builds the predicate on object type and name based on the input functions passed in.
 */
public <T> Predicates<? super T> build(final Function<? super T, String> objectTypeFunction, final Function<? super T, String> objectNameFunction) {
    if (objectNamesByType.isEmpty()) {
        if (filterType == null || filterType.isEmptyInputResult()) {
            return Predicates.alwaysTrue();
        } else {
            return Predicates.alwaysFalse();
        }
    }

    RichIterable<Predicate<? super T>> typePredicates = objectNamesByType.keyMultiValuePairsView().toList().collect(new Function<Pair<String, RichIterable<String>>, Predicate<? super T>>() {
        @Override
        public Predicate<? super T> valueOf(Pair<String, RichIterable<String>> pair) {
            String objectType = pair.getOne();
            RichIterable<String> objectPatterns = pair.getTwo();
            boolean negatePredicate = filterType == FilterType.EXCLUDE;
            if (objectType.startsWith("-")) {
                objectType = objectType.substring(1);
                negatePredicate = true;
            }

            Predicate<T> objectTypeAndNamePredicate = getObjectTypeAndNamePredicate(
                    objectTypeFunction, Lists.immutable.with(objectType),
                    negatePredicate, objectNameFunction, objectPatterns.toList().toImmutable()
            );

            return objectTypeAndNamePredicate;
        }
    });

    if (filterType == null || filterType == FilterType.EXCLUDE) {
        return Predicates.and(typePredicates);
    } else {
        return Predicates.or(typePredicates);
    }
}
 
示例25
private FileSourceParams(RichIterable<FileObject> files, ImmutableSet<String> schemaNames, boolean baseline, ImmutableList<ChangeType> changeTypes, ImmutableSet<String> acceptedExtensions, String defaultSourceEncoding, boolean legacyDirectoryStructureEnabled) {
    this.files = files;
    this.schemaNames = schemaNames;
    this.baseline = baseline;
    this.changeTypes = changeTypes;
    this.acceptedExtensions = acceptedExtensions;
    this.defaultSourceEncoding = defaultSourceEncoding;
    this.legacyDirectoryStructureEnabled = legacyDirectoryStructureEnabled;
}
 
示例26
public ImmutableHierarchicalConfiguration readPlatformProperties(RichIterable<String> configPackages) {
    MutableList<PropertyInput> prioritizedProperties = readConfigPackages(configPackages);

    validate(prioritizedProperties);

    // order properties by priority: higher-numbered files will replace properties of lower-numbered files
    prioritizedProperties.sortThisBy(new Function<PropertyInput, Integer>() {
        @Override
        public Integer valueOf(PropertyInput propertyInput1) {
            return propertyInput1.getPriority();
        }
    }).reverseThis();  // needs to be reversed as CombinedConfiguration takes the higher-priority files first

    // merge properties
    CombinedConfiguration combinedConfiguration = new CombinedConfiguration(new OverrideCombiner());
    for (HierarchicalConfiguration<ImmutableNode> properties : prioritizedProperties.collect(new Function<PropertyInput, HierarchicalConfiguration<ImmutableNode>>() {
        @Override
        public HierarchicalConfiguration<ImmutableNode> valueOf(PropertyInput propertyInput) {
            return propertyInput.getProps();
        }
    })) {
        combinedConfiguration.addConfiguration(properties);
    }

    // remove the configPriority property
    combinedConfiguration.clearTree(PROP_CONFIG_PRIORITY);

    return combinedConfiguration;
}
 
示例27
private MutableList<PropertyInput> readConfigPackages(RichIterable<String> configPackages) {
    MutableSet<PropertyInput> prioritizedProperties = HashingStrategySets.mutable.of(HashingStrategies.fromFunction(new Function<PropertyInput, URL>() {
        @Override
        public URL valueOf(PropertyInput propertyInput) {
            return propertyInput.getPropertyFilePath();
        }
    }));

    for (String configPackage : configPackages) {
        ListIterable<FileObject> fileObjects = FileRetrievalMode.CLASSPATH.resolveFileObjects(configPackage)
                .flatCollect(new Function<FileObject, Iterable<FileObject>>() {
                    @Override
                    public Iterable<FileObject> valueOf(FileObject object) {
                        return ArrayAdapter.adapt(object.getChildren());
                    }
                });
        ListIterable<FileObject> propertyFiles = fileObjects
                .select(new Predicate<FileObject>() {
                    @Override
                    public boolean accept(FileObject it) {
                        return it.getName().getExtension().equals("yaml");
                    }
                });

        for (FileObject propertyFile : propertyFiles) {
            HierarchicalConfiguration<ImmutableNode> fileProps = loadPropertiesFromUrl(propertyFile);

            String configPriorityProp = fileProps.getString(PROP_CONFIG_PRIORITY);
            if (configPriorityProp != null) {
                int priority = Integer.parseInt(configPriorityProp);
                prioritizedProperties.add(new PropertyInput(propertyFile.getName().getBaseName(), propertyFile.getURLDa(), priority, fileProps));
            } else {
                LOG.warn("Property file {} was ignored as it did not contain {} property", propertyFile, PROP_CONFIG_PRIORITY);
            }
        }
    }
    return prioritizedProperties.toList();
}
 
示例28
public static <T> T returnOne(RichIterable<? extends T> coll, String message) {
    if (coll.size() > 1) {
        throw new IllegalArgumentException("Expectiong only 1 message in this collection (" + message
                + "), got this instead: " + coll);
    } else if (coll.size() == 1) {
        return coll.iterator().next();
    } else {
        return null;
    }
}
 
示例29
public static <T> T returnOnlyOne(RichIterable<? extends T> coll, String message) {
    if (coll.size() > 1 || coll.size() == 0) {
        throw new IllegalArgumentException("Expectiong only 1 message in this collection (" + message
                + "), got this instead: " + coll);
    } else {
        return coll.iterator().next();
    }
}
 
示例30
@Override
public ImmutableList<ChangeCommand> calculateCommands(ChangeType changeType, RichIterable<ChangePair> changePairs, RichIterable<Change> allSourceChanges, boolean initAllowedOnHashExceptions) {
    RerunnableObjectInfo rerunnableObjectInfo = changePairs.injectInto(new RerunnableObjectInfo(), new Function2<RerunnableObjectInfo, ChangePair, RerunnableObjectInfo>() {
        @Override
        public RerunnableObjectInfo value(RerunnableObjectInfo rerunnableObjectInfo1, ChangePair changePair) {
            // TODO make this a bit more OO, e.g. avoid the instanceof all over the place
            Change source = changePair.getSourceChange();
            Change deployed = changePair.getDeployedChange();

            if (source == null && deployed == null) {
                // this branch and exception throwing here is to avoid null deference warnings in findbugs for the next else branch
                throw new IllegalStateException("This code branch should never happen; either of source or deployed should exist");
            }

            if (source == null && deployed != null) {
                // In this case - the change exists in the target DB but was removed from the source
                rerunnableObjectInfo1.addDroppedObject(deployed);
            } else if (source != null && deployed == null) {
                rerunnableObjectInfo1.addChangedObject(source);
            } else if (ObjectUtils.equals(source.getContentHash(), deployed.getContentHash())
                    || source.getAcceptableHashes().contains(deployed.getContentHash())) {
                // In this case - the change exists in both the source and target db.
                // We need to check if anything has changed, using the hash

                LOG.trace("Nothing to do here; source [{}] and target [{}] match in hash", source, deployed);
            } else {
                rerunnableObjectInfo1.addChangedObject(source);
            }

            return rerunnableObjectInfo1;
        }
    });

    return this.processRerunnableChanges(changeType, rerunnableObjectInfo, allSourceChanges);
}