maia_modificado/.svn/pristine/32/3204860a2b8679a9638c4d8f2c9...

87 lines
2.7 KiB
Plaintext
Executable File

package com.fp.facade.ejb.helper;
import java.lang.reflect.Method;
import net.sf.json.JSONObject;
import com.fp.common.exception.ExceptionHandler;
import com.fp.common.logger.APPLogger;
import com.fp.common.properties.PropertiesHandler;
import com.fp.dto.Response;
import com.fp.persistence.commondb.data.SessionData;
import com.fp.persistence.commondb.data.ThreadFacade;
public class BeanHelper {
/**
* LLena el threadlocal con el codigo de comania.
* @param pComany Codigo de compania a asocial al threadlocal.
* @throws Exception
*/
protected void fillThreadFacade(Integer pComany) throws Exception {
SessionData s = new SessionData();
s.setCompany(pComany);
s.setIsEjb(false);
ThreadFacade.setSaveRequest(s);
}
/**
* Metodo que entraga el codigo de la compania que llega en el request, con la que trabaja el usuario.
* @param data Json de entrada
* @return Integer
* @throws Exception
*/
protected Integer getCompany(String data) throws Exception {
Integer cia = 1;
try {
PropertiesHandler ph = new PropertiesHandler("fb-facade");
cia = ph.getIntValue("defaultcompany");
} catch (Exception e) {
APPLogger.getLogger().error("Error en getCompany");
e.printStackTrace();
cia = 1;
}
try {
JSONObject rpcObject = JSONObject.fromObject(data);
String dataux = rpcObject.getJSONArray("params").getString(0);
dataux = dataux.substring(1, dataux.length() - 1);
JSONObject a = JSONObject.fromObject(dataux);
String cp = a.getString("company");
return Integer.valueOf(cp);
} catch (Exception e) {
return cia;
}
}
public static void cleanThreadLocal() {
try {
Class<?> c = Class.forName("com.fp.core.fin.helper.ThreadTransaction");
Method m = c.getDeclaredMethod("unset");
m.invoke(null);
} catch (Exception e) {
// NO hacer nada
}
}
/**
* Tranforma las excepciones en un leguaje de usuario, arma y entrega la respuesta.
* @param e Excepcion a transformar a mensaje de usuario.
* @throws Exception
*/
public static final Response fillError(Throwable e) throws Throwable {
try {
// Encera el response.
Response response = null;
// Crea una nueva instancia de response.
ExceptionHandler eh = new ExceptionHandler(e, "ES");
response = new Response(eh.getCode(), eh.getUserMessage());
response.setResponseTechnicalMessage(eh.getTechnicalMessage());
return response;
} catch (Exception e2) {
throw e2;
}
}
}