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

61 lines
1.7 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;
/**
* @param groupTitle
* @param datasetId
* @param username
* @param catalogue
*/
public AssociationToGroupThread(List<String> groupsTitles, String datasetId,
String username, DataCatalogue catalogue) {
this.groupsTitles = groupsTitles;
this.datasetId = datasetId;
this.username = username;
this.catalogue = catalogue;
}
@Override
public void run() {
logger.info("Association thread started to put the dataset with id="+ datasetId + " into group with title(s) " + groupsTitles + " for user " + username);
for (String groupTitle : groupsTitles) {
// check the user has enough privileges to associate it
if(catalogue.checkRoleIntoGroup(username, groupTitle, RolesCkanGroupOrOrg.MEMBER)){
logger.warn("The user " + username + " has not enough privileges to associate the dataset into group " + groupTitle);
continue;
}
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, catalogue.getApiKeyFromUsername(username));
logger.info("Was product put into group? " + putIntoGroup);
}
}
}