Search in sources :

Example 1 with RecordRef

use of com.netsuite.webservices.platform.core.RecordRef in project tdi-studio-se by Talend.

the class NetsuiteManagement_CXF method initializeStub.

public void initializeStub() throws Exception {
    URL wsdl_locationUrl = this.getClass().getResource("/wsdl/netsuite.wsdl");
    QName serviceQname = new QName("urn:platform_2014_2.webservices.netsuite.com", "NetSuiteService");
    NetSuiteService service = new NetSuiteService(wsdl_locationUrl, serviceQname);
    NetSuitePortType port = service.getNetSuitePort();
    BindingProvider provider = (BindingProvider) port;
    Map<String, Object> requestContext = provider.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, _url);
    Preferences preferences = new Preferences();
    preferences.setDisableMandatoryCustomFieldValidation(Boolean.FALSE);
    preferences.setWarningAsError(Boolean.FALSE);
    preferences.setIgnoreReadOnlyFields(Boolean.TRUE);
    preferences.setDisableMandatoryCustomFieldValidation(Boolean.TRUE);
    SearchPreferences searchPreferences = new SearchPreferences();
    searchPreferences.setPageSize(this._pageSize);
    searchPreferences.setBodyFieldsOnly(Boolean.valueOf(false));
    RecordRef role = new RecordRef();
    role.setInternalId(this._role);
    Passport passport = new Passport();
    passport.setEmail(this._email);
    passport.setPassword(this._pwd);
    passport.setRole(role);
    passport.setAccount(this._account);
    // Get the webservices domain for your account
    GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
    dataCenterRequest.setAccount(this._account);
    DataCenterUrls urls = null;
    GetDataCenterUrlsResponse reponse = port.getDataCenterUrls(dataCenterRequest);
    if (reponse != null && reponse.getGetDataCenterUrlsResult() != null) {
        urls = reponse.getGetDataCenterUrlsResult().getDataCenterUrls();
    }
    if (urls == null) {
        throw new Exception("Can't get a correct webservice domain! Please check your configuration or try to run again.");
    }
    String wsDomain = urls.getWebservicesDomain();
    String endpoint = wsDomain.concat(new URL(this._url).getPath());
    requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    List<Header> list = (List<Header>) requestContext.get(Header.HEADER_LIST);
    if (list == null) {
        list = new ArrayList<Header>();
        requestContext.put(Header.HEADER_LIST, list);
    }
    Header searchPreferences_header = new Header(new QName("urn:messages_2014_2.platform.webservices.netsuite.com", "searchPreferences"), searchPreferences, new JAXBDataBinding(searchPreferences.getClass()));
    Header preferences_header = new Header(new QName("urn:messages_2014_2.platform.webservices.netsuite.com", "preferences"), preferences, new JAXBDataBinding(preferences.getClass()));
    list.add(searchPreferences_header);
    list.add(preferences_header);
    LoginRequest request = new LoginRequest();
    request.setPassport(passport);
    port.login(request);
    this._port = port;
    Arrays.asList(new String[] { "", "", "" });
}
Also used : GetDataCenterUrlsResponse(com.netsuite.webservices.platform.messages.GetDataCenterUrlsResponse) QName(javax.xml.namespace.QName) RecordRef(com.netsuite.webservices.platform.core.RecordRef) ListOrRecordRef(com.netsuite.webservices.platform.core.ListOrRecordRef) DataCenterUrls(com.netsuite.webservices.platform.core.DataCenterUrls) BindingProvider(javax.xml.ws.BindingProvider) LoginRequest(com.netsuite.webservices.platform.messages.LoginRequest) URL(java.net.URL) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) SOAPException(javax.xml.soap.SOAPException) ParseException(java.text.ParseException) JAXBException(javax.xml.bind.JAXBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) NetSuitePortType(com.netsuite.webservices.platform.NetSuitePortType) SearchPreferences(com.netsuite.webservices.platform.messages.SearchPreferences) Passport(com.netsuite.webservices.platform.core.Passport) Header(org.apache.cxf.headers.Header) NetSuiteService(com.netsuite.webservices.platform.NetSuiteService) GetDataCenterUrlsRequest(com.netsuite.webservices.platform.messages.GetDataCenterUrlsRequest) List(java.util.List) SearchCustomFieldList(com.netsuite.webservices.platform.core.SearchCustomFieldList) ArrayList(java.util.ArrayList) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) SearchPreferences(com.netsuite.webservices.platform.messages.SearchPreferences) Preferences(com.netsuite.webservices.platform.messages.Preferences)

