Search in sources :

Example 16 with AuthorData

use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.

the class EmailDataUtil method _createDataModelForAuthorFollowEmail.

private static Object[] _createDataModelForAuthorFollowEmail(String userAuthorId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    // Hack
    Long userId = Long.parseLong(userAuthorId.substring(0, userAuthorId.indexOf("-")));
    Long authorId = Long.parseLong(userAuthorId.substring(userAuthorId.indexOf("-") + 1));
    logger.log(Level.INFO, "userId::" + userId);
    logger.log(Level.INFO, "authorId::" + authorId);
    UserData user = UserDataUtil.createUserData(dataAccessor.getUser(userId));
    AuthorData follower = AuthorDataUtil.createAuthorData(dataAccessor.getAuthorByUserId(userId));
    Map<String, Object> dataModel = new HashMap<>();
    dataModel.put("follower_name", follower.getName() != null ? follower.getName() : follower.getNameEn());
    dataModel.put("follower_page_url", _getDomainName(follower.getLanguage()) + follower.getPageUrl());
    dataModel.put("follower_profile_image_url", follower.getProfileImageUrl(50));
    return new Object[] { dataModel, user.getLanguage() };
}
Also used : UserData(com.pratilipi.data.client.UserData) HashMap(java.util.HashMap) DataAccessor(com.pratilipi.data.DataAccessor) AuthorData(com.pratilipi.data.client.AuthorData)

Example 17 with AuthorData

use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.

the class UserV1Api method post.

@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
    UserData userData = request.userId == null ? new UserData(AccessTokenFilter.getAccessToken().getUserId()) : new UserData(request.userId.equals(0L) ? null : request.userId);
    if (request.hasName) {
        String firstName = request.name.trim();
        String lastName = null;
        if (firstName.lastIndexOf(' ') != -1) {
            lastName = firstName.substring(firstName.lastIndexOf(' ') + 1);
            firstName = firstName.substring(0, firstName.lastIndexOf(' '));
        }
        userData.setFirstName(firstName);
        userData.setLastName(lastName);
    }
    if (request.hasEmail)
        userData.setEmail(request.email);
    if (request.hasPhone)
        userData.setPhone(request.phone);
    if (request.hasLanguage)
        userData.setLanguage(request.language);
    // Save UserData
    userData = UserDataUtil.saveUserData(userData);
    // New User (added by AEE)
    if (request.userId != null && request.userId.equals(0L)) {
        // Create Author profile for the User
        Long authorId = AuthorDataUtil.createAuthorProfile(userData, request.language == null ? UxModeFilter.getFilterLanguage() : request.language);
        userData.setAuthor(new AuthorData(authorId));
        userData.setProfilePageUrl("/author/" + authorId);
        // Send welcome mail to the user
        Task task = TaskQueueFactory.newTask().setUrl("/user/email").addParam("userId", userData.getId().toString()).addParam("language", request.language == null ? UxModeFilter.getDisplayLanguage().toString() : request.language.toString()).addParam("sendWelcomeMail", "true");
        TaskQueueFactory.getUserTaskQueue().add(task);
    }
    return new Response(userData);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) Task(com.pratilipi.taskqueue.Task) UserData(com.pratilipi.data.client.UserData) AuthorData(com.pratilipi.data.client.AuthorData) Post(com.pratilipi.api.annotation.Post)

Aggregations

AuthorData (com.pratilipi.data.client.AuthorData)17 DataAccessor (com.pratilipi.data.DataAccessor)8 UserData (com.pratilipi.data.client.UserData)6 GenericResponse (com.pratilipi.api.shared.GenericResponse)5 Get (com.pratilipi.api.annotation.Get)3 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)3 Gson (com.google.gson.Gson)2 Post (com.pratilipi.api.annotation.Post)2 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)2 Author (com.pratilipi.data.type.Author)2 UserAuthor (com.pratilipi.data.type.UserAuthor)2 ArrayList (java.util.ArrayList)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 AuthorFilter (com.pratilipi.common.util.AuthorFilter)1 DocAccessor (com.pratilipi.data.DocAccessor)1 PratilipiData (com.pratilipi.data.client.PratilipiData)1 UserAuthorData (com.pratilipi.data.client.UserAuthorData)1 AccessToken (com.pratilipi.data.type.AccessToken)1 Page (com.pratilipi.data.type.Page)1