1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.mobility.news.service.util;
16
17 import java.util.ArrayList;
18 import java.util.List;
19 import org.apache.commons.collections.CollectionUtils;
20 import org.apache.commons.collections.Transformer;
21 import org.kuali.mobility.news.entity.NewsArticleImpl;
22 import org.kuali.mobility.news.entity.NewsSource;
23 import org.kuali.mobility.news.entity.NewsSourceImpl;
24
25
26
27
28
29 public class NewsSourceTransform implements Transformer {
30
31 @Override
32 public NewsSourceImpl transform(Object obj) {
33 NewsSourceImpl proxy = null;
34
35 if (obj != null) {
36 if (obj instanceof NewsSourceImpl) {
37 proxy = (NewsSourceImpl) obj;
38 } else if (obj instanceof NewsSource) {
39 proxy = new NewsSourceImpl();
40 proxy.setActive(((NewsSource) obj).isActive());
41 proxy.setAuthor(((NewsSource) obj).getAuthor());
42 proxy.setDescription(((NewsSource) obj).getDescription());
43 proxy.setId(((NewsSource) obj).getId());
44 proxy.setName(((NewsSource) obj).getName());
45 proxy.setOrder(((NewsSource) obj).getOrder());
46 proxy.setParentId(((NewsSource) obj).getParentId());
47 proxy.setTitle(((NewsSource) obj).getTitle());
48 proxy.setUrl(((NewsSource) obj).getUrl());
49
50 List<NewsSourceImpl> children = new ArrayList<NewsSourceImpl>();
51 CollectionUtils.collect(((NewsSource) obj).getChildren(), new NewsSourceTransform(), children);
52 proxy.setChildren(children);
53
54 List<NewsArticleImpl> articles = new ArrayList<NewsArticleImpl>();
55 CollectionUtils.collect(((NewsSource) obj).getArticles(), new NewsArticleTransform(), articles);
56 proxy.setArticles(articles);
57
58 }
59 }
60
61 return proxy;
62 }
63 }