Fixed bulk delete/purge

master
Luca Frosini 2 years ago
parent 1fcea2b14b
commit bc50f0b1e5

@ -43,6 +43,11 @@
<artifactId>gcat-api</artifactId>
<version>[2.0.0,3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>

@ -127,6 +127,9 @@ public class Item extends GCatClient implements org.gcube.gcat.api.interfaces.It
public Void bulkDelete(Map<String,String> queryParams, boolean purge) throws WebServiceException{
try {
initRequest();
if(queryParams==null) {
queryParams = new HashMap<>();
}
queryParams.put(GCatConstants.PURGE_QUERY_PARAMETER, String.valueOf(purge));
gxhttpStringRequest.queryParams(queryParams);
HttpURLConnection httpURLConnection = gxhttpStringRequest.delete();

@ -5,18 +5,11 @@ import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Properties;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.secret.GCubeSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
@ -24,8 +17,6 @@ import org.slf4j.LoggerFactory;
*/
public class ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
protected static Properties properties;
protected static final String PROPERTIES_FILENAME = "token.properties";
@ -76,36 +67,29 @@ public class ContextTest {
}
}
public static String getCurrentContextFullName() {
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry = null;
try {
authorizationEntry = Constants.authorizationService().get(token);
} catch(Exception e) {
return ScopeProvider.instance.get();
}
return authorizationEntry.getContext();
public static void set(Secret secret) throws Exception {
SecretManager.instance.get().reset();
secret.set();
}
public static String getContextFullName(String token) throws ObjectNotFound, Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
return authorizationEntry.getContext();
public static void setContext(String token) throws Exception {
Secret secret = getSecret(token);
set(secret);
}
public static void setContextByName(String fullContextName) throws Exception {
Secret secret = getSecretByContextName(fullContextName);
set(secret);
}
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
String token = ContextTest.properties.getProperty(fullContextName);
setContext(token);
private static Secret getSecret(String token) throws Exception {
GCubeSecret secret = new GCubeSecret(token);
return secret;
}
public static void setContext(String token) throws ObjectNotFound, Exception {
SecurityTokenProvider.instance.set(token);
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
ClientInfo clientInfo = authorizationEntry.getClientInfo();
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
String qualifier = authorizationEntry.getQualifier();
Caller caller = new Caller(clientInfo, qualifier);
AuthorizationProvider.instance.set(caller);
ScopeProvider.instance.set(getContextFullName(token));
private static Secret getSecretByContextName(String fullContextName) throws Exception {
String token = ContextTest.properties.getProperty(fullContextName);
return getSecret(token);
}
@BeforeClass
@ -115,8 +99,7 @@ public class ContextTest {
@AfterClass
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
SecretManager.instance.get().reset();
}
}

@ -12,8 +12,10 @@ import java.util.concurrent.TimeUnit;
import org.gcube.com.fasterxml.jackson.databind.JavaType;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.gcat.api.GCatConstants;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -49,37 +51,14 @@ public class ItemTest extends ContextTest {
private static final String ID_KEY = "id";
// @Test
public void deleteAllItems() throws Exception {
// ContextTest.setContext("");
/*
ObjectMapper mapper = new ObjectMapper();
JavaType listType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, String.class);
Item item = new Item();
String itemsString = item.list(1000, 0);
logger.debug("Got items {}", itemsString);
List<String> items = mapper.readValue(itemsString, listType);
logger.debug("Going to purge {} items", items.size());
for(String name : items) {
logger.debug("Going to purge item with name : {}", name);
try {
item.purge(name);
}catch (Exception e) {
logger.error("Error while purging item with name {}", name, e);
}
}
*/
}
@Test
public void testCount() throws MalformedURLException {
Item item = new Item();
int count = item.count();
logger.debug("The items published in the organization corresponding to the VRE {} are {}", ContextTest.getCurrentContextFullName(), count);
logger.debug("The items published in the organization corresponding to the VRE {} are {}", SecretManager.instance.get().getContext(), count);
}
@Ignore
@Test
public void completeTest() throws IOException {
ObjectMapper mapper = new ObjectMapper();
@ -209,6 +188,7 @@ public class ItemTest extends ContextTest {
protected static final String SEARCHABLE_KEY = "searchable";
public static final String GCAT_URL_STRING = "https://gcat.d4science.org/gcat";
@Ignore
// @Test
public void findNotSearchable() throws Exception {
ContextTest.setContextByName("/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue");
@ -233,6 +213,7 @@ public class ItemTest extends ContextTest {
}
}
@Ignore
// @Test
public void purgeAll() throws Exception {
ObjectMapper mapper = new ObjectMapper();
@ -250,4 +231,14 @@ public class ItemTest extends ContextTest {
Thread.sleep(TimeUnit.SECONDS.toMillis(5));
}
}
// @Ignore
@Test
public void testBulkPurge() throws Exception {
Item item = new Item();
Map<String,String> queryParams = new HashMap<>();
queryParams.put(GCatConstants.OWN_ONLY_QUERY_PARAMETER, "false");
item.bulkDelete(queryParams, false);
}
}

Loading…
Cancel
Save