package com.k_int.webapp3;

import com.k_int.bank.service.dto.DTODepthEnum;
import com.k_int.bank.service.dto.TermInfoDTO;
import com.k_int.bank.service.dto.TermReferenceDTO;
import com.k_int.bank.service.dto.VocabReferenceDTO;
import com.k_int.webapp3.util.DTOToDoc;
import com.k_int.zthes.service.impl.ZThesServiceImpl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.xml.parsers.ParserConfigurationException;

public class GetTermAction extends AbstractXmlOrHtmlAction {
  private static final long serialVersionUID = 1L;
  private final Log log = LogFactory.getLog(GetTermAction.class);
  private String auth_id;
  private String vocab_id;
  private String term_id;
  private TermInfoDTO term;
  
  public void setAuthId(String auth_id)   { this.auth_id = auth_id;   }
  public String getAuthId()               { return auth_id;           }
   
  public void setVocabId(String vocab_id) { this.vocab_id = vocab_id; }
  public String getVocabId()              { return vocab_id;          }

  public void setTermId(String term_id)   { this.term_id = term_id;   } 
  public String getTermId()               { return term_id;           }
  
  public TermInfoDTO getTerm()            { return term;              }
  

  public String responseSpecificExecute() throws Exception {    
    VocabReferenceDTO voc_ref = new VocabReferenceDTO(vocab_id, auth_id);
    TermReferenceDTO term_ref = new TermReferenceDTO(voc_ref, term_id);
    
    log.debug("Getting zthes service and looking up term");
    ZThesServiceImpl svc = (ZThesServiceImpl) ctx.getBean("ZThesService");
    term                 = svc.lookupTerm(term_ref, DTODepthEnum.FULL);
    
    if (term!=null) {
      if (response_type.equals("xml")) { 
        try {
          doc = DTOToDoc.getTermZThes(term);
          
        } catch (ParserConfigurationException pce) {
          pce.printStackTrace();
        } 
      }
      
      return SUCCESS+"-"+response_type;      
    }
    
    return ERROR+"-"+response_type;
  }
}