org.apache.commons.beanutils.PropertyUtilsBean Java Examples

The following examples show how to use org.apache.commons.beanutils.PropertyUtilsBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommChange.java    From charging_pile_cloud with MIT License 6 votes vote down vote up
/**
 * 将javabean实体类转为map类型,然后返回一个map类型的值
 * 
 * @param obj
 * @return
 */
public static SortedMap<String, String> beanToMap(Object obj) {
    SortedMap<String, String> params = new TreeMap<String, String>();
    try {
        PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
        PropertyDescriptor[] descriptors = propertyUtilsBean.getPropertyDescriptors(obj);
        for (int i = 0; i < descriptors.length; i++) {
            String name = descriptors[i].getName();
            if (!"class".equals(name)) {
                params.put(name,
                        (String) (propertyUtilsBean.getNestedProperty(obj, name) == null ? null
                                : propertyUtilsBean.getNestedProperty(obj, name)));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return params;
}
 
Example #2
Source File: BeanConfigurator.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
public static void loadBean(HierarchicalConfiguration context, Object beanObject, ConvertUtilsBean converter)   
{
	PropertyUtilsBean beanUtils = new PropertyUtilsBean(); 
	
	PropertyDescriptor[] descriptors = beanUtils.getPropertyDescriptors(beanObject);

	try
	{
		for ( PropertyDescriptor descr : descriptors )
		{
			//check that setter exists
			if ( descr.getWriteMethod() != null )
			{
				String value = context.getString(descr.getName());

                   if(converter.lookup(descr.getPropertyType()) != null) {
                       BeanUtils.setProperty(beanObject, descr.getName(), converter.convert(value, descr.getPropertyType()));
                   }
			}
		}
	}
	catch ( Exception e )
	{
		throw new EPSCommonException(e);
	}
}
 
Example #3
Source File: Input.java    From red5-io with Apache License 2.0 6 votes vote down vote up
protected Type getPropertyType(Object instance, String propertyName) {
    try {
        if (instance != null) {
            Field field = instance.getClass().getField(propertyName);
            return field.getGenericType();
        } else {
            // instance is null for anonymous class, use default type
        }
    } catch (NoSuchFieldException e1) {
        try {
            BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
            PropertyUtilsBean propertyUtils = beanUtilsBean.getPropertyUtils();
            PropertyDescriptor propertyDescriptor = propertyUtils.getPropertyDescriptor(instance, propertyName);
            return propertyDescriptor.getReadMethod().getGenericReturnType();
        } catch (Exception e2) {
            // nothing
        }
    } catch (Exception e) {
        // ignore other exceptions
    }
    // return Object class type by default
    return Object.class;
}
 
Example #4
Source File: SenderMonitorAdapter.java    From iaf with Apache License 2.0 6 votes vote down vote up
public void addNonDefaultAttribute(XmlBuilder senderXml, ISender sender, String attribute) {
	try {
		PropertyUtilsBean pub = new PropertyUtilsBean();

		if (pub.isReadable(sender,attribute) && pub.isWriteable(sender,attribute)) {
			String value = BeanUtils.getProperty(sender,attribute);

			Object defaultSender;
			Class[] classParm = null;
			Object[] objectParm = null;

			Class cl = sender.getClass();
			java.lang.reflect.Constructor co = cl.getConstructor(classParm);
			defaultSender = co.newInstance(objectParm);

			String defaultValue = BeanUtils.getProperty(defaultSender,attribute);				
			if (value!=null && !value.equals(defaultValue)) {
				senderXml.addAttribute(attribute,value);
			}
		}
	} catch (Exception e) {
		log.error("cannot retrieve attribute ["+attribute+"] from sender ["+ClassUtils.nameOf(sender)+"]");
	}
}
 
Example #5
Source File: ServiceStorageHelper.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
public static void convertServiceSettingsToMap(Map<String, String> params, IServiceSettings serviceSettings) {
    ConvertUtilsBean converter = new ConvertUtilsBean();
    PropertyUtilsBean beanUtils = new PropertyUtilsBean();
    PropertyDescriptor[] descriptors = beanUtils.getPropertyDescriptors(serviceSettings);

    for (PropertyDescriptor descr : descriptors) {
        //check that setter exists
        try {
            if (descr.getWriteMethod() != null) {
                Object value = BeanUtils.getProperty(serviceSettings, descr.getName());
                params.put(descr.getName(), converter.convert(value));
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}
 
Example #6
Source File: RecommendationService.java    From mapr-music with Apache License 2.0 6 votes vote down vote up
private AlbumDto albumToDto(Album album) {

        AlbumDto albumDto = new AlbumDto();
        PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
        try {
            propertyUtilsBean.copyProperties(albumDto, album);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("Can not create album Data Transfer Object", e);
        }

        String slug = slugService.getSlugForAlbum(album);
        albumDto.setSlug(slug);

        if (album.getArtists() != null && !album.getArtists().isEmpty()) {

            List<ArtistDto> artistDtoList = album.getArtists().stream()
                    .map(this::artistShortInfoToDto)
                    .collect(toList());

            albumDto.setArtistList(artistDtoList);
        }

        return albumDto;
    }
 
Example #7
Source File: EditClusterPage.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
                                                                                                      throws Exception {
    long clusterId = 0;
    try {
        clusterId = Long.parseLong(request.getParameter("clusterId").trim());
    } catch (Exception e) {
        throw new IllegalArgumentException("parameter 'clusterId' is invalid:" + request.getParameter("clusterId"));
    }
    ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId);
    Map<String, Object> clusterMap = new PropertyUtilsBean().describe(cluster);
    clusterMap.remove("class");
    clusterMap.remove("name");
    clusterMap.remove("deployDesc");

    clusterMap.put("name", CobarStringUtil.htmlEscapedString(cluster.getName()));
    clusterMap.put("deployDesc", CobarStringUtil.htmlEscapedString(cluster.getDeployDesc()));
    return new ModelAndView("m_editCluster",
        new FluenceHashMap<String, Object>().putKeyValue("cluster", clusterMap));
}
 
Example #8
Source File: ArtistService.java    From mapr-music with Apache License 2.0 6 votes vote down vote up
private Artist dtoToArtist(ArtistDto artistDto) {
    Artist artist = new Artist();
    PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
    try {
        propertyUtilsBean.copyProperties(artist, artistDto);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        throw new RuntimeException("Can not create Artist from Data Transfer Object", e);
    }

    if (artistDto.getAlbums() != null) {
        List<Album.ShortInfo> albums = artistDto.getAlbums().stream()
                .map(this::albumDtoToShortInfo)
                .collect(Collectors.toList());
        artist.setAlbums(albums);
    }

    if (artistDto.getBeginDateDay() != null) {
        artist.setBeginDate(new ODate(artistDto.getBeginDateDay()));
    }

    if (artistDto.getEndDateDay() != null) {
        artist.setEndDate(new ODate(artistDto.getEndDateDay()));
    }

    return artist;
}
 
Example #9
Source File: ArtistService.java    From mapr-music with Apache License 2.0 6 votes vote down vote up
private ArtistDto artistToDto(Artist artist) {
    ArtistDto artistDto = new ArtistDto();
    PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
    try {
        propertyUtilsBean.copyProperties(artistDto, artist);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        throw new RuntimeException("Can not create artist Data Transfer Object", e);
    }

    String slug = slugService.getSlugForArtist(artist);
    artistDto.setSlug(slug);

    if (artist.getBeginDate() != null) {
        artistDto.setBeginDateDay(artist.getBeginDate().toDate());
    }

    if (artist.getEndDate() != null) {
        artistDto.setEndDateDay(artist.getEndDate().toDate());
    }

    return artistDto;
}
 
Example #10
Source File: UserService.java    From mapr-music with Apache License 2.0 5 votes vote down vote up
private UserDto userToDto(User user) {

        UserDto userDto = new UserDto();
        PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
        try {
            propertyUtilsBean.copyProperties(userDto, user);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("Can not create user Data Transfer Object", e);
        }

        userDto.setUsername(user.getId());

        return userDto;
    }
 
Example #11
Source File: AbstractSettingsProxy.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public AbstractSettingsProxy(ICommonSettings settings) {
    this.settings = settings;
    PropertyUtilsBean beanUtils = new PropertyUtilsBean();
    PropertyDescriptor[] array = beanUtils.getPropertyDescriptors(this.settings);

    this.descriptors = new HashMap<>();
    for (PropertyDescriptor propertyDescriptor : array) {
        if (propertyDescriptor.getReadMethod() != null && propertyDescriptor.getWriteMethod() != null) {
            descriptors.put(propertyDescriptor.getName(), propertyDescriptor);
        }
    }
}
 
Example #12
Source File: UserService.java    From mapr-music with Apache License 2.0 5 votes vote down vote up
private User dtoToUser(UserDto userDto) {

        User user = new User();
        PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
        try {
            propertyUtilsBean.copyProperties(user, userDto);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("Can not create user from Data Transfer Object", e);
        }

        user.setId(userDto.getUsername());

        return user;
    }
 
Example #13
Source File: WrapCopier.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
protected WrapCopier(PropertyUtilsBean propertyUtilsBean, Class<T> origClass, Class<W> destClass,
		List<String> copyFields, List<String> eraseFields, boolean ignoreNull) {
	this.propertyUtilsBean = propertyUtilsBean;
	this.origClass = origClass;
	this.destClass = destClass;
	if (ListTools.isNotEmpty(copyFields)) {
		this.copyFields = copyFields;
	}
	if (ListTools.isNotEmpty(eraseFields)) {
		this.eraseFields = eraseFields;
	}
	this.ignoreNull = ignoreNull;
}
 
Example #14
Source File: JsonBodyVerificationBuilder.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
private Closure<Object> returnReferencedEntries(
		TestSideRequestTemplateModel templateModel) {
	return MapConverter.fromFunction(entry -> {
		if (!(entry instanceof String) || templateModel == null) {
			return entry;
		}
		String entryAsString = (String) entry;
		if (this.templateProcessor.containsTemplateEntry(entryAsString)
				&& !this.templateProcessor
						.containsJsonPathTemplateEntry(entryAsString)) {
			// TODO: HANDLEBARS LEAKING VIA request.
			String justEntry = minus(entryAsString,
					contractTemplate.escapedOpeningTemplate());
			justEntry = minus(justEntry, contractTemplate.openingTemplate());
			justEntry = minus(justEntry, contractTemplate.escapedClosingTemplate());
			justEntry = minus(justEntry, contractTemplate.closingTemplate());
			justEntry = minus(justEntry, FROM_REQUEST_PREFIX);
			if (FROM_REQUEST_BODY.equalsIgnoreCase(justEntry)) {
				// the body should be transformed by standard mechanism
				return contractTemplate.escapedOpeningTemplate() + FROM_REQUEST_PREFIX
						+ "escapedBody" + contractTemplate.escapedClosingTemplate();
			}
			try {
				Object result = new PropertyUtilsBean().getProperty(templateModel,
						justEntry);
				// Path from the Test model is an object and we'd like to return its
				// String representation
				if (FROM_REQUEST_PATH.equals(justEntry)) {
					return result.toString();
				}
				return result;
			}
			catch (Exception ignored) {
				return entry;
			}
		}
		return entry;
	});
}
 
Example #15
Source File: MetaAttribute.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
public Object getValue(Object dataObject) {
	PropertyUtilsBean utils = BeanUtilsBean.getInstance().getPropertyUtils();
	try {
		return utils.getNestedProperty(dataObject, getName());
	}
	catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
		throw new IllegalStateException("cannot access field " + getName() + " for " + dataObject.getClass().getName(), e);
	}
}
 
Example #16
Source File: MetaAttribute.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
public void setValue(Object dataObject, Object value) {
	PropertyUtilsBean utils = BeanUtilsBean.getInstance().getPropertyUtils();
	try {
		utils.setNestedProperty(dataObject, getName(), value);
	}
	catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
		throw new IllegalStateException("cannot access field " + getName() + " for " + dataObject.getClass().getName(), e);
	}
}
 
Example #17
Source File: MetaDataObjectProviderBase.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
protected void createAttributes(T meta) {
	Class<?> implClass = meta.getImplementationClass();
	PropertyUtilsBean utils = BeanUtilsBean.getInstance().getPropertyUtils();
	PropertyDescriptor[] descriptors = utils.getPropertyDescriptors(implClass);
	for (PropertyDescriptor desc : descriptors) {
		if (desc.getReadMethod().getDeclaringClass() != implClass)
			continue; // contained in super type

		createAttribute(meta, desc);
	}
	
	// 
}
 
Example #18
Source File: CobarNodeInstantPerfValueAjax.java    From tddl5 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked" })
private List<Map<String, Object>> listDatanode(AjaxParams params) {
    CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId());
    if (!perfAccesser.checkConnection()) {
        return null;
    }
    PropertyUtilsBean util = new PropertyUtilsBean();
    List<DataNodesStatus> list = perfAccesser.listDataNodes();
    ;
    if (null != list) {
        ListSortUtil.sortDataNodesByPoolName(list);
    }
    List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
    for (DataNodesStatus c : list) {
        Map<String, Object> map = null;
        try {
            map = util.describe(c);
        } catch (Exception e1) {
            throw new RuntimeException(e1);
        }
        map.remove("class");
        map.remove("executeCount");
        map.put("executeCount", FormatUtil.formatNumber(c.getExecuteCount()));
        map.remove("recoveryTime");
        if (-1 != c.getRecoveryTime()) {
            map.put("recoveryTime", FormatUtil.formatTime(c.getRecoveryTime() * 1000, 2));
        } else {
            map.put("recoveryTime", c.getRecoveryTime());
        }
        returnList.add(map);
    }
    return returnList;
}
 
Example #19
Source File: MClusterListScreen.java    From tddl5 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
                                                                                                      throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    List<ClusterDO> list = xmlAccesser.getClusterDAO().listAllCluster();
    List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>();
    ListSortUtil.sortClusterBySortId(list);
    PropertyUtilsBean util = new PropertyUtilsBean();
    for (ClusterDO e : list) {

        int count = xmlAccesser.getCobarDAO().getCobarList(e.getId(), ConstantDefine.ACTIVE).size();
        count += xmlAccesser.getCobarDAO().getCobarList(e.getId(), ConstantDefine.IN_ACTIVE).size();

        Map<String, Object> map;
        try {
            map = util.describe(e);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        map.remove("class");
        map.remove("name");
        map.remove("deployDesc");

        map.put("name", CobarStringUtil.htmlEscapedString(e.getName()));
        map.put("deployContact", CobarStringUtil.htmlEscapedString(e.getDeployContact()));
        map.put("cobarNum", count);
        clusterList.add(map);
    }
    return new ModelAndView("m_clusterList", new FluenceHashMap<String, Object>().putKeyValue("clusterList",
        clusterList).putKeyValue("user", user));

}
 
Example #20
Source File: MCobarListScreen.java    From tddl5 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked" })
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
                                                                                                      throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    long clusterId = Long.parseLong(request.getParameter("clusterId"));
    ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId);
    List<CobarDO> cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId);
    List<Map<String, Object>> cobarViewList = null;
    if (null != cobarList) {
        ListSortUtil.sortCobarByName(cobarList);
        cobarViewList = new ArrayList<Map<String, Object>>();
        PropertyUtilsBean util = new PropertyUtilsBean();
        for (CobarDO c : cobarList) {
            Map<String, Object> map = util.describe(c);
            map.remove("class");
            map.remove("name");
            map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
            cobarViewList.add(map);
        }
    }
    Map<String, Object> clusterView = new HashMap<String, Object>();
    clusterView.put("id", cluster.getId());
    clusterView.put("name", CobarStringUtil.htmlEscapedString(cluster.getName()));

    return new ModelAndView("m_cobarList", new FluenceHashMap<String, Object>().putKeyValue("cobarList",
        cobarViewList)
        .putKeyValue("user", user)
        .putKeyValue("cluster", clusterView));

}
 
