use of com.netsuite.webservices.v2014_2.platform.core.CustomizationRef in project components by Talend.
the class NetSuiteMockTestBase method createCustomFieldCustomizationRefs.
protected Map<String, CustomizationRef> createCustomFieldCustomizationRefs(Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customFieldSpecs) throws Exception {
Map<String, CustomizationRef> map = new HashMap<>();
for (CustomFieldSpec<RecordType, CustomizationFieldType> spec : customFieldSpecs.values()) {
CustomizationRef ref = new CustomizationRef();
ref.setScriptId(spec.getScriptId());
ref.setInternalId(spec.getInternalId());
ref.setType(spec.getRecordType());
map.put(ref.getScriptId(), ref);
}
return map;
}
use of com.netsuite.webservices.v2014_2.platform.core.CustomizationRef 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 com.netsuite.webservices.v2014_2.platform.core.CustomizationRef 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.v2014_2.platform.core.CustomizationRef in project components by Talend.
the class NetSuiteMockTestBase method createCustomFieldCustomizationRefs.
protected Map<String, CustomizationRef> createCustomFieldCustomizationRefs(Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customFieldSpecs) throws Exception {
Map<String, CustomizationRef> map = new HashMap<>();
for (CustomFieldSpec<RecordType, CustomizationFieldType> spec : customFieldSpecs.values()) {
CustomizationRef ref = new CustomizationRef();
ref.setScriptId(spec.getScriptId());
ref.setInternalId(spec.getInternalId());
ref.setType(spec.getRecordType());
map.put(ref.getScriptId(), ref);
}
return map;
}
use of com.netsuite.webservices.v2014_2.platform.core.CustomizationRef 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;
}
});
}
Aggregations