Search in sources :

Example 1 with BooleanCustomFieldRef

use of com.netsuite.webservices.v2016_2.platform.core.BooleanCustomFieldRef in project components by Talend.

the class NetSuiteOutputWriterIT method makeContactRecords.

private static List<Contact> makeContactRecords(int count, RecordRef subsidiary, Map<String, FieldDesc> fieldDescMap) {
    CustomFieldDesc customFieldDesc1 = fieldDescMap.get("custentity_interest_bpm").asCustom();
    List<Contact> recordList = new ArrayList<>(count);
    for (int i = 1; i <= count; i++) {
        Contact record = new Contact();
        String id = Long.toString(System.currentTimeMillis());
        record.setFirstName("AAA " + id);
        record.setLastName("BBB " + id);
        record.setPhone(id);
        record.setEntityId(id);
        record.setSubsidiary(subsidiary);
        record.setCustomFieldList(new CustomFieldList());
        BooleanCustomFieldRef customFieldRef1 = new BooleanCustomFieldRef();
        customFieldRef1.setScriptId(customFieldDesc1.getCustomizationRef().getScriptId());
        customFieldRef1.setInternalId(customFieldDesc1.getCustomizationRef().getInternalId());
        customFieldRef1.setValue(true);
        record.getCustomFieldList().getCustomField().add(customFieldRef1);
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
        }
        recordList.add(record);
    }
    return recordList;
}
Also used : ArrayList(java.util.ArrayList) BooleanCustomFieldRef(com.netsuite.webservices.v2016_2.platform.core.BooleanCustomFieldRef) CustomFieldList(com.netsuite.webservices.v2016_2.platform.core.CustomFieldList) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) Contact(com.netsuite.webservices.v2016_2.lists.relationships.Contact)

Example 2 with BooleanCustomFieldRef

use of com.netsuite.webservices.v2016_2.platform.core.BooleanCustomFieldRef in project components by Talend.

the class NetSuiteOutputWriterIT method testUpdateWithCustomFields.

