Search in sources :

Example 21 with TypeDesc

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

the class NetSuiteDatasetRuntimeImpl method getSchemaForUpdateFlow.

@Override
public Schema getSchemaForUpdateFlow(String typeName, Schema schema) {
    RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
    TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
    // We should check and add key fields:
    // internalId, externalId and scriptId (for custom record type)
    List<FieldDesc> fieldDescList = new ArrayList<>();
    Schema.Field internalIdField = getNsFieldByName(schema, "internalId");
    if (internalIdField == null) {
        FieldDesc fieldDesc = typeDesc.getField("internalId");
        fieldDescList.add(fieldDesc);
    }
    Schema.Field externalIdField = getNsFieldByName(schema, "externalId");
    if (externalIdField == null) {
        FieldDesc fieldDesc = typeDesc.getField("externalId");
        fieldDescList.add(fieldDesc);
    }
    if (recordTypeInfo instanceof CustomRecordTypeInfo) {
        Schema.Field scriptIdField = getNsFieldByName(schema, "scriptId");
        if (scriptIdField == null) {
            FieldDesc fieldDesc = typeDesc.getField("scriptId");
            if (fieldDesc != null) {
                fieldDescList.add(fieldDesc);
            }
        }
    }
    // Create schema fields for mandatory fields.
    List<Schema.Field> fields = new ArrayList<>();
    Schema.Field f;
    if (!fieldDescList.isEmpty()) {
        Schema schemaToAdd = inferSchemaForType(typeName, fieldDescList);
        for (Schema.Field sourceField : schemaToAdd.getFields()) {
            f = copyField(sourceField);
            f.addProp(SchemaConstants.TALEND_FIELD_GENERATED, "true");
            f.addProp(SchemaConstants.TALEND_IS_LOCKED, "true");
            fields.add(f);
        }
    }
    return extendSchema(schema, typeName + "_FLOW", fields);
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Schema(org.apache.avro.Schema) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 22 with TypeDesc

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

the class NetSuiteDatasetRuntimeImpl method getSchemaForDeleteFlow.

@Override
public Schema getSchemaForDeleteFlow(String typeName, Schema schema) {
    RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
    TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
    // We should check and add key fields:
    // internalId, externalId and scriptId (for custom record type)
    List<FieldDesc> fieldDescList = new ArrayList<>();
    Schema.Field internalIdField = getNsFieldByName(schema, "internalId");
    if (internalIdField == null) {
        FieldDesc fieldDesc = typeDesc.getField("internalId");
        fieldDescList.add(fieldDesc);
    }
    Schema.Field externalIdField = getNsFieldByName(schema, "externalId");
    if (externalIdField == null) {
        FieldDesc fieldDesc = typeDesc.getField("externalId");
        fieldDescList.add(fieldDesc);
    }
    if (recordTypeInfo instanceof CustomRecordTypeInfo) {
        Schema.Field scriptIdField = getNsFieldByName(schema, "scriptId");
        if (scriptIdField == null) {
            FieldDesc fieldDesc = typeDesc.getField("scriptId");
            if (fieldDesc != null) {
                fieldDescList.add(fieldDesc);
            }
        }
    }
    // Create schema fields for mandatory fields.
    List<Schema.Field> fields = new ArrayList<>();
    Schema.Field f;
    if (!fieldDescList.isEmpty()) {
        Schema schemaToAdd = inferSchemaForType(typeName, fieldDescList);
        for (Schema.Field sourceField : schemaToAdd.getFields()) {
            f = copyField(sourceField);
            f.addProp(SchemaConstants.TALEND_FIELD_GENERATED, "true");
            f.addProp(SchemaConstants.TALEND_IS_LOCKED, "true");
            fields.add(f);
        }
    }
    return extendSchema(schema, typeName + "_FLOW", fields);
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Schema(org.apache.avro.Schema) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 23 with TypeDesc

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

the class NetSuiteDatasetRuntimeImpl method getSearchInfo.

@Override
public SearchInfo getSearchInfo(String typeName) {
    try {
        final SearchRecordTypeDesc searchInfo = metaDataSource.getSearchRecordType(typeName);
        final TypeDesc searchRecordInfo = metaDataSource.getBasicMetaData().getTypeInfo(searchInfo.getSearchBasicClass());
        List<FieldDesc> fieldDescList = searchRecordInfo.getFields();
        List<SearchFieldInfo> fields = new ArrayList<>(fieldDescList.size());
        for (FieldDesc fieldDesc : fieldDescList) {
            SearchFieldInfo field = new SearchFieldInfo(fieldDesc.getName(), fieldDesc.getValueType());
            fields.add(field);
        }
        // Sort by display name in alphabetical order
        Collections.sort(fields, new Comparator<SearchFieldInfo>() {

            @Override
            public int compare(SearchFieldInfo o1, SearchFieldInfo o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        return new SearchInfo(searchRecordInfo.getTypeName(), fields);
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) SearchFieldInfo(org.talend.components.netsuite.schema.SearchFieldInfo) SearchInfo(org.talend.components.netsuite.schema.SearchInfo) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 24 with TypeDesc

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

the class NetSuiteDatasetRuntimeImpl method getSchemaForUpdate.

@Override
public Schema getSchemaForUpdate(String typeName) {
    try {
        final RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
        final TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
        List<FieldDesc> fieldDescList = new ArrayList<>(typeDesc.getFields());
        // Sort in alphabetical order
        Collections.sort(fieldDescList, FieldDescComparator.INSTANCE);
        Schema schema = inferSchemaForType(typeDesc.getTypeName(), fieldDescList);
        augmentSchemaWithCustomMetaData(metaDataSource, schema, recordTypeInfo, typeDesc.getFields());
        return schema;
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Schema(org.apache.avro.Schema) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 25 with TypeDesc

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

the class NetSuiteClientServiceTest method testDeleteList.

@Test
public void testDeleteList() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
    List<RecordRef> recordRefList = makeNsObjects(new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), typeDesc), 10);
    DeleteListResponse response = new DeleteListResponse();
    response.setWriteResponseList(createSuccessWriteResponseList(recordRefList.size()));
    when(port.deleteList(notNull(DeleteListRequest.class))).thenReturn(response);
    clientService.deleteList(recordRefList);
    verify(port, times(1)).login(notNull(LoginRequest.class));
    verify(port, times(1)).deleteList(notNull(DeleteListRequest.class));
    List<NsWriteResponse<RecordRef>> writeResponses = clientService.deleteList(null);
    assertTrue(writeResponses.isEmpty());
}
Also used : DeleteListRequest(com.netsuite.webservices.test.platform.messages.DeleteListRequest) DeleteListResponse(com.netsuite.webservices.test.platform.messages.DeleteListResponse) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) Test(org.junit.Test)

Aggregations

TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)48 Test (org.junit.Test)41 Schema (org.apache.avro.Schema)31 IndexedRecord (org.apache.avro.generic.IndexedRecord)23 ArrayList (java.util.ArrayList)14 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)13 LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)12 NetSuiteRuntime (org.talend.components.netsuite.NetSuiteRuntime)10 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)10 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)10 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)10 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)9 PurchaseOrder (com.netsuite.webservices.test.transactions.purchases.PurchaseOrder)8 NetSuiteWebServiceMockTestFixture.assertIndexedRecord (org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord)8 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)8 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)7 CustomRecord (com.netsuite.webservices.test.setup.customization.CustomRecord)7 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)6 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4