-
Notifications
You must be signed in to change notification settings - Fork 530
Metadata language api call #11857
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
base: develop
Are you sure you want to change the base?
Metadata language api call #11857
Changes from 8 commits
052b3c8
f92b387
d63a7b1
ef1803b
3c03362
6df1c81
d901f65
2304ac4
c698298
78e6c59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
A new API endpoint has been implemented for getting the metadata language of a Dataverse Collection: | ||
|
||
`GET /dataverses/{alias}/metadataLanguage`: Returns the specified metadata language(s) in the collection if any. | ||
|
||
For more information, see #11856 and #11856. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package edu.harvard.iq.dataverse.engine.command.impl; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import edu.harvard.iq.dataverse.Dataverse; | ||
import edu.harvard.iq.dataverse.DvObjectContainer; | ||
import edu.harvard.iq.dataverse.authorization.Permission; | ||
import edu.harvard.iq.dataverse.engine.command.AbstractCommand; | ||
import edu.harvard.iq.dataverse.engine.command.CommandContext; | ||
import edu.harvard.iq.dataverse.engine.command.DataverseRequest; | ||
import edu.harvard.iq.dataverse.engine.command.exception.CommandException; | ||
|
||
public class GetDataverseMetadataLanguageCommand extends AbstractCommand<Map<String, String>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm refreshing myself on how this feature even works by reading https://guides.dataverse.org/en/6.8/installation/config.html#allowing-the-language-used-for-dataset-metadata-to-be-specified In this command we're doing a get. Is there a command or at least an API endpoint for doing a set? As of #7958 the docs above say that the metadata language can be configured per collection but is only possible via the UI? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, there's no API endpoint currently to set a metadata language in a collection. It's possible via the UI and Dataverse has a setter method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks for confirming. Are you interested in expanding the scope of this pull request to include the setter method? Also, it could be expanded, if you want, to include a getter for the :MetadataLanguages setting. Please see https://guides.dataverse.org/en/6.8/developers/api-design.html#exposing-settings There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently the GET method is sufficient for my purposes, but adding a POST doesn't seem to be much work. I'll do it tomorrow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, we have a PUT method now! |
||
|
||
private final Dataverse dv; | ||
|
||
public GetDataverseMetadataLanguageCommand(DataverseRequest aRequest, Dataverse dv) { | ||
super(aRequest, dv); | ||
this.dv = dv; | ||
} | ||
|
||
@Override | ||
public Map<String, String> execute(CommandContext ctxt) throws CommandException { | ||
Map<String, String> langMap = ctxt.settings().getBaseMetadataLanguageMap(null, true); | ||
String dvMetadataLanguage = dv.getMetadataLanguage(); | ||
if (!dvMetadataLanguage.equals(DvObjectContainer.UNDEFINED_CODE)) { | ||
return Collections.singletonMap(dvMetadataLanguage, langMap.get(dvMetadataLanguage)); | ||
} | ||
return langMap; | ||
|
||
} | ||
|
||
@Override | ||
public Map<String, Set<Permission>> getRequiredPermissions() { | ||
return Collections.singletonMap("", | ||
dv.isReleased() ? Collections.<Permission>emptySet() | ||
: Collections.singleton(Permission.ViewUnpublishedDataverse)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2457,4 +2457,35 @@ private String getSuperuserToken() { | |
UtilIT.makeSuperUser(username); | ||
return adminApiToken; | ||
} | ||
|
||
@Test | ||
public void testGetDataverseMetadataLanguage() { | ||
Response createUser = UtilIT.createRandomUser(); | ||
createUser.prettyPrint(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest checking for OK or CREATED (I forget which) here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part is pretty common in other test cases too. It would make sense to check for CREATED in all of them, but that's beyond the scope of this pull request, I think. |
||
String username = UtilIT.getUsernameFromResponse(createUser); | ||
String apiToken = UtilIT.getApiTokenFromResponse(createUser); | ||
UtilIT.deleteSetting(":MetadataLanguages"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also go in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't it enough to delete it in the beggining and end of the test case? |
||
Response createDataverse1Response = UtilIT.createRandomDataverse(apiToken); | ||
|
||
createDataverse1Response.prettyPrint(); | ||
createDataverse1Response.then().assertThat().statusCode(CREATED.getStatusCode()); | ||
|
||
String alias = UtilIT.getAliasFromResponse(createDataverse1Response); | ||
|
||
Response noLang = UtilIT.getDataverseMetadataLanguage(alias, apiToken); | ||
noLang.prettyPrint(); | ||
|
||
noLang.then().assertThat().body("data", equalTo(List.of())); | ||
|
||
UtilIT.setSetting(":MetadataLanguages", | ||
"[{\"locale\":\"en\",\"title\":\"English\"},{\"locale\":\"hu\",\"title\":\"magyar\"}]"); | ||
Response allLangs = UtilIT.getDataverseMetadataLanguage(alias, apiToken); | ||
allLangs.prettyPrint(); | ||
allLangs.then().assertThat() | ||
.body("data.size()", equalTo(2)) | ||
.and().body("data[0].locale", equalTo("en")) | ||
.and().body("data[1].locale", equalTo("hu")); | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5001,4 +5001,12 @@ public static Response callCallbackUrl(String callbackUrl) { | |
.when() | ||
.get(callbackUrl); | ||
} | ||
|
||
public static Response getDataverseMetadataLanguage(String alias, String apiToken) { | ||
return given() | ||
.header(API_TOKEN_HTTP_HEADER, apiToken) | ||
.get("/api/dataverses/" | ||
+ alias | ||
+ "/metadataLanguage"); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't investigated, but when :MetadataLanguages is set, I think datasets created via the API need to specify the metadataLanguage they use. So perhaps every test run after it's set is failing? If that's true, in addition to deleting the setting at the end of the test, the test may need to be annotated to not run in parallel with anything else ( |
Uh oh!
There was an error while loading. Please reload this page.