Lug3Resource.java
/*
* Copyright © 2013-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.resources.catalogue;
import java.util.List;
import org.ctan.site.domain.site.Lug;
import org.ctan.site.stores.LugStore;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.dropwizard.hibernate.UnitOfWork;
import jakarta.annotation.security.PermitAll;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import lombok.NonNull;
/**
* The class <code>Lug3Resource</code> contains the controller for the lugs
* resource.
*
* @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
*/
@Path("/3.0")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class Lug3Resource {
/**
* The field <code>store</code> contains the underlying repository.
*/
private LugStore store;
/**
* This is the constructor for the class <code>Lug3Resource</code>.
*
* @param store the underlying store
*/
@SuppressFBWarnings(value = {"CT_CONSTRUCTOR_THROW", "EI_EXPOSE_REP2"})
public Lug3Resource(@NonNull LugStore store) {
this.store = store;
}
/**
* The method <code>getAllLugs</code> provides means to retrieve a list of
* all lugs.
*
* @return a list of matching lug summaries
*/
@GET
@Path("/lugs")
@PermitAll
@UnitOfWork(value = "siteDb")
public List<Lug> getAllLugs() {
return store.findAllBy("");
}
// /**
// * The method <code>getLugByKey</code> provides means to find a LUG by its
// * unique key.
// *
// * @param key the key
// * @return
// */
// @GET
// @Path("/lug/{key}")
// @PermitAll
// @UnitOfWork(value = "siteDb")
// public Lug getLugByKey(@NonNull @PathParam("key") String key) {
//
// var lug = store.getByKey(key);
// if (lug == null) {
// throw new WebApplicationException(Status.NOT_FOUND);
// }
//
// return lug;
// }
/**
* The method <code>getLugs</code> provides means to retrieve a list of lugs
* starting with a given pattern.
*
* @param pattern the initial string of the key
* @return a list of matching lug summaries
*/
@GET
@Path("/lugs/{pattern}")
@PermitAll
@UnitOfWork(value = "siteDb")
public List<Lug> getLugs(@NonNull @PathParam("pattern") String pattern) {
return store.findAllBy(pattern);
}
}