-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from europeana/EA-4015_setClientCode
Ea 4015 set client code
- Loading branch information
Showing
30 changed files
with
1,033 additions
and
882 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
set-client/src/main/java/eu/europeana/set/client/UserSetApiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package eu.europeana.set.client; | ||
|
||
import eu.europeana.set.client.config.ClientConfiguration; | ||
import eu.europeana.set.client.exception.SetApiClientException; | ||
import eu.europeana.set.client.model.result.RecordPreview; | ||
import eu.europeana.set.client.web.SearchUserSetApi; | ||
import eu.europeana.set.client.web.WebUserSetApi; | ||
import eu.europeana.set.definitions.model.UserSet; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Implementation of client api | ||
* | ||
* @author GordeaS | ||
* Refractored by Srishti Singh | ||
*/ | ||
|
||
public class UserSetApiClient extends BaseUserSetApi { | ||
|
||
private final WebUserSetClient webUserSetClient; | ||
private final SearchUserSetClient searchUserSetClient; | ||
|
||
public UserSetApiClient(ClientConfiguration configuration) throws SetApiClientException { | ||
super(configuration); | ||
this.webUserSetClient = new WebUserSetClient(); | ||
this.searchUserSetClient = new SearchUserSetClient(); | ||
} | ||
|
||
public WebUserSetApi getWebUserSetApi() { | ||
return webUserSetClient; | ||
} | ||
|
||
public SearchUserSetApi getSearchUserSetApi() { | ||
return searchUserSetClient; | ||
} | ||
|
||
/** | ||
* Web User Set Client class | ||
*/ | ||
private class WebUserSetClient implements WebUserSetApi { | ||
@Override | ||
public UserSet createUserSet(String set, String profile) throws SetApiClientException { | ||
return getApiConnection().createUserSet(set, profile); | ||
|
||
} | ||
|
||
@Override | ||
public String deleteUserSet(String identifier) throws SetApiClientException { | ||
return getApiConnection().deleteUserSet(identifier); | ||
} | ||
|
||
@Override | ||
public UserSet getUserSet(String identifier, String profile) throws SetApiClientException { | ||
return getApiConnection().getUserSet(identifier, profile); | ||
} | ||
|
||
@Override | ||
public UserSet updateUserSet(String identifier, String set, String profile) throws SetApiClientException { | ||
return getApiConnection().updateUserSet(identifier, set, profile); | ||
} | ||
|
||
@Override | ||
public List<RecordPreview> getPaginationUserSet(String identifier, String sort, String sortOrder, String page, String pageSize, String profile) throws SetApiClientException { | ||
return getApiConnection().getPaginationUserSet(identifier, sort, sortOrder, page, pageSize, profile); | ||
} | ||
} | ||
|
||
private class SearchUserSetClient implements SearchUserSetApi { | ||
|
||
@Override | ||
public List<? extends UserSet> searchUserSet(String query, String[] qf, | ||
String sort, String page, String pageSize, String facet, int facetLimit, String profile) throws SetApiClientException { | ||
return getApiConnection().searchUserSet(query, qf, sort, page, pageSize, facet, facetLimit, profile); | ||
} | ||
} | ||
} |
114 changes: 32 additions & 82 deletions
114
set-client/src/main/java/eu/europeana/set/client/config/ClientConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,76 @@ | ||
package eu.europeana.set.client.config; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
import eu.europeana.set.client.exception.TechnicalRuntimeException; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
/** | ||
* configuration for accessing remote api | ||
* | ||
* @author GordeaS | ||
* | ||
*/ | ||
|
||
public final class ClientConfiguration { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(ClientConfiguration.class); | ||
|
||
protected static final String SET_CLIENT_PROPERTIES_FILE = "/set-client.user.properties"; | ||
protected static final String PROP_SET_API_KEY = "set.api.key"; | ||
protected static final String PROP_SET_SERVICE_URI = "set.service.uri"; | ||
protected static final String PROP_OAUTH_SERVICE_URI = "oauth.service.uri"; | ||
protected static final String PROP_OAUTH_REQUEST_PARAMS = "oauth.token.request.params"; | ||
public static final String PROP_SET_API_KEY = "set.api.key"; | ||
public static final String PROP_SET_SERVICE_URI = "set.service.uri"; | ||
public static final String PROP_OAUTH_SERVICE_URI = "oauth.service.uri"; | ||
public static final String PROP_OAUTH_REQUEST_PARAMS = "oauth.token.request.params"; | ||
|
||
private Properties properties; | ||
private static ClientConfiguration singleton; | ||
|
||
/** | ||
* Hide the default constructor | ||
*/ | ||
private ClientConfiguration() { | ||
} | ||
|
||
/** | ||
* Accessor method for the singleton | ||
* | ||
* @return | ||
* Creates ClientConfiguration instance with set client properties | ||
*/ | ||
public static synchronized ClientConfiguration getInstance() { | ||
if (singleton == null) { | ||
singleton = new ClientConfiguration(); | ||
singleton.loadProperties(); | ||
} | ||
|
||
return singleton; | ||
public ClientConfiguration() { | ||
loadProperties(SET_CLIENT_PROPERTIES_FILE); | ||
} | ||
|
||
/** | ||
* Laizy loading of configuration properties | ||
* CConstructor to inject properties | ||
* @param properties | ||
*/ | ||
public synchronized void loadProperties() { | ||
|
||
try { | ||
properties = new Properties(); | ||
InputStream resourceAsStream = getClass().getResourceAsStream(SET_CLIENT_PROPERTIES_FILE); | ||
if (resourceAsStream == null) { | ||
throw new TechnicalRuntimeException( | ||
"No properties file found in classpath! " + SET_CLIENT_PROPERTIES_FILE); | ||
} | ||
getProperties().load(resourceAsStream); | ||
|
||
} catch (RuntimeException | IOException e) { | ||
throw new TechnicalRuntimeException("Cannot read configuration file: " + SET_CLIENT_PROPERTIES_FILE, e); | ||
} | ||
|
||
public ClientConfiguration(Properties properties) { | ||
this.properties = properties; | ||
} | ||
|
||
/** | ||
* provides access to the configuration properties. It is not recommended to use | ||
* the properties directly, but the | ||
* | ||
* @return | ||
*/ | ||
Properties getProperties() { | ||
return properties; | ||
private Properties loadProperties(String propertiesFile) { | ||
try { | ||
properties = new Properties(); | ||
properties.load(getClass().getResourceAsStream(propertiesFile)); | ||
} catch (IOException e) { | ||
LOGGER.error("Error loading the properties file {}", propertiesFile); | ||
} | ||
return properties; | ||
} | ||
|
||
/** | ||
* | ||
* @return the name of the file storing the client configuration | ||
*/ | ||
String getConfigurationFile() { | ||
return SET_CLIENT_PROPERTIES_FILE; | ||
} | ||
|
||
/** | ||
* This method provides access to the API key defined in the configuration file | ||
* | ||
* @see PROP_EUROPEANA_API_KEY | ||
* | ||
* @return | ||
*/ | ||
public String getApiKey() { | ||
return getProperties().getProperty(PROP_SET_API_KEY); | ||
return getProperty(PROP_SET_API_KEY); | ||
} | ||
|
||
/** | ||
* This method provides access to the search uri value defined in the | ||
* configuration file | ||
* | ||
* @see PROP_EUROPEANA_SEARCH_URI | ||
* | ||
* @return | ||
*/ | ||
|
||
public String getServiceUri() { | ||
return getProperties().getProperty(PROP_SET_SERVICE_URI); | ||
return getProperty(PROP_SET_SERVICE_URI); | ||
} | ||
|
||
/** | ||
* This method returns the uri of the oauth service as configured in | ||
* | ||
* @return | ||
*/ | ||
public String getOauthServiceUri() { | ||
return getProperties().getProperty(PROP_OAUTH_SERVICE_URI); | ||
return getProperty(PROP_OAUTH_SERVICE_URI); | ||
} | ||
|
||
/** | ||
* This method returns the request params needed to acquire a new token | ||
* | ||
* @return | ||
*/ | ||
public String getOauthRequestParams() { | ||
return getProperties().getProperty(PROP_OAUTH_REQUEST_PARAMS); | ||
return getProperty(PROP_OAUTH_REQUEST_PARAMS); | ||
} | ||
|
||
private String getProperty(String propertyName) { | ||
return properties.getProperty(propertyName); | ||
} | ||
|
||
} |
Oops, something went wrong.