Compare commits
24 Commits
12
.classpath
12
.classpath
|
@ -13,11 +13,6 @@
|
|||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
@ -26,9 +21,14 @@
|
|||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
|
|
|
@ -10,6 +10,6 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<installed facet="java" version="1.8"/>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
<installed facet="java" version="1.8"/>
|
||||
</faceted-project>
|
||||
|
|
33
CHANGELOG.md
33
CHANGELOG.md
|
@ -4,11 +4,44 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v1.4.0] - 2024-03-19
|
||||
|
||||
**Enhancements**
|
||||
|
||||
- Added method update item [#26640]
|
||||
- Added method deleteDataset [#26793]
|
||||
- Added method getListExtrasAsHashMap - D4Science model compliant
|
||||
|
||||
|
||||
## [v1.3.0] - 2023-02-06
|
||||
|
||||
**Enhancements**
|
||||
|
||||
- [#23903] Catalogue Moderation: allow to send a message to the moderators
|
||||
- [#23692] Changed interface 'approveItem' adding the parameter socialPost
|
||||
|
||||
## [v1.2.0] - 2022-08-01
|
||||
|
||||
**Enhancements**
|
||||
|
||||
- [#23692] Optimized the listing and the paging of catalogue items
|
||||
- Moved to maven-portal-bom 3.6.4
|
||||
|
||||
## [v1.1.0] - 2022-05-18
|
||||
|
||||
**New Features**
|
||||
|
||||
- [#21643] Integrated with the content-moderator-system facilities
|
||||
- [#22838] Integrated the collection provided by gCat to read the service configurations
|
||||
- [#23108] The Moderation facility accessible to Catalogue Editor/Admin in read only mode
|
||||
- [#23197] Revised the query passed to gCat with the moderation states
|
||||
|
||||
## [v1.0.3] - 2022-01-21
|
||||
|
||||
**Fixes**
|
||||
- [#22691] Share Link on private items does not work
|
||||
|
||||
|
||||
## [v1.0.2] - 2021-06-03
|
||||
|
||||
**Fixes**
|
||||
|
|
20
pom.xml
20
pom.xml
|
@ -6,14 +6,13 @@
|
|||
<parent>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.2.0</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
<groupId>org.gcube.datacatalogue</groupId>
|
||||
<artifactId>catalogue-util-library</artifactId>
|
||||
<version>1.0.3</version>
|
||||
|
||||
<version>1.4.0</version>
|
||||
<name>Ckan utility library</name>
|
||||
<description>
|
||||
Utility library to retrieve users information, organizations information and so on from the ckan d4science datacatalogue
|
||||
|
@ -31,6 +30,8 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<gwtVersion>2.7.0</gwtVersion>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<apache.http.version>4.4.1</apache.http.version>
|
||||
<gcube.jackson.version>2.8.11</gcube.jackson.version>
|
||||
</properties>
|
||||
|
@ -40,7 +41,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>maven-portal-bom</artifactId>
|
||||
<version>3.6.2</version>
|
||||
<version>3.6.4</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -51,6 +52,7 @@
|
|||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-user</artifactId>
|
||||
<version>${gwtVersion}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -99,7 +101,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.data-catalogue</groupId>
|
||||
<artifactId>gcat-client</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0)</version>
|
||||
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -169,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>
|
||||
|
|
|
@ -249,8 +249,6 @@ public class DBCaller {
|
|||
PreparedStatement preparedStatement = connection.prepareStatement(query);
|
||||
preparedStatement.setString(1, username);
|
||||
preparedStatement.setString(2, state);
|
||||
|
||||
LOG.debug("The query is: "+preparedStatement.toString());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
|
|
@ -4,28 +4,42 @@
|
|||
package org.gcube.datacatalogue.utillibrary.gcat;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
import org.gcube.datacatalogue.utillibrary.shared.GCatCatalogueConfiguration;
|
||||
import org.gcube.gcat.api.configuration.CatalogueConfiguration;
|
||||
import org.gcube.gcat.api.moderation.CMItemStatus;
|
||||
import org.gcube.gcat.api.moderation.Moderated;
|
||||
import org.gcube.gcat.client.Configuration;
|
||||
import org.gcube.gcat.client.Group;
|
||||
import org.gcube.gcat.client.Item;
|
||||
import org.gcube.gcat.client.Resource;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class GCatCaller.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
|
||||
* May 29, 2020
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) May 29, 2020
|
||||
*/
|
||||
public class GCatCaller {
|
||||
|
||||
|
||||
private String catalogueURL;
|
||||
|
||||
private GCatCatalogueConfiguration catalogueConfiguration;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GCatCaller.class);
|
||||
|
||||
|
||||
public final static String MODERATOR_ITEM_STATUS_PARAMETER = Moderated.CM_ITEM_STATUS_QUERY_PARAMETER;
|
||||
|
||||
public final static String MODERATOR_ITEM_ANY_STATUS_VALUE = CMItemStatus.ANY.getValue();
|
||||
|
||||
public final static String DEFAULT_SORT_VALUE = "name asc";
|
||||
|
||||
/**
|
||||
* Instantiates a new g cat caller.
|
||||
*
|
||||
|
@ -34,68 +48,7 @@ public class GCatCaller {
|
|||
public GCatCaller(String catalogueURL) {
|
||||
this.catalogueURL = catalogueURL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the dataset for name.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @return the jsonValue
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String getDatasetForName(String datasetName) throws WebApplicationException, MalformedURLException {
|
||||
LOG.debug("GetDatasetForName called");
|
||||
LOG.info("Get dataset for name "+datasetName+ "called");
|
||||
return new Item().read(datasetName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the dataset.
|
||||
*
|
||||
* @param jsonDataset the json dataset
|
||||
* @param socialPost if true sends the social post
|
||||
* @return the jsonValue
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String createDataset(String jsonDataset, boolean socialPost) throws WebApplicationException, MalformedURLException {
|
||||
LOG.debug("Create dataset called");
|
||||
LOG.info("Calling create on: "+jsonDataset);
|
||||
return new Item().create(jsonDataset,socialPost);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the resource to dataset.
|
||||
*
|
||||
* @param datasetId the dataset id
|
||||
* @param jsonValueResource the json value resource
|
||||
* @return the string
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String addResourceToDataset(String datasetId, String jsonValueResource) throws MalformedURLException {
|
||||
LOG.debug("Create resource called");
|
||||
LOG.info("Calling create resource: "+jsonValueResource+ " for dataset id: "+datasetId);
|
||||
return new Resource().create(datasetId, jsonValueResource);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete resource.
|
||||
*
|
||||
* @param datasetId the dataset id
|
||||
* @param resourceId the resource id
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public void deleteResource(String datasetId, String resourceId) throws MalformedURLException {
|
||||
LOG.debug("Delete resource called");
|
||||
LOG.info("Calling delete resource with: "+resourceId+ " for dataset id: "+datasetId);
|
||||
new Resource().delete(datasetId, resourceId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the catalogue URL.
|
||||
*
|
||||
|
@ -105,7 +58,79 @@ public class GCatCaller {
|
|||
return catalogueURL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the dataset for name.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @return the jsonValue
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String getDatasetForName(String datasetName) throws WebApplicationException, MalformedURLException {
|
||||
LOG.debug("getDatasetForName called");
|
||||
LOG.info("Get dataset for name '" + datasetName + "' called");
|
||||
return new Item().read(datasetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the dataset.
|
||||
*
|
||||
* @param jsonDataset the json dataset
|
||||
* @param socialPost if true sends the social post
|
||||
* @return the jsonValue
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String createDataset(String jsonDataset, boolean socialPost)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
LOG.trace("createDataset called");
|
||||
LOG.info("Calling create on: " + jsonDataset);
|
||||
return new Item().create(jsonDataset, socialPost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update dataset.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param jsonDataset the json dataset
|
||||
* @return the string
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String updateDataset(String datasetName, String jsonDataset)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
LOG.trace("updateDataset called");
|
||||
LOG.info("Calling update item with name: " + datasetName + ", on: " + jsonDataset);
|
||||
return new Item().update(datasetName, jsonDataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the resource to dataset.
|
||||
*
|
||||
* @param datasetId the dataset id
|
||||
* @param jsonValueResource the json value resource
|
||||
* @return the string
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String addResourceToDataset(String datasetId, String jsonValueResource) throws MalformedURLException {
|
||||
LOG.trace("addResourceToDataset called");
|
||||
LOG.info("Calling create resource: " + jsonValueResource + " for dataset id: " + datasetId);
|
||||
return new Resource().create(datasetId, jsonValueResource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete resource.
|
||||
*
|
||||
* @param datasetId the dataset id
|
||||
* @param resourceId the resource id
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public void deleteResource(String datasetId, String resourceId) throws MalformedURLException {
|
||||
LOG.trace("deleteResource called");
|
||||
LOG.info("Calling delete resource with: " + resourceId + " for dataset id: " + datasetId);
|
||||
new Resource().delete(datasetId, resourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the group.
|
||||
*
|
||||
|
@ -113,27 +138,244 @@ public class GCatCaller {
|
|||
* @return the string
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String createGroup(String jsonGroup) throws MalformedURLException {
|
||||
LOG.debug("Create group called");
|
||||
LOG.info("Calling create group: "+jsonGroup);
|
||||
public String createGroup(String jsonGroup) throws MalformedURLException {
|
||||
LOG.trace("createGroup called");
|
||||
LOG.info("Calling create group: " + jsonGroup);
|
||||
return new Group().create(jsonGroup);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Patch dataset.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param jsonObj the json obj
|
||||
* @param jsonObj the json obj
|
||||
* @return the string
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String patchDataset(String datasetName, JSONObject jsonObj)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
LOG.trace("patchDataset called");
|
||||
LOG.info("Calling patch dataset with name: " + datasetName);
|
||||
|
||||
return new Item().patch(datasetName, jsonObj.toJSONString());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Message item. Send a message to Moderators
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param moderatorMessage the moderator message
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public void messageItem(String datasetName, String moderatorMessage)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
LOG.trace("messageItem called");
|
||||
LOG.info("Calling mesage item with name: " + datasetName + ", and msg: " + moderatorMessage);
|
||||
|
||||
new Item().message(datasetName, moderatorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve item.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param moderatorMessage the moderator message
|
||||
* @param sendSocialPost the send social post. If 'true` sends the social post
|
||||
* @return the string
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String approveItem(String datasetName, String moderatorMessage, Boolean sendSocialPost)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
LOG.trace("approveItem called");
|
||||
LOG.info("Calling approve item with name: " + datasetName + ", sendSocialPost: " + sendSocialPost
|
||||
+ ", msg: " + moderatorMessage);
|
||||
|
||||
return new Item().approve(datasetName, moderatorMessage, sendSocialPost);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject item.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param permanentlyDelete the permanently delete
|
||||
* @param moderatorMessage the moderator message
|
||||
* @return the string
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String patchDataset(String datasetName, JSONObject jsonObj) throws WebApplicationException, MalformedURLException {
|
||||
LOG.debug("Patch dataset called");
|
||||
LOG.info("Calling patch dataset with name: "+datasetName);
|
||||
return new Item().patch(datasetName, jsonObj.toJSONString());
|
||||
|
||||
public String rejectItem(String datasetName, boolean permanentlyDelete, String moderatorMessage)
|
||||
throws WebServiceException, MalformedURLException {
|
||||
LOG.trace("rejectItem called");
|
||||
LOG.info("Calling reject item with name: " + datasetName + ", and msg: " + moderatorMessage);
|
||||
|
||||
String toReturnMsg = new Item().reject(datasetName, moderatorMessage);
|
||||
|
||||
if (permanentlyDelete) {
|
||||
deleteItem(datasetName, true);
|
||||
}
|
||||
|
||||
return toReturnMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete item.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param purge the purge
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public void deleteItem(String datasetName, boolean purge) throws WebServiceException, MalformedURLException {
|
||||
LOG.trace("deleteItem called");
|
||||
LOG.info("Calling delete item with name: " + datasetName + ", and purge: " + purge);
|
||||
|
||||
new Item().delete(datasetName, purge);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list items for CM status.
|
||||
*
|
||||
* @param status the status
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @param allFields the all fields. If true returns the all fields of an item
|
||||
* @param filters the filters
|
||||
* @param sortForField the sort for field
|
||||
* @return the list items for CM status
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String getListItemsForCMStatus(CMItemStatus status, int limit, int offset, Boolean allFields,
|
||||
Map<String, String> filters, String sortForField) throws WebServiceException, MalformedURLException {
|
||||
LOG.trace("getListItemsForCMStatus called");
|
||||
LOG.info("called getListItemsForCMStatus called with [status: " + status + "], [limit: " + limit
|
||||
+ "], [offset: " + offset + "], [filters: " + filters + "]");
|
||||
|
||||
Map<String, String> queryParams = GCatCallerUtil.genericQueryBuilderFor(status, limit, offset, false, allFields,
|
||||
filters, sortForField);
|
||||
|
||||
return getListItemsForQuery(queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count list items for CM status.
|
||||
*
|
||||
* @param status the status
|
||||
* @param filters the filters
|
||||
* @return the number of items
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public int countListItemsForCMStatus(CMItemStatus status, Map<String, String> filters)
|
||||
throws WebServiceException, MalformedURLException {
|
||||
LOG.trace("countListItemsForCMStatus called");
|
||||
LOG.info("Calling count list items for [status: " + status + "], [filters: " + filters + "]");
|
||||
|
||||
Map<String, String> queryParams = GCatCallerUtil.genericQueryBuilderFor(status, null, null, true, false,
|
||||
filters, null);
|
||||
|
||||
String theCount = getListItemsForQuery(queryParams);
|
||||
int count = 0;
|
||||
try {
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject jsonCount = (JSONObject) parser.parse(theCount);
|
||||
Long total = (Long) jsonCount.get("count");
|
||||
count = total.intValue();
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Size retured by gCat is not an integer, returning: " + count, e);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list items.
|
||||
*
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @return the list items
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String getListItems(int limit, int offset) throws WebServiceException, MalformedURLException {
|
||||
LOG.trace("getListItems called");
|
||||
LOG.info("Calling list items with limit: " + limit + ", offset: " + offset);
|
||||
|
||||
return new Item().list(limit, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list items for query.
|
||||
*
|
||||
* @param queryParams the query params
|
||||
* @return the list items for query
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String getListItemsForQuery(Map<String, String> queryParams)
|
||||
throws WebServiceException, MalformedURLException {
|
||||
LOG.trace("getListItemsForQuery called");
|
||||
LOG.info("Calling list items for query: " + queryParams);
|
||||
|
||||
return new Item().list(queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration.
|
||||
*
|
||||
* @param reload the reload
|
||||
* @return the configuration
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public GCatCatalogueConfiguration getConfiguration(boolean reload) throws MalformedURLException {
|
||||
LOG.trace("getConfiguration called");
|
||||
LOG.info("Calling get configuration with reload config: " + reload);
|
||||
|
||||
if (reload || catalogueConfiguration == null) {
|
||||
catalogueConfiguration = new GCatCatalogueConfiguration();
|
||||
|
||||
Configuration gCatConfig = new Configuration();
|
||||
CatalogueConfiguration gCG = gCatConfig.read();
|
||||
|
||||
catalogueConfiguration.setCkanURL(gCG.getCkanURL());
|
||||
catalogueConfiguration.setContext(gCG.getContext());
|
||||
catalogueConfiguration.setDefaultOrganization(gCG.getDefaultOrganization());
|
||||
catalogueConfiguration.setModerationEnabled(gCG.isModerationEnabled());
|
||||
catalogueConfiguration.setSocialPostEnabled(gCG.isSocialPostEnabled());
|
||||
catalogueConfiguration.setNotificationToUsersEnabled(gCG.isNotificationToUsersEnabled());
|
||||
catalogueConfiguration.setSolrURL(gCG.getSolrURL());
|
||||
catalogueConfiguration.setSupportedOrganizations(gCG.getSupportedOrganizations());
|
||||
}
|
||||
LOG.info("returning gCatConfig: " + catalogueConfiguration);
|
||||
return catalogueConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset to page number.
|
||||
*
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @return the int
|
||||
*/
|
||||
private static int offsetToPageNumber(int limit, int offset) {
|
||||
|
||||
int pageNumber = offset;
|
||||
|
||||
try {
|
||||
pageNumber = offset / limit;
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Page number error: ", e);
|
||||
}
|
||||
|
||||
return pageNumber;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
package org.gcube.datacatalogue.utillibrary.gcat;
|
||||
|
||||
import java.io.InvalidObjectException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.gcat.api.GCatConstants;
|
||||
import org.gcube.gcat.api.moderation.CMItemStatus;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class GCatCallerUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Apr 7, 2022
|
||||
*/
|
||||
public class GCatCallerUtil {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GCatCallerUtil.class);
|
||||
|
||||
/**
|
||||
* Generic query builder for.
|
||||
*
|
||||
* @param status the status
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @param count the count. If true returns only the count
|
||||
* @param allFields the all fields. If true returns the all fields of an item
|
||||
* @param filters the filters
|
||||
* @param sort the sort
|
||||
* @return the map
|
||||
*/
|
||||
public static Map<String, String> genericQueryBuilderFor(CMItemStatus status, Integer limit, Integer offset,
|
||||
Boolean count, Boolean allFields, Map<String, String> filters, String sort) {
|
||||
LOG.info("genericQueryBuilderFor called with [status: " + status + "], [limit: " + limit + "], [offset: "
|
||||
+ offset + "], [count: " + count + "], [allFields: " + allFields + "], [filters: " + filters + "]");
|
||||
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
|
||||
if (filters != null) {
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
|
||||
List<String> keySet = new ArrayList<String>();
|
||||
keySet.addAll(filters.keySet());
|
||||
String firstKey = keySet.get(0);
|
||||
queryBuilder.append(firstKey + ":" + filters.get(firstKey));
|
||||
|
||||
for (int i = 1; i < keySet.size(); i++) {
|
||||
String key = keySet.get(i);
|
||||
queryBuilder.append(" AND " + key + ":" + filters.get(key));
|
||||
}
|
||||
queryParams.put("q", queryBuilder.toString());
|
||||
}
|
||||
|
||||
if (status != null) {
|
||||
queryParams.put(GCatCaller.MODERATOR_ITEM_STATUS_PARAMETER, status.getValue());
|
||||
}
|
||||
|
||||
if (limit != null) {
|
||||
limit = limit < 0 ? 10 : limit;
|
||||
queryParams.put(GCatConstants.LIMIT_QUERY_PARAMETER, String.valueOf(limit));
|
||||
}
|
||||
if (offset != null) {
|
||||
offset = offset < 0 ? 0 : offset;
|
||||
queryParams.put(GCatConstants.OFFSET_QUERY_PARAMETER, String.valueOf(offset));
|
||||
}
|
||||
|
||||
if (sort != null) {
|
||||
queryParams.put("sort", sort);
|
||||
} else {
|
||||
LOG.info("Adding defautl sort: " + GCatCaller.DEFAULT_SORT_VALUE);
|
||||
queryParams.put("sort", GCatCaller.DEFAULT_SORT_VALUE);
|
||||
}
|
||||
|
||||
if (count != null) {
|
||||
if (count) {
|
||||
queryParams.put(GCatConstants.COUNT_QUERY_PARAMETER, String.valueOf(count));
|
||||
}
|
||||
}
|
||||
|
||||
if (allFields != null) {
|
||||
if (allFields) {
|
||||
queryParams.put(GCatConstants.ALL_FIELDS_QUERY_PARAMETER, String.valueOf(allFields));
|
||||
}
|
||||
}
|
||||
|
||||
return queryParams;
|
||||
}
|
||||
|
||||
public static List<String> toListString(String gcatListResponse) throws InvalidObjectException {
|
||||
|
||||
List<String> listData = new ArrayList<String>();
|
||||
|
||||
if (gcatListResponse != null) {
|
||||
LOG.debug("converting list {}", gcatListResponse);
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
JSONArray jsonArray = (JSONArray) parser.parse(gcatListResponse);
|
||||
for (Object data : jsonArray) {
|
||||
if (data instanceof String) {
|
||||
listData.add((String) data);
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
LOG.error("error occurred reading " + gcatListResponse + " as JSONArray", e);
|
||||
throw new InvalidObjectException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return listData;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
|
|||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanGroup;
|
||||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanLicense;
|
||||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanOrganization;
|
||||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanResource;
|
||||
|
||||
/**
|
||||
* The Interface DataCatalogue.
|
||||
|
@ -77,12 +78,20 @@ public interface DataCatalogue {
|
|||
String getUriResolverUrl();
|
||||
|
||||
/**
|
||||
* Return the manage product property.
|
||||
* Return the manage product property (used in the GRSF[-ADMIN] contexts).
|
||||
*
|
||||
* @return the manage product property
|
||||
*/
|
||||
boolean isManageProductEnabled();
|
||||
|
||||
/**
|
||||
* Checks if is moderation enabled.
|
||||
*
|
||||
* @param reloadConfig the reload config from service
|
||||
* @return true, if is moderation enabled
|
||||
*/
|
||||
boolean isModerationEnabled(boolean reloadConfig);
|
||||
|
||||
/**
|
||||
* Return the catalogue portlet for this context(i.e. scope)
|
||||
*
|
||||
|
@ -324,6 +333,35 @@ public interface DataCatalogue {
|
|||
List<ResourceBean> resources, boolean setPublic, boolean setSearchable, boolean socialPost)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Update ckan dataset multiple custom fields.
|
||||
*
|
||||
* @param username the username
|
||||
* @param title the title
|
||||
* @param name the name
|
||||
* @param organizationName the organization name
|
||||
* @param author the author
|
||||
* @param authorMail the author mail
|
||||
* @param maintainer the maintainer
|
||||
* @param maintainerMail the maintainer mail
|
||||
* @param version the version
|
||||
* @param description the description
|
||||
* @param licenseId the license id
|
||||
* @param tags the tags
|
||||
* @param customFieldsMultiple the custom fields multiple
|
||||
* @param resources the resources
|
||||
* @param setPublic the set public
|
||||
* @param setSearchable the set searchable
|
||||
* @param socialPost the social post
|
||||
* @return the string
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
String updateCkanDatasetMultipleCustomFields(String username, String title, String name, String organizationName,
|
||||
String author, String authorMail, String maintainer, String maintainerMail, long version,
|
||||
String description, String licenseId, List<String> tags, Map<String, List<String>> customFieldsMultiple,
|
||||
List<ResourceBean> resources, boolean setPublic, boolean setSearchable, boolean socialPost)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Add a resource described by the bean to the dataset id into
|
||||
* resource.datasetId
|
||||
|
@ -332,14 +370,28 @@ public interface DataCatalogue {
|
|||
* @param organizationName the organization name
|
||||
* @param username the username
|
||||
* @return String the id of the resource on success, null otherwise
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
String addResourceToDataset(ResourceBean resourceBean, String organizationName, String username) throws Exception;
|
||||
|
||||
/**
|
||||
* Adds the resource.
|
||||
*
|
||||
* @param resourceBean the resource bean
|
||||
* @param datasetId the dataset id
|
||||
* @param organizationName the organization name
|
||||
* @param username the username
|
||||
* @return the ckan resource
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
CkanResource addResource(ResourceBean resourceBean, String datasetId, String organizationName, String username)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Remove the resource with id resourceId from dataset in which it is.
|
||||
*
|
||||
* @param resourceId the resource id
|
||||
* @param username the username
|
||||
* @param username the username
|
||||
* @return true on success, false otherwise.
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
|
@ -401,6 +453,24 @@ public interface DataCatalogue {
|
|||
boolean patchProductCustomFields(String productId, String username, Map<String, List<String>> customFieldsToChange,
|
||||
boolean removeOld);
|
||||
|
||||
/**
|
||||
* Refresh dataset.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @return the string
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
String refreshDataset(String datasetName) throws Exception;
|
||||
|
||||
/**
|
||||
* Delete dataset.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @return true, if successful
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
boolean deleteDataset(String datasetName) throws Exception;
|
||||
|
||||
/**
|
||||
* Patch a product with product id productId by using the couples in
|
||||
* customFieldsToChange. NOTE: only the specified custom fields will be changed.
|
||||
|
@ -408,9 +478,9 @@ public interface DataCatalogue {
|
|||
* false, the new values are added at the end of the list. Otherwise they are
|
||||
* lost.
|
||||
*
|
||||
* @param productId the product id
|
||||
* @param customFieldsToChange the custom fields to change
|
||||
* @param removeOld the remove old
|
||||
* @param username the username
|
||||
* @param sourceOrganization the source organization
|
||||
* @param currentRole the current role
|
||||
* @return true, if successful
|
||||
*/
|
||||
// boolean patchProductCustomFields(String productId, Map<String, List<String>> customFieldsToChange,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,101 @@
|
|||
package org.gcube.datacatalogue.utillibrary.server.cms;
|
||||
|
||||
import java.io.InvalidObjectException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
||||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
|
||||
|
||||
/**
|
||||
* The Interface CatalogueContentModeratorSystem.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jan 10, 2022
|
||||
*/
|
||||
public interface CatalogueContentModeratorSystem {
|
||||
|
||||
/**
|
||||
* Checks if is moderation enabled.
|
||||
*
|
||||
* @param reloadConfig the reload config
|
||||
* @return true, if is moderation enabled
|
||||
* @throws MalformedURLException
|
||||
*/
|
||||
boolean isModerationEnabled(boolean reloadConfig) throws MalformedURLException;
|
||||
|
||||
/**
|
||||
* Gets the list items for status.
|
||||
*
|
||||
* @param theStatus the the status
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @param allFields the all fields. If true returns the all fields of an item
|
||||
* @param filters add the input filters to query on CKAN
|
||||
* @param sortForField the sort for field
|
||||
* @return the list items for status
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
* @throws InvalidObjectException the invalid object exception
|
||||
*/
|
||||
List<CkanDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset, Boolean allFields,
|
||||
Map<String, String> filters, String sortForField)
|
||||
throws WebApplicationException, MalformedURLException, InvalidObjectException;
|
||||
|
||||
/**
|
||||
* Reject item.
|
||||
*
|
||||
* @param itemName the item name
|
||||
* @param permanentlyDelete the permanently delete
|
||||
* @param reasonMsg the reason msg
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
void rejectItem(String itemName, boolean permanentlyDelete, String reasonMsg)
|
||||
throws WebServiceException, MalformedURLException;
|
||||
|
||||
/**
|
||||
* Permanently delete.
|
||||
*
|
||||
* @param itemName the item name
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
void permanentlyDelete(String itemName) throws WebServiceException, MalformedURLException;
|
||||
|
||||
/**
|
||||
* Count list items for status.
|
||||
*
|
||||
* @param theStatus the the status
|
||||
* @param filters add the input filters to query on CKAN
|
||||
* @return the long
|
||||
*/
|
||||
long countListItemsForStatus(ItemStatus theStatus, Map<String, String> filters);
|
||||
|
||||
/**
|
||||
* Approve item.
|
||||
*
|
||||
* @param itemName the item name
|
||||
* @param moderatorMessage the moderator message
|
||||
* @param sendSocialPost the send social post. If 'true` sends the social post
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
void approveItem(String itemName, String moderatorMessage, Boolean sendSocialPost) throws WebApplicationException, MalformedURLException;
|
||||
|
||||
/**
|
||||
* Message item.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param moderatorMessage the moderator message
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
void messageItem(String datasetName, String moderatorMessage) throws WebServiceException, MalformedURLException;
|
||||
|
||||
}
|
|
@ -0,0 +1,285 @@
|
|||
package org.gcube.datacatalogue.utillibrary.server.cms;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
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.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;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class DataCatalogueCMSImpl.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jun 14, 2021
|
||||
*/
|
||||
public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DataCatalogueCMSImpl.class);
|
||||
private String runningScope;
|
||||
private GCatCaller gCatCaller;
|
||||
|
||||
/**
|
||||
* Instantiates a new data catalogue CMS impl.
|
||||
*
|
||||
* @param runningScope the running scope
|
||||
* @param gCatCaller the g cat caller
|
||||
*/
|
||||
public DataCatalogueCMSImpl(String runningScope, GCatCaller gCatCaller) {
|
||||
this.runningScope = runningScope;
|
||||
this.gCatCaller = gCatCaller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is Moderation is enabled in the working scope.
|
||||
*
|
||||
* @param reloadConfig the reload config
|
||||
* @return true, if is content moderator enabled
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
@Override
|
||||
public boolean isModerationEnabled(boolean reloadConfig) throws MalformedURLException {
|
||||
return gCatCaller.getConfiguration(reloadConfig).isModerationEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve item.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param moderatorMessage the moderator message
|
||||
* @param sendSocialPost the send social post. If 'true` sends the social post
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
@Override
|
||||
public void approveItem(String datasetName, String moderatorMessage, Boolean sendSocialPost)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
gCatCaller.approveItem(datasetName, moderatorMessage, sendSocialPost);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Message item.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param moderatorMessage the moderator message
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
@Override
|
||||
public void messageItem(String datasetName, String moderatorMessage)
|
||||
throws WebServiceException, MalformedURLException {
|
||||
gCatCaller.messageItem(datasetName, moderatorMessage);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject item.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param permanentlyDelete the permanently delete
|
||||
* @param moderatorMessage the moderator message
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
@Override
|
||||
public void rejectItem(String datasetName, boolean permanentlyDelete, String moderatorMessage)
|
||||
throws WebServiceException, MalformedURLException {
|
||||
gCatCaller.rejectItem(datasetName, permanentlyDelete, moderatorMessage);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently delete.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
@Override
|
||||
public void permanentlyDelete(String datasetName) throws WebServiceException, MalformedURLException {
|
||||
gCatCaller.deleteItem(datasetName, true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the running scope.
|
||||
*
|
||||
* @return the running scope
|
||||
*/
|
||||
public String getRunningScope() {
|
||||
return runningScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list items for status.
|
||||
*
|
||||
* @param theStatus the the status
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @param allFields the all fields. If true returns the all fields of an item
|
||||
* @param filters add the input filters to query on CKAN
|
||||
* @param sortForField the sort for field
|
||||
* @return the list items for status
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
* @throws InvalidObjectException the invalid object exception
|
||||
*/
|
||||
@Override
|
||||
public List<CkanDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset, Boolean allFields,
|
||||
Map<String, String> filters, String sortForField)
|
||||
throws WebApplicationException, MalformedURLException, InvalidObjectException {
|
||||
LOG.info("called getListItemsForStatus with [status: " + theStatus + "], [limit: " + limit + "], [offset: "
|
||||
+ offset + "], [allFields: " + allFields + "], [filters: " + filters + "]");
|
||||
List<CkanDataset> listDataset = null;
|
||||
checkNotNull(theStatus);
|
||||
JSONArray jsonArray = getSourceArrayOfItemsForStatus(theStatus, limit, offset, allFields, filters, sortForField);
|
||||
|
||||
if (jsonArray != null) {
|
||||
int size = jsonArray.size();
|
||||
listDataset = new ArrayList<CkanDataset>(size);
|
||||
LOG.info("reading and converting " + size + " dataset...");
|
||||
for (int i = 0; i < size; i++) {
|
||||
String jsonValueDataset = null;
|
||||
try {
|
||||
CkanDataset toCkanDataset = null;
|
||||
if(!allFields) {
|
||||
//here the array contains the list of dataset name
|
||||
String datasetName = (String) jsonArray.get(i);
|
||||
LOG.debug("going to read from gCat the dataset: " + datasetName);
|
||||
jsonValueDataset = gCatCaller.getDatasetForName(datasetName);
|
||||
LOG.trace("the JSON dataset is: " + jsonValueDataset);
|
||||
}else {
|
||||
LOG.debug("reading from the array the "+i+"mo json object");
|
||||
//here the array contains the list of dataset json fields
|
||||
jsonValueDataset = ((JSONObject) jsonArray.get(i)).toString();
|
||||
LOG.trace("the JSON dataset is: " + jsonValueDataset);
|
||||
}
|
||||
toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset, METHOD.TO_READ);
|
||||
LOG.debug("converted as dataset: " + toCkanDataset);
|
||||
listDataset.add(toCkanDataset);
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Error on reading/converting the dataset: " + jsonValueDataset, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (listDataset == null) {
|
||||
LOG.info("no dataset returned with status: " + theStatus);
|
||||
return listDataset;
|
||||
}
|
||||
|
||||
LOG.info("returning listDataset with size: " + listDataset.size());
|
||||
return listDataset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count list items for status.
|
||||
*
|
||||
* @param theStatus the the status
|
||||
* @param filters add the input filters to query on CKAN
|
||||
* @return the number of items with the input status
|
||||
*/
|
||||
@Override
|
||||
public long countListItemsForStatus(ItemStatus theStatus, Map<String, String> filters) {
|
||||
LOG.info("called countListItemsForStatus with [status: " + theStatus + "]");
|
||||
checkNotNull(theStatus);
|
||||
int count = 0;
|
||||
try {
|
||||
CMItemStatus cmStatus = toCMStatus(theStatus);
|
||||
count = gCatCaller.countListItemsForCMStatus(cmStatus, filters);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error on counting the items for status " + theStatus, e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source array of items for status read by gCatClient.
|
||||
*
|
||||
* @param theStatus the the status
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @param allFields the all fields. If true returns the all fields of an item
|
||||
* @param filters the filters
|
||||
* @param sortForField the sort for field
|
||||
* @return the source array of items for status
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
* @throws InvalidObjectException the invalid object exception
|
||||
*/
|
||||
protected org.json.simple.JSONArray getSourceArrayOfItemsForStatus(ItemStatus theStatus, int limit, int offset,
|
||||
Boolean allFields, Map<String, String> filters, String sortForField)
|
||||
throws WebApplicationException, MalformedURLException, InvalidObjectException {
|
||||
LOG.info("called getSourceArrayOfItemsForStatus with [status: " + theStatus + "], [limit: " + limit
|
||||
+ "], [offset: " + offset + "], [allFields: " + allFields + "], [filters: " + filters + "]");
|
||||
checkNotNull(theStatus);
|
||||
// TODO MUST BE CHANGED FOR THE STATUS
|
||||
org.json.simple.JSONArray jsonArray = null;
|
||||
|
||||
/*
|
||||
* String datasetNames = null; if(theStatus.equals(ItemStatus.PUBLISHED)) {
|
||||
* datasetNames = gCatCaller.getListItems(limit, offset); }else { CMItemStatus
|
||||
* cmiStatus = toCMStatus(theStatus); datasetNames =
|
||||
* gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset); }
|
||||
*/
|
||||
|
||||
CMItemStatus cmiStatus = toCMStatus(theStatus);
|
||||
String datasetNames = gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset, allFields, filters,
|
||||
sortForField);
|
||||
|
||||
if (datasetNames != null) {
|
||||
LOG.trace("for status " + theStatus + " found dataset: " + datasetNames);
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
jsonArray = (JSONArray) parser.parse(datasetNames);
|
||||
} catch (ParseException e) {
|
||||
LOG.error("error occurred reading " + datasetNames + " as JSONArray", e);
|
||||
throw new InvalidObjectException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return jsonArray;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* To CM status.
|
||||
*
|
||||
* @param theStatus the the status
|
||||
* @return the CM item status
|
||||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
private CMItemStatus toCMStatus(ItemStatus theStatus) throws WebApplicationException {
|
||||
try {
|
||||
return CMItemStatus.valueOf(theStatus.name());
|
||||
} catch (Exception e) {
|
||||
throw new WebApplicationException(
|
||||
"No value of " + theStatus.name() + " into enumerator: " + CMItemStatus.values());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -68,8 +68,10 @@ public class CKANConveter {
|
|||
String ckanUsername = CatalogueUtilMethods.fromUsernameToCKanUsername(username);
|
||||
|
||||
String nameToUse = name;
|
||||
if(nameToUse == null)
|
||||
//Applying normalize function if and only if the paramenter 'name' is null
|
||||
if(nameToUse == null) {
|
||||
nameToUse = CatalogueUtilMethods.fromProductTitleToName(title);
|
||||
}
|
||||
|
||||
LOG.debug("Name of the dataset is going to be " + nameToUse + ". Title is going to be " + title);
|
||||
|
||||
|
|
|
@ -96,15 +96,16 @@ public class GCubeUtils {
|
|||
|
||||
|
||||
/**
|
||||
* Detect the OrgName contexts (token and scope) if the working context (in the thread) is a root VO or VO and switch to it according to setInThread parameters
|
||||
* Detect the organizationName context (token and scope of VRE).
|
||||
* If the working context (in the thread) is a root VO or VO and setInThread is true then switch to VRE context (setting ScopeProvider and SecurityTokenProvider)
|
||||
*
|
||||
* @param organizationName the organization name to switch to
|
||||
* @param username the username
|
||||
* @param setInThread set in the target token (in the {@link SecurityTokenProvider}) and the scope (in the {@link ScopeProvider}) detected for the OrgName
|
||||
* @return the gcube context
|
||||
* @param setInThread if true set the target token (in the {@link SecurityTokenProvider}) and the scope (in the {@link ScopeProvider}) detected for the OrgName
|
||||
* @return the gcube context with source scope/token and target (detected for organizationName) scope/token
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static GcubeContext detectTheOrgNameContexts(String organizationName, String username, boolean setInThread) throws Exception {
|
||||
public static GcubeContext detectAndSetTheOrgNameContext(String organizationName, String username, boolean setInThread) throws Exception {
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
package org.gcube.datacatalogue.utillibrary.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
public class GCatCatalogueConfiguration implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1250433017161647236L;
|
||||
private String context;
|
||||
private String defaultOrganization;
|
||||
private Set<String> supportedOrganizations;
|
||||
|
||||
private String ckanURL;
|
||||
private String solrURL;
|
||||
private boolean socialPostEnabled;
|
||||
private boolean notificationToUsersEnabled;
|
||||
private boolean moderationEnabled;
|
||||
|
||||
public GCatCatalogueConfiguration() {
|
||||
|
||||
}
|
||||
|
||||
public String getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public String getDefaultOrganization() {
|
||||
return defaultOrganization;
|
||||
}
|
||||
|
||||
public Set<String> getSupportedOrganizations() {
|
||||
return supportedOrganizations;
|
||||
}
|
||||
|
||||
public String getCkanURL() {
|
||||
return ckanURL;
|
||||
}
|
||||
|
||||
public String getSolrURL() {
|
||||
return solrURL;
|
||||
}
|
||||
|
||||
public boolean isSocialPostEnabled() {
|
||||
return socialPostEnabled;
|
||||
}
|
||||
|
||||
public boolean isNotificationToUsersEnabled() {
|
||||
return notificationToUsersEnabled;
|
||||
}
|
||||
|
||||
public boolean isModerationEnabled() {
|
||||
return moderationEnabled;
|
||||
}
|
||||
|
||||
public void setContext(String context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void setDefaultOrganization(String defaultOrganization) {
|
||||
this.defaultOrganization = defaultOrganization;
|
||||
}
|
||||
|
||||
public void setSupportedOrganizations(Set<String> supportedOrganizations) {
|
||||
this.supportedOrganizations = supportedOrganizations;
|
||||
}
|
||||
|
||||
public void setCkanURL(String ckanURL) {
|
||||
this.ckanURL = ckanURL;
|
||||
}
|
||||
|
||||
public void setSolrURL(String solrURL) {
|
||||
this.solrURL = solrURL;
|
||||
}
|
||||
|
||||
public void setSocialPostEnabled(boolean socialPostEnabled) {
|
||||
this.socialPostEnabled = socialPostEnabled;
|
||||
}
|
||||
|
||||
public void setNotificationToUsersEnabled(boolean notificationToUsersEnabled) {
|
||||
this.notificationToUsersEnabled = notificationToUsersEnabled;
|
||||
}
|
||||
|
||||
public void setModerationEnabled(boolean moderationEnabled) {
|
||||
this.moderationEnabled = moderationEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("GCatCatalogueConfiguration [context=");
|
||||
builder.append(context);
|
||||
builder.append(", defaultOrganization=");
|
||||
builder.append(defaultOrganization);
|
||||
builder.append(", supportedOrganizations=");
|
||||
builder.append(supportedOrganizations);
|
||||
builder.append(", ckanURL=");
|
||||
builder.append(ckanURL);
|
||||
builder.append(", solrURL=");
|
||||
builder.append(solrURL);
|
||||
builder.append(", socialPostEnabled=");
|
||||
builder.append(socialPostEnabled);
|
||||
builder.append(", notificationToUsersEnabled=");
|
||||
builder.append(notificationToUsersEnabled);
|
||||
builder.append(", moderationEnabled=");
|
||||
builder.append(moderationEnabled);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package org.gcube.datacatalogue.utillibrary.shared;
|
||||
|
||||
/**
|
||||
* The Enum ItemStatus.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Feb 17, 2022
|
||||
*/
|
||||
public enum ItemStatus {
|
||||
PENDING("pending", "Pending"), APPROVED("approved", "Approved"), REJECTED("rejected", "Rejected");
|
||||
// Published means that the item is published in the Catalogue, no status is checked,
|
||||
// the "simple" get list of items is called
|
||||
//PUBLISHED("published", "Published");
|
||||
|
||||
private String id;
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* Instantiates a new item status.
|
||||
*
|
||||
* @param id the id
|
||||
* @param label the label
|
||||
*/
|
||||
private ItemStatus(String id, String label) {
|
||||
this.id = id;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the label.
|
||||
*
|
||||
* @return the label
|
||||
*/
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
}
|
|
@ -30,17 +30,15 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
|
|||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A Ckan Dataset, which in turn holds Ckan Resources.
|
||||
*
|
||||
* In Ckan terminology it is also known as 'package'.
|
||||
*
|
||||
* {@link CkanDatasetBase} holds fields that can be sent when
|
||||
* <a href="http://docs.ckan.org/en/latest/api/index.html?#ckan.logic.action.create.package_create" target="_blank">creating
|
||||
* a dataset,</a>, while {@link CkanDataset} holds more fields that can be
|
||||
* returned with searches.
|
||||
* {@link CkanDatasetBase} holds fields that can be sent when <a href=
|
||||
* "http://docs.ckan.org/en/latest/api/index.html?#ckan.logic.action.create.package_create"
|
||||
* target="_blank">creating a dataset,</a>, while {@link CkanDataset} holds more
|
||||
* fields that can be returned with searches.
|
||||
*
|
||||
* This class initializes nothing to fully preserve all we get from ckan. In
|
||||
* practice, all fields of retrieved resources can be null except maybe
|
||||
|
@ -51,148 +49,148 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
|||
*/
|
||||
public class CkanDatasetBase {
|
||||
|
||||
private String author;
|
||||
private String authorEmail;
|
||||
private List<CkanPair> extras;
|
||||
private List<CkanGroup> groups;
|
||||
private String id;
|
||||
private String licenseId;
|
||||
private String maintainer;
|
||||
private String maintainerEmail;
|
||||
private String name;
|
||||
private String notes;
|
||||
private String ownerOrg;
|
||||
private List<CkanDatasetRelationship> relationshipsAsObject;
|
||||
private List<CkanDatasetRelationship> relationshipsAsSubject;
|
||||
private List<CkanResource> resources;
|
||||
private CkanState state;
|
||||
private List<CkanTag> tags;
|
||||
private String title;
|
||||
private String type;
|
||||
private String url;
|
||||
private String version;
|
||||
|
||||
private Boolean priv;
|
||||
private String author;
|
||||
private String authorEmail;
|
||||
private List<CkanPair> extras;
|
||||
private List<CkanGroup> groups;
|
||||
private String id;
|
||||
private String licenseId;
|
||||
private String maintainer;
|
||||
private String maintainerEmail;
|
||||
private String name;
|
||||
private String notes;
|
||||
private String ownerOrg;
|
||||
private List<CkanDatasetRelationship> relationshipsAsObject;
|
||||
private List<CkanDatasetRelationship> relationshipsAsSubject;
|
||||
private List<CkanResource> resources;
|
||||
private CkanState state;
|
||||
private List<CkanTag> tags;
|
||||
private String title;
|
||||
private String type;
|
||||
private String url;
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* Custom CKAN instances might sometimes gift us with properties that don't
|
||||
* end up in extras. They will end up here.
|
||||
*/
|
||||
@Nullable
|
||||
private Map<String, Object> others;
|
||||
private Boolean priv;
|
||||
|
||||
public CkanDatasetBase() {
|
||||
}
|
||||
/**
|
||||
* Custom CKAN instances might sometimes gift us with properties that don't end
|
||||
* up in extras. They will end up here.
|
||||
*/
|
||||
@Nullable
|
||||
private Map<String, Object> others;
|
||||
|
||||
/**
|
||||
* Constructor with the minimal set of attributes required to successfully
|
||||
* create a dataset on the server.
|
||||
*
|
||||
* @param name the dataset name (contains no spaces and has dashes as
|
||||
* separators, i.e. "limestone-pavement-orders")
|
||||
*/
|
||||
public CkanDatasetBase(String name) {
|
||||
this();
|
||||
this.name = name;
|
||||
}
|
||||
public CkanDatasetBase() {
|
||||
}
|
||||
|
||||
/**
|
||||
* CKAN instances might have
|
||||
* <a href="http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html">
|
||||
* custom data schemas</a> that force presence of custom properties among
|
||||
* 'regular' ones. In this case, they go to 'others' field. Note that to
|
||||
* further complicate things there is also an {@link #getExtras() extras}
|
||||
* field.
|
||||
*
|
||||
* @see #putOthers(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
@JsonAnyGetter
|
||||
@Nullable
|
||||
public Map<String, Object> getOthers() {
|
||||
return others;
|
||||
}
|
||||
/**
|
||||
* Constructor with the minimal set of attributes required to successfully
|
||||
* create a dataset on the server.
|
||||
*
|
||||
* @param name the dataset name (contains no spaces and has dashes as
|
||||
* separators, i.e. "limestone-pavement-orders")
|
||||
*/
|
||||
public CkanDatasetBase(String name) {
|
||||
this();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getOthers()
|
||||
* @see #putOthers(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public void setOthers(@Nullable Map<String, Object> others) {
|
||||
this.others = others;
|
||||
}
|
||||
/**
|
||||
* CKAN instances might have <a href=
|
||||
* "http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html"> custom
|
||||
* data schemas</a> that force presence of custom properties among 'regular'
|
||||
* ones. In this case, they go to 'others' field. Note that to further
|
||||
* complicate things there is also an {@link #getExtras() extras} field.
|
||||
*
|
||||
* @see #putOthers(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
@JsonAnyGetter
|
||||
@Nullable
|
||||
public Map<String, Object> getOthers() {
|
||||
return others;
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link #getOthers()}
|
||||
*
|
||||
* @see #setOthers(java.util.Map)
|
||||
*/
|
||||
@JsonAnySetter
|
||||
public void putOthers(String name, Object value) {
|
||||
if (others == null) {
|
||||
others = new HashMap<>();
|
||||
}
|
||||
others.put(name, value);
|
||||
}
|
||||
/**
|
||||
* @see #getOthers()
|
||||
* @see #putOthers(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public void setOthers(@Nullable Map<String, Object> others) {
|
||||
this.others = others;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
/**
|
||||
* See {@link #getOthers()}
|
||||
*
|
||||
* @see #setOthers(java.util.Map)
|
||||
*/
|
||||
@JsonAnySetter
|
||||
public void putOthers(String name, Object value) {
|
||||
if (others == null) {
|
||||
others = new HashMap<>();
|
||||
}
|
||||
others.put(name, value);
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public String getAuthorEmail() {
|
||||
return authorEmail;
|
||||
}
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public void setAuthorEmail(String authorEmail) {
|
||||
this.authorEmail = authorEmail;
|
||||
}
|
||||
public String getAuthorEmail() {
|
||||
return authorEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice that if the dataset was obtained with a
|
||||
* {@link eu.trentorise.opendata.jackan.CkanClient#getDataset(java.lang.String)} call, the returned group
|
||||
* won't have all the params you would get with a
|
||||
* {@link eu.trentorise.opendata.jackan.CkanClient#getGroup(java.lang.String)} call.
|
||||
*/
|
||||
public List<CkanGroup> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
public void setAuthorEmail(String authorEmail) {
|
||||
this.authorEmail = authorEmail;
|
||||
}
|
||||
|
||||
public void setGroups(List<CkanGroup> groups) {
|
||||
this.groups = groups;
|
||||
}
|
||||
/**
|
||||
* Notice that if the dataset was obtained with a
|
||||
* {@link eu.trentorise.opendata.jackan.CkanClient#getDataset(java.lang.String)}
|
||||
* call, the returned group won't have all the params you would get with a
|
||||
* {@link eu.trentorise.opendata.jackan.CkanClient#getGroup(java.lang.String)}
|
||||
* call.
|
||||
*/
|
||||
public List<CkanGroup> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds CkanGroups
|
||||
*
|
||||
* @param ckanGroups The CkanGroups elements
|
||||
*
|
||||
* @since 0.4.3
|
||||
*/
|
||||
public void addGroups(CkanGroup... ckanGroups) {
|
||||
if (this.groups == null) {
|
||||
this.groups = new ArrayList<>(ckanGroups.length);
|
||||
}
|
||||
Collections.addAll(this.groups, ckanGroups);
|
||||
}
|
||||
public void setGroups(List<CkanGroup> groups) {
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regular place where to put custom metadata. See also
|
||||
* {@link #getOthers()}. Note also extras can be in CkanDataset but not in
|
||||
* CkanResource.
|
||||
*/
|
||||
public List<CkanPair> getExtras() {
|
||||
return extras;
|
||||
}
|
||||
/**
|
||||
* Adds CkanGroups
|
||||
*
|
||||
* @param ckanGroups The CkanGroups elements
|
||||
*
|
||||
* @since 0.4.3
|
||||
*/
|
||||
public void addGroups(CkanGroup... ckanGroups) {
|
||||
if (this.groups == null) {
|
||||
this.groups = new ArrayList<>(ckanGroups.length);
|
||||
}
|
||||
Collections.addAll(this.groups, ckanGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link #getExtras()}
|
||||
*/
|
||||
public void setExtras(List<CkanPair> extras) {
|
||||
this.extras = extras;
|
||||
}
|
||||
/**
|
||||
* Regular place where to put custom metadata. See also {@link #getOthers()}.
|
||||
* Note also extras can be in CkanDataset but not in CkanResource.
|
||||
*/
|
||||
public List<CkanPair> getExtras() {
|
||||
return extras;
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link #getExtras()}
|
||||
*/
|
||||
public void setExtras(List<CkanPair> extras) {
|
||||
this.extras = extras;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Always returns a non-null map (which might be empty)
|
||||
*/
|
||||
|
@ -207,285 +205,306 @@ public class CkanDatasetBase {
|
|||
return hm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds CkanExtras
|
||||
*
|
||||
* @param extras The CkanExtra elements
|
||||
*
|
||||
* @since 0.4.3
|
||||
*/
|
||||
public void addExtras(CkanPair... extras) {
|
||||
if (this.extras == null) {
|
||||
this.extras = new ArrayList<>(extras.length);
|
||||
}
|
||||
Collections.addAll(this.extras, extras);
|
||||
}
|
||||
/**
|
||||
* Always returns a non-null map (which might be empty)
|
||||
*
|
||||
* added by Francesco Mangiacrapa at ISTI-CNR
|
||||
*
|
||||
* The D4Science model accepts extra fields with multiple keys
|
||||
*/
|
||||
@JsonIgnore
|
||||
public Map<String, List<String>> getListExtrasAsHashMap() {
|
||||
HashMap<String, List<String>> hm = new HashMap<>();
|
||||
if (extras != null) {
|
||||
for (CkanPair cp : extras) {
|
||||
|
||||
/**
|
||||
* Returns the alphanumerical id, i.e.
|
||||
* "c4577b8f-5603-4098-917e-da03e8ddf461"
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
List<String> list = hm.get(cp.getKey());
|
||||
if (list == null)
|
||||
list = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* Sets the alphanumerical id, i.e. "c4577b8f-5603-4098-917e-da03e8ddf461"
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
list.add(cp.getValue());
|
||||
hm.put(cp.getKey(), list);
|
||||
}
|
||||
}
|
||||
return hm;
|
||||
}
|
||||
|
||||
/**
|
||||
* The license id (i.e. 'cc-zero')
|
||||
*/
|
||||
public String getLicenseId() {
|
||||
return licenseId;
|
||||
}
|
||||
/**
|
||||
* Adds CkanExtras
|
||||
*
|
||||
* @param extras The CkanExtra elements
|
||||
*
|
||||
* @since 0.4.3
|
||||
*/
|
||||
public void addExtras(CkanPair... extras) {
|
||||
if (this.extras == null) {
|
||||
this.extras = new ArrayList<>(extras.length);
|
||||
}
|
||||
Collections.addAll(this.extras, extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* The license id (i.e. 'cc-zero')
|
||||
*/
|
||||
public void setLicenseId(String licenseId) {
|
||||
this.licenseId = licenseId;
|
||||
}
|
||||
/**
|
||||
* Returns the alphanumerical id, i.e. "c4577b8f-5603-4098-917e-da03e8ddf461"
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getMaintainer() {
|
||||
return maintainer;
|
||||
}
|
||||
/**
|
||||
* Sets the alphanumerical id, i.e. "c4577b8f-5603-4098-917e-da03e8ddf461"
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setMaintainer(String maintainer) {
|
||||
this.maintainer = maintainer;
|
||||
}
|
||||
/**
|
||||
* The license id (i.e. 'cc-zero')
|
||||
*/
|
||||
public String getLicenseId() {
|
||||
return licenseId;
|
||||
}
|
||||
|
||||
public String getMaintainerEmail() {
|
||||
return maintainerEmail;
|
||||
}
|
||||
/**
|
||||
* The license id (i.e. 'cc-zero')
|
||||
*/
|
||||
public void setLicenseId(String licenseId) {
|
||||
this.licenseId = licenseId;
|
||||
}
|
||||
|
||||
public void setMaintainerEmail(String maintainerEmail) {
|
||||
this.maintainerEmail = maintainerEmail;
|
||||
}
|
||||
public String getMaintainer() {
|
||||
return maintainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dataset name (contains no spaces and has dashes as separators, i.e.
|
||||
* "limestone-pavement-orders")
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setMaintainer(String maintainer) {
|
||||
this.maintainer = maintainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dataset name. Name must not contain spaces and have dashes as
|
||||
* separators, i.e. "limestone-pavement-orders"
|
||||
*
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getMaintainerEmail() {
|
||||
return maintainerEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* A description of the dataset. See also
|
||||
* {@link CkanDataset#getNotesRendered()} Note CkanResource has instead a
|
||||
* field called {@link CkanResourceBase#getDescription() description}.
|
||||
*/
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
public void setMaintainerEmail(String maintainerEmail) {
|
||||
this.maintainerEmail = maintainerEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* A description of the dataset. See also
|
||||
* {@link CkanDataset#getNotesRendered()} Note CkanResource has instead a
|
||||
* field called {@link CkanResourceBase#getDescription() description}.
|
||||
*/
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
/**
|
||||
* The dataset name (contains no spaces and has dashes as separators, i.e.
|
||||
* "limestone-pavement-orders")
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The owner organization alphanunmerical id, like
|
||||
* "b112ed55-01b7-4ca4-8385-f66d6168efcc".
|
||||
*/
|
||||
public String getOwnerOrg() {
|
||||
return ownerOrg;
|
||||
}
|
||||
/**
|
||||
* The dataset name. Name must not contain spaces and have dashes as separators,
|
||||
* i.e. "limestone-pavement-orders"
|
||||
*
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The owner organization alphanunmerical id, like
|
||||
* "b112ed55-01b7-4ca4-8385-f66d6168efcc".
|
||||
*/
|
||||
public void setOwnerOrg(String ownerOrg) {
|
||||
this.ownerOrg = ownerOrg;
|
||||
}
|
||||
/**
|
||||
* A description of the dataset. See also {@link CkanDataset#getNotesRendered()}
|
||||
* Note CkanResource has instead a field called
|
||||
* {@link CkanResourceBase#getDescription() description}.
|
||||
*/
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public List<CkanDatasetRelationship> getRelationshipsAsObject() {
|
||||
return relationshipsAsObject;
|
||||
}
|
||||
/**
|
||||
* A description of the dataset. See also {@link CkanDataset#getNotesRendered()}
|
||||
* Note CkanResource has instead a field called
|
||||
* {@link CkanResourceBase#getDescription() description}.
|
||||
*/
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public void setRelationshipsAsObject(List<CkanDatasetRelationship> relationshipsAsObject) {
|
||||
this.relationshipsAsObject = relationshipsAsObject;
|
||||
}
|
||||
/**
|
||||
* The owner organization alphanunmerical id, like
|
||||
* "b112ed55-01b7-4ca4-8385-f66d6168efcc".
|
||||
*/
|
||||
public String getOwnerOrg() {
|
||||
return ownerOrg;
|
||||
}
|
||||
|
||||
public List<CkanDatasetRelationship> getRelationshipsAsSubject() {
|
||||
return relationshipsAsSubject;
|
||||
}
|
||||
/**
|
||||
* The owner organization alphanunmerical id, like
|
||||
* "b112ed55-01b7-4ca4-8385-f66d6168efcc".
|
||||
*/
|
||||
public void setOwnerOrg(String ownerOrg) {
|
||||
this.ownerOrg = ownerOrg;
|
||||
}
|
||||
|
||||
public void setRelationshipsAsSubject(List<CkanDatasetRelationship> relationshipsAsSubject) {
|
||||
this.relationshipsAsSubject = relationshipsAsSubject;
|
||||
}
|
||||
public List<CkanDatasetRelationship> getRelationshipsAsObject() {
|
||||
return relationshipsAsObject;
|
||||
}
|
||||
|
||||
public List<CkanResource> getResources() {
|
||||
return this.resources;
|
||||
}
|
||||
public void setRelationshipsAsObject(List<CkanDatasetRelationship> relationshipsAsObject) {
|
||||
this.relationshipsAsObject = relationshipsAsObject;
|
||||
}
|
||||
|
||||
public void setResources(List<CkanResource> resources) {
|
||||
this.resources = resources;
|
||||
}
|
||||
public List<CkanDatasetRelationship> getRelationshipsAsSubject() {
|
||||
return relationshipsAsSubject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds CkanResources
|
||||
*
|
||||
* @param resources The CkanResources elements
|
||||
*
|
||||
* @since 0.4.3
|
||||
*/
|
||||
public void addCkanResources(CkanResource... resources) {
|
||||
if (this.resources == null) {
|
||||
this.resources = new ArrayList<>(resources.length);
|
||||
}
|
||||
Collections.addAll(this.resources, resources);
|
||||
}
|
||||
public void setRelationshipsAsSubject(List<CkanDatasetRelationship> relationshipsAsSubject) {
|
||||
this.relationshipsAsSubject = relationshipsAsSubject;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current state of the dataset, e.g. 'active' or 'deleted', only active
|
||||
* datasets show up in search results and other lists of datasets, this
|
||||
* parameter will be ignored if you are not authorized to change the state
|
||||
* of the dataset (optional, default: 'active')
|
||||
*/
|
||||
public CkanState getState() {
|
||||
return state;
|
||||
}
|
||||
public List<CkanResource> getResources() {
|
||||
return this.resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current state of the dataset, e.g. 'active' or 'deleted', only active
|
||||
* datasets show up in search results and other lists of datasets, this
|
||||
* parameter will be ignored if you are not authorized to change the state
|
||||
* of the dataset (optional, default: 'active')
|
||||
*/
|
||||
public void setState(CkanState state) {
|
||||
this.state = state;
|
||||
}
|
||||
public void setResources(List<CkanResource> resources) {
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
public List<CkanTag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
/**
|
||||
* Adds CkanResources
|
||||
*
|
||||
* @param resources The CkanResources elements
|
||||
*
|
||||
* @since 0.4.3
|
||||
*/
|
||||
public void addCkanResources(CkanResource... resources) {
|
||||
if (this.resources == null) {
|
||||
this.resources = new ArrayList<>(resources.length);
|
||||
}
|
||||
Collections.addAll(this.resources, resources);
|
||||
}
|
||||
|
||||
public void setTags(List<CkanTag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
/**
|
||||
* The current state of the dataset, e.g. 'active' or 'deleted', only active
|
||||
* datasets show up in search results and other lists of datasets, this
|
||||
* parameter will be ignored if you are not authorized to change the state of
|
||||
* the dataset (optional, default: 'active')
|
||||
*/
|
||||
public CkanState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds CkanTag
|
||||
*
|
||||
* @param tags The CkanTags elements
|
||||
*
|
||||
* @since 0.4.3
|
||||
*/
|
||||
public void addTags(CkanTag... tags) {
|
||||
if (this.tags == null) {
|
||||
this.tags = new ArrayList<>(tags.length);
|
||||
}
|
||||
Collections.addAll(this.tags, tags);
|
||||
}
|
||||
/**
|
||||
* The current state of the dataset, e.g. 'active' or 'deleted', only active
|
||||
* datasets show up in search results and other lists of datasets, this
|
||||
* parameter will be ignored if you are not authorized to change the state of
|
||||
* the dataset (optional, default: 'active')
|
||||
*/
|
||||
public void setState(CkanState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* The title, like "Hospitals of Trento"
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
public List<CkanTag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* The title, like "Hospitals of Trento"
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
public void setTags(List<CkanTag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the dataset (optional), IDatasetForm plugins associate
|
||||
* themselves with different dataset types and provide custom dataset
|
||||
* handling behaviour for these types
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
/**
|
||||
* Adds CkanTag
|
||||
*
|
||||
* @param tags The CkanTags elements
|
||||
*
|
||||
* @since 0.4.3
|
||||
*/
|
||||
public void addTags(CkanTag... tags) {
|
||||
if (this.tags == null) {
|
||||
this.tags = new ArrayList<>(tags.length);
|
||||
}
|
||||
Collections.addAll(this.tags, tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the dataset (optional), IDatasetForm plugins associate
|
||||
* themselves with different dataset types and provide custom dataset
|
||||
* handling behaviour for these types
|
||||
*/
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
/**
|
||||
* The title, like "Hospitals of Trento"
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be the landing page on original data provider website describing
|
||||
* the dataset.
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
/**
|
||||
* The title, like "Hospitals of Trento"
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be the landing page on original data provider website describing
|
||||
* the dataset.
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
/**
|
||||
* The type of the dataset (optional), IDatasetForm plugins associate themselves
|
||||
* with different dataset types and provide custom dataset handling behaviour
|
||||
* for these types
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
/**
|
||||
* The type of the dataset (optional), IDatasetForm plugins associate themselves
|
||||
* with different dataset types and provide custom dataset handling behaviour
|
||||
* for these types
|
||||
*/
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
/**
|
||||
* Should be the landing page on original data provider website describing the
|
||||
* dataset.
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id if non-empty, the name otherwise
|
||||
*/
|
||||
@Nullable
|
||||
public String idOrName() {
|
||||
return isNotEmpty(getId()) ? getId() : getName();
|
||||
}
|
||||
/**
|
||||
* Should be the landing page on original data provider website describing the
|
||||
* dataset.
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name if non-empty, the id otherwise
|
||||
*/
|
||||
@Nullable
|
||||
public String nameOrId() {
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
return isNotEmpty(getName()) ? getName() : getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually it is named "private" in the CKAN API. Appears in dataset
|
||||
* searches.
|
||||
*/
|
||||
@JsonProperty("private")
|
||||
public Boolean isPriv() {
|
||||
return priv;
|
||||
}
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually it is named "private" in the CKAN API. Appears in dataset
|
||||
* searches.
|
||||
*/
|
||||
public void setPriv(Boolean priv) {
|
||||
this.priv = priv;
|
||||
}
|
||||
/**
|
||||
* Returns the id if non-empty, the name otherwise
|
||||
*/
|
||||
@Nullable
|
||||
public String idOrName() {
|
||||
return isNotEmpty(getId()) ? getId() : getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name if non-empty, the id otherwise
|
||||
*/
|
||||
@Nullable
|
||||
public String nameOrId() {
|
||||
|
||||
return isNotEmpty(getName()) ? getName() : getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually it is named "private" in the CKAN API. Appears in dataset searches.
|
||||
*/
|
||||
@JsonProperty("private")
|
||||
public Boolean isPriv() {
|
||||
return priv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually it is named "private" in the CKAN API. Appears in dataset searches.
|
||||
*/
|
||||
public void setPriv(Boolean priv) {
|
||||
this.priv = priv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -537,7 +556,5 @@ public class CkanDatasetBase {
|
|||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
/resources/
|
|
@ -0,0 +1 @@
|
|||
/token.properties
|
|
@ -0,0 +1,154 @@
|
|||
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";
|
||||
|
||||
|
||||
public static final String ROOT = "/d4science.research-infrastructures.eu";
|
||||
public static final String VO = ROOT + "/D4OS";
|
||||
public static final String VRE = VO + "/Blue-Cloud2026Project";
|
||||
|
||||
public static final String scope = VRE;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
package org.gcube.datacatalogue.utillibrary.test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datacatalogue.utillibrary.gcat.GCatCaller;
|
||||
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory;
|
||||
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl;
|
||||
import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorSystem;
|
||||
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
||||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
|
||||
import org.gcube.gcat.client.Item;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class TestDataCatalogueLib.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Jun 1, 2020
|
||||
*/
|
||||
public class TestDataCatalogueCMS extends ContextTest {
|
||||
|
||||
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestDataCatalogueCMS.class);
|
||||
|
||||
private DataCatalogueFactory factory;
|
||||
private String testUser = "francesco.mangiacrapa";
|
||||
private String scope = "/gcube/devsec/devVRE";
|
||||
//private String scope = "/gcube/devsec";
|
||||
private String authorizationToken = ""; //devVRE
|
||||
|
||||
/**
|
||||
* Before.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Before
|
||||
public void before() throws Exception {
|
||||
factory = DataCatalogueFactory.getFactory();
|
||||
}
|
||||
|
||||
//@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);
|
||||
String items = new Item().list(limit, offset);
|
||||
LOG.debug("List items: " + items);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Test
|
||||
public void contentModeratorTest() throws Exception {
|
||||
// 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
|
||||
public void listItemsForCMStatus() throws Exception {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
ItemStatus theStatus = ItemStatus.PENDING;
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
DataCatalogueImpl dImpl = factory.getUtilsPerScope(scope);
|
||||
CatalogueContentModeratorSystem cCMS = dImpl.getCatalogueContentModerator();
|
||||
LOG.debug(CatalogueContentModeratorSystem.class.getName() + " instancied correclty");
|
||||
|
||||
List<String> emailsAddresses = new ArrayList<String>();
|
||||
// emailsAddresses.add("luca.frosini@isti.cnr.it");
|
||||
emailsAddresses.add("francesco.mangiacrapa@isti.cnr.it");
|
||||
// emailsAddresses.add("pagano@cnr.it");
|
||||
|
||||
String theQuery = mockQueryForEmails(emailsAddresses, "OR");
|
||||
|
||||
Map<String, String> filters = new HashMap<String, String>();
|
||||
filters.put("author_email", theQuery);
|
||||
|
||||
List<CkanDataset> listItems = cCMS.getListItemsForStatus(theStatus, 10, 0, true, 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scope per url.
|
||||
*
|
||||
* @return the scope per url
|
||||
* @throws Exception
|
||||
*/
|
||||
// @Test
|
||||
public void countListItemsForStatus() throws Exception {
|
||||
|
||||
try {
|
||||
ItemStatus theStatus = ItemStatus.APPROVED;
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
DataCatalogueImpl dImpl = factory.getUtilsPerScope(scope);
|
||||
CatalogueContentModeratorSystem cCMS = dImpl.getCatalogueContentModerator();
|
||||
LOG.debug(CatalogueContentModeratorSystem.class.getName() + " instancied correclty");
|
||||
|
||||
List<String> emailsAddresses = new ArrayList<String>();
|
||||
// emailsAddresses.add("luca.frosini@isti.cnr.it");
|
||||
emailsAddresses.add("francesco.mangiacrapa@isti.cnr.it");
|
||||
// emailsAddresses.add("pagano@cnr.it");
|
||||
|
||||
String theQuery = mockQueryForEmails(emailsAddresses, "OR");
|
||||
|
||||
Map<String, String> filters = new HashMap<String, String>();
|
||||
filters.put("author_email", theQuery);
|
||||
|
||||
long size = cCMS.countListItemsForStatus(theStatus, filters);
|
||||
LOG.debug("Size of list of items for status " + theStatus + " is: " + size);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String mockQueryForEmails(List<String> emailsAddresses, String queryOperator) throws Exception {
|
||||
|
||||
StringBuilder queryMails = new StringBuilder();
|
||||
if (queryOperator == null)
|
||||
queryOperator = "OR";
|
||||
// BUILDING EMAILS QUERY
|
||||
int numberOfEmails = emailsAddresses.size();
|
||||
|
||||
String theQuery = "";
|
||||
|
||||
// case 1 email address
|
||||
if (numberOfEmails == 1) {
|
||||
theQuery = "'" + emailsAddresses.get(0) + "'";
|
||||
} else {
|
||||
// case N > 1 email addresses
|
||||
for (int i = 0; i < emailsAddresses.size() - 1; i++) {
|
||||
String email = emailsAddresses.get(i);
|
||||
if (i == 0) {
|
||||
// opening the query and adding first email address
|
||||
queryMails.append("('" + email + "'");
|
||||
} else {
|
||||
// adding the operator and the email address
|
||||
queryMails.append(" " + queryOperator + " '" + email + "'");
|
||||
}
|
||||
}
|
||||
|
||||
theQuery = queryMails.toString();
|
||||
|
||||
// to be sure that endsWith Operator
|
||||
if (!theQuery.endsWith(queryOperator)) {
|
||||
theQuery += " " + queryOperator + " ";
|
||||
}
|
||||
|
||||
// adding last email address and closing the query
|
||||
theQuery += "'" + emailsAddresses.get(numberOfEmails - 1) + "')";
|
||||
}
|
||||
|
||||
return theQuery;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package org.gcube.datacatalogue.utillibrary.test;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -8,7 +7,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
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;
|
||||
|
@ -24,27 +22,26 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class TestDataCatalogueLib.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
|
||||
* Jun 1, 2020
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Jun 1, 2020
|
||||
*/
|
||||
public class TestDataCatalogueLib {
|
||||
public class TestDataCatalogueLib extends ContextTest{
|
||||
|
||||
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestDataCatalogueLib.class);
|
||||
|
||||
private DataCatalogueFactory factory;
|
||||
private String scope = "/gcube/devsec/devVRE";
|
||||
//private String scope = "/gcube";
|
||||
//private String scope = "/pred4s/preprod/preVRE";
|
||||
//private String scope = "/d4science.research-infrastructures.eu/SoBigData/Catalogue-TerritoriAperti";
|
||||
//private String scope = "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab";
|
||||
//private String testUser = "costantino_perciante";
|
||||
//private String scope = "/gcube/devsec/devVRE";
|
||||
// private String scope = "/gcube";
|
||||
// private String scope = "/pred4s/preprod/preVRE";
|
||||
// private String scope =
|
||||
// "/d4science.research-infrastructures.eu/SoBigData/Catalogue-TerritoriAperti";
|
||||
// private String scope =
|
||||
// "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab";
|
||||
// private String testUser = "costantino_perciante";
|
||||
private String testUser = "francesco.mangiacrapa";
|
||||
private String authorizationToken = "";
|
||||
//private String authorizationToken = "";
|
||||
String subjectId = "aa_father4";
|
||||
String objectId = "bb_son4";
|
||||
String productName = "adatasetcreatedbycatalogue-util-library-873805063";
|
||||
|
@ -54,24 +51,24 @@ public class TestDataCatalogueLib {
|
|||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Before
|
||||
public void before() throws Exception{
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
factory = DataCatalogueFactory.getFactory();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Test
|
||||
public void factoryTest() throws Exception{
|
||||
public void factoryTest() throws Exception {
|
||||
|
||||
DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
|
||||
|
||||
while(true){
|
||||
while (true) {
|
||||
factory.getUtilsPerScope(scope);
|
||||
Thread.sleep(60* 1000 * 3);
|
||||
Thread.sleep(60 * 1000 * 3);
|
||||
factory.getUtilsPerScope(scope);
|
||||
break;
|
||||
}
|
||||
|
@ -82,14 +79,14 @@ public class TestDataCatalogueLib {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the scope per url.
|
||||
*
|
||||
* @return the scope per url
|
||||
*/
|
||||
//@Test
|
||||
public void getScopePerUrl(){
|
||||
// @Test
|
||||
public void getScopePerUrl() {
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
String url = "https://dev2.d4science.org/group/devvre/ckan";
|
||||
|
@ -101,16 +98,15 @@ public class TestDataCatalogueLib {
|
|||
String scopeToUse2 = ApplicationProfileScopePerUrlReader.getScopePerUrl(url2);
|
||||
LOG.debug("Retrieved scope is " + scopeToUse2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the user role by group.
|
||||
*
|
||||
* @return the user role by group
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Test
|
||||
public void getUserRoleByGroup() throws Exception{
|
||||
// @Test
|
||||
public void getUserRoleByGroup() throws Exception {
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
String username = testUser;
|
||||
long init = System.currentTimeMillis();
|
||||
|
@ -118,7 +114,7 @@ public class TestDataCatalogueLib {
|
|||
long end = System.currentTimeMillis();
|
||||
LOG.debug("Time taken " + (end - init));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the user role by group.
|
||||
*
|
||||
|
@ -126,22 +122,28 @@ public class TestDataCatalogueLib {
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
//@Test
|
||||
public void getDataset() throws Exception{
|
||||
public void getDataset() throws Exception {
|
||||
|
||||
String datasetname = "blue-cloud_2026_-_a_federated_european_fair_and_open_research_ecosystem_for_oceans_seas_coastal_and";
|
||||
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
String username = testUser;
|
||||
CkanDataset dataset = instance.getDataset("my_first_restful_transaction_model_private", username);
|
||||
LOG.debug("Got dataset: " +dataset.getName() + ", with id: "+dataset.getId());
|
||||
CkanDataset dataset = instance.getDataset(datasetname, username);
|
||||
LOG.debug("Got dataset: " + dataset.getName() + ", with id: " + dataset.getId());
|
||||
LOG.debug("Got getAuthor: " + dataset.getAuthor());
|
||||
LOG.debug("Got getAuthorEmail: " + dataset.getAuthorEmail());
|
||||
LOG.debug("Got getMantainer: " + dataset.getMaintainer());
|
||||
LOG.debug("Got getMaintainerEmail: " + dataset.getMaintainerEmail());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the user role by organization.
|
||||
*
|
||||
* @return the user role by organization
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Test
|
||||
public void getUserRoleByOrganization() throws Exception{
|
||||
// @Test
|
||||
public void getUserRoleByOrganization() throws Exception {
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
String username = testUser;
|
||||
long init = System.currentTimeMillis();
|
||||
|
@ -149,173 +151,159 @@ public class TestDataCatalogueLib {
|
|||
long end = System.currentTimeMillis();
|
||||
LOG.debug("Time taken " + (end - init));
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getRoleOfUserInOrganization() throws Exception{
|
||||
|
||||
|
||||
// @Test
|
||||
public void getRoleOfUserInOrganization() throws Exception {
|
||||
|
||||
String orgName = "devvre";
|
||||
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
||||
CkanOrganization org = utils.getOrganizationByIdOrName(orgName);
|
||||
String role = utils.getRoleOfUserInOrganization(testUser, org.getName());
|
||||
LOG.debug("The user "+testUser+" in the org "+org.getName() + " has the role "+role);
|
||||
LOG.debug("The user " + testUser + " in the org " + org.getName() + " has the role " + role);
|
||||
}
|
||||
|
||||
|
||||
//@Test
|
||||
public void getOrganizationForName() throws Exception{
|
||||
|
||||
public void getOrganizationForName() throws Exception {
|
||||
|
||||
String orgName = "devvre";
|
||||
|
||||
|
||||
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
||||
|
||||
|
||||
CkanOrganization org = utils.getOrganizationByIdOrName(orgName);
|
||||
|
||||
LOG.debug("The "+CkanOrganization.class.getSimpleName()+" is: "+org.getName());
|
||||
LOG.debug("LandingPages of "+CkanOrganization.class.getSimpleName()+" for name " + utils.getLandingPages());
|
||||
if(org.getUsers()!=null) {
|
||||
|
||||
LOG.debug("The " + CkanOrganization.class.getSimpleName() + " is: " + org.getName());
|
||||
LOG.debug("LandingPages of " + CkanOrganization.class.getSimpleName() + " for name " + utils.getLandingPages());
|
||||
if (org.getUsers() != null) {
|
||||
|
||||
for (CkanUser user : org.getUsers()) {
|
||||
LOG.debug("User: "+user.getName());
|
||||
LOG.debug("User: " + user.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getOrganizationsNamesByUser() throws Exception{
|
||||
|
||||
|
||||
// @Test
|
||||
public void getOrganizationsNamesByUser() throws Exception {
|
||||
|
||||
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
||||
|
||||
|
||||
List<CkanOrganization> listOrgs = utils.getOrganizationsByUser(testUser);
|
||||
|
||||
LOG.debug("User :"+testUser+" found in the Organization/s:");
|
||||
|
||||
|
||||
LOG.debug("User :" + testUser + " found in the Organization/s:");
|
||||
|
||||
for (CkanOrganization ckanOrganization : listOrgs) {
|
||||
LOG.debug("Org: "+ckanOrganization.getName());
|
||||
LOG.debug("Org: " + ckanOrganization.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getGroupsNamesByUser() throws Exception{
|
||||
|
||||
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
||||
|
||||
List<CkanGroup> listGroups = utils.getGroupsByUser(testUser);
|
||||
|
||||
LOG.debug("User :"+testUser+" found in the Group/s:");
|
||||
|
||||
for (CkanGroup ckanGroup : listGroups) {
|
||||
LOG.debug("Group: "+ckanGroup.getName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getLandingPages() throws Exception{
|
||||
// @Test
|
||||
public void getGroupsNamesByUser() throws Exception {
|
||||
|
||||
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
||||
|
||||
List<CkanGroup> listGroups = utils.getGroupsByUser(testUser);
|
||||
|
||||
LOG.debug("User :" + testUser + " found in the Group/s:");
|
||||
|
||||
for (CkanGroup ckanGroup : listGroups) {
|
||||
LOG.debug("Group: " + ckanGroup.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void getLandingPages() throws Exception {
|
||||
|
||||
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
||||
LOG.debug("Landing pages " + utils.getLandingPages());
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void countDatasetForOganization() throws Exception{
|
||||
|
||||
DataCatalogueImpl utils = new DataCatalogueImpl(scope,true);
|
||||
|
||||
// @Test
|
||||
public void countDatasetForOganization() throws Exception {
|
||||
|
||||
DataCatalogueImpl utils = new DataCatalogueImpl(scope, true);
|
||||
|
||||
List<String> listOrgIds = utils.getOrganizationsIds();
|
||||
|
||||
|
||||
System.out.println("'ORGANIZATION NAME': 'NUMBER OF PACKAGE'");
|
||||
|
||||
|
||||
for (String orgID : listOrgIds) {
|
||||
CkanOrganization org = utils.getOrganizationByIdOrName(orgID);
|
||||
int packageCount = org.getPackageCount();
|
||||
//logger.info("ORG: "+org.getName() + " has "+packageCount+ " package/s");
|
||||
System.out.println(org.getName()+": "+packageCount);
|
||||
// logger.info("ORG: "+org.getName() + " has "+packageCount+ " package/s");
|
||||
System.out.println(org.getName() + ": " + packageCount);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void createDataset() throws Exception{
|
||||
|
||||
// @Test
|
||||
public void createDataset() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
String licenseId = instance.getLicenses().get(0).getId();
|
||||
|
||||
|
||||
Map<String, List<String>> customFieldsMultiple = new HashMap<String, List<String>>();
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (int j = 0; j < new Random().nextInt(3); j++) {
|
||||
values.add("value-random-"+ new Random().nextInt(10));
|
||||
values.add("value-random-" + new Random().nextInt(10));
|
||||
}
|
||||
customFieldsMultiple.put("key-random-"+new Random().nextInt(10), values);
|
||||
customFieldsMultiple.put("key-random-" + new Random().nextInt(10), values);
|
||||
}
|
||||
|
||||
|
||||
customFieldsMultiple.put("empty-key", Arrays.asList(""));
|
||||
|
||||
|
||||
customFieldsMultiple.put("system:type", Arrays.asList("EmptyProfile"));
|
||||
|
||||
|
||||
boolean setSearchable = true;
|
||||
boolean setPublic = true;
|
||||
List<ResourceBean> resources = null;
|
||||
|
||||
|
||||
String orgName = scope.split("/")[3].toLowerCase();
|
||||
//System.out.println("Org name by VRE: "+orgName);
|
||||
LOG.debug("Org name by VRE: "+orgName);
|
||||
|
||||
// System.out.println("Org name by VRE: "+orgName);
|
||||
LOG.debug("Org name by VRE: " + orgName);
|
||||
|
||||
int random = new Random().nextInt();
|
||||
String datasetTitle = "a dataset created by catalogue-util-library "+random;
|
||||
String datasetTitle = "a dataset created by catalogue-util-library " + random;
|
||||
String datasetName = datasetTitle.replace(" ", "");
|
||||
String createdDataset = instance.createCkanDatasetMultipleCustomFields(
|
||||
testUser,
|
||||
"a dataset created by catalogue-util-library "+random,
|
||||
datasetName,
|
||||
orgName,
|
||||
testUser,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
1,
|
||||
"the description",
|
||||
licenseId,
|
||||
Arrays.asList("tag 1","tag 2","tag 3"),
|
||||
customFieldsMultiple,
|
||||
resources,
|
||||
setPublic,
|
||||
setSearchable,
|
||||
true);
|
||||
|
||||
LOG.info("Created the dataset with id: " +createdDataset);
|
||||
}catch (Exception e) {
|
||||
String createdDataset = instance.createCkanDatasetMultipleCustomFields(testUser,
|
||||
"a dataset created by catalogue-util-library " + random, datasetName, orgName, testUser, null, null,
|
||||
null, 1, "the description", licenseId, Arrays.asList("tag 1", "tag 2", "tag 3"),
|
||||
customFieldsMultiple, resources, setPublic, setSearchable, true);
|
||||
|
||||
LOG.info("Created the dataset with id: " + createdDataset);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void createGroup() throws Exception{
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
|
||||
// @Test
|
||||
public void createGroup() throws Exception {
|
||||
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
int random = new Random().nextInt();
|
||||
String groupTitle = "a grop created by catalogue-util-library "+random;
|
||||
String groupTitle = "a grop created by catalogue-util-library " + random;
|
||||
String groupName = groupTitle.replace(" ", "");
|
||||
CkanGroup ckanGroup = instance.createGroup(groupName, groupTitle, "description");
|
||||
LOG.info("Created the group: "+ckanGroup);
|
||||
LOG.info("Created the group: " + ckanGroup);
|
||||
}
|
||||
|
||||
//@Test
|
||||
|
||||
// @Test
|
||||
public void addResource() throws Exception {
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
CkanDataset dataset = instance.getDataset(productName, testUser);
|
||||
|
@ -323,57 +311,60 @@ public class TestDataCatalogueLib {
|
|||
for (int i = 1; i < 3; i++) {
|
||||
ResourceBean resourceBean = new ResourceBean("https://data-dev.d4science.net/ie8Y", "resouce " + i,
|
||||
"description " + i, null, testUser, dataset.getId(), null);
|
||||
instance.addResourceToDataset(resourceBean,testUser,dataset.getOrganization().getName());
|
||||
instance.addResourceToDataset(resourceBean, testUser, dataset.getOrganization().getName());
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
|
||||
// @Test
|
||||
public void deleteResource() throws Exception {
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
String resourceId = "ce7295cf-47db-4faf-901f-4fec2d3fae7a";
|
||||
boolean deleted = instance.deleteResourceFromDataset(resourceId, testUser);
|
||||
|
||||
LOG.info("Deleted the resource? "+deleted);
|
||||
LOG.info("Deleted the resource? " + deleted);
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void patchFieldsForDataset() throws Exception{
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
|
||||
// @Test
|
||||
public void patchFieldsForDataset() throws Exception {
|
||||
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
Map<String, String> customFieldsToChange = new HashMap<String, String>();
|
||||
customFieldsToChange.put("key-random-0", "patched");
|
||||
instance.patchFieldsForDataset(productName, customFieldsToChange);
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getUrlProduct() throws Exception{
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
|
||||
// @Test
|
||||
public void getUrlProduct() throws Exception {
|
||||
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
String datasetName = productName;
|
||||
String url = instance.getUnencryptedUrlFromDatasetIdOrName(datasetName);
|
||||
LOG.debug("url is " + url);
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void marshallingDataset() throws Exception{
|
||||
|
||||
// @Test
|
||||
public void marshallingDataset() throws Exception {
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
String username = testUser;
|
||||
CkanDataset dataset = instance.getDataset("sarda-sarda", username);
|
||||
LOG.debug("Got dataset: " +dataset.getName() + ", with id: "+dataset.getId() +" is private: "+dataset.isPriv());
|
||||
String jsonValueDataset = MarshUnmarshCkanObject.toJsonValueDataset(dataset,METHOD.TO_CREATE);
|
||||
LOG.debug("Got dataset: " + dataset.getName() + ", with id: " + dataset.getId() + " is private: "
|
||||
+ dataset.isPriv());
|
||||
String jsonValueDataset = MarshUnmarshCkanObject.toJsonValueDataset(dataset, METHOD.TO_CREATE);
|
||||
System.out.println(jsonValueDataset);
|
||||
dataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset, METHOD.TO_READ);
|
||||
System.out.println(dataset);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue