in progress...

This commit is contained in:
Francesco Mangiacrapa 2024-02-08 17:46:24 +01:00
parent 87a4211301
commit c7f0e908f0
8 changed files with 697 additions and 80 deletions

View File

@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
import java.util.List;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataProfileBeanForUpdate;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.license.LicenseBean;
@ -140,14 +141,24 @@ public interface CKanPublisherService extends RemoteService {
*/
DatasetBean getDatasetBeanForUpdate(String itemID) throws Exception;
/**
* Gets the profile for update.
*
* @param orgName the org name
* @param orgName the org name
* @param datasetType the dataset type
* @param datasedIdOrName the datased id or name
* @return the profile for update
* @throws Exception the exception
*/
List<MetaDataProfileBean> getProfileForUpdate(String orgName, String datasetType, String datasedIdOrName) throws Exception;
MetadataProfileBeanForUpdate getProfileForUpdate(String orgName, String datasetType, String datasedIdOrName) throws Exception;
/**
* Update CKAN dataset.
*
* @param toUpdate the to create
* @return the dataset bean
* @throws Exception the exception
*/
DatasetBean updateCKANDataset(DatasetBean toUpdate) throws Exception;
}

View File

@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
import java.util.List;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataProfileBeanForUpdate;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.license.LicenseBean;
@ -131,7 +132,7 @@ public interface CKanPublisherServiceAsync {
* Checks if is owner or admin user.
*
* @param datasetIdOrName the dataset id or name
* @param callback the callback
* @param callback the callback
* @return true, if is owner or admin user
*/
void isPublisherOwnerOrAdminUser(String datasetIdOrName, AsyncCallback<Boolean> callback);
@ -148,11 +149,21 @@ public interface CKanPublisherServiceAsync {
/**
* Gets the profile for update.
*
* @param orgName the org name
* @param datasetType the dataset type
* @param orgName the org name
* @param datasetType the dataset type
* @param datasedIdOrName the datased id or name
* @param callaback the callaback
* @param callaback the callaback
* @return the profile for update
*/
void getProfileForUpdate(String orgName, String datasetType, String datasedIdOrName, AsyncCallback<List<MetaDataProfileBean>> callaback);
void getProfileForUpdate(String orgName, String datasetType, String datasedIdOrName,
AsyncCallback<MetadataProfileBeanForUpdate> callaback);
/**
* Update CKAN dataset.
*
* @param toUpdate the to update
* @param callaback the callaback
* @throws Exception the exception
*/
void updateCKANDataset(DatasetBean toUpdate, AsyncCallback<DatasetBean> callaback);
}

View File

@ -23,6 +23,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.InfoIc
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.WizardCreator;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace.SelectResourceByWEMainPanel;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataProfileBeanForUpdate;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
import org.gcube.portlets.widgets.mpformbuilder.client.form.MetaDataField;
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION;
@ -126,7 +127,7 @@ public class UpdateDatasetForm extends Composite {
@UiField
Button addCustomFieldButton;
@UiField
Button createButton;
Button updateButton;
@UiField
Button resetButton;
@UiField
@ -273,9 +274,9 @@ public class UpdateDatasetForm extends Composite {
private static final String NONE_PROFILE = "none";
// error/info messages
protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to publish your item.";
protected static final String PRODUCT_CREATED_OK = "Item correctly published!";
private static final String TRYING_TO_CREATE_PRODUCT = "Trying to publish the item, please wait...";
protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to update the item.";
protected static final String PRODUCT_UPDATED_OK = "Item correctly updated!";
private static final String TRYING_TO_UPDATE_PRODUCT = "Trying to update the item, please wait...";
protected static final String MISSING_PUBLISH_RIGHTS = "It seems you are not authorized to edit this item. Either you must be the author item or Catalogue Admininistrator in the organization";
// tab panel
@ -329,7 +330,7 @@ public class UpdateDatasetForm extends Composite {
* @param itemId the item id
*/
public UpdateDatasetForm(HandlerManager eventBus, String itemId) {
createDatasetFormBody(eventBus, itemId, OPERATION.UPDATE);
updateDatasetFormBody(eventBus, itemId, OPERATION.UPDATE);
}
/**
@ -362,7 +363,7 @@ public class UpdateDatasetForm extends Composite {
* @param datasetIdOrName the item id
* @param operation the operation
*/
private void createDatasetFormBody(final HandlerManager eventBus, String datasetIdOrName,
private void updateDatasetFormBody(final HandlerManager eventBus, String datasetIdOrName,
final OPERATION operation) {
initWidget(uiBinder.createAndBindUi(this));
@ -446,12 +447,12 @@ public class UpdateDatasetForm extends Composite {
}
}
// THIS BLOCK is it required? Probably not.
// retrieve custom fields
Map<String, List<String>> customFieldsMap = bean.getCustomFields();
// TODO Check if these tags are ok for the vocabulary
if (customFieldsMap != null && vocabularyTags == null) {
// get the keys and put them as tags
Iterator<Entry<String, List<String>>> iteratorOverCustomField = customFieldsMap
.entrySet().iterator();
@ -474,6 +475,7 @@ public class UpdateDatasetForm extends Composite {
}
}
}
// END BLOCK
// set it as visible anyway
tagsPanel.setVisible(true);
@ -547,7 +549,7 @@ public class UpdateDatasetForm extends Composite {
// perform remote request of profiles for the selected organization
ckanServices.getProfileForUpdate(orgName, bean.getChosenType(), bean.getId(),
new AsyncCallback<List<MetaDataProfileBean>>() {
new AsyncCallback<MetadataProfileBeanForUpdate>() {
@Override
public void onFailure(Throwable caught) {
@ -555,8 +557,13 @@ public class UpdateDatasetForm extends Composite {
}
@Override
public void onSuccess(final List<MetaDataProfileBean> profiles) {
public void onSuccess(
final MetadataProfileBeanForUpdate metadataProfileForUpdate) {
setAlertBlock("", AlertType.ERROR, false);
List<MetaDataProfileBean> profiles = metadataProfileForUpdate
.getListProfileBean();
if (profiles == null) {
setAlertBlock(
"An unknow error occurred while retrieving types, sorry",
@ -573,6 +580,7 @@ public class UpdateDatasetForm extends Composite {
receivedBean.setMetadataList(profiles);
prepareMetadataList(receivedBean, operation);
addCustomField(metadataProfileForUpdate.getCustomFields());
organizationsListbox.setEnabled(true);
metadataTypeListbox.setEnabled(true);
@ -674,12 +682,36 @@ public class UpdateDatasetForm extends Composite {
}
private void addCustomField(Map<String, List<String>> customFieldsMap) {
// TODO Check if these tags are ok for the vocabulary
if (customFieldsMap != null) {
// get the keys and put them as tags
Iterator<Entry<String, List<String>>> iteratorOverCustomField = customFieldsMap.entrySet().iterator();
while (iteratorOverCustomField.hasNext()) {
Map.Entry<java.lang.String, java.util.List<java.lang.String>> entry = iteratorOverCustomField.next();
List<String> values = entry.getValue();
for (String value : values) {
// these are fixed key, variable value custom fields
CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, entry.getKey(), value, false);
customFieldEntriesList.add(toAdd);
customFields.add(toAdd);
}
}
}
}
/**
* When the organization name is changed we need to retrieve the list of
* profiles and groups.
*
* @param operation the operation
*/
//NEVER USED IN UPDATE MODE
private void organizationsListboxChangeHandlerBody(OPERATION operation) {
// remove any other product profiles
@ -799,6 +831,7 @@ public class UpdateDatasetForm extends Composite {
* @param operation the operation
*/
private void prepareMetadataList(final DatasetBean receivedBean, OPERATION operation) {
// the profile should be one
List<MetaDataProfileBean> profiles = receivedBean.getMetadataList();
@ -890,12 +923,6 @@ public class UpdateDatasetForm extends Composite {
if (categories == null || categories.isEmpty()) {
for (MetadataFieldWrapper field : fields) {
/*
* MetaDataFieldSkeleton fieldWidget; try { fieldWidget = new
* MetaDataFieldSkeleton(field, eventBus); metadataFieldsPanel.add(fieldWidget);
* listOfMetadataFields.add(fieldWidget); } catch (Exception e) {
* GWT.log("Unable to build such widget", e); }
*/
MetaDataField fieldWidget;
try {
@ -1151,8 +1178,8 @@ public class UpdateDatasetForm extends Composite {
*
* @param e the e
*/
@UiHandler("createButton")
void createDatasetEvent(ClickEvent e) {
@UiHandler("updateButton")
void updateDatasetEvent(ClickEvent e) {
String errorMessage = areProfileDataValid();
@ -1272,19 +1299,19 @@ public class UpdateDatasetForm extends Composite {
receivedBean.setCustomFields(customFieldsMap);
// alert
alertOnCreate(TRYING_TO_CREATE_PRODUCT, true, AlertType.INFO, false);
alertOnCreate(TRYING_TO_UPDATE_PRODUCT, true, AlertType.INFO, false);
// invoke the create method
createButton.setEnabled(false);
updateButton.setEnabled(false);
goBackButtonSecondStep.setEnabled(false);
ckanServices.createCKanDataset(receivedBean, new AsyncCallback<DatasetBean>() {
ckanServices.updateCKANDataset(receivedBean, new AsyncCallback<DatasetBean>() {
@Override
public void onSuccess(final DatasetBean createdDatasetBean) {
CKanMetadataPublisher.printJs("createCKanDataset returned");
GWT.log("Created the dataset: " + createdDatasetBean);
GWT.log("Updated the dataset: " + createdDatasetBean);
if (createdDatasetBean != null) {
@ -1292,7 +1319,7 @@ public class UpdateDatasetForm extends Composite {
final String datasetUrl = createdDatasetBean.getSource();
alertOnCreate(PRODUCT_CREATED_OK, false, AlertType.SUCCESS, false);
alertOnCreate(PRODUCT_UPDATED_OK, false, AlertType.SUCCESS, false);
try {
// disable dataset fields
@ -1326,7 +1353,7 @@ public class UpdateDatasetForm extends Composite {
});
// set hidden the create button
createButton.setVisible(false);
updateButton.setVisible(false);
// if we are in the "general case" we need to show a form for adding resources
if (!isWorkspaceRequest) {
@ -1543,7 +1570,7 @@ public class UpdateDatasetForm extends Composite {
onCreateAlertBlock.setText(text);
onCreateAlertBlock.setType(type);
onCreateAlertBlock.setVisible(true);
createButton.setEnabled(true);
updateButton.setEnabled(true);
goBackButtonSecondStep.setEnabled(true);
if (hideAfterAWhile) {

View File

@ -425,11 +425,11 @@
styleName="{style.the-margin-gotoitem}"></b:Button>
</g:HorizontalPanel>
<b:Button title="Add resources to the just created item"
<b:Button title="Manage resources of the item"
block="true" type="PRIMARY" visible="false"
ui:field="addResourcesButton">Add Resources</b:Button>
ui:field="addResourcesButton">Manage Resources</b:Button>
<b:Button title="Create Item" ui:field="createButton"
<b:Button title="Update Item" ui:field="updateButton"
type="PRIMARY" block="true">Create</b:Button>
<b:Button title="Go Back" ui:field="goBackButtonSecondStep"

View File

@ -5,6 +5,7 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -36,6 +37,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GenericUt
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.MetadataDiscovery;
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.WorkspaceUtils;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataProfileBeanForUpdate;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.license.LicenseBean;
@ -69,9 +71,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// private static final org.slf4j.Logger logger =
// LoggerFactory.getLogger(CKANPublisherServicesImpl.class);
private static final Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class);
private static final String ITEM_URL_FIELD = "Item URL";
private static final String SYS_TYPE = "system:type";
private static final String TAGS_VOCABULARY_KEY = "TAGS_VOCABULARY";
public static final String ITEM_URL_FIELD = "Item URL";
public static final String SYSTEM_KEY_PREFIX = "system:";
public static final String SYS_TYPE = SYSTEM_KEY_PREFIX + "type";
public static final String TAGS_VOCABULARY_KEY = "TAGS_VOCABULARY";
public static final List<String> SYSTEM_CUSTOM_FIELDS_PREFIXES = Arrays.asList(ITEM_URL_FIELD, SYSTEM_KEY_PREFIX);
// map <orgName, scope>
private ConcurrentHashMap<String, String> mapOrganizationScope = new ConcurrentHashMap<String, String>();
@ -356,6 +361,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
bean = new DatasetBean();
bean.setId(datasetIdOrName);
bean.setCkanName(dataset.getName());
bean.setTitle(dataset.getTitle());
bean.setDescription(dataset.getNotes());
bean.setLicense(dataset.getLicenseTitle());
@ -386,20 +392,19 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
Arrays.asList(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName(), true)));
List<CkanTag> listDatasetTags = dataset.getTags();
if(logger.isDebugEnabled()) {
if (logger.isDebugEnabled()) {
logger.debug("List tags from CKAN are: ");
for (CkanTag ckanTag : listDatasetTags) {
logger.debug("ckanTag: "+ckanTag.getDisplayName());
logger.debug("ckanTag: "+ckanTag.getName());
// logger.debug("ckanTag: " + ckanTag.getDisplayName());
logger.debug("ckanTag: " + ckanTag.getName());
}
}
// selected tags into Dataset
if (listDatasetTags != null) {
List<String> listTags = dataset.getTags().stream().map(t -> t.getName()).collect(Collectors.toList());
logger.info("setTags: {}",listTags);
logger.info("setTags: {}", listTags);
bean.setTags(listTags);
}
@ -427,10 +432,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
}
// Settings the dataset type
Map<String, String> extras = dataset.getExtrasAsHashMap();
Map<String, List<String>> extras = dataset.getExtrasAsHashMap();
if (extras != null) {
String theDatasetType = extras.get(SYS_TYPE);
bean.setChosenType(theDatasetType);
List<String> theDatasetType = extras.get(SYS_TYPE);
if (theDatasetType != null && theDatasetType.size() > 0) {
bean.setChosenType(theDatasetType.get(0));
}
}
logger.debug("Returning bean " + bean);
@ -442,6 +449,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* To resource bean.
*
* @param ckanResource the ckan resource
* @return the resource element bean
*/
public ResourceElementBean toResourceBean(CkanResource ckanResource) {
ResourceElementBean reb = new ResourceElementBean();
@ -500,7 +508,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try {
devModeSetContexts();
logger.info("Request for creating a dataset with these information " + toCreate);
logger.info("Request for creating a dataset with title: {} " + toCreate.getTitle());
if (logger.isDebugEnabled()) {
logger.debug("Dataset is: {} " + toCreate);
}
String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
String title = toCreate.getTitle();
String organizationNameOrId = toCreate.getSelectedOrganization();
@ -588,6 +599,113 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
}
/**
* Update CKAN dataset.
*
* @param toUpdate the to create
* @return the dataset bean
* @throws Exception the exception
*/
@Override
public DatasetBean updateCKANDataset(DatasetBean toUpdate) throws Exception {
try {
devModeSetContexts();
logger.info("Request for updating a dataset with title: {} " + toUpdate.getTitle());
if (logger.isDebugEnabled()) {
logger.debug("Dataset is: {} " + toUpdate);
}
if (toUpdate.getCkanName() == null)
throw new Exception("Error on updating: the input parameter 'name' is null");
String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
String title = toUpdate.getTitle();
String organizationNameOrId = toUpdate.getSelectedOrganization();
String author = toUpdate.getAuthorFullName();
String authorMail = toUpdate.getAuthorEmail();
String maintainer = toUpdate.getMaintainer();
String maintainerMail = toUpdate.getMaintainerEmail();
long version = toUpdate.getVersion();
String description = toUpdate.getDescription();
String chosenLicense = toUpdate.getLicense();
String licenseId = findLicenseIdByLicense(chosenLicense);
List<String> listOfTags = toUpdate.getTags();
Map<String, List<String>> customFields = toUpdate.getCustomFields();
// add Type for custom fields
if (toUpdate.getChosenType() != null)
customFields.put(SYS_TYPE, Arrays.asList(toUpdate.getChosenType()));
boolean setPublic = toUpdate.getVisibility();
// get the list of resources and convert to ResourceBean
List<ResourceBean> resources = null;
ResourceElementBean resourcesToAdd = toUpdate.getResourceRoot();
// converting to resources to be added
if (resourcesToAdd != null) {
Workspace workspace = getWorkspaceFromStorageHub();
resources = WorkspaceUtils.toResources(toUpdate, workspace, userName);
}
logger.debug("The user wants to publish in organization with name " + organizationNameOrId);
String scope = getScopeFromOrgName(organizationNameOrId);
DataCatalogue utils = getCatalogue(scope);
if (!isWithinPortal()) {
logger.debug("Should be added:");
for (String key : customFields.keySet()) {
logger.debug("Custom field with key: " + key + ", value: " + customFields.get(key));
}
}
String datasetId = utils.updateCkanDatasetMultipleCustomFields(userName, title, toUpdate.getCkanName(),
organizationNameOrId, author, authorMail, maintainer, maintainerMail, version, description,
licenseId, listOfTags, customFields, resources, setPublic, true, true);
if (datasetId != null) {
logger.info("Dataset updated!");
toUpdate.setId(datasetId);
// #23491 Building the go to the item to "Catalogue Portlet URL" (instead of URI
// Resolver URL)
String catalogueURL = utils.getPortletUrl();
// logger.debug("Returning catalogueURL: "+catalogueURL);
// logger.debug("Returning datasetId: "+datasetId);
toUpdate.setSource(String.format("%s?path=/dataset/%s", catalogueURL, datasetId));
logger.debug("Returning getSource(): " + toUpdate.getSource());
logger.debug("Returning dataset: " + toUpdate);
// #24744 Returning lazy object
toUpdate.setGroups(null);
toUpdate.setCustomFields(null);
toUpdate.setGroupsForceCreation(null);
toUpdate.setMetadataList(null);
toUpdate.setOrganizationList(null);
logger.info("Returning lazy dataset: " + toUpdate);
// createdDatasetBean.getSource();
// createdDatasetBean.getTitle();
// resourceForm = new AddResourceToDataset(eventBus, createdDatasetBean.getId(),
// createdDatasetBean.getTitle(),
// createdDatasetBean.getSelectedOrganization(), owner, datasetUrl);
return toUpdate;
} else {
logger.error("Failed to update the dataset");
}
} catch (Exception e) {
logger.error("Error while updating item ", e);
throw new Exception(e.getMessage());
}
return null;
}
/**
* Adds the resource to dataset.
*
@ -691,7 +809,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @throws Exception the exception
*/
@Override
public List<MetaDataProfileBean> getProfileForUpdate(String orgName, String datasetType, String datasedIdOrName)
public MetadataProfileBeanForUpdate getProfileForUpdate(String orgName, String datasetType, String datasedIdOrName)
throws Exception {
logger.info("Called getProfileForUpdate for orgName {} and dataset type {} ", orgName, datasetType);
logger.debug("Requested profiles for products into orgName " + orgName);
@ -715,7 +833,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
throw e;
}
HttpSession httpSession = this.getThreadLocalRequest().getSession();
// retrieve scope per current portlet url
String scopePerCurrentUrl = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest());
String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
@ -728,23 +845,49 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// Settings current values in the profile found
MetaDataProfileBean profileBean = toReturn.get(0);
logger.trace("The profile is {}", profileBean);
Map<String, String> extras = dataset.getExtrasAsHashMap();
Map<String, List<String>> extras = dataset.getExtrasAsHashMap();
HashMap<String, List<String>> customFieldsMap = new HashMap<String, List<String>>(extras);
logger.trace("Current extras are {}", extras);
for (MetadataFieldWrapper metadataFieldWrapper : profileBean.getMetadataFields()) {
String fieldName = metadataFieldWrapper.getFieldName();
logger.trace("Searching field name {} in the profile", fieldName);
String currValueOfExtraField = extras.get(metadataFieldWrapper.getFieldName());
logger.trace("Current value found is {} for field name {}", currValueOfExtraField, fieldName);
metadataFieldWrapper.setCurrentValues(currValueOfExtraField);
// removing profile key from the map
customFieldsMap.remove(fieldName);
logger.trace("Searching field name '{}' in the profile", fieldName);
List<String> currValuesOfExtraField = extras.get(metadataFieldWrapper.getFieldName());
logger.trace("Current value found is '{}' for field name '{}'", currValuesOfExtraField, fieldName);
metadataFieldWrapper.setCurrentValues(currValuesOfExtraField.stream().toArray(String[]::new));
}
if (logger.isDebugEnabled()) {
logger.debug("Returning filled profile {}", profileBean.getType());
logger.debug("with MetadataFields {}", profileBean.getMetadataFields());
logger.debug("Custom fields founds {}", customFieldsMap.keySet());
}
int customFieldsSize = customFieldsMap.size();
// There are the Custom Fields not belonging to profile
logger.info("Custom fields founds # {}", customFieldsSize);
if (customFieldsSize > 0) {
logger.info("Purging extras with prefix 'system:' from custom fields..");
for (String key : customFieldsMap.keySet()) {
if (key.startsWith(SYSTEM_KEY_PREFIX)) {
customFieldsMap.remove(key);
}
}
}
logger.info("custom fields to return {}", customFieldsMap.keySet());
MetadataProfileBeanForUpdate mpfu = new MetadataProfileBeanForUpdate();
mpfu.setListProfileBean(Arrays.asList(profileBean));
mpfu.setCustomFields(customFieldsMap);
logger.info("returing the filled profile {}", profileBean.getType());
return Arrays.asList(profileBean);
return mpfu;
}
/**
@ -1030,5 +1173,42 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
throw new Exception("GeoJSON field with value '" + geoJson + "' seems not valid!");
}
}
public static Map<String, List<String>> purgeSystemFields(Map<String, List<String>> extras) {
if (extras == null)
return null;
Map<String, List<String>> extrasPop = new HashMap<String, List<String>>(extras);
for (String key : extras.keySet()) {
List<String> list = SYSTEM_CUSTOM_FIELDS_PREFIXES.stream().filter(scf -> key.startsWith(scf))
.collect(Collectors.toList());
if (list.size() > 0)
extrasPop.remove(key);
}
return extrasPop;
}
public static Map<String, List<String>> getSystemFields(Map<String, List<String>> extras) {
if (extras == null)
return null;
Map<String, List<String>> systemExtras = new HashMap<String, List<String>>();
for (String key : extras.keySet()) {
List<String> list = SYSTEM_CUSTOM_FIELDS_PREFIXES.stream().filter(scf -> key.startsWith(scf))
.collect(Collectors.toList());
if (list.size() > 0)
systemExtras.put(key, extras.get(key));
}
return systemExtras;
}
}

View File

@ -12,12 +12,25 @@ import com.google.gwt.user.client.rpc.IsSerializable;
* This bean will contain during ckan metadata creation information related to
* the future build.
*
* revisited by @author Francesco Mangiacrapa at ISTI-CNR
*
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*
*/
@SuppressWarnings("serial")
public class DatasetBean implements Serializable, IsSerializable {
private String id;
private String ckanName;
public String getCkanName() {
return ckanName;
}
public void setCkanName(String ckanName) {
this.ckanName = ckanName;
}
private String title;
private String description;
private String license; // chosen by the user
@ -45,32 +58,37 @@ public class DatasetBean implements Serializable, IsSerializable {
private List<OrganizationBean> groupsForceCreation;
private List<ResourceElementBean> resources;
/**
* Instantiates a new dataset bean.
*/
public DatasetBean() {
super();
}
/**
* Create a metadata bean object.
*
* @param id
* @param title
* @param description
* @param customFields
* @param tags
* @param license
* @param visibility
* @param source
* @param version
* @param author
* @param authorEmail
* @param maintainer
* @param maintainerEmail
* @param ownerIdentifier
* @param organizationList
* @param selectedOrganization
* @param resourcesIds
* @param addResources
* @param metadataList
*
* @param id the id
* @param title the title
* @param description the description
* @param customFields the custom fields
* @param tags the tags
* @param license the license
* @param visible the visible
* @param source the source
* @param version the version
* @param authorName the author name
* @param authorSurname the author surname
* @param authorEmail the author email
* @param maintainer the maintainer
* @param maintainerEmail the maintainer email
* @param ownerIdentifier the owner identifier
* @param organizationList the organization list
* @param selectedOrganization the selected organization
* @param resourceRoot the resource root
* @param metadataList the metadata list
* @param groups the groups
* @param tagsVocabulary the tags vocabulary
*/
public DatasetBean(String id, String title, String description, Map<String, List<String>> customFields,
List<String> tags, String license, boolean visible, String source, long version, String authorName,
@ -101,202 +119,452 @@ public class DatasetBean implements Serializable, IsSerializable {
this.tagsVocabulary = tagsVocabulary;
}
/**
* Gets the chosen type.
*
* @return the chosen type
*/
public String getChosenType() {
return chosenType;
}
/**
* Sets the chosen type.
*
* @param chosenType the new chosen type
*/
public void setChosenType(String chosenType) {
this.chosenType = chosenType;
}
/**
* Gets the metadata list.
*
* @return the metadata list
*/
public List<MetaDataProfileBean> getMetadataList() {
return metadataList;
}
/**
* Sets the metadata list.
*
* @param metadataListTypes the new metadata list
*/
public void setMetadataList(List<MetaDataProfileBean> metadataListTypes) {
this.metadataList = metadataListTypes;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(String id) {
this.id = id;
}
/**
* Gets the owner identifier.
*
* @return the owner identifier
*/
public String getOwnerIdentifier() {
return ownerIdentifier;
}
/**
* Sets the owner identifier.
*
* @param ownerIdentifier the new owner identifier
*/
public void setOwnerIdentifier(String ownerIdentifier) {
this.ownerIdentifier = ownerIdentifier;
}
/**
* Gets the title.
*
* @return the title
*/
public String getTitle() {
return title;
}
/**
* Sets the title.
*
* @param title the new title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Gets the description.
*
* @return the description
*/
public String getDescription() {
return description;
}
/**
* Sets the description.
*
* @param description the new description
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Gets the custom fields.
*
* @return the custom fields
*/
public Map<String, List<String>> getCustomFields() {
return customFields;
}
/**
* Sets the custom fields.
*
* @param customFields the custom fields
*/
public void setCustomFields(Map<String, List<String>> customFields) {
this.customFields = customFields;
}
/**
* Gets the tags.
*
* @return the tags
*/
public List<String> getTags() {
return tags;
}
/**
* Sets the tags.
*
* @param tags the new tags
*/
public void setTags(List<String> tags) {
this.tags = tags;
}
/**
* Gets the license.
*
* @return the license
*/
public String getLicense() {
return license;
}
/**
* Sets the license.
*
* @param license the new license
*/
public void setLicense(String license) {
this.license = license;
}
/**
* Gets the visibility.
*
* @return the visibility
*/
public boolean getVisibility() {
return visible;
}
/**
* Sets the visibile.
*
* @param visibile the new visibile
*/
public void setVisibile(boolean visibile) {
this.visible = visibile;
}
/**
* Gets the source.
*
* @return the source
*/
public String getSource() {
return source;
}
/**
* Sets the source.
*
* @param source the new source
*/
public void setSource(String source) {
this.source = source;
}
/**
* Gets the version.
*
* @return the version
*/
public long getVersion() {
return version;
}
/**
* Sets the version.
*
* @param version the new version
*/
public void setVersion(long version) {
this.version = version;
}
/**
* Gets the author name.
*
* @return the author name
*/
public String getAuthorName() {
return authorName;
}
/**
* Sets the author name.
*
* @param authorName the new author name
*/
public void setAuthorName(String authorName) {
this.authorName = authorName;
}
/**
* Gets the author surname.
*
* @return the author surname
*/
public String getAuthorSurname() {
return authorSurname;
}
/**
* Sets the author surname.
*
* @param authorSurname the new author surname
*/
public void setAuthorSurname(String authorSurname) {
this.authorSurname = authorSurname;
}
/**
* Gets the author email.
*
* @return the author email
*/
public String getAuthorEmail() {
return authorEmail;
}
/**
* Sets the author email.
*
* @param authorEmail the new author email
*/
public void setAuthorEmail(String authorEmail) {
this.authorEmail = authorEmail;
}
/**
* Gets the maintainer.
*
* @return the maintainer
*/
public String getMaintainer() {
return maintainer;
}
/**
* Sets the maintainer.
*
* @param maintainer the new maintainer
*/
public void setMaintainer(String maintainer) {
this.maintainer = maintainer;
}
/**
* Gets the maintainer email.
*
* @return the maintainer email
*/
public String getMaintainerEmail() {
return maintainerEmail;
}
/**
* Sets the maintainer email.
*
* @param maintainerEmail the new maintainer email
*/
public void setMaintainerEmail(String maintainerEmail) {
this.maintainerEmail = maintainerEmail;
}
/**
* Gets the organization list.
*
* @return the organization list
*/
public List<OrganizationBean> getOrganizationList() {
return organizationList;
}
/**
* Sets the organization list.
*
* @param organizationList the new organization list
*/
public void setOrganizationList(List<OrganizationBean> organizationList) {
this.organizationList = organizationList;
}
/**
* Gets the selected organization.
*
* @return the selected organization
*/
public String getSelectedOrganization() {
return selectedOrganization;
}
/**
* Sets the selected organization.
*
* @param selectedOrganization the new selected organization
*/
public void setSelectedOrganization(String selectedOrganization) {
this.selectedOrganization = selectedOrganization;
}
/**
* Gets the resource root.
*
* @return the resource root
*/
public ResourceElementBean getResourceRoot() {
return resourceRoot;
}
/**
* Sets the resource root.
*
* @param resourceRoot the new resource root
*/
public void setResourceRoot(ResourceElementBean resourceRoot) {
this.resourceRoot = resourceRoot;
}
/**
* Gets the author full name.
*
* @return the author full name
*/
public String getAuthorFullName() {
return authorFullName;
}
/**
* Sets the author full name.
*
* @param authorFullName the new author full name
*/
public void setAuthorFullName(String authorFullName) {
this.authorFullName = authorFullName;
}
/**
* Gets the groups.
*
* @return the groups
*/
public List<OrganizationBean> getGroups() {
return groups;
}
/**
* Sets the groups.
*
* @param groups the new groups
*/
public void setGroups(List<OrganizationBean> groups) {
this.groups = groups;
}
/**
* Gets the tags vocabulary.
*
* @return the tags vocabulary
*/
public List<String> getTagsVocabulary() {
return tagsVocabulary;
}
/**
* Sets the tags vocabulary.
*
* @param tagsVocabulary the new tags vocabulary
*/
public void setTagsVocabulary(List<String> tagsVocabulary) {
this.tagsVocabulary = tagsVocabulary;
}
/**
* Gets the groups force creation.
*
* @return the groups force creation
*/
public List<OrganizationBean> getGroupsForceCreation() {
return groupsForceCreation;
}
/**
* Sets the groups force creation.
*
* @param groupsForceCreation the new groups force creation
*/
public void setGroupsForceCreation(List<OrganizationBean> groupsForceCreation) {
this.groupsForceCreation = groupsForceCreation;
}
/**
* Sets the resources.
*
* @param resources the new resources
*/
public void setResources(List<ResourceElementBean> resources) {
this.resources = resources;
}
/**
* Gets the ckan resources.
*
* @return the ckan resources
*/
public List<ResourceElementBean> getCkanResources() {
return resources;
}
@ -306,6 +574,8 @@ public class DatasetBean implements Serializable, IsSerializable {
StringBuilder builder = new StringBuilder();
builder.append("DatasetBean [id=");
builder.append(id);
builder.append(", ckanName=");
builder.append(ckanName);
builder.append(", title=");
builder.append(title);
builder.append(", description=");
@ -338,6 +608,8 @@ public class DatasetBean implements Serializable, IsSerializable {
builder.append(visible);
builder.append(", organizationList=");
builder.append(organizationList);
builder.append(", resourceRoot=");
builder.append(resourceRoot);
builder.append(", metadataList=");
builder.append(metadataList);
builder.append(", tags=");
@ -354,6 +626,4 @@ public class DatasetBean implements Serializable, IsSerializable {
return builder.toString();
}
}

View File

@ -0,0 +1,96 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.shared;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
/**
* The Class MetadataProfileBeanForUpdate.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Feb 8, 2024
*/
public class MetadataProfileBeanForUpdate implements Serializable {
/**
*
*/
private static final long serialVersionUID = -389855531761329707L;
private List<MetaDataProfileBean> listProfileBean;
private Map<String, List<String>> customFields;
/**
* Instantiates a new metadata profile bean for update.
*/
public MetadataProfileBeanForUpdate() {
super();
}
/**
* Instantiates a new metadata profile bean for update.
*
* @param listProfileBean the list profile bean
* @param customFields the custom fields
*/
public MetadataProfileBeanForUpdate(List<MetaDataProfileBean> listProfileBean, Map<String, List<String>> customFields) {
super();
this.listProfileBean = listProfileBean;
this.customFields = customFields;
}
/**
* Gets the list profile bean.
*
* @return the list profile bean
*/
public List<MetaDataProfileBean> getListProfileBean() {
return listProfileBean;
}
/**
* Gets the custom fields.
*
* @return the custom fields
*/
public Map<String, List<String>> getCustomFields() {
return customFields;
}
/**
* Sets the list profile bean.
*
* @param listProfileBean the new list profile bean
*/
public void setListProfileBean(List<MetaDataProfileBean> listProfileBean) {
this.listProfileBean = listProfileBean;
}
/**
* Sets the custom fields.
*
* @param customFields the custom fields
*/
public void setCustomFields(Map<String, List<String>> customFields) {
this.customFields = customFields;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MetadataProfileBeanForUpdate [listProfileBean=");
builder.append(listProfileBean);
builder.append(", customFields=");
builder.append(customFields);
builder.append("]");
return builder.toString();
}
}

View File

@ -2,6 +2,9 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
@ -9,6 +12,7 @@ import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory;
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl;
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.WorkspaceUtils;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
@ -38,7 +42,7 @@ public class TestPublishingWidget {
public void before() throws Exception {
}
@Test
//@Test
public void getDataset() {
try {
@ -128,5 +132,23 @@ public class TestPublishingWidget {
LOG.info("Got dataset: " + bean);
}
//@Test
public void extrasManage() {
Map<String, List<String>> extras = new HashMap<String, List<String>>();
extras.put("ciao", Arrays.asList("ciao value"));
extras.put(CKANPublisherServicesImpl.SYSTEM_CUSTOM_FIELDS_PREFIXES.get(0), Arrays.asList("rem value 1"));
extras.put(CKANPublisherServicesImpl.SYSTEM_CUSTOM_FIELDS_PREFIXES.get(1), Arrays.asList("rem value 2"));
extras.put(CKANPublisherServicesImpl.SYS_TYPE, Arrays.asList("ciao value"));
extras.put("ultimo value", Arrays.asList("ultimo value"));
Map<String, List<String>> pop = CKANPublisherServicesImpl.purgeSystemFields(extras);
System.out.println("POP: " + pop);
Map<String, List<String>> push = CKANPublisherServicesImpl.getSystemFields(extras);
System.out.println("PUSH: " + push);
}
}