Commit c3574d1a authored by Liang Ding's avatar Liang Ding

c

parent b9b2d102
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.service; package org.b3log.solo.service;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.Query; import org.b3log.latke.repository.Query;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.repository.RepositoryException;
import org.b3log.latke.service.ServiceException; import org.b3log.latke.service.ServiceException;
import org.b3log.latke.util.CollectionUtils; import org.b3log.latke.util.CollectionUtils;
import org.b3log.solo.model.Tag; import org.b3log.solo.model.Tag;
import org.b3log.solo.repository.TagRepository; import org.b3log.solo.repository.TagRepository;
import org.b3log.solo.repository.impl.TagRepositoryImpl; import org.b3log.solo.repository.impl.TagRepositoryImpl;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Tag query service. * Tag query service.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
<<<<<<< HEAD * @version 1.0.0.3, Jun 28, 2012
* @version 1.0.0.2, Nov 11, 2011 * @since 0.4.0
======= */
* @version 1.0.0.3, Jun 28, 2012 public final class TagQueryService {
>>>>>>> origin/0.4.6
* @since 0.4.0 /**
*/ * Logger.
public final class TagQueryService { */
private static final Logger LOGGER = Logger.getLogger(TagQueryService.class.getName());
/** /**
* Logger. * Tag repository.
*/ */
<<<<<<< HEAD private TagRepository tagRepository = TagRepositoryImpl.getInstance();
private static final Logger LOGGER =
Logger.getLogger(TagQueryService.class.getName()); /**
======= * Gets a tag by the specified tag title.
private static final Logger LOGGER = Logger.getLogger(TagQueryService.class.getName()); *
>>>>>>> origin/0.4.6 * @param tagTitle the specified tag title
/** * @return for example,
* Tag repository. * <pre>
*/ * {
private TagRepository tagRepository = TagRepositoryImpl.getInstance(); * "tag": {
* "oId": "",
/** * "tagTitle": "",
* Gets a tag by the specified tag title. * "tagReferenceCount": int,
* * "tagPublishedRefCount": int
* @param tagTitle the specified tag title * }
* @return for example, * }
* <pre> * </pre>, returns {@code null} if not found
* { * @throws ServiceException service exception
* "tag": { */
* "oId": "", public JSONObject getTagByTitle(final String tagTitle) throws ServiceException {
* "tagTitle": "", try {
* "tagReferenceCount": int, final JSONObject ret = new JSONObject();
* "tagPublishedRefCount": int
* } final JSONObject tag = tagRepository.getByTitle(tagTitle);
* }
* </pre>, returns {@code null} if not found if (null == tag) {
* @throws ServiceException service exception return null;
*/ }
<<<<<<< HEAD
public JSONObject getTagByTitle(final String tagTitle) ret.put(Tag.TAG, tag);
throws ServiceException {
======= LOGGER.log(Level.FINER, "Got an tag[title={0}]", tagTitle);
public JSONObject getTagByTitle(final String tagTitle) throws ServiceException {
>>>>>>> origin/0.4.6 return ret;
try { } catch (final RepositoryException e) {
final JSONObject ret = new JSONObject(); LOGGER.log(Level.SEVERE, "Gets an article failed", e);
throw new ServiceException(e);
final JSONObject tag = tagRepository.getByTitle(tagTitle); }
}
if (null == tag) {
return null; /**
} * Gets the count of tags.
*
ret.put(Tag.TAG, tag); * @return count of tags
* @throws ServiceException service exception
LOGGER.log(Level.FINER, "Got an tag[title={0}]", tagTitle); */
public long getTagCount() throws ServiceException {
return ret; try {
} catch (final RepositoryException e) { return tagRepository.count();
LOGGER.log(Level.SEVERE, "Gets an article failed", e); } catch (final RepositoryException e) {
throw new ServiceException(e); LOGGER.log(Level.SEVERE, "Gets tags failed", e);
}
} throw new ServiceException(e);
}
/** }
<<<<<<< HEAD
======= /**
* Gets the count of tags. >>>>>>> origin/0.4.6
* * Gets all tags.
* @return count of tags *
* @throws ServiceException service exception * @return for example,
*/ * <pre>
public long getTagCount() throws ServiceException { * [
try { * {"tagTitle": "", "tagReferenceCount": int, ....},
return tagRepository.count(); * ....
} catch (final RepositoryException e) { * ]
LOGGER.log(Level.SEVERE, "Gets tags failed", e); * </pre>, returns an empty list if not found
* @throws ServiceException service exception
throw new ServiceException(e); */
} public List<JSONObject> getTags() throws ServiceException {
} try {
final Query query = new Query().setPageCount(1);
/**
>>>>>>> origin/0.4.6 final JSONObject result = tagRepository.get(query);
* Gets all tags. final JSONArray tagArray = result.optJSONArray(Keys.RESULTS);
*
* @return for example, return CollectionUtils.jsonArrayToList(tagArray);
* <pre> } catch (final RepositoryException e) {
* [ LOGGER.log(Level.SEVERE, "Gets tags failed", e);
* {"tagTitle": "", "tagReferenceCount": int, ....},
* .... throw new ServiceException(e);
* ] }
* </pre>, returns an empty list if not found }
* @throws ServiceException service exception
*/ /**
public List<JSONObject> getTags() throws ServiceException { * Gets the {@link TagQueryService} singleton.
try { *
final Query query = new Query().setPageCount(1); * @return the singleton
*/
final JSONObject result = tagRepository.get(query); public static TagQueryService getInstance() {
final JSONArray tagArray = result.optJSONArray(Keys.RESULTS); return SingletonHolder.SINGLETON;
}
return CollectionUtils.jsonArrayToList(tagArray);
} catch (final RepositoryException e) { /**
LOGGER.log(Level.SEVERE, "Gets tags failed", e); * Private constructor.
*/
throw new ServiceException(e); private TagQueryService() {
} }
}
/**
/** * Singleton holder.
* Gets the {@link TagQueryService} singleton. *
* * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @return the singleton * @version 1.0.0.0, Oct 24, 2011
*/ */
public static TagQueryService getInstance() { private static final class SingletonHolder {
return SingletonHolder.SINGLETON;
} /**
* Singleton.
/** */
* Private constructor. private static final TagQueryService SINGLETON =
*/ new TagQueryService();
private TagQueryService() {
} /**
* Private default constructor.
/** */
* Singleton holder. private SingletonHolder() {
* }
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> }
* @version 1.0.0.0, Oct 24, 2011 }
*/
private static final class SingletonHolder {
/**
* Singleton.
*/
private static final TagQueryService SINGLETON =
new TagQueryService();
/**
* Private default constructor.
*/
private SingletonHolder() {
}
}
}
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