use of com.netsuite.webservices.v2016_2.platform.messages.GetListRequest 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.messages.GetListRequest 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);
}
use of com.netsuite.webservices.v2016_2.platform.messages.GetListRequest in project components by Talend.
the class NetSuiteMockTestBase method mockGetListRequestResults.
protected <T extends Record> void mockGetListRequestResults(final List<T> records) throws Exception {
final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
when(port.getList(any(GetListRequest.class))).then(new Answer<GetListResponse>() {
@Override
public GetListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
GetListRequest request = (GetListRequest) invocationOnMock.getArguments()[0];
GetListResponse response = new GetListResponse();
ReadResponseList readResponseList = new ReadResponseList();
int count = request.getBaseRef().size();
for (int i = 0; i < count; i++) {
ReadResponse readResponse = new ReadResponse();
T record = records != null ? records.get(i) : null;
if (record != null) {
readResponse.setStatus(createSuccessStatus());
} else {
readResponse.setStatus(createNotFoundStatus());
}
readResponse.setRecord(record);
readResponseList.getReadResponse().add(readResponse);
}
response.setReadResponseList(readResponseList);
return response;
}
});
}
use of com.netsuite.webservices.v2016_2.platform.messages.GetListRequest in project components by Talend.
the class NetSuiteMockTestBase method mockCustomizationRequestResults.
protected void mockCustomizationRequestResults(final Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customFieldSpecs) throws Exception {
final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
when(port.getCustomizationId(any(GetCustomizationIdRequest.class))).then(new Answer<GetCustomizationIdResponse>() {
@Override
public GetCustomizationIdResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
GetCustomizationIdRequest request = (GetCustomizationIdRequest) invocationOnMock.getArguments()[0];
CustomizationType customizationType = request.getCustomizationType();
GetCustomizationIdResult result = new GetCustomizationIdResult();
result.setCustomizationRefList(new CustomizationRefList());
result.setStatus(createSuccessStatus());
Map<String, CustomizationRef> customizationRefMap = createCustomFieldCustomizationRefs(customFieldSpecs);
for (String scriptId : customFieldSpecs.keySet()) {
RecordType recordType = RecordType.fromValue(customizationType.getGetCustomizationType().value());
CustomizationRef customizationRef = customizationRefMap.get(scriptId);
if (recordType == customizationRef.getType()) {
result.getCustomizationRefList().getCustomizationRef().add(customizationRef);
}
}
result.setTotalRecords(result.getCustomizationRefList().getCustomizationRef().size());
GetCustomizationIdResponse response = new GetCustomizationIdResponse();
response.setGetCustomizationIdResult(result);
return response;
}
});
when(port.getList(any(GetListRequest.class))).then(new Answer<GetListResponse>() {
@Override
public GetListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
GetListRequest request = (GetListRequest) invocationOnMock.getArguments()[0];
ReadResponseList readResponseList = new ReadResponseList();
readResponseList.setStatus(createSuccessStatus());
Map<String, CustomFieldType> customFieldTypeMap = createCustomFieldTypes(customFieldSpecs);
for (BaseRef ref : request.getBaseRef()) {
if (ref instanceof CustomizationRef) {
CustomizationRef customizationRef = (CustomizationRef) ref;
if (customFieldTypeMap.containsKey(customizationRef.getScriptId())) {
CustomFieldType fieldType = customFieldTypeMap.get(customizationRef.getScriptId());
ReadResponse readResponse = new ReadResponse();
readResponse.setRecord(fieldType);
readResponse.setStatus(createSuccessStatus());
readResponseList.getReadResponse().add(readResponse);
}
}
}
GetListResponse response = new GetListResponse();
response.setReadResponseList(readResponseList);
return response;
}
});
}
use of com.netsuite.webservices.v2016_2.platform.messages.GetListRequest in project components by Talend.
the class CustomMetaDataRetrieverImpl method retrieveCustomizations.
public List<?> retrieveCustomizations(final List<NsRef> nsCustomizationRefs) throws NetSuiteException {
if (nsCustomizationRefs.isEmpty()) {
return Collections.emptyList();
}
final List<CustomizationRef> customizationRefs = new ArrayList<>(nsCustomizationRefs.size());
for (NsRef nsCustomizationRef : nsCustomizationRefs) {
CustomizationRef customizationRef = new CustomizationRef();
customizationRef.setType(RecordType.fromValue(nsCustomizationRef.getType()));
customizationRef.setScriptId(nsCustomizationRef.getScriptId());
customizationRef.setInternalId(nsCustomizationRef.getInternalId());
customizationRefs.add(customizationRef);
}
List<NsReadResponse<Record>> result = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Record>>, NetSuitePortType>() {
@Override
public List<NsReadResponse<Record>> execute(NetSuitePortType port) throws Exception {
logger.debug("Retrieving customizations: {}", nsCustomizationRefs.size());
StopWatch stopWatch = new StopWatch();
try {
stopWatch.start();
final GetListRequest request = new GetListRequest();
request.getBaseRef().addAll(customizationRefs);
return toNsReadResponseList(port.getList(request).getReadResponseList());
} finally {
stopWatch.stop();
logger.debug("Retrieved customizations: {}, {}", nsCustomizationRefs.size(), stopWatch);
}
}
});
if (!result.isEmpty()) {
List<Record> customizations = new ArrayList<>(result.size());
for (NsReadResponse<Record> response : result) {
if (response.getStatus().isSuccess()) {
customizations.add(response.getRecord());
} else {
throw new NetSuiteException("Retrieving of customization was not successful: " + response.getStatus());
}
}
return customizations;
} else {
return Collections.emptyList();
}
}
Aggregations