View Javadoc
1   /*
2    * Copyright 2014 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl;
20  
21  import java.util.Comparator;
22  import java.util.Date;
23  import java.util.Locale;
24  import java.util.function.Function;
25  
26  import org.springframework.stereotype.Service;
27  
28  import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartyRoleMember;
29  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.PartyGhantChartManager;
30  
31  /**
32   * The Class PartyGhantChartManagerImpl.
33   */
34  @Service
35  public final class PartyGhantChartManagerImpl extends AbstractGhantChartManagerImpl<ViewRiksdagenPartyRoleMember>
36  		implements PartyGhantChartManager {
37  
38  	/**
39  	 * Instantiates a new party ghant chart manager impl.
40  	 */
41  	public PartyGhantChartManagerImpl() {
42  		super();
43  	}
44  
45  	@Override
46  	protected Comparator<ViewRiksdagenPartyRoleMember> getComparator() {
47  		return (o1, o2) -> o1.getFromDate().compareTo(o2.getFromDate());
48  	}
49  
50  	@Override
51  	protected Function<ViewRiksdagenPartyRoleMember, String> getRoleMapping() {
52  		return new RoleMapping();
53  	}
54  
55  	@Override
56  	protected StepMapping<ViewRiksdagenPartyRoleMember> getStepMapping() {
57  		return new StepMapping<ViewRiksdagenPartyRoleMember>() {
58  
59  			@Override
60  			public Date getFromDate(final ViewRiksdagenPartyRoleMember t) {
61  				return t.getFromDate();
62  			}
63  
64  			@Override
65  			public Date getToDate(final ViewRiksdagenPartyRoleMember t) {
66  				return t.getToDate();
67  			}
68  
69  			@Override
70  			public String getRoleCode(final ViewRiksdagenPartyRoleMember t) {
71  				return t.getRoleCode();
72  			}
73  
74  			@Override
75  			public String getOrg(final ViewRiksdagenPartyRoleMember t) {
76  				return t.getDetail();
77  			}
78  
79  			@Override
80  			public String getParty(final ViewRiksdagenPartyRoleMember t) {
81  				return t.getParty();
82  			}
83  
84  			@Override
85  			public String getBackgroundColor(final ViewRiksdagenPartyRoleMember t) {
86  				String color;
87  
88  				if (t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("vice")) {
89  					color = "A8D999";
90  				} else if (t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("partiledare")
91  						|| t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("språkrör")
92  						|| t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("partisekreterare")) {
93  					color = "3271c8";
94  				} else {
95  					color = "0eab76";
96  				}
97  
98  				return color;
99  			}
100 
101 			@Override
102 			public Object getFirstName(final ViewRiksdagenPartyRoleMember t) {
103 				return t.getFirstName();
104 			}
105 
106 			@Override
107 			public Object getLastName(final ViewRiksdagenPartyRoleMember t) {
108 				return t.getLastName();
109 			}
110 
111 		};
112 	}
113 
114 	/**
115 	 * The Class RoleMapping.
116 	 */
117 	private static final class RoleMapping implements Function<ViewRiksdagenPartyRoleMember, String> {
118 
119 		@Override
120 		public String apply(final ViewRiksdagenPartyRoleMember t) {
121 			return t.getRoleCode();
122 		}
123 	}
124 
125 }