Source code file content

Revision: 81

added a better presentation; see, i'm needing a service to full-scan puj's, and also some service to be able to filter them by institutions; also a good service to filter institutions by puj's. so that bidi selection could be bidi filter in fact.
» Project Revision History

» Checkout URL

arena / arena-http / src / main / java / com / kenai / puj / arena / http / PujHomeworkResource.java

Size: 3946 bytes, 1 line
package com.kenai.puj.arena.http;

import java.io.IOException;
import java.text.ParseException;
import java.util.Collection;
import java.util.List;

import javax.ejb.EJB;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;

import com.kenai.puj.arena.model.entity.PujHomeworkEntity;
import com.kenai.puj.arena.model.entity.PujUserDetailsEntity;
import com.kenai.puj.arena.model.entity.facade.EntityFacadeConstants;
import com.kenai.puj.arena.model.entity.facade.PujHomeworkFacade;
import com.kenai.puj.arena.model.entity.facade.PujUserDetailsFacade;
import com.sun.jersey.multipart.FormDataBodyPart;
import com.sun.jersey.multipart.FormDataParam;

@Path("{puj}/homework")
public class PujHomeworkResource {
	@Context
	SecurityContext security;

	@EJB
	private PujHomeworkFacade facade;

	@EJB
	private PujUserDetailsFacade userFacade;

	@GET
	@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Collection<PujHomeworkEntity> readAll(
			@QueryParam(EntityFacadeConstants.PARAM_START) @DefaultValue(EntityFacadeConstants.PARAM_START_DEFAULT_VALUE) int start,
			@QueryParam(EntityFacadeConstants.PARAM_MAX) @DefaultValue(EntityFacadeConstants.PARAM_MAX_DEFAULT_VALUE) int max,
			@PathParam("puj") String puj) {
		return facade.readAllByCompetition(puj, start, max);
	}

	@GET
	@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	@Path("{id}")
	public PujHomeworkEntity read(@PathParam("id") String id) {
		return facade.read(PujHomeworkEntity.class, id);
	}

	@DELETE
	@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	@Path("{id}")
	public void delete(@PathParam("puj") String name, @PathParam("id") String id) {
		facade.delete(PujHomeworkEntity.class, id);
	}

	@POST
	@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	@Path("{acronym}")
	public PujHomeworkEntity create(@PathParam("puj") String name,
			@PathParam("acronym") String acronym) {
		String login = security.getUserPrincipal().getName();
		PujUserDetailsEntity user = userFacade.read(PujUserDetailsEntity.class,
				login);
		PujHomeworkEntity entity = new PujHomeworkEntity();
		entity.setAcronym(acronym);
		// entity.getAuthor().add(user);
		return facade.create(entity);
	}

	@GET
	@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	@Path("{acronym}/author")
	public Collection<PujUserDetailsEntity> readHomeworkStudents(
			@PathParam("acronym") String homeworkAcronym,
			@PathParam("puj") String pujName, @QueryParam("role") String role) {
		return userFacade.readHomeworkAuthors(pujName, homeworkAcronym, role);
	}

	/** ------------ homework attachment --------------- */

	@POST
	@Path("{acronym}/file")
	@Consumes(MediaType.MULTIPART_FORM_DATA)
	public Response uploadAttachment(
			@FormDataParam("file") List<FormDataBodyPart> parts,
			@FormDataParam("submit") FormDataBodyPart submit)
			throws IOException, ParseException {

		System.out.println("XXXX: " + submit.getMediaType());
		System.out.println("XXXX: "
				+ submit.getHeaders().getFirst("Content-Type"));

		for (FormDataBodyPart bp : parts) {
			System.out.println(bp.getMediaType());
			System.out.println(bp.getHeaders().get("Content-Disposition"));
			System.out.println(bp.getParameterizedHeaders().getFirst(
					"Content-Disposition").getParameters().get("name"));
			bp.cleanup();
		}

		return Response.ok("file deleted").build();
	}

	@GET
	@Path("{acronym}/file")
	public byte[] downloadAttachment() {
		return null;
	}

	@DELETE
	@Path("{acronym}/file")
	public Response deleteAttachment() {
		return Response.ok("file deleted").build();
	}
}
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20100127.c5638cb)
 
 
loading
Please Confirm