Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,4 @@

</plugins>
</build>
</project>
</project>
1 change: 0 additions & 1 deletion src/main/java/tw/kits/voicein/bean/ErrorMessageBean.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package tw.kits.voicein.bean;

public class ErrorMessageBean {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/tw/kits/voicein/bean/UserPhoneBean.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package tw.kits.voicein.bean;

import javax.validation.constraints.NotNull;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/tw/kits/voicein/model/Contact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package tw.kits.voicein.model;

import org.mongodb.morphia.annotations.*;
/**
*
* @author Calvin
*/
@Entity("contacts")
public class Contact {
//Field
@Id
private String parentUuid;
private String phoneNumber;

public Contact() {

}
}
108 changes: 108 additions & 0 deletions src/main/java/tw/kits/voicein/model/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package tw.kits.voicein.model;



import org.mongodb.morphia.annotations.*;
/**
*
* @author Calvin
*/
@Entity("accounts")
public class User {
@Id
private String uuid;
private String phoneNumber;
private String location;
private String profile;
private String company;
private String profilePhotoUrl;

/**
* @param uuid the uuid to set
*/
public void setUuid(String uuid) {
this.uuid = uuid;
}

/**
* @param phoneNumber the phoneNumber to set
*/
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

/**
* @return the uuid
*/
public String getUuid() {
return uuid;
}

/**
* @return the phoneNumber
*/
public String getPhoneNumber() {
return phoneNumber;
}

/**
* @return the location
*/
public String getLocation() {
return location;
}

/**
* @param location the location to set
*/
public void setLocation(String location) {
this.location = location;
}

/**
* @return the profile
*/
public String getProfile() {
return profile;
}

/**
* @param profile the profile to set
*/
public void setProfile(String profile) {
this.profile = profile;
}

/**
* @return the company
*/
public String getCompany() {
return company;
}

/**
* @param company the company to set
*/
public void setCompany(String company) {
this.company = company;
}

/**
* @return the profilePhotoUrl
*/
public String getProfilePhotoUrl() {
return profilePhotoUrl;
}

/**
* @param profilePhotoUrl the profilePhotoUrl to set
*/
public void setProfilePhotoUrl(String profilePhotoUrl) {
this.profilePhotoUrl = profilePhotoUrl;
}

@Override
public String toString() {
return "User [uuid=" + uuid + ", phoneNumber=" + phoneNumber + "] Saved!";
}
}
125 changes: 125 additions & 0 deletions src/main/java/tw/kits/voicein/resource/ApiV1/AccountsResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package tw.kits.voicein.resource.ApiV1;

import java.util.logging.*;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import tw.kits.voicein.util.MongoManager;
import org.mongodb.morphia.Datastore;

import tw.kits.voicein.model.User;
import tw.kits.voicein.model.Contact;

/**
* Accounts Resource
* @author Calvin
*/
@Path("/api/v1")
public class AccountsResource {
static final Logger LOGGER = Logger.getLogger("AccountsDebugLogging");
ConsoleHandler consoleHandler = new ConsoleHandler();

/**
* This API allows user to delete a user account by given uuid.
* @param uuid
* @return
*/
@DELETE
@Path("/accounts/{uuid}")
@Consumes(MediaType.APPLICATION_JSON)
public Response deleteUserAccount(@PathParam("uuid") String uuid) {
MongoManager mongoManager = MongoManager.getInstatnce();
Datastore dsObj = mongoManager.getDs();
dsObj.delete(User.class, uuid);

LOGGER.setLevel(Level.ALL);
consoleHandler.setLevel(Level.CONFIG);

LOGGER.addHandler(consoleHandler);
LOGGER.log(Level.CONFIG, "[Config] Delete user u{0}", uuid);

return Response.ok().build();
}

/**
* This API allows client to update user's information.
* @param uuid
* @param u
* @return response to the client
*/
@PUT
@Path("/accounts/{uuid}")
@Consumes(MediaType.APPLICATION_JSON)
//@Produces(MediaType.APPLICATION_JSON)
public Response updateUserAccount(@PathParam("uuid") String uuid, User u) {
MongoManager mongoManager = MongoManager.getInstatnce();
Datastore dsObj = mongoManager.getDs();

u.setUuid(uuid);
dsObj.save(u);

LOGGER.setLevel(Level.ALL);
consoleHandler.setLevel(Level.ALL);

LOGGER.addHandler(consoleHandler);
LOGGER.log(Level.CONFIG, "[Config] Update user u{0}", u);

return Response.ok().build();
}

/**
* This API allows client to retrieve user's full informations.
* @param uuid
* @return User
*/
@GET
@Path("/accounts/{uuid}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public User getUserAccount(@PathParam("uuid")String uuid) {
MongoManager mongoManager = MongoManager.getInstatnce();
Datastore dsObj = mongoManager.getDs();
User user = dsObj.get(User.class, uuid);

LOGGER.setLevel(Level.ALL);
consoleHandler.setLevel(Level.CONFIG);

LOGGER.addHandler(consoleHandler);
LOGGER.log(Level.CONFIG, "[Config] Get user u{0}", uuid);

return user;
}

/**
*
* @param uuid
* @return response
*/
@POST
@Path("/accounts/{uuid}/calls")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response makePhoneCall(@PathParam("uuid") String uuid) {
//TODO Call the phone API.
return Response.status(Status.OK).build();
}

@GET
@Path("/accounts/{uuid}/contacts")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Contact getContactListOfAnUser(@PathParam("uuid") String uuid) {
return new Contact();
}

@POST
@Path("/accounts/{uuid}/contacts")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createNewContactofAnUser(@PathParam("uuid") String uuid) {
return Response.ok().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

@Path("/api/v1")
public class WelcomeResource {

@GET
@Path("/")
@Produces(MediaType.TEXT_PLAIN)
public String index() {
return "API version: v1.";
return "<center>Voicein API Version: V1.<br/> 2016 built by Henry Chang and Calvin Jeng</center>";

}

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/tw/kits/voicein/util/MongoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,32 @@ public class MongoManager {
public final static String DB_NAME = "voicein";
public final static String DB_URI = "mongodb://hsnl-dev:hsnl33564hsnl33564@ds013908.mongolab.com:13908/voicein";
public final static String MAPPING_PACKAGE = "tw.kits.voicein.model";

private final Morphia morphia = new Morphia();

private String mongoUri;
private MongoClient mongo;

private MongoManager(){
morphia.mapPackage(MAPPING_PACKAGE);
MongoClientURI uri = new MongoClientURI(DB_URI);
mongo = new MongoClient(uri);
}

public String getMongoUri() {
return mongoUri;
}
public MongoClient getClient(){

public MongoClient getClient() {
return mongo;
}
public Datastore getDs(){

public Datastore getDs() {
return morphia.createDatastore(mongo, DB_NAME);
}

//singleton
public static MongoManager getInstatnce(){
public static MongoManager getInstatnce() {
if (instance == null){
synchronized (MongoManager.class){
if(instance == null){
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/META-INF/context.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/webservice"/>
<Context path="/voicein-api"/>
10 changes: 0 additions & 10 deletions src/main/webapp/WEB-INF/glassfish-web.xml

This file was deleted.