public void fillEmptyAnalyticalDrivers( Map parameters, BIObject dossier, BIObject containedDocument) { logger.debug("IN"); List dossierParameters = dossier.getBiObjectParameters(); if (dossierParameters != null && dossierParameters.size() > 0) { Iterator it = dossierParameters.iterator(); while (it.hasNext()) { BIObjectParameter dossierParameter = (BIObjectParameter) it.next(); List<BIObjectParameter> containedDocumentParameters = getRelevantContainedDocumentAnalyticalDrivers(dossierParameter, containedDocument); if (containedDocumentParameters != null && containedDocumentParameters.size() > 0) { Iterator<BIObjectParameter> containedDocumentParametersIt = containedDocumentParameters.iterator(); while (containedDocumentParametersIt.hasNext()) { BIObjectParameter containedDocumentParameter = containedDocumentParametersIt.next(); if (isEmpty(containedDocumentParameter, parameters)) { logger.debug( "Updating parameters of document [" + "label : " + containedDocument.getLabel() + "name : " + containedDocument.getName() + "]"); fillEmptyAnalyticalDriver(dossierParameter, containedDocumentParameter, parameters); break; } } } } } logger.debug("OUT"); }
private void newConfiguredDocumentHandler(SourceBean request, SourceBean response) throws SourceBeanException, EMFUserError { logger.debug("IN"); String tempFolder = (String) request.getAttribute(DossierConstants.DOSSIER_TEMP_FOLDER); Object objIdObj = request.getAttribute(DossierConstants.DOSSIER_CONFIGURED_BIOBJECT_ID); if (!(objIdObj instanceof String)) { Map errBackPars = new HashMap(); errBackPars.put("PAGE", DossierConstants.DOSSIER_MANAGEMENT_PAGE); errBackPars.put(DossierConstants.DOSSIER_TEMP_FOLDER, tempFolder); errBackPars.put(LightNavigationManager.LIGHT_NAVIGATOR_DISABLED, "true"); errBackPars.put(SpagoBIConstants.OPERATION, DossierConstants.OPERATION_DETAIL_DOSSIER); throw new EMFUserError( EMFErrorSeverity.ERROR, "102", null, errBackPars, "component_dossier_messages"); } String objIdStr = (String) objIdObj; Integer objId = new Integer(objIdStr); BIObject obj = null; List params = null; List roleList = null; try { IBIObjectDAO biobjdao = DAOFactory.getBIObjectDAO(); obj = biobjdao.loadBIObjectById(objId); Integer id = obj.getId(); IBIObjectParameterDAO biobjpardao = DAOFactory.getBIObjectParameterDAO(); params = biobjpardao.loadBIObjectParametersById(id); IRoleDAO roleDao = DAOFactory.getRoleDAO(); roleList = roleDao.loadAllRoles(); } catch (Exception e) { SpagoBITracer.major( DossierConstants.NAME_MODULE, this.getClass().getName(), "newConfiguredDocumentHandler", "Error while loading biobje parameters and roles", e); } Integer id = obj.getId(); String descr = obj.getDescription(); String label = obj.getLabel(); String name = obj.getName(); Iterator iterParams = params.iterator(); HashMap parNamesMap = new HashMap(); HashMap parValueMap = new HashMap(); while (iterParams.hasNext()) { BIObjectParameter par = (BIObjectParameter) iterParams.next(); String parLabel = par.getLabel(); String parUrlName = par.getParameterUrlName(); parNamesMap.put(parLabel, parUrlName); parValueMap.put(parUrlName, ""); } response.setAttribute("parnamemap", parNamesMap); response.setAttribute("parvaluemap", parValueMap); response.setAttribute("idobj", id); response.setAttribute("description", descr); response.setAttribute("label", label); response.setAttribute("name", name); response.setAttribute(DossierConstants.PUBLISHER_NAME, "DossierConfiguredDocumentDetail"); logger.debug("OUT"); }
/** This action is called by the user who wants to export the result of a Kpi in PDF */ public void service(SourceBean serviceRequest, SourceBean serviceResponse) throws Exception { File tmpFile = null; logger.debug("IN"); HttpServletRequest httpRequest = getHttpRequest(); HttpSession session = httpRequest.getSession(); this.freezeHttpResponse(); try { // get KPI result List<KpiResourceBlock> listKpiBlocks = (List<KpiResourceBlock>) session.getAttribute("KPI_BLOCK"); // List<KpiResourceBlock> listKpiBlocks=executeKpi(objectId); // recover BiObject Name Object idObject = serviceRequest.getAttribute(SpagoBIConstants.OBJECT_ID); if (idObject == null) { logger.error("Document id not found"); return; } Integer id = Integer.valueOf(idObject.toString()); BIObject document = DAOFactory.getBIObjectDAO().loadBIObjectById(id); String docName = document.getName(); // Recover user Id HashedMap parameters = new HashedMap(); String userId = null; Object userIdO = serviceRequest.getAttribute("user_id"); if (userIdO != null) userId = userIdO.toString(); it.eng.spagobi.engines.exporters.KpiExporter exporter = new KpiExporter(); tmpFile = exporter.getKpiReportPDF(listKpiBlocks, document, userId); String outputType = "PDF"; String mimeType = "application/pdf"; logger.debug("Report exported succesfully"); HttpServletResponse response = getHttpResponse(); response.setContentType(mimeType); response.setHeader("Content-Disposition", "filename=\"report." + outputType + "\";"); response.setContentLength((int) tmpFile.length()); BufferedInputStream in = new BufferedInputStream(new FileInputStream(tmpFile)); int b = -1; while ((b = in.read()) != -1) { response.getOutputStream().write(b); } response.getOutputStream().flush(); in.close(); logger.debug("OUT"); } catch (Throwable e) { logger.error("An exception has occured", e); throw new Exception(e); } finally { tmpFile.delete(); } }
private void addMetadataAndContent(BIObject biObject, Map pars) { logger.debug("IN"); try { if (biObject.getObjMetaDataAndContents() != null) { MetadataJSONSerializer jsonSerializer = new MetadataJSONSerializer(); JSONArray metaArray = new JSONArray(); Locale locale = getLocale(); Domain typeDom = DAOFactory.getDomainDAO().loadDomainById(biObject.getBiObjectTypeID()); MessageBuilder msgBuild = new MessageBuilder(); // fill thecnical metadata JSONObject labelJSON = new JSONObject(); String label = msgBuild.getMessage(GetMetadataAction.LABEL, locale); labelJSON.put("meta_name", label); labelJSON.put("meta_content", biObject.getLabel()); labelJSON.put("meta_type", "GENERAL_META"); JSONObject nameJSON = new JSONObject(); String name = msgBuild.getMessage(GetMetadataAction.NAME, locale); nameJSON.put("meta_name", name); nameJSON.put("meta_content", biObject.getName()); nameJSON.put("meta_type", "GENERAL_META"); JSONObject typeJSON = new JSONObject(); String typeL = msgBuild.getMessage(GetMetadataAction.TYPE, locale); String valueType = msgBuild.getMessage(typeDom.getValueName(), locale); typeJSON.put("meta_name", typeL); typeJSON.put("meta_content", valueType); typeJSON.put("meta_type", "GENERAL_META"); JSONObject engineJSON = new JSONObject(); String engine = msgBuild.getMessage(GetMetadataAction.ENG_NAME, locale); engineJSON.put("meta_name", engine); engineJSON.put("meta_content", biObject.getEngine().getName()); engineJSON.put("meta_type", "GENERAL_META"); metaArray.put(labelJSON); metaArray.put(nameJSON); metaArray.put(typeJSON); metaArray.put(engineJSON); for (Iterator iterator = biObject.getObjMetaDataAndContents().iterator(); iterator.hasNext(); ) { DocumentMetadataProperty type = (DocumentMetadataProperty) iterator.next(); Object o = jsonSerializer.serialize(type, locale); metaArray.put(o); logger.debug("Metadata serialzied " + o); } logger.debug("Metadata array serialzied " + metaArray); pars.put(METADATA_AND_METACONTENT, metaArray); } else { logger.debug("no meta and metacontent defined"); } } catch (Exception e) { logger.error( "Impossibile to serialize metadata and metacontent for object with label " + biObject.getLabel(), e); throw new RuntimeException( "Impossibile to serialize metadata and metacontent for object with label " + biObject.getLabel(), e); } logger.debug("OUT"); }
private void saveConfiguredDocumentHandler(SourceBean request, SourceBean response) throws Exception { logger.debug("IN"); String tempFolder = (String) request.getAttribute(DossierConstants.DOSSIER_TEMP_FOLDER); String label = (String) request.getAttribute("biobject_label"); // get logical name assigned to the configured document String logicalName = (String) request.getAttribute("logicalname"); if ((logicalName == null) || logicalName.trim().equalsIgnoreCase("")) { logicalName = ""; // throw new EMFUserError(EMFErrorSeverity.ERROR, 103, "component_dossier_messages"); } // load biobject using label // Integer id = new Integer(idobj); IBIObjectDAO biobjdao = DAOFactory.getBIObjectDAO(); BIObject obj = biobjdao.loadBIObjectByLabel(label); IBIObjectParameterDAO biobjpardao = DAOFactory.getBIObjectParameterDAO(); // gets parameters of the biobject List params = biobjpardao.loadBIObjectParametersById(obj.getId()); Iterator iterParams = params.iterator(); // get map of the param url name and value assigned boolean findOutFormat = false; Map paramValueMap = new HashMap(); Map paramNameMap = new HashMap(); while (iterParams.hasNext()) { BIObjectParameter par = (BIObjectParameter) iterParams.next(); String parUrlName = par.getParameterUrlName(); if (parUrlName.equalsIgnoreCase("outputType")) findOutFormat = true; String value = (String) request.getAttribute(parUrlName); paramValueMap.put(parUrlName, value); paramNameMap.put(par.getLabel(), par.getParameterUrlName()); } if (!findOutFormat) { paramValueMap.put("outputType", "JPGBASE64"); } // fill a configured document bo with data retrived ConfiguredBIDocument confDoc = new ConfiguredBIDocument(); confDoc.setDescription(obj.getDescription()); // confDoc.setId(obj.getId()); confDoc.setLabel(obj.getLabel()); confDoc.setParameters(paramValueMap); confDoc.setName(obj.getName()); confDoc.setLogicalName(logicalName); // check if the error handler contains validation errors EMFErrorHandler errorHandler = getResponseContainer().getErrorHandler(); if (errorHandler.isOKByCategory(EMFErrorCategory.VALIDATION_ERROR)) { // store the configured document IDossierDAO dossierDao = new DossierDAOHibImpl(); dossierDao.addConfiguredDocument(confDoc, tempFolder); response.setAttribute(DossierConstants.PUBLISHER_NAME, "DossierLoopbackDossierDetail"); } else { // set attribute into response response.setAttribute("parnamemap", paramNameMap); response.setAttribute("parvaluemap", paramValueMap); // response.setAttribute("idobj", confDoc.getId()); response.setAttribute("description", confDoc.getDescription()); response.setAttribute("label", confDoc.getLabel()); response.setAttribute("name", confDoc.getName()); response.setAttribute("logicalname", confDoc.getLogicalName()); response.setAttribute(DossierConstants.PUBLISHER_NAME, "DossierConfiguredDocumentDetail"); } logger.debug("OUT"); }
public void doService() { logger.debug("IN"); try { // retrieving execution instance from session, no need to check if user is able to execute the // current document ExecutionInstance executionInstance = getContext().getExecutionInstance(ExecutionInstance.class.getName()); BIObject obj = executionInstance.getBIObject(); BIObjectNotesManager objectNManager = new BIObjectNotesManager(); String execIdentifier = objectNManager.getExecutionIdentifier(obj); String previousNotes = this.getAttributeAsString("PREVIOUS_NOTES"); logger.debug("Parameter [" + PREVIOUS_NOTES + "] is equal to [" + previousNotes + "]"); String notes = this.getAttributeAsString("NOTES"); logger.debug("Parameter [" + NOTES + "] is equal to [" + notes + "]"); String message = this.getAttributeAsString(MESSAGE); logger.debug("Parameter [" + MESSAGE + "] is equal to [" + message + "]"); String visibility = this.getAttributeAsString(VISIBILITY); logger.debug("Parameter [" + VISIBILITY + "] is equal to [" + visibility + "]"); String resultStr = null; ObjNote objnote = null; SessionContainer sessCont = getSessionContainer(); SessionContainer permCont = sessCont.getPermanentContainer(); IEngUserProfile profile = (IEngUserProfile) permCont.getAttribute(IEngUserProfile.ENG_USER_PROFILE); String owner = (String) ((UserProfile) profile).getUserId(); try { objnote = DAOFactory.getObjNoteDAO().getExecutionNotesByOwner(obj.getId(), execIdentifier, owner); } catch (Exception e) { logger.error( "Cannot load notes for document [id: " + obj.getId() + ", label: " + obj.getLabel() + ", name: " + obj.getName() + "]", e); throw new SpagoBIServiceException(SERVICE_NAME, "Cannot load notes", e); } String currentNotes = ""; if (objnote != null) { logger.debug("Existing notes found with the same execution identifier"); byte[] content = objnote.getContent(); currentNotes = new String(content); } if (!"INSERT_NOTE".equalsIgnoreCase(MESSAGE) && !currentNotes.equals(previousNotes)) { logger.debug("Notes have been created by another user"); resultStr = "conflict"; } else { logger.debug("Saving notes..."); try { saveNotes(execIdentifier, obj.getId(), notes, objnote, owner, visibility, profile); logger.debug("Notes saved"); resultStr = "ok"; } catch (Exception e) { throw new SpagoBIServiceException(SERVICE_NAME, "Error while saving notes", e); } } try { JSONObject result = new JSONObject(); result.put("result", resultStr); writeBackToClient(new JSONSuccess(result)); } catch (IOException e) { throw new SpagoBIServiceException( SERVICE_NAME, "Impossible to write back the responce to the client", e); } catch (JSONException e) { throw new SpagoBIServiceException( SERVICE_NAME, "Cannot serialize objects into a JSON object", e); } } finally { logger.debug("OUT"); } }