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() };
}
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());
}
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;
}
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);
}
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);
}
Aggregations