-
Notifications
You must be signed in to change notification settings - Fork 0
Story/cite 163 - We need a bulk upload for files. #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
0eb80cd
34fd534
38ec23f
4d67569
ba12094
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,16 @@ | |
| import org.springframework.social.zotero.api.Collection; | ||
| import org.springframework.social.zotero.api.GroupCollectionsOperations; | ||
| import org.springframework.social.zotero.api.Item; | ||
| import org.springframework.social.zotero.api.ItemCreationResponse; | ||
| import org.springframework.social.zotero.api.ZoteroRequestHeaders; | ||
| import org.springframework.social.zotero.api.ZoteroResponse; | ||
| import org.springframework.social.zotero.exception.ZoteroConnectionException; | ||
| import org.springframework.web.client.RestClientException; | ||
| import org.springframework.web.client.RestTemplate; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.node.ArrayNode; | ||
|
|
||
| public class GroupCollectionsTemplate extends AbstractZoteroOperations implements GroupCollectionsOperations { | ||
|
|
||
|
|
@@ -199,4 +203,27 @@ private long getLatestVersion(HttpHeaders responseHeaders) { | |
| } | ||
| return -1; | ||
| } | ||
|
|
||
| @Override | ||
| public ItemCreationResponse createCollection(String groupId, String collectionName, String parentCollection) throws ZoteroConnectionException { | ||
| String url = String.format("groups/%s/collections", groupId); | ||
|
|
||
| ObjectMapper mapper = new ObjectMapper(); | ||
|
|
||
| JsonNode dataAsJson = mapper.createObjectNode() | ||
| .put("name", collectionName) | ||
| .put("parentCollection", parentCollection); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if there is no parent collection? will this be null or should it just be omitted? the Zotero API documentation doesn't seem to say anything about that, have you tried it?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have tested this, when there's parent collection, the new collection gets added as child to parent collection. Else the new collection is added directly to group. I have kept this because as there might be cases when parent collection is present. |
||
|
|
||
| ArrayNode jsonArray = mapper.createArrayNode(); | ||
| jsonArray.add(dataAsJson); | ||
|
|
||
| HttpEntity<ArrayNode> data = new HttpEntity<ArrayNode>(jsonArray); | ||
|
|
||
| try { | ||
| return restTemplate.exchange(buildUri(url, false), HttpMethod.POST, data, ItemCreationResponse.class) | ||
|
||
| .getBody(); | ||
| } catch (RestClientException e) { | ||
| throw new ZoteroConnectionException("Could not create item.", e); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs javadoc (especially addressing my question below)