use of com.netsuite.webservices.v2016_2.platform.core.RecordRef in project components by Talend.
the class NetSuiteClientServiceImpl method createNativePassport.
@Override
protected Passport createNativePassport(NetSuiteCredentials nsCredentials) {
RecordRef roleRecord = new RecordRef();
roleRecord.setInternalId(nsCredentials.getRoleId());
final Passport passport = new Passport();
passport.setEmail(nsCredentials.getEmail());
passport.setPassword(nsCredentials.getPassword());
passport.setRole(roleRecord);
passport.setAccount(nsCredentials.getAccount());
return passport;
}
use of com.netsuite.webservices.v2016_2.platform.core.RecordRef in project components by Talend.
the class NetSuiteOutputWriterTest method testUpdate.
@Test
public void testUpdate() throws Exception {
final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
final TypeDesc typeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RecordTypeEnum.OPPORTUNITY.getTypeName());
mockGetListRequestResults(null);
final List<Opportunity> updatedRecordList = new ArrayList<>();
when(port.updateList(any(UpdateListRequest.class))).then(new Answer<UpdateListResponse>() {
@Override
public UpdateListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
UpdateListRequest request = (UpdateListRequest) invocationOnMock.getArguments()[0];
assertFalse(request.getRecord().isEmpty());
UpdateListResponse response = new UpdateListResponse();
WriteResponseList writeResponseList = new WriteResponseList();
writeResponseList.setStatus(createSuccessStatus());
for (int i = 0; i < request.getRecord().size(); i++) {
Opportunity record = (Opportunity) request.getRecord().get(i);
assertNotNull(record);
assertNotNull(record.getInternalId());
RecordRef recordRef = new RecordRef();
recordRef.setInternalId(record.getInternalId());
recordRef.setType(RecordType.OPPORTUNITY);
updatedRecordList.add(record);
WriteResponse writeResponse = new WriteResponse();
writeResponse.setStatus(createSuccessStatus());
writeResponse.setBaseRef(recordRef);
writeResponseList.getWriteResponse().add(writeResponse);
}
response.setWriteResponseList(writeResponseList);
return response;
}
});
properties.module.moduleName.setValue(typeDesc.getTypeName());
properties.module.action.setValue(OutputAction.UPDATE);
NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
properties.module.main.schema.setValue(schema);
NetSuiteSink sink = new NetSuiteSinkImpl();
sink.initialize(mockTestFixture.getRuntimeContainer(), properties);
NetSuiteClientService<?> clientService = sink.getClientService();
NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
NetSuiteOutputWriter writer = (NetSuiteOutputWriter) writeOperation.createWriter(mockTestFixture.getRuntimeContainer());
writer.open(UUID.randomUUID().toString());
List<IndexedRecord> indexedRecordList = makeIndexedRecords(clientService, schema, new SimpleObjectComposer<>(typeDesc.getTypeClass()), 150);
for (IndexedRecord record : indexedRecordList) {
writer.write(record);
}
Result writerResult = writer.close();
assertNotNull(writerResult);
assertEquals(indexedRecordList.size(), writerResult.totalCount);
verify(port, times(2)).updateList(any(UpdateListRequest.class));
assertEquals(indexedRecordList.size(), updatedRecordList.size());
}
use of com.netsuite.webservices.v2016_2.platform.core.RecordRef in project components by Talend.
the class NetSuiteOutputWriterTest method testDelete.
@Test
public void testDelete() throws Exception {
final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
final TypeDesc typeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RecordTypeEnum.OPPORTUNITY.getTypeName());
final TypeDesc refTypeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RefType.RECORD_REF.getTypeName());
properties.module.moduleName.setValue(typeDesc.getTypeName());
properties.module.action.setValue(OutputAction.DELETE);
final List<RecordRef> deletedRecordRefList = new ArrayList<>();
when(port.deleteList(any(DeleteListRequest.class))).then(new Answer<DeleteListResponse>() {
@Override
public DeleteListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
DeleteListRequest request = (DeleteListRequest) invocationOnMock.getArguments()[0];
DeleteListResponse response = new DeleteListResponse();
WriteResponseList writeResponseList = new WriteResponseList();
for (int i = 0; i < request.getBaseRef().size(); i++) {
RecordRef recordRef = (RecordRef) request.getBaseRef().get(i);
assertNotNull(recordRef);
assertNotNull(recordRef.getInternalId());
assertNotNull(recordRef.getType());
deletedRecordRefList.add(recordRef);
WriteResponse writeResponse = new WriteResponse();
writeResponse.setStatus(createSuccessStatus());
writeResponse.setBaseRef(recordRef);
writeResponseList.getWriteResponse().add(writeResponse);
}
response.setWriteResponseList(writeResponseList);
return response;
}
});
NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(RefType.RECORD_REF.getTypeName());
properties.module.main.schema.setValue(schema);
NetSuiteSink sink = new NetSuiteSinkImpl();
sink.initialize(mockTestFixture.getRuntimeContainer(), properties);
NetSuiteClientService<?> clientService = sink.getClientService();
NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
NetSuiteOutputWriter writer = (NetSuiteOutputWriter) writeOperation.createWriter(mockTestFixture.getRuntimeContainer());
writer.open(UUID.randomUUID().toString());
List<IndexedRecord> indexedRecordList = makeIndexedRecords(clientService, schema, new RecordRefComposer<>(refTypeDesc.getTypeClass()), 150);
for (IndexedRecord record : indexedRecordList) {
writer.write(record);
}
Result writerResult = writer.close();
assertNotNull(writerResult);
assertEquals(indexedRecordList.size(), writerResult.totalCount);
verify(port, times(2)).deleteList(any(DeleteListRequest.class));
assertEquals(indexedRecordList.size(), deletedRecordRefList.size());
}
use of com.netsuite.webservices.v2016_2.platform.core.RecordRef in project components by Talend.
the class NetSuiteOutputWriterIT method testAddCustomRecord.
@Test
public void testAddCustomRecord() throws Exception {
final NetSuiteClientService<NetSuitePortType> clientService = webServiceTestFixture.getClientService();
clientService.getMetaDataSource().setCustomizationEnabled(true);
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("customrecordqacomp_custom_recordtype");
properties.module.action.setValue(OutputAction.ADD);
NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
runtime.setClientFactory(clientFactory);
NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
Schema targetSchema = TestUtils.makeRecordSchema(schema, Arrays.asList("name", "custrecord79", "custrecord80"));
properties.module.main.schema.setValue(targetSchema);
Schema targetFlowSchema = dataSetRuntime.getSchemaForUpdateFlow(properties.module.moduleName.getValue(), targetSchema);
properties.module.flowSchema.schema.setValue(targetFlowSchema);
Schema targetRejectSchema = dataSetRuntime.getSchemaForUpdateReject(properties.module.moduleName.getValue(), targetSchema);
properties.module.rejectSchema.schema.setValue(targetRejectSchema);
GenericRecord indexedRecordToAdd = new GenericData.Record(targetSchema);
String testId = Long.toString(System.currentTimeMillis());
indexedRecordToAdd.put("Name", "Test Project " + testId);
indexedRecordToAdd.put("Custrecord79", "Test Project " + testId);
indexedRecordToAdd.put("Custrecord80", "0.1.0");
List<IndexedRecord> indexedRecordList = new ArrayList<>();
indexedRecordList.add(indexedRecordToAdd);
// Add records
NetSuiteSink sink = new NetSuiteSinkImpl();
sink.setClientFactory(clientFactory);
sink.initialize(container, properties);
NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
NetSuiteOutputWriter<?, CustomRecordRef> 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);
final List<CustomRecordRef> refList = new ArrayList<>(indexedRecordList.size());
for (NsWriteResponse<CustomRecordRef> response : writer.getWriteResponses()) {
CustomRecordRef recordRef = response.getRef();
refList.add(recordRef);
}
// Re-read updated records
List<NsReadResponse<CustomRecord>> readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<CustomRecord>>, NetSuitePortType>() {
@Override
public List<NsReadResponse<CustomRecord>> execute(NetSuitePortType port) throws Exception {
GetListRequest request = new GetListRequest();
request.getBaseRef().addAll(refList);
return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
}
});
int index = 0;
for (NsReadResponse<CustomRecord> readResponse : readResponseList) {
assertTrue(readResponse.getStatus().isSuccess());
GenericRecord inputRecord = (GenericRecord) indexedRecordList.get(index);
CustomRecord 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);
}
StringCustomFieldRef customFieldRef1 = (StringCustomFieldRef) customFieldRefMap.get("custrecord79");
assertNotNull(customFieldRef1);
assertEquals(inputRecord.get("Custrecord79"), customFieldRef1.getValue());
StringCustomFieldRef customFieldRef2 = (StringCustomFieldRef) customFieldRefMap.get("custrecord80");
assertNotNull(customFieldRef2);
assertEquals(inputRecord.get("Custrecord80"), customFieldRef2.getValue());
}
clientService.deleteList(refList);
}
use of com.netsuite.webservices.v2016_2.platform.core.RecordRef 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;
}
Aggregations