Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/2.1.0-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Mar 8, 2017
2 parents 5b6b4f3 + 0d2dbc1 commit 6e4c66b
Show file tree
Hide file tree
Showing 8 changed files with 626 additions and 35 deletions.
54 changes: 49 additions & 5 deletions src/main/java/org/b3log/symphony/api/v2/DomainAPI2.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
* <p>
* <ul>
* <li>Gets domains (/api/v2/domains), GET</li>
* <li>Gets a domain (/api/v2/domain), GET</li>
* <li>Gets a domain (/api/v2/domain/{domainURI}), GET</li>
* </ul>
* </p>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Mar 5, 2016
* @version 1.1.0.0, Mar 8, 2016
* @since 2.0.0
*/
@RequestProcessor
Expand All @@ -71,6 +71,52 @@ public class DomainAPI2 {
@Inject
private DomainQueryService domainQueryService;

/**
* Gets a domain.
*
* @param context the specified context
* @param request the specified request
* @param domainURI the specified domain URI
*/
@RequestProcessing(value = {"/api/v2/domain/{domainURI}"}, method = HTTPRequestMethod.GET)
@Before(adviceClass = {StopwatchStartAdvice.class, AnonymousViewCheck.class})
@After(adviceClass = {PermissionGrant.class, StopwatchEndAdvice.class})
public void getDomain(final HTTPRequestContext context, final HttpServletRequest request, final String domainURI) {
final JSONObject ret = new JSONObject();
context.renderJSONPretty(ret);

ret.put(Keys.STATUS_CODE, StatusCodes.ERR);
ret.put(Keys.MSG, "");

JSONObject data = null;
try {
final JSONObject domain = domainQueryService.getByURI(domainURI);
if (null == domain) {
ret.put(Keys.MSG, "Domain not found");
ret.put(Keys.STATUS_CODE, StatusCodes.NOT_FOUND);

return;
}

final List<JSONObject> tags = domainQueryService.getTags(domain.optString(Keys.OBJECT_ID));
domain.put(Domain.DOMAIN_T_TAGS, (Object) tags);

V2s.cleanDomain(domain);

data = new JSONObject();
data.put(Domain.DOMAIN, domain);

ret.put(Keys.STATUS_CODE, StatusCodes.SUCC);
} catch (final Exception e) {
final String msg = "Gets a domain failed";

LOGGER.log(Level.ERROR, msg, e);
ret.put(Keys.MSG, msg);
}

ret.put(Common.DATA, data);
}

/**
* Gets domains.
*
Expand Down Expand Up @@ -116,9 +162,7 @@ public void getDomains(final HTTPRequestContext context, final HttpServletReques

final JSONObject result = domainQueryService.getDomains(requestJSONObject, domainFields);
final List<JSONObject> domains = CollectionUtils.jsonArrayToList(result.optJSONArray(Domain.DOMAINS));
for (final JSONObject domain : domains) {
V2s.cleanDomain(domain);
}
V2s.cleanDomains(domains);

data = new JSONObject();
data.put(Domain.DOMAINS, domains);
Expand Down
50 changes: 45 additions & 5 deletions src/main/java/org/b3log/symphony/api/v2/TagAPI2.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
* <p>
* <ul>
* <li>Gets tags (/api/v2/tags), GET</li>
* <li>Gets a tag (/api/v2/tag), GET</li>
* <li>Gets a tag (/api/v2/tag/{tagURI}), GET</li>
* </ul>
* </p>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Mar 5, 2016
* @version 1.1.0.1, Mar 8, 2016
* @since 2.0.0
*/
@RequestProcessor
Expand All @@ -71,6 +71,48 @@ public class TagAPI2 {
@Inject
private TagQueryService tagQueryService;

/**
* Gets a tag.
*
* @param context the specified context
* @param request the specified request
* @param tagURI the specified tag URI
*/
@RequestProcessing(value = {"/api/v2/tag/{tagURI}"}, method = HTTPRequestMethod.GET)
@Before(adviceClass = {StopwatchStartAdvice.class, AnonymousViewCheck.class})
@After(adviceClass = {PermissionGrant.class, StopwatchEndAdvice.class})
public void getTags(final HTTPRequestContext context, final HttpServletRequest request, final String tagURI) {
final JSONObject ret = new JSONObject();
context.renderJSONPretty(ret);

ret.put(Keys.STATUS_CODE, StatusCodes.ERR);
ret.put(Keys.MSG, "");

JSONObject data = null;
try {
final JSONObject tag = tagQueryService.getTagByURI(tagURI);
if (null == tag) {
ret.put(Keys.MSG, "Tag not found");
ret.put(Keys.STATUS_CODE, StatusCodes.NOT_FOUND);

return;
}

data = new JSONObject();
data.put(Tag.TAG, tag);
V2s.cleanTag(tag);

ret.put(Keys.STATUS_CODE, StatusCodes.SUCC);
} catch (final Exception e) {
final String msg = "Gets a tag failed";

LOGGER.log(Level.ERROR, msg, e);
ret.put(Keys.MSG, msg);
}

ret.put(Common.DATA, data);
}

/**
* Gets tags.
*
Expand Down Expand Up @@ -117,9 +159,7 @@ public void getTags(final HTTPRequestContext context, final HttpServletRequest r

data = new JSONObject();
final List<JSONObject> tags = CollectionUtils.jsonArrayToList(result.optJSONArray(Tag.TAGS));
for (final JSONObject tag : tags) {
V2s.cleanTag(tag);
}
V2s.cleanTags(tags);

data.put(Tag.TAGS, tags);
data.put(Pagination.PAGINATION, result.optJSONObject(Pagination.PAGINATION));
Expand Down
Loading

0 comments on commit 6e4c66b

Please sign in to comment.