Package org.ofbiz.entity

Examples of org.ofbiz.entity.GenericEntityException


        if (TIMER) {
            timer.timerString("[GenericWebEventProcessor.processEvents] Start");
        }

        if ((screenName == null) || screenName.equals("")) {
            throw new GenericEntityException("Screen name is required.");
        }

        if ((sectionName == null) || sectionName.equals("")) {
            throw new GenericEntityException("Screen section name is required.");
        }

        UIWebScreenSection uiWebScreenSection = getUiWebScreenSection(userInfo,
                screenName, sectionName, delegator, uiCache);

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Got web screen section");
        }

        // Get the additional parameters that are needed for this screen section.  These will be used
        // for filtering a related entity on a tab page, or in completing keys in a SELECT screen.
        evalUseQueryParameterList(uiWebScreenSection, request);

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Evaluated \"use\" query parameter list");
        }

        Debug.logVerbose("Returned from evalUseQueryParameterList.", module);

        // Find out what needs to be done depending on the action passed in the request object.
        String action = "";

        if (request.getParameter("action") != null) {
            // Actions for Free Form sections:
            //   ACTION_SHOW          - Display the entity in non-edit mode
            //   ACTION_SHOW_UPDATE   - Display the entity so the user can edit it
            //   ACTION_SHOW_INSERT   - Show the form with empty cells so the user can enter a new entity
            //   ACTION_SHOW_QUERY    - Show the form in Query mode, and set next action to QUERY.
            //   ACTION_SHOW_QUERY_REPORT - Show the form in Query mode, and set next action to SHOW_REPORT.
            //   ACTION_SHOW_REPORT   - Show the form in Report mode, and set next action to SHOW_REPORT.
            //   ACTION_SHOW_SELECT   - Show the form in select mode, and set next action to UPDATE_SELECT.
            //   ACTION_SHOW_COPY     - Show the form with a copy of the specified entity from which a new
            //                entity will be created.  (Same as showCreate with values prefilled.)
            //   ACTION_UPDATE        - Save the entity into the database using the form values.
            //   ACTION_INSERT        - Insert a new entity into into the database using the form values
            //   ACTION_DELETE        - Delete the entity from the database.
            //   ACTION_BUTTON        - A button in the header was pushed to get here.  Look for a parameter with
            //                each possible button name until we know which button was pushed.
            // Actions for Tabular sections:
            //   ACTION_QUERY         - Search for values based on attibute values using a custom WHERE clause.
            //   ACTION_QUERY_UPDATE  - Search for values based on attibute values using a custom WHERE clause,
            //                and go into update mode.
            //   ACTION_QUERY_ALL     - Search for all values.
            //   ACTION_UPDATE        - Save the entit(ies) into the database using the form values.
            //   ACTION_UPDATE_SELECT - Add and remove entities in a many-to-many relationship table.
            action = request.getParameter("action");
        } else {
            // No action specified.
            action = uiWebScreenSection.ACTION_NONE;
        }

        if (!action.equals(uiWebScreenSection.ACTION_BUTTON) &&
                !action.equals(uiWebScreenSection.ACTION_COPY) &&
                !action.equals(uiWebScreenSection.ACTION_DELETE) &&
                !action.equals(uiWebScreenSection.ACTION_INSERT) &&
                !action.equals(uiWebScreenSection.ACTION_NONE) &&
                !action.equals(uiWebScreenSection.ACTION_QUERY) &&
                !action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE) &&
                !action.equals(uiWebScreenSection.ACTION_QUERY_ALL) &&
                !action.equals(uiWebScreenSection.ACTION_UPDATE) &&
                !action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_COPY) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_INSERT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_QUERY) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_QUERY_REPORT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_REPORT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_SELECT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_UPDATE)) {
                Debug.logWarning("\"" + action + "\" is not a valid action.", module);

            throw new GenericEntityException(
                "[GenericWebEventProcessor.processEvents] \"" + action +
                "\" is not a valid action.");
        }

        Debug.logVerbose("Starting action is \"" + action + "\".", module);
        Debug.logVerbose(
                "About to convert button action to regular action if necessary.", module);

        action = UIWebUtility.convertButtonAction(action, request);

        Debug.logVerbose("Final action is \"" + action + "\".", module);

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Determined action");
        }

        String queryId = "";

        if (request.getParameter("queryId") != null) {
            queryId = request.getParameter("queryId");
        } else if (request.getParameter("savedQueryName") != null) {
            // The calling link specified to use a named query if it exists.
            String savedQueryName = request.getParameter("savedQueryName");
            GenericValue queryGV = UIQuery.getUiQueryByName(delegator,
                    userInfo.getPartyId(), sectionName, screenName,
                    savedQueryName);

            if (queryGV == null) {
                // Named query was not found.  Don't use a query.
                queryId = "1"// Query = All
                Debug.logWarning("Named query not found for query name " +
                    savedQueryName + ", partyId " + userInfo.getPartyId() +
                    ", sectionName " + sectionName + ", and screenName " +
                    screenName + ".  queryId is now \"" + queryId + "\"", module);
            } else {
                // Named query was found.
                queryId = (queryGV.getString("queryId") == null) ? "NONE"
                                                                 : queryGV.getString(
                        "queryId");

                Debug.logVerbose("Named query was found. queryId is \"" +
                        queryId + "\"", module);
            }
        }

        DataMatrix dataMatrix = new DataMatrix(delegator,
                uiWebScreenSection.getEntityParamVector());

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Constructed data matrix");
        }

        // ---------------------------------------------------------------------------------
        // Process all events before generating the HTML to display the data on the screen.
        // ---------------------------------------------------------------------------------
        // --------
        // INSERT
        // --------
        if (action.equals(uiWebScreenSection.ACTION_INSERT)) {
            // Insert the new record(s) into the database.
            int status = this.processInsert(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix,
                    uiCache);

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished insert");
            }

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while inserting the new information into the data base.";

            case STATUS_CANCEL:
                return "Insert canceled.";
            }

            // --------
            // UPDATE
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_UPDATE)) {
            // Update the existing record(s) in the database.
            int status = this.processUpdate(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix,
                    uiCache);

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished update");
            }

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while updating the information in the data base.";

            case STATUS_CANCEL:
                return "Update canceled.";
            }

            // --------
            // UPDATE_SELECT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT)) {
            // Add and/or remove records in a many-to-many table.
            int status = this.processUpdateSelect(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor);

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEventsSelect] Finished update");
            }

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while updating the information in the data base.";

            case STATUS_CANCEL:
                return "Update canceled.";
            }

            // --------
            // DELETE
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_DELETE)) {
            // Delete the current record.
            int status = this.processDelete(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, uiCache);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while deleting the information.";

            case STATUS_CANCEL:
                return "Delete canceled.";
            }

            // Create an empty entity so the user can insert a new one.
            status = this.processCreate(userInfo, uiWebScreenSection, request,
                    response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while creating an empty data form.";

            case STATUS_CANCEL:
                return "Create canceled.";
            }

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished delete");
            }

            // --------
            // SHOW_INSERT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_SHOW_INSERT)) {
            // Create an empty entity so the user can insert a new one.
            int status = this.processCreate(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while creating an empty data form.";

            case STATUS_CANCEL:
                return "Create canceled.";
            }

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished show_insert");
            }

            // --------
            // SHOW_QUERY or SHOW_QUERY_REPORT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_SHOW_QUERY) ||
                action.equals(uiWebScreenSection.ACTION_SHOW_QUERY_REPORT)) {
            // Create an empty entity to be displayed for query mode.
            int status = this.processShowQuery(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while creating an empty query form.";

            case STATUS_CANCEL:
                return "Create canceled.";
            }

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished show_query");
            }

            // --------
            // SHOW_REPORT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_SHOW_REPORT)) {
            // Load in the entered query criteria, and re-display them in query mode.
            int status = this.processShowReport(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while displaying the report.";

            case STATUS_CANCEL:
                return "Report canceled.";
            }

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished show_report");
            }

            // --------
            // NO ACTION
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_NONE)) {
            // No action was specified.  Allow a blank screen section to be displayed.
            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished no_action");
            }
        }

        // --------
        // RETRIEVE
        // --------
        if (action.equals(uiWebScreenSection.ACTION_SHOW) ||
        action.equals(uiWebScreenSection.ACTION_SHOW_UPDATE) ||
                action.equals(uiWebScreenSection.ACTION_SHOW_COPY) ||
                action.equals(uiWebScreenSection.ACTION_QUERY) ||
                action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE) ||
                action.equals(uiWebScreenSection.ACTION_QUERY_ALL) ||
                action.equals(uiWebScreenSection.ACTION_SHOW_SELECT) ||
                action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT)) {
            // Need to retrieve data from the data base.
            // Note:  ACTION_SHOW_SELECT and ACTION_UPDATE_SELECT are the only two actions that have something happen
            // in the previous IF statement, and then get retrieved.  In all other actions, the data matrix is either
            // filled from the HTML, or does not need to be filled.
            // Determine the retreive method.
            int retrieveMethod = eventProcessor.RETRIEVE_METHOD_ALL;

            switch (uiWebScreenSection.getLayoutTypeId()) {
            case UIWebScreenSection.LAYOUT_TYPE_FREEFORM:

                // Free form section should be retrieved using the primary key.
                retrieveMethod = eventProcessor.RETRIEVE_METHOD_PK;

                break;

            case UIWebScreenSection.LAYOUT_TYPE_TABULAR:

                // Tabular section can be retrieved multiple ways depending on the action
                // requested by the button or link that triggered it.
                if (action.equals(uiWebScreenSection.ACTION_QUERY) ||
                        action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE)) {
                    retrieveMethod = eventProcessor.RETRIEVE_METHOD_CLAUSE;
                } else if (action.equals(uiWebScreenSection.ACTION_QUERY_ALL)) {
                    retrieveMethod = eventProcessor.RETRIEVE_METHOD_ALL;
                } else {
                    throw new GenericEntityException("Action \"" + action +
                        "\" is not valid for tabular layout type.");
                }

                break;

            case UIWebScreenSection.LAYOUT_TYPE_SELECT:

                // A select screen section is always retrieved as a query because it is always subordinate
                // to some other entity.
                retrieveMethod = eventProcessor.RETRIEVE_METHOD_CLAUSE;

                break;

            case UIWebScreenSection.LAYOUT_TYPE_CROSSTAB:
                throw new GenericEntityException(
                    "Crosstab layout type not implemented yet.");

            default:
                throw new GenericEntityException("Invalid layout type.");
            }

            // handle paging of result sets.
            int startRow = 0;
            int rowsPerPage = uiWebScreenSection.getRowsPerPage();
