-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ea 4015 set client code #277
Conversation
…pi's propety file
…from client, update other modules to adapt tghe new HTTpConnection class, added annotation for deserialising the response
…A-4015_setClientCode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to remove the dependencies from defnitions module and adapt the client accordingly
set-client/pom.xml
Outdated
<dependency> | ||
<groupId>jakarta.ws.rs</groupId> | ||
<artifactId>jakarta.ws.rs-api</artifactId> | ||
<version>4.0.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this dependency is not needed, only the UriBuilder class is used in BaseApiConnection. The use of UriBuilder needs to be replaced by the use of org.apache.hc.core5.net.URIBuilder from the httclient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed , used httpclient 5 uri builder
|
||
return singleton; | ||
public ClientConfiguration() { | ||
loadProperties(SET_CLIENT_PROPERTIES_FILE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason to change the configuration to not be a singleton anymore? We should avoid reading the properties files multiple times as that can generate major performance loss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, the filePath for the configuration file should be provided as parameter and stored as class attribute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, we use spring boot and create a bean, only a single instance is always created.
Also, when creating a client for any API, we create an instance of the Client class, and that class should be able to accept a configuration class.
public UserSetApiClient(ClientConfiguration configuration)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but the properties still need to be read and currently we only support properties from the classpath
private Properties loadProperties(String propertiesFile) { | ||
try { | ||
properties = new Properties(); | ||
properties.load(getClass().getResourceAsStream(propertiesFile)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should support externalization of configurations, meaning to be able to handle absolute file path using the file protocol see: https://stackoverflow.com/questions/8406025/local-file-protocol-for-java-net-url. Third parties should be able to provide the location of configuration files. (absolute file path should use the fille:// protocol)
import eu.europeana.set.definitions.model.impl.BaseUserSet; | ||
import eu.europeana.set.definitions.model.vocabulary.ProfileConstants; | ||
import eu.europeana.set.definitions.model.vocabulary.WebUserSetFields; | ||
import jakarta.ws.rs.core.UriBuilder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be replaced by the use of rg.apache.hc.core5.net.URIBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
return records; | ||
} | ||
TypeReference<ResultsPageImpl<RecordPreview>> typeRef = new TypeReference<>() {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have an if/else or switch for profiles. I assume this call is parsing the items.meta profile. see https://docs.google.com/spreadsheets/d/19_5ihd_MKuVenIno-enankAu8bG7v79TGHQuepOtTv8/edit?gid=1005516996#gid=1005516996
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to be aware of the default profile and eventually return an exeption if the requested profile is not supported by the client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set API will return an Invalid profile Exception if there is a wrong parameter passed. In everycase we return List. But for the profile where only item ids are returned, we need to do bit more processing. here for "items" profile we get List which is converted to List with id value only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a deserializer now to handle all the profile responses
import java.util.Objects; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jackson annotations should not be added to base classes which need to be keps as pojos, so that they can be used both by client and server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
import eu.europeana.set.definitions.model.agent.Agent; | ||
import eu.europeana.set.definitions.model.vocabulary.AgentTypes; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jackson annotations should not be added to base classes which need to be keps as pojos, so that they can be used both by client and server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for client side parsing, the ignore unknown fields should be set directly in object mapper https://www.baeldung.com/jackson-deserialize-json-unknown-properties#2-dealing-with-unknown-fields-using-the-objectmapper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
* @author GrafR Modified by Srishti Singh 2-2-2021 | ||
*/ | ||
public abstract class BaseUserSet extends BasePageInfo implements UserSet { | ||
@JsonIgnoreProperties(ignoreUnknown = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jackson annotations should not be added to base classes which need to be keps as pojos, so that they can be used both by client and server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
* @author GrafR Modified by Srishti Singh 2-2-2021 | ||
*/ | ||
public abstract class BaseUserSet extends BasePageInfo implements UserSet { | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class BaseUserSet extends BasePageInfo implements UserSet { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this class should probably stay abstract, as it is not allwed to add jackson annotations to this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed annotations but class can not stay abstract. As i need to instantiate it to create response for items profile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we can create a UserSetImpl extends BaseUserSet or so in the client module
@@ -74,6 +86,7 @@ public abstract class BaseUserSet extends BasePageInfo implements UserSet { | |||
* A reference to the user agent that gathers objects together following | |||
* implicit or explicit criteria or accrual policy. | |||
*/ | |||
@JsonDeserialize(using = AgentDeserializer.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this annotation should be used on a setter method in client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed add in the mapper in the client side deserialisation
No description provided.