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

Story/cite 177: There needs to be an import from Crossref #271

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2b1ce80
[CITE-177] setup and created service to query crossref
jdamerow Jun 20, 2022
557f26f
[CITE-177] front end and backend changes to start crossref import
jdamerow Jul 6, 2022
dacc76f
[CITE-177] Clearing the div before fetching the results
PratikGiri Mar 7, 2023
709aa15
[CITE-177] Added group ID to Kafka message
PradnyaC11 Apr 26, 2024
4791750
[CITE-177] Updated JobInfoController to add groupId to response
PradnyaC11 Apr 30, 2024
0e74de6
[CITE-177] Added test cases for ImportCrossrefJobManager & ImportCros…
PradnyaC11 Jun 12, 2024
90e71d2
Merge branch 'develop' into story/CITE-177
PradnyaC11 Jun 13, 2024
8faa45c
[CITE-177] Updated crossref.html to show alert
PradnyaC11 Jun 13, 2024
8b219a6
Merge branch 'story/CITE-177' of https://github.com/diging/citesphere…
PradnyaC11 Jun 13, 2024
836705d
[CITE-177] Addressing the PR comments
PradnyaC11 Jul 2, 2024
5495a62
[CITE-177] Changed crossref-connect-version in pom.xml
PradnyaC11 Jul 2, 2024
d9ad221
[CITE-177] Addressed PR comments
PradnyaC11 Jul 11, 2024
3fffd0e
[CITE-177] Addressing PR comments
PradnyaC11 Aug 1, 2024
7324581
[CITE-177] Addressing PR comments
PradnyaC11 Aug 2, 2024
fc238b9
[CITE-177] Addressed PR comments
PradnyaC11 Sep 6, 2024
4c7f0d9
[CITE-177] Corrected indentation for crossref.html
PradnyaC11 Sep 6, 2024
4c8c5ac
Merge branch 'story/CITE-177' of https://github.com/diging/citesphere…
PradnyaC11 Sep 6, 2024
ba4a409
[CITE-177] Addressed PR comments
PradnyaC11 Sep 20, 2024
baf03ad
[CITE-177] Addressing PR comments
PradnyaC11 Oct 25, 2024
9afba45
[CITE-177] Addressed PR comments
PradnyaC11 Oct 28, 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
9 changes: 8 additions & 1 deletion citesphere/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
<javers.version>6.2.3</javers.version>
<spring.kafka.version>2.2.6.RELEASE</spring.kafka.version>
<spring-social-zotero.version>0.12</spring-social-zotero.version>
<citesphere.messages.version>0.4</citesphere.messages.version>
<citesphere.messages.version>0.5</citesphere.messages.version>
<citesphere.model.version>1.19</citesphere.model.version>
<crossref-connect-version>0.2</crossref-connect-version>


<admin.password>$2a$04$oQo44vqcDIFRoYKiAXoNheurzkwX9dcNmowvTX/hsWuBMwijqn44i</admin.password>

Expand Down Expand Up @@ -157,6 +159,11 @@
<artifactId>citesphere-model</artifactId>
<version>${citesphere.model.version}</version>
</dependency>
<dependency>
<groupId>edu.asu.diging</groupId>
<artifactId>crossref-connect</artifactId>
<version>${crossref-connect-version}</version>
</dependency>

<!-- Spring -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package edu.asu.diging.citesphere.api.v1.user;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
Expand All @@ -8,13 +13,11 @@
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

