use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project rhino by PLOS.
the class ArticleListView method serialize.
@Override
public JsonObject serialize(JsonSerializationContext context) {
JsonObject serialized = context.serialize(getIdentity()).getAsJsonObject();
serialized.addProperty("title", articleList.getDisplayName());
if (!excludeArticleMetadata) {
List<ArticleRevisionView> articleViews = Lists.transform(articleList.getArticles(), articleFactory::getLatestRevisionView);
serialized.add("articles", context.serialize(articleViews));
}
return serialized;
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project rhino by PLOS.
the class IssueOutputView method serialize.
@Override
public JsonElement serialize(JsonSerializationContext context) {
JsonObject serialized = new JsonObject();
serialized.addProperty("doi", issue.getDoi());
serialized.addProperty("displayName", issue.getDisplayName());
serialized.add("parentVolume", context.serialize(factory.volumeOutputViewFactory.getView(parentVolume)));
Article imageArticle = issue.getImageArticle();
if (imageArticle != null) {
JsonObject serializedImageArticle = new JsonObject();
String figureImageDoi = getIssueImageFigureDoi(factory.articleCrudService, imageArticle);
serializedImageArticle.addProperty("doi", imageArticle.getDoi());
serializedImageArticle.addProperty("figureImageDoi", figureImageDoi);
serialized.add("imageArticle", serializedImageArticle);
}
return serialized;
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project rhino by PLOS.
the class JournalOutputView method serialize.
@Override
public JsonElement serialize(JsonSerializationContext context) {
JsonObject serialized = new JsonObject();
serialized.addProperty("journalKey", journal.getJournalKey());
serialized.addProperty("title", journal.getTitle());
serialized.addProperty("eIssn", journal.geteIssn());
return serialized;
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project pratilipi by Pratilipi.
the class PratilipiSite method createDataModelForReadPage.
public Map<String, Object> createDataModelForReadPage(Long pratilipiId, Integer chapterNo, String version, Language language, boolean basicMode) throws InvalidArgumentException, UnexpectedServerException, InsufficientAccessException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
PratilipiData pratilipiData = PratilipiDataUtil.createPratilipiData(pratilipi);
PratilipiV2Api.Response pratilipiResponse = new PratilipiV2Api.Response(pratilipiData);
UserPratilipiApi.GetRequest userPratilipiRequest = new UserPratilipiApi.GetRequest();
userPratilipiRequest.setPratilipiId(pratilipiId);
UserPratilipiApi.Response userPratilipiResponse = ApiRegistry.getApi(UserPratilipiApi.class).getUserPratilipi(userPratilipiRequest);
String indexJson = null;
Integer pageCount = null;
Object content = null;
// In case, version is not specified in URL
if (version == null) {
if (SystemProperty.STAGE.equals(SystemProperty.STAGE_PROD) && pratilipi.isOldContent() && pratilipi.getContentType() == PratilipiContentType.PRATILIPI) {
version = "1";
} else {
version = "3";
}
}
// Index and pageCount for all contents
if (version.equals("1")) {
indexJson = pratilipi.getIndex();
pageCount = pratilipi.getPageCount() > 0 ? pratilipi.getPageCount() : 1;
} else if (version.equals("2") || version.equals("3")) {
// Json format
PratilipiContentIndexApi.GetRequest indexReq = new PratilipiContentIndexApi.GetRequest();
indexReq.setPratilipiId(pratilipiId);
PratilipiContentIndexApi.Response indexRes = ApiRegistry.getApi(PratilipiContentIndexApi.class).getIndex(indexReq);
indexJson = indexRes.getIndex().toString();
pageCount = indexRes.getIndex().size() > 0 ? indexRes.getIndex().size() : 1;
}
if (pratilipi.getContentType() == PratilipiContentType.PRATILIPI) {
if (chapterNo < 1)
chapterNo = 1;
if (chapterNo > pageCount)
chapterNo = pageCount;
if (version.equals("1")) {
PratilipiContentV1Api.GetRequest req = new PratilipiContentV1Api.GetRequest();
req.setPratilipiId(pratilipiId);
req.setChapterNo(chapterNo);
PratilipiContentV1Api.GetResponse res = (PratilipiContentV1Api.GetResponse) ApiRegistry.getApi(PratilipiContentV1Api.class).get(req);
content = res.getContent();
} else if (version.equals("2")) {
PratilipiContentV2Api.GetRequest req = new PratilipiContentV2Api.GetRequest();
req.setPratilipiId(pratilipiId);
req.setChapterNo(chapterNo);
PratilipiContentV2Api.GetResponse res = (PratilipiContentV2Api.GetResponse) ApiRegistry.getApi(PratilipiContentV2Api.class).get(req);
content = res.getContent();
if (res.getChapterTitle() != null)
content = "<h1>" + res.getChapterTitle() + "</h1>" + content;
} else if (version.equals("3")) {
PratilipiContentV3Api.GetRequest req = new PratilipiContentV3Api.GetRequest();
req.setPratilipiId(pratilipiId);
req.setChapterNo(chapterNo);
PratilipiContentV3Api.GetResponse res = (PratilipiContentV3Api.GetResponse) ApiRegistry.getApi(PratilipiContentV3Api.class).get(req);
content = res.getContent();
if (res.getChapterTitle() != null)
content = "<h1>" + res.getChapterTitle() + "</h1>" + content;
}
} else if (pratilipi.getContentType() == PratilipiContentType.IMAGE) {
PratilipiContentV2Api.GetRequest req = new PratilipiContentV2Api.GetRequest();
req.setPratilipiId(pratilipiId);
PratilipiContentV2Api.GetResponse res = (PratilipiContentV2Api.GetResponse) ApiRegistry.getApi(PratilipiContentV2Api.class).get(req);
PratilipiContentDoc pcDoc = (PratilipiContentDoc) res.getContent();
// Image books can have more than one page in a chapter
pageCount = 0;
for (Chapter chapter : pcDoc.getChapterList()) pageCount += chapter.getPageCount();
if (chapterNo < 1)
chapterNo = 1;
if (chapterNo > pageCount)
chapterNo = pageCount;
if (basicMode) {
JsonObject jsonObject = null;
int c = 0;
for (int i = 1; i <= pcDoc.getChapterCount(); i++) {
for (int j = 1; j <= pcDoc.getChapter(i).getPageCount(); j++) {
if (++c == chapterNo) {
jsonObject = pcDoc.getChapter(i).getPage(j).getPageletList().get(0).getData();
break;
}
}
}
content = PratilipiDocUtil._processImagePagelet(pratilipiId, jsonObject);
} else {
content = new Gson().toJson(res.getContent());
}
}
Gson gson = new Gson();
Map<String, Object> dataModel = new HashMap<String, Object>();
dataModel.put("title", SEOTitleUtil.getReadPageTitle(pratilipiId, language));
dataModel.put("pageNo", chapterNo);
dataModel.put("pageCount", pageCount);
dataModel.put("content", content);
dataModel.put("version", version);
dataModel.put("contentType", pratilipi.getContentType());
if (basicMode) {
dataModel.put("pratilipi", pratilipiResponse);
dataModel.put("userpratilipi", userPratilipiResponse);
dataModel.put("indexList", gson.fromJson(indexJson, Object.class));
} else {
dataModel.put("pratilipiJson", gson.toJson(pratilipiResponse));
dataModel.put("userpratilipiJson", gson.toJson(userPratilipiResponse));
dataModel.put("indexJson", gson.toJson(indexJson));
}
return dataModel;
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project pratilipi by Pratilipi.
the class UserDataUtil method loginUser.
public static UserData loginUser(String email, String password) throws InvalidArgumentException, InsufficientAccessException {
// Do nothing if a user is already logged in
if (!AccessTokenFilter.getAccessToken().getUserId().equals(0L))
return getCurrentUser();
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
User user = dataAccessor.getUserByEmail(email.toLowerCase());
if (user == null || user.getState() == UserState.REFERRAL || user.getState() == UserState.DELETED) {
JsonObject errorMessages = new JsonObject();
errorMessages.addProperty("email", GenericRequest.ERR_EMAIL_NOT_REGISTERED);
throw new InvalidArgumentException(errorMessages);
} else if (user.getState() == UserState.BLOCKED) {
throw new InsufficientAccessException(GenericRequest.ERR_ACCOUNT_BLOCKED);
}
if (user.getPassword() == null && user.getFacebookId() != null)
throw new InvalidArgumentException(GenericRequest.ERR_EMAIL_REGISTERED_WITH_FACEBOOK);
if (user.getPassword() == null && user.getGoogleId() != null)
throw new InvalidArgumentException(GenericRequest.ERR_EMAIL_REGISTERED_WITH_GOOGLE);
if (PasswordUtil.check(password, user.getPassword())) {
_loginUser(AccessTokenFilter.getAccessToken(), user);
return createUserData(user);
}
if (_verifyToken(user, password)) {
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_ADD, user);
user.setVerificationToken(null);
dataAccessor.createOrUpdateUser(user, auditLog);
_loginUser(AccessTokenFilter.getAccessToken(), user);
return createUserData(user);
}
throw new InvalidArgumentException(GenericRequest.ERR_INVALID_CREDENTIALS);
}
Aggregations