Search in sources :

Example 21 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class TestCalendarService method testCreateWithOmMm.

@Test
public void testCreateWithOmMm() throws Exception {
    JSONObject o = createAppointment("test").put("meetingMembers", new JSONArray().put(new JSONObject().put("user", new JSONObject().put("id", 1))));
    String uuid = UUID.randomUUID().toString();
    User u = getUser(uuid);
    u.getGroupUsers().add(new GroupUser(getBean(GroupDao.class).get(1L), u));
    u = createUser(getBean(UserDao.class), u);
    ServiceResult sr = login(u.getLogin(), createPass());
    Response resp = getClient(getCalendarUrl()).path("/").query("sid", sr.getMessage()).form(new Form().param("appointment", o.toString()));
    assertNotNull("Valid AppointmentDTO should be returned", resp);
    assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus());
    AppointmentDTO dto = resp.readEntity(AppointmentDTO.class);
    assertNotNull("Valid DTO should be returned", dto);
    assertNotNull("DTO id should be valid", dto.getId());
}
Also used : Response(javax.ws.rs.core.Response) User(org.apache.openmeetings.db.entity.user.User) AbstractJUnitDefaults.createUser(org.apache.openmeetings.AbstractJUnitDefaults.createUser) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) AbstractJUnitDefaults.getUser(org.apache.openmeetings.AbstractJUnitDefaults.getUser) ServiceResult(org.apache.openmeetings.db.dto.basic.ServiceResult) JSONObject(com.github.openjson.JSONObject) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) Form(javax.ws.rs.core.Form) JSONArray(com.github.openjson.JSONArray) AppointmentDTO(org.apache.openmeetings.db.dto.calendar.AppointmentDTO) GroupDao(org.apache.openmeetings.db.dao.user.GroupDao) Test(org.junit.Test)

Example 22 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class TestCalendarService method createApp.

private String createApp(String title) throws Exception {
    JSONObject o = createAppointment(title);
    String sid = loginNewUser();
    Response resp = getClient(getCalendarUrl()).path("/").query("sid", sid).form(new Form().param("appointment", o.toString()));
    assertNotNull("Valid AppointmentDTO should be returned", resp);
    assertEquals("Call should be successful", Response.Status.OK.getStatusCode(), resp.getStatus());
    AppointmentDTO dto = resp.readEntity(AppointmentDTO.class);
    assertNotNull("Valid DTO should be returned", dto);
    assertNotNull("DTO id should be valid", dto.getId());
    return sid;
}
Also used : Response(javax.ws.rs.core.Response) JSONObject(com.github.openjson.JSONObject) Form(javax.ws.rs.core.Form) AppointmentDTO(org.apache.openmeetings.db.dto.calendar.AppointmentDTO)

Example 23 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class AppointmentMessageBodyWriter method writeTo.

@Override
public void writeTo(AppointmentDTO t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream out) throws IOException {
    Writer writer = new OutputStreamWriter(out, UTF_8);
    writer.write(new JSONObject().put(ROOT, AppointmentParamConverter.json(t)).toString());
    writer.flush();
}
Also used : JSONObject(com.github.openjson.JSONObject) OutputStreamWriter(java.io.OutputStreamWriter) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 24 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class AppointmentParamConverter method fromString.

@Override
public AppointmentDTO fromString(String val) {
    JSONObject o = new JSONObject(val);
    if (o.has(ROOT)) {
        o = o.getJSONObject(ROOT);
    }
    AppointmentDTO a = new AppointmentDTO();
    a.setId(optLong(o, "id"));
    a.setTitle(o.optString("title"));
    a.setLocation(o.optString("location"));
    a.setOwner(UserDTO.get(o.optJSONObject("owner")));
    String tzId = a.getOwner() == null ? null : a.getOwner().getTimeZoneId();
    a.setStart(CalendarParamConverter.get(o.optString("start"), tzId));
    a.setEnd(CalendarParamConverter.get(o.optString("end"), tzId));
    a.setDescription(o.optString("description"));
    a.setInserted(DateParamConverter.get(o.optString("inserted")));
    a.setUpdated(DateParamConverter.get(o.optString("updated")));
    a.setDeleted(o.optBoolean("deleted"));
    a.setReminder(optEnum(Reminder.class, o, "reminder"));
    a.setRoom(RoomDTO.get(o.optJSONObject("room")));
    a.setIcalId(o.optString("icalId"));
    JSONArray mm = o.optJSONArray("meetingMembers");
    if (mm != null) {
        for (int i = 0; i < mm.length(); ++i) {
            a.getMeetingMembers().add(MeetingMemberDTO.get(mm.getJSONObject(i)));
        }
    }
    a.setLanguageId(o.optLong("languageId"));
    a.setPassword(o.optString("password"));
    a.setPasswordProtected(o.optBoolean("passwordProtected"));
    a.setConnectedEvent(o.optBoolean("connectedEvent"));
    a.setReminderEmailSend(o.optBoolean("reminderEmailSend"));
    return a;
}
Also used : Reminder(org.apache.openmeetings.db.entity.calendar.Appointment.Reminder) JSONObject(com.github.openjson.JSONObject) AppointmentDTO(org.apache.openmeetings.db.dto.calendar.AppointmentDTO) JSONArray(com.github.openjson.JSONArray)

Example 25 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class UserMessageBodyWriter method writeTo.

@Override
public void writeTo(UserDTO t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream out) throws IOException {
    Writer writer = new OutputStreamWriter(out, UTF_8);
    writer.write(new JSONObject().put(ROOT, UserParamConverter.json(t)).toString());
    writer.flush();
}
Also used : JSONObject(com.github.openjson.JSONObject) OutputStreamWriter(java.io.OutputStreamWriter) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

JSONObject (com.github.openjson.JSONObject)64 JSONArray (com.github.openjson.JSONArray)23 Test (org.junit.jupiter.api.Test)11 AppointmentDTO (org.apache.openmeetings.db.dto.calendar.AppointmentDTO)7 Client (org.apache.openmeetings.db.entity.basic.Client)7 ArrayList (java.util.ArrayList)6 Whiteboard (org.apache.openmeetings.db.dto.room.Whiteboard)6 NullStringer (org.apache.openmeetings.util.NullStringer)6 Form (javax.ws.rs.core.Form)5 Response (javax.ws.rs.core.Response)5 List (java.util.List)4 Map (java.util.Map)4 OutputStreamWriter (java.io.OutputStreamWriter)3 Writer (java.io.Writer)3 MessageBodyWriter (javax.ws.rs.ext.MessageBodyWriter)3 Room (org.apache.openmeetings.db.entity.room.Room)3 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)3 JSONFunction (org.apache.wicket.ajax.json.JSONFunction)3 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)3 JSONException (com.github.openjson.JSONException)2