Merge branch 'unitImportFix' into develop
* unitImportFix: units is now being removed from scipro employees that does not have a remote unit
This commit is contained in:
commit
5a340fa896
src/main/java/se/su/dsv/scipro/io
@ -527,6 +527,30 @@ public class ImporterFacade {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeUnitFromSupervisorsNotInSet(Set<PersonDTO> supervisorSet) {
|
||||||
|
final Set<Employee> supervisorsWithRemoteUnit = new HashSet<Employee>();
|
||||||
|
final Set<Employee> currentSupervisors = new HashSet<Employee>(supervisorDao.findAll());
|
||||||
|
|
||||||
|
//Create SciPro Employees from DTOs.
|
||||||
|
for (PersonDTO supervisorDTO : supervisorSet) {
|
||||||
|
User supervisorUser = userDao.getUserByIdentifier(supervisorDTO.id);
|
||||||
|
Employee supervisor = supervisorDao.getFrom(supervisorUser);
|
||||||
|
supervisorsWithRemoteUnit.add(supervisor);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Remove units from supervisors that is not in the remote set.
|
||||||
|
for (Employee supervisor : currentSupervisors) {
|
||||||
|
if(!supervisorsWithRemoteUnit.contains(supervisor)) {
|
||||||
|
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));
|
||||||
|
if(!unitsToRemove.isEmpty()){
|
||||||
|
supervisor.getKeywords().getAll().removeAll(unitsToRemove);
|
||||||
|
logger.debug("Removed units from: " + supervisor.getNameAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private UnitDTO dtoFromUnitKeyword(final Keyword unit){
|
private UnitDTO dtoFromUnitKeyword(final Keyword unit){
|
||||||
UnitDTO dto = new UnitDTO();
|
UnitDTO dto = new UnitDTO();
|
||||||
dto.setName(unit.getKeyword());
|
dto.setName(unit.getKeyword());
|
||||||
@ -542,4 +566,5 @@ public class ImporterFacade {
|
|||||||
dto.setId(area.getIdentifier());
|
dto.setId(area.getIdentifier());
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
importerFacade.addUnexistingUnitsAsKeywords(unitSet);
|
importerFacade.addUnexistingUnitsAsKeywords(unitSet);
|
||||||
|
Set<PersonDTO> allSupervisorsOnUnits = new HashSet<PersonDTO>();
|
||||||
for (final UnitDTO unitDTO : unitSet){
|
for (final UnitDTO unitDTO : unitSet){
|
||||||
Set<PersonDTO> supervisorSet = fetchSupervisorsOnUnit(new HashMap<String,String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor() {
|
Set<PersonDTO> supervisorSet = fetchSupervisorsOnUnit(new HashMap<String,String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor() {
|
||||||
@Override
|
@Override
|
||||||
@ -153,15 +153,20 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
|||||||
return (url+"/orgunit/"+unitDTO.id+"/supervisors");
|
return (url+"/orgunit/"+unitDTO.id+"/supervisors");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
allSupervisorsOnUnits.addAll(supervisorSet);
|
||||||
if(!supervisorSet.isEmpty()){
|
if(!supervisorSet.isEmpty()){
|
||||||
for (PersonDTO supervisorDTO : supervisorSet) {
|
for (PersonDTO supervisorDTO : supervisorSet) {
|
||||||
importerFacade.addUnitToSupervisor(supervisorDTO, unitDTO);
|
importerFacade.addUnitToSupervisor(supervisorDTO, unitDTO);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
logger.info("Unit: " + unitDTO.name + " has no supervisors attached.");
|
logger.info("Unit: " + unitDTO.name + " has no supervisors attached.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compare the list of supervisors with remote units with the list of
|
||||||
|
// all supervisors in scipro, to make sure to remove units from the
|
||||||
|
// users that doesn't have one in daisy.
|
||||||
|
logger.debug("Number of supervisors on remote units: " + allSupervisorsOnUnits.size());
|
||||||
|
importerFacade.removeUnitFromSupervisorsNotInSet(allSupervisorsOnUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user