Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4312013
[CITE-163] Created collection.html page to import collection
PradnyaC11 Aug 22, 2024
d426a75
[CITE-163] Added POST for collection upload in ImportCollectionContro…
PradnyaC11 Aug 23, 2024
fe9e22d
[CITE-163] Added response to uploadCollection method
PradnyaC11 Aug 27, 2024
57563b4
[CITE-163] Fixing errors in upload collection code
PradnyaC11 Sep 3, 2024
505c2f2
[CITE-163] Updated the POST URL for upload collection
PradnyaC11 Sep 4, 2024
a108d4a
[CITE-163] Removed IUploadJobCollection class
PradnyaC11 Oct 4, 2024
c5c9cfc
[CITE-163] Added select for collections on import collection page
PradnyaC11 Nov 12, 2024
2134b97
[CITE-163] Added method to get collections of selected group
PradnyaC11 Nov 13, 2024
da60307
[CITE-163] Updated Upload job to include collectionId
PradnyaC11 Nov 14, 2024
57314c4
[CITE-163] Resolved importing to collection issue
PradnyaC11 Nov 20, 2024
ccb03f8
[CITE-163] Added option to select new collection
PradnyaC11 Nov 22, 2024
5a668b0
[CITE-163] Added methods to create new collection
PradnyaC11 Nov 25, 2024
75f108a
[CITE-163] Resolved issues with create new citation
PradnyaC11 Nov 26, 2024
35a4143
Merge branch 'develop' into story/CITE-163
PradnyaC11 Jan 21, 2025
8bac348
[CITE-163] Updated get group item API call
PradnyaC11 Jan 23, 2025
70cd62b
[CITE-163] Updated ItemTextController to added headers
PradnyaC11 Jan 24, 2025
13d0810
[CITE-163] Updated JobInfoController with giles token
PradnyaC11 Jan 30, 2025
9c4e0e9
[CITE-163] Updated get item API to use headers
PradnyaC11 Feb 6, 2025
073a5a0
[CITE-163] Updated versions in pom.xml
PradnyaC11 Feb 25, 2025
34721c4
[CITE-163] Cleaned-up code
PradnyaC11 Feb 27, 2025
9754d1b
[CITE-163] Removed unwanted changes
PradnyaC11 Feb 27, 2025
3d72e60
[CITE-163] Resolved code factor issue
PradnyaC11 Feb 28, 2025
d19ed0a
Merge branch 'develop' into story/CITE-163
PradnyaC11 Feb 28, 2025
1eba17e
Merge branch 'develop' into story/CITE-163
PradnyaC11 Mar 4, 2025
9f35112
[CITE-163] Addressed PR comments
PradnyaC11 May 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion citesphere/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<javers.version>6.2.3</javers.version>
<spring.kafka.version>2.2.6.RELEASE</spring.kafka.version>
<spring-social-zotero.version>0.13</spring-social-zotero.version>
<citesphere.messages.version>0.4</citesphere.messages.version>
<citesphere.messages.version>0.6</citesphere.messages.version>
<citesphere.model.version>1.24</citesphere.model.version>

<admin.password>$2a$04$oQo44vqcDIFRoYKiAXoNheurzkwX9dcNmowvTX/hsWuBMwijqn44i</admin.password>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import edu.asu.diging.citesphere.core.model.jobs.IUploadJob;
import edu.asu.diging.citesphere.core.service.jobs.IUploadJobManager;
import edu.asu.diging.citesphere.core.service.jwt.IJobApiTokenContents;
import edu.asu.diging.citesphere.core.service.oauth.InternalTokenManager;
import edu.asu.diging.citesphere.core.user.IUserManager;
import edu.asu.diging.citesphere.core.zotero.impl.ZoteroTokenManager;
import edu.asu.diging.citesphere.user.IUser;

