remake of unit imports to match new api structure is done. also some changes to research area imports to make sure we have the same keywords as remote host
This commit is contained in:
parent
4ebcd2f9b5
commit
29fd30f7bb
src/main/java/se/su/dsv/scipro
io
match/dataobject
@ -3,8 +3,15 @@ package se.su.dsv.scipro.io.dto;
|
||||
|
||||
public class ResearchAreaDTO {
|
||||
public long id;
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String name;
|
||||
|
||||
public String active;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -17,4 +24,25 @@ public class ResearchAreaDTO {
|
||||
public String toString(){
|
||||
return getName();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (id ^ (id >>> 32));
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ResearchAreaDTO other = (ResearchAreaDTO) obj;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,14 @@ import java.util.Set;
|
||||
|
||||
public class UnitDTO {
|
||||
public long id;
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String name;
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -14,30 +22,35 @@ public class UnitDTO {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//public Set<UnitDTO> subunits = new HashSet<UnitDTO>();
|
||||
public Set<SupervisorDTO> supervisors = new HashSet<SupervisorDTO>();
|
||||
|
||||
public UnitDTO(){}
|
||||
|
||||
public String toString(){
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
final int w = 31;
|
||||
int result = 17;
|
||||
result = w * result + (getName()==null?0:getName().hashCode());
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (id ^ (id >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o){
|
||||
if(o==this)
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if(!(o instanceof UnitDTO))
|
||||
if (obj == null)
|
||||
return false;
|
||||
final UnitDTO other = (UnitDTO)o;
|
||||
return ((getName()==null?other.getName()==null:getName().equals(other.getName())));
|
||||
|
||||
}
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
UnitDTO other = (UnitDTO) obj;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -2,7 +2,6 @@ package se.su.dsv.scipro.io.facade;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -426,7 +425,7 @@ public class ImporterFacade {
|
||||
logger.info(supervisor.getUser().getFullName() + " is already attached to a unit and this is being overwritten.");
|
||||
supervisor.getKeywords().getAll().removeAll(currentUnits);
|
||||
}
|
||||
Keyword unitToAdd = keywordDao.getKeywordByNameAndType(unitDTO.name, keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
||||
Keyword unitToAdd = keywordDao.getKeywordByIdentifierAndType(unitDTO.id, keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
||||
logger.info("Adding unit: " + unitToAdd.getKeyword() + " to supervisor: " + supervisor.getUser().getFullName());
|
||||
supervisor.getKeywords().getAll().add(unitToAdd);
|
||||
}
|
||||
@ -446,8 +445,6 @@ public class ImporterFacade {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void addResearchAreaToUser(User user, Keyword area) {
|
||||
Employee supervisor = supervisorDao.getFrom(user);
|
||||
logger.info("Adding research area: " + area.getKeyword() + " to supervisor " + supervisor.getUser().getFullName());
|
||||
@ -456,43 +453,90 @@ public class ImporterFacade {
|
||||
|
||||
@Transactional
|
||||
public void addUnexistingResearchAreas(final Set<ResearchAreaDTO> areas) {
|
||||
for(final ResearchAreaDTO researchAreaDTO : areas){
|
||||
final Set<Keyword> currentAreas = keywordDao.getKeywords(keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA), true);
|
||||
final Set<ResearchAreaDTO> remoteAreas = new HashSet<ResearchAreaDTO>(areas);
|
||||
final Set<Keyword> areasToRemove = new HashSet<Keyword>();
|
||||
//Compare remote with database
|
||||
for (Keyword currentArea : currentAreas){
|
||||
ResearchAreaDTO translatedArea = dtoFromAreaKeyword(currentArea);
|
||||
if(!remoteAreas.contains(translatedArea)){
|
||||
logger.info("Area " + translatedArea.getName() + " does not exist on remote, preparing to remove.");
|
||||
areasToRemove.add(currentArea);
|
||||
}
|
||||
}
|
||||
//Delete areas that not exist on remote
|
||||
for (Keyword areaToRemove : areasToRemove){
|
||||
keywordDao.delete(areaToRemove);
|
||||
logger.info("Deleted research area: " + areaToRemove.getKeyword() + " 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));
|
||||
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 if (!area.getKeyword().equals(researchAreaDTO.name)){
|
||||
logger.info("Research area " + area.getKeyword() + " has changed name, renaming to: " + researchAreaDTO.name);
|
||||
area.setKeyword(researchAreaDTO.name);
|
||||
} else {
|
||||
logger.info("Research area " + area.getKeyword() + " already exists, skipping");
|
||||
}
|
||||
if (researchAreaDTO.active.equals("false")){
|
||||
logger.info(area.getKeyword() + " is inactivated on remote system.");
|
||||
area.setDeleted(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addUnexistingUnitsAsKeywords(final Set<UnitDTO> subunits) {
|
||||
//include deleted keywords set to true, should it be like that? /Friis
|
||||
public void addUnexistingUnitsAsKeywords(final Set<UnitDTO> unitsFromDTO) {
|
||||
final Set<Keyword> currentUnits = keywordDao.getKeywords(keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT), true);
|
||||
final Set<UnitDTO> remoteUnits = new HashSet<UnitDTO>(subunits);
|
||||
final Set<UnitDTO> remoteUnits = new HashSet<UnitDTO>(unitsFromDTO);
|
||||
final Set<Keyword> unitsToRemove = new HashSet<Keyword>();
|
||||
for (Keyword unit : currentUnits) {
|
||||
UnitDTO translatedUnit = dtoFromUnitKeyword(unit);
|
||||
if (remoteUnits.contains(translatedUnit)) {
|
||||
logger.debug("Unit " + translatedUnit + " already exists, skipping..");
|
||||
remoteUnits.remove(translatedUnit);
|
||||
if (!remoteUnits.contains(translatedUnit)) {
|
||||
logger.info("Unit " + translatedUnit.getName() + " does not exist on remote, preparing to remove.");
|
||||
unitsToRemove.add(unit);
|
||||
}
|
||||
}
|
||||
//Create unit keywords of the units that not exists.
|
||||
for (UnitDTO unitToAdd : remoteUnits) {
|
||||
logger.info("Creating unit keyword: " + unitToAdd.name);
|
||||
Keyword unit = new Keyword(unitToAdd.name, keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
||||
unit = keywordDao.save(unit);
|
||||
//Delete units that not exist on remote
|
||||
for (Keyword unitToRemove : unitsToRemove){
|
||||
keywordDao.delete(unitToRemove);
|
||||
logger.info("Deleted unit: " + unitToRemove.getKeyword() + " since it has been removed from remote system");
|
||||
}
|
||||
//Add units to database
|
||||
for(final UnitDTO unitDTO : remoteUnits){
|
||||
Keyword unit = keywordDao.getKeywordByIdentifierAndType(unitDTO.id, keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
||||
if(unit == null){
|
||||
logger.info("External unit: '"+unitDTO+"' has no local representation, creating");
|
||||
unit = new Keyword(unitDTO.name, keywordTypeDao.findByType(KeywordTypeDao.TYPE.UNIT));
|
||||
unit.setIdentifier(unitDTO.id);
|
||||
unit = keywordDao.save(unit);
|
||||
} else if (!unit.getKeyword().equals(unitDTO.name)){
|
||||
logger.info("Unit " + unit.getKeyword() + " has changed name, renaming to: " + unitDTO.name);
|
||||
unit.setKeyword(unitDTO.name);
|
||||
} else {
|
||||
logger.info("Unit " + unit.getKeyword() + " already exists, skipping");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 ResearchAreaDTO dtoFromAreaKeyword(final Keyword area){
|
||||
ResearchAreaDTO dto = new ResearchAreaDTO();
|
||||
dto.setName(area.getKeyword());
|
||||
if (area.getIdentifier() != null)
|
||||
dto.setId(area.getIdentifier());
|
||||
return dto;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -138,33 +138,24 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
||||
}
|
||||
});
|
||||
|
||||
// TOTAL REMAKE
|
||||
importerFacade.addUnexistingUnitsAsKeywords(unitSet);
|
||||
|
||||
for (final UnitDTO unit : unitSet){
|
||||
// Check if existing
|
||||
|
||||
for (final UnitDTO unitDTO : unitSet){
|
||||
Set<SupervisorDTO> supervisorSet = fetchSupervisorsOnUnit(new HashMap<String,String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor() {
|
||||
@Override
|
||||
String process(final String url){
|
||||
return (url+"/orgunit/"+unit.id+"/supervisors");
|
||||
return (url+"/orgunit/"+unitDTO.id+"/supervisors");
|
||||
}
|
||||
});
|
||||
|
||||
// add supervisors to the current unit
|
||||
|
||||
}
|
||||
/*for (UnitDTO u : unitSet) {
|
||||
if (!u.subunits.isEmpty()) {
|
||||
logger.info("Received " + u.subunits.size() + " subunits from remote");
|
||||
importerFacade.addUnexistingUnitsAsKeywords(u.subunits);
|
||||
for (UnitDTO subunitDTO : u.subunits ) {
|
||||
for (SupervisorDTO supervisorDTO : subunitDTO.supervisors) {
|
||||
importerFacade.addUnitToSupervisor(supervisorDTO, subunitDTO);
|
||||
}
|
||||
}
|
||||
if(!supervisorSet.isEmpty()){
|
||||
for (SupervisorDTO supervisorDTO : supervisorSet) {
|
||||
importerFacade.addUnitToSupervisor(supervisorDTO, unitDTO);
|
||||
}
|
||||
} else
|
||||
logger.info("No subunits found");
|
||||
}*/
|
||||
logger.info("Unit: " + unitDTO.name + " has no supervisors attached.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,11 +1,9 @@
|
||||
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;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
@ -26,7 +24,6 @@ public class Keyword extends LazyDeletableDomainObject {
|
||||
|
||||
private String keyword;
|
||||
|
||||
@Column(unique=true)
|
||||
private Long identifier;
|
||||
|
||||
@ManyToOne
|
||||
|
Loading…
x
Reference in New Issue
Block a user