grsf-publisher-ws/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/AssociationToGroupThread.java

67 lines
2.1 KiB
Java

package org.gcube.data_catalogue.grsf_publish_ws.utils;
import java.util.List;
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Associate the dataset to a group.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class AssociationToGroupThread extends Thread {
private static final Logger logger = LoggerFactory.getLogger(AssociationToGroupThread.class);
private List<String> groupsTitles;
private String datasetId;
private String username;
private DataCatalogue catalogue;
private String organization;
/**
* @param groupTitle
* @param datasetId
* @param username
* @param catalogue
*/
public AssociationToGroupThread(List<String> groupsTitles, String datasetId,
String username, DataCatalogue catalogue, String organization) {
this.groupsTitles = groupsTitles;
this.datasetId = datasetId;
this.username = username;
this.catalogue = catalogue;
this.organization = organization;
}
@Override
public void run() {
logger.info("Association thread started to put the dataset with id="+ datasetId + " into group with title " + groupsTitles + " for user " + username);
// create the group
for (String groupTitle : groupsTitles) {
logger.debug("Group exists, going to add the user " + username + " as its admin...");
// retrieve the role to be assigned according the one the user has into the organization of the dataset
RolesCkanGroupOrOrg role = RolesCkanGroupOrOrg.valueOf(catalogue.getRoleOfUserInOrganization(username, organization, catalogue.getApiKeyFromUsername(username)).toUpperCase());
boolean assigned = catalogue.checkRoleIntoGroup(username, groupTitle, role);
if(assigned){
logger.debug("Admin/editor role was assigned for this group, going to associate the product to the group");
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, catalogue.getApiKeyFromUsername(username));
logger.info("Was product put into group? " + putIntoGroup);
}
}
}
}