use of com.pratilipi.api.annotation.Get in project pratilipi by Pratilipi.
the class PratilipiBackupApi method get.
@Get
public GenericResponse get(GetRequest request) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
// Fetching Cursor from AppProperty
AppProperty appProperty = dataAccessor.getAppProperty(AppProperty.API_PRATILIPI_BACKUP);
if (appProperty == null)
appProperty = dataAccessor.newAppProperty(AppProperty.API_PRATILIPI_BACKUP);
Cursor cursor = appProperty.getValue() == null ? null : Cursor.fromWebSafeString((String) appProperty.getValue());
QueryResultIterator<Key<PratilipiEntity>> itr = ObjectifyService.ofy().load().type(PratilipiEntity.class).filter("LAST_UPDATED >=", // Thu Dec 01 00:00:00 IST 2016
new Date(1480530600000L)).order("LAST_UPDATED").startAt(cursor).keys().iterator();
int batchSize = 1000;
List<Task> taskList = new ArrayList<>(batchSize);
while (itr.hasNext()) {
TaskQueueFactory.getPratilipiTaskQueue().add(TaskQueueFactory.newTask().setUrl("/pratilipi/backup").addParam("pratilipiId", itr.next().getId() + ""));
if (taskList.size() == batchSize || !itr.hasNext()) {
TaskQueueFactory.getPratilipiTaskQueue().addAll(taskList);
taskList.clear();
}
}
// Updating Cursor to AppProperty
appProperty.setValue(itr.getCursor().toWebSafeString());
dataAccessor.createOrUpdateAppProperty(appProperty);
/* DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessorBackup();
Date backupDate = new Date();
DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
DateFormat csvDateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm" );
DateFormat dateTimeFormat = new SimpleDateFormat( "yyyy-MM-dd-HH:mm-z" );
dateFormat.setTimeZone( TimeZone.getTimeZone( "Asia/Kolkata" ) );
csvDateFormat.setTimeZone( TimeZone.getTimeZone( "Asia/Kolkata" ) );
dateTimeFormat.setTimeZone( TimeZone.getTimeZone( "Asia/Kolkata" ) );
StringBuilder backup = new StringBuilder();
StringBuilder csv = new StringBuilder( CSV_HEADER + LINE_SEPARATOR );
int count = 0;
String cursor = null;
PratilipiFilter pratilipiFilter = new PratilipiFilter();
Gson gson = new GsonBuilder().registerTypeAdapter( Date.class, new GsonIstDateAdapter() ).create();
while( true ) {
DataListCursorTuple<Pratilipi> pratilipiListCursorTuple = dataAccessor.getPratilipiList( pratilipiFilter, cursor, 1000 );
List<Pratilipi> pratilipiList = pratilipiListCursorTuple.getDataList();
for( Pratilipi pratilipi : pratilipiList ) {
backup.append( gson.toJson( pratilipi ) + LINE_SEPARATOR );
if( request.generateCsv != null && request.generateCsv )
csv.append( "'" + pratilipi.getId() )
.append( CSV_SEPARATOR ).append( pratilipi.getAuthorId() == null ? "" : "'" + pratilipi.getAuthorId() )
.append( CSV_SEPARATOR ).append( pratilipi.getTitle() == null ? "" : "\"" + pratilipi.getTitle().replace( "\"", "\"\"" ) + "\"" )
.append( CSV_SEPARATOR ).append( pratilipi.getTitleEn() == null ? "" : "\"" + pratilipi.getTitleEn().replace( "\"", "\"\"" ) + "\"" )
.append( CSV_SEPARATOR ).append( pratilipi.getLanguage() )
.append( CSV_SEPARATOR ).append( pratilipi.getSummary() != null && pratilipi.getSummary().trim().length() != 0 )
.append( CSV_SEPARATOR ).append( pratilipi.getType() )
.append( CSV_SEPARATOR ).append( pratilipi.getContentType() )
.append( CSV_SEPARATOR ).append( pratilipi.getState() )
.append( CSV_SEPARATOR ).append( pratilipi.getCoverImage() != null )
.append( CSV_SEPARATOR ).append( csvDateFormat.format( pratilipi.getListingDate() ) )
.append( CSV_SEPARATOR ).append( pratilipi.getReviewCount() )
.append( CSV_SEPARATOR ).append( pratilipi.getRatingCount() )
.append( CSV_SEPARATOR ).append( pratilipi.getTotalRating() )
.append( CSV_SEPARATOR ).append( pratilipi.getReadCount() )
.append( LINE_SEPARATOR );
}
count = count + pratilipiList.size();
if( pratilipiList.size() < 1000 )
break;
else
cursor = pratilipiListCursorTuple.getCursor();
}
String fileName = "datastore.pratilipi/"
+ dateFormat.format( backupDate ) + "/"
+ "pratilipi-" + dateTimeFormat.format( backupDate );
BlobEntry pratilipiBackupEntry = blobAccessor.newBlob(
fileName,
backup.toString().getBytes( Charset.forName( "UTF-8" ) ),
"text/plain" );
blobAccessor.createOrUpdateBlob( pratilipiBackupEntry );
if( request.generateCsv != null && request.generateCsv ) {
BlobEntry authorCsvEntry = blobAccessor.newBlob(
"datastore/pratilipi.csv",
csv.toString().getBytes( Charset.forName( "UTF-8" ) ),
"text/csv" );
blobAccessor.createOrUpdateBlob( authorCsvEntry );
}
logger.log( Level.INFO, "Backed up " + count + " Pratilipi Entities." );
*/
return new GenericResponse();
}
use of com.pratilipi.api.annotation.Get in project pratilipi by Pratilipi.
the class AuthorApi method get.
@Get
public Response get(GetRequest request) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Author author = dataAccessor.getAuthor(request.authorId);
UserAuthor userAuthor = dataAccessor.getUserAuthor(AccessTokenFilter.getAccessToken().getUserId(), request.authorId);
AuthorData authorData = AuthorDataUtil.createAuthorData(author, null, null);
Response response = new Response(authorData);
response.setFollowing(userAuthor != null && userAuthor.getFollowState() == UserFollowState.FOLLOWING);
return response;
}
use of com.pratilipi.api.annotation.Get in project pratilipi by Pratilipi.
the class EventApi method get.
@Get
public Response get(GetRequest request) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Event event = dataAccessor.getEvent(request.eventId);
EventData eventData = EventDataUtil.createEventData(event, true);
return new Response(eventData);
}
use of com.pratilipi.api.annotation.Get in project pratilipi by Pratilipi.
the class PratilipiV1Api 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());
PratilipiData pratilipiData = PratilipiDataUtil.createPratilipiData(pratilipi, author);
if (UxModeFilter.isAndroidApp()) {
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(request.pratilipiId);
pratilipiData.setIndex(pcDoc == null ? null : pcDoc.getIndex());
}
return new Response(pratilipiData);
}
use of com.pratilipi.api.annotation.Get 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));
}
Aggregations