Biblioteca Java - Rev 30
Subversion Repositories:
(root)/Frameworks and Technologies/RestJersey/com.linkscreens.userprofile/src/main/java/com/linkscreens/userprofile/webservice/UserProfileResource.java @ 34
package com.linkscreens.userprofile.webservice;
import net.vz.mongodb.jackson.JacksonDBCollection;
import net.vz.mongodb.jackson.WriteResult;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import com.linkscreens.userprofile.UserProfileServer;
import com.linkscreens.userprofile.entity.UserProfile;
import java.util.List;
@Path("/")
public class UserProfileResource {
private JacksonDBCollection<UserProfile, String> getJacksonDBCollection() {
return JacksonDBCollection.wrap(UserProfileServer.mongoDB.getCollection(UserProfile.class.getSimpleName().toLowerCase()), UserProfile.class, String.class);
}
@Path("profile")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public UserProfile addProfile(UserProfile bar) {
WriteResult<UserProfile, String> result = getJacksonDBCollection().insert(bar);
return result.getSavedObject();
}
@Path("profile")
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<UserProfile> getAllProfiles() {
return getJacksonDBCollection().find().toArray();
}
}
import net.vz.mongodb.jackson.JacksonDBCollection;
import net.vz.mongodb.jackson.WriteResult;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import com.linkscreens.userprofile.UserProfileServer;
import com.linkscreens.userprofile.entity.UserProfile;
import java.util.List;
@Path("/")
public class UserProfileResource {
private JacksonDBCollection<UserProfile, String> getJacksonDBCollection() {
return JacksonDBCollection.wrap(UserProfileServer.mongoDB.getCollection(UserProfile.class.getSimpleName().toLowerCase()), UserProfile.class, String.class);
}
@Path("profile")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public UserProfile addProfile(UserProfile bar) {
WriteResult<UserProfile, String> result = getJacksonDBCollection().insert(bar);
return result.getSavedObject();
}
@Path("profile")
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<UserProfile> getAllProfiles() {
return getJacksonDBCollection().find().toArray();
}
}