Skip to content
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

Merged
merged 22 commits into from
Dec 13, 2024
Merged

Ea 4015 set client code #277

merged 22 commits into from
Dec 13, 2024

Conversation

SrishtiSingh-eu
Copy link
Contributor

No description provided.

Copy link
Collaborator

@gsergiu gsergiu left a 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

<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>4.0.0</version>
Copy link
Collaborator

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

Copy link
Contributor Author

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);
Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Contributor Author

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)

Copy link
Collaborator

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));
Copy link
Collaborator

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;
Copy link
Collaborator

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

Copy link
Contributor Author

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<>() {};
Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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)
Copy link
Collaborator

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

Copy link
Contributor Author

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)
Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Contributor Author

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)
Copy link
Collaborator

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

Copy link
Contributor Author

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 {
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Collaborator

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)
Copy link
Collaborator

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

Copy link
Contributor Author

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

@gsergiu gsergiu merged commit d57a580 into develop Dec 13, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants