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

Skip to content

Commit c473454

Browse files
committed
Some refactoring, regarding readability.
(Removing useless classes for testing, split OdooClient with class OdooObjectLoader for relationships fetching) Fix Dynamic loading of class with reflexion for some use cases (App Server, Quarkus, ...) Improve code coverage from Unit tests
1 parent ab5ff9f commit c473454

File tree

442 files changed

+19699
-149491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

442 files changed

+19699
-149491
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,26 @@ public class OdooClientSampleUsage {
5858
// Initialize an OdooClient to fetch answers
5959

6060
OdooClient cli = new OdooClient(ODOO_URL, DBNAME, USERNAME, PASSWORD, true);
61+
OdooObjectLoader loader = new OdooObjectLoader(cli);
6162

6263
LOG.info(cli.getVersion());
6364

6465
OdooId idToFetch = new OdooId();
6566
idToFetch.id = 2;
6667

6768
// Fetch a single Object by Odoo ID
68-
Project project = cli.fetchObjectById("project.project", idToFetch, Project.class);
69+
Project project = cli.findObjectById("project.project", idToFetch, Project.class);
6970
LOG.info(project.getDisplayName());
7071

7172
OdooId id2fetch = new OdooId();
7273
id2fetch.id = 3;
7374
// Fetch multiple objects by Odoo IDs
74-
List<Project> projects = cli.fetchListByIds("project.project", Arrays.asList(idToFetch, id2fetch), Project.class);
75+
List<Project> projects = cli.findListByIds("project.project", Arrays.asList(idToFetch, id2fetch), Project.class);
7576
LOG.info(projects.stream().map(pt -> pt.getDisplayName()).collect(Collectors.joining(",")));
7677

7778
// Fetch relationships for an odoo object, not recursively, filtering classes we want to fetch
7879

79-
cli.fetchRelationShips(project, Arrays.asList(ProjectTask.class, ResUsers.class));
80+
loader.fetchRelationShips(project, Arrays.asList(ProjectTask.class, ResUsers.class));
8081

8182
LOG.info("1) Find by criteria 'equals' - {}", cli.findByCriteria(1, Project.class, "name", "=", "Sample Project").stream().map(a -> a.getName()).collect(Collectors.joining(",")));
8283
LOG.info("2) Find by criteria 'like' - {}", cli.findByCriteria(1, Project.class, "name", "like", "%Sample%").stream().map(a -> a.getName()).collect(Collectors.joining(",")));
@@ -87,22 +88,28 @@ public class OdooClientSampleUsage {
8788
// Find a list of objects using search criteria, with a limit specified - the first parameter, here 1.
8889
// If no criteria is specified then everything will be fetched.
8990
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+
LOG.info("5) Find by criteria limit 1 without criterion - {}", timesheet.stream().map(a -> a.getName()).collect(Collectors.joining(",")));
9192

9293
// If 0, then will fetch all objects.
9394
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+
LOG.info("6) Find by criteria no limit without criterion - {}", ts.stream().map(a -> a.getName()).collect(Collectors.joining(",")));
9596

9697
// Fetch recursively with depth = 2
97-
cli.fetchRecursivelyRelationShips(ts.get(ts.size() - 1), 2, Collections.emptyList());
98+
loader.fetchRecursivelyRelationShips(ts.getLast(), 2, Collections.emptyList());
9899
// 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());
100+
LOG.info(ts.getLast().getCompanyIdAsObject().getName());
101+
LOG.info(ts.getLast().getCompanyIdAsObject().getCurrencyIdAsObject().getDisplayName());
101102

102103
// Fetch using the criterion name like %Sample%
103104
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());
105+
loader.fetchRelationShips(sampleProjects.getFirst(), Collections.emptyList());
106+
LOG.info(sampleProjects.getFirst().getTasksAsList().get(0).getDisplayName());
107+
108+
// Find by names
109+
cli.findByNames(ProjectTask.class, Collections.singletonList("Sample Project Task 1"));
110+
cli.findByNames(ProjectTask.class, Arrays.asList("Sample Project Task 1", "Sample Project Task 1"));
111+
cli.findByNames(ProjectTask.class, Arrays.asList("InfoLogo - Presales", "Boundary / Cutover", "Unknownwnwnwn"));
112+
106113
}
107114
}
108115
```
@@ -113,7 +120,7 @@ N.B: Model classes have been generated using the java-odoo-xml-rpc-plugin:
113120
<plugin>
114121
<groupId>ch.helvethink.odoo4java</groupId>
115122
<artifactId>java-odoo-xml-rpc-plugin</artifactId>
116-
<version>0.0.1-SNAPSHOT</version>
123+
<version>${odoo4java.version}</version>
117124
<configuration>
118125
<generatedClassesRootPackage>ch.helvethink.odoo.models</generatedClassesRootPackage>
119126
<generatedClassPath>target/generated-sources</generatedClassPath>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* MIT License
43
*
@@ -24,44 +23,26 @@
2423
*
2524
*/
2625

27-
package ch.helvethink.odoo4java.test.ng.res.users.apikeys;
28-
29-
import ch.helvethink.odoo4java.models.OdooObject;
30-
import ch.helvethink.odoo4java.models.OdooObj;;
31-
32-
@OdooObject("res.users.apikeys.show")
33-
public class ResUsersApikeysShow implements OdooObj {
34-
35-
36-
private int id;
37-
38-
39-
private String key;
26+
package ch.helvethink.odoo4java;
4027

41-
42-
public ResUsersApikeysShow() {
43-
// Constructor
44-
}
45-
46-
47-
public int getId() {
48-
return id;
49-
}
50-
51-
public String getKey() {
52-
return key;
53-
}
54-
55-
56-
57-
public void setId(int id) {
58-
this.id = id;
28+
/**
29+
* Exception used when fetch of relationships fails
30+
*/
31+
public class FetchException extends RuntimeException {
32+
33+
/**
34+
* Construuctor from parent exception
35+
* @param e Parent exception
36+
*/
37+
public FetchException(final Exception e) {
38+
super(e);
5939
}
6040

61-
public void setKey(String key) {
62-
this.key = key;
41+
/**
42+
* Exception with message
43+
* @param s The error description
44+
*/
45+
public FetchException(final String s) {
46+
super(s);
6347
}
64-
65-
66-
67-
}
48+
}

java-odoo-xml-rpc-core/src/main/java/ch/helvethink/odoo4java/tools/FieldUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ private FieldUtils() {
4444
* @param fieldName The field name to sanitize
4545
* @return fieldName in CamelCase
4646
*/
47-
public static String formatFieldName(final String fieldName) {
47+
public static String formatFieldName(String fieldName) {
48+
fieldName = fieldName.replaceAll("^_+","");
4849
final String[] splittedFieldName = fieldName.split("_");
4950
final StringBuilder sanitizedFieldName = new StringBuilder();
5051
// There's at least one element as package name into the model
5152
sanitizedFieldName.append(splittedFieldName[0]);
5253
for (int i = 1; i < splittedFieldName.length; i++) {
53-
sanitizedFieldName.append(StringUtils.capitalizeFirstLetter(splittedFieldName[i]));
54+
if(!StringUtils.isEmpty(splittedFieldName[i])) {
55+
sanitizedFieldName.append(StringUtils.capitalizeFirstLetter(splittedFieldName[i]));
56+
}
5457
}
5558
return sanitizedFieldName.toString();
5659
}

0 commit comments

Comments
 (0)