Revision 49828
Added by Panagiotis Kanakakis over 6 years ago
RequestManagerImpl.java | ||
---|---|---|
59 | 59 |
@Autowired |
60 | 60 |
private PublisherManager publisherManager; |
61 | 61 |
|
62 |
|
|
62 | 63 |
@Value("${goldoa.sendCoordinatorEmails}") |
63 | 64 |
private String sendCoordinatorEmails ;//= false; |
64 | 65 |
@Value("${goldoa.sendEvaEmail}") |
... | ... | |
66 | 67 |
@Value("${goldoa.evaEmail}") |
67 | 68 |
private String evaEmail;// = null; |
68 | 69 |
|
69 |
private Log logger = LogFactory.getLog(RequestManagerImpl.class);
|
|
70 |
private Log LOGGER = LogFactory.getLog(RequestManagerImpl.class);
|
|
70 | 71 |
|
71 | 72 |
@Override |
72 | 73 |
public Request saveRequest(final Request request) { |
... | ... | |
649 | 650 |
@Override |
650 | 651 |
@Transactional(propagation = Propagation.REQUIRED , rollbackFor = {PersonManagerException.class, |
651 | 652 |
ManagerException.class,ParseException.class,Exception.class}) |
652 |
public void importCSV(String csv) throws PersonManagerException, ManagerException, ParseException { |
|
653 |
public void importCSV(String csv) throws PersonManagerException, ManagerException, ParseException, OrganizationManagerException {
|
|
653 | 654 |
|
654 | 655 |
String linesWithHeader[] = csv.split("\\r?\\n"); |
655 | 656 |
String lines[] = Arrays.copyOfRange(linesWithHeader,1,linesWithHeader.length); |
656 | 657 |
for(String str : lines){ |
657 | 658 |
String line[] = str.split(","); |
658 |
String userEmail = line.length>0?line[0].trim():null; |
|
659 |
String grant = line.length>1?line[1].trim():null; |
|
660 |
String doi = line.length>2?line[2].trim():null; |
|
661 |
String acceptanceDate = line.length>3?line[3].trim():null; |
|
662 |
String identifierType = line.length>4?line[4].trim():null; |
|
663 |
String identifierValue = line.length>5?line[5].trim():null; |
|
664 |
String apc = line.length>6?line[6].trim():null; |
|
665 |
String apcCurrency = line.length>7?line[7].trim():null; |
|
666 |
String discount = line.length>8?line[8].trim():null; |
|
667 | 659 |
|
668 |
importRequestFromCSV(userEmail,grant,doi,acceptanceDate, |
|
669 |
identifierType,identifierValue,apc, |
|
670 |
apcCurrency,discount); |
|
660 |
String firstname = !line[0].equals("")?line[0].trim():null; |
|
661 |
String lastname = !line[1].equals("")?line[1].trim():null; |
|
662 |
String email = !line[2].equals("")?line[2].trim():null; |
|
663 |
String organization = !line[3].equals("")?line[3].trim():null; |
|
664 |
|
|
665 |
String grant = !line[4].equals("")?line[4].trim():null; |
|
666 |
String doi = !line[5].equals("")?line[5].trim():null; |
|
667 |
String acceptanceDate = !line[6].equals("")?line[6].trim():null; |
|
668 |
String identifierType = !line[7].equals("")?line[7].trim():null; |
|
669 |
String identifierValue = !line[8].equals("")?line[8].trim():null; |
|
670 |
String apc = !line[9].equals("")?line[9].trim():"0"; |
|
671 |
String apcCurrency = !line[10].equals("")?line[10].trim():null; |
|
672 |
String discount = line.length>11?line[11].trim():"0"; |
|
673 |
|
|
674 |
importRequestFromCSV(firstname,lastname,organization,email, |
|
675 |
grant,doi,acceptanceDate, identifierType, |
|
676 |
identifierValue,apc, apcCurrency,discount); |
|
671 | 677 |
} |
672 | 678 |
} |
673 | 679 |
|
674 | 680 |
|
675 |
private void importRequestFromCSV(String userEmail, String grant, String doi, String acceptanceDate, |
|
681 |
private void importRequestFromCSV(String firstname, String lastname, String organization, String email, String grant, |
|
682 |
String doi, String acceptanceDate, |
|
676 | 683 |
String identifierType, String identifierValue, |
677 |
String apc, String apcCurrency,String discount) |
|
678 |
throws PersonManagerException, ParseException, ManagerException { |
|
684 |
String apc, String apcCurrency, String discount)
|
|
685 |
throws PersonManagerException, ParseException, ManagerException, OrganizationManagerException {
|
|
679 | 686 |
|
687 |
Organization org = (Organization) organizationManager.search(organization).get(0); |
|
688 |
if(org == null){ |
|
689 |
LOGGER.debug("Organization " + organization + " not exists!"); |
|
690 |
throw new OrganizationManagerException(OrganizationManagerException.ErrorCause.NOT_EXISTS); |
|
691 |
} |
|
692 |
|
|
693 |
|
|
680 | 694 |
User user = null; |
681 | 695 |
try { |
682 |
user = userManager.getByEmail(userEmail);
|
|
696 |
user = userManager.getByEmail(email);
|
|
683 | 697 |
} catch (PersonManagerException e) { |
684 |
e.printStackTrace(); |
|
685 |
throw new PersonManagerException("User with email " + userEmail + " not exists!"); |
|
698 |
LOGGER.debug("User with email : " + email + "not exists!" ,e); |
|
699 |
LOGGER.debug("Creating new inactive user with default password!"); |
|
700 |
user = userManager.createInActiveResearcher(firstname,lastname,email,org); |
|
686 | 701 |
} |
687 | 702 |
|
688 | 703 |
List<Object> rs = projectManager.search(grant); |
689 | 704 |
Project project = null; |
690 | 705 |
if(rs.size() == 0) { |
691 |
System.out.println("Project with specified grant("+grant+") not found!");
|
|
706 |
LOGGER.debug("Project with specified grant("+grant+") not found!");
|
|
692 | 707 |
throw new ManagerException("Project with specified grant("+grant+") not found!"); |
693 | 708 |
}else |
694 | 709 |
project = (Project) rs.get(0); |
... | ... | |
697 | 712 |
try { |
698 | 713 |
publication = publicationManager.resolveDOI(doi); |
699 | 714 |
} catch (ManagerException e) { |
700 |
e.printStackTrace();
|
|
715 |
LOGGER.debug("Requested doi("+doi+") not found!" , e);
|
|
701 | 716 |
throw new ManagerException("Requested doi("+doi+") not found!"); |
702 | 717 |
} |
703 | 718 |
|
... | ... | |
711 | 726 |
publicationManager.savePublication(publication); |
712 | 727 |
|
713 | 728 |
|
714 |
Request request = requestDAO.getRequestFromCSV(user,project,publication,acceptanceDate, |
|
715 |
identifierType,identifierValue,apc, |
|
716 |
apcCurrency,discount); |
|
729 |
Request request = requestDAO.getRequestFromCSV(user,project,publication,org, |
|
730 |
acceptanceDate, identifierType,identifierValue,apc, apcCurrency,discount); |
|
717 | 731 |
|
718 | 732 |
request.setId("L" + new SimpleDateFormat("yyyyMMdd-").format(new Date()) + requestDAO.getRequestId()); |
719 | 733 |
request.setEligibility(Eligibility.OK); |
720 | 734 |
|
735 |
|
|
721 | 736 |
if(!request.getEligibility().getStatus().equals(Eligibility.Status.OK)) |
722 | 737 |
throw new ManagerException("Request for project "+grant+" is not eligible!"); |
723 | 738 |
requestDAO.saveRequest(request); |
Also available in: Unified diff
1. Change log4j properties file.
2. Add method to create researcher from bulk import csv
3. Change csv handling on bulk import
4. Modify request unit test.