Package org.zanata.webtrans.server.rpc

Source Code of org.zanata.webtrans.server.rpc.GetTargetForLocaleHandler

package org.zanata.webtrans.server.rpc;

import lombok.extern.slf4j.Slf4j;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.zanata.dao.TextFlowTargetDAO;
import org.zanata.model.HLocale;
import org.zanata.model.HTextFlowTarget;
import org.zanata.security.ZanataIdentity;
import org.zanata.webtrans.server.ActionHandlerFor;
import org.zanata.webtrans.shared.model.TextFlowTarget;
import org.zanata.webtrans.shared.model.TextFlowTargetId;
import org.zanata.webtrans.shared.rpc.GetTargetForLocale;
import org.zanata.webtrans.shared.rpc.GetTargetForLocaleResult;

@Name("webtrans.gwt.GetTargetForLocaleHandler")
@Scope(ScopeType.STATELESS)
@ActionHandlerFor(GetTargetForLocale.class)
@Slf4j
public class GetTargetForLocaleHandler extends
        AbstractActionHandler<GetTargetForLocale, GetTargetForLocaleResult> {
    @In
    private ZanataIdentity identity;
    @In
    private TextFlowTargetDAO textFlowTargetDAO;

    @Override
    public GetTargetForLocaleResult execute(GetTargetForLocale action,
    ExecutionContext context) throws ActionException {
        try {
            identity.checkLoggedIn();

            HTextFlowTarget hTextFlowTarget = textFlowTargetDAO
                    .getTextFlowTarget(
                    action.getSourceTransUnitId().getId(),
                    action.getLocale().getId().getLocaleId());

            if (hTextFlowTarget == null) {
                return new GetTargetForLocaleResult(null);
            } else {
                String displayName = retrieveDisplayName(hTextFlowTarget.getLocale());
                TextFlowTarget textFlowTarget = new TextFlowTarget(
                        new TextFlowTargetId(hTextFlowTarget.getId()),
                        action.getLocale(), hTextFlowTarget.getContents().get(0),
                        displayName);

                return new GetTargetForLocaleResult(textFlowTarget);
            }
        } catch (Exception e) {
            log.error("Exception when fetching target: ", e);
            return new GetTargetForLocaleResult(null);
        }
    }

    public String retrieveDisplayName(HLocale hLocale) {
        return hLocale.retrieveDisplayName();
    }

    @Override
    public void rollback(GetTargetForLocale action, GetTargetForLocaleResult result,
    ExecutionContext context) throws ActionException {
    }
}
TOP

Related Classes of org.zanata.webtrans.server.rpc.GetTargetForLocaleHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.