Package ws

Source Code of ws.ServicePalabraSemantica

/**
*
*/
package ws;

import java.util.ArrayList;
import java.util.Collection;

import org.orm.PersistentException;
import org.orm.cfg.JDBCConnectionSetting;

import com.google.gson.Gson;

import SOAPVO.PalabraSoapVO;
import api.ContextObject;
import api.ContextObjectAuth;


/**
* @author varav
*
*/
public class ServicePalabraSemantica {
   private static boolean oBConexion = false;
  
  private void init(){
    if(oBConexion==false){
    try {
      orm.MercadoPublico2PersistentManager.setJDBCConnectionSetting(new util.Config().init());
    } catch (PersistentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    oBConexion = true;
    }
   
  }
  /**
   * Add Palabras
   */
  public int add(String category, String word, int value,String tokenBackend){
    int exits = 0;
    try {
      if(ContextObjectAuth.getoAuthUserBackend().validateToken(tokenBackend)==true){
        this.init();
        ContextObject oContent = new ContextObject();
        exits = oContent.oPalabraSemantica.add(category, value, word);
        }
      else {
        /*
         * Token no valido o expiro
         */
        return -6;
      }
    } catch (PersistentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return exits;
  }
  /**
   * Load Data return JSON
   */
  public String loadJSON(String word, String category){
    String respuesta = "";
   
    Collection<PalabraSoapVO> oColectionPalabraSoapVo = new ArrayList<PalabraSoapVO>();
   
    this.init();
    api.ContextObject context = new api.ContextObject();
      
       orm.Tmp_palabrasemantica[] ormTmp_palabrasemanticas = context.oPalabraSemantica.load(word,category);
      int length = ormTmp_palabrasemanticas.length;
     
      for (int i = 0; i < length; i++) {
       
        oColectionPalabraSoapVo.add(new PalabraSoapVO(ormTmp_palabrasemanticas[i]));
      }
     
      respuesta = new Gson().toJson(oColectionPalabraSoapVo);
    return respuesta;
  }
  /**
   * Load Data return XML
   */
  public String loadXML(String word, String category){
    String respuesta = "";
       
    this.init();
    api.ContextObject context = new api.ContextObject();
      
       orm.Tmp_palabrasemantica[] ormTmp_palabrasemanticas = context.oPalabraSemantica.load(word,category);
      int length = ormTmp_palabrasemanticas.length;

     
      for (int i = 0; i < length; i++) {
       
        respuesta = respuesta + "<registro>" +
            "<id>" + ormTmp_palabrasemanticas[i].getPs_id()+"</id>";
        respuesta = respuesta + "<palabra>" +ormTmp_palabrasemanticas[i].getPs_palabra()+"</palabra>";
        respuesta = respuesta + "<valor>" +ormTmp_palabrasemanticas[i].getPs_valor()+"</valor>";
        respuesta = respuesta + "</registro>";
      }
    return respuesta;
  }

}
TOP

Related Classes of ws.ServicePalabraSemantica

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.