Search in sources :

Example 6 with VisibleForTesting

use of org.jetbrains.annotations.VisibleForTesting in project midpoint by Evolveum.

the class ModelImplUtils method determineObjectDefinition.

@VisibleForTesting
public static ResourceObjectDefinition determineObjectDefinition(ResourceSchema refinedSchema, Task task) throws SchemaException {
    QName objectclass = getTaskExtensionPropertyValue(task, SchemaConstants.MODEL_EXTENSION_OBJECTCLASS);
    ShadowKindType kind = getTaskExtensionPropertyValue(task, SchemaConstants.MODEL_EXTENSION_KIND);
    String intent = getTaskExtensionPropertyValue(task, SchemaConstants.MODEL_EXTENSION_INTENT);
    return determineObjectClassInternal(refinedSchema, objectclass, kind, intent, task);
}
Also used : QName(javax.xml.namespace.QName) VisibleForTesting(org.jetbrains.annotations.VisibleForTesting)

Example 7 with VisibleForTesting

use of org.jetbrains.annotations.VisibleForTesting in project midpoint by Evolveum.

the class SimpleReportReader method createForLocalReportData.

@VisibleForTesting
@NotNull
public static SimpleReportReader createForLocalReportData(@NotNull String reportDataOid, @NotNull List<String> columns, @NotNull CommonTaskBeans beans, @NotNull OperationResult result) throws IOException, SchemaException, ObjectNotFoundException {
    var reportDataObject = beans.repositoryService.getObject(ReportDataType.class, reportDataOid, null, result);
    String filePath = MiscUtil.requireNonNull(reportDataObject.asObjectable().getFilePath(), () -> "No file in " + reportDataObject);
    return createFor(new FileInputStream(filePath), columns);
}
Also used : FileInputStream(java.io.FileInputStream) VisibleForTesting(org.jetbrains.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with VisibleForTesting

use of org.jetbrains.annotations.VisibleForTesting in project jetbrains-plugin by codiga.

the class JavascriptDependency method getDependenciesFromInputStream.

@VisibleForTesting
@Override
public List<Dependency> getDependenciesFromInputStream(InputStream inputStream) {
    List<Dependency> result = new ArrayList<>();
    try {
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        JsonElement jsonElement = JsonParser.parseReader(inputStreamReader);
        if (!jsonElement.isJsonObject()) {
            return ImmutableList.of();
        }
        JsonElement dependenciesElement = jsonElement.getAsJsonObject().get("dependencies");
        if (dependenciesElement == null || !dependenciesElement.isJsonObject()) {
            return ImmutableList.of();
        }
        JsonObject dependencies = dependenciesElement.getAsJsonObject();
        for (Map.Entry<String, JsonElement> entry : dependencies.entrySet()) {
            result.add(new Dependency(entry.getKey(), Optional.empty()));
        }
        return result;
    } catch (UnsupportedEncodingException | JsonIOException | JsonSyntaxException e) {
        LOGGER.info("JavascriptDependency - getDependenciesFromInputStream - error when parsing the JSON file");
        return ImmutableList.of();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Dependency(io.codiga.plugins.jetbrains.model.Dependency) Map(java.util.Map) VisibleForTesting(org.jetbrains.annotations.VisibleForTesting)

Example 9 with VisibleForTesting

use of org.jetbrains.annotations.VisibleForTesting in project jetbrains-plugin by codiga.

the class PhpDependency method getDependenciesFromInputStream.

@VisibleForTesting
@Override
public List<Dependency> getDependenciesFromInputStream(InputStream inputStream) {
    Set<Dependency> result = new HashSet<>();
    try {
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        JsonElement jsonElement = JsonParser.parseReader(inputStreamReader);
        if (!jsonElement.isJsonObject()) {
            return ImmutableList.of();
        }
        JsonElement requireElement = jsonElement.getAsJsonObject().get("require");
        JsonElement requireDevElement = jsonElement.getAsJsonObject().get("require-dev");
        if (requireElement != null && requireElement.isJsonObject()) {
            JsonObject dependencies = requireElement.getAsJsonObject();
            for (Map.Entry<String, JsonElement> entry : dependencies.entrySet()) {
                result.add(new Dependency(entry.getKey(), Optional.empty()));
            }
        }
        if (requireDevElement != null && requireDevElement.isJsonObject()) {
            JsonObject dependencies = requireDevElement.getAsJsonObject();
            for (Map.Entry<String, JsonElement> entry : dependencies.entrySet()) {
                result.add(new Dependency(entry.getKey(), Optional.empty()));
            }
        }
        return new ArrayList<>(result);
    } catch (UnsupportedEncodingException | JsonIOException | JsonSyntaxException e) {
        LOGGER.info("PhpDependency - getDependenciesFromInputStream - error when parsing the JSON file");
        return ImmutableList.of();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Dependency(io.codiga.plugins.jetbrains.model.Dependency) VisibleForTesting(org.jetbrains.annotations.VisibleForTesting)

Example 10 with VisibleForTesting

use of org.jetbrains.annotations.VisibleForTesting in project activej by activej.

the class CubeUplinkMySql method fetchChunkDiffs.

@VisibleForTesting
CubeDiff fetchChunkDiffs(Connection connection, long from, long to) throws SQLException, MalformedDataException {
    CubeDiff cubeDiff;
    try (PreparedStatement ps = connection.prepareStatement(sql("" + "SELECT `id`, `aggregation`, `measures`, `min_key`, `max_key`, `item_count`," + " ISNULL(`removed_revision`) OR `removed_revision`>? " + "FROM {chunk} " + "WHERE " + "(`removed_revision` BETWEEN ? AND ? AND `added_revision`<?)" + " OR " + "(`added_revision` BETWEEN ? AND ? AND (`removed_revision` IS NULL OR `removed_revision`>?))"))) {
        from++;
        ps.setLong(1, to);
        ps.setLong(2, from);
        ps.setLong(3, to);
        ps.setLong(4, from);
        ps.setLong(5, from);
        ps.setLong(6, to);
        ps.setLong(7, to);
        ResultSet resultSet = ps.executeQuery();
        Map<String, Tuple2<Set<AggregationChunk>, Set<AggregationChunk>>> aggregationDiffs = new HashMap<>();
        while (resultSet.next()) {
            long chunkId = resultSet.getLong(1);
            String aggregationId = resultSet.getString(2);
            List<String> measures = measuresFromString(resultSet.getString(3));
            measuresValidator.validate(aggregationId, measures);
            JsonCodec<PrimaryKey> codec = primaryKeyCodecs.getCodec(aggregationId);
            if (codec == null) {
                throw new MalformedDataException("Unknown aggregation: " + aggregationId);
            }
            PrimaryKey minKey = fromJson(codec, resultSet.getString(4));
            PrimaryKey maxKey = fromJson(codec, resultSet.getString(5));
            int count = resultSet.getInt(6);
            boolean isAdded = resultSet.getBoolean(7);
            AggregationChunk chunk = AggregationChunk.create(chunkId, measures, minKey, maxKey, count);
            Tuple2<Set<AggregationChunk>, Set<AggregationChunk>> tuple = aggregationDiffs.computeIfAbsent(aggregationId, $ -> new Tuple2<>(new HashSet<>(), new HashSet<>()));
            if (isAdded) {
                tuple.getValue1().add(chunk);
            } else {
                tuple.getValue2().add(chunk);
            }
        }
        cubeDiff = CubeDiff.of(transformMap(aggregationDiffs, tuple -> AggregationDiff.of(tuple.getValue1(), tuple.getValue2())));
    }
    return cubeDiff;
}
Also used : Collectors.toSet(java.util.stream.Collectors.toSet) CubeDiff(io.activej.cube.ot.CubeDiff) PrimaryKey(io.activej.aggregation.PrimaryKey) MalformedDataException(io.activej.common.exception.MalformedDataException) AggregationChunk(io.activej.aggregation.AggregationChunk) Tuple2(io.activej.common.tuple.Tuple2) VisibleForTesting(org.jetbrains.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (org.jetbrains.annotations.VisibleForTesting)10 Dependency (io.codiga.plugins.jetbrains.model.Dependency)4 ArrayList (java.util.ArrayList)3 InputStreamReader (java.io.InputStreamReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 QName (javax.xml.namespace.QName)2 ASTNode (com.intellij.lang.ASTNode)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 AggregationChunk (io.activej.aggregation.AggregationChunk)1 PrimaryKey (io.activej.aggregation.PrimaryKey)1 MalformedDataException (io.activej.common.exception.MalformedDataException)1 Tuple2 (io.activej.common.tuple.Tuple2)1 CubeDiff (io.activej.cube.ot.CubeDiff)1 LogPositionDiff (io.activej.etl.LogPositionDiff)1 LogFile (io.activej.multilog.LogFile)1 LogPosition (io.activej.multilog.LogPosition)1 FileInputStream (java.io.FileInputStream)1