Example #21
Source File: ReflectionMap.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
public ReflectionMap(Object bean) {
    if (ObjectUtils.isNull(bean)) {
        throw new IllegalArgumentException("This cannot wrap a null object");
    }
    this.bean = bean;
    this.propertyUtilsBean = new PropertyUtilsBean(); // create our own beanUtilsBean to avoid struts injection of KNS classes
}
 
Example #22
Source File: PojoPlugin.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public static void initBeanUtils() {
    // begin Kuali Foundation modification
    ConvertUtilsBean convUtils = new ConvertUtilsBean();
    PropertyUtilsBean propUtils = new PojoPropertyUtilsBean();
    BeanUtilsBean pojoBeanUtils = new BeanUtilsBean(convUtils, propUtils);

    BeanUtilsBean.setInstance(pojoBeanUtils);
    logger.fine("Initialized BeanUtilsBean with " + pojoBeanUtils);
    // end Kuali Foundation modification
}
 
Example #23
Source File: RecommendationService.java    From mapr-music with Apache License 2.0 5 votes vote down vote up
private ArtistDto artistShortInfoToDto(Artist.ShortInfo artistShortInfo) {

        ArtistDto artistDto = new ArtistDto();
        PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
        try {
            propertyUtilsBean.copyProperties(artistDto, artistShortInfo);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("Can not create artist Data Transfer Object", e);
        }

        return artistDto;
    }
 
