added support for retrieving all available research areas from daisy. still needs to be tested appropriately since api-test still is down

This commit is contained in:
Emil Siverhall 2012-02-07 12:57:22 +01:00
parent ca741ff7a1
commit 0611d806ea
7 changed files with 64 additions and 4 deletions

@ -13,7 +13,8 @@
<div>Include linked projects (only applies when importing users): <input type="checkbox" wicket:id="includeLinkedProjects"/></div>
<div>Import all supervisors: <input type="checkbox" wicket:id="importSupervisors"/></div>
<div>Import attached units to supervisors: <input type="checkbox" wicket:id="importSupervisorUnits" /></div>
<div><input type="submit"/></div>
<!-- <div>Import all research areas from remote: <input type="checkbox" wicket:id="importResearchAreas" /></div>
--> <div><input type="submit"/></div>
</form>
</wicket:enclosure>
<div wicket:id="statusMessage"></div>

@ -13,6 +13,7 @@ import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.springframework.context.annotation.ImportResource;
import se.su.dsv.scipro.ApplicationSettings;
import se.su.dsv.scipro.io.ExternalImporter;
@ -54,6 +55,7 @@ public class ManualImportExportPanel extends Panel {
final long userIdIn = params.getImportUserId();
final boolean importSupervisors = params.isImportSupervisors();
final boolean importSupervisorUnits = params.isImportSupervisorUnits();
//final boolean importResearchAreas = params.isImportResearchAreas();
final long projectIdIn = params.getImportProjectId();
final String projectTitleIn = params.getImportProjectTitle();
final long projectIdOut = params.getExportProjectId();
@ -98,6 +100,16 @@ public class ManualImportExportPanel extends Panel {
setMessage("Failed to import units from "+getRemoteUrl()+", error: "+eie.getWrappedErrorCode());
}
}
/* if(importResearchAreas){
logger.debug("Importing all research areas from remote host");
try {
externalImporter.importResearchAreas();
setMessage("Successfully imported research areas from " + getRemoteUrl());
} catch (final ExternalImportException eie){
logger.warn("Caught error while importing research areas from remote system: "+eie.getMessage());
setMessage("Failed to import research areas from "+getRemoteUrl()+", error: "+eie.getWrappedErrorCode());
}
}*/
if(projectIdIn > 0){
logger.debug("Attempting remote import of project: "+projectIdIn);
try{
@ -133,6 +145,7 @@ public class ManualImportExportPanel extends Panel {
importExportForm.add(new CheckBox("includeLinkedProjects"));
importExportForm.add(new CheckBox("importSupervisors"));
importExportForm.add(new CheckBox("importSupervisorUnits"));
//importExportForm.add(new CheckBox("importResearchAreas"));
importExportForm.setVisible(hasRemote());
}
private boolean hasRemote(){
@ -151,6 +164,7 @@ public class ManualImportExportPanel extends Panel {
private long importUserId;
private boolean importSupervisors;
private boolean importSupervisorUnits;
//private boolean importResearchAreas;
private long importProjectId;
private String importProjectTitle;
private long exportProjectId;
@ -203,5 +217,11 @@ public class ManualImportExportPanel extends Panel {
public void setIncludeLinkedProjects(boolean includeLinkedProjects) {
this.includeLinkedProjects = includeLinkedProjects;
}
/* public void setImportResearchAreas(boolean importResearchAreas) {
this.importResearchAreas = importResearchAreas;
}
public boolean isImportResearchAreas() {
return importResearchAreas;
}*/
}
}

@ -13,5 +13,6 @@ public interface ExternalImporter {
void importProject(final long externalIdentifier) throws ExternalImportException;
void importProjects(final String matchingTitle) throws ExternalImportException;
void importSupervisorUnits() throws ExternalImportException;
void importResearchAreas() throws ExternalImportException;
boolean supportsRemoteOperations();
}

@ -5,7 +5,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
//Collection-wrapper for ProjectDTO objects
//Collection-wrapper for ResearchAreaDTO objects
public class ResearchAreaDTOCollectionWrapper implements Iterable<ResearchAreaDTO>{
private final List<ResearchAreaDTO> areas = new ArrayList<ResearchAreaDTO>();
public ResearchAreaDTOCollectionWrapper(){

@ -424,24 +424,41 @@ public class ImporterFacade {
}
private void mergeLinkedResearchAreas(final User user, final Set<ResearchAreaDTO> areas){
for(final ResearchAreaDTO researchAreaDTO : areas){
for(final ResearchAreaDTO researchAreaDTO : areas){
Keyword area = keywordDao.getKeywordByNameAndType(researchAreaDTO.name, 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 = keywordDao.save(area);
} else {
logger.info("Research area " + area.getKeyword() + " already exists, skipping");
}
addResearchAreaToUser(user, area);
}
}
}
private void addResearchAreaToUser(User user, Keyword area) {
Employee supervisor = supervisorDao.getFrom(user);
logger.info("Adding research area: " + area.getKeyword() + " to supervisor " + supervisor.getUser().getFullName());
supervisor.getKeywords().getAll().add(area);
}
@Transactional
public void addUnexistingResearchAreas(final Set<ResearchAreaDTO> areas) {
for(final ResearchAreaDTO researchAreaDTO : areas){
Keyword area = keywordDao.getKeywordByNameAndType(researchAreaDTO.name, 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 = keywordDao.save(area);
} else {
logger.info("Research area " + area.getKeyword() + " already exists, skipping");
}
}
}
@Transactional
public void addUnexistingUnitsAsKeywords(final Set<UnitDTO> subunits) {
//include deleted keywords set to true, should it be like that? /Friis

@ -149,6 +149,21 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
}
}
@Override
@Transactional
public void importResearchAreas() throws ExternalImportException {
Set<ResearchAreaDTO> areaSet = fetchResearchAreas(new HashMap<String,String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor() {
@Override
String process(final String url){
return (url+"/orgunit/4/researchAreas");
}
});
logger.info("Received " + areaSet.size() + " research areas from remote");
if(!areaSet.isEmpty()){
importerFacade.addUnexistingResearchAreas(areaSet);
}
}
private Set<UnitDTO> fetchRemoteUnits(final Map<String,String> parameters,final HttpRequestSender.REQUEST_TYPE requestType,
UrlProcessor urlProcessor) {
final String requestUrl = (urlProcessor==null?getRequestUrl():urlProcessor.process(getRequestUrl()));
@ -343,4 +358,5 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
return url;
}
}
}

@ -40,5 +40,10 @@ public class ExternalImporterDefaultImpl implements ExternalImporter {
public void importSupervisorUnits() throws ExternalImportException {
// TODO Auto-generated method stub
}
@Override
public void importResearchAreas() throws ExternalImportException {
// TODO Auto-generated method stub
}
}