minor fixes

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@134859 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-25 16:26:56 +00:00
parent 50ca67c356
commit 32a50abe9a
2 changed files with 9 additions and 7 deletions

View File

@ -123,6 +123,7 @@
<groupId>com.googlecode.json-simple</groupId> <groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId> <artifactId>json-simple</artifactId>
<version>1.1.1</version> <version>1.1.1</version>
<scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -1695,10 +1695,10 @@ public class DataCatalogueImpl implements DataCatalogue{
httpPostRequest.setHeader("Authorization", token); httpPostRequest.setHeader("Authorization", token);
HttpEntity mpEntity = HttpEntity mpEntity =
MultipartEntityBuilder.create() MultipartEntityBuilder.create()
.addTextBody("package_id", packageId) .addTextBody("package_id", packageId, ContentType.TEXT_PLAIN)
.addTextBody("url", "upload") .addTextBody("url", "upload", ContentType.TEXT_PLAIN)
.addTextBody("description", description == null ? "" : description) .addTextBody("description", description == null ? "" : description, ContentType.TEXT_PLAIN)
.addTextBody("name", name) .addTextBody("name", name, ContentType.TEXT_PLAIN)
.addBinaryBody("upload", file, .addBinaryBody("upload", file,
ContentType.create( ContentType.create(
"application/octet-stream", "application/octet-stream",
@ -1714,21 +1714,22 @@ public class DataCatalogueImpl implements DataCatalogue{
+ apiRequestUrl + " was: " + response.getStatusLine()); + apiRequestUrl + " was: " + response.getStatusLine());
} }
logger.info("Returned message is " + response.getStatusLine());
String json = EntityUtils.toString(response.getEntity()); String json = EntityUtils.toString(response.getEntity());
Object obj = JSONValue.parse(json); Object obj = JSONValue.parse(json);
JSONObject finalResult=(JSONObject)obj; JSONObject finalResult=(JSONObject)obj;
JSONObject result = (JSONObject)finalResult.get("result"); JSONObject result = (JSONObject)finalResult.get("result");
logger.debug("Returned json is " + result.get("id")); logger.debug("Returned json is " + result.get("id"));
returnedId = (String) result.get("id"); returnedId = (String) result.get("id");
return new CheckedCkanClient(CKAN_CATALOGUE_URL, token).getResource(returnedId);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while uploading file"); logger.error("Error while uploading file");
return null; return null;
} }
return new CheckedCkanClient(CKAN_CATALOGUE_URL, token).getResource(returnedId);
} }
@SuppressWarnings("unchecked")
@Override @Override
public boolean patchResource(String resourceId, String url, public boolean patchResource(String resourceId, String url,
String name, String description, String urlType, String apiKey) { String name, String description, String urlType, String apiKey) {