use of org.b3log.latke.repository.RepositoryException in project solo by b3log.
the class PreferenceQueryService method getPreference.
/**
* Gets the user preference.
*
* @return user preference, returns {@code null} if not found
* @throws ServiceException if repository exception
*/
public JSONObject getPreference() throws ServiceException {
try {
final JSONObject checkInit = optionRepository.get(Option.ID_C_ADMIN_EMAIL);
if (null == checkInit) {
return null;
}
final Query query = new Query();
query.setFilter(new PropertyFilter(Option.OPTION_CATEGORY, FilterOperator.EQUAL, Option.CATEGORY_C_PREFERENCE));
final JSONArray opts = optionRepository.get(query).optJSONArray(Keys.RESULTS);
final JSONObject ret = new JSONObject();
for (int i = 0; i < opts.length(); i++) {
final JSONObject opt = opts.optJSONObject(i);
ret.put(opt.optString(Keys.OBJECT_ID), opt.opt(Option.OPTION_VALUE));
}
return ret;
} catch (final RepositoryException e) {
return null;
}
}
use of org.b3log.latke.repository.RepositoryException in project solo by b3log.
the class PageMgmtService method addPage.
/**
* Adds a page with the specified request json object.
*
* @param requestJSONObject the specified request json object, for example, <pre>
* {
* "page": {
* "pageTitle": "",
* "pageContent": "",
* "pageOpenTarget": "",
* "pageCommentable": boolean,
* "pageType": "",
* "pagePermalink": "", // optional
* "pageEditorType": "" // optional, preference specified if not exists this key
* }
* }, see {@link Page} for more details
* </pre>
*
* @return generated page id
* @throws ServiceException if permalink format checks failed or persists failed
*/
public String addPage(final JSONObject requestJSONObject) throws ServiceException {
final Transaction transaction = pageRepository.beginTransaction();
try {
final JSONObject page = requestJSONObject.getJSONObject(Page.PAGE);
page.put(Page.PAGE_COMMENT_COUNT, 0);
final int maxOrder = pageRepository.getMaxOrder();
page.put(Page.PAGE_ORDER, maxOrder + 1);
String permalink = page.optString(Page.PAGE_PERMALINK);
if (Strings.isEmptyOrNull(permalink)) {
permalink = "/pages/" + Ids.genTimeMillisId() + ".html";
}
if (Page.PAGE.equals(page.getString(Page.PAGE_TYPE))) {
if (!permalink.startsWith("/")) {
permalink = "/" + permalink;
}
if (PermalinkQueryService.invalidPagePermalinkFormat(permalink)) {
if (transaction.isActive()) {
transaction.rollback();
}
throw new ServiceException(langPropsService.get("invalidPermalinkFormatLabel"));
}
if (permalinkQueryService.exist(permalink)) {
if (transaction.isActive()) {
transaction.rollback();
}
throw new ServiceException(langPropsService.get("duplicatedPermalinkLabel"));
}
}
page.put(Page.PAGE_PERMALINK, permalink.replaceAll(" ", "-"));
// Set editor type
if (!page.has(Page.PAGE_EDITOR_TYPE)) {
final JSONObject preference = preferenceQueryService.getPreference();
page.put(Page.PAGE_EDITOR_TYPE, preference.optString(Option.ID_C_EDITOR_TYPE));
}
final String ret = pageRepository.add(page);
transaction.commit();
return ret;
} catch (final JSONException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
if (transaction.isActive()) {
transaction.rollback();
}
throw new ServiceException(e);
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
if (transaction.isActive()) {
transaction.rollback();
}
throw new ServiceException(e);
}
}
use of org.b3log.latke.repository.RepositoryException in project solo by b3log.
the class StatisticMgmtService method incBlogArticleCount.
/**
* Blog statistic article count +1.
*
* @throws RepositoryException repository exception
*/
public void incBlogArticleCount() throws RepositoryException {
final JSONObject statistic = statisticRepository.get(Statistic.STATISTIC);
if (null == statistic) {
throw new RepositoryException("Not found statistic");
}
statistic.put(Statistic.STATISTIC_BLOG_ARTICLE_COUNT, statistic.optInt(Statistic.STATISTIC_BLOG_ARTICLE_COUNT) + 1);
statisticRepository.update(Statistic.STATISTIC, statistic);
}
use of org.b3log.latke.repository.RepositoryException in project solo by b3log.
the class StatisticMgmtService method setBlogCommentCount.
/**
* Sets blog comment count with the specified count.
*
* @param count the specified count
* @throws JSONException json exception
* @throws RepositoryException repository exception
*/
public void setBlogCommentCount(final int count) throws JSONException, RepositoryException {
final JSONObject statistic = statisticRepository.get(Statistic.STATISTIC);
if (null == statistic) {
throw new RepositoryException("Not found statistic");
}
statistic.put(Statistic.STATISTIC_BLOG_COMMENT_COUNT, count);
statisticRepository.update(Statistic.STATISTIC, statistic);
}
use of org.b3log.latke.repository.RepositoryException in project solo by b3log.
the class StatisticMgmtService method incPublishedBlogArticleCount.
/**
* Blog statistic published article count +1.
*
* @throws RepositoryException repository exception
*/
public void incPublishedBlogArticleCount() throws RepositoryException {
final JSONObject statistic = statisticRepository.get(Statistic.STATISTIC);
if (null == statistic) {
throw new RepositoryException("Not found statistic");
}
statistic.put(Statistic.STATISTIC_PUBLISHED_ARTICLE_COUNT, statistic.optInt(Statistic.STATISTIC_PUBLISHED_ARTICLE_COUNT) + 1);
statisticRepository.update(Statistic.STATISTIC, statistic);
}
Aggregations