Search in sources :

Example 1 with NsRef

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);
    }
}
Also used : NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) GetCustomizationIdResult(com.netsuite.webservices.v2016_2.platform.core.GetCustomizationIdResult) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NsRef(org.talend.components.netsuite.client.NsRef) StopWatch(org.apache.commons.lang3.time.StopWatch) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) GetCustomizationIdRequest(com.netsuite.webservices.v2016_2.platform.messages.GetCustomizationIdRequest) CustomizationType(com.netsuite.webservices.v2016_2.platform.core.CustomizationType) GetCustomizationType(com.netsuite.webservices.v2016_2.platform.core.types.GetCustomizationType) CustomizationRef(com.netsuite.webservices.v2016_2.platform.core.CustomizationRef)

Example 2 with NsRef

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;
}
Also used : CustomFieldRefType(org.talend.components.netsuite.client.model.customfield.CustomFieldRefType) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) NsRef(org.talend.components.netsuite.client.NsRef)

Example 3 with NsRef

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;
}
Also used : RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) NsRef(org.talend.components.netsuite.client.NsRef) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo)

Example 4 with NsRef

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());
}
Also used : RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) CustomRecordRef(com.netsuite.webservices.test.platform.core.CustomRecordRef) NsRef(org.talend.components.netsuite.client.NsRef) Test(org.junit.Test)

Example 5 with NsRef

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;
}
Also used : Schema(org.apache.avro.Schema) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericData(org.apache.avro.generic.GenericData) NsRef(org.talend.components.netsuite.client.NsRef)

Aggregations

NsRef (org.talend.components.netsuite.client.NsRef)23 Test (org.junit.Test)7 CustomFieldRefType (org.talend.components.netsuite.client.model.customfield.CustomFieldRefType)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)4 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)4 Schema (org.apache.avro.Schema)3 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)3 CustomRecordRef (com.netsuite.webservices.test.platform.core.CustomRecordRef)2 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)2 CustomizationRef (com.netsuite.webservices.v2016_2.platform.core.CustomizationRef)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)2 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)2 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)2 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 CustomizationRef (com.netsuite.webservices.test.platform.core.CustomizationRef)1 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)1