Added missing exist method
This commit is contained in:
parent
76d1a81b9f
commit
9577ba0b13
|
@ -13,16 +13,17 @@ import org.gcube.informationsystem.types.reference.Type;
|
||||||
*/
|
*/
|
||||||
public interface ResourceRegistrySchemaClient {
|
public interface ResourceRegistrySchemaClient {
|
||||||
|
|
||||||
public <E extends Element> Type create(Class<E> clz)
|
public <E extends Element> Type create(Class<E> clz) throws SchemaException, ResourceRegistryException;
|
||||||
throws SchemaException, ResourceRegistryException;
|
|
||||||
|
public String create(String typeDefinitition) throws SchemaException, ResourceRegistryException;
|
||||||
public String create(String typeDefinitition)
|
|
||||||
throws SchemaException, ResourceRegistryException;
|
public <E extends Element> boolean exist(Class<E> clz) throws ResourceRegistryException;
|
||||||
|
|
||||||
|
public boolean exist(String typeName) throws ResourceRegistryException;
|
||||||
|
|
||||||
public <E extends Element> List<Type> read(Class<E> clz, Boolean polymorphic)
|
public <E extends Element> List<Type> read(Class<E> clz, Boolean polymorphic)
|
||||||
throws SchemaNotFoundException, ResourceRegistryException;
|
throws SchemaNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
public String read(String typeName, Boolean polymorphic)
|
public String read(String typeName, Boolean polymorphic) throws SchemaNotFoundException, ResourceRegistryException;
|
||||||
throws SchemaNotFoundException, ResourceRegistryException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.Map;
|
||||||
import org.gcube.common.gxhttp.reference.GXConnection;
|
import org.gcube.common.gxhttp.reference.GXConnection;
|
||||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||||
import org.gcube.informationsystem.base.reference.Element;
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextAlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
|
||||||
|
@ -76,6 +77,45 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends Element> boolean exist(Class<E> clz) throws ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
String typeName = Utility.getTypeName(clz);
|
||||||
|
return exist(typeName);
|
||||||
|
} catch(ResourceRegistryException e) {
|
||||||
|
throw e;
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean exist(String typeName) throws ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
logger.info("Going to get {} schema", typeName);
|
||||||
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||||
|
gxHTTPStringRequest.from(ResourceRegistrySchemaClient.class.getSimpleName());
|
||||||
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
|
gxHTTPStringRequest.path(TypePath.TYPES_PATH_PART);
|
||||||
|
gxHTTPStringRequest.path(typeName);
|
||||||
|
|
||||||
|
Map<String,String> parameters = new HashMap<>();
|
||||||
|
parameters.put(TypePath.POLYMORPHIC_PARAM, Boolean.FALSE.toString());
|
||||||
|
gxHTTPStringRequest.queryParams(parameters);
|
||||||
|
|
||||||
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||||
|
HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
return false;
|
||||||
|
} catch(ResourceRegistryException e) {
|
||||||
|
throw e;
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends Element> List<Type> read(Class<E> clz, Boolean polymorphic)
|
public <E extends Element> List<Type> read(Class<E> clz, Boolean polymorphic)
|
||||||
|
|
Loading…
Reference in New Issue