2021-04-09 14:51:55 +02:00
|
|
|
package org.gcube.portlets.widgets.ckandatapublisherwidget;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
2024-02-08 14:09:56 +01:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
2021-04-09 14:51:55 +02:00
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
|
|
|
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory;
|
2024-02-08 14:09:56 +01:00
|
|
|
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl;
|
|
|
|
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
|
2021-04-09 14:51:55 +02:00
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.WorkspaceUtils;
|
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean;
|
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
2024-02-08 14:09:56 +01:00
|
|
|
import org.junit.Test;
|
2021-04-09 14:51:55 +02:00
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class TestDataCatalogueLib.
|
|
|
|
*
|
2024-02-08 14:09:56 +01:00
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Jun 1, 2020
|
2021-04-09 14:51:55 +02:00
|
|
|
*/
|
|
|
|
public class TestPublishingWidget {
|
|
|
|
|
|
|
|
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestPublishingWidget.class);
|
|
|
|
|
|
|
|
private String scope = "/gcube";
|
2024-02-08 14:09:56 +01:00
|
|
|
// private String testUser = "costantino_perciante";
|
2021-04-09 14:51:55 +02:00
|
|
|
private String testUser = "francesco.mangiacrapa";
|
|
|
|
private String authorizationToken = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Before.
|
|
|
|
*
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2024-02-08 14:09:56 +01:00
|
|
|
// @Before
|
|
|
|
public void before() throws Exception {
|
2021-04-09 14:51:55 +02:00
|
|
|
}
|
2024-02-08 14:09:56 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getDataset() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
scope = "/d4science.research-infrastructures.eu/D4OS/Blue-Cloud2026Project";
|
|
|
|
authorizationToken = "8c3ce374-5482-422d-9542-97b1b9360747-843339462"; //Blue-Cloud2026Project
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
SecurityTokenProvider.instance.set(authorizationToken);
|
|
|
|
|
|
|
|
String datasetId = "blue-cloud_2026_-_a_federated_european_fair_and_open_research_ecosystem_for_oceans_seas_coastal_and";
|
|
|
|
|
|
|
|
DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
|
|
|
|
|
2021-04-09 14:51:55 +02:00
|
|
|
|
2024-02-08 14:09:56 +01:00
|
|
|
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
|
|
|
|
|
|
|
CkanDataset dataset = utils.getDataset(datasetId, testUser);
|
|
|
|
System.out.println("Dataset: "+dataset);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-09 14:51:55 +02:00
|
|
|
/**
|
|
|
|
* Factory test.
|
|
|
|
*
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2024-02-08 14:09:56 +01:00
|
|
|
// @Test
|
|
|
|
public void factoryTest() throws Exception {
|
2021-04-09 14:51:55 +02:00
|
|
|
|
|
|
|
DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
|
|
|
|
|
2024-02-08 14:09:56 +01:00
|
|
|
while (true) {
|
2021-04-09 14:51:55 +02:00
|
|
|
factory.getUtilsPerScope(scope);
|
2024-02-08 14:09:56 +01:00
|
|
|
Thread.sleep(60 * 1000 * 3);
|
2021-04-09 14:51:55 +02:00
|
|
|
factory.getUtilsPerScope(scope);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
factory.getUtilsPerScope(scope);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-02-08 14:09:56 +01:00
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void getDatasetBeanTest() throws Exception {
|
2021-04-09 14:51:55 +02:00
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
String userName = testUser;
|
|
|
|
String token = authorizationToken;
|
2024-02-08 14:09:56 +01:00
|
|
|
|
2021-04-09 14:51:55 +02:00
|
|
|
String folderId = "6399daa7-2173-4314-b4f7-2afa24eae8f8";
|
|
|
|
DatasetBean bean;
|
2024-02-08 14:09:56 +01:00
|
|
|
try {
|
2021-04-09 14:51:55 +02:00
|
|
|
bean = new DatasetBean();
|
|
|
|
bean.setId(folderId);
|
|
|
|
bean.setDescription("This is a fantastic description");
|
|
|
|
bean.setVersion(1);
|
|
|
|
String onlyAlphanumeric = "test-creation-blablabla".replaceAll("[^A-Za-z0-9]", "");
|
|
|
|
bean.setTitle(onlyAlphanumeric + Calendar.getInstance().getTimeInMillis());
|
|
|
|
bean.setAuthorName("Francesco");
|
|
|
|
bean.setAuthorSurname("Mangiacrapa");
|
|
|
|
bean.setAuthorEmail("francesco.mangiacrapa@isti.cnr.it");
|
|
|
|
bean.setMaintainer("Francesco Mangiacrapa");
|
|
|
|
bean.setMaintainerEmail("francesco.mangiacrapa@isti.cnr.it");
|
|
|
|
|
2024-02-08 14:09:56 +01:00
|
|
|
// UPDATED By Francesco
|
|
|
|
String vreName = scope.substring(scope.lastIndexOf("/") + 1, scope.length());
|
|
|
|
LOG.debug("In dev mode using the scope: " + scope + " and VRE name: " + vreName);
|
2021-04-09 14:51:55 +02:00
|
|
|
bean.setOrganizationList(Arrays.asList(new OrganizationBean(vreName, vreName.toLowerCase(), true)));
|
|
|
|
|
|
|
|
bean.setOwnerIdentifier(userName);
|
|
|
|
|
2024-02-08 14:09:56 +01:00
|
|
|
if (folderId != null && !folderId.isEmpty()) {
|
2021-04-09 14:51:55 +02:00
|
|
|
StorageHubWrapper storageHubWrapper = new StorageHubWrapper(scope, token, false, false, true);
|
|
|
|
WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, storageHubWrapper.getWorkspace());
|
|
|
|
}
|
2024-02-08 14:09:56 +01:00
|
|
|
} catch (Exception e) {
|
2021-04-09 14:51:55 +02:00
|
|
|
LOG.error("Error while building bean into dev mode", e);
|
|
|
|
throw new Exception("Error while retrieving basic information " + e.getMessage());
|
|
|
|
}
|
2024-02-08 14:09:56 +01:00
|
|
|
|
|
|
|
LOG.info("Got dataset: " + bean);
|
2021-04-09 14:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|