refactored the remaining import methods that work with units
This commit is contained in:
parent
4ee2837c72
commit
4d4ac5bbba
src/main/java/se/su/dsv/scipro/io
@ -525,20 +525,30 @@ public class ImporterFacade {
|
|||||||
public void addUnitToSupervisor(PersonDTO supervisorDTO, UnitDTO unitDTO) {
|
public void addUnitToSupervisor(PersonDTO supervisorDTO, UnitDTO unitDTO) {
|
||||||
User supervisorUser = userDao.getUserByIdentifier(supervisorDTO.id);
|
User supervisorUser = userDao.getUserByIdentifier(supervisorDTO.id);
|
||||||
Employee supervisor = supervisorDao.getFrom(supervisorUser);
|
Employee supervisor = supervisorDao.getFrom(supervisorUser);
|
||||||
if (supervisor != null) {
|
if (supervisor != null){
|
||||||
List<Keyword> currentUnits = supervisor.getKeywords().getFiltered(keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
if (supervisor.getUnit()!=null){
|
||||||
//If supervisor is already assigned to a unit, remove to make sure only the latest unit is being added since we only allow one unit in Scipro.
|
|
||||||
//Supervisor is not going to be allowed to have more than one unit in the future, but some have two in Daisy at the moment.
|
|
||||||
if (!currentUnits.isEmpty()) {
|
|
||||||
logger.info(supervisor.getUser().getFullName() + " is already attached to a unit and this is being overwritten.");
|
logger.info(supervisor.getUser().getFullName() + " is already attached to a unit and this is being overwritten.");
|
||||||
supervisor.getKeywords().getAll().removeAll(currentUnits);
|
|
||||||
}
|
}
|
||||||
Keyword unitToAdd = keywordDao.getKeywordByIdentifierAndType(unitDTO.id, keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
Unit unitToAdd = unitService.findByIdentifier(unitDTO.getId());
|
||||||
logger.debug("Adding unit: " + unitToAdd.getKeyword() + " to supervisor: " + supervisor.getUser().getFullName());
|
logger.debug("Adding unit: " + unitToAdd.getTitle() + " to supervisor: " + supervisor.getUser().getFullName());
|
||||||
supervisor.getKeywords().getAll().add(unitToAdd);
|
supervisor.setUnit(unitToAdd);
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Can't find supervisor: " + supervisorDTO.id);
|
logger.debug("Can't find supervisor: " + supervisorDTO.id);
|
||||||
}
|
}
|
||||||
|
// if (supervisor != null) {
|
||||||
|
// List<Keyword> currentUnits = supervisor.getKeywords().getFiltered(keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
||||||
|
// //If supervisor is already assigned to a unit, remove to make sure only the latest unit is being added since we only allow one unit in Scipro.
|
||||||
|
// //Supervisor is not going to be allowed to have more than one unit in the future, but some have two in Daisy at the moment.
|
||||||
|
// if (!currentUnits.isEmpty()) {
|
||||||
|
// logger.info(supervisor.getUser().getFullName() + " is already attached to a unit and this is being overwritten.");
|
||||||
|
// supervisor.getKeywords().getAll().removeAll(currentUnits);
|
||||||
|
// }
|
||||||
|
// Keyword unitToAdd = keywordDao.getKeywordByIdentifierAndType(unitDTO.id, keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
||||||
|
// logger.debug("Adding unit: " + unitToAdd.getKeyword() + " to supervisor: " + supervisor.getUser().getFullName());
|
||||||
|
// supervisor.getKeywords().getAll().add(unitToAdd);
|
||||||
|
// } else {
|
||||||
|
// logger.debug("Can't find supervisor: " + supervisorDTO.id);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeLinkedResearchAreas(final User user, final Set<ResearchAreaDTO> areas) {
|
private void mergeLinkedResearchAreas(final User user, final Set<ResearchAreaDTO> areas) {
|
||||||
@ -653,11 +663,13 @@ public class ImporterFacade {
|
|||||||
for (Employee supervisor : currentSupervisors) {
|
for (Employee supervisor : currentSupervisors) {
|
||||||
if (!supervisorsWithRemoteUnit.contains(supervisor)) {
|
if (!supervisorsWithRemoteUnit.contains(supervisor)) {
|
||||||
logger.debug(supervisor.getNameAsString() + " does not have a remote unit. Searching for local units to remove.");
|
logger.debug(supervisor.getNameAsString() + " does not have a remote unit. Searching for local units to remove.");
|
||||||
List<Keyword> unitsToRemove = supervisor.getKeywords().getFiltered(keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
supervisor.setUnit(null);
|
||||||
if (!unitsToRemove.isEmpty()) {
|
logger.debug("Removed units from: " + supervisor.getNameAsString());
|
||||||
supervisor.getKeywords().getAll().removeAll(unitsToRemove);
|
// List<Keyword> unitsToRemove = supervisor.getKeywords().getFiltered(keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
||||||
logger.debug("Removed units from: " + supervisor.getNameAsString());
|
// if (!unitsToRemove.isEmpty()) {
|
||||||
}
|
// supervisor.getKeywords().getAll().removeAll(unitsToRemove);
|
||||||
|
// logger.debug("Removed units from: " + supervisor.getNameAsString());
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,8 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
importerFacade.addUnexistingUnitsAsKeywords(unitSet);
|
importerFacade.addUnexistingUnitsAsUnits(unitSet);
|
||||||
|
|
||||||
Set<PersonDTO> allSupervisorsOnUnits = new HashSet<PersonDTO>();
|
Set<PersonDTO> allSupervisorsOnUnits = new HashSet<PersonDTO>();
|
||||||
for (final UnitDTO unitDTO : unitSet) {
|
for (final UnitDTO unitDTO : unitSet) {
|
||||||
Set<PersonDTO> supervisorSet = fetchSupervisorsOnUnit(new HashMap<String, String>(), ApiClient.REQUEST_TYPE.GET, new UrlProcessor() {
|
Set<PersonDTO> supervisorSet = fetchSupervisorsOnUnit(new HashMap<String, String>(), ApiClient.REQUEST_TYPE.GET, new UrlProcessor() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user