diff --git a/.classpath b/.classpath index bf026c8..9450698 100644 --- a/.classpath +++ b/.classpath @@ -28,11 +28,5 @@ - - - - - - diff --git a/CHANGELOG.md b/CHANGELOG.md index 757f8bd..5ba2ea3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,17 +4,23 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.1.0-SNAPSHOT] - 2022-03-01 + +#### Enhancement + +- [#22890] Overloaded the method getProfilesInTheScope + ## [v1.0.1-SNAPSHOT] - 2020-10-08 #### Bug fixes -[#20446] Catalogue Publishing Widget: field value unexpectedly added in case of optional field +- [#20446] Catalogue Publishing Widget: field value unexpectedly added in case of optional field ## [v1.0.0] - 2020-10-08 #### First release -[#19884] Create widget to build a data-entry form by using metadata-profile-discovery +- [#19884] Create widget to build a data-entry form by using metadata-profile-discovery -[#19878] Create a data entry facility to get (meta)data object defined by "gCube Metada Profile" \ No newline at end of file +- [#19878] Create a data entry facility to get (meta)data object defined by "gCube Metada Profile" \ No newline at end of file diff --git a/pom.xml b/pom.xml index d1f3e49..0c01f11 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.gcube.portlets.widgets metadata-profile-form-builder-widget jar - 1.0.1-SNAPSHOT + 1.1.0-SNAPSHOT Metadata Profile Form Builder The Metadata Profile Form Builder is a widget able to build dynamically a web form by reading "gCube Metadata Profile/s" diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderService.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderService.java index ff0e871..57eb5bd 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderService.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderService.java @@ -8,7 +8,6 @@ import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploadingState import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; -// TODO: Auto-generated Javadoc /** * The client side stub for the RPC service. * @@ -54,4 +53,15 @@ public interface MetadataProfileFormBuilderService extends RemoteService { * @throws Exception the exception */ Integer purgeFilesUploaded() throws Exception; + + /** + * Gets the profiles in the scope. + * + * @param scope the scope + * @param genericResourceSecondaryType the generic resource secondary type + * @param resourceName the resource name + * @return the profiles in the scope + * @throws Exception the exception + */ + List getProfilesInTheScopeForName(String scope,String genericResourceSecondaryType, String resourceName) throws Exception; } diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderServiceAsync.java index fc98a96..56c7e93 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderServiceAsync.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderServiceAsync.java @@ -42,4 +42,7 @@ public interface MetadataProfileFormBuilderServiceAsync { void getUploadStatus(String clientUploadKey, AsyncCallback asyncCallback); void purgeFilesUploaded(AsyncCallback callback); + + void getProfilesInTheScopeForName(String scope, String genericResourceSecondaryType, String resourceName, + AsyncCallback> callback); } diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataDiscovery.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataDiscovery.java index 53968d3..c12b761 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataDiscovery.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataDiscovery.java @@ -75,6 +75,63 @@ public class MetadataDiscovery { } + /** + * Gets the metadata profiles list. + * + * @param scope the scope + * @param gRSecondaryType the g R secondary type + * @param resourceName the resource name + * @return the metadata profiles list + * @throws Exception the exception + */ + public static List getMetadataProfilesList(String scope, String gRSecondaryType, String resourceName) + throws Exception { + + List beans = new ArrayList(); + + LOG.debug("Discovering into scope " + scope); + + String currentContext = ScopeProvider.instance.get(); + try { + + ScopeProvider.instance.set(scope); + + // TODO two reset methods could be added to force the reader to read again these + // information (after a while) + MetadataProfileReader reader = new MetadataProfileReader(gRSecondaryType, resourceName); + + List profiles = reader.getListOfMetadataProfiles(); + prettyPrintProfiles(profiles); + LOG.info("Profiles are " + profiles.size()); + + List categories = reader.getListOfNamespaceCategories(); + if (categories == null) + categories = new ArrayList(); + + LOG.debug("All Categories are " + categories); + + for (MetadataProfile profile : profiles) { + LOG.debug("Wrapping profile with name " + profile.getName() + " and type " + profile.getMetadataType()); + MetadataFormat metadata = reader.getMetadataFormatForMetadataProfile(profile); + MetaDataProfileBean bean = toMetaDataProfileBean(metadata, categories, profile.getName()); + beans.add(bean); + } + + prettyPrintList(beans); + LOG.info("Returning " + beans.size() + " profile/s"); + + } catch (Exception e) { + LOG.error("Error while retrieving metadata beans ", e); + throw new Exception("Failed to parse Types: " + e.getMessage()); + } finally { + ScopeProvider.instance.set(currentContext); + } + + return beans; + } + + + /** * Gets the metadata profiles list. * diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataProfileFormBuilderServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataProfileFormBuilderServiceImpl.java index 45ff593..c44a657 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataProfileFormBuilderServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataProfileFormBuilderServiceImpl.java @@ -66,6 +66,40 @@ public class MetadataProfileFormBuilderServiceImpl extends RemoteServiceServlet return toReturn; } + + /** + * Gets the profiles in the scope. + * + * @param scope the scope + * @param genericResourceSecondaryType the generic resource secondary type + * @param resourceName the resource name + * @return the profiles in the scope + * @throws Exception the exception + */ + @Override + public List getProfilesInTheScopeForName(String scope,String genericResourceSecondaryType, String resourceName) throws Exception { + LOG.info("Called getProfilesInTheScope with parameter scope: " +scope+ ", genericResourceSecondaryType: "+genericResourceSecondaryType, "resourceName: "+resourceName); + + if(genericResourceSecondaryType==null || genericResourceSecondaryType.isEmpty()) + throw new Exception("The input parameter 'genericResourceSecondaryType' is not valid"); + + if(resourceName==null || resourceName.isEmpty()) + throw new Exception("The input parameter 'resourceName' is not valid"); + + List toReturn = new ArrayList(); + try { + + String evaluatedScope = scope == null || scope.isEmpty()?ScopeProvider.instance.get():scope; + LOG.debug("Evaluated scope is " + scope); + toReturn = MetadataDiscovery.getMetadataProfilesList(evaluatedScope, genericResourceSecondaryType, resourceName); + } catch (Exception e) { + LOG.error("Failed to retrieve profiles for scope " +scope, e); + throw e; + } + + return toReturn; + } + /** * Gets the profile for metadata. * @@ -132,7 +166,7 @@ public class MetadataProfileFormBuilderServiceImpl extends RemoteServiceServlet /** - * Purge files uploaded in the current session + * Purge files uploaded in the current session. * * @return number of files deleted. Null otherwise. * @throws Exception the exception