added new entity for research areas instead of using keywords for everything. also made appropriate changes to importer facade
This commit is contained in:
parent
0bc3128272
commit
49a33cdfe6
src/main/java/se/su/dsv/scipro
data/dataobjects
io/facade
springdata
@ -0,0 +1,54 @@
|
||||
package se.su.dsv.scipro.data.dataobjects;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import se.su.dsv.scipro.dataproviders.SortableField;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="researcharea")
|
||||
@Cacheable(true)
|
||||
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
|
||||
public class ResearchArea extends LazyDeletableDomainObject {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Column(unique=true)
|
||||
private Long identifier;
|
||||
|
||||
@Column(length=255)
|
||||
@Basic(optional=false)
|
||||
@SortableField
|
||||
private String title;
|
||||
|
||||
public ResearchArea(){}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(Long identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
}
|
@ -44,6 +44,7 @@ import se.su.dsv.scipro.match.dao.interfaces.KeywordTypeDao;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.SupervisorDao;
|
||||
import se.su.dsv.scipro.match.dataobject.Keyword;
|
||||
import se.su.dsv.scipro.springdata.services.MessageBoardService;
|
||||
import se.su.dsv.scipro.springdata.services.ResearchAreaService;
|
||||
import se.su.dsv.scipro.springdata.services.UnitService;
|
||||
|
||||
/**
|
||||
@ -55,7 +56,8 @@ public class ImporterFacade {
|
||||
|
||||
@Autowired
|
||||
private UnitService unitService;
|
||||
|
||||
@Autowired
|
||||
private ResearchAreaService researchAreaService;
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
@Autowired
|
||||
@ -543,32 +545,34 @@ public class ImporterFacade {
|
||||
|
||||
private void mergeLinkedResearchAreas(final User user, final Set<ResearchAreaDTO> areas) {
|
||||
for (final ResearchAreaDTO researchAreaDTO : areas) {
|
||||
Keyword area = keywordDao.getKeywordByIdentifierAndType(researchAreaDTO.id, keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA));
|
||||
if (area == null) {
|
||||
//Keyword area = keywordDao.getKeywordByIdentifierAndType(researchAreaDTO.id, keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA));
|
||||
ResearchArea area = researchAreaService.findByIdentifier(researchAreaDTO.id);
|
||||
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 = new ResearchArea();
|
||||
area.setTitle(researchAreaDTO.name);
|
||||
area.setIdentifier(researchAreaDTO.id);
|
||||
area = keywordDao.save(area);
|
||||
area = researchAreaService.save(area);
|
||||
} else {
|
||||
logger.info("Research area " + area.getKeyword() + " already exists, skipping");
|
||||
logger.info("Research area " + area.getTitle() + " already exists, skipping");
|
||||
}
|
||||
addResearchAreaToUser(user, area);
|
||||
}
|
||||
}
|
||||
|
||||
private void addResearchAreaToUser(User user, Keyword area) {
|
||||
private void addResearchAreaToUser(User user, ResearchArea area) {
|
||||
Employee supervisor = supervisorDao.getFrom(user);
|
||||
logger.info("Adding research area: " + area.getKeyword() + " to supervisor " + supervisor.getUser().getFullName());
|
||||
supervisor.getKeywords().getAll().add(area);
|
||||
logger.info("Adding research area: " + area.getTitle() + " to supervisor " + supervisor.getUser().getFullName());
|
||||
//supervisor.getKeywords().getAll().add(area);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addUnexistingResearchAreas(final Set<ResearchAreaDTO> areas) {
|
||||
final Set<Keyword> currentAreas = keywordDao.getKeywords(keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA), true);
|
||||
final Set<ResearchArea> currentAreas = researchAreaService.findAllAsSet();
|
||||
final Set<ResearchAreaDTO> remoteAreas = new HashSet<ResearchAreaDTO>(areas);
|
||||
final Set<Keyword> areasToRemove = new HashSet<Keyword>();
|
||||
final Set<ResearchArea> areasToRemove = new HashSet<ResearchArea>();
|
||||
//Compare remote with database
|
||||
for (Keyword currentArea : currentAreas) {
|
||||
for (ResearchArea currentArea : currentAreas) {
|
||||
ResearchAreaDTO translatedArea = dtoFromAreaKeyword(currentArea);
|
||||
if (!remoteAreas.contains(translatedArea)) {
|
||||
logger.info("Area " + translatedArea.getName() + " does not exist on remote, preparing to remove.");
|
||||
@ -576,26 +580,27 @@ public class ImporterFacade {
|
||||
}
|
||||
}
|
||||
//Delete areas that not exist on remote
|
||||
for (Keyword areaToRemove : areasToRemove) {
|
||||
keywordDao.delete(areaToRemove);
|
||||
logger.debug("Deleted research area: " + areaToRemove.getKeyword() + " since it has been removed from remote system");
|
||||
for (ResearchArea areaToRemove : areasToRemove) {
|
||||
researchAreaService.deleteArea(areaToRemove);
|
||||
logger.info("Deleted research area: " + areaToRemove.getTitle() + " since it has been removed from remote system");
|
||||
}
|
||||
//Add areas to database
|
||||
for (final ResearchAreaDTO researchAreaDTO : remoteAreas) {
|
||||
Keyword area = keywordDao.getKeywordByIdentifierAndType(researchAreaDTO.id, keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA));
|
||||
ResearchArea area = researchAreaService.findByIdentifier(researchAreaDTO.id);
|
||||
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 = new ResearchArea();
|
||||
area.setTitle(researchAreaDTO.name);
|
||||
area.setIdentifier(researchAreaDTO.id);
|
||||
area = keywordDao.save(area);
|
||||
} else if (!area.getKeyword().equals(researchAreaDTO.name)) {
|
||||
logger.info("Research area " + area.getKeyword() + " has changed name, renaming to: " + researchAreaDTO.name);
|
||||
area.setKeyword(researchAreaDTO.name);
|
||||
area = researchAreaService.save(area);
|
||||
} else if (!area.getTitle().equals(researchAreaDTO.name)) {
|
||||
logger.info("Research area " + area.getTitle() + " has changed name, renaming to: " + researchAreaDTO.name);
|
||||
area.setTitle(researchAreaDTO.name);
|
||||
} else {
|
||||
logger.info("Research area " + area.getKeyword() + " already exists, skipping");
|
||||
logger.info("Research area " + area.getTitle() + " already exists, skipping");
|
||||
}
|
||||
if (researchAreaDTO.active.equals("false")) {
|
||||
logger.info(area.getKeyword() + " is inactivated on remote system.");
|
||||
logger.info(area.getTitle() + " is inactivated on remote system.");
|
||||
area.setDeleted(true);
|
||||
}
|
||||
}
|
||||
@ -669,13 +674,7 @@ public class ImporterFacade {
|
||||
}
|
||||
}
|
||||
|
||||
private UnitDTO dtoFromUnitKeyword(final Keyword unit) {
|
||||
UnitDTO dto = new UnitDTO();
|
||||
dto.setName(unit.getKeyword());
|
||||
if (unit.getIdentifier() != null)
|
||||
dto.setId(unit.getIdentifier());
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
||||
private UnitDTO dtoFromUnit(final Unit unit) {
|
||||
UnitDTO dto = new UnitDTO();
|
||||
@ -685,9 +684,9 @@ public class ImporterFacade {
|
||||
return dto;
|
||||
}
|
||||
|
||||
private ResearchAreaDTO dtoFromAreaKeyword(final Keyword area) {
|
||||
private ResearchAreaDTO dtoFromAreaKeyword(final ResearchArea area) {
|
||||
ResearchAreaDTO dto = new ResearchAreaDTO();
|
||||
dto.setName(area.getKeyword());
|
||||
dto.setName(area.getTitle());
|
||||
if (area.getIdentifier() != null)
|
||||
dto.setId(area.getIdentifier());
|
||||
return dto;
|
||||
|
@ -0,0 +1,14 @@
|
||||
package se.su.dsv.scipro.springdata.repos;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import se.su.dsv.scipro.data.dataobjects.ResearchArea;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public interface ResearchAreaRepo extends JpaRepository<ResearchArea, Long>, QueryDslPredicateExecutor<ResearchArea> {
|
||||
|
||||
public ResearchArea findByIdentifier(Long identifier);
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package se.su.dsv.scipro.springdata.serviceimpls;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import se.su.dsv.scipro.data.dataobjects.ResearchArea;
|
||||
import se.su.dsv.scipro.springdata.repos.ResearchAreaRepo;
|
||||
import se.su.dsv.scipro.springdata.services.ResearchAreaService;
|
||||
|
||||
|
||||
|
||||
@Service ( "researchareaService" )
|
||||
@Transactional ( readOnly = true )
|
||||
public class ResearchAreaServiceImpl extends AbstractQueryService<ResearchArea, Long> implements ResearchAreaService {
|
||||
|
||||
@Resource
|
||||
private ResearchAreaRepo researchAreaRepo;
|
||||
|
||||
@Autowired
|
||||
public ResearchAreaServiceImpl(
|
||||
@Qualifier("researchAreaRepo")
|
||||
ResearchAreaRepo researchAreaRepo) {
|
||||
super(researchAreaRepo, researchAreaRepo);
|
||||
System.out.println("ResearchAreaServiceImpl instantiating...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResearchArea findByIdentifier(Long identifier) {
|
||||
return researchAreaRepo.findByIdentifier(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResearchArea> findAllAsSet() {
|
||||
return new HashSet<ResearchArea>(researchAreaRepo.findAll());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResearchArea> findAllAsList() {
|
||||
return researchAreaRepo.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteArea(ResearchArea area) {
|
||||
researchAreaRepo.delete(area);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package se.su.dsv.scipro.springdata.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import se.su.dsv.scipro.data.dataobjects.ResearchArea;
|
||||
|
||||
/**
|
||||
* @author: fred-fri
|
||||
* date: 2012 03 26
|
||||
*/
|
||||
public interface ResearchAreaService extends GenericService<ResearchArea, Long>, QueryService<ResearchArea, Long> {
|
||||
|
||||
public ResearchArea findByIdentifier(Long identifier);
|
||||
public Set<ResearchArea> findAllAsSet();
|
||||
public List<ResearchArea> findAllAsList();
|
||||
void deleteArea(ResearchArea area);
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user