Project

General

Profile

Download (7.75 KB) Statistics
| Branch: | Tag: | Revision:
1 31f1e71a n.hoffmann
		----
2
		Developing with the CDM Library
3
		----
4
5
6 3b8dd375 n.hoffmann
Developing with the CDM Library
7
8 2eecc314 n.hoffmann
	<Table of Contents>
9 3b8dd375 n.hoffmann
10 2eecc314 n.hoffmann
%{toc|section=0|fromDepth=2|toDepth=3}
11 1b03f6e4 Andreas Kohlbecker
12 3b8dd375 n.hoffmann
13 991d761f Patrick Plitzner
  <<Note:>> The CDM Library uses Apache Maven for dependency management. If you are not familiar with that please take a look at the {{{https://dev.e-taxonomy.eu/redmine/projects/edit/wiki/GeneralDev#Maven}developer resources on the wiki}}. In case you run into problems, you might want to check {{{./troubleshooting.html}Troubleshooting}} or contact {{{mailto:editsupport@bgbm.org}editsupport@bgbm.org}} directly.
14 3b8dd375 n.hoffmann
15
* Integrating the CDM Library into a maven project
16
17 1b03f6e4 Andreas Kohlbecker
	To integrate the CDM Library into your personal maven project pelase add our maven repository to your POM:
18 e3dab47f Andreas Müller
	{{https://cybertaxonomy.eu/mavenrepo/}}. To use the <cdmlib-service> package add the following
19 31f1e71a n.hoffmann
	dependency to you POM (adapt the right version number !!):
20 3b8dd375 n.hoffmann
21
---
22
<dependency>
23
	<groupId>eu.etaxonomy</groupId>
24 7df53928 Cherian Mathew
	<artifactId>cdmlib-services</artifactId>
25 3b8dd375 n.hoffmann
	<version>x.x</version>
26
</dependency>
27
---
28
29
30
* Spring applications with the CDM Library
31
32 1b03f6e4 Andreas Kohlbecker
	In your own applicationContext.xml you can simply import the cdm service spring beans from the library.
33
	In addition it also needs a datasource bean and a hibernateProperties bean specific for that datasource.
34
	The CDM Library comes with an embedded hypersonic database that is super easy to use. All you need to do
35 31f1e71a n.hoffmann
	is to import that hsql specific spring configuration like this:
36 3b8dd375 n.hoffmann
37
---
38
applicationContext.xml
39
40
<?xml version="1.0" encoding="UTF-8"?>
41
<beans xmlns="http://www.springframework.org/schema/beans"
42
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
43 1b03f6e4 Andreas Kohlbecker
    xsi:schemaLocation="http://www.springframework.org/schema/beans
44 3b8dd375 n.hoffmann
		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
45
46
	<import resource="classpath:/eu/etaxonomy/cdm/services.xml" />
47
	<import resource="classpath:/eu/etaxonomy/cdm/hsql-datasource.xml" />
48 1b03f6e4 Andreas Kohlbecker
49 3b8dd375 n.hoffmann
</beans>
50
---
51
52 1b03f6e4 Andreas Kohlbecker
	In case you want to define the datasource within your own applicationContext you can surely do so.
53
	For a typical mysql database it looks like this:
54 3b8dd375 n.hoffmann
55
---
56
applicationContext.xml
57
58
<?xml version="1.0" encoding="UTF-8"?>
59
<beans xmlns="http://www.springframework.org/schema/beans"
60
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
61 1b03f6e4 Andreas Kohlbecker
    xsi:schemaLocation="http://www.springframework.org/schema/beans
62 3b8dd375 n.hoffmann
		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
63
64
	<import resource="classpath:/eu/etaxonomy/cdm/services.xml" />
65
66 1b03f6e4 Andreas Kohlbecker
    <bean id="dataSource"
67 3b8dd375 n.hoffmann
			class="org.springframework.jdbc.datasource.DriverManagerDataSource">
68 1c073da5 Andreas Müller
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
69 3b8dd375 n.hoffmann
        <property name="url" value="jdbc:mysql://192.168.2.10/cdm_build"/>
70
        <property name="username" value="cdm_user"/>
71
        <property name="password" value="why_do_i_need_this"/>
72
    </bean>
73 1b03f6e4 Andreas Kohlbecker
74
    <bean id="hibernateProperties"
75 3b8dd375 n.hoffmann
			class="org.springframework.beans.factory.config.PropertiesFactoryBean">
76
        <property name="properties">
77
            <props>
78
                <prop key="hibernate.hbm2ddl.auto">validate</prop>
79
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
80
                <prop key="hibernate.cache.provider_class">
81
					org.hibernate.cache.NoCacheProvider
82
				</prop>
83
                <prop key="hibernate.show_sql">false</prop>
84
                <prop key="hibernate.format_sql">false</prop>
85
            </props>
86
        </property>
87 1b03f6e4 Andreas Kohlbecker
    </bean>
88 3b8dd375 n.hoffmann
</beans>
89
---
90
91
92 31f1e71a n.hoffmann
* Developing the CDM Library with Eclipse
93 3b8dd375 n.hoffmann
94 31f1e71a n.hoffmann
	To use the entire CDM Library with {{{http://www.eclipse.org/} Eclipse}}, you must meet the following prerequisites:
95 3b8dd375 n.hoffmann
96 991d761f Patrick Plitzner
    * Maven 3 commandline tools. Follow the instruction to install maven on your local machine. See {{{https://dev.e-taxonomy.eu/redmine/projects/edit/wiki/GeneralDev#Maven}}} for installation instructions.
97 3b8dd375 n.hoffmann
98 1c073da5 Andreas Müller
    * Git
99 3b8dd375 n.hoffmann
100 1c073da5 Andreas Müller
    * Java JDK >= 1.8 (JRE is not enough) and JAVA_HOME is set to JDK path
101 3b8dd375 n.hoffmann
102 31f1e71a n.hoffmann
	[]
103 1b03f6e4 Andreas Kohlbecker
104 31f1e71a n.hoffmann
** Preparing the CDM Library
105 1b03f6e4 Andreas Kohlbecker
106 8b607fc9 Patrick Plitzner
	Start by checking out the source code from the git repository:
107 3b8dd375 n.hoffmann
108
---
109 8b607fc9 Patrick Plitzner
$ 	git clone https://dev.e-taxonomy.eu/git/cdmlib.git
110
$ 	git clone ssh://git@dev.e-taxonomy.eu/var/git/cdmlib.git
111 3b8dd375 n.hoffmann
---
112
113 31f1e71a n.hoffmann
	Change into the cdmlib directory, compile and install the cdmlib packages in your local repository. This will also download the dependencies into your local repository.
114 5313d0d0 Andreas Kohlbecker
	You will need to configure the MAVEN_OPTS environment variable to configure JVM memory (-Xmx600M). The below example commands uses the 'export' command which is available in most default shells in Linux.
115 3b8dd375 n.hoffmann
116
---
117 31f1e71a n.hoffmann
$ cd cdmlib
118 5313d0d0 Andreas Kohlbecker
$ export MAVEN_OPTS=-Xmx600M
119 1b03f6e4 Andreas Kohlbecker
$ mvn install
120 3b8dd375 n.hoffmann
---
121 31f1e71a n.hoffmann
122
	Let maven create project dependencies and Eclipse metafiles (.project s.o.)
123 1b03f6e4 Andreas Kohlbecker
124 3b8dd375 n.hoffmann
---
125 1b03f6e4 Andreas Kohlbecker
$ mvn eclipse:eclipse
126
---
127
128 31f1e71a n.hoffmann
** Configuring Eclipse
129 1b03f6e4 Andreas Kohlbecker
130 31f1e71a n.hoffmann
	* Setup a new Eclipse workspace (where ever you want but using the cdmlib folder may be comfortable)
131 3b8dd375 n.hoffmann
132 1b03f6e4 Andreas Kohlbecker
	* In Eclipse preferences (not project properties) set a java class variable called <<<M2_REPO>>>, pointing to your local repository.
133 3b8dd375 n.hoffmann
134 31f1e71a n.hoffmann
		* Eclipse Preferences: Java -> Build Path -> Classpath
135 1b03f6e4 Andreas Kohlbecker
136 31f1e71a n.hoffmann
		* Click <<<New>>>. In the upcoming dialog, enter <<<M2_REPO>>> as the variables name and browse the filesystem for the location of the maven repository
137 1b03f6e4 Andreas Kohlbecker
138 31f1e71a n.hoffmann
			* In OSX for example    <<</Users/USERNAME/.m2/repository>>>
139 1b03f6e4 Andreas Kohlbecker
140 31f1e71a n.hoffmann
			* In WinXP for example  <<<C:\Documents and Settings\USERNAME\.m2\repository>>>
141 3b8dd375 n.hoffmann
142 1b03f6e4 Andreas Kohlbecker
	* Import the cdmlib projects:
143 3b8dd375 n.hoffmann
144 31f1e71a n.hoffmann
		* In Eclipse open the Import Wizard: File -> Import -> General -> Existing Projects into Workspace
145 3b8dd375 n.hoffmann
146 31f1e71a n.hoffmann
		* Choose "Select root directory". Click "Browse" and navigate to your cdmlib folder and confirm the file dialog.
147 3b8dd375 n.hoffmann
148 31f1e71a n.hoffmann
		* The projects should now show in the Import Wizard window. Select the projects you want wo work on (usually all) and hit OK.
149 3b8dd375 n.hoffmann
150 1b03f6e4 Andreas Kohlbecker
* Getting started with the cdmlib based web services
151
152
    A good starting point for getting familiar with the cdmlib based web services is this documentation
153
    on the cdm-server in general, and the documentation on the {{{rest-api.html} CDM REST API}}.
154
    Usually you will be mostly interested into the generic API Service which exposes more or less
155
    one to one the service layer of the CDM architecture to the web.
156
157
    If you want to take a look at the code, the almost all of the web service implementation
158
    is found in the maven sub module <<<cdmlib/cdmlib-remote>>>. Inside this module the controllers
159
    are found in <<</src/main/java/eu/etaxonomy/cdm/remote/controller>>>.
160
    The serialization to json and xml is done by <<<JSON-lib>>> but we might switch to Jackson in the future.
161
    Beans which support the serialization are found in <<</src/main/java/eu/etaxonomy/cdm/remote/json>>>,
162
    and last but not least you will also be interested into the configuration which ties everything
163
    together: <<</src/main/resources/eu/etaxonomy/cdm/remote/json/jsonConfigurations.xml>>>
164
    The maven module module <<<cdmlib/cdmlib-remote>>> only contains the views and the controllers.
165
    All parts (mostly configuration) required to let it run in a web application context are
166
    contained in another module <<<cdmlib/cdmlib-remote-webapp>>>, this module actually is run as a
167
    server instance by the {{{/cdm-server}cdm-server}}, configuration files are found in <<</src/main/webapp/WEB-INF/>>>
168 3b8dd375 n.hoffmann
169
* Where do I go from here?
170
171 1b03f6e4 Andreas Kohlbecker
	Now that you have integrated or installed the CDM Library you are probably looking for documentation
172
	on how to develop with it. A good start is to read the {{{./reference.html}reference documentation}}
173 31f1e71a n.hoffmann
	of the CDM Library. The {{{./cdm-uml}UML diagrams}} are also a good starting point to get familiar
174
	with the structure of the Common Data Model itself or consult the {{{./apidocs}javadoc}} for the API documentation.
175 991d761f Patrick Plitzner
	Please also have a look at the {{{https://dev.e-taxonomy.eu/redmine/projects/edit/wiki/GeneralDev} general information}} and
176
	{{{https://dev.e-taxonomy.eu/redmine/projects/edit/wiki/CdmLibraryDev} further information about coding with the CDM Library}} in the development wiki.
177 1b03f6e4 Andreas Kohlbecker
178 3b8dd375 n.hoffmann