Skip to content
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

DD-421 wrong location header #62

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ public License getByName(String name) throws FetchException {
return licenses.get(0);
}

public License save(License license) throws PersistenceException, RequestBodyException {
public void save(License license) throws PersistenceException, RequestBodyException {
if (license.getId() == null) {
em.persist(license);
return license;
} else {
throw new RequestBodyException("There shouldn't be an ID in the request body");
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Admin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.harvard.iq.dataverse.api;

import com.google.common.net.UrlEscapers;
import edu.harvard.iq.dataverse.BannerMessage;
import edu.harvard.iq.dataverse.BannerMessageServiceBean;
import edu.harvard.iq.dataverse.BannerMessageText;
Expand Down Expand Up @@ -1958,7 +1959,8 @@ public Response getLicenseByName(@PathParam("name") String name) {
public Response addLicense(License license) {
try {
licenseService.save(license);
return created("/api/admin/licenses", Json.createObjectBuilder().add("message", "License created"));
String location = "/api/admin/licenses/name/" + UrlEscapers.urlFragmentEscaper().escape(license.getName());
return created(location, Json.createObjectBuilder().add("message", "License created"));
} catch (RequestBodyException e) {
return error(Response.Status.BAD_REQUEST, e.getMessage());
} catch(PersistenceException e) {
Expand Down