Search in sources :

Example 6 with AppointmentDTO

use of org.apache.openmeetings.db.dto.calendar.AppointmentDTO in project openmeetings by apache.

the class TestCalendarService method createEventWithGuests.

private static AppointmentDTO createEventWithGuests(String sid) throws Exception {
    JSONObject o = createAppointment("test").put("meetingMembers", new JSONArray().put(new JSONObject().put("user", new JSONObject().put("firstname", "John 1").put("lastname", "Doe").put("address", new JSONObject().put("email", "john1@doe.email")))).put(new JSONObject().put("user", new JSONObject().put("firstname", "John 2").put("lastname", "Doe").put("address", new JSONObject().put("email", "john2@doe.email")))));
    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());
    assertEquals("DTO should have 2 attendees", 2, dto.getMeetingMembers().size());
    for (MeetingMemberDTO mm : dto.getMeetingMembers()) {
        assertNotNull("Email should be valid", mm.getUser().getAddress().getEmail());
    }
    return dto;
}
Also used : Response(javax.ws.rs.core.Response) JSONObject(com.github.openjson.JSONObject) Form(javax.ws.rs.core.Form) JSONArray(com.github.openjson.JSONArray) AppointmentDTO(org.apache.openmeetings.db.dto.calendar.AppointmentDTO) MeetingMemberDTO(org.apache.openmeetings.db.dto.calendar.MeetingMemberDTO)

Example 7 with AppointmentDTO

use of org.apache.openmeetings.db.dto.calendar.AppointmentDTO in project openmeetings by apache.

the class TestCalendarService method testCreateWithGuestsCleanOne.

@Test
public void testCreateWithGuestsCleanOne() throws Exception {
    String sid = loginNewUser();
    AppointmentDTO dto = createEventWithGuests(sid);
    List<MeetingMemberDTO> initialList = new ArrayList<>(dto.getMeetingMembers());
    MeetingMemberDao mmDao = getBean(MeetingMemberDao.class);
    MeetingMember mm = mmDao.get(initialList.get(initialList.size() - 1).getId());
    Long mmId = mm.getId(), mmUserId = mm.getUser().getId();
    String hash = mm.getInvitation().getHash();
    dto.getMeetingMembers().remove(initialList.size() - 1);
    // try to change MM list
    JSONObject o = AppointmentParamConverter.json(dto);
    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());
    dto = resp.readEntity(AppointmentDTO.class);
    assertNotNull("Valid DTO should be returned", dto);
    assertNotNull("DTO id should be valid", dto.getId());
    assertEquals("DTO should have 1 attendees", 1, dto.getMeetingMembers().size());
    assertNull("Meeting member should deleted", mmDao.get(mmId));
    assertNull("Invitation should deleted", getBean(InvitationDao.class).getByHash(hash, true, false));
    User uc = getBean(UserDao.class).get(mmUserId);
    assertNotNull("Meeting member user should not be deleted", uc);
    assertFalse("Meeting member user should not be deleted", uc.isDeleted());
}
Also used : 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) Form(javax.ws.rs.core.Form) ArrayList(java.util.ArrayList) MeetingMember(org.apache.openmeetings.db.entity.calendar.MeetingMember) MeetingMemberDao(org.apache.openmeetings.db.dao.calendar.MeetingMemberDao) Response(javax.ws.rs.core.Response) JSONObject(com.github.openjson.JSONObject) UserDao(org.apache.openmeetings.db.dao.user.UserDao) AppointmentDTO(org.apache.openmeetings.db.dto.calendar.AppointmentDTO) MeetingMemberDTO(org.apache.openmeetings.db.dto.calendar.MeetingMemberDTO) Test(org.junit.Test)

Example 8 with AppointmentDTO

use of org.apache.openmeetings.db.dto.calendar.AppointmentDTO in project openmeetings by apache.

the class CalendarWebService method save.

/**
 * Save an appointment
 *
 * @param sid
 *            The SID of the User. This SID must be marked as Loggedin
 * @param appointment
 *            calendar event
 *
 * @return - appointment saved
 */
@WebMethod
@POST
@Path("/")
public AppointmentDTO save(@QueryParam("sid") @WebParam(name = "sid") String sid, @FormParam("appointment") @WebParam(name = "appointment") AppointmentDTO appointment) {
    // Seems to be create
    log.debug("save SID: {}", sid);
    return performCall(sid, sd -> {
        User u = userDao.get(sd.getUserId());
        if (!AuthLevelUtil.hasUserLevel(u.getRights())) {
            log.error("save: not authorized");
            return false;
        }
        return AuthLevelUtil.hasWebServiceLevel(u.getRights()) || appointment.getOwner() == null || appointment.getOwner().getId().equals(u.getId());
    }, sd -> {
        User u = userDao.get(sd.getUserId());
        Appointment a = appointment.get(userDao, fileDao, dao, u);
        if (a.getRoom().getId() != null) {
            if (a.getRoom().isAppointment()) {
                a.getRoom().setIspublic(false);
            } else {
                a.setRoom(roomDao.get(a.getRoom().getId()));
            }
        }
        return new AppointmentDTO(dao.update(a, u.getId()));
    });
}
Also used : Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) User(org.apache.openmeetings.db.entity.user.User) AppointmentDTO(org.apache.openmeetings.db.dto.calendar.AppointmentDTO) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 9 with AppointmentDTO

use of org.apache.openmeetings.db.dto.calendar.AppointmentDTO in project openmeetings by apache.

the class AppointmentListMessageBodyWriter method writeTo.

@Override
public void writeTo(List<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);
    JSONArray rr = new JSONArray();
    for (AppointmentDTO dto : t) {
        rr.put(AppointmentParamConverter.json(dto));
    }
    writer.write(new JSONObject().put(ROOT, rr).toString());
    writer.flush();
}
Also used : JSONObject(com.github.openjson.JSONObject) JSONArray(com.github.openjson.JSONArray) AppointmentDTO(org.apache.openmeetings.db.dto.calendar.AppointmentDTO) OutputStreamWriter(java.io.OutputStreamWriter) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

AppointmentDTO (org.apache.openmeetings.db.dto.calendar.AppointmentDTO)9 JSONObject (com.github.openjson.JSONObject)7 JSONArray (com.github.openjson.JSONArray)5 Form (javax.ws.rs.core.Form)5 Response (javax.ws.rs.core.Response)5 User (org.apache.openmeetings.db.entity.user.User)4 AbstractJUnitDefaults.createUser (org.apache.openmeetings.AbstractJUnitDefaults.createUser)3 AbstractJUnitDefaults.getUser (org.apache.openmeetings.AbstractJUnitDefaults.getUser)3 GroupUser (org.apache.openmeetings.db.entity.user.GroupUser)3 Test (org.junit.Test)3 GroupDao (org.apache.openmeetings.db.dao.user.GroupDao)2 ServiceResult (org.apache.openmeetings.db.dto.basic.ServiceResult)2 MeetingMemberDTO (org.apache.openmeetings.db.dto.calendar.MeetingMemberDTO)2 Appointment (org.apache.openmeetings.db.entity.calendar.Appointment)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 WebMethod (javax.jws.WebMethod)1 POST (javax.ws.rs.POST)1