* @throws SecurityException the security exception
* @throws EMFUserError the EMF user error
* @throws EMFInternalError the EMF internal error
*/
public Content readTemplate(String user, String document, HashMap parameters) throws SecurityException, EMFUserError, EMFInternalError {
Content content;
BIObject biobj;
logger.debug("IN");
logger.debug("user: [" + user + "]");
logger.debug("document: [" + document + "]");
if (parameters == null) {
logger.debug("Input parameters map is null. It will be considered as an empty map");
parameters = new HashMap();
}
content = new Content();
try {
Integer id = new Integer(document);
biobj = DAOFactory.getBIObjectDAO().loadBIObjectById(id);
// only if the user is not Scheduler or Workflow system user or it is a call to retrieve a subreport,
//check visibility on document and parameter values
boolean checkNeeded = true;
boolean modContained = parameters.containsKey("SBI_READ_ONLY_TEMPLATE");
if(modContained){
boolean onlytemplate = parameters.containsValue("true");
if(onlytemplate){
checkNeeded = false;
}
}
if (checkNeeded && !UserProfile.isSchedulerUser(user) && !UserProfile.isWorkflowUser(user) && !isSubReportCall(biobj, parameters)) {
checkRequestCorrectness(user, biobj, parameters);
}
IObjTemplateDAO tempdao = DAOFactory.getObjTemplateDAO();
ObjTemplate temp = tempdao.getBIObjectActiveTemplate(biobj.getId());
if (temp==null){
logger.warn("The template dor document [" + id + "] is NULL");
throw new SecurityException("The template dor document [" + id + "] is NULL");
}
byte[] template = temp.getContent();
BASE64Encoder bASE64Encoder = new BASE64Encoder();
content.setContent(bASE64Encoder.encode(template));
logger.debug("template read");
content.setFileName(temp.getName());
} catch (NumberFormatException e) {
logger.error("NumberFormatException", e);
throw e;
} catch (EMFUserError e) {
logger.error("EMFUserError", e);