Package com.dotmarketing.portlets.workflows.business

Examples of com.dotmarketing.portlets.workflows.business.WorkflowAPI


    public void run() {
      if(Config.getBooleanProperty("ESCALATION_ENABLE",false)) {
            final int interval=Config.getIntProperty("ESCALATION_CHECK_INTERVAL_SECS",600);
            final String wfActionAssign=Config.getStringProperty("ESCALATION_DEFAULT_ASSIGN","");
            final String wfActionComments=Config.getStringProperty("ESCALATION_DEFAULT_COMMENT","Task time out");
            WorkflowAPI wapi=APILocator.getWorkflowAPI();
            while(!Thread.interrupted()) {
                try {
                   if(LicenseUtil.getLevel()>=200) {
                    try {
                        HibernateUtil.startTransaction();
                        List<WorkflowTask> tasks=wapi.findExpiredTasks();
                        for (WorkflowTask task : tasks) {
                            String stepId=task.getStatus();
                            WorkflowStep step=wapi.findStep(stepId);
                            String actionId=step.getEscalationAction();
                            WorkflowAction action=wapi.findAction(actionId, APILocator.getUserAPI().getSystemUser());
                           
                            Logger.info(this, "Task '"+task.getTitle()+"' " +
                                    "on contentlet id '"+task.getWebasset()+"' "+
                                "timeout on step '"+step.getName()+"' " +
                                "excecuting escalation action '"+action.getName()+"'");
                           
                            // find contentlet for default language
                            Contentlet def=APILocator.getContentletAPI().findContentletByIdentifier(task.getWebasset(), false,
                                    APILocator.getLanguageAPI().getDefaultLanguage().getId(),
                                    APILocator.getUserAPI().getSystemUser(), false);
                            String inode=def.getInode();
                           
                            Contentlet c;

                            // if the worflow requires a checkin
                            if(action.requiresCheckout()){
                                c = APILocator.getContentletAPI().checkout(inode, APILocator.getUserAPI().getSystemUser(), false);
                                c.setStringProperty("wfActionId", action.getId());
                                c.setStringProperty("wfActionComments", wfActionComments);
                                c.setStringProperty("wfActionAssign", wfActionAssign);
                               
                                c = APILocator.getContentletAPI().checkin(c, APILocator.getUserAPI().getSystemUser(), false);
                            }
                           
                            // if the worflow requires a checkin
                            else{
                                c = APILocator.getContentletAPI().find(inode, APILocator.getUserAPI().getSystemUser(), false);
                                c.setStringProperty("wfActionId", action.getId());
                                c.setStringProperty("wfActionComments", wfActionComments);
                                c.setStringProperty("wfActionAssign", wfActionAssign);
                                wapi.fireWorkflowNoCheckin(c, APILocator.getUserAPI().getSystemUser());
                            }
                        }
                        HibernateUtil.commitTransaction();
                    }
                    catch(Exception ex) {
View Full Code Here


        if(contentlet.getMap().get(Contentlet.DONT_VALIDATE_ME) == null) {
            canLock(contentlet, user);
        }
        contentlet.setModUser(user.getUserId());
        // start up workflow
        WorkflowAPI wapi  = APILocator.getWorkflowAPI();
        WorkflowProcessor workflow=null;

        if(contentlet.getMap().get("__disable_workflow__")==null) {
            workflow = wapi.fireWorkflowPreCheckin(contentlet,user);
        }

        workingContentlet = contentlet;
        if(createNewVersion)
            workingContentlet = findWorkingContentlet(contentlet);
        String workingContentletInode = (workingContentlet==null) ? "" : workingContentlet.getInode();

        boolean priority = contentlet.isLowIndexPriority();
        boolean isNewContent = false;
        if(!InodeUtils.isSet(workingContentletInode)){
            isNewContent = true;
        }

        if (contentlet.getLanguageId() == 0) {
            Language defaultLanguage = lanAPI.getDefaultLanguage();
            contentlet.setLanguageId(defaultLanguage.getId());
        }

        contentlet.setModUser(user != null ? user.getUserId() : "");

        if (contentlet.getOwner() == null || contentlet.getOwner().length() < 1) {
            contentlet.setOwner(user.getUserId());
        }

        // check contentlet Host
        User sysuser = APILocator.getUserAPI().getSystemUser();
                if (!UtilMethods.isSet(contentlet.getHost())) {
            contentlet.setHost(APILocator.getHostAPI().findSystemHost(sysuser, true).getIdentifier());
        }
        if (!UtilMethods.isSet(contentlet.getFolder())) {
            contentlet.setFolder(FolderAPI.SYSTEM_FOLDER);
        }

        Contentlet contentletRaw=contentlet;

                if ( contentlet.getMap().get( "_use_mod_date" ) != null ) {
                    /*
                     When a content is sent using the remote push publishing we want to respect the modification
                     dates the content already had.
                     */
                    contentlet.setModDate( (Date) contentlet.getMap().get( "_use_mod_date" ) );
                } else {
                    contentlet.setModDate( new Date() );
                }

        // Keep the 5 properties BEFORE store the contentlet on DB.
        contentPushPublishDate = contentlet.getStringProperty("wfPublishDate");
        contentPushPublishTime = contentlet.getStringProperty("wfPublishTime");
        contentPushExpireDate = contentlet.getStringProperty("wfExpireDate");
        contentPushExpireTime = contentlet.getStringProperty("wfExpireTime");
        String contentPushNeverExpire = contentlet.getStringProperty("wfNeverExpire");
        String contentWhereToSend = contentlet.getStringProperty("whereToSend");
        String forcePush = contentlet.getStringProperty("forcePush");

        if(saveWithExistingID)
            contentlet = conFac.save(contentlet, existingInode);
        else
            contentlet = conFac.save(contentlet);

        if (!InodeUtils.isSet(contentlet.getIdentifier())) {
            Treeable parent = null;
            if(UtilMethods.isSet(contentletRaw.getFolder()) && !contentletRaw.getFolder().equals(FolderAPI.SYSTEM_FOLDER)){
                parent = APILocator.getFolderAPI().find(contentletRaw.getFolder(), sysuser, false);
            }else{
                parent = APILocator.getHostAPI().find(contentlet.getHost(), sysuser, false);
            }
            Identifier ident;
            final Contentlet contPar=contentlet.getStructure().getStructureType()==Structure.STRUCTURE_TYPE_FILEASSET?contentletRaw:contentlet;
            if(existingIdentifier!=null)
                ident = APILocator.getIdentifierAPI().createNew(contPar, parent, existingIdentifier);
            else
                ident = APILocator.getIdentifierAPI().createNew(contPar, parent);
            contentlet.setIdentifier(ident.getId());
            contentlet = conFac.save(contentlet);
        } else {
            Identifier ident = APILocator.getIdentifierAPI().find(contentlet);

            String oldURI=ident.getURI();

            // make sure the identifier is removed from cache
            // because changes here may affect URI then IdentifierCache
            // can't remove it
            CacheLocator.getIdentifierCache().removeFromCacheByVersionable(contentlet);

            ident.setHostId(contentlet.getHost());
            if(contentlet.getStructure().getStructureType()==Structure.STRUCTURE_TYPE_FILEASSET){
                try {
                    ident.setAssetName(contentletRaw.getBinary(FileAssetAPI.BINARY_FIELD).getName());
                } catch (IOException e) {
                    // TODO
                }
            }
            if(UtilMethods.isSet(contentletRaw.getFolder()) && !contentletRaw.getFolder().equals(FolderAPI.SYSTEM_FOLDER)){
                Folder folder = APILocator.getFolderAPI().find(contentletRaw.getFolder(), sysuser, false);
                Identifier folderIdent = APILocator.getIdentifierAPI().find(folder);
                ident.setParentPath(folderIdent.getPath());
            }
            else {
                ident.setParentPath("/");
            }
            ident=APILocator.getIdentifierAPI().save(ident);

            changedURI = ! oldURI.equals(ident.getURI());
        }



        APILocator.getVersionableAPI().setWorking(contentlet);

        boolean structureHasAHostField = hasAHostField(contentlet.getStructureInode());

        List<Field> fields = FieldsCache.getFieldsByStructureInode(contentlet.getStructureInode());
        for (Field field : fields) {
            if (field.getFieldType().equals(Field.FieldType.TAG.toString())) {
              String value= null;
              if(contentlet.getStringProperty(field.getVelocityVarName()) != null)
                value=contentlet.getStringProperty(field.getVelocityVarName()).trim();

                if(UtilMethods.isSet(value)) {
                    String hostId = Host.SYSTEM_HOST;
                    if(structureHasAHostField){
                        Host host = null;
                        try{
                            host = APILocator.getHostAPI().find(contentlet.getHost(), user, true);
                        }catch(Exception e){
                            Logger.error(this, "Unable to get contentlet host");
                            Logger.debug(this, "Unable to get contentlet host", e);
                        }
                        if(host.getIdentifier().equals(Host.SYSTEM_HOST))
                            hostId = Host.SYSTEM_HOST;
                        else
                            hostId = host.getIdentifier();

                    }
                    List<Tag> list=tagAPI.getTagsInText(value, "", hostId);
                    for(Tag tag : list)
                        tagAPI.addTagInode(tag.getTagName(), contentlet.getInode(), hostId);
                }
            }

        }


        if (workingContentlet == null) {
            workingContentlet = contentlet;
        }

        // DOTCMS-4732
//          if(isNewContent && !hasAHostFieldSet(contentlet.getStructureInode(),contentlet)){
//              List<Permission> stPers = perAPI.getPermissions(contentlet.getStructure());
//              if(stPers != null && stPers.size()>0){
//                  if(stPers.get(0).isIndividualPermission()){
//                      perAPI.copyPermissions(contentlet.getStructure(), contentlet);
//                  }
//              }
//          }else{
//              perAPI.resetPermissionReferences(contentlet);
//          }

        if (createNewVersion || (!createNewVersion && (contentRelationships != null || cats != null))) {
            moveContentDependencies(workingContentlet, contentlet, contentRelationships, cats, permissions, user, respectFrontendRoles);
        }

        // Refreshing permissions
        if (hasAHostField(contentlet.getStructureInode()) && !isNewContent) {
            perAPI.resetPermissionReferences(contentlet);
        }

        // Publish once if needed and reindex once if needed. The publish
        // method reindexes.
        contentlet.setLowIndexPriority(priority);





        // http://jira.dotmarketing.net/browse/DOTCMS-1073
        // storing binary files in file system.
        Logger.debug(this, "ContentletAPIImpl : storing binary files in file system.");


        // Binary Files
        String newInode = contentlet.getInode();
                String oldInode = workingContentlet.getInode();


                java.io.File newDir = new java.io.File(APILocator.getFileAPI().getRealAssetPath() + java.io.File.separator
                    + newInode.charAt(0)
                        + java.io.File.separator
                        + newInode.charAt(1) + java.io.File.separator + newInode);
                newDir.mkdirs();

                java.io.File oldDir = null;
                if(UtilMethods.isSet(oldInode)) {
                  oldDir = new java.io.File(APILocator.getFileAPI().getRealAssetPath()
                  + java.io.File.separator + oldInode.charAt(0)
                  + java.io.File.separator + oldInode.charAt(1)
                  + java.io.File.separator + oldInode);
                }

                java.io.File tmpDir = null;
                if(UtilMethods.isSet(oldInode)) {
                  tmpDir = new java.io.File(APILocator.getFileAPI().getRealAssetPathTmpBinary()
                      + java.io.File.separator + oldInode.charAt(0)
                      + java.io.File.separator + oldInode.charAt(1)
                      + java.io.File.separator + oldInode);
                }



        // loop over the new field values
        // if we have a new temp file or a deleted file
        // do it to the new inode directory
          List<Field> structFields = FieldsCache.getFieldsByStructureInode(contentlet.getStructureInode());
          for (Field field : structFields) {
              if (field.getFieldContentlet().startsWith("binary")) {
                  try {

                      String velocityVarNm = field.getVelocityVarName();
                      java.io.File incomingFile = contentletRaw.getBinary(velocityVarNm);
                      java.io.File binaryFieldFolder = new java.io.File(newDir.getAbsolutePath() + java.io.File.separator + velocityVarNm);

                      java.io.File metadata=null;
                      if(contentlet.getStructure().getStructureType()==Structure.STRUCTURE_TYPE_FILEASSET) {
                          metadata=APILocator.getFileAssetAPI().getContentMetadataFile(contentlet.getInode());
                      }

                      // if the user has removed this  file via the ui
                      if (incomingFile == null  || incomingFile.getAbsolutePath().contains("-removed-")){
                          FileUtil.deltree(binaryFieldFolder);
                          contentlet.setBinary(velocityVarNm, null);
                          if(metadata!=null && metadata.exists())
                              metadata.delete();
                        continue;
                      }

                      // if we have an incoming file
                      else if (incomingFile.exists() ){
                        String oldFileName  = incomingFile.getName();
                        String newFileName  = (UtilMethods.isSet(contentlet.getStringProperty("fileName")) && contentlet.getStructure().getStructureType() == Structure.STRUCTURE_TYPE_FILEASSET) ? contentlet.getStringProperty("fileName"): oldFileName;




                        java.io.File oldFile = null;
                        if(UtilMethods.isSet(oldInode)) {
                          //get old file
                          oldFile = new java.io.File(oldDir.getAbsolutePath()  + java.io.File.separator + velocityVarNm + java.io.File.separator +  oldFileName);

                          // do we have an inline edited file, if so use that
                          java.io.File editedFile = new java.io.File(tmpDir.getAbsolutePath()  + java.io.File.separator + velocityVarNm + java.io.File.separator + WebKeys.TEMP_FILE_PREFIX + oldFileName);
                          if(editedFile.exists()){
                              incomingFile = editedFile;
                            }
                        }

                        java.io.File newFile = new java.io.File(newDir.getAbsolutePath()  + java.io.File.separator + velocityVarNm + java.io.File.separator +  newFileName);
                        binaryFieldFolder.mkdirs();

                        // we move files that have been newly uploaded or edited
                        if(oldFile==null || !oldFile.equals(incomingFile)){
                          //FileUtil.deltree(binaryFieldFolder);

                          FileUtil.move(incomingFile, newFile);

                          // delete old content metadata if exists
                          if(metadata!=null && metadata.exists())
                              metadata.delete();

                          // what happens is we never clean up the temp directory
                          // answer: this happends --> https://github.com/dotCMS/dotCMS/issues/1071
                          // there is a quarz job to clean that
                          /*java.io.File delMe = new java.io.File(incomingFile.getParentFile().getParentFile(), oldFileName);
                          if(delMe.exists() && delMe.getAbsolutePath().contains(
                                  APILocator.getFileAPI().getRealAssetPathTmpBinary()
                      + java.io.File.separator + user.getUserId()
                      + java.io.File.separator  ) ){
                            delMe.delete();
                            delMe = incomingFile.getParentFile().getParentFile();
                            FileUtil.deltree(delMe);
                          }*/

                        }
                        else if (oldFile.exists()) {
                          // otherwise, we copy the files as hardlinks
                          FileUtil.copyFile(oldFile, newFile);

                          // try to get the content metadata from the old version
                          if(metadata!=null) {
                              java.io.File oldMeta=APILocator.getFileAssetAPI().getContentMetadataFile(oldInode);
                              if(oldMeta.exists()) {
                                  if(metadata.exists()) // unlikely to happend. deleting just in case
                                      metadata.delete();
                                  metadata.getParentFile().mkdirs();
                                  FileUtil.copyFile(oldMeta, metadata);
                              }
                          }
                        }
                        contentlet.setBinary(velocityVarNm, newFile);
                      }
                  } catch (FileNotFoundException e) {
                      throw new DotContentletValidationException("Error occurred while processing the file:" + e.getMessage(),e);
                  } catch (IOException e) {
                      throw new DotContentletValidationException("Error occurred while processing the file:" + e.getMessage(),e);
                  }
              }
          }


          // lets update identifier's syspubdate & sysexpiredate
          if ((contentlet != null) && InodeUtils.isSet(contentlet.getIdentifier())) {
              Structure st=contentlet.getStructure();
              if(UtilMethods.isSet(st.getPublishDateVar()) || UtilMethods.isSet(st.getPublishDateVar())) {
                  Identifier ident=APILocator.getIdentifierAPI().find(contentlet);
                  boolean save=false;
                  if(UtilMethods.isSet(st.getPublishDateVar())) {
                      Date pdate=contentletRaw.getDateProperty(st.getPublishDateVar());
                      contentlet.setDateProperty(st.getPublishDateVar(), pdate);
                      if((ident.getSysPublishDate()==null && pdate!=null) || // was null and now we have a value
                          (ident.getSysPublishDate()!=null && //wasn't null and now is null or different
                             (pdate==null || !pdate.equals(ident.getSysPublishDate())))) {
                          ident.setSysPublishDate(pdate);
                          save=true;
                      }
                  }
                  if(UtilMethods.isSet(st.getExpireDateVar())) {
                            Date edate=contentletRaw.getDateProperty(st.getExpireDateVar());
                            contentlet.setDateProperty(st.getExpireDateVar(), edate);
                            if((ident.getSysExpireDate()==null && edate!=null) || // was null and now we have a value
                                (ident.getSysExpireDate()!=null && //wasn't null and now is null or different
                                   (edate==null || !edate.equals(ident.getSysExpireDate())))) {
                                ident.setSysExpireDate(edate);
                                save=true;
                            }
                        }
                  if (!contentlet.isLive() && UtilMethods.isSet( st.getExpireDateVar() ) ) {//Verify if the structure have a Expire Date Field set
                  if(UtilMethods.isSet(ident.getSysExpireDate()) && ident.getSysExpireDate().before( new Date())) {
                    throw new DotContentletValidationException( "message.contentlet.expired" );
                      }
                  }
                  if(save) {

                      // publish/expire dates changed
                      APILocator.getIdentifierAPI().save(ident);

                      // we take all inodes associated with that identifier
                      // remove them from cache and then reindex them
                      HibernateUtil hu=new HibernateUtil(ContentletVersionInfo.class);
                      hu.setQuery("from "+ContentletVersionInfo.class.getCanonicalName()+" where identifier=?");
                      hu.setParam(ident.getId());
                      List<ContentletVersionInfo> list=hu.list();
                      List<String> inodes=new ArrayList<String>();
                      for(ContentletVersionInfo cvi : list) {
                          inodes.add(cvi.getWorkingInode());
                          if(UtilMethods.isSet(cvi.getLiveInode()) && !cvi.getWorkingInode().equals(cvi.getLiveInode()))
                              inodes.add(cvi.getLiveInode());
                      }
                      for(String inode : inodes) {
                          CacheLocator.getContentletCache().remove(inode);
                          Contentlet ct=APILocator.getContentletAPI().find(inode, sysuser, false);
                          APILocator.getContentletIndexAPI().addContentToIndex(ct,false);
                      }
                  }
              }
          }

        Structure hostStructure = StructureCache.getStructureByVelocityVarName("Host");
        if ((contentlet != null) && InodeUtils.isSet(contentlet.getIdentifier()) && contentlet.getStructureInode().equals(hostStructure.getInode())) {
            HostAPI hostAPI = APILocator.getHostAPI();
            hostAPI.updateCache(new Host(contentlet));

            ContentletCache cc = CacheLocator.getContentletCache();
            Identifier ident=APILocator.getIdentifierAPI().find(contentlet);
            List<Contentlet> contentlets = findAllVersions(ident, sysuser, respectFrontendRoles);
            for (Contentlet c : contentlets) {
            Host h = new Host(c);
            cc.remove(h.getHostname());
            cc.remove(h.getIdentifier());
          }

            hostAPI.updateVirtualLinks(new Host(workingContentlet), new Host(contentlet));//DOTCMS-5025
            hostAPI.updateMenuLinks(new Host(workingContentlet), new Host(contentlet));

          //update tag references
            String oldTagStorageId = "SYSTEM_HOST";
            if(workingContentlet.getMap().get("tagStorage")!=null) {
              oldTagStorageId = workingContentlet.getMap().get("tagStorage").toString();
          }

            String newTagStorageId = "SYSTEM_HOST";
            if(contentlet.getMap().get("tagStorage")!=null) {
              newTagStorageId = contentlet.getMap().get("tagStorage").toString();
            }
          tagAPI.updateTagReferences(contentlet.getIdentifier(), oldTagStorageId, newTagStorageId);
        }

        if(contentlet.getStructure().getStructureType()==Structure.STRUCTURE_TYPE_FILEASSET){
            Identifier contIdent = APILocator.getIdentifierAPI().find(contentlet);
            //Parse file META-DATA
            java.io.File binFile =  getBinaryFile(contentlet.getInode(), FileAssetAPI.BINARY_FIELD, user);
            if(binFile!=null){
                contentlet.setProperty(FileAssetAPI.FILE_NAME_FIELD, binFile.getName());
                if(!UtilMethods.isSet(contentlet.getStringProperty(FileAssetAPI.DESCRIPTION))){
                    String desc = UtilMethods.getFileName(binFile.getName());
                    contentlet.setProperty(FileAssetAPI.DESCRIPTION, desc);
                }
                Map<String, String> metaMap = APILocator.getFileAssetAPI().getMetaDataMap(contentlet, binFile);

                if(metaMap!=null) {
                    Gson gson = new GsonBuilder().disableHtmlEscaping().create();
                    contentlet.setProperty(FileAssetAPI.META_DATA_FIELD, gson.toJson(metaMap));
                    contentlet = conFac.save(contentlet);
                    if(!isNewContent){
                        LiveCache.removeAssetFromCache(contentlet);
                        LiveCache.addToLiveAssetToCache(contentlet);
                        WorkingCache.removeAssetFromCache(contentlet);
                        WorkingCache.addToWorkingAssetToCache(contentlet);
                        Host host = APILocator.getHostAPI().find(contIdent.getHostId(), user, respectFrontendRoles);
                        Folder folder = APILocator.getFolderAPI().findFolderByPath(contIdent.getParentPath(), host , user, respectFrontendRoles);
                        if(RefreshMenus.shouldRefreshMenus(APILocator.getFileAssetAPI().fromContentlet(workingContentlet),APILocator.getFileAssetAPI().fromContentlet(contentlet))){
                          RefreshMenus.deleteMenu(folder);
                          CacheLocator.getNavToolCache().removeNav(host.getIdentifier(), folder.getInode());
                        }
                    }
                }
            }

            // clear possible CSS cache
            CacheLocator.getCSSCache().remove(contIdent.getHostId(), contIdent.getURI(), true);
            CacheLocator.getCSSCache().remove(contIdent.getHostId(), contIdent.getURI(), false);

        }
        if (contentlet.isLive()) {
            publishAssociated(contentlet, isNewContent, createNewVersion);
        } else {
            if (!isNewContent) {
                ContentletServices.invalidate(contentlet, true);
                // writes the contentlet object to a file
                ContentletMapServices.invalidate(contentlet, true);
            }

            indexAPI.addContentToIndex(contentlet);
        }

        if(structureHasAHostField && changedURI) {
            DotConnect dc=new DotConnect();
            dc.setSQL("select working_inode,live_inode from contentlet_version_info where identifier=? and lang<>?");
            dc.addParam(contentlet.getIdentifier());
            dc.addParam(contentlet.getLanguageId());
            List<Map<String,Object>> others = dc.loadResults();
            for(Map<String,Object> other : others) {
                String workingi=(String)other.get("working_inode");
                indexAPI.addContentToIndex(find(workingi,user,false));
                String livei=(String)other.get("live_inode");
                if(UtilMethods.isSet(livei) && !livei.equals(workingi))
                    indexAPI.addContentToIndex(find(livei,user,false));
            }
        }

        // Set the properties again after the store on DB and before the fire on an Actionlet.
        contentlet.setStringProperty("wfPublishDate", contentPushPublishDate);
        contentlet.setStringProperty("wfPublishTime", contentPushPublishTime);
        contentlet.setStringProperty("wfExpireDate", contentPushExpireDate);
        contentlet.setStringProperty("wfExpireTime", contentPushExpireTime);
        contentlet.setStringProperty("wfNeverExpire", contentPushNeverExpire);
        contentlet.setStringProperty("whereToSend", contentWhereToSend);
        contentlet.setStringProperty("forcePush", forcePush);

        //wapi.
        if(workflow!=null) {
            workflow.setContentlet(contentlet);
            wapi.fireWorkflowPostCheckin(workflow);
        }

        // DOTCMS-7290
        DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
        Identifier contIdent = APILocator.getIdentifierAPI().find(contentlet);
View Full Code Here

        //Getting the service to register our Actionlet
        ServiceReference serviceRefSelected = context.getServiceReference( WorkflowAPIOsgiService.class.getName() );
        if ( serviceRefSelected == null ) {

            //Forcing the loading of the WorkflowService
            WorkflowAPI workflowAPI = APILocator.getWorkflowAPI();
            if ( workflowAPI != null ) {

                serviceRefSelected = context.getServiceReference( WorkflowAPIOsgiService.class.getName() );
                if ( serviceRefSelected == null ) {
                    //Forcing the registration of our required services
                    workflowAPI.registerBundleService();
                }
            }
        }
    }
View Full Code Here

    }
  }

  public void importWorkflowExport(File file) throws IOException {

    WorkflowAPI wapi = APILocator.getWorkflowAPI();
    BufferedReader in = null;
    try {
      FileReader fstream = new FileReader(file);
      in = new BufferedReader(fstream);
      ObjectMapper mapper = new ObjectMapper();
      mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
      StringWriter sw = new StringWriter();
      String str;
      while ((str = in.readLine()) != null) {
        sw.append(str);
      }

      WorkflowSchemeImportExportObject importer = mapper.readValue((String) sw.toString(), WorkflowSchemeImportExportObject.class);

      for (WorkflowScheme scheme : importer.getSchemes()) {
        wapi.saveScheme(scheme);
      }
      for (WorkflowStep step : importer.getSteps()) {
        wapi.saveStep(step);
      }

      for (WorkflowAction aciton : importer.getActions()) {
        wapi.saveAction(aciton, null);
      }

      for (WorkflowActionClass actionClass : importer.getActionClasses()) {
        wapi.saveActionClass(actionClass);
      }
     
     
      for(Map<String, String> map : importer.getWorkflowStructures()){
        DotConnect dc = new DotConnect();
        dc.setSQL("delete from workflow_scheme_x_structure where id=?");
        dc.addParam(map.get("id"));
        dc.loadResult();
        dc.setSQL("insert into workflow_scheme_x_structure (id, scheme_id, structure_id) values (?, ?, ?)");
        dc.addParam(map.get("id"));
        dc.addParam(map.get("scheme_id"));
        dc.addParam(map.get("structure_id"));
        dc.loadResult();
      }
     
     
     
     

      wapi.saveWorkflowActionClassParameters(importer.getActionClassParams());

    } catch (Exception e) {// Catch exception if any
      Logger.error(this.getClass(), "Error: " + e.getMessage(), e);
    } finally {
View Full Code Here

    }
  }

  public WorkflowSchemeImportExportObject buildExportObject() throws DotDataException, DotSecurityException {
    WorkflowAPI wapi = APILocator.getWorkflowAPI();
    List<WorkflowScheme> schemes = wapi.findSchemes(true);
    List<WorkflowStep> steps = new ArrayList<WorkflowStep>();
    List<WorkflowAction> actions = new ArrayList<WorkflowAction>();
    List<WorkflowActionClass> actionClasses = new ArrayList<WorkflowActionClass>();
    List<WorkflowActionClassParameter> actionClassParams = new ArrayList<WorkflowActionClassParameter>();

    for (WorkflowScheme scheme : schemes) {

      int stepOrder = 0;
      List<WorkflowStep> mySteps = wapi.findSteps(scheme);
      for (WorkflowStep myStep : mySteps) {
        myStep.setMyOrder(stepOrder++);
        int actionOrder = 0;
        List<WorkflowAction> myActions = wapi.findActions(myStep, APILocator.getUserAPI().getSystemUser());
        for (WorkflowAction myAction : myActions) {
          myAction.setOrder(actionOrder++);
          int actionClassOrder = 0;
          List<WorkflowActionClass> myActionClasses = wapi.findActionClasses(myAction);
          for (WorkflowActionClass myActionClass : myActionClasses) {
            myActionClass.setOrder(actionClassOrder++);
            Map<String, WorkflowActionClassParameter> myActionClassParams = wapi.findParamsForActionClass(myActionClass);
            List<WorkflowActionClassParameter> params = new ArrayList<WorkflowActionClassParameter>();
            for (String x : myActionClassParams.keySet()) {
              params.add(myActionClassParams.get(x));
            }
            actionClassParams.addAll(params);
View Full Code Here

public class WfSchemeAjax extends WfBaseAction {
   public void action(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{};

  public void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    WorkflowAPI wapi = APILocator.getWorkflowAPI();


    String schemeName = request.getParameter("schemeName");
    String schemeId = request.getParameter("schemeId");
    String schemeDescription = request.getParameter("schemeDescription");
    boolean schemeArchived = (request.getParameter("schemeArchived") != null);
    boolean schemeMandatory = (request.getParameter("schemeMandatory") != null);
    String schemeEntryAction = request.getParameter("schemeEntryAction");
    if(!UtilMethods.isSet(schemeEntryAction)){
      schemeEntryAction=null;
    }
    WorkflowScheme newScheme = new WorkflowScheme();

    try {

      WorkflowScheme origScheme = APILocator.getWorkflowAPI().findScheme(schemeId);
      BeanUtils.copyProperties(newScheme, origScheme);
    } catch (Exception e) {
      Logger.debug(this.getClass(), "Unable to find scheme" + schemeId);
    }

    newScheme.setArchived(schemeArchived);
    newScheme.setDescription(schemeDescription);
    newScheme.setName(schemeName);
    newScheme.setMandatory(schemeMandatory);
    newScheme.setEntryActionId(schemeEntryAction);

    try {
      wapi.saveScheme(newScheme);
      response.getWriter().println("SUCCESS");
    } catch (Exception e) {
      Logger.error(this.getClass(), e.getMessage(), e);
      writeError(response, e.getMessage());
    }
View Full Code Here

    String o = request.getParameter("stepOrder");
    String stepName = request.getParameter("stepName");
    boolean enableEscalation=request.getParameter("enableEscalation")!=null;
    String escalationAction = request.getParameter("escalationAction");
    String escalationTime = request.getParameter("escalationTime");
    WorkflowAPI wapi = APILocator.getWorkflowAPI();
    boolean stepResolved = request.getParameter("stepResolved") != null;
    int order = 0;
    try {
      WorkflowStep step = wapi.findStep(stepId);
      if(step.isNew()){
        writeError(response, "Cannot-edit-step");
        return;
      }
      if(enableEscalation) {
          step.setEnableEscalation(true);
          step.setEscalationAction(escalationAction);
          step.setEscalationTime(Integer.parseInt(escalationTime));
      }
      else {
          step.setEnableEscalation(false);
          step.setEscalationAction(null);
          step.setEscalationTime(0);
      }
      step.setName(stepName);
      step.setResolved(stepResolved);
      order = step.getMyOrder();
      try{
        order = Integer.parseInt(o);
        wapi.reorderStep(step, order );
      }
      catch(Exception e1){
        wapi.saveStep(step);
      }

     
    }
    catch(Exception e){
View Full Code Here

  }
 
  public void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String stepId = request.getParameter("stepId");

    WorkflowAPI wapi = APILocator.getWorkflowAPI();
   
    try {

      WorkflowStep step = wapi.findStep(stepId);
      wapi.deleteStep(step);
    } catch (DotDataException e) {
      Logger.error(this.getClass(),e.getMessage());
      writeError(response, "</br> Delete Failed : </br>"+  e.getMessage());
    }
   
View Full Code Here

  public void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   
    String stepName = URLDecoder.decode(request.getParameter("stepName"), "UTF-8");
    String schemeId = request.getParameter("schemeId");
    boolean stepResolved = request.getParameter("stepResolved") != null;
    WorkflowAPI wapi = APILocator.getWorkflowAPI();
   
    try {

      List<WorkflowStep> steps =wapi.findSteps(wapi.findScheme(schemeId));
      int maxOrder = 0;
      for(WorkflowStep step : steps){
        if(step.getMyOrder() > maxOrder){
          maxOrder = step.getMyOrder() ;
        }
      }
      WorkflowStep step = new WorkflowStep();
      if(steps.size() != 0)
        maxOrder = maxOrder + 1;
      step.setMyOrder(maxOrder);
      step.setName(stepName);
      step.setSchemeId(schemeId);
      step.setResolved(stepResolved);
      wapi.saveStep(step);
     
    } catch (DotDataException e) {
      Logger.error(this.getClass(),e.getMessage(),e);
      writeError(response, e.getMessage());
    }catch (AlreadyExistException e) {
View Full Code Here

  public void listByScheme(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String schemeId = request.getParameter("schemeId");
    if(schemeId ==null || schemeId.length() < 1){
      return;
    }
    WorkflowAPI wapi = APILocator.getWorkflowAPI();

    try {
      WorkflowScheme scheme = wapi.findScheme(schemeId);
      List<WorkflowStep> steps =  wapi.findSteps(scheme);
     
     
            response.getWriter().write(stepsToJson(steps));

     
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.workflows.business.WorkflowAPI

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.