/** * Returns an url for the test of the EXTERNAL engine. * * @param objLabel the logical label of the document (gets from the template file) * @param sessionContainer session object * @param requestSB request object * @return String the complete url. It use this format: <code_error>|<url>. If there is an error * during the execution <code_error> is valorized and url is null, else it is null and the url * is complete. */ public static String getEngineTestUrl( String objLabel, SessionContainer sessionContainer, SourceBean requestSB) { logger.debug("IN"); Monitor monitor = MonitorFactory.start("spagobi.engines.DocumentCompositionUtils.getEngineTestUrl"); String baseUrlReturn = ""; String urlReturn = ""; if (objLabel == null || objLabel.equals("")) { logger.error("Object Label is null: cannot get engine's url."); return "1008|"; } try { // get the user profile from session SessionContainer permSession = sessionContainer.getPermanentContainer(); BIObject obj = DAOFactory.getBIObjectDAO().loadBIObjectByLabel(objLabel); if (obj == null) { logger.error( "Cannot obtain engine url. Document with label " + objLabel + " doesn't exist into database."); List l = new ArrayList(); l.add(objLabel); throw new EMFUserError(EMFErrorSeverity.ERROR, "1005", l, messageBundle); } String className = obj.getEngine().getClassName(); if (className == null || className.trim().equals("")) { // external engine baseUrlReturn = obj.getEngine().getUrl() + "Test?"; urlReturn = baseUrlReturn; logger.debug("urlReturn: " + "|" + urlReturn); } } catch (Exception ex) { logger.error("Error while getting execution url: " + ex); return null; } finally { monitor.stop(); } logger.debug("OUT"); return "|" + urlReturn; }
/** * Function not implemented. Thid method should not be called * * @param biobject The BIOBject to edit * @param profile the profile * @return the edits the document template build url * @throws InvalidOperationRequest the invalid operation request */ public EngineURL getEditDocumentTemplateBuildUrl(Object biobject, IEngUserProfile profile) throws InvalidOperationRequest { EngineURL engineURL; BIObject obj; String documentId; Engine engine; String url; HashMap parameters; logger.debug("IN"); try { obj = null; try { obj = (BIObject) biobject; } catch (ClassCastException cce) { logger.error("The input object is not a BIObject type", cce); return null; } documentId = obj.getId().toString(); engine = obj.getEngine(); url = engine.getUrl(); parameters = new HashMap(); // getting the dataset label from template, if smart filter is based on a dataset ObjTemplate objectTemplate = obj.getActiveTemplate(); byte[] content = objectTemplate.getContent(); SourceBean sbTemplate = getTemplateAsSourceBean(content); if (sbTemplate.getName().equals(EngineConstants.SMART_FILTER_TAG) && sbTemplate.containsAttribute("DATASET")) { String label = (String) ((SourceBean) sbTemplate.getAttribute("DATASET")).getAttribute("label"); parameters.put("dataset_label", label); } parameters.put("document", documentId); parameters.put(PARAM_SERVICE_NAME, "FORM_ENGINE_TEMPLATE_BUILD_ACTION"); parameters.put(PARAM_NEW_SESSION, "TRUE"); parameters.put(PARAM_MODALITY, "EDIT"); applySecurity(parameters, profile); engineURL = new EngineURL(url, parameters); } catch (Throwable t) { throw new RuntimeException("Cannot get engine edit URL", t); } finally { logger.debug("OUT"); } return engineURL; }
/** * Method called by document composition publisher , that returns alla available exporters for a * single document contained in the composed one. * * @param objLabel * @param sessionContainer * @param requestSB * @return */ public static List getAvailableExporters( String objLabel, SessionContainer sessionContainer, SourceBean requestSB) { logger.debug("IN"); List<Exporters> exporters = null; List<String> exportersTypes = null; if (objLabel == null || objLabel.equals("")) { logger.error("Object Label is null: cannot get engine's url."); return null; } try { // get the user profile from session SessionContainer permSession = sessionContainer.getPermanentContainer(); IEngUserProfile profile = (IEngUserProfile) permSession.getAttribute(IEngUserProfile.ENG_USER_PROFILE); BIObject obj = DAOFactory.getBIObjectDAO().loadBIObjectByLabel(objLabel); if (obj == null) { logger.error( "Cannot obtain engine url. Document with label " + objLabel + " doesn't exist into database."); List l = new ArrayList(); l.add(objLabel); throw new EMFUserError(EMFErrorSeverity.ERROR, "1005", l, messageBundle); } Engine engine = obj.getEngine(); exporters = DAOFactory.getEngineDAO().getAssociatedExporters(engine); if (exporters != null) { exportersTypes = new ArrayList<String>(); for (int i = 0; i < exporters.size(); i++) { Domain domain = DAOFactory.getDomainDAO().loadDomainById(exporters.get(i).getDomainId()); String cd = domain.getValueCd(); exportersTypes.add(cd); } } } catch (Exception e) { logger.error("Error while getting document's exporters for label :" + objLabel + ": " + e); return null; } finally { logger.debug("OUT"); } return exportersTypes; }
/** * Function not implemented. Thid method should not be called * * @param biobject The BIOBject to edit * @param profile the profile * @return the new document template build url * @throws InvalidOperationRequest the invalid operation request */ public EngineURL getNewDocumentTemplateBuildUrl(Object biobject, IEngUserProfile profile) throws InvalidOperationRequest { EngineURL engineURL; BIObject obj; String documentId; Engine engine; String url; HashMap parameters; logger.debug("IN"); try { obj = null; try { obj = (BIObject) biobject; } catch (ClassCastException cce) { logger.error("The input object is not a BIObject type", cce); return null; } documentId = obj.getId().toString(); engine = obj.getEngine(); url = engine.getUrl(); // url = url.replaceFirst("/servlet/AdapterHTTP", ""); // url += "/templateBuilder.jsp"; parameters = new HashMap(); parameters.put("document", documentId); parameters.put(PARAM_SERVICE_NAME, "FORM_ENGINE_TEMPLATE_BUILD_ACTION"); parameters.put(PARAM_NEW_SESSION, "TRUE"); parameters.put(PARAM_MODALITY, "NEW"); applySecurity(parameters, profile); engineURL = new EngineURL(url, parameters); } finally { logger.debug("OUT"); } return engineURL; }
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"); }
/** * Returns an url for execute the document with the engine associated. It calls relative driver. * * @param objLabel the logical label of the document (gets from the template file) * @param sessionContainer session object * @param requestSB request object * @return String the complete url. It use this format: <code_error>|<url>. If there is an error * during the execution <code_error> is valorized and url is null, else it is null and the url * is complete. */ public static String getExecutionUrl( String objLabel, SessionContainer sessionContainer, SourceBean requestSB) { logger.debug("IN"); Monitor monitor = MonitorFactory.start("spagobi.engines.DocumentCompositionUtils.getExecutionUrl"); String baseUrlReturn = ""; String urlReturn = ""; if (objLabel == null || objLabel.equals("")) { logger.error("Object Label is null: cannot get engine's url."); return "1008|"; } try { // get the user profile from session SessionContainer permSession = sessionContainer.getPermanentContainer(); IEngUserProfile profile = (IEngUserProfile) permSession.getAttribute(IEngUserProfile.ENG_USER_PROFILE); // get the execution role CoreContextManager contextManager = new CoreContextManager( new SpagoBISessionContainer(sessionContainer), new LightNavigatorContextRetrieverStrategy(requestSB)); ExecutionInstance instance = contextManager.getExecutionInstance(ExecutionInstance.class.getName()); String executionRole = instance.getExecutionRole(); Integer objId = DAOFactory.getBIObjectDAO().loadBIObjectByLabel(objLabel).getId(); BIObject obj = DAOFactory.getBIObjectDAO().loadBIObjectForExecutionByIdAndRole(objId, executionRole); // BIObject obj = // DAOFactory.getBIObjectDAO().loadBIObjectForExecutionByLabelAndRole(objLabel, // executionRole); // BIObject obj = DAOFactory.getBIObjectDAO().loadBIObjectByLabel(objLabel); if (obj == null) { logger.error( "Cannot obtain engine url. Document with label " + objLabel + " doesn't exist into database."); List l = new ArrayList(); l.add(objLabel); throw new EMFUserError(EMFErrorSeverity.ERROR, "1005", l, messageBundle); } // Engine engine = obj.getEngine(); /*ALL CONTROLS OF COMPATIBILITY ARE REMANDED TO THE SINGLE ENGINE CALLED // GET THE TYPE OF ENGINE (INTERNAL / EXTERNAL) AND THE SUITABLE BIOBJECT TYPES Domain engineType = null; Domain compatibleBiobjType = null; try { engineType = DAOFactory.getDomainDAO().loadDomainById(engine.getEngineTypeId()); compatibleBiobjType = DAOFactory.getDomainDAO().loadDomainById(engine.getBiobjTypeId()); } catch (EMFUserError error) { logger.error("Error retrieving document's engine information", error); return "1009|"; } catch (Exception error) { logger.error("Error retrieving document's engine information", error); return "1009|"; } String compatibleBiobjTypeCd = compatibleBiobjType.getValueCd(); String biobjTypeCd = obj.getBiObjectTypeCode(); // CHECK IF THE BIOBJECT IS COMPATIBLE WITH THE TYPES SUITABLE FOR THE ENGINE if (!compatibleBiobjTypeCd.equalsIgnoreCase(biobjTypeCd)) { // the engine document type and the biobject type are not compatible logger.error("Engine cannot execute input document type: " + "the engine " + engine.getName() + " can execute '" + compatibleBiobjTypeCd + "' type documents " + "while the input document is a '" + biobjTypeCd + "'."); Vector params = new Vector(); params.add(engine.getName()); params.add(compatibleBiobjTypeCd); params.add(biobjTypeCd); //errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR, 2002, params)); return "2002|"; } */ // IF USER CAN'T EXECUTE THE OBJECT RETURN // if (!ObjectsAccessVerifier.canSee(obj, profile)) return "1010|"; // get object configuration DocumentCompositionConfiguration docConfig = null; docConfig = (DocumentCompositionConfiguration) contextManager.get("docConfig"); Document document = null; // get correct document configuration List lstDoc = docConfig.getLabelsArray(); boolean foundDoc = false; for (int i = 0; i < lstDoc.size(); i++) { document = (Document) docConfig.getDocument((String) lstDoc.get(i)); if (document != null) { if (!obj.getLabel().equalsIgnoreCase(document.getSbiObjLabel())) continue; else { foundDoc = true; break; } } } if (!foundDoc) { List l = new ArrayList(); l.add(obj.getLabel()); EMFUserError userError = new EMFUserError(EMFErrorSeverity.ERROR, 1079, l); logger.error( "The object with label " + obj.getLabel() + " hasn't got a document into template"); return "1002|"; } String className = obj.getEngine().getClassName(); if ((className == null || className.trim().equals("")) && (document.getSnapshot() == null || !document.getSnapshot())) { // external engine // baseUrlReturn = obj.getEngine().getUrl() + "?"; baseUrlReturn = obj.getEngine().getUrl(); if (baseUrlReturn.indexOf("?") < 0) baseUrlReturn += "?"; String driverClassName = obj.getEngine().getDriverName(); IEngineDriver aEngineDriver = (IEngineDriver) Class.forName(driverClassName).newInstance(); Map mapPars = aEngineDriver.getParameterMap(obj, profile, executionRole); String id = (String) requestSB.getAttribute("vpId"); if (id != null) { IViewpointDAO VPDAO = DAOFactory.getViewpointDAO(); Viewpoint vp = VPDAO.loadViewpointByID(new Integer(id)); String[] vpParameters = vp.getVpValueParams().split("%26"); if (vpParameters != null) { for (int i = 0; i < vpParameters.length; i++) { String param = (String) vpParameters[i]; String name = param.substring(0, param.indexOf("%3D")); String value = param.substring(param.indexOf("%3D") + 3); if (mapPars.get(name) != null) { mapPars.remove(name); mapPars.put(name, value); } else mapPars.put(name, value); } } } mapPars.put(SpagoBIConstants.SBI_CONTEXT, GeneralUtilities.getSpagoBiContext()); mapPars.put(SpagoBIConstants.SBI_HOST, GeneralUtilities.getSpagoBiHost()); UUIDGenerator uuidGen = UUIDGenerator.getInstance(); UUID uuidObj = uuidGen.generateRandomBasedUUID(); String executionId = uuidObj.toString(); executionId = executionId.replaceAll("-", ""); mapPars.put("SBI_EXECUTION_ID", executionId); mapPars.put("EXECUTION_CONTEXT", "DOCUMENT_COMPOSITION"); // Auditing AuditManager auditManager = AuditManager.getInstance(); Integer executionAuditId = auditManager.insertAudit( instance.getBIObject(), null, profile, executionRole, instance.getExecutionModality()); // adding parameters for AUDIT updating if (executionAuditId != null) { mapPars.put(AuditManager.AUDIT_ID, executionAuditId.toString()); } Set parKeys = mapPars.keySet(); Iterator parKeysIter = parKeys.iterator(); do { if (!parKeysIter.hasNext()) { break; } String parkey = parKeysIter.next().toString(); String parvalue = mapPars.get(parkey).toString(); urlReturn = (new StringBuilder()) .append(urlReturn) .append("&") .append(parkey) .append("=") .append(parvalue) .toString(); } while (true); } else { // internal engine baseUrlReturn = GeneralUtilities.getSpagoBIProfileBaseUrl(profile.getUserUniqueIdentifier().toString()); urlReturn = "&" + ObjectsTreeConstants.OBJECT_LABEL + "=" + objLabel; // identity string for context UUIDGenerator uuidGen = UUIDGenerator.getInstance(); UUID uuid = uuidGen.generateRandomBasedUUID(); urlReturn += "&" + LightNavigationManager.LIGHT_NAVIGATOR_ID + "=" + uuid.toString(); if (document.getSnapshot() != null && document.getSnapshot()) { Snapshot snap = DAOFactory.getSnapshotDAO().getLastSnapshot(objId); if (snap != null) { urlReturn += "&SNAPSHOT_ID=" + snap.getId(); } urlReturn += "&OBJECT_ID=" + objId; urlReturn += "&ACTION_NAME=GET_SNAPSHOT_CONTENT"; } else { urlReturn += "&PAGE=ExecuteBIObjectPage&" + SpagoBIConstants.IGNORE_SUBOBJECTS_VIEWPOINTS_SNAPSHOTS + "=true"; urlReturn += "&" + ObjectsTreeConstants.MODALITY + "=" + SpagoBIConstants.DOCUMENT_COMPOSITION; } } // I add passing of SBI_LANGUAGE and SBI_COUNTRY // on session container they are called AF_COUNTRY and AF_LANGUAGE SessionContainer sContainer = sessionContainer.getPermanentContainer(); if (sContainer != null) { Object language = sContainer.getAttribute("AF_LANGUAGE"); Object country = sContainer.getAttribute("AF_COUNTRY"); if (language == null) { language = sContainer.getAttribute("SBI_LANGUAGE"); } if (country == null) { country = sContainer.getAttribute("SBI_COUNTRY"); } if (language != null && country != null) { urlReturn += "&" + SpagoBIConstants.SBI_LANGUAGE + "=" + language + "&" + SpagoBIConstants.SBI_COUNTRY + "=" + country; } } urlReturn += "&" + SpagoBIConstants.ROLE + "=" + executionRole; urlReturn += getParametersUrl(obj, document, requestSB, instance); // adds '|' char for management error into jsp if is necessary. urlReturn = baseUrlReturn + urlReturn; logger.debug("urlReturn: " + "|" + urlReturn); } catch (Exception ex) { logger.error("Error while getting execution url: " + ex); return null; } finally { monitor.stop(); } logger.debug("OUT"); return "|" + urlReturn; }
/** * Return a string representative an url with all parameters set with a request value (if it is * present) or with the default's value. * * @param doc the document object that is managed * @param document the document configurator * @param requestSB the request object * @return a string with the url completed */ private static String getParametersUrl( BIObject obj, Document document, SourceBean requestSB, ExecutionInstance instance) { logger.debug("IN"); String paramUrl = ""; // set others parameters value Properties lstParams = document.getParams(); String key = ""; List values = new ArrayList(); String singleValue = ""; int cont = 0; try { if (lstParams != null) { ParameterValuesEncoder encoderUtility = new ParameterValuesEncoder(); // while(enParams.hasMoreElements()) { for (int i = 0; i < lstParams.size(); i++) { String typeParam = lstParams.getProperty("type_par_" + document.getNumOrder() + "_" + cont); // only for parameter in input to the document managed (type equal 'IN') if (typeParam != null && typeParam.indexOf("IN") >= 0) { String tmpKey = "sbi_par_label_param_" + document.getNumOrder() + "_" + cont; key = lstParams.getProperty(tmpKey); if (key == null && !document.getTypeCross().equalsIgnoreCase(Constants.CROSS_EXTERNAL)) break; values = (List) requestSB.getAttributeAsList(key); // if value isn't defined, check if there is a value into the instance(there is when a // document is called from a refresh o viewpoint mode) if (values == null || values.size() == 0 || ((String) values.get(0)).equals("")) { List instanceValue = getInstanceValue(key, instance); if (instanceValue != null && instanceValue.size() > 0 && !instanceValue.get(0).equals("")) values = instanceValue; } // if value isn't defined, gets the default value from the template if (values == null || values.size() == 0 || ((String) values.get(0)).equals("")) { values.add( lstParams.getProperty( ("default_value_param_" + document.getNumOrder() + "_" + cont))); } logger.debug("Values to pass : "******"")) { // EXTERNAL ENGINES BIObjectParameter par = getBIObjectParameter(obj, key); par.setParameterValues(values); Parameter tmpPar = par.getParameter(); logger.debug("Manage parameter : " + tmpPar.getLabel() + "..."); if (tmpPar != null && values.size() > 1 && tmpPar.getModalityValue() != null && ((!(par).isMultivalue()) || tmpPar .getModalityValue() .getITypeCd() .equalsIgnoreCase(SpagoBIConstants.INPUT_TYPE_MAN_IN_CODE))) { logger.debug("Force the multivalue modality for parameter " + tmpPar.getLabel()); // force the multivalue management if the parameter has defined as MANUAL INPUT and // the values is multiple. tmpPar.getModalityValue().setMultivalue(true); tmpPar.getModalityValue().setITypeCd(SpagoBIConstants.INPUT_TYPE_QUERY_CODE); par.setParameter(tmpPar); } String parsValue = encoderUtility.encode(par); // conversion in UTF-8 of the par Map parsMap = new HashMap(); parsMap.put(key, parsValue); String tmpUrl = GeneralUtilities.getUrl("", parsMap); logger.debug("tmpUrl for " + obj.getLabel() + ": " + tmpUrl); paramUrl += "&" + tmpUrl.substring(tmpUrl.indexOf("?") + 1); // paramUrl += "&" + key + "=" + tmpUrl; } else { // INTERNAL ENGINES for (int j = 0; j < values.size(); j++) { singleValue = (String) values.get(j); if (singleValue.equals("%")) singleValue = "%25"; // setting an url likes &key=val1;val2;valn if (j == 0) { paramUrl += "&" + key + "=" + singleValue; } else { paramUrl += ";" + singleValue; } } } cont++; } } } } catch (Exception ex) { logger.error( "Error while getting parameter's document " + document.getSbiObjLabel() + " param: " + key + ": " + ex); return null; } /* if (forInternalEngine) paramUrl = paramUrl.substring(0, paramUrl.length()-3); else paramUrl = paramUrl.substring(0, paramUrl.length()-5); */ logger.debug("paramUrl: " + paramUrl); logger.debug("OUT"); return paramUrl; }