added two methods needed to Catalogue Portlet

This commit is contained in:
Francesco Mangiacrapa 2021-02-12 15:38:11 +01:00
parent 331f1e2a9f
commit 1e342b33f3
2 changed files with 166 additions and 26 deletions

View File

@ -11,10 +11,13 @@ import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanGroup;
import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanLicense;
import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanOrganization;
/**
* The Interface DataCatalogue.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Jun 1, 2020
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Feb 12, 2021
*/
public interface DataCatalogue {
@ -168,6 +171,14 @@ public interface DataCatalogue {
*/
List<String> getOrganizationsNamesByUser(String username);
/**
* Returns a group given its name.
*
* @param nameOrId the name or id
* @return return a {@link CkanGroup} or null if no group with this name exists
*/
CkanGroup getGroupByName(String nameOrId);
/**
* Given the username and the organization name the method retrieves the role of
* the user (i.e. his/her 'capacity')
@ -189,10 +200,10 @@ public interface DataCatalogue {
/**
* Check if this role is present for this user in the organization. If he/she is
* not present we need to add it with the given role.
*
* @param username
* @param organizationName
* @param correspondentRoleToCheck
*
* @param username the username
* @param organizationName the organization name
* @param correspondentRoleToCheck the correspondent role to check
* @return true if the role can be set, false if it cannot
*/
boolean checkRoleIntoOrganization(String username, String organizationName,
@ -201,10 +212,10 @@ public interface DataCatalogue {
/**
* Check if this role is present for this user in the group. If he/she is not
* present we need to add it with the given role.
*
* @param username
* @param organizationName
* @param correspondentRoleToCheck
*
* @param username the username
* @param groupName the group name
* @param correspondentRoleToCheck the correspondent role to check
* @return true if the role can be set, false if it cannot
*/
boolean checkRoleIntoGroup(String username, String groupName, RolesCkanGroupOrOrg correspondentRoleToCheck);
@ -221,40 +232,73 @@ public interface DataCatalogue {
/**
* Returns a Map with key 'capacity' and as value a list of users with that
* capacity into the group groupNameOrTitle.
*
* @return
*
* @param groupNameOrTitle the group name or title
* @return the roles and users group
*/
Map<RolesCkanGroupOrOrg, List<String>> getRolesAndUsersGroup(String groupNameOrTitle);
/**
* Get the parent groups of this group
*
* Get the parent groups of this group.
*
* @param groupName the group name
* @param apiKey the api key
* @return the group parent, if any
*/
List<CkanGroup> getParentGroups(String groupName, String apiKey);
/**
* Retrieve the organization with this name
* Retrieve the organization with this name.
*
* @param name the name
* @return the organization by name
*/
CkanOrganization getOrganizationByName(String name);
/**
*****************************************************************************
* Check if the users of the current context need to be alerted from a post
* creation or not. Default is false.
*
* @return a boolean value
*/
boolean isNotificationToUsersEnabled();
/**
* ***************************************************************************
*
*
* WRITE OPERATIONS
*
*
*
*****************************************************************************
*
*
*
* /** Create a dataset with those information. The method allows to have
* multiple values for the same custom field key. NOTE: unfortunately java
* doesn't support overload in java interface methods (that's way I cannot use
* the same name for the method)
* ***************************************************************************.
*
* @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
*/
/**
* Create a dataset with those information. The method allows to have multiple
* values for the same custom field key. NOTE: unfortunately java doesn't
* support overload in java interface methods (that's way I cannot use the same
* name for the method)
*
* @param username the username
* @param title the title
@ -338,7 +382,7 @@ public interface DataCatalogue {
boolean setSearchableFieldForDataset(String datasetId, boolean searchable) throws Exception;
/**
* Patch the fields for dataset passed
* Patch the fields for dataset passed.
*
* @param datasetId the dataset id
* @param mapFields the map fields
@ -356,4 +400,29 @@ public interface DataCatalogue {
*/
boolean assignDatasetToGroup(String groupNameOrId, String datasetNameOrId);
/**
* ********************************************************************************
*
*
* MANAGEMENT OPERATIONS
*
*
* ********************************************************************************.
*
* @param username the username
* @param sourceOrganization the source organization
* @param currentRole the current role
*/
/**
* Check if the user identified by username has to be registered in other
* organizations with some role.
*
* @param username
* @param sourceOrganization
* @param currentRole
*/
void assignRolesOtherOrganization(String username, String sourceOrganization, RolesCkanGroupOrOrg currentRole);
}

View File

@ -12,6 +12,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -442,6 +443,23 @@ public class DataCatalogueImpl implements DataCatalogue {
return MANAGE_PRODUCT_BUTTON;
}
@Override
public CkanGroup getGroupByName(String name) {
String ckanName = CatalogueUtilMethods.fromGroupTitleToName(name);
try{
return ckanCaller.getGroup(ckanName);
}catch(Exception e){
LOG.error("Failed to retrieve the group with name" + name, e);
}
return null;
}
@Override
public boolean isNotificationToUsersEnabled() {
return ALERT_USERS_ON_POST_CREATION;
}
@Override
public List<CkanOrganization> getOrganizationsByUser(String username) {
@ -1293,5 +1311,58 @@ public class DataCatalogueImpl implements DataCatalogue {
}
}
/*******************************************************************************
*
*
* MANAGEMENT OPERATIONS
*
*
*******************************************************************************/
@Override
public void assignRolesOtherOrganization(String username,
String sourceOrganization, RolesCkanGroupOrOrg currentRole) {
checkNotNull(username);
checkNotNull(sourceOrganization);
checkNotNull(currentRole);
LOG.info("Request for assigning other roles for user " + username + ", whose current role is " + currentRole + " and organization " + sourceOrganization);
Iterator<Entry<String, String>> iterator = extendRoleInOrganization.entrySet().iterator();
LOG.debug("List of entries to check is " + extendRoleInOrganization);
while (iterator.hasNext()) {
Map.Entry<java.lang.String, java.lang.String> entry = iterator
.next();
String sourceOrg = entry.getKey();
LOG.debug("Found organization source " + sourceOrg);
if(sourceOrg.equals(sourceOrganization)){
String[] values = entry.getValue().split(DataCatalogueRunningCluster.TUPLES_SEPARATOR);
for(int i = 0; i < values.length; i++){
String destOrg = values[i].split("\\"+DataCatalogueRunningCluster.ROLE_ORGANIZATION_SEPARATOR)[0];
String role = values[i].split("\\"+DataCatalogueRunningCluster.ROLE_ORGANIZATION_SEPARATOR)[1];
LOG.debug("Role is " + role + " and organization is " + destOrg);
RolesCkanGroupOrOrg ckanRole;
if(role.equals(DataCatalogueRunningCluster.CKAN_GENERIC_ROLE))
ckanRole = currentRole;
else
ckanRole = RolesCkanGroupOrOrg.convertFromCapacity(role);
LOG.info("Checking for extra role: role is " + ckanRole + " and organization is " + destOrg);
checkRoleIntoOrganization(username, destOrg, ckanRole);
}
}
}
}
}