diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c5103e..1383ca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ 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.1.0-SNAPSHOT] - 2021-06-14 + +**New Features** +[#21643] Integrated with the content-moderator-system facilities + ## [v1.0.2] - 2021-06-03 **Fixes** diff --git a/pom.xml b/pom.xml index e3e6265..b3fac14 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.datacatalogue catalogue-util-library - 1.0.2 + 1.1.0-SNAPSHOT Ckan utility library @@ -40,7 +40,7 @@ org.gcube.distribution maven-portal-bom - 3.6.2 + 3.6.2-SNAPSHOT pom import diff --git a/src/main/java/org/gcube/datacatalogue/utillibrary/server/DataCatalogueImpl.java b/src/main/java/org/gcube/datacatalogue/utillibrary/server/DataCatalogueImpl.java index 00f007d..7a57688 100644 --- a/src/main/java/org/gcube/datacatalogue/utillibrary/server/DataCatalogueImpl.java +++ b/src/main/java/org/gcube/datacatalogue/utillibrary/server/DataCatalogueImpl.java @@ -33,6 +33,8 @@ import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject.METHOD; import org.gcube.datacatalogue.utillibrary.db.DBCaller; import org.gcube.datacatalogue.utillibrary.gcat.GCatCaller; import org.gcube.datacatalogue.utillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET; +import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorSystem; +import org.gcube.datacatalogue.utillibrary.server.cms.DataCatalogueCMSImpl; import org.gcube.datacatalogue.utillibrary.server.utils.CKANConveter; import org.gcube.datacatalogue.utillibrary.server.utils.CatalogueUtilMethods; import org.gcube.datacatalogue.utillibrary.server.utils.GCubeUtils; @@ -57,6 +59,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// TODO: Auto-generated Javadoc /** * This is the Ckan Utils implementation class. * @@ -87,27 +90,28 @@ public class DataCatalogueImpl implements DataCatalogue { private Map extendRoleInOrganization; public Map mapAccessURLToCatalogue; - private static final String CATALOGUE_TAB_ENDING_URL = "/catalogue"; - + // gCat client private GCatCaller gCatCaller; - + // db client private DBCaller dbCaller; - + // ckan client private ExtendCkanClient ckanCaller; - + // hashmap for ckan api keys private ConcurrentHashMap apiKeysMap; - //http ckan caller - //private DirectCkanCaller directCkanCaller; //is not needed anymore? - + // http ckan caller + // private DirectCkanCaller directCkanCaller; //is not needed anymore? + // apikey bean expires after X minutes in the above map private static final int EXPIRE_KEY_TIME = 60 * 60 * 1000; + + private DataCatalogueCMSImpl dataCatalogueCMSImpl = null; /** @@ -168,6 +172,11 @@ public class DataCatalogueImpl implements DataCatalogue { ckanCaller = new ExtendCkanClient(CKAN_CATALOGUE_URL, CKAN_TOKEN_SYS); } + /** + * Gets the catalogue url. + * + * @return the catalogue url + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getCatalogueUrl() */ @@ -177,6 +186,11 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Gets the portlet url. + * + * @return the portlet url + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getPortletUrl() */ @@ -207,6 +221,12 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Find license id by license title. + * + * @param chosenLicense the chosen license + * @return the string + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#findLicenseIdByLicenseTitle(java.lang.String) */ @@ -228,6 +248,11 @@ public class DataCatalogueImpl implements DataCatalogue { return null; } + /** + * Gets the license titles. + * + * @return the license titles + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getLicenseTitles() */ @@ -248,6 +273,11 @@ public class DataCatalogueImpl implements DataCatalogue { return result; } + /** + * Gets the licenses. + * + * @return the licenses + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getLicenses() */ @@ -259,6 +289,13 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Gets the dataset. + * + * @param datasetIdOrName the dataset id or name + * @param username the username + * @return the dataset + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getDataset(java.lang.String, java.lang.String) */ @@ -289,7 +326,27 @@ public class DataCatalogueImpl implements DataCatalogue { return null; } + + /** + * Gets the catalogue content moderator system + * + * @return the catalogue content moderator + */ + public CatalogueContentModeratorSystem getCatalogueContentModerator() { + if(dataCatalogueCMSImpl==null) { + dataCatalogueCMSImpl = new DataCatalogueCMSImpl(); + } + + return dataCatalogueCMSImpl; + } + + /** + * Gets the unencrypted url from dataset id or name. + * + * @param datasetIdOrName the dataset id or name + * @return the unencrypted url from dataset id or name + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getUnencryptedUrlFromDatasetIdOrName(java.lang.String) */ @@ -324,6 +381,12 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Gets the user role by group. + * + * @param username the username + * @return the user role by group + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getUserRoleByGroup(java.lang.String) */ @@ -358,6 +421,12 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Gets the user role by organization. + * + * @param username the username + * @return the user role by organization + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getUserRoleByOrganization(java.lang.String) */ @@ -432,6 +501,12 @@ public class DataCatalogueImpl implements DataCatalogue { return toReturn; } + /** + * Gets the landing pages. + * + * @return the landing pages + * @throws Exception the exception + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getLandingPages() */ @@ -446,6 +521,11 @@ public class DataCatalogueImpl implements DataCatalogue { return landingPages; } + /** + * Gets the uri resolver url. + * + * @return the uri resolver url + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getUriResolverUrl() */ @@ -464,6 +544,12 @@ public class DataCatalogueImpl implements DataCatalogue { return MANAGE_PRODUCT_BUTTON; } + /** + * Gets the group by name. + * + * @param name the name + * @return the group by name + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getGroupByName(java.lang.String) */ @@ -478,6 +564,11 @@ public class DataCatalogueImpl implements DataCatalogue { return null; } + /** + * Checks if is notification to users enabled. + * + * @return true, if is notification to users enabled + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#isNotificationToUsersEnabled() */ @@ -487,6 +578,12 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Gets the organizations by user. + * + * @param username the username + * @return the organizations by user + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getOrganizationsByUser(java.lang.String) */ @@ -518,6 +615,12 @@ public class DataCatalogueImpl implements DataCatalogue { return toReturn; } + /** + * Gets the groups by user. + * + * @param username the username + * @return the groups by user + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getGroupsByUser(java.lang.String) */ @@ -548,6 +651,11 @@ public class DataCatalogueImpl implements DataCatalogue { return toReturn; } + /** + * Gets the organizations ids. + * + * @return the organizations ids + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getOrganizationsIds() */ @@ -565,6 +673,11 @@ public class DataCatalogueImpl implements DataCatalogue { return toReturn; } + /** + * Gets the organizations names. + * + * @return the organizations names + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getOrganizationsNames() */ @@ -582,6 +695,12 @@ public class DataCatalogueImpl implements DataCatalogue { return toReturn; } + /** + * Gets the organizations names by user. + * + * @param username the username + * @return the organizations names by user + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getOrganizationsNamesByUser(java.lang.String) */ @@ -607,6 +726,13 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Gets the role of user in organization. + * + * @param username the username + * @param orgName the org name + * @return the role of user in organization + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getRoleOfUserInOrganization(java.lang.String, java.lang.String) */ @@ -695,6 +821,12 @@ public class DataCatalogueImpl implements DataCatalogue { return null; } + /** + * Exist product with name or id. + * + * @param nameOrId the name or id + * @return true, if successful + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#existProductWithNameOrId(java.lang.String) */ @@ -714,6 +846,12 @@ public class DataCatalogueImpl implements DataCatalogue { } } + /** + * Gets the organization by id or name. + * + * @param idOrName the id or name + * @return the organization by id or name + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getOrganizationByIdOrName(java.lang.String) */ @@ -792,6 +930,13 @@ public class DataCatalogueImpl implements DataCatalogue { + /** + * Gets the parent groups. + * + * @param groupName the group name + * @param apiKey the api key + * @return the parent groups + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getParentGroups(java.lang.String, java.lang.String) */ @@ -811,6 +956,12 @@ public class DataCatalogueImpl implements DataCatalogue { return null; } + /** + * Gets the organization by name. + * + * @param name the name + * @return the organization by name + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getOrganizationByName(java.lang.String) */ @@ -908,6 +1059,14 @@ public class DataCatalogueImpl implements DataCatalogue { return false; } + /** + * Check role into group. + * + * @param username the username + * @param groupName the group name + * @param correspondentRoleToCheck the correspondent role to check + * @return true, if successful + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#checkRoleIntoGroup(java.lang.String, java.lang.String, org.gcube.datacatalogue.utillibrary.shared.RolesCkanGroupOrOrg) */ @@ -966,6 +1125,29 @@ public class DataCatalogueImpl implements DataCatalogue { return false; } + /** + * Creates the 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 + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#createCkanDatasetMultipleCustomFields(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, long, java.lang.String, java.lang.String, java.util.List, java.util.Map, java.util.List, boolean, boolean, boolean) */ @@ -1019,6 +1201,14 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Patch fields for dataset. + * + * @param datasetIdOrName the dataset id or name + * @param mapFields the map fields + * @return true, if successful + * @throws Exception the exception + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#patchFieldsForDataset(java.lang.String, java.util.Map) */ @@ -1052,6 +1242,14 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Sets the searchable field for dataset. + * + * @param datasetId the dataset id + * @param searchable the searchable + * @return true, if successful + * @throws Exception the exception + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#setSearchableFieldForDataset(java.lang.String, boolean) */ @@ -1079,6 +1277,15 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Adds the resource to dataset. + * + * @param resourceBean the resource bean + * @param organizationName the organization name + * @param username the username + * @return the string + * @throws Exception the exception + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#addResourceToDataset(org.gcube.datacatalogue.utillibrary.shared.ResourceBean) */ @@ -1132,6 +1339,14 @@ public class DataCatalogueImpl implements DataCatalogue { return null; } + /** + * Delete resource from dataset. + * + * @param resourceId the resource id + * @param username the username + * @return true, if successful + * @throws Exception the exception + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#deleteResourceFromDataset(java.lang.String) */ @@ -1168,6 +1383,15 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Creates the group. + * + * @param name the name + * @param title the title + * @param description the description + * @return the ckan group + * @throws Exception the exception + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#createGroup(java.lang.String, java.lang.String, java.lang.String) */ @@ -1207,6 +1431,12 @@ public class DataCatalogueImpl implements DataCatalogue { } + /** + * Gets the roles and users group. + * + * @param groupName the group name + * @return the roles and users group + */ /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#getRolesAndUsersGroup(java.lang.String) */ @@ -1245,6 +1475,13 @@ public class DataCatalogueImpl implements DataCatalogue { /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#assignDatasetToGroup(java.lang.String, java.lang.String) */ + /** + * Assign dataset to group. + * + * @param groupNameOrId the group name or id + * @param datasetNameOrId the dataset name or id + * @return true, if successful + */ //TODO HAS TO BE REVISITED by gCAT @Override public boolean assignDatasetToGroup(String groupNameOrId, String datasetNameOrId) { @@ -1255,6 +1492,15 @@ public class DataCatalogueImpl implements DataCatalogue { /* (non-Javadoc) * @see org.gcube.datacatalogue.utillibrary.server.DataCatalogue#patchProductCustomFields(java.lang.String, java.lang.String, java.util.Map, boolean) */ + /** + * Patch product custom fields. + * + * @param productId the product id + * @param username the username + * @param customFieldsToChange the custom fields to change + * @param removeOld the remove old + * @return true, if successful + */ //TODO HAS TO BE REVISITED by gCAT @Override public boolean patchProductCustomFields(String productId, String username, diff --git a/src/main/java/org/gcube/datacatalogue/utillibrary/server/cms/CatalogueContentModeratorSystem.java b/src/main/java/org/gcube/datacatalogue/utillibrary/server/cms/CatalogueContentModeratorSystem.java new file mode 100644 index 0000000..c27f4b7 --- /dev/null +++ b/src/main/java/org/gcube/datacatalogue/utillibrary/server/cms/CatalogueContentModeratorSystem.java @@ -0,0 +1,81 @@ +package org.gcube.datacatalogue.utillibrary.server.cms; + +import java.net.MalformedURLException; +import java.util.List; + +import javax.ws.rs.WebApplicationException; + +import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset; +import org.json.JSONException; + +/** + * The Interface CatalogueContentModeratorSystem. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 14, 2021 + */ +public interface CatalogueContentModeratorSystem { + + /** + * Checks if is content moderator enabled. + * + * @return true, if is content moderator enabled + */ + boolean isContentModeratorEnabled(); + + /** + * Sets the status. + * + * @param itemId the item id + * @param theStatus the the status + */ + void setStatus(String itemId, ItemStatus theStatus); + + /** + * Gets the list items for status. + * + * @param theStatus the the status + * @param limit the limit + * @param offset the offset + * @return the list items for status + * @throws WebApplicationException the web application exception + * @throws MalformedURLException the malformed URL exception + * @throws JSONException the JSON exception + */ + public List getListItemsForStatus(ItemStatus theStatus, int limit, int offset) + throws WebApplicationException, MalformedURLException, JSONException; + + /** + * Approve item. + * + * @param itemId the item id + */ + void approveItem(String itemId); + + /** + * Reject item. + * + * @param itemId the item id + * @param permanentlyDelete the permanently delete + * @param reasonMsg the reason msg + */ + void rejectItem(String itemId, boolean permanentlyDelete, String reasonMsg); + + /** + * Permanently delete. + * + * @param itemId the item id + */ + void permanentlyDelete(String itemId); + + + /** + * Count list items for status. + * + * @param theStatus the the status + * @return the long + */ + long countListItemsForStatus(ItemStatus theStatus); + +} diff --git a/src/main/java/org/gcube/datacatalogue/utillibrary/server/cms/DataCatalogueCMSImpl.java b/src/main/java/org/gcube/datacatalogue/utillibrary/server/cms/DataCatalogueCMSImpl.java new file mode 100644 index 0000000..0fd7ca9 --- /dev/null +++ b/src/main/java/org/gcube/datacatalogue/utillibrary/server/cms/DataCatalogueCMSImpl.java @@ -0,0 +1,199 @@ +package org.gcube.datacatalogue.utillibrary.server.cms; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.WebApplicationException; + +import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject; +import org.gcube.datacatalogue.utillibrary.ckan.MarshUnmarshCkanObject.METHOD; +import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset; +import org.gcube.gcat.client.Item; +import org.json.JSONArray; +import org.json.JSONException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +// TODO: Auto-generated Javadoc +/** + * The Class DataCatalogueCMSImpl. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 14, 2021 + */ +public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem { + + private static final Logger LOG = LoggerFactory.getLogger(DataCatalogueCMSImpl.class); + + /** + * Instantiates a new data catalogue CMS impl. + */ + public DataCatalogueCMSImpl() { + + } + + /** + * Checks if is content moderator enabled. + * + * @return true, if is content moderator enabled + */ + @Override + public boolean isContentModeratorEnabled() { + // TODO Auto-generated method stub + return false; + } + + /** + * Sets the status. + * + * @param itemId the item id + * @param theStatus the the status + */ + @Override + public void setStatus(String itemId, ItemStatus theStatus) { + // TODO Auto-generated method stub + + } + + /** + * Gets the list items for status. + * + * @param theStatus the the status + * @param limit the limit + * @param offset the offset + * @return the list items for status + * @throws WebApplicationException the web application exception + * @throws MalformedURLException the malformed URL exception + * @throws JSONException + */ + @Override + public List getListItemsForStatus(ItemStatus theStatus, int limit, int offset) + throws WebApplicationException, MalformedURLException, JSONException { + LOG.info("called getListItemsForStatus with [status: " + theStatus + "], [limit: " + limit + "], [offset: " + + offset + "]"); + List listDataset = null; + checkNotNull(theStatus); + JSONArray jsonArray = getSourceArrayOfItemsForStatus(theStatus, limit, offset); + + if (jsonArray != null) { + int size = jsonArray.length(); + listDataset = new ArrayList(size); + LOG.debug("converting " + size + " dataset..."); + for (int i = 0; i < size; i++) { + String datasetName = null; + try { + datasetName = jsonArray.getString(i); + LOG.trace("reading dataset: " + datasetName); + String jsonValueDataset = new Item().read(datasetName); + CkanDataset toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonValueDataset, + METHOD.TO_READ); + LOG.trace("converted as dataset: " + toCkanDataset); + listDataset.add(toCkanDataset); + } catch (JSONException | IOException e) { + LOG.warn("Error on reading/converting the dataset name: " + datasetName, e); + } + } + } + + + if (listDataset == null) { + LOG.info("no dataset returned with status: " + theStatus); + return listDataset; + } + + LOG.info("returning listDataset with size: " + listDataset.size()); + return listDataset; + } + + /** + * Gets the source array of items for status read by gCatClient. + * + * @param theStatus the the status + * @param limit the limit + * @param offset the offset + * @return the source array of items for status + * @throws WebApplicationException the web application exception + * @throws MalformedURLException the malformed URL exception + * @throws JSONException the JSON exception + */ + protected JSONArray getSourceArrayOfItemsForStatus(ItemStatus theStatus, int limit, int offset) + throws WebApplicationException, MalformedURLException, JSONException { + LOG.info("called getSourceArrayOfItemsForStatus with [status: " + theStatus + "], [limit: " + limit + + "], [offset: " + offset + "]"); + checkNotNull(theStatus); + // TODO MUST BE CHANGED FOR THE STATUS + JSONArray jsonArray = null; + String datasetNames = new Item().list(limit, offset); + if (datasetNames != null) { + LOG.debug("for status " + theStatus + " found dataset: " + datasetNames); + jsonArray = new JSONArray(datasetNames); + } + + return jsonArray; + + } + + /** + * Count list items for status. + * + * @param theStatus the the status + * @return the long + */ + @Override + public long countListItemsForStatus(ItemStatus theStatus) { + LOG.info("called countListItemsForStatus with [status: " + theStatus + "]"); + checkNotNull(theStatus); + int count = 0; + try { + // TODO MUST BE CHANGED FOR THE STATUS + count = new Item().count(); + } catch (Exception e) { + LOG.error("Error on couting list items for status "+theStatus, e); + return -1; + } + + return count; + + } + + /** + * Approve item. + * + * @param itemId the item id + */ + @Override + public void approveItem(String itemId) { + // TODO Auto-generated method stub + + } + + /** + * Reject item. + * + * @param itemId the item id + * @param permanentlyDelete the permanently delete + * @param reasonMsg the reason msg + */ + @Override + public void rejectItem(String itemId, boolean permanentlyDelete, String reasonMsg) { + // TODO Auto-generated method stub + + } + + /** + * Permanently delete. + * + * @param itemId the item id + */ + @Override + public void permanentlyDelete(String itemId) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/java/org/gcube/datacatalogue/utillibrary/server/cms/ItemStatus.java b/src/main/java/org/gcube/datacatalogue/utillibrary/server/cms/ItemStatus.java new file mode 100644 index 0000000..67d9759 --- /dev/null +++ b/src/main/java/org/gcube/datacatalogue/utillibrary/server/cms/ItemStatus.java @@ -0,0 +1,45 @@ +package org.gcube.datacatalogue.utillibrary.server.cms; + +/** + * The Enum ItemStatus. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 7, 2021 + */ +public enum ItemStatus { + PENDING("pending", "Pending"), APPROVED("approved", "Approved"), REJECTED("rejected", "Rejected"); + + private String id; + private String label; + + /** + * Instantiates a new item status. + * + * @param id the id + * @param label the label + */ + private ItemStatus(String id, String label) { + this.id = id; + this.label = label; + } + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Gets the label. + * + * @return the label + */ + public String getLabel() { + return label; + } + +} \ No newline at end of file diff --git a/src/test/java/org/gcube/datacatalogue/utillibrary/test/TestDataCatalogueCMS.java b/src/test/java/org/gcube/datacatalogue/utillibrary/test/TestDataCatalogueCMS.java new file mode 100644 index 0000000..977d386 --- /dev/null +++ b/src/test/java/org/gcube/datacatalogue/utillibrary/test/TestDataCatalogueCMS.java @@ -0,0 +1,107 @@ +package org.gcube.datacatalogue.utillibrary.test; + +import java.util.List; + +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory; +import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl; +import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorSystem; +import org.gcube.datacatalogue.utillibrary.server.cms.ItemStatus; +import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset; +import org.junit.Test; +import org.slf4j.LoggerFactory; + +/** + * The Class TestDataCatalogueLib. + * + * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Jun 1, 2020 + */ +public class TestDataCatalogueCMS { + + 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 = "8e74a17c-92f1-405a-b591-3a6090066248-98187548"; + + /** + * Before. + * + * @throws Exception the exception + */ + // @Before + public void before() throws Exception { + factory = DataCatalogueFactory.getFactory(); + } + + /** + * Factory test. + * + * @throws Exception the exception + */ + // @Test + public void contentModeratorTest() throws Exception { + 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"); + } + + /** + * Gets the scope per url. + * + * @return the scope per url + * @throws Exception + */ + //@Test + public void getListItemsForStatus() throws Exception { + + try { + 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"); + + List listDatasets = cCMS.getListItemsForStatus(ItemStatus.PENDING, 20, 0); + + for (CkanDataset ckanDataset : listDatasets) { + LOG.debug("CkanDataset read: " + ckanDataset); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Gets the scope per url. + * + * @return the scope per url + * @throws Exception + */ + //@Test + public void getSizeOfListItemsForStatus() throws Exception { + + try { + ItemStatus theStatus = ItemStatus.PENDING; + 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"); + + long size = cCMS.countListItemsForStatus(theStatus); + LOG.debug("Size of list of items for status "+theStatus + " is: "+ size); + } catch (Exception e) { + e.printStackTrace(); + } + } + + +} \ No newline at end of file