Search in sources :

Example 1 with SearchQuery

use of org.talend.components.netsuite.client.search.SearchQuery in project components by Talend.

the class SearchQueryTest method testSearchMultiSelectField.

@Test
public void testSearchMultiSelectField() throws Exception {
    clientService.getMetaDataSource().setCustomMetaDataSource(new TestCustomMetaDataSource());
    SearchQuery s1 = clientService.newSearch();
    s1.target("custom_record_type_1");
    s1.condition(new SearchCondition("Owner", "List.anyOf", Arrays.asList("123456789")));
    SearchRecord sr1 = (SearchRecord) s1.toNativeQuery();
    assertNotNull(sr1);
    Assert.assertEquals(CustomRecordSearch.class, sr1.getClass());
    CustomRecordSearch search = (CustomRecordSearch) sr1;
    assertNotNull(search.getBasic());
    CustomRecordSearchBasic searchBasic = search.getBasic();
    assertNotNull(searchBasic.getOwner());
    SearchMultiSelectField sf1 = searchBasic.getOwner();
    assertNotNull(sf1.getSearchValue());
    Assert.assertEquals(1, sf1.getSearchValue().size());
    Assert.assertEquals("123456789", sf1.getSearchValue().get(0).getInternalId());
}
Also used : SearchQuery(org.talend.components.netsuite.client.search.SearchQuery) SearchRecord(com.netsuite.webservices.test.platform.core.SearchRecord) SearchCondition(org.talend.components.netsuite.client.search.SearchCondition) CustomRecordSearch(com.netsuite.webservices.test.setup.customization.CustomRecordSearch) CustomRecordSearchBasic(com.netsuite.webservices.test.platform.common.CustomRecordSearchBasic) SearchMultiSelectField(com.netsuite.webservices.test.platform.core.SearchMultiSelectField) Test(org.junit.Test)

Example 2 with SearchQuery

use of org.talend.components.netsuite.client.search.SearchQuery in project components by Talend.

the class SearchQueryTest method testBasics.

@Test
public void testBasics() throws Exception {
    SearchQuery s1 = clientService.newSearch();
    s1.target("Account");
    s1.condition(new SearchCondition("Type", "List.anyOf", Arrays.asList("bank")));
    s1.condition(new SearchCondition("Balance", "Double.greaterThanOrEqualTo", Arrays.asList("10000.0", "")));
    s1.condition(new SearchCondition("LegalName", "String.contains", Arrays.asList("Acme")));
    s1.condition(new SearchCondition("IsInactive", "Boolean", Arrays.asList("true")));
    s1.condition(new SearchCondition("CustomBooleanField1", "Boolean", Arrays.asList("true")));
    s1.condition(new SearchCondition("CustomStringField1", "String.doesNotContain", Arrays.asList("Foo")));
    s1.condition(new SearchCondition("CustomLongField1", "Long.lessThan", Arrays.asList("100", "")));
    SearchRecord sr1 = (SearchRecord) s1.toNativeQuery();
    assertNotNull(sr1);
    Assert.assertEquals(AccountSearch.class, sr1.getClass());
    AccountSearch search = (AccountSearch) sr1;
    assertNotNull(search.getBasic());
    AccountSearchBasic searchBasic = search.getBasic();
    assertNotNull(searchBasic.getBalance());
    SearchEnumMultiSelectField typeField = searchBasic.getType();
    Assert.assertEquals(SearchEnumMultiSelectFieldOperator.ANY_OF, typeField.getOperator());
    Assert.assertEquals(Arrays.asList("bank"), typeField.getSearchValue());
    SearchDoubleField balanceField = searchBasic.getBalance();
    Assert.assertEquals(SearchDoubleFieldOperator.GREATER_THAN_OR_EQUAL_TO, balanceField.getOperator());
    Assert.assertEquals(Double.valueOf(10000.0), balanceField.getSearchValue());
    SearchBooleanField isInactiveField = searchBasic.getIsInactive();
    Assert.assertEquals(Boolean.TRUE, isInactiveField.getSearchValue());
    SearchStringField legalNameField = searchBasic.getLegalName();
    Assert.assertEquals(SearchStringFieldOperator.CONTAINS, legalNameField.getOperator());
    Assert.assertEquals("Acme", legalNameField.getSearchValue());
    SearchCustomFieldList customFieldList = searchBasic.getCustomFieldList();
    assertNotNull(customFieldList);
    assertNotNull(customFieldList.getCustomField());
    Assert.assertEquals(3, customFieldList.getCustomField().size());
    SearchBooleanCustomField customBooleanField1 = (SearchBooleanCustomField) customFieldList.getCustomField().get(0);
    Assert.assertEquals(Boolean.TRUE, customBooleanField1.getSearchValue());
    SearchStringCustomField customStringField1 = (SearchStringCustomField) customFieldList.getCustomField().get(1);
    Assert.assertEquals(SearchStringFieldOperator.DOES_NOT_CONTAIN, customStringField1.getOperator());
    Assert.assertEquals("Foo", customStringField1.getSearchValue());
    SearchLongCustomField customLongField1 = (SearchLongCustomField) customFieldList.getCustomField().get(2);
    Assert.assertEquals(SearchLongFieldOperator.LESS_THAN, customLongField1.getOperator());
    Assert.assertEquals(Long.valueOf(100), customLongField1.getSearchValue());
}
Also used : SearchQuery(org.talend.components.netsuite.client.search.SearchQuery) SearchBooleanCustomField(com.netsuite.webservices.test.platform.core.SearchBooleanCustomField) SearchStringCustomField(com.netsuite.webservices.test.platform.core.SearchStringCustomField) SearchCustomFieldList(com.netsuite.webservices.test.platform.core.SearchCustomFieldList) SearchLongCustomField(com.netsuite.webservices.test.platform.core.SearchLongCustomField) AccountSearchBasic(com.netsuite.webservices.test.platform.common.AccountSearchBasic) AccountSearch(com.netsuite.webservices.test.lists.accounting.AccountSearch) SearchRecord(com.netsuite.webservices.test.platform.core.SearchRecord) SearchBooleanField(com.netsuite.webservices.test.platform.core.SearchBooleanField) SearchCondition(org.talend.components.netsuite.client.search.SearchCondition) SearchDoubleField(com.netsuite.webservices.test.platform.core.SearchDoubleField) SearchStringField(com.netsuite.webservices.test.platform.core.SearchStringField) SearchEnumMultiSelectField(com.netsuite.webservices.test.platform.core.SearchEnumMultiSelectField) Test(org.junit.Test)