Example 2 with RecordRef

use of com.netsuite.webservices.platform.core.RecordRef in project tdi-studio-se by Talend.

the class NetsuiteManagement_CXF method getSearchField.

private Object getSearchField(Class<?> searchClass, List<String> searchValue, String searchFieldName, String searchOperator) throws DatatypeConfigurationException {
    Object criteria = null;
    Method getFieldMethod = findMethod(searchClass, "get" + searchFieldName);
    String searchType = getFieldMethod.getReturnType().getSimpleName();
    if (searchType.equals("SearchStringField")) {
        SearchStringField searchArgumentType = new SearchStringField();
        if (searchValue != null && searchValue.size() != 0) {
            searchArgumentType.setSearchValue(searchValue.get(0));
        }
        searchArgumentType.setOperator(SearchStringFieldOperator.fromValue(searchOperator));
        criteria = searchArgumentType;
    } else if (searchType.equals("SearchLongField")) {
        SearchLongField searchArgumentType = new SearchLongField();
        if (searchValue != null && searchValue.size() != 0) {
            searchArgumentType.setSearchValue(Long.valueOf(Long.parseLong(searchValue.get(0))));
            if (searchValue.size() > 1) {
                searchArgumentType.setSearchValue2(Long.valueOf(Long.parseLong(searchValue.get(1))));
            }
        }
        searchArgumentType.setOperator(SearchLongFieldOperator.fromValue(searchOperator));
        criteria = searchArgumentType;
    } else if (searchType.equals("SearchDateField")) {
        SearchDateField searchArgumentType = new SearchDateField();
        if (searchValue != null && searchValue.size() != 0) {
            Calendar calValue = Calendar.getInstance();
            String dateFormat = "yyyy-MM-dd";
            String timeFormat = "HH:mm:ss";
            String format = dateFormat + " " + timeFormat;
            if (searchValue.get(0).length() == dateFormat.length()) {
                format = dateFormat;
            }
            if (searchValue.get(0).length() == timeFormat.length()) {
                searchValue.set(0, new SimpleDateFormat(dateFormat).format(calValue.getTime()) + " " + searchValue.get(0));
            }
            DateFormat df = new SimpleDateFormat(format);
            try {
                calValue.setTime(df.parse(searchValue.get(0)));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            XMLGregorianCalendar xts = DatatypeFactory.newInstance().newXMLGregorianCalendar();
            xts.setYear(calValue.get(Calendar.YEAR));
            xts.setMonth(calValue.get(Calendar.MONTH) + 1);
            xts.setDay(calValue.get(Calendar.DAY_OF_MONTH));
            xts.setHour(calValue.get(Calendar.HOUR_OF_DAY));
            xts.setMinute(calValue.get(Calendar.MINUTE));
            xts.setSecond(calValue.get(Calendar.SECOND));
            xts.setMillisecond(calValue.get(Calendar.MILLISECOND));
            xts.setTimezone(calValue.get(Calendar.ZONE_OFFSET) / 60000);
            searchArgumentType.setSearchValue(xts);
            if (searchValue.size() > 1) {
                try {
                    calValue.setTime(df.parse(searchValue.get(1)));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                XMLGregorianCalendar xts2 = DatatypeFactory.newInstance().newXMLGregorianCalendar();
                xts2.setYear(calValue.get(Calendar.YEAR));
                xts2.setMonth(calValue.get(Calendar.MONTH) + 1);
                xts2.setDay(calValue.get(Calendar.DAY_OF_MONTH));
                xts2.setHour(calValue.get(Calendar.HOUR_OF_DAY));
                xts2.setMinute(calValue.get(Calendar.MINUTE));
                xts2.setSecond(calValue.get(Calendar.SECOND));
                xts2.setMillisecond(calValue.get(Calendar.MILLISECOND));
                xts2.setTimezone(calValue.get(Calendar.ZONE_OFFSET) / 60000);
                searchArgumentType.setSearchValue2(xts2);
            }
        }
        searchArgumentType.setOperator(SearchDateFieldOperator.fromValue(searchOperator));
        criteria = searchArgumentType;
    } else if (searchType.equals("SearchBooleanField")) {
        SearchBooleanField searchArgumentType = new SearchBooleanField();
        searchArgumentType.setSearchValue(Boolean.valueOf(searchValue.get(0)));
        criteria = searchArgumentType;
    } else if (searchType.equals("SearchDoubleField")) {
        SearchDoubleField searchArgumentType = new SearchDoubleField();
        if (searchValue != null && searchValue.size() != 0) {
            searchArgumentType.setSearchValue(Double.valueOf(Double.parseDouble(searchValue.get(0))));
            if (searchValue.size() > 1) {
                searchArgumentType.setSearchValue2(Double.valueOf(Double.parseDouble(searchValue.get(1))));
            }
        }
        searchArgumentType.setOperator(SearchDoubleFieldOperator.fromValue(searchOperator));
        criteria = searchArgumentType;
    } else if (searchType.equals("SearchMultiSelectField")) {
        SearchMultiSelectField searchArgumentType = new SearchMultiSelectField();
        List<RecordRef> values = searchArgumentType.getSearchValue();
        for (int i = 0; i < searchValue.size(); i++) {
            RecordRef ref = new RecordRef();
            ref.setName(searchValue.get(i));
            ref.setInternalId(searchValue.get(i));
            ref.setExternalId(null);
            ref.setType(null);
            values.add(ref);
        }
        searchArgumentType.setOperator(SearchMultiSelectFieldOperator.fromValue(searchOperator));
        criteria = searchArgumentType;
    } else if (searchType.equals("SearchEnumMultiSelectField")) {
        SearchEnumMultiSelectField searchArgumentType = new SearchEnumMultiSelectField();
        searchArgumentType.getSearchValue().addAll(searchValue);
        searchArgumentType.setOperator(SearchEnumMultiSelectFieldOperator.fromValue(searchOperator));
        criteria = searchArgumentType;
    } else if (searchType.equals("String[]")) {
        SearchEnumMultiSelectField searchArgumentType = new SearchEnumMultiSelectField();
        searchArgumentType.getSearchValue().addAll(searchValue);
        searchArgumentType.setOperator(SearchEnumMultiSelectFieldOperator.fromValue(searchOperator));
        criteria = searchArgumentType;
    } else {
        throw new IllegalArgumentException("Unsupported search field type: " + searchType);
    }
    return criteria;
}
Also used : SearchDateField(com.netsuite.webservices.platform.core.SearchDateField) Calendar(java.util.Calendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) RecordRef(com.netsuite.webservices.platform.core.RecordRef) ListOrRecordRef(com.netsuite.webservices.platform.core.ListOrRecordRef) Method(java.lang.reflect.Method) SearchLongField(com.netsuite.webservices.platform.core.SearchLongField) SearchMultiSelectField(com.netsuite.webservices.platform.core.SearchMultiSelectField) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SearchBooleanField(com.netsuite.webservices.platform.core.SearchBooleanField) SearchDoubleField(com.netsuite.webservices.platform.core.SearchDoubleField) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SearchStringField(com.netsuite.webservices.platform.core.SearchStringField) List(java.util.List) SearchCustomFieldList(com.netsuite.webservices.platform.core.SearchCustomFieldList) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) SearchEnumMultiSelectField(com.netsuite.webservices.platform.core.SearchEnumMultiSelectField)

Example 3 with RecordRef

use of com.netsuite.webservices.platform.core.RecordRef in project tdi-studio-se by Talend.

the class NetsuiteManagement_CXF method get.

public Record get(String entitytype, String id) throws Exception {
    String typeName = TalendComponentGenerator.toInitialLower(TalendComponentGenerator.getEntityClass(entitytype).getSimpleName());
    RecordRef ref = new RecordRef();
    ref.setInternalId(id);
    ref.setType(RecordType.fromValue(typeName));
    GetRequest getRequest = new GetRequest();
    getRequest.setBaseRef(ref);
    GetResponse getResponse = getPort().get(getRequest);
    if (getResponse.getReadResponse().getStatus().isIsSuccess()) {
        return getResponse.getReadResponse().getRecord();
    }
    return null;
}
Also used : GetRequest(com.netsuite.webservices.platform.messages.GetRequest) RecordRef(com.netsuite.webservices.platform.core.RecordRef) ListOrRecordRef(com.netsuite.webservices.platform.core.ListOrRecordRef) GetResponse(com.netsuite.webservices.platform.messages.GetResponse)

Example 4 with RecordRef

use of com.netsuite.webservices.platform.core.RecordRef in project tdi-studio-se by Talend.

the class NetsuiteManagement_CXF method delete.

public void delete(String entitytype, String id) throws Exception {
    String typeName = TalendComponentGenerator.toInitialLower(Class.forName(entitytype).getSimpleName());
    RecordRef recordRef = new RecordRef();
    recordRef.setType(RecordType.fromValue(typeName));
    recordRef.setInternalId(id);
    DeleteRequest deleteRequest = new DeleteRequest();
    deleteRequest.setBaseRef(recordRef);
    DeleteResponse response = getPort().delete(deleteRequest);
    if (!response.getWriteResponse().getStatus().isIsSuccess()) {
        throw new NetsuiteException(getErrorCodes(response.getWriteResponse().getStatus()), getErrorMessages(response.getWriteResponse().getStatus()));
    }
}
Also used : DeleteResponse(com.netsuite.webservices.platform.messages.DeleteResponse) RecordRef(com.netsuite.webservices.platform.core.RecordRef) ListOrRecordRef(com.netsuite.webservices.platform.core.ListOrRecordRef) DeleteRequest(com.netsuite.webservices.platform.messages.DeleteRequest)

Aggregations

ListOrRecordRef (com.netsuite.webservices.platform.core.ListOrRecordRef)4 RecordRef (com.netsuite.webservices.platform.core.RecordRef)4 SearchCustomFieldList (com.netsuite.webservices.platform.core.SearchCustomFieldList)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NetSuitePortType (com.netsuite.webservices.platform.NetSuitePortType)1 NetSuiteService (com.netsuite.webservices.platform.NetSuiteService)1 DataCenterUrls (com.netsuite.webservices.platform.core.DataCenterUrls)1 Passport (com.netsuite.webservices.platform.core.Passport)1 SearchBooleanField (com.netsuite.webservices.platform.core.SearchBooleanField)1 SearchDateField (com.netsuite.webservices.platform.core.SearchDateField)1 SearchDoubleField (com.netsuite.webservices.platform.core.SearchDoubleField)1 SearchEnumMultiSelectField (com.netsuite.webservices.platform.core.SearchEnumMultiSelectField)1 SearchLongField (com.netsuite.webservices.platform.core.SearchLongField)1 SearchMultiSelectField (com.netsuite.webservices.platform.core.SearchMultiSelectField)1 SearchStringField (com.netsuite.webservices.platform.core.SearchStringField)1 DeleteRequest (com.netsuite.webservices.platform.messages.DeleteRequest)1 DeleteResponse (com.netsuite.webservices.platform.messages.DeleteResponse)1 GetDataCenterUrlsRequest (com.netsuite.webservices.platform.messages.GetDataCenterUrlsRequest)1