2021-10-25 11:39:59 +02:00
package org.gcube.informationsystem.resourceregistry.contexts ;
2017-11-23 11:42:05 +01:00
2020-11-04 17:38:57 +01:00
import java.io.IOException ;
2023-05-05 12:14:19 +02:00
import java.io.UnsupportedEncodingException ;
2019-01-17 11:18:02 +01:00
import java.net.HttpURLConnection ;
2023-02-27 18:21:52 +01:00
import java.util.HashMap ;
2017-12-06 15:23:47 +01:00
import java.util.List ;
2023-02-27 18:21:52 +01:00
import java.util.Map ;
2017-11-23 11:42:05 +01:00
import java.util.UUID ;
2020-11-04 17:38:57 +01:00
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException ;
2023-02-22 15:14:45 +01:00
import org.gcube.common.context.ContextUtility ;
2019-02-06 12:03:35 +01:00
import org.gcube.common.gxhttp.reference.GXConnection ;
2019-01-17 11:18:02 +01:00
import org.gcube.common.gxhttp.request.GXHTTPStringRequest ;
2023-02-22 15:14:45 +01:00
import org.gcube.common.http.GXHTTPUtility ;
2021-10-25 11:39:59 +02:00
import org.gcube.informationsystem.contexts.reference.entities.Context ;
2020-11-04 17:38:57 +01:00
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache ;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal ;
2022-02-09 12:23:55 +01:00
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException ;
2017-11-23 11:42:05 +01:00
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException ;
2022-02-01 16:46:25 +01:00
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextAlreadyPresentException ;
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException ;
2023-11-09 19:04:36 +01:00
import org.gcube.informationsystem.resourceregistry.api.request.BaseRequestInfo ;
2017-11-23 11:42:05 +01:00
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath ;
2019-01-17 11:18:02 +01:00
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility ;
2023-02-09 18:02:57 +01:00
import org.gcube.informationsystem.serialization.ElementMapper ;
2023-04-19 11:37:22 +02:00
import org.gcube.informationsystem.utils.UUIDManager ;
2017-11-23 11:42:05 +01:00
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
/ * *
* @author Luca Frosini ( ISTI - CNR )
* /
2023-11-09 19:04:36 +01:00
public class ResourceRegistryContextClientImpl extends BaseRequestInfo implements ResourceRegistryContextClient {
2019-01-17 11:18:02 +01:00
2017-11-23 11:42:05 +01:00
private static final Logger logger = LoggerFactory . getLogger ( ResourceRegistryContextClientImpl . class ) ;
2019-01-17 11:18:02 +01:00
2023-02-27 18:21:52 +01:00
private static final String ACCEPT_HTTP_HEADER_KEY = " Accept " ;
private static final String CONTENT_TYPE_HTTP_HEADER_KEY = " Content-Type " ;
2017-11-23 11:42:05 +01:00
protected final String address ;
2019-01-17 11:18:02 +01:00
2023-02-27 18:21:52 +01:00
protected Map < String , String > headers ;
2023-03-02 14:51:31 +01:00
protected ContextCache contextCache ;
2023-05-05 12:14:19 +02:00
private void addOptionalQueryParameters ( Map < String , String > queryParams ) throws UnsupportedEncodingException {
addIncludeMeta ( queryParams ) ;
}
private GXHTTPStringRequest includeAdditionalQueryParameters ( GXHTTPStringRequest gxHTTPStringRequest ) throws UnsupportedEncodingException {
Map < String , String > queryParams = new HashMap < > ( ) ;
return includeAdditionalQueryParameters ( gxHTTPStringRequest , queryParams ) ;
}
private GXHTTPStringRequest includeAdditionalQueryParameters ( GXHTTPStringRequest gxHTTPStringRequest , Map < String , String > queryParams ) throws UnsupportedEncodingException {
if ( queryParams = = null ) {
queryParams = new HashMap < > ( ) ;
}
addOptionalQueryParameters ( queryParams ) ;
return gxHTTPStringRequest . queryParams ( queryParams ) ;
}
private void addIncludeMeta ( Map < String , String > queryParams ) throws UnsupportedEncodingException {
2023-11-09 19:04:36 +01:00
addIncludeMeta ( queryParams , includeMeta ) ;
}
private void addIncludeMeta ( Map < String , String > queryParams , boolean includeMeta ) throws UnsupportedEncodingException {
2023-05-05 12:14:19 +02:00
if ( includeMeta ) {
2023-11-09 19:11:12 +01:00
queryParams . put ( ContextPath . INCLUDE_META_QUERY_PARAMETER , Boolean . toString ( includeMeta ) ) ;
2023-05-05 12:14:19 +02:00
}
}
2023-11-09 19:04:36 +01:00
/ *
private void addOffset ( Map < String , String > queryParams ) throws UnsupportedEncodingException {
addOffset ( queryParams , offset ) ;
}
* /
private void addOffset ( Map < String , String > queryParams , Integer offset ) throws UnsupportedEncodingException {
if ( offset ! = null ) {
2023-11-09 19:11:12 +01:00
queryParams . put ( ContextPath . OFFSET_QUERY_PARAMETER , offset . toString ( ) ) ;
2023-11-09 19:04:36 +01:00
}
}
/ *
private void addLimit ( Map < String , String > queryParams ) throws UnsupportedEncodingException {
addLimit ( queryParams , limit ) ;
}
* /
private void addLimit ( Map < String , String > queryParams , Integer limit ) throws UnsupportedEncodingException {
if ( limit ! = null ) {
2023-11-09 19:11:12 +01:00
queryParams . put ( ContextPath . LIMIT_QUERY_PARAMETER , limit . toString ( ) ) ;
2023-11-09 19:04:36 +01:00
}
}
2020-11-04 17:38:57 +01:00
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal ( ) {
@Override
public List < Context > renew ( ) throws ResourceRegistryException {
2023-11-09 19:04:36 +01:00
return getAllContextFromServer ( true , 0 , BaseRequestInfo . UNBOUNDED_LIMIT ) ;
2020-11-04 17:38:57 +01:00
}
} ;
2023-03-01 14:24:04 +01:00
@Override
2023-02-27 18:21:52 +01:00
public void addHeader ( String name , String value ) {
headers . put ( name , value ) ;
}
protected GXHTTPStringRequest getGXHTTPStringRequest ( ) {
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility . getGXHTTPStringRequest ( address ) ;
gxHTTPStringRequest . from ( this . getClass ( ) . getSimpleName ( ) ) ;
for ( String name : headers . keySet ( ) ) {
gxHTTPStringRequest . header ( name , headers . get ( name ) ) ;
}
return gxHTTPStringRequest ;
}
2017-11-23 11:42:05 +01:00
public ResourceRegistryContextClientImpl ( String address ) {
2023-03-02 14:51:31 +01:00
this ( address , true ) ;
}
public ResourceRegistryContextClientImpl ( String address , boolean sharedContextCache ) {
2017-11-23 11:42:05 +01:00
this . address = address ;
2023-02-27 18:21:52 +01:00
this . headers = new HashMap < > ( ) ;
2023-05-05 12:14:19 +02:00
this . includeMeta = false ;
2023-03-02 14:51:31 +01:00
if ( sharedContextCache ) {
contextCache = ContextCache . getInstance ( ) ;
} else {
contextCache = new ContextCache ( ) ;
}
2020-11-04 17:38:57 +01:00
contextCache . setContextCacheRenewal ( contextCacheRenewal ) ;
2017-11-23 11:42:05 +01:00
}
2018-06-13 16:24:34 +02:00
2020-11-04 19:34:07 +01:00
private void forceCacheRefresh ( ) {
try {
contextCache . cleanCache ( ) ;
contextCache . refreshContextsIfNeeded ( ) ;
} catch ( Exception e ) {
logger . warn ( " Unable to force cache refresh. " , e ) ;
}
}
2023-11-09 19:04:36 +01:00
/ * *
* It reads all the contexts from server .
* The cache used for contexts is bypassed and not updated .
* @return All Contexts read from server
* @throws ResourceRegistryException
* /
public List < Context > getAllContextFromServer ( ) throws ResourceRegistryException {
return getAllContextFromServer ( includeMeta , offset , limit ) ;
}
protected List < Context > getAllContextFromServer ( boolean includeMeta , Integer offset , Integer limit ) throws ResourceRegistryException {
2022-02-09 12:23:55 +01:00
try {
2023-11-09 19:04:36 +01:00
logger . info ( " Going to read all {}s " , Context . NAME ) ;
2023-02-27 18:21:52 +01:00
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest ( ) ;
gxHTTPStringRequest . header ( ACCEPT_HTTP_HEADER_KEY , GXConnection . APPLICATION_JSON_CHARSET_UTF_8 ) ;
2022-02-09 12:23:55 +01:00
gxHTTPStringRequest . path ( ContextPath . CONTEXTS_PATH_PART ) ;
2023-11-09 19:04:36 +01:00
Map < String , String > parameters = new HashMap < > ( ) ;
addIncludeMeta ( parameters , includeMeta ) ;
addOffset ( parameters , offset ) ;
addLimit ( parameters , limit ) ;
gxHTTPStringRequest . queryParams ( parameters ) ;
2023-05-05 12:14:19 +02:00
2022-02-09 12:23:55 +01:00
HttpURLConnection httpURLConnection = gxHTTPStringRequest . get ( ) ;
String all = HTTPUtility . getResponse ( String . class , httpURLConnection ) ;
logger . debug ( " Got contexts are {} " , Context . NAME , all ) ;
return ElementMapper . unmarshalList ( Context . class , all ) ;
} catch ( ResourceRegistryException e ) {
// logger.trace("Error Creating {}", facet, e);
throw e ;
} catch ( Exception e ) {
// logger.trace("Error Creating {}", facet, e);
throw new RuntimeException ( e ) ;
}
}
@Override
public List < Context > all ( ) throws ResourceRegistryException {
return contextCache . getContexts ( ) ;
}
2023-11-09 19:04:36 +01:00
@Override
public ContextCache getContextCache ( ) {
return contextCache ;
}
2018-06-13 16:24:34 +02:00
protected String internalCreate ( Context context ) throws ContextAlreadyPresentException , ResourceRegistryException {
try {
2023-04-28 11:46:55 +02:00
UUID uuid = context . getID ( ) ;
2023-04-19 11:37:22 +02:00
if ( uuid = = null ) {
2023-04-21 15:57:13 +02:00
uuid = UUIDManager . getInstance ( ) . generateValidUUID ( ) ;
2023-04-28 11:46:55 +02:00
context . setID ( uuid ) ;
2018-06-13 16:24:34 +02:00
}
2023-04-19 11:37:22 +02:00
2018-06-13 16:24:34 +02:00
2020-02-03 10:52:35 +01:00
String contextString = ElementMapper . marshal ( context ) ;
2018-06-13 16:24:34 +02:00
logger . trace ( " Going to create {} " , contextString ) ;
2023-02-27 18:21:52 +01:00
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest ( ) ;
gxHTTPStringRequest . header ( ACCEPT_HTTP_HEADER_KEY , GXConnection . APPLICATION_JSON_CHARSET_UTF_8 ) ;
gxHTTPStringRequest . header ( CONTENT_TYPE_HTTP_HEADER_KEY , GXConnection . APPLICATION_JSON_CHARSET_UTF_8 ) ;
2019-01-17 11:18:02 +01:00
gxHTTPStringRequest . path ( ContextPath . CONTEXTS_PATH_PART ) ;
gxHTTPStringRequest . path ( uuid . toString ( ) ) ;
2018-06-13 16:24:34 +02:00
2023-05-05 12:14:19 +02:00
includeAdditionalQueryParameters ( gxHTTPStringRequest ) ;
2019-01-17 11:18:02 +01:00
HttpURLConnection httpURLConnection = gxHTTPStringRequest . put ( contextString ) ;
String c = HTTPUtility . getResponse ( String . class , httpURLConnection ) ;
2018-06-13 16:24:34 +02:00
2020-11-04 19:34:07 +01:00
forceCacheRefresh ( ) ;
2020-11-04 17:38:57 +01:00
2020-11-04 19:34:07 +01:00
logger . trace ( " {} successfully created " , c ) ;
2018-06-13 16:24:34 +02:00
return c ;
2019-01-17 11:18:02 +01:00
} catch ( ResourceRegistryException e ) {
2018-06-13 16:24:34 +02:00
// logger.trace("Error Creating {}", facet, e);
throw e ;
2019-01-17 11:18:02 +01:00
} catch ( Exception e ) {
2018-06-13 16:24:34 +02:00
// logger.trace("Error Creating {}", facet, e);
throw new RuntimeException ( e ) ;
}
}
2017-11-23 11:42:05 +01:00
@Override
public Context create ( Context context ) throws ContextAlreadyPresentException , ResourceRegistryException {
try {
2018-06-13 16:24:34 +02:00
String res = internalCreate ( context ) ;
2020-02-03 10:52:35 +01:00
return ElementMapper . unmarshal ( Context . class , res ) ;
2019-01-17 11:18:02 +01:00
} catch ( ResourceRegistryException e ) {
2017-11-23 11:42:05 +01:00
// logger.trace("Error Creating {}", facet, e);
throw e ;
2019-01-17 11:18:02 +01:00
} catch ( Exception e ) {
2017-11-23 11:42:05 +01:00
// logger.trace("Error Creating {}", facet, e);
throw new RuntimeException ( e ) ;
}
}
2019-01-17 11:18:02 +01:00
2017-11-23 11:42:05 +01:00
@Override
public String create ( String context ) throws ContextAlreadyPresentException , ResourceRegistryException {
try {
2020-02-03 10:52:35 +01:00
Context c = ElementMapper . unmarshal ( Context . class , context ) ;
2018-06-13 16:24:34 +02:00
return internalCreate ( c ) ;
2019-01-17 11:18:02 +01:00
} catch ( ResourceRegistryException e ) {
2017-11-23 11:42:05 +01:00
// logger.trace("Error Creating {}", facet, e);
throw e ;
2019-01-17 11:18:02 +01:00
} catch ( Exception e ) {
2017-11-23 11:42:05 +01:00
// logger.trace("Error Creating {}", facet, e);
throw new RuntimeException ( e ) ;
}
}
2022-02-09 12:23:55 +01:00
public boolean existFromServer ( String uuid ) throws ContextNotFoundException , ResourceRegistryException {
try {
logger . trace ( " Going to read {} with UUID {} " , Context . NAME , uuid ) ;
2023-02-27 18:21:52 +01:00
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest ( ) ;
gxHTTPStringRequest . header ( ACCEPT_HTTP_HEADER_KEY , GXConnection . APPLICATION_JSON_CHARSET_UTF_8 ) ;
2022-02-09 12:23:55 +01:00
gxHTTPStringRequest . path ( ContextPath . CONTEXTS_PATH_PART ) ;
gxHTTPStringRequest . path ( uuid ) ;
HttpURLConnection httpURLConnection = gxHTTPStringRequest . head ( ) ;
HTTPUtility . getResponse ( String . class , httpURLConnection ) ;
return true ;
} catch ( NotFoundException e ) {
return false ;
} catch ( ResourceRegistryException e ) {
// logger.trace("Error Creating {}", facet, e);
throw e ;
} catch ( Exception e ) {
// logger.trace("Error Creating {}", facet, e);
throw new RuntimeException ( e ) ;
}
}
@Override
public boolean exist ( String uuid ) throws ResourceRegistryException {
return exist ( UUID . fromString ( uuid ) ) ;
}
@Override
public boolean exist ( UUID uuid ) throws ResourceRegistryException {
try {
read ( uuid ) ;
return true ;
} catch ( ContextNotFoundException e ) {
return false ;
}
}
2017-11-23 11:42:05 +01:00
@Override
public Context read ( Context context ) throws ContextNotFoundException , ResourceRegistryException {
2023-04-28 11:46:55 +02:00
return read ( context . getID ( ) ) ;
2017-11-23 11:42:05 +01:00
}
2019-01-17 11:18:02 +01:00
2017-11-23 11:42:05 +01:00
@Override
public Context read ( UUID uuid ) throws ContextNotFoundException , ResourceRegistryException {
2023-03-02 14:51:31 +01:00
Context context = contextCache . getContextByUUID ( uuid ) ; ;
2020-11-04 17:38:57 +01:00
if ( context = = null ) {
String contextJson = readFromServer ( uuid . toString ( ) ) ;
try {
context = ElementMapper . unmarshal ( Context . class , contextJson ) ;
} catch ( IOException e ) {
throw new RuntimeException ( e ) ;
}
2020-11-04 19:34:07 +01:00
forceCacheRefresh ( ) ;
2023-04-28 11:46:55 +02:00
Context c = contextCache . getContextByUUID ( context . getID ( ) ) ;
2020-11-04 17:38:57 +01:00
if ( c ! = null ) {
context = c ;
} else {
logger . error ( " Context with UUID {} is {}. It is possibile to get it from the server but not from the cache. This is very strange and should not occur. " , uuid , context ) ;
}
}
return context ;
}
2020-11-04 19:34:07 +01:00
@Override
public Context readCurrentContext ( ) throws ContextNotFoundException , ResourceRegistryException {
2023-02-22 15:14:45 +01:00
String contextFullName = ContextUtility . getCurrentContextFullName ( ) ;
2020-11-04 17:38:57 +01:00
UUID uuid = contextCache . getUUIDByFullName ( contextFullName ) ;
2023-03-02 14:51:31 +01:00
return read ( uuid ) ;
2020-11-04 17:38:57 +01:00
}
@Override
public String read ( String uuid ) throws ContextNotFoundException , ResourceRegistryException {
2017-11-23 11:42:05 +01:00
try {
2020-11-04 17:38:57 +01:00
return ElementMapper . marshal ( read ( UUID . fromString ( uuid ) ) ) ;
} catch ( ContextNotFoundException e ) {
2017-11-23 11:42:05 +01:00
throw e ;
2020-11-04 17:38:57 +01:00
} catch ( JsonProcessingException e ) {
2017-11-23 11:42:05 +01:00
throw new RuntimeException ( e ) ;
2020-11-04 17:38:57 +01:00
} catch ( ResourceRegistryException e ) {
throw e ;
2017-11-23 11:42:05 +01:00
}
}
2019-01-17 11:18:02 +01:00
2020-11-04 17:38:57 +01:00
public String readFromServer ( String uuid ) throws ContextNotFoundException , ResourceRegistryException {
2017-11-23 11:42:05 +01:00
try {
2018-06-11 16:27:29 +02:00
logger . trace ( " Going to read {} with UUID {} " , Context . NAME , uuid ) ;
2023-02-27 18:21:52 +01:00
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest ( ) ;
gxHTTPStringRequest . header ( ACCEPT_HTTP_HEADER_KEY , GXConnection . APPLICATION_JSON_CHARSET_UTF_8 ) ;
2019-01-17 11:18:02 +01:00
gxHTTPStringRequest . path ( ContextPath . CONTEXTS_PATH_PART ) ;
gxHTTPStringRequest . path ( uuid ) ;
2023-05-05 12:14:19 +02:00
includeAdditionalQueryParameters ( gxHTTPStringRequest ) ;
2019-01-17 11:18:02 +01:00
HttpURLConnection httpURLConnection = gxHTTPStringRequest . get ( ) ;
String c = HTTPUtility . getResponse ( String . class , httpURLConnection ) ;
2017-11-23 11:42:05 +01:00
logger . debug ( " Got {} is {} " , Context . NAME , c ) ;
return c ;
2019-01-17 11:18:02 +01:00
} catch ( ResourceRegistryException e ) {
2017-11-23 11:42:05 +01:00
// logger.trace("Error Creating {}", facet, e);
throw e ;
2019-01-17 11:18:02 +01:00
} catch ( Exception e ) {
2017-11-23 11:42:05 +01:00
// logger.trace("Error Creating {}", facet, e);
throw new RuntimeException ( e ) ;
}
}
2018-06-13 16:24:34 +02:00
2021-09-13 12:24:04 +02:00
public String internalUpdate ( Context context ) throws ContextNotFoundException , ResourceRegistryException {
2018-06-13 16:24:34 +02:00
try {
2020-02-03 10:52:35 +01:00
String contextString = ElementMapper . marshal ( context ) ;
2018-06-13 16:24:34 +02:00
logger . trace ( " Going to update {} " , contextString ) ;
2023-04-28 11:46:55 +02:00
UUID uuid = context . getID ( ) ;
2018-06-13 16:24:34 +02:00
2023-02-27 18:21:52 +01:00
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest ( ) ;
gxHTTPStringRequest . header ( ACCEPT_HTTP_HEADER_KEY , GXConnection . APPLICATION_JSON_CHARSET_UTF_8 ) ;
gxHTTPStringRequest . header ( CONTENT_TYPE_HTTP_HEADER_KEY , GXConnection . APPLICATION_JSON_CHARSET_UTF_8 ) ;
2019-01-17 11:18:02 +01:00
gxHTTPStringRequest . path ( ContextPath . CONTEXTS_PATH_PART ) ;
gxHTTPStringRequest . path ( uuid . toString ( ) ) ;
2023-05-05 12:14:19 +02:00
includeAdditionalQueryParameters ( gxHTTPStringRequest ) ;
2019-01-17 11:18:02 +01:00
HttpURLConnection httpURLConnection = gxHTTPStringRequest . put ( contextString ) ;
String c = HTTPUtility . getResponse ( String . class , httpURLConnection ) ;
2018-06-13 16:24:34 +02:00
2020-11-04 19:34:07 +01:00
forceCacheRefresh ( ) ;
2018-06-13 16:24:34 +02:00
logger . trace ( " {} successfully updated " , c ) ;
return c ;
2019-01-17 11:18:02 +01:00
} catch ( ResourceRegistryException e ) {
2018-06-13 16:24:34 +02:00
// logger.trace("Error Creating {}", facet, e);
throw e ;
2019-01-17 11:18:02 +01:00
} catch ( Exception e ) {
2018-06-13 16:24:34 +02:00
// logger.trace("Error Creating {}", facet, e);
throw new RuntimeException ( e ) ;
}
}
2017-11-23 11:42:05 +01:00
@Override
2021-09-13 12:24:04 +02:00
public Context update ( Context context ) throws ContextNotFoundException , ResourceRegistryException {
2017-11-23 11:42:05 +01:00
try {
2018-06-13 16:24:34 +02:00
String res = internalUpdate ( context ) ;
2020-02-03 10:52:35 +01:00
return ElementMapper . unmarshal ( Context . class , res ) ;
2019-01-17 11:18:02 +01:00
} catch ( ResourceRegistryException e ) {
2017-11-23 11:42:05 +01:00
// logger.trace("Error Updating {}", facet, e);
throw e ;
2019-01-17 11:18:02 +01:00
} catch ( Exception e ) {
2017-11-23 11:42:05 +01:00
// logger.trace("Error Updating {}", facet, e);
throw new RuntimeException ( e ) ;
}
}
2019-01-17 11:18:02 +01:00
2017-11-23 11:42:05 +01:00
@Override
2021-09-13 12:24:04 +02:00
public String update ( String context ) throws ContextNotFoundException , ResourceRegistryException {
2017-11-23 11:42:05 +01:00
try {
2020-02-03 10:52:35 +01:00
Context c = ElementMapper . unmarshal ( Context . class , context ) ;
2018-06-13 16:24:34 +02:00
return internalUpdate ( c ) ;
2019-01-17 11:18:02 +01:00
} catch ( ResourceRegistryException e ) {
2018-06-13 16:24:34 +02:00
// logger.trace("Error Updating {}", facet, e);
2017-11-23 11:42:05 +01:00
throw e ;
2019-01-17 11:18:02 +01:00
} catch ( Exception e ) {
2018-06-13 16:24:34 +02:00
// logger.trace("Error Updating {}", facet, e);
2017-11-23 11:42:05 +01:00
throw new RuntimeException ( e ) ;
}
}
2019-01-17 11:18:02 +01:00
2017-11-23 11:42:05 +01:00
@Override
public boolean delete ( Context context ) throws ContextNotFoundException , ResourceRegistryException {
2023-04-28 11:46:55 +02:00
return delete ( context . getID ( ) ) ;
2017-11-23 11:42:05 +01:00
}
2019-01-17 11:18:02 +01:00
2017-11-23 11:42:05 +01:00
@Override
public boolean delete ( UUID uuid ) throws ContextNotFoundException , ResourceRegistryException {
return delete ( uuid . toString ( ) ) ;
}
2019-01-17 11:18:02 +01:00
2017-11-23 11:42:05 +01:00
@Override
public boolean delete ( String uuid ) throws ContextNotFoundException , ResourceRegistryException {
try {
2017-11-23 12:33:08 +01:00
logger . trace ( " Going to delete {} with UUID {} " , Context . NAME , uuid ) ;
2023-02-27 18:21:52 +01:00
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest ( ) ;
gxHTTPStringRequest . header ( ACCEPT_HTTP_HEADER_KEY , GXConnection . APPLICATION_JSON_CHARSET_UTF_8 ) ;
2019-01-17 11:18:02 +01:00
gxHTTPStringRequest . path ( ContextPath . CONTEXTS_PATH_PART ) ;
gxHTTPStringRequest . path ( uuid ) ;
HttpURLConnection httpURLConnection = gxHTTPStringRequest . delete ( ) ;
2019-02-12 18:05:48 +01:00
HTTPUtility . getResponse ( String . class , httpURLConnection ) ;
boolean deleted = true ;
2019-01-17 11:18:02 +01:00
2017-11-23 11:42:05 +01:00
logger . info ( " {} with UUID {} {} " , Context . NAME , uuid ,
deleted ? " successfully deleted " : " was NOT deleted " ) ;
return deleted ;
2019-01-17 11:18:02 +01:00
} catch ( ResourceRegistryException e ) {
2017-11-23 11:42:05 +01:00
// logger.trace("Error Creating {}", facet, e);
throw e ;
2019-01-17 11:18:02 +01:00
} catch ( Exception e ) {
2017-11-23 11:42:05 +01:00
// logger.trace("Error Creating {}", facet, e);
throw new RuntimeException ( e ) ;
2020-11-04 17:38:57 +01:00
} finally {
try {
2023-03-02 14:51:31 +01:00
forceCacheRefresh ( ) ;
2020-11-04 17:38:57 +01:00
} catch ( Exception e ) {
}
2017-11-23 11:42:05 +01:00
}
}
2019-01-17 11:18:02 +01:00
2017-11-23 11:42:05 +01:00
}