Search in sources :

Example 1 with SearchDateCustomField

use of com.netsuite.webservices.platform.core.SearchDateCustomField in project tdi-studio-se by Talend.

the class NetsuiteManagement_CXF method search.

public void search(String searchentity, String searchFieldName, String searchOperator, List<String> searchValue, String forcedType) throws DatatypeConfigurationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if ((searchValue.get(0) != null) && (searchFieldName != null)) {
        this.criteriaSetter = findMethod(this.searchBasicClass, "set" + searchFieldName);
        if (this.criteriaSetter == null) {
            SearchCustomField customCriteria = null;
            if (forcedType.equals("String")) {
                SearchStringCustomField searchArgumentType = new SearchStringCustomField();
                searchArgumentType.setInternalId(searchFieldName);
                if (searchValue != null && searchValue.size() != 0) {
                    searchArgumentType.setSearchValue(searchValue.get(0));
                }
                searchArgumentType.setOperator(SearchStringFieldOperator.fromValue(searchOperator));
                customCriteria = searchArgumentType;
            } else if (forcedType.equals("Long")) {
                SearchLongCustomField searchArgumentType = new SearchLongCustomField();
                searchArgumentType.setInternalId(searchFieldName);
                if (searchValue != null && searchValue.size() != 0) {
                    searchArgumentType.setSearchValue(Long.valueOf(Long.parseLong(searchValue.get(0))));
                    if (searchValue.size() > 1) {
                        searchArgumentType.setSearchValue2(Long.valueOf(Long.parseLong(searchValue.get(1))));
                    }
                }
                searchArgumentType.setOperator(SearchLongFieldOperator.fromValue(searchOperator));
                customCriteria = searchArgumentType;
            } else if (forcedType.equals("Date")) {
                SearchDateCustomField searchArgumentType = new SearchDateCustomField();
                if (searchValue != null && searchValue.size() != 0) {
                    Calendar calValue = Calendar.getInstance();
                    Calendar calValue2 = Calendar.getInstance();
                    String dateFormat = "yyyy-MM-dd";
                    String timeFormat = "HH:mm:ss";
                    String format = dateFormat + " " + timeFormat;
                    if (searchValue.get(0).length() == dateFormat.length()) {
                        format = dateFormat;
                    }
                    if (searchValue.get(0).length() == timeFormat.length()) {
                        searchValue.set(0, new SimpleDateFormat(dateFormat).format(calValue.getTime()) + " " + searchValue.get(0));
                        if (searchValue.size() > 1) {
                            searchValue.set(1, new SimpleDateFormat(dateFormat).format(calValue.getTime()) + " " + searchValue.get(1));
                        }
                    }
                    DateFormat df = new SimpleDateFormat(format);
                    try {
                        calValue.setTime(df.parse(searchValue.get(0)));
                        if (searchValue.size() > 1) {
                            calValue2.setTime(df.parse(searchValue.get(1)));
                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    XMLGregorianCalendar xts = DatatypeFactory.newInstance().newXMLGregorianCalendar();
                    xts.setYear(calValue.get(Calendar.YEAR));
                    xts.setMonth(calValue.get(Calendar.MONTH) + 1);
                    xts.setDay(calValue.get(Calendar.DAY_OF_MONTH));
                    xts.setHour(calValue.get(Calendar.HOUR_OF_DAY));
                    xts.setMinute(calValue.get(Calendar.MINUTE));
                    xts.setSecond(calValue.get(Calendar.SECOND));
                    xts.setMillisecond(calValue.get(Calendar.MILLISECOND));
                    xts.setTimezone(calValue.get(Calendar.ZONE_OFFSET) / 60000);
                    searchArgumentType.setSearchValue(xts);
                    if (searchValue.size() > 1) {
                        XMLGregorianCalendar xts2 = DatatypeFactory.newInstance().newXMLGregorianCalendar();
                        xts2.setYear(calValue.get(Calendar.YEAR));
                        xts2.setMonth(calValue.get(Calendar.MONTH) + 1);
                        xts2.setDay(calValue.get(Calendar.DAY_OF_MONTH));
                        xts2.setHour(calValue.get(Calendar.HOUR_OF_DAY));
                        xts2.setMinute(calValue.get(Calendar.MINUTE));
                        xts2.setSecond(calValue.get(Calendar.SECOND));
                        xts2.setMillisecond(calValue.get(Calendar.MILLISECOND));
                        xts2.setTimezone(calValue.get(Calendar.ZONE_OFFSET) / 60000);
                        searchArgumentType.setSearchValue2(xts2);
                    }
                }
                searchArgumentType.setOperator(SearchDateFieldOperator.fromValue(searchOperator));
                customCriteria = searchArgumentType;
            } else if (forcedType.equals("Boolean")) {
                SearchBooleanCustomField searchArgumentType = new SearchBooleanCustomField();
                searchArgumentType.setInternalId(searchFieldName);
                searchArgumentType.setSearchValue(Boolean.valueOf(Boolean.parseBoolean(searchValue.get(0))));
                customCriteria = searchArgumentType;
            } else if (forcedType.equals("Double")) {
                SearchDoubleCustomField searchArgumentType = new SearchDoubleCustomField();
                searchArgumentType.setInternalId(searchFieldName);
                if (searchValue != null && searchValue.size() != 0) {
                    searchArgumentType.setSearchValue(Double.valueOf(Double.parseDouble(searchValue.get(0))));
                    if (searchValue.size() > 1) {
                        searchArgumentType.setSearchValue2(Double.valueOf(Double.parseDouble(searchValue.get(1))));
                    }
                }
                searchArgumentType.setOperator(SearchDoubleFieldOperator.fromValue(searchOperator));
                customCriteria = searchArgumentType;
            } else if (forcedType.equals("List")) {
                SearchMultiSelectCustomField searchArgumentType = new SearchMultiSelectCustomField();
                int len = searchValue.size();
                List<ListOrRecordRef> lr = searchArgumentType.getSearchValue();
                for (int i = 0; i < len; i++) {
                    ListOrRecordRef lRecordRef = new ListOrRecordRef();
                    lRecordRef.setName(searchValue.get(i));
                    lr.add(lRecordRef);
                }
                searchArgumentType.setOperator(SearchMultiSelectFieldOperator.fromValue(searchOperator));
                customCriteria = searchArgumentType;
            } else {
                throw new IllegalArgumentException("Unsupported search field type: " + forcedType);
            }
            push(customCriteria);
            this.hasCustomCriteria = true;
        } else {
            this.criteriaSetter.invoke(this.searchBasic, new Object[] { getSearchField(this.searchBasicClass, searchValue, searchFieldName, searchOperator) });
        }
    }
}
Also used : SearchBooleanCustomField(com.netsuite.webservices.platform.core.SearchBooleanCustomField) SearchStringCustomField(com.netsuite.webservices.platform.core.SearchStringCustomField) SearchMultiSelectCustomField(com.netsuite.webservices.platform.core.SearchMultiSelectCustomField) ListOrRecordRef(com.netsuite.webservices.platform.core.ListOrRecordRef) Calendar(java.util.Calendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SearchLongCustomField(com.netsuite.webservices.platform.core.SearchLongCustomField) SearchCustomField(com.netsuite.webservices.platform.core.SearchCustomField) SearchDoubleCustomField(com.netsuite.webservices.platform.core.SearchDoubleCustomField) SearchDateCustomField(com.netsuite.webservices.platform.core.SearchDateCustomField) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) List(java.util.List) SearchCustomFieldList(com.netsuite.webservices.platform.core.SearchCustomFieldList) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ListOrRecordRef (com.netsuite.webservices.platform.core.ListOrRecordRef)1 SearchBooleanCustomField (com.netsuite.webservices.platform.core.SearchBooleanCustomField)1 SearchCustomField (com.netsuite.webservices.platform.core.SearchCustomField)1 SearchCustomFieldList (com.netsuite.webservices.platform.core.SearchCustomFieldList)1 SearchDateCustomField (com.netsuite.webservices.platform.core.SearchDateCustomField)1 SearchDoubleCustomField (com.netsuite.webservices.platform.core.SearchDoubleCustomField)1 SearchLongCustomField (com.netsuite.webservices.platform.core.SearchLongCustomField)1 SearchMultiSelectCustomField (com.netsuite.webservices.platform.core.SearchMultiSelectCustomField)1 SearchStringCustomField (com.netsuite.webservices.platform.core.SearchStringCustomField)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 List (java.util.List)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1