Search in sources :

Example 26 with User

use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.

the class EmailDataUtil method _updateUserEntity.

private static void _updateUserEntity(Long userId) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    User user = dataAccessor.getUser(userId);
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_UPDATE, user);
    user.setLastEmailedDate(new Date());
    user.setLastUpdated(new Date());
    user = dataAccessor.createOrUpdateUser(user, auditLog);
}
Also used : User(com.pratilipi.data.type.User) DataAccessor(com.pratilipi.data.DataAccessor) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 27 with User

use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.

the class ConversationDataUtil method saveMessage.

public static void saveMessage(ContactTeam team, Long userId, String name, String email, String phone, String message, JsonObject data) throws InvalidArgumentException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    User user = dataAccessor.getUser(userId);
    Author author = dataAccessor.getAuthorByUserId(userId);
    Conversation conversation = dataAccessor.getConversation(team, userId);
    if (conversation == null)
        dataAccessor.getConversation(team, email);
    if (conversation != null) {
    // Do Nothing !
    } else if (user != null && (user.getState() == UserState.ACTIVE || user.getState() == UserState.REGISTERED)) {
        // &&
        // conversation
        // ==
        // null
        conversation = dataAccessor.newConversation(team, userId);
        conversation.setCreator(userId);
        conversation.setCreatorName(name);
        conversation.setCreatorEmail(email);
        conversation.setCreatorPhone(phone);
        conversation.setCreationDate(new Date());
        List<ConversationUser> conversationUserList = new ArrayList<>(team.getUserIds().length + 1);
        conversationUserList.add(dataAccessor.newConversationUser(conversation.getId(), userId));
        for (Long recipientUserId : team.getUserIds()) conversationUserList.add(dataAccessor.newConversationUser(conversation.getId(), recipientUserId));
        conversation = dataAccessor.createOrUpdateConversation(conversation, conversationUserList);
    } else if (email != null) {
        // && conversation == null
        conversation = dataAccessor.newConversation(team, email);
        conversation.setCreatorName(name);
        conversation.setCreatorEmail(email);
        conversation.setCreatorPhone(phone);
        conversation.setCreationDate(new Date());
        List<ConversationUser> conversationUserList = new ArrayList<>(team.getUserIds().length + 1);
        for (Long recipientUserId : team.getUserIds()) conversationUserList.add(dataAccessor.newConversationUser(conversation.getId(), recipientUserId));
        conversation = dataAccessor.createOrUpdateConversation(conversation, conversationUserList);
    } else {
        throw new InvalidArgumentException("Valid 'email' is required.");
    }
    conversation.setLastUpdated(new Date());
    ConversationMessage conversationMessage = dataAccessor.newConversationMessage();
    conversationMessage.setConversationId(conversation.getId());
    conversationMessage.setCreatorId(userId);
    conversationMessage.setMessage(message);
    conversationMessage.setData(data);
    conversationMessage.setCreationDate(new Date());
    conversation = dataAccessor.createOrUpdateConversation(conversation, conversationMessage);
    String language = author != null ? author.getLanguage().getNameEn().toLowerCase() : null;
    try {
        ArrayList<String> receiverList = createReceiversId(team.name().toLowerCase(), language);
        createSupportMailTask(receiverList, userId.toString(), name, email, phone, message, data, team.name(), language);
    } catch (UnsupportedEncodingException | UnexpectedServerException e) {
        logger.log(Level.SEVERE, "Exception while creating conversation mail task");
        logger.log(Level.SEVERE, "User ID : " + userId);
        logger.log(Level.SEVERE, "Conversation Id : " + conversation.getId());
        e.printStackTrace();
    }
}
Also used : ConversationUser(com.pratilipi.data.type.ConversationUser) User(com.pratilipi.data.type.User) DataAccessor(com.pratilipi.data.DataAccessor) ConversationMessage(com.pratilipi.data.type.ConversationMessage) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Conversation(com.pratilipi.data.type.Conversation) Date(java.util.Date) InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) Author(com.pratilipi.data.type.Author) ArrayList(java.util.ArrayList) List(java.util.List) ConversationUser(com.pratilipi.data.type.ConversationUser)

