Search in sources :

Example 1 with VisibleForTesting

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

the class CubeUplinkMySql method fetchPositionDiffs.

@VisibleForTesting
Map<String, LogPositionDiff> fetchPositionDiffs(Connection connection, long from, long to) throws SQLException {
    Map<String, LogPositionDiff> positions = new HashMap<>();
    try (PreparedStatement ps = connection.prepareStatement(sql("" + "SELECT p.`partition_id`, p.`filename`, p.`remainder`, p.`position`, g.`to` " + "FROM (SELECT `partition_id`, MAX(`revision_id`) AS `max_revision`, `revision_id`>? as `to`" + " FROM {position}" + " WHERE `revision_id`<=?" + " GROUP BY `partition_id`, `to`) g " + "LEFT JOIN" + " {position} p " + "ON p.`partition_id` = g.`partition_id` " + "AND p.`revision_id` = g.`max_revision` " + "ORDER BY p.`partition_id`, `to`"))) {
        ps.setLong(1, from);
        ps.setLong(2, to);
        ResultSet resultSet = ps.executeQuery();
        LogPosition[] fromTo = new LogPosition[2];
        String currentPartition = null;
        while (resultSet.next()) {
            String partition = resultSet.getString(1);
            if (!partition.equals(currentPartition)) {
                fromTo[0] = null;
                fromTo[1] = null;
            }
            currentPartition = partition;
            String filename = resultSet.getString(2);
            int remainder = resultSet.getInt(3);
            long position = resultSet.getLong(4);
            boolean isTo = resultSet.getBoolean(5);
            LogFile logFile = new LogFile(filename, remainder);
            LogPosition logPosition = LogPosition.create(logFile, position);
            if (isTo) {
                if (fromTo[0] == null) {
                    fromTo[0] = LogPosition.initial();
                }
                fromTo[1] = logPosition;
            } else {
                fromTo[0] = logPosition;
                fromTo[1] = null;
                continue;
            }
            LogPositionDiff logPositionDiff = new LogPositionDiff(fromTo[0], fromTo[1]);
            positions.put(partition, logPositionDiff);
        }
    }
    return positions;
}
Also used : LogFile(io.activej.multilog.LogFile) LogPositionDiff(io.activej.etl.LogPositionDiff) LogPosition(io.activej.multilog.LogPosition) VisibleForTesting(org.jetbrains.annotations.VisibleForTesting)

Example 2 with VisibleForTesting

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

the class PythonDependency method getDependenciesFromInputStream.

@VisibleForTesting
@Override
public List<Dependency> getDependenciesFromInputStream(InputStream inputStream) {
    List<Dependency> result = new ArrayList<>();
    String pattern = "^([a-zA-Z0-9\\-]+)";
    Pattern r = Pattern.compile(pattern);
    try {
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            Matcher m = r.matcher(line);
            if (m.find()) {
                result.add(new Dependency(m.group(0), Optional.empty()));
            }
        }
        return result;
    } catch (IOException e) {
        LOGGER.info("PythonDependency - getDependenciesFromInputStream - error when parsing the file");
        return ImmutableList.of();
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Dependency(io.codiga.plugins.jetbrains.model.Dependency) VisibleForTesting(org.jetbrains.annotations.VisibleForTesting)

Example 3 with VisibleForTesting

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

the class RubyDependency method getDependenciesFromInputStream.

@VisibleForTesting
@Override
public List<Dependency> getDependenciesFromInputStream(InputStream inputStream) {
    List<Dependency> result = new ArrayList<>();
    String pattern = "^\\s*gem\\s+[\\'|\\\"]([a-zA-Z0-9\\-]+)[\\'|\\\"]";
    Pattern r = Pattern.compile(pattern);
    try {
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            System.out.println(line);
            // if there is a comment, do not use
            if (line.contains("#")) {
                continue;
            }
            Matcher m = r.matcher(line);
            if (m.find()) {
                result.add(new Dependency(m.group(1), Optional.empty()));
            }
        }
        return result;
    } catch (IOException e) {
        LOGGER.info("PythonDependency - getDependenciesFromInputStream - error when parsing the file");
        return ImmutableList.of();
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Dependency(io.codiga.plugins.jetbrains.model.Dependency) VisibleForTesting(org.jetbrains.annotations.VisibleForTesting)

Example 4 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 5 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)

Aggregations

VisibleForTesting (org.jetbrains.annotations.VisibleForTesting)9 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 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 Map (java.util.Map)1