Search in sources :

Example 21 with NsRef

use of org.talend.components.netsuite.client.NsRef in project components by Talend.

the class NetSuiteMockTestBase method createCustomFieldCustomizationRefs.

protected Map<String, NsRef> createCustomFieldCustomizationRefs(Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customFieldSpecs) throws Exception {
    Map<String, NsRef> map = new HashMap<>();
    for (CustomFieldSpec<RecordType, CustomizationFieldType> spec : customFieldSpecs.values()) {
        NsRef ref = new NsRef(RefType.CUSTOMIZATION_REF);
        ref.setScriptId(spec.getScriptId());
        ref.setInternalId(spec.getInternalId());
        ref.setType(spec.getRecordType().value());
        map.put(ref.getScriptId(), ref);
    }
    return map;
}
Also used : CustomizationFieldType(com.netsuite.webservices.test.setup.customization.types.CustomizationFieldType) RecordType(com.netsuite.webservices.test.platform.core.types.RecordType) CustomRecordType(com.netsuite.webservices.test.setup.customization.CustomRecordType) HashMap(java.util.HashMap) NsRef(org.talend.components.netsuite.client.NsRef)

Example 22 with NsRef

use of org.talend.components.netsuite.client.NsRef in project components by Talend.

the class NetSuiteMockTestBase method createCustomRecordCustomizationRef.

protected NsRef createCustomRecordCustomizationRef(CustomRecordType customRecordType) throws Exception {
    NsRef ref = new NsRef(RefType.CUSTOMIZATION_REF);
    ref.setScriptId(customRecordType.getScriptId());
    ref.setInternalId(customRecordType.getInternalId());
    ref.setType(TestRecordTypeEnum.CUSTOM_RECORD_TYPE.getType());
    ref.setName(customRecordType.getRecordName());
    return ref;
}
Also used : NsRef(org.talend.components.netsuite.client.NsRef)

Example 23 with NsRef

use of org.talend.components.netsuite.client.NsRef 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();
    }
}
Also used : ArrayList(java.util.ArrayList) NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NsReadResponse(org.talend.components.netsuite.client.NsReadResponse) NsRef(org.talend.components.netsuite.client.NsRef) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) StopWatch(org.apache.commons.lang3.time.StopWatch) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) CustomizationRef(com.netsuite.webservices.v2016_2.platform.core.CustomizationRef) ArrayList(java.util.ArrayList) NetSuiteClientServiceImpl.toNsReadResponseList(org.talend.components.netsuite.v2016_2.client.NetSuiteClientServiceImpl.toNsReadResponseList) List(java.util.List) Record(com.netsuite.webservices.v2016_2.platform.core.Record) GetListRequest(com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)

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