CatalogueUpdateTask.java

/*
 * Copyright © 2024-2025 The CTAN Team and individual authors
 *
 * This file is distributed under the 3-clause BSD license.
 * See file LICENSE for details.
 */
package org.ctan.site.tasks;

import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import org.ctan.site.services.catalogue.CatalogueImportService;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.dropwizard.servlets.tasks.Task;
import lombok.NonNull;

/**
 * The class <code>CatalogueUpdateTask</code> contains the task to start the
 * update action from the catalogue XML files.
 *
 * @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
 */
public class CatalogueUpdateTask extends Task {

    /**
     * The field <code>service</code> contains the underlying service.
     */
    private CatalogueImportService service;

    /**
     * This is the constructor for <code>CatalogueUpdateTask</code>.
     *
     * @param service the underlying service
     */
    @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW")
    public CatalogueUpdateTask(@NonNull CatalogueImportService service) {

        super("catalogue-update");
        this.service = service;
    }

    /**
     * {@inheritDoc}
     *
     * @see io.dropwizard.servlets.tasks.Task#execute(java.util.Map,
     *     java.io.PrintWriter)
     */
    @Override
    public void execute(Map<String, List<String>> parameters,
        PrintWriter output)
        throws Exception {

        output.print("### Catalogue Update Task ####\n");
        service.update();
        output.print("### Catalogue Update Completed ####\n");
    }
}