Example #24
Source File: BeanConfigurator.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public static void saveBean(HierarchicalConfiguration context, Object beanObject)
{
	ConvertUtilsBean converter = new ConvertUtilsBean();
	
	PropertyUtilsBean beanUtils = new PropertyUtilsBean(); 
	
	PropertyDescriptor[] descriptors = beanUtils.getPropertyDescriptors(beanObject);

	try
	{
		for ( PropertyDescriptor descr : descriptors )
		{
			//check that setter exists
			if ( descr.getWriteMethod() != null )
			{
				Object value = BeanUtils.getProperty(beanObject, descr.getName());
				
				context.setProperty(descr.getName(), converter.convert(value));
			}
		}
	}
	catch ( Exception e )
	{
		throw new EPSCommonException(e);
	}
	
}
 
Example #25
Source File: BeanConfigurator.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public static void copyBean(Object beanOrig, Object beanClone)
{
	PropertyUtilsBean beanUtils = new PropertyUtilsBean();
	
	try
	{
		beanUtils.copyProperties(beanClone, beanOrig);
	}
	catch ( Exception e )
	{
		throw new EPSCommonException(e);
	}
	
}
 
Example #26
Source File: ServiceStorageHelper.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public static void convertMapToServiceSettings(IServiceSettings serviceSettings, Map<String, String> params) {
    ConvertUtilsBean converter = new ConvertUtilsBean();
    PropertyUtilsBean beanUtils = new PropertyUtilsBean();
    PropertyDescriptor[] descriptors = beanUtils.getPropertyDescriptors(serviceSettings);

    converter.register(new SailfishURIConverter(), SailfishURI.class);
    converter.register(true, false, 0);

    for(PropertyDescriptor descriptor : descriptors) {
        if(descriptor.getWriteMethod() == null) {
            continue;
        }

        String name = descriptor.getName();
        String value = params.get(name);

        if(value == null) {
            continue;
        }

        try {
            BeanUtils.setProperty(serviceSettings, name, converter.convert(value, descriptor.getPropertyType()));
        } catch(Exception e) {
            throw new EPSCommonException(String.format("Failed to set setting '%s' to: %s", name, value), e);
        }
    }
}
 
