minor fixes

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@147224 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-04-27 14:24:21 +00:00
parent 270ea7101b
commit f73277c929
17 changed files with 350 additions and 202 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/java"> <classpathentry including="**/*.java" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -17,20 +17,20 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="${webappDirectory}/WEB-INF/classes"/> <classpathentry kind="output" path="${webappDirectory}/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -5,7 +5,6 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
<property name="context-root" value="ckan-metadata-publisher-widget"/> <property name="context-root" value="ckan-metadata-publisher-widget"/>
<property name="java-output-path" value="/ckan-metadata-publisher-widget/target/ckan-metadata-publisher-widget-1.0.0-SNAPSHOT/WEB-INF/classes"/> <property name="java-output-path" value="/ckan-metadata-publisher-widget/target/ckan-metadata-publisher-widget-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module> </wb-module>

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ckan-metadata-publisher-widget</artifactId> <artifactId>ckan-metadata-publisher-widget</artifactId>
<version>1.2.3-SNAPSHOT</version> <version>1.3.0-SNAPSHOT</version>
<name>gCube Ckan metadata publisher widget</name> <name>gCube Ckan metadata publisher widget</name>
<description> <description>
@ -55,6 +55,11 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<!-- <dependency> -->
<!-- <groupId>xerces</groupId> -->
<!-- <artifactId>xercesImpl</artifactId> -->
<!-- <version>2.9.1</version> -->
<!-- </dependency> -->
<dependency> <dependency>
<groupId>com.google.gwt</groupId> <groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId> <artifactId>gwt-servlet</artifactId>

View File

@ -196,7 +196,7 @@ public class CKanMetadataPublisher implements EntryPoint {
for (MetaDataFieldSkeleton field : widgetsList) { for (MetaDataFieldSkeleton field : widgetsList) {
String error = field.isFieldValueValid(); String error = field.isFieldValueValid();
if(error != null) if(error != null)
Window.alert(field.getFieldName() + " is not valid. Suggestion: " + error); Window.alert(field.getFieldNameOriginal() + " is not valid. Suggestion: " + error);
else else
Window.alert("No ERROR: " + field.getFieldCurrentValue()); Window.alert("No ERROR: " + field.getFieldCurrentValue());
@ -222,7 +222,7 @@ public class CKanMetadataPublisher implements EntryPoint {
private void startExample() { private void startExample() {
String idFolderWorkspace = "1fede4e2-5859-4f19-bddb-aec7dd5b632f"; String idFolderWorkspace = "1fede4e2-5859-4f19-bddb-aec7dd5b632f";
RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(idFolderWorkspace, eventBus)); RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(eventBus));
} }

View File

@ -29,14 +29,15 @@ public interface CKanPublisherService extends RemoteService {
* Retrieve the list of profiles for a given organization name . * Retrieve the list of profiles for a given organization name .
* @return a List<MetaDataProfileBean> on success, <b>null</b> on error. * @return a List<MetaDataProfileBean> on success, <b>null</b> on error.
*/ */
List<MetaDataProfileBean> getProfiles(String orgName); List<MetaDataProfileBean> getProfiles(String orgName) throws Exception;
/** /**
* Retrieve a partially filled bean given a folder id/file id and its owner. * Retrieve a partially filled bean given a folder id/file id and its owner.
* @param folderIdOrFileId the id of the folder of file to publish * @param folderIdOrFileId the id of the folder of file to publish
* @return @return a DatasetMetadataBean on success, <b>null</b> on error. * @return @return a DatasetMetadataBean on success, <b>null</b> on error.
* @throws Exception
*/ */
DatasetBean getDatasetBean(String folderIdOrFileId); DatasetBean getDatasetBean(String folderIdOrFileId) throws Exception;
/** /**
* Try to create such dataset starting from the information contained into the toCreate bean. * Try to create such dataset starting from the information contained into the toCreate bean.
@ -57,16 +58,18 @@ public interface CKanPublisherService extends RemoteService {
* @param resource * @param resource
* @param datasetId * @param datasetId
* @return <b>true</b> on success, false otherwise * @return <b>true</b> on success, false otherwise
* @throws Exception
*/ */
boolean deleteResourceFromDataset(ResourceElementBean resource); boolean deleteResourceFromDataset(ResourceElementBean resource) throws Exception;
/** /**
* Given the title the user wants to give to the new product to create, a check is performed * Given the title the user wants to give to the new product to create, a check is performed
* to understand if a dataset with the proposed title (and so the id generated at server side) already exists * to understand if a dataset with the proposed title (and so the id generated at server side) already exists
* @param title * @param title
* @return true if it exists, false otherwise * @return true if it exists, false otherwise
* @throws Exception
*/ */
boolean datasetIdAlreadyExists(String title, String orgName); boolean datasetIdAlreadyExists(String title, String orgName) throws Exception;
/** /**
* Retrieve the list of groups the user can choose to associate this product with. * Retrieve the list of groups the user can choose to associate this product with.
@ -79,15 +82,17 @@ public interface CKanPublisherService extends RemoteService {
/** /**
* The method checks if the user is a publisher or he/she doesn't have the rights to publish * The method checks if the user is a publisher or he/she doesn't have the rights to publish
* @return true if he/she can publish, false otherwise * @return true if he/she can publish, false otherwise
* @throws Exception
*/ */
boolean isPublisherUser(boolean isWorkspaceRequest); boolean isPublisherUser(boolean isWorkspaceRequest) throws Exception;
/** /**
* Get the list of vocabulary tags for this scope * Get the list of vocabulary tags for this scope
* @param orgName * @param orgName
* @return * @return
* @throws Exception
*/ */
List<String> getTagsForOrganization(String orgName); List<String> getTagsForOrganization(String orgName) throws Exception;
/** /**
* Validate a geo json field * Validate a geo json field

View File

@ -294,7 +294,7 @@ public class CreateDatasetForm extends Composite{
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
setAlertBlock("Error while retrieving information", AlertType.ERROR, true); setAlertBlock(caught.getMessage(), AlertType.ERROR, true);
} }
@ -303,7 +303,7 @@ public class CreateDatasetForm extends Composite{
if(bean == null){ if(bean == null){
setAlertBlock("Error while retrieving information", AlertType.ERROR, true); setAlertBlock("Error while retrieving information.", AlertType.ERROR, true);
} }
else{ else{
@ -324,12 +324,9 @@ public class CreateDatasetForm extends Composite{
List<String> vocabularyTags = bean.getTagsVocabulary(); List<String> vocabularyTags = bean.getTagsVocabulary();
// vocabulary list of tags has preemption // vocabulary list of tags has preemption
if(vocabularyTags != null && !vocabularyTags.isEmpty()){ tagsPanel.setVocabulary(vocabularyTags);
tagsPanel.setVocabulary(vocabularyTags); if(customFieldsMap != null){
}
else if(customFieldsMap != null){
// get the keys and put them as tags // get the keys and put them as tags
Iterator<Entry<String, List<String>>> iteratorOverCustomField = customFieldsMap.entrySet().iterator(); Iterator<Entry<String, List<String>>> iteratorOverCustomField = customFieldsMap.entrySet().iterator();
@ -391,19 +388,42 @@ public class CreateDatasetForm extends Composite{
// get the name of the organization from the title // get the name of the organization from the title
final String orgName = nameTitleOrganizationMap.get(organizationsListbox.getSelectedItemText()); final String orgName = nameTitleOrganizationMap.get(organizationsListbox.getSelectedItemText());
// force tags
setAlertBlock("Checking for tags vocabulary, please wait...", AlertType.INFO, true);
ckanServices.getTagsForOrganization(orgName, new AsyncCallback<List<String>>() {
@Override
public void onSuccess(List<String> vocabulary) {
tagsPanel.setVocabulary(vocabulary);
tagsPanel.setVisible(true);
setAlertBlock("", AlertType.ERROR, false);
}
@Override
public void onFailure(Throwable arg0) {
setAlertBlock("Error while checking if a vocabulary of tags is defined in the selected organization.", AlertType.ERROR, true);
tagsPanel.setVocabulary(null);
tagsPanel.setVisible(true);
}
});
// perform remote request of profiles for the selected organization // perform remote request of profiles for the selected organization
ckanServices.getProfiles(orgName, new AsyncCallback<List<MetaDataProfileBean>>() { ckanServices.getProfiles(orgName, new AsyncCallback<List<MetaDataProfileBean>>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
setAlertBlock("Error while retrieving types, retry later", AlertType.ERROR, true); setAlertBlock(caught.getMessage(), AlertType.ERROR, true);
} }
@Override @Override
public void onSuccess(final List<MetaDataProfileBean> profiles) { public void onSuccess(final List<MetaDataProfileBean> profiles) {
if(profiles == null){ if(profiles == null){
setAlertBlock("Error while retrieving types, retry later", AlertType.ERROR, true); setAlertBlock("An unknow error occurred while retrieving types, sorry", AlertType.ERROR, true);
} }
else{ else{
@ -418,7 +438,7 @@ public class CreateDatasetForm extends Composite{
@Override @Override
public void onFailure(Throwable caught){ public void onFailure(Throwable caught){
setAlertBlock("Error while retrieving licenses, try later", AlertType.ERROR, true); setAlertBlock(caught.getMessage(), AlertType.ERROR, true);
} }
@Override @Override
@ -467,7 +487,7 @@ public class CreateDatasetForm extends Composite{
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
setAlertBlock("Error while retrieving groups, try later", AlertType.ERROR, true); setAlertBlock(caught.getMessage(), AlertType.ERROR, true);
} }
}); });
@ -578,6 +598,7 @@ public class CreateDatasetForm extends Composite{
// check also for tags (if for that context there is a vocabulary or not) // check also for tags (if for that context there is a vocabulary or not)
tagsPanel.setVisible(false); tagsPanel.setVisible(false);
setAlertBlock("Checking for tags vocabulary, please wait...", AlertType.INFO, true);
ckanServices.getTagsForOrganization(orgName, new AsyncCallback<List<String>>() { ckanServices.getTagsForOrganization(orgName, new AsyncCallback<List<String>>() {
@Override @Override
@ -585,12 +606,14 @@ public class CreateDatasetForm extends Composite{
tagsPanel.setVocabulary(vocabulary); tagsPanel.setVocabulary(vocabulary);
tagsPanel.setVisible(true); tagsPanel.setVisible(true);
setAlertBlock("", AlertType.ERROR, false);
} }
@Override @Override
public void onFailure(Throwable arg0) { public void onFailure(Throwable arg0) {
setAlertBlock("Error while checking if a vocabulary of tags is defined in the selected organization.", AlertType.ERROR, true); setAlertBlock("Error while checking if a vocabulary of tags is defined in the selected organization.", AlertType.ERROR, true);
tagsPanel.setVocabulary(null);
tagsPanel.setVisible(true); tagsPanel.setVisible(true);
} }
@ -685,6 +708,8 @@ public class CreateDatasetForm extends Composite{
List<MetadataFieldWrapper> fields = bean.getMetadataFields(); List<MetadataFieldWrapper> fields = bean.getMetadataFields();
List<CategoryWrapper> categories = bean.getCategories(); List<CategoryWrapper> categories = bean.getCategories();
GWT.log("There are " + categories.size() + " categories for profile " + bean.getTitle());
if(categories == null || categories.isEmpty()){ if(categories == null || categories.isEmpty()){
for (MetadataFieldWrapper field : fields) { for (MetadataFieldWrapper field : fields) {
MetaDataFieldSkeleton fieldWidget; MetaDataFieldSkeleton fieldWidget;
@ -700,42 +725,45 @@ public class CreateDatasetForm extends Composite{
// create the categories, then parse the fields. Fields do not belonging to a category are put at the end // create the categories, then parse the fields. Fields do not belonging to a category are put at the end
for (CategoryWrapper categoryWrapper : categories) { for (CategoryWrapper categoryWrapper : categories) {
CategoryPanel cp = new CategoryPanel(categoryWrapper.getTitle(), categoryWrapper.getDescription()); if(categoryWrapper.getFieldsForThisCategory() != null && categoryWrapper.getFieldsForThisCategory().size() > 0){
List<MetadataFieldWrapper> fieldsForThisCategory = categoryWrapper.getFieldsForThisCategory(); CategoryPanel cp = new CategoryPanel(categoryWrapper.getTitle(), categoryWrapper.getDescription());
fields.removeAll(fieldsForThisCategory); List<MetadataFieldWrapper> fieldsForThisCategory = categoryWrapper.getFieldsForThisCategory();
fields.removeAll(fieldsForThisCategory);
for (MetadataFieldWrapper metadataFieldWrapper : fieldsForThisCategory) {
MetaDataFieldSkeleton fieldWidget; for (MetadataFieldWrapper metadataFieldWrapper : fieldsForThisCategory) {
try { MetaDataFieldSkeleton fieldWidget;
fieldWidget = new MetaDataFieldSkeleton(metadataFieldWrapper, eventBus); try {
cp.addField(fieldWidget); fieldWidget = new MetaDataFieldSkeleton(metadataFieldWrapper, eventBus);
listOfMetadataFields.add(fieldWidget); cp.addField(fieldWidget);
} catch (Exception e) { listOfMetadataFields.add(fieldWidget);
GWT.log("Unable to build such widget", e); } catch (Exception e) {
GWT.log("Unable to build such widget", e);
}
} }
metadataFieldsPanel.add(cp);
} }
metadataFieldsPanel.add(cp);
} }
// add the remaining one at the end of the categories TODO // add the remaining one at the end of the categories
CategoryPanel extrasCategory = new CategoryPanel("Other", null);
for (MetadataFieldWrapper field : fields) { for (MetadataFieldWrapper field : fields) {
MetaDataFieldSkeleton fieldWidget; MetaDataFieldSkeleton fieldWidget;
try { try {
fieldWidget = new MetaDataFieldSkeleton(field, eventBus); fieldWidget = new MetaDataFieldSkeleton(field, eventBus);
metadataFieldsPanel.add(fieldWidget); extrasCategory.addField(fieldWidget);
listOfMetadataFields.add(fieldWidget); listOfMetadataFields.add(fieldWidget);
} catch (Exception e) { } catch (Exception e) {
GWT.log("Unable to build such widget", e); GWT.log("Unable to build such widget", e);
} }
} }
metadataFieldsPanel.add(extrasCategory);
} }
metadataFieldsPanel.setVisible(true); metadataFieldsPanel.setVisible(true);
} }
} }
} }
@UiHandler("addCustomFieldButton") @UiHandler("addCustomFieldButton")
void addCustomFieldEvent(ClickEvent e){ void addCustomFieldEvent(ClickEvent e){
@ -887,6 +915,7 @@ public class CreateDatasetForm extends Composite{
} }
List<OrganizationBean> groups = new ArrayList<OrganizationBean>(); List<OrganizationBean> groups = new ArrayList<OrganizationBean>();
List<OrganizationBean> groupsToForceCreation = new ArrayList<OrganizationBean>();
// get groups, if any // get groups, if any
int items = groupsListbox.getItemCount(); int items = groupsListbox.getItemCount();
@ -902,11 +931,9 @@ public class CreateDatasetForm extends Composite{
// prepare custom fields // prepare custom fields
for (MetaDataFieldSkeleton field : listOfMetadataFields) { for (MetaDataFieldSkeleton field : listOfMetadataFields) {
String value = field.getFieldCurrentValue(); String value = field.getFieldCurrentValue();
if(!value.isEmpty()){ if(!value.isEmpty()){
String key = field.getFieldName(); String key = field.getFieldNameQualified();
List<String> valuesForThisField = null; List<String> valuesForThisField = null;
if(customFieldsMap.containsKey(key)) if(customFieldsMap.containsKey(key))
valuesForThisField = customFieldsMap.get(key); valuesForThisField = customFieldsMap.get(key);
@ -915,34 +942,32 @@ public class CreateDatasetForm extends Composite{
valuesForThisField.add(value); valuesForThisField.add(value);
customFieldsMap.put(key, valuesForThisField); customFieldsMap.put(key, valuesForThisField);
// get also tag/group if it is the case for this field // get also tag/group if it is the case for this field
String tag = field.getTagFromThisField(); String tag = field.getTagFromThisField();
if(tag != null) if(tag != null)
tags.add(tag); tags.add(tag);
String groupTitle = field.getGroupTitleFromThisGroup();
if(groupTitle != null)
groups.add(new OrganizationBean(groupTitle, groupTitle, false));
}
String groupTitle = field.getGroupTitleFromThisGroup();
if(groupTitle != null){
if(field.isGroupToForce())
groupsToForceCreation.add(new OrganizationBean(groupTitle, groupTitle, false));
else
groups.add(new OrganizationBean(groupTitle, groupTitle, false));
}
}
} }
for(CustomFieldEntry customEntry : customFieldEntriesList){ for(CustomFieldEntry customEntry : customFieldEntriesList){
String key = customEntry.getKey(); String key = customEntry.getKey();
String value = customEntry.getValue(); String value = customEntry.getValue();
if(value != null && !value.isEmpty()){ if(value != null && !value.isEmpty()){
List<String> valuesForThisField = null; List<String> valuesForThisField = null;
if(customFieldsMap.containsKey(key)) if(customFieldsMap.containsKey(key))
valuesForThisField = customFieldsMap.get(key); valuesForThisField = customFieldsMap.get(key);
else else
valuesForThisField = new ArrayList<String>(); valuesForThisField = new ArrayList<String>();
valuesForThisField.add(value); valuesForThisField.add(value);
customFieldsMap.put(key, valuesForThisField); customFieldsMap.put(key, valuesForThisField);
} }
@ -961,6 +986,7 @@ public class CreateDatasetForm extends Composite{
receivedBean.setTags(new ArrayList<String>(tags)); receivedBean.setTags(new ArrayList<String>(tags));
receivedBean.setSelectedOrganization(chosenOrganization); receivedBean.setSelectedOrganization(chosenOrganization);
receivedBean.setGroups(groups); receivedBean.setGroups(groups);
receivedBean.setGroupsForceCreation(groupsToForceCreation);
if(resourcesTwinPanel != null) if(resourcesTwinPanel != null)
receivedBean.setResourceRoot(resourcesTwinPanel.getResourcesToPublish()); receivedBean.setResourceRoot(resourcesTwinPanel.getResourcesToPublish());
receivedBean.setCustomFields(customFieldsMap); receivedBean.setCustomFields(customFieldsMap);
@ -1227,7 +1253,7 @@ public class CreateDatasetForm extends Composite{
String error = field.isFieldValueValid(); String error = field.isFieldValueValid();
if(error != null){ if(error != null){
field.showError(); field.showError();
return field.getFieldName() + " is not valid. Suggestion: " + error; return field.getFieldNameOriginal() + " is not valid. Suggestion: " + error;
} }
} }

View File

@ -5,6 +5,7 @@ import java.util.List;
import com.github.gwtbootstrap.client.ui.PageHeader; import com.github.gwtbootstrap.client.ui.PageHeader;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Float;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
@ -35,8 +36,12 @@ public class CategoryPanel extends Composite{
*/ */
public CategoryPanel(String title, String description) { public CategoryPanel(String title, String description) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
title = title == null ? "" : title;
description = description == null ? "" : description;
categoryHeader.setTitle(title); categoryHeader.setTitle(title);
categoryHeader.setText(title);
categoryHeader.setSubtext(description); categoryHeader.setSubtext(description);
categoryHeader.getElement().getStyle().setFloat(Float.LEFT);
} }
/** /**
@ -47,6 +52,7 @@ public class CategoryPanel extends Composite{
if(fieldsForThisCategory == null){ if(fieldsForThisCategory == null){
fieldsForThisCategory = new ArrayList<MetaDataFieldSkeleton>(); fieldsForThisCategory = new ArrayList<MetaDataFieldSkeleton>();
fieldWidget.setVisible(true); fieldWidget.setVisible(true);
fieldsPanel.setVisible(true);
} }
fieldsForThisCategory.add(fieldWidget); fieldsForThisCategory.add(fieldWidget);
fieldsPanel.add(fieldWidget); fieldsPanel.add(fieldWidget);

View File

@ -2,7 +2,7 @@
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"> xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel> <g:HTMLPanel>
<g:VerticalPanel width="100%"> <g:VerticalPanel>
<b:PageHeader ui:field="categoryHeader"></b:PageHeader> <b:PageHeader ui:field="categoryHeader"></b:PageHeader>
<!-- Here will be placed the metadata fields formats --> <!-- Here will be placed the metadata fields formats -->
<g:VerticalPanel ui:field="fieldsPanel" visible="false" <g:VerticalPanel ui:field="fieldsPanel" visible="false"

View File

@ -493,6 +493,8 @@ public class MetaDataFieldSkeleton extends Composite{
* @return true if validator is null OR value.matches(reges), false otherwise * @return true if validator is null OR value.matches(reges), false otherwise
*/ */
private boolean checkValidator(String value, String validator) { private boolean checkValidator(String value, String validator) {
GWT.log("Value is " + value);
GWT.log("Validator is " + validator);
if(validator == null || validator.isEmpty()) if(validator == null || validator.isEmpty())
return true; return true;
else return value.matches(validator); else return value.matches(validator);
@ -596,7 +598,17 @@ public class MetaDataFieldSkeleton extends Composite{
* Returns the current name of the field * Returns the current name of the field
* @return * @return
*/ */
public String getFieldName(){ public String getFieldNameOriginal(){
return field.getFieldName();
}
/**
* Returns the current name of the field
* @return
*/
public String getFieldNameQualified(){
if(field.getFieldNameFromCategory() != null) if(field.getFieldNameFromCategory() != null)
return field.getFieldNameFromCategory(); return field.getFieldNameFromCategory();
@ -710,7 +722,7 @@ public class MetaDataFieldSkeleton extends Composite{
if(asTag != null){ if(asTag != null){
return TaggingGroupingValue.getComposedValue(field.getFieldName(), getFieldCurrentValue(), asTag.getSeparator(), asTag.getTaggingValue()); return TaggingGroupingValue.getComposedValue(field.getFieldName(), getFieldCurrentValue(), asTag.getSeparator(), asTag.getTaggingValue());
} }
return null; return null;
} }
@ -719,12 +731,23 @@ public class MetaDataFieldSkeleton extends Composite{
* @return a tag as string * @return a tag as string
*/ */
public String getGroupTitleFromThisGroup(){ public String getGroupTitleFromThisGroup(){
FieldAsGroup asGroup = field.getAsGroup(); FieldAsGroup asGroup = field.getAsGroup();
if(asGroup != null){ if(asGroup != null){
return TaggingGroupingValue.getComposedValue(field.getFieldName(), getFieldCurrentValue(), " ", asGroup.getGroupingValue()); return TaggingGroupingValue.getComposedValue(field.getFieldName(), getFieldCurrentValue(), " ", asGroup.getGroupingValue());
} }
return null; return null;
} }
/**
* Check if the group associated (if it exists) should be forced
* @return
*/
public boolean isGroupToForce(){
FieldAsGroup asGroup = field.getAsGroup();
if(asGroup != null){
return asGroup.getCreate();
}
return false;
}
} }

View File

@ -69,6 +69,12 @@ public class TagsPanel extends Composite{
*/ */
public void setVocabulary(List<String> vocabularyTags) { public void setVocabulary(List<String> vocabularyTags) {
tagsEnterListBox.clear();
tagsPanel.clear();
tagsList.clear();
GWT.log("Vocabulary of tags is " + vocabularyTags);
if(vocabularyTags == null || vocabularyTags.isEmpty()){ if(vocabularyTags == null || vocabularyTags.isEmpty()){
tagsEnterListBox.setVisible(false); tagsEnterListBox.setVisible(false);
tagsPanel.setVisible(true); tagsPanel.setVisible(true);
@ -83,9 +89,6 @@ public class TagsPanel extends Composite{
tagsEnterTextBox.setVisible(false); tagsEnterTextBox.setVisible(false);
tagsEnterListBox.setVisible(true); tagsEnterListBox.setVisible(true);
} }
tagsPanel.clear();
tagsList.clear();
} }
/** /**

View File

@ -179,7 +179,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
@Override @Override
public DatasetBean getDatasetBean(String folderId){ public DatasetBean getDatasetBean(String folderId) throws Exception{
DatasetBean bean = null; DatasetBean bean = null;
String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
@ -220,7 +220,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
}catch(Exception e){ }catch(Exception e){
logger.error("Error while retrieving folder information", e); logger.error("Error while retrieving bean information", e);
throw new Exception("Error while retrieving basic information " + e.getMessage());
} }
}else{ }else{
@ -239,8 +240,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
bean.setAuthorEmail("costantino.perciante@isti.cnr.it"); bean.setAuthorEmail("costantino.perciante@isti.cnr.it");
bean.setMaintainer("Costantino Perciante"); bean.setMaintainer("Costantino Perciante");
bean.setMaintainerEmail("costantino.perciante@isti.cnr.it"); bean.setMaintainerEmail("costantino.perciante@isti.cnr.it");
//bean.setOrganizationList(getUserOrganizationsListAdmin(userName, Utils.getCurrentContext(getThreadLocalRequest(), true))); bean.setOrganizationList(Arrays.asList(new OrganizationBean("NextNext", "nextnext", true)));
bean.setOrganizationList(Arrays.asList(new OrganizationBean("preVRE", "prevre", true)));
bean.setOwnerIdentifier(userName); bean.setOwnerIdentifier(userName);
if(folderId != null && !folderId.isEmpty()){ if(folderId != null && !folderId.isEmpty()){
@ -248,6 +248,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
}catch(Exception e){ }catch(Exception e){
logger.error("Error while building bean into dev mode", e); logger.error("Error while building bean into dev mode", e);
throw new Exception("Error while retrieving basic information " + e.getMessage());
} }
} }
@ -258,8 +259,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
/** /**
* Discover from the IS the vocabulary of tags for this scope, if present * Discover from the IS the vocabulary of tags for this scope, if present
* @return a list of tags vocabulary * @return a list of tags vocabulary
* @throws Exception
*/ */
private List<String> discoverTagsVocabulary(String context) { private List<String> discoverTagsVocabulary(String context){
logger.debug("Looking for vocabulary of tags in this context " + context); logger.debug("Looking for vocabulary of tags in this context " + context);
String keyPerVocabulary = UtilMethods.concatenateSessionKeyScope(TAGS_VOCABULARY_KEY, context); String keyPerVocabulary = UtilMethods.concatenateSessionKeyScope(TAGS_VOCABULARY_KEY, context);
@ -267,7 +269,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
List<String> vocabulary = (List<String>) getThreadLocalRequest().getSession().getAttribute(keyPerVocabulary); List<String> vocabulary = (List<String>) getThreadLocalRequest().getSession().getAttribute(keyPerVocabulary);
if(vocabulary == null){ if(vocabulary == null){
vocabulary = DiscoverTagsList.discoverTagsList(context); vocabulary = DiscoverTagsList.discoverTagsList(context);
getThreadLocalRequest().getSession().setAttribute(keyPerVocabulary, vocabulary); if(vocabulary != null)
getThreadLocalRequest().getSession().setAttribute(keyPerVocabulary, vocabulary);
} }
logger.debug("Vocabulary for tags is " + vocabulary); logger.debug("Vocabulary for tags is " + vocabulary);
@ -276,7 +279,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
@Override @Override
public List<String> getTagsForOrganization(String orgName) { public List<String> getTagsForOrganization(String orgName) throws Exception{
return discoverTagsVocabulary(getScopeFromOrgName(orgName)); return discoverTagsVocabulary(getScopeFromOrgName(orgName));
} }
@ -343,6 +346,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
AssociationToGroupAndNotifyThread threadAssociationToGroup = AssociationToGroupAndNotifyThread threadAssociationToGroup =
new AssociationToGroupAndNotifyThread( new AssociationToGroupAndNotifyThread(
toCreate.getGroups(), toCreate.getGroups(),
toCreate.getGroupsForceCreation(),
null, //toCreate.getChosenType(), TODO null, //toCreate.getChosenType(), TODO
datasetUrl, datasetUrl,
datasetId, datasetId,
@ -377,7 +381,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
}catch(Exception e){ }catch(Exception e){
logger.error("Error while creating item ", e); logger.error("Error while creating item ", e);
throw new Exception(e.getMessage()); throw new Exception("An error occurred while creating the item " + e.getMessage());
} }
return null; return null;
@ -426,7 +430,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
@Override @Override
public boolean deleteResourceFromDataset(ResourceElementBean resource) { public boolean deleteResourceFromDataset(ResourceElementBean resource) throws Exception{
logger.debug("Request for deleting resource " + resource); logger.debug("Request for deleting resource " + resource);
boolean deleted = false; boolean deleted = false;
@ -449,14 +453,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.error("Resource described by " + resource + " NOT deleted"); logger.error("Resource described by " + resource + " NOT deleted");
}catch(Exception e){ }catch(Exception e){
logger.error("Error while trying to delete resource described by " + resource, e); logger.error("Error while trying to delete resource described by " + resource, e);
throw new Exception("Error while trying to delete resource." + e.getMessage());
} }
return deleted; return deleted;
} }
} }
@Override @Override
public List<MetaDataProfileBean> getProfiles(String orgName) { public List<MetaDataProfileBean> getProfiles(String orgName) throws Exception{
logger.debug("Requested profiles for products into orgName " + orgName); logger.debug("Requested profiles for products into orgName " + orgName);
List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>(); List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>();
@ -466,23 +470,25 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
toReturn = MetadataDiscovery.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest()); toReturn = MetadataDiscovery.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest());
}catch(Exception e){ }catch(Exception e){
logger.error("Failed to retrieve profiles for scope coming from organization name " + orgName, e); logger.error("Failed to retrieve profiles for scope coming from organization name " + orgName, e);
throw e;
} }
return toReturn; return toReturn;
} }
@Override @Override
public boolean datasetIdAlreadyExists(String title, String orgName) { public boolean datasetIdAlreadyExists(String title, String orgName) throws Exception{
if(title == null || title.isEmpty()) if(title == null || title.isEmpty())
return true; // it's an error somehow return true; // it's an error somehow
try{ try{
String scopeFromOrgName = getScopeFromOrgName(orgName); String scopeFromOrgName = getScopeFromOrgName(orgName);
String idFromTitle = UtilMethods.fromProductTitleToName(title); String idFromTitle = UtilMethods.fromProductTitleToName(title);
logger.debug("Evaluating if dataset with id " + title + " in context " + scopeFromOrgName + " already exists");
return getCatalogue(scopeFromOrgName).existProductWithNameOrId(idFromTitle); return getCatalogue(scopeFromOrgName).existProductWithNameOrId(idFromTitle);
}catch(Exception e){ }catch(Exception e){
logger.error("Unable to check if such a dataset id already exists", e); logger.error("Unable to check if such a dataset id already exists", e);
throw new Exception("Unable to check if such a dataset id already exists " + e.getMessage());
} }
return false;
} }
/** /**
@ -510,7 +516,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
} }
}else{ }else{
toReturn = "/gcube/preprod/preVRE"; toReturn = "/gcube/devNext/NextNext";
mapOrganizationScope.put(orgName, toReturn); mapOrganizationScope.put(orgName, toReturn);
} }
logger.debug("Returning scope " + toReturn); logger.debug("Returning scope " + toReturn);
@ -560,7 +566,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
@Override @Override
public boolean isPublisherUser(boolean isWorkspaceRequest) { public boolean isPublisherUser(boolean isWorkspaceRequest) throws Exception{
String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
logger.info("Checking if the user " + username + " can publish or not on the catalogue"); logger.info("Checking if the user " + username + " can publish or not on the catalogue");
@ -621,10 +627,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
}catch(Exception e){ }catch(Exception e){
logger.error("Failed to check the user's role", e); logger.error("Failed to check the user's role", e);
throw new Exception("Failed to check if you are an Administrator or Editor " + e.getMessage());
} }
// return false
return false;
} }
@Override @Override

View File

@ -39,10 +39,11 @@ public class AssociationToGroupAndNotifyThread extends Thread {
private String datasetTitle; private String datasetTitle;
private String userFullName; private String userFullName;
private DataCatalogue catalogue; private DataCatalogue catalogue;
private String organization; // private String organization;
private List<OrganizationBean> groups; private List<OrganizationBean> groups;
private HttpServletRequest request; private HttpServletRequest request;
private String datasetUrl; private String datasetUrl;
private List<OrganizationBean> groupsForceCreation;
/** /**
* @param list * @param list
@ -51,15 +52,16 @@ public class AssociationToGroupAndNotifyThread extends Thread {
* @param username * @param username
* @param catalogue * @param catalogue
*/ */
public AssociationToGroupAndNotifyThread(List<OrganizationBean> groups, String groupTitle, String datasetUrl, String datasetId, String datasetTitle, String userFullName, public AssociationToGroupAndNotifyThread(List<OrganizationBean> groups, List<OrganizationBean> groupsForceCreation, String groupTitle, String datasetUrl, String datasetId, String datasetTitle, String userFullName,
String username, DataCatalogue catalogue, String organization, HttpServletRequest request) { String username, DataCatalogue catalogue, String organization, HttpServletRequest request) {
this.request = request; this.request = request;
this.groups = groups; this.groups = groups == null ? new ArrayList<OrganizationBean>() : groups;
this.groupsForceCreation = groupsForceCreation;
this.groupTitle = groupTitle; this.groupTitle = groupTitle;
this.datasetId = datasetId; this.datasetId = datasetId;
this.username = username; this.username = username;
this.catalogue = catalogue; this.catalogue = catalogue;
this.organization = organization; // this.organization = organization;
this.datasetTitle = datasetTitle; this.datasetTitle = datasetTitle;
this.userFullName = userFullName; this.userFullName = userFullName;
this.datasetUrl = datasetUrl; this.datasetUrl = datasetUrl;
@ -70,44 +72,58 @@ public class AssociationToGroupAndNotifyThread extends Thread {
logger.info("Association thread started to put the dataset with id = "+ datasetId + " into group with title " + groupTitle + " for user " + username); logger.info("Association thread started to put the dataset with id = "+ datasetId + " into group with title " + groupTitle + " for user " + username);
if(groupTitle != null){ // if(groupTitle != null){
try{ // try{
//
// // create the group
// CkanGroup group = catalogue.createGroup(groupTitle, groupTitle, "");
//
// if(group == null){
//
// logger.warn("The group doesn't exist! Unable to perform such association");
//
// }else{
//
// 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());
//
// if(!role.equals(RolesCkanGroupOrOrg.ADMIN))
// role = RolesCkanGroupOrOrg.MEMBER; // decrease the role to member if it is not an admin
//
// 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);
//
// if(putIntoGroup)
// notifyGroupAdmins(catalogue, group.getName(), group.getTitle(), username);
//
// }
// }
//
// }catch(Exception e){
// logger.warn("Something went wrong when tried to add the group " + groupTitle, e);
// }
// }
// create the group // force creation of groups if needed
CkanGroup group = catalogue.createGroup(groupTitle, groupTitle, ""); if(groupsForceCreation != null){
logger.info("Groups that must be created before association are " + groupsForceCreation);
if(group == null){ for (OrganizationBean groupToForce : groupsForceCreation) {
CkanGroup group = catalogue.createGroup(groupToForce.getName(), groupToForce.getTitle(), "");
logger.warn("The group doesn't exist! Unable to perform such association"); if(group == null)
logger.warn("Unable to retrieve or create group with name " + group);
}else{ else
groups.add(new OrganizationBean(group.getTitle(), group.getName(), false));
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());
if(!role.equals(RolesCkanGroupOrOrg.ADMIN))
role = RolesCkanGroupOrOrg.MEMBER; // decrease the role to member if it is not an admin
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);
if(putIntoGroup)
notifyGroupAdmins(catalogue, group.getName(), group.getTitle(), username);
}
}
}catch(Exception e){
logger.warn("Something went wrong when tried to add the group " + groupTitle, e);
} }
} }
logger.info("Other groups to which the product should be associate are " + groups); logger.info("Other groups to which the product should be associate are " + groups);
if(groups != null) if(groups != null)