@Controller
public class JobInfoController extends BaseJobInfoController {
Expand All @@ -37,6 +39,8 @@ public class JobInfoController extends BaseJobInfoController {
@Autowired
private IExportTaskManager exportTaskManager;

@Autowired
private InternalTokenManager internalTokenManager;

@RequestMapping(value="/job/info")
public ResponseEntity<String> getProfile(@RequestHeader HttpHeaders headers) {
Expand All @@ -62,6 +66,9 @@ public ResponseEntity<String> getProfile(@RequestHeader HttpHeaders headers) {
// FIXME: ugly, needs better solution
if (job instanceof IUploadJob) {
node.put("groupId", ((IUploadJob)job).getCitationGroup());
node.put("collectionId", ((IUploadJob)job).getCitationCollection());
IUser user = userManager.findByUsername(job.getUsername());
node.put("giles", internalTokenManager.getAccessToken(user).getValue());
}
if (job instanceof IExportJob) {
IExportTask exportTask = exportTaskManager.get(((IExportJob)job).getTaskId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public interface IUploadJob extends IJob {
void setCitationGroup(String citationGroup);

String getCitationGroup();

String getCitationCollection();

void setCitationCollection(String citationCollection);

ICitationGroup getCitationGroupDetail();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class UploadJob extends Job implements IUploadJob {
private long fileSize;
private String contentType;
private String citationGroup;
private String citationCollection;
@Transient
private ICitationGroup citationGroupDetail;

Expand Down Expand Up @@ -57,6 +58,14 @@ public void setCitationGroup(String citationGroup) {
this.citationGroup = citationGroup;
}
@Override
public String getCitationCollection() {
return citationCollection;
}
@Override
public void setCitationCollection(String citationCollection) {
this.citationCollection = citationCollection;
}
@Override
public ICitationGroup getCitationGroupDetail() {
return citationGroupDetail;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import java.util.List;

import org.springframework.social.zotero.exception.ZoteroConnectionException;

import edu.asu.diging.citesphere.core.exceptions.GroupDoesNotExistException;
import edu.asu.diging.citesphere.core.exceptions.ZoteroItemCreationFailedException;
import edu.asu.diging.citesphere.model.bib.ICitationCollection;
import edu.asu.diging.citesphere.model.bib.impl.CitationCollectionResult;
import edu.asu.diging.citesphere.user.IUser;
Expand All @@ -20,5 +23,8 @@ List<ICitationCollection> getAllCollections(IUser user, String groupId, String p
throws GroupDoesNotExistException;

void deleteLocalGroupCollections(String groupId);

ICitationCollection createCollection(IUser user, String groupId, String collectionName, String parentCollection)
throws GroupDoesNotExistException, ZoteroItemCreationFailedException, ZoteroConnectionException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.social.zotero.exception.ZoteroConnectionException;
import org.springframework.stereotype.Service;

import edu.asu.diging.citesphere.core.exceptions.GroupDoesNotExistException;
import edu.asu.diging.citesphere.core.exceptions.ZoteroItemCreationFailedException;
import edu.asu.diging.citesphere.core.service.ICitationCollectionManager;
import edu.asu.diging.citesphere.core.zotero.IZoteroManager;
import edu.asu.diging.citesphere.data.bib.CitationCollectionRepository;
import edu.asu.diging.citesphere.data.bib.CitationGroupRepository;
import edu.asu.diging.citesphere.data.bib.ICollectionMongoDao;
import edu.asu.diging.citesphere.model.bib.ICitationCollection;
import edu.asu.diging.citesphere.model.bib.ICitationGroup;
import edu.asu.diging.citesphere.model.bib.impl.CitationCollection;
import edu.asu.diging.citesphere.model.bib.impl.CitationCollectionResult;
import edu.asu.diging.citesphere.user.IUser;

Expand Down Expand Up @@ -107,4 +110,22 @@ public ICitationCollection getCollection(IUser user, String groupId, String coll
public void deleteLocalGroupCollections(String groupId) {
collectionRepository.deleteByGroupId(groupId);
}

@Override
public ICitationCollection createCollection(IUser user, String groupId, String collectionName, String parentCollection)
throws GroupDoesNotExistException, ZoteroItemCreationFailedException, ZoteroConnectionException {
Optional<ICitationGroup> groupOptional = groupRepository.findFirstByGroupId(new Long(groupId));
if (!groupOptional.isPresent()) {
throw new GroupDoesNotExistException("Group with id " + groupId + " does not exist.");
}
if(parentCollection != null) {
Optional<ICitationCollection> collectionOptional = collectionRepository.findByKey(parentCollection);
if (!collectionOptional.isPresent()) {
throw new GroupDoesNotExistException("Collection with id " + parentCollection + " does not exist.");
}
}

ICitationCollection newCollection = zoteroManager.createCitationCollection(user, groupId, collectionName, parentCollection);
return collectionRepository.save((CitationCollection)newCollection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public interface IUploadJobManager {

IUploadJob findUploadJob(String id);

List<IUploadJob> createUploadJob(IUser user, MultipartFile[] files, List<byte[]> fileBytes, String groupId) throws GroupDoesNotExistException;
List<IUploadJob> createUploadJob(IUser user, MultipartFile[] files, List<byte[]> fileBytes,
String groupId, String collectionId, String kafkaMessage) throws GroupDoesNotExistException;

byte[] getUploadedFile(IUploadJob job);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public IUploadJob findUploadJobFullyLoaded(String id) {
}

@Override
public List<IUploadJob> createUploadJob(IUser user, MultipartFile[] files, List<byte[]> fileBytes, String groupId) throws GroupDoesNotExistException {
public List<IUploadJob> createUploadJob(IUser user, MultipartFile[] files, List<byte[]> fileBytes,
String groupId, String collectionId, String kafkaMessage) throws GroupDoesNotExistException {
ICitationGroup group = groupManager.getGroup(user, groupId);
if (group == null) {
throw new GroupDoesNotExistException();
Expand All @@ -128,6 +129,7 @@ public List<IUploadJob> createUploadJob(IUser user, MultipartFile[] files, List<
job.setCreatedOn(OffsetDateTime.now());
job.setUsername(user.getUsername());
job.setCitationGroup(groupId);
job.setCitationCollection(collectionId);
job.setPhases(new ArrayList<>());
try {
if (fileBytes != null && fileBytes.size() == files.length) {
Expand Down Expand Up @@ -174,7 +176,7 @@ public List<IUploadJob> createUploadJob(IUser user, MultipartFile[] files, List<
uploadJobRepository.save(job);
String token = tokenService.generateJobApiToken(job);
try {
kafkaProducer.sendRequest(new KafkaJobMessage(token), KafkaTopics.REFERENCES_IMPORT_TOPIC);
kafkaProducer.sendRequest(new KafkaJobMessage(token), kafkaMessage);
} catch (MessageCreationException e) {
logger.error("Could not send Kafka message.", e);
job.setStatus(JobStatus.FAILURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ void clearCollectionItemsCache(IUser user, String groupId, String collectionId,

Map<ItemDeletionResponse, List<String>> deleteMultipleItems(IUser user, String groupId, List<String> citationKeys, Long citationVersion) throws ZoteroConnectionException, ZoteroHttpStatusException;

Collection createCitationCollection(IUser user, String groupId, String collectionName,
String parentCollection) throws ZoteroItemCreationFailedException, ZoteroConnectionException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,18 @@ CitationResults getCollectionItems(IUser user, String groupId, String collection
long getLatestGroupVersion(IUser user, String groupId);

Map<ItemDeletionResponse, List<String>> deleteMultipleItems(IUser user, String groupId, List<String> citationKeys, Long citationVersion) throws ZoteroConnectionException, ZoteroHttpStatusException;

/**
* Creates a new citation collection in the specified Zotero group and returns it as an {@link ICitationCollection} domain object.
*
* @param user the {@link IUser} on whose behalf the collection is being created (used for authentication)
* @param groupId the identifier of the Zotero group in which to create the collection
* @param collectionName the human-readable name for the new collection
* @param parentCollection the identifier of an existing parent collection under which to nest the new collection, or {@code null} to create a top-level collection
* @return a fully initialized {@link ICitationCollection} representing the newly created collection
* @throws ZoteroItemCreationFailedException if Zotero rejects the creation request (e.g. duplicate key)
* @throws ZoteroConnectionException if there is a network or API connectivity error when talking to Zotero
*/
ICitationCollection createCitationCollection(IUser user, String groupId, String collectionName, String parentCollection) throws ZoteroItemCreationFailedException, ZoteroConnectionException;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs javadoc (including explanation of parentCollection: null if no parent collection?).


}
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,29 @@ public Map<ItemDeletionResponse, List<String>> deleteMultipleItems(IUser user, S
Zotero zotero = getApi(user);
return zotero.getGroupsOperations().deleteMultipleItems(groupId, citationKeys, citationVersion);
}

@Override
public Collection createCitationCollection(IUser user, String groupId, String collectionName,
String parentCollection) throws ZoteroItemCreationFailedException, ZoteroConnectionException {
Zotero zotero = getApi(user);

ItemCreationResponse response = zotero.getGroupCollectionsOperations().createCollection(groupId, collectionName, parentCollection);

// let's give Zotero a minute to process
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
logger.error("Could not sleep.", e);
// well if something goes wrong here, let's just ignore it
}

Map<String, String> success = response.getSuccess();
if (success.isEmpty()) {
logger.error("Could not create collection: " + response.getFailed().get("0"));
throw new ZoteroItemCreationFailedException(response);
}

// since we only submitted one collection, there should only be one in the map
return getCitationCollection(user, groupId, success.values().iterator().next());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,11 @@ public Map<ItemDeletionResponse, List<String>> deleteMultipleItems(IUser user, S
throws ZoteroConnectionException, ZoteroHttpStatusException {
return zoteroConnector.deleteMultipleItems(user, groupId, citationKeys, citationVersion);
}

@Override
public ICitationCollection createCitationCollection(IUser user, String groupId, String collectionName,
String parentCollection) throws ZoteroItemCreationFailedException, ZoteroConnectionException {
Collection collection = zoteroConnector.createCitationCollection(user, groupId, collectionName, parentCollection);
return collectionFactory.createCitationCollection(collection);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package edu.asu.diging.citesphere.web.user;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import edu.asu.diging.citesphere.api.v1.model.impl.Collections;
import edu.asu.diging.citesphere.api.v1.user.JsonUtil;
import edu.asu.diging.citesphere.core.exceptions.GroupDoesNotExistException;
import edu.asu.diging.citesphere.core.service.ICitationCollectionManager;
import edu.asu.diging.citesphere.core.service.IGroupManager;
import edu.asu.diging.citesphere.model.bib.ICitationGroup;
import edu.asu.diging.citesphere.user.IUser;

@Controller
public class GetCollectionListController {
private final Logger logger = LoggerFactory.getLogger(getClass());

@Autowired
private ICitationCollectionManager collectionManager;

@Autowired
private IGroupManager groupManager;

@Autowired
private JsonUtil jsonUtil;

@RequestMapping(value = "/auth/import/collection/getgroupcollections", method = RequestMethod.GET)
public ResponseEntity<Collections> getCollections( @RequestParam("groupId") String groupId, Authentication authentication) {
IUser user = (IUser)authentication.getPrincipal();

ICitationGroup group = groupManager.getGroup(user, groupId);
if (group == null) {
return new ResponseEntity<Collections>(HttpStatus.NOT_FOUND);
}

Collections collectionResponse = new Collections();
collectionResponse.setGroup(jsonUtil.createGroup(group));
try {
collectionResponse.setCollections(
collectionManager.getAllCollections(user, groupId, null, "title", 20));
} catch (GroupDoesNotExistException e) {
logger.error("Could not create job because group does not exist.", e);
return new ResponseEntity<Collections>(HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<Collections>(collectionResponse, HttpStatus.OK);
}
}
Loading