use of org.talend.components.netsuite.client.NsRef in project components by Talend.
the class CustomMetaDataRetrieverImpl method retrieveCustomizationIds.
public List<NsRef> retrieveCustomizationIds(final BasicRecordType type) throws NetSuiteException {
GetCustomizationIdResult result = clientService.execute(new NetSuiteClientService.PortOperation<GetCustomizationIdResult, NetSuitePortType>() {
@Override
public GetCustomizationIdResult execute(NetSuitePortType port) throws Exception {
logger.debug("Retrieving customization IDs: {}", type.getType());
StopWatch stopWatch = new StopWatch();
try {
stopWatch.start();
final GetCustomizationIdRequest request = new GetCustomizationIdRequest();
CustomizationType customizationType = new CustomizationType();
customizationType.setGetCustomizationType(GetCustomizationType.fromValue(type.getType()));
request.setCustomizationType(customizationType);
return port.getCustomizationId(request).getGetCustomizationIdResult();
} finally {
stopWatch.stop();
logger.debug("Retrieved customization IDs: {}, {}", type.getType(), stopWatch);
}
}
});
if (result.getStatus().getIsSuccess()) {
List<NsRef> nsRefs;
if (result.getTotalRecords() > 0) {
final List<CustomizationRef> refs = result.getCustomizationRefList().getCustomizationRef();
nsRefs = new ArrayList<>(refs.size());
for (final CustomizationRef ref : refs) {
NsRef nsRef = new NsRef();
nsRef.setRefType(RefType.CUSTOMIZATION_REF);
nsRef.setScriptId(ref.getScriptId());
nsRef.setInternalId(ref.getInternalId());
nsRef.setType(ref.getType().value());
nsRef.setName(ref.getName());
nsRefs.add(nsRef);
}
} else {
nsRefs = Collections.emptyList();
}
return nsRefs;
} else {
throw new NetSuiteException("Retrieving of customizations was not successful: " + type);
}
}
use of org.talend.components.netsuite.client.NsRef in project components by Talend.
the class TestUtils method readCustomField.
public static CustomFieldDesc readCustomField(JsonNode node) {
String scriptId = node.get("scriptId").asText();
String internalId = node.get("internalId").asText();
String customizationType = node.get("customizationType").asText();
String type = node.get("valueType").asText();
NsRef ref = new NsRef();
ref.setRefType(RefType.CUSTOMIZATION_REF);
ref.setScriptId(scriptId);
ref.setInternalId(internalId);
ref.setType(customizationType);
CustomFieldRefType customFieldRefType = CustomFieldRefType.valueOf(type);
CustomFieldDesc fieldDesc = new CustomFieldDesc();
fieldDesc.setCustomFieldType(customFieldRefType);
fieldDesc.setCustomizationRef(ref);
fieldDesc.setName(scriptId);
fieldDesc.setValueType(NetSuiteDatasetRuntimeImpl.getCustomFieldValueClass(customFieldRefType));
fieldDesc.setNullable(true);
return fieldDesc;
}
use of org.talend.components.netsuite.client.NsRef in project components by Talend.
the class TestUtils method readCustomRecord.
public static CustomRecordTypeInfo readCustomRecord(BasicMetaData basicMetaData, JsonNode node) {
String scriptId = node.get("scriptId").asText();
String internalId = node.get("internalId").asText();
String customizationType = node.get("customizationType").asText();
String recordType = node.get("recordType").asText();
NsRef ref = new NsRef();
ref.setRefType(RefType.CUSTOMIZATION_REF);
ref.setScriptId(scriptId);
ref.setInternalId(internalId);
ref.setType(customizationType);
RecordTypeDesc recordTypeDesc = basicMetaData.getRecordType(recordType);
CustomRecordTypeInfo recordTypeInfo = new CustomRecordTypeInfo(scriptId, recordTypeDesc, ref);
return recordTypeInfo;
}
use of org.talend.components.netsuite.client.NsRef in project components by Talend.
the class NsRefTest method testRecordRef.
@Test
public void testRecordRef() {
NsRef ref1 = new NsRef(RefType.RECORD_REF);
ref1.setType(RecordType.ACCOUNT.value());
ref1.setInternalId("10001");
ref1.setExternalId(UUID.randomUUID().toString());
RecordRef recordRef = (RecordRef) ref1.toNativeRef(basicMetaData);
assertNotNull(recordRef);
assertEquals(RecordType.ACCOUNT, recordRef.getType());
assertEquals(ref1.getInternalId(), recordRef.getInternalId());
assertEquals(ref1.getExternalId(), recordRef.getExternalId());
NsRef ref2 = NsRef.fromNativeRef(recordRef);
assertNotNull(ref2);
assertEquals(RecordType.ACCOUNT.value(), ref2.getType());
assertEquals(recordRef.getInternalId(), ref2.getInternalId());
assertEquals(recordRef.getExternalId(), ref2.getExternalId());
}
use of org.talend.components.netsuite.client.NsRef in project components by Talend.
the class NetSuiteOutputWriter method createSuccessRecord.
/**
* Create record for outgoing {@code success} flow.
*
* @param response write response
* @param record indexed record which was written
* @return result record
*/
private IndexedRecord createSuccessRecord(NsWriteResponse<RefT> response, IndexedRecord record) {
NsRef ref = NsRef.fromNativeRef(response.getRef());
GenericData.Record targetRecord = new GenericData.Record(flowSchema);
for (Schema.Field field : schema.getFields()) {
Schema.Field targetField = flowSchema.getField(field.name());
if (targetField != null) {
Object value = record.get(field.pos());
targetRecord.put(targetField.name(), value);
}
}
Schema.Field internalIdField = NetSuiteDatasetRuntimeImpl.getNsFieldByName(flowSchema, "internalId");
if (internalIdField != null && targetRecord.get(internalIdField.pos()) == null) {
targetRecord.put(internalIdField.pos(), ref.getInternalId());
}
Schema.Field externalIdField = NetSuiteDatasetRuntimeImpl.getNsFieldByName(flowSchema, "externalId");
if (externalIdField != null && targetRecord.get(externalIdField.pos()) == null) {
targetRecord.put(externalIdField.pos(), ref.getExternalId());
}
if (ref.getRefType() == RefType.CUSTOMIZATION_REF) {
Schema.Field scriptIdField = NetSuiteDatasetRuntimeImpl.getNsFieldByName(flowSchema, "scriptId");
if (scriptIdField != null && targetRecord.get(scriptIdField.pos()) == null) {
targetRecord.put(scriptIdField.pos(), ref.getScriptId());
}
}
return targetRecord;
}
Aggregations