Skip to content
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

Bug/cite 221 #276

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1ae05d4
[CITE-221] Added config for creating mongo DB index
PradnyaC11 Jul 3, 2024
4b4e181
[CITE-221] Added config to create mongo index
PradnyaC11 Jul 5, 2024
a8fbf93
[CITE-221] Added index config for key and groupId for citation, colle…
PradnyaC11 Jul 8, 2024
c7a356b
[CITE-221] Added duplicate key exception to methods
PradnyaC11 Jul 9, 2024
7121561
[CITE-221] Added duplicate key exception for group
PradnyaC11 Jul 12, 2024
fec500a
[CITE-221] Added duplicate key exception for group
PradnyaC11 Jul 15, 2024
2ac9b55
[CITE-221] Added few for Duplicate key exceptions and updated logic
PradnyaC11 Jul 16, 2024
73c3aaf
[CITE-221] Reverted duplicate key exceptions changes
PradnyaC11 Jul 17, 2024
0b2624a
[CITE-221] Updated logic so as to not throw duplicate key exception
PradnyaC11 Jul 18, 2024
a87f135
[CITE-221] Updated logic to avoid getting duplicate key exception
PradnyaC11 Jul 19, 2024
12f6aa3
[CITE-221] Addressing PR comment
PradnyaC11 Jul 19, 2024
42d1c8e
[CITE-221] Updated citesphere model version in pom.xml
PradnyaC11 Sep 24, 2024
d7a4219
Merge branch 'develop' into bug/CITE-221
PradnyaC11 Oct 28, 2024
a8a977c
[CITE-221] Addressed PR comments
PradnyaC11 Oct 29, 2024
b039e95
[CITE-221] Addressed PR comments
PradnyaC11 Oct 31, 2024
928ea95
[CITE-221] Resolved code factor dependency issue
PradnyaC11 Oct 31, 2024
1bea700
[CITE-221] Fixed test cases
PradnyaC11 Dec 3, 2024
87abbe4
Merge branch 'develop' into bug/CITE-221
PradnyaC11 Dec 3, 2024
ac2599b
[CITE-221] Fixed code factor issues
PradnyaC11 Dec 3, 2024
426cfbc
Merge branch 'bug/CITE-221' of https://github.com/diging/citesphere i…
PradnyaC11 Dec 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -89,6 +90,9 @@ public ResponseEntity<String> getItem(@RequestHeader HttpHeaders headers,
} catch (ZoteroHttpStatusException e) {
logger.error("Zotero threw exception.", e);
return new ResponseEntity<String>("{\"error\": \"" + e.getMessage() + ".\"}", HttpStatus.INTERNAL_SERVER_ERROR);
} catch (DuplicateKeyException e) {
logger.error("Duplicate key found.", e);
return new ResponseEntity<String>("{\"error\": \"" + e.getMessage() + ".\"}", HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<String>(output, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -60,7 +61,7 @@ public ResponseEntity<Collections> getCollectionsByGroupId(@RequestHeader HttpHe
@RequestParam(defaultValue = "1", required = false, value = "page") String page,
@RequestParam(defaultValue = "20", required = false, value = "maxCollectionNumber") String maxCollections,
@RequestParam(defaultValue = "title", required = false, value = "sort") String sort, Principal principal)
throws GroupDoesNotExistException {
throws GroupDoesNotExistException, DuplicateKeyException {
// TODO add pagination

IUser user = userManager.findByUsername(principal.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.security.Principal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -37,7 +38,7 @@ public class GroupApiController extends V1Controller {

@RequestMapping(value = { "/groups/{zoteroGroupId}" }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<Group> getCollectionsByGroupId(@RequestHeader HttpHeaders headers,
@PathVariable("zoteroGroupId") String groupId, Principal principal) throws GroupDoesNotExistException {
@PathVariable("zoteroGroupId") String groupId, Principal principal) throws GroupDoesNotExistException, DuplicateKeyException {

IUser user = userManager.findByUsername(principal.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import java.io.IOException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class ItemApiController extends V1Controller {

@GetMapping(value = "/groups/{groupId}/items/{item}", produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<String> getItem(@PathVariable("groupId") String groupId, @PathVariable("item") String itemKey,
Principal principal) throws GroupDoesNotExistException {
Principal principal) throws GroupDoesNotExistException, DuplicateKeyException {
IUser user = userManager.findByUsername(principal.getName());

ICitationGroup group = groupManager.getGroup(user, groupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -67,7 +68,7 @@ public ResponseEntity<String> getCollectionsByGroupId(@RequestHeader HttpHeaders
@RequestParam(defaultValue = "1", required = false, value = "page") String page,
@RequestParam(defaultValue = "title", required = false, value = "sort") String sort,
@RequestParam(required = false, value = "columns") String[] columns, Principal principal)
throws GroupDoesNotExistException {
throws GroupDoesNotExistException, DuplicateKeyException {
Integer pageInt = 1;
try {
pageInt = new Integer(page);
Expand All @@ -90,7 +91,9 @@ public ResponseEntity<String> getCollectionsByGroupId(@RequestHeader HttpHeaders
return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
} catch (ZoteroHttpStatusException e1) {
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
}
} catch(DuplicateKeyException de) {
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
}

Items itemsResponse = new Items();
itemsResponse.setGroup(jsonUtil.createGroup(group));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
import java.time.ZoneOffset;
import java.util.Arrays;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.index.Index;
import org.springframework.data.mongodb.core.index.IndexOperations;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.stereotype.Component;
Expand All @@ -28,6 +33,10 @@
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;

import edu.asu.diging.citesphere.model.bib.impl.Citation;
import edu.asu.diging.citesphere.model.bib.impl.CitationCollection;
import edu.asu.diging.citesphere.model.bib.impl.CitationGroup;

@Configuration
@PropertySource({ "classpath:config.properties", "${appConfigFile:classpath:}/app.properties" })
@EnableMongoRepositories({ "edu.asu.diging.citesphere.core.mongo", "edu.asu.diging.citesphere.data.bib" })
Expand Down Expand Up @@ -98,4 +107,21 @@ public OffsetDateTime convert(String source) {
return OffsetDateTime.parse(source);
}
}

@Configuration
public static class MongoIndex implements InitializingBean {

@Autowired
private MongoTemplate mongoTemplate;

@Override
public void afterPropertiesSet() throws Exception {
IndexOperations citationIndexOps = mongoTemplate.indexOps(Citation.class);
citationIndexOps.ensureIndex(new Index().on("key", Sort.Direction.ASC).unique());
IndexOperations citationCollectionIndexOps = mongoTemplate.indexOps(CitationCollection.class);
citationCollectionIndexOps.ensureIndex(new Index().on("key", Sort.Direction.ASC).unique());
IndexOperations citationGorupIndexOps = mongoTemplate.indexOps(CitationGroup.class);
citationGorupIndexOps.ensureIndex(new Index().on("groupId", Sort.Direction.ASC).unique());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import edu.asu.diging.citesphere.core.exceptions.AccessForbiddenException;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void init() {
@Override
public void export(ExportType exportType, IUser user, String groupId, String collectionId)
throws GroupDoesNotExistException, ExportTypeNotSupportedException, ExportFailedException,
ExportTooBigException, ZoteroHttpStatusException, AccessForbiddenException {
ExportTooBigException, ZoteroHttpStatusException, AccessForbiddenException, DuplicateKeyException {

ICitationGroup group = groupManager.getGroup(user, groupId);
if (group == null) {
Expand Down Expand Up @@ -156,7 +157,7 @@ public void export(ExportType exportType, IUser user, String groupId, String col
@Override
public void distributedExport(ExportType exportType, IUser user, String groupId, String collectionId)
throws GroupDoesNotExistException, ExportTypeNotSupportedException, ExportFailedException,
ExportTooBigException, ZoteroHttpStatusException, AccessForbiddenException {
ExportTooBigException, ZoteroHttpStatusException, AccessForbiddenException, DuplicateKeyException {

ICitationGroup group = groupManager.getGroup(user, groupId);
if (group == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
Expand Down Expand Up @@ -199,7 +200,7 @@ public void updateCitation(ICitation citation, Set<IGilesUpload> checkedUploads,
citationManager.updateCitation(user, citation.getGroup(),
currentCitation);
} catch (ZoteroConnectionException | CitationIsOutdatedException
| ZoteroHttpStatusException | ZoteroItemCreationFailedException e) {
| ZoteroHttpStatusException | ZoteroItemCreationFailedException | DuplicateKeyException e) {
logger.error("Could not update citation.", e);
}
}
Expand All @@ -216,6 +217,8 @@ public ICitation getCurrentCitation(ICitation citation, IUser user) {
logger.error("Could not get citation.", e);
} catch (ZoteroHttpStatusException e) {
logger.error("Could not get citation.", e);
} catch (DuplicateKeyException e) {
logger.error("Duplicate key found.", e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -206,7 +207,7 @@ private void removeDeletedItems(DeletedZoteroElements deletedElements, GroupSync
}
}

private long retrieveCitations(IUser user, String groupId, List<String> keysToRetrieve) throws ZoteroHttpStatusException {
private long retrieveCitations(IUser user, String groupId, List<String> keysToRetrieve) throws ZoteroHttpStatusException, DuplicateKeyException {
try {
// wait 1 second to not send too many requests to Zotero
TimeUnit.SECONDS.sleep(1);
Expand Down Expand Up @@ -234,7 +235,7 @@ private long retrieveCollections(IUser user, String groupId, List<String> keysTo
return response.getContentVersion();
}

private void storeCitation(ICitation citation) {
private void storeCitation(ICitation citation) throws DuplicateKeyException {
Optional<ICitation> optional = citationStore.findById(citation.getKey());
if (optional.isPresent()) {
citationStore.delete((Citation) optional.get());
Expand Down
Loading