Example 28 with User

use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.

the class AuthorDataUtil method updateAuthorSearchIndex.

public static void updateAuthorSearchIndex(Long authorId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    SearchAccessor searchAccessor = DataAccessorFactory.getSearchAccessor();
    Author author = dataAccessor.getAuthor(authorId);
    if (author.getState() == AuthorState.ACTIVE) {
        User user = author.getUserId() == null ? null : dataAccessor.getUser(author.getUserId());
        searchAccessor.indexAuthorData(createAuthorData(author), UserDataUtil.createUserData(user));
    } else {
        searchAccessor.deleteAuthorDataIndex(authorId);
    }
}
Also used : SearchAccessor(com.pratilipi.data.SearchAccessor) User(com.pratilipi.data.type.User) DataAccessor(com.pratilipi.data.DataAccessor) Author(com.pratilipi.data.type.Author)

Example 29 with User

use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.

the class DataAccessorGaeImpl method getUserByGoogleId.

@Override
public User getUserByGoogleId(String googleId) {
    String memcacheId = "DataStore.User-google::" + googleId;
    User user = memcache.get(memcacheId);
    if (user != null)
        return user;
    user = ObjectifyService.ofy().load().type(UserEntity.class).filter("GOOGLE_ID", googleId).filter("STATE !=", UserState.DELETED).order("STATE").order("SIGN_UP_DATE").first().now();
    if (user != null)
        memcache.put(memcacheId, user);
    return user;
}
Also used : ConversationUser(com.pratilipi.data.type.ConversationUser) User(com.pratilipi.data.type.User) ConversationUserEntity(com.pratilipi.data.type.gae.ConversationUserEntity) UserEntity(com.pratilipi.data.type.gae.UserEntity)

Example 30 with User

use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.

the class DataAccessorGaeImpl method getUserByFacebookId.

@Override
public User getUserByFacebookId(String facebookId) {
    String memcacheId = "DataStore.User-fb::" + facebookId;
    User user = memcache.get(memcacheId);
    if (user != null)
        return user;
    user = ObjectifyService.ofy().load().type(UserEntity.class).filter("FACEBOOK_ID", facebookId).filter("STATE !=", UserState.DELETED).order("STATE").order("SIGN_UP_DATE").first().now();
    if (user != null)
        memcache.put(memcacheId, user);
    return user;
}
Also used : ConversationUser(com.pratilipi.data.type.ConversationUser) User(com.pratilipi.data.type.User) ConversationUserEntity(com.pratilipi.data.type.gae.ConversationUserEntity) UserEntity(com.pratilipi.data.type.gae.UserEntity)

Aggregations

User (com.pratilipi.data.type.User)30 DataAccessor (com.pratilipi.data.DataAccessor)22 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)9 AuditLog (com.pratilipi.data.type.AuditLog)8 UserData (com.pratilipi.data.client.UserData)7 UserEntity (com.pratilipi.data.type.gae.UserEntity)7 Date (java.util.Date)7 Author (com.pratilipi.data.type.Author)6 ConversationUser (com.pratilipi.data.type.ConversationUser)5 ArrayList (java.util.ArrayList)5 JsonObject (com.google.gson.JsonObject)4 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)4 ConversationUserEntity (com.pratilipi.data.type.gae.ConversationUserEntity)4 GenericResponse (com.pratilipi.api.shared.GenericResponse)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 HashMap (java.util.HashMap)3 Get (com.pratilipi.api.annotation.Get)2 BlobAccessor (com.pratilipi.data.BlobAccessor)2 DocAccessor (com.pratilipi.data.DocAccessor)2