diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..b43235b --- /dev/null +++ b/.classpath @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gwt/.gwt-log b/.gwt/.gwt-log new file mode 100644 index 0000000..e69de29 diff --git a/.project b/.project new file mode 100644 index 0000000..2780700 --- /dev/null +++ b/.project @@ -0,0 +1,53 @@ + + + ckan-metadata-publisher-widget + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + com.google.gdt.eclipse.core.webAppProjectValidator + + + + + com.google.gwt.eclipse.core.gwtProjectValidator + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + com.google.gwt.eclipse.core.gwtNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..b72a6a4 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs new file mode 100644 index 0000000..0326a93 --- /dev/null +++ b/.settings/com.google.gdt.eclipse.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +lastWarOutDir=/home/costantino/workspace/ckan-metadata-publisher-widget/target/ckan-metadata-publisher-widget-1.0.0-SNAPSHOT +warSrcDir=src/main/webapp +warSrcDirIsOutput=false diff --git a/.settings/com.google.gwt.eclipse.core.prefs b/.settings/com.google.gwt.eclipse.core.prefs new file mode 100644 index 0000000..f23a752 --- /dev/null +++ b/.settings/com.google.gwt.eclipse.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +entryPointModules= diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..29abf99 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..443e085 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..0190c48 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..735eb31 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..048200b --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Implementation-Title: Gwt-Tour +Implementation-Version: 2.0.0-SNAPSHOT + diff --git a/META-INF/clientlog4j.properties b/META-INF/clientlog4j.properties new file mode 100644 index 0000000..574c7b1 --- /dev/null +++ b/META-INF/clientlog4j.properties @@ -0,0 +1,13 @@ +log4j.rootLogger=DEBUG, A1 +log4j.appender.A1=org.apache.log4j.ConsoleAppender +log4j.appender.A1.layout=org.apache.log4j.PatternLayout + +# Print the date in ISO 8601 format +log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n + +# Print only messages of level TRACE or above in the package org.gcube +log4j.logger.org.gcube=TRACE +log4j.logger.org.gcube.application.framework.core.session=INFO +log4j.logger.com.netflix.astyanax.connectionpool=ERROR +log4j.logger.org.gcube.portal.databook.server.DBCassandraAstyanaxImpl=TRACE +log4j.logger.org.gcube.common=ERROR \ No newline at end of file diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..2d9616a --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1 @@ +${gcube.license} \ No newline at end of file diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..38d5603 --- /dev/null +++ b/distro/README @@ -0,0 +1,62 @@ +The gCube System - ${name} +-------------------------------------------------- + +${description} + + +${gcube.description} + +${gcube.funding} + + +Version +-------------------------------------------------- + +${version} (${buildDate}) + +Please see the file named "changelog.xml" in this directory for the release notes. + + +Authors +-------------------------------------------------- + +* Costantino Perciante (costantino.perciante@isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Maintainers +----------- + +* Costantino Perciante (costantino.perciante@isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Download information +-------------------------------------------------- + +Source code is available from SVN: + ${scm.url} + +Binaries can be downloaded from the gCube website: + ${gcube.website} + + +Installation +-------------------------------------------------- + +Installation documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot} + +Documentation +-------------------------------------------------- + +Documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot} + +Support +-------------------------------------------------- + +Bugs and support requests can be reported in the gCube issue tracking tool: + ${gcube.issueTracking} + + +Licensing +-------------------------------------------------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. \ No newline at end of file diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..0e46339 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,5 @@ + + + First Release + + diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..b3f5628 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,31 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + changelog.xml + profile.xml + + 755 + true + + + + + target/${build.finalName}.${project.packaging} + /${artifactId} + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..255885a --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,25 @@ + + + + Service + + ${Description} + PortletWidgets + ${artifactId} + ${version} + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + target/${build.finalName}.jar + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..471f4bc --- /dev/null +++ b/pom.xml @@ -0,0 +1,233 @@ + + + + 4.0.0 + + maven-parent + org.gcube.tools + 1.0.0 + + + + org.gcube.portlets.widgets + ckan-metadata-publisher-widget + war + 1.0.0-SNAPSHOT + gCube Ckan metadata publisher widget + + + gCube Ckan metadata publisher widget is a GWT Widget that allows to publish metadata on the d4science ckan data catalogue. + + + scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/${project.artifactId} + scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/${project.artifactId} + http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/${project.artifactId} + + + + + 2.7.0 + distro + + 1.7 + 1.7 + UTF-8 + UTF-8 + + + + + + org.gcube.distribution + maven-portal-bom + LATEST + pom + import + + + com.google.gwt + gwt + ${gwtVersion} + pom + import + + + + + + + com.google.gwt + gwt-servlet + ${gwtVersion} + provided + + + com.google.gwt + gwt-user + ${gwtVersion} + provided + + + com.google.gwt + gwt-dev + ${gwtVersion} + provided + + + com.github.gwtbootstrap + gwt-bootstrap + 2.3.2.0 + + + + eu.trentorise.opendata + jackan + 0.4.2 + + + org.slf4j + slf4j-log4j12 + 1.6.4 + provided + + + org.slf4j + slf4j-api + 1.6.4 + provided + + + org.gcube.common.portal + portal-manager + provided + + + junit + junit + 4.11 + test + + + javax.portlet + portlet-api + provided + + + com.liferay.portal + portal-service + provided + + + org.gcube.applicationsupportlayer + aslcore + + + org.gcube.portal + custom-portal-handler + [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) + provided + + + + + + ${webappDirectory}/WEB-INF/classes + + + src/main/java + + **/*.* + + + + src/main/resources + + **/*.* + + + + + + + + + org.codehaus.mojo + gwt-maven-plugin + ${gwtVersion} + + + + compile + test + + + + + + CKanMetadataPublisher.html + + org.gcube.portlets.widgets.ckandatapublisherwidget.CKanMetadataPublisher + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + ${distroDirectory}/descriptor.xml + + + + + servicearchive + install + + single + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + + + diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java new file mode 100644 index 0000000..15ab355 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java @@ -0,0 +1,28 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.EditMetadataForm; + +import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.user.client.ui.RootPanel; + +/** + * Entry point classes define onModuleLoad(). + */ +public class CKanMetadataPublisher implements EntryPoint { + + /** + * This is the entry point method. + */ + public void onModuleLoad() { + + // remove comment to the below line for testing the widget + startExample(); + + } + + private void startExample() { + + RootPanel.get("ckan-metadata-publisher-div").add(new EditMetadataForm()); + + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java new file mode 100644 index 0000000..41f8a5d --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java @@ -0,0 +1,18 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +/** + * CKAN publisher services. + * @author Costantino Perciante at ISTI-CNR + * (costantino.perciante@isti.cnr.it) + */ +@RemoteServiceRelativePath("ckanservices") +public interface CKanPublisherService extends RemoteService { + + LicensesBean getLicenses(); + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java new file mode 100644 index 0000000..fa6c08c --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java @@ -0,0 +1,16 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +/** + * CKAN publisher services RPC. + * @author Costantino Perciante at ISTI-CNR + * (costantino.perciante@isti.cnr.it) + */ +public interface CKanPublisherServiceAsync { + + void getLicenses(AsyncCallback callback); + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CustomFieldEntry.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CustomFieldEntry.java new file mode 100644 index 0000000..878305c --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CustomFieldEntry.java @@ -0,0 +1,45 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui; + +import com.github.gwtbootstrap.client.ui.TextBox; +import com.google.gwt.core.client.GWT; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; + +public class CustomFieldEntry extends Composite { + + private static CustomFieldEntryUiBinder uiBinder = GWT + .create(CustomFieldEntryUiBinder.class); + + interface CustomFieldEntryUiBinder extends + UiBinder { + } + + @UiField TextBox keyField; + @UiField TextBox valueField; + + public CustomFieldEntry() { + initWidget(uiBinder.createAndBindUi(this)); + } + + /** + * Get current key value + * @return string + */ + public String getCurrentKey(){ + + return keyField.getText(); + + } + + /** + * Get current value value + * @return string + */ + public String getCurrentValue(){ + + return valueField.getText(); + + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CustomFieldEntry.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CustomFieldEntry.ui.xml new file mode 100644 index 0000000..3729e76 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CustomFieldEntry.ui.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/EditMetadataForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/EditMetadataForm.java new file mode 100644 index 0000000..8f8c278 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/EditMetadataForm.java @@ -0,0 +1,139 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean; + +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.ControlGroup; +import com.github.gwtbootstrap.client.ui.ListBox; +import com.github.gwtbootstrap.client.ui.TextArea; +import com.github.gwtbootstrap.client.ui.TextBox; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; + +/** + * Edit metadata form for ckan dataset. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class EditMetadataForm extends Composite{ + + /** + * Create a remote service proxy to talk to the server-side ckan service. + */ + private final CKanPublisherServiceAsync ckanServices = GWT.create(CKanPublisherService.class); + + private static EditMetadataFormUiBinder uiBinder = GWT + .create(EditMetadataFormUiBinder.class); + + interface EditMetadataFormUiBinder extends + UiBinder { + } + + @UiField TextBox titleTextBox; + @UiField TextBox urlTextbox; + @UiField TextArea descriptionTextarea; + @UiField TextBox tagsTextbox; + @UiField ListBox licenseListbox; + @UiField ListBox visibilityListbox; + @UiField ListBox searchableListbox; + @UiField TextBox sourceTextbox; + @UiField TextBox versionTextbox; + @UiField TextBox authorTextbox; + @UiField TextBox authorEmailTextbox; + @UiField TextBox maintainerTextbox; + @UiField TextBox maintainerEmailTextbox; + @UiField ControlGroup customFields; + @UiField Button addCustomFieldButton; + @UiField Button createButton; + @UiField Button resetButton; + + // the licenses + private LicensesBean licenseBean; + + // added custom field entries + List customFieldEntries = new ArrayList(); + + public EditMetadataForm() { + initWidget(uiBinder.createAndBindUi(this)); + + // get back the licenses + ckanServices.getLicenses(new AsyncCallback() { + + @Override + public void onSuccess(LicensesBean result) { + + if(result != null && !result.getLicenses().isEmpty()){ + + licenseBean = result; + + // fill the listbox + for(String license: licenseBean.getLicenses()){ + + licenseListbox.addItem(license); + + } + + }else + { + // TODO + } + } + + @Override + public void onFailure(Throwable caught) { + + // TODO + + } + }); + } + + @UiHandler("addCustomFieldButton") + void addCustomFieldEvent(ClickEvent e){ + + CustomFieldEntry toAdd = new CustomFieldEntry(); + customFieldEntries.add(toAdd); + customFields.add(toAdd); + + } + + @UiHandler("createButton") + void createDatasetEvent(ClickEvent e){ + + // TODO + + } + + @UiHandler("resetButton") + void resetFormEvent(ClickEvent e){ + + // reset main fields + titleTextBox.setText(""); + urlTextbox.setText(""); + descriptionTextarea.setText(""); + tagsTextbox.setText(""); + sourceTextbox.setText(""); + versionTextbox.setText(""); + authorTextbox.setText(""); + authorEmailTextbox.setText(""); + maintainerTextbox.setText(""); + maintainerEmailTextbox.setText(""); + + // delete custom fields + for (CustomFieldEntry customField : customFieldEntries) { + customField.removeFromParent(); + } + customFieldEntries.clear(); + + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/EditMetadataForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/EditMetadataForm.ui.xml new file mode 100644 index 0000000..765c8f5 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/EditMetadataForm.ui.xml @@ -0,0 +1,229 @@ + + + + .form-main-style { + margin-left: 10px; + } + + .fieldset-border-style { + border: 1px groove #444; + -webkit-box-shadow: 0px 0px 0px 0px #000; + box-shadow: 0px 0px 0px 0px #000; + padding: 10px; + } + + .legend-style { + width: auto; + padding: 10px; + margin-bottom: 0px; + } + + @external .form-horizontal .input-large; + .form-horizontal .input-large { + width: 95%; + margin-bottom: 15px; + } + + .block-alert-style { + margin-top: 10px; + padding: 10px; + } + + + + + + + Insert Dataset Metadata + * is required + + + + + * + Title : + + + + + + + + + + * + URL: + + + + + + + + + Description: + + + + + + + + + Tags: + + + + + + + + License: + + + + + + License definitions and additional information can be found at + opendefinition.org + + + + + + Visibility: + + + Private + Public + + + + Private datasets can only be accessed by certain users, while + public datasets can be accessed by anyone. + + + + + + Searchable: + + + true + false + + + + Searchable datasets can be searched by anyone, while + not-searchable datasets can only be accessed by entering directly + its URL. + + + + + + + Source: + + + + + + + + + Version: + + + + + + + + + Author: + + + + + + + + + Author Email: + + + + + + + + + Maintainer: + + + + + + + + + Maintainer Email: + + + + + + + + + Custom Field: + + + + + + + + + + + + + + + + + + Create + Reset + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java new file mode 100644 index 0000000..364754f --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -0,0 +1,104 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.server; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.application.framework.core.session.SessionManager; +import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.liferay.portal.service.UserLocalServiceUtil; + +import eu.trentorise.opendata.jackan.CkanClient; +import eu.trentorise.opendata.jackan.model.CkanLicense; + +/** + * Server side of the data publisher. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +@SuppressWarnings("serial") +public class CKANPublisherServicesImpl extends RemoteServiceServlet implements CKanPublisherService{ + + public static final String HOSTNAME_CKAN = "https://ckan-d-d4s.d4science.org/"; + public static final String API_KEY = "803ada7f-2080-493f-8a99-3e593e880d94"; + + // Logger + private static final Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class); + + //dev user + public static final String defaultUserId = "test.user"; + + //dev vre + private static final String vreID = "/gcube/devsec/devVRE"; + + /** + * when packaging test will fail if the user is not set to test.user + * @return . + */ + public String getDevelopmentUser() { + String user = defaultUserId; + // user = "costantino.perciante"; + return user; + } + + /** + * the current ASLSession + * @return the session + */ + private ASLSession getASLSession() { + + String sessionID = this.getThreadLocalRequest().getSession().getId(); + String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); + + if (user == null) { + + logger.warn("USER IS NULL setting " + defaultUserId + " and Running OUTSIDE PORTAL"); + user = getDevelopmentUser(); + SessionManager.getInstance().getASLSession(sessionID, user).setScope(vreID); + + } + + return SessionManager.getInstance().getASLSession(sessionID, user); + } + + /** + * Online or in development mode? + * @return true if you're running into the portal, false if in development + */ + private boolean isWithinPortal() { + try { + UserLocalServiceUtil.getService(); + return true; + } + catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) { + logger.trace("Development Mode ON"); + return false; + } + } + + @Override + public LicensesBean getLicenses() { + + logger.debug("Request for CKAN licenses"); + + List result = new ArrayList(); + + CkanClient cc = new CkanClient(HOSTNAME_CKAN); + + //retrieve the list of available licenses + List licenses = cc.getLicenseList(); + + for (CkanLicense ckanLicense : licenses) { + result.add(ckanLicense.getTitle()); + logger.debug("License is " + ckanLicense.getTitle()); + } + + return new LicensesBean(result); + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/LicensesBean.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/LicensesBean.java new file mode 100644 index 0000000..ad281dc --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/LicensesBean.java @@ -0,0 +1,42 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.shared; + +import java.io.Serializable; +import java.util.List; + +/** + * This bean contains the retrieved list of available licenses for CKAN. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +@SuppressWarnings("serial") +public class LicensesBean implements Serializable{ + + List licenses; + + /** + * + */ + public LicensesBean() { + super(); + } + + /** + * @param licenses + */ + public LicensesBean(List licenses) { + super(); + this.licenses = licenses; + } + + public List getLicenses() { + return licenses; + } + + public void setLicenses(List licenses) { + this.licenses = licenses; + } + + @Override + public String toString() { + return "LicensesBean [licenses=" + licenses + "]"; + } +} diff --git a/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml b/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml new file mode 100644 index 0000000..cd2dda6 --- /dev/null +++ b/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/client/Messages_fr.properties b/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/client/Messages_fr.properties new file mode 100644 index 0000000..b4a7627 --- /dev/null +++ b/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/client/Messages_fr.properties @@ -0,0 +1,2 @@ +sendButton = Envoyer +nameField = Entrez votre nom \ No newline at end of file diff --git a/src/main/webapp/CKanMetadataPublisher.css b/src/main/webapp/CKanMetadataPublisher.css new file mode 100644 index 0000000..7aca7ac --- /dev/null +++ b/src/main/webapp/CKanMetadataPublisher.css @@ -0,0 +1,34 @@ +/** Add css rules here for your application. */ + + +/** Example rules used by the template application (remove for your app) */ +h1 { + font-size: 2em; + font-weight: bold; + color: #777777; + margin: 40px 0px 70px; + text-align: center; +} + +.sendButton { + display: block; + font-size: 16pt; +} + +/** Most GWT widgets already have a style name defined */ +.gwt-DialogBox { + width: 400px; +} + +.dialogVPanel { + margin: 5px; +} + +.serverResponseLabelError { + color: red; +} + +/** Set ids using widget.getElement().setId("idOfElement") */ +#closeButton { + margin: 15px 6px 6px; +} diff --git a/src/main/webapp/CKanMetadataPublisher.html b/src/main/webapp/CKanMetadataPublisher.html new file mode 100644 index 0000000..f0b17e1 --- /dev/null +++ b/src/main/webapp/CKanMetadataPublisher.html @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + +
+ + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..1f5a954 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + + + + + + ckanpublisherservices + org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl + + + + ckanpublisherservices + /CKanMetadataPublisher/ckanservices + + + + + + CKanMetadataPublisher.html + + + diff --git a/src/test/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisherJUnit.gwt.xml b/src/test/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisherJUnit.gwt.xml new file mode 100644 index 0000000..3395ad8 --- /dev/null +++ b/src/test/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisherJUnit.gwt.xml @@ -0,0 +1,9 @@ + + + + + + + + +