Search in sources :

Example 1 with ServiceException

use of org.apache.openmeetings.webservice.error.ServiceException in project openmeetings by apache.

the class FileWebService method add.

/**
 * to add a folder to the private drive, set parentId = 0 and isOwner to 1/true and
 * externalUserId/externalUserType to a valid user
 *
 * @param sid
 *            The SID of the User. This SID must be marked as logged in
 * @param file
 *            the The file to be added
 * @param stream
 *            the The file to be added
 * @return - Object created
 */
@WebMethod
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/")
public FileItemDTO add(@WebParam(name = "sid") @QueryParam("sid") String sid, @Multipart(value = "file", type = MediaType.APPLICATION_JSON) @WebParam(name = "file") FileItemDTO file, @Multipart(value = "stream", type = MediaType.APPLICATION_OCTET_STREAM, required = false) @WebParam(name = "stream") InputStream stream) {
    return performCall(sid, User.Right.Room, sd -> {
        FileItem f = file == null ? null : file.get();
        if (f == null || f.getId() != null) {
            throw new ServiceException("Bad id");
        }
        f.setInsertedBy(sd.getUserId());
        if (stream != null) {
            try {
                ProcessResultList result = fileProcessor.processFile(f, stream);
                if (result.hasError()) {
                    throw new ServiceException(result.getLogMessage());
                }
            } catch (Exception e) {
                throw new ServiceException(e.getMessage());
            }
        } else {
            f = fileDao.update(f);
        }
        return new FileItemDTO(f);
    });
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) FileItemDTO(org.apache.openmeetings.db.dto.file.FileItemDTO) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) ProcessResultList(org.apache.openmeetings.util.process.ProcessResultList) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with ServiceException

use of org.apache.openmeetings.webservice.error.ServiceException in project openmeetings by apache.

the class UserWebService method add.

/**
 * Adds a new User like through the Frontend, but also does activates the
 * Account To do SSO see the methods to create a hash and use those ones!
 *
 * @param sid
 *            The SID from getSession
 * @param user
 *            user object
 * @param confirm
 *            whatever or not to send email, leave empty for auto-send
 *
 * @return - id of the user added or error code
 */
@WebMethod
@POST
@Path("/")
public UserDTO add(@WebParam(name = "sid") @QueryParam("sid") String sid, @WebParam(name = "user") @FormParam("user") UserDTO user, @WebParam(name = "confirm") @FormParam("confirm") Boolean confirm) {
    return performCall(sid, User.Right.Soap, sd -> {
        User testUser = userDao.getExternalUser(user.getExternalId(), user.getExternalType());
        if (testUser != null) {
            throw new ServiceException("User does already exist!");
        }
        String tz = user.getTimeZoneId();
        if (Strings.isEmpty(tz)) {
            tz = getDefaultTimezone();
        }
        if (user.getAddress() == null) {
            user.setAddress(new Address());
            user.getAddress().setCountry(Locale.getDefault().getCountry());
        }
        if (user.getLanguageId() == null) {
            user.setLanguageId(1L);
        }
        IValidator<String> passValidator = new StrongPasswordValidator(true, getMinPasswdLength(cfgDao), user.get(userDao));
        Validatable<String> passVal = new Validatable<>(user.getPassword());
        passValidator.validate(passVal);
        if (!passVal.isValid()) {
            StringBuilder sb = new StringBuilder();
            for (IValidationError err : passVal.getErrors()) {
                sb.append(((ValidationError) err).getMessage()).append(System.lineSeparator());
            }
            log.debug("addNewUser::weak password '{}', msg: {}", user.getPassword(), sb);
            throw new ServiceException(sb.toString());
        }
        Object _user = userManager.registerUser(user.getLogin(), user.getPassword(), user.getLastname(), user.getFirstname(), user.getAddress().getEmail(), new Date(), user.getAddress().getStreet(), user.getAddress().getAdditionalname(), user.getAddress().getFax(), user.getAddress().getZip(), user.getAddress().getCountry(), user.getAddress().getTown(), user.getLanguageId(), // generate SIP Data if the config is enabled
        "", // generate SIP Data if the config is enabled
        false, // generate SIP Data if the config is enabled
        true, tz, confirm);
        if (_user == null) {
            throw new ServiceException(UNKNOWN.getMessage());
        } else if (_user instanceof String) {
            throw new ServiceException((String) _user);
        }
        User u = (User) _user;
        u.getRights().add(Right.Room);
        if (Strings.isEmpty(user.getExternalId()) && Strings.isEmpty(user.getExternalType())) {
            // activate the User
            u.getRights().add(Right.Login);
            u.getRights().add(Right.Dashboard);
        } else {
            u.setType(User.Type.external);
            u.setExternalId(user.getExternalId());
            u.setExternalType(user.getExternalType());
        }
        u = userDao.update(u, sd.getUserId());
        return new UserDTO(u);
    });
}
Also used : User(org.apache.openmeetings.db.entity.user.User) Address(org.apache.openmeetings.db.entity.user.Address) UserDTO(org.apache.openmeetings.db.dto.user.UserDTO) ExternalUserDTO(org.apache.openmeetings.db.dto.user.ExternalUserDTO) IValidationError(org.apache.wicket.validation.IValidationError) StrongPasswordValidator(org.apache.openmeetings.core.util.StrongPasswordValidator) Validatable(org.apache.wicket.validation.Validatable) Date(java.util.Date) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) RemoteSessionObject(org.apache.openmeetings.db.entity.server.RemoteSessionObject) ValidationError(org.apache.wicket.validation.ValidationError) IValidationError(org.apache.wicket.validation.IValidationError) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with ServiceException

