0 Replies Latest reply on Aug 1, 2007 6:27 AM by szaccaria

    check if entity is change

    szaccaria

      Hi to all,
      It is possible to know if a entity it is changed after submit a form and first the entityManager flush this change in db? I make this kind of question because I need to controll if a entity be changed from the user, so I can sign a flag.

      Morover I have the follow SFSB

      @Stateful
      @Scope(ScopeType.CONVERSATION)
      @Name("gestione")
      public class Gestione implements GestioneI {
      
       @PersistenceContext(type = PersistenceContextType.EXTENDED)
       EntityManager entityManager;
      
       @Out(scope = ScopeType.CONVERSATION, required = false)
       Documento doc;
      
       @In(required = false)
       Long idDocumento;
      
       @In(required = false)
       TaskInstance taskInstance;
      
       @In
       private Actor actor;
      
       @Logger
       private Log log;
      
       @DataModel
       private List<TaskInstance> taskInstacesResponsabile;
      
       @DataModelSelection
       private TaskInstance task;
      
       private String tab;
      
       @StartTask(flushMode=FlushModeType.MANUAL)
       public String iniziaValutazioneDoc(String tab) {
      
       String out = continuaValutazioneDoc(tab);
      
       return out;
       }
      
       @BeginTask(flushMode=FlushModeType.MANUAL)
       public String continuaValutazioneDoc(String tab) {
      
       this.tab = tab;
      
       doc = (Documento) entityManager.createQuery("select distinct d from Documento d where d.id = :id").setParameter("id", idDocumento).getSingleResult();
      
       return "/documento.xhtml";
      
       }
      
       @BeginTask
       @EndTask(transition = "confermato")
       public String chiudiValutazioneDoc(String tab) {
      
       if (taskInstance.getStart() == null)
       taskInstance.start();
      
       this.tab = tab;
      
       return "/todo2.xhtml";
       }
      
       @EndTask(transition = "confermato")
       public String confermaAInterno(String tab) {
      
       taskInstance.setActorId((String)taskInstance.getVariable("responsabile"));
      
       taskInstance.setVariable(getTrackVariableNameForActor(actor), actor.getId());
      
      
       this.tab = tab;
      
       return "/todo.xhtml";
       }
      
       @End
       public String sospendiValutazioneDoc(String tab) {
      
       this.tab = tab;
       return "/todo2.xhtml";
      
       }
      
      
      
      
      
       @Destroy
       @Remove
       public void destroy() {
       }
      
      
      
       public void caricaTasksInCarico() {
      
       JbpmContext context = ManagedJbpmContext.instance();
      
       taskInstacesResponsabile = context.getSession().createQuery(
       "select ti "+
       "from org.jbpm.taskmgmt.exe.TaskInstance ti, "+
       " org.jbpm.context.exe.VariableInstance vi join vi.processInstance pi " +
       "where " +
       " pi.end = null and " +
       " ti.token.processInstance = pi and " +
       " vi.name = :track and " +
       " vi.value = :trackValue and " +
       " ( ti.actorId = null or ti.actorId != :actorId ) and " +
       " ti.isOpen = true" ).setString("track", getTrackVariableNameForActor(actor)).setString("trackValue",actor.getId()).setString("actorId", actor.getId()).list();
      
      
       for (Iterator iter = taskInstacesResponsabile.iterator(); iter.hasNext();) {
       TaskInstance element = (TaskInstance) iter.next();
       log.error("TaskInstance n° #0 di #1", element.getId(), element.getActorId());
       }
      
       }
      
       /**
       * Genero il documento pdf in memoria
       */
       public String stampaDocumento() {
      
       FacesContext faces = FacesContext.getCurrentInstance();
      
       ByteArrayOutputStream bAOS = PdfUtility.stampaPDF(doc);
      
       HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();
       response.setContentType("application/pdf");
       response.setContentLength(bAOS.size());
       response.setHeader("Content-disposition", "Attachment; filename=\"" + doc.getClifor() + "_" + doc.getNumdoc() + ".pdf" + "\"");
       try {
       ServletOutputStream out;
       out = response.getOutputStream();
       out.write(bAOS.toByteArray());
       } catch (IOException e) {
       e.printStackTrace();
       }
       faces.responseComplete();
      
       return null;
      
       }
      
      
       public String consultazioneDocumento( String tab) {
      
       doc = (Documento) entityManager.createQuery("select distinct d from Documento d where d.id = :id").setParameter("id", task.getVariable("idDocumento"))
       .getSingleResult();
      
       this.tab = tab;
       return "/documento.xhtml";
      
       }
      
      
      
       public String salvaDocumento() {
      
       entityManager.persist(doc);
      
       return null;
       }
      
       public TaskInstance getTaskInstance() {
       return taskInstance;
       }
      
       public void setTaskInstance(TaskInstance taskInstance) {
       this.taskInstance = taskInstance;
       }
      
       /**
       * Mi torna il nome della variabile track per l'utente actor
       */
       private String getTrackVariableNameForActor(Actor actor) {
      
       String sActor = actor.getId();
       StringBuffer trackBuff = new StringBuffer();
       trackBuff.append("trackFor");
       if (sActor != null && sActor.trim().length() > 1) {
       trackBuff.append(sActor.substring(0, 1).toUpperCase());
       trackBuff.append(sActor.substring(1));
       }
       return trackBuff.toString();
      
       }
      
      
      }
      
      


      when I call from a xhtml page the action: gestione.stampaDocumento
      like:

      <h:form>
      <h:commandButton
       action="#{gestione.stampaDocumento}"
       value="#{messages.generapdf}"
       style="border: none;"
       image="/img/pdf.png"
       title="#{messages.generapdf}"
       rendered="#{s:hasRole('controllo')}">
      </h:commandButton>
      </h:form>
      


      The possible change that user made to the endity are flush in to the db, although i don't end the conversation, ( flushMode=FlushModeType.MANUAL is set in al @starttask )

      Thanks !!!