/***************************************************************************************** Infosistema - OpenBaas Copyright(C) 2002-2014 Infosistema, S.A. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. www.infosistema.com info@openbaas.com Av. José Gomes Ferreira, 11 3rd floor, s.34 Miraflores 1495-139 Algés Portugal ****************************************************************************************/ package infosistema.openbaas.rest; import infosistema.openbaas.data.Error; import infosistema.openbaas.data.ListResult; import infosistema.openbaas.data.QueryParameters; import infosistema.openbaas.data.enums.ModelEnum; import infosistema.openbaas.middleLayer.MediaMiddleLayer; import infosistema.openbaas.middleLayer.SessionMiddleLayer; import infosistema.openbaas.utils.Const; import infosistema.openbaas.utils.Utils; import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.Response.Status; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONObject; //@Path("/apps/{appId}/media") public class MediaResource { // private Map<String, Media> media = new HashMap<String, Media>(); private String appId; private SessionMiddleLayer sessionMid; private MediaMiddleLayer mediaMid; //static final int idGenerator = 3; public MediaResource(String appId) { this.appId = appId; this.sessionMid = SessionMiddleLayer.getInstance(); this.mediaMid = MediaMiddleLayer.getInstance(); } // *** CREATE *** // // *** UPDATE *** // // *** DELETE *** // // *** GET LIST *** // /** * Gets all the users in the application. * * @return */ @GET @Produces(MediaType.APPLICATION_JSON) public Response find(@Context UriInfo ui, @Context HttpHeaders hh, @QueryParam("show") JSONArray arrayShow, @QueryParam("query") JSONObject query, @QueryParam(Const.RADIUS) String radiusStr, @QueryParam(Const.LAT) String latitudeStr, @QueryParam(Const.LONG) String longitudeStr, @QueryParam(Const.ELEM_COUNT) String pageCount, @QueryParam(Const.ELEM_INDEX) String pageIndex, @QueryParam(Const.PAGE_NUMBER) String pageNumberStr, @QueryParam(Const.PAGE_SIZE) String pageSizeStr, @QueryParam(Const.ORDER_BY) String orderByStr, @QueryParam(Const.ORDER_BY) String orderTypeStr) { QueryParameters qp = QueryParameters.getQueryParameters(appId, null, query, radiusStr, latitudeStr, longitudeStr, pageNumberStr, pageSizeStr, orderByStr, orderTypeStr, ModelEnum.media,pageCount,pageIndex); Response response = null; String sessionToken = Utils.getSessionToken(hh); if (!sessionMid.checkAppForToken(sessionToken, appId)) return Response.status(Status.UNAUTHORIZED).entity(new Error("Action in wrong app: "+appId)).build(); int code = Utils.treatParametersAdmin(ui, hh); if (code == 1) { try { ListResult res = mediaMid.find(qp,arrayShow); response = Response.status(Status.OK).entity(res).build(); } catch (Exception e) { response = Response.status(Status.FORBIDDEN).entity(e.getMessage()).build(); } } else if (code == -2) { response = Response.status(Status.FORBIDDEN).entity("Invalid Session Token.").build(); } else if (code == -1) response = Response.status(Status.BAD_REQUEST).entity("Error handling the request.").build(); return response; } // *** GET *** // // *** DOWNLOAD *** // // *** RESOURCES *** // // *** OTHERS *** // }