|
46 | 46 | import edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand; |
47 | 47 | import edu.harvard.iq.dataverse.settings.Setting; |
48 | 48 | import edu.harvard.iq.dataverse.util.json.JsonPrinter; |
| 49 | +import java.net.URI; |
49 | 50 | import javax.json.Json; |
50 | 51 | import javax.json.JsonArrayBuilder; |
51 | 52 | import javax.json.JsonObjectBuilder; |
52 | | -import javax.persistence.PersistenceException; |
53 | 53 | import javax.ws.rs.DELETE; |
54 | 54 | import javax.ws.rs.GET; |
55 | 55 | import javax.ws.rs.POST; |
@@ -2013,15 +2013,21 @@ public Response getLicenseByName(@PathParam("name") String name) { |
2013 | 2013 |
|
2014 | 2014 | @POST |
2015 | 2015 | @Path("/licenses") |
2016 | | - public Response addLicense(License license) { |
| 2016 | + public Response addLicense(JsonObject jsonObject) { |
2017 | 2017 | try { |
| 2018 | + License license = new License(); |
| 2019 | + license.setName(jsonObject.getString("name")); |
| 2020 | + license.setShortDescription(jsonObject.getString("shortDescription")); |
| 2021 | + license.setUri(new URI(jsonObject.getString("uri"))); |
| 2022 | + license.setIconUrl(new URI(jsonObject.getString("iconUrl"))); |
| 2023 | + license.setActive(jsonObject.getBoolean("active")); |
2018 | 2024 | licenseService.save(license); |
2019 | 2025 | String location = "/api/admin/licenses/name/" + UrlEscapers.urlFragmentEscaper().escape(license.getName()); |
2020 | 2026 | return created(location, Json.createObjectBuilder().add("message", "License created")); |
2021 | 2027 | } catch (RequestBodyException e) { |
2022 | | - return error(Response.Status.BAD_REQUEST, e.getMessage()); |
2023 | | - } catch(PersistenceException e) { |
2024 | | - return error(Response.Status.CONFLICT, "A license with the same URI or name is already present."); |
| 2028 | + return error(Response.Status.BAD_REQUEST, e.getMessage()); |
| 2029 | + } catch (Exception e) { |
| 2030 | + return error(Response.Status.BAD_REQUEST, "Something went wrong."); |
2025 | 2031 | } |
2026 | 2032 | } |
2027 | 2033 |
|
|
0 commit comments