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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations