added refresh dataset. refactored method
This commit is contained in:
parent
3904cb48e0
commit
5e54cfde38
|
@ -59,8 +59,8 @@ public class GCatCaller {
|
|||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String getDatasetForName(String datasetName) throws WebApplicationException, MalformedURLException {
|
||||
LOG.debug("GetDatasetForName called");
|
||||
LOG.info("Get dataset for name " + datasetName + "called");
|
||||
LOG.debug("getDatasetForName called");
|
||||
LOG.info("Get dataset for name '" + datasetName + "' called");
|
||||
return new Item().read(datasetName);
|
||||
}
|
||||
|
||||
|
@ -75,11 +75,27 @@ public class GCatCaller {
|
|||
*/
|
||||
public String createDataset(String jsonDataset, boolean socialPost)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
LOG.debug("Create dataset called");
|
||||
LOG.trace("createDataset called");
|
||||
LOG.info("Calling create on: " + jsonDataset);
|
||||
return new Item().create(jsonDataset, socialPost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update dataset.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @param jsonDataset the json dataset
|
||||
* @return the string
|
||||
* @throws WebApplicationException the web application exception
|
||||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String updateDataset(String datasetName, String jsonDataset)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
LOG.trace("updateDataset called");
|
||||
LOG.info("Calling update item with name: " + datasetName + ", on: " + jsonDataset);
|
||||
return new Item().update(datasetName, jsonDataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the resource to dataset.
|
||||
*
|
||||
|
@ -89,7 +105,7 @@ public class GCatCaller {
|
|||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String addResourceToDataset(String datasetId, String jsonValueResource) throws MalformedURLException {
|
||||
LOG.debug("Create resource called");
|
||||
LOG.trace("addResourceToDataset called");
|
||||
LOG.info("Calling create resource: " + jsonValueResource + " for dataset id: " + datasetId);
|
||||
return new Resource().create(datasetId, jsonValueResource);
|
||||
}
|
||||
|
@ -102,7 +118,7 @@ public class GCatCaller {
|
|||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public void deleteResource(String datasetId, String resourceId) throws MalformedURLException {
|
||||
LOG.debug("Delete resource called");
|
||||
LOG.trace("deleteResource called");
|
||||
LOG.info("Calling delete resource with: " + resourceId + " for dataset id: " + datasetId);
|
||||
new Resource().delete(datasetId, resourceId);
|
||||
}
|
||||
|
@ -115,7 +131,7 @@ public class GCatCaller {
|
|||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String createGroup(String jsonGroup) throws MalformedURLException {
|
||||
LOG.debug("Create group called");
|
||||
LOG.trace("createGroup called");
|
||||
LOG.info("Calling create group: " + jsonGroup);
|
||||
return new Group().create(jsonGroup);
|
||||
}
|
||||
|
@ -131,7 +147,7 @@ public class GCatCaller {
|
|||
*/
|
||||
public String patchDataset(String datasetName, JSONObject jsonObj)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
LOG.debug("Patch dataset called");
|
||||
LOG.trace("patchDataset called");
|
||||
LOG.info("Calling patch dataset with name: " + datasetName);
|
||||
|
||||
return new Item().patch(datasetName, jsonObj.toJSONString());
|
||||
|
@ -149,7 +165,7 @@ public class GCatCaller {
|
|||
*/
|
||||
public String approveItem(String datasetName, String moderatorMessage)
|
||||
throws WebApplicationException, MalformedURLException {
|
||||
LOG.debug("Approve item called");
|
||||
LOG.trace("approveItem called");
|
||||
LOG.info("Calling approve item with name: " + datasetName + ", and msg: " + moderatorMessage);
|
||||
|
||||
return new Item().approve(datasetName, moderatorMessage);
|
||||
|
@ -168,7 +184,7 @@ public class GCatCaller {
|
|||
*/
|
||||
public String rejectItem(String datasetName, boolean permanentlyDelete, String moderatorMessage)
|
||||
throws WebServiceException, MalformedURLException {
|
||||
LOG.debug("Reject item called");
|
||||
LOG.trace("rejectItem called");
|
||||
LOG.info("Calling reject item with name: " + datasetName + ", and msg: " + moderatorMessage);
|
||||
|
||||
String toReturnMsg = new Item().reject(datasetName, moderatorMessage);
|
||||
|
@ -189,14 +205,13 @@ public class GCatCaller {
|
|||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public void deleteItem(String datasetName, boolean purge) throws WebServiceException, MalformedURLException {
|
||||
LOG.debug("Delete item called");
|
||||
LOG.trace("deleteItem called");
|
||||
LOG.info("Calling delete item with name: " + datasetName + ", and purge: " + purge);
|
||||
|
||||
new Item().delete(datasetName, purge);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list items for CM status.
|
||||
*
|
||||
|
@ -209,7 +224,7 @@ public class GCatCaller {
|
|||
*/
|
||||
public String getListItemsForCMStatus(CMItemStatus status, int limit, int offset)
|
||||
throws WebServiceException, MalformedURLException {
|
||||
LOG.debug("getListItemsForStatus called");
|
||||
LOG.trace("getListItemsForCMStatus called");
|
||||
LOG.info("Calling list items for status: " + status);
|
||||
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
|
@ -238,7 +253,7 @@ public class GCatCaller {
|
|||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public int countListItemsForCMStatus(CMItemStatus status) throws WebServiceException, MalformedURLException {
|
||||
LOG.debug("countListItemsForCMStatus called");
|
||||
LOG.trace("countListItemsForCMStatus called");
|
||||
LOG.info("Calling coun list items for status: " + status);
|
||||
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
|
@ -267,7 +282,7 @@ public class GCatCaller {
|
|||
* @throws MalformedURLException the malformed URL exception
|
||||
*/
|
||||
public String getListItems(int limit, int offset) throws WebServiceException, MalformedURLException {
|
||||
LOG.debug("getListItems called");
|
||||
LOG.trace("getListItems called");
|
||||
LOG.info("Calling list items with limit: " + limit + ", offset: " + offset);
|
||||
|
||||
return new Item().list(limit, offset);
|
||||
|
@ -283,13 +298,12 @@ public class GCatCaller {
|
|||
*/
|
||||
public String getListItemsForQuery(Map<String, String> queryParams)
|
||||
throws WebServiceException, MalformedURLException {
|
||||
LOG.debug("getListItems forQuery called");
|
||||
LOG.trace("getListItemsForQuery called");
|
||||
LOG.info("Calling list items for query: " + queryParams);
|
||||
|
||||
return new Item().list(queryParams);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the configuration.
|
||||
*
|
||||
|
@ -297,15 +311,15 @@ public class GCatCaller {
|
|||
* @return the configuration
|
||||
*/
|
||||
public Configuration getConfiguration(boolean reload) {
|
||||
LOG.debug("getConfiguration called");
|
||||
LOG.trace("getConfiguration called");
|
||||
LOG.info("Calling get configuration");
|
||||
|
||||
if(reload || serviceConfiguration==null) {
|
||||
//Must be loa
|
||||
|
||||
if (reload || serviceConfiguration == null) {
|
||||
// Must be loa
|
||||
LOG.warn("\n\n\nI'M USING A MOCK CONFIGURATION\n\n\n\n");
|
||||
serviceConfiguration = new Configuration();
|
||||
}
|
||||
|
||||
|
||||
return serviceConfiguration;
|
||||
}
|
||||
|
||||
|
|
|
@ -410,6 +410,15 @@ public interface DataCatalogue {
|
|||
boolean patchProductCustomFields(String productId, String username, Map<String, List<String>> customFieldsToChange,
|
||||
boolean removeOld);
|
||||
|
||||
/**
|
||||
* Refresh dataset.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @return the string
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
String refreshDataset(String datasetName) throws Exception;
|
||||
|
||||
/**
|
||||
* Patch a product with product id productId by using the couples in
|
||||
* customFieldsToChange. NOTE: only the specified custom fields will be changed.
|
||||
|
@ -449,6 +458,4 @@ public interface DataCatalogue {
|
|||
*/
|
||||
void assignRolesOtherOrganization(String username, String sourceOrganization, RolesCkanGroupOrOrg currentRole);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -578,8 +578,8 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
LOG.info("Called isModerationEnabled with reloadConfig: " + reloadConfig);
|
||||
Configuration config = gCatCaller.getConfiguration(reloadConfig);
|
||||
return config.isModerationEnabled();
|
||||
}catch (Exception e) {
|
||||
LOG.error("Error occurred on checking if moderation is enabled. Returning false",e);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error occurred on checking if moderation is enabled. Returning false", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1258,7 +1258,7 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
GcubeContext gcubeContext = null;
|
||||
try {
|
||||
|
||||
gcubeContext = GCubeUtils.detectTheOrgNameContexts(organizationName, username, true);
|
||||
gcubeContext = GCubeUtils.detectAndSetTheOrgNameContext(organizationName, username, true);
|
||||
|
||||
String toPassOrganizationToGcat = null; // Not needed to pass this information to gCat, never.
|
||||
// String ckanUsername = getUserFromApiKey(apiKey).getName();
|
||||
|
@ -1291,6 +1291,46 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh dataset.
|
||||
*
|
||||
* @param datasetName the dataset name
|
||||
* @return the string
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public String refreshDataset(String datasetName) throws Exception {
|
||||
LOG.info("Called refreshDataset");
|
||||
|
||||
checkNotNull(datasetName);
|
||||
GcubeContext gcubeContext = null;
|
||||
try {
|
||||
|
||||
// is required?
|
||||
// gcubeContext = GCubeUtils.detectAndSetTheOrgNameContext(organizationName,
|
||||
// username, true);
|
||||
|
||||
String jsonDataset = gCatCaller.getDatasetForName(datasetName);
|
||||
jsonDataset = gCatCaller.updateDataset(datasetName, jsonDataset);
|
||||
LOG.debug("Updated dataset is: " + jsonDataset);
|
||||
|
||||
if (jsonDataset != null) {
|
||||
CkanDataset toCkanDataset = MarshUnmarshCkanObject.toCkanDataset(jsonDataset, METHOD.TO_READ);
|
||||
LOG.info("Dataset with name " + toCkanDataset.getName() + " has been updated correctly");
|
||||
return toCkanDataset.getId();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error on updatating the dataset: ", e);
|
||||
throw e;
|
||||
} finally {
|
||||
|
||||
if (gcubeContext != null)
|
||||
GCubeUtils.revertToSourceContext(gcubeContext);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch fields for dataset.
|
||||
*
|
||||
|
@ -1413,7 +1453,7 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
try {
|
||||
|
||||
// Switch the context if needed
|
||||
gcubeContext = GCubeUtils.detectTheOrgNameContexts(organizationName, username, true);
|
||||
gcubeContext = GCubeUtils.detectAndSetTheOrgNameContext(organizationName, username, true);
|
||||
|
||||
CkanResource resource = CKANConveter.toCkanResource(CKAN_CATALOGUE_URL, resourceBean);
|
||||
|
||||
|
@ -1469,7 +1509,8 @@ public class DataCatalogueImpl implements DataCatalogue {
|
|||
CkanDataset theDataset = getDataset(theResource.getPackageId(), username);
|
||||
|
||||
// Switch the context if needed
|
||||
gcubeContext = GCubeUtils.detectTheOrgNameContexts(theDataset.getOrganization().getName(), username, true);
|
||||
gcubeContext = GCubeUtils.detectAndSetTheOrgNameContext(theDataset.getOrganization().getName(), username,
|
||||
true);
|
||||
|
||||
gCatCaller.deleteResource(theResource.getPackageId(), resourceId);
|
||||
LOG.info("Resource with id: " + resourceId + " deleted correclty");
|
||||
|
|
|
@ -208,13 +208,17 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
|
|||
// TODO MUST BE CHANGED FOR THE STATUS
|
||||
org.json.simple.JSONArray jsonArray = null;
|
||||
|
||||
String datasetNames = null;
|
||||
/*String datasetNames = null;
|
||||
if(theStatus.equals(ItemStatus.PUBLISHED)) {
|
||||
datasetNames = gCatCaller.getListItems(limit, offset);
|
||||
}else {
|
||||
CMItemStatus cmiStatus = toCMStatus(theStatus);
|
||||
datasetNames = gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset);
|
||||
}
|
||||
}*/
|
||||
|
||||
CMItemStatus cmiStatus = toCMStatus(theStatus);
|
||||
String datasetNames = gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset);
|
||||
|
||||
if (datasetNames != null) {
|
||||
LOG.debug("for status " + theStatus + " found dataset: " + datasetNames);
|
||||
JSONParser parser = new JSONParser();
|
||||
|
|
|
@ -96,15 +96,16 @@ public class GCubeUtils {
|
|||
|
||||
|
||||
/**
|
||||
* Detect the OrgName contexts (token and scope) if the working context (in the thread) is a root VO or VO and switch to it according to setInThread parameters
|
||||
* Detect the organizationName context (token and scope of VRE).
|
||||
* If the working context (in the thread) is a root VO or VO and setInThread is true then switch to VRE context (setting ScopeProvider and SecurityTokenProvider)
|
||||
*
|
||||
* @param organizationName the organization name to switch to
|
||||
* @param username the username
|
||||
* @param setInThread set in the target token (in the {@link SecurityTokenProvider}) and the scope (in the {@link ScopeProvider}) detected for the OrgName
|
||||
* @return the gcube context
|
||||
* @param setInThread if true set the target token (in the {@link SecurityTokenProvider}) and the scope (in the {@link ScopeProvider}) detected for the OrgName
|
||||
* @return the gcube context with source scope/token and target (detected for organizationName) scope/token
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static GcubeContext detectTheOrgNameContexts(String organizationName, String username, boolean setInThread) throws Exception {
|
||||
public static GcubeContext detectAndSetTheOrgNameContext(String organizationName, String username, boolean setInThread) throws Exception {
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
|
|
|
@ -8,10 +8,10 @@ package org.gcube.datacatalogue.utillibrary.shared;
|
|||
* Feb 17, 2022
|
||||
*/
|
||||
public enum ItemStatus {
|
||||
PENDING("pending", "Pending"), APPROVED("approved", "Approved"), REJECTED("rejected", "Rejected"),
|
||||
PENDING("pending", "Pending"), APPROVED("approved", "Approved"), REJECTED("rejected", "Rejected");
|
||||
// Published means that the item is published in the Catalogue, no status is checked,
|
||||
// the "simple" get list of items is called
|
||||
PUBLISHED("published", "Published");
|
||||
//PUBLISHED("published", "Published");
|
||||
|
||||
private String id;
|
||||
private String label;
|
||||
|
|
Loading…
Reference in New Issue