Example #27
Source File: AlbumService.java    From mapr-music with Apache License 2.0 5 votes vote down vote up
private AlbumDto albumToDto(Album album) {

        AlbumDto albumDto = new AlbumDto();
        PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
        try {
            propertyUtilsBean.copyProperties(albumDto, album);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("Can not create album Data Transfer Object", e);
        }

        String slug = slugService.getSlugForAlbum(album);
        albumDto.setSlug(slug);

        if (album.getTrackList() != null && !album.getTrackList().isEmpty()) {

            List<TrackDto> trackDtoList = album.getTrackList().stream()
                    .map(this::trackToDto)
                    .collect(toList());

            albumDto.setTrackList(trackDtoList);
        }

        if (album.getArtists() != null && !album.getArtists().isEmpty()) {

            List<ArtistDto> artistDtoList = album.getArtists().stream()
                    .map(this::artistShortInfoToDto)
                    .collect(toList());

            albumDto.setArtistList(artistDtoList);
        }

        if (album.getReleasedDate() != null) {
            albumDto.setReleasedDateDay(album.getReleasedDate().toDate());
        }

        return albumDto;
    }
 
Example #28
Source File: AlbumService.java    From mapr-music with Apache License 2.0 5 votes vote down vote up
private TrackDto trackToDto(Track track) {

        TrackDto trackDto = new TrackDto();
        PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
        try {
            propertyUtilsBean.copyProperties(trackDto, track);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("Can not create track Data Transfer Object", e);
        }

        return trackDto;
    }
 