use of org.apache.openmeetings.webservice.error.ServiceException in project openmeetings by apache.

the class RoomWebService method hash.

/**
 * Method to get invitation hash with given parameters
 *
 * @param sid - The SID of the User. This SID must be marked as Loggedin
 * @param invite - parameters of the invitation
 * @param sendmail - flag to determine if email should be sent or not
 * @return - serviceResult object with the result
 */
@WebMethod
@POST
@Path("/hash")
public ServiceResult hash(@WebParam(name = "sid") @QueryParam("sid") String sid, @WebParam(name = "invite") @QueryParam("invite") InvitationDTO invite, @WebParam(name = "sendmail") @QueryParam("sendmail") boolean sendmail) {
    log.debug("[hash] invite {}", invite);
    return performCall(sid, User.Right.Soap, sd -> {
        Invitation i = invite.get(sd.getUserId(), userDao, roomDao);
        i = inviteDao.update(i);
        if (i != null) {
            if (sendmail) {
                try {
                    inviteManager.sendInvitationLink(i, MessageType.Create, invite.getSubject(), invite.getMessage(), false);
                } catch (Exception e) {
                    throw new ServiceException(e.getMessage());
                }
            }
            return new ServiceResult(i.getHash(), Type.SUCCESS);
        } else {
            return new ServiceResult("error.unknown", Type.ERROR);
        }
    });
}
Also used : ServiceResult(org.apache.openmeetings.db.dto.basic.ServiceResult) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) Invitation(org.apache.openmeetings.db.entity.room.Invitation) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

WebMethod (javax.jws.WebMethod)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 ServiceException (org.apache.openmeetings.webservice.error.ServiceException)3 Date (java.util.Date)1 Consumes (javax.ws.rs.Consumes)1 StrongPasswordValidator (org.apache.openmeetings.core.util.StrongPasswordValidator)1 ServiceResult (org.apache.openmeetings.db.dto.basic.ServiceResult)1 FileItemDTO (org.apache.openmeetings.db.dto.file.FileItemDTO)1 ExternalUserDTO (org.apache.openmeetings.db.dto.user.ExternalUserDTO)1 UserDTO (org.apache.openmeetings.db.dto.user.UserDTO)1 FileItem (org.apache.openmeetings.db.entity.file.FileItem)1 Invitation (org.apache.openmeetings.db.entity.room.Invitation)1 RemoteSessionObject (org.apache.openmeetings.db.entity.server.RemoteSessionObject)1 Address (org.apache.openmeetings.db.entity.user.Address)1 User (org.apache.openmeetings.db.entity.user.User)1 ProcessResultList (org.apache.openmeetings.util.process.ProcessResultList)1 IValidationError (org.apache.wicket.validation.IValidationError)1 Validatable (org.apache.wicket.validation.Validatable)1 ValidationError (org.apache.wicket.validation.ValidationError)1