Mercurial > lada > lada-server
view src/main/java/de/intevation/lada/rest/SProbenartService.java @ 321:5844d7457dde
Completed importer for LAF format. Ort objects still need some attention.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 23 Aug 2013 11:35:24 +0200 |
parents | d8a3d188046f |
children | 567ce7697fc7 |
line wrap: on
line source
package de.intevation.lada.rest; import java.util.ArrayList; import java.util.logging.Logger; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import de.intevation.lada.auth.Authentication; import de.intevation.lada.auth.AuthenticationException; import de.intevation.lada.data.Repository; import de.intevation.lada.model.SProbenart; /** * This class produces a RESTful service to read SProbenart objects. * * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> */ @Path("/probenart") @RequestScoped public class SProbenartService { /** * The Repository for SProbenart. */ @Inject @Named("readonlyrepository") private Repository repository; /** * The authorization module. */ @Inject @Named("ldapauth") private Authentication authentication; /** * The logger for this class */ @Inject private Logger logger; /** * Request all SProbenart objects. * * @return Response object. */ @GET @Produces("text/json") public Response findAll(@Context HttpHeaders headers) { try { if (authentication.isAuthorizedUser(headers)) { return repository.findAll(SProbenart.class); } return new Response(false, 699, new ArrayList<SProbenart>()); } catch(AuthenticationException ae) { return new Response(false, 699, new ArrayList<SProbenart>()); } } /** * Request a single SProbenart via its id. * * @param id The object id. * @param header The HTTP header containing authorization information. * @return Response object. */ @GET @Path("/{id}") @Produces("text/json") public Response findById( @PathParam("id") String id, @Context HttpHeaders headers ) { try { if (authentication.isAuthorizedUser(headers)) { return repository.findById(SProbenart.class, id); } return new Response(false, 699, new ArrayList<SProbenart>()); } catch(AuthenticationException ae) { return new Response(false, 699, new ArrayList<SProbenart>()); } } }