Improved code efficiency
This commit is contained in:
parent
2d9f469a46
commit
8bfb0c3b39
|
@ -1,15 +1,11 @@
|
|||
package org.gcube.gcat.rest;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.InternalServerErrorException;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.gcat.api.GCatConstants;
|
||||
import org.gcube.gcat.persistence.ckan.CKANLicense;
|
||||
|
||||
|
@ -52,18 +48,13 @@ public class License extends REST<CKANLicense> implements org.gcube.gcat.api.int
|
|||
*/
|
||||
@GET
|
||||
@Produces(GCatConstants.APPLICATION_JSON_API)
|
||||
public String listAsJsonAPI() throws WebServiceException {
|
||||
public String listAsJsonAPI() {
|
||||
String ret = super.list(-1, -1);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||
try {
|
||||
JsonNode licenses = objectMapper.readTree(ret);
|
||||
objectNode.set(GCatConstants.JSON_API_DATA_FIELD_NAME, licenses);
|
||||
ret = objectMapper.writeValueAsString(objectNode);
|
||||
}catch (Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
return ret;
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("{ \"data\":");
|
||||
stringBuffer.append(ret);
|
||||
stringBuffer.append("}");
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue