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);
}
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);
}
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();
}
}
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();
}
}
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;
}
Aggregations