added identifier from daisy to keywords to avoid duplicates.
This commit is contained in:
parent
3527e2cbf9
commit
9b2f7c568d
src/main/java/se/su/dsv/scipro
io/facade
match
@ -433,10 +433,11 @@ public class ImporterFacade {
|
||||
|
||||
private void mergeLinkedResearchAreas(final User user, final Set<ResearchAreaDTO> areas){
|
||||
for(final ResearchAreaDTO researchAreaDTO : areas){
|
||||
Keyword area = keywordDao.getKeywordByNameAndType(researchAreaDTO.name, keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA));
|
||||
Keyword area = keywordDao.getKeywordByIdentifierAndType(researchAreaDTO.id, keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA));
|
||||
if(area == null){
|
||||
logger.info("External research area: '"+researchAreaDTO+"' has no local representation, creating");
|
||||
area = new Keyword(researchAreaDTO.name, keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA));
|
||||
area.setIdentifier(researchAreaDTO.id);
|
||||
area = keywordDao.save(area);
|
||||
} else {
|
||||
logger.info("Research area " + area.getKeyword() + " already exists, skipping");
|
||||
@ -456,10 +457,11 @@ public class ImporterFacade {
|
||||
@Transactional
|
||||
public void addUnexistingResearchAreas(final Set<ResearchAreaDTO> areas) {
|
||||
for(final ResearchAreaDTO researchAreaDTO : areas){
|
||||
Keyword area = keywordDao.getKeywordByNameAndType(researchAreaDTO.name, keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA));
|
||||
Keyword area = keywordDao.getKeywordByIdentifierAndType(researchAreaDTO.id, keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA));
|
||||
if(area == null){
|
||||
logger.info("External research area: '"+researchAreaDTO+"' has no local representation, creating");
|
||||
area = new Keyword(researchAreaDTO.name, keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA));
|
||||
area.setIdentifier(researchAreaDTO.id);
|
||||
area = keywordDao.save(area);
|
||||
} else {
|
||||
logger.info("Research area " + area.getKeyword() + " already exists, skipping");
|
||||
|
@ -13,6 +13,8 @@ public interface KeywordDao extends LazyDeleteDao<Keyword>{
|
||||
|
||||
public List<Keyword> findAllFromType(KeywordType kt, boolean includeDeleted);
|
||||
|
||||
Keyword getKeywordByIdentifierAndType(final Long externalIdentifier, KeywordType type);
|
||||
Keyword getKeywordByNameAndType(String keywordName, KeywordType type);
|
||||
|
||||
|
||||
}
|
||||
|
@ -83,6 +83,23 @@ public class KeywordDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<Keyword> imple
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Keyword getKeywordByIdentifierAndType(final Long externalIdentifier, final KeywordType type) {
|
||||
return getJpaTemplate().execute(new JpaCallback<Keyword>() {
|
||||
public Keyword doInJpa(EntityManager em) throws PersistenceException {
|
||||
TypedQuery<Keyword> query = em.createQuery("SELECT x FROM "+domainClassString+" x WHERE x.type = :type AND x.identifier = :identifier", domainClass);
|
||||
query.setParameter("type", type);
|
||||
query.setParameter("identifier", externalIdentifier);
|
||||
try {
|
||||
return query.getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Keyword getKeywordByNameAndType(final String keywordName, final KeywordType type) {
|
||||
return getJpaTemplate().execute(new JpaCallback<Keyword>() {
|
||||
@ -100,5 +117,4 @@ public class KeywordDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<Keyword> imple
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package se.su.dsv.scipro.match.dataobject;
|
||||
|
||||
import javax.persistence.Cacheable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
@ -25,6 +26,9 @@ public class Keyword extends LazyDeletableDomainObject {
|
||||
|
||||
private String keyword;
|
||||
|
||||
@Column(unique=true)
|
||||
private Long identifier;
|
||||
|
||||
@ManyToOne
|
||||
private KeywordType type;
|
||||
|
||||
@ -57,7 +61,13 @@ public class Keyword extends LazyDeletableDomainObject {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setIdentifier(Long identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public Long getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user