Search in sources :

Example 6 with RecordTypeInfo

use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.

the class SearchResultSetTest method testEmptyResult.

@Test
public void testEmptyResult() throws Exception {
    NetSuiteClientService<?> conn = mock(NetSuiteClientService.class);
    SearchResult result1 = new SearchResult();
    Status status = new Status();
    status.setIsSuccess(true);
    result1.setStatus(status);
    result1.setSearchId("abc123");
    result1.setPageIndex(1);
    result1.setTotalRecords(0);
    result1.setTotalPages(0);
    SearchResponse response1 = new SearchResponse();
    response1.setSearchResult(result1);
    AccountSearch nsSearchRecord1 = new AccountSearch();
    NsSearchResult nsSearchResult1 = TestNetSuiteClientService.toNsSearchResult(result1);
    when(conn.search(eq(nsSearchRecord1))).thenReturn(nsSearchResult1);
    NetSuiteClientService<?> clientService = new TestNetSuiteClientService();
    RecordTypeInfo recordTypeInfo = clientService.getMetaDataSource().getRecordType("Account");
    SearchRecordTypeDesc searchRecordTypeDesc = clientService.getMetaDataSource().getSearchRecordType(recordTypeInfo.getRecordType().getSearchRecordType());
    SearchResultSet<Record> resultSet = new SearchResultSet<>(conn, recordTypeInfo.getRecordType(), searchRecordTypeDesc, nsSearchResult1);
    assertFalse(resultSet.next());
}
Also used : Status(com.netsuite.webservices.test.platform.core.Status) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) TestNetSuiteClientService(org.talend.components.netsuite.test.client.TestNetSuiteClientService) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchResultSet(org.talend.components.netsuite.client.search.SearchResultSet) SearchResult(com.netsuite.webservices.test.platform.core.SearchResult) Record(com.netsuite.webservices.test.platform.core.Record) SearchResponse(com.netsuite.webservices.test.platform.messages.SearchResponse) AccountSearch(com.netsuite.webservices.test.lists.accounting.AccountSearch) Test(org.junit.Test)

Example 7 with RecordTypeInfo

use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.

the class DefaultMetaDataSource method getSearchableTypes.

/**
 * {@inheritDoc}
 */
@Override
public Collection<NamedThing> getSearchableTypes() {
    List<NamedThing> searchableTypes = new ArrayList<>(256);
    Collection<RecordTypeInfo> recordTypes = getRecordTypes();
    for (RecordTypeInfo recordTypeInfo : recordTypes) {
        RecordTypeDesc recordTypeDesc = recordTypeInfo.getRecordType();
        if (recordTypeDesc.getSearchRecordType() != null) {
            SearchRecordTypeDesc searchRecordType = clientService.getBasicMetaData().getSearchRecordType(recordTypeDesc);
            if (searchRecordType != null) {
                searchableTypes.add(new SimpleNamedThing(recordTypeInfo.getName(), recordTypeInfo.getDisplayName()));
            }
        }
    }
    return searchableTypes;
}
Also used : SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing)

Example 8 with RecordTypeInfo

use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.

the class NetSuiteDatasetRuntimeImpl method getSchemaForRecordRef.

public Schema getSchemaForRecordRef(String typeName) {
    try {
        // Get info for target record type
        final RecordTypeInfo referencedRecordTypeInfo = metaDataSource.getRecordType(typeName);
        final RefType refType = referencedRecordTypeInfo.getRefType();
        // Get type info for record ref
        final TypeDesc typeDesc = metaDataSource.getTypeInfo(refType.getTypeName());
        List<FieldDesc> fieldDescList = new ArrayList<>(typeDesc.getFields());
        // Sort in alphabetical order
        Collections.sort(fieldDescList, FieldDescComparator.INSTANCE);
        Schema schema = inferSchemaForType(typeDesc.getTypeName(), fieldDescList);
        augmentSchemaWithCustomMetaData(metaDataSource, schema, referencedRecordTypeInfo, null);
        return schema;
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : CustomFieldRefType(org.talend.components.netsuite.client.model.customfield.CustomFieldRefType) RefType(org.talend.components.netsuite.client.model.RefType) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Schema(org.apache.avro.Schema) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 9 with RecordTypeInfo

use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.

the class NetSuiteDatasetRuntimeImpl method getSchema.

@Override
public Schema getSchema(String typeName) {
    try {
        final RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
        final TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
        List<FieldDesc> fieldDescList = new ArrayList<>(typeDesc.getFields());
        // Sort in alphabetical order
        Collections.sort(fieldDescList, FieldDescComparator.INSTANCE);
        Schema schema = inferSchemaForType(typeDesc.getTypeName(), fieldDescList);
        augmentSchemaWithCustomMetaData(metaDataSource, schema, recordTypeInfo, fieldDescList);
        return schema;
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Schema(org.apache.avro.Schema) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 10 with RecordTypeInfo

use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.

the class NetSuiteDatasetRuntimeImpl method getSchemaForUpdateFlow.

@Override
public Schema getSchemaForUpdateFlow(String typeName, Schema schema) {
    RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
    TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
    // We should check and add key fields:
    // internalId, externalId and scriptId (for custom record type)
    List<FieldDesc> fieldDescList = new ArrayList<>();
    Schema.Field internalIdField = getNsFieldByName(schema, "internalId");
    if (internalIdField == null) {
        FieldDesc fieldDesc = typeDesc.getField("internalId");
        fieldDescList.add(fieldDesc);
    }
    Schema.Field externalIdField = getNsFieldByName(schema, "externalId");
    if (externalIdField == null) {
        FieldDesc fieldDesc = typeDesc.getField("externalId");
        fieldDescList.add(fieldDesc);
    }
    if (recordTypeInfo instanceof CustomRecordTypeInfo) {
        Schema.Field scriptIdField = getNsFieldByName(schema, "scriptId");
        if (scriptIdField == null) {
            FieldDesc fieldDesc = typeDesc.getField("scriptId");
            if (fieldDesc != null) {
                fieldDescList.add(fieldDesc);
            }
        }
    }
    // Create schema fields for mandatory fields.
    List<Schema.Field> fields = new ArrayList<>();
    Schema.Field f;
    if (!fieldDescList.isEmpty()) {
        Schema schemaToAdd = inferSchemaForType(typeName, fieldDescList);
        for (Schema.Field sourceField : schemaToAdd.getFields()) {
            f = copyField(sourceField);
            f.addProp(SchemaConstants.TALEND_FIELD_GENERATED, "true");
            f.addProp(SchemaConstants.TALEND_IS_LOCKED, "true");
            fields.add(f);
        }
    }
    return extendSchema(schema, typeName + "_FLOW", fields);
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Schema(org.apache.avro.Schema) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Aggregations

RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)24 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)17 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)11 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)11 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)9 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)8 Schema (org.apache.avro.Schema)7 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)7 HashSet (java.util.HashSet)5 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)5 ComponentException (org.talend.components.api.exception.ComponentException)4 Record (com.netsuite.webservices.test.platform.core.Record)3 SearchResult (com.netsuite.webservices.test.platform.core.SearchResult)3 Status (com.netsuite.webservices.test.platform.core.Status)3 SearchResponse (com.netsuite.webservices.test.platform.messages.SearchResponse)3 SearchResultSet (org.talend.components.netsuite.client.search.SearchResultSet)3 TestNetSuiteClientService (org.talend.components.netsuite.test.client.TestNetSuiteClientService)3 NamedThing (org.talend.daikon.NamedThing)3