Compare commits
21 Commits
23
CHANGELOG.md
23
CHANGELOG.md
|
@ -4,6 +4,29 @@
|
|||
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**
|
||||
|
|
18
pom.xml
18
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.1.0</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
|
||||
|
@ -42,7 +41,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>maven-portal-bom</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<version>3.6.4</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -53,6 +52,7 @@
|
|||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-user</artifactId>
|
||||
<version>${gwtVersion}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -101,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>
|
||||
|
||||
|
@ -171,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>
|
||||
|
|
|
@ -34,11 +34,11 @@ public class GCatCaller {
|
|||
|
||||
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";
|
||||
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.
|
||||
|
@ -162,21 +162,41 @@ public class GCatCaller {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
public String approveItem(String datasetName, String moderatorMessage, Boolean sendSocialPost)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
LOG.trace("approveItem called");
|
||||
LOG.info("Calling approve item with name: " + datasetName + ", and msg: " + moderatorMessage);
|
||||
LOG.info("Calling approve item with name: " + datasetName + ", sendSocialPost: " + sendSocialPost
|
||||
+ ", msg: " + moderatorMessage);
|
||||
|
||||
return new Item().approve(datasetName, moderatorMessage, sendSocialPost);
|
||||
|
||||
return new Item().approve(datasetName, moderatorMessage);
|
||||
|
||||
}
|
||||
|
||||
|
@ -223,22 +243,24 @@ public class GCatCaller {
|
|||
/**
|
||||
* Gets the list items for CM status.
|
||||
*
|
||||
* @param status the status
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @param filters the filters
|
||||
* @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, Map<String, String> filters, String sortForField)
|
||||
throws WebServiceException, MalformedURLException {
|
||||
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, filters, sortForField);
|
||||
Map<String, String> queryParams = GCatCallerUtil.genericQueryBuilderFor(status, limit, offset, false, allFields,
|
||||
filters, sortForField);
|
||||
|
||||
return getListItemsForQuery(queryParams);
|
||||
}
|
||||
|
@ -247,7 +269,7 @@ public class GCatCaller {
|
|||
* Count list items for CM status.
|
||||
*
|
||||
* @param status the status
|
||||
* @param filters
|
||||
* @param filters the filters
|
||||
* @return the number of items
|
||||
* @throws WebServiceException the web service exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
|
@ -257,7 +279,8 @@ public class GCatCaller {
|
|||
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, filters, null);
|
||||
Map<String, String> queryParams = GCatCallerUtil.genericQueryBuilderFor(status, null, null, true, false,
|
||||
filters, null);
|
||||
|
||||
String theCount = getListItemsForQuery(queryParams);
|
||||
int count = 0;
|
||||
|
@ -309,7 +332,7 @@ public class GCatCaller {
|
|||
*
|
||||
* @param reload the reload
|
||||
* @return the configuration
|
||||
* @throws MalformedURLException
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public GCatCatalogueConfiguration getConfiguration(boolean reload) throws MalformedURLException {
|
||||
LOG.trace("getConfiguration called");
|
||||
|
@ -334,6 +357,13 @@ public class GCatCaller {
|
|||
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;
|
||||
|
|
|
@ -6,6 +6,7 @@ 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;
|
||||
|
@ -27,17 +28,19 @@ public class GCatCallerUtil {
|
|||
/**
|
||||
* Generic query builder for.
|
||||
*
|
||||
* @param status the status
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @param count the count
|
||||
* @param filters the filters
|
||||
* @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, Map<String, String> filters, String sort) {
|
||||
Boolean count, Boolean allFields, Map<String, String> filters, String sort) {
|
||||
LOG.info("genericQueryBuilderFor called with [status: " + status + "], [limit: " + limit + "], [offset: "
|
||||
+ offset + "], [count: " + count + "], [filters: " + filters + "]");
|
||||
+ offset + "], [count: " + count + "], [allFields: " + allFields + "], [filters: " + filters + "]");
|
||||
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
|
||||
|
@ -62,24 +65,29 @@ public class GCatCallerUtil {
|
|||
|
||||
if (limit != null) {
|
||||
limit = limit < 0 ? 10 : limit;
|
||||
queryParams.put("limit", limit + "");
|
||||
queryParams.put(GCatConstants.LIMIT_QUERY_PARAMETER, String.valueOf(limit));
|
||||
}
|
||||
if (offset != null) {
|
||||
offset = offset < 0 ? 0 : offset;
|
||||
queryParams.put("offset", 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);
|
||||
} else {
|
||||
LOG.info("Adding defautl sort: " + GCatCaller.DEFAULT_SORT_VALUE);
|
||||
queryParams.put("sort", GCatCaller.DEFAULT_SORT_VALUE);
|
||||
}
|
||||
|
||||
|
||||
if (count != null) {
|
||||
if (count) {
|
||||
queryParams.put("count", "true");
|
||||
queryParams.put(GCatConstants.COUNT_QUERY_PARAMETER, String.valueOf(count));
|
||||
}
|
||||
}
|
||||
|
||||
if (allFields != null) {
|
||||
if (allFields) {
|
||||
queryParams.put(GCatConstants.ALL_FIELDS_QUERY_PARAMETER, String.valueOf(allFields));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -332,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
|
||||
|
@ -344,6 +374,19 @@ public interface DataCatalogue {
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -419,6 +462,15 @@ public interface DataCatalogue {
|
|||
*/
|
||||
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.
|
||||
|
|
|
@ -866,7 +866,7 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
|
||||
// in order to avoid errors, the username is always converted
|
||||
String ckanUsername = CatalogueUtilMethods.fromUsernameToCKanUsername(username);
|
||||
LOG.debug("username: "+username + " converted to ckanUsername: "+ckanUsername);
|
||||
LOG.debug("username: " + username + " converted to ckanUsername: " + ckanUsername);
|
||||
|
||||
// check in the hashmap first
|
||||
if (apiKeysMap.containsKey(ckanUsername)) {
|
||||
|
@ -1305,7 +1305,7 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
|
||||
if (jsonValueDataset != null) {
|
||||
CkanDataset toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset, METHOD.TO_READ);
|
||||
LOG.info("Dataset with name " + toCkanDataset.getName() + " has been created correctly");
|
||||
LOG.info("Dataset with name " + toCkanDataset.getName() + " has been correctly created");
|
||||
return toCkanDataset.getId();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -1320,6 +1320,80 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Override
|
||||
public 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 {
|
||||
LOG.info("Called updateCkanDatasetMultipleCustomFields");
|
||||
|
||||
// checks (minimum)
|
||||
checkNotNull(username);
|
||||
// checkNotNull(organizationNameOrId);
|
||||
// checkArgument(!organizationNameOrId.isEmpty());
|
||||
checkArgument(!(title == null && name == null || title.isEmpty() && name.isEmpty()),
|
||||
"Name and Title cannot be empty/null at the same time!");
|
||||
|
||||
GcubeContext gcubeContext = null;
|
||||
try {
|
||||
|
||||
gcubeContext = GCubeUtils.detectAndSetTheOrgNameContext(organizationName, username, true);
|
||||
|
||||
String toPassOrganizationToGcat = null; // Not needed to pass this information to gCat, never.
|
||||
// String ckanUsername = getUserFromApiKey(apiKey).getName();
|
||||
LOG.debug("The visibility parameter passed is (isPublic): " + setPublic);
|
||||
CkanDataset dataset = CKANConveter.toCkanDataset(ckanCaller, username, title, name,
|
||||
toPassOrganizationToGcat, author, authorMail, maintainer, maintainerMail, version, description,
|
||||
licenseId, tags, null, customFieldsMultiple, resources, setPublic, setSearchable);
|
||||
|
||||
LOG.debug("The isPriv property into dataset is: " + dataset.isPriv());
|
||||
// trying to create by gCat
|
||||
String jsonValueDataset = MarshUnmarshCkanObject.toJsonValueDataset(dataset, METHOD.TO_CREATE);
|
||||
LOG.info("Serialized dataset to update is: " + jsonValueDataset);
|
||||
jsonValueDataset = gCatCaller.updateDataset(name, jsonValueDataset);
|
||||
LOG.debug("Updated dataset is: " + jsonValueDataset);
|
||||
|
||||
if (jsonValueDataset != null) {
|
||||
CkanDataset toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset, METHOD.TO_READ);
|
||||
LOG.info("Dataset with name " + toCkanDataset.getName() + " has been correctly updated");
|
||||
return toCkanDataset.getId();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error on updating the dataset: ", e);
|
||||
throw e;
|
||||
} finally {
|
||||
|
||||
if (gcubeContext != null)
|
||||
GCubeUtils.revertToSourceContext(gcubeContext);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh dataset.
|
||||
*
|
||||
|
@ -1360,6 +1434,32 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete dataset.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @return true, if successful
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteDataset(String datasetName) throws Exception {
|
||||
LOG.info("Called deleteDataset");
|
||||
|
||||
checkNotNull(datasetName);
|
||||
boolean deleted = false;
|
||||
try {
|
||||
|
||||
gCatCaller.deleteItem(datasetName, true);
|
||||
deleted = true;
|
||||
LOG.info("Deleted the dataset: {} ", datasetName);
|
||||
return deleted;
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error on deleting the dataset: ", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch fields for dataset.
|
||||
*
|
||||
|
@ -1462,22 +1562,47 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
throws Exception {
|
||||
LOG.info("Called addResourceToDataset by this bean " + resourceBean);
|
||||
|
||||
CkanResource resource = createResource(resourceBean, organizationName, username);
|
||||
if (resource != null)
|
||||
return resource.getId();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the resource to dataset.
|
||||
*
|
||||
* @param resourceBean the resource bean
|
||||
* @param datasetId the dataset id
|
||||
* @param organizationName the organization name
|
||||
* @param username the username
|
||||
* @return the string
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public CkanResource addResource(ResourceBean resourceBean, String datasetId, String organizationName,
|
||||
String username) throws Exception {
|
||||
LOG.info("Called addResource by this bean " + resourceBean.getName() + ", datasetId: " + datasetId);
|
||||
|
||||
resourceBean.setDatasetId(datasetId);
|
||||
return createResource(resourceBean, organizationName, username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the resource.
|
||||
*
|
||||
* @param resourceBean the resource bean
|
||||
* @param organizationName the organization name
|
||||
* @param username the username
|
||||
* @return the ckan resource
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private CkanResource createResource(ResourceBean resourceBean, String organizationName, String username)
|
||||
throws Exception {
|
||||
|
||||
// checks
|
||||
checkNotNull(resourceBean);
|
||||
checkNotNull(resourceBean.getUrl());
|
||||
|
||||
// Commented since #21259
|
||||
/*
|
||||
* boolean isAccessibleURL = false; try { isAccessibleURL =
|
||||
* CatalogueUtilMethods.resourceExists(resourceBean.getUrl()); } catch
|
||||
* (Exception e) { throw new Exception("It seems the resource at this url " +
|
||||
* resourceBean.getUrl()+" is not reachable. Error: "+e.getMessage()); }
|
||||
*
|
||||
* if(!isAccessibleURL){ throw new
|
||||
* Exception("It seems there is no resource at this url " +
|
||||
* resourceBean.getUrl()); }
|
||||
*/
|
||||
|
||||
GcubeContext gcubeContext = null;
|
||||
try {
|
||||
|
||||
|
@ -1496,7 +1621,7 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
if (createdRes != null) {
|
||||
LOG.info("Resource with id: " + createdRes.getId() + ", name: " + createdRes.getName()
|
||||
+ " added correclty");
|
||||
return createdRes.getId();
|
||||
return createdRes;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Unable to add the resource " + resourceBean, e);
|
||||
|
@ -1507,6 +1632,7 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1533,7 +1659,17 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
|
||||
GcubeContext gcubeContext = null;
|
||||
try {
|
||||
CkanResource theResource = ckanCaller.getResource(resourceId);
|
||||
CkanResource theResource = null;
|
||||
// Using CKAN API KEY TO READ THE RESOURCE
|
||||
if (username != null && !username.isEmpty()) {
|
||||
LOG.info("username found. Calling the " + ExtendCkanClient.class.getSimpleName());
|
||||
String apiKey = getApiKeyFromUsername(username);
|
||||
ExtendCkanClient client = new ExtendCkanClient(CKAN_CATALOGUE_URL, apiKey);
|
||||
theResource = client.getResource(resourceId);
|
||||
} else {
|
||||
// GUEST MODE - NO API
|
||||
theResource = ckanCaller.getResource(resourceId);
|
||||
}
|
||||
|
||||
CkanDataset theDataset = getDataset(theResource.getPackageId(), username);
|
||||
|
||||
|
|
|
@ -32,18 +32,20 @@ public interface CatalogueContentModeratorSystem {
|
|||
/**
|
||||
* Gets the list items for status.
|
||||
*
|
||||
* @param theStatus the the status
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @param filters add the input filters to query on CKAN
|
||||
* @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
|
||||
*/
|
||||
public List<CkanDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset,
|
||||
Map<String, String> filters, String sortForField) throws WebApplicationException, MalformedURLException, InvalidObjectException;
|
||||
List<CkanDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset, Boolean allFields,
|
||||
Map<String, String> filters, String sortForField)
|
||||
throws WebApplicationException, MalformedURLException, InvalidObjectException;
|
||||
|
||||
/**
|
||||
* Reject item.
|
||||
|
@ -80,9 +82,20 @@ public interface CatalogueContentModeratorSystem {
|
|||
*
|
||||
* @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) throws WebApplicationException, MalformedURLException;
|
||||
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;
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
|||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
|
||||
import org.gcube.gcat.api.moderation.CMItemStatus;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -49,10 +50,11 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks if is Moderation is enabled in the working scope
|
||||
* Checks if is Moderation is enabled in the working scope.
|
||||
*
|
||||
* @param reloadConfig the reload config
|
||||
* @return true, if is content moderator enabled
|
||||
* @throws MalformedURLException
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
@Override
|
||||
public boolean isModerationEnabled(boolean reloadConfig) throws MalformedURLException {
|
||||
|
@ -64,13 +66,30 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
|||
*
|
||||
* @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)
|
||||
public void approveItem(String datasetName, String moderatorMessage, Boolean sendSocialPost)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
gCatCaller.approveItem(datasetName, moderatorMessage);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -115,10 +134,11 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
|||
/**
|
||||
* Gets the list items for status.
|
||||
*
|
||||
* @param theStatus the the status
|
||||
* @param limit the limit
|
||||
* @param offset the offset
|
||||
* @param filters add the input filters to query on CKAN
|
||||
* @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
|
||||
|
@ -126,30 +146,40 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
|||
* @throws InvalidObjectException the invalid object exception
|
||||
*/
|
||||
@Override
|
||||
public List<CkanDataset> getListItemsForStatus(ItemStatus theStatus, int limit, int offset,
|
||||
Map<String, String> filters, String sortForField) throws WebApplicationException, MalformedURLException, InvalidObjectException {
|
||||
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 + "], [filters: " + filters + "]");
|
||||
+ offset + "], [allFields: " + allFields + "], [filters: " + filters + "]");
|
||||
List<CkanDataset> listDataset = null;
|
||||
checkNotNull(theStatus);
|
||||
JSONArray jsonArray = getSourceArrayOfItemsForStatus(theStatus, limit, offset, filters, sortForField);
|
||||
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 datasetName = null;
|
||||
String jsonValueDataset = null;
|
||||
try {
|
||||
datasetName = (String) jsonArray.get(i);
|
||||
LOG.debug("reading dataset: " + datasetName);
|
||||
String jsonValueDataset = gCatCaller.getDatasetForName(datasetName);
|
||||
LOG.trace("the JSON dataset is: " + jsonValueDataset);
|
||||
CkanDataset toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset, METHOD.TO_READ);
|
||||
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 name: " + datasetName, e);
|
||||
LOG.warn("Error on reading/converting the dataset: " + jsonValueDataset, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -190,10 +220,11 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
|||
/**
|
||||
* 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 filters the filters
|
||||
* @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
|
||||
|
@ -201,9 +232,10 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
|||
* @throws InvalidObjectException the invalid object exception
|
||||
*/
|
||||
protected org.json.simple.JSONArray getSourceArrayOfItemsForStatus(ItemStatus theStatus, int limit, int offset,
|
||||
Map<String, String> filters, String sortForField) throws WebApplicationException, MalformedURLException, InvalidObjectException {
|
||||
Boolean allFields, Map<String, String> filters, String sortForField)
|
||||
throws WebApplicationException, MalformedURLException, InvalidObjectException {
|
||||
LOG.info("called getSourceArrayOfItemsForStatus with [status: " + theStatus + "], [limit: " + limit
|
||||
+ "], [offset: " + offset + "], [filters: " + filters + "]");
|
||||
+ "], [offset: " + offset + "], [allFields: " + allFields + "], [filters: " + filters + "]");
|
||||
checkNotNull(theStatus);
|
||||
// TODO MUST BE CHANGED FOR THE STATUS
|
||||
org.json.simple.JSONArray jsonArray = null;
|
||||
|
@ -216,10 +248,11 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
|||
*/
|
||||
|
||||
CMItemStatus cmiStatus = toCMStatus(theStatus);
|
||||
String datasetNames = gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset, filters, sortForField);
|
||||
String datasetNames = gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset, allFields, filters,
|
||||
sortForField);
|
||||
|
||||
if (datasetNames != null) {
|
||||
LOG.debug("for status " + theStatus + " found dataset: " + datasetNames);
|
||||
LOG.trace("for status " + theStatus + " found dataset: " + datasetNames);
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
jsonArray = (JSONArray) parser.parse(datasetNames);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -13,8 +13,7 @@ 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.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.gcube.gcat.client.Item;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
|
@ -22,63 +21,89 @@ import org.slf4j.LoggerFactory;
|
|||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Jun 1, 2020
|
||||
*/
|
||||
public class TestDataCatalogueCMS {
|
||||
public class TestDataCatalogueCMS extends ContextTest {
|
||||
|
||||
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestDataCatalogueCMS.class);
|
||||
|
||||
private DataCatalogueFactory factory;
|
||||
private String scope = "/gcube/devsec/devVRE";
|
||||
private String testUser = "francesco.mangiacrapa";
|
||||
private String authorizationToken = "";
|
||||
private String scope = "/gcube/devsec/devVRE";
|
||||
//private String scope = "/gcube/devsec";
|
||||
private String authorizationToken = ""; //devVRE
|
||||
|
||||
/**
|
||||
* Before.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Before
|
||||
//@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
|
||||
//@Test
|
||||
public void contentModeratorTest() throws Exception {
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
|
||||
DataCatalogueImpl dImpl = factory.getUtilsPerScope(scope);
|
||||
CatalogueContentModeratorSystem cCMS = dImpl.getCatalogueContentModerator();
|
||||
LOG.debug(CatalogueContentModeratorSystem.class.getName() + " instancied correclty");
|
||||
}
|
||||
|
||||
// @Test
|
||||
//@Test
|
||||
public void listItemsForCMStatus() throws Exception {
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
String theQuery = mockQueryForEmails(emailsAddresses, "OR");
|
||||
|
||||
Map<String, String> filters = new HashMap<String, String>();
|
||||
filters.put("author_email", theQuery);
|
||||
Map<String, String> filters = new HashMap<String, String>();
|
||||
filters.put("author_email", theQuery);
|
||||
|
||||
List<CkanDataset> listItems = cCMS.getListItemsForStatus(theStatus, 10, 0, filters, GCatCaller.DEFAULT_SORT_VALUE);
|
||||
int i = 0;
|
||||
for (CkanDataset ckanDataset : listItems) {
|
||||
System.out.println(++i + ") item returned: " + ckanDataset);
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -89,7 +114,7 @@ public class TestDataCatalogueCMS {
|
|||
* @return the scope per url
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
// @Test
|
||||
public void countListItemsForStatus() throws Exception {
|
||||
|
||||
try {
|
||||
|
@ -101,9 +126,9 @@ public class TestDataCatalogueCMS {
|
|||
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");
|
||||
// emailsAddresses.add("luca.frosini@isti.cnr.it");
|
||||
emailsAddresses.add("francesco.mangiacrapa@isti.cnr.it");
|
||||
// emailsAddresses.add("pagano@cnr.it");
|
||||
|
||||
String theQuery = mockQueryForEmails(emailsAddresses, "OR");
|
||||
|
||||
|
|
|
@ -7,11 +7,9 @@ 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;
|
||||
import org.gcube.datacatalogue.utillibrary.gcat.GCatCaller;
|
||||
import org.gcube.datacatalogue.utillibrary.server.ApplicationProfileScopePerUrlReader;
|
||||
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory;
|
||||
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl;
|
||||
|
@ -29,12 +27,12 @@ import org.slf4j.LoggerFactory;
|
|||
*
|
||||
* @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/devsec/devVRE";
|
||||
// private String scope = "/gcube";
|
||||
// private String scope = "/pred4s/preprod/preVRE";
|
||||
// private String scope =
|
||||
|
@ -43,7 +41,7 @@ public class TestDataCatalogueLib {
|
|||
// "/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";
|
||||
|
@ -53,7 +51,7 @@ public class TestDataCatalogueLib {
|
|||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
// @Before
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
factory = DataCatalogueFactory.getFactory();
|
||||
}
|
||||
|
@ -63,7 +61,7 @@ public class TestDataCatalogueLib {
|
|||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
// @Test
|
||||
//@Test
|
||||
public void factoryTest() throws Exception {
|
||||
|
||||
DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
|
||||
|
@ -123,12 +121,19 @@ public class TestDataCatalogueLib {
|
|||
* @return the user role by group
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
// @Test
|
||||
//@Test
|
||||
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);
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,7 +162,7 @@ public class TestDataCatalogueLib {
|
|||
LOG.debug("The user " + testUser + " in the org " + org.getName() + " has the role " + role);
|
||||
}
|
||||
|
||||
// @Test
|
||||
//@Test
|
||||
public void getOrganizationForName() throws Exception {
|
||||
|
||||
String orgName = "devvre";
|
||||
|
@ -237,8 +242,8 @@ public class TestDataCatalogueLib {
|
|||
|
||||
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();
|
||||
|
@ -283,8 +288,8 @@ public class TestDataCatalogueLib {
|
|||
// @Test
|
||||
public void createGroup() throws Exception {
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
int random = new Random().nextInt();
|
||||
|
@ -297,8 +302,8 @@ public class TestDataCatalogueLib {
|
|||
// @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);
|
||||
|
@ -313,8 +318,8 @@ public class TestDataCatalogueLib {
|
|||
// @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";
|
||||
|
@ -326,8 +331,8 @@ public class TestDataCatalogueLib {
|
|||
// @Test
|
||||
public void patchFieldsForDataset() throws Exception {
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
Map<String, String> customFieldsToChange = new HashMap<String, String>();
|
||||
|
@ -338,8 +343,8 @@ public class TestDataCatalogueLib {
|
|||
// @Test
|
||||
public void getUrlProduct() throws Exception {
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(authorizationToken);
|
||||
|
||||
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
||||
String datasetName = productName;
|
||||
|
|
Loading…
Reference in New Issue