Commit 7d44435d authored by Liang Ding's avatar Liang Ding

🔨 适应 Latke 框架调整

parent 15618f0f
...@@ -49,7 +49,7 @@ import java.util.Date; ...@@ -49,7 +49,7 @@ import java.util.Date;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author ArmstrongCN * @author ArmstrongCN
* @version 1.0.2.9, Jun 26, 2017 * @version 1.0.2.10, Jul 6, 2017
* @since 0.3.1 * @since 0.3.1
*/ */
public final class ArticleSender extends AbstractEventListener<JSONObject> { public final class ArticleSender extends AbstractEventListener<JSONObject> {
...@@ -136,7 +136,7 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> { ...@@ -136,7 +136,7 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> {
requestJSONObject.put("blogHost", Latkes.getServePath()); requestJSONObject.put("blogHost", Latkes.getServePath());
requestJSONObject.put("userB3Key", preference.optString(Option.ID_C_KEY_OF_SOLO)); requestJSONObject.put("userB3Key", preference.optString(Option.ID_C_KEY_OF_SOLO));
requestJSONObject.put("clientAdminEmail", preference.optString(Option.ID_C_ADMIN_EMAIL)); requestJSONObject.put("clientAdminEmail", preference.optString(Option.ID_C_ADMIN_EMAIL));
requestJSONObject.put("clientRuntimeEnv", Latkes.getRuntimeEnv().name()); requestJSONObject.put("clientRuntimeEnv", "LOCAL");
httpRequest.setPayload(requestJSONObject.toString().getBytes("UTF-8")); httpRequest.setPayload(requestJSONObject.toString().getBytes("UTF-8"));
......
...@@ -48,7 +48,7 @@ import java.util.Date; ...@@ -48,7 +48,7 @@ import java.util.Date;
* </p> * </p>
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.3, Jun 26, 2017 * @version 1.0.0.4, Jul 6, 2017
* @since 0.6.0 * @since 0.6.0
*/ */
public final class ArticleUpdater extends AbstractEventListener<JSONObject> { public final class ArticleUpdater extends AbstractEventListener<JSONObject> {
...@@ -135,7 +135,7 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> { ...@@ -135,7 +135,7 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> {
requestJSONObject.put("blogHost", Latkes.getServerHost() + ":" + Latkes.getServerPort()); requestJSONObject.put("blogHost", Latkes.getServerHost() + ":" + Latkes.getServerPort());
requestJSONObject.put("userB3Key", preference.optString(Option.ID_C_KEY_OF_SOLO)); requestJSONObject.put("userB3Key", preference.optString(Option.ID_C_KEY_OF_SOLO));
requestJSONObject.put("clientAdminEmail", preference.optString(Option.ID_C_ADMIN_EMAIL)); requestJSONObject.put("clientAdminEmail", preference.optString(Option.ID_C_ADMIN_EMAIL));
requestJSONObject.put("clientRuntimeEnv", Latkes.getRuntimeEnv().name()); requestJSONObject.put("clientRuntimeEnv", "LOCAL");
httpRequest.setPayload(requestJSONObject.toString().getBytes("UTF-8")); httpRequest.setPayload(requestJSONObject.toString().getBytes("UTF-8"));
......
...@@ -43,9 +43,9 @@ import java.net.URL; ...@@ -43,9 +43,9 @@ import java.net.URL;
/** /**
* This listener is responsible for sending comment to B3log Symphony. * This listener is responsible for sending comment to B3log Symphony.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.4, Nov 20, 2015 * @version 1.0.0.5, Jul 6, 2017
* @since 0.5.5 * @since 0.5.5
*/ */
public final class CommentSender extends AbstractEventListener<JSONObject> { public final class CommentSender extends AbstractEventListener<JSONObject> {
...@@ -53,7 +53,7 @@ public final class CommentSender extends AbstractEventListener<JSONObject> { ...@@ -53,7 +53,7 @@ public final class CommentSender extends AbstractEventListener<JSONObject> {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(CommentSender.class.getName()); private static final Logger LOGGER = Logger.getLogger(CommentSender.class);
/** /**
* URL fetch service. * URL fetch service.
...@@ -87,7 +87,6 @@ public final class CommentSender extends AbstractEventListener<JSONObject> { ...@@ -87,7 +87,6 @@ public final class CommentSender extends AbstractEventListener<JSONObject> {
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class); final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) { if (null == preference) {
throw new EventException("Not found preference"); throw new EventException("Not found preference");
} }
...@@ -113,7 +112,7 @@ public final class CommentSender extends AbstractEventListener<JSONObject> { ...@@ -113,7 +112,7 @@ public final class CommentSender extends AbstractEventListener<JSONObject> {
requestJSONObject.put(Comment.COMMENT, comment); requestJSONObject.put(Comment.COMMENT, comment);
requestJSONObject.put("clientVersion", SoloServletListener.VERSION); requestJSONObject.put("clientVersion", SoloServletListener.VERSION);
requestJSONObject.put("clientRuntimeEnv", Latkes.getRuntimeEnv().name()); requestJSONObject.put("clientRuntimeEnv", "LOCAL");
requestJSONObject.put("clientName", "B3log Solo"); requestJSONObject.put("clientName", "B3log Solo");
requestJSONObject.put("clientHost", Latkes.getServerHost() + ":" + Latkes.getServerPort()); requestJSONObject.put("clientHost", Latkes.getServerHost() + ":" + Latkes.getServerPort());
requestJSONObject.put("clientAdminEmail", preference.optString(Option.ID_C_ADMIN_EMAIL)); requestJSONObject.put("clientAdminEmail", preference.optString(Option.ID_C_ADMIN_EMAIL));
...@@ -131,7 +130,7 @@ public final class CommentSender extends AbstractEventListener<JSONObject> { ...@@ -131,7 +130,7 @@ public final class CommentSender extends AbstractEventListener<JSONObject> {
/** /**
* Gets the event type {@linkplain EventTypes#ADD_COMMENT_TO_ARTICLE}. * Gets the event type {@linkplain EventTypes#ADD_COMMENT_TO_ARTICLE}.
* *
* @return event type * @return event type
*/ */
@Override @Override
......
...@@ -50,9 +50,9 @@ import java.util.concurrent.Future; ...@@ -50,9 +50,9 @@ import java.util.concurrent.Future;
/** /**
* Broadcast chance processor. * Broadcast chance processor.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.10, Nov 20, 2015 * @version 1.0.0.11, Jul 6, 2017
* @since 0.6.0 * @since 0.6.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -61,7 +61,7 @@ public class ChanceProcessor { ...@@ -61,7 +61,7 @@ public class ChanceProcessor {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(ChanceProcessor.class.getName()); private static final Logger LOGGER = Logger.getLogger(ChanceProcessor.class);
/** /**
* Option management service. * Option management service.
...@@ -85,7 +85,7 @@ public class ChanceProcessor { ...@@ -85,7 +85,7 @@ public class ChanceProcessor {
*/ */
@Inject @Inject
private UserQueryService userQueryService; private UserQueryService userQueryService;
/** /**
* Preference query service. * Preference query service.
*/ */
...@@ -108,7 +108,6 @@ public class ChanceProcessor { ...@@ -108,7 +108,6 @@ public class ChanceProcessor {
/** /**
* Adds a broadcast chance to option repository. * Adds a broadcast chance to option repository.
*
* <p> * <p>
* Renders the response with a json object, for example, * Renders the response with a json object, for example,
* <pre> * <pre>
...@@ -119,27 +118,23 @@ public class ChanceProcessor { ...@@ -119,27 +118,23 @@ public class ChanceProcessor {
* </pre> * </pre>
* </p> * </p>
* *
* @param context the specified http request context * @param context the specified http request context
* @param request the specified http servlet request * @param request the specified http servlet request
* @param response the specified http servlet response * @param response the specified http servlet response
* @throws Exception * @throws Exception
*/ */
@RequestProcessing(value = "/console/plugins/b3log-broadcast/chance", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/console/plugins/b3log-broadcast/chance", method = HTTPRequestMethod.POST)
public void addChance(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) public void addChance(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws Exception { throws Exception {
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
try { try {
// TODO: verify b3 key // TODO: verify b3 key
final String time = request.getParameter("time"); final String time = request.getParameter("time");
if (Strings.isEmptyOrNull(time)) { if (Strings.isEmptyOrNull(time)) {
ret.put(Keys.STATUS_CODE, false); ret.put(Keys.STATUS_CODE, false);
...@@ -147,9 +142,7 @@ public class ChanceProcessor { ...@@ -147,9 +142,7 @@ public class ChanceProcessor {
} }
final long expirationTime = Long.valueOf(time); final long expirationTime = Long.valueOf(time);
final JSONObject option = new JSONObject(); final JSONObject option = new JSONObject();
option.put(Keys.OBJECT_ID, Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME); option.put(Keys.OBJECT_ID, Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
option.put(Option.OPTION_VALUE, expirationTime); option.put(Option.OPTION_VALUE, expirationTime);
option.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_BROADCAST); option.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_BROADCAST);
...@@ -171,11 +164,9 @@ public class ChanceProcessor { ...@@ -171,11 +164,9 @@ public class ChanceProcessor {
/** /**
* Dose the client has a broadcast chance. * Dose the client has a broadcast chance.
*
* <p> * <p>
* If the request come from a user not administrator, consider it is no broadcast chance. * If the request come from a user not administrator, consider it is no broadcast chance.
* </p> * </p>
*
* <p> * <p>
* Renders the response with a json object, for example, * Renders the response with a json object, for example,
* <pre> * <pre>
...@@ -186,14 +177,14 @@ public class ChanceProcessor { ...@@ -186,14 +177,14 @@ public class ChanceProcessor {
* </pre> * </pre>
* </p> * </p>
* *
* @param context the specified http request context * @param context the specified http request context
* @param request the specified http servlet request * @param request the specified http servlet request
* @param response the specified http servlet response * @param response the specified http servlet response
* @throws Exception * @throws Exception
*/ */
@RequestProcessing(value = "/console/plugins/b3log-broadcast/chance", method = HTTPRequestMethod.GET) @RequestProcessing(value = "/console/plugins/b3log-broadcast/chance", method = HTTPRequestMethod.GET)
public void hasChance(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) public void hasChance(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws Exception { throws Exception {
if (!userQueryService.isLoggedIn(request, response)) { if (!userQueryService.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
...@@ -201,11 +192,8 @@ public class ChanceProcessor { ...@@ -201,11 +192,8 @@ public class ChanceProcessor {
} }
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
if (!userQueryService.isAdminLoggedIn(request)) { if (!userQueryService.isAdminLoggedIn(request)) {
...@@ -217,7 +205,6 @@ public class ChanceProcessor { ...@@ -217,7 +205,6 @@ public class ChanceProcessor {
try { try {
final JSONObject option = optionQueryService.getOptionById(Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME); final JSONObject option = optionQueryService.getOptionById(Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
if (null == option) { if (null == option) {
ret.put(Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME, 0L); ret.put(Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME, 0L);
ret.put(Keys.STATUS_CODE, false); ret.put(Keys.STATUS_CODE, false);
...@@ -238,7 +225,6 @@ public class ChanceProcessor { ...@@ -238,7 +225,6 @@ public class ChanceProcessor {
/** /**
* Submits a broadcast. * Submits a broadcast.
*
* <p> * <p>
* Renders the response with a json object, for example, * Renders the response with a json object, for example,
* <pre> * <pre>
...@@ -249,23 +235,21 @@ public class ChanceProcessor { ...@@ -249,23 +235,21 @@ public class ChanceProcessor {
* </pre> * </pre>
* </p> * </p>
* *
* @param context the specified http request context * @param context the specified http request context
* @param request the specified http servlet request, for example, * @param request the specified http servlet request, for example,
* <pre> * {
* { * "broadcast": {
* "broadcast": { * "title": "",
* "title": "", * "content": "",
* "content": "", * "link": "" // optional
* "link": "" // optional * }
* } * }
* }
* </pre>
* @param response the specified http servlet response * @param response the specified http servlet response
* @throws Exception * @throws Exception
*/ */
@RequestProcessing(value = "/console/plugins/b3log-broadcast", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/console/plugins/b3log-broadcast", method = HTTPRequestMethod.POST)
public void submitBroadcast(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) public void submitBroadcast(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws Exception { throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) { if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
...@@ -273,11 +257,8 @@ public class ChanceProcessor { ...@@ -273,11 +257,8 @@ public class ChanceProcessor {
} }
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
try { try {
...@@ -290,7 +271,7 @@ public class ChanceProcessor { ...@@ -290,7 +271,7 @@ public class ChanceProcessor {
final String clientName = "B3log Solo"; final String clientName = "B3log Solo";
final String clientVersion = SoloServletListener.VERSION; final String clientVersion = SoloServletListener.VERSION;
final String clientTitle = preference.getString(Option.ID_C_BLOG_TITLE); final String clientTitle = preference.getString(Option.ID_C_BLOG_TITLE);
final String clientRuntimeEnv = Latkes.getRuntimeEnv().name(); final String clientRuntimeEnv = "LOCAL";
final JSONObject broadcastRequest = new JSONObject(); final JSONObject broadcastRequest = new JSONObject();
...@@ -309,8 +290,7 @@ public class ChanceProcessor { ...@@ -309,8 +290,7 @@ public class ChanceProcessor {
httpRequest.setRequestMethod(HTTPRequestMethod.POST); httpRequest.setRequestMethod(HTTPRequestMethod.POST);
httpRequest.setPayload(broadcastRequest.toString().getBytes("UTF-8")); httpRequest.setPayload(broadcastRequest.toString().getBytes("UTF-8"));
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked") final Future<HTTPResponse> future = (Future<HTTPResponse>) urlFetchService.fetchAsync(httpRequest);
final Future<HTTPResponse> future = (Future<HTTPResponse>) urlFetchService.fetchAsync(httpRequest);
final HTTPResponse result = future.get(); final HTTPResponse result = future.get();
if (HttpServletResponse.SC_OK == result.getResponseCode()) { if (HttpServletResponse.SC_OK == result.getResponseCode()) {
......
...@@ -17,7 +17,6 @@ package org.b3log.solo.processor; ...@@ -17,7 +17,6 @@ package org.b3log.solo.processor;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.RuntimeEnv;
import org.b3log.latke.ioc.inject.Inject; import org.b3log.latke.ioc.inject.Inject;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.Pagination; import org.b3log.latke.model.Pagination;
...@@ -52,7 +51,7 @@ import java.util.Set; ...@@ -52,7 +51,7 @@ import java.util.Set;
* Blog processor. * Blog processor.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.0.4, Dec 17, 2015 * @version 1.3.0.5, Jul 6, 2017
* @since 0.4.6 * @since 0.4.6
*/ */
@RequestProcessor @RequestProcessor
...@@ -61,7 +60,7 @@ public class BlogProcessor { ...@@ -61,7 +60,7 @@ public class BlogProcessor {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(BlogProcessor.class.getName()); private static final Logger LOGGER = Logger.getLogger(BlogProcessor.class);
/** /**
* Article query service. * Article query service.
...@@ -100,7 +99,6 @@ public class BlogProcessor { ...@@ -100,7 +99,6 @@ public class BlogProcessor {
/** /**
* Gets blog information. * Gets blog information.
*
* <ul> * <ul>
* <li>Time of the recent updated article</li> * <li>Time of the recent updated article</li>
* <li>Article count</li> * <li>Article count</li>
...@@ -119,11 +117,8 @@ public class BlogProcessor { ...@@ -119,11 +117,8 @@ public class BlogProcessor {
@RequestProcessing(value = "/blog/info", method = HTTPRequestMethod.GET) @RequestProcessing(value = "/blog/info", method = HTTPRequestMethod.GET)
public void getBlogInfo(final HTTPRequestContext context) throws Exception { public void getBlogInfo(final HTTPRequestContext context) throws Exception {
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject(); final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
jsonObject.put("recentArticleTime", articleQueryService.getRecentArticleTime()); jsonObject.put("recentArticleTime", articleQueryService.getRecentArticleTime());
...@@ -137,12 +132,7 @@ public class BlogProcessor { ...@@ -137,12 +132,7 @@ public class BlogProcessor {
jsonObject.put("version", SoloServletListener.VERSION); jsonObject.put("version", SoloServletListener.VERSION);
jsonObject.put("locale", Latkes.getLocale()); jsonObject.put("locale", Latkes.getLocale());
jsonObject.put("runtimeMode", Latkes.getRuntimeMode()); jsonObject.put("runtimeMode", Latkes.getRuntimeMode());
final RuntimeEnv runtimeEnv = Latkes.getRuntimeEnv(); jsonObject.put("runtimeDatabase", Latkes.getRuntimeDatabase());
jsonObject.put("runtimeEnv", runtimeEnv);
if (RuntimeEnv.LOCAL == runtimeEnv) {
jsonObject.put("runtimeDatabase", Latkes.getRuntimeDatabase());
}
} }
/** /**
...@@ -154,11 +144,8 @@ public class BlogProcessor { ...@@ -154,11 +144,8 @@ public class BlogProcessor {
@RequestProcessing(value = "/blog/symphony/user", method = HTTPRequestMethod.GET) @RequestProcessing(value = "/blog/symphony/user", method = HTTPRequestMethod.GET)
public void syncUser(final HTTPRequestContext context) throws Exception { public void syncUser(final HTTPRequestContext context) throws Exception {
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject(); final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
if (Latkes.getServePath().contains("localhost")) { if (Latkes.getServePath().contains("localhost")) {
...@@ -166,19 +153,16 @@ public class BlogProcessor { ...@@ -166,19 +153,16 @@ public class BlogProcessor {
} }
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) { if (null == preference) {
return; // not init yet return; // not init yet
} }
final HTTPRequest httpRequest = new HTTPRequest(); final HTTPRequest httpRequest = new HTTPRequest();
httpRequest.setURL(new URL(SoloServletListener.B3LOG_SYMPHONY_SERVE_PATH + "/apis/user")); httpRequest.setURL(new URL(SoloServletListener.B3LOG_SYMPHONY_SERVE_PATH + "/apis/user"));
httpRequest.setRequestMethod(HTTPRequestMethod.POST); httpRequest.setRequestMethod(HTTPRequestMethod.POST);
final JSONObject requestJSONObject = new JSONObject(); final JSONObject requestJSONObject = new JSONObject();
final JSONObject admin = userQueryService.getAdmin(); final JSONObject admin = userQueryService.getAdmin();
requestJSONObject.put(User.USER_NAME, admin.getString(User.USER_NAME)); requestJSONObject.put(User.USER_NAME, admin.getString(User.USER_NAME));
requestJSONObject.put(User.USER_EMAIL, admin.getString(User.USER_EMAIL)); requestJSONObject.put(User.USER_EMAIL, admin.getString(User.USER_EMAIL));
requestJSONObject.put(User.USER_PASSWORD, admin.getString(User.USER_PASSWORD)); requestJSONObject.put(User.USER_PASSWORD, admin.getString(User.USER_PASSWORD));
...@@ -192,7 +176,7 @@ public class BlogProcessor { ...@@ -192,7 +176,7 @@ public class BlogProcessor {
/** /**
* Gets tags of all articles. * Gets tags of all articles.
* * <p>
* <pre> * <pre>
* { * {
* "data": [ * "data": [
...@@ -202,9 +186,10 @@ public class BlogProcessor { ...@@ -202,9 +186,10 @@ public class BlogProcessor {
* ] * ]
* } * }
* </pre> * </pre>
* </p>
* *
* @param context the specified context * @param context the specified context
* @param request the specified HTTP servlet request * @param request the specified HTTP servlet request
* @param response the specified HTTP servlet response * @param response the specified HTTP servlet response
* @throws Exception io exception * @throws Exception io exception
*/ */
...@@ -212,7 +197,6 @@ public class BlogProcessor { ...@@ -212,7 +197,6 @@ public class BlogProcessor {
public void getArticlesTags(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) public void getArticlesTags(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws Exception { throws Exception {
final String pwd = request.getParameter("pwd"); final String pwd = request.getParameter("pwd");
if (Strings.isEmptyOrNull(pwd)) { if (Strings.isEmptyOrNull(pwd)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
...@@ -220,7 +204,6 @@ public class BlogProcessor { ...@@ -220,7 +204,6 @@ public class BlogProcessor {
} }
final JSONObject admin = userQueryService.getAdmin(); final JSONObject admin = userQueryService.getAdmin();
if (!MD5.hash(pwd).equals(admin.getString(User.USER_PASSWORD))) { if (!MD5.hash(pwd).equals(admin.getString(User.USER_PASSWORD))) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
...@@ -228,7 +211,6 @@ public class BlogProcessor { ...@@ -228,7 +211,6 @@ public class BlogProcessor {
} }
final JSONObject requestJSONObject = new JSONObject(); final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, 1); requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, 1);
requestJSONObject.put(Pagination.PAGINATION_PAGE_SIZE, Integer.MAX_VALUE); requestJSONObject.put(Pagination.PAGINATION_PAGE_SIZE, Integer.MAX_VALUE);
requestJSONObject.put(Pagination.PAGINATION_WINDOW_SIZE, Integer.MAX_VALUE); requestJSONObject.put(Pagination.PAGINATION_WINDOW_SIZE, Integer.MAX_VALUE);
...@@ -250,15 +232,11 @@ public class BlogProcessor { ...@@ -250,15 +232,11 @@ public class BlogProcessor {
final JSONArray articles = result.optJSONArray(Article.ARTICLES); final JSONArray articles = result.optJSONArray(Article.ARTICLES);
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
final JSONArray data = new JSONArray(); final JSONArray data = new JSONArray();
ret.put("data", data); ret.put("data", data);
for (int i = 0; i < articles.length(); i++) { for (int i = 0; i < articles.length(); i++) {
...@@ -266,14 +244,12 @@ public class BlogProcessor { ...@@ -266,14 +244,12 @@ public class BlogProcessor {
final String tagString = article.optString(Article.ARTICLE_TAGS_REF); final String tagString = article.optString(Article.ARTICLE_TAGS_REF);
final JSONArray tagArray = new JSONArray(); final JSONArray tagArray = new JSONArray();
data.put(tagArray); data.put(tagArray);
final String[] tags = tagString.split(","); final String[] tags = tagString.split(",");
for (final String tag : tags) { for (final String tag : tags) {
final String trim = tag.trim(); final String trim = tag.trim();
if (!Strings.isEmptyOrNull(trim)) { if (!Strings.isEmptyOrNull(trim)) {
tagArray.put(tag); tagArray.put(tag);
} }
...@@ -283,15 +259,16 @@ public class BlogProcessor { ...@@ -283,15 +259,16 @@ public class BlogProcessor {
/** /**
* Gets interest tags (top 10 and bottom 10). * Gets interest tags (top 10 and bottom 10).
* * <p>
* <pre> * <pre>
* { * {
* "data": ["tag1", "tag2", ....] * "data": ["tag1", "tag2", ....]
* } * }
* </pre> * </pre>
* </p>
* *
* @param context the specified context * @param context the specified context
* @param request the specified HTTP servlet request * @param request the specified HTTP servlet request
* @param response the specified HTTP servlet response * @param response the specified HTTP servlet response
* @throws Exception io exception * @throws Exception io exception
*/ */
......
...@@ -17,8 +17,6 @@ package org.b3log.solo.processor; ...@@ -17,8 +17,6 @@ package org.b3log.solo.processor;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.b3log.latke.Latkes;
import org.b3log.latke.RuntimeEnv;
import org.b3log.latke.image.Image; import org.b3log.latke.image.Image;
import org.b3log.latke.image.ImageService; import org.b3log.latke.image.ImageService;
import org.b3log.latke.image.ImageServiceFactory; import org.b3log.latke.image.ImageServiceFactory;
...@@ -35,7 +33,6 @@ import javax.servlet.http.HttpServletRequest; ...@@ -35,7 +33,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import java.io.*; import java.io.*;
import java.net.URL;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Random; import java.util.Random;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
...@@ -44,14 +41,12 @@ import java.util.zip.ZipFile; ...@@ -44,14 +41,12 @@ import java.util.zip.ZipFile;
/** /**
* Captcha processor. * Captcha processor.
*
* <p> * <p>
* Checkout <a href="http://toy-code.googlecode.com/svn/trunk/CaptchaGenerator"> * Checkout <a href="http://toy-code.googlecode.com/svn/trunk/CaptchaGenerator"> the sample captcha generator</a> for more details.
* the sample captcha generator</a> for more details.
* </p> * </p>
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.4, Oct 31, 2015 * @version 1.1.0.5, Jul 6, 2017
* @since 0.3.1 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -60,7 +55,7 @@ public class CaptchaProcessor { ...@@ -60,7 +55,7 @@ public class CaptchaProcessor {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(CaptchaProcessor.class.getName()); private static final Logger LOGGER = Logger.getLogger(CaptchaProcessor.class);
/** /**
* Images service. * Images service.
...@@ -84,7 +79,7 @@ public class CaptchaProcessor { ...@@ -84,7 +79,7 @@ public class CaptchaProcessor {
/** /**
* Gets captcha. * Gets captcha.
* *
* @param context the specified context * @param context the specified context
*/ */
@RequestProcessing(value = "/captcha.do", method = HTTPRequestMethod.GET) @RequestProcessing(value = "/captcha.do", method = HTTPRequestMethod.GET)
...@@ -132,23 +127,15 @@ public class CaptchaProcessor { ...@@ -132,23 +127,15 @@ public class CaptchaProcessor {
try { try {
captchas = new Image[CAPTCHA_COUNT]; captchas = new Image[CAPTCHA_COUNT];
ZipFile zipFile; final InputStream inputStream = SoloServletListener.class.getClassLoader().getResourceAsStream("captcha_static.zip");
final File file = File.createTempFile("b3log_captcha_static", null);
final OutputStream outputStream = new FileOutputStream(file);
if (RuntimeEnv.LOCAL == Latkes.getRuntimeEnv()) { IOUtils.copy(inputStream, outputStream);
final InputStream inputStream = SoloServletListener.class.getClassLoader().getResourceAsStream("captcha_static.zip"); final ZipFile zipFile = new ZipFile(file);
final File file = File.createTempFile("b3log_captcha_static", null);
final OutputStream outputStream = new FileOutputStream(file);
IOUtils.copy(inputStream, outputStream); IOUtils.closeQuietly(inputStream);
zipFile = new ZipFile(file); IOUtils.closeQuietly(outputStream);
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
} else {
final URL captchaURL = SoloServletListener.class.getClassLoader().getResource("captcha_static.zip");
zipFile = new ZipFile(captchaURL.getFile());
}
final Enumeration<? extends ZipEntry> entries = zipFile.entries(); final Enumeration<? extends ZipEntry> entries = zipFile.entries();
......
...@@ -70,7 +70,7 @@ import java.util.*; ...@@ -70,7 +70,7 @@ import java.util.*;
* Admin console render processing. * Admin console render processing.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.5.2.11, Jun 18, 2017 * @version 1.5.2.12, Jul 6, 2017
* @since 0.4.1 * @since 0.4.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -117,16 +117,6 @@ public class AdminConsole { ...@@ -117,16 +117,6 @@ public class AdminConsole {
@Inject @Inject
private EventManager eventManager; private EventManager eventManager;
/**
* Imports markdown files.
*
* @param context
* @param request
*/
public void importMDs(final HTTPRequestContext context, final HttpServletRequest request) {
}
/** /**
* Shows administrator index with the specified context. * Shows administrator index with the specified context.
* *
...@@ -149,11 +139,9 @@ public class AdminConsole { ...@@ -149,11 +139,9 @@ public class AdminConsole {
final JSONObject currentUser = userQueryService.getCurrentUser(request); final JSONObject currentUser = userQueryService.getCurrentUser(request);
final String userName = currentUser.optString(User.USER_NAME); final String userName = currentUser.optString(User.USER_NAME);
dataModel.put(User.USER_NAME, userName); dataModel.put(User.USER_NAME, userName);
final String roleName = currentUser.optString(User.USER_ROLE); final String roleName = currentUser.optString(User.USER_ROLE);
dataModel.put(User.USER_ROLE, roleName); dataModel.put(User.USER_ROLE, roleName);
final String email = currentUser.optString(User.USER_EMAIL); final String email = currentUser.optString(User.USER_EMAIL);
...@@ -287,7 +275,6 @@ public class AdminConsole { ...@@ -287,7 +275,6 @@ public class AdminConsole {
final StringBuilder timeZoneIdOptions = new StringBuilder(); final StringBuilder timeZoneIdOptions = new StringBuilder();
final String[] availableIDs = TimeZone.getAvailableIDs(); final String[] availableIDs = TimeZone.getAvailableIDs();
for (int i = 0; i < availableIDs.length; i++) { for (int i = 0; i < availableIDs.length; i++) {
final String id = availableIDs[i]; final String id = availableIDs[i];
String option; String option;
...@@ -323,14 +310,14 @@ public class AdminConsole { ...@@ -323,14 +310,14 @@ public class AdminConsole {
return; return;
} }
if (!Latkes.runsWithJDBCDatabase()) { final RuntimeDatabase runtimeDatabase = Latkes.getRuntimeDatabase();
if (RuntimeDatabase.H2 != runtimeDatabase && RuntimeDatabase.MYSQL != runtimeDatabase) {
context.renderJSON().renderMsg("Just support MySQL/H2 export now"); context.renderJSON().renderMsg("Just support MySQL/H2 export now");
return; return;
} }
final RuntimeDatabase runtimeDatabase = Latkes.getRuntimeDatabase();
final String dbUser = Latkes.getLocalProperty("jdbc.username"); final String dbUser = Latkes.getLocalProperty("jdbc.username");
final String dbPwd = Latkes.getLocalProperty("jdbc.password"); final String dbPwd = Latkes.getLocalProperty("jdbc.password");
final String dbURL = Latkes.getLocalProperty("jdbc.URL"); final String dbURL = Latkes.getLocalProperty("jdbc.URL");
......
...@@ -20,7 +20,6 @@ import org.apache.commons.lang.time.DateUtils; ...@@ -20,7 +20,6 @@ import org.apache.commons.lang.time.DateUtils;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.RuntimeDatabase; import org.b3log.latke.RuntimeDatabase;
import org.b3log.latke.RuntimeEnv;
import org.b3log.latke.ioc.inject.Inject; import org.b3log.latke.ioc.inject.Inject;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
...@@ -63,7 +62,7 @@ import java.util.Set; ...@@ -63,7 +62,7 @@ import java.util.Set;
* Solo initialization service. * Solo initialization service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.5.2.11, Nov 8, 2016 * @version 1.5.2.12, Jul 6, 2017
* @since 0.4.0 * @since 0.4.0
*/ */
@Service @Service
...@@ -72,7 +71,7 @@ public class InitService { ...@@ -72,7 +71,7 @@ public class InitService {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(InitService.class.getName()); private static final Logger LOGGER = Logger.getLogger(InitService.class);
/** /**
* Statistic repository. * Statistic repository.
...@@ -175,7 +174,6 @@ public class InitService { ...@@ -175,7 +174,6 @@ public class InitService {
/** /**
* Initializes Solo. * Initializes Solo.
*
* <p> * <p>
* Initializes the followings in sequence: * Initializes the followings in sequence:
* <ol> * <ol>
...@@ -184,23 +182,19 @@ public class InitService { ...@@ -184,23 +182,19 @@ public class InitService {
* <li>Administrator</li> * <li>Administrator</li>
* </ol> * </ol>
* </p> * </p>
*
* <p> * <p>
* We will try to initialize Solo 3 times at most. * We will try to initialize Solo 3 times at most.
* </p> * </p>
*
* <p> * <p>
* Posts "Hello World!" article and its comment while Solo initialized. * Posts "Hello World!" article and its comment while Solo initialized.
* </p> * </p>
* *
* @param requestJSONObject the specified request json object, for example, <pre> * @param requestJSONObject the specified request json object, for example,
* { * {
* "userName": "", * "userName": "",
* "userEmail": "", * "userEmail": "",
* "userPassword": "", // Unhashed * "userPassword": "", // Unhashed
* } * }
* </pre>
*
* @throws ServiceException service exception * @throws ServiceException service exception
*/ */
public void init(final JSONObject requestJSONObject) throws ServiceException { public void init(final JSONObject requestJSONObject) throws ServiceException {
...@@ -208,24 +202,19 @@ public class InitService { ...@@ -208,24 +202,19 @@ public class InitService {
return; return;
} }
final RuntimeEnv runtimeEnv = Latkes.getRuntimeEnv(); LOGGER.log(Level.INFO, "Solo is running with database [{0}], creates all tables", Latkes.getRuntimeDatabase());
if (RuntimeEnv.LOCAL == runtimeEnv) {
LOGGER.log(Level.INFO, "Solo is running on [" + runtimeEnv + "] environment, database [{0}], creates "
+ "all tables", Latkes.getRuntimeDatabase());
if (RuntimeDatabase.H2 == Latkes.getRuntimeDatabase()) { if (RuntimeDatabase.H2 == Latkes.getRuntimeDatabase()) {
String dataDir = Latkes.getLocalProperty("jdbc.URL"); String dataDir = Latkes.getLocalProperty("jdbc.URL");
dataDir = dataDir.replace("~", System.getProperty("user.home")); dataDir = dataDir.replace("~", System.getProperty("user.home"));
LOGGER.log(Level.INFO, "YOUR DATA will be stored in directory [" + dataDir + "], " LOGGER.log(Level.INFO, "YOUR DATA will be stored in directory [" + dataDir + "], "
+ "please pay more attention to it~"); + "please pay more attention to it~");
} }
final List<CreateTableResult> createTableResults = JdbcRepositories.initAllTables(); final List<CreateTableResult> createTableResults = JdbcRepositories.initAllTables();
for (final CreateTableResult createTableResult : createTableResults) { for (final CreateTableResult createTableResult : createTableResults) {
LOGGER.log(Level.DEBUG, "Create table result[tableName={0}, isSuccess={1}]", LOGGER.log(Level.DEBUG, "Create table result[tableName={0}, isSuccess={1}]",
createTableResult.getName(), createTableResult.isSuccess()); createTableResult.getName(), createTableResult.isSuccess());
}
} }
int retries = MAX_RETRIES_CNT; int retries = MAX_RETRIES_CNT;
...@@ -281,7 +270,7 @@ public class InitService { ...@@ -281,7 +270,7 @@ public class InitService {
final HTTPRequest req = new HTTPRequest(); final HTTPRequest req = new HTTPRequest();
req.setURL(new URL(Latkes.getServePath() + "/blog/symphony/user")); req.setURL(new URL(Latkes.getServePath() + "/blog/symphony/user"));
urlFetchService.fetch(req); urlFetchService.fetchAsync(req);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.TRACE, "Sync account failed"); LOGGER.log(Level.TRACE, "Sync account failed");
} }
...@@ -400,15 +389,13 @@ public class InitService { ...@@ -400,15 +389,13 @@ public class InitService {
/** /**
* Archive the create date with the specified article. * Archive the create date with the specified article.
* *
* @param article the specified article, for example, <pre> * @param article the specified article, for example,
* { * {
* ...., * ....,
* "oId": "", * "oId": "",
* "articleCreateDate": java.util.Date, * "articleCreateDate": java.util.Date,
* .... * ....
* } * }
* </pre>
*
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
public void archiveDate(final JSONObject article) throws RepositoryException { public void archiveDate(final JSONObject article) throws RepositoryException {
...@@ -438,7 +425,7 @@ public class InitService { ...@@ -438,7 +425,7 @@ public class InitService {
/** /**
* Adds relation of the specified tags and article. * Adds relation of the specified tags and article.
* *
* @param tags the specified tags * @param tags the specified tags
* @param article the specified article * @param article the specified article
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
...@@ -458,7 +445,7 @@ public class InitService { ...@@ -458,7 +445,7 @@ public class InitService {
* Tags the specified article with the specified tag titles. * Tags the specified article with the specified tag titles.
* *
* @param tagTitles the specified tag titles * @param tagTitles the specified tag titles
* @param article the specified article * @param article the specified article
* @return an array of tags * @return an array of tags
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
...@@ -488,14 +475,12 @@ public class InitService { ...@@ -488,14 +475,12 @@ public class InitService {
/** /**
* Initializes administrator with the specified request json object, and then logins it. * Initializes administrator with the specified request json object, and then logins it.
* *
* @param requestJSONObject the specified request json object, for example, <pre> * @param requestJSONObject the specified request json object, for example,
* { * {
* "userName": "", * "userName": "",
* "userEmail": "", * "userEmail": "",
* "userPassowrd": "" // Unhashed * "userPassowrd": "" // Unhashed
* } * }
* </pre>
*
* @throws Exception exception * @throws Exception exception
*/ */
private void initAdmin(final JSONObject requestJSONObject) throws Exception { private void initAdmin(final JSONObject requestJSONObject) throws Exception {
...@@ -538,7 +523,7 @@ public class InitService { ...@@ -538,7 +523,7 @@ public class InitService {
* Initializes statistic. * Initializes statistic.
* *
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
* @throws JSONException json exception * @throws JSONException json exception
*/ */
private void initStatistic() throws RepositoryException, JSONException { private void initStatistic() throws RepositoryException, JSONException {
LOGGER.debug("Initializing statistic...."); LOGGER.debug("Initializing statistic....");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment