Skip to content

Commit 41887c5

Browse files
authored
Merge pull request #67 from JingMa87/DD-424-post-wrong-json
DD-424 post wrong json
2 parents 855f8a0 + f6c99eb commit 41887c5

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/main/java/edu/harvard/iq/dataverse/License.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,7 @@ public boolean equals(Object o) {
126126
if (this == o) return true;
127127
if (o == null || getClass() != o.getClass()) return false;
128128
License license = (License) o;
129-
return active == license.active &&
130-
Objects.equals(id, license.id) &&
131-
Objects.equals(name, license.name) &&
132-
Objects.equals(shortDescription, license.shortDescription) &&
133-
Objects.equals(uri, license.uri) &&
134-
Objects.equals(iconUrl, license.iconUrl);
129+
return active == license.active && id.equals(license.id) && name.equals(license.name) && shortDescription.equals(license.shortDescription) && uri.equals(license.uri) && iconUrl.equals(license.iconUrl);
135130
}
136131

137132
@Override

src/main/java/edu/harvard/iq/dataverse/api/Admin.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
import edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand;
4747
import edu.harvard.iq.dataverse.settings.Setting;
4848
import edu.harvard.iq.dataverse.util.json.JsonPrinter;
49+
import java.net.URI;
4950
import javax.json.Json;
5051
import javax.json.JsonArrayBuilder;
5152
import javax.json.JsonObjectBuilder;
52-
import javax.persistence.PersistenceException;
5353
import javax.ws.rs.DELETE;
5454
import javax.ws.rs.GET;
5555
import javax.ws.rs.POST;
@@ -2013,15 +2013,21 @@ public Response getLicenseByName(@PathParam("name") String name) {
20132013

20142014
@POST
20152015
@Path("/licenses")
2016-
public Response addLicense(License license) {
2016+
public Response addLicense(JsonObject jsonObject) {
20172017
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"));
20182024
licenseService.save(license);
20192025
String location = "/api/admin/licenses/name/" + UrlEscapers.urlFragmentEscaper().escape(license.getName());
20202026
return created(location, Json.createObjectBuilder().add("message", "License created"));
20212027
} 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.");
20252031
}
20262032
}
20272033

0 commit comments

Comments
 (0)