Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c4fd71e

Browse files
committed
Improve README
1 parent 29449d8 commit c4fd71e

File tree

4 files changed

+126
-50
lines changed

4 files changed

+126
-50
lines changed

java-odoo-xml-rpc-core/README.MD

Lines changed: 115 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,121 @@ To add `java-odoo-xml-rpc-core` to your project, add the following to your `pom.
2121

2222
## Basic Usage
2323

24+
Here's a sample class with methods we used frequently from OdooClient:
25+
2426
```java
25-
public static void main(String[] args) throws MalformedURLException, XmlRpcException {
26-
// Initialize an OdooClient to fetch answers
27-
OdooClient cli = new OdooClient(ODOO_URL, DBNAME, USERNAME, PASSWORD, true);
28-
LOG.info(cli.getVersion()); // The version of your Odoo instance
29-
30-
OdooId idToFetch = new OdooId();
31-
idToFetch.id = 2;
32-
// Fetch a single Object by Odoo ID
33-
Project project = cli.fetchObjectById("project.project", idToFetch, Project.class);
34-
LOG.info(project.getDisplayName()); // The project's display name attribute
35-
36-
OdooId id2fetch = new OdooId();
37-
id2fetch.id = 3;
38-
39-
// Fetch multiple objects by Odoo ID
40-
List<Project> projects = cli.fetchListByIds("project.project", Arrays.asList(idToFetch, id2fetch), Project.class);
41-
LOG.info(projects.stream().map(pt -> pt.getDisplayName()).collect(Collectors.joining(",")));
42-
43-
// Fetch relationships for an odoo object, not recursively
44-
cli.fetchRelationShips(project, Arrays.asList(ProjectTask.class, ResUsers.class));
45-
System.out.println("1) " + cli.findByCriteria(1, Project.class, "name", "=", "Sample Project").stream().map(a -> a.getName()).collect(Collectors.joining(",")));
46-
System.out.println("2) " + cli.findByCriteria(1, Project.class, "name", "like", "%Sample%").stream().map(a -> a.getName()).collect(Collectors.joining(",")));
47-
System.out.println("3) " + cli.findByCriteria(1, Project.class).stream().map(a -> a.getName()).collect(Collectors.joining(",")));
48-
System.out.println("4) " + cli.findByCriteria(1, Project.class, "id", "=", "1").stream().map(a -> a.getName()).collect(Collectors.joining(",")));
49-
50-
// Find a list of objects using search criteria, with a limit specified - the first parameter, here 1.
51-
// If no criteria is specified then everything will be fetched.
52-
List<TimesheetsAnalysisReport> timesheet = cli.findByCriteria(1, TimesheetsAnalysisReport.class);
53-
System.out.println("5) " + timesheet.stream().map(a -> a.getName()).collect(Collectors.joining(",")));
54-
55-
// If 0, then will fetch all objects.
56-
List<TimesheetsAnalysisReport> ts = cli.findByCriteria(0, TimesheetsAnalysisReport.class);
57-
System.out.println("6) " + ts.stream().map(a -> a.getName()).collect(Collectors.joining(",")));
58-
59-
// Fetch recursively with depth = 2
60-
cli.fetchRecursivelyRelationShips(ts.get(ts.size() - 1), 2, Collections.emptyList());
61-
62-
System.out.println(ts.get(ts.size() - 1).getCompanyIdAsObject());
63-
System.out.println(ts.get(ts.size() - 1).getCompanyIdAsObject().getName());
64-
System.out.println(ts.get(ts.size() - 1).getCompanyIdAsObject().getCurrencyIdAsObject().getDisplayName());
65-
66-
// Fetch using the criterion name like %Sample%
67-
List<Project> sampleProjects = cli.findByCriteria(1, Project.class, "name", "like", "%Sample%");
68-
// LOG.info("1) {}", sampleProjects.stream().map(a -> a.name).collect(Collectors.joining(",")));
69-
cli.fetchRelationShips(sampleProjects.get(0), Collections.emptyList());
70-
System.out.println(sampleProjects.get(0).getTasksAsList().get(0));
27+
package ch.helvethink.odoo.sample;
28+
29+
import ch.helvethink.odoo.models.project.Project;
30+
import ch.helvethink.odoo.models.project.ProjectTask;
31+
import ch.helvethink.odoo.models.res.ResCompany;
32+
import ch.helvethink.odoo.models.res.ResPartner;
33+
import ch.helvethink.odoo.models.res.ResUsers;
34+
import ch.helvethink.odoo.models.timesheets.analysis.TimesheetsAnalysisReport;
35+
import ch.helvethink.odoo4java.models.OdooId;
36+
import ch.helvethink.odoo4java.xmlrpc.OdooClient;
37+
import org.apache.xmlrpc.XmlRpcException;
38+
import org.slf4j.Logger;
39+
import org.slf4j.LoggerFactory;
40+
41+
import java.net.MalformedURLException;
42+
import java.util.Arrays;
43+
import java.util.Collections;
44+
import java.util.List;
45+
import java.util.stream.Collectors;
46+
47+
public class OdooClientSampleUsage {
48+
49+
50+
public static final String USERNAME = System.getenv("username");
51+
public static final String DBNAME = System.getenv("dbname");
52+
public static final String PASSWORD = System.getenv("password");
53+
public static final String ODOO_URL = System.getenv("url");
54+
55+
private static final Logger LOG = LoggerFactory.getLogger(OdooClientSampleUsage.class);
56+
57+
public static void main(String[] args) throws MalformedURLException, XmlRpcException {
58+
// Initialize an OdooClient to fetch answers
59+
60+
OdooClient cli = new OdooClient(ODOO_URL, DBNAME, USERNAME, PASSWORD, true);
61+
62+
LOG.info(cli.getVersion());
63+
64+
OdooId idToFetch = new OdooId();
65+
idToFetch.id = 2;
66+
67+
// Fetch a single Object by Odoo ID
68+
Project project = cli.fetchObjectById("project.project", idToFetch, Project.class);
69+
LOG.info(project.getDisplayName());
70+
71+
OdooId id2fetch = new OdooId();
72+
id2fetch.id = 3;
73+
// Fetch multiple objects by Odoo IDs
74+
List<Project> projects = cli.fetchListByIds("project.project", Arrays.asList(idToFetch, id2fetch), Project.class);
75+
LOG.info(projects.stream().map(pt -> pt.getDisplayName()).collect(Collectors.joining(",")));
76+
77+
// Fetch relationships for an odoo object, not recursively, filtering classes we want to fetch
78+
79+
cli.fetchRelationShips(project, Arrays.asList(ProjectTask.class, ResUsers.class));
80+
81+
LOG.info("1) Find by criteria 'equals' - {}", cli.findByCriteria(1, Project.class, "name", "=", "Sample Project").stream().map(a -> a.getName()).collect(Collectors.joining(",")));
82+
LOG.info("2) Find by criteria 'like' - {}", cli.findByCriteria(1, Project.class, "name", "like", "%Sample%").stream().map(a -> a.getName()).collect(Collectors.joining(",")));
83+
LOG.info("3) Find by criteria limit 1 without criterion - {}", cli.findByCriteria(1, Project.class).stream().map(a -> a.getName()).collect(Collectors.joining(",")));
84+
LOG.info("4) Find by criteria id equals - {}", cli.findByCriteria(1, Project.class, "id", "=", "1").stream().map(a -> a.getName()).collect(Collectors.joining(",")));
85+
86+
87+
// Find a list of objects using search criteria, with a limit specified - the first parameter, here 1.
88+
// If no criteria is specified then everything will be fetched.
89+
List<TimesheetsAnalysisReport> timesheet = cli.findByCriteria(1, TimesheetsAnalysisReport.class);
90+
LOG.info("5) Find by criteria limit 1 without criterion - {}" + timesheet.stream().map(a -> a.getName()).collect(Collectors.joining(",")));
91+
92+
// If 0, then will fetch all objects.
93+
List<TimesheetsAnalysisReport> ts = cli.findByCriteria(0, TimesheetsAnalysisReport.class);
94+
LOG.info("6) Find by criteria no limit without criterion - {}" + ts.stream().map(a -> a.getName()).collect(Collectors.joining(",")));
95+
96+
// Fetch recursively with depth = 2
97+
cli.fetchRecursivelyRelationShips(ts.get(ts.size() - 1), 2, Collections.emptyList());
98+
// Check that we fetched Currency Too
99+
LOG.info(ts.get(ts.size() - 1).getCompanyIdAsObject().getName());
100+
LOG.info(ts.get(ts.size() - 1).getCompanyIdAsObject().getCurrencyIdAsObject().getDisplayName());
101+
102+
// Fetch using the criterion name like %Sample%
103+
List<Project> sampleProjects = cli.findByCriteria(1, Project.class, "name", "like", "%Sample%");
104+
cli.fetchRelationShips(sampleProjects.get(0), Collections.emptyList());
105+
LOG.info(sampleProjects.get(0).getTasksAsList().get(0).getDisplayName());
106+
}
71107
}
108+
```
109+
110+
N.B: Model classes have been generated using the java-odoo-xml-rpc-plugin:
111+
112+
```xml
113+
<plugin>
114+
<groupId>ch.helvethink.odoo4java</groupId>
115+
<artifactId>java-odoo-xml-rpc-plugin</artifactId>
116+
<version>0.0.1-SNAPSHOT</version>
117+
<configuration>
118+
<generatedClassesRootPackage>ch.helvethink.odoo.models</generatedClassesRootPackage>
119+
<generatedClassPath>target/generated-sources</generatedClassPath>
120+
<odooDatabase>ANGRY_MARMOT_ODOO_DB</odooDatabase>
121+
<odooUsername>ANGRY_MARMOT_USERNAME</odooUsername>
122+
<odooInstanceUrl>https://ANGRY_MARMOT_ODOO_URL</odooInstanceUrl>
123+
<odooPassword>ANGRY_MARMOT_PASS</odooPassword>
124+
<includedPrefixes>
125+
<include>account</include>
126+
<include>project</include>
127+
<include>res</include>
128+
<include>timesheets</include>
129+
</includedPrefixes>
130+
</configuration>
131+
<executions>
132+
<execution>
133+
<id>generate-sources</id>
134+
<goals>
135+
<goal>generate</goal>
136+
</goals>
137+
<phase>generate-sources</phase>
138+
</execution>
139+
</executions>
140+
</plugin>
72141
```

java-odoo-xml-rpc-core/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2828
<modelVersion>4.0.0</modelVersion>
2929
<artifactId>java-odoo-xml-rpc-core</artifactId>
30-
<version>${parent.version}</version>
3130
<name>java-odoo-xml-rpc-core</name>
3231
<url>https://github.com/Helvethink/java-odoo-xml-rpc</url>
3332

java-odoo-xml-rpc-plugin/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<modelVersion>4.0.0</modelVersion>
2929

3030
<artifactId>java-odoo-xml-rpc-plugin</artifactId>
31-
<version>${parent.version}</version>
3231
<packaging>maven-plugin</packaging>
3332
<url>https://github.com/Helvethink/java-odoo-xml-rpc</url>
3433

@@ -57,7 +56,6 @@
5756
<dependency>
5857
<groupId>ch.helvethink.odoo4java</groupId>
5958
<artifactId>java-odoo-xml-rpc-core</artifactId>
60-
<version>${parent.version}</version>
6159
</dependency>
6260

6361
<!-- xml rpc cli -->

pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,17 @@
7777

7878
<scm>
7979
<connection>scm:git:git://github.com/Helvethink/java-odoo-xml-rpc.git</connection>
80-
<developerConnection>scm:git:ssh://github.com:Helvethink/java-odoo-xml-rpc.git</developerConnection>
80+
<developerConnection>scm:git:ssh://git@github.com/Helvethink/java-odoo-xml-rpc.git</developerConnection>
8181
<url>https://github.com/Helvethink/java-odoo-xml-rpc.git</url>
8282
</scm>
8383

8484
<dependencyManagement>
8585
<dependencies>
86+
<dependency>
87+
<groupId>ch.helvethink.odoo4java</groupId>
88+
<artifactId>java-odoo-xml-rpc-core</artifactId>
89+
<version>${project.version}</version>
90+
</dependency>
8691
<!-- xml rpc cli -->
8792
<dependency>
8893
<groupId>org.apache.xmlrpc</groupId>
@@ -201,6 +206,11 @@
201206
<publishingServerId>central</publishingServerId>
202207
</configuration>
203208
</plugin>
209+
<plugin>
210+
<groupId>org.apache.maven.plugins</groupId>
211+
<artifactId>maven-release-plugin</artifactId>
212+
<version>3.1.1</version>
213+
</plugin>
204214
</plugins>
205215
</build>
206216

0 commit comments

Comments
 (0)