View File

@ -37,8 +37,9 @@ public class DiscoverTagsList {
/** /**
* Discover the list of tags vocabulary if needed * Discover the list of tags vocabulary if needed
* @throws Exception
*/ */
public static List<String> discoverTagsList(String context) { public static List<String> discoverTagsList(String context){
if(context == null || context.isEmpty()) if(context == null || context.isEmpty())
throw new IllegalArgumentException("Context cannot be empty or null!"); throw new IllegalArgumentException("Context cannot be empty or null!");
@ -58,7 +59,6 @@ public class DiscoverTagsList {
XPathHelper helper = new XPathHelper(node); XPathHelper helper = new XPathHelper(node);
List<String> tagsVocabulary = helper.evaluate("/Resource/Profile/Body/tags/tag/text()"); List<String> tagsVocabulary = helper.evaluate("/Resource/Profile/Body/tags/tag/text()");
logger.debug("Retrieved tags " + tagsVocabulary); logger.debug("Retrieved tags " + tagsVocabulary);
return tagsVocabulary; return tagsVocabulary;
} }
}catch(Exception e){ }catch(Exception e){
@ -66,7 +66,7 @@ public class DiscoverTagsList {
}finally{ }finally{
ScopeProvider.instance.set(currentContext); ScopeProvider.instance.set(currentContext);
} }
return null; return null;
} }

View File

@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -13,13 +14,13 @@ import org.gcube.datacatalogue.ckanutillibrary.server.utils.SessionCatalogueAttr
import org.gcube.datacatalogue.ckanutillibrary.server.utils.UtilMethods; import org.gcube.datacatalogue.ckanutillibrary.server.utils.UtilMethods;
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader; import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile; import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataCategory;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataGrouping; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataGrouping;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataTagging; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataTagging;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataVocabulary; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataVocabulary;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.NamespaceCategory;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.CategoryWrapper; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.CategoryWrapper;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.DataTypeWrapper; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.DataTypeWrapper;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.FieldAsGroup; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.FieldAsGroup;
@ -112,7 +113,7 @@ public class MetadataDiscovery {
* @return * @return
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static List<MetaDataProfileBean> getMetadataProfilesList(String scope, HttpServletRequest request) { public static List<MetaDataProfileBean> getMetadataProfilesList(String scope, HttpServletRequest request) throws Exception{
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>(); List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
String username = GenericUtils.getCurrentUser(request).getUsername(); String username = GenericUtils.getCurrentUser(request).getUsername();
@ -139,23 +140,34 @@ public class MetadataDiscovery {
ScopeProvider.instance.set(scopeInWhichDiscover); ScopeProvider.instance.set(scopeInWhichDiscover);
// TODO two reset methods could be added to force the reader to read again these information (after a while)
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader(); DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
List<MetadataProfile> profiles = reader.getListOfMetadataProfiles(); List<MetadataProfile> profiles = reader.getListOfMetadataProfiles();
logger.debug("Profiles are " + profiles);
List<NamespaceCategory> categories = reader.getListOfNamespaceCategories();
if(categories == null)
categories = new ArrayList<NamespaceCategory>();
logger.debug("All Categories are " + categories);
for (MetadataProfile profile : profiles) { for (MetadataProfile profile : profiles) {
logger.debug("Wrapping profile with name " + profile.getName() + " and type " + profile.getMetadataType());
MetadataFormat metadata = reader.getMetadataFormatForMetadataProfile(profile); MetadataFormat metadata = reader.getMetadataFormatForMetadataProfile(profile);
String type = metadata.getMetadataType(); String type = metadata.getType();
String title = profile.getName(); String title = profile.getName();
List<MetadataCategory> categories = metadata.getMetadataCategories();
List<MetadataField> fields = metadata.getMetadataFields(); List<MetadataField> fields = metadata.getMetadataFields();
// we need to wrap the list of metadata // we need to wrap the list of metadata and categories
List<MetadataFieldWrapper> fieldsWrapper = new ArrayList<MetadataFieldWrapper>(fields != null ? fields.size() : 0); List<MetadataFieldWrapper> fieldsWrapper = new ArrayList<MetadataFieldWrapper>(fields != null ? fields.size() : 0);
List<CategoryWrapper> categoriesWrapper = new ArrayList<CategoryWrapper>(categories != null ? categories.size() : 0); List<CategoryWrapper> categoriesWrapper = new ArrayList<CategoryWrapper>(categories.size());
Map<String, CategoryWrapper> idToCategory = new HashMap<String, CategoryWrapper>(categoriesWrapper.size()); Map<String, CategoryWrapper> idToCategory = new HashMap<String, CategoryWrapper>(categories.size());
// manage the categories // manage the categories
for (MetadataCategory category : categories) { for (NamespaceCategory category : categories) {
CategoryWrapper categoryWrapped = new CategoryWrapper(category.getId(), category.getTitle(), category.getDescription()); CategoryWrapper categoryWrapped = new CategoryWrapper(category.getId(), category.getTitle(), category.getDescription());
categoriesWrapper.add(categoryWrapped); categoriesWrapper.add(categoryWrapped);
idToCategory.put(category.getId(), categoryWrapped); idToCategory.put(category.getId(), categoryWrapped);
@ -173,7 +185,6 @@ public class MetadataDiscovery {
wrapperObj.setDefaultValue(metadataField.getDefaultValue()); wrapperObj.setDefaultValue(metadataField.getDefaultValue());
wrapperObj.setFieldName(metadataField.getFieldName()); wrapperObj.setFieldName(metadataField.getFieldName());
wrapperObj.setMandatory(metadataField.getMandatory()); wrapperObj.setMandatory(metadataField.getMandatory());
metadataField.getNamespaceFieldToCategoryReference();
wrapperObj.setNote(metadataField.getNote()); wrapperObj.setNote(metadataField.getNote());
MetadataValidator validator = metadataField.getValidator(); MetadataValidator validator = metadataField.getValidator();
if(validator != null) if(validator != null)
@ -201,7 +212,7 @@ public class MetadataDiscovery {
if(grouping != null){ if(grouping != null){
FieldAsGroup group = new FieldAsGroup(); FieldAsGroup group = new FieldAsGroup();
group.setCreate(group.getCreate()); group.setCreate(grouping.getCreate());
group.setGroupingValue(TaggingGroupingValue.valueOf(grouping.getGroupingValue().toString())); group.setGroupingValue(TaggingGroupingValue.valueOf(grouping.getGroupingValue().toString()));
wrapperObj.setAsGroup(group); wrapperObj.setAsGroup(group);
@ -209,35 +220,50 @@ public class MetadataDiscovery {
// set to which category this field belongs to and vice-versa // set to which category this field belongs to and vice-versa
if(metadataField.getCategoryRef() != null){ if(metadataField.getCategoryRef() != null){
CategoryWrapper ownerCategory = idToCategory.get(metadataField.getCategoryRef()); CategoryWrapper ownerCategory = idToCategory.get(metadataField.getCategoryRef());
wrapperObj.setOwnerCategory(ownerCategory);
if(ownerCategory == null){
List<MetadataFieldWrapper> fieldsPerCategoryN = fieldsPerCategory.get(metadataField.getCategoryRef()); logger.warn("A field with categoryref " + metadataField.getCategoryRef() + " has been found, but"
if(fieldsPerCategoryN == null) + " such category is not defined within the namespaces");
fieldsPerCategoryN = new ArrayList<MetadataFieldWrapper>(); }else{
fieldsPerCategoryN.add(wrapperObj); wrapperObj.setOwnerCategory(ownerCategory);
fieldsPerCategory.put(metadataField.getCategoryRef(), fieldsPerCategoryN);
List<MetadataFieldWrapper> fieldsPerCategoryN = fieldsPerCategory.get(metadataField.getCategoryRef());
// instead of re-looping on the fieldsPerCategory map later, just set this potentially partial list if(fieldsPerCategoryN == null)
ownerCategory.setFieldsForThisCategory(fieldsPerCategoryN); fieldsPerCategoryN = new ArrayList<MetadataFieldWrapper>();
fieldsPerCategoryN.add(wrapperObj);
fieldsPerCategory.put(metadataField.getCategoryRef(), fieldsPerCategoryN);
// instead of re-looping on the fieldsPerCategory map later, just set this potentially partial list
ownerCategory.setFieldsForThisCategory(fieldsPerCategoryN);
}
} }
fieldsWrapper.add(wrapperObj); fieldsWrapper.add(wrapperObj);
} }
// filter the categories without children here
Iterator<CategoryWrapper> categoryToRemoveIT = categoriesWrapper.iterator();
while (categoryToRemoveIT.hasNext()) {
CategoryWrapper categoryWrapper = (CategoryWrapper) categoryToRemoveIT
.next();
if(categoryWrapper.getFieldsForThisCategory() == null)
categoryToRemoveIT.remove();
}
MetaDataProfileBean bean = new MetaDataProfileBean(type, title, fieldsWrapper, categoriesWrapper); MetaDataProfileBean bean = new MetaDataProfileBean(type, title, fieldsWrapper, categoriesWrapper);
beans.add(bean); beans.add(bean);
} }
logger.trace("List of beans is " + beans); logger.debug("List of beans is " + beans);
httpSession.setAttribute(keyPerScope, beans); httpSession.setAttribute(keyPerScope, beans);
logger.info("List of profiles has been saved into session"); logger.info("List of profiles has been saved into session");
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while retrieving metadata beans ", e); logger.error("Error while retrieving metadata beans ", e);
throw new Exception("Failed to parse Types: " + e.getMessage());
}finally{ }finally{
ScopeProvider.instance.set(oldScope); ScopeProvider.instance.set(oldScope);
} }
@ -246,5 +272,8 @@ public class MetadataDiscovery {
return beans; return beans;
} }
// public static void main(String[] args) throws Exception {
// MetadataDiscovery.getMetadataProfilesList("/gcube/devsec/devVRE", null);
// }
} }

View File

@ -36,6 +36,7 @@ public class DatasetBean implements Serializable {
private List<String> tagsVocabulary; // when available private List<String> tagsVocabulary; // when available
private Map<String, List<String>> customFields; private Map<String, List<String>> customFields;
private List<OrganizationBean> groups; private List<OrganizationBean> groups;
private List<OrganizationBean> groupsForceCreation;
public DatasetBean(){ public DatasetBean(){
super(); super();
@ -278,22 +279,57 @@ public class DatasetBean implements Serializable {
this.tagsVocabulary = tagsVocabulary; this.tagsVocabulary = tagsVocabulary;
} }
public List<OrganizationBean> getGroupsForceCreation() {
return groupsForceCreation;
}
public void setGroupsForceCreation(List<OrganizationBean> groupsForceCreation) {
this.groupsForceCreation = groupsForceCreation;
}
@Override @Override
public String toString() { public String toString() {
return "DatasetMetadataBean [id=" + id + ", title=" + title return "DatasetBean ["
+ ", description=" + description + ", license=" + license + (id != null ? "id=" + id + ", " : "")
+ ", source=" + source + ", authorName=" + authorName + (title != null ? "title=" + title + ", " : "")
+ ", authorSurname=" + authorSurname + ", authorFullName=" + (description != null ? "description=" + description + ", "
+ authorFullName + ", authorEmail=" + authorEmail : "")
+ ", maintainer=" + maintainer + ", maintainerEmail=" + (license != null ? "license=" + license + ", " : "")
+ maintainerEmail + ", ownerIdentifier=" + ownerIdentifier + (source != null ? "source=" + source + ", " : "")
+ ", chosenType=" + chosenType + ", selectedOrganization=" + (authorName != null ? "authorName=" + authorName + ", " : "")
+ selectedOrganization + ", version=" + version + (authorSurname != null ? "authorSurname=" + authorSurname
+ ", visible=" + visible + ", organizationList=" + ", " : "")
+ organizationList + ", resourceRoot=" + resourceRoot + (authorFullName != null ? "authorFullName=" + authorFullName
+ ", metadataList=" + metadataList + ", tags=" + tags + ", " : "")
+ ", tagsVocabulary=" + tagsVocabulary + ", customFields=" + (authorEmail != null ? "authorEmail=" + authorEmail + ", "
+ customFields + ", groups=" + groups + "]"; : "")
+ (maintainer != null ? "maintainer=" + maintainer + ", " : "")
+ (maintainerEmail != null ? "maintainerEmail="
+ maintainerEmail + ", " : "")
+ (ownerIdentifier != null ? "ownerIdentifier="
+ ownerIdentifier + ", " : "")
+ (chosenType != null ? "chosenType=" + chosenType + ", " : "")
+ (selectedOrganization != null ? "selectedOrganization="
+ selectedOrganization + ", " : "")
+ "version="
+ version
+ ", visible="
+ visible
+ ", "
+ (organizationList != null ? "organizationList="
+ organizationList + ", " : "")
+ (resourceRoot != null ? "resourceRoot=" + resourceRoot + ", "
: "")
+ (metadataList != null ? "metadataList=" + metadataList + ", "
: "")
+ (tags != null ? "tags=" + tags + ", " : "")
+ (tagsVocabulary != null ? "tagsVocabulary=" + tagsVocabulary
+ ", " : "")
+ (customFields != null ? "customFields=" + customFields + ", "
: "")
+ (groups != null ? "groups=" + groups + ", " : "")
+ (groupsForceCreation != null ? "groupsForceCreation="
+ groupsForceCreation : "") + "]";
} }
} }

View File

@ -62,17 +62,14 @@ public class CategoryWrapper implements Serializable{
@Override @Override
public String toString() { public String toString() {
final int maxLen = 10; return "CategoryWrapper ["
return "CategoryWrapper [id=" + (id != null ? "id=" + id + ", " : "")
+ id + (title != null ? "title=" + title + ", " : "")
+ ", title=" + (description != null ? "description=" + description + ", "
+ title : "")
+ ", description=" + (fieldsForThisCategory != null ? "fieldsForThisCategory="
+ description + fieldsForThisCategory.size() : "") + "]";
+ ", fieldsForThisCategory="
+ (fieldsForThisCategory != null ? fieldsForThisCategory
.subList(0,
Math.min(fieldsForThisCategory.size(), maxLen))
: null) + "]";
} }
} }

View File

@ -227,25 +227,24 @@ public class MetadataFieldWrapper implements Serializable{
@Override @Override
public String toString() { public String toString() {
final int maxLen = 10; return "MetadataFieldWrapper ["
return "MetadataFieldWrapper [fieldName=" + (fieldName != null ? "fieldName=" + fieldName + ", " : "")
+ fieldName + (fieldNameFromCategory != null ? "fieldNameFromCategory="
+ ", fieldNameFromCategory=" + fieldNameFromCategory + ", " : "")
+ fieldNameFromCategory + (mandatory != null ? "mandatory=" + mandatory + ", " : "")
+ ", mandatory=" + (type != null ? "type=" + type + ", " : "")
+ mandatory + (defaultValue != null ? "defaultValue=" + defaultValue + ", "
+ ", type=" : "")
+ type + (note != null ? "note=" + note + ", " : "")
+ ", defaultValue=" + (vocabulary != null ? "vocabulary=" + vocabulary + ", " : "")
+ defaultValue + "multiSelection="
+ ", note=" + multiSelection
+ note + ", "
+ ", vocabulary=" + (validator != null ? "validator=" + validator + ", " : "")
+ (vocabulary != null ? vocabulary.subList(0, + (ownerCategory != null ? "ownerCategory=" + ownerCategory.getId()
Math.min(vocabulary.size(), maxLen)) : null) + ", " : "")
+ ", multiSelection=" + multiSelection + ", validator=" + (asGroup != null ? "asGroup=" + asGroup + ", " : "")
+ validator + ", ownerCategory=" + ownerCategory + ", asGroup=" + (asTag != null ? "asTag=" + asTag : "") + "]";
+ asGroup + ", asTag=" + asTag + "]";
} }
} }