-
Notifications
You must be signed in to change notification settings - Fork 3
Closes #2736 Import Geonames Data #2782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
fairchive-webapp/src/main/java/edu/harvard/iq/dataverse/api/GeoNameApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package edu.harvard.iq.dataverse.api; | ||
|
|
||
| import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
| import static javax.ws.rs.core.MediaType.TEXT_PLAIN; | ||
| import static javax.ws.rs.core.Response.Status.FORBIDDEN; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
||
| import javax.ejb.Stateless; | ||
| import javax.inject.Inject; | ||
| import javax.ws.rs.Consumes; | ||
| import javax.ws.rs.DELETE; | ||
| import javax.ws.rs.POST; | ||
| import javax.ws.rs.Path; | ||
| import javax.ws.rs.Produces; | ||
| import javax.ws.rs.core.Response; | ||
|
|
||
| import edu.harvard.iq.dataverse.persistence.user.AuthenticatedUser; | ||
| import edu.harvard.iq.dataverse.search.geonames.GeoNameIndexingService; | ||
|
|
||
| @Stateless | ||
| @Path("geonames") | ||
| public class GeoNameApi extends AbstractApiBean { | ||
|
|
||
| private GeoNameIndexingService indexingService; | ||
|
|
||
| public GeoNameApi() { | ||
| } | ||
|
|
||
| @Inject | ||
| public GeoNameApi(final GeoNameIndexingService indexingService) { | ||
| this.indexingService = indexingService; | ||
| } | ||
|
|
||
| @POST | ||
| @Path("/") | ||
| @Consumes(TEXT_PLAIN) | ||
| @Produces(APPLICATION_JSON) | ||
| public Response upload(final InputStream in) throws Exception { | ||
| try { | ||
| findSuperuserOrDie(); | ||
| this.indexingService.importNames(in); | ||
| return ok("Imported"); | ||
| } catch (final AbstractApiBean.WrappedResponse wrappedResponse) { | ||
| return wrappedResponse.getResponse(); | ||
| } | ||
| } | ||
|
|
||
| @DELETE | ||
| @Path("/") | ||
| @Produces(APPLICATION_JSON) | ||
| public Response clear() throws Exception { | ||
| try { | ||
| findSuperuserOrDie(); | ||
| this.indexingService.clear(); | ||
| return ok("Cleared"); | ||
| } catch (final AbstractApiBean.WrappedResponse wrappedResponse) { | ||
| return wrappedResponse.getResponse(); | ||
| } | ||
| } | ||
| } | ||
|
|
100 changes: 100 additions & 0 deletions
100
...rc/main/java/edu/harvard/iq/dataverse/dataset/metadata/inputRenderer/GeoNameRenderer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package edu.harvard.iq.dataverse.dataset.metadata.inputRenderer; | ||
|
|
||
| import static edu.harvard.iq.dataverse.persistence.dataset.InputRendererType.GEONAME; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import javax.faces.component.UIComponent; | ||
| import javax.faces.context.FacesContext; | ||
| import javax.faces.convert.Converter; | ||
| import javax.faces.event.ValueChangeEvent; | ||
|
|
||
| import edu.harvard.iq.dataverse.persistence.dataset.DatasetField; | ||
| import edu.harvard.iq.dataverse.persistence.dataset.InputRendererType; | ||
| import edu.harvard.iq.dataverse.search.geonames.GeoName; | ||
| import edu.harvard.iq.dataverse.search.geonames.GeoNameDataFinder; | ||
|
|
||
| public class GeoNameRenderer implements InputFieldRenderer { | ||
|
|
||
| private Optional<GeoName> selectedGeoName = Optional.empty(); | ||
| private final GeoNameDataFinder geoNames; | ||
| private final CapturingConverter converter = new CapturingConverter(); | ||
|
|
||
| public GeoNameRenderer(final GeoNameDataFinder geoNames) { | ||
| this.geoNames = geoNames; | ||
| } | ||
|
|
||
| // -------------------- GETTERS -------------------- | ||
|
|
||
| @Override | ||
| public InputRendererType getType() { | ||
| return GEONAME; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean renderInTwoColumns() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isHidden() { | ||
| return false; | ||
| } | ||
|
|
||
| // -------------------- LOGIC -------------------- | ||
|
|
||
| /** | ||
| * Workaround for p:autocomplete in order to use function with 2 arguments in | ||
| * 'completeMethod'. Since value is bound to {@link DatasetField} and binded | ||
| * only after executing 'completeMethod' the query will not work since it will | ||
| * take previously binded value, so we are taking it from {@link FacesContext} | ||
| * directly. | ||
| */ | ||
| public List<GeoName> processSuggestionQuery(final DatasetField datasetField) { | ||
| final String query = SuggestionAutocompleteHelper | ||
| .processSuggestionQuery("geoname") | ||
| .orElseThrow(() -> new IllegalStateException( | ||
| "Autocomplete query was not found.")); | ||
| List<GeoName> result = this.geoNames.find(query, 50); | ||
| return result; | ||
| } | ||
|
|
||
| public boolean displayDetails() { | ||
| return this.selectedGeoName.isPresent(); | ||
| } | ||
|
|
||
| public String getDetails() { | ||
| return this.selectedGeoName.map(gn -> gn.getDetails("<b>", "</b>", "<br/>")) | ||
| .orElse(""); | ||
| } | ||
|
|
||
| public Converter getConverter() { | ||
| return this.converter; | ||
| } | ||
|
|
||
| public void processValueChange(final ValueChangeEvent event) { | ||
| if (event.getNewValue() != null) { | ||
| this.selectedGeoName = this.geoNames | ||
| .findById(event.getNewValue().toString()); | ||
| } | ||
| } | ||
|
|
||
| private class CapturingConverter implements Converter { | ||
|
|
||
| @Override | ||
| public Object getAsObject(final FacesContext context, | ||
| final UIComponent component, | ||
| final String value) { | ||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public String getAsString(final FacesContext context, | ||
| final UIComponent component, | ||
| final Object value) { | ||
| selectedGeoName = geoNames.findById(value.toString()); | ||
| return value.toString(); | ||
| } | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
.../java/edu/harvard/iq/dataverse/dataset/metadata/inputRenderer/GeoNameRendererFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package edu.harvard.iq.dataverse.dataset.metadata.inputRenderer; | ||
|
|
||
| import javax.ejb.Stateless; | ||
| import javax.inject.Inject; | ||
|
|
||
| import com.google.gson.JsonObject; | ||
|
|
||
| import edu.harvard.iq.dataverse.persistence.dataset.DatasetFieldType; | ||
| import edu.harvard.iq.dataverse.persistence.dataset.InputRendererType; | ||
| import edu.harvard.iq.dataverse.search.geonames.GeoNameDataFinder; | ||
|
|
||
| @Stateless | ||
| public class GeoNameRendererFactory implements InputFieldRendererFactory<GeoNameRenderer> { | ||
|
|
||
| private final GeoNameDataFinder geoNames; | ||
|
|
||
| @Inject | ||
| public GeoNameRendererFactory(final GeoNameDataFinder geoNames) { | ||
| this.geoNames = geoNames; | ||
| } | ||
|
|
||
| @Override | ||
| public InputRendererType isFactoryForType() { | ||
| return InputRendererType.GEONAME; | ||
| } | ||
|
|
||
| @Override | ||
| public GeoNameRenderer createRenderer(DatasetFieldType fieldType, JsonObject jsonOptions) { | ||
| return new GeoNameRenderer(this.geoNames); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.