AssignmentFilterBuilderDODS.java :  » Workflow-Engines » shark » org » enhydra » shark » Java Open Source

Java Open Source » Workflow Engines » shark 
shark » org » enhydra » shark » AssignmentFilterBuilderDODS.java
/* AssignmentIteratorExpressionBuilderDODS.java */

package org.enhydra.shark;

import java.util.Properties;

import org.enhydra.shark.Shark;
import org.enhydra.shark.api.client.wfmc.wapi.WMFilter;
import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
import org.enhydra.shark.api.client.wfservice.NotConnected;
import org.enhydra.shark.api.common.AssignmentFilterBuilder;
import org.enhydra.shark.api.common.SharkConstants;
import org.enhydra.shark.utilities.MiscUtilities;

/**
 * AssignmentIteratorExpressionBuilderDODS
 * 
 * @author V.Puskas
 * @version 0.21
 */
public class AssignmentFilterBuilderDODS extends BasicFilterBuilder implements
                                                                   AssignmentFilterBuilder {
   private static final String sqlUsername = " ResourceId ";

   private static final String sqlProcessId = " ActivityProcessId ";

   private static AssignmentFilterBuilder anInstance;

   private AssignmentFilterBuilderDODS(Properties p) {
      super(p);
   }

   public static AssignmentFilterBuilder getInstance() {
      if (null == anInstance) {
         synchronized (AssignmentFilterBuilderDODS.class) {
            if (null == anInstance) {
               Properties props=new Properties();
               try {
                  props=MiscUtilities.convertNameValueArrayToProperties(Shark.getInstance().getProperties());
               } catch (Exception ex) {
               }

               anInstance = new AssignmentFilterBuilderDODS(props);
            }
         }
      }
      return anInstance;
   }

   public WMFilter addUsernameEquals(WMSessionHandle shandle, String un) throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addUsernameEquals");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addUsernameEquals", null);

         return addEqualsWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_RESOURCE_USERNAME,
                                      " TheResource ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " from SHKResourcesTable where "+getSQLUpperCaseIfNeccessary("Username")+" = ",
                                      un,
                                      ") ");
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.addUsernameEquals", this);
      }
   }

   public WMFilter addProcessIdEquals(WMSessionHandle shandle, String pid)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addProcessIdEquals");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addProcessIdEquals", null);

         return addEqualsWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_PROCESS_ID,
                                      " Activity ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " FROM SHKActivities where "
                                            + getSQLUpperCaseIfNeccessary("ProcessId")+" = ",
                                      pid,
                                      ") ");
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.addProcessIdEquals", this);
      }
   }

   public WMFilter addProcessPriorityEquals(WMSessionHandle shandle, int p)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addProcessPriorityEquals");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addProcessPriorityEquals", null);

         String sqlW = " ActivityId IN (SELECT Id FROM SHKActivities WHERE Process IN "
                       + "(SELECT " + objectid_column_name
                       + " FROM SHKProcesses WHERE Priority = " + p + ")) ";

         WMFilter fret = new WMFilter(SQL_TYPE_ASSIGNMENT);

         fret.setSQLWhereExpression(sqlW);

         return fret;

      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp,
                       "AssignmentFilterBuilderDODS.addProcessPiorityEquals",
                       this);
      }
   }

   public WMFilter addProcessPriorityLessThan(WMSessionHandle shandle, int p)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addProcessPriorityLessThan");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addProcessPriorityEquals", null);

         String sqlW = " ActivityId IN (SELECT Id FROM SHKActivities WHERE Process IN "
                       + "(SELECT " + objectid_column_name
                       + " FROM SHKProcesses WHERE Priority < " + p + ")) ";

         WMFilter fret = new WMFilter(SQL_TYPE_ASSIGNMENT);

         fret.setSQLWhereExpression(sqlW);

         return fret;

      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp,
                       "AssignmentFilterBuilderDODS.addProcessPiorityLessThan",
                       this);
      }
   }

   public WMFilter addProcessPriorityGreaterThan(WMSessionHandle shandle, int p)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addProcessPriorityGreaterThan");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addProcessPriorityEquals", null);

         String sqlW = " ActivityId IN (SELECT Id FROM SHKActivities WHERE Process IN "
                       + "(SELECT " + objectid_column_name
                       + " FROM SHKProcesses WHERE Priority > " + p + ")) ";

         WMFilter fret = new WMFilter(SQL_TYPE_ASSIGNMENT);

         fret.setSQLWhereExpression(sqlW);

         return fret;

      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp,
                       "AssignmentFilterBuilderDODS.addProcessPiorityGreaterThan",
                       this);
      }
   }

   public WMFilter addIsAccepted(WMSessionHandle shandle) throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addIsAccepted");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addIsAccepted", null);

         String javaName = SharkConstants.ASS_ACCEPTED;
         String sqlName = " Activity ";
         String sqlInPart = "IN (select "
                            + objectid_column_name + " FROM SHKActivities where "
                            + "TheResource IS NOT NULL";
         String sqlEndPart = ") ";

         WMFilter filter = new WMFilter(SQL_TYPE_ASSIGNMENT);

         filter.setBshExpression(javaName + ".booleanValue()");
         filter.setSQLWhereExpression(sqlName + sqlInPart + sqlEndPart);
         
         addNewPropertyUsed(filter, SharkConstants.ASS_ACCEPTED,"true");

         return filter;
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.addIsAccepted", this);
      }
   }

   public WMFilter addPackageIdEquals(WMSessionHandle shandle, String un)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addPackageIdEquals");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addPackageIdEquals", null);

         return addEqualsWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_PACKAGE_ID,
                                      " Activity ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " from SHKActivities where "
                                            + "Process IN (select "
                                            + objectid_column_name
                                            + " from SHKProcesses where "
                                            + "ProcessDefinition IN (select "
                                            + objectid_column_name
                                            + " FROM SHKProcessDefinitions where "+getSQLUpperCaseIfNeccessary("PackageId")+" = ",
                                      un,
                                      "))) ");
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.addPackageIdEquals", this);
      }
   }

   public WMFilter addPackageVersionEquals(WMSessionHandle shandle, String un)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addPackageVersionEquals");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addPackageVersionEquals", null);

         return addEqualsWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_PACKAGE_VERSION,
                                      " Activity ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " FROM SHKActivities where "
                                            + "Process IN (select "
                                            + objectid_column_name
                                            + " FROM SHKProcesses where "
                                            + "ProcessDefinition IN (select "
                                            + objectid_column_name
                                            + " FROM SHKProcessDefinitions where ProcessDefinitionVersion = ",
                                      un,
                                      "))) ");
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp,
                       "AssignmentFilterBuilderDODS.addPackageVersionEquals",
                       this);
      }
   }

   public WMFilter addProcessDefIdEquals(WMSessionHandle shandle, String un)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addProcessDefIdEquals");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addProcessDefIdEquals", null);

         return addEqualsWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_PROCESS_DEFINITION_ID,
                                      " Activity ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " FROM SHKActivities where "
                                            + "Process IN (select "
                                            + objectid_column_name
                                            + " FROM SHKProcesses where "
                                            + "ProcessDefinition IN (select "
                                            + objectid_column_name
                                            + " FROM SHKProcessDefinitions where "+getSQLUpperCaseIfNeccessary("ProcessDefinitionId")+" = ",
                                      un,
                                      "))) ");
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.addProcessDefIdEquals", this);
      }
   }

   public WMFilter addActivitySetDefIdEquals(WMSessionHandle shandle, String un)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addActivitySetDefIdEquals");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addActivitySetDefIdEquals", null);

         return addEqualsWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_ACTIVITY_SET_DEFINITION_ID,
                                      " Activity ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " FROM SHKActivities where "+getSQLUpperCaseIfNeccessary("ActivitySetDefinitionId")+" = ",
                                      un,
                                      ") ");
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp,
                       "AssignmentFilterBuilderDODS.addActivitySetDefIdEquals",
                       this);
      }
   }

   public WMFilter addActivityDefIdEquals(WMSessionHandle shandle, String un)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addActivityDefIdEquals");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addActivityDefIdEquals", null);

         return addEqualsWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_ACTIVITY_DEFINITION_ID,
                                      " Activity ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " FROM SHKActivities where "+getSQLUpperCaseIfNeccessary("ActivityDefinitionId")+" = ",
                                      un,
                                      ") ");
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.addActivityDefIdEquals", this);
      }
   }

   public WMFilter addActivityIdEquals(WMSessionHandle shandle, String un)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addActivityIdEquals");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addActivityIdEquals", null);

         return addEqualsWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_ACTIVITY_ID,
                                      " Activity ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " FROM SHKActivities where "+getSQLUpperCaseIfNeccessary("Id")+" = ",
                                      un,
                                      ") ");
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.addActivityIdEquals", this);
      }
   }

   public WMFilter addActivityPriorityEquals(WMSessionHandle shandle, int p)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addActivityPriorityEquals");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addActivityPriorityEquals", null);

         return addEqualsWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_ACTIVITY_PRIORITY,
                                      " Activity ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " from SHKActivities where Priority = ",
                                      p,
                                      ") ");

      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp,
                       "AssignmentFilterBuilderDODS.addActivityPriorityEquals",
                       this);
      }
   }

   public WMFilter addActivityPriorityLessThan(WMSessionHandle shandle, int p)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addActivityPriorityLessThan");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addActivityPriorityLessThan", null);

         return addLessThanWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_ACTIVITY_PRIORITY,
                                      " Activity ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " from SHKActivities where Priority ",
                                      p,
                                      ") ");

      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp,
                       "AssignmentFilterBuilderDODS.addActivityPriorityLessThan",
                       this);
      }
   }

   public WMFilter addActivityPriorityGreaterThan(WMSessionHandle shandle, int p)
      throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.addActivityPriorityGreaterThan");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "addActivityPriorityGreaterThan", null);

         return addGreaterThanWithSubQuery(SQL_TYPE_ASSIGNMENT,
                                      SharkConstants.ASS_ACTIVITY_PRIORITY,
                                      " Activity ",
                                      "IN (select "
                                            + objectid_column_name
                                            + " from SHKActivities where Priority ",
                                      p,
                                      ") ");

      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp,
                       "AssignmentFilterBuilderDODS.addActivityPriorityGreaterThan",
                       this);
      }
   }

   public WMFilter setOrderByUsername(WMSessionHandle shandle,
                                      WMFilter filter,
                                      boolean ascending) throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.setOrderByUsername");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "setOrderByUsername", null);

         return super.setOrderBy(filter, sqlUsername, ascending);
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.setOrderByUsername", this);
      }
   }

   public WMFilter setOrderByProcessId(WMSessionHandle shandle,
                                       WMFilter filter,
                                       boolean ascending) throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.setOrderByProcessId");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "setOrderByProcessId", null);

         return super.setOrderBy(filter, sqlProcessId, ascending);
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.setOrderByProcessId", this);
      }
   }

   public WMFilter setOrderByCreatedTime(WMSessionHandle shandle,
                                         WMFilter filter,
                                         boolean ascending) throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.setOrderByCreatedTime");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "setOrderByCreatedTime", null);

         return super.setOrderBy(filter,
                                 BasicFilterBuilder.objectid_column_name,
                                 ascending);
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.setOrderByCreatedTime", this);
      }
   }

   public WMFilter setOrderByAccepted(WMSessionHandle shandle,
                                      WMFilter filter,
                                      boolean ascending) throws Exception {
      long tStamp = SharkEngineManager.getInstance()
         .getCallbackUtilities()
         .methodStart(shandle,"AssignmentFilterBuilderDODS.setOrderByAccepted");
      try {
         if (!SharkUtilities.checkSession(shandle)) {
            throw new NotConnected("The session handle is not valid!");
         }
         checkSecurity(shandle, "setOrderByAccepted", null);

         return super.setOrderBy(filter, " IsAccepted ", ascending);
      } finally {
         SharkEngineManager.getInstance()
            .getCallbackUtilities()
            .methodEnd(shandle,tStamp, "AssignmentFilterBuilderDODS.setOrderByAccepted", this);
      }
   }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.