Example #29
Source File: AlbumService.java    From mapr-music with Apache License 2.0 5 votes vote down vote up
private Track dtoToTrack(TrackDto trackDto) {

        Track track = new Track();
        PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
        try {
            propertyUtilsBean.copyProperties(track, trackDto);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("Can not create track from Data Transfer Object", e);
        }

        return track;
    }
 
Example #30
Source File: AlbumService.java    From mapr-music with Apache License 2.0 5 votes vote down vote up
private Album dtoToAlbum(AlbumDto albumDto) {

        Album album = new Album();
        PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
        try {
            propertyUtilsBean.copyProperties(album, albumDto);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("Can not create album Data Transfer Object", e);
        }

        if (albumDto.getTrackList() != null && !albumDto.getTrackList().isEmpty()) {

            List<Track> trackList = albumDto.getTrackList().stream()
                    .map(this::dtoToTrack)
                    .collect(toList());

            album.setTrackList(trackList);
        }

        if (albumDto.getArtistList() != null && !albumDto.getArtistList().isEmpty()) {

            List<Artist.ShortInfo> artistShortInfoList = albumDto.getArtistList().stream()
                    .map(this::artistDtoToShortInfo)
                    .collect(toList());

            album.setArtists(artistShortInfoList);
        }

        if (albumDto.getReleasedDateDay() != null) {
            album.setReleasedDate(new ODate(albumDto.getReleasedDateDay()));
        }

        return album;
    }