Examples of IDossierDAO


Examples of it.eng.spagobi.engines.dossier.dao.IDossierDAO

     * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
     */
    public void execute(ExecutionContext context) throws Exception {
  XComponent xComponent = null;
  XDesktop xdesktop = null;
  IDossierDAO dossierDAO = null;
  XBridge bridge = null;
  String tempFolder = null;
  ContextInstance contextInstance = null;
  try {
      logger.debug("Start execution");
      contextInstance = context.getContextInstance();
      logger.debug("Context Instance retrived " + contextInstance);
      ProcessInstance processInstance = context.getProcessInstance();
      Long workflowProcessId = new Long(processInstance.getId());
      logger.debug("Workflow process id: " + workflowProcessId);
      String dossierIdStr = (String) contextInstance.getVariable(DossierConstants.DOSSIER_ID);
      logger.debug("Dossier id variable retrived " + dossierIdStr);
      Integer dossierId = new Integer(dossierIdStr);
      BIObject dossier = DAOFactory.getBIObjectDAO().loadBIObjectById(dossierId);
      logger.debug("Dossier retrived " + dossier);
      dossierDAO = DAOFactory.getDossierDAO();
      tempFolder = dossierDAO.init(dossier);
      logger.debug("Path tmp folder dossier =" + tempFolder + " created.");

      // gets the template file data
      String templateFileName = dossierDAO.getPresentationTemplateFileName(tempFolder);
      logger.debug("Template file name: " + templateFileName);
      InputStream contentTempIs = dossierDAO.getPresentationTemplateContent(tempFolder);
      logger.debug("InputStream opened on dossier template.");
      byte[] contentTempBytes = GeneralUtilities.getByteArrayFromInputStream(contentTempIs);
      logger.debug("DossierTemplateContent stored into a byte array.");
      contentTempIs.close();
      // write template content into a temp file
      File templateFile = new File(tempFolder, templateFileName);
      FileOutputStream fosTemplate = new FileOutputStream(templateFile);
      fosTemplate.write(contentTempBytes);
      fosTemplate.flush();
      fosTemplate.close();
      logger.debug("Dossier template content written into a temp file.");

      // initialize openoffice environment
      ConfigSingleton config = ConfigSingleton.getInstance();
      SourceBean officeConnectSB = (SourceBean) config.getAttribute("DOSSIER.OFFICECONNECTION");
      logger.debug("Office connection Sourcebean retrieved: " + officeConnectSB.toXML());
      String host = (String) officeConnectSB.getAttribute("host");
      String port = (String) officeConnectSB.getAttribute("port");
      logger.debug("Office connection host: " + host);
      logger.debug("Office connection port: " + port);
      XComponentContext xRemoteContext = Bootstrap.createInitialComponentContext(null);
      logger.debug("InitialComponentContext xRemoteContext created: " + xRemoteContext);

      Object x = xRemoteContext.getServiceManager().createInstanceWithContext(
        "com.sun.star.connection.Connector", xRemoteContext);
      XConnector xConnector = (XConnector) UnoRuntime.queryInterface(XConnector.class, x);
      logger.debug("XConnector retrieved: " + xConnector);
      XConnection connection = xConnector.connect("socket,host=" + host + ",port=" + port);
      logger.debug("XConnection retrieved: " + connection);
      x = xRemoteContext.getServiceManager().createInstanceWithContext("com.sun.star.bridge.BridgeFactory",
        xRemoteContext);
      XBridgeFactory xBridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class, x);
      logger.debug("XBridgeFactory retrieved: " + xBridgeFactory);
      // this is the bridge that you will dispose
      bridge = xBridgeFactory.createBridge("", "urp", connection, null);
      logger.debug("XBridge retrieved: " + bridge);
      XComponent xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge);
      // get the remote instance
      x = bridge.getInstance("StarOffice.ServiceManager");
      logger.debug("StarOffice.ServiceManager instance retrieved: " + x);
      // Query the initial object for its main factory interface
      XMultiComponentFactory xRemoteServiceManager = (XMultiComponentFactory) UnoRuntime.queryInterface(
        XMultiComponentFactory.class, x);

      // XMultiComponentFactory xRemoteServiceManager =
      // (XMultiComponentFactory)UnoRuntime.queryInterface(XMultiComponentFactory.class,
      // initialObject);
      logger.debug("xRemoteServiceManager: " + xRemoteServiceManager);
      XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
        xRemoteServiceManager);
      logger.debug("XPropertySet: " + xPropertySet);
      Object oDefaultContext = xPropertySet.getPropertyValue("DefaultContext");
      logger.debug("DefaultContext: " + oDefaultContext);
      xRemoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext);
      logger.debug("xRemoteContext: " + xRemoteContext);
      Object desktop = xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop",
        xRemoteContext);
      logger.debug("Desktop object instance created: " + desktop);
      xdesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);
      logger.debug("XDesktop object: " + xdesktop);

      XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
        xdesktop);
      // load the template into openoffice
      logger.debug("Path template = " + templateFile.getAbsolutePath());
      xComponent = openTemplate(xComponentLoader, "file:///" + templateFile.getAbsolutePath());
      logger.debug("Template opened: " + xComponent);
      XMultiServiceFactory xServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
        XMultiServiceFactory.class, xComponent);
      logger.debug("xServiceFactory: " + xServiceFactory);
      // get draw pages
      XDrawPagesSupplier xDrawPageSup = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class,
        xComponent);
      XDrawPages drawPages = xDrawPageSup.getDrawPages();
      logger.debug("Draw pages found: " + drawPages);
      int numPages = drawPages.getCount();
      logger.debug("Draw pages number: " + numPages);
      IDossierPartsTempDAO dptDAO = DAOFactory.getDossierPartsTempDAO();
      for (int i = 0; i < numPages; i++) {
    logger.debug("Start examining page " + i);
    // get images corresponding to that part of the template
    int pageNum = i + 1;
    Map images = dptDAO.getImagesOfDossierPart(dossierId, pageNum, workflowProcessId);
    logger.debug("Images map retrieved: " + images);
    // get draw page
    Object pageObj = drawPages.getByIndex(i);
    XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, pageObj);
    logger.debug("Draw page: " + xDrawPage);
    // get shapes of the page
    XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
    logger.debug("Shapes found: " + xShapes);
    int numShapes = xShapes.getCount();
    logger.debug("Shapes number: " + numShapes);
    // prepare list for shapes to remove and to add
    List shapetoremove = new ArrayList();
    List shapetoadd = new ArrayList();
    Object oBitmapsObj = xServiceFactory.createInstance("com.sun.star.drawing.BitmapTable");
    XNameContainer oBitmaps = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oBitmapsObj);
    // check each shape
    for (int j = 0; j < numShapes; j++) {
        logger.debug("Start examining shape " + j + " of page " + i);
        Object shapeObj = xShapes.getByIndex(j);
        XShape xshape = (XShape) UnoRuntime.queryInterface(XShape.class, shapeObj);
        logger.debug("xshape: " + xshape);
        XText xShapeText = (XText) UnoRuntime.queryInterface(XText.class, shapeObj);
        logger.debug("XShapeText retrived " + xShapeText);
        if (xShapeText == null) {
      continue;
        }
        String shapeText = xShapeText.getString();
        logger.debug("shape text retrived " + shapeText);
        shapeText = shapeText.trim();
        // sobstitute the placeholder with the correspondent image
        if (shapeText.startsWith("spagobi_placeholder_")) {
      String nameImg = shapeText.substring(20);
      logger.debug("Name of the image corresponding to the placeholder: " + nameImg);
      Size size = xshape.getSize();
      Point position = xshape.getPosition();
      logger.debug("Stored shape size and position on local variables");
      shapetoremove.add(xshape);
      logger.debug("Shape loaded on shapes to be removed");
      Object newShapeObj = xServiceFactory.createInstance("com.sun.star.drawing.GraphicObjectShape");
      logger.debug("New shape object instantiated: " + newShapeObj);
      XShape xShapeNew = (XShape) UnoRuntime.queryInterface(XShape.class, newShapeObj);
      logger.debug("New XShape instantiated from the new shape object: " + xShapeNew);
      xShapeNew.setPosition(position);
      xShapeNew.setSize(size);
      logger.debug("Stored size and position set for the new XShape");
      // write the corresponding image into file system
      String pathTmpImgFolder = tempFolder + "/tmpImgs/";
      logger.debug("Path tmp images: " + pathTmpImgFolder);
      File fileTmpImgFolder = new File(pathTmpImgFolder);
      fileTmpImgFolder.mkdirs();
      logger.debug("Folder tmp images: " + pathTmpImgFolder + " created.");
      String pathTmpImg = pathTmpImgFolder + nameImg + ".jpg";
      logger.debug("Path tmp image file: " + pathTmpImg);
      File fileTmpImg = new File(pathTmpImg);
      FileOutputStream fos = new FileOutputStream(fileTmpImg);
      byte[] content = (byte[]) images.get(nameImg);
      if (content == null)
          logger.debug("Image with name \"" + nameImg + "\" was NOT found!!!");
      else
          logger.debug("Image with name \"" + nameImg + "\" was found");
      fos.write(content);
      fos.flush();
      fos.close();
      logger.debug("Tmp image file written");
      // load the image into document
      XPropertySet xSPS = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShapeNew);
      try {
          String fileoopath = transformPathForOpenOffice(fileTmpImg);
          logger.debug("Path image loaded into openoffice = " + fileoopath);
          String externalGraphicUrl = "file:///" + fileoopath;
          if (!oBitmaps.hasByName(nameImg)) {
        logger.debug("Bitmap table does not contain an element with name '" + nameImg
          + "'.");
        oBitmaps.insertByName(nameImg, externalGraphicUrl);
          } else {
        logger.debug("Bitmap table already contains an element with name '" + nameImg
          + "'.");
          }
          Object internalGraphicUrl = oBitmaps.getByName(nameImg);
          logger.debug("Retrieved internal url for image '" + nameImg + "': "
            + internalGraphicUrl);
          xSPS.setPropertyValue("GraphicURL", internalGraphicUrl);
      } catch (Exception e) {
        logger.error("error while adding graphic shape", e);
      }
      shapetoadd.add(xShapeNew);
      logger.debug("New shape loaded on shapes to be added");
        }
    }
    // add and remove shape
    Iterator iter = shapetoremove.iterator();
    while (iter.hasNext()) {
        XShape shape = (XShape) iter.next();
        xShapes.remove(shape);
    }
    logger.debug("Removed shapes to be removed from document");
    iter = shapetoadd.iterator();
    while (iter.hasNext()) {
        XShape shape = (XShape) iter.next();
        xShapes.add(shape);
    }
    logger.debug("Added shapes to be added to the document");
    // add notes
    XPresentationPage xPresPage = (XPresentationPage) UnoRuntime.queryInterface(XPresentationPage.class,
      xDrawPage);
    XDrawPage notesPage = xPresPage.getNotesPage();
    logger.debug("Notes page retrieved: " + notesPage);
    XShapes xShapesNotes = (XShapes) UnoRuntime.queryInterface(XShapes.class, notesPage);
    logger.debug("Shape notes retrieved: " + xShapesNotes);
    int numNoteShapes = xShapesNotes.getCount();
    logger.debug("Number of shape notes: " + numNoteShapes);
    for (int indShap = 0; indShap < numNoteShapes; indShap++) {
        logger.debug("Start examining shape note number " + indShap + " of page " + i);
        Object shapeNoteObj = xShapesNotes.getByIndex(indShap);
        XShape xshapeNote = (XShape) UnoRuntime.queryInterface(XShape.class, shapeNoteObj);
        logger.debug("xshapeNote: " + xshapeNote);
        String type = xshapeNote.getShapeType();
        logger.debug("Shape type: " + type);
        if (type.endsWith("NotesShape")) {
      XText textNote = (XText) UnoRuntime.queryInterface(XText.class, shapeNoteObj);
      logger.debug("XText: " + textNote);
      byte[] notesByte = dptDAO.getNotesOfDossierPart(dossierId, pageNum, workflowProcessId);
      String notes = null;
      if (notesByte == null) {
          logger.debug("Notes bytes array is null!!!!");
          notes = "";
      } else {
          logger.debug("Notes bytes array retrieved");
          notes = new String(notesByte);
      }
      textNote.setString(notes);
      logger.debug("Notes applied to the XText");
        }
    }
      }

      // save final document
      String pathFinalDoc = tempFolder + "/" + dossier.getName() + ".ppt";
      logger.debug("Path final document = " + pathFinalDoc);
      File fileFinalDoc = new File(pathFinalDoc);
      String fileoopath = transformPathForOpenOffice(fileFinalDoc);
      logger.debug("Open Office path: " + fileoopath);
      if (fileoopath.equals(""))
    return;
      XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xComponent);
      logger.debug("XStorable: " + xStorable);
      PropertyValue[] documentProperties = new PropertyValue[2];
      documentProperties[0] = new PropertyValue();
      documentProperties[0].Name = "Overwrite";
      documentProperties[0].Value = new Boolean(true);
      documentProperties[1] = new PropertyValue();
      documentProperties[1].Name = "FilterName";
      documentProperties[1].Value = "MS PowerPoint 97";
      try {
        logger.debug("Try to store document with path = " + "file:///" + fileoopath);
        xStorable.storeAsURL("file:///" + fileoopath, documentProperties);
        logger.debug("Document stored with path = " + "file:///" + fileoopath);
      } catch (IOException e) {
        logger.error("Error while storing the final document", e);
      }
      FileInputStream fis = new FileInputStream(pathFinalDoc);
      byte[] docCont = GeneralUtilities.getByteArrayFromInputStream(fis);
      IDossierPresentationsDAO dpDAO = DAOFactory.getDossierPresentationDAO();
     
      DossierPresentation dossierPresentation = new DossierPresentation();
      dossierPresentation.setApproved(null);
      dossierPresentation.setProg(null);
      dossierPresentation.setBiobjectId(dossier.getId());
      dossierPresentation.setContent(docCont);
      dossierPresentation.setName(dossier.getName());
      dossierPresentation.setWorkflowProcessId(workflowProcessId);
      dpDAO.insertPresentation(dossierPresentation);
      logger.debug("Document stored.");
      fis.close();
      dptDAO.cleanDossierParts(dossierId, workflowProcessId);
      logger.debug("Dossier temporary parts relevant to document id = [" + dossierId + "] " +
          "and workflow process id = [" + workflowProcessId + "] deleted.");
  } catch (Exception e) {
    logger.error("Error during the generation of the final document", e);
      // AUDIT UPDATE
      if (contextInstance != null) {
    Integer auditId = (Integer) contextInstance.getVariable(AuditManager.AUDIT_ID);
    AuditManager auditManager = AuditManager.getInstance();
    auditManager.updateAudit(auditId, null, new Long(System.currentTimeMillis()), "EXECUTION_FAILED", e
      .getMessage(), null);
      }
      // store as final document the template

  } finally {
      // close open document and environment
      if (xComponent != null) {
      XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xComponent);
      XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xModel);
      try {
          xCloseable.close(true);
      } catch (Exception e) {
        logger.error("Cannot close openoffice template document", e);
      }
      }
      // cleans dossier temp folder
      if (dossierDAO != null && tempFolder != null) {
        dossierDAO.clean(tempFolder);
        logger.debug("Deleted folder " + tempFolder);
      }
      logger.debug("OUT");
  }

View Full Code Here

Examples of it.eng.spagobi.engines.dossier.dao.IDossierDAO

  private void runCollaborationHandler(SourceBean request, SourceBean response) throws EMFUserError {
    logger.debug("IN");
//    String dossierIdStr = (String) request.getAttribute(DossierConstants.DOSSIER_ID);
//    Integer dossierId = new Integer(dossierIdStr);
    IDossierDAO dossierDAO = DAOFactory.getDossierDAO();
    BIObject dossier;
    String pathTempFolder = null;
    JbpmContext jbpmContext = null;
    InputStream procDefIS = null;
    String executionMsg = null;
    AuditManager auditManager = AuditManager.getInstance();
    Integer auditId = null;
    try {
//      try {
//        dossier = DAOFactory.getBIObjectDAO().loadBIObjectById(dossierId);
        RequestContainer requestContainer = this.getRequestContainer();
        SessionContainer session = requestContainer.getSessionContainer();
        CoreContextManager contextManager = new CoreContextManager(new SpagoBISessionContainer(session),
          new LightNavigatorContextRetrieverStrategy(request));
        ExecutionInstance executionInstance = contextManager.getExecutionInstance( ExecutionInstance.class.getName() );
        dossier = executionInstance.getBIObject();
        pathTempFolder = dossierDAO.init(dossier);
//      } catch (EMFUserError e) {
//        logger.error("Error while recovering dossier information: " + e);
//        throw e;
//      }
      IEngUserProfile profile = UserProfile.createWorkFlowUserProfile();
        // AUDIT
      if (dossier != null) {
        auditId = auditManager.insertAudit(dossier, null, profile, "", "WORKFLOW");
      }
      try {
        procDefIS = dossierDAO.getProcessDefinitionContent(pathTempFolder);
      } catch (Exception e) {
        logger.error("Error while reading process definition file content from dossier template: " + e);
        throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
      }
     
      // parse process definition
      ProcessDefinition processDefinition = null;
      try{
        processDefinition = ProcessDefinition.parseXmlInputStream(procDefIS);
      } catch(Exception e) {
        executionMsg = msgBuilder.getMessage("dossier.processDefNotCorrect", "component_dossier_messages");
        logger.error("Process definition xml file not correct", e);
        throw e;
     
        // get name of the process
      String nameProcess = processDefinition.getName();
      // get jbpm context
      JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
      jbpmContext = jbpmConfiguration.createJbpmContext();
      // deploy process  
      try{
        jbpmContext.deployProcessDefinition(processDefinition)
      } catch (Exception e) {
        executionMsg = msgBuilder.getMessage("dossier.workProcessStartError", "component_dossier_messages");
        logger.error("Error while deploying process definition", e);
        throw e;
      }
      // create process instance
      ProcessInstance processInstance = new ProcessInstance(processDefinition);
      // get context instance and set the dossier id variable
      ContextInstance contextInstance = processInstance.getContextInstance();
      contextInstance.createVariable(DossierConstants.DOSSIER_ID, dossier.getId().toString());
      contextInstance.createVariable(DossierConstants.DOSSIER_PARAMETERS, getDossierParameters(dossier));
     
      // adding parameters for AUDIT updating
      if (auditId != null) {
        contextInstance.createVariable(AuditManager.AUDIT_ID, auditId);
      }
     
      // start workflow
      Token token = processInstance.getRootToken();
      GraphSession graphSess = jbpmContext.getGraphSession();
      try {
        token.signal();
      } catch (Exception e) {
        if(e.getCause() instanceof OpenOfficeConnectionException ) {
          executionMsg = msgBuilder.getMessage("dossier.errorConnectionOO", "component_dossier_messages");
        }
          throw e;
      }
      // save workflow data
      jbpmContext.save(processInstance);
     
      } catch (Exception e) {
        if (executionMsg == null) {
          executionMsg = msgBuilder.getMessage("dossier.workProcessStartError", "component_dossier_messages");
        }
        logger.error("Error while starting workflow", e);
      // AUDIT UPDATE
      auditManager.updateAudit(auditId, null, new Long(System.currentTimeMillis()),
          "STARTUP_FAILED", e.getMessage(), null);
      } finally {
        if (executionMsg == null) {
          executionMsg = msgBuilder.getMessage("dossier.workProcessStartCorrectly", "component_dossier_messages");
          // AUDIT UPDATE
          auditManager.updateAudit(auditId, new Long(System.currentTimeMillis()), null,
            "EXECUTION_STARTED", null, null);
        }
        if (jbpmContext != null) {
          jbpmContext.close();
        }
        if (procDefIS != null)
        try {
          procDefIS.close();
        } catch (IOException e) {
          logger.error(e);
        }
        // cleans dossier temp folder
        if (dossierDAO != null && pathTempFolder != null) {
          dossierDAO.clean(pathTempFolder);
          logger.debug("Deleted folder " + pathTempFolder);
        }
        logger.debug("OUT");
      }
     
View Full Code Here

Examples of it.eng.spagobi.engines.dossier.dao.IDossierDAO

    public void execute(ExecutionContext context) throws Exception {
     
      String pathTmpFold = null;
    ContextInstance contextInstance = null;
    File tempDir = null;
    IDossierDAO dossierDAO = null;
    logger.debug("IN");
    try {
        // RECOVER CONFIGURATION PARAMETER
        contextInstance = context.getContextInstance();
        logger.debug("Context Instance retrived " + contextInstance);
        ProcessInstance processInstance = context.getProcessInstance();
        Long workflowProcessId = new Long(processInstance.getId());
        String dossierIdStr = (String) contextInstance.getVariable(DossierConstants.DOSSIER_ID);
        logger.debug("Dossier id variable retrived " + dossierIdStr);
        Integer dossierId = new Integer(dossierIdStr);
        BIObject dossier = DAOFactory.getBIObjectDAO().loadBIObjectById(dossierId);
        dossier.setBiObjectParameters(DAOFactory.getBIObjectDAO().getBIObjectParameters(dossier));
        setAnalyticalDriversValues(dossier, (Map) contextInstance.getVariable(DossierConstants.DOSSIER_PARAMETERS));
        logger.debug("Dossier variable retrived " + dossier);
        dossierDAO = DAOFactory.getDossierDAO();
        pathTmpFold = dossierDAO.init(dossier);
        logger.debug("Using tmp folder path " + pathTmpFold);
        ConfigSingleton config = ConfigSingleton.getInstance();
        tempDir = new File(pathTmpFold);
        logger.debug("Create tmp folders " + tempDir);
 
        // GETS OO TEMPLATE AND WRITE IT INTO THE TMP DIRECTORY
        String templateFileName = dossierDAO.getPresentationTemplateFileName(pathTmpFold);
        logger.debug("dossier oo template name retrived " + templateFileName);
        InputStream contentTempIs = null;
        byte[] contentTempBytes = null;
        try {
          contentTempIs = dossierDAO.getPresentationTemplateContent(pathTmpFold);
          logger.debug("dossier oo template input stream retrived " + contentTempIs);
          contentTempBytes = GeneralUtilities.getByteArrayFromInputStream(contentTempIs);
          logger.debug("dossier oo template bytes retrived ");
        } finally {
          if (contentTempIs != null) contentTempIs.close();
        }
        // write template content into a temp file
        File templateOOFile = new File(tempDir, templateFileName);
        FileOutputStream fosTemplate = new FileOutputStream(templateOOFile);
        fosTemplate.write(contentTempBytes);
        logger.debug("oo template bytes written into a tmp file ");
        fosTemplate.flush();
        fosTemplate.close();
 
        // INITIALIZE OFFICE ENVIRONMENT
        SourceBean officeConnectSB = (SourceBean) config.getAttribute("DOSSIER.OFFICECONNECTION");
        if (officeConnectSB == null) {
          logger.error("Cannot found sourcebean DOSSIER.OFFICECONNECTION into configuration");
          throw new Exception("Cannot found sourcebean DOSSIER.OFFICECONNECTION into configuration");
        } else {
          logger.debug("Dossier office connection sourcebean retrived " + officeConnectSB);
        }
        String host = (String) officeConnectSB.getAttribute("host");
        String port = (String) officeConnectSB.getAttribute("port");
        logger.debug("office connection, using host " + host + " and port " + port);
        XComponentContext xRemoteContext = Bootstrap.createInitialComponentContext(null);
        logger.debug("initial XComponentContext created " + xRemoteContext);
 
        Object x = xRemoteContext.getServiceManager().createInstanceWithContext(
          "com.sun.star.connection.Connector", xRemoteContext);
        XConnector xConnector = (XConnector) UnoRuntime.queryInterface(XConnector.class, x);
        logger.debug("XConnector retrieved: " + xConnector);
            XConnection connection = null;
            try {
          connection = xConnector.connect("socket,host=" + host + ",port=" + port);
          if (connection == null) {
            logger.error("Cannot connect to open office using host " + host + " and port " + port);
            throw new OpenOfficeConnectionException("Cannot connect to open office using host " + host
                + " and port " + port);
          }
            } catch (Exception e) {
              logger.error("Cannot connect to open office using host " + host + " and port " + port, e);
              throw new OpenOfficeConnectionException("Cannot connect to open office using host " + host + " and port " + port);
            }
        logger.debug("XConnection retrieved: " + connection);
        x = xRemoteContext.getServiceManager().createInstanceWithContext("com.sun.star.bridge.BridgeFactory",
          xRemoteContext);
        XBridgeFactory xBridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class, x);
        logger.debug("XBridgeFactory retrieved: " + xBridgeFactory);
        // this is the bridge that you will dispose
        bridge = xBridgeFactory.createBridge("", "urp", connection, null);
        logger.debug("XBridge retrieved: " + bridge);
        XComponent xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge);
        // get the remote instance
        x = bridge.getInstance("StarOffice.ServiceManager");
        logger.debug("StarOffice.ServiceManager instance retrieved: " + x);
        // Query the initial object for its main factory interface
        XMultiComponentFactory xRemoteServiceManager = (XMultiComponentFactory) UnoRuntime.queryInterface(
          XMultiComponentFactory.class, x);
 
        // XMultiComponentFactory xRemoteServiceManager =
        // (XMultiComponentFactory)UnoRuntime.queryInterface(XMultiComponentFactory.class,
        // initialObject);
        logger.debug("XMultiComponentFactory retrived " + xRemoteServiceManager);
        XPropertySet xProperySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
          xRemoteServiceManager);
        logger.debug("xProperySet retrived " + xProperySet);
        Object oDefaultContext = xProperySet.getPropertyValue("DefaultContext");
        logger.debug("DefaultContext Propery  value retrived " + oDefaultContext);
        xRemoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext);
        logger.debug("remote XComponentContext retrived " + xRemoteContext);
        Object desktop = xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop",
          xRemoteContext);
        logger.debug("Desktop object retrived " + desktop);
        xdesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);
        logger.debug("XDesktop object retrived " + desktop);
 
        // LOAD OO TEMPLATE INTO OPEN OFFICE
        XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
          xdesktop);
        logger.debug("XComponentLoader object retrived " + xComponentLoader);
        xComponent = openTemplate(xComponentLoader, "file:///" + templateOOFile.getAbsolutePath());
        logger.debug("Template loaded into openffice ");
 
        // ANALYZE OO TEMPLATE, EXTRACT NAME OF PLACEHOLDERS, CALL ENGINE
        // AND STORE RESULT IMAGES
        // gets the number of the parts of the documents
        XMultiServiceFactory xServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
          XMultiServiceFactory.class, xComponent);
        logger.debug("XMultiServiceFactory of the Template retrived " + xServiceFactory);
        XDrawPagesSupplier xDrawPageSup = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class,
          xComponent);
        logger.debug("XDrawPagesSupplier retrived " + xDrawPageSup);
        XDrawPages drawPages = xDrawPageSup.getDrawPages();
        logger.debug("XDrawPages retrived " + drawPages);
        int numPages = drawPages.getCount();
        logger.debug("Template has " + numPages + " pages");
       
        // for each part of the document gets the image images and stores
        // them into cms
        for (int i = 0; i < numPages; i++) {
        int numPage = i + 1;
        logger.debug("processing page with index " + i);
        Object pageObj = drawPages.getByIndex(i);
        logger.debug("page object retrived " + pageObj);
        XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, pageObj);
        logger.debug("XDrawPage retrived " + xDrawPage);
        XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
        logger.debug("xShapes of pages retrived " + xShapes);
        int numShapes = xShapes.getCount();
        logger.debug("Page has " + numShapes + " shapes");
        for (int j = 0; j < numShapes; j++) {
            logger.debug("processing shape with index " + j);
            Object shapeObj = xShapes.getByIndex(j);
            logger.debug("shape object retrived " + shapeObj);
            XText xShapeText = (XText) UnoRuntime.queryInterface(XText.class, shapeObj);
            logger.debug("XShapeText retrived " + xShapeText);
            if (xShapeText != null) {
            String shapeText = xShapeText.getString();
            logger.debug("shape text retrived " + shapeText);
            shapeText = shapeText.trim();
            if (shapeText.startsWith("spagobi_placeholder_")) {
                String logicalObjectName = shapeText.substring(20);
                logger.debug("Logical Name of the shape " + logicalObjectName);
                ConfiguredBIDocument confDoc = dossierDAO.getConfiguredDocument(logicalObjectName, pathTmpFold);
                logger.debug("Configured document with Logical Name " + logicalObjectName
                  + " retrived " + confDoc);
                storeDocImages(confDoc, numPage, dossier, workflowProcessId);
            }
            }
        }
        }
 
    } catch (Exception e) {
        logger.error("Exception during execution : \n" + e);
        // AUDIT UPDATE
        if (contextInstance != null) {
        Integer auditId = (Integer) contextInstance.getVariable(AuditManager.AUDIT_ID);
        AuditManager auditManager = AuditManager.getInstance();
        auditManager.updateAudit(auditId, null, new Long(System.currentTimeMillis()), "EXECUTION_FAILED", e
          .getMessage(), null);
        }
        throw e;
    } finally {
        if (xComponent != null) {
        logger.debug("Start close xComponent (template document)");
        XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xComponent);
        logger.debug("XModel interface retrived " + xModel);
        XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xModel);
        logger.debug("XCloseable interface retrived " + xCloseable);
        try {
            xCloseable.close(true);
            logger.debug("xComponent (template document) closed");
        } catch (Exception e) {
            logger.error("Cannot close openoffice template document \n " + e);
        }
        }
 
        // close the bridge
        if (bridge != null) {
        XComponent xcomponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge);
        xcomponent.dispose();
        logger.debug("Bridge disposed");
        }
 
        // deletes the dossier temporary folder
        if (dossierDAO != null && pathTmpFold != null) {
          dossierDAO.clean(pathTmpFold);
          logger.debug("Dossier temp directory " + pathTmpFold + " deleted");
        }
        logger.debug("OUT");
    }
