Search in sources :

Example 41 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project components by Talend.

the class MarketoSOAPClient method getMultipleLeads.

/**
 * In getMultipleLeadsJSON you have to add includeAttributes base fields like Email. Otherwise, they return null from
 * API. WTF ?!? It's like that...
 */
@Override
public MarketoRecordResult getMultipleLeads(TMarketoInputProperties parameters, String offset) {
    LOG.debug("MarketoSOAPClient.getMultipleLeadsJSON with {}", parameters.leadSelectorSOAP.getValue());
    Schema schema = parameters.schemaInput.schema.getValue();
    Map<String, String> mappings = parameters.mappingInput.getNameMappingsForMarketo();
    int bSize = parameters.batchSize.getValue();
    // 
    // Create Request
    // 
    ParamsGetMultipleLeads request = new ParamsGetMultipleLeads();
    // 
    if (parameters.leadSelectorSOAP.getValue().equals(LeadKeySelector)) {
        LOG.info("LeadKeySelector - Key type:  {} with value : {}.", parameters.leadKeyTypeSOAP.getValue().toString(), parameters.leadKeyValues.getValue());
        LeadKeySelector keySelector = new LeadKeySelector();
        keySelector.setKeyType(valueOf(parameters.leadKeyTypeSOAP.getValue().toString()));
        ArrayOfString aos = new ArrayOfString();
        String[] keys = parameters.leadKeyValues.getValue().split("(,|;|\\s)");
        for (String s : keys) {
            LOG.debug("Adding leadKeyValue : {}.", s);
            aos.getStringItems().add(s);
        }
        keySelector.setKeyValues(aos);
        request.setLeadSelector(keySelector);
    } else if (parameters.leadSelectorSOAP.getValue().equals(LastUpdateAtSelector)) {
        LOG.debug("LastUpdateAtSelector - since {} to  {}.", parameters.oldestUpdateDate.getValue(), parameters.latestUpdateDate.getValue());
        LastUpdateAtSelector leadSelector = new LastUpdateAtSelector();
        try {
            DatatypeFactory factory = newInstance();
            Date oldest = MarketoUtils.parseDateString(parameters.oldestUpdateDate.getValue());
            Date latest = MarketoUtils.parseDateString(parameters.latestUpdateDate.getValue());
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(latest);
            JAXBElement<XMLGregorianCalendar> until = objectFactory.createLastUpdateAtSelectorLatestUpdatedAt(factory.newXMLGregorianCalendar(gc));
            GregorianCalendar since = new GregorianCalendar();
            since.setTime(oldest);
            leadSelector.setOldestUpdatedAt(factory.newXMLGregorianCalendar(since));
            leadSelector.setLatestUpdatedAt(until);
            request.setLeadSelector(leadSelector);
        } catch (ParseException | DatatypeConfigurationException e) {
            LOG.error("Error for LastUpdateAtSelector : {}.", e.getMessage());
            throw new ComponentException(e);
        }
    } else // 
    if (parameters.leadSelectorSOAP.getValue().equals(StaticListSelector)) {
        LOG.info("StaticListSelector - List type : {} with value : {}.", parameters.listParam.getValue(), parameters.listParamListName.getValue());
        StaticListSelector staticListSelector = new StaticListSelector();
        if (parameters.listParam.getValue().equals(STATIC_LIST_NAME)) {
            JAXBElement<String> listName = objectFactory.createStaticListSelectorStaticListName(parameters.listParamListName.getValue());
            staticListSelector.setStaticListName(listName);
        } else {
            // you can find listId by examining the URL : https://app-abq.marketo.com/#ST29912B2
            // #ST29912B2 :
            // #ST -> Static list identifier
            // 29912 -> our list FIELD_ID !
            // B2 -> tab in the UI
            JAXBElement<Integer> listId = objectFactory.createStaticListSelectorStaticListId(// 
            parameters.listParamListId.getValue());
            staticListSelector.setStaticListId(listId);
        }
        request.setLeadSelector(staticListSelector);
    } else {
        // Duh !
        LOG.error("Unknown LeadSelector : {}.", parameters.leadSelectorSOAP.getValue());
        throw new ComponentException(new Exception("Incorrect parameter value for LeadSelector : " + parameters.leadSelectorSOAP.getValue()));
    }
    // attributes
    // curiously we have to put some basic fields like Email in attributes if we have them feed...
    ArrayOfString attributes = new ArrayOfString();
    for (String s : mappings.values()) {
        attributes.getStringItems().add(s);
    }
    attributes.getStringItems().add("Company");
    request.setIncludeAttributes(attributes);
    // batchSize : another curious behavior... Don't seem to work properly with leadKeySelector...
    // nevertheless, the server automatically adjust batch size according request.
    JAXBElement<Integer> batchSize = new ObjectFactory().createParamsGetMultipleLeadsBatchSize(bSize);
    request.setBatchSize(batchSize);
    // stream position
    if (offset != null && !offset.isEmpty()) {
        request.setStreamPosition(new ObjectFactory().createParamsGetMultipleLeadsStreamPosition(offset));
    }
    // 
    // 
    // Request execution
    // 
    SuccessGetMultipleLeads result = null;
    MarketoRecordResult mkto = new MarketoRecordResult();
    try {
        result = getPort().getMultipleLeads(request, header);
    } catch (Exception e) {
        LOG.error("Lead not found : {}.", e.getMessage());
        mkto.setSuccess(false);
        mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, e.getMessage())));
        return mkto;
    }
    if (result == null || result.getResult().getReturnCount() == 0) {
        LOG.debug(MESSAGE_REQUEST_RETURNED_0_MATCHING_LEADS);
        mkto.setSuccess(true);
        mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, MESSAGE_NO_LEADS_FOUND)));
        mkto.setRecordCount(0);
        mkto.setRemainCount(0);
        return mkto;
    } else {
        String streamPos = result.getResult().getNewStreamPosition();
        int recordCount = result.getResult().getReturnCount();
        int remainCount = result.getResult().getRemainingCount();
        // Process results
        List<IndexedRecord> results = convertLeadRecords(result.getResult().getLeadRecordList().getValue().getLeadRecords(), schema, mappings);
        return new MarketoRecordResult(true, streamPos, recordCount, remainCount, results);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayOfString(com.marketo.mktows.ArrayOfString) StaticListSelector(com.marketo.mktows.StaticListSelector) StaticListSelector(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector.StaticListSelector) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) ObjectFactory(com.marketo.mktows.ObjectFactory) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) LeadKeySelector(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector.LeadKeySelector) LeadKeySelector(com.marketo.mktows.LeadKeySelector) LastUpdateAtSelector(com.marketo.mktows.LastUpdateAtSelector) LastUpdateAtSelector(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector.LastUpdateAtSelector) DatatypeFactory(javax.xml.datatype.DatatypeFactory) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) JAXBElement(javax.xml.bind.JAXBElement) ParamsGetMultipleLeads(com.marketo.mktows.ParamsGetMultipleLeads) Date(java.util.Date) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) WebServiceException(javax.xml.ws.WebServiceException) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ParseException(java.text.ParseException) JAXBException(javax.xml.bind.JAXBException) ComponentException(org.talend.components.api.exception.ComponentException) MalformedURLException(java.net.MalformedURLException) ArrayOfString(com.marketo.mktows.ArrayOfString) ComponentException(org.talend.components.api.exception.ComponentException) SuccessGetMultipleLeads(com.marketo.mktows.SuccessGetMultipleLeads)

