Search in sources :

Example 46 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class DataStoreCleanupUtil method deleteUser.

public static void deleteUser(String userProfileUri, boolean preview) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    delete(dataAccessor.getUser(dataAccessor.getAuthor(dataAccessor.getPage(userProfileUri).getPrimaryContentId()).getUserId()), preview);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor)

Example 47 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class DataStoreCleanupUtil method migratePratilipi.

public static void migratePratilipi(String fromAuthorPageUri, String toAuthorPageUri) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    migratePratilipi(dataAccessor.getPage(fromAuthorPageUri).getPrimaryContentId(), dataAccessor.getPage(toAuthorPageUri).getPrimaryContentId());
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor)

Example 48 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class DataStoreUtil method main.

public static void main(String... args) throws IOException, UnexpectedServerException, InterruptedException, ParseException {
    RemoteApiOptions options = new RemoteApiOptions().server("m.gamma.pratilipi.com", 80).useServiceAccountCredential("prod-pratilipi@appspot.gserviceaccount.com", "PrivateKey.p12").remoteApiPath("/remote_api");
    RemoteApiInstaller installer = new RemoteApiInstaller();
    installer.install(options);
    ObjectifyService.begin();
    Memcache memcache = DataAccessorFactory.getL2CacheAccessor();
    GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    SearchAccessor searchAccessor = DataAccessorFactory.getSearchAccessor();
    BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    // START
    // END
    installer.uninstall();
}
Also used : RemoteApiInstaller(com.google.appengine.tools.remoteapi.RemoteApiInstaller) SearchAccessor(com.pratilipi.data.SearchAccessor) GcsService(com.google.appengine.tools.cloudstorage.GcsService) DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) RemoteApiOptions(com.google.appengine.tools.remoteapi.RemoteApiOptions) BlobAccessor(com.pratilipi.data.BlobAccessor) Memcache(com.pratilipi.data.Memcache)

Example 49 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class UserProcessApi method post.

@Post
public GenericResponse post(PostRequest request) throws InvalidArgumentException, UnexpectedServerException {
    if (request.validateData != null && request.validateData) {
        DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
        User user = dataAccessor.getUser(request.userId);
        // DELETED User entity can not have a non-DELETED Author entity linked.
        if (user.getState() == UserState.DELETED) {
            Author author = dataAccessor.getAuthorByUserId(user.getId());
            if (author != null && author.getState() != AuthorState.DELETED)
                throw new InvalidArgumentException("DELETED User entity has a non-DELETED Author entity linked.");
            // TODO: DELETED User entity can not have non-DELETED UserAuthor entities.
            return new GenericResponse();
        }
        // Either of two - email and facebook id - must be present.
        if (user.getEmail() == null && user.getFacebookId() == null)
            throw new InvalidArgumentException("Neither email nor facebook id is set.");
        // Email, if present, must not be empty.
        if (user.getEmail() != null && user.getEmail().trim().isEmpty())
            throw new InvalidArgumentException("Email is empty.");
        // Facebook id, if present, must not be empty.
        if (user.getFacebookId() != null && user.getFacebookId().trim().isEmpty())
            throw new InvalidArgumentException("Facebook Id is empty.");
        // Email, if present, must be trimmed and converted to lower case.
        if (user.getEmail() != null && !user.getEmail().equals(user.getEmail().trim().toLowerCase()))
            throw new InvalidArgumentException("Email is either not trimmed or not converted to lower case.");
        // Only one non-DELETED User entity can exist per email id.
        if (user.getEmail() != null) {
            Query<UserEntity> query = ObjectifyService.ofy().load().type(UserEntity.class).filter("EMAIL", user.getEmail()).filter("STATE !=", UserState.DELETED).order("STATE").order("SIGN_UP_DATE");
            List<UserEntity> list = query.list();
            if (list.size() != 1)
                throw new InvalidArgumentException(list.size() + " non-DELETED User entities found for email " + user.getEmail() + " .");
        }
        // Only one non-DELETED User entity can exist per facebook id.
        if (user.getFacebookId() != null) {
            Query<UserEntity> query = ObjectifyService.ofy().load().type(UserEntity.class).filter("FACEBOOK_ID", user.getFacebookId()).filter("STATE !=", UserState.DELETED).order("STATE").order("SIGN_UP_DATE");
            List<UserEntity> list = query.list();
            if (list.size() != 1)
                throw new InvalidArgumentException(list.size() + " non-DELETED User entities found for Facebook Id " + user.getFacebookId() + " .");
        }
        // Author profile for the user.
        Query<AuthorEntity> query = ObjectifyService.ofy().load().type(AuthorEntity.class).filter("USER_ID", user.getId()).filter("STATE !=", AuthorState.DELETED).order("STATE").order("REGISTRATION_DATE");
        List<AuthorEntity> authorList = query.list();
        if (authorList.size() == 0) {
            if (user.getState() != UserState.REFERRAL || user.getSignUpSource() != UserSignUpSource.PRE_LAUNCH_WEBSITE)
                throw new InvalidArgumentException("Could not find an Author entity linked.");
        } else if (authorList.size() == 1) {
        // Do Nothing.
        } else {
            throw new InvalidArgumentException("User has " + authorList.size() + " non-DELETED Author entities linked.");
        }
    }
    if (request.updateFollowsDoc != null && request.updateFollowsDoc) {
        UserDocUtil.updateUserFollows(request.userId);
    }
    if (request.updateUserAuthorStats != null && request.updateUserAuthorStats) {
        UserDataUtil.updateUserAuthorStats(request.userId);
    }
    return new GenericResponse();
}
Also used : User(com.pratilipi.data.type.User) InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) Author(com.pratilipi.data.type.Author) UserEntity(com.pratilipi.data.type.gae.UserEntity) AuthorEntity(com.pratilipi.data.type.gae.AuthorEntity) Post(com.pratilipi.api.annotation.Post)

Example 50 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class PratilipiV2Api method get.

@Get
public Response get(GetRequest request) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(request.pratilipiId);
    Author author = pratilipi.getAuthorId() == null ? null : dataAccessor.getAuthor(pratilipi.getAuthorId());
    return new Response(PratilipiDataUtil.createPratilipiData(pratilipi, author));
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) Author(com.pratilipi.data.type.Author) Pratilipi(com.pratilipi.data.type.Pratilipi) Get(com.pratilipi.api.annotation.Get)

Aggregations

DataAccessor (com.pratilipi.data.DataAccessor)162 Date (java.util.Date)53 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)37 Pratilipi (com.pratilipi.data.type.Pratilipi)34 Author (com.pratilipi.data.type.Author)33 AuditLog (com.pratilipi.data.type.AuditLog)32 UserPratilipi (com.pratilipi.data.type.UserPratilipi)32 ArrayList (java.util.ArrayList)30 Page (com.pratilipi.data.type.Page)28 HashMap (java.util.HashMap)25 GenericResponse (com.pratilipi.api.shared.GenericResponse)24 DocAccessor (com.pratilipi.data.DocAccessor)22 User (com.pratilipi.data.type.User)22 Get (com.pratilipi.api.annotation.Get)20 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)19 PratilipiData (com.pratilipi.data.client.PratilipiData)15 UserData (com.pratilipi.data.client.UserData)14 BlobAccessor (com.pratilipi.data.BlobAccessor)13 Email (com.pratilipi.data.type.Email)13 JsonObject (com.google.gson.JsonObject)12