gcat-client/src/main/java/org/gcube/gcat/client/Configuration.java

75 lines
2.1 KiB
Java
Raw Permalink Normal View History

2022-02-21 13:04:56 +01:00
package org.gcube.gcat.client;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.ws.WebServiceException;
2022-02-21 13:17:14 +01:00
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.gcat.api.configuration.CatalogueConfiguration;
2022-02-21 13:04:56 +01:00
/**
* @author Luca Frosini (ISTI - CNR)
*/
2022-02-21 13:17:14 +01:00
public class Configuration extends GCatClient implements org.gcube.gcat.api.interfaces.Configuration<CatalogueConfiguration,Void> {
protected ObjectMapper mapper;
2022-02-21 13:04:56 +01:00
public Configuration() throws MalformedURLException {
2022-02-22 10:46:23 +01:00
super(CONFIGURATIONS);
2022-02-21 13:17:14 +01:00
mapper = new ObjectMapper();
2022-02-21 13:04:56 +01:00
}
public Configuration(URL enforcedServiceURL) throws MalformedURLException {
2022-02-22 10:46:23 +01:00
super(enforcedServiceURL, CONFIGURATIONS);
2022-02-21 13:17:14 +01:00
mapper = new ObjectMapper();
2022-02-21 13:04:56 +01:00
}
2022-02-21 13:17:14 +01:00
protected CatalogueConfiguration getCatalogueConfigurationFromString(String json) throws WebServiceException {
try {
return mapper.readValue(json, CatalogueConfiguration.class);
} catch (WebServiceException e) {
throw e;
} catch (Exception e) {
throw new WebServiceException(e);
}
}
2022-02-21 13:04:56 +01:00
@Override
2022-02-21 13:17:14 +01:00
public CatalogueConfiguration create(String json) throws WebServiceException {
String ret = super.create(json);
return getCatalogueConfigurationFromString(ret);
2022-02-21 13:04:56 +01:00
}
@Override
2022-02-21 13:17:14 +01:00
public CatalogueConfiguration read() throws WebServiceException {
String ret = super.read(CURRENT_CONTEXT_PATH_PARAMETER);
return getCatalogueConfigurationFromString(ret);
2022-02-21 13:04:56 +01:00
}
@Override
2022-02-21 13:17:14 +01:00
public CatalogueConfiguration update(String json) throws WebServiceException {
String ret = super.update(json, CURRENT_CONTEXT_PATH_PARAMETER);
return getCatalogueConfigurationFromString(ret);
2022-02-21 13:04:56 +01:00
}
@Override
2022-02-21 13:17:14 +01:00
public CatalogueConfiguration patch(String json) throws WebServiceException {
String ret = super.patch(json, CURRENT_CONTEXT_PATH_PARAMETER);
return getCatalogueConfigurationFromString(ret);
2022-02-21 13:04:56 +01:00
}
@Override
public Void delete() throws WebServiceException {
super.delete(false, CURRENT_CONTEXT_PATH_PARAMETER);
return null;
}
@Override
public Void purge() throws WebServiceException {
super.delete(true, CURRENT_CONTEXT_PATH_PARAMETER);
return null;
}
}