Search in sources :

Example 11 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();
    UserAuthor userAuthor = dataAccessor.getUserAuthor(userAuthorId);
    UserData user = UserDataUtil.createUserData(dataAccessor.getUser(userAuthor.getUserId()));
    AuthorData follower = AuthorDataUtil.createAuthorData(dataAccessor.getAuthorByUserId(userAuthor.getUserId()));
    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));
    if (follower.getFollowCount() > 0)
        dataModel.put("follower_followers_count", follower.getFollowCount());
    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) UserAuthor(com.pratilipi.data.type.UserAuthor)

Example 12 with AuthorData

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

the class AuthorDataUtil method getAuthorDataList.

public static DataListCursorTuple<AuthorData> getAuthorDataList(String searchQuery, AuthorFilter authorFilter, String cursor, Integer resultCount) throws InsufficientAccessException {
    if (!hasAccessToListAuthorData(authorFilter.getLanguage()))
        throw new InsufficientAccessException();
    // Processing search query
    if (searchQuery != null)
        searchQuery = searchQuery.toLowerCase().trim().replaceAll(",|\\sor\\s", " ").replaceAll("[\\s]+", " OR ");
    DataListCursorTuple<Long> authorIdListCursorTuple = DataAccessorFactory.getSearchAccessor().searchAuthor(searchQuery, authorFilter, cursor, null, resultCount);
    List<AuthorData> authorDataList = createAuthorDataList(authorIdListCursorTuple.getDataList(), true);
    return new DataListCursorTuple<AuthorData>(authorDataList, authorIdListCursorTuple.getCursor());
}
Also used : DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) AuthorData(com.pratilipi.data.client.AuthorData) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException)

Example 13 with AuthorData

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

the class AuthorDataUtil method createAuthorData.

public static AuthorData createAuthorData(Author author, Page authorPage, User user) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    if (authorPage == null)
        authorPage = dataAccessor.getPage(PageType.AUTHOR, author.getId());
    AuthorData authorData = createAuthorData(author, authorPage);
    if (user == null)
        authorData.setUser(UserDataUtil.createUserData(dataAccessor.getUser(author.getUserId()), null));
    else
        authorData.setUser(UserDataUtil.createUserData(user, null));
    return authorData;
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) AuthorData(com.pratilipi.data.client.AuthorData)

Example 14 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);
    }
    // Send verification mail if user updates his email and state is REGISTERED
    if (request.hasEmail && userData.getState() == UserState.REGISTERED) {
        Task task = TaskQueueFactory.newTask().setUrl("/user/email").addParam("userId", userData.getId().toString()).addParam("language", (userData.getLanguage() == null ? Language.ENGLISH : userData.getLanguage()).toString()).addParam("sendEmailVerificationMail", "true");
        TaskQueueFactory.getUserTaskQueue().add(task);
    }
    // Process Author data
    Task task = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", userData.getAuthor().getId().toString()).addParam("processData", "true");
    TaskQueueFactory.getAuthorTaskQueue().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)

Example 15 with AuthorData

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

the class UserV2Api method get.

@Get
public Response get(GetRequest request) throws InsufficientAccessException {
    if (request.userId == null || request.userId.equals(UserDataUtil.getCurrentUser().getId()))
        return new Response(UserDataUtil.getCurrentUser(), UserV2Api.class);
    if (!UserAccessUtil.hasUserAccess(UserDataUtil.getCurrentUser().getId(), UxModeFilter.getWebsite().getFilterLanguage(), AccessType.AUTHOR_ADD))
        throw new InsufficientAccessException();
    UserData userData = UserDataUtil.createUserData(DataAccessorFactory.getDataAccessor().getUser(request.userId), null);
    userData.setAuthor(new AuthorData());
    return new Response(userData, UserV2Api.class);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) UserData(com.pratilipi.data.client.UserData) AuthorData(com.pratilipi.data.client.AuthorData) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) Get(com.pratilipi.api.annotation.Get)

Aggregations

AuthorData (com.pratilipi.data.client.AuthorData)15 DataAccessor (com.pratilipi.data.DataAccessor)7 UserData (com.pratilipi.data.client.UserData)6 GenericResponse (com.pratilipi.api.shared.GenericResponse)5 Author (com.pratilipi.data.type.Author)4 ArrayList (java.util.ArrayList)4 Get (com.pratilipi.api.annotation.Get)3 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)3 Page (com.pratilipi.data.type.Page)3 UserAuthor (com.pratilipi.data.type.UserAuthor)3 Post (com.pratilipi.api.annotation.Post)2 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)2 User (com.pratilipi.data.type.User)2 Task (com.pratilipi.taskqueue.Task)2 HashMap (java.util.HashMap)2 Gson (com.google.gson.Gson)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