import edu.asu.diging.citesphere.core.export.IExportTaskManager;
import edu.asu.diging.citesphere.core.model.IZoteroToken;
import edu.asu.diging.citesphere.core.model.export.IExportTask;
import edu.asu.diging.citesphere.core.model.jobs.IExportJob;
import edu.asu.diging.citesphere.core.model.jobs.IImportCrossrefJob;
import edu.asu.diging.citesphere.core.model.jobs.IJob;
import edu.asu.diging.citesphere.core.model.jobs.IUploadJob;
import edu.asu.diging.citesphere.core.service.jobs.IUploadJobManager;
Expand Down Expand Up @@ -54,24 +57,26 @@ public ResponseEntity<String> getProfile(@RequestHeader HttpHeaders headers) {
IJob job = jobManager.findJob(tokenContents.getJobId());
IZoteroToken zoteroToken = tokenManager.getToken(userManager.findByUsername(job.getUsername()));

ObjectMapper mapper = new ObjectMapper();
ObjectNode node = mapper.createObjectNode();
Map<String, Object> node = new HashMap<>();
node.put("zotero", zoteroToken.getToken());
node.put("zoteroId", zoteroToken.getUserId());
node.put("username", job.getUsername());
// FIXME: ugly, needs better solution
if (job instanceof IUploadJob) {
node.put("groupId", ((IUploadJob)job).getCitationGroup());
}
if (job instanceof IExportJob) {
} else if (job instanceof IExportJob) {
IExportTask exportTask = exportTaskManager.get(((IExportJob)job).getTaskId());
node.put("groupId", exportTask.getGroupId());
node.put("collectionId", exportTask.getCollectionId());
node.put("exportType", exportTask.getExportType().name());
node.put("taskId", exportTask.getId());
} else if (job instanceof IImportCrossrefJob) {
List<String> doisList = new ArrayList<>();
((IImportCrossrefJob)job).getDois().forEach(d -> doisList.add(d));
node.put("dois", doisList);
node.put("groupId", ((IImportCrossrefJob)job).getCitationGroup());
Copy link
Member

Choose a reason for hiding this comment

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

I think it's time to clean this up. let's create a map that maps object type to methods that are then called here.

Copy link
Member

Choose a reason for hiding this comment

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

this still

}


return new ResponseEntity<>(node.toString(), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.asu.diging.citesphere.core.model.jobs;

import java.util.List;

import edu.asu.diging.citesphere.model.bib.ICitationGroup;

public interface IImportCrossrefJob extends IJob {

/**
* Get the DOIs of the resources to be imported from Crossref.
* @return list of resources to be imported
*/
List<String> getDois();

void setDois(List<String> dois);

void setCitationGroup(String citationGroup);

String getCitationGroup();

ICitationGroup getCitationGroupDetail();

void setCitationGroupDetail(ICitationGroup citationGroupDetail);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package edu.asu.diging.citesphere.core.model.jobs.impl;

import java.util.List;

import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Transient;

import edu.asu.diging.citesphere.core.model.jobs.IImportCrossrefJob;
import edu.asu.diging.citesphere.model.bib.ICitationGroup;

@Entity
public class ImportCrossrefJob extends Job implements IImportCrossrefJob {

@ElementCollection
private List<String> dois;
private String citationGroup;
@Transient
private ICitationGroup citationGroupDetail;

/**
* Get the DOIs of the resources to be imported from Crossref.
* @return list of resources to be imported
*/
@Override
public List<String> getDois() {
return dois;
}

@Override
public void setDois(List<String> dois) {
this.dois = dois;
}

@Override
public String getCitationGroup() {
return citationGroup;
}

@Override
public void setCitationGroup(String citationGroup) {
this.citationGroup = citationGroup;
}

@Override
public ICitationGroup getCitationGroupDetail() {
return citationGroupDetail;
}

@Override
public void setCitationGroupDetail(ICitationGroup citationGroupDetail) {
this.citationGroupDetail = citationGroupDetail;
}




}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.asu.diging.citesphere.core.model.jobs.impl;

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
Expand Down Expand Up @@ -42,7 +43,7 @@ public class Job implements IJob {

@JsonIgnore
@OneToMany(cascade=CascadeType.ALL)
private List<JobPhase> phases;
private List<JobPhase> phases = new ArrayList<>();


/* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package edu.asu.diging.citesphere.core.repository.jobs;

import org.springframework.data.repository.CrudRepository;

import edu.asu.diging.citesphere.core.model.jobs.impl.ImportCrossrefJob;

public interface ImportCrossrefJobRepository extends CrudRepository<ImportCrossrefJob, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package edu.asu.diging.citesphere.core.service.crossref;

import java.io.IOException;
import java.util.List;

import edu.asu.diging.crossref.exception.RequestFailedException;
import edu.asu.diging.crossref.model.Item;

public interface CrossrefService {

List<Item> search(String query, int page) throws RequestFailedException, IOException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package edu.asu.diging.citesphere.core.service.crossref.impl;

import java.io.IOException;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;

import edu.asu.diging.citesphere.core.service.crossref.CrossrefService;
import edu.asu.diging.crossref.exception.RequestFailedException;
import edu.asu.diging.crossref.model.Item;
import edu.asu.diging.crossref.service.CrossrefConfiguration;
import edu.asu.diging.crossref.service.CrossrefWorksService;
import edu.asu.diging.crossref.service.impl.CrossrefWorksServiceImpl;

@Service
@PropertySource("classpath:config.properties")
public class CrossrefServiceImpl implements CrossrefService {

@Value("${_crossref_default_pagesize}")
private int defaultPageSize;

private CrossrefWorksService service;

@PostConstruct
public void init() {
service = new CrossrefWorksServiceImpl(CrossrefConfiguration.getDefaultConfig());
}


@Override
public List<Item> search(String query, int page) throws RequestFailedException, IOException {
return service.search(query, defaultPageSize, (page-1)*defaultPageSize);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package edu.asu.diging.citesphere.core.service.jobs;

import java.util.List;

import edu.asu.diging.citesphere.core.exceptions.GroupDoesNotExistException;
import edu.asu.diging.citesphere.core.model.jobs.IImportCrossrefJob;
import edu.asu.diging.citesphere.user.IUser;

public interface IImportCrossrefJobManager {

IImportCrossrefJob createJob(IUser user, String groupId, List<String> dois) throws GroupDoesNotExistException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package edu.asu.diging.citesphere.core.service.jobs.impl;

import java.time.OffsetDateTime;
import java.util.List;

import javax.transaction.Transactional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;

import edu.asu.diging.citesphere.core.exceptions.GroupDoesNotExistException;
import edu.asu.diging.citesphere.core.exceptions.MessageCreationException;
import edu.asu.diging.citesphere.core.kafka.IKafkaRequestProducer;
import edu.asu.diging.citesphere.core.model.jobs.IImportCrossrefJob;
import edu.asu.diging.citesphere.core.model.jobs.JobStatus;
import edu.asu.diging.citesphere.core.model.jobs.impl.ImportCrossrefJob;
import edu.asu.diging.citesphere.core.model.jobs.impl.JobPhase;
import edu.asu.diging.citesphere.core.repository.jobs.ImportCrossrefJobRepository;
import edu.asu.diging.citesphere.core.service.IGroupManager;
import edu.asu.diging.citesphere.core.service.jobs.IImportCrossrefJobManager;
import edu.asu.diging.citesphere.core.service.jwt.IJwtTokenService;
import edu.asu.diging.citesphere.messages.KafkaTopics;
import edu.asu.diging.citesphere.messages.model.KafkaJobMessage;
import edu.asu.diging.citesphere.model.bib.ICitationGroup;
import edu.asu.diging.citesphere.user.IUser;

@Service
@Transactional
@PropertySource("classpath:/config.properties")
public class ImportCrossrefJobManager implements IImportCrossrefJobManager {

private final Logger logger = LoggerFactory.getLogger(getClass());

@Value("${_job_page_size}")
private int jobPageSize;

@Autowired
private IGroupManager groupManager;

@Autowired
private ImportCrossrefJobRepository jobRepo;

@Autowired
private IKafkaRequestProducer kafkaProducer;

@Autowired
private IJwtTokenService tokenService;

@Override
public IImportCrossrefJob createJob(IUser user, String groupId, List<String> dois) throws GroupDoesNotExistException {
ICitationGroup group = groupManager.getGroup(user, groupId);
if (group == null) {
throw new GroupDoesNotExistException("Group does not exists");
}

ImportCrossrefJob job = new ImportCrossrefJob();
job.setCreatedOn(OffsetDateTime.now());
job.setUsername(user.getUsername());
job.setDois(dois);
job.setCitationGroup(groupId);
job.setStatus(JobStatus.PREPARED);
jobRepo.save(job);

String token = tokenService.generateJobApiToken(job);
try {
kafkaProducer.sendRequest(new KafkaJobMessage(token), KafkaTopics.REFERENCES_IMPORT_CROSSREF_TOPIC);
} catch (MessageCreationException e) {
logger.error("Could not send Kafka message.", e);
job.setStatus(JobStatus.FAILURE);
job.getPhases().add(new JobPhase(JobStatus.FAILURE, e.getMessage()));
jobRepo.save(job);
}

return job;
}
}
Loading