com.manywho.sdk.services.AbstractCollectionParser Maven / Gradle / Ivy
package com.manywho.sdk.services;
import com.github.fge.lambdas.Throwing;
import com.manywho.sdk.entities.ContentValueAware;
import com.manywho.sdk.entities.ObjectDataAware;
import com.manywho.sdk.entities.ValueAware;
import com.manywho.sdk.entities.run.elements.type.MObject;
import com.manywho.sdk.entities.run.elements.type.ObjectCollection;
import com.manywho.sdk.services.annotations.TypeElement;
import com.manywho.sdk.services.types.TypeParser;
import com.manywho.sdk.services.types.TypeUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @deprecated As of version 1.18.0, this way of parsing is deprecated and annotating actions
* with {@link com.manywho.sdk.services.annotations.Action} is the preferred way of parsing requests into beans
*/
@Deprecated
public abstract class AbstractCollectionParser {
protected TypeParser typeParser;
/**
* @deprecated As of version 1.18.0, this way of parsing is deprecated and annotating actions
* with {@link com.manywho.sdk.services.annotations.Action} is the preferred way of parsing requests into beans
*/
@Deprecated
public abstract T parse(ValueAware properties, Class tClass) throws Exception;
/**
* @deprecated As of version 1.18.0, this way of parsing is deprecated and annotating actions
* with {@link com.manywho.sdk.services.annotations.Action} is the preferred way of parsing requests into beans
*/
@Deprecated
public abstract T parse(ValueAware properties, String id, Class tClass) throws Exception;
protected void setListField(Field field, String annotationValue, ObjectDataAware properties, Object entity) throws Exception {
ObjectCollection nestedPropertyCollection = properties.getObjectData(annotationValue);
if (CollectionUtils.isNotEmpty(nestedPropertyCollection)) {
// Find the generic type of the field
Class> fieldClass = TypeUtils.getGenericType(field.getGenericType());
// If the field is annotated with @TypeElement, parse the incoming data using TypeParser
if (fieldClass.isAnnotationPresent(TypeElement.class)) {
field.set(entity, typeParser.parseList(nestedPropertyCollection, fieldClass));
} else {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy