Search in sources :

Example 71 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.

the class AdminProcessor method showReservedWords.

/**
 * Shows reserved words.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/reserved-words", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showReservedWords(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/reserved-words.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModel.put(Common.WORDS, optionQueryService.getReservedWords());
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 72 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.

the class AdminProcessor method showDomains.

/**
 * Shows admin domains.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/domains", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showDomains(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/domains.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    String pageNumStr = request.getParameter("p");
    if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
        pageNumStr = "1";
    }
    final int pageNum = Integer.valueOf(pageNumStr);
    final int pageSize = PAGE_SIZE;
    final int windowSize = WINDOW_SIZE;
    final JSONObject requestJSONObject = new JSONObject();
    requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    requestJSONObject.put(Pagination.PAGINATION_PAGE_SIZE, pageSize);
    requestJSONObject.put(Pagination.PAGINATION_WINDOW_SIZE, windowSize);
    final String domainTitle = request.getParameter(Common.TITLE);
    if (!Strings.isEmptyOrNull(domainTitle)) {
        requestJSONObject.put(Domain.DOMAIN_TITLE, domainTitle);
    }
    final Map<String, Class<?>> domainFields = new HashMap<>();
    domainFields.put(Keys.OBJECT_ID, String.class);
    domainFields.put(Domain.DOMAIN_TITLE, String.class);
    domainFields.put(Domain.DOMAIN_DESCRIPTION, String.class);
    domainFields.put(Domain.DOMAIN_ICON_PATH, String.class);
    domainFields.put(Domain.DOMAIN_STATUS, String.class);
    domainFields.put(Domain.DOMAIN_URI, String.class);
    final JSONObject result = domainQueryService.getDomains(requestJSONObject, domainFields);
    dataModel.put(Common.ALL_DOMAINS, CollectionUtils.jsonArrayToList(result.optJSONArray(Domain.DOMAINS)));
    final JSONObject pagination = result.optJSONObject(Pagination.PAGINATION);
    final int pageCount = pagination.optInt(Pagination.PAGINATION_PAGE_COUNT);
    final JSONArray pageNums = pagination.optJSONArray(Pagination.PAGINATION_PAGE_NUMS);
    dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.opt(0));
    dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.opt(pageNums.length() - 1));
    dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
    dataModel.put(Pagination.PAGINATION_PAGE_NUMS, CollectionUtils.jsonArrayToList(pageNums));
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 73 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.

the class AdminProcessor method addDomainTag.

/**
 * Adds a tag into a domain.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @param domainId the specified domain id
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/domain/{domainId}/add-tag", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void addDomainTag(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String domainId) throws Exception {
    String tagTitle = request.getParameter(Tag.TAG_TITLE);
    final JSONObject tag = tagQueryService.getTagByTitle(tagTitle);
    String tagId;
    if (tag != null) {
        tagId = tag.optString(Keys.OBJECT_ID);
    } else {
        try {
            if (Strings.isEmptyOrNull(tagTitle)) {
                throw new Exception(langPropsService.get("tagsErrorLabel"));
            }
            tagTitle = Tag.formatTags(tagTitle);
            if (!Tag.containsWhiteListTags(tagTitle)) {
                if (!Tag.TAG_TITLE_PATTERN.matcher(tagTitle).matches()) {
                    throw new Exception(langPropsService.get("tagsErrorLabel"));
                }
                if (tagTitle.length() > Tag.MAX_TAG_TITLE_LENGTH) {
                    throw new Exception(langPropsService.get("tagsErrorLabel"));
                }
            }
        } catch (final Exception e) {
            final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
            context.setRenderer(renderer);
            renderer.setTemplateName("admin/error.ftl");
            final Map<String, Object> dataModel = renderer.getDataModel();
            dataModel.put(Keys.MSG, e.getMessage());
            dataModelService.fillHeaderAndFooter(request, response, dataModel);
            return;
        }
        final JSONObject admin = (JSONObject) request.getAttribute(User.USER);
        final String userId = admin.optString(Keys.OBJECT_ID);
        try {
            tagId = tagMgmtService.addTag(userId, tagTitle);
        } catch (final ServiceException e) {
            final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
            context.setRenderer(renderer);
            renderer.setTemplateName("admin/error.ftl");
            final Map<String, Object> dataModel = renderer.getDataModel();
            dataModel.put(Keys.MSG, e.getMessage());
            dataModelService.fillHeaderAndFooter(request, response, dataModel);
            return;
        }
    }
    if (domainQueryService.containTag(tagTitle, domainId)) {
        final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
        context.setRenderer(renderer);
        renderer.setTemplateName("admin/error.ftl");
        final Map<String, Object> dataModel = renderer.getDataModel();
        String msg = langPropsService.get("domainContainTagLabel");
        msg = msg.replace("{tag}", tagTitle);
        dataModel.put(Keys.MSG, msg);
        dataModelService.fillHeaderAndFooter(request, response, dataModel);
        return;
    }
    final JSONObject domainTag = new JSONObject();
    domainTag.put(Domain.DOMAIN + "_" + Keys.OBJECT_ID, domainId);
    domainTag.put(Tag.TAG + "_" + Keys.OBJECT_ID, tagId);
    domainMgmtService.addDomainTag(domainTag);
    response.sendRedirect(Latkes.getServePath() + "/admin/domain/" + domainId);
}
Also used : JSONObject(org.json.JSONObject) ServiceException(org.b3log.latke.service.ServiceException) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) ServiceException(org.b3log.latke.service.ServiceException) ParseException(java.text.ParseException) IOException(java.io.IOException) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 74 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.

the class AdminProcessor method removeDomain.

/**
 * Removes a tag from a domain.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @param domainId the specified domain id
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/domain/{domainId}/remove-tag", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void removeDomain(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String domainId) throws Exception {
    final String tagTitle = request.getParameter(Tag.TAG_TITLE);
    final JSONObject tag = tagQueryService.getTagByTitle(tagTitle);
    if (null == tag) {
        final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
        context.setRenderer(renderer);
        renderer.setTemplateName("admin/error.ftl");
        final Map<String, Object> dataModel = renderer.getDataModel();
        dataModel.put(Keys.MSG, langPropsService.get("invalidTagLabel"));
        dataModelService.fillHeaderAndFooter(request, response, dataModel);
        return;
    }
    final JSONObject domainTag = new JSONObject();
    domainTag.put(Domain.DOMAIN + "_" + Keys.OBJECT_ID, domainId);
    domainTag.put(Tag.TAG + "_" + Keys.OBJECT_ID, tag.optString(Keys.OBJECT_ID));
    domainMgmtService.removeDomainTag(domainId, tag.optString(Keys.OBJECT_ID));
    response.sendRedirect(Latkes.getServePath() + "/admin/domain/" + domainId);
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 75 with AbstractFreeMarkerRenderer

use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.

the class AdminProcessor method initPoint.

/**
 * Compensates a user's initial point.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @param userId   the specified user id
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/user/{userId}/init-point", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void initPoint(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userId) throws Exception {
    try {
        final JSONObject user = userQueryService.getUser(userId);
        if (null == user || UserExt.USER_STATUS_C_VALID != user.optInt(UserExt.USER_STATUS) || UserExt.NULL_USER_NAME.equals(user.optString(User.USER_NAME))) {
            response.sendRedirect(Latkes.getServePath() + "/admin/user/" + userId);
            return;
        }
        final List<JSONObject> records = pointtransferQueryService.getLatestPointtransfers(userId, Pointtransfer.TRANSFER_TYPE_C_INIT, 1);
        if (records.isEmpty()) {
            pointtransferMgmtService.transfer(Pointtransfer.ID_C_SYS, userId, Pointtransfer.TRANSFER_TYPE_C_INIT, Pointtransfer.TRANSFER_SUM_C_INIT, userId, Long.valueOf(userId));
        }
    } catch (final IOException | NumberFormatException | ServiceException e) {
        final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
        context.setRenderer(renderer);
        renderer.setTemplateName("admin/error.ftl");
        final Map<String, Object> dataModel = renderer.getDataModel();
        dataModel.put(Keys.MSG, e.getMessage());
        dataModelService.fillHeaderAndFooter(request, response, dataModel);
        return;
    }
    response.sendRedirect(Latkes.getServePath() + "/admin/user/" + userId);
}
Also used : JSONObject(org.json.JSONObject) ServiceException(org.b3log.latke.service.ServiceException) IOException(java.io.IOException) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Aggregations

AbstractFreeMarkerRenderer (org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer)120 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)119 JSONObject (org.json.JSONObject)117 After (org.b3log.latke.servlet.annotation.After)105 Before (org.b3log.latke.servlet.annotation.Before)105 ServiceException (org.b3log.latke.service.ServiceException)22 IOException (java.io.IOException)15 Date (java.util.Date)12 ArrayList (java.util.ArrayList)8 JSONArray (org.json.JSONArray)8 Auth (com.qiniu.util.Auth)7 FreeMarkerRenderer (org.b3log.latke.servlet.renderer.freemarker.FreeMarkerRenderer)7 ConsoleRenderer (org.b3log.solo.processor.renderer.ConsoleRenderer)7 ParseException (java.text.ParseException)6 List (java.util.List)6 EventException (org.b3log.latke.event.EventException)3 JSONException (org.json.JSONException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Locale (java.util.Locale)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2