/** * Creates CkanDataset on the server * * @param dataset data set with a given parameters * @return the newly created dataset * @throws JackanException */ public synchronized CkanDataset createDataset(CkanDataset dataset) { logger.warning("TODO 0.4 CREATION OF FULL DATASETS IS EXPERIMENTAL!"); checkNotNull(dataset); if (ckanToken == null) { throw new JackanException( "Tried to create dataset" + dataset.getName() + ", but ckan token was not set!"); } ObjectMapper objectMapper = CkanClient.getObjectMapper(); String json = null; try { json = objectMapper.writeValueAsString(dataset); } catch (IOException e) { throw new JackanException("Couldn't serialize the provided CkanDatasetMinimized!", this, e); } DatasetResponse datasetresponse = postHttp( DatasetResponse.class, "/api/3/action/package_create", json, ContentType.APPLICATION_JSON); return datasetresponse.result; }
/** * Updates a resource on the ckan server. * * @param resource ckan resource object * @return the updated resource * @throws JackanException */ public synchronized CkanResource updateResource(CkanResource resource, Boolean checkConsistency) { if (ckanToken == null) { throw new JackanException( "Tried to update resource" + resource.getName() + ", but ckan token was not set!"); } // check consistance with original version of the to be updated resource if (checkConsistency) { CkanResource originalResource = getResource(resource.getId()); for (Field f : originalResource.getClass().getDeclaredFields()) { f.setAccessible(true); String fieldName; try { if ((f.get(originalResource) != null) && (f.get(resource) == null) && (!f.getName().equals("created"))) { fieldName = f.getName(); // if(!fieldName.equals("created")){ f.set(resource, f.get(originalResource)); System.out.println("Not a null: " + fieldName + " Value: "); // //}; // System.out.println("Not a null: "+fieldName+ " Value: "); } } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // System.out.println("After consistance checking resource is consist of: // "+resource.toString()); ObjectMapper objectMapper = CkanClient.getObjectMapper(); String json = null; try { json = objectMapper.writeValueAsString(resource); } catch (IOException e) { throw new JackanException("Couldn't serialize the provided CkanResourceMinimized!", e); } return postHttp( ResourceResponse.class, "/api/3/action/resource_update", json, ContentType.APPLICATION_JSON) .result; }
/** * Creates ckan resource on the server. * * @param resource ckan resource object with the minimal set of parameters required. See {@link * CkanResource#CkanResource(java.lang.String, java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String)} * @return the newly created resource * @throws JackanException */ public synchronized CkanResource createResource(CkanResourceMinimized resource) { checkResource(resource); if (ckanToken == null) { throw new JackanException( "Tried to create resource" + resource.getName() + ", but ckan token was not set!"); } ObjectMapper objMapper = CkanClient.getObjectMapper(); String json = null; try { json = objMapper.writeValueAsString(resource); } catch (IOException e) { throw new JackanException("Couldn't serialize the provided CkanResource!", e); } return postHttp( ResourceResponse.class, "/api/3/action/resource_create", json, ContentType.APPLICATION_JSON) .result; }