Example 3 with SearchQuery

use of org.talend.components.netsuite.client.search.SearchQuery in project components by Talend.

the class SearchQueryTest method testSearchDateField.

@Test
public void testSearchDateField() throws Exception {
    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm:ss");
    Instant now = Instant.now();
    String currentDateFormatted = dateFormatter.print(now.getMillis());
    SearchQuery s1 = clientService.newSearch();
    s1.target("Check");
    s1.condition(new SearchCondition("TranDate", "Date.onOrAfter", Arrays.asList("2017-01-01 12:00:00")));
    s1.condition(new SearchCondition("CustomDateField1", "Date.onOrAfter", Arrays.asList("14:00:00")));
    SearchRecord sr1 = (SearchRecord) s1.toNativeQuery();
    assertNotNull(sr1);
    Assert.assertEquals(TransactionSearch.class, sr1.getClass());
    TransactionSearch search = (TransactionSearch) sr1;
    assertNotNull(search.getBasic());
    TransactionSearchBasic searchBasic = search.getBasic();
    assertNotNull(searchBasic.getTranDate());
    SearchDateField field1 = searchBasic.getTranDate();
    Assert.assertEquals(SearchDateFieldOperator.ON_OR_AFTER, field1.getOperator());
    assertNotNull(field1.getSearchValue());
    assertNull(field1.getSearchValue2());
    assertEquals("2017-01-01 12:00:00", dateTimeFormatter.print((Long) calendarValueConverter.convertToAvro(field1.getSearchValue())));
    SearchCustomFieldList customFieldList = searchBasic.getCustomFieldList();
    assertNotNull(customFieldList);
    assertNotNull(customFieldList.getCustomField());
    Assert.assertEquals(1, customFieldList.getCustomField().size());
    MutableDateTime controlDateTime = new MutableDateTime();
    controlDateTime.setHourOfDay(14);
    controlDateTime.setMinuteOfHour(0);
    controlDateTime.setSecondOfMinute(0);
    controlDateTime.setMillisOfSecond(0);
    String controlTimeFormatted = timeFormatter.print(controlDateTime);
    SearchDateCustomField customField1 = (SearchDateCustomField) customFieldList.getCustomField().get(0);
    Assert.assertEquals(SearchDateFieldOperator.ON_OR_AFTER, customField1.getOperator());
    assertNotNull(customField1.getSearchValue());
    assertNull(customField1.getSearchValue2());
    assertEquals(currentDateFormatted + " " + controlTimeFormatted, dateTimeFormatter.print((Long) calendarValueConverter.convertToAvro(customField1.getSearchValue())));
}
Also used : SearchQuery(org.talend.components.netsuite.client.search.SearchQuery) TransactionSearch(com.netsuite.webservices.test.transactions.sales.TransactionSearch) Instant(org.joda.time.Instant) SearchDateField(com.netsuite.webservices.test.platform.core.SearchDateField) MutableDateTime(org.joda.time.MutableDateTime) TransactionSearchBasic(com.netsuite.webservices.test.platform.common.TransactionSearchBasic) SearchCustomFieldList(com.netsuite.webservices.test.platform.core.SearchCustomFieldList) SearchRecord(com.netsuite.webservices.test.platform.core.SearchRecord) SearchDateCustomField(com.netsuite.webservices.test.platform.core.SearchDateCustomField) SearchCondition(org.talend.components.netsuite.client.search.SearchCondition) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 4 with SearchQuery

