use of org.haiku.haikudepotserver.pkg.model.PkgIconConfiguration in project haikudepotserver by haiku.
the class PkgIconSpreadsheetJobRunner method run.
@Override
public void run(JobService jobService, PkgIconSpreadsheetJobSpecification specification) throws IOException {
Preconditions.checkArgument(null != jobService);
Preconditions.checkArgument(null != specification);
final ObjectContext context = serverRuntime.newContext();
// this will register the outbound data against the job.
JobDataWithByteSink jobDataWithByteSink = jobService.storeGeneratedData(specification.getGuid(), "download", MediaType.CSV_UTF_8.toString());
try (OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')) {
final List<PkgIconConfiguration> pkgIconConfigurations = pkgIconService.getInUsePkgIconConfigurations(context);
{
List<String> headings = new ArrayList<>();
headings.add("pkg-name");
headings.add("repository-codes");
headings.add("no-icons");
for (PkgIconConfiguration pkgIconConfiguration : pkgIconConfigurations) {
StringBuilder heading = new StringBuilder();
heading.append(pkgIconConfiguration.getMediaType().getCode());
if (null != pkgIconConfiguration.getSize()) {
heading.append("@");
heading.append(pkgIconConfiguration.getSize().toString());
}
headings.add(heading.toString());
}
writer.writeNext(headings.toArray(new String[headings.size()]));
}
// stream out the packages.
long startMs = System.currentTimeMillis();
LOGGER.info("will produce icon spreadsheet report");
long count = pkgService.eachPkg(context, false, pkg -> {
PkgSupplement pkgSupplement = pkg.getPkgSupplement();
List<String> cells = new ArrayList<>();
cells.add(pkg.getName());
cells.add(repositoryService.getRepositoriesForPkg(context, pkg).stream().map(Repository::getCode).collect(Collectors.joining(";")));
cells.add(pkg.getPkgSupplement().getPkgIcons().isEmpty() ? MARKER : "");
for (PkgIconConfiguration pkgIconConfiguration : pkgIconConfigurations) {
cells.add(pkgSupplement.getPkgIcon(pkgIconConfiguration.getMediaType(), pkgIconConfiguration.getSize()).map(pi -> MARKER).orElse(""));
}
writer.writeNext(cells.toArray(new String[cells.size()]));
return true;
});
LOGGER.info("did produce icon report for {} packages in {}ms", count, System.currentTimeMillis() - startMs);
}
}
use of org.haiku.haikudepotserver.pkg.model.PkgIconConfiguration in project haikudepotserver by haiku.
the class PkgIconServiceImpl method getInUsePkgIconConfigurations.
@Override
public List<PkgIconConfiguration> getInUsePkgIconConfigurations(ObjectContext objectContext) {
Preconditions.checkArgument(null != objectContext, "the object context must be supplied");
List<PkgIconConfiguration> result = new ArrayList<>();
for (MediaType mediaType : getInUsePkgIconMediaTypes(objectContext)) {
List<Integer> sizes = getInUsePkgIconSizes(objectContext, mediaType);
if (sizes.isEmpty()) {
result.add(new PkgIconConfiguration(mediaType, null));
} else {
for (Integer size : sizes) {
result.add(new PkgIconConfiguration(mediaType, size));
}
}
}
Collections.sort(result);
return result;
}
Aggregations