Search in sources :

Example 6 with CustomizationRef

use of com.netsuite.webservices.v2016_2.platform.core.CustomizationRef 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

CustomizationRef (com.netsuite.webservices.v2016_2.platform.core.CustomizationRef)4 HashMap (java.util.HashMap)4 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)3 CustomizationRef (com.netsuite.webservices.v2014_2.platform.core.CustomizationRef)2 RecordType (com.netsuite.webservices.v2014_2.platform.core.types.RecordType)2 CustomizationType (com.netsuite.webservices.v2016_2.platform.core.CustomizationType)2 GetCustomizationIdResult (com.netsuite.webservices.v2016_2.platform.core.GetCustomizationIdResult)2 RecordType (com.netsuite.webservices.v2016_2.platform.core.types.RecordType)2 GetCustomizationIdRequest (com.netsuite.webservices.v2016_2.platform.messages.GetCustomizationIdRequest)2 GetListRequest (com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)2 Map (java.util.Map)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)2 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)2 NsRef (org.talend.components.netsuite.client.NsRef)2 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)1 BaseRef (com.netsuite.webservices.v2014_2.platform.core.BaseRef)1 CustomizationRefList (com.netsuite.webservices.v2014_2.platform.core.CustomizationRefList)1 CustomizationType (com.netsuite.webservices.v2014_2.platform.core.CustomizationType)1