updated createDataset and addResource

This commit is contained in:
Francesco Mangiacrapa 2021-02-09 17:55:44 +01:00
parent 20d4579785
commit 4b05ed4e97
5 changed files with 45 additions and 44 deletions

17
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.datacatalogue</groupId>
<artifactId>catalogue-util-library</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<name>Ckan utility library</name>
<description>
@ -27,7 +27,6 @@
<properties>
<serviceClass>data-catalogue</serviceClass>
<jackanVersion>0.4.2</jackanVersion>
<postgresVersion>9.4.1208.jre7</postgresVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -40,7 +39,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<version>3.6.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -54,14 +53,6 @@
<scope>provided</scope>
</dependency>
<!-- CKAN client library -->
<!-- <dependency> -->
<!-- <groupId>eu.trentorise.opendata</groupId> -->
<!-- <artifactId>jackan</artifactId> -->
<!-- <version>${jackanVersion}</version> -->
<!-- <scope>compile</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>gcube-jackson-core</artifactId>
@ -105,9 +96,9 @@
</dependency>
<dependency>
<groupId>org.gcube.data-publishing</groupId>
<groupId>org.gcube.data-catalogue</groupId>
<artifactId>gcat-client</artifactId>
<version>[1.0.0, 2.0.0)</version>
<version>[2.0.0-SNAPSHOT, 3.0.0)</version>
<scope>compile</scope>
</dependency>

View File

@ -111,7 +111,7 @@ public interface DataCatalogue {
* Retrieve a ckan dataset given its id.
*
* @param datasetId the dataset id
* @param apiKey the api key
* @param apiKey the api key. If null uses gCat to get the Dataset
* @return the dataset
*/
CkanDataset getDataset(String datasetId, String apiKey);

View File

@ -234,6 +234,9 @@ public class DataCatalogueImpl implements DataCatalogue {
return ckanCaller.getLicenseList();
}
/* (non-Javadoc)
* @see org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue#getDataset(java.lang.String, java.lang.String)
*/
@Override
public CkanDataset getDataset(String datasetId, String apiKey) {
LOG.info("Request ckan dataset with id " + datasetId);
@ -854,7 +857,7 @@ public class DataCatalogueImpl implements DataCatalogue {
*/
@Override
public String createCkanDatasetMultipleCustomFields(String username, String title, String name, String organizationNameOrId,
public String createCkanDatasetMultipleCustomFields(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 {
@ -862,13 +865,16 @@ public class DataCatalogueImpl implements DataCatalogue {
// checks (minimum)
checkNotNull(username);
checkNotNull(organizationNameOrId);
checkArgument(!organizationNameOrId.isEmpty());
//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!");
try {
//TODO IF THE SCOPE IS ROOT OR VO WE NEED TO PASS THE ORGNAME TO gCAT, no otherwise
// String ckanUsername = getUserFromApiKey(apiKey).getName();
CkanDataset dataset = CKANConveter.toCkanDataset(ckanCaller, username, title, name, organizationNameOrId, author, authorMail,
CkanDataset dataset = CKANConveter.toCkanDataset(ckanCaller, username, title, name, organizationName, author, authorMail,
maintainer, maintainerMail, version, description, licenseId, tags, null, customFieldsMultiple,
resources, setPublic, setSearchable);

View File

@ -39,7 +39,7 @@ public class CKANConveter {
* @param username the username
* @param title the title
* @param name the name
* @param organizationNameOrId the organization name or id
* @param organizationName the organization name or id
* @param author the author
* @param authorMail the author mail
* @param maintainer the maintainer
@ -55,7 +55,7 @@ public class CKANConveter {
* @param setSearchable the set searchable
* @return the ckan dataset
*/
public static CkanDataset toCkanDataset(ExtendCkanClient ckanCaller, String username, String title, String name, String organizationNameOrId, String author,
public static CkanDataset toCkanDataset(ExtendCkanClient ckanCaller, 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, String> customFields,
Map<String, List<String>> customFieldsMultipleValues, List<ResourceBean> resources, boolean setPublic, boolean setSearchable) {
@ -81,8 +81,10 @@ public class CKANConveter {
dataset.setTitle(title);
//TODO SHOULD BE REVISITED by gCAT?
CkanOrganization orgOwner = ckanCaller.getOrganization(organizationNameOrId);
dataset.setOwnerOrg(orgOwner.getId());
if(organizationName!=null) {
CkanOrganization orgOwner = ckanCaller.getOrganization(organizationName);
dataset.setOwnerOrg(orgOwner.getId());
}
dataset.setAuthor(author);
dataset.setAuthorEmail(authorMail);

View File

@ -14,6 +14,7 @@ import org.gcube.datacatalogue.ckanutillibrary.server.ApplicationProfileScopePer
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean;
import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanDataset;
import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanGroup;
import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanOrganization;
import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanUser;
@ -223,8 +224,8 @@ public class TestDataCatalogueLib {
ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
String licenseId = instance.getLicenses().get(0).getId();
Map<String, List<String>> customFieldsMultiple = new HashMap<String, List<String>>();
@ -247,6 +248,8 @@ public class TestDataCatalogueLib {
//System.out.println("Org name by VRE: "+orgName);
LOG.debug("Org name by VRE: "+orgName);
orgName = null;
int random = new Random().nextInt();
String datasetTitle = "a dataset created by catalogue-util-library "+random;
String datasetName = datasetTitle.replace(" ", "");
@ -278,8 +281,10 @@ public class TestDataCatalogueLib {
//@Test
public void createGroup() throws Exception{
ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
int random = new Random().nextInt();
String groupTitle = "a grop created by catalogue-util-library "+random;
@ -287,6 +292,23 @@ public class TestDataCatalogueLib {
CkanGroup ckanGroup = instance.createGroup(groupName, groupTitle, "description");
LOG.info("Created the group: "+ckanGroup);
}
@Test
public void testAddResource() throws Exception{
ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(authorizationToken);
DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
CkanDataset dataset = instance.getDataset("adatasetcreatedbycatalogue-util-library-1644679434", null);
for (int i = 0; i < 5; i++) {
ResourceBean resourceBean = new ResourceBean("https://google.com", "resouce "+i, "description "+i, null, testUser, dataset.getId(), null);
instance.addResourceToDataset(resourceBean);
}
}
@ -577,27 +599,7 @@ public class TestDataCatalogueLib {
//
// }
//
// //@Test
// public void testAddResource() throws Exception{
//
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
// String datasetId = "test_publish_folder_15_44";
// //instance.assignDatasetToGroup(groupName, datasetId, instance.getApiKeyFromUsername("costantino_perciante"));
//
// String api = instance.getApiKeyFromUsername("costantino_perciante");
// CheckedCkanClient client = new CheckedCkanClient(instance.getCatalogueUrl(), api);
// List<String> randomName = Arrays.asList("FIRMS", "RAM", "FishSource");
// for (int i = 0; i < 100; i++) {
//
// CkanResource resource = new CkanResource("https://goo.gl/FH5AQ5", datasetId);
// String name = randomName.get((int)Math.round(Math.ceil(Math.random() * 3)));
//
// resource.setName(name);
// client.createResource(resource);
//
// }
// }
//
// //@Test
// public void checkGroupRole() throws Exception{
//