Skip to content

Commit d99cdd2

Browse files
committed
profile rest api skeleton
1 parent 55a586c commit d99cdd2

4 files changed

Lines changed: 278 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.restcomm.connect.http;
2+
3+
/*
4+
* TeleStax, Open Source Cloud Communications
5+
* Copyright 2011-2014, Telestax Inc and individual contributors
6+
* by the @authors tag.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation; either version 3 of
11+
* the License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>
20+
*
21+
*/
22+
23+
24+
import java.lang.annotation.ElementType;
25+
import java.lang.annotation.Retention;
26+
import java.lang.annotation.RetentionPolicy;
27+
import java.lang.annotation.Target;
28+
import javax.ws.rs.HttpMethod;
29+
30+
/**
31+
*
32+
* @author
33+
*/
34+
@Target({ElementType.METHOD})
35+
@Retention(RetentionPolicy.RUNTIME)
36+
@HttpMethod("PATCH")
37+
public @interface LINK {
38+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* TeleStax, Open Source Cloud Communications
3+
* Copyright 2011-2014, Telestax Inc and individual contributors
4+
* by the @authors tag.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation; either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>
18+
*
19+
*/
20+
package org.restcomm.connect.http;
21+
22+
import java.io.InputStream;
23+
import java.net.URI;
24+
import java.net.URISyntaxException;
25+
import javax.annotation.PostConstruct;
26+
import javax.servlet.ServletContext;
27+
import javax.servlet.http.HttpServletRequest;
28+
import javax.ws.rs.core.HttpHeaders;
29+
import javax.ws.rs.core.MediaType;
30+
import javax.ws.rs.core.Response;
31+
import javax.ws.rs.core.UriInfo;
32+
import org.apache.commons.configuration.Configuration;
33+
import org.restcomm.connect.dao.DaoManager;
34+
import org.restcomm.connect.dao.ProfileAssociationsDao;
35+
36+
public class ProfileEndpoint extends SecuredEndpoint {
37+
//TODO compose schema location
38+
protected static final String PROFILE_CONTENT_TYPE = "application/instance+json;schema=";
39+
protected static final String PROFILE_SCHEMA_CONTENT_TYPE = "application/schema+json";
40+
protected static final String LINK_HEADER = "Link";
41+
42+
protected Configuration runtimeConfiguration;
43+
protected Configuration rootConfiguration; // top-level configuration element
44+
//protected ProfilesDAO profileDao;
45+
protected ProfileAssociationsDao profileAssociationsDao;
46+
47+
public ProfileEndpoint() {
48+
super();
49+
}
50+
51+
// used for testing
52+
public ProfileEndpoint(ServletContext context, HttpServletRequest request) {
53+
super(context, request);
54+
}
55+
56+
@PostConstruct
57+
void init() {
58+
rootConfiguration = (Configuration) context.getAttribute(Configuration.class.getName());
59+
runtimeConfiguration = rootConfiguration.subset("runtime-settings");
60+
super.init(runtimeConfiguration);
61+
profileAssociationsDao = ((DaoManager) context.getAttribute(DaoManager.class.getName())).getProfileAssociationsDao();
62+
}
63+
64+
public Response getProfiles(UriInfo info) {
65+
66+
return Response.ok("{}", MediaType.APPLICATION_JSON).build();
67+
}
68+
69+
public Response unlinkProfile(String profileSid, HttpHeaders headers) {
70+
return Response.ok().build();
71+
}
72+
73+
public Response linkProfile(String profileSid, HttpHeaders headers) {
74+
return Response.ok().build();
75+
}
76+
77+
public Response deleteProfile(String profileSid) {
78+
return Response.ok().build();
79+
}
80+
81+
public Response updateProfile(String profileSid, InputStream body) {
82+
return Response.ok().build();
83+
}
84+
85+
public Response getProfile(String profileSid) {
86+
Response.ResponseBuilder ok = Response.ok();ok.header(LINK_HEADER, "http://cloud.restcomm.comm/Profiles/PO1234");
87+
return Response.ok().build();
88+
}
89+
90+
public Response createProfile(InputStream body) {
91+
Response response ;
92+
try {
93+
URI location = new URI("http://cloud.restcomm.comm/Profiles/PO1234");
94+
response = Response.created(location).build();
95+
} catch (URISyntaxException ex) {
96+
response = Response.serverError().build();
97+
}
98+
return response;
99+
}
100+
101+
public Response getProfileSchema() {
102+
return Response.ok("{}", PROFILE_SCHEMA_CONTENT_TYPE).build();
103+
}
104+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* TeleStax, Open Source Cloud Communications
3+
* Copyright 2011-2014, Telestax Inc and individual contributors
4+
* by the @authors tag.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation; either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>
18+
*
19+
*/
20+
package org.restcomm.connect.http;
21+
22+
import java.io.InputStream;
23+
import javax.ws.rs.Consumes;
24+
import javax.ws.rs.DELETE;
25+
import javax.ws.rs.GET;
26+
import javax.ws.rs.POST;
27+
import javax.ws.rs.PUT;
28+
import javax.ws.rs.Path;
29+
import javax.ws.rs.PathParam;
30+
import javax.ws.rs.Produces;
31+
import javax.ws.rs.core.Context;
32+
import javax.ws.rs.core.HttpHeaders;
33+
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
34+
import javax.ws.rs.core.Response;
35+
import javax.ws.rs.core.UriInfo;
36+
import org.restcomm.connect.commons.annotations.concurrency.ThreadSafe;
37+
38+
@Path("/Profiles")
39+
@ThreadSafe
40+
public class ProfileJsonEndpoint extends ProfileEndpoint {
41+
42+
@GET
43+
@Produces(APPLICATION_JSON)
44+
public Response getProfilesAsJson(@Context UriInfo info) {
45+
return getProfiles(info);
46+
}
47+
48+
@POST
49+
@Consumes(PROFILE_CONTENT_TYPE)
50+
@Produces(PROFILE_CONTENT_TYPE)
51+
public Response createProfileAsJson(InputStream body) {
52+
return createProfile(body);
53+
}
54+
55+
@Path("/{profileSid}")
56+
@GET
57+
@Produces(PROFILE_CONTENT_TYPE)
58+
public Response getProfileAsJson(@PathParam("profileSid") final String profileSid) {
59+
return getProfile(profileSid);
60+
}
61+
62+
@Path("/{profileSid}")
63+
@PUT
64+
@Consumes(PROFILE_CONTENT_TYPE)
65+
public Response updateProfileAsJson(@PathParam("profileSid") final String profileSid,
66+
InputStream body) {
67+
return updateProfile(profileSid, body);
68+
}
69+
70+
@Path("/{profileSid}")
71+
@DELETE
72+
public Response deleteProfileAsJson(@PathParam("profileSid") final String profileSid) {
73+
return deleteProfile(profileSid);
74+
}
75+
76+
@Path("/{profileSid}")
77+
@LINK
78+
public Response linkProfileAsJson(@PathParam("profileSid") final String profileSid,
79+
@Context HttpHeaders headers
80+
) {
81+
return linkProfile(profileSid, headers);
82+
}
83+
84+
@Path("/{profileSid}")
85+
@UNLINK
86+
public Response unlinkProfileAsJson(@PathParam("profileSid") final String profileSid,
87+
@Context HttpHeaders headers) {
88+
return unlinkProfile(profileSid, headers);
89+
}
90+
91+
@Path("/rc-profile-schema")
92+
@GET
93+
@Produces(PROFILE_SCHEMA_CONTENT_TYPE)
94+
public Response getProfileSchemaAsJson() {
95+
return getProfileSchema();
96+
}
97+
98+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.restcomm.connect.http;
2+
3+
/*
4+
* TeleStax, Open Source Cloud Communications
5+
* Copyright 2011-2014, Telestax Inc and individual contributors
6+
* by the @authors tag.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation; either version 3 of
11+
* the License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>
20+
*
21+
*/
22+
23+
24+
import java.lang.annotation.ElementType;
25+
import java.lang.annotation.Retention;
26+
import java.lang.annotation.RetentionPolicy;
27+
import java.lang.annotation.Target;
28+
import javax.ws.rs.HttpMethod;
29+
30+
/**
31+
*
32+
* @author
33+
*/
34+
@Target({ElementType.METHOD})
35+
@Retention(RetentionPolicy.RUNTIME)
36+
@HttpMethod("PATCH")
37+
public @interface UNLINK {
38+
}

0 commit comments

Comments
 (0)