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:
Emil Siverhall 2012-02-22 20:22:30 +01:00
commit 5a340fa896
2 changed files with 36 additions and 6 deletions
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){
UnitDTO dto = new UnitDTO();
dto.setName(unit.getKeyword());
@ -542,4 +566,5 @@ public class ImporterFacade {
dto.setId(area.getIdentifier());
return dto;
}
}

@ -145,7 +145,7 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
});
importerFacade.addUnexistingUnitsAsKeywords(unitSet);
Set<PersonDTO> allSupervisorsOnUnits = new HashSet<PersonDTO>();
for (final UnitDTO unitDTO : unitSet){
Set<PersonDTO> supervisorSet = fetchSupervisorsOnUnit(new HashMap<String,String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor() {
@Override
@ -153,15 +153,20 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
return (url+"/orgunit/"+unitDTO.id+"/supervisors");
}
});
allSupervisorsOnUnits.addAll(supervisorSet);
if(!supervisorSet.isEmpty()){
for (PersonDTO supervisorDTO : supervisorSet) {
for (PersonDTO supervisorDTO : supervisorSet) {
importerFacade.addUnitToSupervisor(supervisorDTO, unitDTO);
}
}
} else
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