Completed task #23692. Integrated with ContextText. Using gcat-client
[2.0.0-SNAPSHOT, 2.3.0-SNAPSHOT)
This commit is contained in:
parent
e0eff32f80
commit
b0a36a3da2
11
pom.xml
11
pom.xml
|
@ -52,6 +52,7 @@
|
|||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-user</artifactId>
|
||||
<version>${gwtVersion}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -100,7 +101,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.data-catalogue</groupId>
|
||||
<artifactId>gcat-client</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<version>[2.0.0-SNAPSHOT, 2.3.0-SNAPSHOT)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -170,6 +171,14 @@
|
|||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-utils</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
|||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
|
||||
import org.gcube.gcat.api.moderation.CMItemStatus;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -153,7 +154,7 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
|||
}else {
|
||||
LOG.debug("reading from the array the "+i+"mo json object");
|
||||
//here the array contains the list of dataset json fields
|
||||
jsonValueDataset = (String) jsonArray.get(i);
|
||||
jsonValueDataset = ((JSONObject) jsonArray.get(i)).toString();
|
||||
LOG.trace("the JSON dataset is: " + jsonValueDataset);
|
||||
}
|
||||
toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset, METHOD.TO_READ);
|
||||
|
@ -233,7 +234,7 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
|||
sortForField);
|
||||
|
||||
if (datasetNames != null) {
|
||||
LOG.debug("for status " + theStatus + " found dataset: " + datasetNames);
|
||||
LOG.trace("for status " + theStatus + " found dataset: " + datasetNames);
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
jsonArray = (JSONArray) parser.parse(datasetNames);
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/token.properties
|
|
@ -0,0 +1,147 @@
|
|||
package org.gcube.datacatalogue.utillibrary.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||
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;
|
||||
|
||||
/**
|
||||
* The Class ContextTest.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jul 28, 2022
|
||||
*/
|
||||
public class ContextTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
||||
|
||||
protected static Properties properties;
|
||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||
|
||||
public static final String ROOT = "/gcube";
|
||||
public static final String VO = ROOT + "/devsec";
|
||||
public static final String VRE = VO + "/devVRE";
|
||||
|
||||
static {
|
||||
properties = new Properties();
|
||||
|
||||
try (InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME)) {
|
||||
|
||||
if (input == null) {
|
||||
String error = "Sorry, unable to find the file: " + PROPERTIES_FILENAME;
|
||||
System.out.println(error);
|
||||
throw new RuntimeException(error);
|
||||
}
|
||||
|
||||
// load a properties file from class path, inside static method
|
||||
properties.load(input);
|
||||
|
||||
// // get the property value and print it out
|
||||
// System.out.println(prop.getProperty("db.url"));
|
||||
// System.out.println(prop.getProperty("db.user"));
|
||||
// System.out.println(prop.getProperty("db.password"));
|
||||
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the.
|
||||
*
|
||||
* @param secret the secret
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static void set(Secret secret) throws Exception {
|
||||
SecretManagerProvider.instance.reset();
|
||||
SecretManager secretManager = new SecretManager();
|
||||
SecretManagerProvider.instance.set(secretManager);
|
||||
secretManager.addSecret(secret);
|
||||
secretManager.set();
|
||||
String username = secretManager.getUser().getUsername();
|
||||
String context = secretManager.getContext();
|
||||
logger.debug("Set authorization for user {} in context {}", username, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the context.
|
||||
*
|
||||
* @param token the new context
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static void setContext(String token) throws Exception {
|
||||
Secret secret = getSecret(token);
|
||||
set(secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the context by name.
|
||||
*
|
||||
* @param fullContextName the new context by name
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static void setContextByName(String fullContextName) throws Exception {
|
||||
logger.debug("setContextByName {}", fullContextName);
|
||||
Secret secret = getSecretByContextName(fullContextName);
|
||||
set(secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the secret.
|
||||
*
|
||||
* @param token the token
|
||||
* @return the secret
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private static Secret getSecret(String token) throws Exception {
|
||||
GCubeSecret secret = new GCubeSecret(token);
|
||||
return secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the secret by context name.
|
||||
*
|
||||
* @param fullContextName the full context name
|
||||
* @return the secret by context name
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private static Secret getSecretByContextName(String fullContextName) throws Exception {
|
||||
logger.debug("getSecretByContextName {}", fullContextName);
|
||||
String token = ContextTest.properties.getProperty(fullContextName);
|
||||
logger.debug("token is {}", token);
|
||||
return getSecret(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before class.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
logger.debug("beforeClass");
|
||||
setContextByName(VRE);
|
||||
}
|
||||
|
||||
/**
|
||||
* After class.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
logger.debug("afterClass");
|
||||
SecretManagerProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
|
@ -14,6 +14,8 @@ import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorS
|
|||
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
||||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
|
||||
import org.gcube.gcat.client.Item;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
|
@ -21,7 +23,7 @@ import org.slf4j.LoggerFactory;
|
|||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Jun 1, 2020
|
||||
*/
|
||||
public class TestDataCatalogueCMS {
|
||||
public class TestDataCatalogueCMS extends ContextTest {
|
||||
|
||||
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestDataCatalogueCMS.class);
|
||||
|
||||
|
@ -36,21 +38,21 @@ public class TestDataCatalogueCMS {
|
|||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Before
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
factory = DataCatalogueFactory.getFactory();
|
||||
}
|
||||
|
||||
//@Test
|
||||
@Test
|
||||
public void testGCatAvailability() {
|
||||
try {
|
||||
LOG.info("testGCatAvailability running");
|
||||
|
||||
int offset = 0;
|
||||
int limit = 10;
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
LOG.debug("Trying with scope: "+scope);
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
// LOG.debug("Trying with scope: "+scope);
|
||||
String items = new Item().list(limit, offset);
|
||||
LOG.debug("List items: " + items);
|
||||
} catch (Exception e) {
|
||||
|
@ -63,22 +65,23 @@ public class TestDataCatalogueCMS {
|
|||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
// @Test
|
||||
//@Test
|
||||
public void contentModeratorTest() throws Exception {
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
|
||||
DataCatalogueImpl dImpl = factory.getUtilsPerScope(scope);
|
||||
CatalogueContentModeratorSystem cCMS = dImpl.getCatalogueContentModerator();
|
||||
LOG.debug(CatalogueContentModeratorSystem.class.getName() + " instancied correclty");
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void listItemsForCMStatus() throws Exception {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
ItemStatus theStatus = ItemStatus.PENDING;
|
||||
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
DataCatalogueImpl dImpl = factory.getUtilsPerScope(scope);
|
||||
CatalogueContentModeratorSystem cCMS = dImpl.getCatalogueContentModerator();
|
||||
LOG.debug(CatalogueContentModeratorSystem.class.getName() + " instancied correclty");
|
||||
|
@ -93,14 +96,14 @@ public class TestDataCatalogueCMS {
|
|||
Map<String, String> filters = new HashMap<String, String>();
|
||||
filters.put("author_email", theQuery);
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
List<CkanDataset> listItems = cCMS.getListItemsForStatus(theStatus, 10, 0, true, filters,
|
||||
List<CkanDataset> listItems = cCMS.getListItemsForStatus(theStatus, 10, 0, false, filters,
|
||||
GCatCaller.DEFAULT_SORT_VALUE);
|
||||
int i = 0;
|
||||
for (CkanDataset ckanDataset : listItems) {
|
||||
System.out.println(++i + ") item returned: " + ckanDataset);
|
||||
}
|
||||
long endTime = System.currentTimeMillis()-start;
|
||||
System.out.println("Terminated in: "+endTime + "ms");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject;
|
||||
import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject.METHOD;
|
||||
import org.gcube.datacatalogue.utillibrary.gcat.GCatCaller;
|
||||
import org.gcube.datacatalogue.utillibrary.server.ApplicationProfileScopePerUrlReader;
|
||||
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory;
|
||||
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl;
|
||||
|
@ -63,7 +62,7 @@ public class TestDataCatalogueLib {
|
|||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
// @Test
|
||||
//@Test
|
||||
public void factoryTest() throws Exception {
|
||||
|
||||
DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
|
||||
|
@ -123,7 +122,7 @@ public class TestDataCatalogueLib {
|
|||
* @return the user role by group
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
// @Test
|
||||
//@Test
|
||||
public void getDataset() throws Exception {
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
String username = testUser;
|
||||
|
@ -157,7 +156,7 @@ public class TestDataCatalogueLib {
|
|||
LOG.debug("The user " + testUser + " in the org " + org.getName() + " has the role " + role);
|
||||
}
|
||||
|
||||
// @Test
|
||||
//@Test
|
||||
public void getOrganizationForName() throws Exception {
|
||||
|
||||
String orgName = "devvre";
|
||||
|
|
Loading…
Reference in New Issue