View Javadoc

1   /*
2    * Copyright 2011-2012 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
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   * @author Joe Swanson <joseswan@umich.edu>
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  }