@Test
public void testUpdateWithCustomFields() throws Exception {
    final NetSuiteClientService<NetSuitePortType> clientService = webServiceTestFixture.getClientService();
    RuntimeContainer container = mock(RuntimeContainer.class);
    NetSuiteOutputProperties properties = new NetSuiteOutputProperties("test");
    properties.init();
    properties.connection.endpoint.setValue(webServiceTestFixture.getEndpointUrl());
    properties.connection.email.setValue(webServiceTestFixture.getCredentials().getEmail());
    properties.connection.password.setValue(webServiceTestFixture.getCredentials().getPassword());
    properties.connection.account.setValue(webServiceTestFixture.getCredentials().getAccount());
    properties.connection.role.setValue(Integer.valueOf(webServiceTestFixture.getCredentials().getRoleId()));
    properties.connection.applicationId.setValue(webServiceTestFixture.getCredentials().getApplicationId());
    properties.module.moduleName.setValue(RecordTypeEnum.CONTACT.getTypeName());
    properties.module.action.setValue(OutputAction.UPDATE);
    NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
    runtime.setClientFactory(clientFactory);
    NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    properties.module.main.schema.setValue(schema);
    SubsidiarySearch subsidiarySearch = new SubsidiarySearch();
    SubsidiarySearchBasic subsidiarySearchBasic = new SubsidiarySearchBasic();
    subsidiarySearch.setBasic(subsidiarySearchBasic);
    NsSearchResult<Subsidiary> searchResult = clientService.search(subsidiarySearch);
    assertTrue(searchResult.isSuccess());
    assertNotNull(searchResult.getRecordList());
    assertTrue(searchResult.getRecordList().size() > 0);
    Subsidiary subsidiary = searchResult.getRecordList().get(0);
    RecordRef subsidiaryRef = new RecordRef();
    subsidiaryRef.setType(RecordType.SUBSIDIARY);
    subsidiaryRef.setInternalId(subsidiary.getInternalId());
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("Contact");
    assertNotNull(typeDesc.getField("custentity_interest_bpm"));
    List<Contact> recordsToAdd = makeContactRecords(5, subsidiaryRef, typeDesc.getFieldMap());
    final List<RecordRef> refList = new ArrayList<>(recordsToAdd.size());
    // Add records
    List<NsWriteResponse<RecordRef>> writeResponseList = clientService.addList(recordsToAdd);
    for (NsWriteResponse<RecordRef> writeResponse : writeResponseList) {
        assertTrue("Add: " + writeResponse.getStatus(), writeResponse.getStatus().isSuccess());
        assertNotNull(writeResponse.getRef());
        refList.add(writeResponse.getRef());
    }
    // Read added records
    List<Contact> recordList = new ArrayList<>(refList.size());
    List<NsReadResponse<Contact>> readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Contact>>, NetSuitePortType>() {

        @Override
        public List<NsReadResponse<Contact>> execute(NetSuitePortType port) throws Exception {
            GetListRequest request = new GetListRequest();
            request.getBaseRef().addAll(refList);
            return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
        }
    });
    for (NsReadResponse<Contact> readResponse : readResponseList) {
        assertTrue(readResponse.getStatus().isSuccess());
        recordList.add(readResponse.getRecord());
    }
    List<IndexedRecord> indexedRecordList = new ArrayList<>(refList.size());
    for (Contact record : recordList) {
        GenericRecord indexedRecord = new GenericData.Record(schema);
        indexedRecord.put("InternalId", record.getInternalId());
        // Updated fields
        indexedRecord.put("custentity_interest_bpm", Boolean.FALSE);
        indexedRecordList.add(indexedRecord);
    }
    // Update records
    NetSuiteSink sink = new NetSuiteSinkImpl();
    sink.setClientFactory(clientFactory);
    sink.initialize(container, properties);
    NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
    NetSuiteOutputWriter writer = (NetSuiteOutputWriter) writeOperation.createWriter(container);
    writer.open(UUID.randomUUID().toString());
    for (IndexedRecord indexedRecord : indexedRecordList) {
        writer.write(indexedRecord);
    }
    Result writerResult = writer.close();
    assertNotNull(writerResult);
    assertEquals(indexedRecordList.size(), writerResult.totalCount);
    assertEquals(indexedRecordList.size(), writerResult.successCount);
    // Re-read updated records
    readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Contact>>, NetSuitePortType>() {

        @Override
        public List<NsReadResponse<Contact>> execute(NetSuitePortType port) throws Exception {
            GetListRequest request = new GetListRequest();
            request.getBaseRef().addAll(refList);
            return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
        }
    });
    for (NsReadResponse<Contact> readResponse : readResponseList) {
        assertTrue(readResponse.getStatus().isSuccess());
        Contact record = readResponse.getRecord();
        CustomFieldList customFieldList = record.getCustomFieldList();
        assertNotNull(customFieldList);
        Map<String, CustomFieldRef> customFieldRefMap = new HashMap<>();
        for (CustomFieldRef fieldRef : customFieldList.getCustomField()) {
            customFieldRefMap.put(fieldRef.getScriptId(), fieldRef);
        }
        BooleanCustomFieldRef customFieldRef1 = (BooleanCustomFieldRef) customFieldRefMap.get("custentity_interest_bpm");
        assertNotNull(customFieldRef1);
        assertEquals(Boolean.FALSE, customFieldRef1.getValue());
    }
    clientService.deleteList(refList);
}
Also used : NetSuiteSinkImpl(org.talend.components.netsuite.v2016_2.NetSuiteSinkImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) HashMap(java.util.HashMap) Schema(org.apache.avro.Schema) RecordRef(com.netsuite.webservices.v2016_2.platform.core.RecordRef) CustomRecordRef(com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteWriteOperation(org.talend.components.netsuite.output.NetSuiteWriteOperation) CustomFieldList(com.netsuite.webservices.v2016_2.platform.core.CustomFieldList) NsReadResponse(org.talend.components.netsuite.client.NsReadResponse) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl) Result(org.talend.components.api.component.runtime.Result) NsSearchResult(org.talend.components.netsuite.client.NsSearchResult) SubsidiarySearch(com.netsuite.webservices.v2016_2.lists.accounting.SubsidiarySearch) Subsidiary(com.netsuite.webservices.v2016_2.lists.accounting.Subsidiary) BooleanCustomFieldRef(com.netsuite.webservices.v2016_2.platform.core.BooleanCustomFieldRef) CustomFieldList(com.netsuite.webservices.v2016_2.platform.core.CustomFieldList) List(java.util.List) ArrayList(java.util.ArrayList) RecordRefList(com.netsuite.webservices.v2016_2.platform.core.RecordRefList) CustomRecord(com.netsuite.webservices.v2016_2.setup.customization.CustomRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) GenericRecord(org.apache.avro.generic.GenericRecord) NsWriteResponse(org.talend.components.netsuite.client.NsWriteResponse) NetSuiteOutputWriter(org.talend.components.netsuite.output.NetSuiteOutputWriter) NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) SubsidiarySearchBasic(com.netsuite.webservices.v2016_2.platform.common.SubsidiarySearchBasic) NetSuiteOutputProperties(org.talend.components.netsuite.output.NetSuiteOutputProperties) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) Contact(com.netsuite.webservices.v2016_2.lists.relationships.Contact) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) CustomFieldRef(com.netsuite.webservices.v2016_2.platform.core.CustomFieldRef) StringCustomFieldRef(com.netsuite.webservices.v2016_2.platform.core.StringCustomFieldRef) BooleanCustomFieldRef(com.netsuite.webservices.v2016_2.platform.core.BooleanCustomFieldRef) NetSuiteSink(org.talend.components.netsuite.NetSuiteSink) GetListRequest(com.netsuite.webservices.v2016_2.platform.messages.GetListRequest) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Aggregations

Contact (com.netsuite.webservices.v2016_2.lists.relationships.Contact)2 BooleanCustomFieldRef (com.netsuite.webservices.v2016_2.platform.core.BooleanCustomFieldRef)2 CustomFieldList (com.netsuite.webservices.v2016_2.platform.core.CustomFieldList)2 ArrayList (java.util.ArrayList)2 Subsidiary (com.netsuite.webservices.v2016_2.lists.accounting.Subsidiary)1 SubsidiarySearch (com.netsuite.webservices.v2016_2.lists.accounting.SubsidiarySearch)1 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)1 SubsidiarySearchBasic (com.netsuite.webservices.v2016_2.platform.common.SubsidiarySearchBasic)1 CustomFieldRef (com.netsuite.webservices.v2016_2.platform.core.CustomFieldRef)1 CustomRecordRef (com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef)1 RecordRef (com.netsuite.webservices.v2016_2.platform.core.RecordRef)1 RecordRefList (com.netsuite.webservices.v2016_2.platform.core.RecordRefList)1 StringCustomFieldRef (com.netsuite.webservices.v2016_2.platform.core.StringCustomFieldRef)1 GetListRequest (com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)1 CustomRecord (com.netsuite.webservices.v2016_2.setup.customization.CustomRecord)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Schema (org.apache.avro.Schema)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1