Example 42 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project cxf by apache.

the class Client method createComplexType.

private NestedComplexType createComplexType() {
    NestedComplexType complexType = new NestedComplexType();
    complexType.setVarString("#12345ABc");
    complexType.setVarUByte((short) 255);
    complexType.setVarUnsignedLong(new BigInteger("13691056728"));
    complexType.setVarFloat(Float.MAX_VALUE);
    complexType.setVarQName(new QName("http://cxf.apache.org", "return"));
    try {
        complexType.setVarStruct(getSimpleStruct());
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
    complexType.setVarEnum(ColourEnum.RED);
    byte[] binary = new byte[256];
    for (int jdx = 0; jdx < 256; jdx++) {
        binary[jdx] = (byte) (jdx - 128);
    }
    complexType.setVarHexBinary(binary);
    complexType.setVarBase64Binary(binary);
    return complexType;
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) QName(javax.xml.namespace.QName) NestedComplexType(org.apache.cxf.cxf.performance.types.NestedComplexType) BigInteger(java.math.BigInteger)

Example 43 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project cxf by apache.

the class Client method initTestData.

public void initTestData() {
    NestedComplexType complexType = new NestedComplexType();
    complexType.setVarString("#12345ABc");
    complexType.setVarUByte(Short.MAX_VALUE);
    complexType.setVarUnsignedLong(new BigInteger("13691056728"));
    complexType.setVarFloat(Float.MAX_VALUE);
    complexType.setVarQName(new QName("return", "return"));
    try {
        complexType.setVarStruct(getSimpleStruct());
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
    complexType.setVarEnum(ColourEnum.RED);
    byte[] binary = new byte[1024];
    for (int idx = 0; idx < 4; idx++) {
        for (int jdx = 0; jdx < 256; jdx++) {
            binary[idx * 256 + jdx] = (byte) (jdx - 128);
        }
    }
    complexType.setVarBase64Binary(binary);
    complexType.setVarHexBinary(binary);
    for (int i = 0; i < packetSize; i++) {
        complexTypeSeq.getItem().add(complexType);
    }
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) QName(javax.xml.namespace.QName) NestedComplexType(org.apache.cxf.performance.complex_type.types.NestedComplexType) BigInteger(java.math.BigInteger)

Example 44 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project cxf by apache.

the class AbstractSearchConditionParser method convertToTemporal.

private Temporal convertToTemporal(Class<? extends Temporal> valueType, String value) throws SearchParseException {
    Message m = JAXRSUtils.getCurrentMessage();
    Temporal obj = InjectionUtils.createFromParameterHandler(value, valueType, valueType, new Annotation[] {}, m);
    if (obj != null) {
        return obj;
    }
    try {
        if (LocalTime.class.isAssignableFrom(valueType)) {
            return LocalTime.parse(value);
        } else if (LocalDate.class.isAssignableFrom(valueType)) {
            return LocalDate.from(convertToDefaultDate(value).toInstant().atZone(ZoneId.systemDefault()));
        } else if (LocalDateTime.class.isAssignableFrom(valueType)) {
            return convertTo(value, SearchUtils.DEFAULT_DATETIME_FORMAT, Boolean.FALSE, LocalDateTime::parse);
        } else if (OffsetTime.class.isAssignableFrom(valueType)) {
            return OffsetTime.parse(value);
        } else if (OffsetDateTime.class.isAssignableFrom(valueType)) {
            return convertTo(value, SearchUtils.DEFAULT_OFFSET_DATETIME_FORMAT, Boolean.TRUE, OffsetDateTime::parse);
        } else if (ZonedDateTime.class.isAssignableFrom(valueType)) {
            return convertTo(value, SearchUtils.DEFAULT_ZONE_DATETIME_FORMAT, Boolean.TRUE, ZonedDateTime::parse);
        } else {
            return convertToDefaultDate(value).toInstant();
        }
    } catch (ParseException | DateTimeParseException e) {
        // is that duration?
        try {
            Date now = new Date();
            DatatypeFactory.newInstance().newDuration(value).addTo(now);
            return LocalDateTime.from(now.toInstant().atZone(ZoneId.systemDefault()));
        } catch (DatatypeConfigurationException e1) {
            throw new SearchParseException(e1);
        } catch (IllegalArgumentException e1) {
            throw new SearchParseException("Can parse " + value + " neither as date nor duration", e);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Message(org.apache.cxf.message.Message) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) DateTimeParseException(java.time.format.DateTimeParseException) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Temporal(java.time.temporal.Temporal) OffsetDateTime(java.time.OffsetDateTime) ZonedDateTime(java.time.ZonedDateTime) OffsetTime(java.time.OffsetTime) ParseException(java.text.ParseException) DateTimeParseException(java.time.format.DateTimeParseException)

Example 45 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project cxf by apache.

the class XsDateTimeFormat method parseObject.

public Object parseObject(String pString, ParsePosition pParsePosition) {
    if (pString == null) {
        throw new NullPointerException("The String argument must not be null.");
    }
    if (pParsePosition == null) {
        throw new NullPointerException("The ParsePosition argument must not be null.");
    }
    int offset = pParsePosition.getIndex();
    int idxSpc = pString.indexOf(' ', offset);
    int idxCom = pString.indexOf(',', offset);
    if (idxCom != -1 && idxCom < idxSpc) {
        idxSpc = idxCom;
    }
    final String newVal;
    if (idxSpc == -1) {
        newVal = pString.substring(offset);
    } else {
        newVal = pString.substring(offset, idxSpc);
    }
    DatatypeFactory factory;
    try {
        factory = DatatypeFactory.newInstance();
        XMLGregorianCalendar cal = factory.newXMLGregorianCalendar(newVal);
        pParsePosition.setIndex(idxSpc);
        return cal.toGregorianCalendar();
    } catch (DatatypeConfigurationException e) {
        pParsePosition.setErrorIndex(offset);
    }
    return null;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) DatatypeFactory(javax.xml.datatype.DatatypeFactory)

Aggregations

DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)56 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)35 GregorianCalendar (java.util.GregorianCalendar)33 DatatypeFactory (javax.xml.datatype.DatatypeFactory)20 Date (java.util.Date)18 BigInteger (java.math.BigInteger)6 ParseException (java.text.ParseException)6 JAXBException (javax.xml.bind.JAXBException)5 QName (javax.xml.namespace.QName)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ConverterException (ch.ehi.ili2db.converter.ConverterException)2 BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)2 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)2 NumericType (ch.interlis.ili2c.metamodel.NumericType)2 PrecisionDecimal (ch.interlis.ili2c.metamodel.PrecisionDecimal)2 IomObject (ch.interlis.iom.IomObject)2 ArrayOfString (com.marketo.mktows.ArrayOfString)2 LastUpdateAtSelector (com.marketo.mktows.LastUpdateAtSelector)2 File (java.io.File)2