class DomainMgmtService {

    /**
     * Logger.
     */
    private static final Logger LOGGER = LogManager.getLogger(DomainMgmtService.class);

    /**
     * Domain repository.
     */
    @Inject
    private DomainRepository domainRepository;

    /**
     * Domain tag repository.
     */
    @Inject
    private DomainTagRepository domainTagRepository;

    /**
     * Option repository.
     */
    @Inject
    private OptionRepository optionRepository;

    /**
     * Domain cache.
     */
    @Inject
    private DomainCache domainCache;

    /**
     * Removes a domain-tag relation.
     *
     * @param domainId the specified domain id
     * @param tagId    the specified tag id
     */
    @Transactional
    public void removeDomainTag(final String domainId, final String tagId) {
        try {
            final JSONObject domain = domainRepository.get(domainId);
            domain.put(Domain.DOMAIN_TAG_COUNT, domain.optInt(Domain.DOMAIN_TAG_COUNT) - 1);

            domainRepository.update(domainId, domain);

            final Query query = new Query().setFilter(
                    CompositeFilterOperator.and(
                            new PropertyFilter(Domain.DOMAIN + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, domainId),
                            new PropertyFilter(Tag.TAG + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, tagId)));
            final List<JSONObject> relations = domainTagRepository.getList(query);
            if (relations.size() < 1) {
                return;
            }

            final JSONObject relation = relations.get(0);
            domainTagRepository.remove(relation.optString(Keys.OBJECT_ID));

            // Refresh cache
            domainCache.loadDomains();
        } catch (final RepositoryException e) {
            LOGGER.log(Level.ERROR, "Adds a domain-tag relation failed", e);
        }
    }

    /**
     * Adds a domain-tag relation.
     *
     * @param domainTag the specified domain-tag relation
     */
    @Transactional
    public void addDomainTag(final JSONObject domainTag) {<FILL_FUNCTION_BODY>}

    /**
     * Adds a domain relation.
     *
     * @param domain the specified domain relation
     * @return domain id
     * @throws ServiceException service exception
     */
    @Transactional
    public String addDomain(final JSONObject domain) throws ServiceException {
        try {
            final JSONObject record = new JSONObject();
            record.put(Domain.DOMAIN_CSS, domain.optString(Domain.DOMAIN_CSS));
            record.put(Domain.DOMAIN_DESCRIPTION, domain.optString(Domain.DOMAIN_DESCRIPTION));
            record.put(Domain.DOMAIN_ICON_PATH, domain.optString(Domain.DOMAIN_ICON_PATH));
            record.put(Domain.DOMAIN_SEO_DESC, domain.optString(Domain.DOMAIN_SEO_DESC));
            record.put(Domain.DOMAIN_SEO_KEYWORDS, domain.optString(Domain.DOMAIN_SEO_KEYWORDS));
            record.put(Domain.DOMAIN_SEO_TITLE, domain.optString(Domain.DOMAIN_SEO_TITLE));
            record.put(Domain.DOMAIN_STATUS, domain.optInt(Domain.DOMAIN_STATUS));
            record.put(Domain.DOMAIN_TITLE, domain.optString(Domain.DOMAIN_TITLE));
            record.put(Domain.DOMAIN_URI, domain.optString(Domain.DOMAIN_URI));
            record.put(Domain.DOMAIN_TAG_COUNT, 0);
            record.put(Domain.DOMAIN_TYPE, "");
            record.put(Domain.DOMAIN_SORT, 10);
            record.put(Domain.DOMAIN_NAV, Domain.DOMAIN_NAV_C_ENABLED);

            final JSONObject domainCntOption = optionRepository.get(Option.ID_C_STATISTIC_DOMAIN_COUNT);
            final int domainCnt = domainCntOption.optInt(Option.OPTION_VALUE);
            domainCntOption.put(Option.OPTION_VALUE, domainCnt + 1);
            optionRepository.update(Option.ID_C_STATISTIC_DOMAIN_COUNT, domainCntOption);

            final String ret = domainRepository.add(record);

            // Refresh cache
            domainCache.loadDomains();

            return ret;
        } catch (final RepositoryException e) {
            LOGGER.log(Level.ERROR, "Adds a domain failed", e);

            throw new ServiceException(e);
        }
    }

    /**
     * Updates the specified domain by the given domain id.
     *
     * @param domainId the given domain id
     * @param domain   the specified domain
     */
    @Transactional
    public void updateDomain(final String domainId, final JSONObject domain) {
        try {
            domainRepository.update(domainId, domain);

            // Refresh cache
            domainCache.loadDomains();
        } catch (final RepositoryException e) {
            LOGGER.log(Level.ERROR, "Updates a domain [id=" + domainId + "] failed", e);
        }
    }

    /**
     * Removes the specified domain by the given domain id.
     *
     * @param domainId the given domain id
     */
    @Transactional
    public void removeDomain(final String domainId) {
        try {
            domainTagRepository.removeByDomainId(domainId);
            domainRepository.remove(domainId);

            final JSONObject domainCntOption = optionRepository.get(Option.ID_C_STATISTIC_DOMAIN_COUNT);
            final int domainCnt = domainCntOption.optInt(Option.OPTION_VALUE);
            domainCntOption.put(Option.OPTION_VALUE, domainCnt - 1);
            optionRepository.update(Option.ID_C_STATISTIC_DOMAIN_COUNT, domainCntOption);

            // Refresh cache
            domainCache.loadDomains();
        } catch (final RepositoryException e) {
            LOGGER.log(Level.ERROR, "Updates a domain [id=" + domainId + "] failed", e);
        }
    }
}

        try {
            final String domainId = domainTag.optString(Domain.DOMAIN + "_" + Keys.OBJECT_ID);
            final JSONObject domain = domainRepository.get(domainId);
            domain.put(Domain.DOMAIN_TAG_COUNT, domain.optInt(Domain.DOMAIN_TAG_COUNT) + 1);

            domainRepository.update(domainId, domain);
            domainTagRepository.add(domainTag);

            // Refresh cache
            domainCache.loadDomains();
        } catch (final RepositoryException e) {
            LOGGER.log(Level.ERROR, "Adds a domain-tag relation failed", e);
        }
    
<no_super_class>