raimund@441: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
raimund@441: * Software engineering by Intevation GmbH
raimund@441: *
rrenkert@628: * This file is Free Software under the GNU GPL (v>=3)
rrenkert@628: * and comes with ABSOLUTELY NO WARRANTY! Check out
rrenkert@628: * the documentation coming with IMIS-Labordaten-Application for details.
raimund@441: */
raimund@441: package de.intevation.lada.rest;
raimund@441:
raimund@450: import java.util.List;
raimund@572: import java.util.Map;
raimund@450:
raimund@700: import javax.ejb.EJBTransactionRolledbackException;
raimund@441: import javax.enterprise.context.RequestScoped;
raimund@441: import javax.inject.Inject;
raimund@455: import javax.json.JsonObject;
raimund@700: import javax.persistence.TransactionRequiredException;
raimund@582: import javax.servlet.http.HttpServletRequest;
raimund@450: import javax.ws.rs.DELETE;
raimund@441: import javax.ws.rs.GET;
raimund@450: import javax.ws.rs.POST;
raimund@450: import javax.ws.rs.PUT;
raimund@441: import javax.ws.rs.Path;
raimund@441: import javax.ws.rs.PathParam;
raimund@441: import javax.ws.rs.Produces;
raimund@441: import javax.ws.rs.core.Context;
raimund@441: import javax.ws.rs.core.HttpHeaders;
raimund@441: import javax.ws.rs.core.MediaType;
raimund@455: import javax.ws.rs.core.MultivaluedMap;
raimund@455: import javax.ws.rs.core.UriInfo;
raimund@441:
raimund@657: import de.intevation.lada.factory.ProbeFactory;
raimund@595: import de.intevation.lada.lock.LockConfig;
raimund@595: import de.intevation.lada.lock.LockType;
raimund@595: import de.intevation.lada.lock.ObjectLocker;
tom@1072: import de.intevation.lada.model.land.Messprogramm;
tom@1097: import de.intevation.lada.model.land.Probe;
raimund@455: import de.intevation.lada.query.QueryTools;
raimund@441: import de.intevation.lada.util.annotation.AuthorizationConfig;
raimund@441: import de.intevation.lada.util.annotation.RepositoryConfig;
raimund@441: import de.intevation.lada.util.auth.Authorization;
raimund@441: import de.intevation.lada.util.auth.AuthorizationType;
raimund@450: import de.intevation.lada.util.data.QueryBuilder;
raimund@441: import de.intevation.lada.util.data.Repository;
raimund@441: import de.intevation.lada.util.data.RepositoryType;
raimund@582: import de.intevation.lada.util.rest.RequestMethod;
raimund@441: import de.intevation.lada.util.rest.Response;
raimund@543: import de.intevation.lada.validation.Validator;
raimund@543: import de.intevation.lada.validation.Violation;
raimund@543: import de.intevation.lada.validation.annotation.ValidationConfig;
raimund@441:
raimund@451: /**
rrenkert@628: * REST service for Probe objects.
rrenkert@628: *
rrenkert@628: * The services produce data in the application/json media type.
rrenkert@628: * All HTTP methods use the authorization module to determine if the user is
rrenkert@628: * allowed to perform the requested action.
rrenkert@628: * A typical response holds information about the action performed and the data.
rrenkert@628: *
rrenkert@628: *
rrenkert@628: * {
rrenkert@628: * "success": [boolean];
rrenkert@628: * "message": [string],
rrenkert@628: * "data":[{
rrenkert@628: * "id":[number],
rrenkert@628: * "baId": [string],
rrenkert@628: * "datenbasisId": [number],
rrenkert@628: * "letzteAenderung": [timestamp],
rrenkert@628: * "media": [string],
rrenkert@628: * "mediaDesk": [string],
rrenkert@628: * "mittelungsdauer": [number],
rrenkert@628: * "mstId": [string],
rrenkert@628: * "netzbetreiberId":[string],
rrenkert@628: * "probeentnahmeBeginn": [timestamp],
rrenkert@628: * "probeentnahmeEnde": [timestamp],
rrenkert@628: * "probenartId": [number],
rrenkert@628: * "test": [boolean],
rrenkert@628: * "umwId": [string],
rrenkert@628: * "hauptprobenNr": [string],
rrenkert@628: * "erzeugerId": [string],
rrenkert@628: * "mpKat": [string],
rrenkert@628: * "mplId": [number],
rrenkert@628: * "mprId": [number],
rrenkert@628: * "probeNehmerId": [number],
rrenkert@628: * "solldatumBeginn": [timestamp],
rrenkert@628: * "solldatumEnde": [timestamp],
rrenkert@628: * "treeModified": [timestamp],
rrenkert@628: * "readonly": [boolean],
rrenkert@628: * "owner": [boolean],
rrenkert@628: * "probeIdAlt": [string]
rrenkert@628: * }],
rrenkert@628: * "errors": [object],
rrenkert@628: * "warnings": [object],
rrenkert@628: * "readonly": [boolean],
rrenkert@628: * "totalCount": [number]
rrenkert@628: * }
rrenkert@628: *
rrenkert@628: *
raimund@451: *
raimund@451: * @author Raimund Renkert
raimund@451: */
raimund@827: @Path("rest/probe")
raimund@441: @RequestScoped
raimund@441: public class ProbeService {
raimund@441:
rrenkert@628: /**
rrenkert@628: * The data repository granting read/write access.
rrenkert@628: */
raimund@441: @Inject
raimund@441: @RepositoryConfig(type=RepositoryType.RW)
raimund@848: private Repository repository;
raimund@441:
rrenkert@628: /**
rrenkert@628: * The authorization module.
rrenkert@628: */
raimund@441: @Inject
raimund@722: @AuthorizationConfig(type=AuthorizationType.HEADER)
raimund@441: private Authorization authorization;
raimund@441:
rrenkert@628: /**
rrenkert@628: * The object lock mechanism.
rrenkert@628: */
raimund@543: @Inject
raimund@595: @LockConfig(type=LockType.TIMESTAMP)
raimund@595: private ObjectLocker lock;
raimund@595:
rrenkert@628: /**
raimund@657: * The validator used for Probe objects.
rrenkert@628: */
raimund@595: @Inject
raimund@543: @ValidationConfig(type="Probe")
raimund@543: private Validator validator;
raimund@543:
raimund@451: /**
raimund@657: * The factory to create Probe objects.
raimund@657: * Used for messprogramm.
raimund@657: */
raimund@657: @Inject
raimund@657: private ProbeFactory factory;
raimund@657:
raimund@848: @Inject
raimund@848: private QueryTools queryTools;
raimund@848:
raimund@657: /**
rrenkert@628: * Get all Probe objects.
rrenkert@628: *
rrenkert@628: * The requested objects can be filtered using the following URL
rrenkert@628: * parameters:
rrenkert@628: * * qid: The id of the query.
rrenkert@628: * * page: The page to display in a paginated result grid.
rrenkert@628: * * start: The first Probe item.
rrenkert@628: * * limit: The count of Probe items.
rrenkert@628: * * sort: Sort the result ascending(ASC) or descenting (DESC).
rrenkert@628: *
rrenkert@628: * The response data contains a stripped set of Probe objects. The returned fields
rrenkert@628: * are defined in the query used in the request.
rrenkert@628: *
rrenkert@628: * Example:
rrenkert@628: * http://example.com/probe?qid=[ID]&page=[PAGE]&start=[START]&limit=[LIMIT]&sort=[{"property":"probeId","direction":"ASC"}]
raimund@451: *
rrenkert@628: * @return Response object containing all Probe objects.
raimund@451: */
raimund@455: @SuppressWarnings("unchecked")
raimund@441: @GET
raimund@441: @Path("/")
raimund@441: @Produces("application/json")
raimund@455: public Response get(
raimund@455: @Context HttpHeaders headers,
raimund@582: @Context UriInfo info,
raimund@582: @Context HttpServletRequest request
raimund@455: ) {
raimund@455: MultivaluedMap params = info.getQueryParameters();
raimund@455: if (params.isEmpty() || !params.containsKey("qid")) {
tom@1097: return repository.getAll(Probe.class, "land");
raimund@455: }
raimund@848: Integer id = null;
raimund@455: try {
raimund@848: id = Integer.valueOf(params.getFirst("qid"));
raimund@455: }
raimund@848: catch (NumberFormatException e) {
raimund@848: return new Response(false, 603, "Not a valid filter id");
raimund@455: }
raimund@572: List