package org.gcube.portlets.widgets.ckandatapublisherwidget; import java.util.Arrays; import java.util.Calendar; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory; 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; import org.slf4j.LoggerFactory; /** * The Class TestDataCatalogueLib. * * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) * Jun 1, 2020 */ public class TestPublishingWidget { private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestPublishingWidget.class); private String scope = "/gcube"; //private String testUser = "costantino_perciante"; private String testUser = "francesco.mangiacrapa"; private String authorizationToken = ""; /** * Before. * * @throws Exception the exception */ //@Before public void before() throws Exception{ } /** * Factory test. * * @throws Exception the exception */ //@Test public void factoryTest() throws Exception{ DataCatalogueFactory factory = DataCatalogueFactory.getFactory(); while(true){ factory.getUtilsPerScope(scope); Thread.sleep(60* 1000 * 3); factory.getUtilsPerScope(scope); break; } for (int i = 0; i < 5; i++) { Thread.sleep(1000); factory.getUtilsPerScope(scope); } } //@Test public void getDatasetBeanTest() throws Exception{ ScopeProvider.instance.set(scope); String userName = testUser; String token = authorizationToken; String folderId = "6399daa7-2173-4314-b4f7-2afa24eae8f8"; DatasetBean bean; try{ 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"); //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); bean.setOrganizationList(Arrays.asList(new OrganizationBean(vreName, vreName.toLowerCase(), true))); bean.setOwnerIdentifier(userName); if(folderId != null && !folderId.isEmpty()){ StorageHubWrapper storageHubWrapper = new StorageHubWrapper(scope, token, false, false, true); WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, storageHubWrapper.getWorkspace()); } }catch(Exception e){ LOG.error("Error while building bean into dev mode", e); throw new Exception("Error while retrieving basic information " + e.getMessage()); } LOG.info("Got dataset: "+bean); } }