Examples of UtilTimer


Examples of org.ofbiz.base.util.UtilTimer

        UIWebScreenSection uiWebScreenSection, int retrieveMethod,
        HttpServletRequest request, HttpServletResponse response,
        GenericDelegator delegator, GenericEventProcessor eventProcessor,
        DataMatrix dataMatrix, StringBuffer queryIdBuffer, String action)
        throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processRetrieve] Start");
        }

        int status = STATUS_CONTINUE;

        String queryId = queryIdBuffer.toString();

        // Get info about the screen.
        String screenName = uiWebScreenSection.getUiScreen().getScreenName();

        // Get info about the screen section.
        String sectionId = uiWebScreenSection.getSectionId();
        String sectionName = uiWebScreenSection.getSectionName();
        int layoutTypeId = uiWebScreenSection.getLayoutTypeId();

        String primaryEntityName = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                     .getUiEntity()
                                                     .getEntityName();

        Debug.logVerbose("Primary entity name: " + primaryEntityName, module);

        ModelEntity primaryME = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                  .getUiEntity().getModelEntity();
        List primaryPkFieldNames = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                     .getUiEntity()
                                                     .getPrimaryKeyFieldNames();

        // Specify how the primary entity will be retrieved.
        HashMap fields = new HashMap();
        ArrayList orderBy = new ArrayList();
        QueryInfo queryInfo = new QueryInfo(delegator, primaryEntityName);
        Enumeration params = null;
        String searchAttribValue = "";
        String searchEntityName = "";
        String searchAttribName = "";
        String queryName = "";
        String listName = "";
        EntityComparisonOperator entityOperator = null;
        List relatedSearchClauses = new LinkedList();
        List selectFields = new ArrayList();
       
        // Note that we only care about primary entity fields in the select at the moment.
        // TODO:  change the queries so that all related data is retrieved as part of the main retrieve
        //        which it is, but the original code was written before dynamicViewEntities were added
    int selectFieldListSize = uiWebScreenSection.getUiFieldList().size();
    for (int fieldNbr = 0; fieldNbr < selectFieldListSize; fieldNbr++) { 
      UIFieldInfo fieldInfo = uiWebScreenSection.getUiField(fieldNbr);
      String fieldName = fieldInfo.getUiAttribute().getAttributeName();
      String entityName = fieldInfo.getUiAttribute().getUiEntity().getEntityName();
      if ( entityName.equals(primaryEntityName) )
        selectFields.add(fieldName);

/*      if ( fieldInfo.getIsVisible() )
      {
        String fieldName = fieldInfo.getUiAttribute().getAttributeName();
        String entityName = fieldInfo.getUiAttribute().getUiEntity().getEntityName();
        String aliasName = fieldName;
        if ( ! entityName.equals(primaryEntityName))
          aliasName = entityName + "." + fieldName;
        selectFields.add(aliasName);
      }
*/
    }
    queryInfo.setSelectFields(selectFields);

        if (request.getParameter("queryName") != null) {
            queryName = request.getParameter("queryName");
        }

        if (request.getParameter("listName") != null) {
            listName = request.getParameter("listName");
            if ( queryName.length() < 1)
                queryName = listName;
        }

       
        //    HashMap querySaveMap = new HashMap();
        UIQuery uiQuery = null;


    // Specify how associated entities will be retrieved.
    Iterator uiScreenSectionEntityI = uiWebScreenSection.getUiScreenSectionEntityList()
                              .iterator();
    uiScreenSectionEntityI.next(); // Pass up the primary entity.

    while (uiScreenSectionEntityI.hasNext()) {
      UIScreenSectionEntity uiScreenSectionEntity = (UIScreenSectionEntity) uiScreenSectionEntityI.next();
     
      relatedSearchClauses.add(uiScreenSectionEntity);
    }

    uiScreenSectionEntityI = null; // Reset the iterator.




        switch (retrieveMethod) {
        case GenericEventProcessor.RETRIEVE_METHOD_ALL:

            // Find all entities of this type.
            // Don't need to populate the fields map.
            break;

        case GenericEventProcessor.RETRIEVE_METHOD_AND:

            // Find the main entity(ies) by building a WHERE clause using "=" and AND.
            throw new GenericEntityException(
                "RETRIEVE_METHOD_AND not implemented yet.");

        case GenericEventProcessor.RETRIEVE_METHOD_CLAUSE:

            if (TIMER) {
                timer.timerString(1,
                    "[GenericWebEventProcessor.processRetrieve] Start RETRIEVE_METHOD_CLAUSE");
            }

      HashMap joinedEntities = new HashMap();
     
      joinedEntities.put(primaryEntityName, "Y");
     
            // Find the main entity(ies) by building a WHERE clause using LIKE and AND, with one or more tables in the FROM clause.
            // First join all secondary screen section entities in the WHERE and FROM clauses in case
            // we are going to use query values from them.
            Iterator relatedClauseI = relatedSearchClauses.iterator();

            while (relatedClauseI.hasNext()) {
                UIScreenSectionEntity uiScreenSectionEntity = (UIScreenSectionEntity) relatedClauseI.next();
                String relationTitle = uiScreenSectionEntity.getRelationTitle();
                String relatedEntityName = uiScreenSectionEntity.getUiEntity().getEntityName();
        boolean isOuterJoin = uiScreenSectionEntity.getIsOuterJoined();
        String relatedAndFields = uiScreenSectionEntity.getRelationByAndFields();

                Debug.logVerbose("Adding relation clauses for " +
                        relationTitle + "/" + relatedEntityName, module);

                eventProcessor.addOneRelationClause(delegator, relationTitle, relatedAndFields,
                    relatedEntityName, primaryEntityName, primaryME, isOuterJoin,
                    queryInfo);
                   
                joinedEntities.put(relatedEntityName, "Y");
            }

            Debug.logVerbose(
                    "queryId at beginning of RETRIEVE_METHOD_CLAUSE section: " +
                    queryId, module);

            if (queryId.equalsIgnoreCase("NONE")) {
                // Don't retrieve any data. The calling link specified to use the last query, but there wasn't one.
                return STATUS_CONTINUE;
            } else if (!queryId.equals("")) {
                // User selected a saved query.  Get it from the data base.
                uiQuery = new UIQuery(queryId, delegator);

                if (!uiQuery.getQueryId().equals("")) {
                    // Query was found.
                    uiQuery.appendEntityClauses(delegator, queryInfo);

                    //            // Store the attribute ID and value in the query save map.
                    //            querySaveMap.put(attributeId, searchAttribValue);
                }

                // add extra clauses from the hidden query parameters in case this is a detail screen
                addUseQueryParameterClauses(uiWebScreenSection, queryInfo,
                    relatedSearchClauses, primaryEntityName, request);
            } else {
                // Brand new query. Process all the parameters coming in through the request object to get the values to search by.
                uiQuery = new UIQuery();

        String queryListMaxRows = request.getParameter("queryListMaxRows");
        // if queryListMaxRows is set, then we are using advanced query mode
        if ( (queryListMaxRows != null ) && ( queryListMaxRows.length() > 0) )
        {
          int maxRows = Integer.valueOf(queryListMaxRows).intValue();
          for ( int i=1; i <= maxRows; i++ )
          {
            String qlFieldInfo = request.getParameter("queryListField" + i);
            if ( ( qlFieldInfo != null ) && ( qlFieldInfo.length() > 0 ) )
            {
              StringTokenizer tokSemi = new StringTokenizer(qlFieldInfo,";");
              String qlFieldName = "";
              String qlAttributeId = "";
              String qlDisplayObjectId = "";
              String qlDisplayTypeId = "";
             
              if (tokSemi.countTokens() == 4) {
                  qlFieldName = tokSemi.nextToken();
                  qlAttributeId = tokSemi.nextToken();
                  qlDisplayTypeId = tokSemi.nextToken();
                  qlDisplayObjectId = tokSemi.nextToken();
              }
              else
              {
                qlFieldName = qlFieldInfo;
              }

              String qlOperator  = request.getParameter("queryListOperator" + i);
              String qlValue     = request.getParameter("queryListValue" + i);
             
              if ( qlOperator.equals("like"))
                qlValue =  "%" + qlValue.replace('*','%') + "%";
              else if ( qlOperator.equals("startsWith"))
              {
                qlValue =  qlValue.replace('*','%') + "%";
                qlOperator = "like";
              }
              else if ( qlOperator.equals("endsWith"))
              {
                qlValue =  "%" + qlValue.replace('*','%');
                qlOperator = "like";
              }

              searchEntityName = UIWebUtility.getEntityFromParamName(qlFieldName);
 
              String hasJoin = (String) joinedEntities.get(searchEntityName);
             
              if ( ( hasJoin == null ) || ( !hasJoin.equals("Y")) )
              {
                eventProcessor.addOneRelationClause(delegator, "", "",searchEntityName, primaryEntityName, primaryME, false, queryInfo);

                joinedEntities.put(searchEntityName, "Y");
              }
             
              if ((searchEntityName == null) ||
                  searchEntityName.equals("")) {
                searchEntityName = primaryEntityName;
              }
 
              searchAttribName = UIWebUtility.getAttribFromParamName(qlFieldName);
              entityOperator = EntityOperator.lookupComparison(qlOperator);
              Object searchValue = qlValue;
             
              // If this is a set operator, convert the String param into a comma separated List
              if ( (entityOperator.equals(EntityOperator.IN)) || (entityOperator.equals(EntityOperator.NOT_IN)) || (entityOperator.equals(EntityOperator.BETWEEN)))
              {
                List valueList = new ArrayList();
                StringTokenizer tokComma = new StringTokenizer(qlValue, ",");

                while (tokComma.hasMoreTokens()) {
                  String valueItem = tokComma.nextToken();
                  valueList.add(valueItem);
                }
                searchValue = valueList;
              }
             
              try {
                // Figure out the attribute ID for the UiAttribute this parameter corresponds to so we can
                // save the query.
                String attributeId = UIWebUtility.getAttributeId(delegator,
                    searchAttribName, searchEntityName);
 
                // Generate an entry in the WHERE clause for this attribute.  The entityOperator
                // is returned in case appendEntityClause changes it.
                // NOTE:  changes here must also be applied to UIQuery.appendEntityClauses() to work with saved queries
                //
                if ( qlDisplayTypeId.equals(UIDisplayObject.DISPLAY_TYPE_SELECT) || qlDisplayTypeId.equals(UIDisplayObject.DISPLAY_TYPE_SEARCH_TEXT))
                {
                  String aliasName = searchEntityName + searchAttribName + "srch";
                  UIUtility.addSelectSearch( queryInfo, qlDisplayObjectId, searchEntityName, searchAttribName, aliasName, entityOperator, searchValue );
                }
                else
                {
                  if ( searchValue instanceof String )
                  {
                  entityOperator = EventUtility.appendEntityClause(searchEntityName,
                      searchAttribName, (String) searchValue,
                    entityOperator, queryInfo);
                }
                  else if ( searchValue instanceof Collection)
                  {
                    entityOperator = EventUtility.appendEntityClause(searchEntityName,
                      searchAttribName, (Collection) searchValue,
                      entityOperator, queryInfo);
                  }
                  else
                    throw new IllegalArgumentException("Query Param must be String or Collection");
                }

                // Store the attribute ID and value in the query save map.
                //                  querySaveMap.put(attributeId, searchAttribValue);
                uiQuery.addUiQueryValue(attributeId, entityOperator, qlValue, qlDisplayTypeId, qlDisplayObjectId, delegator);
              } catch (GenericEntityException e) {
                //this parameter was not associated with a column in a table, so skip it
                Debug.logVerbose("skipping parameter which is not an entity attribute: " + qlFieldName, module);
              }

            }
          }
        }
        else
        {

                params = request.getParameterNames();

                while (params.hasMoreElements()) {
                    String paramName = (String) params.nextElement();

                    //            boolean useSentQueryParameter =
                    //              !action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE &&
                    //              !action.equals(uiWebScreenSection.ACTION_QUERY &&
                    //              uiWebScreenSection.getUseQueryParameterMap().containsValue(paramName);
                    Debug.logVerbose("paramName: " + paramName, module);
                    Debug.logVerbose("action: " + action, module);
                    Debug.logVerbose(
                            "uiWebScreenSection.getUseQueryParameterMap().containsValue(paramName): " +
                            String.valueOf(uiWebScreenSection.getUseQueryParameterMap()
                                                             .containsValue(paramName)), module);

                    if (UIWebUtility.checkReservedParameterName(paramName)) {
                        //                (  action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE) || action.equals(uiWebScreenSection.ACTION_QUERY))
                        //              ) {
                        // This is a value being passed in from the prior screen in query mode.  Use it to search.
                        if (paramName.equals("nameToSearch")) {
                            // Alpha search using alphabet buttons.
                            HashMap alphaSearchValues = EventUtility.getAlphaSearchValues(delegator,
                                    uiWebScreenSection,
                                    request.getParameter("nameToSearch"));
                            searchEntityName = (String) alphaSearchValues.get(
                                    "searchEntityName");
                            searchAttribName = (String) alphaSearchValues.get(
                                    "searchAttribName");
                            searchAttribValue = (String) alphaSearchValues.get(
                                    "searchAttribValue");
                            entityOperator = null;
                        } else {
                            // Regular search attribute in query mode.
                            searchEntityName = UIWebUtility.getEntityFromParamName(paramName);

                            if ((searchEntityName == null) ||
                                    searchEntityName.equals("")) {
                                searchEntityName = primaryEntityName;
                            }

                            searchAttribName = UIWebUtility.getAttribFromParamName(paramName);

                            String[] searchAttribValueArray = request.getParameterValues(paramName);

                            Debug.logVerbose(
                                    "Number of values for query attribute " +
                                    paramName + ": " +
                                    String.valueOf(
                                        searchAttribValueArray.length), module);

                            searchAttribValue = getRequestParameterValue(paramName,
                                    searchAttribValueArray);

                            //  Determine the entity search operator to use.  If multiple, use IN
                            if ((null != searchAttribValue) &&
                                    (searchAttribValueArray.length > 1)) {
                                entityOperator = EntityOperator.IN;
                            } else {
                                entityOperator = null;
                            }

                            Debug.logVerbose("searchEntityName: " + searchEntityName, module);
                            Debug.logVerbose("searchAttribName: " + searchAttribName, module);
                            Debug.logVerbose("searchAttribValue: " + searchAttribValue, module);
                        }

                        if ((searchAttribValue != null) &&
                                !searchAttribValue.equals("")) {
                            try {
                                // Figure out the attribute ID for the UiAttribute this parameter corresponds to so we can
                                // save the query.
                                String attributeId = UIWebUtility.getAttributeId(delegator,
                                        searchAttribName, searchEntityName);

                                // Generate an entry in the WHERE clause for this attribute.  The entityOperator
                                // is returned in case appendEntityClause changes it.
                                entityOperator = EventUtility.appendEntityClause(searchEntityName,
                                        searchAttribName, searchAttribValue,
                                        entityOperator, queryInfo);

                                // Store the attribute ID and value in the query save map.
                                //                  querySaveMap.put(attributeId, searchAttribValue);
                                  uiQuery.addUiQueryValue(attributeId, entityOperator, searchAttribValue, "", "", delegator);
                            } catch (GenericEntityException e) {
                                //this parameter was not associated with a column in a table, so skip it
                                Debug.logVerbose("skipping parameter which is not an entity attribute: " + paramName, module);
                            }
                        }
                    }
                }
              }
                // add extra clauses from the hidden query parameters in case this is a detail screen
                addUseQueryParameterClauses(uiWebScreenSection, queryInfo,
                    relatedSearchClauses, primaryEntityName, request);
            }

            // Save the Query
            if (!queryName.equals("")) {
                // User entered a name for the query. Save it with the given name.
                // Change the party ID to the current user's party ID, and the section ID to the current section ID
                // in case either of these was -1 (wildcard).
                uiQuery.setSectionId(uiWebScreenSection.getSectionId());
                uiQuery.setPartyId(userInfo.getPartyId());
                uiQuery.setQueryName(queryName);
                queryId = uiQuery.save(delegator);

                //      queryId = UIQuery.saveUiQuery(delegator, userInfo.getPartyId(), sectionId, queryName, querySaveMap);
                Debug.logVerbose("queryId after saving query \"" + queryName + "\": " + queryId, module);

                if (TIMER) {
                    timer.timerString(1,
                        "[GenericWebEventProcessor.processRetrieve] Saved query");
                }
            }

            if ( listName.length() > 0)
            {
          // save the UiList info
                List uiListGVL = delegator.findByAnd("UiList", UtilMisc.toMap("listName", listName, "partyId", userInfo.getAccountId()), null);
                GenericValue uiListGV = null;
                if ( uiListGVL.size() > 0)
                {
                    uiListGV = (GenericValue) uiListGVL.get(0);
                    delegator.removeByAnd("UiListItem", UtilMisc.toMap("listId", uiListGV.getString("listId")));
                }
                else
                {
                    uiListGV = new GenericValue(delegator.getModelEntity("UiList"));
              String listId = GenericReplicator.getNextSeqId("UiList", delegator);
              uiListGV.set("listId", listId);
                }
                String listId = uiListGV.getString("listId");
          uiListGV.setDelegator(delegator);
         
          uiListGV.set("listName", listName);
          uiListGV.set("partyId", userInfo.getAccountId());
          uiListGV.set("queryId", queryId);
          uiListGV.set("sectionId", sectionId);
          uiListGV.set("listType", primaryEntityName);
         
          delegator.createOrStore(uiListGV);

                queryInfo.setSaveResultListId(listId);
            }

            // Save the query as the last query.  First make a new UIQuery using the same values as the original query.
            // Change the party ID to the current user's party ID, and the section ID to the current section ID
            // in case either of these was -1 (wildcard).
            //    UIQuery.saveUiQuery(delegator, userInfo.getPartyId(), sectionId, UIQuery.LAST_QUERY_NAME, querySaveMap);
            UIQuery uiQueryLast = new UIQuery("",
                    uiWebScreenSection.getSectionId(), userInfo.getPartyId(),
                    UIQuery.LAST_QUERY_NAME, uiQuery.getUiQueryValueList());
            String lastQueryId = uiQueryLast.save(delegator);
           
            // if the query was not saved, set the queryId to be returned to lastQueryId so that the query parameters
            // can be used when displaying the page (Primarily to set the params on the next and previous buttons for multi-page datasets
            if ( queryId == null || queryId.equals(""))
              queryId = lastQueryId;
             
            Debug.logVerbose("Saved query as last query. Id=" + lastQueryId + ", returning queryId=" + queryId, module);

            if (TIMER) {
                timer.timerString(1,
                    "[GenericWebEventProcessor.processRetrieve] End RETRIEVE_METHOD_CLAUSE");
            }

            break;

        case GenericEventProcessor.RETRIEVE_METHOD_LIKE:

            // Find the main entity(ies) using findByLike.
            // Process all the parameters coming into through the request object to get the values to search by.
            params = request.getParameterNames();

            while (params.hasMoreElements()) {
                String paramName = (String) params.nextElement();

                if (UIWebUtility.checkReservedParameterName(paramName)) {
                    // This is a value being passed in from the prior screen.  Use it to search.

                    /*                                                if (paramName.equals("nameToSearch")) {
                                                                            // Alpha search using alphabet buttons.
                                                                            HashMap alphaSearchValues = EventUtility.getAlphaSearchValues(
                                                                                    delegator,
                                                                                    uiScreenSectionGV,
                                                                                    request.getParameter("nameToSearch"));
                                                                            searchEntityName = (String)alphaSearchValues.get("searchEntityName");
                                                                            searchAttribName = (String)alphaSearchValues.get("searchAttribName");
                                                                            searchAttribValue = (String)alphaSearchValues.get("searchAttribValue");
                                                                    } else { */

                    // Regular search attribute.
                    searchEntityName = UIWebUtility.getEntityFromParamName(paramName);
                    searchAttribName = UIWebUtility.getAttribFromParamName(paramName);
                    searchAttribValue = request.getParameter(paramName).replace('*',
                            '%') + "%";

                    /*                                                } */
                    if ((searchEntityName != null) &&
                            !searchEntityName.equals("") &&
                            !searchEntityName.equals(primaryEntityName)) {
                        throw new GenericEntityException(
                            "Cannot do a LIKE search using a value from a related entity. Values must be from the primary entity.");
                    }

                    fields.put(searchAttribName, searchAttribValue);
                }
            }

            break;

        case GenericEventProcessor.RETRIEVE_METHOD_PK:

            if (TIMER) {
                timer.timerString(1,
                    "[GenericWebEventProcessor.processRetrieve] Start RETRIEVE_METHOD_PK");
            }

            // Get one main entity using the primary key.
            Iterator primaryPkFieldNameI = primaryPkFieldNames.iterator();

            while (primaryPkFieldNameI.hasNext()) {
                String primaryPkFieldName = (String) primaryPkFieldNameI.next();
                String primaryPkFieldValue = "";

                if (request.getParameter(primaryPkFieldName) != null) {
                    primaryPkFieldValue = request.getParameter(primaryPkFieldName);
                } else if (request.getParameter(primaryEntityName + "_" +
                            primaryPkFieldName) != null) {
                    primaryPkFieldValue = request.getParameter(primaryEntityName +
                            "_" + primaryPkFieldName);
                }

                fields.put(primaryPkFieldName, primaryPkFieldValue);
            }

            if (TIMER) {
                timer.timerString(1,
                    "[GenericWebEventProcessor.processRetrieve] End RETRIEVE_METHOD_PK");
            }

            break;

        default:
            throw new GenericEntityException("Invalid retrieve method.");

            //        break;
        }


        // Specify the sort order.
        orderBy = new DelimitedValueDecoder(uiWebScreenSection.getSortDef()).decode();

        Debug.logVerbose("orderBy: " + orderBy.toString(), module);

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processRetrieve] Specified retrieve info");
        }

        // Trigger the pre-retrieve event.
        status = this.preRetrieve(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix,
                primaryEntityName, retrieveMethod, fields, orderBy,
                queryInfo, relatedSearchClauses, queryId);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the retrieve event.
        status = this.retrieve(userInfo, uiWebScreenSection, request, response,
                delegator, eventProcessor, dataMatrix, primaryEntityName,
                retrieveMethod, fields, orderBy, queryInfo,
                relatedSearchClauses, queryId);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the post-retrieve event.
        status = this.postRetrieve(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix,
                primaryEntityName, retrieveMethod, fields, orderBy,
                queryInfo, relatedSearchClauses, queryId);

        Debug.logVerbose("queryId before returning from processRetrieve: " + queryId, module);

        queryIdBuffer.delete(0, queryIdBuffer.length());
        queryIdBuffer.append(queryId);

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processRetrieve] End");
        }

        return status;
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

    protected int processUpdate(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix,
        UICache uiCache) throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processUpdate] Start");
        }

        int status = STATUS_CONTINUE;

        // Pre fill the data matrix from the info entered on the screen.
        dataMatrix.fillFromHtml(request, uiWebScreenSection);

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processUpdate] Filled data matrix");
        }

        // Trigger the pre-update event.
        status = this.preUpdate(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, uiCache);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processUpdate] Preupdate finished");
        }

        // Trigger the update event.
        status = this.update(userInfo, uiWebScreenSection, request, response,
                delegator, eventProcessor, dataMatrix, uiCache);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processUpdate] Update finished");
        }

        // Trigger the post-update event.
        status = this.postUpdate(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, uiCache);

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processUpdate] Postupdate finished");
        }

        return status;
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

        GenericEventProcessor eventProcessor, UICache uiCache)
        throws GenericEntityException {

        int status = STATUS_CONTINUE;

        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processDelete] Start");
        }

        // Get the main entity using the primary key.
        HashMap fields = new HashMap();
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

    public int retrieve(UserInfo userInfo, String mainEntityName, int method,
        Map fields, List orderBy, QueryInfo queryInfo,
        List relatedSearchClauses, GenericDelegator delegator,
        DataMatrix dataMatrix) {

        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(2, "[GenericEventProcessor.retrieve] Start");
        }

        Debug.logVerbose(
                "Getting entity info to see if it has an accountId field = " +
                String.valueOf(method), module);

        SecurityLinkInfo securityInfo = getSecurityLinkInfo(userInfo, delegator);

        if (securityInfo == null) {
            Debug.logVerbose("No securityInfo defined", module);
        } else {
            Debug.logVerbose("securityInfo = " + securityInfo.toString(), module);
        }

        Debug.logVerbose("About to retrieve main entity. Method = " + String.valueOf(method), module);
        Debug.logVerbose("orderBy: " + orderBy.toString(), module);
        Debug.logVerbose("Retrieve Method: " + String.valueOf(method), module);

        // Retrieve the main entity or entities.
        List mainGVL = retrieveMainEntity(securityInfo, userInfo,
                mainEntityName, method, fields, orderBy, queryInfo,
                delegator);

        totalRows = mainGVL.size();

        Debug.logVerbose("GEP:  rowOffset = " + rowOffset + " fetchSize = " + fetchSize, module);

        Debug.logVerbose("Finished retrieving main entity.", module);

        Iterator mainGVI = mainGVL.iterator();
        int rowCount = 0;

        while (mainGVI.hasNext()) {
            rowCount++;

            GenericValue mainGV1 = (GenericValue) mainGVI.next();
            GenericValue mainGV = EntityHelper.getPrimaryGVFromDynamicGV(delegator, mainGV1, mainEntityName);

            if (TIMER) {
                timer.timerString(2,
                    "[GenericEventProcessor.retrieve] Start processing row " +
                    String.valueOf(rowCount));
            }

            // For each instance of the main entity, start a vector of entities, and then
            // retrieve the associated entities and add them also.
            Vector outGVV = new Vector();
            outGVV.add(mainGV);

            Debug.logVerbose("About to retrieve related entities.", module);

            // Loop through the relations to get related entities.
            int entityCount = 0;
            Iterator relatedSearchClauseI = relatedSearchClauses.iterator();

            while (relatedSearchClauseI.hasNext()) {
                UIScreenSectionEntity relatedSearchClause = (UIScreenSectionEntity) relatedSearchClauseI.next();
                entityCount++;

                String relationRelEntityName = relatedSearchClause.getEntityName();

                if (TIMER) {
                    timer.timerString(2,
                        "[GenericEventProcessor.retrieve] Start appending related entity " +
                        String.valueOf(entityCount) + " (" +
                        relationRelEntityName + ") for row " +
                        String.valueOf(rowCount));
                }
//TODO copy mainGV to primaryEntityGV if this is a dynamic view
                GenericValue relatedGV = retrieveOneRelatedGV(mainGV,
                        relatedSearchClause, outGVV, userInfo, delegator);

                if (relatedGV == null) {
                    // Related generic value was not found.  Create a new one.
                    relatedGV = new GenericValue(delegator.getModelEntity(
                                relationRelEntityName));
                    relatedGV.setDelegator(delegator);
                }

                // Add the new related generic value to the entity vector with the main entity.
                Debug.logVerbose("About to append related entity \"" +
                        relationRelEntityName + "\" onto generic value map.", module);

                outGVV.add(relatedGV);

                if (TIMER) {
                    timer.timerString(2,
                        "[GenericEventProcessor.retrieve] End appending related entity " +
                        String.valueOf(entityCount) + " for row " +
                        String.valueOf(rowCount));
                }
            }

            Debug.logVerbose("Generic value vector: " + outGVV.toString(), module);

            // Append the vector of generic entities onto the List.
            Debug.logVerbose("About to append generic value vector onto generic value vector List.", module);

            dataMatrix.getCurrentBuffer().addContentsRow(outGVV);

            if (TIMER) {
                timer.timerString(2,
                    "[GenericEventProcessor.retrieve] Added row to current buffer.");
            }

            Debug.logVerbose("Finished appending row " + String.valueOf(rowCount), module);
        }

        //    if (DEBUG) Debug.logVerbose("Data matrix current buffer: " + dataMatrix.getCurrentBuffer().getContents().toString());
        Debug.logVerbose("Finished retrieve method.", module);

        if (TIMER) {
            timer.timerString(2, "[GenericEventProcessor.retrieve] End");
        }

        return STATUS_CONTINUE;
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

     * @return
     */
    protected List retrieveMainEntity(SecurityLinkInfo securityInfo,
        UserInfo userInfo, String mainEntityName, int method, Map fields,
        List orderBy, QueryInfo queryInfo, GenericDelegator delegator) {
        UtilTimer timer = new UtilTimer();

        GenericValue mainGV = null;
        List mainGVL = null;
        ArrayList queryList = new ArrayList();
        EntityListIterator eli = null;

        switch (method) {
        case RETRIEVE_METHOD_ALL:

      // do nothing, leave condition = null
            break;

        case RETRIEVE_METHOD_AND:

                if (fields != null) {
                    Iterator entries = fields.entrySet().iterator();
                    while (entries.hasNext()) {
          Map.Entry anEntry = (Map.Entry) entries.next();
          queryInfo.addCondition( mainEntityName, (String) anEntry.getKey(), EntityOperator.EQUALS, anEntry.getValue());
                    }
                }
            break;

        case RETRIEVE_METHOD_CLAUSE:

      // nothing needed, as queryInfo is already setup
            break;

        case RETRIEVE_METHOD_LIKE:

      if (fields != null) {
        Iterator entries = fields.entrySet().iterator();
        while ( entries.hasNext() )  {
          Map.Entry anEntry = (Map.Entry) entries.next();
          queryInfo.addCondition( mainEntityName, (String) anEntry.getKey(), EntityOperator.EQUALS,  ((String) anEntry.getValue()).replace('*', '%') + "%");
            }
            }

            break;

        case RETRIEVE_METHOD_PK:

            // Get one main entity using a primary key built from the field map passed in.

            if (securityInfo == null) {
                try {
                    mainGV = delegator.findByPrimaryKey(mainEntityName, fields);
                } catch (GenericEntityException e) {
                    Debug.logError("An error occurred in the " +
                        "GenericDelegator.findByPrimaryKey method: " +
                        e.getLocalizedMessage(), module);
                }

                if (mainGV != null) {
                    // The entity was found. Store it in a List
                    mainGVL = new LinkedList();
                    mainGVL.add(mainGV);
                    return mainGVL;
                }
            } else {
                if (fields != null) {
                    Iterator entries = fields.entrySet().iterator();
                    while (entries.hasNext()) {
            Map.Entry anEntry = (Map.Entry) entries.next();
            queryInfo.addCondition( mainEntityName, (String) anEntry.getKey(), EntityOperator.EQUALS, anEntry.getValue());
                    }
                }
            }

            break;
            }

    Debug.logVerbose("calling  (findIteratorByCondition)", module);
    Debug.logVerbose("mainEntityName: " + mainEntityName, module);

            if (TIMER) {
                timer.timerString(3,
        "[GenericEventProcessor.retrieveMainEntity] Start findIteratorByCondition)");
            }

            if (securityInfo == null) {
                try {
        queryInfo.setOrderBy(orderBy);
        eli = queryInfo.getQueryIterator();
                } catch (GenericEntityException e) {
                    Debug.logError("An error occurred in the " +
          "GenericDelegator.findByCondition method: " +
                        e.getLocalizedMessage(), module);
                }
            } else {
      try {

        eli = SecurityWrapper.findListIteratorByCondition(mainEntityName,
            queryInfo, orderBy, userInfo, securityInfo,  delegator);
      } catch (GenericEntityException e) {
        Debug.logError("An error occurred in the " +
          "SecurityWrapper.findByCondition method: " +
          e.getLocalizedMessage(), module);
                    }
                }

    if ( eli != null )
    {
                try {
        mainGVL = eli.getPartialList( getRowOffset() + 1, getFetchSize());
       
        hasMoreRows = false;
       
        // check next value since we close the cursor anyway. 
        if ( (mainGVL.size() == getFetchSize()) && (eli.next() != null ))
          hasMoreRows = true;
         
   
        // check to see if we need to save the output to a named list.
        if ( ( queryInfo.getSaveResultListId() != null ) && ( queryInfo.getSaveResultListId().length() > 0) )
            {
              eli.beforeFirst();
              GenericValue gv = null;
              ModelEntity me = delegator.getModelEntity("UiListItem");
              ModelEntity primaryME = delegator.getModelEntity(mainEntityName);
             
              if ( primaryME.getPksSize() != 1)
                    throw new IllegalArgumentException("Multi-Field primary Keys not allows in Save Result List");

              String keyFieldName = primaryME.getPk(0).getName();
             
              while ( (gv = (GenericValue) eli.next()) != null )
              {
                  GenericValue itemGV = new GenericValue(me);
                  itemGV.setDelegator(delegator);
                  itemGV.set("listItemId", GenericReplicator.getNextSeqId("UiListItem", delegator));
                  itemGV.set("listId", queryInfo.getSaveResultListId());
                  itemGV.set("entityName", mainEntityName);
                  String entityId = gv.getString(keyFieldName);
                  itemGV.set("entityId", entityId);
                  itemGV.set("status", "new");
                 
                  delegator.create(itemGV);
              }
            }
       
        eli.close();

                } catch (GenericEntityException e) {
        Debug.logError("An error occurred in the  getPartialList method: " + e.getLocalizedMessage(), module);
                }
            }
            if (TIMER) {
                timer.timerString(3,
        "[GenericEventProcessor.retrieveMainEntity] End findIteratorByCondition");
            }


        return mainGVL;
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

    // Put values from the screen into the value matrix
    //-------------------------------------------------------------------------
    public int fillFromHtml(HttpServletRequest request,
        UIScreenSection uiScreenSection) throws GenericEntityException {

        UtilTimer utilTimer = new UtilTimer();

        if (TIMER) {
            utilTimer.timerString(3, "[DataMatrix.fillFromHTML] Start");
        }

        // Get the row count.
        if (request.getParameter("rowCount") == null) {
            throw new GenericEntityException(
                "rowCount parameter not found in request object.");
        }

        if (request.getParameter("rowCount").equals("")) {
            throw new GenericEntityException(
                "rowCount parameter is empty in request object.");
        }

        try {
            setRowCount(Integer.valueOf(request.getParameter("rowCount"))
                               .intValue());
        } catch (NumberFormatException e) {
            throw new GenericEntityException(
                "rowCount parameter in request object does not contain a number.");
        }

        for (int row = 0; row < getRowCount(); row++) {
            // Create an array list of empty generic values to hold the values from the screen for one row.
            addRowFromHTML(row, request, uiScreenSection);
        }

        if (TIMER) {
            utilTimer.timerString(3, "[DataMatrix.fillFromHTML] End");
        }

        return getRowCount();
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

     *
     * @throws GenericEntityException
     */
    public void addRowFromHTML(int row, HttpServletRequest request,
        UIScreenSection uiScreenSection) throws GenericEntityException {
        UtilTimer utilTimer = new UtilTimer();

        if (TIMER) {
            utilTimer.timerString(4, "[DataMatrix.addRowFromHTML] Start");
        }

        // Create an empty row to be updated and stored in the current and original buffers.
        Vector currentRow = getCurrentBuffer().createEmptyRow();

        //    Vector originalRow = (Vector)currentRow.clone(); -- This didn't really create a new object. It caused
        //      all operations on originalRow to be done on the currentRow also.
        Vector originalRow = getOriginalBuffer().createEmptyRow();

        // Loop through the entities and attributes for the current screen section, and get the value
        // from the request object for each one, and store it in the contents.
        for (int entityNbr = 0; entityNbr < getEntityParamVector().size();
                entityNbr++) {
            String entityName = getEntityName(entityNbr);

            if (TIMER) {
                utilTimer.timerString(4,
                    "[DataMatrix.addRowFromHTML] Start processing entity " +
                    String.valueOf(entityNbr) + " (" + entityName + ")");
            }

            // Get references to the orginal and current generic values for this entity.
            GenericValue currentGV = (GenericValue) (currentRow.get(entityNbr));
            GenericValue originalGV = (GenericValue) (originalRow.get(entityNbr));

            // Process each attribute for this entity.
            for (int attributeNbr = 0;
                    attributeNbr < getAttributeVector(entityNbr).size();
                    attributeNbr++) {
                String attributeName = getAttributeName(entityNbr, attributeNbr);
                String rowDotEntityDotAttribName = String.valueOf(row) + "." +
                    entityName + "." + attributeName;

                if (TIMER) {
                    utilTimer.timerString(4,
                        "[DataMatrix.addRowFromHTML] Start processing attribute " +
                        rowDotEntityDotAttribName);
                }

                String originalParamName = UIWebUtility.getParamName(UIWebUtility.HTML_NAME_PREFIX_ORIGINAL,
                        uiScreenSection.getSectionName(), entityName,
                        attributeName, row);
                String currentParamName = UIWebUtility.getParamName(UIWebUtility.HTML_NAME_PREFIX_CURRENT,
                        uiScreenSection.getSectionName(), entityName,
                        attributeName, row);

                if (request.getParameter(originalParamName) != null) {
                    // This attribute exists in "original" hidden fields in the HTML data.  Continue to process it.
                    boolean currentFound = false;

                    if (request.getParameter(currentParamName) == null) {
                        // Attribute does not appear in the "current" parameters. It could be excluded, or it could
                        // be a check box, which would not appear if it is not checked.  Continue, but don't set flag.
                    } else {
                        // Attribute appears in the "current" parameters.
                        currentFound = true;
                    }

                    // We will need to determine whether this field is a check box.  Get the field info.
                    if (TIMER) {
                        utilTimer.timerString(4,
                            "[DataMatrix.addRowFromHTML] Start getting UIFieldInfo for " +
                            rowDotEntityDotAttribName);
                    }

                    UIFieldInfo uiFieldInfo = uiScreenSection.getUiField(entityName,
                            attributeName);

                    if (TIMER) {
                        utilTimer.timerString(4,
                            "[DataMatrix.addRowFromHTML] Finished getting UIFieldInfo for " +
                            rowDotEntityDotAttribName);
                    }

                    if ((uiFieldInfo != null) &&
                            (uiFieldInfo.getDisplayOrder() > 0)) {
                        // The field info was found. Get the display object.
                        if (TIMER) {
                            utilTimer.timerString(4,
                                "[DataMatrix.addRowFromHTML] Start getting UIDisplayObject for " +
                                rowDotEntityDotAttribName);
                        }

                        UIDisplayObject uiDisplayObject = uiFieldInfo.getUiDisplayObject();

                        if (TIMER) {
                            utilTimer.timerString(4,
                                "[DataMatrix.addRowFromHTML] Finished getting UIDisplayObject for " +
                                rowDotEntityDotAttribName);
                        }

                        // Find out if this field is a check box. If so, need to use special handling.
                        boolean isCheckbox = false;

                        if (uiDisplayObject.getDisplayTypeId().equals(uiDisplayObject.DISPLAY_TYPE_CHECKBOX)) {
                            isCheckbox = true;
                        }

                        // Make sure the current value was found in the HTML, or that this is a checkbox field,
                        // which would not appear in the HTML if its box is not checked.
                        if (currentFound || isCheckbox) {
                            if (isCheckbox) {
                                // Need to load the display object attributes when there is a check box attribute.
                                if (TIMER) {
                                    utilTimer.timerString(4,
                                        "[DataMatrix.addRowFromHTML] Start getting UIDisplayObject attributes for " +
                                        rowDotEntityDotAttribName);
                                }

                                uiDisplayObject.loadAttributes();

                                if (TIMER) {
                                    utilTimer.timerString(4,
                                        "[DataMatrix.addRowFromHTML] Finished getting UIDisplayObject attributes for " +
                                        rowDotEntityDotAttribName);
                                }
                            }

                            // Get the original value and store it in the "original" buffer.
                            String originalAttributeValue = request.getParameter(originalParamName);

                            if (TIMER) {
                                utilTimer.timerString(4,
                                    "[DataMatrix.addRowFromHTML] Start getDataType for " +
                                    rowDotEntityDotAttribName);
                            }

                            String fieldType = EventUtility.getDataType(originalGV,
                                    attributeName, getDelegator());

                            if (TIMER) {
                                utilTimer.timerString(4,
                                    "[DataMatrix.addRowFromHTML] End getDataType for " +
                                    rowDotEntityDotAttribName);
                            }

                            if (TIMER) {
                                utilTimer.timerString(4,
                                    "[DataMatrix.addRowFromHTML] Start storeValue original for " +
                                    rowDotEntityDotAttribName);
                            }

                            EventUtility.storeValue(originalGV, attributeName,
                                originalAttributeValue, getDelegator(),
                                fieldType);

                            if (TIMER) {
                                utilTimer.timerString(4,
                                    "[DataMatrix.addRowFromHTML] End storeValue original for " +
                                    rowDotEntityDotAttribName);
                            }

                            if (!currentFound) {
                                // Attribute does not appear in the "current" HTML parameters.  It must be a checkbox, or this code
                                // would not be executing. Get the unchecked value, and store it in the buffer.
                                EventUtility.storeValue(currentGV,
                                    attributeName,
                                    uiDisplayObject.getAttribUncheckedValue(),
                                    getDelegator(), fieldType);

                            } else {
                                // Attribute does appear in the "current" HTML parameters.
                                if (isCheckbox) {
                                    // This is a checked checkbox.  Get the checked value, and store it in the current buffer.
                                    EventUtility.storeValue(currentGV,
                                        attributeName,
                                        uiDisplayObject.getAttribCheckedValue(),
                                        getDelegator(), fieldType);

                                } else {
                                    // Non-checkbox field. Just store the value.
                                    String currentAttributeValue = request.getParameter(currentParamName);

                                    if (TIMER) {
                                        utilTimer.timerString(4,
                                            "[DataMatrix.addRowFromHTML] Calling storeValue for " +
                                            rowDotEntityDotAttribName);
                                    }

                                    EventUtility.storeValue(currentGV,
                                        attributeName, currentAttributeValue,
                                        getDelegator(), fieldType);

                                    if (TIMER) {
                                        utilTimer.timerString(4,
                                            "[DataMatrix.addRowFromHTML] Finished storeValue for " +
                                            rowDotEntityDotAttribName);
                                    }

                                }
                            }
                        }
                    }
                }
            }
        }

        // Store the new row in each buffer.
        getCurrentBuffer().addContentsRow(currentRow);
        getOriginalBuffer().addContentsRow(originalRow);

        // Check for delete flag for the new row.
        if (request.getParameter("deleteFlag" + String.valueOf(row)) != null) {
            // The user specified for this row to be deleted.  Set the delete flag to true for this row.
            addDeleteFlag(true);
        } else {
            // Either there was no delete check box, or it was not checked.  Set delete flag to false for this row.
            addDeleteFlag(false);
        }

        if (TIMER) {
            utilTimer.timerString(4, "[DataMatrix.addRowFromHTML] End");
        }

        return;
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

    }

  public void addRowFromArray( int row, Vector dataValues, Vector importFields, UIScreenSection uiScreenSection)
    throws GenericEntityException
  {
    UtilTimer utilTimer = new UtilTimer();

    if (TIMER) {
      utilTimer.timerString(4, "[DataMatrix.addRowFromArray] Start");
    }

    // Create an empty row to be updated and stored in the current and original buffers.
    Vector currentRow = getCurrentBuffer().getContentsRow(0);
    Vector originalRow = getOriginalBuffer().getContentsRow(0);
    if ( currentRow == null)
    {
      currentRow = getCurrentBuffer().createEmptyRow();
    }
    if ( originalRow == null )
    {
      originalRow = getOriginalBuffer().createEmptyRow();
    }
 
    for (int fieldNum = 0; fieldNum < dataValues.size(); fieldNum++) {
      String paramName = (String) importFields.get(fieldNum);

      if ((paramName == null) || (paramName.length() == 0)) {
        continue;
      }

      String paramEntityName = UIWebUtility.getEntityFromParamName(paramName);
      String paramAttributeName = UIWebUtility.getAttribFromParamName(paramName);

      String paramDataValue = (String) dataValues.get(fieldNum);

      // Loop through the entities and attributes for the current screen section, and get the value
      // from the request object for each one, and store it in the contents.
      for (int entityNbr = 0; entityNbr < getEntityParamVector().size();
          entityNbr++) {
        String entityName = getEntityName(entityNbr);

        if (TIMER) {
          utilTimer.timerString(4,
            "[DataMatrix.addRowFromArray] Start processing entity " +
            String.valueOf(entityNbr) + " (" + entityName + ")");
        }

        if (entityName.equals(paramEntityName)) {
          // Get references to the orginal and current generic values for this entity.
          GenericValue currentGV = (GenericValue) (currentRow.get(entityNbr));
          String fieldType = EventUtility.getDataType(currentGV,
              paramAttributeName, getDelegator());
          EventUtility.storeValue(currentGV, paramAttributeName,
            paramDataValue, getDelegator(), fieldType);
        }
      }
    }

    // Store the new row in each buffer.
    getCurrentBuffer().setContentsRow(0,currentRow);
    getOriginalBuffer().setContentsRow(0,originalRow);

    if (TIMER) {
      utilTimer.timerString(4, "[DataMatrix.addRowFromArray] End");
    }

    return;
  }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

     *
     * @return
     */
    public static String getDataType(GenericValue gV, String fieldName,
        GenericDelegator delegator) {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString("[EventUtility.getDataType] Start");
        }

        ModelEntity modelEntity = delegator.getModelEntity(gV.getEntityName());
        ModelField curField = modelEntity.getField(fieldName);

        ModelFieldTypeReader modelFieldTypeReader = new ModelFieldTypeReader(
                "mysql");
        ModelFieldType mft = modelFieldTypeReader.getModelFieldType(curField.getType());
        String fieldType = mft.getJavaType();

        if (TIMER) {
            timer.timerString("[EventUtility.getDataType] End");
        }

        return fieldType;
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

     * @param delegator
     * @param fieldType
     */
    public static void storeValue(GenericValue gV, String fieldName,
        String value, GenericDelegator delegator, String fieldType) {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString("[EventUtility.storeValue] Start");
        }

        if (fieldType.equals("java.lang.String") || fieldType.equals("String")) {
            gV.set(fieldName, value);
        } else if (fieldType.equals("java.sql.Timestamp") || fieldType.equals("Timestamp")) {
            if ((value == null) || (value.trim().length() == 0)) {
                gV.set(fieldName, null);
            } else {
                String[] parseMask = {
                    "y-M-d", "M/d/y", "M-d-y", "M d, y", "H:m:s.S",
                    "y-M-d H:m:s.S", "M/d/y H:m:s.S", "M-d-y H:m:s.S",
                    "M d, y H:m:s.S", "h:m:s a", "y-M-d h:m:s a",
                    "M/d/y h:m:s a", "M-d-y h:m:s a", "M d, y h:m:s a", "H:m:s",
                    "y-M-d H:m:s", "M/d/y H:m:s", "M-d-y H:m:s", "M d, y H:m:s",
                    "h:m a", "y-M-d h:m a", "M/d/y h:m a", "M-d-y h:m a",
                    "M d, y h:m a", "H:m", "y-M-d H:m", "M/d/y H:m", "M-d-y H:m",
                    "M d, y H:m"
                };
                java.util.Date parsedDate = null;
                boolean isParsed = false;
                String currentMask = "";

                for (int maskNbr = 0; maskNbr < parseMask.length; maskNbr++) {
                    currentMask = parseMask[maskNbr];

                    SimpleDateFormat dateFormat = new SimpleDateFormat(currentMask);

                    try {
                        parsedDate = dateFormat.parse(value);
                        isParsed = true;

                        break;
                    } catch (ParseException e) {
                        // Try the next mask.
                    }
                }

                if (isParsed) {

                    Timestamp parsedTimestamp = new Timestamp(parsedDate.getTime());


                    gV.set(fieldName, parsedTimestamp);
                } else {
                    Debug.logWarning(
                        "[EventUtility.storeValue()]: Could not parse a Date or Datetime from " +
                        value, module);
                }
            }
        } else if (fieldType.equals("java.sql.Time") || fieldType.equals("Time")) {
            if (( value == null ) || (value.trim().length() == 0)) {
                gV.set(fieldName, null);
            } else {
                String[] parseMask = {
                    "H:m:s.S", "H:m:s", "H:m", "h:m a", "h:m:s a"
                };
                java.util.Date parsedDate = null;
                boolean isParsed = false;
                String currentMask = "";

                for (int maskNbr = 0; maskNbr < parseMask.length; maskNbr++) {
                    currentMask = parseMask[maskNbr];

                    SimpleDateFormat dateFormat = new SimpleDateFormat(currentMask);

                    try {
                        parsedDate = dateFormat.parse(value);
                        isParsed = true;

                        break;
                    } catch (ParseException e) {
                        // Try the next mask.
                    }
                }

                if (isParsed) {

                    //          gV.set(fieldName, new java.sql.Time(parsedDate.getTime()));
                    gV.set(fieldName,
                        new java.sql.Timestamp(parsedDate.getTime()));
                } else {
                    Debug.logWarning(
                        "[EventUtility.storeValue()]: Could not parse a time from " +
                        value, module);
                }
            }
        } else if (fieldType.equals("java.util.Date") || fieldType.equals("java.sql.Date") || fieldType.equals("Date")) {
            if ((value == null) || (value.trim().length() == 0)) {
                gV.set(fieldName, null);
            } else {
                String[] parseMask = { "y-M-d", "M/d/y", "M-d-y", "M d, y" };
                java.util.Date parsedDate = null;
                boolean isParsed = false;
                String currentMask = "";

                for (int maskNbr = 0; maskNbr < parseMask.length; maskNbr++) {
                    currentMask = parseMask[maskNbr];

                    SimpleDateFormat dateFormat = new SimpleDateFormat(currentMask);

                    try {
                        parsedDate = dateFormat.parse(value);
                        isParsed = true;

                        break;
                    } catch (ParseException e) {
                        // Try the next mask.
                    }
                }

                if (isParsed) {

                    gV.set(fieldName, new java.sql.Date(parsedDate.getTime()));
                } else {
                    Debug.logWarning(
                        "[EventUtility.storeValue()]: Could not parse a date from " +
                        value, module);
                }
            }
        } else if (fieldType.equals("java.lang.Integer") ||
                fieldType.equals("Integer") ||
                fieldType.equals("java.lang.Long") || fieldType.equals("Long") ||
                fieldType.equals("java.lang.Float") ||
                fieldType.equals("Float") ||
                fieldType.equals("java.lang.Double") ||
                fieldType.equals("Double")) {
            if ((value == null) || (value.trim().length() == 0)) {
                value = "0";
            }

            //      gV.set(fieldName, String.valueOf(parseNumber(value)));
            gV.set(fieldName, parseNumber(value));
        }

        if (TIMER) {
            timer.timerString("[EventUtility.storeValue] End.");
        }

        return;
    }
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.