View Full Code Here


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


View Full Code Here

            } else if (request.getParameter(primaryEntityName + "_" +
                        primaryPkFieldName) != null) {
                primaryPkFieldValue = request.getParameter(primaryEntityName +
                        "_" + primaryPkFieldName);
            } else {
                throw new GenericEntityException("Parameter \"" +
                    primaryPkFieldName + "\" is required for delete.");
            }

            fields.put(primaryPkFieldName, primaryPkFieldValue);
        }
View Full Code Here

        EntityOperator.AND);
       
        List queryGVL = EntityHelper.findByCondition( delegator, dve, condition, null );

        if (queryGVL.size() == 0) {
            throw new GenericEntityException(
                "No UI Attribute found for entity name \"" + searchEntityName +
                "\" and attribute name \"" + searchAttribName + "\"");
        }

        GenericValue uiAttributeGV = (GenericValue) queryGVL.iterator().next();
View Full Code Here

            try {
                String dummy = String.valueOf(screenEntityDetails.get(
                            screenAttributeName));
            } catch (IllegalArgumentException e) {
                throw new GenericEntityException(
                    "[UIUtility.decodeFieldValue]: Problem with attribute value definition \"" +
                    attributeValueSource + "\": " + e.getLocalizedMessage());

                //        Debug.logWarning("[UIUtility.decodeFieldValue]: Problem with entity find definition \"" + entityFindDef + "\":");
                //        Debug.logWarning(e.getMessage());
View Full Code Here

        findHashMap.put("screenName", screenName);

        List uiScreenGVL = delegator.findByAnd("UiScreen", findHashMap, null);

        if (uiScreenGVL.size() == 0) {
            throw new GenericEntityException("No screen with name \"" +
                screenName + "\" was found in database.");
        }

        if (uiScreenGVL.size() > 1) {
            throw new GenericEntityException(
                "More than one screen found with name \"" + screenName + "\".");
        }

        GenericValue uiScreenGV = (GenericValue) uiScreenGVL.iterator().next();
        initialize(uiScreenGV, delegator);
View Full Code Here

      if (cl == null) {
          cl = this.getClass().getClassLoader();
      }
      return (cl.loadClass(className));
    } catch (Exception e) {
      throw new GenericEntityException(
          "Cannot load column class '" + className + "': " + e);
    }

  }
View Full Code Here

            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.
View Full Code Here

      queryInfo.addCondition( "EntityAccess", "entity", EntityOperator.EQUALS, linkEntity);
      queryInfo.addCondition( "EntityAccess", "partyEntityType", EntityOperator.EQUALS, "Team");
      queryInfo.addJoin( "EntityAccess", "TeamMember", Boolean.FALSE, "partyId", "teamId");
      queryInfo.addCondition( "TeamMember", "partyId", EntityOperator.EQUALS, partyId);
        } else {
            throw new GenericEntityException(
                "SecurityWrapper.buildSecurityInfo() must use either role or team as a parameter.");
        }

        return queryInfo;
    }
View Full Code Here

            GenericPK uiAttributePk = new GenericPK(uiAttributeEntity,
                    uiAttributeFindMap);
            GenericValue uiAttributeGenericValue = delegator.findByPrimaryKeyCache(uiAttributePk);

            if (uiAttributeGenericValue == null) {
                throw new GenericEntityException(
                    "No Ui Attribute was found for ui_attribute.attribute_id=" +
                    searchAttributeId);
            }

            String searchAttribName = uiAttributeGenericValue.getString(
View Full Code Here

TOP

Related Classes of org.ofbiz.entity.GenericEntityException

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.