Compare commits

...

6 Commits

9 changed files with 644 additions and 417 deletions

View File

@ -4,6 +4,15 @@
All notable changes to this project will be documented in this file. 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). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.4.0-SNAPSHOT] - 2024-02-08
**Enhancements**
- Added method update item [#26640]
- Added method deleteDataset [#26793]
- Added method getListExtrasAsHashMap - D4Science model compliant
## [v1.3.0] - 2023-02-06 ## [v1.3.0] - 2023-02-06
**Enhancements** **Enhancements**

View File

@ -6,13 +6,13 @@
<parent> <parent>
<artifactId>maven-parent</artifactId> <artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId> <groupId>org.gcube.tools</groupId>
<version>1.1.0</version> <version>1.2.0</version>
<relativePath /> <relativePath />
</parent> </parent>
<groupId>org.gcube.datacatalogue</groupId> <groupId>org.gcube.datacatalogue</groupId>
<artifactId>catalogue-util-library</artifactId> <artifactId>catalogue-util-library</artifactId>
<version>1.3.0</version> <version>1.4.0-SNAPSHOT</version>
<name>Ckan utility library</name> <name>Ckan utility library</name>
<description> <description>
Utility library to retrieve users information, organizations information and so on from the ckan d4science datacatalogue Utility library to retrieve users information, organizations information and so on from the ckan d4science datacatalogue

View File

@ -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.CkanGroup;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanLicense; 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.CkanOrganization;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanResource;
/** /**
* The Interface DataCatalogue. * The Interface DataCatalogue.
@ -332,6 +333,35 @@ public interface DataCatalogue {
List<ResourceBean> resources, boolean setPublic, boolean setSearchable, boolean socialPost) List<ResourceBean> resources, boolean setPublic, boolean setSearchable, boolean socialPost)
throws Exception; 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 * Add a resource described by the bean to the dataset id into
* resource.datasetId * resource.datasetId
@ -344,6 +374,19 @@ public interface DataCatalogue {
*/ */
String addResourceToDataset(ResourceBean resourceBean, String organizationName, String username) throws 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. * 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; 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 * Patch a product with product id productId by using the couples in
* customFieldsToChange. NOTE: only the specified custom fields will be changed. * customFieldsToChange. NOTE: only the specified custom fields will be changed.

View File

@ -1305,7 +1305,7 @@ public class DataCatalogueImpl implements DataCatalogue {
if (jsonValueDataset != null) { if (jsonValueDataset != null) {
CkanDataset toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset, METHOD.TO_READ); 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(); return toCkanDataset.getId();
} }
} catch (Exception e) { } catch (Exception e) {
@ -1320,6 +1320,80 @@ public class DataCatalogueImpl implements DataCatalogue {
return null; 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. * Refresh dataset.
* *
@ -1360,6 +1434,32 @@ public class DataCatalogueImpl implements DataCatalogue {
return null; 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. * Patch fields for dataset.
* *
@ -1462,22 +1562,47 @@ public class DataCatalogueImpl implements DataCatalogue {
throws Exception { throws Exception {
LOG.info("Called addResourceToDataset by this bean " + resourceBean); 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 // checks
checkNotNull(resourceBean); checkNotNull(resourceBean);
checkNotNull(resourceBean.getUrl()); 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; GcubeContext gcubeContext = null;
try { try {
@ -1496,7 +1621,7 @@ public class DataCatalogueImpl implements DataCatalogue {
if (createdRes != null) { if (createdRes != null) {
LOG.info("Resource with id: " + createdRes.getId() + ", name: " + createdRes.getName() LOG.info("Resource with id: " + createdRes.getId() + ", name: " + createdRes.getName()
+ " added correclty"); + " added correclty");
return createdRes.getId(); return createdRes;
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error("Unable to add the resource " + resourceBean, e); LOG.error("Unable to add the resource " + resourceBean, e);
@ -1507,6 +1632,7 @@ public class DataCatalogueImpl implements DataCatalogue {
} }
return null; return null;
} }
/** /**
@ -1533,7 +1659,17 @@ public class DataCatalogueImpl implements DataCatalogue {
GcubeContext gcubeContext = null; GcubeContext gcubeContext = null;
try { 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); CkanDataset theDataset = getDataset(theResource.getPackageId(), username);

View File

@ -68,8 +68,10 @@ public class CKANConveter {
String ckanUsername = CatalogueUtilMethods.fromUsernameToCKanUsername(username); String ckanUsername = CatalogueUtilMethods.fromUsernameToCKanUsername(username);
String nameToUse = name; 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); nameToUse = CatalogueUtilMethods.fromProductTitleToName(title);
}
LOG.debug("Name of the dataset is going to be " + nameToUse + ". Title is going to be " + title); LOG.debug("Name of the dataset is going to be " + nameToUse + ". Title is going to be " + title);

View File

@ -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.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty; import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
/** /**
* A Ckan Dataset, which in turn holds Ckan Resources. * A Ckan Dataset, which in turn holds Ckan Resources.
* *
* In Ckan terminology it is also known as 'package'. * In Ckan terminology it is also known as 'package'.
* *
* {@link CkanDatasetBase} holds fields that can be sent when * {@link CkanDatasetBase} holds fields that can be sent when <a href=
* <a href="http://docs.ckan.org/en/latest/api/index.html?#ckan.logic.action.create.package_create" target="_blank">creating * "http://docs.ckan.org/en/latest/api/index.html?#ckan.logic.action.create.package_create"
* a dataset,</a>, while {@link CkanDataset} holds more fields that can be * target="_blank">creating a dataset,</a>, while {@link CkanDataset} holds more
* returned with searches. * fields that can be returned with searches.
* *
* This class initializes nothing to fully preserve all we get from ckan. In * This class initializes nothing to fully preserve all we get from ckan. In
* practice, all fields of retrieved resources can be null except maybe * practice, all fields of retrieved resources can be null except maybe
@ -75,8 +73,8 @@ public class CkanDatasetBase {
private Boolean priv; private Boolean priv;
/** /**
* Custom CKAN instances might sometimes gift us with properties that don't * Custom CKAN instances might sometimes gift us with properties that don't end
* end up in extras. They will end up here. * up in extras. They will end up here.
*/ */
@Nullable @Nullable
private Map<String, Object> others; private Map<String, Object> others;
@ -97,12 +95,11 @@ public class CkanDatasetBase {
} }
/** /**
* CKAN instances might have * CKAN instances might have <a href=
* <a href="http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html"> * "http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html"> custom
* custom data schemas</a> that force presence of custom properties among * data schemas</a> that force presence of custom properties among 'regular'
* 'regular' ones. In this case, they go to 'others' field. Note that to * ones. In this case, they go to 'others' field. Note that to further
* further complicate things there is also an {@link #getExtras() extras} * complicate things there is also an {@link #getExtras() extras} field.
* field.
* *
* @see #putOthers(java.lang.String, java.lang.Object) * @see #putOthers(java.lang.String, java.lang.Object)
*/ */
@ -151,9 +148,10 @@ public class CkanDatasetBase {
/** /**
* Notice that if the dataset was obtained with a * Notice that if the dataset was obtained with a
* {@link eu.trentorise.opendata.jackan.CkanClient#getDataset(java.lang.String)} call, the returned group * {@link eu.trentorise.opendata.jackan.CkanClient#getDataset(java.lang.String)}
* won't have all the params you would get with a * 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. * {@link eu.trentorise.opendata.jackan.CkanClient#getGroup(java.lang.String)}
* call.
*/ */
public List<CkanGroup> getGroups() { public List<CkanGroup> getGroups() {
return groups; return groups;
@ -178,9 +176,8 @@ public class CkanDatasetBase {
} }
/** /**
* Regular place where to put custom metadata. See also * Regular place where to put custom metadata. See also {@link #getOthers()}.
* {@link #getOthers()}. Note also extras can be in CkanDataset but not in * Note also extras can be in CkanDataset but not in CkanResource.
* CkanResource.
*/ */
public List<CkanPair> getExtras() { public List<CkanPair> getExtras() {
return extras; return extras;
@ -193,6 +190,7 @@ public class CkanDatasetBase {
this.extras = extras; this.extras = extras;
} }
/** /**
* Always returns a non-null map (which might be empty) * Always returns a non-null map (which might be empty)
*/ */
@ -207,6 +205,30 @@ public class CkanDatasetBase {
return hm; return hm;
} }
/**
* 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) {
List<String> list = hm.get(cp.getKey());
if (list == null)
list = new ArrayList<String>();
list.add(cp.getValue());
hm.put(cp.getKey(), list);
}
}
return hm;
}
/** /**
* Adds CkanExtras * Adds CkanExtras
* *
@ -222,8 +244,7 @@ public class CkanDatasetBase {
} }
/** /**
* Returns the alphanumerical id, i.e. * Returns the alphanumerical id, i.e. "c4577b8f-5603-4098-917e-da03e8ddf461"
* "c4577b8f-5603-4098-917e-da03e8ddf461"
*/ */
public String getId() { public String getId() {
return id; return id;
@ -275,8 +296,8 @@ public class CkanDatasetBase {
} }
/** /**
* The dataset name. Name must not contain spaces and have dashes as * The dataset name. Name must not contain spaces and have dashes as separators,
* separators, i.e. "limestone-pavement-orders" * i.e. "limestone-pavement-orders"
* *
*/ */
public void setName(String name) { public void setName(String name) {
@ -284,18 +305,18 @@ public class CkanDatasetBase {
} }
/** /**
* A description of the dataset. See also * A description of the dataset. See also {@link CkanDataset#getNotesRendered()}
* {@link CkanDataset#getNotesRendered()} Note CkanResource has instead a * Note CkanResource has instead a field called
* field called {@link CkanResourceBase#getDescription() description}. * {@link CkanResourceBase#getDescription() description}.
*/ */
public String getNotes() { public String getNotes() {
return notes; return notes;
} }
/** /**
* A description of the dataset. See also * A description of the dataset. See also {@link CkanDataset#getNotesRendered()}
* {@link CkanDataset#getNotesRendered()} Note CkanResource has instead a * Note CkanResource has instead a field called
* field called {@link CkanResourceBase#getDescription() description}. * {@link CkanResourceBase#getDescription() description}.
*/ */
public void setNotes(String notes) { public void setNotes(String notes) {
this.notes = notes; this.notes = notes;
@ -358,8 +379,8 @@ public class CkanDatasetBase {
/** /**
* The current state of the dataset, e.g. 'active' or 'deleted', only active * 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 * 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 * parameter will be ignored if you are not authorized to change the state of
* of the dataset (optional, default: 'active') * the dataset (optional, default: 'active')
*/ */
public CkanState getState() { public CkanState getState() {
return state; return state;
@ -368,8 +389,8 @@ public class CkanDatasetBase {
/** /**
* The current state of the dataset, e.g. 'active' or 'deleted', only active * 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 * 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 * parameter will be ignored if you are not authorized to change the state of
* of the dataset (optional, default: 'active') * the dataset (optional, default: 'active')
*/ */
public void setState(CkanState state) { public void setState(CkanState state) {
this.state = state; this.state = state;
@ -412,34 +433,34 @@ public class CkanDatasetBase {
} }
/** /**
* The type of the dataset (optional), IDatasetForm plugins associate * The type of the dataset (optional), IDatasetForm plugins associate themselves
* themselves with different dataset types and provide custom dataset * with different dataset types and provide custom dataset handling behaviour
* handling behaviour for these types * for these types
*/ */
public String getType() { public String getType() {
return type; return type;
} }
/** /**
* The type of the dataset (optional), IDatasetForm plugins associate * The type of the dataset (optional), IDatasetForm plugins associate themselves
* themselves with different dataset types and provide custom dataset * with different dataset types and provide custom dataset handling behaviour
* handling behaviour for these types * for these types
*/ */
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
/** /**
* Should be the landing page on original data provider website describing * Should be the landing page on original data provider website describing the
* the dataset. * dataset.
*/ */
public String getUrl() { public String getUrl() {
return url; return url;
} }
/** /**
* Should be the landing page on original data provider website describing * Should be the landing page on original data provider website describing the
* the dataset. * dataset.
*/ */
public void setUrl(String url) { public void setUrl(String url) {
this.url = url; this.url = url;
@ -471,8 +492,7 @@ public class CkanDatasetBase {
} }
/** /**
* Actually it is named "private" in the CKAN API. Appears in dataset * Actually it is named "private" in the CKAN API. Appears in dataset searches.
* searches.
*/ */
@JsonProperty("private") @JsonProperty("private")
public Boolean isPriv() { public Boolean isPriv() {
@ -480,8 +500,7 @@ public class CkanDatasetBase {
} }
/** /**
* Actually it is named "private" in the CKAN API. Appears in dataset * Actually it is named "private" in the CKAN API. Appears in dataset searches.
* searches.
*/ */
public void setPriv(Boolean priv) { public void setPriv(Boolean priv) {
this.priv = priv; this.priv = priv;
@ -538,6 +557,4 @@ public class CkanDatasetBase {
return builder.toString(); return builder.toString();
} }
} }

View File

@ -27,9 +27,16 @@ public class ContextTest {
protected static Properties properties; protected static Properties properties;
protected static final String PROPERTIES_FILENAME = "token.properties"; protected static final String PROPERTIES_FILENAME = "token.properties";
public static final String ROOT = "/gcube"; // public static final String ROOT = "/gcube";
public static final String VO = ROOT + "/devsec"; // public static final String VO = ROOT + "/devsec";
public static final String VRE = VO + "/devVRE"; // 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 { static {
properties = new Properties(); properties = new Properties();

View File

@ -14,8 +14,6 @@ import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorS
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus; import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset; import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
import org.gcube.gcat.client.Item; import org.gcube.gcat.client.Item;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**

View File

@ -7,7 +7,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject; import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject;
import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject.METHOD; import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject.METHOD;
@ -28,12 +27,12 @@ import org.slf4j.LoggerFactory;
* *
* @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 static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestDataCatalogueLib.class);
private DataCatalogueFactory factory; private DataCatalogueFactory factory;
private String scope = "/gcube/devsec/devVRE"; //private String scope = "/gcube/devsec/devVRE";
// private String scope = "/gcube"; // private String scope = "/gcube";
// private String scope = "/pred4s/preprod/preVRE"; // private String scope = "/pred4s/preprod/preVRE";
// private String scope = // private String scope =
@ -42,7 +41,7 @@ public class TestDataCatalogueLib {
// "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab"; // "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab";
// private String testUser = "costantino_perciante"; // private String testUser = "costantino_perciante";
private String testUser = "francesco.mangiacrapa"; private String testUser = "francesco.mangiacrapa";
private String authorizationToken = ""; //private String authorizationToken = "";
String subjectId = "aa_father4"; String subjectId = "aa_father4";
String objectId = "bb_son4"; String objectId = "bb_son4";
String productName = "adatasetcreatedbycatalogue-util-library-873805063"; String productName = "adatasetcreatedbycatalogue-util-library-873805063";
@ -52,7 +51,7 @@ public class TestDataCatalogueLib {
* *
* @throws Exception the exception * @throws Exception the exception
*/ */
// @Before @Before
public void before() throws Exception { public void before() throws Exception {
factory = DataCatalogueFactory.getFactory(); factory = DataCatalogueFactory.getFactory();
} }
@ -124,10 +123,17 @@ public class TestDataCatalogueLib {
*/ */
//@Test //@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); DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
String username = testUser; 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 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());
} }
/** /**
@ -236,8 +242,8 @@ public class TestDataCatalogueLib {
try { try {
ScopeProvider.instance.set(scope); // ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); // SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope); DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
String licenseId = instance.getLicenses().get(0).getId(); String licenseId = instance.getLicenses().get(0).getId();
@ -282,8 +288,8 @@ public class TestDataCatalogueLib {
// @Test // @Test
public void createGroup() throws Exception { public void createGroup() throws Exception {
ScopeProvider.instance.set(scope); // ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); // SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope); DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
int random = new Random().nextInt(); int random = new Random().nextInt();
@ -296,8 +302,8 @@ public class TestDataCatalogueLib {
// @Test // @Test
public void addResource() throws Exception { public void addResource() throws Exception {
ScopeProvider.instance.set(scope); // ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); // SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope); DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
CkanDataset dataset = instance.getDataset(productName, testUser); CkanDataset dataset = instance.getDataset(productName, testUser);
@ -312,8 +318,8 @@ public class TestDataCatalogueLib {
// @Test // @Test
public void deleteResource() throws Exception { public void deleteResource() throws Exception {
ScopeProvider.instance.set(scope); // ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); // SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope); DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
String resourceId = "ce7295cf-47db-4faf-901f-4fec2d3fae7a"; String resourceId = "ce7295cf-47db-4faf-901f-4fec2d3fae7a";
@ -325,8 +331,8 @@ public class TestDataCatalogueLib {
// @Test // @Test
public void patchFieldsForDataset() throws Exception { public void patchFieldsForDataset() throws Exception {
ScopeProvider.instance.set(scope); // ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); // SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope); DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
Map<String, String> customFieldsToChange = new HashMap<String, String>(); Map<String, String> customFieldsToChange = new HashMap<String, String>();
@ -337,8 +343,8 @@ public class TestDataCatalogueLib {
// @Test // @Test
public void getUrlProduct() throws Exception { public void getUrlProduct() throws Exception {
ScopeProvider.instance.set(scope); // ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken); // SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope); DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
String datasetName = productName; String datasetName = productName;