Package org.uengine.persistence.processdefinitionversion

Examples of org.uengine.persistence.processdefinitionversion.ProcessDefinitionVersionRepositoryLocal


      if(pdvid.indexOf("@")>-1){
        pdvid = ProcessDefinition.splitDefinitionAndVersionId(pdvid)[1];
      }
     
      ProcessDefinitionVersionRepositoryHomeLocal pdvhr = GlobalContext.createProcessDefinitionVersionRepositoryHomeLocal(getTransactionContext());
      ProcessDefinitionVersionRepositoryLocal pdvlr = pdvhr.findByPrimaryKey(new Long(pdvid));
     
      ProcessDefinitionRepositoryHomeLocal pdhr = GlobalContext.createProcessDefinitionRepositoryHomeLocal(getTransactionContext());
      ProcessDefinitionRepositoryLocal pdlr = pdhr.findByPrimaryKey(pdvlr.getDefId());
     
      pdlr.setProdVer(pdvlr.getVer().intValue());
      pdlr.setProdVerId(new Long(pdvid));
     
      if(pdlr.getObjType()==null){
        ProcessDefinition definition = getProcessDefinition(pdvid);
        String shortDescription = definition.getShortDescription();
View Full Code Here


      ProcessDefinition pd = pdf.getDefinition(pdvid);
      pd.setName(newName);

      //rename process definition version
      ProcessDefinitionVersionRepositoryHomeLocal pdvhr = GlobalContext.createProcessDefinitionVersionRepositoryHomeLocal(tc);   
      ProcessDefinitionVersionRepositoryLocal pdvr = pdvhr.findByPrimaryKey(new Long(pdvid));
      pdvr.setDefName(newName);
         
      //restore upd file
      String path = null;
      String def = (String)pdvr.getFilePath();
      if(def.startsWith("LINK:")){
        path = def.substring("LINK:".length());
      }
      pdf.storeProcessDefinition(path, pd);
     
View Full Code Here

  }
 
  public ProcessDefinitionRemote getProcessDefinitionRemote(String pdvid) throws RemoteException{
    try{
      ProcessDefinitionVersionRepositoryHomeLocal pdvrhl = GlobalContext.createProcessDefinitionVersionRepositoryHomeLocal(getTransactionContext());
      ProcessDefinitionVersionRepositoryLocal pdvrl = pdvrhl.findByPrimaryKey(new Long(pdvid));
     
      ProcessDefinitionRepositoryHomeLocal pdhr = GlobalContext.createProcessDefinitionRepositoryHomeLocal(getTransactionContext());
      ProcessDefinitionRepositoryLocal pdl = pdhr.findByPrimaryKey(pdvrl.getDefId());
      int productionVersion = pdl.getProdVer();
     
      ProcessDefinitionRemote pdr =null;
     
      try{
        ProcessDefinition pd = getDefinition(pdvid);
        if(pd !=null && pd instanceof ProcessDefinition){
          pdr = new ProcessDefinitionRemote(pd, getTransactionContext(), pdvrl);
         
          if(pdl.getObjType() != null){
            pdr.setObjType(pdl.getObjType());
          }
        }
      }catch (Exception e) {
        pdr = new ProcessDefinitionRemote(pdl, pdvrl);
      }
     
     
//      ProcessDefinitionRemote pdr = new ProcessDefinitionRemote(getDefinition(pdvid), getTransactionContext());
      //TODO: Method 'getProcessDefinitionRemoteWithInstanceId' also need such correction
      //pdr.setName(TextContext.createInstance());
      //pdr.getName().setText(pdl.getName());
      //pdr.setBelongingDefinitionId(pdl.getId().toString());
     
      if(pdvrl.getVer().intValue() == productionVersion)
        pdr.setProduction(true);
      else{
        pdr.setProduction(false);
      }
     
View Full Code Here

 
  private void getFilePathNFileCopy(ProcessDefinitionRemote pdr, String parentDirectory, boolean isSub) throws Exception {
    ProcessManagerBean pmb = this;
    ProcessTransactionContext tc = pmb.getTransactionContext();
    ProcessDefinitionVersionRepositoryHomeLocal pdvhr = GlobalContext.createProcessDefinitionVersionRepositoryHomeLocal(tc);
    ProcessDefinitionVersionRepositoryLocal pdvr;

    pdvr = pdvhr.findByPrimaryKey(new Long(pdr.getId()));
    String def = (String) pdvr.getFilePath();
    if (def.startsWith("LINK:")) {
      File f = new File(TEMP_DIRECTORY + parentDirectory);
      if (!f.exists())
        f.mkdirs();
      String resourceLocation = def.substring("LINK:".length());
View Full Code Here

          //Object[] nameAndVersion = UEngineUtil.getProcessNameAndVersion(pdr.getName());
          //String name = (String)nameAndVersion[0];
         
          Collection versions = pdihr.findAllVersions(new Long(pdr.getId()));
          for(Iterator iter2 = versions.iterator(); iter2.hasNext();){           
            ProcessDefinitionVersionRepositoryLocal pdirl = ((ProcessDefinitionVersionRepositoryLocal)iter2.next());
           
            pdr = new ProcessDefinitionRemote();
            pdr.setId(pdirl.getDefVerId().toString());
            pdr.setFolder(false);
            pdr.setParentFolder(pdrl.getParentFolder().toString());
            pdr.setName(TextContext.createInstance())
            pdr.getName().setText(pdrl.getName());
            pdr.setVersion(pdirl.getVer().intValue());
            pdr.setBelongingDefinitionId(definitionGroupId);
            pdr.setObjType(objType);
            pdr.setAlias(pdrl.getAlias());
            pdr.setVisible(pdrl.getIsVisible());
           
            if(pdirl.getVer().intValue() == productionVersion)
              pdr.setProduction(true);

            processDefinitionRemotes.add(pdr);
          }         
        }else
View Full Code Here

        pdid = getProcessDefinitionIdByAlias(definitionAlias);
      }   
   
      Collection versions = pdihr.findAllVersions(new Long(pdid));
      for(Iterator iter2 = versions.iterator(); iter2.hasNext();){   
        ProcessDefinitionVersionRepositoryLocal pdirl = ((ProcessDefinitionVersionRepositoryLocal)iter2.next());
       
        pdr = new ProcessDefinitionRemote();
        pdr.setId(pdirl.getDefVerId().toString());
        pdr.setFolder(false);
        //pdr.setParentFolder(pdrl.getParentFolder().toString());
        pdr.setName(TextContext.createInstance());
        //pdr.getName().setText(pdrl.getName());
        pdr.setVersion(pdirl.getVer().intValue());
        pdr.setModifiedDate(pdirl.getModDate());
        //pdr.setBelongingDefinitionId(definitionGroupId);
       
        //if(pdirl.getVer() == productionVersion)
        if( productionVersion != null && productionVersion.equals(pdirl.getDefVerId().toString())){
          pdr.setProduction(true);
        }

        processDefinitionRemotes.add(pdr);
      }         
View Full Code Here

 
 
  public String getResourcePath(String resourceId) throws Exception{
    ProcessDefinitionVersionRepositoryHomeLocal pdvhr = GlobalContext.createProcessDefinitionVersionRepositoryHomeLocal(tc);   
   
    ProcessDefinitionVersionRepositoryLocal pdvr;
    try{
      pdvr = pdvhr.findByPrimaryKey(new Long(resourceId));
    }catch(ObjectNotFoundException onfe){
      throw new UEngineException("No such Resource Version id [" + resourceId + "]", onfe);
    }
   
    String def = (String)pdvr.getFilePath();
   
    if(def.startsWith(LINK_SIGN)){
      String resourceLocation = def.substring(LINK_SIGN.length());
      return resourceLocation = DEFINITION_ROOT + resourceLocation;
    }
View Full Code Here

  }
 
  protected Object getDefinitionSourceImpl(String pdvid, boolean fromCompilationVersion, boolean shouldBeObjectResult) throws Exception{
    ProcessDefinitionVersionRepositoryHomeLocal pdvhr = GlobalContext.createProcessDefinitionVersionRepositoryHomeLocal(tc);   
   
    ProcessDefinitionVersionRepositoryLocal pdvr;
    try{
      pdvr = pdvhr.findByPrimaryKey(new Long(pdvid));
    }catch(ObjectNotFoundException onfe){
      throw new UEngineException("No such Process Definition version id [" + pdvid + "]", onfe);
    }
   
    String def = (String)pdvr.getFilePath();
   
    if(def.startsWith(LINK_SIGN)){
      String resourceLocation = def.substring(LINK_SIGN.length());
     
      //try to load cached(binary) version of definition
      if(fromCompilationVersion){
        ObjectInputStream ow = null;
        try{
          resourceLocation = DEFINITION_ROOT + resourceLocation;
         
          String fileName = resourceLocation + ".cached";
         
          if(processDefinitions.containsKey(pdvid)) return getActivity(pdvid, true);
          ow = new ObjectInputStream(new FileInputStream(fileName));
          if(processDefinitions.containsKey(pdvid)) return getActivity(pdvid, true);

          ProcessDefinition objectDefinition = (ProcessDefinition)ow.readObject();
          objectDefinition.setBelongingDefinitionId(pdvr.getDefId().toString());
         
          Calendar rightModifiedDate = Calendar.getInstance();{
            Date md = pdvr.getModDate();
            if(md!=null)
              rightModifiedDate.setTime(md);
          }
          objectDefinition.setModifiedDate(rightModifiedDate);
       
System.out.println("load '"+ resourceLocation +"' from cached file..succeed!");
          return objectDefinition;       
        }catch(Exception ice){
          if(ice instanceof java.io.InvalidClassException)
            System.out.println("XML-Bean version is loaded for '"+ resourceLocation +"'..since the class version has been modified.");
         
          try{
            ProcessDefinition objectDefinition = getDefinition(new FileInputStream(resourceLocation));
            objectDefinition.setBelongingDefinitionId(pdvr.getDefId().toString());
            objectDefinition.setName(pdvr.getDefName());
           
            //dynamically create the cached(compiled) version
            compileDefinition(resourceLocation, objectDefinition);

            Calendar rightModifiedDate = Calendar.getInstance();{
              Date md = pdvr.getModDate();
              if(md!=null)
                rightModifiedDate.setTime(md);
            }
            objectDefinition.setModifiedDate(rightModifiedDate);

            return objectDefinition;
          }catch(Exception e){
            throw new UEngineException("Error when to deserialize definition file '" + resourceLocation +"': "+ e.getMessage(), e);
          }
        }finally{
          try{ow.close();}catch(Exception e){}
        }
      }
     
      if(shouldBeObjectResult){
        ProcessDefinition pd = getDefinition(new FileInputStream(DEFINITION_ROOT + resourceLocation));
        pd.setBelongingDefinitionId(pdvr.getDefId().toString());
        return pd;
      }else
        return new FileInputStream(DEFINITION_ROOT + resourceLocation);     
    }

    StringBufferInputStream is = new java.io.StringBufferInputStream(def);
   
    if(shouldBeObjectResult){
      ProcessDefinition pd = getDefinition(is);
      pd.setBelongingDefinitionId(pdvr.getDefId().toString());
      pd.setName(pdvr.getDefName());
      return pd;
    }else
      return is;
  }
View Full Code Here

//    Object[] nameAndVersion = UEngineUtil.getProcessNameAndVersion(pdid);
//    String name = (String)nameAndVersion[0];
//    int version = ((Integer)nameAndVersion[1]).intValue();
   
    ProcessDefinitionVersionRepositoryHomeLocal pdvh = GlobalContext.createProcessDefinitionVersionRepositoryHomeLocal(tc);
    ProcessDefinitionVersionRepositoryLocal pdvl = pdvh.findByPrimaryKey(new Long(pdvid));
    Long pdid = pdvl.getDefId();   
   
    try{
      ProcessDefinitionVersionRepositoryLocal pdir = pdvh.findByPrimaryKey(new Long(pdvid));
      //don't remove to prevent danggling instances
      //pdir.remove();
      pdir.setIsDeleted(true);
     
      Collection versions = pdvh.findAllVersions(pdid);
      //force to remove the definition if there's no more version.
      if(!versions.iterator().hasNext()) throw new ObjectNotFoundException();
    }catch(javax.ejb.ObjectNotFoundException e){
View Full Code Here

     
    //create a version
    if(pdvid==null)
      pdvid = ""+UniqueKeyGenerator.issueProcessDefinitionVersionKey(tc);     
    ProcessDefinitionVersionRepositoryHomeLocal pdvhr;
    ProcessDefinitionVersionRepositoryLocal pdvr = null;
    pdvhr = GlobalContext.createProcessDefinitionVersionRepositoryHomeLocal(tc);
    if(!overwrite){
      if(version!=-1){
        Collection existingVersions = pdvhr.findByDefinitionAndVersion(new Long(belongingPdid), new Long(version));
        if(existingVersions.iterator().hasNext()){
          pdvr = (ProcessDefinitionVersionRepositoryLocal)existingVersions.iterator().next();
          pdvid = ""+pdvr.getDefVerId();
//          throw new UEngineException("There is same version already exists. Choose another version.");
         
          //FIXME: implement for non-ejb version.
          if(!"org.uengine.kernel.DefaultProcessInstance".equals(GlobalContext.getPropertyString("processinstance.class"))){
            ProcessInstanceDAOType pidaotype = ProcessInstanceDAOType.getInstance(tc);
            ProcessInstanceDAO existingInstances = pidaotype.findByDefinitionVersion(pdvr.getDefVerId());
            if(existingInstances.size()>0){
              throw new UEngineException("There is some instances belonged to this definition already exists. Choose another version number.");
            }
          }
          overwrite = true;
          verifyModifiedDateWhenOverwriting = false;
         
        }       
      }
     
      if(pdvr==null){
        pdvr = pdvhr.create(new Long(pdvid));
        pdvr.setVer(new Long(version));
        pdvr.setDefId(new Long(belongingPdid));
        pdvr.setDefName(name);
      }
     
    }else{
      pdvr = pdvhr.findByPrimaryKey(new Long(pdvid));
    }
   
    String fullFileName;
    String relativeFileName;
    if(overwrite){
      removeFromCache(pdvid);
      relativeFileName = pdvr.getFilePath().substring(LINK_SIGN.length());
      int extPos = relativeFileName.lastIndexOf(".");
      if(extPos == -1){
        relativeFileName = relativeFileName + "_rev1";
      }else{
        int revPos = relativeFileName.indexOf("_rev");
       
        int overWriteIndex = 0;
        if(revPos != -1)
          overWriteIndex = Integer.parseInt(relativeFileName.substring(revPos+4,extPos));
        else
          revPos = extPos;
       
        overWriteIndex++;
        relativeFileName = relativeFileName.substring(0, revPos) + "_rev" +overWriteIndex + relativeFileName.substring(extPos);
      }
    }else if(isAdhoc){
      String calDir = UEngineUtil.getCalendarDir() + "/";
      String dir = DEFINITION_ROOT + calDir;
      (new File(dir)).mkdirs();
     
      relativeFileName = calDir + pdvid + "." + objectType;
    }else{
      relativeFileName = pdvid + "." + objectType;
    }

    fullFileName = DEFINITION_ROOT + relativeFileName;
   
    //store a binary version (to reduce serialization cost)
   
    boolean isProcessDefinitionType=false;
    if(definition instanceof String){
      try{
        if(GlobalContext.deserialize(definition.toString(), Object.class) instanceof ProcessDefinition){
          isProcessDefinitionType=true;
        }
      }catch (Exception e) {
        isProcessDefinitionType=false;
      }
    }else if(definition instanceof ProcessDefinition){
      isProcessDefinitionType=true;
    }
   
    if(isProcessDefinitionType){
      ProcessDefinition objectDefinition;     
      if(definition instanceof String){
        ByteArrayInputStream bis = new ByteArrayInputStream(((String)definition).getBytes("UTF-8"));
        try{
          objectDefinition = getDefinition(bis);
        }catch(Exception e){
          throw new UEngineException("Error to parse definition: "+definition + " as Process Definition. Please check if the stream is not form of Process Definition.", e);
        }
      }else/* if(defintion instanceof ProcessDefinition)*/{
        objectDefinition = (ProcessDefinition)definition;
      }
     
      //TODO: [performance] Definition in object form is here gotten. So it's no need to load again in the next transaction. Why not just put this in the cache?
     
  //TODO: [disabled now]
  //    if(overwrite &&
  //        verifyModifiedDateWhenOverwriting &&
  //        objectDefinition.getModifiedDate()!=null && !objectDefinition.getModifiedDate().getTime().equals(pdvr.getModDate())
  //    )
  //      throw new UEngineException("This definition is modified by someone during you're editing.");
 
      objectDefinition.setBelongingDefinitionId(belongingPdid);
      objectDefinition.setId(pdvid);
      objectDefinition.setVersion(version);
      objectDefinition.setModifiedDate(modifiedDate);
     
      String[] deployFilters = GlobalContext.getPropertyStringArray("deployfilters");
      if(deployFilters!=null){
        for(int i=0; i<deployFilters.length; i++){
          try{
            DeployFilter deployFilter = (DeployFilter)Class.forName(deployFilters[i]).newInstance();
            deployFilter.beforeDeploy(objectDefinition, tc,folder,!definitionExist);
          }catch(Exception e){
            e.printStackTrace();
          }
        }
      }
     
      compileDefinition(fullFileName, objectDefinition);
     
      if(options!=null && options.containsKey("associatedInstance")){
        ProcessInstance instance = (ProcessInstance)options.get("associatedInstance");
        instance.setProcessDefinition(objectDefinition);
      }
     
      if(definition instanceof String){
        definition = GlobalContext.serialize(objectDefinition, String.class);
      }
     
    }
   
    Timestamp timestamp = new Timestamp(modifiedDate.getTimeInMillis());
    if(!DAOFactory.getInstance(tc).getDBMSProductName().startsWith("DB2"))
      pdvr.setModDate(timestamp);
   
   
    //store definition as XML-Bean text file
    //if(version!=-1){ //only when the definition is adhoc instance //changed to alwalys
    String strDef;
    if(definition instanceof String){
      strDef = (String)definition;
    }else{
      ByteArrayOutputStream bao = new ByteArrayOutputStream();     
      GlobalContext.serialize((ProcessDefinition)definition, bao, String.class);
      strDef = bao.toString("UTF-8");
    }
 
    OutputStreamWriter bw = null;
    try{
      bw = new OutputStreamWriter(new FileOutputStream(fullFileName), "UTF-8");
      bw.write(strDef);
      bw.close();
    }catch(Exception e){
      throw e;
    }finally{
      if(bw!=null)
        try{bw.close();}catch(Exception e){};
    }
    //}
   
    //verify consistency with referencing instances /////////////////// --> disabled
/*    if(overwrite && options!=null){
      String instanceId = (options.containsKey("instanceId") ? (String)options.get("instanceId") : null);
      if(instanceId!=null){
        ProcessInstance instance = ProcessInstance.create().getInstance(instanceId);
        Vector runningActivityTracingTags = instance.getRunningOrCompletedActivityTracingTags();
       
        for(int i=0; i<runningActivityTracingTags.size(); i++){
          String tracingTagToVerify = (String)runningActivityTracingTags.elementAt(i);
          Activity activityNew = objectDefinition.getActivity(tracingTagToVerify);
          if(activityNew == null){
            throw new UEngineException("The changed definition is not consistent with running instance. REASON: Though activity with tracingtag '" + tracingTagToVerify + "' is already running or completed, it is ommitted in the changed process.");
          }
        }
      }
    }*/
   
    //if(!overwrite){
    pdvr.setFilePath(LINK_SIGN + relativeFileName);
    //}

   
    return new String[]{pdvid, belongingPdid, LINK_SIGN + relativeFileName};
  }
View Full Code Here

TOP

Related Classes of org.uengine.persistence.processdefinitionversion.ProcessDefinitionVersionRepositoryLocal

Copyright © 2018 www.massapicom. 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.