View Full Code Here

Examples of it.eng.spagobi.engines.dossier.dao.IDossierDAO

         out.write(finalDocBytes);
              return;
             
       } else if(task.equalsIgnoreCase(DossierConstants.DOSSIER_SERVICE_TASK_DOWN_OOTEMPLATE)) {
         String tempFolder = (String) serviceRequest.getAttribute(DossierConstants.DOSSIER_TEMP_FOLDER);
         IDossierDAO dossierDao = new DossierDAOHibImpl();
         String templateFileName = dossierDao.getPresentationTemplateFileName(tempFolder);
         InputStream templateIs = dossierDao.getPresentationTemplateContent(tempFolder);
         byte[] templateByts = GeneralUtilities.getByteArrayFromInputStream(templateIs);
         response.setHeader("Content-Disposition","attachment; filename=\"" + templateFileName + "\";");
         response.setContentLength(templateByts.length);
         out.write(templateByts);
         out.flush();
              return;
        
       } else if(task.equalsIgnoreCase(DossierConstants.DOSSIER_SERVICE_TASK_DOWN_WORKFLOW_DEFINITION)) {
         String tempFolder = (String) serviceRequest.getAttribute(DossierConstants.DOSSIER_TEMP_FOLDER);
         IDossierDAO dossierDao = new DossierDAOHibImpl();
         String workDefName = dossierDao.getProcessDefinitionFileName(tempFolder);
         InputStream workIs = dossierDao.getProcessDefinitionContent(tempFolder);
         byte[] workByts = GeneralUtilities.getByteArrayFromInputStream(workIs);
         response.setHeader("Content-Disposition","attachment; filename=\"" + workDefName + "\";");
         response.setContentLength(workByts.length);
         out.write(workByts);
         out.flush();
View Full Code Here

Examples of it.eng.spagobi.engines.dossier.dao.IDossierDAO

  }

  private void exitFromDetailHandler(SourceBean request, SourceBean response) throws EMFUserError, SourceBeanException {
    logger.debug("IN");
    String tempFolder = (String) request.getAttribute(DossierConstants.DOSSIER_TEMP_FOLDER);
    IDossierDAO dossierDao = DAOFactory.getDossierDAO();
    // cleans temp folder
    dossierDao.clean(tempFolder);
    // propagates dossier id (usefull to return to document main detail page if light navigator is disabled)
    Integer dossierId = dossierDao.getDossierId(tempFolder);
    response.setAttribute(ObjectsTreeConstants.OBJECT_ID, dossierId.toString());
    response.setAttribute(DossierConstants.PUBLISHER_NAME, "ExitFromDossierDetailLoop");
    logger.debug("OUT");
  }
View Full Code Here

Examples of it.eng.spagobi.engines.dossier.dao.IDossierDAO

  private String initDossier(SourceBean request, SourceBean response) throws EMFUserError, SourceBeanException {
    logger.debug("IN");
    String objIdStr = (String) request.getAttribute(SpagoBIConstants.OBJECT_ID);
    Integer objId = new Integer(objIdStr);
    BIObject dossier = DAOFactory.getBIObjectDAO().loadBIObjectById(objId);
    IDossierDAO dossierDao = DAOFactory.getDossierDAO();
    String tempFolder = dossierDao.init(dossier);
    logger.debug("OUT");
    return tempFolder;
  }
View Full Code Here

Examples of it.eng.spagobi.engines.dossier.dao.IDossierDAO

  private void loadProcessDefinitionFileHandler(SourceBean request,
      SourceBean response) throws SourceBeanException, EMFUserError {
    logger.debug("IN");
    try {
      String tempFolder = (String) request.getAttribute(DossierConstants.DOSSIER_TEMP_FOLDER);
      IDossierDAO dossierDao = new DossierDAOHibImpl();
      FileItem upFile = (FileItem) request.getAttribute("UPLOADED_FILE");
      if (upFile != null) {
        String fileName = GeneralUtilities.getRelativeFileNames(upFile.getName());
        if (upFile.getSize() == 0) {
          EMFValidationError error = new EMFValidationError(EMFErrorSeverity.ERROR, "uploadFile", "201");
          getErrorHandler().addError(error);
          return;
        }
        int maxSize = GeneralUtilities.getTemplateMaxSize();
        if (upFile.getSize() > maxSize) {
          EMFValidationError error = new EMFValidationError(EMFErrorSeverity.ERROR, "uploadFile", "202");
          getErrorHandler().addError(error);
          return;
        }
        if (!fileName.toUpperCase().endsWith(".XML")) {
          List params = new ArrayList();
          params.add("xml");
          EMFUserError error = new EMFValidationError(EMFErrorSeverity.ERROR, "UPLOADED_FILE", "107", params, null, "component_dossier_messages");
          getErrorHandler().addError(error);
        } else {
          byte[] fileContent = upFile.get();
          dossierDao.storeProcessDefinitionFile(fileName, fileContent, tempFolder);
        }
      } else {
        logger.warn("Upload file was null!!!");
      }
     
View Full Code Here

Examples of it.eng.spagobi.engines.dossier.dao.IDossierDAO

  private void loadPresentationTemplateHandler(SourceBean request,
      SourceBean response) throws SourceBeanException, EMFUserError {
    logger.debug("IN");
    try {
      String tempFolder = (String) request.getAttribute(DossierConstants.DOSSIER_TEMP_FOLDER);
      IDossierDAO dossierDao = new DossierDAOHibImpl();
      FileItem upFile = (FileItem) request.getAttribute("UPLOADED_FILE");
      if (upFile != null) {
        String fileName = GeneralUtilities.getRelativeFileNames(upFile.getName());
        if (upFile.getSize() == 0) {
          EMFValidationError error = new EMFValidationError(EMFErrorSeverity.ERROR, "uploadFile", "201");
          getErrorHandler().addError(error);
          return;
        }
        int maxSize = GeneralUtilities.getTemplateMaxSize();
        if (upFile.getSize() > maxSize) {
          EMFValidationError error = new EMFValidationError(EMFErrorSeverity.ERROR, "uploadFile", "202");
          getErrorHandler().addError(error);
          return;
        }
        if (!fileName.toUpperCase().endsWith(".PPT")) {
          List params = new ArrayList();
          params.add("ppt");
          EMFUserError error = new EMFValidationError(EMFErrorSeverity.ERROR, "UPLOADED_FILE", "107", params, null, "component_dossier_messages");
          getErrorHandler().addError(error);
        } else {
          byte[] fileContent = upFile.get();
          dossierDao.storePresentationTemplateFile(fileName, fileContent, tempFolder);
        }
      } else {
        logger.warn("Upload file was null!!!");
      }
     
View Full Code Here

Examples of it.eng.spagobi.engines.dossier.dao.IDossierDAO

   
    // 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);
View Full Code Here

Examples of it.eng.spagobi.engines.dossier.dao.IDossierDAO

 
 
  private void dossierDetailHandler(SourceBean request, SourceBean response) throws SourceBeanException, EMFUserError {
    logger.debug("IN");
    String tempFolder = (String) request.getAttribute(DossierConstants.DOSSIER_TEMP_FOLDER);
    IDossierDAO dossierDao = new DossierDAOHibImpl();
//    List roleList = null;
//    try{
//      IRoleDAO roleDao = DAOFactory.getRoleDAO();
//      roleList = roleDao.loadAllRoles();
//    } catch(Exception e) {
//      logger.error("Error while loading all roles", e);
//    }
    // get the current template file name
    String tempFileName = dossierDao.getPresentationTemplateFileName(tempFolder);
    if (tempFileName == null) tempFileName = "";
    // get list of the configured document
    List confDoc = dossierDao.getConfiguredDocumentList(tempFolder);
    // get the current process definition file name
    String procDefFileName = dossierDao.getProcessDefinitionFileName(tempFolder);
    if (procDefFileName == null) procDefFileName = "";
    //WorkflowConfiguration workConf = bookDao.getWorkflowConfiguration(pathConfBook);
    List functionalities;
    try {
      functionalities = DAOFactory.getLowFunctionalityDAO().loadAllLowFunctionalities(true);
View Full Code Here
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.