Skip to content

Commit

Permalink
Code complete.
Browse files Browse the repository at this point in the history
Missing to add the unit tests for the IssnManager
  • Loading branch information
Camelia-Orcid committed Mar 20, 2023
1 parent 3b326ba commit ac35fbf
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class IssnClient {

private static final Logger LOG = LoggerFactory.getLogger(IssnClient.class);

private static final String START_OF_STRING="\u0098";
private static final String STRING_TERMINATOR = "\u009C";

@Resource
private IssnPortalUrlBuilder issnPortalUrlBuilder;

Expand Down Expand Up @@ -77,7 +80,9 @@ private String getJsonDataFromIssnPortal(String issn) throws IOException, Interr
}

private String cleanText(String text) {
return text.replaceAll("\\p{C}", "");
return text.replaceAll("\\p{C}", "")
.replaceAll(START_OF_STRING,"")
.replaceAll(STRING_TERMINATOR, "");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
public class IssnLoadManagerImpl implements IssnLoadManager {

private static final Logger LOGGER = LoggerFactory.getLogger(IssnLoadManagerImpl.class);

@Resource
private IssnLoadSource issnLoadSource;

@Resource
private SlackManager slackManager;
Expand All @@ -24,17 +25,21 @@ public class IssnLoadManagerImpl implements IssnLoadManager {

@Value("${org.orcid.core.orgs.load.slackUser}")
private String slackUser;

@Value("${org.orcid.core.issn.source}")
private String issnSource;


@Override
public void loadIssn() {
try {
IssnLoadSource loadIssn = new IssnLoadSource();
loadIssn.loadIssn();
slackManager.sendAlert("Issn date succesfully updated for client XXXX", slackChannel, slackUser);
LOGGER.debug("Load ISSN for client : " + issnSource);
issnLoadSource.loadIssn(issnSource);
slackManager.sendAlert("Issn succesfully updated for client " + issnSource, slackChannel, slackUser);

} catch (Exception ex) {
slackManager.sendAlert("Error when running ISSN for client XXX ", slackChannel, slackUser);
LOGGER.error("Error when running ISSN for client" + issnSource, ex);
slackManager.sendAlert("Error when running ISSN for client " + issnSource, slackChannel, slackUser);

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.orcid.scheduler.loader.source.cli;

import org.orcid.scheduler.loader.manager.IssnLoadManager;
import org.orcid.scheduler.loader.manager.OrgLoadManager;
import org.orcid.scheduler.loader.source.OrgLoadSource;
import org.orcid.scheduler.loader.source.issn.IssnLoadSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class LoadDataForIssnSource {

private static final Logger LOG = LoggerFactory.getLogger(LoadDataForIssnSource.class);
private IssnLoadManager issnLoadManager;


private IssnLoadSource issnDataSource;

/**
* Setup our spring resources
*
*/
@SuppressWarnings({ "resource" })
private void init() {
ApplicationContext context = new ClassPathXmlApplicationContext("orcid-scheduler-context.xml");
issnLoadManager = (IssnLoadManager) context.getBean("issnLoadManager");
issnDataSource = (IssnLoadSource) context.getBean("issnDataSource");

}


public void loadIssn() {
issnLoadManager.loadIssn();
return;
}


public static void main(String[] args) {
LoadDataForIssnSource loadDataForIssnSource = new LoadDataForIssnSource();
loadDataForIssnSource.loadIssn();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import org.orcid.core.groupIds.issn.IssnClient;
import org.orcid.core.groupIds.issn.IssnData;
import org.orcid.core.groupIds.issn.IssnValidator;
Expand All @@ -16,10 +18,9 @@
import org.orcid.persistence.jpa.entities.InvalidIssnGroupIdRecordEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class IssnLoadSource {

private static final Logger LOG = LoggerFactory.getLogger(IssnLoadSource.class);
Expand All @@ -28,35 +29,39 @@ public class IssnLoadSource {

private static final int BATCH_SIZE = 30;

@Resource
private GroupIdRecordDao groupIdRecordDao;

@Resource(name="groupIdRecordDaoReadOnly")
private GroupIdRecordDao groupIdRecordDaoReadOnly;

@Resource
private GenericDao<InvalidIssnGroupIdRecordEntity, Long> invalidIssnGroupIdRecordDao;

@Resource(name="clientDetailsDaoReadOnly")
private ClientDetailsDao clientDetailsDaoReadOnly;

private ClientDetailsEntity orcidSource;

@Resource
private IssnValidator issnValidator;

@Resource
private IssnClient issnClient;

@Value("${org.orcid.core.issn.source}")
private String issnSource;


public void loadIssn() {
public void loadIssn(String issnSource) {

if (issnSource == null) {
throw new RuntimeException("Missing the configuration for ORCID source client details id check your environment config for org.orcid.core.issn.source");
throw new RuntimeException("Missing the ORCID source client details id");
}
orcidSource = clientDetailsDaoReadOnly.find(issnSource);
if (orcidSource == null) {
throw new RuntimeException("Client details entity not found for id " + issnSource);
}
this.init(issnSource);
LOG.debug("Loading ISSN for ORCID source client details id: " + issnSource);
this.updateIssnGroupIdRecords();
}

public static void main(String[] args) {
IssnLoadSource loadIssnData = new IssnLoadSource();
loadIssnData.loadIssn();
}

private void updateIssnGroupIdRecords() {
Date start = new Date();
List<GroupIdRecordEntity> issnEntities = groupIdRecordDaoReadOnly.getIssnRecordsNotModifiedSince(BATCH_SIZE, start);
Expand Down Expand Up @@ -111,20 +116,4 @@ private String getIssn(GroupIdRecordEntity issnEntity) {
return null;
}

@SuppressWarnings({ "resource", "unchecked" })
private void init(String orcidSourceClientDetailsId) {
ApplicationContext context = new ClassPathXmlApplicationContext("orcid-core-context.xml");
groupIdRecordDaoReadOnly = (GroupIdRecordDao) context.getBean("groupIdRecordDaoReadOnly");
groupIdRecordDao = (GroupIdRecordDao) context.getBean("groupIdRecordDao");
issnValidator = context.getBean(IssnValidator.class);
issnClient = context.getBean(IssnClient.class);
invalidIssnGroupIdRecordDao = (GenericDao<InvalidIssnGroupIdRecordEntity, Long>) context.getBean("invalidIssnGroupIdRecordDao");

ClientDetailsDao clientDetailsDaoReadOnly = (ClientDetailsDao) context.getBean("clientDetailsDaoReadOnly");
orcidSource = clientDetailsDaoReadOnly.find(orcidSourceClientDetailsId);
if (orcidSource == null) {
throw new RuntimeException("Client details entity not found for id " + orcidSourceClientDetailsId);
}
}

}
22 changes: 20 additions & 2 deletions orcid-scheduler-web/src/main/resources/orcid-scheduler-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<context:component-scan
base-package="org.orcid.scheduler.loader" />

<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="webhookManager" method="processWebhooks" cron="${org.orcid.scheduler.web.processWebhooks:25 25 0-2 * * *}"/>
<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="webhookManager" method="processWebhooks" cron="${org.orcid.scheduler.web.processWebhooks:25 25 0-2 * * *}"/>
<task:scheduled ref="statisticsManager" method="generateStatistics" cron="${org.orcid.scheduler.web.generateStats:0 0 0 * * FRI}"/>
<task:scheduled ref="orgDisambiguatedManager" method="processOrgsWithIncorrectPopularity" cron="${org.orcid.scheduler.web.processOrgsWithIncorrectPopularity:45 45 0-2 * * *}"/>
<task:scheduled ref="orgDisambiguatedManager" method="processOrgsForIndexing" cron="${org.orcid.scheduler.web.processOrgsForIndexing:55 55 0-2 * * *}"/>
Expand All @@ -34,6 +34,7 @@
<task:scheduled ref="orcidRecordIndexer" method="reindexRecordsOnS3" fixed-delay="${org.orcid.scheduler.web.s3UpdateDelaySeconds:900}000"/>
<task:scheduled ref="publicProfileValidator" method="processValidationCycle" cron="${org.orcid.scheduler.api.profile.validation.cronConfig:0 */10 * * * *}"/>
<task:scheduled ref="orgLoadManager" method="loadOrgs" cron="${org.orcid.scheduler.web.orgImportsCronConfig}" />
<task:scheduled ref="issnLoadManager" method="loadIssn" cron="${org.orcid.scheduler.web.loadIssnCronConfig:0 0 0 * * FRI"/>
</task:scheduled-tasks>

<task:scheduler id="scheduler" pool-size="${org.orcid.scheduler.tasks.pool_size:20}"/>
Expand Down Expand Up @@ -87,6 +88,7 @@
<bean id="rorOrgDataSource" class="org.orcid.scheduler.loader.source.ror.RorOrgLoadSource" />
<bean id="fundrefOrgDataSource" class="org.orcid.scheduler.loader.source.fundref.FundrefOrgLoadSource" />
<bean id="ringgoldOrgDataSource" class="org.orcid.scheduler.loader.source.ringgold.RinggoldOrgLoadSource" />
<bean id="issnDataSource" class="org.orcid.scheduler.loader.source.issn.IssnLoadSource" />

<bean id="jerseyClientHelper" class="org.orcid.utils.jersey.JerseyClientHelper">
<constructor-arg value="${org.orcid.utils.jersey.development_mode:false}"/>
Expand All @@ -112,5 +114,21 @@
<bean id="statisticsManager" class="org.orcid.core.stats.impl.StatisticsManagerImpl"/>

<bean id="orgLoadManager" class="org.orcid.scheduler.loader.manager.impl.OrgLoadManagerImpl"/>

<bean id="groupIdRecordManager" class="org.orcid.core.manager.impl.GroupIdRecordManagerImpl">
<property name="groupIdRecordDao" ref="groupIdRecordDao" />
</bean>

<bean id="groupIdRecordManagerReadOnly" class="org.orcid.core.manager.read_only.impl.GroupIdRecordManagerReadOnlyImpl">
<property name="groupIdRecordDao" ref="groupIdRecordDaoReadOnly" />
</bean>

<bean id="clientDetailsDao" class="org.orcid.persistence.dao.impl.ClientDetailsDaoImpl" />

<bean id="clientDetailsDaoReadOnly" class="org.orcid.persistence.dao.impl.ClientDetailsDaoImpl">
<property name="entityManager" ref="entityManagerReadOnly" />
</bean>

<bean id="issnLoadManager" class="org.orcid.scheduler.loader.manager.impl.IssnLoadManagerImpl"/>

</beans>
3 changes: 3 additions & 0 deletions properties/development.properties
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,6 @@ org.orcid.microservice.salesforce.token=X
# Account lockout
org.orcid.core.profile.lockout.threshhold=10
org.orcid.core.profile.lockout.window=5

# ISSN Loader Cron Configuration
org.orcid.scheduler.web.loadIssnCronConfig=0 0 0 * * FRI

0 comments on commit ac35fbf

Please sign in to comment.