Search in sources :

Example 1 with PkgIconConfiguration

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);
    }
}
Also used : PkgIconConfiguration(org.haiku.haikudepotserver.pkg.model.PkgIconConfiguration) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) CSVWriter(com.opencsv.CSVWriter) JobDataWithByteSink(org.haiku.haikudepotserver.job.model.JobDataWithByteSink) PkgSupplement(org.haiku.haikudepotserver.dataobjects.PkgSupplement) Repository(org.haiku.haikudepotserver.dataobjects.Repository) OutputStreamWriter(java.io.OutputStreamWriter) ArrayList(java.util.ArrayList) List(java.util.List) ObjectContext(org.apache.cayenne.ObjectContext)

Example 2 with PkgIconConfiguration

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;
}
Also used : PkgIconConfiguration(org.haiku.haikudepotserver.pkg.model.PkgIconConfiguration) MediaType(org.haiku.haikudepotserver.dataobjects.MediaType)

Aggregations

PkgIconConfiguration (org.haiku.haikudepotserver.pkg.model.PkgIconConfiguration)2 CSVWriter (com.opencsv.CSVWriter)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ObjectContext (org.apache.cayenne.ObjectContext)1 MediaType (org.haiku.haikudepotserver.dataobjects.MediaType)1 PkgSupplement (org.haiku.haikudepotserver.dataobjects.PkgSupplement)1 Repository (org.haiku.haikudepotserver.dataobjects.Repository)1 JobDataWithByteSink (org.haiku.haikudepotserver.job.model.JobDataWithByteSink)1