use of org.talend.components.netsuite.client.search.SearchQuery in project components by Talend.

the class NetSuiteSearchInputReader method search.

/**
 * Build and execute NetSuite search query.
 *
 * @return
 * @throws NetSuiteException if an error occurs during execution of search
 */
private ResultSet<?> search() throws NetSuiteException {
    SearchQuery search = buildSearchQuery();
    RecordTypeInfo recordTypeInfo = search.getRecordTypeInfo();
    // Set up object translator
    transducer = new NsObjectInputTransducer(clientService, schema, recordTypeInfo.getName());
    transducer.setMetaDataSource(metaDataSource);
    transducer.setApiVersion(properties.connection.apiVersion.getValue());
    ResultSet<?> resultSet = search.search();
    return resultSet;
}
Also used : SearchQuery(org.talend.components.netsuite.client.search.SearchQuery) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo)

Example 5 with SearchQuery

use of org.talend.components.netsuite.client.search.SearchQuery in project components by Talend.

the class NetSuiteSearchInputReader method buildSearchQuery.

/**
 * Build search query from properties.
 *
 * @return search query object
 */
private SearchQuery buildSearchQuery() {
    String target = properties.module.moduleName.getStringValue();
    SearchQuery search = clientService.newSearch(metaDataSource);
    search.target(target);
    // Build search conditions
    List<String> fieldNames = properties.module.searchQuery.field.getValue();
    if (fieldNames != null && !fieldNames.isEmpty()) {
        for (int i = 0; i < fieldNames.size(); i++) {
            String fieldName = fieldNames.get(i);
            String operator = properties.module.searchQuery.operator.getValue().get(i);
            Object value1 = properties.module.searchQuery.value1.getValue().get(i);
            Object value2 = properties.module.searchQuery.value2.getValue().get(i);
            search.condition(buildSearchCondition(fieldName, operator, value1, value2));
        }
    }
    return search;
}
Also used : SearchQuery(org.talend.components.netsuite.client.search.SearchQuery)

Aggregations

SearchQuery (org.talend.components.netsuite.client.search.SearchQuery)9 Test (org.junit.Test)7 SearchRecord (com.netsuite.webservices.test.platform.core.SearchRecord)6 SearchCondition (org.talend.components.netsuite.client.search.SearchCondition)6 SearchCustomFieldList (com.netsuite.webservices.test.platform.core.SearchCustomFieldList)4 SearchEnumMultiSelectField (com.netsuite.webservices.test.platform.core.SearchEnumMultiSelectField)3 AccountSearch (com.netsuite.webservices.test.lists.accounting.AccountSearch)2 AccountSearchBasic (com.netsuite.webservices.test.platform.common.AccountSearchBasic)2 TransactionSearchBasic (com.netsuite.webservices.test.platform.common.TransactionSearchBasic)2 SearchDateCustomField (com.netsuite.webservices.test.platform.core.SearchDateCustomField)2 SearchDateField (com.netsuite.webservices.test.platform.core.SearchDateField)2 SearchStringCustomField (com.netsuite.webservices.test.platform.core.SearchStringCustomField)2 SearchStringField (com.netsuite.webservices.test.platform.core.SearchStringField)2 TransactionSearch (com.netsuite.webservices.test.transactions.sales.TransactionSearch)2 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)2 AddressSearchBasic (com.netsuite.webservices.test.platform.common.AddressSearchBasic)1 CustomRecordSearchBasic (com.netsuite.webservices.test.platform.common.CustomRecordSearchBasic)1 SearchBooleanCustomField (com.netsuite.webservices.test.platform.core.SearchBooleanCustomField)1 SearchBooleanField (com.netsuite.webservices.test.platform.core.SearchBooleanField)1 SearchDoubleField (com.netsuite.webservices.test.platform.core.SearchDoubleField)1