Project

General

Profile

« Previous | Next » 

Revision 33676

modular-ui property inspector

View differences:

modules/dnet-modular-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/ContainerPropertiesController.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import java.io.IOException;
4
import java.util.HashMap;
5
import java.util.Map;
6
import java.util.Map.Entry;
7
import java.util.Properties;
8

  
9
import javax.servlet.http.HttpServletRequest;
10
import javax.servlet.http.HttpServletResponse;
11

  
12
import org.apache.commons.logging.Log;
13
import org.apache.commons.logging.LogFactory;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.context.ResourceLoaderAware;
16
import org.springframework.core.io.Resource;
17
import org.springframework.core.io.ResourceLoader;
18
import org.springframework.core.io.support.ResourcePatternUtils;
19
import org.springframework.ui.ModelMap;
20

  
21
import com.google.common.collect.Maps;
22

  
23
import eu.dnetlib.conf.PropertyFetcher;
24
import eu.dnetlib.miscutils.collections.Pair;
25

  
26
public class ContainerPropertiesController extends ModuleEntryPoint implements ResourceLoaderAware {
27

  
28
	private static final Log log = LogFactory.getLog(ContainerPropertiesController.class);
29

  
30
	@Autowired
31
	private PropertyFetcher propertyFetcher;
32

  
33
	private Properties propertyFetcherProps;
34

  
35
	private ResourceLoader resourceLoader;
36

  
37
	@Override
38
	protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
39
		propertyFetcherProps = propertyFetcher.getProps();
40
		map.addAttribute("properties", fetchProperties());
41
	}
42

  
43
	private Map<String, Map<String, Pair<String, Boolean>>> fetchProperties() throws IOException {
44
		final Map<String, Map<String, Pair<String, Boolean>>> propertiesMap = Maps.newLinkedHashMap();
45
		// map structure: propertyKey | PropertyValue | Propertyfile| isChecked
46
		for (Resource res : ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath*:/eu/dnetlib/**/*.properties")) {
47
			Properties p = new Properties();
48
			p.load(res.getInputStream());
49

  
50
			for (Entry<Object, Object> e : p.entrySet()) {
51
				Map<String, Pair<String, Boolean>> propValues;
52
				if (propertiesMap.containsKey(e.getKey())) {
53
					propValues = propertiesMap.get(e.getKey());
54
				} else {
55
					propValues = new HashMap<String, Pair<String, Boolean>>();
56
				}
57

  
58
				Pair<String, Boolean> pair = new Pair<String, Boolean>(res.getFilename(), isChecked((String) e.getKey(), (String) e.getValue()));
59
				propValues.put((String) e.getValue(), pair);
60
				propertiesMap.put((String) e.getKey(), propValues);
61
			}
62
		}
63

  
64
		return propertiesMap;
65
	}
66

  
67
	private Boolean isChecked(final String prop, final String value) {
68
		String winningPropertyValue = propertyFetcherProps.getProperty(prop);
69
		if (value.equals(winningPropertyValue)) {
70
			return true;
71
		} else {
72
			return false;
73
		}
74
	}
75

  
76
	public ResourceLoader getResourceLoader() {
77
		return resourceLoader;
78
	}
79

  
80
	@Override
81
	public void setResourceLoader(final ResourceLoader resourceLoader) {
82
		this.resourceLoader = resourceLoader;
83
	}
84
}
modules/dnet-modular-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/views/ui/properties.st
1
$common/master( header={}, onLoad={}, body={
2
	<table class="table table-hover table-condensed small" style="table-layout: fixed; word-wrap: break-word;">
3
		$properties.keys:{prop|
4
			<tr>
5
				<th class="col-xs-3">$prop$</th>
6
				<td class="col-xs-9">
7
					$properties.(prop).keys:{value|
8
						$if(properties.(prop).(value).value)$
9
							<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
10
						$endif$
11
						<span>$value$</span> <span class="pull-right"><strong>$properties.(prop).(value).key$</strong></span> <br/>
12
					}$
13
				</td>
14
			</tr>
15
		}$
16
	</table>
17
})$
modules/dnet-modular-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/webContext-modular-ui.xml
57 57
		</property>
58 58
	</bean>
59 59
	
60
		<bean name="/ui/info.do"
60
	<bean name="/ui/info.do"
61 61
		class="eu.dnetlib.functionality.modular.ui.InfoController"
62 62
		p:menu="Container configuration details" p:title="Container configuration details"
63 63
		p:description="Container configuration details" p:group="Configuration"
......
73 73
		</property>
74 74
	</bean>
75 75
	
76
	<bean name="/ui/properties.do"
77
		class="eu.dnetlib.functionality.modular.ui.ContainerPropertiesController"
78
		p:menu="Container properties" p:title="Container properties"
79
		p:description="Container properties" p:group="Configuration"
80
		p:order="1"
81
		p:groupOrder="99" >
82
		<property name="permissionLevels">
83
			<set>
84
				<value>SUPER_ADMIN</value>
85
			</set>
86
		</property>
87
	</bean>
76 88
	
89
	
77 90
	<bean name="/ui/prepareShutdown.do"
78 91
		class="eu.dnetlib.functionality.modular.ui.PrepareShutdownController"
79 92
		p:menu="Prepare for shutdown" p:title="Prepare for shutdown"
modules/dnet-modular-ui/trunk/pom.xml
32 32
		</dependency>
33 33
		<dependency>
34 34
			<groupId>eu.dnetlib</groupId>
35
			<artifactId>dnet-runtime</artifactId>
36
			<version>[1.0.0,2.0.0)</version>
37
		</dependency>
38
		<dependency>
39
			<groupId>eu.dnetlib</groupId>
35 40
			<artifactId>cnr-service-common</artifactId>
36 41
			<version>[2.1.0,3.0.0)</version>
37 42
		</dependency>

Also available in: Unified diff